]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Generate router_id automatically if possible (standard "smallest of local
authorMartin Mares <mj@ucw.cz>
Mon, 19 Oct 1998 18:13:36 +0000 (18:13 +0000)
committerMartin Mares <mj@ucw.cz>
Mon, 19 Oct 1998 18:13:36 +0000 (18:13 +0000)
regular interface addresses" rule).

Protocols should NOT rely on router_id existence -- when router ID is not
available, the router_id variable is set to zero and protocols requiring
valid router ID should just refuse to start, reporting such error to the log.

nest/iface.c
nest/iface.h
sysdep/unix/main.c

index f6f33a99cc34b7920875fbd2ee936422b822367f..5f356fd8d3fe0780c570598580774b36d020b739 100644 (file)
@@ -15,6 +15,8 @@
 
 static pool *if_pool;
 
+u32 router_id;
+
 /*
  *     Neighbor Cache
  *
@@ -196,7 +198,7 @@ if_dump_all(void)
   debug("Known network interfaces:\n");
   WALK_LIST(i, iface_list)
     if_dump(i);
-  debug("\n");
+  debug("\nRouter ID: %08x\n\n", router_id);
 }
 
 static inline int
@@ -324,6 +326,25 @@ if_feed_baby(struct proto *p)
     p->if_notify(p, IF_CHANGE_CREATE | ((i->flags & IF_UP) ? IF_CHANGE_UP : 0), NULL, i);
 }
 
+void
+auto_router_id(void)                   /* FIXME: What if we run IPv6??? */
+{
+  struct iface *i, *j;
+
+  if (router_id)
+    return;
+  j = NULL;
+  WALK_LIST(i, iface_list)
+    if ((i->flags & IF_UP) &&
+       !(i->flags & (IF_UNNUMBERED | IF_LOOPBACK | IF_IGNORE)) &&
+       (!j || ipa_to_u32(i->ip) < ipa_to_u32(j->ip)))
+      j = i;
+  if (!j)                              /* FIXME: allow configuration or running without RID */
+    die("Cannot determine router ID, please configure manually");
+  router_id = ipa_to_u32(j->ip);
+  debug("Router ID set to %08x (%s)\n", router_id, j->name);
+}
+
 void
 if_init(void)
 {
index ff6ddeea82a36acdf31d2bee0cb068252a1d51da..ea937207586565b8e185a6d75bf22218dd89a753 100644 (file)
@@ -54,6 +54,7 @@ void if_dump_all(void);
 void if_update(struct iface *);
 void if_end_update(void);
 void if_feed_baby(struct proto *);
+void auto_router_id(void);
 
 /*
  *     Neighbor Cache. We hold (direct neighbor, protocol) pairs we've seen
index 4c60ee62f7365324439edcc7ed42633dc860537f..3d927cb79206c1fc7faedd49a314245e2948ebcf 100644 (file)
@@ -86,6 +86,7 @@ main(void)
   signal_init();
 
   scan_if_init();
+  auto_router_id();
 
   protos_start();