From bb99eb5df35a0a4516e1e677e2cd85e5a9aa6735 Mon Sep 17 00:00:00 2001 From: GalaxyGorilla Date: Thu, 9 Jul 2020 17:37:42 +0000 Subject: [PATCH] isisd: lib: refactor ISIS BFD API Use `zclient_bfd_command` instead of `bfd_peer_sendmsg`. Signed-off-by: GalaxyGorilla --- isisd/isis_bfd.c | 71 ++++++++++++++++++++++++++++++++---------------- lib/bfd.c | 11 ++++++++ 2 files changed, 59 insertions(+), 23 deletions(-) diff --git a/isisd/isis_bfd.c b/isisd/isis_bfd.c index 4408c8bb8b..5729994baa 100644 --- a/isisd/isis_bfd.c +++ b/isisd/isis_bfd.c @@ -255,6 +255,43 @@ static void bfd_debug(int family, union g_addr *dst, union g_addr *src, command_str, dst_str, interface, src_str); } +static void bfd_command(int command, struct bfd_info *bfd_info, int family, + const void *dst_ip, const void *src_ip, + const char *if_name) +{ + struct bfd_session_arg args = {}; + size_t addrlen; + + args.cbit = 1; + args.family = family; + args.vrf_id = VRF_DEFAULT; + args.command = command; + args.bfd_info = bfd_info; + if (args.bfd_info) { + args.min_rx = bfd_info->required_min_rx; + args.min_tx = bfd_info->desired_min_tx; + args.detection_multiplier = bfd_info->detect_mult; + if (bfd_info->profile[0]) { + args.profilelen = strlen(bfd_info->profile); + strlcpy(args.profile, bfd_info->profile, + sizeof(args.profile)); + } + } + + addrlen = family == AF_INET ? sizeof(struct in_addr) + : sizeof(struct in6_addr); + memcpy(&args.dst, dst_ip, addrlen); + if (src_ip) + memcpy(&args.src, src_ip, addrlen); + + if (if_name) { + strlcpy(args.ifname, if_name, sizeof(args.ifname)); + args.ifnamelen = strlen(args.ifname); + } + + zclient_bfd_command(zclient, &args); +} + static void bfd_handle_adj_down(struct isis_adjacency *adj) { if (!adj->bfd_session) @@ -264,17 +301,11 @@ static void bfd_handle_adj_down(struct isis_adjacency *adj) &adj->bfd_session->src_ip, adj->circuit->interface->name, ZEBRA_BFD_DEST_DEREGISTER); - bfd_peer_sendmsg(zclient, NULL, adj->bfd_session->family, - &adj->bfd_session->dst_ip, &adj->bfd_session->src_ip, - (adj->circuit->interface) - ? adj->circuit->interface->name - : NULL, - 0, /* ttl */ - 0, /* multihop */ - 1, /* control plane independent bit is on */ - ZEBRA_BFD_DEST_DEREGISTER, - 0, /* set_flag */ - VRF_DEFAULT); + bfd_command(ZEBRA_BFD_DEST_DEREGISTER, NULL, adj->bfd_session->family, + &adj->bfd_session->dst_ip, &adj->bfd_session->src_ip, + (adj->circuit->interface) ? adj->circuit->interface->name + : NULL); + bfd_session_free(&adj->bfd_session); } @@ -324,18 +355,12 @@ static void bfd_handle_adj_up(struct isis_adjacency *adj, int command) bfd_debug(adj->bfd_session->family, &adj->bfd_session->dst_ip, &adj->bfd_session->src_ip, circuit->interface->name, command); - bfd_peer_sendmsg(zclient, circuit->bfd_info, adj->bfd_session->family, - &adj->bfd_session->dst_ip, - &adj->bfd_session->src_ip, - (adj->circuit->interface) - ? adj->circuit->interface->name - : NULL, - 0, /* ttl */ - 0, /* multihop */ - 1, /* control plane independent bit is on */ - command, - 0, /* set flag */ - VRF_DEFAULT); + + bfd_command(command, circuit->bfd_info, family, + &adj->bfd_session->dst_ip, &adj->bfd_session->src_ip, + (adj->circuit->interface) ? adj->circuit->interface->name + : NULL); + return; out: bfd_handle_adj_down(adj); diff --git a/lib/bfd.c b/lib/bfd.c index d2bcb5b8aa..3c298cce9e 100644 --- a/lib/bfd.c +++ b/lib/bfd.c @@ -128,6 +128,8 @@ void bfd_set_param(struct bfd_info **bfd_info, uint32_t min_rx, uint32_t min_tx, /* * bfd_peer_sendmsg - Format and send a peer register/Unregister * command to Zebra to be forwarded to BFD + * + * DEPRECATED: use zclient_bfd_command instead */ void bfd_peer_sendmsg(struct zclient *zclient, struct bfd_info *bfd_info, int family, void *dst_ip, void *src_ip, char *if_name, @@ -441,6 +443,15 @@ int zclient_bfd_command(struct zclient *zc, struct bfd_session_arg *args) struct stream *s; size_t addrlen; + /* Individual reg/dereg messages are suppressed during shutdown. */ + if (CHECK_FLAG(bfd_gbl.flags, BFD_GBL_FLAG_IN_SHUTDOWN)) { + if (bfd_debug) + zlog_debug( + "%s: Suppressing BFD peer reg/dereg messages", + __func__); + return -1; + } + /* Check socket. */ if (!zc || zc->sock < 0) { if (bfd_debug) -- 2.39.5