]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Implements protocol-specific Router ID for OSPF.
authorOndrej Zajicek <santiago@crfreenet.org>
Fri, 11 Dec 2009 00:20:53 +0000 (01:20 +0100)
committerOndrej Zajicek <santiago@crfreenet.org>
Fri, 11 Dec 2009 10:06:51 +0000 (11:06 +0100)
And fixes one minor bug.

doc/bird.sgml
proto/ospf/dbdes.c
proto/ospf/hello.c
proto/ospf/lsalib.c
proto/ospf/lsupd.c
proto/ospf/neighbor.c
proto/ospf/ospf.h
proto/ospf/packet.c
proto/ospf/rt.c
proto/ospf/topology.c

index 0c2b8fbe87c068bd2ab88df2cbb8116f783509b5..b4dece16f0f72029711ba64ab9c28fe0dc50cccc 100644 (file)
@@ -298,8 +298,7 @@ to zero to disable it. An empty <cf><m/switch/</cf> is equivalent to <cf/on/
        <cf/packets/ for packets sent and received by the protocol. Default: off.
 
        <tag>router id <m/IPv4 address/</tag> This option can be used to override global
-       router id for a given protocol. This option is not yet implemented for OSPF
-       protocol. Default: uses global router id.
+       router id for a given protocol. Default: uses global router id.
 
        <tag>import all | none | filter <m/name/ | filter { <m/filter commands/ } | where <m/filter expression/</tag> 
        Specify a filter to be used for filtering routes coming from the protocol to the routing table. <cf/all/ is shorthand for <cf/where true/ and <cf/none/ is shorthand for <cf/where false/. Default: <cf/all/.
