1999-11-17 23:50:41 +08:00
|
|
|
/*
|
|
|
|
* BIRD -- OSPF
|
|
|
|
*
|
2000-06-08 06:56:52 +08:00
|
|
|
* (c) 1999 - 2000 Ondrej Filip <feela@network.cz>
|
1999-11-17 23:50:41 +08:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ospf.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
install_inactim(struct ospf_neighbor *n)
|
|
|
|
{
|
|
|
|
struct proto *p;
|
|
|
|
struct ospf_iface *ifa;
|
|
|
|
|
|
|
|
ifa=n->ifa;
|
|
|
|
p=(struct proto *)(ifa->proto);
|
|
|
|
|
|
|
|
if(n->inactim==NULL)
|
|
|
|
{
|
|
|
|
n->inactim=tm_new(p->pool);
|
|
|
|
n->inactim->data=n;
|
|
|
|
n->inactim->randomize=0;
|
|
|
|
n->inactim->hook=neighbor_timer_hook;
|
|
|
|
n->inactim->recurrent=0;
|
|
|
|
DBG("%s: Installing inactivity timer.\n", p->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
restart_inactim(struct ospf_neighbor *n)
|
|
|
|
{
|
|
|
|
tm_start(n->inactim,n->ifa->deadc*n->ifa->helloint);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
restart_hellotim(struct ospf_iface *ifa)
|
|
|
|
{
|
|
|
|
tm_start(ifa->hello_timer,ifa->helloint);
|
|
|
|
}
|
|
|
|
|
2000-09-02 08:03:36 +08:00
|
|
|
void
|
|
|
|
restart_polltim(struct ospf_iface *ifa)
|
|
|
|
{
|
|
|
|
if(ifa->poll_timer)
|
|
|
|
tm_start(ifa->poll_timer,ifa->pollint);
|
|
|
|
}
|
|
|
|
|
1999-11-17 23:50:41 +08:00
|
|
|
void
|
|
|
|
restart_waittim(struct ospf_iface *ifa)
|
|
|
|
{
|
|
|
|
tm_start(ifa->wait_timer,ifa->waitint);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ospf_hello_rx(struct ospf_hello_packet *ps, struct proto *p,
|
|
|
|
struct ospf_iface *ifa, int size, ip_addr faddr)
|
|
|
|
{
|
|
|
|
u32 nrid, *pnrid;
|
|
|
|
struct ospf_neighbor *neigh,*n;
|
2003-09-04 01:31:23 +08:00
|
|
|
u8 twoway,oldpriority;
|
|
|
|
u32 i;
|
2000-06-08 09:49:19 +08:00
|
|
|
ip_addr olddr,oldbdr;
|
2000-06-08 10:28:04 +08:00
|
|
|
ip_addr mask;
|
2000-04-19 02:21:10 +08:00
|
|
|
char *beg=": Bad OSPF hello packet from ", *rec=" received: ";
|
2000-09-02 08:03:36 +08:00
|
|
|
int eligible=0;
|
1999-11-17 23:50:41 +08:00
|
|
|
|
|
|
|
nrid=ntohl(((struct ospf_packet *)ps)->routerid);
|
|
|
|
|
2000-06-06 10:34:57 +08:00
|
|
|
OSPF_TRACE(D_PACKETS, "Received hello from %I via %s",faddr,ifa->iface->name);
|
2000-06-08 10:28:04 +08:00
|
|
|
mask=ps->netmask;
|
|
|
|
ipa_ntoh(mask);
|
2000-05-11 07:42:13 +08:00
|
|
|
|
2000-06-08 10:28:04 +08:00
|
|
|
if((unsigned)ipa_mklen(mask)!=ifa->iface->addr->pxlen)
|
1999-11-17 23:50:41 +08:00
|
|
|
{
|
2000-06-14 03:03:41 +08:00
|
|
|
log("%s%s%I%sbad netmask %I.", p->name, beg, nrid, rec,
|
2000-06-08 10:28:04 +08:00
|
|
|
mask);
|
1999-11-17 23:50:41 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ntohs(ps->helloint)!=ifa->helloint)
|
|
|
|
{
|
2000-06-05 03:56:06 +08:00
|
|
|
log("%s%s%I%shello interval mismatch.", p->name, beg, faddr, rec);
|
1999-11-17 23:50:41 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ntohl(ps->deadint)!=ifa->helloint*ifa->deadc)
|
|
|
|
{
|
2000-06-05 03:56:06 +08:00
|
|
|
log("%s%s%I%sdead interval mismatch.", p->name, beg, faddr, rec);
|
1999-11-17 23:50:41 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ps->options!=ifa->options)
|
|
|
|
{
|
2000-06-05 03:56:06 +08:00
|
|
|
log("%s%s%I%soptions mismatch.", p->name, beg, faddr, rec);
|
1999-11-17 23:50:41 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if((n=find_neigh(ifa, nrid))==NULL)
|
|
|
|
{
|
2000-09-02 08:03:36 +08:00
|
|
|
if((ifa->type==OSPF_IT_NBMA))
|
|
|
|
{
|
|
|
|
struct nbma_node *nn;
|
|
|
|
int found=0;
|
|
|
|
|
|
|
|
WALK_LIST(nn,ifa->nbma_list)
|
|
|
|
{
|
|
|
|
if(ipa_compare(faddr,nn->ip)==0)
|
|
|
|
{
|
|
|
|
found=1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if((found==0)&&(ifa->strictnbma))
|
|
|
|
{
|
2000-09-04 00:16:33 +08:00
|
|
|
log("%s: Ignoring new neighbor: %I on %s.", p->name, faddr,
|
2000-09-02 08:03:36 +08:00
|
|
|
ifa->iface->name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(found)
|
|
|
|
{
|
|
|
|
eligible=nn->eligible;
|
|
|
|
if(((ps->priority==0)&&eligible)||((ps->priority>0)&&(eligible==0)))
|
|
|
|
{
|
2000-09-04 00:16:33 +08:00
|
|
|
log("%s: Eligibility mismatch for neighbor: %I on %s", p->name,
|
2000-09-02 08:03:36 +08:00
|
|
|
faddr, ifa->iface->name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-06-06 10:34:57 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "New neighbor found: %I on %s.", faddr,
|
2000-05-11 07:42:13 +08:00
|
|
|
ifa->iface->name);
|
2000-05-09 06:24:22 +08:00
|
|
|
n=mb_allocz(p->pool, sizeof(struct ospf_neighbor));
|
1999-11-17 23:50:41 +08:00
|
|
|
add_tail(&ifa->neigh_list, NODE n);
|
|
|
|
n->rid=nrid;
|
|
|
|
n->ip=faddr;
|
2000-06-08 10:28:04 +08:00
|
|
|
n->dr=ps->dr;
|
|
|
|
ipa_ntoh(n->dr);
|
|
|
|
n->bdr=ps->bdr;
|
|
|
|
ipa_ntoh(n->bdr);
|
1999-11-17 23:50:41 +08:00
|
|
|
n->priority=ps->priority;
|
|
|
|
n->options=ps->options;
|
|
|
|
n->ifa=ifa;
|
|
|
|
n->adj=0;
|
2000-03-08 20:50:28 +08:00
|
|
|
n->ldbdes=mb_alloc(p->pool, ifa->iface->mtu);
|
2000-05-09 06:24:22 +08:00
|
|
|
n->state=NEIGHBOR_DOWN;
|
1999-11-17 23:50:41 +08:00
|
|
|
install_inactim(n);
|
2000-03-30 01:18:06 +08:00
|
|
|
n->rxmt_timer=tm_new(p->pool);
|
|
|
|
n->rxmt_timer->data=n;
|
|
|
|
n->rxmt_timer->randomize=0;
|
|
|
|
n->rxmt_timer->hook=rxmt_timer_hook;
|
|
|
|
n->rxmt_timer->recurrent=ifa->rxmtint;
|
|
|
|
DBG("%s: Installing rxmt timer.\n", p->name);
|
2000-03-30 08:18:59 +08:00
|
|
|
n->lsrr_timer=tm_new(p->pool);
|
|
|
|
n->lsrr_timer->data=n;
|
|
|
|
n->lsrr_timer->randomize=0;
|
|
|
|
n->lsrr_timer->hook=lsrr_timer_hook;
|
|
|
|
n->lsrr_timer->recurrent=ifa->rxmtint;
|
|
|
|
DBG("%s: Installing lsrr timer.\n", p->name);
|
2000-04-18 09:06:16 +08:00
|
|
|
init_list(&n->ackl);
|
|
|
|
n->ackd_timer=tm_new(p->pool);
|
|
|
|
n->ackd_timer->data=n;
|
|
|
|
n->ackd_timer->randomize=0;
|
|
|
|
n->ackd_timer->hook=ackd_timer_hook;
|
2000-06-08 05:50:16 +08:00
|
|
|
n->ackd_timer->recurrent=ifa->rxmtint/2;
|
2000-04-18 09:06:16 +08:00
|
|
|
DBG("%s: Installing ackd timer.\n", p->name);
|
1999-11-17 23:50:41 +08:00
|
|
|
}
|
|
|
|
ospf_neigh_sm(n, INM_HELLOREC);
|
|
|
|
|
|
|
|
pnrid=(u32 *)((struct ospf_hello_packet *)(ps+1));
|
|
|
|
|
|
|
|
twoway=0;
|
|
|
|
for(i=0;i<size-(sizeof(struct ospf_hello_packet));i++)
|
|
|
|
{
|
|
|
|
if(ntohl(*(pnrid+i))==p->cf->global->router_id)
|
|
|
|
{
|
2000-05-11 07:42:13 +08:00
|
|
|
DBG("%s: Twoway received from %I\n", p->name, faddr);
|
1999-11-17 23:50:41 +08:00
|
|
|
ospf_neigh_sm(n, INM_2WAYREC);
|
|
|
|
twoway=1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!twoway) ospf_neigh_sm(n, INM_1WAYREC);
|
|
|
|
|
2000-05-09 19:27:31 +08:00
|
|
|
olddr = n->dr;
|
2000-06-08 10:04:45 +08:00
|
|
|
n->dr = ipa_ntoh(ps->dr);
|
2000-05-09 19:27:31 +08:00
|
|
|
oldbdr = n->bdr;
|
2000-06-08 10:04:45 +08:00
|
|
|
n->bdr = ipa_ntoh(ps->bdr);
|
2000-05-09 19:27:31 +08:00
|
|
|
oldpriority = n->priority;
|
|
|
|
n->priority = ps->priority;
|
|
|
|
|
1999-11-17 23:50:41 +08:00
|
|
|
/* Check priority change */
|
2000-05-09 19:27:31 +08:00
|
|
|
if(n->state>=NEIGHBOR_2WAY)
|
1999-11-17 23:50:41 +08:00
|
|
|
{
|
2000-05-09 19:27:31 +08:00
|
|
|
if(n->priority!=oldpriority) ospf_int_sm(ifa, ISM_NEICH);
|
1999-11-17 23:50:41 +08:00
|
|
|
|
2000-05-09 19:27:31 +08:00
|
|
|
/* Router is declaring itself ad DR and there is no BDR */
|
2000-06-08 09:49:19 +08:00
|
|
|
if((ipa_compare(n->ip,n->dr)==0) && (ipa_to_u32(n->bdr)==0)
|
|
|
|
&& (n->state!=NEIGHBOR_FULL))
|
2000-05-10 02:35:57 +08:00
|
|
|
ospf_int_sm(ifa, ISM_BACKS);
|
1999-11-17 23:50:41 +08:00
|
|
|
|
2000-05-09 19:27:31 +08:00
|
|
|
/* Neighbor is declaring itself as BDR */
|
2000-06-08 09:49:19 +08:00
|
|
|
if((ipa_compare(n->ip,n->bdr)==0) && (n->state!=NEIGHBOR_FULL))
|
2000-05-10 02:35:57 +08:00
|
|
|
ospf_int_sm(ifa, ISM_BACKS);
|
2000-05-09 19:27:31 +08:00
|
|
|
|
|
|
|
/* Neighbor is newly declaring itself as DR or BDR */
|
2000-06-08 09:49:19 +08:00
|
|
|
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)))
|
2000-05-09 19:27:31 +08:00
|
|
|
ospf_int_sm(ifa, ISM_NEICH);
|
|
|
|
|
|
|
|
/* Neighbor is no more declaring itself as DR or BDR */
|
2000-06-08 09:49:19 +08:00
|
|
|
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)))
|
2000-05-09 19:27:31 +08:00
|
|
|
ospf_int_sm(ifa, ISM_NEICH);
|
1999-11-17 23:50:41 +08:00
|
|
|
}
|
|
|
|
|
2000-09-02 08:03:36 +08:00
|
|
|
if(ifa->type!=OSPF_IT_NBMA)
|
|
|
|
{
|
|
|
|
if((ifa->priority==0)&&(n->priority>0)) hello_send(NULL,0, n);
|
|
|
|
}
|
1999-11-17 23:50:41 +08:00
|
|
|
ospf_neigh_sm(n, INM_HELLOREC);
|
|
|
|
}
|
|
|
|
|
2000-09-02 08:03:36 +08:00
|
|
|
void
|
|
|
|
poll_timer_hook(timer *timer)
|
|
|
|
{
|
|
|
|
hello_send(timer,1, NULL);
|
|
|
|
}
|
|
|
|
|
1999-11-17 23:50:41 +08:00
|
|
|
void
|
|
|
|
hello_timer_hook(timer *timer)
|
2000-09-02 08:03:36 +08:00
|
|
|
{
|
|
|
|
hello_send(timer,0, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
hello_send(timer *timer,int poll, struct ospf_neighbor *dirn)
|
1999-11-17 23:50:41 +08:00
|
|
|
{
|
|
|
|
struct ospf_iface *ifa;
|
|
|
|
struct ospf_hello_packet *pkt;
|
|
|
|
struct ospf_packet *op;
|
|
|
|
struct proto *p;
|
|
|
|
struct ospf_neighbor *neigh;
|
|
|
|
u16 length;
|
|
|
|
u32 *pp;
|
|
|
|
u8 i;
|
|
|
|
|
2000-09-02 08:03:36 +08:00
|
|
|
if(timer==NULL) ifa=dirn->ifa;
|
|
|
|
else ifa=(struct ospf_iface *)timer->data;
|
|
|
|
|
2000-09-02 16:54:40 +08:00
|
|
|
if(ifa->stub) return; /* Don't send any packet on stub iface */
|
|
|
|
|
1999-11-17 23:50:41 +08:00
|
|
|
p=(struct proto *)(ifa->proto);
|
2000-09-02 08:03:36 +08:00
|
|
|
DBG("%s: Hello/Poll timer fired on interface %s.\n",
|
1999-11-17 23:50:41 +08:00
|
|
|
p->name, ifa->iface->name);
|
|
|
|
/* Now we should send a hello packet */
|
|
|
|
/* First a common packet header */
|
|
|
|
if(ifa->type!=OSPF_IT_NBMA)
|
|
|
|
{
|
|
|
|
pkt=(struct ospf_hello_packet *)(ifa->hello_sk->tbuf);
|
2000-06-06 07:44:26 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pkt=(struct ospf_hello_packet *)(ifa->ip_sk->tbuf);
|
|
|
|
}
|
1999-11-17 23:50:41 +08:00
|
|
|
|
2000-06-06 07:44:26 +08:00
|
|
|
/* Now fill ospf_hello header */
|
|
|
|
op=(struct ospf_packet *)pkt;
|
1999-11-17 23:50:41 +08:00
|
|
|
|
2000-06-06 07:44:26 +08:00
|
|
|
fill_ospf_pkt_hdr(ifa, pkt, HELLO_P);
|
|
|
|
|
|
|
|
pkt->netmask=ipa_mkmask(ifa->iface->addr->pxlen);
|
|
|
|
ipa_hton(pkt->netmask);
|
|
|
|
pkt->helloint=ntohs(ifa->helloint);
|
|
|
|
pkt->options=ifa->options;
|
|
|
|
pkt->priority=ifa->priority;
|
|
|
|
pkt->deadint=htonl(ifa->deadc*ifa->helloint);
|
2000-06-08 10:28:04 +08:00
|
|
|
pkt->dr=ifa->drip;
|
|
|
|
ipa_hton(pkt->dr);
|
|
|
|
pkt->bdr=ifa->bdrip;
|
|
|
|
ipa_hton(pkt->bdr);
|
2000-06-06 07:44:26 +08:00
|
|
|
|
|
|
|
/* Fill all neighbors */
|
|
|
|
i=0;
|
|
|
|
pp=(u32 *)(((u8 *)pkt)+sizeof(struct ospf_hello_packet));
|
|
|
|
WALK_LIST (neigh, ifa->neigh_list)
|
|
|
|
{
|
|
|
|
*(pp+i)=htonl(neigh->rid);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
length=sizeof(struct ospf_hello_packet)+i*sizeof(u32);
|
|
|
|
op->length=htons(length);
|
|
|
|
|
|
|
|
ospf_pkt_finalize(ifa, op);
|
1999-11-17 23:50:41 +08:00
|
|
|
|
|
|
|
/* And finally send it :-) */
|
2000-06-06 07:44:26 +08:00
|
|
|
if(ifa->type!=OSPF_IT_NBMA)
|
|
|
|
{
|
1999-11-17 23:50:41 +08:00
|
|
|
sk_send(ifa->hello_sk,length);
|
|
|
|
}
|
2000-06-06 07:44:26 +08:00
|
|
|
else /* NBMA */
|
|
|
|
{
|
|
|
|
struct ospf_neighbor *n1;
|
|
|
|
struct nbma_node *nb;
|
|
|
|
int send;
|
2000-05-11 07:42:13 +08:00
|
|
|
|
2000-09-02 08:03:36 +08:00
|
|
|
if(timer==NULL) /* Response to received hello */
|
|
|
|
{
|
|
|
|
sk_send_to(ifa->ip_sk, length, dirn->ip, OSPF_PROTO);
|
|
|
|
}
|
|
|
|
else
|
2000-06-06 07:44:26 +08:00
|
|
|
{
|
2000-09-02 08:03:36 +08:00
|
|
|
int toall=0;
|
|
|
|
int meeli=0;
|
|
|
|
if(ifa->state>OSPF_IS_DROTHER) toall=1;
|
|
|
|
if(ifa->priority>0) meeli=1;
|
|
|
|
|
|
|
|
WALK_LIST(nb,ifa->nbma_list)
|
2000-06-06 07:44:26 +08:00
|
|
|
{
|
2000-09-02 08:03:36 +08:00
|
|
|
send=1;
|
|
|
|
WALK_LIST(n1, ifa->neigh_list)
|
|
|
|
{
|
|
|
|
if(ipa_compare(nb->ip,n1->ip)==0)
|
|
|
|
{
|
|
|
|
send=0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if((poll==1)&&(send))
|
2000-06-06 07:44:26 +08:00
|
|
|
{
|
2000-09-02 08:03:36 +08:00
|
|
|
if(toall||(meeli&&nb->eligible))
|
|
|
|
sk_send_to(ifa->ip_sk, length, nb->ip, OSPF_PROTO);
|
2000-06-06 07:44:26 +08:00
|
|
|
}
|
|
|
|
}
|
2000-09-02 08:03:36 +08:00
|
|
|
if(poll==0)
|
|
|
|
{
|
|
|
|
WALK_LIST(n1,ifa->neigh_list)
|
|
|
|
{
|
|
|
|
if(toall||(n1->rid==ifa->drid)||(n1->rid==ifa->bdrid)||
|
|
|
|
(meeli&&(n1->priority>0)))
|
|
|
|
sk_send_to(ifa->ip_sk, length, n1->ip, OSPF_PROTO);
|
|
|
|
}
|
|
|
|
}
|
2000-06-06 07:44:26 +08:00
|
|
|
}
|
|
|
|
}
|
2000-06-06 10:34:57 +08:00
|
|
|
OSPF_TRACE(D_PACKETS, "Hello sent via %s",ifa->iface->name);
|
1999-11-17 23:50:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
wait_timer_hook(timer *timer)
|
|
|
|
{
|
|
|
|
struct ospf_iface *ifa;
|
|
|
|
struct proto *p;
|
|
|
|
|
|
|
|
ifa=(struct ospf_iface *)timer->data;
|
|
|
|
p=(struct proto *)(ifa->proto);
|
2000-06-06 10:50:49 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "Wait timer fired on interface %s.",
|
|
|
|
ifa->iface->name);
|
1999-11-17 23:50:41 +08:00
|
|
|
ospf_int_sm(ifa, ISM_WAITF);
|
|
|
|
}
|
|
|
|
|