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,7 +9,7 @@
#include "ospf.h"
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)
{
u32 nrid, *pnrid;
@ -17,38 +17,39 @@ ospf_hello_receive(struct ospf_hello_packet *ps, struct proto *p,
u8 i, twoway, oldpriority;
ip_addr olddr, oldbdr;
ip_addr mask;
char *beg=": Bad OSPF hello packet from ", *rec=" received: ";
char *beg = "Bad OSPF hello packet from ", *rec = " received: ";
int eligible = 0;
pool *pool;
struct proto *p = (struct proto *) ifa->proto;
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,
ifa->iface->name);
mask = ps->netmask;
ipa_ntoh(mask);
if ((unsigned) ipa_mklen(mask) != ifa->iface->addr->pxlen)
{
log("%s%s%I%sbad netmask %I.", p->name, beg, nrid, rec,
mask);
log(L_ERR, "%s%I%sbad netmask %I.", beg, nrid, rec, mask);
return;
}
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;
}
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;
}
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;
}
@ -69,16 +70,17 @@ ospf_hello_receive(struct ospf_hello_packet *ps, struct proto *p,
}
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);
return;
}
if (found)
{
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);
return;
}
@ -114,7 +116,8 @@ ospf_hello_receive(struct ospf_hello_packet *ps, struct proto *p,
}
}
if(!twoway) ospf_neigh_sm(n, INM_1WAYREC);
if (!twoway)
ospf_neigh_sm(n, INM_1WAYREC);
olddr = n->dr;
n->dr = ipa_ntoh(ps->dr);
@ -126,7 +129,8 @@ ospf_hello_receive(struct ospf_hello_packet *ps, struct proto *p,
/* Check priority change */
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 */
if ((ipa_compare(n->ip, n->dr) == 0) && (ipa_to_u32(n->bdr) == 0)
@ -139,18 +143,21 @@ ospf_hello_receive(struct ospf_hello_packet *ps, struct proto *p,
/* Neighbor is newly declaring itself as DR or BDR */
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);
/* Neighbor is no more declaring itself as DR or BDR */
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);
}
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);
}
@ -167,10 +174,13 @@ ospf_hello_send(timer *timer,int poll, struct ospf_neighbor *dirn)
u32 *pp;
u8 i;
if(timer==NULL) ifa=dirn->ifa;
else ifa=(struct ospf_iface *)timer->data;
if (timer == NULL)
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);
DBG("%s: Hello/Poll timer fired on interface %s.\n",
@ -235,8 +245,10 @@ ospf_hello_send(timer *timer,int poll, struct ospf_neighbor *dirn)
{
int toall = 0;
int meeli = 0;
if(ifa->state>OSPF_IS_DROTHER) toall=1;
if(ifa->priority>0) meeli=1;
if (ifa->state > OSPF_IS_DROTHER)
toall = 1;
if (ifa->priority > 0)
meeli = 1;
WALK_LIST(nb, ifa->nbma_list)
{

View file

@ -10,7 +10,7 @@
#ifndef _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);
void ospf_hello_send(timer * timer, int poll, struct ospf_neighbor *dirn);

View file

@ -175,7 +175,7 @@ ospf_rx_hook (sock * sk, int size)
{
case HELLO_P:
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);
break;
case DBDES_P: