1999-11-17 15:50:41 +00:00
|
|
|
/*
|
|
|
|
* BIRD -- OSPF
|
|
|
|
*
|
2000-06-07 21:46:22 +00:00
|
|
|
* (c) 1999 - 2000 Ondrej Filip <feela@network.cz>
|
1999-11-17 15:50:41 +00:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ospf.h"
|
|
|
|
|
2000-06-01 15:53:06 +00:00
|
|
|
char *ospf_ns[]={" down",
|
|
|
|
" attempt",
|
|
|
|
" init",
|
|
|
|
" 2way",
|
|
|
|
" exstart",
|
|
|
|
"exchange",
|
|
|
|
" loading",
|
|
|
|
" full"};
|
2000-04-18 17:58:16 +00:00
|
|
|
|
2000-04-18 19:22:49 +00:00
|
|
|
const char *ospf_inm[]={ "hello received", "neighbor start", "2-way received",
|
|
|
|
"negotiation done", "exstart done", "bad ls request", "load done",
|
|
|
|
"adjacency ok?", "sequence mismatch", "1-way received", "kill neighbor",
|
|
|
|
"inactivity timer", "line down" };
|
|
|
|
|
2000-06-07 21:46:22 +00:00
|
|
|
/**
|
|
|
|
* neigh_chstate - handles changes related to new or lod state of neighbor
|
|
|
|
* @n: OSPF neighbor
|
|
|
|
* @state: new state
|
|
|
|
*
|
2003-08-23 10:42:41 +00:00
|
|
|
* Many actions have to be taken acording to a change of state of a neighbor. It
|
2000-06-07 21:46:22 +00:00
|
|
|
* starts rxmt timers, call interface state machine etc.
|
|
|
|
*/
|
|
|
|
|
1999-11-17 15:50:41 +00:00
|
|
|
void
|
|
|
|
neigh_chstate(struct ospf_neighbor *n, u8 state)
|
|
|
|
{
|
2000-05-08 22:40:55 +00:00
|
|
|
u8 oldstate;
|
1999-11-17 15:50:41 +00:00
|
|
|
|
2000-05-08 22:40:55 +00:00
|
|
|
oldstate=n->state;
|
|
|
|
|
|
|
|
if(oldstate!=state)
|
1999-11-17 15:50:41 +00:00
|
|
|
{
|
2000-05-09 11:52:44 +00:00
|
|
|
struct ospf_iface *ifa=n->ifa;
|
|
|
|
struct proto_ospf *po=ifa->oa->po;
|
|
|
|
struct proto *p=&po->proto;
|
|
|
|
|
2000-05-08 22:40:55 +00:00
|
|
|
n->state=state;
|
2000-05-09 11:52:44 +00:00
|
|
|
|
2000-06-06 02:34:57 +00:00
|
|
|
OSPF_TRACE( D_EVENTS, "Neighbor %I changes state from \"%s\" to \"%s\".",
|
|
|
|
n->ip, ospf_ns[oldstate], ospf_ns[state]);
|
2000-05-09 11:52:44 +00:00
|
|
|
|
2000-05-09 11:29:52 +00:00
|
|
|
if((state==NEIGHBOR_2WAY) && (oldstate<NEIGHBOR_2WAY))
|
2000-05-09 11:52:44 +00:00
|
|
|
ospf_int_sm(ifa, ISM_NEICH);
|
2000-05-09 11:29:52 +00:00
|
|
|
if((state<NEIGHBOR_2WAY) && (oldstate>=NEIGHBOR_2WAY))
|
2000-05-09 11:52:44 +00:00
|
|
|
ospf_int_sm(ifa, ISM_NEICH);
|
|
|
|
|
2000-05-08 22:40:55 +00:00
|
|
|
if(oldstate==NEIGHBOR_FULL) /* Decrease number of adjacencies */
|
2000-05-03 00:08:48 +00:00
|
|
|
{
|
2000-05-04 01:23:03 +00:00
|
|
|
ifa->fadj--;
|
2000-05-31 14:06:33 +00:00
|
|
|
schedule_rt_lsa(ifa->oa);
|
2001-08-11 14:01:54 +00:00
|
|
|
schedule_net_lsa(ifa);
|
2000-05-03 00:08:48 +00:00
|
|
|
}
|
1999-11-17 15:50:41 +00:00
|
|
|
|
2000-05-08 22:40:55 +00:00
|
|
|
if(state==NEIGHBOR_FULL) /* Increase number of adjacencies */
|
2000-05-03 00:08:48 +00:00
|
|
|
{
|
2000-05-04 01:23:03 +00:00
|
|
|
ifa->fadj++;
|
2000-05-31 14:06:33 +00:00
|
|
|
schedule_rt_lsa(ifa->oa);
|
2001-08-11 14:01:54 +00:00
|
|
|
schedule_net_lsa(ifa);
|
2000-05-03 00:08:48 +00:00
|
|
|
}
|
2004-05-31 13:22:49 +00:00
|
|
|
if(oldstate>=NEIGHBOR_EXSTART && state<NEIGHBOR_EXSTART)
|
|
|
|
{
|
|
|
|
/* Stop RXMT timer */
|
|
|
|
tm_stop(n->rxmt_timer);
|
|
|
|
}
|
2000-05-08 22:40:55 +00:00
|
|
|
if(state==NEIGHBOR_EXSTART)
|
|
|
|
{
|
|
|
|
if(n->adj==0) /* First time adjacency */
|
|
|
|
{
|
|
|
|
n->dds=random_u32();
|
|
|
|
}
|
|
|
|
n->dds++;
|
|
|
|
n->myimms.byte=0;
|
|
|
|
n->myimms.bit.ms=1;
|
|
|
|
n->myimms.bit.m=1;
|
|
|
|
n->myimms.bit.i=1;
|
|
|
|
tm_start(n->rxmt_timer,1); /* Or some other number ? */
|
|
|
|
}
|
2000-05-08 23:46:31 +00:00
|
|
|
if(state<NEIGHBOR_EXCHANGE) tm_stop(n->lsrr_timer);
|
2003-08-23 10:47:46 +00:00
|
|
|
if(state<NEIGHBOR_EXSTART) tm_stop(n->rxmt_timer);
|
|
|
|
if(state>NEIGHBOR_EXSTART) n->myimms.bit.i=0;
|
1999-11-17 15:50:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ospf_neighbor *
|
|
|
|
electbdr(list nl)
|
|
|
|
{
|
|
|
|
struct ospf_neighbor *neigh,*n1,*n2;
|
|
|
|
|
|
|
|
n1=NULL;
|
|
|
|
n2=NULL;
|
|
|
|
WALK_LIST (neigh, nl) /* First try those decl. themselves */
|
|
|
|
{
|
|
|
|
if(neigh->state>=NEIGHBOR_2WAY) /* Higher than 2WAY */
|
|
|
|
if(neigh->priority>0) /* Eligible */
|
2000-06-08 01:49:19 +00:00
|
|
|
if(ipa_compare(neigh->ip,neigh->dr)!=0) /* And not decl. itself DR */
|
1999-11-17 15:50:41 +00:00
|
|
|
{
|
2000-06-08 01:49:19 +00:00
|
|
|
if(ipa_compare(neigh->ip,neigh->bdr)==0) /* Declaring BDR */
|
1999-11-17 15:50:41 +00:00
|
|
|
{
|
|
|
|
if(n1!=NULL)
|
|
|
|
{
|
|
|
|
if(neigh->priority>n1->priority) n1=neigh;
|
|
|
|
else if(neigh->priority==n1->priority)
|
|
|
|
if(neigh->rid>n1->rid) n1=neigh;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
n1=neigh;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* And NOT declaring BDR */
|
|
|
|
{
|
|
|
|
if(n2!=NULL)
|
|
|
|
{
|
|
|
|
if(neigh->priority>n2->priority) n2=neigh;
|
|
|
|
else if(neigh->priority==n2->priority)
|
|
|
|
if(neigh->rid>n2->rid) n2=neigh;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
n2=neigh;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(n1==NULL) n1=n2;
|
|
|
|
|
|
|
|
return(n1);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ospf_neighbor *
|
|
|
|
electdr(list nl)
|
|
|
|
{
|
|
|
|
struct ospf_neighbor *neigh,*n;
|
|
|
|
|
|
|
|
n=NULL;
|
|
|
|
WALK_LIST (neigh, nl) /* And now DR */
|
|
|
|
{
|
|
|
|
if(neigh->state>=NEIGHBOR_2WAY) /* Higher than 2WAY */
|
|
|
|
if(neigh->priority>0) /* Eligible */
|
2000-06-08 01:49:19 +00:00
|
|
|
if(ipa_compare(neigh->ip,neigh->dr)==0) /* And declaring itself DR */
|
1999-11-17 15:50:41 +00:00
|
|
|
{
|
|
|
|
if(n!=NULL)
|
|
|
|
{
|
|
|
|
if(neigh->priority>n->priority) n=neigh;
|
|
|
|
else if(neigh->priority==n->priority)
|
|
|
|
if(neigh->rid>n->rid) n=neigh;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
n=neigh;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
can_do_adj(struct ospf_neighbor *n)
|
|
|
|
{
|
|
|
|
struct ospf_iface *ifa;
|
|
|
|
struct proto *p;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ifa=n->ifa;
|
|
|
|
p=(struct proto *)(ifa->proto);
|
|
|
|
i=0;
|
|
|
|
|
|
|
|
switch(ifa->type)
|
|
|
|
{
|
|
|
|
case OSPF_IT_PTP:
|
|
|
|
case OSPF_IT_VLINK:
|
|
|
|
i=1;
|
|
|
|
break;
|
|
|
|
case OSPF_IT_BCAST:
|
|
|
|
case OSPF_IT_NBMA:
|
|
|
|
switch(ifa->state)
|
|
|
|
{
|
|
|
|
case OSPF_IS_DOWN:
|
2000-06-06 01:00:34 +00:00
|
|
|
bug("%s: Iface %s in down state?", p->name, ifa->iface->name);
|
1999-11-17 15:50:41 +00:00
|
|
|
break;
|
|
|
|
case OSPF_IS_WAITING:
|
|
|
|
DBG("%s: Neighbor? on iface %s\n",p->name, ifa->iface->name);
|
|
|
|
break;
|
|
|
|
case OSPF_IS_DROTHER:
|
|
|
|
if(((n->rid==ifa->drid) || (n->rid==ifa->bdrid))
|
2000-05-09 13:56:47 +00:00
|
|
|
&& (n->state>=NEIGHBOR_2WAY)) i=1;
|
1999-11-17 15:50:41 +00:00
|
|
|
break;
|
|
|
|
case OSPF_IS_PTP:
|
|
|
|
case OSPF_IS_BACKUP:
|
|
|
|
case OSPF_IS_DR:
|
2000-05-09 12:18:41 +00:00
|
|
|
if(n->state>=NEIGHBOR_2WAY) i=1;
|
1999-11-17 15:50:41 +00:00
|
|
|
break;
|
|
|
|
default:
|
2000-06-06 01:00:34 +00:00
|
|
|
bug("%s: Iface %s in unknown state?",p->name, ifa->iface->name);
|
1999-11-17 15:50:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2000-06-06 01:00:34 +00:00
|
|
|
bug("%s: Iface %s is unknown type?",p->name, ifa->iface->name);
|
1999-11-17 15:50:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
DBG("%s: Iface %s can_do_adj=%d\n",p->name, ifa->iface->name,i);
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2000-06-07 21:46:22 +00:00
|
|
|
/**
|
|
|
|
* ospf_neigh_sm - ospf neighbor state machine
|
|
|
|
* @n: neighor
|
|
|
|
* @event: actual event
|
|
|
|
*
|
2003-08-23 10:42:41 +00:00
|
|
|
* This part implements the neighbor state machine as described in 10.3 of
|
|
|
|
* RFC 2328. The only difference is that state %NEIGHBOR_ATTEMPT is not
|
|
|
|
* used. We discover neighbors on nonbroadcast networks in the
|
|
|
|
* same way as on broadcast networks. The only difference is in
|
|
|
|
* sending hello packets. These are sent to IPs listed in
|
2000-06-07 21:46:22 +00:00
|
|
|
* @ospf_iface->nbma_list .
|
|
|
|
*/
|
1999-11-17 15:50:41 +00:00
|
|
|
void
|
|
|
|
ospf_neigh_sm(struct ospf_neighbor *n, int event)
|
|
|
|
{
|
2000-04-30 22:14:31 +00:00
|
|
|
struct proto *p=(struct proto *)(n->ifa->proto);
|
|
|
|
struct proto_ospf *po=n->ifa->proto;
|
1999-11-17 15:50:41 +00:00
|
|
|
|
2000-04-18 19:22:49 +00:00
|
|
|
DBG("%s: Neighbor state machine for neighbor %I, event \"%s\".\n",
|
|
|
|
p->name, n->rid, ospf_inm[event]);
|
|
|
|
|
1999-11-17 15:50:41 +00:00
|
|
|
switch(event)
|
|
|
|
{
|
|
|
|
case INM_START:
|
|
|
|
neigh_chstate(n,NEIGHBOR_ATTEMPT);
|
2000-06-07 21:46:22 +00:00
|
|
|
/* NBMA are used different way */
|
1999-11-17 15:50:41 +00:00
|
|
|
break;
|
|
|
|
case INM_HELLOREC:
|
|
|
|
switch(n->state)
|
|
|
|
{
|
|
|
|
case NEIGHBOR_ATTEMPT:
|
|
|
|
case NEIGHBOR_DOWN:
|
|
|
|
neigh_chstate(n,NEIGHBOR_INIT);
|
|
|
|
default:
|
|
|
|
restart_inactim(n);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case INM_2WAYREC:
|
2000-05-10 13:35:49 +00:00
|
|
|
if(n->state<NEIGHBOR_2WAY) neigh_chstate(n,NEIGHBOR_2WAY);
|
|
|
|
if((n->state==NEIGHBOR_2WAY) && can_do_adj(n))
|
|
|
|
neigh_chstate(n,NEIGHBOR_EXSTART);
|
1999-11-17 15:50:41 +00:00
|
|
|
break;
|
|
|
|
case INM_NEGDONE:
|
|
|
|
if(n->state==NEIGHBOR_EXSTART)
|
|
|
|
{
|
|
|
|
neigh_chstate(n,NEIGHBOR_EXCHANGE);
|
2004-06-01 13:12:10 +00:00
|
|
|
while(!EMPTY_LIST(n->ackl))
|
|
|
|
{
|
|
|
|
struct lsah_n *no;
|
|
|
|
no=(struct lsah_n *)HEAD(n->ackl);
|
|
|
|
rem_node(NODE no);
|
|
|
|
mb_free(no);
|
|
|
|
}
|
2000-03-08 12:50:28 +00:00
|
|
|
s_init_list(&(n->lsrql));
|
2004-06-01 13:12:10 +00:00
|
|
|
if(n->lsrqh) ospf_top_free(n->lsrqh);
|
|
|
|
n->lsrqh=ospf_top_new(n->pool, n->ifa->proto);
|
2000-03-08 12:50:28 +00:00
|
|
|
s_init_list(&(n->lsrtl));
|
2004-06-01 13:12:10 +00:00
|
|
|
if(n->lsrth) ospf_top_free(n->lsrth);
|
|
|
|
n->lsrth=ospf_top_new(n->pool, n->ifa->proto);
|
2000-03-08 12:50:28 +00:00
|
|
|
s_init(&(n->dbsi), &(n->ifa->oa->lsal));
|
2000-03-30 00:18:59 +00:00
|
|
|
s_init(&(n->lsrqi), &(n->lsrql));
|
2000-04-04 00:32:17 +00:00
|
|
|
s_init(&(n->lsrti), &(n->lsrtl));
|
2000-03-30 00:18:59 +00:00
|
|
|
tm_start(n->lsrr_timer,n->ifa->rxmtint);
|
2000-04-18 01:06:16 +00:00
|
|
|
tm_start(n->ackd_timer,n->ifa->rxmtint/2);
|
1999-11-17 15:50:41 +00:00
|
|
|
}
|
2000-06-06 01:00:34 +00:00
|
|
|
else bug("NEGDONE and I'm not in EXSTART?");
|
1999-11-17 15:50:41 +00:00
|
|
|
break;
|
|
|
|
case INM_EXDONE:
|
2000-03-29 17:18:06 +00:00
|
|
|
neigh_chstate(n,NEIGHBOR_LOADING);
|
1999-11-17 15:50:41 +00:00
|
|
|
break;
|
|
|
|
case INM_LOADDONE:
|
2000-04-04 00:32:17 +00:00
|
|
|
neigh_chstate(n,NEIGHBOR_FULL);
|
1999-11-17 15:50:41 +00:00
|
|
|
break;
|
|
|
|
case INM_ADJOK:
|
|
|
|
switch(n->state)
|
|
|
|
{
|
|
|
|
case NEIGHBOR_2WAY:
|
2000-05-10 13:35:49 +00:00
|
|
|
/* Can In build adjacency? */
|
1999-11-17 15:50:41 +00:00
|
|
|
if(can_do_adj(n))
|
|
|
|
{
|
|
|
|
neigh_chstate(n,NEIGHBOR_EXSTART);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if(n->state>=NEIGHBOR_EXSTART)
|
|
|
|
if(!can_do_adj(n))
|
|
|
|
{
|
|
|
|
neigh_chstate(n,NEIGHBOR_2WAY);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case INM_SEQMIS:
|
2004-05-31 13:22:49 +00:00
|
|
|
OSPF_TRACE(D_EVENTS, "Seq mis!");
|
1999-11-17 15:50:41 +00:00
|
|
|
case INM_BADLSREQ:
|
2000-06-06 02:34:57 +00:00
|
|
|
OSPF_TRACE(D_EVENTS, "Bad LS req!");
|
1999-11-17 15:50:41 +00:00
|
|
|
if(n->state>=NEIGHBOR_EXCHANGE)
|
|
|
|
{
|
|
|
|
neigh_chstate(n,NEIGHBOR_EXSTART);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case INM_KILLNBR:
|
|
|
|
case INM_LLDOWN:
|
|
|
|
case INM_INACTTIM:
|
|
|
|
neigh_chstate(n,NEIGHBOR_DOWN);
|
|
|
|
break;
|
|
|
|
case INM_1WAYREC:
|
2000-05-09 11:27:31 +00:00
|
|
|
neigh_chstate(n,NEIGHBOR_INIT);
|
1999-11-17 15:50:41 +00:00
|
|
|
break;
|
|
|
|
default:
|
2000-06-06 01:00:34 +00:00
|
|
|
bug("%s: INM - Unknown event?",p->name);
|
1999-11-17 15:50:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-07 21:46:22 +00:00
|
|
|
/**
|
|
|
|
* bdr_election - (Backup) Designed Router election
|
|
|
|
* @ifa: actual interface
|
|
|
|
*
|
2003-08-23 10:42:41 +00:00
|
|
|
* When the wait timer fires, it is time to elect (Backup) Designated Router.
|
2000-06-07 21:46:22 +00:00
|
|
|
* Structure describing me is added to this list so every electing router
|
2003-08-23 10:42:41 +00:00
|
|
|
* has the same list. Backup Designated Router is elected before Designated
|
2000-06-07 21:46:22 +00:00
|
|
|
* Router. This process is described in 9.4 of RFC 2328.
|
|
|
|
*/
|
1999-11-17 15:50:41 +00:00
|
|
|
void
|
2000-06-07 21:46:22 +00:00
|
|
|
bdr_election(struct ospf_iface *ifa)
|
1999-11-17 15:50:41 +00:00
|
|
|
{
|
2000-04-30 22:14:31 +00:00
|
|
|
struct ospf_neighbor *neigh,*ndr,*nbdr,me,*tmp;
|
2000-06-08 01:49:19 +00:00
|
|
|
u32 myid;
|
|
|
|
ip_addr ndrip, nbdrip;
|
1999-11-17 15:50:41 +00:00
|
|
|
int doadj;
|
2000-06-07 21:46:22 +00:00
|
|
|
struct proto *p=&ifa->proto->proto;
|
1999-11-17 15:50:41 +00:00
|
|
|
|
2000-06-08 01:49:19 +00:00
|
|
|
DBG("(B)DR election.\n");
|
1999-11-17 15:50:41 +00:00
|
|
|
|
|
|
|
myid=p->cf->global->router_id;
|
|
|
|
|
|
|
|
me.state=NEIGHBOR_2WAY;
|
|
|
|
me.rid=myid;
|
|
|
|
me.priority=ifa->priority;
|
2000-06-08 01:49:19 +00:00
|
|
|
me.dr=ifa->drip;
|
|
|
|
me.bdr=ifa->bdrip;
|
2000-05-31 12:52:12 +00:00
|
|
|
me.ip=ifa->iface->addr->ip;
|
1999-11-17 15:50:41 +00:00
|
|
|
|
|
|
|
add_tail(&ifa->neigh_list, NODE &me);
|
|
|
|
|
|
|
|
nbdr=electbdr(ifa->neigh_list);
|
|
|
|
ndr=electdr(ifa->neigh_list);
|
|
|
|
|
2000-06-07 21:46:22 +00:00
|
|
|
if(ndr==NULL) ndr=nbdr;
|
1999-11-17 15:50:41 +00:00
|
|
|
|
2000-05-10 23:41:52 +00:00
|
|
|
if(((ifa->drid==myid) && (ndr!=&me))
|
|
|
|
|| ((ifa->drid!=myid) && (ndr==&me))
|
|
|
|
|| ((ifa->bdrid==myid) && (nbdr!=&me))
|
|
|
|
|| ((ifa->bdrid!=myid) && (nbdr==&me)))
|
1999-11-17 15:50:41 +00:00
|
|
|
{
|
2000-06-08 01:49:19 +00:00
|
|
|
if(ndr==NULL) ifa->drip=me.dr=ipa_from_u32(0);
|
|
|
|
else ifa->drip=me.dr=ndr->ip;
|
1999-11-17 15:50:41 +00:00
|
|
|
|
2000-06-08 01:49:19 +00:00
|
|
|
if(nbdr==NULL) ifa->bdrip=me.bdr=ipa_from_u32(0);
|
|
|
|
else ifa->bdrip=me.bdr=nbdr->ip;
|
1999-11-17 15:50:41 +00:00
|
|
|
|
|
|
|
nbdr=electbdr(ifa->neigh_list);
|
|
|
|
ndr=electdr(ifa->neigh_list);
|
|
|
|
}
|
|
|
|
|
2000-06-08 01:49:19 +00:00
|
|
|
if(ndr==NULL) ndrip=ipa_from_u32(0);
|
|
|
|
else ndrip=ndr->ip;
|
1999-11-17 15:50:41 +00:00
|
|
|
|
2000-06-08 01:49:19 +00:00
|
|
|
if(nbdr==NULL) nbdrip=ipa_from_u32(0);
|
|
|
|
else nbdrip=nbdr->ip;
|
1999-11-17 15:50:41 +00:00
|
|
|
|
|
|
|
doadj=0;
|
2000-06-08 01:49:19 +00:00
|
|
|
if((ipa_compare(ifa->drip,ndrip)!=0) || (ipa_compare(ifa->bdrip,nbdrip)!=0))
|
|
|
|
doadj=1;
|
|
|
|
|
|
|
|
if(ndr==NULL)
|
2000-05-10 11:48:21 +00:00
|
|
|
{
|
|
|
|
ifa->drid=0;
|
|
|
|
ifa->drip=ipa_from_u32(0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-06-08 01:49:19 +00:00
|
|
|
ifa->drid=ndr->rid;
|
|
|
|
ifa->drip=ndr->ip;
|
2000-05-10 11:48:21 +00:00
|
|
|
}
|
|
|
|
|
2000-06-08 01:49:19 +00:00
|
|
|
if(nbdr==NULL)
|
2000-05-10 11:48:21 +00:00
|
|
|
{
|
|
|
|
ifa->bdrid=0;
|
|
|
|
ifa->bdrip=ipa_from_u32(0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-06-08 01:49:19 +00:00
|
|
|
ifa->bdrid=nbdr->rid;
|
|
|
|
ifa->bdrip=nbdr->ip;
|
2000-05-10 11:48:21 +00:00
|
|
|
}
|
1999-11-17 15:50:41 +00:00
|
|
|
|
2000-06-08 01:49:19 +00:00
|
|
|
DBG("DR=%I, BDR=%I\n", ifa->drid, ifa->bdrid);
|
1999-11-17 15:50:41 +00:00
|
|
|
|
|
|
|
if(myid==ifa->drid) iface_chstate(ifa, OSPF_IS_DR);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(myid==ifa->bdrid) iface_chstate(ifa, OSPF_IS_BACKUP);
|
|
|
|
else iface_chstate(ifa, OSPF_IS_DROTHER);
|
|
|
|
}
|
|
|
|
|
|
|
|
rem_node(NODE &me);
|
|
|
|
|
|
|
|
if(doadj)
|
|
|
|
{
|
|
|
|
WALK_LIST (neigh, ifa->neigh_list)
|
|
|
|
{
|
|
|
|
ospf_neigh_sm(neigh, INM_ADJOK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ospf_neighbor *
|
|
|
|
find_neigh(struct ospf_iface *ifa, u32 rid)
|
|
|
|
{
|
|
|
|
struct ospf_neighbor *n;
|
|
|
|
|
|
|
|
WALK_LIST (n, ifa->neigh_list)
|
|
|
|
if(n->rid == rid)
|
|
|
|
return n;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-06-09 14:55:10 +00:00
|
|
|
|
|
|
|
/* Find a closest neighbor which is at leas 2-Way */
|
2000-04-30 11:31:05 +00:00
|
|
|
struct ospf_neighbor *
|
|
|
|
find_neigh_noifa(struct proto_ospf *po, u32 rid)
|
|
|
|
{
|
2001-06-09 14:55:10 +00:00
|
|
|
struct ospf_neighbor *n=NULL,*m;
|
2000-04-30 11:31:05 +00:00
|
|
|
struct ospf_iface *ifa;
|
|
|
|
|
|
|
|
WALK_LIST (ifa, po->iface_list)
|
2001-06-09 14:55:10 +00:00
|
|
|
if((m=find_neigh(ifa, rid))!=NULL)
|
|
|
|
{
|
|
|
|
if(m->state>=NEIGHBOR_2WAY)
|
|
|
|
{
|
|
|
|
if(n==NULL) n=m;
|
|
|
|
else
|
|
|
|
if(m->ifa->cost < n->ifa->cost) n=m;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return n;
|
2000-04-30 11:31:05 +00:00
|
|
|
}
|
|
|
|
|
2000-04-03 22:31:07 +00:00
|
|
|
struct ospf_area *
|
|
|
|
ospf_find_area(struct proto_ospf *po, u32 aid)
|
|
|
|
{
|
|
|
|
struct ospf_area *oa;
|
|
|
|
WALK_LIST(NODE oa,po->area_list)
|
|
|
|
if(((struct ospf_area *)oa)->areaid==aid) return oa;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-05-10 12:37:43 +00:00
|
|
|
/* Neighbor is inactive for a long time. Remove it. */
|
|
|
|
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);
|
2000-06-06 02:34:57 +00:00
|
|
|
OSPF_TRACE(D_EVENTS,"Inactivity timer fired on interface %s for neighbor %I.",
|
|
|
|
ifa->iface->name, n->ip);
|
2000-05-16 23:59:38 +00:00
|
|
|
ospf_neigh_remove(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ospf_neigh_remove(struct ospf_neighbor *n)
|
|
|
|
{
|
|
|
|
struct ospf_iface *ifa;
|
|
|
|
struct proto *p;
|
|
|
|
|
|
|
|
ifa=n->ifa;
|
|
|
|
p=(struct proto *)(ifa->proto);
|
2000-05-10 12:37:43 +00:00
|
|
|
neigh_chstate(n, NEIGHBOR_DOWN);
|
|
|
|
rem_node(NODE n);
|
2004-06-01 13:12:10 +00:00
|
|
|
rfree(n->pool);
|
2000-06-06 02:34:57 +00:00
|
|
|
OSPF_TRACE(D_EVENTS, "Deleting neigbor.");
|
2000-05-16 23:59:38 +00:00
|
|
|
}
|
2000-06-01 15:53:06 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
ospf_sh_neigh_info(struct ospf_neighbor *n)
|
|
|
|
{
|
|
|
|
struct ospf_iface *ifa=n->ifa;
|
|
|
|
char *pos="other";
|
|
|
|
char etime[6];
|
|
|
|
int exp,sec,min;
|
|
|
|
|
|
|
|
exp=n->inactim->expires-now;
|
|
|
|
sec=exp-(exp/60);
|
|
|
|
min=(exp-sec)/60;
|
|
|
|
if(min>59)
|
|
|
|
{
|
2000-06-01 16:26:59 +00:00
|
|
|
bsprintf(etime,"-Inf-");
|
2000-06-01 15:53:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-06-01 16:26:59 +00:00
|
|
|
bsprintf(etime,"%02u:%02u", min, sec);
|
2000-06-01 15:53:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(n->rid==ifa->drid) pos="dr ";
|
|
|
|
if(n->rid==ifa->bdrid) pos="bdr ";
|
2000-06-06 12:50:02 +00:00
|
|
|
if(n->ifa->type==OSPF_IT_PTP) pos="ptp ";
|
2000-06-01 15:53:06 +00:00
|
|
|
|
2001-08-19 11:15:24 +00:00
|
|
|
cli_msg(-1013,"%-1I\t%3u\t%s/%s\t%-5s\t%-1I\t%-10s",n->rid, n->priority,
|
2000-06-01 15:53:06 +00:00
|
|
|
ospf_ns[n->state], pos, etime, n->ip,ifa->iface->name);
|
|
|
|
}
|