1999-11-17 15:50:41 +00:00
|
|
|
/*
|
|
|
|
* BIRD -- OSPF
|
|
|
|
*
|
2004-06-04 12:53:10 +00:00
|
|
|
* (c) 1999 - 2004 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"
|
|
|
|
|
2004-06-06 09:37:54 +00:00
|
|
|
char *ospf_ns[] = { " down",
|
|
|
|
" attempt",
|
|
|
|
" init",
|
|
|
|
" 2way",
|
|
|
|
" exstart",
|
|
|
|
"exchange",
|
|
|
|
" loading",
|
|
|
|
" full"
|
|
|
|
};
|
|
|
|
|
|
|
|
const char *ospf_inm[] =
|
|
|
|
{ "hello received", "neighbor start", "2-way received",
|
2000-04-18 19:22:49 +00:00
|
|
|
"negotiation done", "exstart done", "bad ls request", "load done",
|
|
|
|
"adjacency ok?", "sequence mismatch", "1-way received", "kill neighbor",
|
2004-06-06 09:37:54 +00:00
|
|
|
"inactivity timer", "line down"
|
|
|
|
};
|
2000-04-18 19:22:49 +00:00
|
|
|
|
2009-01-13 18:15:49 +00:00
|
|
|
static void neigh_chstate(struct ospf_neighbor *n, u8 state);
|
|
|
|
static struct ospf_neighbor *electbdr(list nl);
|
|
|
|
static struct ospf_neighbor *electdr(list nl);
|
|
|
|
static void neighbor_timer_hook(timer * timer);
|
|
|
|
static void rxmt_timer_hook(timer * timer);
|
|
|
|
static void ackd_timer_hook(timer * t);
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_lists(struct ospf_neighbor *n)
|
|
|
|
{
|
|
|
|
s_init_list(&(n->lsrql));
|
|
|
|
n->lsrqh = ospf_top_new(n->pool);
|
|
|
|
s_init(&(n->lsrqi), &(n->lsrql));
|
|
|
|
|
|
|
|
s_init_list(&(n->lsrtl));
|
|
|
|
n->lsrth = ospf_top_new(n->pool);
|
|
|
|
s_init(&(n->lsrti), &(n->lsrtl));
|
|
|
|
}
|
2004-06-04 12:53:10 +00:00
|
|
|
|
2009-01-13 18:25:27 +00:00
|
|
|
/* Resets LSA request and retransmit lists.
|
2009-01-13 18:15:49 +00:00
|
|
|
* We do not reset DB summary list iterator here,
|
|
|
|
* it is reset during entering EXCHANGE state.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
reset_lists(struct ospf_neighbor *n)
|
|
|
|
{
|
|
|
|
ospf_top_free(n->lsrqh);
|
|
|
|
ospf_top_free(n->lsrth);
|
|
|
|
init_lists(n);
|
|
|
|
}
|
2004-06-04 12:53:10 +00:00
|
|
|
|
|
|
|
struct ospf_neighbor *
|
|
|
|
ospf_neighbor_new(struct ospf_iface *ifa)
|
|
|
|
{
|
2004-07-15 16:37:52 +00:00
|
|
|
struct proto *p = (struct proto *) (ifa->oa->po);
|
2009-01-13 18:15:49 +00:00
|
|
|
struct proto_ospf *po = ifa->oa->po;
|
2004-06-04 12:53:10 +00:00
|
|
|
struct pool *pool = rp_new(p->pool, "OSPF Neighbor");
|
|
|
|
struct ospf_neighbor *n = mb_allocz(pool, sizeof(struct ospf_neighbor));
|
|
|
|
|
|
|
|
n->pool = pool;
|
|
|
|
n->ifa = ifa;
|
|
|
|
add_tail(&ifa->neigh_list, NODE n);
|
|
|
|
n->adj = 0;
|
2004-06-26 20:15:34 +00:00
|
|
|
n->csn = 0;
|
2004-06-06 09:37:54 +00:00
|
|
|
n->ldbdes = mb_allocz(pool, ifa->iface->mtu);
|
|
|
|
n->state = NEIGHBOR_DOWN;
|
2004-06-04 12:53:10 +00:00
|
|
|
|
2009-01-13 18:15:49 +00:00
|
|
|
init_lists(n);
|
|
|
|
s_init(&(n->dbsi), &(po->lsal));
|
|
|
|
|
2004-06-04 12:53:10 +00:00
|
|
|
n->inactim = tm_new(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);
|
|
|
|
|
|
|
|
n->rxmt_timer = tm_new(pool);
|
|
|
|
n->rxmt_timer->data = n;
|
|
|
|
n->rxmt_timer->randomize = 0;
|
|
|
|
n->rxmt_timer->hook = rxmt_timer_hook;
|
|
|
|
n->rxmt_timer->recurrent = ifa->rxmtint;
|
2004-06-06 09:37:54 +00:00
|
|
|
tm_start(n->rxmt_timer, n->ifa->rxmtint);
|
2004-06-04 12:53:10 +00:00
|
|
|
DBG("%s: Installing rxmt timer.\n", p->name);
|
|
|
|
|
|
|
|
n->ackd_timer = tm_new(pool);
|
|
|
|
n->ackd_timer->data = n;
|
|
|
|
n->ackd_timer->randomize = 0;
|
|
|
|
n->ackd_timer->hook = ackd_timer_hook;
|
2004-06-06 09:37:54 +00:00
|
|
|
n->ackd_timer->recurrent = ifa->rxmtint / 2;
|
2004-06-04 16:30:04 +00:00
|
|
|
init_list(&n->ackl[ACKL_DIRECT]);
|
|
|
|
init_list(&n->ackl[ACKL_DELAY]);
|
2004-06-06 09:37:54 +00:00
|
|
|
tm_start(n->ackd_timer, n->ifa->rxmtint / 2);
|
2004-06-04 12:53:10 +00:00
|
|
|
DBG("%s: Installing ackd timer.\n", p->name);
|
|
|
|
|
2004-06-06 09:37:54 +00:00
|
|
|
return (n);
|
2004-06-04 12:53:10 +00:00
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2009-01-13 18:15:49 +00:00
|
|
|
static void
|
1999-11-17 15:50:41 +00:00
|
|
|
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
|
|
|
|
2004-06-06 09:37:54 +00:00
|
|
|
oldstate = n->state;
|
2000-05-08 22:40:55 +00:00
|
|
|
|
2004-06-06 09:37:54 +00:00
|
|
|
if (oldstate != state)
|
1999-11-17 15:50:41 +00:00
|
|
|
{
|
2004-06-06 09:37:54 +00:00
|
|
|
struct ospf_iface *ifa = n->ifa;
|
|
|
|
struct proto_ospf *po = ifa->oa->po;
|
|
|
|
struct proto *p = &po->proto;
|
2000-05-09 11:52:44 +00:00
|
|
|
|
2004-06-06 09:37:54 +00:00
|
|
|
n->state = state;
|
2000-05-09 11:52:44 +00:00
|
|
|
|
2004-06-06 09:37:54 +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
|
|
|
|
2004-06-06 09:37:54 +00:00
|
|
|
if ((state == NEIGHBOR_2WAY) && (oldstate < NEIGHBOR_2WAY))
|
2004-06-06 08:55:33 +00:00
|
|
|
ospf_iface_sm(ifa, ISM_NEICH);
|
2004-06-06 09:37:54 +00:00
|
|
|
if ((state < NEIGHBOR_2WAY) && (oldstate >= NEIGHBOR_2WAY))
|
2004-06-06 08:55:33 +00:00
|
|
|
ospf_iface_sm(ifa, ISM_NEICH);
|
2000-05-09 11:52:44 +00:00
|
|
|
|
2004-06-06 09:37:54 +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);
|
2005-02-13 23:36:31 +00:00
|
|
|
if (ifa->type == OSPF_IT_VLINK) schedule_rt_lsa(ifa->voa);
|
2001-08-11 14:01:54 +00:00
|
|
|
schedule_net_lsa(ifa);
|
2000-05-03 00:08:48 +00:00
|
|
|
}
|
2004-06-06 09:37:54 +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);
|
2004-07-14 21:46:20 +00:00
|
|
|
if (ifa->type == OSPF_IT_VLINK) schedule_rt_lsa(ifa->voa);
|
2001-08-11 14:01:54 +00:00
|
|
|
schedule_net_lsa(ifa);
|
2000-05-03 00:08:48 +00:00
|
|
|
}
|
2004-06-06 09:37:54 +00:00
|
|
|
if (state == NEIGHBOR_EXSTART)
|
2000-05-08 22:40:55 +00:00
|
|
|
{
|
2004-06-06 09:37:54 +00:00
|
|
|
if (n->adj == 0) /* First time adjacency */
|
2000-05-08 22:40:55 +00:00
|
|
|
{
|
2004-06-06 09:37:54 +00:00
|
|
|
n->dds = random_u32();
|
2000-05-08 22:40:55 +00:00
|
|
|
}
|
|
|
|
n->dds++;
|
2004-06-06 09:37:54 +00:00
|
|
|
n->myimms.byte = 0;
|
|
|
|
n->myimms.bit.ms = 1;
|
|
|
|
n->myimms.bit.m = 1;
|
|
|
|
n->myimms.bit.i = 1;
|
2000-05-08 22:40:55 +00:00
|
|
|
}
|
2004-06-06 09:37:54 +00:00
|
|
|
if (state > NEIGHBOR_EXSTART)
|
|
|
|
n->myimms.bit.i = 0;
|
1999-11-17 15:50:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-13 18:15:49 +00:00
|
|
|
static struct ospf_neighbor *
|
1999-11-17 15:50:41 +00:00
|
|
|
electbdr(list nl)
|
|
|
|
{
|
2004-06-06 09:37:54 +00:00
|
|
|
struct ospf_neighbor *neigh, *n1, *n2;
|
2009-08-21 07:27:52 +00:00
|
|
|
u32 nid;
|
|
|
|
|
2004-06-06 09:37:54 +00:00
|
|
|
n1 = NULL;
|
|
|
|
n2 = NULL;
|
2009-08-21 07:27:52 +00:00
|
|
|
WALK_LIST(neigh, nl) /* First try those decl. themselves */
|
1999-11-17 15:50:41 +00:00
|
|
|
{
|
2009-08-25 14:42:14 +00:00
|
|
|
#ifdef OSPFv2
|
|
|
|
nid = ipa_to_u32(neigh->ip);
|
|
|
|
#else /* OSPFv3 */
|
|
|
|
nid = neigh->rid;
|
|
|
|
#endif
|
|
|
|
|
2004-06-06 09:37:54 +00:00
|
|
|
if (neigh->state >= NEIGHBOR_2WAY) /* Higher than 2WAY */
|
2009-08-21 07:27:52 +00:00
|
|
|
if (neigh->priority > 0) /* Eligible */
|
|
|
|
if (neigh->dr != nid) /* And not decl. itself DR */
|
1999-11-17 15:50:41 +00:00
|
|
|
{
|
2009-08-21 07:27:52 +00:00
|
|
|
if (neigh->bdr == nid) /* Declaring BDR */
|
2004-06-06 09:37:54 +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;
|
|
|
|
}
|
1999-11-17 15:50:41 +00:00
|
|
|
else
|
2004-06-06 09:37:54 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
1999-11-17 15:50:41 +00:00
|
|
|
else
|
2004-06-06 09:37:54 +00:00
|
|
|
{
|
|
|
|
n2 = neigh;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-11-17 15:50:41 +00:00
|
|
|
}
|
2004-06-06 09:37:54 +00:00
|
|
|
if (n1 == NULL)
|
|
|
|
n1 = n2;
|
1999-11-17 15:50:41 +00:00
|
|
|
|
2004-06-06 09:37:54 +00:00
|
|
|
return (n1);
|
1999-11-17 15:50:41 +00:00
|
|
|
}
|
|
|
|
|
2009-01-13 18:15:49 +00:00
|
|
|
static struct ospf_neighbor *
|
1999-11-17 15:50:41 +00:00
|
|
|
electdr(list nl)
|
|
|
|
{
|
2004-06-06 09:37:54 +00:00
|
|
|
struct ospf_neighbor *neigh, *n;
|
2009-08-21 07:27:52 +00:00
|
|
|
u32 nid;
|
|
|
|
|
2009-08-25 14:42:14 +00:00
|
|
|
n = NULL;
|
|
|
|
WALK_LIST(neigh, nl) /* And now DR */
|
|
|
|
{
|
2009-08-21 07:27:52 +00:00
|
|
|
#ifdef OSPFv2
|
2009-08-25 14:42:14 +00:00
|
|
|
nid = ipa_to_u32(neigh->ip);
|
2009-08-21 07:27:52 +00:00
|
|
|
#else /* OSPFv3 */
|
2009-08-25 14:42:14 +00:00
|
|
|
nid = neigh->rid;
|
2009-08-21 07:27:52 +00:00
|
|
|
#endif
|
1999-11-17 15:50:41 +00:00
|
|
|
|
2004-06-06 09:37:54 +00:00
|
|
|
if (neigh->state >= NEIGHBOR_2WAY) /* Higher than 2WAY */
|
2009-08-21 07:27:52 +00:00
|
|
|
if (neigh->priority > 0) /* Eligible */
|
|
|
|
if (neigh->dr == nid) /* And declaring itself DR */
|
1999-11-17 15:50:41 +00:00
|
|
|
{
|
2004-06-06 09:37:54 +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;
|
|
|
|
}
|
1999-11-17 15:50:41 +00:00
|
|
|
else
|
2004-06-06 09:37:54 +00:00
|
|
|
{
|
|
|
|
n = neigh;
|
|
|
|
}
|
|
|
|
}
|
1999-11-17 15:50:41 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 09:37:54 +00:00
|
|
|
return (n);
|
1999-11-17 15:50:41 +00:00
|
|
|
}
|
|
|
|
|
2004-06-05 09:58:23 +00:00
|
|
|
static int
|
1999-11-17 15:50:41 +00:00
|
|
|
can_do_adj(struct ospf_neighbor *n)
|
|
|
|
{
|
|
|
|
struct ospf_iface *ifa;
|
|
|
|
struct proto *p;
|
|
|
|
int i;
|
|
|
|
|
2004-06-06 09:37:54 +00:00
|
|
|
ifa = n->ifa;
|
2004-07-15 16:37:52 +00:00
|
|
|
p = (struct proto *) (ifa->oa->po);
|
2004-06-06 09:37:54 +00:00
|
|
|
i = 0;
|
1999-11-17 15:50:41 +00:00
|
|
|
|
2004-06-06 09:37:54 +00:00
|
|
|
switch (ifa->type)
|
1999-11-17 15:50:41 +00:00
|
|
|
{
|
2004-06-06 09:37:54 +00:00
|
|
|
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:
|
|
|
|
bug("%s: Iface %s in down state?", p->name, ifa->iface->name);
|
1999-11-17 15:50:41 +00:00
|
|
|
break;
|
2004-06-06 09:37:54 +00:00
|
|
|
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))
|
|
|
|
&& (n->state >= NEIGHBOR_2WAY))
|
|
|
|
i = 1;
|
|
|
|
break;
|
|
|
|
case OSPF_IS_PTP:
|
|
|
|
case OSPF_IS_BACKUP:
|
|
|
|
case OSPF_IS_DR:
|
|
|
|
if (n->state >= NEIGHBOR_2WAY)
|
|
|
|
i = 1;
|
1999-11-17 15:50:41 +00:00
|
|
|
break;
|
|
|
|
default:
|
2004-06-06 09:37:54 +00:00
|
|
|
bug("%s: Iface %s in unknown state?", p->name, ifa->iface->name);
|
1999-11-17 15:50:41 +00:00
|
|
|
break;
|
2004-06-06 09:37:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
bug("%s: Iface %s is unknown type?", p->name, ifa->iface->name);
|
|
|
|
break;
|
1999-11-17 15:50:41 +00:00
|
|
|
}
|
2004-06-06 09:37:54 +00:00
|
|
|
DBG("%s: Iface %s can_do_adj=%d\n", p->name, ifa->iface->name, i);
|
1999-11-17 15:50:41 +00:00
|
|
|
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)
|
|
|
|
{
|
2004-07-15 16:37:52 +00:00
|
|
|
struct proto_ospf *po = n->ifa->oa->po;
|
|
|
|
struct proto *p = &po->proto;
|
1999-11-17 15:50:41 +00:00
|
|
|
|
2009-01-11 11:14:27 +00:00
|
|
|
DBG("Neighbor state machine for neighbor %I, event '%s'\n", n->ip,
|
2004-06-06 09:37:54 +00:00
|
|
|
ospf_inm[event]);
|
2000-04-18 19:22:49 +00:00
|
|
|
|
2004-06-06 09:37:54 +00:00
|
|
|
switch (event)
|
1999-11-17 15:50:41 +00:00
|
|
|
{
|
2004-06-06 09:37:54 +00:00
|
|
|
case INM_START:
|
|
|
|
neigh_chstate(n, NEIGHBOR_ATTEMPT);
|
|
|
|
/* NBMA are used different way */
|
|
|
|
break;
|
|
|
|
case INM_HELLOREC:
|
|
|
|
switch (n->state)
|
|
|
|
{
|
|
|
|
case NEIGHBOR_ATTEMPT:
|
|
|
|
case NEIGHBOR_DOWN:
|
|
|
|
neigh_chstate(n, NEIGHBOR_INIT);
|
|
|
|
default:
|
2005-02-20 04:27:56 +00:00
|
|
|
tm_start(n->inactim, n->ifa->dead); /* Restart inactivity timer */
|
1999-11-17 15:50:41 +00:00
|
|
|
break;
|
2004-06-06 09:37:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case INM_2WAYREC:
|
|
|
|
if (n->state < NEIGHBOR_2WAY)
|
|
|
|
neigh_chstate(n, NEIGHBOR_2WAY);
|
|
|
|
if ((n->state == NEIGHBOR_2WAY) && can_do_adj(n))
|
|
|
|
neigh_chstate(n, NEIGHBOR_EXSTART);
|
|
|
|
break;
|
|
|
|
case INM_NEGDONE:
|
|
|
|
if (n->state == NEIGHBOR_EXSTART)
|
|
|
|
{
|
|
|
|
neigh_chstate(n, NEIGHBOR_EXCHANGE);
|
2009-01-13 18:15:49 +00:00
|
|
|
|
|
|
|
/* Reset DB summary list iterator */
|
|
|
|
s_get(&(n->dbsi));
|
2004-07-15 16:37:52 +00:00
|
|
|
s_init(&(n->dbsi), &po->lsal);
|
2009-01-13 18:15:49 +00:00
|
|
|
|
2004-06-06 09:37:54 +00:00
|
|
|
while (!EMPTY_LIST(n->ackl[ACKL_DELAY]))
|
1999-11-17 15:50:41 +00:00
|
|
|
{
|
2004-06-06 09:37:54 +00:00
|
|
|
struct lsah_n *no;
|
|
|
|
no = (struct lsah_n *) HEAD(n->ackl[ACKL_DELAY]);
|
|
|
|
rem_node(NODE no);
|
|
|
|
mb_free(no);
|
1999-11-17 15:50:41 +00:00
|
|
|
}
|
2004-06-06 09:37:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
bug("NEGDONE and I'm not in EXSTART?");
|
|
|
|
break;
|
|
|
|
case INM_EXDONE:
|
|
|
|
neigh_chstate(n, NEIGHBOR_LOADING);
|
|
|
|
break;
|
|
|
|
case INM_LOADDONE:
|
|
|
|
neigh_chstate(n, NEIGHBOR_FULL);
|
|
|
|
break;
|
|
|
|
case INM_ADJOK:
|
|
|
|
switch (n->state)
|
|
|
|
{
|
|
|
|
case NEIGHBOR_2WAY:
|
|
|
|
/* Can In build adjacency? */
|
|
|
|
if (can_do_adj(n))
|
1999-11-17 15:50:41 +00:00
|
|
|
{
|
2004-06-06 09:37:54 +00:00
|
|
|
neigh_chstate(n, NEIGHBOR_EXSTART);
|
1999-11-17 15:50:41 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2004-06-06 09:37:54 +00:00
|
|
|
if (n->state >= NEIGHBOR_EXSTART)
|
|
|
|
if (!can_do_adj(n))
|
|
|
|
{
|
2009-01-13 18:15:49 +00:00
|
|
|
reset_lists(n);
|
2004-06-06 09:37:54 +00:00
|
|
|
neigh_chstate(n, NEIGHBOR_2WAY);
|
|
|
|
}
|
1999-11-17 15:50:41 +00:00
|
|
|
break;
|
2004-06-06 09:37:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case INM_SEQMIS:
|
|
|
|
case INM_BADLSREQ:
|
|
|
|
if (n->state >= NEIGHBOR_EXCHANGE)
|
|
|
|
{
|
2009-01-13 18:15:49 +00:00
|
|
|
reset_lists(n);
|
2004-06-06 09:37:54 +00:00
|
|
|
neigh_chstate(n, NEIGHBOR_EXSTART);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case INM_KILLNBR:
|
|
|
|
case INM_LLDOWN:
|
|
|
|
case INM_INACTTIM:
|
2009-01-13 18:15:49 +00:00
|
|
|
reset_lists(n);
|
2004-06-06 09:37:54 +00:00
|
|
|
neigh_chstate(n, NEIGHBOR_DOWN);
|
|
|
|
break;
|
|
|
|
case INM_1WAYREC:
|
2009-01-13 18:15:49 +00:00
|
|
|
reset_lists(n);
|
2004-06-06 09:37:54 +00:00
|
|
|
neigh_chstate(n, NEIGHBOR_INIT);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
bug("%s: INM - Unknown event?", p->name);
|
|
|
|
break;
|
1999-11-17 15:50:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2009-12-11 00:20:53 +00:00
|
|
|
struct proto_ospf *po = ifa->oa->po;
|
|
|
|
u32 myid = po->router_id;
|
2004-06-06 09:37:54 +00:00
|
|
|
struct ospf_neighbor *neigh, *ndr, *nbdr, me;
|
1999-11-17 15:50:41 +00:00
|
|
|
int doadj;
|
|
|
|
|
2000-06-08 01:49:19 +00:00
|
|
|
DBG("(B)DR election.\n");
|
1999-11-17 15:50:41 +00:00
|
|
|
|
2004-06-06 09:37:54 +00:00
|
|
|
me.state = NEIGHBOR_2WAY;
|
|
|
|
me.rid = myid;
|
|
|
|
me.priority = ifa->priority;
|
1999-11-17 15:50:41 +00:00
|
|
|
|
2009-08-21 07:27:52 +00:00
|
|
|
#ifdef OSPFv2
|
2009-08-27 16:25:46 +00:00
|
|
|
me.ip = ifa->iface->addr->ip;
|
2009-08-21 07:27:52 +00:00
|
|
|
me.dr = ipa_to_u32(ifa->drip);
|
|
|
|
me.bdr = ipa_to_u32(ifa->bdrip);
|
|
|
|
#else /* OSPFv3 */
|
2009-08-27 16:25:46 +00:00
|
|
|
me.ip = ifa->lladdr;
|
2009-08-21 07:27:52 +00:00
|
|
|
me.dr = ifa->drid;
|
|
|
|
me.bdr = ifa->bdrid;
|
|
|
|
me.iface_id = ifa->iface->index;
|
|
|
|
#endif
|
|
|
|
|
2004-06-06 09:37:54 +00:00
|
|
|
add_tail(&ifa->neigh_list, NODE & me);
|
1999-11-17 15:50:41 +00:00
|
|
|
|
2004-06-06 09:37:54 +00:00
|
|
|
nbdr = electbdr(ifa->neigh_list);
|
|
|
|
ndr = electdr(ifa->neigh_list);
|
1999-11-17 15:50:41 +00:00
|
|
|
|
2004-06-06 09:37:54 +00:00
|
|
|
if (ndr == NULL)
|
|
|
|
ndr = nbdr;
|
1999-11-17 15:50:41 +00:00
|
|
|
|
2009-08-21 07:27:52 +00:00
|
|
|
/* 9.4. (4) */
|
2004-06-06 09:37:54 +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
|
|
|
{
|
2009-08-21 07:27:52 +00:00
|
|
|
#ifdef OSPFv2
|
2009-09-04 09:06:51 +00:00
|
|
|
me.dr = ndr ? ipa_to_u32(ndr->ip) : 0;
|
|
|
|
me.bdr = nbdr ? ipa_to_u32(nbdr->ip) : 0;
|
2009-08-21 07:27:52 +00:00
|
|
|
#else /* OSPFv3 */
|
|
|
|
me.dr = ndr ? ndr->rid : 0;
|
|
|
|
me.bdr = nbdr ? nbdr->rid : 0;
|
|
|
|
#endif
|
2004-06-06 09:37:54 +00:00
|
|
|
|
|
|
|
nbdr = electbdr(ifa->neigh_list);
|
|
|
|
ndr = electdr(ifa->neigh_list);
|
2000-06-08 01:49:19 +00:00
|
|
|
|
2009-08-21 07:27:52 +00:00
|
|
|
if (ndr == NULL)
|
|
|
|
ndr = nbdr;
|
2000-05-10 11:48:21 +00:00
|
|
|
}
|
|
|
|
|
2009-08-21 07:27:52 +00:00
|
|
|
u32 odrid = ifa->drid;
|
|
|
|
u32 obdrid = ifa->bdrid;
|
|
|
|
|
|
|
|
ifa->drid = ndr ? ndr->rid : 0;
|
|
|
|
ifa->drip = ndr ? ndr->ip : IPA_NONE;
|
|
|
|
ifa->bdrid = nbdr ? nbdr->rid : 0;
|
|
|
|
ifa->bdrip = nbdr ? nbdr->ip : IPA_NONE;
|
|
|
|
|
|
|
|
#ifdef OSPFv3
|
|
|
|
ifa->dr_iface_id = ndr ? ndr->iface_id : 0;
|
|
|
|
#endif
|
1999-11-17 15:50:41 +00:00
|
|
|
|
2009-07-23 14:51:28 +00:00
|
|
|
DBG("DR=%R, BDR=%R\n", ifa->drid, ifa->bdrid);
|
1999-11-17 15:50:41 +00:00
|
|
|
|
2009-08-21 07:27:52 +00:00
|
|
|
doadj = ((ifa->drid != odrid) || (ifa->bdrid != obdrid));
|
|
|
|
|
2004-06-06 09:37:54 +00:00
|
|
|
if (myid == ifa->drid)
|
|
|
|
ospf_iface_chstate(ifa, OSPF_IS_DR);
|
1999-11-17 15:50:41 +00:00
|
|
|
else
|
|
|
|
{
|
2004-06-06 09:37:54 +00:00
|
|
|
if (myid == ifa->bdrid)
|
|
|
|
ospf_iface_chstate(ifa, OSPF_IS_BACKUP);
|
|
|
|
else
|
|
|
|
ospf_iface_chstate(ifa, OSPF_IS_DROTHER);
|
1999-11-17 15:50:41 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 09:37:54 +00:00
|
|
|
rem_node(NODE & me);
|
1999-11-17 15:50:41 +00:00
|
|
|
|
2004-06-06 09:37:54 +00:00
|
|
|
if (doadj)
|
1999-11-17 15:50:41 +00:00
|
|
|
{
|
2004-06-06 09:37:54 +00:00
|
|
|
WALK_LIST(neigh, ifa->neigh_list)
|
1999-11-17 15:50:41 +00:00
|
|
|
{
|
|
|
|
ospf_neigh_sm(neigh, INM_ADJOK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ospf_neighbor *
|
|
|
|
find_neigh(struct ospf_iface *ifa, u32 rid)
|
|
|
|
{
|
|
|
|
struct ospf_neighbor *n;
|
|
|
|
|
2004-06-06 09:37:54 +00:00
|
|
|
WALK_LIST(n, ifa->neigh_list) if (n->rid == rid)
|
|
|
|
return n;
|
1999-11-17 15:50:41 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-06-09 14:55:10 +00:00
|
|
|
|
2005-02-13 23:36:31 +00:00
|
|
|
/* Find a closest neighbor which is at least 2-Way */
|
2000-04-30 11:31:05 +00:00
|
|
|
struct ospf_neighbor *
|
|
|
|
find_neigh_noifa(struct proto_ospf *po, u32 rid)
|
|
|
|
{
|
2004-06-06 09:37:54 +00:00
|
|
|
struct ospf_neighbor *n = NULL, *m;
|
2000-04-30 11:31:05 +00:00
|
|
|
struct ospf_iface *ifa;
|
|
|
|
|
2004-06-06 09:37:54 +00:00
|
|
|
WALK_LIST(ifa, po->iface_list) if ((m = find_neigh(ifa, rid)) != NULL)
|
|
|
|
{
|
|
|
|
if (m->state >= NEIGHBOR_2WAY)
|
2001-06-09 14:55:10 +00:00
|
|
|
{
|
2004-06-06 09:37:54 +00:00
|
|
|
if (n == NULL)
|
|
|
|
n = m;
|
|
|
|
else if (m->ifa->cost < n->ifa->cost)
|
|
|
|
n = m;
|
2001-06-09 14:55:10 +00:00
|
|
|
}
|
2004-06-06 09:37:54 +00:00
|
|
|
}
|
2001-06-09 14:55:10 +00:00
|
|
|
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;
|
2005-02-14 11:54:16 +00:00
|
|
|
WALK_LIST(oa, po->area_list)
|
2004-06-06 09:37:54 +00:00
|
|
|
if (((struct ospf_area *) oa)->areaid == aid)
|
|
|
|
return oa;
|
2000-04-03 22:31:07 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-05-10 12:37:43 +00:00
|
|
|
/* Neighbor is inactive for a long time. Remove it. */
|
2009-01-13 18:15:49 +00:00
|
|
|
static void
|
2004-06-06 09:37:54 +00:00
|
|
|
neighbor_timer_hook(timer * timer)
|
2000-05-10 12:37:43 +00:00
|
|
|
{
|
2004-07-15 16:37:52 +00:00
|
|
|
struct ospf_neighbor *n = (struct ospf_neighbor *) timer->data;
|
|
|
|
struct ospf_iface *ifa = n->ifa;
|
|
|
|
struct proto *p = &ifa->oa->po->proto;
|
2000-05-10 12:37:43 +00:00
|
|
|
|
2004-06-06 09:37:54 +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)
|
|
|
|
{
|
2004-07-15 16:37:52 +00:00
|
|
|
struct ospf_iface *ifa = n->ifa;
|
|
|
|
struct proto *p = &ifa->oa->po->proto;
|
2000-05-16 23:59:38 +00:00
|
|
|
|
2009-01-13 18:15:49 +00:00
|
|
|
s_get(&(n->dbsi));
|
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)
|
|
|
|
{
|
2004-06-06 09:37:54 +00:00
|
|
|
struct ospf_iface *ifa = n->ifa;
|
|
|
|
char *pos = "other";
|
|
|
|
char etime[6];
|
|
|
|
int exp, sec, min;
|
|
|
|
|
|
|
|
exp = n->inactim->expires - now;
|
2005-02-20 03:30:44 +00:00
|
|
|
sec = exp % 60;
|
|
|
|
min = exp / 60;
|
2004-06-06 09:37:54 +00:00
|
|
|
if (min > 59)
|
|
|
|
{
|
|
|
|
bsprintf(etime, "-Inf-");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bsprintf(etime, "%02u:%02u", min, sec);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n->rid == ifa->drid)
|
|
|
|
pos = "dr ";
|
|
|
|
if (n->rid == ifa->bdrid)
|
|
|
|
pos = "bdr ";
|
2004-07-14 21:46:20 +00:00
|
|
|
if ((n->ifa->type == OSPF_IT_PTP) || (n->ifa->type == OSPF_IT_VLINK))
|
2004-06-06 09:37:54 +00:00
|
|
|
pos = "ptp ";
|
|
|
|
|
2010-01-03 11:17:52 +00:00
|
|
|
cli_msg(-1013, "%-1R\t%3u\t%s/%s\t%-5s\t%-10s %-1I", n->rid, n->priority,
|
|
|
|
ospf_ns[n->state], pos, etime,
|
|
|
|
(ifa->type == OSPF_IT_VLINK ? "vlink" : ifa->iface->name), n->ip);
|
2000-06-01 15:53:06 +00:00
|
|
|
}
|
2004-06-04 12:53:10 +00:00
|
|
|
|
2009-01-13 18:15:49 +00:00
|
|
|
static void
|
2004-06-06 09:37:54 +00:00
|
|
|
rxmt_timer_hook(timer * timer)
|
2004-06-04 12:53:10 +00:00
|
|
|
{
|
2004-06-06 09:37:54 +00:00
|
|
|
struct ospf_neighbor *n = (struct ospf_neighbor *) timer->data;
|
2010-02-21 13:34:53 +00:00
|
|
|
// struct proto *p = &n->ifa->oa->po->proto;
|
2004-06-04 12:53:10 +00:00
|
|
|
struct top_hash_entry *en;
|
|
|
|
|
|
|
|
DBG("%s: RXMT timer fired on interface %s for neigh: %I.\n",
|
2009-01-11 11:14:27 +00:00
|
|
|
p->name, n->ifa->iface->name, n->ip);
|
2004-06-11 09:34:48 +00:00
|
|
|
|
|
|
|
if(n->state < NEIGHBOR_EXSTART) return;
|
|
|
|
|
|
|
|
if (n->state == NEIGHBOR_EXSTART)
|
|
|
|
{
|
2009-04-06 14:53:06 +00:00
|
|
|
ospf_dbdes_send(n, 1);
|
2004-06-11 09:34:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((n->state == NEIGHBOR_EXCHANGE) && n->myimms.bit.ms) /* I'm master */
|
2009-04-06 14:53:06 +00:00
|
|
|
ospf_dbdes_send(n, 0);
|
2004-06-11 09:34:48 +00:00
|
|
|
|
2004-06-04 12:53:10 +00:00
|
|
|
|
2004-06-11 09:34:48 +00:00
|
|
|
if (n->state < NEIGHBOR_FULL)
|
|
|
|
ospf_lsreq_send(n); /* EXCHANGE or LOADING */
|
2004-06-04 12:53:10 +00:00
|
|
|
else
|
|
|
|
{
|
2004-06-11 09:34:48 +00:00
|
|
|
if (!EMPTY_SLIST(n->lsrtl)) /* FULL */
|
2004-06-04 12:53:10 +00:00
|
|
|
{
|
|
|
|
list uplist;
|
|
|
|
slab *upslab;
|
|
|
|
struct l_lsr_head *llsh;
|
|
|
|
|
|
|
|
init_list(&uplist);
|
2004-06-06 09:37:54 +00:00
|
|
|
upslab = sl_new(n->pool, sizeof(struct l_lsr_head));
|
2004-06-04 12:53:10 +00:00
|
|
|
|
2005-02-14 11:54:16 +00:00
|
|
|
WALK_SLIST(en, n->lsrtl)
|
2004-06-04 12:53:10 +00:00
|
|
|
{
|
2004-06-06 09:37:54 +00:00
|
|
|
if ((SNODE en)->next == (SNODE en))
|
|
|
|
bug("RTList is cycled");
|
|
|
|
llsh = sl_alloc(upslab);
|
|
|
|
llsh->lsh.id = en->lsa.id;
|
|
|
|
llsh->lsh.rt = en->lsa.rt;
|
|
|
|
llsh->lsh.type = en->lsa.type;
|
2009-07-23 14:51:28 +00:00
|
|
|
DBG("Working on ID: %R, RT: %R, Type: %u\n",
|
|
|
|
en->lsa.id, en->lsa.rt, en->lsa.type);
|
2004-06-06 09:37:54 +00:00
|
|
|
add_tail(&uplist, NODE llsh);
|
2004-06-04 12:53:10 +00:00
|
|
|
}
|
2004-06-04 21:05:43 +00:00
|
|
|
ospf_lsupd_send_list(n, &uplist);
|
2004-06-04 12:53:10 +00:00
|
|
|
rfree(upslab);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-13 18:15:49 +00:00
|
|
|
static void
|
2004-06-06 09:37:54 +00:00
|
|
|
ackd_timer_hook(timer * t)
|
2004-06-04 15:45:35 +00:00
|
|
|
{
|
2004-06-06 09:37:54 +00:00
|
|
|
struct ospf_neighbor *n = t->data;
|
2004-06-04 16:30:04 +00:00
|
|
|
ospf_lsack_send(n, ACKL_DELAY);
|
2004-06-04 15:45:35 +00:00
|
|
|
}
|