1999-11-17 23:50:41 +08:00
|
|
|
/*
|
|
|
|
* BIRD -- OSPF
|
|
|
|
*
|
2014-06-26 17:58:57 +08:00
|
|
|
* (c) 1999--2004 Ondrej Filip <feela@network.cz>
|
|
|
|
* (c) 2009--2014 Ondrej Zajicek <santiago@crfreenet.org>
|
|
|
|
* (c) 2009--2014 CZ.NIC z.s.p.o.
|
1999-11-17 23:50:41 +08:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ospf.h"
|
|
|
|
|
2014-10-24 16:27:21 +08:00
|
|
|
|
|
|
|
const char *ospf_ns_names[] = {
|
|
|
|
"Down", "Attempt", "Init", "2-Way", "ExStart", "Exchange", "Loading", "Full"
|
2004-06-06 17:37:54 +08:00
|
|
|
};
|
|
|
|
|
2014-10-24 16:27:21 +08:00
|
|
|
const char *ospf_inm_names[] = {
|
|
|
|
"HelloReceived", "Start", "2-WayReceived", "NegotiationDone", "ExchangeDone",
|
|
|
|
"BadLSReq", "LoadingDone", "AdjOK?", "SeqNumberMismatch", "1-WayReceived",
|
|
|
|
"KillNbr", "InactivityTimer", "LLDown"
|
2004-06-06 17:37:54 +08:00
|
|
|
};
|
2000-04-19 03:22:49 +08:00
|
|
|
|
2014-10-24 16:27:21 +08:00
|
|
|
|
|
|
|
static int can_do_adj(struct ospf_neighbor *n);
|
2014-11-03 17:42:55 +08:00
|
|
|
static void inactivity_timer_hook(timer * timer);
|
|
|
|
static void dbdes_timer_hook(timer *t);
|
|
|
|
static void lsrq_timer_hook(timer *t);
|
|
|
|
static void lsrt_timer_hook(timer *t);
|
|
|
|
static void ackd_timer_hook(timer *t);
|
|
|
|
|
2009-01-14 02:15:49 +08:00
|
|
|
|
|
|
|
static void
|
2014-07-19 00:24:12 +08:00
|
|
|
init_lists(struct ospf_proto *p, struct ospf_neighbor *n)
|
2009-01-14 02:15:49 +08:00
|
|
|
{
|
|
|
|
s_init_list(&(n->lsrql));
|
2014-11-03 17:42:55 +08:00
|
|
|
n->lsrqi = SHEAD(n->lsrql);
|
2014-07-19 00:24:12 +08:00
|
|
|
n->lsrqh = ospf_top_new(p, n->pool);
|
2009-01-14 02:15:49 +08:00
|
|
|
|
|
|
|
s_init_list(&(n->lsrtl));
|
2014-07-19 00:24:12 +08:00
|
|
|
n->lsrth = ospf_top_new(p, n->pool);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
release_lsrtl(struct ospf_proto *p, struct ospf_neighbor *n)
|
|
|
|
{
|
|
|
|
struct top_hash_entry *ret, *en;
|
|
|
|
|
|
|
|
WALK_SLIST(ret, n->lsrtl)
|
|
|
|
{
|
|
|
|
en = ospf_hash_find_entry(p->gr, ret);
|
|
|
|
if (en)
|
|
|
|
en->ret_count--;
|
|
|
|
}
|
2009-01-14 02:15:49 +08:00
|
|
|
}
|
2004-06-04 20:53:10 +08:00
|
|
|
|
2009-01-14 02:25:27 +08:00
|
|
|
/* Resets LSA request and retransmit lists.
|
2014-07-19 23:28:38 +08:00
|
|
|
* We do not reset DB summary list iterator here,
|
2009-01-14 02:15:49 +08:00
|
|
|
* it is reset during entering EXCHANGE state.
|
|
|
|
*/
|
|
|
|
static void
|
2014-07-19 00:24:12 +08:00
|
|
|
reset_lists(struct ospf_proto *p, struct ospf_neighbor *n)
|
2009-01-14 02:15:49 +08:00
|
|
|
{
|
2014-11-03 17:42:55 +08:00
|
|
|
release_lsrtl(p, n);
|
2009-01-14 02:15:49 +08:00
|
|
|
ospf_top_free(n->lsrqh);
|
|
|
|
ospf_top_free(n->lsrth);
|
2014-11-03 17:42:55 +08:00
|
|
|
ospf_reset_lsack_queue(n);
|
|
|
|
|
2017-11-29 00:43:20 +08:00
|
|
|
tm_stop(n->dbdes_timer);
|
|
|
|
tm_stop(n->lsrq_timer);
|
|
|
|
tm_stop(n->lsrt_timer);
|
|
|
|
tm_stop(n->ackd_timer);
|
2014-11-03 17:42:55 +08:00
|
|
|
|
2014-07-19 00:24:12 +08:00
|
|
|
init_lists(p, n);
|
2009-01-14 02:15:49 +08:00
|
|
|
}
|
2004-06-04 20:53:10 +08:00
|
|
|
|
|
|
|
struct ospf_neighbor *
|
|
|
|
ospf_neighbor_new(struct ospf_iface *ifa)
|
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
struct ospf_proto *p = ifa->oa->po;
|
|
|
|
struct pool *pool = rp_new(p->p.pool, "OSPF Neighbor");
|
2004-06-04 20:53:10 +08:00
|
|
|
struct ospf_neighbor *n = mb_allocz(pool, sizeof(struct ospf_neighbor));
|
|
|
|
|
|
|
|
n->pool = pool;
|
|
|
|
n->ifa = ifa;
|
|
|
|
add_tail(&ifa->neigh_list, NODE n);
|
2004-06-06 17:37:54 +08:00
|
|
|
n->state = NEIGHBOR_DOWN;
|
2004-06-04 20:53:10 +08:00
|
|
|
|
2014-07-19 00:24:12 +08:00
|
|
|
init_lists(p, n);
|
2014-06-26 17:58:57 +08:00
|
|
|
s_init(&(n->dbsi), &(p->lsal));
|
2009-01-14 02:15:49 +08:00
|
|
|
|
2004-06-05 00:30:04 +08:00
|
|
|
init_list(&n->ackl[ACKL_DIRECT]);
|
|
|
|
init_list(&n->ackl[ACKL_DELAY]);
|
2014-11-03 17:42:55 +08:00
|
|
|
|
2017-11-29 00:43:20 +08:00
|
|
|
n->inactim = tm_new_init(pool, inactivity_timer_hook, n, 0, 0);
|
|
|
|
n->dbdes_timer = tm_new_init(pool, dbdes_timer_hook, n, ifa->rxmtint S, 0);
|
|
|
|
n->lsrq_timer = tm_new_init(pool, lsrq_timer_hook, n, ifa->rxmtint S, 0);
|
|
|
|
n->lsrt_timer = tm_new_init(pool, lsrt_timer_hook, n, ifa->rxmtint S, 0);
|
|
|
|
n->ackd_timer = tm_new_init(pool, ackd_timer_hook, n, ifa->rxmtint S / 2, 0);
|
2004-06-04 20:53:10 +08:00
|
|
|
|
2004-06-06 17:37:54 +08:00
|
|
|
return (n);
|
2004-06-04 20:53:10 +08:00
|
|
|
}
|
|
|
|
|
2014-10-24 16:27:21 +08:00
|
|
|
static void
|
|
|
|
ospf_neigh_down(struct ospf_neighbor *n)
|
|
|
|
{
|
|
|
|
struct ospf_iface *ifa = n->ifa;
|
|
|
|
struct ospf_proto *p = ifa->oa->po;
|
2016-03-10 00:37:44 +08:00
|
|
|
u32 rid = n->rid;
|
2014-10-24 16:27:21 +08:00
|
|
|
|
|
|
|
if ((ifa->type == OSPF_IT_NBMA) || (ifa->type == OSPF_IT_PTMP))
|
|
|
|
{
|
|
|
|
struct nbma_node *nn = find_nbma_node(ifa, n->ip);
|
|
|
|
if (nn)
|
|
|
|
nn->found = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
s_get(&(n->dbsi));
|
|
|
|
release_lsrtl(p, n);
|
|
|
|
rem_node(NODE n);
|
|
|
|
rfree(n->pool);
|
|
|
|
|
2016-03-10 00:37:44 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "Neighbor %R on %s removed", rid, ifa->ifname);
|
2014-10-24 16:27:21 +08:00
|
|
|
}
|
|
|
|
|
2000-06-08 05:46:22 +08:00
|
|
|
/**
|
2014-10-24 16:27:21 +08:00
|
|
|
* ospf_neigh_chstate - handles changes related to new or lod state of neighbor
|
2000-06-08 05:46:22 +08:00
|
|
|
* @n: OSPF neighbor
|
|
|
|
* @state: new state
|
|
|
|
*
|
2003-08-23 18:42:41 +08:00
|
|
|
* Many actions have to be taken acording to a change of state of a neighbor. It
|
2000-06-08 05:46:22 +08:00
|
|
|
* starts rxmt timers, call interface state machine etc.
|
|
|
|
*/
|
2009-01-14 02:15:49 +08:00
|
|
|
static void
|
2014-10-24 16:27:21 +08:00
|
|
|
ospf_neigh_chstate(struct ospf_neighbor *n, u8 state)
|
1999-11-17 23:50:41 +08:00
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
struct ospf_iface *ifa = n->ifa;
|
|
|
|
struct ospf_proto *p = ifa->oa->po;
|
|
|
|
u8 old_state = n->state;
|
|
|
|
int old_fadj = ifa->fadj;
|
1999-11-17 23:50:41 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
if (state == old_state)
|
|
|
|
return;
|
2000-05-09 06:40:55 +08:00
|
|
|
|
2014-10-24 16:27:21 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "Neighbor %R on %s changed state from %s to %s",
|
|
|
|
n->rid, ifa->ifname, ospf_ns_names[old_state], ospf_ns_names[state]);
|
2000-05-09 19:52:44 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
n->state = state;
|
2000-05-09 19:52:44 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
/* Increase number of partial adjacencies */
|
|
|
|
if ((state == NEIGHBOR_EXCHANGE) || (state == NEIGHBOR_LOADING))
|
|
|
|
p->padj++;
|
2000-05-09 19:52:44 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
/* Decrease number of partial adjacencies */
|
|
|
|
if ((old_state == NEIGHBOR_EXCHANGE) || (old_state == NEIGHBOR_LOADING))
|
|
|
|
p->padj--;
|
2004-06-06 17:37:54 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
/* Increase number of full adjacencies */
|
|
|
|
if (state == NEIGHBOR_FULL)
|
|
|
|
ifa->fadj++;
|
|
|
|
|
|
|
|
/* Decrease number of full adjacencies */
|
|
|
|
if (old_state == NEIGHBOR_FULL)
|
|
|
|
ifa->fadj--;
|
|
|
|
|
|
|
|
if (ifa->fadj != old_fadj)
|
|
|
|
{
|
|
|
|
/* RFC 2328 12.4 Event 4 - neighbor enters/leaves Full state */
|
|
|
|
ospf_notify_rt_lsa(ifa->oa);
|
|
|
|
ospf_notify_net_lsa(ifa);
|
|
|
|
|
|
|
|
/* RFC 2328 12.4 Event 8 - vlink state change */
|
|
|
|
if (ifa->type == OSPF_IT_VLINK)
|
|
|
|
ospf_notify_rt_lsa(ifa->voa);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state == NEIGHBOR_EXSTART)
|
|
|
|
{
|
2019-02-03 23:20:37 +08:00
|
|
|
/* First time adjacency attempt */
|
|
|
|
if (old_state < NEIGHBOR_EXSTART)
|
2014-06-26 17:58:57 +08:00
|
|
|
n->dds = random_u32();
|
|
|
|
|
|
|
|
n->dds++;
|
|
|
|
n->myimms = DBDES_IMMS;
|
2014-11-03 17:42:55 +08:00
|
|
|
|
2017-11-29 00:43:20 +08:00
|
|
|
tm_start(n->dbdes_timer, 0);
|
|
|
|
tm_start(n->ackd_timer, ifa->rxmtint S / 2);
|
1999-11-17 23:50:41 +08:00
|
|
|
}
|
2014-06-26 17:58:57 +08:00
|
|
|
|
|
|
|
if (state > NEIGHBOR_EXSTART)
|
|
|
|
n->myimms &= ~DBDES_I;
|
1999-11-17 23:50:41 +08:00
|
|
|
|
2014-10-24 16:27:21 +08:00
|
|
|
/* Generate NeighborChange event if needed, see RFC 2328 9.2 */
|
|
|
|
if ((state == NEIGHBOR_2WAY) && (old_state < NEIGHBOR_2WAY))
|
|
|
|
ospf_iface_sm(ifa, ISM_NEICH);
|
|
|
|
if ((state < NEIGHBOR_2WAY) && (old_state >= NEIGHBOR_2WAY))
|
|
|
|
ospf_iface_sm(ifa, ISM_NEICH);
|
1999-11-17 23:50:41 +08:00
|
|
|
}
|
|
|
|
|
2000-06-08 05:46:22 +08:00
|
|
|
/**
|
|
|
|
* ospf_neigh_sm - ospf neighbor state machine
|
|
|
|
* @n: neighor
|
|
|
|
* @event: actual event
|
|
|
|
*
|
2003-08-23 18:42:41 +08: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-08 05:46:22 +08:00
|
|
|
* @ospf_iface->nbma_list .
|
|
|
|
*/
|
1999-11-17 23:50:41 +08:00
|
|
|
void
|
|
|
|
ospf_neigh_sm(struct ospf_neighbor *n, int event)
|
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
struct ospf_proto *p = n->ifa->oa->po;
|
1999-11-17 23:50:41 +08:00
|
|
|
|
2014-10-24 16:27:21 +08:00
|
|
|
DBG("Neighbor state machine for %R on %s, event %s\n",
|
|
|
|
n->rid, n->ifa->ifname, ospf_inm_names[event]);
|
2000-04-19 03:22:49 +08:00
|
|
|
|
2004-06-06 17:37:54 +08:00
|
|
|
switch (event)
|
1999-11-17 23:50:41 +08:00
|
|
|
{
|
2004-06-06 17:37:54 +08:00
|
|
|
case INM_START:
|
2014-10-24 16:27:21 +08:00
|
|
|
ospf_neigh_chstate(n, NEIGHBOR_ATTEMPT);
|
2004-06-06 17:37:54 +08:00
|
|
|
/* NBMA are used different way */
|
|
|
|
break;
|
2014-06-26 17:58:57 +08:00
|
|
|
|
2004-06-06 17:37:54 +08:00
|
|
|
case INM_HELLOREC:
|
2014-10-24 16:27:21 +08:00
|
|
|
if (n->state < NEIGHBOR_INIT)
|
|
|
|
ospf_neigh_chstate(n, NEIGHBOR_INIT);
|
2014-06-26 17:58:57 +08:00
|
|
|
|
|
|
|
/* Restart inactivity timer */
|
2017-11-29 00:43:20 +08:00
|
|
|
tm_start(n->inactim, n->ifa->deadint S);
|
2004-06-06 17:37:54 +08:00
|
|
|
break;
|
2014-06-26 17:58:57 +08:00
|
|
|
|
2004-06-06 17:37:54 +08:00
|
|
|
case INM_2WAYREC:
|
|
|
|
if (n->state < NEIGHBOR_2WAY)
|
2014-10-24 16:27:21 +08:00
|
|
|
ospf_neigh_chstate(n, NEIGHBOR_2WAY);
|
2004-06-06 17:37:54 +08:00
|
|
|
if ((n->state == NEIGHBOR_2WAY) && can_do_adj(n))
|
2014-10-24 16:27:21 +08:00
|
|
|
ospf_neigh_chstate(n, NEIGHBOR_EXSTART);
|
2004-06-06 17:37:54 +08:00
|
|
|
break;
|
2014-06-26 17:58:57 +08:00
|
|
|
|
2004-06-06 17:37:54 +08:00
|
|
|
case INM_NEGDONE:
|
|
|
|
if (n->state == NEIGHBOR_EXSTART)
|
|
|
|
{
|
2014-10-24 16:27:21 +08:00
|
|
|
ospf_neigh_chstate(n, NEIGHBOR_EXCHANGE);
|
2009-01-14 02:15:49 +08:00
|
|
|
|
|
|
|
/* Reset DB summary list iterator */
|
|
|
|
s_get(&(n->dbsi));
|
2014-06-26 17:58:57 +08:00
|
|
|
s_init(&(n->dbsi), &p->lsal);
|
2009-01-14 02:15:49 +08:00
|
|
|
|
2014-07-19 00:24:12 +08:00
|
|
|
/* Add MaxAge LSA entries to retransmission list */
|
|
|
|
ospf_add_flushed_to_lsrt(p, n);
|
2004-06-06 17:37:54 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
bug("NEGDONE and I'm not in EXSTART?");
|
|
|
|
break;
|
2014-06-26 17:58:57 +08:00
|
|
|
|
2004-06-06 17:37:54 +08:00
|
|
|
case INM_EXDONE:
|
2014-11-03 17:42:55 +08:00
|
|
|
if (!EMPTY_SLIST(n->lsrql))
|
|
|
|
ospf_neigh_chstate(n, NEIGHBOR_LOADING);
|
|
|
|
else
|
|
|
|
ospf_neigh_chstate(n, NEIGHBOR_FULL);
|
2004-06-06 17:37:54 +08:00
|
|
|
break;
|
2014-06-26 17:58:57 +08:00
|
|
|
|
2004-06-06 17:37:54 +08:00
|
|
|
case INM_LOADDONE:
|
2014-10-24 16:27:21 +08:00
|
|
|
ospf_neigh_chstate(n, NEIGHBOR_FULL);
|
2004-06-06 17:37:54 +08:00
|
|
|
break;
|
2014-06-26 17:58:57 +08:00
|
|
|
|
2004-06-06 17:37:54 +08:00
|
|
|
case INM_ADJOK:
|
2014-11-03 17:42:55 +08:00
|
|
|
/* Can In build adjacency? */
|
|
|
|
if ((n->state == NEIGHBOR_2WAY) && can_do_adj(n))
|
2004-06-06 17:37:54 +08:00
|
|
|
{
|
2014-11-03 17:42:55 +08:00
|
|
|
ospf_neigh_chstate(n, NEIGHBOR_EXSTART);
|
|
|
|
}
|
|
|
|
else if ((n->state >= NEIGHBOR_EXSTART) && !can_do_adj(n))
|
|
|
|
{
|
|
|
|
reset_lists(p, n);
|
|
|
|
ospf_neigh_chstate(n, NEIGHBOR_2WAY);
|
2004-06-06 17:37:54 +08:00
|
|
|
}
|
|
|
|
break;
|
2014-06-26 17:58:57 +08:00
|
|
|
|
2004-06-06 17:37:54 +08:00
|
|
|
case INM_SEQMIS:
|
|
|
|
case INM_BADLSREQ:
|
|
|
|
if (n->state >= NEIGHBOR_EXCHANGE)
|
|
|
|
{
|
2014-07-19 00:24:12 +08:00
|
|
|
reset_lists(p, n);
|
2014-10-24 16:27:21 +08:00
|
|
|
ospf_neigh_chstate(n, NEIGHBOR_EXSTART);
|
2004-06-06 17:37:54 +08:00
|
|
|
}
|
|
|
|
break;
|
2014-06-26 17:58:57 +08:00
|
|
|
|
2004-06-06 17:37:54 +08:00
|
|
|
case INM_KILLNBR:
|
|
|
|
case INM_LLDOWN:
|
|
|
|
case INM_INACTTIM:
|
2014-10-24 16:27:21 +08:00
|
|
|
/* No need for reset_lists() */
|
|
|
|
ospf_neigh_chstate(n, NEIGHBOR_DOWN);
|
|
|
|
ospf_neigh_down(n);
|
2004-06-06 17:37:54 +08:00
|
|
|
break;
|
2014-06-26 17:58:57 +08:00
|
|
|
|
2004-06-06 17:37:54 +08:00
|
|
|
case INM_1WAYREC:
|
2014-07-19 00:24:12 +08:00
|
|
|
reset_lists(p, n);
|
2014-10-24 16:27:21 +08:00
|
|
|
ospf_neigh_chstate(n, NEIGHBOR_INIT);
|
2004-06-06 17:37:54 +08:00
|
|
|
break;
|
2014-06-26 17:58:57 +08:00
|
|
|
|
2004-06-06 17:37:54 +08:00
|
|
|
default:
|
2014-06-26 17:58:57 +08:00
|
|
|
bug("%s: INM - Unknown event?", p->p.name);
|
2004-06-06 17:37:54 +08:00
|
|
|
break;
|
1999-11-17 23:50:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-24 16:27:21 +08:00
|
|
|
static int
|
|
|
|
can_do_adj(struct ospf_neighbor *n)
|
|
|
|
{
|
|
|
|
struct ospf_iface *ifa = n->ifa;
|
|
|
|
struct ospf_proto *p = ifa->oa->po;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
switch (ifa->type)
|
|
|
|
{
|
|
|
|
case OSPF_IT_PTP:
|
|
|
|
case OSPF_IT_PTMP:
|
|
|
|
case OSPF_IT_VLINK:
|
|
|
|
i = 1;
|
|
|
|
break;
|
|
|
|
case OSPF_IT_BCAST:
|
|
|
|
case OSPF_IT_NBMA:
|
|
|
|
switch (ifa->state)
|
|
|
|
{
|
|
|
|
case OSPF_IS_DOWN:
|
|
|
|
case OSPF_IS_LOOP:
|
|
|
|
bug("%s: Iface %s in down state?", p->p.name, ifa->ifname);
|
|
|
|
break;
|
|
|
|
case OSPF_IS_WAITING:
|
|
|
|
DBG("%s: Neighbor? on iface %s\n", p->p.name, ifa->ifname);
|
|
|
|
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;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
bug("%s: Iface %s in unknown state?", p->p.name, ifa->ifname);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
bug("%s: Iface %s is unknown type?", p->p.name, ifa->ifname);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DBG("%s: Iface %s can_do_adj=%d\n", p->p.name, ifa->ifname, i);
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline u32 neigh_get_id(struct ospf_proto *p, struct ospf_neighbor *n)
|
|
|
|
{ return ospf_is_v2(p) ? ipa_to_u32(n->ip) : n->rid; }
|
|
|
|
|
|
|
|
static struct ospf_neighbor *
|
|
|
|
elect_bdr(struct ospf_proto *p, list nl)
|
|
|
|
{
|
|
|
|
struct ospf_neighbor *neigh, *n1, *n2;
|
|
|
|
u32 nid;
|
|
|
|
|
|
|
|
n1 = NULL;
|
|
|
|
n2 = NULL;
|
|
|
|
WALK_LIST(neigh, nl) /* First try those decl. themselves */
|
|
|
|
{
|
|
|
|
nid = neigh_get_id(p, neigh);
|
|
|
|
|
|
|
|
if (neigh->state >= NEIGHBOR_2WAY) /* Higher than 2WAY */
|
|
|
|
if (neigh->priority > 0) /* Eligible */
|
|
|
|
if (neigh->dr != nid) /* And not decl. itself DR */
|
|
|
|
{
|
|
|
|
if (neigh->bdr == nid) /* Declaring BDR */
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ospf_neighbor *
|
|
|
|
elect_dr(struct ospf_proto *p, list nl)
|
|
|
|
{
|
|
|
|
struct ospf_neighbor *neigh, *n;
|
|
|
|
u32 nid;
|
|
|
|
|
|
|
|
n = NULL;
|
|
|
|
WALK_LIST(neigh, nl) /* And now DR */
|
|
|
|
{
|
|
|
|
nid = neigh_get_id(p, neigh);
|
|
|
|
|
|
|
|
if (neigh->state >= NEIGHBOR_2WAY) /* Higher than 2WAY */
|
|
|
|
if (neigh->priority > 0) /* Eligible */
|
|
|
|
if (neigh->dr == nid) /* And declaring itself DR */
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2000-06-08 05:46:22 +08:00
|
|
|
/**
|
2014-06-26 17:58:57 +08:00
|
|
|
* ospf_dr_election - (Backup) Designed Router election
|
2000-06-08 05:46:22 +08:00
|
|
|
* @ifa: actual interface
|
|
|
|
*
|
2003-08-23 18:42:41 +08:00
|
|
|
* When the wait timer fires, it is time to elect (Backup) Designated Router.
|
2014-10-24 16:27:21 +08:00
|
|
|
* Structure describing me is added to this list so every electing router has
|
|
|
|
* the same list. Backup Designated Router is elected before Designated
|
|
|
|
* Router. This process is described in 9.4 of RFC 2328. The function is
|
|
|
|
* supposed to be called only from ospf_iface_sm() as a part of the interface
|
|
|
|
* state machine.
|
2000-06-08 05:46:22 +08:00
|
|
|
*/
|
1999-11-17 23:50:41 +08:00
|
|
|
void
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_dr_election(struct ospf_iface *ifa)
|
1999-11-17 23:50:41 +08:00
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
struct ospf_proto *p = ifa->oa->po;
|
2004-06-06 17:37:54 +08:00
|
|
|
struct ospf_neighbor *neigh, *ndr, *nbdr, me;
|
2014-06-26 17:58:57 +08:00
|
|
|
u32 myid = p->router_id;
|
1999-11-17 23:50:41 +08:00
|
|
|
|
2000-06-08 09:49:19 +08:00
|
|
|
DBG("(B)DR election.\n");
|
1999-11-17 23:50:41 +08:00
|
|
|
|
2004-06-06 17:37:54 +08:00
|
|
|
me.state = NEIGHBOR_2WAY;
|
|
|
|
me.rid = myid;
|
|
|
|
me.priority = ifa->priority;
|
2010-02-11 17:23:35 +08:00
|
|
|
me.ip = ifa->addr->ip;
|
1999-11-17 23:50:41 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
me.dr = ospf_is_v2(p) ? ipa_to_u32(ifa->drip) : ifa->drid;
|
|
|
|
me.bdr = ospf_is_v2(p) ? ipa_to_u32(ifa->bdrip) : ifa->bdrid;
|
2012-11-01 00:14:35 +08:00
|
|
|
me.iface_id = ifa->iface_id;
|
2009-08-21 15:27:52 +08:00
|
|
|
|
2004-06-06 17:37:54 +08:00
|
|
|
add_tail(&ifa->neigh_list, NODE & me);
|
1999-11-17 23:50:41 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
nbdr = elect_bdr(p, ifa->neigh_list);
|
|
|
|
ndr = elect_dr(p, ifa->neigh_list);
|
1999-11-17 23:50:41 +08:00
|
|
|
|
2004-06-06 17:37:54 +08:00
|
|
|
if (ndr == NULL)
|
|
|
|
ndr = nbdr;
|
1999-11-17 23:50:41 +08:00
|
|
|
|
2009-08-21 15:27:52 +08:00
|
|
|
/* 9.4. (4) */
|
2004-06-06 17:37:54 +08: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 23:50:41 +08:00
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
me.dr = ndr ? neigh_get_id(p, ndr) : 0;
|
|
|
|
me.bdr = nbdr ? neigh_get_id(p, nbdr) : 0;
|
2004-06-06 17:37:54 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
nbdr = elect_bdr(p, ifa->neigh_list);
|
|
|
|
ndr = elect_dr(p, ifa->neigh_list);
|
2000-06-08 09:49:19 +08:00
|
|
|
|
2009-08-21 15:27:52 +08:00
|
|
|
if (ndr == NULL)
|
|
|
|
ndr = nbdr;
|
2000-05-10 19:48:21 +08:00
|
|
|
}
|
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
rem_node(NODE & me);
|
|
|
|
|
|
|
|
|
|
|
|
u32 old_drid = ifa->drid;
|
|
|
|
u32 old_bdrid = ifa->bdrid;
|
2015-12-24 22:52:03 +08:00
|
|
|
ip_addr none = ospf_is_v2(p) ? IPA_NONE4 : IPA_NONE6;
|
2014-07-19 23:28:38 +08:00
|
|
|
|
2009-08-21 15:27:52 +08:00
|
|
|
ifa->drid = ndr ? ndr->rid : 0;
|
2015-12-24 22:52:03 +08:00
|
|
|
ifa->drip = ndr ? ndr->ip : none;
|
2014-06-26 17:58:57 +08:00
|
|
|
ifa->dr_iface_id = ndr ? ndr->iface_id : 0;
|
|
|
|
|
2009-08-21 15:27:52 +08:00
|
|
|
ifa->bdrid = nbdr ? nbdr->rid : 0;
|
2015-12-24 22:52:03 +08:00
|
|
|
ifa->bdrip = nbdr ? nbdr->ip : none;
|
2009-08-21 15:27:52 +08:00
|
|
|
|
2009-07-23 22:51:28 +08:00
|
|
|
DBG("DR=%R, BDR=%R\n", ifa->drid, ifa->bdrid);
|
1999-11-17 23:50:41 +08:00
|
|
|
|
2014-10-24 16:27:21 +08:00
|
|
|
/* We are part of the interface state machine */
|
2014-06-26 17:58:57 +08:00
|
|
|
if (ifa->drid == myid)
|
2004-06-06 17:37:54 +08:00
|
|
|
ospf_iface_chstate(ifa, OSPF_IS_DR);
|
2014-06-26 17:58:57 +08:00
|
|
|
else if (ifa->bdrid == myid)
|
|
|
|
ospf_iface_chstate(ifa, OSPF_IS_BACKUP);
|
1999-11-17 23:50:41 +08:00
|
|
|
else
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_iface_chstate(ifa, OSPF_IS_DROTHER);
|
1999-11-17 23:50:41 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
/* Review neighbor adjacencies if DR or BDR changed */
|
|
|
|
if ((ifa->drid != old_drid) || (ifa->bdrid != old_bdrid))
|
2004-06-06 17:37:54 +08:00
|
|
|
WALK_LIST(neigh, ifa->neigh_list)
|
2014-06-26 17:58:57 +08:00
|
|
|
if (neigh->state >= NEIGHBOR_2WAY)
|
|
|
|
ospf_neigh_sm(neigh, INM_ADJOK);
|
|
|
|
|
|
|
|
/* RFC 2328 12.4 Event 3 - DR change */
|
|
|
|
if (ifa->drid != old_drid)
|
|
|
|
ospf_notify_rt_lsa(ifa->oa);
|
1999-11-17 23:50:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct ospf_neighbor *
|
|
|
|
find_neigh(struct ospf_iface *ifa, u32 rid)
|
|
|
|
{
|
|
|
|
struct ospf_neighbor *n;
|
2010-12-25 01:08:07 +08:00
|
|
|
WALK_LIST(n, ifa->neigh_list)
|
|
|
|
if (n->rid == rid)
|
|
|
|
return n;
|
|
|
|
return NULL;
|
|
|
|
}
|
1999-11-17 23:50:41 +08:00
|
|
|
|
2010-12-25 01:08:07 +08:00
|
|
|
struct ospf_neighbor *
|
|
|
|
find_neigh_by_ip(struct ospf_iface *ifa, ip_addr ip)
|
|
|
|
{
|
|
|
|
struct ospf_neighbor *n;
|
|
|
|
WALK_LIST(n, ifa->neigh_list)
|
|
|
|
if (ipa_equal(n->ip, ip))
|
|
|
|
return n;
|
1999-11-17 23:50:41 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-01-14 02:15:49 +08:00
|
|
|
static void
|
2014-11-03 17:42:55 +08:00
|
|
|
inactivity_timer_hook(timer * timer)
|
2000-05-10 20:37:43 +08:00
|
|
|
{
|
2004-07-16 00:37:52 +08:00
|
|
|
struct ospf_neighbor *n = (struct ospf_neighbor *) timer->data;
|
2014-10-24 16:27:21 +08:00
|
|
|
struct ospf_proto *p = n->ifa->oa->po;
|
2014-07-19 00:24:12 +08:00
|
|
|
|
2014-11-03 17:42:55 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "Inactivity timer expired for nbr %R on %s",
|
2014-10-24 16:27:21 +08:00
|
|
|
n->rid, n->ifa->ifname);
|
|
|
|
ospf_neigh_sm(n, INM_INACTTIM);
|
2000-05-17 07:59:38 +08:00
|
|
|
}
|
2000-06-01 23:53:06 +08:00
|
|
|
|
2013-11-20 05:33:48 +08:00
|
|
|
static void
|
|
|
|
ospf_neigh_bfd_hook(struct bfd_request *req)
|
|
|
|
{
|
|
|
|
struct ospf_neighbor *n = req->data;
|
2014-06-26 17:58:57 +08:00
|
|
|
struct ospf_proto *p = n->ifa->oa->po;
|
2013-11-20 05:33:48 +08:00
|
|
|
|
|
|
|
if (req->down)
|
|
|
|
{
|
2014-11-03 17:42:55 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "BFD session down for nbr %R on %s",
|
2014-10-24 16:27:21 +08:00
|
|
|
n->rid, n->ifa->ifname);
|
|
|
|
ospf_neigh_sm(n, INM_INACTTIM);
|
2013-11-20 05:33:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ospf_neigh_update_bfd(struct ospf_neighbor *n, int use_bfd)
|
|
|
|
{
|
|
|
|
if (use_bfd && !n->bfd_req)
|
|
|
|
n->bfd_req = bfd_request_session(n->pool, n->ip, n->ifa->addr->ip, n->ifa->iface,
|
|
|
|
ospf_neigh_bfd_hook, n);
|
|
|
|
|
|
|
|
if (!use_bfd && n->bfd_req)
|
|
|
|
{
|
|
|
|
rfree(n->bfd_req);
|
|
|
|
n->bfd_req = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-03 17:42:55 +08:00
|
|
|
static void
|
|
|
|
dbdes_timer_hook(timer *t)
|
|
|
|
{
|
|
|
|
struct ospf_neighbor *n = t->data;
|
|
|
|
struct ospf_proto *p = n->ifa->oa->po;
|
|
|
|
|
|
|
|
// OSPF_TRACE(D_EVENTS, "DBDES timer expired for nbr %R on %s", n->rid, n->ifa->ifname);
|
|
|
|
|
|
|
|
if (n->state == NEIGHBOR_EXSTART)
|
|
|
|
ospf_send_dbdes(p, n);
|
|
|
|
|
|
|
|
if ((n->state == NEIGHBOR_EXCHANGE) && (n->myimms & DBDES_MS))
|
|
|
|
ospf_rxmt_dbdes(p, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
lsrq_timer_hook(timer *t)
|
|
|
|
{
|
|
|
|
struct ospf_neighbor *n = t->data;
|
|
|
|
struct ospf_proto *p = n->ifa->oa->po;
|
|
|
|
|
|
|
|
// OSPF_TRACE(D_EVENTS, "LSRQ timer expired for nbr %R on %s", n->rid, n->ifa->ifname);
|
|
|
|
|
|
|
|
if ((n->state >= NEIGHBOR_EXCHANGE) && !EMPTY_SLIST(n->lsrql))
|
|
|
|
ospf_send_lsreq(p, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
lsrt_timer_hook(timer *t)
|
|
|
|
{
|
|
|
|
struct ospf_neighbor *n = t->data;
|
|
|
|
struct ospf_proto *p = n->ifa->oa->po;
|
|
|
|
|
|
|
|
// OSPF_TRACE(D_EVENTS, "LSRT timer expired for nbr %R on %s", n->rid, n->ifa->ifname);
|
|
|
|
|
|
|
|
if ((n->state >= NEIGHBOR_EXCHANGE) && !EMPTY_SLIST(n->lsrtl))
|
|
|
|
ospf_rxmt_lsupd(p, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ackd_timer_hook(timer *t)
|
|
|
|
{
|
|
|
|
struct ospf_neighbor *n = t->data;
|
|
|
|
struct ospf_proto *p = n->ifa->oa->po;
|
|
|
|
|
|
|
|
ospf_send_lsack(p, n, ACKL_DELAY);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-01 23:53:06 +08:00
|
|
|
void
|
|
|
|
ospf_sh_neigh_info(struct ospf_neighbor *n)
|
|
|
|
{
|
2004-06-06 17:37:54 +08:00
|
|
|
struct ospf_iface *ifa = n->ifa;
|
2014-11-03 17:42:55 +08:00
|
|
|
char *pos = "PtP ";
|
2004-06-06 17:37:54 +08:00
|
|
|
|
2014-10-24 16:27:21 +08:00
|
|
|
if ((ifa->type == OSPF_IT_BCAST) || (ifa->type == OSPF_IT_NBMA))
|
|
|
|
{
|
|
|
|
if (n->rid == ifa->drid)
|
2014-11-03 17:42:55 +08:00
|
|
|
pos = "DR ";
|
2014-10-24 16:27:21 +08:00
|
|
|
else if (n->rid == ifa->bdrid)
|
2014-11-03 17:42:55 +08:00
|
|
|
pos = "BDR ";
|
2014-10-24 16:27:21 +08:00
|
|
|
else
|
2014-11-03 17:42:55 +08:00
|
|
|
pos = "Other";
|
2014-10-24 16:27:21 +08:00
|
|
|
}
|
2004-06-06 17:37:54 +08:00
|
|
|
|
2017-06-13 22:52:21 +08:00
|
|
|
cli_msg(-1013, "%-1R\t%3u\t%s/%s\t%7t\t%-10s %-1I",
|
|
|
|
n->rid, n->priority, ospf_ns_names[n->state], pos,
|
2017-11-29 00:43:20 +08:00
|
|
|
tm_remains(n->inactim), ifa->ifname, n->ip);
|
2000-06-01 23:53:06 +08:00
|
|
|
}
|