From 314327610ecbd77f098fe19d6e40279aa1c35d00 Mon Sep 17 00:00:00 2001 From: Javier Garcia Date: Tue, 21 Jun 2022 08:38:09 +0200 Subject: [PATCH] bfdd: clang-format, messages and reset local address. Some formatting fixes. Add some extra traces. Also reset local address because in the case is changed after bfd session is up echo pkts will have old address. Signed-off-by: Javier Garcia --- bfdd/bfd.c | 2 ++ bfdd/bfd_packet.c | 27 +++++++++++-------- bfdd/bfdd_cli.c | 10 +++++-- .../bfd_vrf_topo1/test_bfd_vrf_topo1.py | 2 +- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/bfdd/bfd.c b/bfdd/bfd.c index 13d22479df85..483beb1b17ce 100644 --- a/bfdd/bfd.c +++ b/bfdd/bfd.c @@ -572,6 +572,8 @@ void ptm_bfd_sess_dn(struct bfd_session *bfd, uint8_t diag) /* clear peer's mac address */ UNSET_FLAG(bfd->flags, BFD_SESS_FLAG_MAC_SET); memset(bfd->peer_hw_addr, 0, sizeof(bfd->peer_hw_addr)); + /* reset local address ,it might has been be changed after bfd is up*/ + memset(&bfd->local_address, 0, sizeof(bfd->local_address)); } static struct bfd_session *bfd_find_disc(struct sockaddr_any *sa, diff --git a/bfdd/bfd_packet.c b/bfdd/bfd_packet.c index fcacbcc07b61..feb7fd632a18 100644 --- a/bfdd/bfd_packet.c +++ b/bfdd/bfd_packet.c @@ -147,7 +147,7 @@ int _ptm_bfd_send(struct bfd_session *bs, uint16_t *port, const void *data, * Checksum is not set in the packet, just computed. * * pkt - * VRRP packet, fully filled out except for checksum field. + * Packet, fully filled out except for checksum field. * * pktsize * sizeof(*pkt) @@ -156,7 +156,7 @@ int _ptm_bfd_send(struct bfd_session *bs, uint16_t *port, const void *data, * IP address that pkt will be transmitted from and too. * * Returns: - * VRRP checksum in network byte order. + * Checksum in network byte order. */ static uint16_t bfd_pkt_checksum(struct udphdr *pkt, size_t pktsize, struct in6_addr *ip, sa_family_t family) @@ -428,7 +428,6 @@ void ptm_bfd_snd(struct bfd_session *bfd, int fbit) #ifdef BFD_LINUX /* * receive the ipv4 echo packet that was loopback in the peers forwarding plane - * */ ssize_t bfd_recv_ipv4_fp(int sd, uint8_t *msgbuf, size_t msgbuflen, uint8_t *ttl, ifindex_t *ifindex, @@ -470,8 +469,9 @@ ssize_t bfd_recv_ipv4_fp(int sd, uint8_t *msgbuf, size_t msgbuflen, checksum = in_cksum((const void *)ip, sizeof(struct iphdr)); if (recv_checksum != checksum) { if (bglobal.debug_network) - zlog_debug("%s: invalid iphdr checksum expected 0x%x rcvd 0x%x", - __func__, checksum, recv_checksum ); + zlog_debug( + "%s: invalid iphdr checksum expected 0x%x rcvd 0x%x", + __func__, checksum, recv_checksum); return -1; } @@ -501,11 +501,12 @@ ssize_t bfd_recv_ipv4_fp(int sd, uint8_t *msgbuf, size_t msgbuflen, recv_checksum = uh->check; uh->check = 0; checksum = bfd_pkt_checksum(uh, ntohs(uh->len), - (struct in6_addr *)&ip->saddr, AF_INET); + (struct in6_addr *)&ip->saddr, AF_INET); if (recv_checksum != checksum) { if (bglobal.debug_network) - zlog_debug("%s: invalid udphdr checksum expected 0x%x rcvd 0x%x", - __func__, checksum, recv_checksum ); + zlog_debug( + "%s: invalid udphdr checksum expected 0x%x rcvd 0x%x", + __func__, checksum, recv_checksum); return -1; } return mlen; @@ -1564,7 +1565,8 @@ int bp_echo_socket(const struct vrf *vrf) /* adjust filter for socket to only receive ECHO packets */ pf.filter = my_filterudp; pf.len = MY_FILTER_LENGTH; - if (setsockopt(s, SOL_SOCKET, SO_ATTACH_FILTER, &pf, sizeof(pf)) == -1) { + if (setsockopt(s, SOL_SOCKET, SO_ATTACH_FILTER, &pf, sizeof(pf)) == + -1) { zlog_warn("%s: setsockopt(SO_ATTACH_FILTER): %s", __func__, strerror(errno)); return -1; @@ -1574,7 +1576,11 @@ int bp_echo_socket(const struct vrf *vrf) sll.sll_family = AF_PACKET; sll.sll_protocol = htons(ETH_P_IP); sll.sll_ifindex = 0; - bind(s, (struct sockaddr *)&sll, sizeof(sll)); + if (bind(s, (struct sockaddr *)&sll, sizeof(sll)) < 0) { + zlog_warn("Failed to bind echo socket: %s", + safe_strerror(errno)); + return -1; + } return s; } @@ -1586,7 +1592,6 @@ int bp_echo_socket(const struct vrf *vrf) frr_with_privs(&bglobal.bfdd_privs) { s = vrf_socket(AF_INET, SOCK_DGRAM, 0, vrf->vrf_id, vrf->name); } - if (s == -1) zlog_fatal("echo-socket: socket: %s", strerror(errno)); diff --git a/bfdd/bfdd_cli.c b/bfdd/bfdd_cli.c index 142c962c1369..69424c45d9a8 100644 --- a/bfdd/bfdd_cli.c +++ b/bfdd/bfdd_cli.c @@ -423,13 +423,19 @@ DEFPY_YANG( "Configure echo mode\n") { if (!bfd_cli_is_profile(vty) && !bfd_cli_is_single_hop(vty)) { - vty_out(vty, "%% Echo mode is only available for single hop sessions.\n"); + vty_out(vty, + "%% Echo mode is only available for single hop sessions.\n"); return CMD_WARNING_CONFIG_FAILED; } if (!no && !bglobal.bg_use_dplane) { +#ifdef BFD_LINUX + vty_out(vty, + "%% Echo mode works correctly for IPv4, but only works when the peer is also FRR for IPv6.\n"); +#else vty_out(vty, - "%% Echo mode works correctly for ipv4, but only works when the peer is also FRR for IPv6.\n"); + "%% Current implementation of echo mode works only when the peer is also FRR.\n"); +#endif /* BFD_LINUX */ } nb_cli_enqueue_change(vty, "./echo-mode", NB_OP_MODIFY, diff --git a/tests/topotests/bfd_vrf_topo1/test_bfd_vrf_topo1.py b/tests/topotests/bfd_vrf_topo1/test_bfd_vrf_topo1.py index acb86ea7f290..700e64cfe2de 100644 --- a/tests/topotests/bfd_vrf_topo1/test_bfd_vrf_topo1.py +++ b/tests/topotests/bfd_vrf_topo1/test_bfd_vrf_topo1.py @@ -186,7 +186,7 @@ def test_bgp_fast_convergence(): "show ip bgp vrf {}-bfd-cust1 json".format(router.name), expected, ) - _, res = topotest.run_and_expect(test_func, None, count=40, wait=1) + _, res = topotest.run_and_expect(test_func, None, count=40, wait=2) assertmsg = "{}: bgp did not converge".format(router.name) assert res is None, assertmsg