summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--proto/ospf/hello.c19
-rw-r--r--proto/ospf/neighbor.c55
-rw-r--r--proto/ospf/ospf.h8
3 files changed, 40 insertions, 42 deletions
diff --git a/proto/ospf/hello.c b/proto/ospf/hello.c
index de1669f..09dbfae 100644
--- a/proto/ospf/hello.c
+++ b/proto/ospf/hello.c
@@ -53,7 +53,7 @@ ospf_hello_rx(struct ospf_hello_packet *ps, struct proto *p,
u32 nrid, *pnrid;
struct ospf_neighbor *neigh,*n;
u8 i,twoway,oldpriority;
- u32 olddr,oldbdr;
+ ip_addr olddr,oldbdr;
char *beg=": Bad OSPF hello packet from ", *rec=" received: ";
nrid=ntohl(((struct ospf_packet *)ps)->routerid);
@@ -153,21 +153,22 @@ ospf_hello_rx(struct ospf_hello_packet *ps, struct proto *p,
if(n->priority!=oldpriority) ospf_int_sm(ifa, ISM_NEICH);
/* Router is declaring itself ad DR and there is no BDR */
- if((n->rid==n->dr) && (n->bdr==0) && (n->state!=NEIGHBOR_FULL))
+ if((ipa_compare(n->ip,n->dr)==0) && (ipa_to_u32(n->bdr)==0)
+ && (n->state!=NEIGHBOR_FULL))
ospf_int_sm(ifa, ISM_BACKS);
/* Neighbor is declaring itself as BDR */
- if((n->rid==n->bdr) && (n->state!=NEIGHBOR_FULL))
+ if((ipa_compare(n->ip,n->bdr)==0) && (n->state!=NEIGHBOR_FULL))
ospf_int_sm(ifa, ISM_BACKS);
/* Neighbor is newly declaring itself as DR or BDR */
- if(((n->rid==n->dr) && (n->dr!=olddr)) || ((n->rid==n->bdr) &&
- (n->bdr!=oldbdr)))
+ if(((ipa_compare(n->ip,n->dr)==0) && (ipa_compare(n->dr,olddr)!=0))
+ || ((ipa_compare(n->ip,n->bdr)==0) && (ipa_compare(n->bdr,oldbdr)!=0)))
ospf_int_sm(ifa, ISM_NEICH);
/* Neighbor is no more declaring itself as DR or BDR */
- if(((n->rid==olddr) && (n->dr!=olddr)) || ((n->rid==oldbdr) &&
- (n->bdr!=oldbdr)))
+ if(((ipa_compare(n->ip,olddr)==0) && (ipa_compare(n->dr,olddr)!=0))
+ || ((ipa_compare(n->ip,oldbdr)==0) && (ipa_compare(n->bdr,oldbdr)!=0)))
ospf_int_sm(ifa, ISM_NEICH);
}
@@ -212,8 +213,8 @@ hello_timer_hook(timer *timer)
pkt->options=ifa->options;
pkt->priority=ifa->priority;
pkt->deadint=htonl(ifa->deadc*ifa->helloint);
- pkt->dr=htonl(ifa->drid);
- pkt->bdr=htonl(ifa->bdrid);
+ pkt->dr=htonl(ifa->drip);
+ pkt->bdr=htonl(ifa->bdrip);
/* Fill all neighbors */
i=0;
diff --git a/proto/ospf/neighbor.c b/proto/ospf/neighbor.c
index ddc2e62..d22a60e 100644
--- a/proto/ospf/neighbor.c
+++ b/proto/ospf/neighbor.c
@@ -100,9 +100,9 @@ electbdr(list nl)
{
if(neigh->state>=NEIGHBOR_2WAY) /* Higher than 2WAY */
if(neigh->priority>0) /* Eligible */
- if(neigh->rid!=neigh->dr) /* And not declaring itself DR */
+ if(ipa_compare(neigh->ip,neigh->dr)!=0) /* And not decl. itself DR */
{
- if(neigh->rid==neigh->bdr) /* Declaring BDR */
+ if(ipa_compare(neigh->ip,neigh->bdr)==0) /* Declaring BDR */
{
if(n1!=NULL)
{
@@ -145,7 +145,7 @@ electdr(list nl)
{
if(neigh->state>=NEIGHBOR_2WAY) /* Higher than 2WAY */
if(neigh->priority>0) /* Eligible */
- if(neigh->rid==neigh->dr) /* And declaring itself DR */
+ if(ipa_compare(neigh->ip,neigh->dr)==0) /* And declaring itself DR */
{
if(n!=NULL)
{
@@ -331,19 +331,20 @@ void
bdr_election(struct ospf_iface *ifa)
{
struct ospf_neighbor *neigh,*ndr,*nbdr,me,*tmp;
- u32 myid, ndrid, nbdrid;
+ u32 myid;
+ ip_addr ndrip, nbdrip;
int doadj;
struct proto *p=&ifa->proto->proto;
- DBG("%s: (B)DR election.\n",p->name);
+ DBG("(B)DR election.\n");
myid=p->cf->global->router_id;
me.state=NEIGHBOR_2WAY;
me.rid=myid;
me.priority=ifa->priority;
- me.dr=ifa->drid;
- me.bdr=ifa->bdrid;
+ me.dr=ifa->drip;
+ me.bdr=ifa->bdrip;
me.ip=ifa->iface->addr->ip;
add_tail(&ifa->neigh_list, NODE &me);
@@ -358,53 +359,49 @@ bdr_election(struct ospf_iface *ifa)
|| ((ifa->bdrid==myid) && (nbdr!=&me))
|| ((ifa->bdrid!=myid) && (nbdr==&me)))
{
- if(ndr==NULL) ifa->drid=me.dr=0;
- else ifa->drid=me.dr=ndr->rid;
+ if(ndr==NULL) ifa->drip=me.dr=ipa_from_u32(0);
+ else ifa->drip=me.dr=ndr->ip;
- if(nbdr==NULL) ifa->bdrid=me.bdr=0;
- else ifa->bdrid=me.bdr=nbdr->rid;
+ 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->drid=0;
- if(ndr==NULL) ndrid=0;
- else ndrid=ndr->rid;
+ if(ndr==NULL) ndrip=ipa_from_u32(0);
+ else ndrip=ndr->ip;
- if(nbdr==NULL) nbdrid=0;
- else nbdrid=nbdr->rid;
+ if(nbdr==NULL) nbdrip=ipa_from_u32(0);
+ else nbdrip=nbdr->ip;
doadj=0;
- if((ifa->drid!=ndrid) || (ifa->bdrid!=nbdrid)) doadj=1;
- ifa->drid=ndrid;
- if(ndrid==0)
+ if((ipa_compare(ifa->drip,ndrip)!=0) || (ipa_compare(ifa->bdrip,nbdrip)!=0))
+ doadj=1;
+
+ if(ndr==NULL)
{
ifa->drid=0;
ifa->drip=ipa_from_u32(0);
}
else
{
- if((tmp=find_neigh(ifa,ndrid))==NULL)
- bug("Error in DR election.");
- ifa->drid=ndrid;
- ifa->drip=tmp->ip;
+ ifa->drid=ndr->rid;
+ ifa->drip=ndr->ip;
}
- if(nbdrid==0)
+ if(nbdr==NULL)
{
ifa->bdrid=0;
ifa->bdrip=ipa_from_u32(0);
}
else
{
- if((tmp=find_neigh(ifa,nbdrid))==NULL)
- bug("Error in BDR election.");
- ifa->bdrid=nbdrid;
- ifa->bdrip=tmp->ip;
+ ifa->bdrid=nbdr->rid;
+ ifa->bdrip=nbdr->ip;
}
- DBG("%s: DR=%I, BDR=%I\n",p->name, ifa->drid, ifa->bdrid);
+ DBG("DR=%I, BDR=%I\n", ifa->drid, ifa->bdrid);
if(myid==ifa->drid) iface_chstate(ifa, OSPF_IS_DR);
else
diff --git a/proto/ospf/ospf.h b/proto/ospf/ospf.h
index d22b617..8854d8d 100644
--- a/proto/ospf/ospf.h
+++ b/proto/ospf/ospf.h
@@ -154,8 +154,8 @@ struct ospf_hello_packet {
u8 options;
u8 priority;
u32 deadint;
- u32 dr;
- u32 bdr;
+ ip_addr dr;
+ ip_addr bdr;
};
struct immsb {
@@ -305,8 +305,8 @@ struct ospf_neighbor
ip_addr ip; /* IP of it's interface */
u8 priority; /* Priority */
u8 options; /* Options received */
- u32 dr; /* Neigbour's idea of DR */
- u32 bdr; /* Neigbour's idea of BDR */
+ 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 */