Skip to content

Commit

Permalink
bfdd: clang-format, messages and reset local address.
Browse files Browse the repository at this point in the history
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 <javier.martin.garcia@ibm.com>
  • Loading branch information
Javier Garcia committed Jun 21, 2022
1 parent 0a0f7b8 commit 94db7ee
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
2 changes: 2 additions & 0 deletions bfdd/bfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
27 changes: 16 additions & 11 deletions bfdd/bfd_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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));

Expand Down
10 changes: 8 additions & 2 deletions bfdd/bfdd_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 94db7ee

Please sign in to comment.