index 2cb2dd8d92b100bff5cfc8b155b8aa6a5f2f55ca..a249d75f84bd9cca7edb1ca1f441273e3db21adf 100644 (file)
@@ -247,8 +247,8 @@ void
 ospf_dbdes_receive(struct ospf_packet *ps_i, struct ospf_iface *ifa,
                   struct ospf_neighbor *n)
 {
-  struct proto *p = &ifa->oa->po->proto;
-  u32 myrid = p->cf->global->router_id;
+  struct proto_ospf *po = ifa->oa->po;
+  struct proto *p = &po->proto;
 
   unsigned int size = ntohs(ps_i->length);
   if (size < sizeof(struct ospf_dbdes_packet))
@@ -278,7 +278,7 @@ ospf_dbdes_receive(struct ospf_packet *ps_i, struct ospf_iface *ifa,
       return;
   case NEIGHBOR_EXSTART:
     if ((ps->imms.bit.m && ps->imms.bit.ms && ps->imms.bit.i)
-       && (n->rid > myrid) && (size == sizeof(struct ospf_dbdes_packet)))
+       && (n->rid > po->router_id) && (size == sizeof(struct ospf_dbdes_packet)))
     {
       /* I'm slave! */
       n->dds = ps_ddseq;
@@ -293,7 +293,7 @@ ospf_dbdes_receive(struct ospf_packet *ps_i, struct ospf_iface *ifa,
     }
 
     if (((ps->imms.bit.i == 0) && (ps->imms.bit.ms == 0)) &&
-        (n->rid < myrid) && (n->dds == ps_ddseq))
+        (n->rid < po->router_id) && (n->dds == ps_ddseq))
     {
       /* I'm master! */
       n->options = ps_options;
index 855b07008543583f5857c5eb58a35573ba6f7327..738748d8592d3a74df73b896f1ef2140f8b6a100 100644 (file)
@@ -45,7 +45,8 @@ void
 ospf_hello_receive(struct ospf_packet *ps_i, struct ospf_iface *ifa,
                   struct ospf_neighbor *n, ip_addr faddr)
 {
-  struct proto *p = &ifa->oa->po->proto;
+  struct proto_ospf *po = ifa->oa->po;
+  struct proto *p = &po->proto;
   char *beg = "Bad OSPF HELLO packet from ", *rec = " received: ";
   unsigned int size, i, twoway, oldpriority, eligible, peers;
   u32 olddr, oldbdr, oldiface_id, tmp;
@@ -175,7 +176,7 @@ ospf_hello_receive(struct ospf_packet *ps_i, struct ospf_iface *ifa,
   twoway = 0;
   for (i = 0; i < peers; i++)
   {
-    if (ntohl(*(pnrid + i)) == p->cf->global->router_id)
+    if (ntohl(pnrid[i]) == po->router_id)
     {
       DBG("%s: Twoway received from %I\n", p->name, faddr);
       ospf_neigh_sm(n, INM_2WAYREC);
@@ -206,9 +207,9 @@ ospf_hello_receive(struct ospf_packet *ps_i, struct ospf_iface *ifa,
   if (n->state >= NEIGHBOR_2WAY)
   {
 #ifdef OSPFv2
-    u32 rid = ipa_to_u32(n->ip);
+    u32 neigh = ipa_to_u32(n->ip);
 #else /* OSPFv3 */
-    u32 rid = p->cf->global->router_id;
+    u32 neigh = n->rid;
 #endif
 
     if (n->priority != oldpriority)
@@ -219,23 +220,23 @@ ospf_hello_receive(struct ospf_packet *ps_i, struct ospf_iface *ifa,
       ospf_iface_sm(ifa, ISM_NEICH);
 #endif
 
-    /* Router is declaring itself ad DR and there is no BDR */
-    if ((rid == n->dr) && (n->bdr == 0)
+    /* Neighbor is declaring itself ad DR and there is no BDR */
+    if ((n->dr == neigh) && (n->bdr == 0)
        && (n->state != NEIGHBOR_FULL))
       ospf_iface_sm(ifa, ISM_BACKS);
 
     /* Neighbor is declaring itself as BDR */
-    if ((rid == n->bdr) && (n->state != NEIGHBOR_FULL))
+    if ((n->bdr == neigh) && (n->state != NEIGHBOR_FULL))
       ospf_iface_sm(ifa, ISM_BACKS);
 
     /* Neighbor is newly declaring itself as DR or BDR */
-    if (((rid == n->dr) && (n->dr != olddr))
-       || ((rid == n->bdr) && (n->bdr != oldbdr)))
+    if (((n->dr == neigh) && (n->dr != olddr))
+       || ((n->bdr == neigh) && (n->bdr != oldbdr)))
       ospf_iface_sm(ifa, ISM_NEICH);
 
     /* Neighbor is no more declaring itself as DR or BDR */
-    if (((rid == olddr) && (n->dr != olddr))
-       || ((rid == oldbdr) && (n->bdr != oldbdr)))
+    if (((olddr == neigh) && (n->dr != olddr))
+       || ((oldbdr == neigh) && (n->bdr != oldbdr)))
       ospf_iface_sm(ifa, ISM_NEICH);
   }
 
index 7ee3aa4bdf52ed843ff1bf0948feb9a2a7dd7f15..deb311362bf6281cc4ff581efa6eff7ae6b24d51 100644 (file)
@@ -65,8 +65,7 @@ ospf_age(struct proto_ospf *po)
        flush_lsa(en, po);
       continue;
     }
-    if ((en->lsa.rt == p->cf->global->router_id) &&
-       (en->lsa.age >= LSREFRESHTIME))
+    if ((en->lsa.rt == po->router_id) && (en->lsa.age >= LSREFRESHTIME))
     {
       OSPF_TRACE(D_EVENTS, "Refreshing my LSA: Type: %u, Id: %R, Rt: %R",
                 en->lsa.type, en->lsa.id, en->lsa.rt);
index a0133855aae5aa2ee793c28f98bb3153b8db9557..a49fded7df76286e2104db4636032799e4ff6c48 100644 (file)
@@ -524,7 +524,7 @@ ospf_lsupd_receive(struct ospf_packet *ps_i, struct ospf_iface *ifa,
     if ((lsadb == NULL) || (lsa_comp(&lsatmp, &lsadb->lsa) == CMP_NEWER))
     {
       struct ospf_iface *ift = NULL;
-      int self = (lsatmp.rt == p->cf->global->router_id);
+      int self = (lsatmp.rt == po->router_id);
 
       DBG("PG143(5): Received LSA is newer\n");
 
index aa7bc2fc826ceed39cc696bb166fe5a5906b4906..ba8d7b98b3bf01097507e3da3fec1ecf8de12435 100644 (file)
@@ -439,15 +439,14 @@ ospf_neigh_sm(struct ospf_neighbor *n, int event)
 void
 bdr_election(struct ospf_iface *ifa)
 {
+  struct proto_ospf *po = ifa->oa->po;
+  struct proto *p = &po->proto;
+  u32 myid = po->router_id;
   struct ospf_neighbor *neigh, *ndr, *nbdr, me;
-  u32 myid;
   int doadj;
-  struct proto *p = &ifa->oa->po->proto;
 
   DBG("(B)DR election.\n");
 
-  myid = p->cf->global->router_id;
-
   me.state = NEIGHBOR_2WAY;
   me.rid = myid;
   me.priority = ifa->priority;
index 5a11418f9e8b2cb21e2faf0f240d2801c0168557..0930a0654c2f906d3d55d3b409114cb8a9fe5112 100644 (file)
@@ -730,6 +730,7 @@ struct proto_ospf
   struct ospf_area *backbone;  /* If exists */
   void *lsab;                  /* LSA buffer used when originating router LSAs */
   int lsab_size, lsab_used;
+  u32 router_id;
 };
 
 struct ospf_iface_patt
index 94ec010936ecab058d64b474a97f22adb9324a29..1a02c00eb950599d8128b4e97d8d332e36f64baf 100644 (file)
@@ -13,8 +13,9 @@
 void
 ospf_pkt_fill_hdr(struct ospf_iface *ifa, void *buf, u8 h_type)
 {
+  struct proto_ospf *po = ifa->oa->po;
+  struct proto *p = &po->proto;
   struct ospf_packet *pkt;
-  struct proto *p = (struct proto *) (ifa->oa->po);
 
   pkt = (struct ospf_packet *) buf;
 
@@ -22,7 +23,7 @@ ospf_pkt_fill_hdr(struct ospf_iface *ifa, void *buf, u8 h_type)
 
   pkt->type = h_type;
 
-  pkt->routerid = htonl(p->cf->global->router_id);
+  pkt->routerid = htonl(po->router_id);
   pkt->areaid = htonl(ifa->oa->areaid);
 
 #ifdef OSPFv3
@@ -345,7 +346,7 @@ ospf_rx_hook(sock * sk, int size)
   }
 #endif
 
-  if (ntohl(ps->routerid) == p->cf->global->router_id)
+  if (ntohl(ps->routerid) == po->router_id)
   {
     log(L_ERR "%s%I - received my own router ID!", mesg, sk->faddr);
     return 1;
index dde6dcd53680474fe2e02107256c0439a1a73694..60e48cf8e94601a970ce8e05ce7937dba4553299 100644 (file)
@@ -534,10 +534,9 @@ ospf_rt_sum_tr(struct ospf_area *oa)
     if (en->dist == LSINFINITY)
       continue;
 
-    if (en->lsa.rt == p->cf->global->router_id)
+    if (en->lsa.rt == po->router_id)
       continue;
 
-
     if (en->lsa.type == LSA_T_SUM_NET)
     {
 #ifdef OSPFv2
@@ -630,7 +629,7 @@ ospf_rt_sum(struct ospf_area *oa)
       continue;
 
     /* Page 169 (2) */
-    if (en->lsa.rt == p->cf->global->router_id)
+    if (en->lsa.rt == po->router_id)
       continue;
 
 
@@ -826,7 +825,7 @@ ospf_ext_spf(struct proto_ospf *po)
       continue;
 
     /* 16.4. (2) */
-    if (en->lsa.rt == p->cf->global->router_id)
+    if (en->lsa.rt == po->router_id)
       continue;
 
     DBG("%s: Working on LSA. ID: %R, RT: %R, Type: %u\n",
index 5b6d631a4c6c5bf8d0829a11db333fdb851379cd..231db134721e31636412788ecbf4ba282ab09877 100644 (file)
@@ -424,7 +424,6 @@ originate_rt_lsa(struct ospf_area *oa)
   struct ospf_lsa_header lsa;
   struct proto_ospf *po = oa->po;
   struct proto *p = &po->proto;
-  u32 rid = po->proto.cf->global->router_id;
   void *body;
 
   OSPF_TRACE(D_EVENTS, "Originating router-LSA for area %R", oa->areaid);
@@ -436,8 +435,8 @@ originate_rt_lsa(struct ospf_area *oa)
   lsa.options = oa->options;
 #endif
   
-  lsa.id = rid;
-  lsa.rt = rid;
+  lsa.id = po->router_id;
+  lsa.rt = po->router_id;
   lsa.sn = oa->rt ? (oa->rt->lsa.sn + 1) : LSA_INITSEQNO;
   u32 dom = oa->areaid;
 
@@ -473,6 +472,7 @@ static void *
 originate_net_lsa_body(struct ospf_iface *ifa, u16 *length,
                       struct proto_ospf *po)
 {
+  u32 rid = proto_get_router_id(po->proto.cf);
   u16 i = 1;
   struct ospf_neighbor *n;
   struct ospf_lsa_net *net;
@@ -491,7 +491,7 @@ originate_net_lsa_body(struct ospf_iface *ifa, u16 *length,
   u32 options = 0;
 #endif
 
-  net->routers[0] = po->proto.cf->global->router_id;
+  net->routers[0] = po->router_id;
 
   WALK_LIST(n, ifa->neigh_list)
   {
@@ -532,10 +532,10 @@ void
 originate_net_lsa(struct ospf_iface *ifa)
 {
   struct proto_ospf *po = ifa->oa->po;
+  struct proto *p = &po->proto;
   struct ospf_lsa_header lsa;
-  u32 rid = po->proto.cf->global->router_id;
   u32 dom = ifa->oa->areaid;
-  struct proto *p = &po->proto;
+  
   void *body;
 
   OSPF_TRACE(D_EVENTS, "Originating network-LSA for iface %s",
@@ -551,7 +551,7 @@ originate_net_lsa(struct ospf_iface *ifa)
   lsa.id = ifa->iface->index;
 #endif
 
-  lsa.rt = rid;
+  lsa.rt = po->router_id;
   lsa.sn = ifa->net_lsa ? (ifa->net_lsa->lsa.sn + 1) : LSA_INITSEQNO;
 
   body = originate_net_lsa_body(ifa, &lsa.length, po);
@@ -707,7 +707,6 @@ originate_sum_net_lsa(struct ospf_area *oa, struct fib_node *fn, int metric)
   struct proto_ospf *po = oa->po;
   struct proto *p = &po->proto;
   struct top_hash_entry *en;
-  u32 rid = po->proto.cf->global->router_id;
   u32 dom = oa->areaid;
   struct ospf_lsa_header lsa;
   void *body;
@@ -722,7 +721,7 @@ originate_sum_net_lsa(struct ospf_area *oa, struct fib_node *fn, int metric)
 #endif
   lsa.type = LSA_T_SUM_NET;
   lsa.id = fibnode_to_lsaid(po, fn);
-  lsa.rt = rid;
+  lsa.rt = po->router_id;
   lsa.sn = LSA_INITSEQNO;
 
   if ((en = ospf_hash_find_header(po->gr, dom, &lsa)) != NULL)
@@ -749,7 +748,6 @@ originate_sum_rt_lsa(struct ospf_area *oa, struct fib_node *fn, int metric, u32
   struct proto_ospf *po = oa->po;
   struct proto *p = &po->proto;
   struct top_hash_entry *en;
-  u32 rid = po->proto.cf->global->router_id;
   u32 dom = oa->areaid;  
   struct ospf_lsa_header lsa;
   void *body;
@@ -764,7 +762,7 @@ originate_sum_rt_lsa(struct ospf_area *oa, struct fib_node *fn, int metric, u32
   lsa.type = LSA_T_SUM_RT;
   /* In OSPFv3, LSA ID is meaningless, but we still use Router ID of ASBR */
   lsa.id = ipa_to_rid(fn->prefix);
-  lsa.rt = rid;
+  lsa.rt = po->router_id;
   lsa.sn = LSA_INITSEQNO;
 
   if ((en = ospf_hash_find_header(po->gr, dom, &lsa)) != NULL)
@@ -793,10 +791,9 @@ flush_sum_lsa(struct ospf_area *oa, struct fib_node *fn, int type)
   struct proto_ospf *po = oa->po;
   struct proto *p = &po->proto;
   struct top_hash_entry *en;
-  u32 rid = po->proto.cf->global->router_id;
   struct ospf_lsa_header lsa;
 
-  lsa.rt = rid;
+  lsa.rt = po->router_id;
   if (type == ORT_NET)
     {
       lsa.id = fibnode_to_lsaid(po, fn);
@@ -971,7 +968,6 @@ originate_ext_lsa(net * n, rte * e, struct proto_ospf *po,
   struct proto *p = &po->proto;
   struct fib_node *fn = &n->n;
   struct ospf_lsa_header lsa;
-  u32 rid = po->proto.cf->global->router_id;
   struct top_hash_entry *en = NULL;
   void *body;
   struct ospf_area *oa;
@@ -985,7 +981,7 @@ originate_ext_lsa(net * n, rte * e, struct proto_ospf *po,
 #endif
   lsa.type = LSA_T_EXT;
   lsa.id = fibnode_to_lsaid(po, fn);
-  lsa.rt = rid;
+  lsa.rt = po->router_id;
   lsa.sn = LSA_INITSEQNO;
 
   if ((en = ospf_hash_find_header(po->gr, 0, &lsa)) != NULL)
@@ -1021,7 +1017,6 @@ flush_ext_lsa(net *n, struct proto_ospf *po)
 {
   struct proto *p = &po->proto;
   struct fib_node *fn = &n->n;
-  u32 rid = po->proto.cf->global->router_id;
   struct ospf_area *oa;
   struct top_hash_entry *en;
 
@@ -1030,7 +1025,7 @@ flush_ext_lsa(net *n, struct proto_ospf *po)
 
   u32 lsaid = fibnode_to_lsaid(po, fn);
 
-  if (en = ospf_hash_find(po->gr, 0, lsaid, rid, LSA_T_EXT))
+  if (en = ospf_hash_find(po->gr, 0, lsaid, po->router_id, LSA_T_EXT))
     {
       if (check_ext_lsaid_collision(fn, en))
        {
@@ -1085,7 +1080,6 @@ originate_link_lsa(struct ospf_iface *ifa)
   struct ospf_lsa_header lsa;
   struct proto_ospf *po = ifa->oa->po;
   struct proto *p = &po->proto;
-  u32 rid = po->proto.cf->global->router_id;
   void *body;
 
   /* FIXME check for vlink and skip that? */
@@ -1094,7 +1088,7 @@ originate_link_lsa(struct ospf_iface *ifa)
   lsa.age = 0;
   lsa.type = LSA_T_LINK;
   lsa.id = ifa->iface->index;
-  lsa.rt = rid;
+  lsa.rt = po->router_id;
   lsa.sn = ifa->link_lsa ? (ifa->link_lsa->lsa.sn + 1) : LSA_INITSEQNO;
   u32 dom = ifa->iface->index;
 
@@ -1127,7 +1121,6 @@ originate_prefix_rt_lsa_body(struct ospf_area *oa, u16 *length)
   struct proto_ospf *po = oa->po;
   struct ospf_iface *ifa;
   struct ospf_lsa_prefix *lp;
-  u32 rid = po->proto.cf->global->router_id;
   int net_lsa;
   int i = 0;
   u8 flags;
@@ -1136,7 +1129,7 @@ originate_prefix_rt_lsa_body(struct ospf_area *oa, u16 *length)
   lp = lsab_allocz(po, sizeof(struct ospf_lsa_prefix));
   lp->ref_type = LSA_T_RT;
   lp->ref_id = 0;
-  lp->ref_rt = rid;
+  lp->ref_rt = po->router_id;
   lp = NULL; /* buffer might be reallocated later */
 
   WALK_LIST(ifa, po->iface_list)
@@ -1190,7 +1183,6 @@ originate_prefix_rt_lsa(struct ospf_area *oa)
 {
   struct proto_ospf *po = oa->po;
   struct proto *p = &po->proto;  
-  u32 rid = po->proto.cf->global->router_id;
   struct ospf_lsa_header lsa;
   void *body;
 
@@ -1199,7 +1191,7 @@ originate_prefix_rt_lsa(struct ospf_area *oa)
   lsa.age = 0;
   lsa.type = LSA_T_PREFIX;
   lsa.id = 0;
-  lsa.rt = rid;
+  lsa.rt = po->router_id;
   lsa.sn = oa->pxr_lsa ? (oa->pxr_lsa->lsa.sn + 1) : LSA_INITSEQNO;
   u32 dom = oa->areaid;
 
@@ -1289,14 +1281,13 @@ originate_prefix_net_lsa_body(struct ospf_iface *ifa, u16 *length)
   struct ospf_lsa_prefix *lp;
   struct ospf_neighbor *n;
   struct top_hash_entry *en;
-  u32 rid = po->proto.cf->global->router_id;
   int pxc, offset;
 
   ASSERT(po->lsab_used == 0);
   lp = lsab_allocz(po, sizeof(struct ospf_lsa_prefix));
   lp->ref_type = LSA_T_NET;
   lp->ref_id = ifa->net_lsa->lsa.id;
-  lp->ref_rt = rid;
+  lp->ref_rt = po->router_id;
   lp = NULL; /* buffer might be reallocated later */
 
   pxc = 0;
@@ -1322,7 +1313,6 @@ originate_prefix_net_lsa(struct ospf_iface *ifa)
 {
   struct proto_ospf *po = ifa->oa->po;
   struct proto *p = &po->proto;
-  u32 rid = po->proto.cf->global->router_id;
   struct ospf_lsa_header lsa;
   void *body;
 
@@ -1332,7 +1322,7 @@ originate_prefix_net_lsa(struct ospf_iface *ifa)
   lsa.age = 0;
   lsa.type = LSA_T_PREFIX;
   lsa.id = ifa->iface->index;
-  lsa.rt = rid;
+  lsa.rt = po->router_id;
   lsa.sn = ifa->pxn_lsa ? (ifa->pxn_lsa->lsa.sn + 1) : LSA_INITSEQNO;
   u32 dom = ifa->oa->areaid;