2000-03-01 22:51:47 +08:00
|
|
|
/*
|
|
|
|
* BIRD -- Neighbor Cache
|
|
|
|
*
|
|
|
|
* (c) 1998--2000 Martin Mares <mj@ucw.cz>
|
2018-06-27 22:51:53 +08:00
|
|
|
* (c) 2008--2018 Ondrej Zajicek <santiago@crfreenet.org>
|
|
|
|
* (c) 2008--2018 CZ.NIC z.s.p.o.
|
2000-03-01 22:51:47 +08:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
2000-06-02 00:16:49 +08:00
|
|
|
/**
|
|
|
|
* DOC: Neighbor cache
|
|
|
|
*
|
|
|
|
* Most routing protocols need to associate their internal state data with
|
2018-06-27 22:51:53 +08:00
|
|
|
* neighboring routers, check whether an address given as the next hop attribute
|
|
|
|
* of a route is really an address of a directly connected host and which
|
|
|
|
* interface is it connected through. Also, they often need to be notified when
|
|
|
|
* a neighbor ceases to exist or when their long awaited neighbor becomes
|
|
|
|
* connected. The neighbor cache is there to solve all these problems.
|
2000-06-02 00:16:49 +08:00
|
|
|
*
|
2018-06-27 22:51:53 +08:00
|
|
|
* The neighbor cache maintains a collection of neighbor entries. Each entry
|
|
|
|
* represents one IP address corresponding to either our directly connected
|
|
|
|
* neighbor or our own end of the link (when the scope of the address is set to
|
|
|
|
* %SCOPE_HOST) together with per-neighbor data belonging to a single protocol.
|
|
|
|
* A neighbor entry may be bound to a specific interface, which is required for
|
|
|
|
* link-local IP addresses and optional for global IP addresses.
|
2000-06-02 00:16:49 +08:00
|
|
|
*
|
2018-06-27 22:51:53 +08:00
|
|
|
* Neighbor cache entries are stored in a hash table, which is indexed by triple
|
|
|
|
* (protocol, IP, requested-iface), so if both regular and iface-bound neighbors
|
|
|
|
* are requested, they are represented by two neighbor cache entries. Active
|
|
|
|
* entries are also linked in per-interface list (allowing quick processing of
|
|
|
|
* interface change events). Inactive entries exist only when the protocol has
|
|
|
|
* explicitly requested it via the %NEF_STICKY flag because it wishes to be
|
|
|
|
* notified when the node will again become a neighbor. Such entries are instead
|
|
|
|
* linked in a special list, which is walked whenever an interface changes its
|
|
|
|
* state to up. Neighbor entry VRF association is implied by respective
|
|
|
|
* protocol.
|
|
|
|
*
|
|
|
|
* Besides the already mentioned %NEF_STICKY flag, there is also %NEF_ONLINK,
|
|
|
|
* which specifies that neighbor should be considered reachable on given iface
|
|
|
|
* regardless of associated address ranges, and %NEF_IFACE, which represents
|
|
|
|
* pseudo-neighbor entry for whole interface (and uses %IPA_NONE IP address).
|
2000-06-02 00:16:49 +08:00
|
|
|
*
|
|
|
|
* When a neighbor event occurs (a neighbor gets disconnected or a sticky
|
2018-06-27 22:51:53 +08:00
|
|
|
* inactive neighbor becomes connected), the protocol hook neigh_notify() is
|
|
|
|
* called to advertise the change.
|
2000-06-02 00:16:49 +08:00
|
|
|
*/
|
|
|
|
|
2000-03-13 05:01:38 +08:00
|
|
|
#undef LOCAL_DEBUG
|
2000-03-01 22:51:47 +08:00
|
|
|
|
|
|
|
#include "nest/bird.h"
|
|
|
|
#include "nest/iface.h"
|
|
|
|
#include "nest/protocol.h"
|
2018-06-27 22:51:53 +08:00
|
|
|
#include "lib/hash.h"
|
2000-03-01 22:51:47 +08:00
|
|
|
#include "lib/resource.h"
|
|
|
|
|
|
|
|
#define NEIGH_HASH_SIZE 256
|
2015-12-24 22:52:03 +08:00
|
|
|
#define NEIGH_HASH_OFFSET 24
|
2000-03-01 22:51:47 +08:00
|
|
|
|
|
|
|
static slab *neigh_slab;
|
2018-06-27 22:51:53 +08:00
|
|
|
static list neigh_hash_table[NEIGH_HASH_SIZE], sticky_neigh_list;
|
2000-03-01 22:51:47 +08:00
|
|
|
|
2015-05-19 14:53:34 +08:00
|
|
|
static inline uint
|
2018-06-27 22:51:53 +08:00
|
|
|
neigh_hash(struct proto *p, ip_addr a, struct iface *i)
|
2000-03-01 22:51:47 +08:00
|
|
|
{
|
2018-06-27 22:51:53 +08:00
|
|
|
return (p->hash_key ^ ipa_hash(a) ^ ptr_hash(i)) >> NEIGH_HASH_OFFSET;
|
2000-03-01 22:51:47 +08:00
|
|
|
}
|
|
|
|
|
2000-03-27 20:16:37 +08:00
|
|
|
static int
|
2018-06-27 22:51:53 +08:00
|
|
|
if_connected(ip_addr a, struct iface *i, struct ifa **ap, uint flags)
|
2000-03-01 22:51:47 +08:00
|
|
|
{
|
|
|
|
struct ifa *b;
|
|
|
|
|
2018-06-27 22:51:53 +08:00
|
|
|
/* Handle iface pseudo-neighbors */
|
|
|
|
if (flags & NEF_IFACE)
|
|
|
|
return *ap = NULL, (i->flags & IF_UP) ? SCOPE_HOST : -1;
|
|
|
|
|
|
|
|
/* Host addresses match even if iface is down */
|
|
|
|
WALK_LIST(b, i->addrs)
|
|
|
|
if (ipa_equal(a, b->ip))
|
|
|
|
return *ap = b, SCOPE_HOST;
|
|
|
|
|
|
|
|
/* Rest do not match if iface is down */
|
2000-03-01 22:51:47 +08:00
|
|
|
if (!(i->flags & IF_UP))
|
2018-06-27 22:51:53 +08:00
|
|
|
return *ap = NULL, -1;
|
2013-12-02 18:54:32 +08:00
|
|
|
|
2018-06-27 22:51:53 +08:00
|
|
|
/* Regular neighbors */
|
2000-03-01 22:51:47 +08:00
|
|
|
WALK_LIST(b, i->addrs)
|
2018-06-27 22:51:53 +08:00
|
|
|
{
|
|
|
|
if (b->flags & IA_PEER)
|
2000-03-01 22:51:47 +08:00
|
|
|
{
|
2018-06-27 22:51:53 +08:00
|
|
|
if (ipa_equal(a, b->opposite))
|
|
|
|
return *ap = b, b->scope;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ipa_in_netX(a, &b->prefix))
|
|
|
|
{
|
|
|
|
/* Do not allow IPv4 network and broadcast addresses */
|
|
|
|
if (ipa_is_ip4(a) &&
|
|
|
|
(net_pxlen(&b->prefix) < (IP4_MAX_PREFIX_LENGTH - 1)) &&
|
|
|
|
(ipa_equal(a, net_prefix(&b->prefix)) || /* Network address */
|
|
|
|
ipa_equal(a, b->brd))) /* Broadcast */
|
|
|
|
return *ap = NULL, -1;
|
|
|
|
|
|
|
|
return *ap = b, b->scope;
|
2000-03-01 22:51:47 +08:00
|
|
|
}
|
2018-06-27 22:51:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle ONLINK flag */
|
|
|
|
if (flags & NEF_ONLINK)
|
|
|
|
return *ap = NULL, ipa_classify(a) & IADDR_SCOPE_MASK;
|
2013-12-02 18:54:32 +08:00
|
|
|
|
2018-06-27 22:51:53 +08:00
|
|
|
return *ap = NULL, -1;
|
2000-03-01 22:51:47 +08:00
|
|
|
}
|
|
|
|
|
2018-06-27 22:51:53 +08:00
|
|
|
static inline int
|
|
|
|
if_connected_any(ip_addr a, struct iface *vrf, struct iface **iface, struct ifa **addr, uint flags)
|
2009-08-28 00:25:46 +08:00
|
|
|
{
|
2018-06-27 22:51:53 +08:00
|
|
|
struct iface *i;
|
|
|
|
struct ifa *b;
|
|
|
|
int s, scope = -1;
|
|
|
|
|
|
|
|
*iface = NULL;
|
|
|
|
*addr = NULL;
|
|
|
|
|
|
|
|
/* Get first match, but prefer SCOPE_HOST to other matches */
|
|
|
|
WALK_LIST(i, iface_list)
|
|
|
|
if ((!vrf || vrf == i->master) && ((s = if_connected(a, i, &b, flags)) >= 0))
|
|
|
|
if ((scope < 0) || ((scope > SCOPE_HOST) && (s == SCOPE_HOST)))
|
|
|
|
{
|
|
|
|
*iface = i;
|
|
|
|
*addr = b;
|
|
|
|
scope = s;
|
|
|
|
}
|
2009-09-08 19:45:02 +08:00
|
|
|
|
2018-06-27 22:51:53 +08:00
|
|
|
return scope;
|
|
|
|
}
|
2009-08-28 00:25:46 +08:00
|
|
|
|
2018-06-27 22:51:53 +08:00
|
|
|
/**
|
|
|
|
* neigh_find - find or create a neighbor entry
|
|
|
|
* @p: protocol which asks for the entry
|
|
|
|
* @a: IP address of the node to be searched for
|
|
|
|
* @iface: optionally bound neighbor to this iface (may be NULL)
|
|
|
|
* @flags: %NEF_STICKY for sticky entry, %NEF_ONLINK for onlink entry
|
|
|
|
*
|
|
|
|
* Search the neighbor cache for a node with given IP address. Iface can be
|
|
|
|
* specified for link-local addresses or for cases, where neighbor is expected
|
|
|
|
* on given interface. If it is found, a pointer to the neighbor entry is
|
|
|
|
* returned. If no such entry exists and the node is directly connected on one
|
|
|
|
* of our active interfaces, a new entry is created and returned to the caller
|
|
|
|
* with protocol-dependent fields initialized to zero. If the node is not
|
|
|
|
* connected directly or *@a is not a valid unicast IP address, neigh_find()
|
|
|
|
* returns %NULL.
|
|
|
|
*/
|
2009-08-28 00:25:46 +08:00
|
|
|
neighbor *
|
2018-06-27 22:51:53 +08:00
|
|
|
neigh_find(struct proto *p, ip_addr a, struct iface *iface, uint flags)
|
2000-03-01 22:51:47 +08:00
|
|
|
{
|
|
|
|
neighbor *n;
|
2012-08-16 19:09:26 +08:00
|
|
|
int class, scope = -1;
|
2018-06-27 22:51:53 +08:00
|
|
|
uint h = neigh_hash(p, a, iface);
|
|
|
|
struct iface *ifreq = iface;
|
|
|
|
struct ifa *addr = NULL;
|
2000-03-01 22:51:47 +08:00
|
|
|
|
|
|
|
WALK_LIST(n, neigh_hash_table[h]) /* Search the cache */
|
2018-06-27 22:51:53 +08:00
|
|
|
if ((n->proto == p) && ipa_equal(n->addr, a) && (n->ifreq == iface))
|
2000-03-01 22:51:47 +08:00
|
|
|
return n;
|
|
|
|
|
2018-06-27 22:51:53 +08:00
|
|
|
if (flags & NEF_IFACE)
|
|
|
|
{
|
|
|
|
if (ipa_nonzero(a) || !iface)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
class = ipa_classify(a);
|
|
|
|
if (class < 0) /* Invalid address */
|
|
|
|
return NULL;
|
|
|
|
if (((class & IADDR_SCOPE_MASK) == SCOPE_HOST) ||
|
|
|
|
(((class & IADDR_SCOPE_MASK) == SCOPE_LINK) && !iface) ||
|
|
|
|
!(class & IADDR_HOST))
|
|
|
|
return NULL; /* Bad scope or a somecast */
|
|
|
|
}
|
2000-03-01 22:51:47 +08:00
|
|
|
|
2018-06-27 22:51:53 +08:00
|
|
|
if ((flags & NEF_ONLINK) && !iface)
|
|
|
|
return NULL;
|
2010-02-26 17:55:58 +08:00
|
|
|
|
2018-06-27 22:51:53 +08:00
|
|
|
if (iface)
|
|
|
|
{
|
|
|
|
scope = if_connected(a, iface, &addr, flags);
|
|
|
|
iface = (scope < 0) ? NULL : iface;
|
|
|
|
}
|
2009-09-08 19:45:02 +08:00
|
|
|
else
|
2018-06-27 22:51:53 +08:00
|
|
|
scope = if_connected_any(a, p->vrf, &iface, &addr, flags);
|
2009-09-08 19:45:02 +08:00
|
|
|
|
2010-02-26 17:55:58 +08:00
|
|
|
/* scope < 0 means i don't know neighbor */
|
2018-06-27 22:51:53 +08:00
|
|
|
/* scope >= 0 <=> iface != NULL */
|
2010-02-26 17:55:58 +08:00
|
|
|
|
|
|
|
if ((scope < 0) && !(flags & NEF_STICKY))
|
2000-03-01 22:51:47 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
n = sl_alloc(neigh_slab);
|
2017-02-21 21:56:14 +08:00
|
|
|
memset(n, 0, sizeof(neighbor));
|
|
|
|
|
2018-06-27 22:51:53 +08:00
|
|
|
add_tail(&neigh_hash_table[h], &n->n);
|
|
|
|
add_tail((scope >= 0) ? &iface->neighbors : &sticky_neigh_list, &n->if_n);
|
|
|
|
n->addr = a;
|
2013-12-02 18:54:32 +08:00
|
|
|
n->ifa = addr;
|
2018-06-27 22:51:53 +08:00
|
|
|
n->iface = iface;
|
|
|
|
n->ifreq = ifreq;
|
2000-03-01 22:51:47 +08:00
|
|
|
n->proto = p;
|
|
|
|
n->flags = flags;
|
2000-06-01 20:58:04 +08:00
|
|
|
n->scope = scope;
|
2017-02-21 21:56:14 +08:00
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2000-06-02 00:16:49 +08:00
|
|
|
/**
|
|
|
|
* neigh_dump - dump specified neighbor entry.
|
|
|
|
* @n: the entry to dump
|
|
|
|
*
|
2018-06-27 22:51:53 +08:00
|
|
|
* This functions dumps the contents of a given neighbor entry to debug output.
|
2000-06-02 00:16:49 +08:00
|
|
|
*/
|
2000-03-01 22:51:47 +08:00
|
|
|
void
|
|
|
|
neigh_dump(neighbor *n)
|
|
|
|
{
|
2018-06-27 22:51:53 +08:00
|
|
|
debug("%p %I %s %s ", n, n->addr,
|
|
|
|
n->iface ? n->iface->name : "[]",
|
|
|
|
n->ifreq ? n->ifreq->name : "[]");
|
2000-06-01 20:58:04 +08:00
|
|
|
debug("%s %p %08x scope %s", n->proto->name, n->data, n->aux, ip_scope_text(n->scope));
|
2000-03-01 22:51:47 +08:00
|
|
|
if (n->flags & NEF_STICKY)
|
|
|
|
debug(" STICKY");
|
2018-06-27 22:51:53 +08:00
|
|
|
if (n->flags & NEF_ONLINK)
|
|
|
|
debug(" ONLINK");
|
2000-03-01 22:51:47 +08:00
|
|
|
debug("\n");
|
|
|
|
}
|
|
|
|
|
2000-06-02 00:16:49 +08:00
|
|
|
/**
|
|
|
|
* neigh_dump_all - dump all neighbor entries.
|
|
|
|
*
|
2018-06-27 22:51:53 +08:00
|
|
|
* This function dumps the contents of the neighbor cache to debug output.
|
2000-06-02 00:16:49 +08:00
|
|
|
*/
|
2000-03-01 22:51:47 +08:00
|
|
|
void
|
|
|
|
neigh_dump_all(void)
|
|
|
|
{
|
|
|
|
neighbor *n;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
debug("Known neighbors:\n");
|
|
|
|
for(i=0; i<NEIGH_HASH_SIZE; i++)
|
2000-05-08 18:13:59 +08:00
|
|
|
WALK_LIST(n, neigh_hash_table[i])
|
|
|
|
neigh_dump(n);
|
2000-03-01 22:51:47 +08:00
|
|
|
debug("\n");
|
|
|
|
}
|
|
|
|
|
2018-06-27 22:51:53 +08:00
|
|
|
static inline void
|
|
|
|
neigh_notify(neighbor *n)
|
|
|
|
{
|
|
|
|
if (n->proto->neigh_notify && (n->proto->proto_state != PS_STOP))
|
|
|
|
n->proto->neigh_notify(n);
|
|
|
|
}
|
|
|
|
|
2011-12-12 07:24:15 +08:00
|
|
|
static void
|
2018-06-27 22:51:53 +08:00
|
|
|
neigh_up(neighbor *n, struct iface *i, struct ifa *a, int scope)
|
2011-12-12 07:24:15 +08:00
|
|
|
{
|
2017-02-21 21:56:14 +08:00
|
|
|
DBG("Waking up sticky neighbor %I\n", n->addr);
|
2011-12-12 07:24:15 +08:00
|
|
|
n->iface = i;
|
2013-12-02 18:54:32 +08:00
|
|
|
n->ifa = a;
|
2011-12-12 07:24:15 +08:00
|
|
|
n->scope = scope;
|
2017-02-21 21:56:14 +08:00
|
|
|
|
2018-06-27 22:51:53 +08:00
|
|
|
rem_node(&n->if_n);
|
|
|
|
add_tail(&i->neighbors, &n->if_n);
|
2017-02-21 21:56:14 +08:00
|
|
|
|
2018-06-27 22:51:53 +08:00
|
|
|
neigh_notify(n);
|
2011-12-12 07:24:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
neigh_down(neighbor *n)
|
|
|
|
{
|
2013-09-26 23:33:00 +08:00
|
|
|
DBG("Flushing neighbor %I on %s\n", n->addr, n->iface->name);
|
2018-06-27 22:51:53 +08:00
|
|
|
n->iface = NULL;
|
2013-12-02 18:54:32 +08:00
|
|
|
n->ifa = NULL;
|
2012-01-01 19:02:20 +08:00
|
|
|
n->scope = -1;
|
2017-02-21 21:56:14 +08:00
|
|
|
|
2018-06-27 22:51:53 +08:00
|
|
|
rem_node(&n->if_n);
|
|
|
|
add_tail(&sticky_neigh_list, &n->if_n);
|
2017-02-21 21:56:14 +08:00
|
|
|
|
2018-06-27 22:51:53 +08:00
|
|
|
neigh_notify(n);
|
|
|
|
}
|
2017-02-21 21:56:14 +08:00
|
|
|
|
2018-06-27 22:51:53 +08:00
|
|
|
static inline void
|
|
|
|
neigh_free(neighbor *n)
|
|
|
|
{
|
|
|
|
rem_node(&n->n);
|
|
|
|
rem_node(&n->if_n);
|
|
|
|
sl_free(neigh_slab, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* neigh_update: update neighbor entry w.r.t. change on specific iface
|
|
|
|
* @n: neighbor to update
|
|
|
|
* @iface: changed iface
|
|
|
|
*
|
|
|
|
* The function recalculates state of the neighbor entry @n assuming that only
|
|
|
|
* the interface @iface may changed its state or addresses. Then, appropriate
|
|
|
|
* actions are executed (the neighbor goes up, down, up-down, or just notified).
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
neigh_update(neighbor *n, struct iface *iface)
|
|
|
|
{
|
|
|
|
struct ifa *ifa = NULL;
|
|
|
|
int scope = -1;
|
|
|
|
|
|
|
|
/* Iface-bound neighbors ignore other ifaces */
|
|
|
|
if (n->ifreq && (n->ifreq != iface))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* VRF-bound neighbors ignore changes in other VRFs */
|
|
|
|
if (n->proto->vrf && (n->proto->vrf != iface->master))
|
|
|
|
return;
|
|
|
|
|
|
|
|
scope = if_connected(n->addr, iface, &ifa, n->flags);
|
|
|
|
|
|
|
|
/* When neighbor is going down, try to respawn it on other ifaces */
|
|
|
|
if ((scope < 0) && (n->scope >= 0) && !n->ifreq && (n->flags & NEF_STICKY))
|
|
|
|
scope = if_connected_any(n->addr, n->proto->vrf, &iface, &ifa, n->flags);
|
|
|
|
|
|
|
|
/* No change or minor change - ignore or notify */
|
|
|
|
if ((scope == n->scope) && (iface == n->iface))
|
|
|
|
{
|
|
|
|
if (ifa != n->ifa)
|
2012-08-16 19:09:26 +08:00
|
|
|
{
|
2018-06-27 22:51:53 +08:00
|
|
|
n->ifa = ifa;
|
|
|
|
neigh_notify(n);
|
2012-08-16 19:09:26 +08:00
|
|
|
}
|
2017-02-21 21:56:14 +08:00
|
|
|
|
2018-06-27 22:51:53 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Major change - going down and/or going up */
|
|
|
|
|
|
|
|
if (n->scope >= 0)
|
|
|
|
neigh_down(n);
|
|
|
|
|
|
|
|
if ((n->scope < 0) && !(n->flags & NEF_STICKY))
|
|
|
|
{
|
|
|
|
neigh_free(n);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scope >= 0)
|
|
|
|
neigh_up(n, iface, ifa, scope);
|
2011-12-12 07:24:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-02 00:16:49 +08:00
|
|
|
/**
|
|
|
|
* neigh_if_up: notify neighbor cache about interface up event
|
|
|
|
* @i: interface in question
|
|
|
|
*
|
|
|
|
* Tell the neighbor cache that a new interface became up.
|
|
|
|
*
|
|
|
|
* The neighbor cache wakes up all inactive sticky neighbors with
|
|
|
|
* addresses belonging to prefixes of the interface @i.
|
|
|
|
*/
|
2000-03-01 22:51:47 +08:00
|
|
|
void
|
|
|
|
neigh_if_up(struct iface *i)
|
|
|
|
{
|
2017-02-21 21:56:14 +08:00
|
|
|
neighbor *n;
|
|
|
|
node *x, *y;
|
2000-03-01 22:51:47 +08:00
|
|
|
|
2018-06-27 22:51:53 +08:00
|
|
|
WALK_LIST2_DELSAFE(n, x, y, sticky_neigh_list, if_n)
|
|
|
|
neigh_update(n, i);
|
2000-03-01 22:51:47 +08:00
|
|
|
}
|
|
|
|
|
2000-06-02 00:16:49 +08:00
|
|
|
/**
|
|
|
|
* neigh_if_down - notify neighbor cache about interface down event
|
|
|
|
* @i: the interface in question
|
|
|
|
*
|
|
|
|
* Notify the neighbor cache that an interface has ceased to exist.
|
|
|
|
*
|
2018-06-27 22:51:53 +08:00
|
|
|
* It causes all neighbors connected to this interface to be updated or removed.
|
2000-06-02 00:16:49 +08:00
|
|
|
*/
|
2000-03-01 22:51:47 +08:00
|
|
|
void
|
|
|
|
neigh_if_down(struct iface *i)
|
|
|
|
{
|
2017-02-21 21:56:14 +08:00
|
|
|
neighbor *n;
|
2000-03-01 22:51:47 +08:00
|
|
|
node *x, *y;
|
|
|
|
|
2017-02-21 21:56:14 +08:00
|
|
|
WALK_LIST2_DELSAFE(n, x, y, i->neighbors, if_n)
|
2018-06-27 22:51:53 +08:00
|
|
|
neigh_update(n, i);
|
2000-03-01 22:51:47 +08:00
|
|
|
}
|
|
|
|
|
2010-11-11 19:24:27 +08:00
|
|
|
/**
|
|
|
|
* neigh_if_link - notify neighbor cache about interface link change
|
|
|
|
* @i: the interface in question
|
|
|
|
*
|
2018-06-27 22:51:53 +08:00
|
|
|
* Notify the neighbor cache that an interface changed link state. All owners of
|
|
|
|
* neighbor entries connected to this interface are notified.
|
2010-11-11 19:24:27 +08:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
neigh_if_link(struct iface *i)
|
|
|
|
{
|
2017-02-21 21:56:14 +08:00
|
|
|
neighbor *n;
|
2010-11-11 19:24:27 +08:00
|
|
|
node *x, *y;
|
|
|
|
|
2017-02-21 21:56:14 +08:00
|
|
|
WALK_LIST2_DELSAFE(n, x, y, i->neighbors, if_n)
|
2018-06-27 22:51:53 +08:00
|
|
|
neigh_notify(n);
|
2010-11-11 19:24:27 +08:00
|
|
|
}
|
|
|
|
|
2011-12-12 07:24:15 +08:00
|
|
|
/**
|
|
|
|
* neigh_ifa_update: notify neighbor cache about interface address add or remove event
|
2016-05-12 21:49:44 +08:00
|
|
|
* @a: interface address in question
|
2011-12-12 07:24:15 +08:00
|
|
|
*
|
|
|
|
* Tell the neighbor cache that an address was added or removed.
|
|
|
|
*
|
|
|
|
* The neighbor cache wakes up all inactive sticky neighbors with
|
|
|
|
* addresses belonging to prefixes of the interface belonging to @ifa
|
|
|
|
* and causes all unreachable neighbors to be flushed.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
neigh_ifa_update(struct ifa *a)
|
|
|
|
{
|
|
|
|
struct iface *i = a->iface;
|
2017-02-21 21:56:14 +08:00
|
|
|
neighbor *n;
|
2018-06-27 22:51:53 +08:00
|
|
|
node *x, *y;
|
2017-02-21 21:56:14 +08:00
|
|
|
|
2018-06-27 22:51:53 +08:00
|
|
|
/* Update all neighbors whose scope has changed */
|
2017-02-21 21:56:14 +08:00
|
|
|
WALK_LIST2_DELSAFE(n, x, y, i->neighbors, if_n)
|
2018-06-27 22:51:53 +08:00
|
|
|
neigh_update(n, i);
|
2011-12-12 07:24:15 +08:00
|
|
|
|
|
|
|
/* Wake up all sticky neighbors that are reachable now */
|
2018-06-27 22:51:53 +08:00
|
|
|
WALK_LIST2_DELSAFE(n, x, y, sticky_neigh_list, if_n)
|
|
|
|
neigh_update(n, i);
|
2011-12-12 07:24:15 +08:00
|
|
|
}
|
|
|
|
|
2000-05-08 18:13:59 +08:00
|
|
|
static inline void
|
|
|
|
neigh_prune_one(neighbor *n)
|
|
|
|
{
|
2008-12-08 19:24:55 +08:00
|
|
|
if (n->proto->proto_state != PS_DOWN)
|
2000-05-08 18:13:59 +08:00
|
|
|
return;
|
2018-06-27 22:51:53 +08:00
|
|
|
|
|
|
|
neigh_free(n);
|
2000-05-08 18:13:59 +08:00
|
|
|
}
|
|
|
|
|
2000-06-02 00:16:49 +08:00
|
|
|
/**
|
|
|
|
* neigh_prune - prune neighbor cache
|
|
|
|
*
|
|
|
|
* neigh_prune() examines all neighbor entries cached and removes those
|
|
|
|
* corresponding to inactive protocols. It's called whenever a protocol
|
|
|
|
* is shut down to get rid of all its heritage.
|
|
|
|
*/
|
2000-03-01 22:51:47 +08:00
|
|
|
void
|
|
|
|
neigh_prune(void)
|
|
|
|
{
|
|
|
|
neighbor *n;
|
|
|
|
node *m;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
DBG("Pruning neighbors\n");
|
|
|
|
for(i=0; i<NEIGH_HASH_SIZE; i++)
|
|
|
|
WALK_LIST_DELSAFE(n, m, neigh_hash_table[i])
|
2000-05-08 18:13:59 +08:00
|
|
|
neigh_prune_one(n);
|
2000-03-01 22:51:47 +08:00
|
|
|
}
|
|
|
|
|
2000-06-02 00:16:49 +08:00
|
|
|
/**
|
|
|
|
* neigh_init - initialize the neighbor cache.
|
|
|
|
* @if_pool: resource pool to be used for neighbor entries.
|
|
|
|
*
|
|
|
|
* This function is called during BIRD startup to initialize
|
|
|
|
* the neighbor cache module.
|
|
|
|
*/
|
2000-03-01 22:51:47 +08:00
|
|
|
void
|
|
|
|
neigh_init(pool *if_pool)
|
|
|
|
{
|
|
|
|
neigh_slab = sl_new(if_pool, sizeof(neighbor));
|
2017-02-21 21:56:14 +08:00
|
|
|
|
|
|
|
for(int i = 0; i < NEIGH_HASH_SIZE; i++)
|
2000-03-01 22:51:47 +08:00
|
|
|
init_list(&neigh_hash_table[i]);
|
2018-06-27 22:51:53 +08:00
|
|
|
|
|
|
|
init_list(&sticky_neigh_list);
|
2000-03-01 22:51:47 +08:00
|
|
|
}
|