From 8a70a13e7e79afa6818b10cf64d4f1ae4cf89e4b Mon Sep 17 00:00:00 2001 From: Ondrej Zajicek Date: Fri, 11 Dec 2009 01:20:53 +0100 Subject: Implements protocol-specific Router ID for OSPF. And fixes one minor bug. --- proto/ospf/dbdes.c | 8 ++++---- proto/ospf/hello.c | 23 ++++++++++++----------- proto/ospf/lsalib.c | 3 +-- proto/ospf/lsupd.c | 2 +- proto/ospf/neighbor.c | 7 +++---- proto/ospf/ospf.h | 1 + proto/ospf/packet.c | 7 ++++--- proto/ospf/rt.c | 7 +++---- proto/ospf/topology.c | 44 +++++++++++++++++--------------------------- 9 files changed, 46 insertions(+), 56 deletions(-) (limited to 'proto/ospf') diff --git a/proto/ospf/dbdes.c b/proto/ospf/dbdes.c index 2cb2dd8d..a249d75f 100644 --- a/proto/ospf/dbdes.c +++ b/proto/ospf/dbdes.c @@ -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; diff --git a/proto/ospf/hello.c b/proto/ospf/hello.c index 855b0700..738748d8 100644 --- a/proto/ospf/hello.c +++ b/proto/ospf/hello.c @@ -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); } diff --git a/proto/ospf/lsalib.c b/proto/ospf/lsalib.c index 7ee3aa4b..deb31136 100644 --- a/proto/ospf/lsalib.c +++ b/proto/ospf/lsalib.c @@ -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); diff --git a/proto/ospf/lsupd.c b/proto/ospf/lsupd.c index a0133855..a49fded7 100644 --- a/proto/ospf/lsupd.c +++ b/proto/ospf/lsupd.c @@ -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"); diff --git a/proto/ospf/neighbor.c b/proto/ospf/neighbor.c index aa7bc2fc..ba8d7b98 100644 --- a/proto/ospf/neighbor.c +++ b/proto/ospf/neighbor.c @@ -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; diff --git a/proto/ospf/ospf.h b/proto/ospf/ospf.h index 5a11418f..0930a065 100644 --- a/proto/ospf/ospf.h +++ b/proto/ospf/ospf.h @@ -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 diff --git a/proto/ospf/packet.c b/proto/ospf/packet.c index 94ec0109..1a02c00e 100644 --- a/proto/ospf/packet.c +++ b/proto/ospf/packet.c @@ -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; diff --git a/proto/ospf/rt.c b/proto/ospf/rt.c index dde6dcd5..60e48cf8 100644 --- a/proto/ospf/rt.c +++ b/proto/ospf/rt.c @@ -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", diff --git a/proto/ospf/topology.c b/proto/ospf/topology.c index 5b6d631a..231db134 100644 --- a/proto/ospf/topology.c +++ b/proto/ospf/topology.c @@ -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; -- cgit v1.2.3