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>
diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c
index 3b69a1b..925e267 100644
--- a/bgpd/bgp_vty.c
+++ b/bgpd/bgp_vty.c
@@ -51,8 +51,6 @@
 #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 @@
       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 @@
 	}
     }
 
-  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;
 }
diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c
index 4066a9a..85380f0 100644
--- a/bgpd/bgp_zebra.c
+++ b/bgpd/bgp_zebra.c
@@ -53,8 +53,6 @@
     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 @@
 
   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;
 }
 
diff --git a/bgpd/bgp_zebra.h b/bgpd/bgp_zebra.h
index e69a0bc..2565158 100644
--- a/bgpd/bgp_zebra.h
+++ b/bgpd/bgp_zebra.h
@@ -24,6 +24,7 @@
 #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);
diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c
index 9521927..db952c7 100644
--- a/bgpd/bgpd.c
+++ b/bgpd/bgpd.c
@@ -160,7 +160,7 @@
 }
 
 /* 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 @@
   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)
diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h
index 53f8cb7..a6ced5b 100644
--- a/bgpd/bgpd.h
+++ b/bgpd/bgpd.h
@@ -886,7 +886,8 @@
 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 *);