]> git.proxmox.com Git - mirror_frr.git/commitdiff
isisd: lib: refactor ISIS BFD API
authorGalaxyGorilla <sascha@netdef.org>
Thu, 9 Jul 2020 17:37:42 +0000 (17:37 +0000)
committerGalaxyGorilla <sascha@netdef.org>
Fri, 10 Jul 2020 12:51:04 +0000 (12:51 +0000)
Use `zclient_bfd_command` instead of `bfd_peer_sendmsg`.

Signed-off-by: GalaxyGorilla <sascha@netdef.org>
isisd/isis_bfd.c
lib/bfd.c

index 4408c8bb8bbe26dc02b64913bb5de85dc496a421..5729994baac15a1a96f058a2e620673b6dec3d68 100644 (file)
@@ -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);
index d2bcb5b8aaf56f904392dae9abfd7fd0d94c1dc3..3c298cce9e8e0db12816e883df67ce1ec8f1e546 100644 (file)
--- 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)