summaryrefslogtreecommitdiff
path: root/proto/ospf
diff options
context:
space:
mode:
Diffstat (limited to 'proto/ospf')
-rw-r--r--proto/ospf/dbdes.c6
-rw-r--r--proto/ospf/hello.c6
-rw-r--r--proto/ospf/iface.c10
-rw-r--r--proto/ospf/lsack.c2
-rw-r--r--proto/ospf/lsalib.c414
-rw-r--r--proto/ospf/lsalib.h9
-rw-r--r--proto/ospf/lsreq.c3
-rw-r--r--proto/ospf/neighbor.c657
-rw-r--r--proto/ospf/ospf.c710
-rw-r--r--proto/ospf/ospf.h264
-rw-r--r--proto/ospf/packet.c234
-rw-r--r--proto/ospf/packet.h10
-rw-r--r--proto/ospf/rt.c795
-rw-r--r--proto/ospf/rt.h12
14 files changed, 1640 insertions, 1492 deletions
diff --git a/proto/ospf/dbdes.c b/proto/ospf/dbdes.c
index 5b455448..3d8ec50a 100644
--- a/proto/ospf/dbdes.c
+++ b/proto/ospf/dbdes.c
@@ -117,9 +117,9 @@ ospf_dbdes_send(struct ospf_neighbor *n)
case NEIGHBOR_LOADING:
case NEIGHBOR_FULL:
- length = ntohs(((struct ospf_packet *)n->ldbdes)->length);
+ length = ntohs(((struct ospf_packet *) n->ldbdes)->length);
- if(!length)
+ if (!length)
{
OSPF_TRACE(D_PACKETS, "No packet in my buffer for repeating");
ospf_neigh_sm(n, INM_KILLNBR);
@@ -127,7 +127,7 @@ ospf_dbdes_send(struct ospf_neighbor *n)
}
memcpy(ifa->ip_sk->tbuf, n->ldbdes, length);
- /* Copy last sent packet again */
+ /* Copy last sent packet again */
sk_send_to(ifa->ip_sk, length, n->ip, OSPF_PROTO);
OSPF_TRACE(D_PACKETS, "DB_DES (M) sent to %I via %s.", n->ip,
diff --git a/proto/ospf/hello.c b/proto/ospf/hello.c
index 18104d49..6e1fa92a 100644
--- a/proto/ospf/hello.c
+++ b/proto/ospf/hello.c
@@ -36,13 +36,15 @@ ospf_hello_receive(struct ospf_hello_packet *ps,
if (ntohs(ps->helloint) != ifa->helloint)
{
- log(L_WARN "%s%I%shello interval mismatch (%d).", beg, faddr, rec, ntohs(ps->helloint));
+ log(L_WARN "%s%I%shello interval mismatch (%d).", beg, faddr, rec,
+ ntohs(ps->helloint));
return;
}
if (ntohl(ps->deadint) != ifa->helloint * ifa->deadc)
{
- log(L_ERR "%s%I%sdead interval mismatch (%d).", beg, faddr, rec, ntohl(ps->deadint));
+ log(L_ERR "%s%I%sdead interval mismatch (%d).", beg, faddr, rec,
+ ntohl(ps->deadint));
return;
}
diff --git a/proto/ospf/iface.c b/proto/ospf/iface.c
index b2052646..71b907ac 100644
--- a/proto/ospf/iface.c
+++ b/proto/ospf/iface.c
@@ -150,8 +150,7 @@ ospf_iface_sm(struct ospf_iface *ifa, int event)
{
struct ospf_area *oa = ifa->oa;
- DBG("SM on iface %s. Event is \"%s\".",
- ifa->iface->name, ospf_ism[event]);
+ DBG("SM on iface %s. Event is \"%s\".", ifa->iface->name, ospf_ism[event]);
switch (event)
{
@@ -248,7 +247,7 @@ ospf_open_mc_socket(struct ospf_iface *ifa)
}
static sock *
-ospf_open_ip_socket(struct ospf_iface * ifa)
+ospf_open_ip_socket(struct ospf_iface *ifa)
{
sock *ipsk;
struct proto *p;
@@ -278,7 +277,7 @@ ospf_open_ip_socket(struct ospf_iface * ifa)
}
u8
-ospf_iface_clasify(struct iface *ifa)
+ospf_iface_clasify(struct iface * ifa)
{
if ((ifa->flags & (IF_MULTIACCESS | IF_MULTICAST)) ==
(IF_MULTIACCESS | IF_MULTICAST))
@@ -386,8 +385,7 @@ ospf_iface_notify(struct proto *p, unsigned flags, struct iface *iface)
ifa->options = 2; /* FIXME what options? */
if (ip->type == OSPF_IT_UNDEF)
- ifa->type =
- ospf_iface_clasify(ifa->iface);
+ ifa->type = ospf_iface_clasify(ifa->iface);
else
ifa->type = ip->type;
diff --git a/proto/ospf/lsack.c b/proto/ospf/lsack.c
index 71306f15..3a4e9652 100644
--- a/proto/ospf/lsack.c
+++ b/proto/ospf/lsack.c
@@ -161,7 +161,7 @@ ospf_lsack_receive(struct ospf_lsack_packet *ps,
{
ntohlsah(plsa + i, &lsa);
if ((en = ospf_hash_find_header(n->lsrth, &lsa)) == NULL)
- continue; /* pg 155 */
+ continue; /* pg 155 */
if (lsa_comp(&lsa, &en->lsa) != CMP_SAME) /* pg 156 */
{
diff --git a/proto/ospf/lsalib.c b/proto/ospf/lsalib.c
index 394301d6..d78e30af 100644
--- a/proto/ospf/lsalib.c
+++ b/proto/ospf/lsalib.c
@@ -11,13 +11,15 @@
void
flush_lsa(struct top_hash_entry *en, struct ospf_area *oa)
{
- struct proto *p=&oa->po->proto;
- OSPF_TRACE(D_EVENTS, "Going to remove node Type: %u, Id: %I, Rt: %I, Age: %u",
- en->lsa.type, en->lsa.id, en->lsa.rt, en->lsa.age);
+ struct proto *p = &oa->po->proto;
+ OSPF_TRACE(D_EVENTS,
+ "Going to remove node Type: %u, Id: %I, Rt: %I, Age: %u",
+ en->lsa.type, en->lsa.id, en->lsa.rt, en->lsa.age);
s_rem_node(SNODE en);
- if(en->lsa_body!=NULL) mb_free(en->lsa_body);
- en->lsa_body=NULL;
- ospf_hash_delete(oa->gr,en);
+ if (en->lsa_body != NULL)
+ mb_free(en->lsa_body);
+ en->lsa_body = NULL;
+ ospf_hash_delete(oa->gr, en);
}
/**
@@ -38,49 +40,52 @@ flush_lsa(struct top_hash_entry *en, struct ospf_area *oa)
void
ospf_age(struct ospf_area *oa)
{
- struct proto *p=&oa->po->proto;
- struct proto_ospf *po=(struct proto_ospf *)p;
- struct top_hash_entry *en,*nxt;
- int flush=can_flush_lsa(oa);
+ struct proto *p = &oa->po->proto;
+ struct proto_ospf *po = (struct proto_ospf *) p;
+ struct top_hash_entry *en, *nxt;
+ int flush = can_flush_lsa(oa);
OSPF_TRACE(D_EVENTS, "Running ospf_age");
- WALK_SLIST_DELSAFE(en,nxt,oa->lsal)
+ WALK_SLIST_DELSAFE(en, nxt, oa->lsal)
{
- if(oa->calcrt)
+ if (oa->calcrt)
{
- en->color=OUTSPF;
- en->dist=LSINFINITY;
- en->nhi=NULL;
- en->nh=ipa_from_u32(0);
+ en->color = OUTSPF;
+ en->dist = LSINFINITY;
+ en->nhi = NULL;
+ en->nh = ipa_from_u32(0);
DBG("Infinitying Type: %u, Id: %I, Rt: %I\n", en->lsa.type, en->lsa.id,
- en->lsa.rt);
+ en->lsa.rt);
}
- if(en->lsa.age==LSA_MAXAGE)
+ if (en->lsa.age == LSA_MAXAGE)
{
- if(flush) flush_lsa(en,oa);
+ if (flush)
+ flush_lsa(en, oa);
continue;
}
- if((en->lsa.rt==p->cf->global->router_id)&&(en->lsa.age>=LSREFRESHTIME))
+ if ((en->lsa.rt == p->cf->global->router_id) &&(en->lsa.age >=
+ LSREFRESHTIME))
{
- OSPF_TRACE(D_EVENTS, "Refreshing my LSA: Type: %u, Id: %I, Rt: %I",
- en->lsa.type, en->lsa.id, en->lsa.rt);
- en->lsa.sn++;
- en->lsa.age=0;
- en->inst_t=now;
- en->ini_age=0;
- lsasum_calculate(&en->lsa,en->lsa_body,po);
- ospf_lsupd_flood(NULL,NULL,&en->lsa,NULL,oa,1);
- continue;
+ OSPF_TRACE(D_EVENTS, "Refreshing my LSA: Type: %u, Id: %I, Rt: %I",
+ en->lsa.type, en->lsa.id, en->lsa.rt);
+ en->lsa.sn++;
+ en->lsa.age = 0;
+ en->inst_t = now;
+ en->ini_age = 0;
+ lsasum_calculate(&en->lsa, en->lsa_body, po);
+ ospf_lsupd_flood(NULL, NULL, &en->lsa, NULL, oa, 1);
+ continue;
}
- if((en->lsa.age=(en->ini_age+(now-en->inst_t)))>=LSA_MAXAGE)
+ if ((en->lsa.age = (en->ini_age + (now - en->inst_t))) >= LSA_MAXAGE)
{
- if(flush)
+ if (flush)
{
- flush_lsa(en,oa);
- schedule_rtcalc(oa);
+ flush_lsa(en, oa);
+ schedule_rtcalc(oa);
}
- else en->lsa.age=LSA_MAXAGE;
+ else
+ en->lsa.age = LSA_MAXAGE;
}
}
}
@@ -88,124 +93,125 @@ ospf_age(struct ospf_area *oa)
void
htonlsah(struct ospf_lsa_header *h, struct ospf_lsa_header *n)
{
- n->age=htons(h->age);
- n->options=h->options;
- n->type=h->type;
- n->id=htonl(h->id);
- n->rt=htonl(h->rt);
- n->sn=htonl(h->sn);
- n->checksum=htons(h->checksum);
- n->length=htons(h->length);
+ n->age = htons(h->age);
+ n->options = h->options;
+ n->type = h->type;
+ n->id = htonl(h->id);
+ n->rt = htonl(h->rt);
+ n->sn = htonl(h->sn);
+ n->checksum = htons(h->checksum);
+ n->length = htons(h->length);
};
void
ntohlsah(struct ospf_lsa_header *n, struct ospf_lsa_header *h)
{
- h->age=ntohs(n->age);
- h->options=n->options;
- h->type=n->type;
- h->id=ntohl(n->id);
- h->rt=ntohl(n->rt);
- h->sn=ntohl(n->sn);
- h->checksum=ntohs(n->checksum);
- h->length=ntohs(n->length);
+ h->age = ntohs(n->age);
+ h->options = n->options;
+ h->type = n->type;
+ h->id = ntohl(n->id);
+ h->rt = ntohl(n->rt);
+ h->sn = ntohl(n->sn);
+ h->checksum = ntohs(n->checksum);
+ h->length = ntohs(n->length);
};
void
htonlsab(void *h, void *n, u8 type, u16 len)
{
unsigned int i;
- switch(type)
+ switch (type)
{
- case LSA_T_RT:
+ case LSA_T_RT:
{
struct ospf_lsa_rt *hrt, *nrt;
- struct ospf_lsa_rt_link *hrtl,*nrtl;
+ struct ospf_lsa_rt_link *hrtl, *nrtl;
u16 links;
- nrt=n;
- hrt=h;
- links=hrt->links;
+ nrt = n;
+ hrt = h;
+ links = hrt->links;
- nrt->veb.byte=hrt->veb.byte;
- nrt->padding=0;
- nrt->links=htons(hrt->links);
- nrtl=(struct ospf_lsa_rt_link *)(nrt+1);
- hrtl=(struct ospf_lsa_rt_link *)(hrt+1);
- for(i=0;i<links;i++)
+ nrt->veb.byte = hrt->veb.byte;
+ nrt->padding = 0;
+ nrt->links = htons(hrt->links);
+ nrtl = (struct ospf_lsa_rt_link *) (nrt + 1);
+ hrtl = (struct ospf_lsa_rt_link *) (hrt + 1);
+ for (i = 0; i < links; i++)
{
- (nrtl+i)->id=htonl((hrtl+i)->id);
- (nrtl+i)->data=htonl((hrtl+i)->data);
- (nrtl+i)->type=(hrtl+i)->type;
- (nrtl+i)->notos=(hrtl+i)->notos;
- (nrtl+i)->metric=htons((hrtl+i)->metric);
+ (nrtl + i)->id = htonl((hrtl + i)->id);
+ (nrtl + i)->data = htonl((hrtl + i)->data);
+ (nrtl + i)->type = (hrtl + i)->type;
+ (nrtl + i)->notos = (hrtl + i)->notos;
+ (nrtl + i)->metric = htons((hrtl + i)->metric);
}
break;
}
- case LSA_T_NET:
+ case LSA_T_NET:
{
- u32 *hid,*nid;
+ u32 *hid, *nid;
- nid=n;
- hid=h;
+ nid = n;
+ hid = h;
- for(i=0;i<(len/sizeof(u32));i++)
+ for (i = 0; i < (len / sizeof(u32)); i++)
{
- *(nid+i)=htonl(*(hid+i));
+ *(nid + i) = htonl(*(hid + i));
}
break;
}
- case LSA_T_SUM_NET:
- case LSA_T_SUM_RT:
+ case LSA_T_SUM_NET:
+ case LSA_T_SUM_RT:
{
struct ospf_lsa_summ *hs, *ns;
struct ospf_lsa_summ_net *hn, *nn;
- hs=h;
- ns=n;
+ hs = h;
+ ns = n;
- ns->netmask=hs->netmask;
+ ns->netmask = hs->netmask;
ipa_hton(ns->netmask);
- hn=(struct ospf_lsa_summ_net *)(hs+1);
- nn=(struct ospf_lsa_summ_net *)(ns+1);
+ hn = (struct ospf_lsa_summ_net *) (hs + 1);
+ nn = (struct ospf_lsa_summ_net *) (ns + 1);
- for(i=0;i<((len-sizeof(struct ospf_lsa_summ))/
- sizeof(struct ospf_lsa_summ_net));i++)
+ for (i = 0; i < ((len - sizeof(struct ospf_lsa_summ)) /
+ sizeof(struct ospf_lsa_summ_net)); i++)
{
- (nn+i)->tos=(hn+i)->tos;
- (nn+i)->metric=htons((hn+i)->metric);
- (nn+i)->padding=0;
+ (nn + i)->tos = (hn + i)->tos;
+ (nn + i)->metric = htons((hn + i)->metric);
+ (nn + i)->padding = 0;
}
break;
}
- case LSA_T_EXT:
+ case LSA_T_EXT:
{
struct ospf_lsa_ext *he, *ne;
struct ospf_lsa_ext_tos *ht, *nt;
- he=h;
- ne=n;
+ he = h;
+ ne = n;
- ne->netmask=he->netmask;
+ ne->netmask = he->netmask;
ipa_hton(ne->netmask);
- ht=(struct ospf_lsa_ext_tos *)(he+1);
- nt=(struct ospf_lsa_ext_tos *)(ne+1);
+ ht = (struct ospf_lsa_ext_tos *) (he + 1);
+ nt = (struct ospf_lsa_ext_tos *) (ne + 1);
- for(i=0;i<((len-sizeof(struct ospf_lsa_ext))/
- sizeof(struct ospf_lsa_ext_tos));i++)
+ for (i = 0; i < ((len - sizeof(struct ospf_lsa_ext)) /
+ sizeof(struct ospf_lsa_ext_tos)); i++)
{
- (nt+i)->etos=(ht+i)->etos;
- (nt+i)->padding=0;
- (nt+i)->metric=htons((ht+i)->metric);
- (nt+i)->fwaddr=(ht+i)->fwaddr;
- ipa_hton((nt+i)->fwaddr);
- (nt+i)->tag=htonl((ht+i)->tag);
+ (nt + i)->etos = (ht + i)->etos;
+ (nt + i)->padding = 0;
+ (nt + i)->metric = htons((ht + i)->metric);
+ (nt + i)->fwaddr = (ht + i)->fwaddr;
+ ipa_hton((nt + i)->fwaddr);
+ (nt + i)->tag = htonl((ht + i)->tag);
}
break;
}
- default: bug("(hton): Unknown LSA");
+ default:
+ bug("(hton): Unknown LSA");
}
};
@@ -213,96 +219,97 @@ void
ntohlsab(void *n, void *h, u8 type, u16 len)
{
unsigned int i;
- switch(type)
+ switch (type)
{
- case LSA_T_RT:
+ case LSA_T_RT:
{
struct ospf_lsa_rt *hrt, *nrt;
- struct ospf_lsa_rt_link *hrtl,*nrtl;
+ struct ospf_lsa_rt_link *hrtl, *nrtl;
u16 links;
- nrt=n;
- hrt=h;
+ nrt = n;
+ hrt = h;
- hrt->veb.byte=nrt->veb.byte;
- hrt->padding=0;
- links=hrt->links=ntohs(nrt->links);
- nrtl=(struct ospf_lsa_rt_link *)(nrt+1);
- hrtl=(struct ospf_lsa_rt_link *)(hrt+1);
- for(i=0;i<links;i++)
+ hrt->veb.byte = nrt->veb.byte;
+ hrt->padding = 0;
+ links = hrt->links = ntohs(nrt->links);
+ nrtl = (struct ospf_lsa_rt_link *) (nrt + 1);
+ hrtl = (struct ospf_lsa_rt_link *) (hrt + 1);
+ for (i = 0; i < links; i++)
{
- (hrtl+i)->id=ntohl((nrtl+i)->id);
- (hrtl+i)->data=ntohl((nrtl+i)->data);
- (hrtl+i)->type=(nrtl+i)->type;
- (hrtl+i)->notos=(nrtl+i)->notos;
- (hrtl+i)->metric=ntohs((nrtl+i)->metric);
+ (hrtl + i)->id = ntohl((nrtl + i)->id);
+ (hrtl + i)->data = ntohl((nrtl + i)->data);
+ (hrtl + i)->type = (nrtl + i)->type;
+ (hrtl + i)->notos = (nrtl + i)->notos;
+ (hrtl + i)->metric = ntohs((nrtl + i)->metric);
}
break;
}
- case LSA_T_NET:
+ case LSA_T_NET:
{
- u32 *hid,*nid;
+ u32 *hid, *nid;
- hid=h;
- nid=n;
+ hid = h;
+ nid = n;
- for(i=0;i<(len/sizeof(u32));i++)
+ for (i = 0; i < (len / sizeof(u32)); i++)
{
- *(hid+i)=ntohl(*(nid+i));
+ *(hid + i) = ntohl(*(nid + i));
}
break;
}
- case LSA_T_SUM_NET:
- case LSA_T_SUM_RT:
+ case LSA_T_SUM_NET:
+ case LSA_T_SUM_RT:
{
struct ospf_lsa_summ *hs, *ns;
struct ospf_lsa_summ_net *hn, *nn;
- hs=h;
- ns=n;
+ hs = h;
+ ns = n;
- hs->netmask=ns->netmask;
+ hs->netmask = ns->netmask;
ipa_ntoh(hs->netmask);
- hn=(struct ospf_lsa_summ_net *)(hs+1);
- nn=(struct ospf_lsa_summ_net *)(ns+1);
+ hn = (struct ospf_lsa_summ_net *) (hs + 1);
+ nn = (struct ospf_lsa_summ_net *) (ns + 1);
- for(i=0;i<((len-sizeof(struct ospf_lsa_summ))/
- sizeof(struct ospf_lsa_summ_net));i++)
+ for (i = 0; i < ((len - sizeof(struct ospf_lsa_summ)) /
+ sizeof(struct ospf_lsa_summ_net)); i++)
{
- (hn+i)->tos=(nn+i)->tos;
- (hn+i)->metric=ntohs((nn+i)->metric);
- (hn+i)->padding=0;
+ (hn + i)->tos = (nn + i)->tos;
+ (hn + i)->metric = ntohs((nn + i)->metric);
+ (hn + i)->padding = 0;
}
break;
}
- case LSA_T_EXT:
+ case LSA_T_EXT:
{
struct ospf_lsa_ext *he, *ne;
struct ospf_lsa_ext_tos *ht, *nt;
- he=h;
- ne=n;
+ he = h;
+ ne = n;
- he->netmask=ne->netmask;
+ he->netmask = ne->netmask;
ipa_ntoh(he->netmask);
- ht=(struct ospf_lsa_ext_tos *)(he+1);
- nt=(struct ospf_lsa_ext_tos *)(ne+1);
+ ht = (struct ospf_lsa_ext_tos *) (he + 1);
+ nt = (struct ospf_lsa_ext_tos *) (ne + 1);
- for(i=0;i<((len-sizeof(struct ospf_lsa_ext))/
- sizeof(struct ospf_lsa_ext_tos));i++)
+ for (i = 0; i < ((len - sizeof(struct ospf_lsa_ext)) /
+ sizeof(struct ospf_lsa_ext_tos)); i++)
{
- (ht+i)->etos=(nt+i)->etos;
- (ht+i)->padding=0;
- (ht+i)->metric=ntohs((nt+i)->metric);
- (ht+i)->fwaddr=(nt+i)->fwaddr;
- ipa_ntoh((ht+i)->fwaddr);
- (ht+i)->tag=ntohl((nt+i)->tag);
+ (ht + i)->etos = (nt + i)->etos;
+ (ht + i)->padding = 0;
+ (ht + i)->metric = ntohs((nt + i)->metric);
+ (ht + i)->fwaddr = (nt + i)->fwaddr;
+ ipa_ntoh((ht + i)->fwaddr);
+ (ht + i)->tag = ntohl((nt + i)->tag);
}
break;
}
- default: bug("(ntoh): Unknown LSA");
+ default:
+ bug("(ntoh): Unknown LSA");
}
};
@@ -314,19 +321,19 @@ ntohlsab(void *n, void *h, u8 type, u16 len)
/* FIXME This is VERY uneficient, I have huge endianity problems */
void
-lsasum_calculate(struct ospf_lsa_header *h,void *body,struct proto_ospf *po)
+lsasum_calculate(struct ospf_lsa_header *h, void *body, struct proto_ospf *po)
{
u16 length;
-
- length=h->length;
- htonlsah(h,h);
- htonlsab(body,body,h->type,length-sizeof(struct ospf_lsa_header));
+ length = h->length;
+
+ htonlsah(h, h);
+ htonlsab(body, body, h->type, length - sizeof(struct ospf_lsa_header));
- (void)lsasum_check(h,body,po);
-
- ntohlsah(h,h);
- ntohlsab(body,body,h->type,length-sizeof(struct ospf_lsa_header));
+ (void) lsasum_check(h, body, po);
+
+ ntohlsah(h, h);
+ ntohlsab(body, body, h->type, length - sizeof(struct ospf_lsa_header));
}
/*
@@ -334,7 +341,7 @@ lsasum_calculate(struct ospf_lsa_header *h,void *body,struct proto_ospf *po)
* It also returns value in big endian
*/
u16
-lsasum_check(struct ospf_lsa_header *h,void *body,struct proto_ospf *po)
+lsasum_check(struct ospf_lsa_header *h, void *body, struct proto_ospf *po)
{
u8 *sp, *ep, *p, *q, *b;
int c0 = 0, c1 = 0;
@@ -343,13 +350,14 @@ lsasum_check(struct ospf_lsa_header *h,void *body,struct proto_ospf *po)
b = body;
sp = (char *) &h->options;
- length = ntohs(h->length)-2;
+ length = ntohs(h->length) - 2;
h->checksum = 0;
for (ep = sp + length; sp < ep; sp = q)
- { /* Actually MODX is very large, do we need the for-cyclus? */
+ { /* Actually MODX is very large, do we need the for-cyclus? */
q = sp + MODX;
- if (q > ep) q = ep;
+ if (q > ep)
+ q = ep;
for (p = sp; p < q; p++)
{
/*
@@ -358,13 +366,13 @@ lsasum_check(struct ospf_lsa_header *h,void *body,struct proto_ospf *po)
* (probably checksum in update receiving) and I go on
* after header
*/
- if((b==NULL) || (p<(u8 *)(h+1)))
+ if ((b == NULL) || (p < (u8 *) (h + 1)))
{
- c0 += *p;
+ c0 += *p;
}
else
{
- c0 += *(b+(p-sp)-sizeof(struct ospf_lsa_header)+2);
+ c0 += *(b + (p - sp) - sizeof(struct ospf_lsa_header) + 2);
}
c1 += c0;
@@ -374,12 +382,14 @@ lsasum_check(struct ospf_lsa_header *h,void *body,struct proto_ospf *po)
}
x = ((length - LSA_CHECKSUM_OFFSET) * c0 - c1) % 255;
- if (x <= 0) x += 255;
+ if (x <= 0)
+ x += 255;
y = 510 - c0 - x;
- if (y > 255) y -= 255;
+ if (y > 255)
+ y -= 255;
- ((u8*)&h->checksum)[0] = x;
- ((u8*)&h->checksum)[1] = y;
+ ((u8 *) & h->checksum)[0] = x;
+ ((u8 *) & h->checksum)[1] = y;
return h->checksum;
}
@@ -387,22 +397,26 @@ int
lsa_comp(struct ospf_lsa_header *l1, struct ospf_lsa_header *l2)
/* Return codes from point of view of l1 */
{
- u32 sn1,sn2;
+ u32 sn1, sn2;
- sn1=l1->sn-LSA_INITSEQNO+1;
- sn2=l2->sn-LSA_INITSEQNO+1;
+ sn1 = l1->sn - LSA_INITSEQNO + 1;
+ sn2 = l2->sn - LSA_INITSEQNO + 1;
- if(sn1>sn2) return CMP_NEWER;
- if(sn1<sn2) return CMP_OLDER;
+ if (sn1 > sn2)
+ return CMP_NEWER;
+ if (sn1 < sn2)
+ return CMP_OLDER;
- if(l1->checksum!=l2->checksum)
- return l1->checksum<l2->checksum ? CMP_OLDER : CMP_NEWER;
+ if (l1->checksum != l2->checksum)
+ return l1->checksum < l2->checksum ? CMP_OLDER : CMP_NEWER;
- if((l1->age==LSA_MAXAGE)&&(l2->age!=LSA_MAXAGE)) return CMP_NEWER;
- if((l2->age==LSA_MAXAGE)&&(l1->age!=LSA_MAXAGE)) return CMP_OLDER;
+ if ((l1->age == LSA_MAXAGE) && (l2->age != LSA_MAXAGE))
+ return CMP_NEWER;
+ if ((l2->age == LSA_MAXAGE) && (l1->age != LSA_MAXAGE))
+ return CMP_OLDER;
- if(ABS(l1->age-l2->age)>LSA_MAXAGEDIFF)
- return l1->age<l2->age ? CMP_NEWER : CMP_OLDER;
+ if (ABS(l1->age - l2->age) > LSA_MAXAGEDIFF)
+ return l1->age < l2->age ? CMP_NEWER : CMP_OLDER;
return CMP_SAME;
}
@@ -421,27 +435,28 @@ struct top_hash_entry *
lsa_install_new(struct ospf_lsa_header *lsa, void *body, struct ospf_area *oa)
{
/* LSA can be temporarrily, but body must be mb_allocated. */
- int change=0;
+ int change = 0;
unsigned i;
struct top_hash_entry *en;
- if((en=ospf_hash_find_header(oa->gr,lsa))==NULL)
+ if ((en = ospf_hash_find_header(oa->gr, lsa)) == NULL)
{
- en=ospf_hash_get_header(oa->gr,lsa);
- change=1;
+ en = ospf_hash_get_header(oa->gr, lsa);
+ change = 1;
}
else
{
- if((en->lsa.length!=lsa->length)||(en->lsa.options!=lsa->options)||
- ((en->lsa.age==LSA_MAXAGE)||(lsa->age==LSA_MAXAGE))) change=1;
+ if ((en->lsa.length != lsa->length) || (en->lsa.options != lsa->options)
+ || ((en->lsa.age == LSA_MAXAGE) || (lsa->age == LSA_MAXAGE)))
+ change = 1;
else
{
- u8 *k=en->lsa_body,*l=body;
- for(i=0;i<(lsa->length-sizeof(struct ospf_lsa_header));i++)
+ u8 *k = en->lsa_body, *l = body;
+ for (i = 0; i < (lsa->length - sizeof(struct ospf_lsa_header)); i++)
{
- if(*(k+i)!=*(l+i))
+ if (*(k + i) != *(l + i))
{
- change=1;
+ change = 1;
break;
}
}
@@ -450,19 +465,20 @@ lsa_install_new(struct ospf_lsa_header *lsa, void *body, struct ospf_area *oa)
}
DBG("Inst lsa: Id: %I, Rt: %I, Type: %u, Age: %u, Sum: %u, Sn: 0x%x\n",
- lsa->id, lsa->rt, lsa->type, lsa->age, lsa->checksum, lsa->sn);
+ lsa->id, lsa->rt, lsa->type, lsa->age, lsa->checksum, lsa->sn);
s_add_tail(&oa->lsal, SNODE en);
- en->inst_t=now;
- if(en->lsa_body!=NULL) mb_free(en->lsa_body);
- en->lsa_body=body;
- memcpy(&en->lsa,lsa,sizeof(struct ospf_lsa_header));
- en->ini_age=en->lsa.age;
-
- if(change)
+ en->inst_t = now;
+ if (en->lsa_body != NULL)
+ mb_free(en->lsa_body);
+ en->lsa_body = body;
+ memcpy(&en->lsa, lsa, sizeof(struct ospf_lsa_header));
+ en->ini_age = en->lsa.age;
+
+ if (change)
{
schedule_rtcalc(oa);
}
-
+
return en;
}
diff --git a/proto/ospf/lsalib.h b/proto/ospf/lsalib.h
index 5722e8ef..cde30de8 100644
--- a/proto/ospf/lsalib.h
+++ b/proto/ospf/lsalib.h
@@ -15,14 +15,15 @@ void ntohlsah(struct ospf_lsa_header *n, struct ospf_lsa_header *h);
void htonlsab(void *h, void *n, u8 type, u16 len);
void ntohlsab(void *n, void *h, u8 type, u16 len);
void lsasum_calculate(struct ospf_lsa_header *header, void *body,
- struct proto_ospf *p);
-u16 lsasum_check(struct ospf_lsa_header *h,void *body,struct proto_ospf *po);
+ struct proto_ospf *p);
+u16 lsasum_check(struct ospf_lsa_header *h, void *body,
+ struct proto_ospf *po);
#define CMP_NEWER 1
#define CMP_SAME 0
#define CMP_OLDER -1
int lsa_comp(struct ospf_lsa_header *l1, struct ospf_lsa_header *l2);
-struct top_hash_entry *lsa_install_new(struct ospf_lsa_header *lsa, void *body,
- struct ospf_area *oa);
+struct top_hash_entry *lsa_install_new(struct ospf_lsa_header *lsa,
+ void *body, struct ospf_area *oa);
void ospf_age(struct ospf_area *oa);
void flush_lsa(struct top_hash_entry *en, struct ospf_area *oa);
diff --git a/proto/ospf/lsreq.c b/proto/ospf/lsreq.c
index c862d73f..046e1495 100644
--- a/proto/ospf/lsreq.c
+++ b/proto/ospf/lsreq.c
@@ -109,7 +109,8 @@ ospf_lsreq_receive(struct ospf_lsreq_packet *ps,
if (ospf_hash_find(n->ifa->oa->gr, llsh->lsh.id, llsh->lsh.rt,
llsh->lsh.type) == NULL)
{
- log(L_WARN "Received bad LS req from: %I looking: RT: %I, ID: %I, Type: %u",
+ log(L_WARN
+ "Received bad LS req from: %I looking: RT: %I, ID: %I, Type: %u",
n->ip, lsh->rt, lsh->id, lsh->type);
ospf_neigh_sm(n, INM_BADLSREQ);
rfree(upslab);
diff --git a/proto/ospf/neighbor.c b/proto/ospf/neighbor.c
index b32e4620..c3f4c321 100644
--- a/proto/ospf/neighbor.c
+++ b/proto/ospf/neighbor.c
@@ -8,29 +8,32 @@
#include "ospf.h"
-char *ospf_ns[]={" down",
- " attempt",
- " init",
- " 2way",
- " exstart",
- "exchange",
- " loading",
- " full"};
-
-const char *ospf_inm[]={ "hello received", "neighbor start", "2-way received",
+char *ospf_ns[] = { " down",
+ " attempt",
+ " init",
+ " 2way",
+ " exstart",
+ "exchange",
+ " loading",
+ " full"
+};
+
+const char *ospf_inm[] =
+ { "hello received", "neighbor start", "2-way received",
"negotiation done", "exstart done", "bad ls request", "load done",
"adjacency ok?", "sequence mismatch", "1-way received", "kill neighbor",
- "inactivity timer", "line down" };
+ "inactivity timer", "line down"
+};
-void neighbor_timer_hook(timer *timer);
-void rxmt_timer_hook(timer *timer);
-void ackd_timer_hook(timer *t);
+void neighbor_timer_hook(timer * timer);
+void rxmt_timer_hook(timer * timer);
+void ackd_timer_hook(timer * t);
struct ospf_neighbor *
ospf_neighbor_new(struct ospf_iface *ifa)
{
- struct proto *p = (struct proto *)(ifa->proto);
+ struct proto *p = (struct proto *) (ifa->proto);
struct pool *pool = rp_new(p->pool, "OSPF Neighbor");
struct ospf_neighbor *n = mb_allocz(pool, sizeof(struct ospf_neighbor));
@@ -38,8 +41,8 @@ ospf_neighbor_new(struct ospf_iface *ifa)
n->ifa = ifa;
add_tail(&ifa->neigh_list, NODE n);
n->adj = 0;
- n->ldbdes=mb_allocz(pool, ifa->iface->mtu);
- n->state=NEIGHBOR_DOWN;
+ n->ldbdes = mb_allocz(pool, ifa->iface->mtu);
+ n->state = NEIGHBOR_DOWN;
n->inactim = tm_new(pool);
n->inactim->data = n;
@@ -59,20 +62,20 @@ ospf_neighbor_new(struct ospf_iface *ifa)
n->lsrth = ospf_top_new(pool, n->ifa->proto);
s_init(&(n->lsrqi), &(n->lsrql));
s_init(&(n->lsrti), &(n->lsrtl));
- tm_start(n->rxmt_timer,n->ifa->rxmtint);
+ tm_start(n->rxmt_timer, n->ifa->rxmtint);
DBG("%s: Installing rxmt timer.\n", p->name);
n->ackd_timer = tm_new(pool);
n->ackd_timer->data = n;
n->ackd_timer->randomize = 0;
n->ackd_timer->hook = ackd_timer_hook;
- n->ackd_timer->recurrent = ifa->rxmtint/2;
+ n->ackd_timer->recurrent = ifa->rxmtint / 2;
init_list(&n->ackl[ACKL_DIRECT]);
init_list(&n->ackl[ACKL_DELAY]);
- tm_start(n->ackd_timer,n->ifa->rxmtint/2);
+ tm_start(n->ackd_timer, n->ifa->rxmtint / 2);
DBG("%s: Installing ackd timer.\n", p->name);
- return(n);
+ return (n);
}
/**
@@ -89,125 +92,133 @@ neigh_chstate(struct ospf_neighbor *n, u8 state)
{
u8 oldstate;
- oldstate=n->state;
+ oldstate = n->state;
- if(oldstate!=state)
+ if (oldstate != state)
{
- struct ospf_iface *ifa=n->ifa;
- struct proto_ospf *po=ifa->oa->po;
- struct proto *p=&po->proto;
+ struct ospf_iface *ifa = n->ifa;
+ struct proto_ospf *po = ifa->oa->po;
+ struct proto *p = &po->proto;
- n->state=state;
+ n->state = state;
- OSPF_TRACE( D_EVENTS, "Neighbor %I changes state from \"%s\" to \"%s\".",
- n->ip, ospf_ns[oldstate], ospf_ns[state]);
+ OSPF_TRACE(D_EVENTS, "Neighbor %I changes state from \"%s\" to \"%s\".",
+ n->ip, ospf_ns[oldstate], ospf_ns[state]);
- if((state==NEIGHBOR_2WAY) && (oldstate<NEIGHBOR_2WAY))
+ if ((state == NEIGHBOR_2WAY) && (oldstate < NEIGHBOR_2WAY))
ospf_iface_sm(ifa, ISM_NEICH);
- if((state<NEIGHBOR_2WAY) && (oldstate>=NEIGHBOR_2WAY))
+ if ((state < NEIGHBOR_2WAY) && (oldstate >= NEIGHBOR_2WAY))
ospf_iface_sm(ifa, ISM_NEICH);
- if(oldstate==NEIGHBOR_FULL) /* Decrease number of adjacencies */
+ if (oldstate == NEIGHBOR_FULL) /* Decrease number of adjacencies */
{
ifa->fadj--;
schedule_rt_lsa(ifa->oa);
schedule_net_lsa(ifa);
}
-
- if(state==NEIGHBOR_FULL) /* Increase number of adjacencies */
+
+ if (state == NEIGHBOR_FULL) /* Increase number of adjacencies */
{
ifa->fadj++;
schedule_rt_lsa(ifa->oa);
schedule_net_lsa(ifa);
}
- if(state==NEIGHBOR_EXSTART)
+ if (state == NEIGHBOR_EXSTART)
{
- if(n->adj==0) /* First time adjacency */
+ if (n->adj == 0) /* First time adjacency */
{
- n->dds=random_u32();
+ n->dds = random_u32();
}
n->dds++;
- n->myimms.byte=0;
- n->myimms.bit.ms=1;
- n->myimms.bit.m=1;
- n->myimms.bit.i=1;
+ n->myimms.byte = 0;
+ n->myimms.bit.ms = 1;
+ n->myimms.bit.m = 1;
+ n->myimms.bit.i = 1;
}
- if(state>NEIGHBOR_EXSTART) n->myimms.bit.i=0;
+ if (state > NEIGHBOR_EXSTART)
+ n->myimms.bit.i = 0;
}
}
struct ospf_neighbor *
electbdr(list nl)
{
- struct ospf_neighbor *neigh,*n1,*n2;
+ struct ospf_neighbor *neigh, *n1, *n2;
- n1=NULL;
- n2=NULL;
- WALK_LIST (neigh, nl) /* First try those decl. themselves */
+ n1 = NULL;
+ n2 = NULL;
+ WALK_LIST(neigh, nl) /* First try those decl. themselves */
{
- if(neigh->state>=NEIGHBOR_2WAY) /* Higher than 2WAY */
- if(neigh->priority>0) /* Eligible */
- if(ipa_compare(neigh->ip,neigh->dr)!=0) /* And not decl. itself DR */
+ if (neigh->state >= NEIGHBOR_2WAY) /* Higher than 2WAY */
+ if (neigh->priority > 0) /* Eligible */
+ if (ipa_compare(neigh->ip, neigh->dr) != 0) /* And not decl. itself DR */
{
- if(ipa_compare(neigh->ip,neigh->bdr)==0) /* Declaring BDR */
- {
- if(n1!=NULL)
- {
- if(neigh->priority>n1->priority) n1=neigh;
- else if(neigh->priority==n1->priority)
- if(neigh->rid>n1->rid) n1=neigh;
- }
+ if (ipa_compare(neigh->ip, neigh->bdr) == 0) /* Declaring BDR */
+ {
+ if (n1 != NULL)
+ {
+ if (neigh->priority > n1->priority)
+ n1 = neigh;
+ else if (neigh->priority == n1->priority)
+ if (neigh->rid > n1->rid)
+ n1 = neigh;
+ }
else
- {
- n1=neigh;
- }
- }
- else /* And NOT declaring BDR */
- {
- if(n2!=NULL)
- {
- if(neigh->priority>n2->priority) n2=neigh;
- else if(neigh->priority==n2->priority)
- if(neigh->rid>n2->rid) n2=neigh;
- }
+ {
+ n1 = neigh;
+ }
+ }
+ else /* And NOT declaring BDR */
+ {
+ if (n2 != NULL)
+ {
+ if (neigh->priority > n2->priority)
+ n2 = neigh;
+ else if (neigh->priority == n2->priority)
+ if (neigh->rid > n2->rid)
+ n2 = neigh;
+ }
else
- {
- n2=neigh;
- }
- }
- }
+ {
+ n2 = neigh;
+ }
+ }
+ }
}
- if(n1==NULL) n1=n2;
+ if (n1 == NULL)
+ n1 = n2;
- return(n1);
+ return (n1);
}
struct ospf_neighbor *
electdr(list nl)
{
- struct ospf_neighbor *neigh,*n;
+ struct ospf_neighbor *neigh, *n;
- n=NULL;
- WALK_LIST (neigh, nl) /* And now DR */
+ n = NULL;
+ WALK_LIST(neigh, nl) /* And now DR */
{
- if(neigh->state>=NEIGHBOR_2WAY) /* Higher than 2WAY */
- if(neigh->priority>0) /* Eligible */
- if(ipa_compare(neigh->ip,neigh->dr)==0) /* And declaring itself DR */
+ if (neigh->state >= NEIGHBOR_2WAY) /* Higher than 2WAY */
+ if (neigh->priority > 0) /* Eligible */
+ if (ipa_compare(neigh->ip, neigh->dr) == 0) /* And declaring itself DR */
{
- if(n!=NULL)
- {
- if(neigh->priority>n->priority) n=neigh;
- else if(neigh->priority==n->priority)
- if(neigh->rid>n->rid) n=neigh;
- }
+ if (n != NULL)
+ {
+ if (neigh->priority > n->priority)
+ n = neigh;
+ else if (neigh->priority == n->priority)
+ if (neigh->rid > n->rid)
+ n = neigh;
+ }
else
- {
- n=neigh;
- }
- }
+ {
+ n = neigh;
+ }
+ }
}
- return(n);
+ return (n);
}
static int
@@ -217,45 +228,47 @@ can_do_adj(struct ospf_neighbor *n)
struct proto *p;
int i;
- ifa=n->ifa;
- p=(struct proto *)(ifa->proto);
- i=0;
+ ifa = n->ifa;
+ p = (struct proto *) (ifa->proto);
+ i = 0;
- switch(ifa->type)
+ switch (ifa->type)
{
- case OSPF_IT_PTP:
- case OSPF_IT_VLINK:
- i=1;
+ case OSPF_IT_PTP:
+ case OSPF_IT_VLINK:
+ i = 1;
+ break;
+ case OSPF_IT_BCAST:
+ case OSPF_IT_NBMA:
+ switch (ifa->state)
+ {
+ case OSPF_IS_DOWN:
+ bug("%s: Iface %s in down state?", p->name, ifa->iface->name);
break;
- case OSPF_IT_BCAST:
- case OSPF_IT_NBMA:
- switch(ifa->state)
- {
- case OSPF_IS_DOWN:
- bug("%s: Iface %s in down state?", p->name, ifa->iface->name);
- break;
- case OSPF_IS_WAITING:
- DBG("%s: Neighbor? on iface %s\n",p->name, ifa->iface->name);
- break;
- case OSPF_IS_DROTHER:
- if(((n->rid==ifa->drid) || (n->rid==ifa->bdrid))
- && (n->state>=NEIGHBOR_2WAY)) i=1;
- break;
- case OSPF_IS_PTP:
- case OSPF_IS_BACKUP:
- case OSPF_IS_DR:
- if(n->state>=NEIGHBOR_2WAY) i=1;
- break;
- default:
- bug("%s: Iface %s in unknown state?",p->name, ifa->iface->name);
- break;
- }
+ case OSPF_IS_WAITING:
+ DBG("%s: Neighbor? on iface %s\n", p->name, ifa->iface->name);
+ break;
+ case OSPF_IS_DROTHER:
+ if (((n->rid == ifa->drid) || (n->rid == ifa->bdrid))
+ && (n->state >= NEIGHBOR_2WAY))
+ i = 1;
+ break;
+ case OSPF_IS_PTP:
+ case OSPF_IS_BACKUP:
+ case OSPF_IS_DR:
+ if (n->state >= NEIGHBOR_2WAY)
+ i = 1;
break;
default:
- bug("%s: Iface %s is unknown type?",p->name, ifa->iface->name);
+ bug("%s: Iface %s in unknown state?", p->name, ifa->iface->name);
break;
+ }
+ break;
+ default:
+ bug("%s: Iface %s is unknown type?", p->name, ifa->iface->name);
+ break;
}
- DBG("%s: Iface %s can_do_adj=%d\n",p->name, ifa->iface->name,i);
+ DBG("%s: Iface %s can_do_adj=%d\n", p->name, ifa->iface->name, i);
return i;
}
@@ -274,92 +287,95 @@ can_do_adj(struct ospf_neighbor *n)
void
ospf_neigh_sm(struct ospf_neighbor *n, int event)
{
- struct proto_ospf *po=n->ifa->proto;
- struct proto *p=(struct proto *)po;
+ struct proto_ospf *po = n->ifa->proto;
+ struct proto *p = (struct proto *) po;
- OSPF_TRACE(D_EVENTS, "Neighbor state machine for neighbor %I, event \"%s\".",
- n->ip, ospf_inm[event]);
+ OSPF_TRACE(D_EVENTS,
+ "Neighbor state machine for neighbor %I, event \"%s\".", n->ip,
+ ospf_inm[event]);
- switch(event)
+ switch (event)
{
- case INM_START:
- neigh_chstate(n,NEIGHBOR_ATTEMPT);
- /* NBMA are used different way */
- break;
- case INM_HELLOREC:
- switch(n->state)
- {
- case NEIGHBOR_ATTEMPT:
- case NEIGHBOR_DOWN:
- neigh_chstate(n, NEIGHBOR_INIT);
- default:
- tm_start(n->inactim, n->ifa->deadc*n->ifa->helloint); /* Restart inactivity timer */
- break;
- }
- break;
- case INM_2WAYREC:
- if(n->state<NEIGHBOR_2WAY) neigh_chstate(n,NEIGHBOR_2WAY);
- if((n->state==NEIGHBOR_2WAY) && can_do_adj(n))
- neigh_chstate(n,NEIGHBOR_EXSTART);
+ case INM_START:
+ neigh_chstate(n, NEIGHBOR_ATTEMPT);
+ /* NBMA are used different way */
+ break;
+ case INM_HELLOREC:
+ switch (n->state)
+ {
+ case NEIGHBOR_ATTEMPT:
+ case NEIGHBOR_DOWN:
+ neigh_chstate(n, NEIGHBOR_INIT);
+ default:
+ tm_start(n->inactim, n->ifa->deadc * n->ifa->helloint); /* Restart inactivity timer */
break;
- case INM_NEGDONE:
- if(n->state==NEIGHBOR_EXSTART)
+ }
+ break;
+ case INM_2WAYREC:
+ if (n->state < NEIGHBOR_2WAY)
+ neigh_chstate(n, NEIGHBOR_2WAY);
+ if ((n->state == NEIGHBOR_2WAY) && can_do_adj(n))
+ neigh_chstate(n, NEIGHBOR_EXSTART);
+ break;
+ case INM_NEGDONE:
+ if (n->state == NEIGHBOR_EXSTART)
+ {
+ neigh_chstate(n, NEIGHBOR_EXCHANGE);
+ s_init(&(n->dbsi), &(n->ifa->oa->lsal));
+ while (!EMPTY_LIST(n->ackl[ACKL_DELAY]))
{
- neigh_chstate(n,NEIGHBOR_EXCHANGE);
- s_init(&(n->dbsi), &(n->ifa->oa->lsal));
- while(!EMPTY_LIST(n->ackl[ACKL_DELAY]))
- {
- struct lsah_n *no;
- no=(struct lsah_n *)HEAD(n->ackl[ACKL_DELAY]);
- rem_node(NODE no);
- mb_free(no);
- }
+ struct lsah_n *no;
+ no = (struct lsah_n *) HEAD(n->ackl[ACKL_DELAY]);
+ rem_node(NODE no);
+ mb_free(no);
}
- else bug("NEGDONE and I'm not in EXSTART?");
- break;
- case INM_EXDONE:
- neigh_chstate(n,NEIGHBOR_LOADING);
- break;
- case INM_LOADDONE:
- neigh_chstate(n,NEIGHBOR_FULL);
- break;
- case INM_ADJOK:
- switch(n->state)
- {
- case NEIGHBOR_2WAY:
- /* Can In build adjacency? */
- if(can_do_adj(n))
- {
- neigh_chstate(n,NEIGHBOR_EXSTART);
- }
- break;
- default:
- if(n->state>=NEIGHBOR_EXSTART)
- if(!can_do_adj(n))
- {
- neigh_chstate(n,NEIGHBOR_2WAY);
- }
- break;
- }
- break;
- case INM_SEQMIS:
- case INM_BADLSREQ:
- if(n->state>=NEIGHBOR_EXCHANGE)
+ }
+ else
+ bug("NEGDONE and I'm not in EXSTART?");
+ break;
+ case INM_EXDONE:
+ neigh_chstate(n, NEIGHBOR_LOADING);
+ break;
+ case INM_LOADDONE:
+ neigh_chstate(n, NEIGHBOR_FULL);
+ break;
+ case INM_ADJOK:
+ switch (n->state)
+ {
+ case NEIGHBOR_2WAY:
+ /* Can In build adjacency? */
+ if (can_do_adj(n))
{
- neigh_chstate(n,NEIGHBOR_EXSTART);
+ neigh_chstate(n, NEIGHBOR_EXSTART);
}
break;
- case INM_KILLNBR:
- case INM_LLDOWN:
- case INM_INACTTIM:
- neigh_chstate(n,NEIGHBOR_DOWN);
- break;
- case INM_1WAYREC:
- neigh_chstate(n,NEIGHBOR_INIT);
- break;
default:
- bug("%s: INM - Unknown event?",p->name);
+ if (n->state >= NEIGHBOR_EXSTART)
+ if (!can_do_adj(n))
+ {
+ neigh_chstate(n, NEIGHBOR_2WAY);
+ }
break;
+ }
+ break;
+ case INM_SEQMIS:
+ case INM_BADLSREQ:
+ if (n->state >= NEIGHBOR_EXCHANGE)
+ {
+ neigh_chstate(n, NEIGHBOR_EXSTART);
+ }
+ break;
+ case INM_KILLNBR:
+ case INM_LLDOWN:
+ case INM_INACTTIM:
+ neigh_chstate(n, NEIGHBOR_DOWN);
+ break;
+ case INM_1WAYREC:
+ neigh_chstate(n, NEIGHBOR_INIT);
+ break;
+ default:
+ bug("%s: INM - Unknown event?", p->name);
+ break;
}
}
@@ -375,91 +391,104 @@ ospf_neigh_sm(struct ospf_neighbor *n, int event)
void
bdr_election(struct ospf_iface *ifa)
{
- struct ospf_neighbor *neigh,*ndr,*nbdr,me;
+ struct ospf_neighbor *neigh, *ndr, *nbdr, me;
u32 myid;
ip_addr ndrip, nbdrip;
int doadj;
- struct proto *p=&ifa->proto->proto;
+ struct proto *p = &ifa->proto->proto;
DBG("(B)DR election.\n");
- myid=p->cf->global->router_id;
+ myid = p->cf->global->router_id;
- me.state=NEIGHBOR_2WAY;
- me.rid=myid;
- me.priority=ifa->priority;
- me.dr=ifa->drip;
- me.bdr=ifa->bdrip;
- me.ip=ifa->iface->addr->ip;
+ me.state = NEIGHBOR_2WAY;
+ me.rid = myid;
+ me.priority = ifa->priority;
+ me.dr = ifa->drip;
+ me.bdr = ifa->bdrip;
+ me.ip = ifa->iface->addr->ip;
- add_tail(&ifa->neigh_list, NODE &me);
+ add_tail(&ifa->neigh_list, NODE & me);
- nbdr=electbdr(ifa->neigh_list);
- ndr=electdr(ifa->neigh_list);
+ nbdr = electbdr(ifa->neigh_list);
+ ndr = electdr(ifa->neigh_list);
- if(ndr==NULL) ndr=nbdr;
+ if (ndr == NULL)
+ ndr = nbdr;
- if(((ifa->drid==myid) && (ndr!=&me))
- || ((ifa->drid!=myid) && (ndr==&me))
- || ((ifa->bdrid==myid) && (nbdr!=&me))
- || ((ifa->bdrid!=myid) && (nbdr==&me)))
+ if (((ifa->drid == myid) && (ndr != &me))
+ || ((ifa->drid != myid) && (ndr == &me))
+ || ((ifa->bdrid == myid) && (nbdr != &me))
+ || ((ifa->bdrid != myid) && (nbdr == &me)))
{
- if(ndr==NULL) ifa->drip=me.dr=ipa_from_u32(0);
- else ifa->drip=me.dr=ndr->ip;
-
- if(nbdr==NULL) ifa->bdrip=me.bdr=ipa_from_u32(0);
- else ifa->bdrip=me.bdr=nbdr->ip;
-
- nbdr=electbdr(ifa->neigh_list);
- ndr=electdr(ifa->neigh_list);
+ if (ndr == NULL)
+ ifa->drip = me.dr = ipa_from_u32(0);
+ else
+ ifa->drip = me.dr = ndr->ip;
+
+ if (nbdr == NULL)
+ ifa->bdrip = me.bdr = ipa_from_u32(0);
+ else
+ ifa->bdrip = me.bdr = nbdr->ip;
+
+ nbdr = electbdr(ifa->neigh_list);
+ ndr = electdr(ifa->neigh_list);
}
- if(ndr==NULL) ndrip=ipa_from_u32(0);
- else ndrip=ndr->ip;
+ if (ndr == NULL)
+ ndrip = ipa_from_u32(0);
+ else
+ ndrip = ndr->ip;
- if(nbdr==NULL) nbdrip=ipa_from_u32(0);
- else nbdrip=nbdr->ip;
+ if (nbdr == NULL)
+ nbdrip = ipa_from_u32(0);
+ else
+ nbdrip = nbdr->ip;
- doadj=0;
- if((ipa_compare(ifa->drip,ndrip)!=0) || (ipa_compare(ifa->bdrip,nbdrip)!=0))
- doadj=1;
+ doadj = 0;
+ if ((ipa_compare(ifa->drip, ndrip) != 0)
+ || (ipa_compare(ifa->bdrip, nbdrip) != 0))
+ doadj = 1;
- if(ndr==NULL)
+ if (ndr == NULL)
{
- ifa->drid=0;
- ifa->drip=ipa_from_u32(0);
+ ifa->drid = 0;
+ ifa->drip = ipa_from_u32(0);
}
else
{
- ifa->drid=ndr->rid;
- ifa->drip=ndr->ip;
+ ifa->drid = ndr->rid;
+ ifa->drip = ndr->ip;
}
- if(nbdr==NULL)
+ if (nbdr == NULL)
{
- ifa->bdrid=0;
- ifa->bdrip=ipa_from_u32(0);
+ ifa->bdrid = 0;
+ ifa->bdrip = ipa_from_u32(0);
}
else
{
- ifa->bdrid=nbdr->rid;
- ifa->bdrip=nbdr->ip;
+ ifa->bdrid = nbdr->rid;
+ ifa->bdrip = nbdr->ip;
}
DBG("DR=%I, BDR=%I\n", ifa->drid, ifa->bdrid);
- if(myid==ifa->drid) ospf_iface_chstate(ifa, OSPF_IS_DR);
+ if (myid == ifa->drid)
+ ospf_iface_chstate(ifa, OSPF_IS_DR);
else
{
- if(myid==ifa->bdrid) ospf_iface_chstate(ifa, OSPF_IS_BACKUP);
- else ospf_iface_chstate(ifa, OSPF_IS_DROTHER);
+ if (myid == ifa->bdrid)
+ ospf_iface_chstate(ifa, OSPF_IS_BACKUP);
+ else
+ ospf_iface_chstate(ifa, OSPF_IS_DROTHER);
}
- rem_node(NODE &me);
+ rem_node(NODE & me);
- if(doadj)
+ if (doadj)
{
- WALK_LIST (neigh, ifa->neigh_list)
+ WALK_LIST(neigh, ifa->neigh_list)
{
ospf_neigh_sm(neigh, INM_ADJOK);
}
@@ -471,9 +500,8 @@ find_neigh(struct ospf_iface *ifa, u32 rid)
{
struct ospf_neighbor *n;
- WALK_LIST (n, ifa->neigh_list)
- if(n->rid == rid)
- return n;
+ WALK_LIST(n, ifa->neigh_list) if (n->rid == rid)
+ return n;
return NULL;
}
@@ -482,19 +510,19 @@ find_neigh(struct ospf_iface *ifa, u32 rid)
struct ospf_neighbor *
find_neigh_noifa(struct proto_ospf *po, u32 rid)
{
- struct ospf_neighbor *n=NULL,*m;
+ struct ospf_neighbor *n = NULL, *m;
struct ospf_iface *ifa;
- WALK_LIST (ifa, po->iface_list)
- if((m=find_neigh(ifa, rid))!=NULL)
+ WALK_LIST(ifa, po->iface_list) if ((m = find_neigh(ifa, rid)) != NULL)
+ {
+ if (m->state >= NEIGHBOR_2WAY)
{
- if(m->state>=NEIGHBOR_2WAY)
- {
- if(n==NULL) n=m;
- else
- if(m->ifa->cost < n->ifa->cost) n=m;
- }
+ if (n == NULL)
+ n = m;
+ else if (m->ifa->cost < n->ifa->cost)
+ n = m;
}
+ }
return n;
}
@@ -502,24 +530,26 @@ struct ospf_area *
ospf_find_area(struct proto_ospf *po, u32 aid)
{
struct ospf_area *oa;
- WALK_LIST(NODE oa,po->area_list)
- if(((struct ospf_area *)oa)->areaid==aid) return oa;
+ WALK_LIST(NODE oa, po->area_list)
+ if (((struct ospf_area *) oa)->areaid == aid)
+ return oa;
return NULL;
}
/* Neighbor is inactive for a long time. Remove it. */
void
-neighbor_timer_hook(timer *timer)
+neighbor_timer_hook(timer * timer)
{
struct ospf_neighbor *n;
struct ospf_iface *ifa;
struct proto *p;
- n=(struct ospf_neighbor *)timer->data;
- ifa=n->ifa;
- p=(struct proto *)(ifa->proto);
- OSPF_TRACE(D_EVENTS,"Inactivity timer fired on interface %s for neighbor %I.",
- ifa->iface->name, n->ip);
+ n = (struct ospf_neighbor *) timer->data;
+ ifa = n->ifa;
+ p = (struct proto *) (ifa->proto);
+ OSPF_TRACE(D_EVENTS,
+ "Inactivity timer fired on interface %s for neighbor %I.",
+ ifa->iface->name, n->ip);
ospf_neigh_remove(n);
}
@@ -529,8 +559,8 @@ ospf_neigh_remove(struct ospf_neighbor *n)
struct ospf_iface *ifa;
struct proto *p;
- ifa=n->ifa;
- p=(struct proto *)(ifa->proto);
+ ifa = n->ifa;
+ p = (struct proto *) (ifa->proto);
neigh_chstate(n, NEIGHBOR_DOWN);
rem_node(NODE n);
rfree(n->pool);
@@ -540,63 +570,69 @@ ospf_neigh_remove(struct ospf_neighbor *n)
void
ospf_sh_neigh_info(struct ospf_neighbor *n)
{
- struct ospf_iface *ifa=n->ifa;
- char *pos="other";
- char etime[6];
- int exp,sec,min;
-
- exp=n->inactim->expires-now;
- sec=exp-(exp/60);
- min=(exp-sec)/60;
- if(min>59)
- {
- bsprintf(etime,"-Inf-");
- }
- else
- {
- bsprintf(etime,"%02u:%02u", min, sec);
- }
-
- if(n->rid==ifa->drid) pos="dr ";
- if(n->rid==ifa->bdrid) pos="bdr ";
- if(n->ifa->type==OSPF_IT_PTP) pos="ptp ";
-
- cli_msg(-1013,"%-1I\t%3u\t%s/%s\t%-5s\t%-1I\t%-10s",n->rid, n->priority,
- ospf_ns[n->state], pos, etime, n->ip,ifa->iface->name);
+ struct ospf_iface *ifa = n->ifa;
+ char *pos = "other";
+ char etime[6];
+ int exp, sec, min;
+
+ exp = n->inactim->expires - now;
+ sec = exp - (exp / 60);
+ min = (exp - sec) / 60;
+ if (min > 59)
+ {
+ bsprintf(etime, "-Inf-");
+ }
+ else
+ {
+ bsprintf(etime, "%02u:%02u", min, sec);
+ }
+
+ if (n->rid == ifa->drid)
+ pos = "dr ";
+ if (n->rid == ifa->bdrid)
+ pos = "bdr ";
+ if (n->ifa->type == OSPF_IT_PTP)
+ pos = "ptp ";
+
+ cli_msg(-1013, "%-1I\t%3u\t%s/%s\t%-5s\t%-1I\t%-10s", n->rid, n->priority,
+ ospf_ns[n->state], pos, etime, n->ip, ifa->iface->name);
}
void
-rxmt_timer_hook(timer *timer)
+rxmt_timer_hook(timer * timer)
{
- struct ospf_neighbor *n = (struct ospf_neighbor *)timer->data;
+ struct ospf_neighbor *n = (struct ospf_neighbor *) timer->data;
struct top_hash_entry *en;
DBG("%s: RXMT timer fired on interface %s for neigh: %I.\n",
- p->name, ifa->iface->name, n->ip);
- if (n->state < NEIGHBOR_LOADING) ospf_dbdes_send(n);
+ p->name, ifa->iface->name, n->ip);
+ if (n->state < NEIGHBOR_LOADING)
+ ospf_dbdes_send(n);
- if(n->state < NEIGHBOR_FULL) ospf_lsreq_send(n);
+ if (n->state < NEIGHBOR_FULL)
+ ospf_lsreq_send(n);
else
{
- if(!EMPTY_SLIST(n->lsrtl))
+ if (!EMPTY_SLIST(n->lsrtl))
{
list uplist;
slab *upslab;
struct l_lsr_head *llsh;
init_list(&uplist);
- upslab=sl_new(n->pool,sizeof(struct l_lsr_head));
+ upslab = sl_new(n->pool, sizeof(struct l_lsr_head));
- WALK_SLIST(SNODE en,n->lsrtl)
+ WALK_SLIST(SNODE en, n->lsrtl)
{
- if((SNODE en)->next==(SNODE en)) bug("RTList is cycled");
- llsh=sl_alloc(upslab);
- llsh->lsh.id=en->lsa.id;
- llsh->lsh.rt=en->lsa.rt;
- llsh->lsh.type=en->lsa.type;
+ if ((SNODE en)->next == (SNODE en))
+ bug("RTList is cycled");
+ llsh = sl_alloc(upslab);
+ llsh->lsh.id = en->lsa.id;
+ llsh->lsh.rt = en->lsa.rt;
+ llsh->lsh.type = en->lsa.type;
DBG("Working on ID: %I, RT: %I, Type: %u\n",
- en->lsa.id, en->lsa.rt, en->lsa.type);
- add_tail(&uplist, NODE llsh);
+ en->lsa.id, en->lsa.rt, en->lsa.type);
+ add_tail(&uplist, NODE llsh);
}
ospf_lsupd_send_list(n, &uplist);
rfree(upslab);
@@ -605,9 +641,8 @@ rxmt_timer_hook(timer *timer)
}
void
-ackd_timer_hook(timer *t)
+ackd_timer_hook(timer * t)
{
- struct ospf_neighbor *n=t->data;
+ struct ospf_neighbor *n = t->data;
ospf_lsack_send(n, ACKL_DELAY);
}
-
diff --git a/proto/ospf/ospf.c b/proto/ospf/ospf.c
index 73460820..78e46446 100644
--- a/proto/ospf/ospf.c
+++ b/proto/ospf/ospf.c
@@ -76,52 +76,53 @@ static int ospf_rte_same(struct rte *new, struct rte *old);
static int
ospf_start(struct proto *p)
{
- struct proto_ospf *po=(struct proto_ospf *)p;
- struct ospf_config *c=(struct ospf_config *)(p->cf);
+ struct proto_ospf *po = (struct proto_ospf *) p;
+ struct ospf_config *c = (struct ospf_config *) (p->cf);
struct ospf_area_config *ac;
struct ospf_area *oa;
- struct area_net *anet,*antmp;
+ struct area_net *anet, *antmp;
- fib_init(&po->efib,p->pool,sizeof(struct extfib),16,init_efib);
+ fib_init(&po->efib, p->pool, sizeof(struct extfib), 16, init_efib);
init_list(&(po->iface_list));
init_list(&(po->area_list));
- po->areano=0;
- if(EMPTY_LIST(c->area_list))
+ po->areano = 0;
+ if (EMPTY_LIST(c->area_list))
{
log("%s: Cannot start, no OSPF areas configured", p->name);
return PS_DOWN;
}
- WALK_LIST(ac,c->area_list)
+ WALK_LIST(ac, c->area_list)
{
- oa=mb_allocz(po->proto.pool, sizeof(struct ospf_area));
+ oa = mb_allocz(po->proto.pool, sizeof(struct ospf_area));
add_tail(&po->area_list, NODE oa);
po->areano++;
- oa->stub=ac->stub;
- oa->tick=ac->tick;
- oa->areaid=ac->areaid;
- oa->gr=ospf_top_new(po->proto.pool, po);
+ oa->stub = ac->stub;
+ oa->tick = ac->tick;
+ oa->areaid = ac->areaid;
+ oa->gr = ospf_top_new(po->proto.pool, po);
s_init_list(&(oa->lsal));
- oa->rt=NULL;
- oa->po=po;
- oa->disp_timer=tm_new(po->proto.pool);
- oa->disp_timer->data=oa;
- oa->disp_timer->randomize=0;
- oa->disp_timer->hook=area_disp;
- oa->disp_timer->recurrent=oa->tick;
+ oa->rt = NULL;
+ oa->po = po;
+ oa->disp_timer = tm_new(po->proto.pool);
+ oa->disp_timer->data = oa;
+ oa->disp_timer->randomize = 0;
+ oa->disp_timer->hook = area_disp;
+ oa->disp_timer->recurrent = oa->tick;
tm_start(oa->disp_timer, 1);
- oa->calcrt=0;
- oa->origrt=0;
+ oa->calcrt = 0;
+ oa->origrt = 0;
init_list(&oa->net_list);
- WALK_LIST(anet,ac->net_list)
+ WALK_LIST(anet, ac->net_list)
{
- antmp=mb_allocz(po->proto.pool, sizeof(struct area_net));
- antmp->px.addr=anet->px.addr;
- antmp->px.len=anet->px.len;
- antmp->hidden=anet->hidden;
+ antmp = mb_allocz(po->proto.pool, sizeof(struct area_net));
+ antmp->px.addr = anet->px.addr;
+ antmp->px.len = anet->px.len;
+ antmp->hidden = anet->hidden;
add_tail(&oa->net_list, NODE antmp);
}
- fib_init(&oa->infib,po->proto.pool,sizeof(struct infib),16,init_infib);
+ fib_init(&oa->infib, po->proto.pool, sizeof(struct infib), 16,
+ init_infib);
}
return PS_UP;
}
@@ -131,7 +132,7 @@ ospf_dump(struct proto *p)
{
struct ospf_iface *ifa;
struct ospf_neighbor *n;
- struct proto_ospf *po=(struct proto_ospf *)p;
+ struct proto_ospf *po = (struct proto_ospf *) p;
struct ospf_area *oa;
OSPF_TRACE(D_EVENTS, "Area number: %d", po->areano);
@@ -148,11 +149,12 @@ ospf_dump(struct proto *p)
}
}
- WALK_LIST(NODE oa,po->area_list)
+ WALK_LIST(NODE oa, po->area_list)
{
OSPF_TRACE(D_EVENTS, "LSA graph dump for area \"%I\" start:", oa->areaid);
- ospf_top_dump(oa->gr,p);
- OSPF_TRACE(D_EVENTS, "LSA graph dump for area \"%I\" finished", oa->areaid);
+ ospf_top_dump(oa->gr, p);
+ OSPF_TRACE(D_EVENTS, "LSA graph dump for area \"%I\" finished",
+ oa->areaid);
}
neigh_dump_all();
}
@@ -161,8 +163,8 @@ static struct proto *
ospf_init(struct proto_config *c)
{
struct proto *p = proto_new(c, sizeof(struct proto_ospf));
- struct proto_ospf *po=(struct proto_ospf *)p;
- struct ospf_config *oc=(struct ospf_config *)c;
+ struct proto_ospf *po = (struct proto_ospf *) p;
+ struct ospf_config *oc = (struct ospf_config *) c;
p->import_control = ospf_import_control;
p->make_tmp_attrs = ospf_make_tmp_attrs;
@@ -172,8 +174,8 @@ ospf_init(struct proto_config *c)
p->rte_better = ospf_rte_better;
p->rte_same = ospf_rte_same;
- po->rfc1583=oc->rfc1583;
- po->ebit=0;
+ po->rfc1583 = oc->rfc1583;
+ po->ebit = 0;
return p;
}
@@ -181,24 +183,31 @@ ospf_init(struct proto_config *c)
static int
ospf_rte_better(struct rte *new, struct rte *old)
{
- if(new->u.ospf.metric1==LSINFINITY) return 0;
+ if (new->u.ospf.metric1 == LSINFINITY)
+ return 0;
/* External paths are always longer that internal */
- if(((new->attrs->source==RTS_OSPF) || (new->attrs->source==RTS_OSPF_IA))
- && (old->attrs->source==RTS_OSPF_EXT)) return 1;
- if(((old->attrs->source==RTS_OSPF) || (old->attrs->source==RTS_OSPF_IA))
- && (new->attrs->source==RTS_OSPF_EXT)) return 0;
-
- if(new->u.ospf.metric2<old->u.ospf.metric2)
+ if (((new->attrs->source == RTS_OSPF)
+ || (new->attrs->source == RTS_OSPF_IA))
+ && (old->attrs->source == RTS_OSPF_EXT))
+ return 1;
+ if (((old->attrs->source == RTS_OSPF)
+ || (old->attrs->source == RTS_OSPF_IA))
+ && (new->attrs->source == RTS_OSPF_EXT))
+ return 0;
+
+ if (new->u.ospf.metric2 < old->u.ospf.metric2)
{
- if(old->u.ospf.metric2==LSINFINITY) return 0; /* Old is E1, new is E2 */
- return 1; /* Both are E2 */
+ if (old->u.ospf.metric2 == LSINFINITY)
+ return 0; /* Old is E1, new is E2 */
+ return 1; /* Both are E2 */
}
-
- if(new->u.ospf.metric2>old->u.ospf.metric2)
+
+ if (new->u.ospf.metric2 > old->u.ospf.metric2)
{
- if(new->u.ospf.metric2==LSINFINITY) return 1; /* New is E1, old is E2 */
- return 0; /* Both are E2 */
+ if (new->u.ospf.metric2 == LSINFINITY)
+ return 1; /* New is E1, old is E2 */
+ return 0; /* Both are E2 */
}
/*
@@ -207,8 +216,9 @@ ospf_rte_better(struct rte *new, struct rte *old)
* 2) Paths are E1.
*/
- if(new->u.ospf.metric1<old->u.ospf.metric1) return 1;
- return 0; /* Old is shorter or same */
+ if (new->u.ospf.metric1 < old->u.ospf.metric1)
+ return 1;
+ return 0; /* Old is shorter or same */
}
static int
@@ -218,13 +228,15 @@ ospf_rte_same(struct rte *new, struct rte *old)
return
new->u.ospf.metric1 == old->u.ospf.metric1 &&
new->u.ospf.metric2 == old->u.ospf.metric2 &&
- new->u.ospf.tag == old->u.ospf.tag;
+ new->u.ospf.tag == old->u.ospf.tag;
}
static ea_list *
-ospf_build_attrs(ea_list *next, struct linpool *pool, u32 m1, u32 m2, u32 tag)
+ospf_build_attrs(ea_list * next, struct linpool *pool, u32 m1, u32 m2,
+ u32 tag)
{
- struct ea_list *l = lp_alloc(pool, sizeof(struct ea_list) + 3*sizeof(eattr));
+ struct ea_list *l =
+ lp_alloc(pool, sizeof(struct ea_list) + 3 * sizeof(eattr));
l->next = next;
l->flags = EALF_SORTED;
@@ -247,31 +259,31 @@ ospf_build_attrs(ea_list *next, struct linpool *pool, u32 m1, u32 m2, u32 tag)
void
schedule_net_lsa(struct ospf_iface *ifa)
{
- ifa->orignet = 1;
+ ifa->orignet = 1;
}
void
schedule_rt_lsa(struct ospf_area *oa)
{
- struct proto_ospf *po=oa->po;
- struct proto *p=&po->proto;
+ struct proto_ospf *po = oa->po;
+ struct proto *p = &po->proto;
OSPF_TRACE(D_EVENTS, "Scheduling RT lsa origination for area %I.",
- oa->areaid);
- oa->origrt=1;
+ oa->areaid);
+ oa->origrt = 1;
}
void
schedule_rtcalc(struct ospf_area *oa)
{
- struct proto_ospf *po=oa->po;
- struct proto *p=&po->proto;
+ struct proto_ospf *po = oa->po;
+ struct proto *p = &po->proto;
- if(oa->calcrt) return;
+ if (oa->calcrt)
+ return;
- OSPF_TRACE(D_EVENTS, "Scheduling RT calculation for area %I.",
- oa->areaid);
- oa->calcrt=1;
+ OSPF_TRACE(D_EVENTS, "Scheduling RT calculation for area %I.", oa->areaid);
+ oa->calcrt = 1;
}
/**
@@ -285,27 +297,30 @@ schedule_rtcalc(struct ospf_area *oa)
* table calculation when @ospf_area->calcrt is set.
*/
void
-area_disp(timer *timer)
+area_disp(timer * timer)
{
- struct ospf_area *oa=timer->data;
- struct proto_ospf *po=oa->po;
+ struct ospf_area *oa = timer->data;
+ struct proto_ospf *po = oa->po;
struct ospf_iface *ifa;
/* Now try to originage rt_lsa */
- if(oa->origrt) originate_rt_lsa(oa);
+ if (oa->origrt)
+ originate_rt_lsa(oa);
/* Now try to originate network LSA's */
WALK_LIST(ifa, po->iface_list)
{
- if(ifa->orignet&&(ifa->an==oa->areaid)) originate_net_lsa(ifa);
+ if (ifa->orignet && (ifa->an == oa->areaid))
+ originate_net_lsa(ifa);
}
/* Age LSA DB */
ospf_age(oa);
/* Calculate routing table */
- if(oa->calcrt) ospf_rt_spfa(oa);
- oa->calcrt=0;
+ if (oa->calcrt)
+ ospf_rt_spfa(oa);
+ oa->calcrt = 0;
}
/**
@@ -320,19 +335,22 @@ area_disp(timer *timer)
*/
int
-ospf_import_control(struct proto *p, rte **new, ea_list **attrs, struct linpool *pool)
+ospf_import_control(struct proto *p, rte ** new, ea_list ** attrs,
+ struct linpool *pool)
{
- rte *e=*new;
+ rte *e = *new;
- if(p==e->attrs->proto) return -1; /* Reject our own routes */
+ if (p == e->attrs->proto)
+ return -1; /* Reject our own routes */
*attrs = ospf_build_attrs(*attrs, pool, LSINFINITY, 10000, 0);
- return 0; /* Leave decision to the filters */
+ return 0; /* Leave decision to the filters */
}
struct ea_list *
ospf_make_tmp_attrs(struct rte *rt, struct linpool *pool)
{
- return ospf_build_attrs(NULL, pool, rt->u.ospf.metric1, rt->u.ospf.metric2, rt->u.ospf.tag);
+ return ospf_build_attrs(NULL, pool, rt->u.ospf.metric1, rt->u.ospf.metric2,
+ rt->u.ospf.tag);
}
void
@@ -340,7 +358,7 @@ ospf_store_tmp_attrs(struct rte *rt, struct ea_list *attrs)
{
rt->u.ospf.metric1 = ea_get_int(attrs, EA_OSPF_METRIC1, LSINFINITY);
rt->u.ospf.metric2 = ea_get_int(attrs, EA_OSPF_METRIC2, 10000);
- rt->u.ospf.tag = ea_get_int(attrs, EA_OSPF_TAG, 0);
+ rt->u.ospf.tag = ea_get_int(attrs, EA_OSPF_TAG, 0);
}
/**
@@ -356,123 +374,138 @@ ospf_store_tmp_attrs(struct rte *rt, struct ea_list *attrs)
static int
ospf_shutdown(struct proto *p)
{
- struct proto_ospf *po=(struct proto_ospf *)p;
+ struct proto_ospf *po = (struct proto_ospf *) p;
struct ospf_iface *ifa;
OSPF_TRACE(D_EVENTS, "Shutdown requested");
/* And send to all my neighbors 1WAY */
- WALK_LIST(ifa, po->iface_list)
- ospf_iface_shutdown(ifa);
-
+ WALK_LIST(ifa, po->iface_list) ospf_iface_shutdown(ifa);
+
return PS_DOWN;
}
void
-ospf_rt_notify(struct proto *p, net *n, rte *new, rte *old UNUSED, ea_list *attrs)
+ospf_rt_notify(struct proto *p, net * n, rte * new, rte * old UNUSED,
+ ea_list * attrs)
{
- struct proto_ospf *po=(struct proto_ospf *)p;
+ struct proto_ospf *po = (struct proto_ospf *) p;
/* Temporarily down write anything
OSPF_TRACE(D_EVENTS, "Got route %I/%d %s", p->name, n->n.prefix,
n->n.pxlen, new ? "up" : "down");
*/
- if(new) /* Got some new route */
+ if (new) /* Got some new route */
{
originate_ext_lsa(n, new, po, attrs);
}
else
{
- u32 rtid=po->proto.cf->global->router_id;
+ u32 rtid = po->proto.cf->global->router_id;
struct ospf_area *oa;
struct top_hash_entry *en;
- u32 pr=ipa_to_u32(n->n.prefix);
+ u32 pr = ipa_to_u32(n->n.prefix);
struct ospf_lsa_ext *ext;
int i;
- int max=max_ext_lsa(n->n.pxlen);
+ int max = max_ext_lsa(n->n.pxlen);
/* Flush old external LSA */
WALK_LIST(oa, po->area_list)
{
- for(i=0;i<max;i++,pr++)
+ for (i = 0; i < max; i++, pr++)
{
- if(en=ospf_hash_find(oa->gr, pr, rtid, LSA_T_EXT))
- {
- ext=en->lsa_body;
- if(ipa_compare(ext->netmask, ipa_mkmask(n->n.pxlen))==0)
- {
- ospf_lsupd_flush_nlsa(en,oa);
- break;
- }
- }
+ if (en = ospf_hash_find(oa->gr, pr, rtid, LSA_T_EXT))
+ {
+ ext = en->lsa_body;
+ if (ipa_compare(ext->netmask, ipa_mkmask(n->n.pxlen)) == 0)
+ {
+ ospf_lsupd_flush_nlsa(en, oa);
+ break;
+ }
+ }
}
}
}
}
static void
-ospf_get_status(struct proto *p, byte *buf)
+ospf_get_status(struct proto *p, byte * buf)
{
- struct proto_ospf *po=(struct proto_ospf *)p;
+ struct proto_ospf *po = (struct proto_ospf *) p;
- if (p->proto_state == PS_DOWN) buf[0] = 0;
+ if (p->proto_state == PS_DOWN)
+ buf[0] = 0;
else
{
struct ospf_iface *ifa;
struct ospf_neighbor *n;
- int adj=0;
+ int adj = 0;
- WALK_LIST(ifa,po->iface_list)
- WALK_LIST(n,ifa->neigh_list)
- if(n->state==NEIGHBOR_FULL) adj=1;
+ WALK_LIST(ifa, po->iface_list)
+ WALK_LIST(n, ifa->neigh_list) if (n->state == NEIGHBOR_FULL)
+ adj = 1;
- if(adj==0) strcpy(buf, "Alone");
- else strcpy(buf, "Running");
+ if (adj == 0)
+ strcpy(buf, "Alone");
+ else
+ strcpy(buf, "Running");
}
}
static void
-ospf_get_route_info(rte *rte, byte *buf, ea_list *attrs UNUSED)
+ospf_get_route_info(rte * rte, byte * buf, ea_list * attrs UNUSED)
{
- char met=' ';
- char type=' ';
+ char met = ' ';
+ char type = ' ';
- if(rte->attrs->source==RTS_OSPF_EXT)
+ if (rte->attrs->source == RTS_OSPF_EXT)
{
- met='1';
- type='E';
+ met = '1';
+ type = 'E';
}
- if(rte->u.ospf.metric2!=LSINFINITY) met='2';
- if(rte->attrs->source==RTS_OSPF_IA) type='A';
- if(rte->attrs->source==RTS_OSPF) type='I';
+ if (rte->u.ospf.metric2 != LSINFINITY)
+ met = '2';
+ if (rte->attrs->source == RTS_OSPF_IA)
+ type = 'A';
+ if (rte->attrs->source == RTS_OSPF)
+ type = 'I';
buf += bsprintf(buf, " %c", type);
- if(met!=' ') buf += bsprintf(buf, "%c", met);
+ if (met != ' ')
+ buf += bsprintf(buf, "%c", met);
buf += bsprintf(buf, " (%d/%d", rte->pref, rte->u.ospf.metric1);
- if(rte->u.ospf.metric2!=LSINFINITY) buf += bsprintf(buf, "/%d", rte->u.ospf.metric2);
+ if (rte->u.ospf.metric2 != LSINFINITY)
+ buf += bsprintf(buf, "/%d", rte->u.ospf.metric2);
buf += bsprintf(buf, ")");
- if(rte->attrs->source==RTS_OSPF_EXT && rte->u.ospf.tag)
+ if (rte->attrs->source == RTS_OSPF_EXT && rte->u.ospf.tag)
{
buf += bsprintf(buf, " [%x]", rte->u.ospf.tag);
}
}
static int
-ospf_get_attr(eattr *a, byte *buf)
+ospf_get_attr(eattr * a, byte * buf)
{
switch (a->id)
- {
- case EA_OSPF_METRIC1: bsprintf(buf, "metric1"); return GA_NAME;
- case EA_OSPF_METRIC2: bsprintf(buf, "metric2"); return GA_NAME;
- case EA_OSPF_TAG: bsprintf(buf, "tag: %08x", a->u.data); return GA_FULL;
- default: return GA_UNKNOWN;
- }
+ {
+ case EA_OSPF_METRIC1:
+ bsprintf(buf, "metric1");
+ return GA_NAME;
+ case EA_OSPF_METRIC2:
+ bsprintf(buf, "metric2");
+ return GA_NAME;
+ case EA_OSPF_TAG:
+ bsprintf(buf, "tag: %08x", a->u.data);
+ return GA_FULL;
+ default:
+ return GA_UNKNOWN;
+ }
}
static int
ospf_patt_compare(struct ospf_iface_patt *a, struct ospf_iface_patt *b)
{
- return ((a->type==b->type)&&(a->priority==b->priority));
+ return ((a->type == b->type) && (a->priority == b->priority));
}
/**
@@ -488,412 +521,411 @@ ospf_patt_compare(struct ospf_iface_patt *a, struct ospf_iface_patt *b)
static int
ospf_reconfigure(struct proto *p, struct proto_config *c)
{
- struct ospf_config *old=(struct ospf_config *)(p->cf);
- struct ospf_config *new=(struct ospf_config *)c;
- struct ospf_area_config *ac1,*ac2;
- struct proto_ospf *po=( struct proto_ospf *)p;
- struct ospf_iface_patt *ip1,*ip2;
+ struct ospf_config *old = (struct ospf_config *) (p->cf);
+ struct ospf_config *new = (struct ospf_config *) c;
+ struct ospf_area_config *ac1, *ac2;
+ struct proto_ospf *po = (struct proto_ospf *) p;
+ struct ospf_iface_patt *ip1, *ip2;
struct ospf_iface *ifa;
- struct nbma_node *nb1,*nb2,*nbnx;
- struct ospf_area *oa=NULL;
- struct area_net *anet,*antmp;
+ struct nbma_node *nb1, *nb2, *nbnx;
+ struct ospf_area *oa = NULL;
+ struct area_net *anet, *antmp;
int found;
- po->rfc1583=new->rfc1583;
+ po->rfc1583 = new->rfc1583;
WALK_LIST(oa, po->area_list) /* Routing table must be recalculated */
{
schedule_rtcalc(oa);
}
- ac1=HEAD(old->area_list);
- ac2=HEAD(new->area_list);
+ ac1 = HEAD(old->area_list);
+ ac2 = HEAD(new->area_list);
/* I should get it in same order */
-
- while(((NODE (ac1))->next!=NULL) && ((NODE (ac2))->next!=NULL))
+
+ while (((NODE(ac1))->next != NULL) && ((NODE(ac2))->next != NULL))
{
- if(ac1->areaid!=ac2->areaid) return 0;
- if(ac1->stub!=ac2->stub) return 0; /* FIXME: non zero values can change */
+ if (ac1->areaid != ac2->areaid)
+ return 0;
+ if (ac1->stub != ac2->stub)
+ return 0; /* FIXME: non zero values can change */
- WALK_LIST(oa,po->area_list)
- if(oa->areaid==ac2->areaid) break;
+ WALK_LIST(oa, po->area_list) if (oa->areaid == ac2->areaid)
+ break;
- if(!oa) return 0;
+ if (!oa)
+ return 0;
- if(ac1->tick!=ac2->tick)
+ if (ac1->tick != ac2->tick)
{
- if(oa->areaid==ac2->areaid)
+ if (oa->areaid == ac2->areaid)
{
- oa->tick=ac2->tick;
- tm_start(oa->disp_timer,oa->tick);
- OSPF_TRACE(D_EVENTS,
- "Changing tick interval on area %I from %d to %d",
- oa->areaid, ac1->tick, ac2->tick);
- break;
+ oa->tick = ac2->tick;
+ tm_start(oa->disp_timer, oa->tick);
+ OSPF_TRACE(D_EVENTS,
+ "Changing tick interval on area %I from %d to %d",
+ oa->areaid, ac1->tick, ac2->tick);
+ break;
}
}
/* Change net_list */
WALK_LIST_DELSAFE(anet, antmp, oa->net_list)
{
- rem_node(NODE anet);
- mb_free(anet);
+ rem_node(NODE anet);
+ mb_free(anet);
}
WALK_LIST(anet, ac2->net_list)
{
- antmp=mb_alloc(p->pool, sizeof(struct area_net));
- antmp->px.addr=anet->px.addr;
- antmp->px.len=anet->px.len;
- antmp->hidden=anet->hidden;
- add_tail(&oa->net_list, NODE antmp);
+ antmp = mb_alloc(p->pool, sizeof(struct area_net));
+ antmp->px.addr = anet->px.addr;
+ antmp->px.len = anet->px.len;
+ antmp->hidden = anet->hidden;
+ add_tail(&oa->net_list, NODE antmp);
}
- if(!iface_patts_equal(&ac1->patt_list, &ac2->patt_list,
- (void *) ospf_patt_compare))
- return 0;
+ if (!iface_patts_equal(&ac1->patt_list, &ac2->patt_list,
+ (void *) ospf_patt_compare))
+ return 0;
WALK_LIST(ifa, po->iface_list)
{
- if(ip1=(struct ospf_iface_patt *)
- iface_patt_match(&ac1->patt_list, ifa->iface))
+ if (ip1 = (struct ospf_iface_patt *)
+ iface_patt_match(&ac1->patt_list, ifa->iface))
{
- /* Now reconfigure interface */
- if(!(ip2=(struct ospf_iface_patt *)
- iface_patt_match(&ac2->patt_list, ifa->iface))) return 0;
+ /* Now reconfigure interface */
+ if (!(ip2 = (struct ospf_iface_patt *)
+ iface_patt_match(&ac2->patt_list, ifa->iface)))
+ return 0;
/* HELLO TIMER */
- if(ip1->helloint!=ip2->helloint)
+ if (ip1->helloint != ip2->helloint)
{
- ifa->helloint=ip2->helloint;
- ifa->hello_timer->recurrent=ifa->helloint;
- tm_start(ifa->hello_timer,ifa->helloint);
+ ifa->helloint = ip2->helloint;
+ ifa->hello_timer->recurrent = ifa->helloint;
+ tm_start(ifa->hello_timer, ifa->helloint);
OSPF_TRACE(D_EVENTS,
- "Changing hello interval on interface %s from %d to %d",
- ifa->iface->name,ip1->helloint,ip2->helloint);
+ "Changing hello interval on interface %s from %d to %d",
+ ifa->iface->name, ip1->helloint, ip2->helloint);
}
/* POLL TIMER */
- if(ip1->pollint!=ip2->pollint)
+ if (ip1->pollint != ip2->pollint)
{
- ifa->pollint=ip2->helloint;
- ifa->poll_timer->recurrent=ifa->pollint;
- tm_start(ifa->poll_timer,ifa->pollint);
+ ifa->pollint = ip2->helloint;
+ ifa->poll_timer->recurrent = ifa->pollint;
+ tm_start(ifa->poll_timer, ifa->pollint);
OSPF_TRACE(D_EVENTS,
- "Changing poll interval on interface %s from %d to %d",
- ifa->iface->name,ip1->pollint,ip2->pollint);
+ "Changing poll interval on interface %s from %d to %d",
+ ifa->iface->name, ip1->pollint, ip2->pollint);
}
/* COST */
- if(ip1->cost!=ip2->cost)
+ if (ip1->cost != ip2->cost)
{
- ifa->cost=ip2->cost;
+ ifa->cost = ip2->cost;
OSPF_TRACE(D_EVENTS,
- "Changing cost interface %s from %d to %d",
- ifa->iface->name,ip1->cost,ip2->cost);
+ "Changing cost interface %s from %d to %d",
+ ifa->iface->name, ip1->cost, ip2->cost);
schedule_rt_lsa(ifa->oa);
}
/* strict nbma */
- if((ip1->strictnbma==0)&&(ip2->strictnbma!=0))
+ if ((ip1->strictnbma == 0) && (ip2->strictnbma != 0))
{
- ifa->strictnbma=ip2->strictnbma;
+ ifa->strictnbma = ip2->strictnbma;
OSPF_TRACE(D_EVENTS,
- "Interface %s is now strict NBMA.",
- ifa->iface->name);
+ "Interface %s is now strict NBMA.", ifa->iface->name);
}
- if((ip1->strictnbma!=0)&&(ip2->strictnbma==0))
+ if ((ip1->strictnbma != 0) && (ip2->strictnbma == 0))
{
- ifa->strictnbma=ip2->strictnbma;
+ ifa->strictnbma = ip2->strictnbma;
OSPF_TRACE(D_EVENTS,
- "Interface %s is no longer strict NBMA.",
- ifa->iface->name);
+ "Interface %s is no longer strict NBMA.",
+ ifa->iface->name);
}
/* stub */
- if((ip1->stub==0)&&(ip2->stub!=0))
+ if ((ip1->stub == 0) && (ip2->stub != 0))
{
- ifa->stub=ip2->stub;
- OSPF_TRACE(D_EVENTS,
- "Interface %s is now stub.",
- ifa->iface->name);
+ ifa->stub = ip2->stub;
+ OSPF_TRACE(D_EVENTS, "Interface %s is now stub.", ifa->iface->name);
}
- if((ip1->stub!=0)&&(ip2->stub==0)&&
- ((ifa->ioprob & OSPF_I_IP)==0)&&
- (((ifa->ioprob & OSPF_I_MC)==0)||
- (ifa->type==OSPF_IT_NBMA)))
+ if ((ip1->stub != 0) && (ip2->stub == 0) &&
+ ((ifa->ioprob & OSPF_I_IP) == 0) &&
+ (((ifa->ioprob & OSPF_I_MC) == 0) || (ifa->type == OSPF_IT_NBMA)))
{
- ifa->stub=ip2->stub;
+ ifa->stub = ip2->stub;
OSPF_TRACE(D_EVENTS,
- "Interface %s is no longer stub.",
- ifa->iface->name);
+ "Interface %s is no longer stub.", ifa->iface->name);
}
/* AUTHENTICATION */
- if(ip1->autype!=ip2->autype)
+ if (ip1->autype != ip2->autype)
{
- ifa->autype=ip2->autype;
+ ifa->autype = ip2->autype;
OSPF_TRACE(D_EVENTS,
- "Changing authentication type on interface %s",
- ifa->iface->name);
+ "Changing authentication type on interface %s",
+ ifa->iface->name);
}
- if(strncmp(ip1->password,ip2->password,8)!=0)
+ if (strncmp(ip1->password, ip2->password, 8) != 0)
{
- memcpy(ifa->aukey,ip2->password,8);
+ memcpy(ifa->aukey, ip2->password, 8);
OSPF_TRACE(D_EVENTS,
- "Changing password on interface %s",
- ifa->iface->name);
+ "Changing password on interface %s", ifa->iface->name);
}
/* RXMT */
- if(ip1->rxmtint!=ip2->rxmtint)
+ if (ip1->rxmtint != ip2->rxmtint)
{
- ifa->rxmtint=ip2->rxmtint;
+ ifa->rxmtint = ip2->rxmtint;
OSPF_TRACE(D_EVENTS,
- "Changing retransmit interval on interface %s from %d to %d",
- ifa->iface->name,ip1->rxmtint,ip2->rxmtint);
+ "Changing retransmit interval on interface %s from %d to %d",
+ ifa->iface->name, ip1->rxmtint, ip2->rxmtint);
}
/* WAIT */
- if(ip1->waitint!=ip2->waitint)
+ if (ip1->waitint != ip2->waitint)
{
- ifa->waitint=ip2->waitint;
- if(ifa->wait_timer->expires!=0)
- tm_start(ifa->wait_timer,ifa->waitint);
+ ifa->waitint = ip2->waitint;
+ if (ifa->wait_timer->expires != 0)
+ tm_start(ifa->wait_timer, ifa->waitint);
OSPF_TRACE(D_EVENTS,
- "Changing wait interval on interface %s from %d to %d",
- ifa->iface->name,ip1->waitint,ip2->waitint);
+ "Changing wait interval on interface %s from %d to %d",
+ ifa->iface->name, ip1->waitint, ip2->waitint);
}
/* INFTRANS */
- if(ip1->inftransdelay!=ip2->inftransdelay)
+ if (ip1->inftransdelay != ip2->inftransdelay)
{
- ifa->inftransdelay=ip2->inftransdelay;
+ ifa->inftransdelay = ip2->inftransdelay;
OSPF_TRACE(D_EVENTS,
- "Changing transmit delay on interface %s from %d to %d",
- ifa->iface->name,ip1->inftransdelay,ip2->inftransdelay);
+ "Changing transmit delay on interface %s from %d to %d",
+ ifa->iface->name, ip1->inftransdelay,
+ ip2->inftransdelay);
}
/* DEAD COUNT */
- if(ip1->deadc!=ip2->deadc)
+ if (ip1->deadc != ip2->deadc)
{
- ifa->deadc=ip2->deadc;
+ ifa->deadc = ip2->deadc;
OSPF_TRACE(D_EVENTS,
- "Changing dead count on interface %s from %d to %d",
- ifa->iface->name,ip1->deadc,ip2->deadc);
+ "Changing dead count on interface %s from %d to %d",
+ ifa->iface->name, ip1->deadc, ip2->deadc);
}
/* NBMA LIST */
/* First remove old */
WALK_LIST_DELSAFE(nb1, nbnx, ifa->nbma_list)
{
- found=0;
+ found = 0;
WALK_LIST(nb2, ip2->nbma_list)
- if(ipa_compare(nb1->ip,nb2->ip)==0)
- {
- found=1;
- if(nb1->eligible!=nb2->eligible)
- OSPF_TRACE(D_EVENTS,
- "Changing neighbor eligibility %I on interface %s",
- nb1->ip,ifa->iface->name);
- break;
- }
-
- if(!found)
+ if (ipa_compare(nb1->ip, nb2->ip) == 0)
+ {
+ found = 1;
+ if (nb1->eligible != nb2->eligible)
+ OSPF_TRACE(D_EVENTS,
+ "Changing neighbor eligibility %I on interface %s",
+ nb1->ip, ifa->iface->name);
+ break;
+ }
+
+ if (!found)
{
OSPF_TRACE(D_EVENTS,
- "Removing NBMA neighbor %I on interface %s",
- nb1->ip,ifa->iface->name);
+ "Removing NBMA neighbor %I on interface %s",
+ nb1->ip, ifa->iface->name);
rem_node(NODE nb1);
mb_free(nb1);
}
- }
+ }
/* And then add new */
WALK_LIST(nb2, ip2->nbma_list)
{
- found=0;
+ found = 0;
WALK_LIST(nb1, ifa->nbma_list)
- if(ipa_compare(nb1->ip,nb2->ip)==0)
- {
- found=1;
- break;
- }
- if(!found)
+ if (ipa_compare(nb1->ip, nb2->ip) == 0)
+ {
+ found = 1;
+ break;
+ }
+ if (!found)
{
- nb1=mb_alloc(p->pool,sizeof(struct nbma_node));
- nb1->ip=nb2->ip;
- nb1->eligible=nb2->eligible;
+ nb1 = mb_alloc(p->pool, sizeof(struct nbma_node));
+ nb1->ip = nb2->ip;
+ nb1->eligible = nb2->eligible;
add_tail(&ifa->nbma_list, NODE nb1);
OSPF_TRACE(D_EVENTS,
- "Adding NBMA neighbor %I on interface %s",
- nb1->ip,ifa->iface->name);
+ "Adding NBMA neighbor %I on interface %s",
+ nb1->ip, ifa->iface->name);
}
- }
+ }
}
}
- NODE ac1=(NODE (ac1))->next;
- NODE ac2=(NODE (ac2))->next;
+ NODE ac1 = (NODE(ac1))->next;
+ NODE ac2 = (NODE(ac2))->next;
}
- if(((NODE (ac1))->next)!=((NODE (ac2))->next))
- return 0; /* One is not null */
+ if (((NODE(ac1))->next) != ((NODE(ac2))->next))
+ return 0; /* One is not null */
- return 1; /* Everything OK :-) */
+ return 1; /* Everything OK :-) */
}
void
ospf_sh_neigh(struct proto *p, char *iff)
{
- struct ospf_iface *ifa=NULL,*f;
+ struct ospf_iface *ifa = NULL, *f;
struct ospf_neighbor *n;
- struct proto_ospf *po=(struct proto_ospf *)p;
+ struct proto_ospf *po = (struct proto_ospf *) p;
- if(p->proto_state != PS_UP)
+ if (p->proto_state != PS_UP)
{
- cli_msg(-1013,"%s: is not up", p->name);
- cli_msg(0,"");
+ cli_msg(-1013, "%s: is not up", p->name);
+ cli_msg(0, "");
return;
}
-
- if(iff!=NULL)
+
+ if (iff != NULL)
{
WALK_LIST(f, po->iface_list)
{
- if(strcmp(iff,f->iface->name)==0)
+ if (strcmp(iff, f->iface->name) == 0)
{
- ifa=f;
- break;
+ ifa = f;
+ break;
}
}
- if(ifa==NULL)
+ if (ifa == NULL)
{
- cli_msg(0,"");
+ cli_msg(0, "");
return;
}
- cli_msg(-1013,"%s:", p->name);
- cli_msg(-1013,"%-12s\t%3s\t%-15s\t%-5s\t%-12s\t%-10s","Router ID","Pri",
- " State", "DTime", "Router IP", "Interface");
+ cli_msg(-1013, "%s:", p->name);
+ cli_msg(-1013, "%-12s\t%3s\t%-15s\t%-5s\t%-12s\t%-10s", "Router ID",
+ "Pri", " State", "DTime", "Router IP", "Interface");
WALK_LIST(n, ifa->neigh_list) ospf_sh_neigh_info(n);
- cli_msg(0,"");
+ cli_msg(0, "");
return;
}
- cli_msg(-1013,"%s:", p->name);
- cli_msg(-1013,"%-12s\t%3s\t%-15s\t%-5s\t%-12s\t%-10s","Router ID","Pri",
- " State", "DTime", "Router IP", "Interface");
- WALK_LIST(ifa,po->iface_list)
- WALK_LIST(n, ifa->neigh_list)
- ospf_sh_neigh_info(n);
- cli_msg(0,"");
+ cli_msg(-1013, "%s:", p->name);
+ cli_msg(-1013, "%-12s\t%3s\t%-15s\t%-5s\t%-12s\t%-10s", "Router ID", "Pri",
+ " State", "DTime", "Router IP", "Interface");
+ WALK_LIST(ifa, po->iface_list)
+ WALK_LIST(n, ifa->neigh_list) ospf_sh_neigh_info(n);
+ cli_msg(0, "");
}
void
ospf_sh(struct proto *p)
{
struct ospf_area *oa;
- struct proto_ospf *po=(struct proto_ospf *)p;
+ struct proto_ospf *po = (struct proto_ospf *) p;
struct ospf_iface *ifa;
struct ospf_neighbor *n;
int ifano;
int nno;
int adjno;
- if(p->proto_state != PS_UP)
+ if (p->proto_state != PS_UP)
{
- cli_msg(-1014,"%s: is not up", p->name);
- cli_msg(0,"");
+ cli_msg(-1014, "%s: is not up", p->name);
+ cli_msg(0, "");
return;
}
- cli_msg(-1014,"%s:", p->name);
- cli_msg(-1014,"Number of areas: %u", po->areano);
-
- WALK_LIST(oa,po->area_list)
+ cli_msg(-1014, "%s:", p->name);
+ cli_msg(-1014, "Number of areas: %u", po->areano);
+
+ WALK_LIST(oa, po->area_list)
{
- cli_msg(-1014,"\tArea: %I (%u) %s", oa->areaid, oa->areaid,
- oa->areaid==0 ? "[BACKBONE]" : "");
- ifano=0;
- nno=0;
- adjno=0;
+ cli_msg(-1014, "\tArea: %I (%u) %s", oa->areaid, oa->areaid,
+ oa->areaid == 0 ? "[BACKBONE]" : "");
+ ifano = 0;
+ nno = 0;
+ adjno = 0;
WALK_LIST(ifa, po->iface_list)
{
- if(oa==ifa->oa) ifano++;
+ if (oa == ifa->oa)
+ ifano++;
WALK_LIST(n, ifa->neigh_list)
{
- nno++;
- if(n->state==NEIGHBOR_FULL) adjno++;
+ nno++;
+ if (n->state == NEIGHBOR_FULL)
+ adjno++;
}
}
- cli_msg(-1014,"\t\tStub:\t%s", oa->stub ? "Yes" : "No");
- cli_msg(-1014,"\t\tRT scheduler tick:\t%u", oa->tick);
- cli_msg(-1014,"\t\tNumber of interfaces:\t%u", ifano);
- cli_msg(-1014,"\t\tNumber of LSAs in DB:\t%u", oa->gr->hash_entries);
- cli_msg(-1014,"\t\tNumber of neighbors:\t%u", nno);
- cli_msg(-1014,"\t\tNumber of adjacent neighbors:\t%u", adjno);
- if(!EMPTY_LIST(oa->net_list))
+ cli_msg(-1014, "\t\tStub:\t%s", oa->stub ? "Yes" : "No");
+ cli_msg(-1014, "\t\tRT scheduler tick:\t%u", oa->tick);
+ cli_msg(-1014, "\t\tNumber of interfaces:\t%u", ifano);
+ cli_msg(-1014, "\t\tNumber of LSAs in DB:\t%u", oa->gr->hash_entries);
+ cli_msg(-1014, "\t\tNumber of neighbors:\t%u", nno);
+ cli_msg(-1014, "\t\tNumber of adjacent neighbors:\t%u", adjno);
+ if (!EMPTY_LIST(oa->net_list))
{
struct area_net *anet;
- cli_msg(-1014,"\t\tArea networks:");
+ cli_msg(-1014, "\t\tArea networks:");
WALK_LIST(anet, oa->net_list)
{
- cli_msg(-1014,"\t\t\t%1I/%u\t%s", anet->px.addr, anet->px.len,
- anet->hidden ? "Hidden" : "Advertise");
+ cli_msg(-1014, "\t\t\t%1I/%u\t%s", anet->px.addr, anet->px.len,
+ anet->hidden ? "Hidden" : "Advertise");
}
}
}
- cli_msg(0,"");
+ cli_msg(0, "");
}
void
ospf_sh_iface(struct proto *p, char *iff)
{
- struct proto_ospf *po=(struct proto_ospf *)p;
- struct ospf_iface *ifa=NULL,*f;
+ struct proto_ospf *po = (struct proto_ospf *) p;
+ struct ospf_iface *ifa = NULL, *f;
- if(p->proto_state != PS_UP)
+ if (p->proto_state != PS_UP)
{
- cli_msg(-1015,"%s: is not up", p->name);
- cli_msg(0,"");
+ cli_msg(-1015, "%s: is not up", p->name);
+ cli_msg(0, "");
return;
}
- if(iff!=NULL)
+ if (iff != NULL)
{
WALK_LIST(f, po->iface_list)
{
- if(strcmp(iff,f->iface->name)==0)
+ if (strcmp(iff, f->iface->name) == 0)
{
- ifa=f;
- break;
+ ifa = f;
+ break;
}
}
- if(ifa==NULL)
+ if (ifa == NULL)
{
- cli_msg(0,"");
+ cli_msg(0, "");
return;
}
- cli_msg(-1015,"%s:", p->name);
+ cli_msg(-1015, "%s:", p->name);
ospf_iface_info(ifa);
- cli_msg(0,"");
+ cli_msg(0, "");
return;
}
- cli_msg(-1015,"%s:", p->name);
+ cli_msg(-1015, "%s:", p->name);
WALK_LIST(ifa, po->iface_list) ospf_iface_info(ifa);
- cli_msg(0,"");
+ cli_msg(0, "");
}
struct protocol proto_ospf = {
- name: "OSPF",
- template: "ospf%d",
- attr_class: EAP_OSPF,
- init: ospf_init,
- dump: ospf_dump,
- start: ospf_start,
- shutdown: ospf_shutdown,
- get_route_info: ospf_get_route_info,
- get_attr: ospf_get_attr,
- get_status: ospf_get_status,
- reconfigure: ospf_reconfigure
+ name:"OSPF",
+ template:"ospf%d",
+ attr_class:EAP_OSPF,
+ init:ospf_init,
+ dump:ospf_dump,
+ start:ospf_start,
+ shutdown:ospf_shutdown,
+ get_route_info:ospf_get_route_info,
+ get_attr:ospf_get_attr,
+ get_status:ospf_get_status,
+ reconfigure:ospf_reconfigure
};
-
diff --git a/proto/ospf/ospf.h b/proto/ospf/ospf.h
index b0ac1e9f..cf984aaa 100644
--- a/proto/ospf/ospf.h
+++ b/proto/ospf/ospf.h
@@ -53,19 +53,22 @@
#define LSINFINITY 0xffff /* RFC says 0xffffff ??? */
#define DISPTICK 7
-struct ospf_config {
+struct ospf_config
+{
struct proto_config c;
int rfc1583;
list area_list;
};
-struct nbma_node {
+struct nbma_node
+{
node n;
ip_addr ip;
int eligible;
};
-struct area_net {
+struct area_net
+{
node n;
struct prefix px;
int hidden;
@@ -73,7 +76,8 @@ struct area_net {
int oldactive;
};
-struct ospf_area_config {
+struct ospf_area_config
+{
node n;
u32 areaid;
int stub;
@@ -82,47 +86,48 @@ struct ospf_area_config {
list net_list;
};
-struct ospf_iface {
+struct ospf_iface
+{
node n;
struct proto_ospf *proto;
- struct iface *iface; /* Nest's iface */
+ struct iface *iface; /* Nest's iface */
struct ospf_area *oa;
struct object_lock *lock;
- u32 an; /* Area number */
- sock *hello_sk; /* Hello socket */
- sock *dr_sk; /* For states DR or BACKUP */
- sock *ip_sk; /* IP socket (for DD ...) */
- list neigh_list; /* List of neigbours */
- u16 cost; /* Cost of iface */
- u16 rxmtint; /* number of seconds between LSA retransmissions */
- u16 inftransdelay; /* The estimated number of seconds it takes to
- transmit a Link State Update Packet over this
- interface. LSAs contained in the update */
- u8 priority; /* A router priority for DR election */
- u16 helloint; /* number of seconds between hello sending */
- u16 waitint; /* number of sec before changing state from wait */
- u16 pollint; /* Poll interval */
- u32 deadc; /* after "deadint" missing hellos is router dead */
+ u32 an; /* Area number */
+ sock *hello_sk; /* Hello socket */
+ sock *dr_sk; /* For states DR or BACKUP */
+ sock *ip_sk; /* IP socket (for DD ...) */
+ list neigh_list; /* List of neigbours */
+ u16 cost; /* Cost of iface */
+ u16 rxmtint; /* number of seconds between LSA retransmissions */
+ u16 inftransdelay; /* The estimated number of seconds it takes to
+ transmit a Link State Update Packet over this
+ interface. LSAs contained in the update */
+ u8 priority; /* A router priority for DR election */
+ u16 helloint; /* number of seconds between hello sending */
+ u16 waitint; /* number of sec before changing state from wait */
+ u16 pollint; /* Poll interval */
+ u32 deadc; /* after "deadint" missing hellos is router dead */
u16 autype;
u8 aukey[8];
u8 options;
- ip_addr drip; /* Designated router */
+ ip_addr drip; /* Designated router */
u32 drid;
- ip_addr bdrip; /* Backup DR */
+ ip_addr bdrip; /* Backup DR */
u32 bdrid;
- u8 type; /* OSPF view of type */
+ u8 type; /* OSPF view of type */
#define OSPF_IT_BCAST 0
#define OSPF_IT_NBMA 1
#define OSPF_IT_PTP 2
#define OSPF_IT_VLINK 3
#define OSPF_IT_UNDEF 4
- u8 strictnbma; /* Can I talk with unknown neighbors? */
- u8 stub; /* Inactive interface */
+ u8 strictnbma; /* Can I talk with unknown neighbors? */
+ u8 stub; /* Inactive interface */
u8 ioprob;
-#define OSPF_I_OK 0 /* Everything OK */
-#define OSPF_I_MC 1 /* I didn't open MC socket */
-#define OSPF_I_IP 2 /* I didn't open IP socet */
- u8 state; /* Interface state machine */
+#define OSPF_I_OK 0 /* Everything OK */
+#define OSPF_I_MC 1 /* I didn't open MC socket */
+#define OSPF_I_IP 2 /* I didn't open IP socet */
+ u8 state; /* Interface state machine */
#define OSPF_IS_DOWN 0 /* Not working */
#define OSPF_IS_LOOP 1 /* Should never happen */
#define OSPF_IS_WAITING 2 /* Waiting for Wait timer */
@@ -141,23 +146,24 @@ struct ospf_iface {
#define HELLOINT_D 10
#define POLLINT_D 20
#define DEADC_D 4
-#define WAIT_DMH 4 /* Value of Wait timer - not found it in RFC
- * - using 4*HELLO
- */
+#define WAIT_DMH 4 /* Value of Wait timer - not found it in RFC
+ * - using 4*HELLO
+ */
struct top_hash_entry *nlsa; /* Originated net lsa */
- int orignet; /* Schedule network LSA origination */
- int fadj; /* Number of full adjacent neigh */
+ int orignet; /* Schedule network LSA origination */
+ int fadj; /* Number of full adjacent neigh */
list nbma_list;
};
-struct ospf_packet {
+struct ospf_packet
+{
u8 version;
u8 type;
-#define HELLO_P 1 /* Hello */
-#define DBDES_P 2 /* Database description */
-#define LSREQ_P 3 /* Link state request */
-#define LSUPD_P 4 /* Link state update */
-#define LSACK_P 5 /* Link state acknowledgement */
+#define HELLO_P 1 /* Hello */
+#define DBDES_P 2 /* Database description */
+#define LSREQ_P 3 /* Link state request */
+#define LSUPD_P 4 /* Link state update */
+#define LSACK_P 5 /* Link state acknowledgement */
u16 length;
u32 routerid;
u32 areaid;
@@ -167,7 +173,8 @@ struct ospf_packet {
u8 authetication[8];
};
-struct ospf_hello_packet {
+struct ospf_hello_packet
+{
struct ospf_packet ospf_packet;
ip_addr netmask;
u16 helloint;
@@ -178,7 +185,8 @@ struct ospf_hello_packet {
ip_addr bdr;
};
-struct immsb {
+struct immsb
+{
#ifdef _BIG_ENDIAN
u8 padding:5;
u8 i:1;
@@ -192,12 +200,14 @@ struct immsb {
#endif
};
-union imms {
+union imms
+{
u8 byte;
struct immsb bit;
};
-struct ospf_dbdes_packet {
+struct ospf_dbdes_packet
+{
struct ospf_packet ospf_packet;
u16 iface_mtu;
u8 options;
@@ -209,11 +219,12 @@ struct ospf_dbdes_packet {
};
-struct ospf_lsa_header {
- u16 age; /* LS Age */
-#define LSA_MAXAGE 3600 /* 1 hour */
-#define LSA_CHECKAGE 300 /* 5 minutes */
-#define LSA_MAXAGEDIFF 900 /* 15 minutes */
+struct ospf_lsa_header
+{
+ u16 age; /* LS Age */
+#define LSA_MAXAGE 3600 /* 1 hour */
+#define LSA_CHECKAGE 300 /* 5 minutes */
+#define LSA_MAXAGEDIFF 900 /* 15 minutes */
u8 options;
u8 type;
u32 id;
@@ -222,27 +233,30 @@ struct ospf_lsa_header {
#define LSA_T_SUM_NET 3
#define LSA_T_SUM_RT 4
#define LSA_T_EXT 5
- u32 rt; /* Advertising router */
- s32 sn; /* LS Sequence number */
+ u32 rt; /* Advertising router */
+ s32 sn; /* LS Sequence number */
#define LSA_INITSEQNO 0x80000001
#define LSA_MAXSEQNO 0x7fffffff
u16 checksum;
- u16 length;
+ u16 length;
};
-struct vebb {
+struct vebb
+{
u8 b:1;
u8 e:1;
u8 v:1;
u8 padding:5;
};
-union veb {
+union veb
+{
u8 byte;
struct vebb bit;
};
-struct ospf_lsa_rt {
+struct ospf_lsa_rt
+{
union veb veb;
#define LSA_RT_V 5
#define LSA_RT_E 6
@@ -251,7 +265,8 @@ struct ospf_lsa_rt {
u16 links;
};
-struct ospf_lsa_rt_link {
+struct ospf_lsa_rt_link
+{
u32 id;
u32 data;
u8 type;
@@ -263,31 +278,37 @@ struct ospf_lsa_rt_link {
u16 metric;
};
-struct ospf_lsa_rt_link_tos { /* Actually we ignore TOS. This is useless */
+struct ospf_lsa_rt_link_tos
+{ /* Actually we ignore TOS. This is useless */
u8 tos;
u8 padding;
u16 metric;
};
-struct ospf_lsa_net {
+struct ospf_lsa_net
+{
ip_addr netmask;
};
-struct ospf_lsa_summ {
+struct ospf_lsa_summ
+{
ip_addr netmask;
};
-struct ospf_lsa_summ_net {
+struct ospf_lsa_summ_net
+{
u8 tos;
u8 padding;
u16 metric;
};
-struct ospf_lsa_ext {
+struct ospf_lsa_ext
+{
ip_addr netmask;
};
-struct ospf_lsa_ext_tos {
+struct ospf_lsa_ext_tos
+{
u8 etos;
u8 padding;
u16 metric;
@@ -295,29 +316,34 @@ struct ospf_lsa_ext_tos {
u32 tag;
};
-struct ospf_lsreq_packet {
+struct ospf_lsreq_packet
+{
struct ospf_packet ospf_packet;
};
-struct ospf_lsreq_header {
+struct ospf_lsreq_header
+{
u16 padd1;
u8 padd2;
u8 type;
u32 id;
- u32 rt; /* Advertising router */
+ u32 rt; /* Advertising router */
};
-struct l_lsr_head {
+struct l_lsr_head
+{
node n;
struct ospf_lsreq_header lsh;
};
-struct ospf_lsupd_packet {
+struct ospf_lsupd_packet
+{
struct ospf_packet ospf_packet;
- u32 lsano; /* Number of LSA's */
+ u32 lsano; /* Number of LSA's */
};
-struct ospf_lsack_packet {
+struct ospf_lsack_packet
+{
struct ospf_packet ospf_packet;
};
@@ -336,58 +362,59 @@ struct ospf_neighbor
#define NEIGHBOR_EXCHANGE 5
#define NEIGHBOR_LOADING 6
#define NEIGHBOR_FULL 7
- timer *inactim; /* Inactivity timer */
+ timer *inactim; /* Inactivity timer */
union imms imms; /* I, M, Master/slave received */
- u32 dds; /* DD Sequence number being sent */
- u32 ddr; /* last Dat Des packet received */
+ u32 dds; /* DD Sequence number being sent */
+ u32 ddr; /* last Dat Des packet received */
union imms myimms; /* I, M Master/slave */
- u32 rid; /* Router ID */
- ip_addr ip; /* IP of it's interface */
- u8 priority; /* Priority */
- u8 options; /* Options received */
- ip_addr dr; /* Neigbour's idea of DR */
- ip_addr bdr; /* Neigbour's idea of BDR */
- u8 adj; /* built adjacency? */
- siterator dbsi; /* Database summary list iterator */
- slist lsrql; /* Link state request */
- struct top_graph *lsrqh; /* LSA graph */
+ u32 rid; /* Router ID */
+ ip_addr ip; /* IP of it's interface */
+ u8 priority; /* Priority */
+ u8 options; /* Options received */
+ ip_addr dr; /* Neigbour's idea of DR */
+ ip_addr bdr; /* Neigbour's idea of BDR */
+ u8 adj; /* built adjacency? */
+ siterator dbsi; /* Database summary list iterator */
+ slist lsrql; /* Link state request */
+ struct top_graph *lsrqh; /* LSA graph */
siterator lsrqi;
- slist lsrtl; /* Link state retransmission list */
+ slist lsrtl; /* Link state retransmission list */
siterator lsrti;
struct top_graph *lsrth;
- void *ldbdes; /* Last database description packet */
- timer *rxmt_timer; /* RXMT timer */
+ void *ldbdes; /* Last database description packet */
+ timer *rxmt_timer; /* RXMT timer */
list ackl[2];
#define ACKL_DIRECT 0
#define ACKL_DELAY 1
- timer *ackd_timer; /* Delayed ack timer */
+ timer *ackd_timer; /* Delayed ack timer */
};
/* Definitions for interface state machine */
-#define ISM_UP 0 /* Interface Up */
-#define ISM_WAITF 1 /* Wait timer fired */
-#define ISM_BACKS 2 /* Backup seen */
-#define ISM_NEICH 3 /* Neighbor change */
-#define ISM_LOOP 4 /* Loop indicated */
-#define ISM_UNLOOP 5 /* Unloop indicated */
-#define ISM_DOWN 6 /* Interface down */
+#define ISM_UP 0 /* Interface Up */
+#define ISM_WAITF 1 /* Wait timer fired */
+#define ISM_BACKS 2 /* Backup seen */
+#define ISM_NEICH 3 /* Neighbor change */
+#define ISM_LOOP 4 /* Loop indicated */
+#define ISM_UNLOOP 5 /* Unloop indicated */
+#define ISM_DOWN 6 /* Interface down */
/* Definitions for neighbor state machine */
-#define INM_HELLOREC 0 /* Hello Received */
-#define INM_START 1 /* Neighbor start - for NBMA */
-#define INM_2WAYREC 2 /* 2-Way received */
-#define INM_NEGDONE 3 /* Negotiation done */
-#define INM_EXDONE 4 /* Exchange done */
-#define INM_BADLSREQ 5 /* Bad LS Request */
-#define INM_LOADDONE 6 /* Load done */
-#define INM_ADJOK 7 /* AdjOK? */
-#define INM_SEQMIS 8 /* Sequence number mismatch */
-#define INM_1WAYREC 9 /* 1-Way */
-#define INM_KILLNBR 10 /* Kill Neighbor */
-#define INM_INACTTIM 11 /* Inactivity timer */
-#define INM_LLDOWN 12 /* Line down */
-
-struct ospf_area {
+#define INM_HELLOREC 0 /* Hello Received */
+#define INM_START 1 /* Neighbor start - for NBMA */
+#define INM_2WAYREC 2 /* 2-Way received */
+#define INM_NEGDONE 3 /* Negotiation done */
+#define INM_EXDONE 4 /* Exchange done */
+#define INM_BADLSREQ 5 /* Bad LS Request */
+#define INM_LOADDONE 6 /* Load done */
+#define INM_ADJOK 7 /* AdjOK? */
+#define INM_SEQMIS 8 /* Sequence number mismatch */
+#define INM_1WAYREC 9 /* 1-Way */
+#define INM_KILLNBR 10 /* Kill Neighbor */
+#define INM_INACTTIM 11 /* Inactivity timer */
+#define INM_LLDOWN 12 /* Line down */
+
+struct ospf_area
+{
node n;
u32 areaid;
timer *disp_timer; /* Area's dispatcher hear beat */
@@ -405,7 +432,8 @@ struct ospf_area {
unsigned tick;
};
-struct proto_ospf {
+struct proto_ospf
+{
struct proto proto;
list iface_list; /* Interfaces we really use */
list area_list;
@@ -415,14 +443,15 @@ struct proto_ospf {
int ebit; /* Did I originate any ext lsa? */
};
-struct ospf_iface_patt {
+struct ospf_iface_patt
+{
struct iface_patt i;
int cost;
int helloint;
int rxmtint;
int pollint;
- int inftransdelay;
- int priority;
+ int inftransdelay;
+ int priority;
int waitint;
int deadc;
int type;
@@ -437,12 +466,13 @@ struct ospf_iface_patt {
list nbma_list;
};
-int ospf_import_control(struct proto *p, rte **new, ea_list **attrs,
- struct linpool *pool);
+int ospf_import_control(struct proto *p, rte ** new, ea_list ** attrs,
+ struct linpool *pool);
struct ea_list *ospf_make_tmp_attrs(struct rte *rt, struct linpool *pool);
void ospf_store_tmp_attrs(struct rte *rt, struct ea_list *attrs);
-void ospf_rt_notify(struct proto *p, net *n, rte *new, rte *old,ea_list *attrs);
-void area_disp(timer *timer);
+void ospf_rt_notify(struct proto *p, net * n, rte * new, rte * old,
+ ea_list * attrs);
+void area_disp(timer * timer);
void schedule_rt_lsa(struct ospf_area *oa);
void schedule_rtcalc(struct ospf_area *oa);
void schedule_net_lsa(struct ospf_iface *ifa);
diff --git a/proto/ospf/packet.c b/proto/ospf/packet.c
index 7bdc104a..4d782b8f 100644
--- a/proto/ospf/packet.c
+++ b/proto/ospf/packet.c
@@ -9,7 +9,7 @@
#include "ospf.h"
void
-fill_ospf_pkt_hdr (struct ospf_iface *ifa, void *buf, u8 h_type)
+fill_ospf_pkt_hdr(struct ospf_iface *ifa, void *buf, u8 h_type)
{
struct ospf_packet *pkt;
struct proto *p;
@@ -22,51 +22,51 @@ fill_ospf_pkt_hdr (struct ospf_iface *ifa, void *buf, u8 h_type)
pkt->type = h_type;
- pkt->routerid = htonl (p->cf->global->router_id);
- pkt->areaid = htonl (ifa->an);
- pkt->autype = htons (ifa->autype);
+ pkt->routerid = htonl(p->cf->global->router_id);
+ pkt->areaid = htonl(ifa->an);
+ pkt->autype = htons(ifa->autype);
pkt->checksum = 0;
}
void
-ospf_tx_authenticate (struct ospf_iface *ifa, struct ospf_packet *pkt)
+ospf_tx_authenticate(struct ospf_iface *ifa, struct ospf_packet *pkt)
{
- pkt->autype = htons (ifa->autype);
- memcpy (pkt->authetication, ifa->aukey, 8);
+ pkt->autype = htons(ifa->autype);
+ memcpy(pkt->authetication, ifa->aukey, 8);
return;
}
static int
-ospf_rx_authenticate (struct ospf_iface *ifa, struct ospf_packet *pkt)
+ospf_rx_authenticate(struct ospf_iface *ifa, struct ospf_packet *pkt)
{
int i;
- if (pkt->autype != htons (ifa->autype))
+ if (pkt->autype != htons(ifa->autype))
return 0;
if (ifa->autype == AU_NONE)
return 1;
if (ifa->autype == AU_SIMPLE)
+ {
+ for (i = 0; i < 8; i++)
{
- for (i = 0; i < 8; i++)
- {
- if (pkt->authetication[i] != ifa->aukey[i])
- return 0;
- }
- return 1;
+ if (pkt->authetication[i] != ifa->aukey[i])
+ return 0;
}
+ return 1;
+ }
return 0;
}
void
-ospf_pkt_finalize (struct ospf_iface *ifa, struct ospf_packet *pkt)
+ospf_pkt_finalize(struct ospf_iface *ifa, struct ospf_packet *pkt)
{
- ospf_tx_authenticate (ifa, pkt);
+ ospf_tx_authenticate(ifa, pkt);
/* Count checksum */
- pkt->checksum = ipsum_calculate (pkt, sizeof (struct ospf_packet) - 8,
- (pkt + 1),
- ntohs (pkt->length) -
- sizeof (struct ospf_packet), NULL);
+ pkt->checksum = ipsum_calculate(pkt, sizeof(struct ospf_packet) - 8,
+ (pkt + 1),
+ ntohs(pkt->length) -
+ sizeof(struct ospf_packet), NULL);
}
/**
@@ -79,7 +79,7 @@ ospf_pkt_finalize (struct ospf_iface *ifa, struct ospf_packet *pkt)
* non generic functions.
*/
int
-ospf_rx_hook (sock *sk, int size)
+ospf_rx_hook(sock * sk, int size)
{
#ifndef IPV6
struct ospf_packet *ps;
@@ -89,76 +89,71 @@ ospf_rx_hook (sock *sk, int size)
if (ifa->stub)
return (1);
- DBG ("%s: RX_Hook called on interface %s.\n", p->name, sk->iface->name);
+ DBG("%s: RX_Hook called on interface %s.\n", p->name, sk->iface->name);
- ps = (struct ospf_packet *) ipv4_skip_header (sk->rbuf, &size);
+ ps = (struct ospf_packet *) ipv4_skip_header(sk->rbuf, &size);
if (ps == NULL)
- {
- log ("%s: Bad OSPF packet received: bad IP header", p->name);
- log ("%s: Discarding", p->name);
- return (1);
- }
+ {
+ log("%s: Bad OSPF packet received: bad IP header", p->name);
+ log("%s: Discarding", p->name);
+ return (1);
+ }
- if ((unsigned) size < sizeof (struct ospf_packet))
- {
- log ("%s: Bad OSPF packet received: too short (%u bytes)", p->name,
- size);
- log ("%s: Discarding", p->name);
- return (1);
- }
+ if ((unsigned) size < sizeof(struct ospf_packet))
+ {
+ log("%s: Bad OSPF packet received: too short (%u bytes)", p->name, size);
+ log("%s: Discarding", p->name);
+ return (1);
+ }
- if ((ntohs (ps->length) != size) || (size != (4 * (size / 4))))
- {
- log ("%s: Bad OSPF packet received: size field does not match",
- p->name);
- log ("%s: Discarding", p->name);
- return (1);
- }
+ if ((ntohs(ps->length) != size) || (size != (4 * (size / 4))))
+ {
+ log("%s: Bad OSPF packet received: size field does not match", p->name);
+ log("%s: Discarding", p->name);
+ return (1);
+ }
if (ps->version != OSPF_VERSION)
- {
- log ("%s: Bad OSPF packet received: version %u", p->name, ps->version);
- log ("%s: Discarding", p->name);
- return (1);
- }
+ {
+ log("%s: Bad OSPF packet received: version %u", p->name, ps->version);
+ log("%s: Discarding", p->name);
+ return (1);
+ }
- if (!ipsum_verify (ps, 16, (void *) ps + sizeof (struct ospf_packet),
- ntohs (ps->length) - sizeof (struct ospf_packet), NULL))
- {
- log ("%s: Bad OSPF packet received: bad checksum", p->name);
- log ("%s: Discarding", p->name);
- return (1);
- }
+ if (!ipsum_verify(ps, 16, (void *) ps + sizeof(struct ospf_packet),
+ ntohs(ps->length) - sizeof(struct ospf_packet), NULL))
+ {
+ log("%s: Bad OSPF packet received: bad checksum", p->name);
+ log("%s: Discarding", p->name);
+ return (1);
+ }
- if (!ospf_rx_authenticate (ifa, ps))
- {
- log ("%s: Bad OSPF packet received: bad password", p->name);
- return (1);
- }
+ if (!ospf_rx_authenticate(ifa, ps))
+ {
+ log("%s: Bad OSPF packet received: bad password", p->name);
+ return (1);
+ }
- if (ntohl (ps->areaid) != ifa->an)
- {
- log ("%s: Bad OSPF packet received: other area %ld", p->name,
- ps->areaid);
- log ("%s: Discarding", p->name);
- return (1);
- }
+ if (ntohl(ps->areaid) != ifa->an)
+ {
+ log("%s: Bad OSPF packet received: other area %ld", p->name, ps->areaid);
+ log("%s: Discarding", p->name);
+ return (1);
+ }
- if (ntohl (ps->routerid) == p->cf->global->router_id)
- {
- log ("%s: Bad OSPF packet received: received my own router ID!",
- p->name);
- log ("%s: Discarding", p->name);
- return (1);
- }
+ if (ntohl(ps->routerid) == p->cf->global->router_id)
+ {
+ log("%s: Bad OSPF packet received: received my own router ID!", p->name);
+ log("%s: Discarding", p->name);
+ return (1);
+ }
- if (ntohl (ps->routerid) == 0)
- {
- log ("%s: Bad OSPF packet received: Id 0.0.0.0 is not allowed.",
- p->name);
- log ("%s: Discarding", p->name);
- return (1);
- }
+ if (ntohl(ps->routerid) == 0)
+ {
+ log("%s: Bad OSPF packet received: Id 0.0.0.0 is not allowed.", p->name);
+ log("%s: Discarding", p->name);
+ return (1);
+ }
/* Dump packet
pu8=(u8 *)(sk->rbuf+5*4);
@@ -169,33 +164,32 @@ ospf_rx_hook (sock *sk, int size)
*/
switch (ps->type)
- {
- case HELLO_P:
- DBG ("%s: Hello received.\n", p->name);
- ospf_hello_receive((struct ospf_hello_packet *) ps, ifa, size,
- sk->faddr);
- break;
- case DBDES_P:
- DBG ("%s: Database description received.\n", p->name);
- ospf_dbdes_receive ((struct ospf_dbdes_packet *) ps, ifa, size);
- break;
- case LSREQ_P:
- DBG ("%s: Link state request received.\n", p->name);
- ospf_lsreq_receive((struct ospf_lsreq_packet *) ps, ifa, size);
- break;
- case LSUPD_P:
- DBG ("%s: Link state update received.\n", p->name);
- ospf_lsupd_receive((struct ospf_lsupd_packet *) ps, ifa, size);
- break;
- case LSACK_P:
- DBG ("%s: Link state ack received.\n", p->name);
- ospf_lsack_receive((struct ospf_lsack_packet *) ps, ifa, size);
- break;
- default:
- log ("%s: Bad packet received: wrong type %u", p->name, ps->type);
- log ("%s: Discarding\n", p->name);
- return (1);
- };
+ {
+ case HELLO_P:
+ DBG("%s: Hello received.\n", p->name);
+ ospf_hello_receive((struct ospf_hello_packet *) ps, ifa, size, sk->faddr);
+ break;
+ case DBDES_P:
+ DBG("%s: Database description received.\n", p->name);
+ ospf_dbdes_receive((struct ospf_dbdes_packet *) ps, ifa, size);
+ break;
+ case LSREQ_P:
+ DBG("%s: Link state request received.\n", p->name);
+ ospf_lsreq_receive((struct ospf_lsreq_packet *) ps, ifa, size);
+ break;
+ case LSUPD_P:
+ DBG("%s: Link state update received.\n", p->name);
+ ospf_lsupd_receive((struct ospf_lsupd_packet *) ps, ifa, size);
+ break;
+ case LSACK_P:
+ DBG("%s: Link state ack received.\n", p->name);
+ ospf_lsack_receive((struct ospf_lsack_packet *) ps, ifa, size);
+ break;
+ default:
+ log("%s: Bad packet received: wrong type %u", p->name, ps->type);
+ log("%s: Discarding\n", p->name);
+ return (1);
+ };
#else
#error RX_Hook does not work for IPv6 now.
#endif
@@ -203,7 +197,7 @@ ospf_rx_hook (sock *sk, int size)
}
void
-ospf_tx_hook (sock * sk)
+ospf_tx_hook(sock * sk)
{
struct ospf_iface *ifa;
struct proto *p;
@@ -211,11 +205,11 @@ ospf_tx_hook (sock * sk)
ifa = (struct ospf_iface *) (sk->data);
p = (struct proto *) (ifa->proto);
- DBG ("%s: TX_Hook called on interface %s\n", p->name, sk->iface->name);
+ DBG("%s: TX_Hook called on interface %s\n", p->name, sk->iface->name);
}
void
-ospf_err_hook (sock * sk, int err UNUSED)
+ospf_err_hook(sock * sk, int err UNUSED)
{
struct ospf_iface *ifa;
struct proto *p;
@@ -223,23 +217,23 @@ ospf_err_hook (sock * sk, int err UNUSED)
ifa = (struct ospf_iface *) (sk->data);
p = (struct proto *) (ifa->proto);
- DBG ("%s: Err_Hook called on interface %s\n", p->name, sk->iface->name);
+ DBG("%s: Err_Hook called on interface %s\n", p->name, sk->iface->name);
}
void
-sk_send_to_agt (sock * sk, u16 len, struct ospf_iface *ifa, u8 state)
+sk_send_to_agt(sock * sk, u16 len, struct ospf_iface *ifa, u8 state)
{
struct ospf_neighbor *n;
- WALK_LIST (NODE n, ifa->neigh_list) if (n->state >= state)
- sk_send_to (sk, len, n->ip, OSPF_PROTO);
+ WALK_LIST(NODE n, ifa->neigh_list) if (n->state >= state)
+ sk_send_to(sk, len, n->ip, OSPF_PROTO);
}
void
-sk_send_to_bdr (sock * sk, u16 len, struct ospf_iface *ifa)
+sk_send_to_bdr(sock * sk, u16 len, struct ospf_iface *ifa)
{
- if (ipa_compare (ifa->drip, ipa_from_u32 (0)) != 0)
- sk_send_to (sk, len, ifa->drip, OSPF_PROTO);
- if (ipa_compare (ifa->bdrip, ipa_from_u32 (0)) != 0)
- sk_send_to (sk, len, ifa->bdrip, OSPF_PROTO);
+ if (ipa_compare(ifa->drip, ipa_from_u32(0)) != 0)
+ sk_send_to(sk, len, ifa->drip, OSPF_PROTO);
+ if (ipa_compare(ifa->bdrip, ipa_from_u32(0)) != 0)
+ sk_send_to(sk, len, ifa->bdrip, OSPF_PROTO);
}
diff --git a/proto/ospf/packet.h b/proto/ospf/packet.h
index 4e3a1db7..fa2c85d2 100644
--- a/proto/ospf/packet.h
+++ b/proto/ospf/packet.h
@@ -13,10 +13,10 @@
void fill_ospf_pkt_hdr(struct ospf_iface *ifa, void *buf, u8 h_type);
void ospf_tx_authenticate(struct ospf_iface *ifa, struct ospf_packet *pkt);
void ospf_pkt_finalize(struct ospf_iface *ifa, struct ospf_packet *pkt);
-int ospf_rx_hook(sock *sk, int size);
-void ospf_tx_hook(sock *sk);
-void ospf_err_hook(sock *sk, int err);
-void sk_send_to_agt(sock *sk, u16 len, struct ospf_iface *ifa, u8 state);
-void sk_send_to_bdr(sock *sk, u16 len, struct ospf_iface *ifa);
+int ospf_rx_hook(sock * sk, int size);
+void ospf_tx_hook(sock * sk);
+void ospf_err_hook(sock * sk, int err);
+void sk_send_to_agt(sock * sk, u16 len, struct ospf_iface *ifa, u8 state);
+void sk_send_to_bdr(sock * sk, u16 len, struct ospf_iface *ifa);
#endif /* _BIRD_OSPF_PACKET_H_ */
diff --git a/proto/ospf/rt.c b/proto/ospf/rt.c
index 72076bcd..f7453bd3 100644
--- a/proto/ospf/rt.c
+++ b/proto/ospf/rt.c
@@ -11,26 +11,26 @@
void
init_infib(struct fib_node *fn)
{
- struct infib *f=(struct infib *)fn;
+ struct infib *f = (struct infib *) fn;
- f->metric=LSINFINITY;
- f->oldmetric=LSINFINITY;
- f->en=NULL;
- f->olden=NULL;
+ f->metric = LSINFINITY;
+ f->oldmetric = LSINFINITY;
+ f->en = NULL;
+ f->olden = NULL;
}
void
init_efib(struct fib_node *fn)
{
- struct extfib *f=(struct extfib *)fn;
-
- f->metric=LSINFINITY;
- f->metric2=LSINFINITY;
- f->nh=ipa_from_u32(0);
- f->nhi=NULL;
- f->oldmetric=LSINFINITY;
- f->oldmetric2=LSINFINITY;
- f->oldnh=ipa_from_u32(0);
+ struct extfib *f = (struct extfib *) fn;
+
+ f->metric = LSINFINITY;
+ f->metric2 = LSINFINITY;
+ f->nh = ipa_from_u32(0);
+ f->nhi = NULL;
+ f->oldmetric = LSINFINITY;
+ f->oldmetric2 = LSINFINITY;
+ f->oldnh = ipa_from_u32(0);
}
/**
@@ -46,148 +46,158 @@ init_efib(struct fib_node *fn)
void
ospf_rt_spfa(struct ospf_area *oa)
{
- u32 i,*rts;
+ u32 i, *rts;
struct ospf_lsa_rt *rt;
- struct ospf_lsa_rt_link *rtl,*rr;
- struct fib *in=&oa->infib;
+ struct ospf_lsa_rt_link *rtl, *rr;
+ struct fib *in = &oa->infib;
struct infib *nf;
struct fib_iterator fit;
- struct proto *p=&oa->po->proto;
- struct proto_ospf *po=oa->po;
+ struct proto *p = &oa->po->proto;
+ struct proto_ospf *po = oa->po;
ip_addr ip;
struct ospf_lsa_net *ln;
OSPF_TRACE(D_EVENTS, "Starting routing table calculation for area %I",
- oa->areaid);
+ oa->areaid);
- if(oa->rt==NULL) return;
+ if (oa->rt == NULL)
+ return;
- FIB_WALK(in,nftmp)
+ FIB_WALK(in, nftmp)
{
- nf=(struct infib *)nftmp;
- nf->metric=LSINFINITY;
- nf->en=NULL;
+ nf = (struct infib *) nftmp;
+ nf->metric = LSINFINITY;
+ nf->en = NULL;
}
FIB_WALK_END;
init_list(&oa->cand); /* Empty list of candidates */
- oa->trcap=0;
+ oa->trcap = 0;
DBG("LSA db prepared, adding me into candidate list.\n");
- oa->rt->dist=0;
- oa->rt->color=CANDIDATE;
+ oa->rt->dist = 0;
+ oa->rt->color = CANDIDATE;
add_head(&oa->cand, &oa->rt->cn);
- DBG("RT LSA: rt: %I, id: %I, type: %u\n",oa->rt->lsa.rt,
- oa->rt->lsa.id,oa->rt->lsa.type);
+ DBG("RT LSA: rt: %I, id: %I, type: %u\n", oa->rt->lsa.rt,
+ oa->rt->lsa.id, oa->rt->lsa.type);
- while(!EMPTY_LIST(oa->cand))
+ while (!EMPTY_LIST(oa->cand))
{
- struct top_hash_entry *act,*tmp;
+ struct top_hash_entry *act, *tmp;
node *n;
u16 met;
- n=HEAD(oa->cand);
- act=SKIP_BACK(struct top_hash_entry, cn, n);
+ n = HEAD(oa->cand);
+ act = SKIP_BACK(struct top_hash_entry, cn, n);
rem_node(n);
- DBG("Working on LSA: rt: %I, id: %I, type: %u\n",act->lsa.rt,
- act->lsa.id,act->lsa.type);
+ DBG("Working on LSA: rt: %I, id: %I, type: %u\n", act->lsa.rt,
+ act->lsa.id, act->lsa.type);
- act->color=INSPF;
- switch(act->lsa.type)
+ act->color = INSPF;
+ switch (act->lsa.type)
{
- case LSA_T_RT:
- rt=(struct ospf_lsa_rt *)act->lsa_body;
- if(rt->veb.bit.v) oa->trcap=1;
- rr=(struct ospf_lsa_rt_link *)(rt+1);
- DBG(" Number of links: %u\n",rt->links);
- for(i=0;i<rt->links;i++)
+ case LSA_T_RT:
+ rt = (struct ospf_lsa_rt *) act->lsa_body;
+ if (rt->veb.bit.v)
+ oa->trcap = 1;
+ rr = (struct ospf_lsa_rt_link *) (rt + 1);
+ DBG(" Number of links: %u\n", rt->links);
+ for (i = 0; i < rt->links; i++)
+ {
+ tmp = NULL;
+ rtl = (rr + i);
+ DBG(" Working on link: %I (type: %u) ", rtl->id, rtl->type);
+ switch (rtl->type)
{
- tmp=NULL;
- rtl=(rr+i);
- DBG(" Working on link: %I (type: %u) ",rtl->id,rtl->type);
- switch(rtl->type)
+ case LSART_STUB:
+ /* This violates rfc2328! but I hope it's also correct. */
+ DBG("\n");
+ ip = ipa_from_u32(rtl->id);
+ nf = fib_get(in, &ip, ipa_mklen(ipa_from_u32(rtl->data)));
+ if (nf->metric > (met = act->dist + rtl->metric))
{
- case LSART_STUB:
- /* This violates rfc2328! but I hope it's also correct. */
- DBG("\n");
- ip=ipa_from_u32(rtl->id);
- nf=fib_get(in,&ip, ipa_mklen(ipa_from_u32(rtl->data)));
- if(nf->metric>(met=act->dist+rtl->metric))
- {
- DBG(" Adding stub route....\n");
- if(oa->rt==act) break;
- if(act->nhi==NULL) break;
- nf->metric=met;
- nf->en=act;
- DBG(" Adding stub route: %I\n",ip);
- DBG(" Next hop=%I\n",nf->en->nh);
- }
- else DBG(" NOT adding stub route: %I\n",ip);
- break;
- case LSART_VLNK:
- DBG("Ignoring\n");
- continue;
- break;
- case LSART_NET:
- tmp=ospf_hash_find(oa->gr,rtl->id,rtl->id,LSA_T_NET);
- if(tmp==NULL) DBG("Not found!\n");
- else DBG("Found. :-)\n");
- break;
- case LSART_PTP:
- tmp=ospf_hash_find(oa->gr,rtl->id,rtl->id,LSA_T_RT);
- DBG("PTP found.\n");
+ DBG(" Adding stub route....\n");
+ if (oa->rt == act)
break;
- default:
- log("Unknown link type in router lsa.");
+ if (act->nhi == NULL)
break;
+ nf->metric = met;
+ nf->en = act;
+ DBG(" Adding stub route: %I\n", ip);
+ DBG(" Next hop=%I\n", nf->en->nh);
}
- if(tmp) DBG("Going to add cand, Mydist: %u, Req: %u\n",
- tmp->dist, act->dist+rtl->metric);
- add_cand(&oa->cand,tmp,act,act->dist+rtl->metric,oa);
- }
- break;
- case LSA_T_NET:
- ln=act->lsa_body;
- ip=ipa_and(ipa_from_u32(act->lsa.id),ln->netmask);
- nf=fib_get(in,&ip, ipa_mklen(ln->netmask));
- if(nf->metric>act->dist)
- {
- nf->metric=act->dist;
- nf->en=act;
- DBG(" Adding into routing table\n");
- }
- rts=(u32 *)(ln+1);
- for(i=0;i<(act->lsa.length-sizeof(struct ospf_lsa_header)-
- sizeof(struct ospf_lsa_net))/sizeof(u32);i++)
- {
- DBG(" Working on router %I ", *(rts+i));
- tmp=ospf_hash_find(oa->gr, *(rts+i), *(rts+i), LSA_T_RT);
- if(tmp!=NULL) DBG("Found :-)\n");
- else DBG("Not found!\n");
- add_cand(&oa->cand,tmp,act,act->dist,oa);
+ else
+ DBG(" NOT adding stub route: %I\n", ip);
+ break;
+ case LSART_VLNK:
+ DBG("Ignoring\n");
+ continue;
+ break;
+ case LSART_NET:
+ tmp = ospf_hash_find(oa->gr, rtl->id, rtl->id, LSA_T_NET);
+ if (tmp == NULL)
+ DBG("Not found!\n");
+ else
+ DBG("Found. :-)\n");
+ break;
+ case LSART_PTP:
+ tmp = ospf_hash_find(oa->gr, rtl->id, rtl->id, LSA_T_RT);
+ DBG("PTP found.\n");
+ break;
+ default:
+ log("Unknown link type in router lsa.");
+ break;
}
- break;
+ if (tmp)
+ DBG("Going to add cand, Mydist: %u, Req: %u\n",
+ tmp->dist, act->dist + rtl->metric);
+ add_cand(&oa->cand, tmp, act, act->dist + rtl->metric, oa);
+ }
+ break;
+ case LSA_T_NET:
+ ln = act->lsa_body;
+ ip = ipa_and(ipa_from_u32(act->lsa.id), ln->netmask);
+ nf = fib_get(in, &ip, ipa_mklen(ln->netmask));
+ if (nf->metric > act->dist)
+ {
+ nf->metric = act->dist;
+ nf->en = act;
+ DBG(" Adding into routing table\n");
+ }
+ rts = (u32 *) (ln + 1);
+ for (i = 0; i < (act->lsa.length - sizeof(struct ospf_lsa_header) -
+ sizeof(struct ospf_lsa_net)) / sizeof(u32); i++)
+ {
+ DBG(" Working on router %I ", *(rts + i));
+ tmp = ospf_hash_find(oa->gr, *(rts + i), *(rts + i), LSA_T_RT);
+ if (tmp != NULL)
+ DBG("Found :-)\n");
+ else
+ DBG("Not found!\n");
+ add_cand(&oa->cand, tmp, act, act->dist, oa);
+ }
+ break;
}
}
/* Now sync our fib with nest's */
DBG("Now syncing my rt table with nest's\n");
- FIB_ITERATE_INIT(&fit,in);
+ FIB_ITERATE_INIT(&fit, in);
again:
- FIB_ITERATE_START(in,&fit,nftmp)
+ FIB_ITERATE_START(in, &fit, nftmp)
{
- nf=(struct infib *)nftmp;
- if(nf->metric==LSINFINITY)
+ nf = (struct infib *) nftmp;
+ if (nf->metric == LSINFINITY)
{
net *ne;
- struct top_hash_entry *en=nf->en;
- ln=en->lsa_body;
-
- ne=net_get(p->table, nf->fn.prefix, nf->fn.pxlen);
- if((en!=NULL)&&(en->nhi!=NULL))
- DBG("Deleting rt entry %I\n (P: %x, GW: %I, Iface: %s)\n",
- nf->fn.prefix, en, en->nh,en->nhi->name);
+ struct top_hash_entry *en = nf->en;
+ ln = en->lsa_body;
+
+ ne = net_get(p->table, nf->fn.prefix, nf->fn.pxlen);
+ if ((en != NULL) && (en->nhi != NULL))
+ DBG("Deleting rt entry %I\n (P: %x, GW: %I, Iface: %s)\n",
+ nf->fn.prefix, en, en->nh, en->nhi->name);
rte_update(p->table, ne, p, NULL);
/* Now delete my fib */
@@ -198,57 +208,59 @@ again:
else
{
/* Update routing table */
- if(ipa_equal(nf->en->nh,ipa_from_u32(0)))
+ if (ipa_equal(nf->en->nh, ipa_from_u32(0)))
{
- struct top_hash_entry *en=nf->en;
- struct ospf_neighbor *neigh;
- neighbor *nn;
+ struct top_hash_entry *en = nf->en;
+ struct ospf_neighbor *neigh;
+ neighbor *nn;
- if((neigh=find_neigh_noifa(po,en->lsa.rt))==NULL)
+ if ((neigh = find_neigh_noifa(po, en->lsa.rt)) == NULL)
{
goto skip;
}
- nn=neigh_find(p,&neigh->ip,0);
- DBG(" Next hop calculated: %I\n", nn->addr);
- en->nh=nn->addr;
- en->nhi=nn->iface;
+ nn = neigh_find(p, &neigh->ip, 0);
+ DBG(" Next hop calculated: %I\n", nn->addr);
+ en->nh = nn->addr;
+ en->nhi = nn->iface;
}
- if((nf->en!=nf->olden)||(nf->metric!=nf->oldmetric))
+ if ((nf->en != nf->olden) || (nf->metric != nf->oldmetric))
{
- net *ne;
- rta a0;
- rte *e;
- struct top_hash_entry *en=nf->en;
- ln=en->lsa_body;
-
- bzero(&a0, sizeof(a0));
-
- a0.proto=p;
- a0.source=RTS_OSPF;
- a0.scope=SCOPE_UNIVERSE;
- a0.cast=RTC_UNICAST;
- if(ipa_to_u32(en->nh)==0) a0.dest=RTD_DEVICE;
- else a0.dest=RTD_ROUTER;
- a0.flags=0;
- a0.aflags=0;
- a0.iface=en->nhi;
- a0.gw=en->nh;
-
- ne=net_get(p->table, nf->fn.prefix, nf->fn.pxlen);
- e=rte_get_temp(&a0);
- e->u.ospf.metric1=nf->metric;
- e->u.ospf.metric2=LSINFINITY;
- e->u.ospf.tag=0;
- e->pflags = 0;
- e->net=ne;
+ net *ne;
+ rta a0;
+ rte *e;
+ struct top_hash_entry *en = nf->en;
+ ln = en->lsa_body;
+
+ bzero(&a0, sizeof(a0));
+
+ a0.proto = p;
+ a0.source = RTS_OSPF;
+ a0.scope = SCOPE_UNIVERSE;
+ a0.cast = RTC_UNICAST;
+ if (ipa_to_u32(en->nh) == 0)
+ a0.dest = RTD_DEVICE;
+ else
+ a0.dest = RTD_ROUTER;
+ a0.flags = 0;
+ a0.aflags = 0;
+ a0.iface = en->nhi;
+ a0.gw = en->nh;
+
+ ne = net_get(p->table, nf->fn.prefix, nf->fn.pxlen);
+ e = rte_get_temp(&a0);
+ e->u.ospf.metric1 = nf->metric;
+ e->u.ospf.metric2 = LSINFINITY;
+ e->u.ospf.tag = 0;
+ e->pflags = 0;
+ e->net = ne;
e->pref = p->preference;
- DBG("Modifying rt entry %I\n (GW: %I, Iface: %s)\n",
- nf->fn.prefix,en->nh,en->nhi->name);
- rte_update(p->table, ne, p, e);
+ DBG("Modifying rt entry %I\n (GW: %I, Iface: %s)\n",
+ nf->fn.prefix, en->nh, en->nhi->name);
+ rte_update(p->table, ne, p, e);
- nf->olden=nf->en;
- nf->oldmetric=nf->metric;
+ nf->olden = nf->en;
+ nf->oldmetric = nf->metric;
}
}
@@ -269,217 +281,229 @@ skip:
void
ospf_ext_spfa(struct proto_ospf *po) /* FIXME looking into inter-area */
{
- struct top_hash_entry *en,*etmp,*absr;
- struct fib *ef=&po->efib;
+ struct top_hash_entry *en, *etmp, *absr;
+ struct fib *ef = &po->efib;
struct extfib *nf;
struct infib *inf;
struct fib_iterator fit;
- struct ospf_area *oa=NULL,*atmp,*absroa;
- struct proto *p=&po->proto;
+ struct ospf_area *oa = NULL, *atmp, *absroa;
+ struct proto *p = &po->proto;
struct ospf_lsa_ext *le;
struct ospf_lsa_ext_tos *lt;
int mlen;
- ip_addr ip,nnh;
- struct iface *nnhi=NULL;
- u16 met,met2;
+ ip_addr ip, nnh;
+ struct iface *nnhi = NULL;
+ u16 met, met2;
u32 tag;
neighbor *nn;
- OSPF_TRACE(D_EVENTS,"Starting routing table calculation for ext routes");
+ OSPF_TRACE(D_EVENTS, "Starting routing table calculation for ext routes");
- FIB_WALK(ef,nftmp)
+ FIB_WALK(ef, nftmp)
{
- nf=(struct extfib *)nftmp;
- nf->metric=LSINFINITY;
- nf->metric2=LSINFINITY;
+ nf = (struct extfib *) nftmp;
+ nf->metric = LSINFINITY;
+ nf->metric2 = LSINFINITY;
}
FIB_WALK_END;
- WALK_LIST(oa,po->area_list)
+ WALK_LIST(oa, po->area_list)
{
- if(!oa->stub) break;
+ if (!oa->stub)
+ break;
}
- if(oa==NULL) return;
+ if (oa == NULL)
+ return;
- WALK_SLIST(en,oa->lsal)
+ WALK_SLIST(en, oa->lsal)
{
- if(en->lsa.type!=LSA_T_EXT) continue;
- if(en->lsa.age==LSA_MAXAGE) continue;
- if(en->lsa.rt==p->cf->global->router_id) continue;
+ if (en->lsa.type != LSA_T_EXT)
+ continue;
+ if (en->lsa.age == LSA_MAXAGE)
+ continue;
+ if (en->lsa.rt == p->cf->global->router_id)
+ continue;
- le=en->lsa_body;
- lt=(struct ospf_lsa_ext_tos *)(le+1);
+ le = en->lsa_body;
+ lt = (struct ospf_lsa_ext_tos *) (le + 1);
DBG("%s: Working on LSA. ID: %I, RT: %I, Type: %u, Mask %I\n",
- p->name,en->lsa.id,en->lsa.rt,en->lsa.type,le->netmask);
+ p->name, en->lsa.id, en->lsa.rt, en->lsa.type, le->netmask);
- if(lt->metric==LSINFINITY) continue;
- ip=ipa_and(ipa_from_u32(en->lsa.id),le->netmask);
- mlen=ipa_mklen(le->netmask);
- if((mlen<0)||(mlen>32))
+ if (lt->metric == LSINFINITY)
+ continue;
+ ip = ipa_and(ipa_from_u32(en->lsa.id), le->netmask);
+ mlen = ipa_mklen(le->netmask);
+ if ((mlen < 0) || (mlen > 32))
{
log("%s: Invalid mask in LSA. ID: %I, RT: %I, Type: %u, Mask %I",
- p->name,en->lsa.id,en->lsa.rt,en->lsa.type,le->netmask);
+ p->name, en->lsa.id, en->lsa.rt, en->lsa.type, le->netmask);
continue;
}
- nf=NULL;
+ nf = NULL;
- WALK_LIST(atmp,po->area_list)
+ WALK_LIST(atmp, po->area_list)
{
- if((nf=fib_find(&atmp->infib,&ip, mlen))!=NULL) break;
+ if ((nf = fib_find(&atmp->infib, &ip, mlen)) != NULL)
+ break;
}
- if(nf!=NULL) continue; /* Some intra area path exists */
+ if (nf != NULL)
+ continue; /* Some intra area path exists */
- absr=NULL;
- absroa=NULL;
- nnhi=NULL;
- nnh=IPA_NONE;
+ absr = NULL;
+ absroa = NULL;
+ nnhi = NULL;
+ nnh = IPA_NONE;
- met=0;met2=0;tag=0;
+ met = 0;
+ met2 = 0;
+ tag = 0;
- WALK_LIST(atmp,po->area_list) /*
+ WALK_LIST(atmp, po->area_list) /*
* Find shortest path
* to advertising router
*/
{
- if((etmp=ospf_hash_find(atmp->gr,en->lsa.rt,en->lsa.rt,LSA_T_RT))!=NULL)
+ if ((etmp =
+ ospf_hash_find(atmp->gr, en->lsa.rt, en->lsa.rt,
+ LSA_T_RT)) != NULL)
{
- if((absr==NULL) || (absr->dist>etmp->dist) ||
- ((etmp->dist==absr->dist) && (absroa->areaid<atmp->areaid)))
- {
- absr=etmp;
- absroa=atmp;
+ if ((absr == NULL) || (absr->dist > etmp->dist) ||
+ ((etmp->dist == absr->dist) && (absroa->areaid < atmp->areaid)))
+ {
+ absr = etmp;
+ absroa = atmp;
break;
- }
+ }
}
}
- if((absr==NULL)||(absr->dist==LSINFINITY)||
- (((struct ospf_lsa_rt *)(absr->lsa_body))->veb.bit.e==0))
+ if ((absr == NULL) || (absr->dist == LSINFINITY) ||
+ (((struct ospf_lsa_rt *) (absr->lsa_body))->veb.bit.e == 0))
{
DBG("ASBR is null or its dist=INF\n");
continue;
}
- if(ipa_compare(lt->fwaddr,ipa_from_u32(0))==0)
+ if (ipa_compare(lt->fwaddr, ipa_from_u32(0)) == 0)
{
- if(lt->etos>0) /* FW address == 0 */
+ if (lt->etos > 0) /* FW address == 0 */
{
- met=absr->dist;
- met2=lt->metric;
+ met = absr->dist;
+ met2 = lt->metric;
}
else
{
- met=absr->dist+lt->metric;
- met2=LSINFINITY;
+ met = absr->dist + lt->metric;
+ met2 = LSINFINITY;
}
- tag=lt->tag;
+ tag = lt->tag;
}
- else /* FW address !=0 */
+ else /* FW address !=0 */
{
- inf=NULL;
- WALK_LIST(atmp,po->area_list)
+ inf = NULL;
+ WALK_LIST(atmp, po->area_list)
{
- if((inf=fib_route(&atmp->infib,lt->fwaddr,32))!=NULL)
+ if ((inf = fib_route(&atmp->infib, lt->fwaddr, 32)) != NULL)
{
break;
}
}
- if(inf==NULL)
+ if (inf == NULL)
{
- DBG("Cannot find network route (GW=%I)\n",lt->fwaddr);
- continue;
+ DBG("Cannot find network route (GW=%I)\n", lt->fwaddr);
+ continue;
}
- if(lt->etos>0)
+ if (lt->etos > 0)
{
- met=inf->metric;
- met2=lt->metric;
+ met = inf->metric;
+ met2 = lt->metric;
}
else
{
- met=inf->metric+lt->metric;
- met2=LSINFINITY;
+ met = inf->metric + lt->metric;
+ met2 = LSINFINITY;
}
- tag=lt->tag;
+ tag = lt->tag;
- if((nn=neigh_find(p,&lt->fwaddr,0))!=NULL)
+ if ((nn = neigh_find(p, &lt->fwaddr, 0)) != NULL)
{
- nnh=lt->fwaddr;
- nnhi=nn->iface;
+ nnh = lt->fwaddr;
+ nnhi = nn->iface;
}
else
{
- nnh=inf->en->nh;
- nnhi=inf->en->nhi;
+ nnh = inf->en->nh;
+ nnhi = inf->en->nhi;
}
}
- nf=fib_get(ef,&ip, mlen);
- if((nf->metric==LSINFINITY) || /* nf is new */
- ((met<nf->metric)&&(nf->metric2==met2)) || /* both E1 or E2
- * with same metric */
- ((met2<nf->metric2)&&(nf->metric2!=LSINFINITY)) || /* E2 smaller and
- * 1st is not E1 */
- ((nf->metric2!=LSINFINITY)&&(met2==LSINFINITY))) /* 2nd is E1 and
- * 1st is E2 */
+ nf = fib_get(ef, &ip, mlen);
+ if ((nf->metric == LSINFINITY) || /* nf is new */
+ ((met < nf->metric) && (nf->metric2 == met2)) || /* both E1 or E2
+ * with same metric */
+ ((met2 < nf->metric2) && (nf->metric2 != LSINFINITY)) || /* E2 smaller and
+ * 1st is not E1 */
+ ((nf->metric2 != LSINFINITY) && (met2 == LSINFINITY))) /* 2nd is E1 and
+ * 1st is E2 */
{
- if(nf->metric!=LSINFINITY)
- OSPF_TRACE(D_EVENTS,
- "Rewriting %I/%d met=%d, met2=%d, nmet=%d, nmet2=%d",
- ip, mlen, nf->metric, nf->metric2, met, met2);
- nf->metric=met;
- nf->metric2=met2;
- nf->tag=tag;
-
- if(nnhi!=NULL)
+ if (nf->metric != LSINFINITY)
+ OSPF_TRACE(D_EVENTS,
+ "Rewriting %I/%d met=%d, met2=%d, nmet=%d, nmet2=%d",
+ ip, mlen, nf->metric, nf->metric2, met, met2);
+ nf->metric = met;
+ nf->metric2 = met2;
+ nf->tag = tag;
+
+ if (nnhi != NULL)
{
- nf->nh=nnh;
- nf->nhi=nnhi;
+ nf->nh = nnh;
+ nf->nhi = nnhi;
}
else
{
- if(ipa_compare(absr->nh,ipa_from_u32(0))==0)
- {
- struct ospf_neighbor *neigh;
+ if (ipa_compare(absr->nh, ipa_from_u32(0)) == 0)
+ {
+ struct ospf_neighbor *neigh;
- if((neigh=find_neigh_noifa(po,absr->lsa.rt))==NULL)
+ if ((neigh = find_neigh_noifa(po, absr->lsa.rt)) == NULL)
{
- DBG("Cannot find neighbor\n");
- nf->metric=LSINFINITY; /* delete this route */
- continue;
+ DBG("Cannot find neighbor\n");
+ nf->metric = LSINFINITY; /* delete this route */
+ continue;
}
- nn=neigh_find(p,&neigh->ip,0);
- DBG(" Next hop calculated: %I\n", nn->addr);
- nf->nh=nn->addr;
- nf->nhi=nn->iface;
- }
- else
- {
- nf->nh=absr->nh;
- nf->nhi=absr->nhi;
- }
+ nn = neigh_find(p, &neigh->ip, 0);
+ DBG(" Next hop calculated: %I\n", nn->addr);
+ nf->nh = nn->addr;
+ nf->nhi = nn->iface;
+ }
+ else
+ {
+ nf->nh = absr->nh;
+ nf->nhi = absr->nhi;
+ }
}
}
}
DBG("Now syncing my rt table with nest's\n");
- FIB_ITERATE_INIT(&fit,ef);
+ FIB_ITERATE_INIT(&fit, ef);
noch:
- FIB_ITERATE_START(ef,&fit,nftmp)
+ FIB_ITERATE_START(ef, &fit, nftmp)
{
- nf=(struct extfib *)nftmp;
- if(nf->metric==LSINFINITY)
+ nf = (struct extfib *) nftmp;
+ if (nf->metric == LSINFINITY)
{
net *ne;
-
- ne=net_get(p->table, nf->fn.prefix, nf->fn.pxlen);
+
+ ne = net_get(p->table, nf->fn.prefix, nf->fn.pxlen);
DBG("Deleting rt entry %I\n (IP: %I, GW: %I)\n",
- nf->fn.prefix,ip,nf->nh);
+ nf->fn.prefix, ip, nf->nh);
rte_update(p->table, ne, p, NULL);
/* Now delete my fib */
@@ -488,106 +512,114 @@ noch:
goto noch;
}
else
- if((nf->metric!=nf->oldmetric)||(nf->metric2!=nf->oldmetric2)||
- (!ipa_equal(nf->nh,nf->oldnh))||(nf->tag!=nf->oldtag))
- {
- net *ne;
- rta a0;
- rte *e;
-
- bzero(&a0, sizeof(a0));
-
- a0.proto=p;
- a0.source=RTS_OSPF_EXT;
- a0.scope=SCOPE_UNIVERSE;
- a0.cast=RTC_UNICAST;
- a0.dest=RTD_ROUTER;
- a0.flags=0;
- a0.aflags=0;
- a0.iface=nf->nhi;
- a0.gw=nf->nh;
- ne=net_get(p->table, nf->fn.prefix, nf->fn.pxlen);
- e=rte_get_temp(&a0);
- e->u.ospf.metric1=nf->metric;
- e->u.ospf.metric2=nf->metric2;
- e->u.ospf.tag=nf->tag;
- e->pflags = 0;
- e->net=ne;
- e->pref = p->preference;
- DBG("Modifying rt entry %I\n (IP: %I, GW: %I)\n",
- nf->fn.prefix,ip,nf->nh);
- rte_update(p->table, ne, p, e);
-
- nf->oldmetric=nf->metric;
- nf->oldmetric2=nf->metric2;
- nf->oldnh=nf->nh;
- nf->oldtag=nf->tag;
- }
+ if ((nf->metric != nf->oldmetric) || (nf->metric2 != nf->oldmetric2) ||
+ (!ipa_equal(nf->nh, nf->oldnh)) || (nf->tag != nf->oldtag))
+ {
+ net *ne;
+ rta a0;
+ rte *e;
+
+ bzero(&a0, sizeof(a0));
+
+ a0.proto = p;
+ a0.source = RTS_OSPF_EXT;
+ a0.scope = SCOPE_UNIVERSE;
+ a0.cast = RTC_UNICAST;
+ a0.dest = RTD_ROUTER;
+ a0.flags = 0;
+ a0.aflags = 0;
+ a0.iface = nf->nhi;
+ a0.gw = nf->nh;
+ ne = net_get(p->table, nf->fn.prefix, nf->fn.pxlen);
+ e = rte_get_temp(&a0);
+ e->u.ospf.metric1 = nf->metric;
+ e->u.ospf.metric2 = nf->metric2;
+ e->u.ospf.tag = nf->tag;
+ e->pflags = 0;
+ e->net = ne;
+ e->pref = p->preference;
+ DBG("Modifying rt entry %I\n (IP: %I, GW: %I)\n",
+ nf->fn.prefix, ip, nf->nh);
+ rte_update(p->table, ne, p, e);
+
+ nf->oldmetric = nf->metric;
+ nf->oldmetric2 = nf->metric2;
+ nf->oldnh = nf->nh;
+ nf->oldtag = nf->tag;
+ }
}
FIB_ITERATE_END(nftmp);
}
/* Add LSA into list of candidates in Dijkstra's algorithm */
void
-add_cand(list *l, struct top_hash_entry *en, struct top_hash_entry *par,
- u16 dist, struct ospf_area *oa)
+add_cand(list * l, struct top_hash_entry *en, struct top_hash_entry *par,
+ u16 dist, struct ospf_area *oa)
{
- node *prev,*n;
- int added=0;
+ node *prev, *n;
+ int added = 0;
struct top_hash_entry *act;
- if(en==NULL) return;
- if(en->lsa.age==LSA_MAXAGE) return;
+ if (en == NULL)
+ return;
+ if (en->lsa.age == LSA_MAXAGE)
+ return;
/* FIXME Does it have link back? Test it! */
- if(en->color==INSPF) return;
+ if (en->color == INSPF)
+ return;
- if(dist>=en->dist) return;
+ if (dist >= en->dist)
+ return;
/*
* FIXME The line above is not a bug, but we don't support
* multiple next hops. I'll start as soon as nest will
*/
- DBG(" Adding candidate: rt: %I, id: %I, type: %u\n",en->lsa.rt,en->lsa.id,en->lsa.type);
+ DBG(" Adding candidate: rt: %I, id: %I, type: %u\n", en->lsa.rt,
+ en->lsa.id, en->lsa.type);
+
+ en->nhi = NULL;
+ en->nh = IPA_NONE;
- en->nhi=NULL;
- en->nh=IPA_NONE;
-
calc_next_hop(en, par, oa);
- if(!en->nhi) return; /* We cannot find next hop, ignore it */
+ if (!en->nhi)
+ return; /* We cannot find next hop, ignore it */
- if(en->color==CANDIDATE) /* We found a shorter path */
+ if (en->color == CANDIDATE) /* We found a shorter path */
{
rem_node(&en->cn);
}
- en->dist=dist;
- en->color=CANDIDATE;
+ en->dist = dist;
+ en->color = CANDIDATE;
- prev=NULL;
+ prev = NULL;
- if(EMPTY_LIST(*l))
+ if (EMPTY_LIST(*l))
{
- add_head(l,&en->cn);
+ add_head(l, &en->cn);
}
else
{
- WALK_LIST(n,*l)
+ WALK_LIST(n, *l)
{
- act=SKIP_BACK(struct top_hash_entry, cn, n);
- if((act->dist>dist)||
- ((act->dist==dist)&&(act->lsa.type==LSA_T_NET)))
+ act = SKIP_BACK(struct top_hash_entry, cn, n);
+ if ((act->dist > dist) ||
+ ((act->dist == dist) && (act->lsa.type == LSA_T_NET)))
{
- if(prev==NULL) add_head(l,&en->cn);
- else insert_node(&en->cn,prev);
- added=1;
- break;
+ if (prev == NULL)
+ add_head(l, &en->cn);
+ else
+ insert_node(&en->cn, prev);
+ added = 1;
+ break;
}
- prev=n;
+ prev = n;
}
- if(!added)
+ if (!added)
{
- add_tail(l,&en->cn);
+ add_tail(l, &en->cn);
}
}
/* FIXME Some VLINK stuff should be here */
@@ -595,73 +627,78 @@ add_cand(list *l, struct top_hash_entry *en, struct top_hash_entry *par,
void
calc_next_hop(struct top_hash_entry *en, struct top_hash_entry *par,
- struct ospf_area *oa)
+ struct ospf_area *oa)
{
struct ospf_neighbor *neigh;
- struct proto *p=&oa->po->proto;
- struct proto_ospf *po=oa->po;
+ struct proto *p = &oa->po->proto;
+ struct proto_ospf *po = oa->po;
struct ospf_iface *ifa;
- u32 myrid=p->cf->global->router_id;
+ u32 myrid = p->cf->global->router_id;
DBG(" Next hop called.\n");
- if(ipa_equal(par->nh,IPA_NONE))
+ if (ipa_equal(par->nh, IPA_NONE))
{
neighbor *nn;
DBG(" Next hop calculating for id: %I rt: %I type: %u\n",
- en->lsa.id,en->lsa.rt,en->lsa.type);
+ en->lsa.id, en->lsa.rt, en->lsa.type);
- if(par==oa->rt)
+ if (par == oa->rt)
{
- if(en->lsa.type==LSA_T_NET)
+ if (en->lsa.type == LSA_T_NET)
{
- if(en->lsa.rt==myrid)
- {
- WALK_LIST(ifa,po->iface_list)
- if(ipa_compare(ifa->iface->addr->ip,ipa_from_u32(en->lsa.id))==0)
- {
- en->nhi=ifa->iface;
- return;
- }
- log(L_ERR "I didn't find interface for my self originated LSA!\n");
- /* This could sometimes happen */
- return;
- }
- else
- {
- ip_addr ip=ipa_from_u32(en->lsa.id);
- nn=neigh_find(p,&ip,0);
- if(nn) en->nhi=nn->iface;
- return;
- }
+ if (en->lsa.rt == myrid)
+ {
+ WALK_LIST(ifa, po->iface_list)
+ if (ipa_compare(ifa->iface->addr->ip, ipa_from_u32(en->lsa.id)) ==
+ 0)
+ {
+ en->nhi = ifa->iface;
+ return;
+ }
+ log(L_ERR "I didn't find interface for my self originated LSA!\n");
+ /* This could sometimes happen */
+ return;
+ }
+ else
+ {
+ ip_addr ip = ipa_from_u32(en->lsa.id);
+ nn = neigh_find(p, &ip, 0);
+ if (nn)
+ en->nhi = nn->iface;
+ return;
+ }
}
else
{
- if((neigh=find_neigh_noifa(po,en->lsa.rt))==NULL) return;
- en->nhi=neigh->ifa->iface;
- en->nh=neigh->ip; /* Yes, neighbor is it's own next hop */
- return;
+ if ((neigh = find_neigh_noifa(po, en->lsa.rt)) == NULL)
+ return;
+ en->nhi = neigh->ifa->iface;
+ en->nh = neigh->ip; /* Yes, neighbor is it's own next hop */
+ return;
}
}
- if(par->lsa.type==LSA_T_NET)
+ if (par->lsa.type == LSA_T_NET)
{
- if(en->lsa.type==LSA_T_NET) bug("Parent for net is net?");
- if((en->nhi=par->nhi)==NULL)
- bug("Did not find next hop interface for INSPF lsa!");
- if((neigh=find_neigh_noifa(po,en->lsa.rt))==NULL) return;
- en->nhi=neigh->ifa->iface;
- en->nh=neigh->ip; /* Yes, neighbor is it's own next hop */
+ if (en->lsa.type == LSA_T_NET)
+ bug("Parent for net is net?");
+ if ((en->nhi = par->nhi) == NULL)
+ bug("Did not find next hop interface for INSPF lsa!");
+ if ((neigh = find_neigh_noifa(po, en->lsa.rt)) == NULL)
+ return;
+ en->nhi = neigh->ifa->iface;
+ en->nh = neigh->ip; /* Yes, neighbor is it's own next hop */
return;
}
- else /* Parent is some RT neighbor */
+ else /* Parent is some RT neighbor */
{
- log(L_ERR "Router's parent has no next hop. (EN=%I, PAR=%I)", en->lsa.id, par->lsa.id);
- /* I hoped this would never happen */
+ log(L_ERR "Router's parent has no next hop. (EN=%I, PAR=%I)",
+ en->lsa.id, par->lsa.id);
+ /* I hoped this would never happen */
return;
}
}
- en->nh=par->nh;
- en->nhi=par->nhi;
+ en->nh = par->nh;
+ en->nhi = par->nhi;
DBG(" Next hop calculated: %I.\n", en->nh);
}
-
diff --git a/proto/ospf/rt.h b/proto/ospf/rt.h
index ba78e625..c236fcea 100644
--- a/proto/ospf/rt.h
+++ b/proto/ospf/rt.h
@@ -10,7 +10,8 @@
#ifndef _BIRD_OSPF_RT_H_
#define _BIRD_OSPF_RT_H_
-struct infib {
+struct infib
+{
struct fib_node fn;
u16 metric;
u16 oldmetric;
@@ -18,7 +19,8 @@ struct infib {
struct top_hash_entry *olden;
};
-struct extfib {
+struct extfib
+{
struct fib_node fn;
u16 metric;
u16 metric2;
@@ -33,10 +35,10 @@ struct extfib {
void ospf_rt_spfa(struct ospf_area *oa);
void ospf_ext_spfa(struct proto_ospf *po);
-void add_cand(list *l, struct top_hash_entry *en, struct top_hash_entry *par,
- u16 dist, struct ospf_area *oa);
+void add_cand(list * l, struct top_hash_entry *en, struct top_hash_entry *par,
+ u16 dist, struct ospf_area *oa);
void calc_next_hop(struct top_hash_entry *par, struct top_hash_entry *en,
- struct ospf_area *oa);
+ struct ospf_area *oa);
void init_infib(struct fib_node *fn);
void init_efib(struct fib_node *fn);