Browse Source

bgpd: divorce router-id logic from CLI & zebra

Logic for determining the router-id was spread out over bgp_zebra.c and
bgp_vty.c.  Move to bgpd/bgpd.c and have these two call more properly
encapsulated functions.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
David Lamparter 4 years ago
parent
commit
584083d505
5 changed files with 29 additions and 16 deletions
  1. 3 6
      bgpd/bgp_vty.c
  2. 1 8
      bgpd/bgp_zebra.c
  3. 1 0
      bgpd/bgp_zebra.h
  4. 22 1
      bgpd/bgpd.c
  5. 2 1
      bgpd/bgpd.h

+ 3 - 6
bgpd/bgp_vty.c

@@ -51,8 +51,6 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 #include "bgpd/bgp_vty.h"
 #include "bgpd/bgp_mpath.h"
 
-extern struct in_addr router_id_zebra;
-
 /* Utility function to get address family from current node.  */
 afi_t
 bgp_node_afi (struct vty *vty)
@@ -489,8 +487,7 @@ DEFUN (bgp_router_id,
       return CMD_WARNING;
     }
 
-  bgp->router_id_static = id;
-  bgp_router_id_set (bgp, &id);
+  bgp_router_id_static_set (bgp, id);
 
   return CMD_SUCCESS;
 }
@@ -524,8 +521,8 @@ DEFUN (no_bgp_router_id,
 	}
     }
 
-  bgp->router_id_static.s_addr = 0;
-  bgp_router_id_set (bgp, &router_id_zebra);
+  id.s_addr = 0;
+  bgp_router_id_static_set (bgp, id);
 
   return CMD_SUCCESS;
 }

+ 1 - 8
bgpd/bgp_zebra.c

@@ -53,8 +53,6 @@ bgp_router_id_update (int command, struct zclient *zclient, zebra_size_t length,
     vrf_id_t vrf_id)
 {
   struct prefix router_id;
-  struct listnode *node, *nnode;
-  struct bgp *bgp;
 
   zebra_router_id_update_read(zclient->ibuf,&router_id);
 
@@ -67,12 +65,7 @@ bgp_router_id_update (int command, struct zclient *zclient, zebra_size_t length,
 
   router_id_zebra = router_id.u.prefix4;
 
-  for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
-    {
-      if (!bgp->router_id_static.s_addr)
-        bgp_router_id_set (bgp, &router_id.u.prefix4);
-    }
-
+  bgp_router_id_zebra_bump ();
   return 0;
 }
 

+ 1 - 0
bgpd/bgp_zebra.h

@@ -24,6 +24,7 @@ Boston, MA 02111-1307, USA.  */
 #define BGP_NEXTHOP_BUF_SIZE (8 * sizeof (struct in_addr *))
 
 extern struct stream *bgp_nexthop_buf;
+extern struct in_addr router_id_zebra;
 
 extern void bgp_zebra_init (struct thread_master *master);
 extern void bgp_zebra_destroy (void);

+ 22 - 1
bgpd/bgpd.c

@@ -160,7 +160,7 @@ bgp_config_check (struct bgp *bgp, int config)
 }
 
 /* Set BGP router identifier. */
-int
+static int
 bgp_router_id_set (struct bgp *bgp, struct in_addr *id)
 {
   struct peer *peer;
@@ -188,6 +188,27 @@ bgp_router_id_set (struct bgp *bgp, struct in_addr *id)
   return 0;
 }
 
+void
+bgp_router_id_zebra_bump (void)
+{
+  struct listnode *node, *nnode;
+  struct bgp *bgp;
+
+  for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
+    {
+      if (!bgp->router_id_static.s_addr)
+        bgp_router_id_set (bgp, &router_id_zebra);
+    }
+}
+
+int
+bgp_router_id_static_set (struct bgp *bgp, struct in_addr id)
+{
+  bgp->router_id_static = id;
+  bgp_router_id_set (bgp, id.s_addr ? &id : &router_id_zebra);
+  return 0;
+}
+
 /* BGP's cluster-id control. */
 int
 bgp_cluster_id_set (struct bgp *bgp, struct in_addr *cluster_id)

+ 2 - 1
bgpd/bgpd.h

@@ -886,7 +886,8 @@ extern int bgp_flag_check (struct bgp *, int);
 extern void bgp_lock (struct bgp *);
 extern void bgp_unlock (struct bgp *);
 
-extern int bgp_router_id_set (struct bgp *, struct in_addr *);
+extern void bgp_router_id_zebra_bump (void);
+extern int bgp_router_id_static_set (struct bgp *, struct in_addr);
 
 extern int bgp_cluster_id_set (struct bgp *, struct in_addr *);
 extern int bgp_cluster_id_unset (struct bgp *);