hello.* reindented, code cleanup.

This commit is contained in:
Ondrej Filip 2004-06-04 17:12:27 +00:00
parent 8e15e048f2
commit 77539c4471
3 changed files with 133 additions and 121 deletions

View file

@ -9,76 +9,78 @@
#include "ospf.h" #include "ospf.h"
void void
ospf_hello_receive(struct ospf_hello_packet *ps, struct proto *p, ospf_hello_receive(struct ospf_hello_packet *ps,
struct ospf_iface *ifa, int size, ip_addr faddr) struct ospf_iface *ifa, int size, ip_addr faddr)
{ {
u32 nrid, *pnrid; u32 nrid, *pnrid;
struct ospf_neighbor *neigh,*n; struct ospf_neighbor *neigh, *n;
u8 i,twoway,oldpriority; u8 i, twoway, oldpriority;
ip_addr olddr,oldbdr; ip_addr olddr, oldbdr;
ip_addr mask; ip_addr mask;
char *beg=": Bad OSPF hello packet from ", *rec=" received: "; char *beg = "Bad OSPF hello packet from ", *rec = " received: ";
int eligible=0; int eligible = 0;
pool *pool; pool *pool;
struct proto *p = (struct proto *) ifa->proto;
nrid=ntohl(((struct ospf_packet *)ps)->routerid); nrid = ntohl(((struct ospf_packet *) ps)->routerid);
OSPF_TRACE(D_PACKETS, "Received hello from %I via %s",faddr,ifa->iface->name); OSPF_TRACE(D_PACKETS, "Received hello from %I via %s", faddr,
mask=ps->netmask; ifa->iface->name);
mask = ps->netmask;
ipa_ntoh(mask); ipa_ntoh(mask);
if((unsigned)ipa_mklen(mask)!=ifa->iface->addr->pxlen) if ((unsigned) ipa_mklen(mask) != ifa->iface->addr->pxlen)
{ {
log("%s%s%I%sbad netmask %I.", p->name, beg, nrid, rec, log(L_ERR, "%s%I%sbad netmask %I.", beg, nrid, rec, mask);
mask);
return; return;
} }
if(ntohs(ps->helloint)!=ifa->helloint) if (ntohs(ps->helloint) != ifa->helloint)
{ {
log("%s%s%I%shello interval mismatch.", p->name, beg, faddr, rec); log(L_WARN "%s%I%shello interval mismatch.", beg, faddr, rec);
return; return;
} }
if(ntohl(ps->deadint)!=ifa->helloint*ifa->deadc) if (ntohl(ps->deadint) != ifa->helloint * ifa->deadc)
{ {
log("%s%s%I%sdead interval mismatch.", p->name, beg, faddr, rec); log(L_ERR "%s%I%sdead interval mismatch.", beg, faddr, rec);
return; return;
} }
if(ps->options!=ifa->options) if (ps->options != ifa->options)
{ {
log("%s%s%I%soptions mismatch.", p->name, beg, faddr, rec); log(L_ERR "%s%I%soptions mismatch.", beg, faddr, rec);
return; return;
} }
if((n=find_neigh(ifa, nrid))==NULL) if ((n = find_neigh(ifa, nrid)) == NULL)
{ {
if((ifa->type==OSPF_IT_NBMA)) if ((ifa->type == OSPF_IT_NBMA))
{ {
struct nbma_node *nn; struct nbma_node *nn;
int found=0; int found = 0;
WALK_LIST(nn,ifa->nbma_list) WALK_LIST(nn, ifa->nbma_list)
{ {
if(ipa_compare(faddr,nn->ip)==0) if (ipa_compare(faddr, nn->ip) == 0)
{ {
found=1; found = 1;
break; break;
} }
} }
if((found==0)&&(ifa->strictnbma)) if ((found == 0) && (ifa->strictnbma))
{ {
log("%s: Ignoring new neighbor: %I on %s.", p->name, faddr, log(L_WARN "Ignoring new neighbor: %I on %s.", faddr,
ifa->iface->name); ifa->iface->name);
return; return;
} }
if(found) if (found)
{ {
eligible=nn->eligible; eligible = nn->eligible;
if(((ps->priority==0)&&eligible)||((ps->priority>0)&&(eligible==0))) if (((ps->priority == 0) && eligible)
|| ((ps->priority > 0) && (eligible == 0)))
{ {
log("%s: Eligibility mismatch for neighbor: %I on %s", p->name, log(L_ERR "Eligibility mismatch for neighbor: %I on %s",
faddr, ifa->iface->name); faddr, ifa->iface->name);
return; return;
} }
@ -89,32 +91,33 @@ ospf_hello_receive(struct ospf_hello_packet *ps, struct proto *p,
n = ospf_neighbor_new(ifa); n = ospf_neighbor_new(ifa);
n->rid=nrid; n->rid = nrid;
n->ip=faddr; n->ip = faddr;
n->dr=ps->dr; n->dr = ps->dr;
ipa_ntoh(n->dr); ipa_ntoh(n->dr);
n->bdr=ps->bdr; n->bdr = ps->bdr;
ipa_ntoh(n->bdr); ipa_ntoh(n->bdr);
n->priority=ps->priority; n->priority = ps->priority;
n->options=ps->options; n->options = ps->options;
} }
ospf_neigh_sm(n, INM_HELLOREC); ospf_neigh_sm(n, INM_HELLOREC);
pnrid=(u32 *)((struct ospf_hello_packet *)(ps+1)); pnrid = (u32 *) ((struct ospf_hello_packet *) (ps + 1));
twoway=0; twoway = 0;
for(i=0;i<size-(sizeof(struct ospf_hello_packet));i++) for (i = 0; i < size - (sizeof(struct ospf_hello_packet)); i++)
{ {
if(ntohl(*(pnrid+i))==p->cf->global->router_id) if (ntohl(*(pnrid + i)) == p->cf->global->router_id)
{ {
DBG("%s: Twoway received from %I\n", p->name, faddr); DBG("%s: Twoway received from %I\n", p->name, faddr);
ospf_neigh_sm(n, INM_2WAYREC); ospf_neigh_sm(n, INM_2WAYREC);
twoway=1; twoway = 1;
break; break;
} }
} }
if(!twoway) ospf_neigh_sm(n, INM_1WAYREC); if (!twoway)
ospf_neigh_sm(n, INM_1WAYREC);
olddr = n->dr; olddr = n->dr;
n->dr = ipa_ntoh(ps->dr); n->dr = ipa_ntoh(ps->dr);
@ -124,39 +127,43 @@ ospf_hello_receive(struct ospf_hello_packet *ps, struct proto *p,
n->priority = ps->priority; n->priority = ps->priority;
/* Check priority change */ /* Check priority change */
if(n->state>=NEIGHBOR_2WAY) if (n->state >= NEIGHBOR_2WAY)
{ {
if(n->priority!=oldpriority) ospf_int_sm(ifa, ISM_NEICH); if (n->priority != oldpriority)
ospf_int_sm(ifa, ISM_NEICH);
/* Router is declaring itself ad DR and there is no BDR */ /* Router is declaring itself ad DR and there is no BDR */
if((ipa_compare(n->ip,n->dr)==0) && (ipa_to_u32(n->bdr)==0) if ((ipa_compare(n->ip, n->dr) == 0) && (ipa_to_u32(n->bdr) == 0)
&& (n->state!=NEIGHBOR_FULL)) && (n->state != NEIGHBOR_FULL))
ospf_int_sm(ifa, ISM_BACKS); ospf_int_sm(ifa, ISM_BACKS);
/* Neighbor is declaring itself as BDR */ /* Neighbor is declaring itself as BDR */
if((ipa_compare(n->ip,n->bdr)==0) && (n->state!=NEIGHBOR_FULL)) if ((ipa_compare(n->ip, n->bdr) == 0) && (n->state != NEIGHBOR_FULL))
ospf_int_sm(ifa, ISM_BACKS); ospf_int_sm(ifa, ISM_BACKS);
/* Neighbor is newly declaring itself as DR or BDR */ /* Neighbor is newly declaring itself as DR or BDR */
if(((ipa_compare(n->ip,n->dr)==0) && (ipa_compare(n->dr,olddr)!=0)) 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))) || ((ipa_compare(n->ip, n->bdr) == 0)
&& (ipa_compare(n->bdr, oldbdr) != 0)))
ospf_int_sm(ifa, ISM_NEICH); ospf_int_sm(ifa, ISM_NEICH);
/* Neighbor is no more declaring itself as DR or BDR */ /* Neighbor is no more declaring itself as DR or BDR */
if(((ipa_compare(n->ip,olddr)==0) && (ipa_compare(n->dr,olddr)!=0)) 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))) || ((ipa_compare(n->ip, oldbdr) == 0)
&& (ipa_compare(n->bdr, oldbdr) != 0)))
ospf_int_sm(ifa, ISM_NEICH); ospf_int_sm(ifa, ISM_NEICH);
} }
if(ifa->type!=OSPF_IT_NBMA) if (ifa->type != OSPF_IT_NBMA)
{ {
if((ifa->priority==0)&&(n->priority>0)) ospf_hello_send(NULL, 0, n); if ((ifa->priority == 0) && (n->priority > 0))
ospf_hello_send(NULL, 0, n);
} }
ospf_neigh_sm(n, INM_HELLOREC); ospf_neigh_sm(n, INM_HELLOREC);
} }
void void
ospf_hello_send(timer *timer,int poll, struct ospf_neighbor *dirn) ospf_hello_send(timer * timer, int poll, struct ospf_neighbor *dirn)
{ {
struct ospf_iface *ifa; struct ospf_iface *ifa;
struct ospf_hello_packet *pkt; struct ospf_hello_packet *pkt;
@ -167,59 +174,62 @@ ospf_hello_send(timer *timer,int poll, struct ospf_neighbor *dirn)
u32 *pp; u32 *pp;
u8 i; u8 i;
if(timer==NULL) ifa=dirn->ifa; if (timer == NULL)
else ifa=(struct ospf_iface *)timer->data; ifa = dirn->ifa;
else
ifa = (struct ospf_iface *) timer->data;
if(ifa->stub) return; /* Don't send any packet on stub iface */ if (ifa->stub)
return; /* Don't send any packet on stub iface */
p=(struct proto *)(ifa->proto); p = (struct proto *) (ifa->proto);
DBG("%s: Hello/Poll timer fired on interface %s.\n", DBG("%s: Hello/Poll timer fired on interface %s.\n",
p->name, ifa->iface->name); p->name, ifa->iface->name);
/* Now we should send a hello packet */ /* Now we should send a hello packet */
/* First a common packet header */ /* First a common packet header */
if(ifa->type!=OSPF_IT_NBMA) if (ifa->type != OSPF_IT_NBMA)
{ {
pkt=(struct ospf_hello_packet *)(ifa->hello_sk->tbuf); pkt = (struct ospf_hello_packet *) (ifa->hello_sk->tbuf);
} }
else else
{ {
pkt=(struct ospf_hello_packet *)(ifa->ip_sk->tbuf); pkt = (struct ospf_hello_packet *) (ifa->ip_sk->tbuf);
} }
/* Now fill ospf_hello header */ /* Now fill ospf_hello header */
op=(struct ospf_packet *)pkt; op = (struct ospf_packet *) pkt;
fill_ospf_pkt_hdr(ifa, pkt, HELLO_P); fill_ospf_pkt_hdr(ifa, pkt, HELLO_P);
pkt->netmask=ipa_mkmask(ifa->iface->addr->pxlen); pkt->netmask = ipa_mkmask(ifa->iface->addr->pxlen);
ipa_hton(pkt->netmask); ipa_hton(pkt->netmask);
pkt->helloint=ntohs(ifa->helloint); pkt->helloint = ntohs(ifa->helloint);
pkt->options=ifa->options; pkt->options = ifa->options;
pkt->priority=ifa->priority; pkt->priority = ifa->priority;
pkt->deadint=htonl(ifa->deadc*ifa->helloint); pkt->deadint = htonl(ifa->deadc * ifa->helloint);
pkt->dr=ifa->drip; pkt->dr = ifa->drip;
ipa_hton(pkt->dr); ipa_hton(pkt->dr);
pkt->bdr=ifa->bdrip; pkt->bdr = ifa->bdrip;
ipa_hton(pkt->bdr); ipa_hton(pkt->bdr);
/* Fill all neighbors */ /* Fill all neighbors */
i=0; i = 0;
pp=(u32 *)(((u8 *)pkt)+sizeof(struct ospf_hello_packet)); pp = (u32 *) (((u8 *) pkt) + sizeof(struct ospf_hello_packet));
WALK_LIST (neigh, ifa->neigh_list) WALK_LIST(neigh, ifa->neigh_list)
{ {
*(pp+i)=htonl(neigh->rid); *(pp + i) = htonl(neigh->rid);
i++; i++;
} }
length=sizeof(struct ospf_hello_packet)+i*sizeof(u32); length = sizeof(struct ospf_hello_packet) + i * sizeof(u32);
op->length=htons(length); op->length = htons(length);
ospf_pkt_finalize(ifa, op); ospf_pkt_finalize(ifa, op);
/* And finally send it :-) */ /* And finally send it :-) */
if(ifa->type!=OSPF_IT_NBMA) if (ifa->type != OSPF_IT_NBMA)
{ {
sk_send(ifa->hello_sk,length); sk_send(ifa->hello_sk, length);
} }
else /* NBMA */ else /* NBMA */
{ {
@ -227,44 +237,46 @@ ospf_hello_send(timer *timer,int poll, struct ospf_neighbor *dirn)
struct nbma_node *nb; struct nbma_node *nb;
int send; int send;
if(timer==NULL) /* Response to received hello */ if (timer == NULL) /* Response to received hello */
{ {
sk_send_to(ifa->ip_sk, length, dirn->ip, OSPF_PROTO); sk_send_to(ifa->ip_sk, length, dirn->ip, OSPF_PROTO);
} }
else else
{ {
int toall=0; int toall = 0;
int meeli=0; int meeli = 0;
if(ifa->state>OSPF_IS_DROTHER) toall=1; if (ifa->state > OSPF_IS_DROTHER)
if(ifa->priority>0) meeli=1; toall = 1;
if (ifa->priority > 0)
meeli = 1;
WALK_LIST(nb,ifa->nbma_list) WALK_LIST(nb, ifa->nbma_list)
{ {
send=1; send = 1;
WALK_LIST(n1, ifa->neigh_list) WALK_LIST(n1, ifa->neigh_list)
{ {
if(ipa_compare(nb->ip,n1->ip)==0) if (ipa_compare(nb->ip, n1->ip) == 0)
{ {
send=0; send = 0;
break; break;
} }
} }
if((poll==1)&&(send)) if ((poll == 1) && (send))
{ {
if(toall||(meeli&&nb->eligible)) if (toall || (meeli && nb->eligible))
sk_send_to(ifa->ip_sk, length, nb->ip, OSPF_PROTO); sk_send_to(ifa->ip_sk, length, nb->ip, OSPF_PROTO);
} }
} }
if(poll==0) if (poll == 0)
{ {
WALK_LIST(n1,ifa->neigh_list) WALK_LIST(n1, ifa->neigh_list)
{ {
if(toall||(n1->rid==ifa->drid)||(n1->rid==ifa->bdrid)|| if (toall || (n1->rid == ifa->drid) || (n1->rid == ifa->bdrid) ||
(meeli&&(n1->priority>0))) (meeli && (n1->priority > 0)))
sk_send_to(ifa->ip_sk, length, n1->ip, OSPF_PROTO); sk_send_to(ifa->ip_sk, length, n1->ip, OSPF_PROTO);
} }
} }
} }
} }
OSPF_TRACE(D_PACKETS, "Hello sent via %s",ifa->iface->name); OSPF_TRACE(D_PACKETS, "Hello sent via %s", ifa->iface->name);
} }

