]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/bfd.c
ldpd: use red-black trees to store 'tnbr' elements
[mirror_frr.git] / lib / bfd.c
index 613c71487e4e37f7e7767bd393abfa2c8e977bd3..a498daf762b5e538c1aa907aa1be744512f19af2 100644 (file)
--- a/lib/bfd.c
+++ b/lib/bfd.c
 #include "vty.h"
 #include "bfd.h"
 
+DEFINE_MTYPE_STATIC(LIB, BFD_INFO, "BFD info")
+
+int bfd_debug = 0;
+struct bfd_gbl bfd_gbl;
+
+/*
+ * bfd_gbl_init - Initialize the BFD global structure
+ */
+void
+bfd_gbl_init(void)
+{
+  memset(&bfd_gbl, 0, sizeof (struct bfd_gbl));
+}
+
+/*
+ * bfd_gbl_exit - Called when daemon exits
+ */
+void
+bfd_gbl_exit(void)
+{
+  SET_FLAG (bfd_gbl.flags, BFD_GBL_FLAG_IN_SHUTDOWN);
+}
+
 /*
  * bfd_info_create - Allocate the BFD information
  */
@@ -45,6 +68,7 @@ bfd_info_create(void)
   assert(bfd_info);
 
   bfd_info->status = BFD_STATUS_UNKNOWN;
+  bfd_info->type = BFD_TYPE_NOT_CONFIGURED;
   bfd_info->last_update = 0;
   return bfd_info;
 }
@@ -119,23 +143,35 @@ bfd_set_param (struct bfd_info **bfd_info, u_int32_t min_rx, u_int32_t min_tx,
 void
 bfd_peer_sendmsg (struct zclient *zclient, struct bfd_info *bfd_info,
                   int family, void *dst_ip, void *src_ip, char *if_name,
-                  int ttl, int multihop, int command, int set_flag)
+                  int ttl, int multihop, int command, int set_flag,
+                  vrf_id_t vrf_id)
 {
   struct stream *s;
   int ret;
   int len;
 
+  /* Individual reg/dereg messages are supressed 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", __FUNCTION__);
+      return;
+    }
+
   /* Check socket. */
   if (!zclient || zclient->sock < 0)
     {
-      zlog_debug("%s: Can't send BFD peer register, Zebra client not "
-                  "established", __FUNCTION__);
+      if (bfd_debug)
+       zlog_debug("%s: Can't send BFD peer register, Zebra client not "
+                  "established", __FUNCTION__);
       return;
     }
 
   s = zclient->obuf;
   stream_reset (s);
-  zclient_create_header (s, command);
+  zclient_create_header (s, command, vrf_id);
+
+  stream_putl(s, getpid());
 
   stream_putw(s, family);
   switch (family)
@@ -210,7 +246,8 @@ bfd_peer_sendmsg (struct zclient *zclient, struct bfd_info *bfd_info,
 
   if (ret < 0)
     {
-      zlog_warn("bfd_peer_sendmsg: zclient_send_message() failed");
+      if (bfd_debug)
+       zlog_debug("bfd_peer_sendmsg: zclient_send_message() failed");
       return;
     }
 
@@ -250,7 +287,7 @@ bfd_get_command_dbg_str(int command)
  */
 struct interface *
 bfd_get_peer_info (struct stream *s, struct prefix *dp, struct prefix *sp,
-                    int *status)
+                    int *status, vrf_id_t vrf_id)
 {
   unsigned int ifindex;
   struct interface *ifp = NULL;
@@ -262,11 +299,12 @@ bfd_get_peer_info (struct stream *s, struct prefix *dp, struct prefix *sp,
   /* Lookup index. */
   if (ifindex != 0)
     {
-      ifp = if_lookup_by_index (ifindex);
+      ifp = if_lookup_by_index_vrf (ifindex, vrf_id);
       if (ifp == NULL)
         {
-          zlog_warn ("zebra_interface_bfd_read: "
-                     "Can't find interface by ifindex: %d ", ifindex);
+         if (bfd_debug)
+           zlog_debug ("zebra_interface_bfd_read: "
+                       "Can't find interface by ifindex: %d ", ifindex);
           return NULL;
         }
     }
@@ -435,3 +473,43 @@ bfd_show_info(struct vty *vty, struct bfd_info *bfd_info, int multihop,
   else
     vty_out (vty, "%s", VTY_NEWLINE);
 }
+
+/*
+ * bfd_client_sendmsg - Format and send a client register
+ *                    command to Zebra to be forwarded to BFD
+ */
+void
+bfd_client_sendmsg (struct zclient *zclient, int command)
+{
+  struct stream *s;
+  int ret;
+
+  /* Check socket. */
+  if (!zclient || zclient->sock < 0)
+    {
+      if (bfd_debug)
+       zlog_debug ("%s: Can't send BFD client register, Zebra client not "
+                  "established", __FUNCTION__);
+      return;
+    }
+
+  s = zclient->obuf;
+  stream_reset (s);
+  zclient_create_header (s, command, VRF_DEFAULT);
+
+  stream_putl(s, getpid());
+
+  stream_putw_at (s, 0, stream_get_endp (s));
+
+  ret = zclient_send_message(zclient);
+
+  if (ret < 0)
+    {
+      if (bfd_debug)
+       zlog_debug ("bfd_client_sendmsg %ld: zclient_send_message() failed",
+                  (long) getpid());
+      return;
+    }
+
+  return;
+}