Indentation.

This commit is contained in:
Ondrej Filip 2004-06-06 09:37:54 +00:00
parent 66261211a9
commit 2e10a170fe
14 changed files with 1629 additions and 1481 deletions

View file

@ -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,

View file

@ -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;
}

View file

@ -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;

View file

@ -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 */
{

View file

@ -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;
(void)lsasum_check(h,body,po);
ntohlsah(h,h);
ntohlsab(body,body,h->type,length-sizeof(struct ospf_lsa_header));
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));
}
/*
@ -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;
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)
if (change)
{
schedule_rtcalc(oa);
}
return en;
}

View file

@ -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);

View file

@ -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);

View file

@ -8,29 +8,32 @@
#include "ospf.h"
char *ospf_ns[]={" down",
" attempt",
" init",
" 2way",
" exstart",
"exchange",
" loading",
" full"};
char *ospf_ns[] = { " down",
" attempt",
" init",
" 2way",
" exstart",
"exchange",
" loading",
" full"
};
const char *ospf_inm[]={ "hello received", "neighbor start", "2-way received",
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 */
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_HELLOREC:
switch(n->state)
}
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]))
{
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;
struct lsah_n *no;
no = (struct lsah_n *) HEAD(n->ackl[ACKL_DELAY]);
rem_node(NODE no);
mb_free(no);
}
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)
}
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_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);
}
neigh_chstate(n, NEIGHBOR_EXSTART);
}
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)
{
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 (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;
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);
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;
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 ";
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);
}
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);
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);
}

File diff suppressed because it is too large Load diff

View file

@ -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 */
#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 {
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);

View file

@ -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);
}

View file

@ -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_ */

File diff suppressed because it is too large Load diff

View file

@ -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);