View file

@ -10,8 +10,8 @@
#ifndef _BIRD_OSPF_HELLO_H_ #ifndef _BIRD_OSPF_HELLO_H_
#define _BIRD_OSPF_HELLO_H_ #define _BIRD_OSPF_HELLO_H_
void ospf_hello_receive(struct ospf_hello_packet *ps, struct proto *p, void ospf_hello_receive(struct ospf_hello_packet *ps,
struct ospf_iface *ifa, int size, ip_addr faddr); struct ospf_iface *ifa, int size, ip_addr faddr);
void ospf_hello_send(timer *timer,int poll, struct ospf_neighbor *dirn); void ospf_hello_send(timer * timer, int poll, struct ospf_neighbor *dirn);
#endif /* _BIRD_OSPF_HELLO_H_ */ #endif /* _BIRD_OSPF_HELLO_H_ */

View file

@ -175,7 +175,7 @@ ospf_rx_hook (sock * sk, int size)
{ {
case HELLO_P: case HELLO_P:
DBG ("%s: Hello received.\n", p->name); DBG ("%s: Hello received.\n", p->name);
ospf_hello_receive((struct ospf_hello_packet *) ps, p, ifa, size, ospf_hello_receive((struct ospf_hello_packet *) ps, ifa, size,
sk->faddr); sk->faddr);
break; break;
case DBDES_P: case DBDES_P: