Common router id.
diff --git a/bgpd/ChangeLog b/bgpd/ChangeLog
index 2bcce1c..d5ab328 100644
--- a/bgpd/ChangeLog
+++ b/bgpd/ChangeLog
@@ -1,3 +1,11 @@
+2004-10-03 James R. Leu <jleu at mindspring.com>
+
+	* bgp_vty.c: Router id from zebra can be manually overriden.
+	* bgp_zebra.c: Read router id related messages from zebra daemon.
+	  Remove own code related with router id selection.
+	* bgpd.c, bgpd.h: Remove own router id selection code. Use the one
+	  from zebra daemon if it isn't manually overriden.
+
 2004-09-26 Hasso Tepper <hasso at quagga.net>
 
 	* bgp_aspath.c, bgp_packet.c, bgp_vty.c: Fix compiler warnings.
diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c
index 27a3c2e..6b3c498 100644
--- a/bgpd/bgp_vty.c
+++ b/bgpd/bgp_vty.c
@@ -41,6 +41,8 @@
 #include "bgpd/bgp_zebra.h"
 #include "bgpd/bgp_table.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)
@@ -400,6 +402,7 @@
       return CMD_WARNING;
     }
 
+  bgp->router_id_static = id;
   bgp_router_id_set (bgp, &id);
 
   return CMD_SUCCESS;
@@ -427,14 +430,15 @@
 	  return CMD_WARNING;
 	}
 
-      if (! IPV4_ADDR_SAME (&bgp->router_id, &id))
+      if (! IPV4_ADDR_SAME (&bgp->router_id_static, &id))
 	{
 	  vty_out (vty, "%% BGP router-id doesn't match%s", VTY_NEWLINE);
 	  return CMD_WARNING;
 	}
     }
 
-  bgp_router_id_unset (bgp);
+  bgp->router_id_static.s_addr = 0;
+  bgp_router_id_set (bgp, &router_id_zebra);
 
   return CMD_SUCCESS;
 }
diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c
index 42b8fc7..6226a93 100644
--- a/bgpd/bgp_zebra.c
+++ b/bgpd/bgp_zebra.c
@@ -39,61 +39,25 @@
 
 /* All information about zebra. */
 static struct zclient *zclient = NULL;
+struct in_addr router_id_zebra;
 
-/* Update default router id. */
+/* Router-id update message from zebra. */
 int
-bgp_if_update (struct interface *ifp)
+bgp_router_id_update (int command, struct zclient *zclient, zebra_size_t length)
 {
-  struct bgp *bgp;
-  struct listnode *cn;
+  struct prefix router_id;
   struct listnode *nn;
-  struct listnode *nm;
-  struct peer *peer;
+  struct bgp *bgp;
 
-  for (cn = listhead (ifp->connected); cn; nextnode (cn))
+  zebra_router_id_update_read(zclient->ibuf,&router_id);
+  router_id_zebra = router_id.u.prefix4;
+
+  LIST_LOOP (bm->bgp, bgp, nn)
     {
-      struct connected *co;
-      struct in_addr addr;
-
-      co = getdata (cn);
-
-      if (co->address->family == AF_INET)
-	{
-	  addr = co->address->u.prefix4;
-
-	  /* Ignore NET127. */
-	  if (IPV4_NET127 (ntohl (addr.s_addr)))
-	    continue;
-
-	  LIST_LOOP (bm->bgp, bgp, nn)
-	    {
-	      /* Respect configured router id */
-	      if (! (bgp->config & BGP_CONFIG_ROUTER_ID))
-		if (ntohl (bgp->router_id.s_addr) < ntohl (addr.s_addr))
-		  {
-		    bgp->router_id = addr;
-		    LIST_LOOP (bgp->peer, peer, nm)
-		      {
-			peer->local_id = addr;
-		      }
-		  }
-	    }
-	}
+      if (!bgp->router_id_static.s_addr)
+      bgp_router_id_set (bgp, &router_id.u.prefix4);
     }
-  return 0;
-}
 
-int
-bgp_if_update_all ()
-{
-  struct listnode *node;
-  struct interface *ifp;
-
-  for (node = listhead (iflist); node; node = nextnode (node))
-    {
-      ifp = getdata (node);
-      bgp_if_update (ifp);
-    }
   return 0;
 }
 
@@ -104,7 +68,6 @@
   struct interface *ifp;
 
   ifp = zebra_interface_add_read (zclient->ibuf);
-  bgp_if_update (ifp);
 
   return 0;
 }
@@ -206,8 +169,6 @@
   if (ifc == NULL)
     return 0;
 
-  bgp_if_update (ifc->ifp);
-
   if (if_is_operative (ifc->ifp))
     bgp_connected_add (ifc);
 
@@ -225,8 +186,6 @@
   if (ifc == NULL)
     return 0;
 
-  bgp_if_update (ifc->ifp);
-
   if (if_is_operative (ifc->ifp))
     bgp_connected_delete (ifc);
 
@@ -987,6 +946,7 @@
   /* Set default values. */
   zclient = zclient_new ();
   zclient_init (zclient, ZEBRA_ROUTE_BGP);
+  zclient->router_id_update = bgp_router_id_update;
   zclient->interface_add = bgp_interface_add;
   zclient->interface_delete = bgp_interface_delete;
   zclient->interface_address_add = bgp_interface_address_add;
diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c
index 6afbe95..61ffe27 100644
--- a/bgpd/bgpd.c
+++ b/bgpd/bgpd.c
@@ -63,6 +63,8 @@
 /* BGP process wide configuration.  */
 static struct bgp_master bgp_master;
 
+extern struct in_addr router_id_zebra;
+
 /* BGP process wide configuration pointer to export.  */
 struct bgp_master *bm;
 
@@ -182,42 +184,6 @@
   return 0;
 }
 
-/* Unset BGP router identifier. */
-int
-bgp_router_id_unset (struct bgp *bgp)
-{
-  struct peer *peer;
-  struct listnode *nn;
-
-  if (! bgp_config_check (bgp, BGP_CONFIG_ROUTER_ID))
-    return 0;
-
-  bgp->router_id.s_addr = 0;
-  bgp_config_unset (bgp, BGP_CONFIG_ROUTER_ID);
-
-  /* Clear peer router id configuration.  */
-  LIST_LOOP (bgp->peer, peer, nn)
-    {
-      peer->local_id.s_addr = 0;
-    }
-
-  /* Set router-id from interface's address. */
-  bgp_if_update_all ();
-
-  /* Reset all BGP sessions to use new router-id.  */
-  LIST_LOOP (bgp->peer, peer, nn)
-    {
-      if (peer->status == Established)
-       {
-         peer->last_reset = PEER_DOWN_RID_CHANGE;
-         bgp_notify_send (peer, BGP_NOTIFY_CEASE,
-                          BGP_NOTIFY_CEASE_CONFIG_CHANGE);
-       }
-    }
-
-  return 0;
-}
-
 /* BGP's cluster-id control. */
 int
 bgp_cluster_id_set (struct bgp *bgp, struct in_addr *cluster_id)
@@ -1910,7 +1876,7 @@
 
   bgp = bgp_create (as, name);
   listnode_add (bm->bgp, bgp);
-  bgp_if_update_all ();
+  bgp_router_id_set(bgp, &router_id_zebra);
   *bgp_val = bgp;
 
   return 0;
diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h
index 61472d8..ed3f4d1 100644
--- a/bgpd/bgpd.h
+++ b/bgpd/bgpd.h
@@ -76,6 +76,7 @@
 
   /* BGP router identifier.  */
   struct in_addr router_id;
+  struct in_addr router_id_static;
 
   /* BGP route reflector cluster ID.  */
   struct in_addr cluster_id;