diff options
author | Ondrej Filip <feela@network.cz> | 1999-06-01 18:35:18 +0200 |
---|---|---|
committer | Ondrej Filip <feela@network.cz> | 1999-06-01 18:35:18 +0200 |
commit | cd70d93470498c0b68a084be5aeab5dd45a0df60 (patch) | |
tree | ec9f4b8f8fac9442e71ee2cd367eff89c252c1b1 | |
parent | bd7f1081f24aa6ca4cdba004478742b730644a91 (diff) | |
download | bird-cd70d93470498c0b68a084be5aeab5dd45a0df60.tar bird-cd70d93470498c0b68a084be5aeab5dd45a0df60.zip |
Detecting of new neighbor added. It starts inactivity timer.
-rw-r--r-- | proto/ospf/ospf.c | 68 | ||||
-rw-r--r-- | proto/ospf/ospf.h | 8 |
2 files changed, 63 insertions, 13 deletions
diff --git a/proto/ospf/ospf.c b/proto/ospf/ospf.c index 47c87f8..de60f4e 100644 --- a/proto/ospf/ospf.c +++ b/proto/ospf/ospf.c @@ -24,16 +24,35 @@ #include "ospf.h" void +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); + debug("%s: Inactivity timer fired on interface %s for neighbor %d.\n", + p->name, ifa->iface->name, n->rid); +} + +void ospf_hello_rx(struct ospf_hello_packet *ps, struct proto *p, struct ospf_iface *ifa) { char sip[100]; /* FIXME: Should be smaller */ + u32 nrid; + struct ospf_neighbor *neigh,*n; + int i; + + nrid=ntohl(((struct ospf_packet *)ps)->routerid); if(ipa_mklen(ipa_ntoh(ps->netmask))!=ifa->iface->addr->pxlen) { ip_ntop(ps->netmask,sip); log("%s: Bad OSPF packet from %d received: bad netmask %s.", - p->name, ntohl(((struct ospf_packet *)ps)->routerid), sip); + p->name, nrid, sip); log("%s: Discarding",p->name); return; } @@ -41,7 +60,7 @@ ospf_hello_rx(struct ospf_hello_packet *ps, struct proto *p, if(ntohs(ps->helloint)!=ifa->helloint) { log("%s: Bad OSPF packet from %d received: hello interval mismatch.", - p->name, ntohl(((struct ospf_packet *)ps)->routerid)); + p->name, nrid); log("%s: Discarding",p->name); return; } @@ -49,19 +68,53 @@ ospf_hello_rx(struct ospf_hello_packet *ps, struct proto *p, if(ntohl(ps->deadint)!=ifa->helloint*ifa->deadc) { log("%s: Bad OSPF packet from %d received: dead interval mismatch.", - p->name, ntohl(((struct ospf_packet *)ps)->routerid)); + p->name, nrid); log("%s: Discarding",p->name); return; } + if(ps->options!=ifa->options) { log("%s: Bad OSPF packet from %d received: options mismatch.", - p->name, ntohl(((struct ospf_packet *)ps)->routerid)); + p->name, nrid); log("%s: Discarding",p->name); return; } + n=NULL; + WALK_LIST (neigh, ifa->neigh_list) + { + if(neigh->rid==nrid) + { + n=neigh; + break; + } + } + + if(n==NULL) + { + log("%s: New neighbor found: %d.",p->name,nrid); + n=mb_alloc(p->pool, sizeof(struct ospf_neighbor)); + add_tail(&ifa->neigh_list, NODE n); + n->inactim=tm_new(p->pool); + n->inactim->data=n; + n->inactim->randomize=0; + n->inactim->hook=neighbor_timer_hook; + n->inactim->recurrent=ifa->deadc*ifa->helloint; + n->inactim->expires=0; + tm_start(ifa->hello_timer,ifa->deadc*ifa->helloint); + DBG("%s: Installing inactivity timer.\n", p->name); + n->state=NEIGHBOR_INIT; + n->rid=nrid; + n->dr=ntohl(ps->dr); + n->bdr=ntohl(ps->bdr); + n->priority=ps->priority; + n->options=ps->options; + } + + /* XXXX */ + switch(ifa->state) { case OSPF_IS_DOWN: @@ -323,8 +376,7 @@ hello_timer_hook(timer *timer) p->name, ifa->iface->name); /* Now we should send a hello packet */ /* First a common packet header */ - //if(ifa->type!=OSPF_IT_NBMA) - if(ifa->hello_sk!=NULL) + if(ifa->type!=OSPF_IT_NBMA) { /* Now fill ospf_hello header */ pkt=(struct ospf_hello_packet *)(ifa->hello_sk->tbuf); @@ -359,9 +411,8 @@ hello_timer_hook(timer *timer) op->checksum=ipsum_calculate(op,sizeof(struct ospf_packet)-8, &(pkt->netmask),length-sizeof(struct ospf_packet),NULL); + /* And finally send it :-) */ sk_send(ifa->hello_sk,length); - - /* XXXX */ } } @@ -434,7 +485,6 @@ ospf_add_timers(struct ospf_iface *ifa, pool *pool, int wait) DBG(": Installing wait timer.\n"); } else ifa->state=OSPF_IS_PTP; - } void diff --git a/proto/ospf/ospf.h b/proto/ospf/ospf.h index 19c9eeb..164bed3 100644 --- a/proto/ospf/ospf.h +++ b/proto/ospf/ospf.h @@ -113,9 +113,9 @@ struct ospf_neighbor struct ospf_iface *ifa; int state; #define NEIGHBOR_DOWN 0 -#define NEIGHBOR_INIT 1 -#define NEIGHBOR_2WAY 2 -#define NEIGHBOR_ATTEMPT 3 +#define NEIGHBOR_ATTEMPT 1 +#define NEIGHBOR_INIT 2 +#define NEIGHBOR_2WAY 3 #define NEIGHBOR_EXSTART 4 #define NEIGHBOR_EXCHANGE 5 #define NEIGHBOR_LOADING 6 @@ -125,7 +125,7 @@ struct ospf_neighbor u32 dds; /* DD Sequence number being sentg */ u32 ddr; /* last Dat Des packet */ u32 rid; /* Router ID */ - byte pri; /* Priority */ + byte priority; /* Priority */ byte options; /* Options */ u32 dr; /* Neigbour's idea of DR */ u32 bdr; /* Neigbour's idea of BDR */ |