2016-04-29 00:01:40 +08:00
|
|
|
/*
|
|
|
|
* BIRD -- The Babel protocol
|
|
|
|
*
|
|
|
|
* Copyright (c) 2015--2016 Toke Hoiland-Jorgensen
|
2017-11-28 22:11:41 +08:00
|
|
|
* (c) 2016--2017 Ondrej Zajicek <santiago@crfreenet.org>
|
|
|
|
* (c) 2016--2017 CZ.NIC z.s.p.o.
|
2016-04-29 00:01:40 +08:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*
|
|
|
|
* This file contains the main routines for handling and sending TLVs, as
|
|
|
|
* well as timers and interaction with the nest.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DOC: The Babel protocol
|
|
|
|
*
|
|
|
|
* Babel (RFC6126) is a loop-avoiding distance-vector routing protocol that is
|
|
|
|
* robust and efficient both in ordinary wired networks and in wireless mesh
|
|
|
|
* networks.
|
|
|
|
*
|
|
|
|
* The Babel protocol keeps state for each neighbour in a &babel_neighbor
|
|
|
|
* struct, tracking received Hello and I Heard You (IHU) messages. A
|
|
|
|
* &babel_interface struct keeps hello and update times for each interface, and
|
|
|
|
* a separate hello seqno is maintained for each interface.
|
|
|
|
*
|
|
|
|
* For each prefix, Babel keeps track of both the possible routes (with next hop
|
|
|
|
* and router IDs), as well as the feasibility distance for each prefix and
|
|
|
|
* router id. The prefix itself is tracked in a &babel_entry struct, while the
|
|
|
|
* possible routes for the prefix are tracked as &babel_route entries and the
|
|
|
|
* feasibility distance is maintained through &babel_source structures.
|
|
|
|
*
|
|
|
|
* The main route selection is done in babel_select_route(). This is called when
|
|
|
|
* an entry is updated by receiving updates from the network or when modified by
|
2017-11-28 22:11:41 +08:00
|
|
|
* internal timers. The function selects from feasible and reachable routes the
|
|
|
|
* one with the lowest metric to be announced to the core.
|
2016-04-29 00:01:40 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "babel.h"
|
|
|
|
|
2021-04-17 21:04:16 +08:00
|
|
|
#define LOG_PKT_AUTH(msg, args...) \
|
|
|
|
log_rl(&p->log_pkt_tbf, L_AUTH "%s: " msg, p->p.name, args)
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Is one number greater or equal than another mod 2^16? This is based on the
|
|
|
|
* definition of serial number space in RFC 1982. Note that arguments are of
|
|
|
|
* uint type to avoid integer promotion to signed integer.
|
|
|
|
*/
|
|
|
|
static inline int ge_mod64k(uint a, uint b)
|
|
|
|
{ return (u16)(a - b) < 0x8000; }
|
|
|
|
|
2017-11-08 21:35:52 +08:00
|
|
|
static void babel_expire_requests(struct babel_proto *p, struct babel_entry *e);
|
2017-11-28 22:11:41 +08:00
|
|
|
static void babel_select_route(struct babel_proto *p, struct babel_entry *e, struct babel_route *mod);
|
|
|
|
static inline void babel_announce_retraction(struct babel_proto *p, struct babel_entry *e);
|
2017-10-27 18:20:58 +08:00
|
|
|
static void babel_send_route_request(struct babel_proto *p, struct babel_entry *e, struct babel_neighbor *n);
|
2017-11-08 21:35:52 +08:00
|
|
|
static void babel_send_seqno_request(struct babel_proto *p, struct babel_entry *e, struct babel_seqno_request *sr);
|
2017-10-25 23:14:08 +08:00
|
|
|
static void babel_update_cost(struct babel_neighbor *n);
|
2016-04-29 00:01:40 +08:00
|
|
|
static inline void babel_kick_timer(struct babel_proto *p);
|
|
|
|
static inline void babel_iface_kick_timer(struct babel_iface *ifa);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Functions to maintain data structures
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2021-11-30 02:23:42 +08:00
|
|
|
babel_init_entry(struct fib *f UNUSED, void *E)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
2016-12-10 07:11:26 +08:00
|
|
|
struct babel_entry *e = E;
|
|
|
|
|
2017-10-13 18:34:08 +08:00
|
|
|
e->updated = current_time();
|
2017-11-08 21:35:52 +08:00
|
|
|
init_list(&e->requests);
|
2016-04-29 00:01:40 +08:00
|
|
|
init_list(&e->sources);
|
|
|
|
init_list(&e->routes);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct babel_entry *
|
2016-12-10 07:11:26 +08:00
|
|
|
babel_find_entry(struct babel_proto *p, const net_addr *n)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
2017-06-08 18:18:16 +08:00
|
|
|
struct fib *rtable = (n->type == NET_IP4) ? &p->ip4_rtable : &p->ip6_rtable;
|
|
|
|
return fib_find(rtable, n);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct babel_entry *
|
2016-12-10 07:11:26 +08:00
|
|
|
babel_get_entry(struct babel_proto *p, const net_addr *n)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
2017-06-08 18:18:16 +08:00
|
|
|
struct fib *rtable = (n->type == NET_IP4) ? &p->ip4_rtable : &p->ip6_rtable;
|
|
|
|
struct babel_entry *e = fib_get(rtable, n);
|
2016-04-29 00:01:40 +08:00
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct babel_source *
|
|
|
|
babel_find_source(struct babel_entry *e, u64 router_id)
|
|
|
|
{
|
|
|
|
struct babel_source *s;
|
|
|
|
|
|
|
|
WALK_LIST(s, e->sources)
|
|
|
|
if (s->router_id == router_id)
|
|
|
|
return s;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct babel_source *
|
2017-10-27 18:20:58 +08:00
|
|
|
babel_get_source(struct babel_proto *p, struct babel_entry *e, u64 router_id)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
|
|
|
struct babel_source *s = babel_find_source(e, router_id);
|
|
|
|
|
|
|
|
if (s)
|
|
|
|
return s;
|
|
|
|
|
2020-11-24 09:32:13 +08:00
|
|
|
s = sl_allocz(p->source_slab);
|
2016-04-29 00:01:40 +08:00
|
|
|
s->router_id = router_id;
|
2017-10-13 18:34:08 +08:00
|
|
|
s->expires = current_time() + BABEL_GARBAGE_INTERVAL;
|
2016-04-29 00:01:40 +08:00
|
|
|
s->seqno = 0;
|
|
|
|
s->metric = BABEL_INFINITY;
|
|
|
|
add_tail(&e->sources, NODE s);
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-10-27 18:20:58 +08:00
|
|
|
babel_expire_sources(struct babel_proto *p, struct babel_entry *e)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
|
|
|
struct babel_source *n, *nx;
|
2017-10-13 18:34:08 +08:00
|
|
|
btime now_ = current_time();
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
WALK_LIST_DELSAFE(n, nx, e->sources)
|
|
|
|
{
|
2017-10-13 18:34:08 +08:00
|
|
|
if (n->expires && n->expires <= now_)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
|
|
|
rem_node(NODE n);
|
|
|
|
sl_free(p->source_slab, n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-21 06:57:23 +08:00
|
|
|
static u16
|
|
|
|
babel_calc_smoothed_metric(struct babel_proto *p, struct babel_route *r, u8 update)
|
|
|
|
{
|
|
|
|
struct babel_config *cf = (void *) p->p.cf;
|
|
|
|
uint metric = r->metric, smoothed_metric = r->smoothed_metric;
|
|
|
|
btime smoothed_time = r->smoothed_time, now = current_time();
|
|
|
|
|
|
|
|
if (!cf->metric_decay || metric == BABEL_INFINITY ||
|
|
|
|
metric == smoothed_metric || !smoothed_time)
|
|
|
|
{
|
|
|
|
smoothed_metric = metric;
|
|
|
|
smoothed_time = now;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
int diff = metric - smoothed_metric;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The decay defines the half-life of the metric convergence, so first iterate
|
|
|
|
* in halving steps
|
|
|
|
*/
|
|
|
|
while (smoothed_time < now - cf->metric_decay && diff) {
|
|
|
|
smoothed_metric += diff/2;
|
|
|
|
smoothed_time += cf->metric_decay;
|
|
|
|
diff = metric - smoothed_metric;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Then, update remainder in BABEL_SMOOTHING_STEP intervals using the
|
|
|
|
* exponential function (approximated via the pre-computed reciprocal).
|
|
|
|
*/
|
|
|
|
while (smoothed_time < now - BABEL_SMOOTHING_STEP && diff) {
|
|
|
|
smoothed_metric += (BABEL_SMOOTHING_STEP * diff *
|
|
|
|
(cf->smooth_recp - BABEL_SMOOTHING_UNIT) / BABEL_SMOOTHING_UNIT);
|
|
|
|
smoothed_time += BABEL_SMOOTHING_STEP;
|
|
|
|
diff = metric - smoothed_metric;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Consider the metric converged once we're close enough */
|
|
|
|
if (ABS(diff) < BABEL_SMOOTHING_MIN_DIFF)
|
|
|
|
smoothed_metric = metric;
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (update) {
|
|
|
|
r->smoothed_metric = smoothed_metric;
|
|
|
|
r->smoothed_time = smoothed_time;
|
|
|
|
}
|
|
|
|
|
|
|
|
return smoothed_metric;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u16
|
|
|
|
babel_update_smoothed_metric(struct babel_proto *p, struct babel_route *r)
|
|
|
|
{
|
|
|
|
if (!r->metric)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!r->smoothed_metric) {
|
|
|
|
r->smoothed_metric = r->metric;
|
|
|
|
r->smoothed_time = current_time();
|
|
|
|
return r->smoothed_metric;
|
|
|
|
}
|
|
|
|
|
|
|
|
u16 smoothed = babel_calc_smoothed_metric(p, r, 1);
|
|
|
|
DBG("Updated smoothed metric for prefix %N: router-id %lR metric %d/%d\n",
|
|
|
|
r->e->n.addr, r->router_id, r->metric, smoothed);
|
|
|
|
|
|
|
|
return smoothed;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u16
|
|
|
|
babel_smoothed_metric(struct babel_proto *p, struct babel_route *r)
|
|
|
|
{
|
|
|
|
return babel_calc_smoothed_metric(p, r, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
babel_update_metric(struct babel_proto *p, struct babel_route *r, u16 metric)
|
|
|
|
{
|
|
|
|
babel_update_smoothed_metric(p, r);
|
|
|
|
r->metric = metric;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u8
|
|
|
|
babel_route_better(struct babel_proto *p, struct babel_route *mod,
|
|
|
|
struct babel_route *best)
|
|
|
|
{
|
|
|
|
if (!mod->feasible)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!best)
|
|
|
|
return mod->metric < BABEL_INFINITY;
|
|
|
|
|
|
|
|
return (mod->metric < best->metric &&
|
|
|
|
babel_smoothed_metric(p, mod) < babel_smoothed_metric(p, best));
|
|
|
|
}
|
|
|
|
|
2016-04-29 00:01:40 +08:00
|
|
|
static struct babel_route *
|
|
|
|
babel_find_route(struct babel_entry *e, struct babel_neighbor *n)
|
|
|
|
{
|
|
|
|
struct babel_route *r;
|
|
|
|
|
|
|
|
WALK_LIST(r, e->routes)
|
|
|
|
if (r->neigh == n)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct babel_route *
|
2017-10-27 18:20:58 +08:00
|
|
|
babel_get_route(struct babel_proto *p, struct babel_entry *e, struct babel_neighbor *nbr)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
|
|
|
struct babel_route *r = babel_find_route(e, nbr);
|
|
|
|
|
2022-04-21 06:57:23 +08:00
|
|
|
if (r) {
|
|
|
|
babel_update_smoothed_metric(p, r);
|
2016-04-29 00:01:40 +08:00
|
|
|
return r;
|
2022-04-21 06:57:23 +08:00
|
|
|
}
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2020-11-24 09:32:13 +08:00
|
|
|
r = sl_allocz(p->route_slab);
|
2017-11-28 22:11:41 +08:00
|
|
|
|
2016-04-29 00:01:40 +08:00
|
|
|
r->e = e;
|
2017-11-28 22:11:41 +08:00
|
|
|
r->neigh = nbr;
|
2016-04-29 00:01:40 +08:00
|
|
|
add_tail(&e->routes, NODE r);
|
2017-11-28 22:11:41 +08:00
|
|
|
add_tail(&nbr->routes, NODE &r->neigh_route);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2017-11-28 22:11:41 +08:00
|
|
|
static inline void
|
|
|
|
babel_retract_route(struct babel_proto *p, struct babel_route *r)
|
|
|
|
{
|
|
|
|
r->metric = r->advert_metric = BABEL_INFINITY;
|
|
|
|
|
|
|
|
if (r == r->e->selected)
|
|
|
|
babel_select_route(p, r->e, r);
|
|
|
|
}
|
|
|
|
|
2016-04-29 00:01:40 +08:00
|
|
|
static void
|
2017-10-27 18:20:58 +08:00
|
|
|
babel_flush_route(struct babel_proto *p, struct babel_route *r)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
2016-12-10 07:11:26 +08:00
|
|
|
DBG("Babel: Flush route %N router_id %lR neigh %I\n",
|
2017-11-28 22:11:41 +08:00
|
|
|
r->e->n.addr, r->router_id, r->neigh->addr);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
rem_node(NODE r);
|
2017-11-28 22:11:41 +08:00
|
|
|
rem_node(&r->neigh_route);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2017-11-28 22:11:41 +08:00
|
|
|
if (r->e->selected == r)
|
|
|
|
r->e->selected = NULL;
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
sl_free(p->route_slab, r);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-10-27 18:20:58 +08:00
|
|
|
babel_expire_route(struct babel_proto *p, struct babel_route *r)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
2017-11-28 22:11:41 +08:00
|
|
|
struct babel_config *cf = (void *) p->p.cf;
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2016-12-10 07:11:26 +08:00
|
|
|
TRACE(D_EVENTS, "Route expiry timer for %N router-id %lR fired",
|
2017-11-28 22:11:41 +08:00
|
|
|
r->e->n.addr, r->router_id);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
if (r->metric < BABEL_INFINITY)
|
|
|
|
{
|
2017-10-25 23:14:08 +08:00
|
|
|
r->metric = r->advert_metric = BABEL_INFINITY;
|
2017-11-28 22:11:41 +08:00
|
|
|
r->expires = current_time() + cf->hold_time;
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-27 18:20:58 +08:00
|
|
|
babel_flush_route(p, r);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-10-27 18:20:58 +08:00
|
|
|
babel_refresh_route(struct babel_proto *p, struct babel_route *r)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
2017-11-28 22:11:41 +08:00
|
|
|
if (r == r->e->selected)
|
2017-10-27 18:20:58 +08:00
|
|
|
babel_send_route_request(p, r->e, r->neigh);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
r->refresh_time = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-10-27 18:20:58 +08:00
|
|
|
babel_expire_routes_(struct babel_proto *p, struct fib *rtable)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
2017-11-28 22:11:41 +08:00
|
|
|
struct babel_config *cf = (void *) p->p.cf;
|
2016-04-29 00:01:40 +08:00
|
|
|
struct babel_route *r, *rx;
|
|
|
|
struct fib_iterator fit;
|
2017-10-13 18:34:08 +08:00
|
|
|
btime now_ = current_time();
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2017-06-08 18:18:16 +08:00
|
|
|
FIB_ITERATE_INIT(&fit, rtable);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
loop:
|
2017-06-08 18:18:16 +08:00
|
|
|
FIB_ITERATE_START(rtable, &fit, struct babel_entry, e)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
|
|
|
int changed = 0;
|
|
|
|
|
|
|
|
WALK_LIST_DELSAFE(r, rx, e->routes)
|
|
|
|
{
|
2017-10-13 18:34:08 +08:00
|
|
|
if (r->refresh_time && r->refresh_time <= now_)
|
2017-10-27 18:20:58 +08:00
|
|
|
babel_refresh_route(p, r);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2017-10-13 18:34:08 +08:00
|
|
|
if (r->expires && r->expires <= now_)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
2017-11-28 22:11:41 +08:00
|
|
|
changed = changed || (r == e->selected);
|
2017-10-27 18:20:58 +08:00
|
|
|
babel_expire_route(p, r);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changed)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We have to restart the iteration because there may be a cascade of
|
|
|
|
* synchronous events babel_select_route() -> nest table change ->
|
2017-06-08 18:18:16 +08:00
|
|
|
* babel_rt_notify() -> rtable change, invalidating hidden variables.
|
2016-04-29 00:01:40 +08:00
|
|
|
*/
|
2017-11-28 22:11:41 +08:00
|
|
|
FIB_ITERATE_PUT(&fit);
|
|
|
|
babel_select_route(p, e, NULL);
|
|
|
|
goto loop;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clean up stale entries */
|
|
|
|
if ((e->valid == BABEL_ENTRY_STALE) && ((e->updated + cf->hold_time) <= now_))
|
|
|
|
e->valid = BABEL_ENTRY_DUMMY;
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2017-11-28 22:11:41 +08:00
|
|
|
/* Clean up unreachable route */
|
|
|
|
if (e->unreachable && (!e->valid || (e->router_id == p->router_id)))
|
|
|
|
{
|
2016-12-10 07:11:26 +08:00
|
|
|
FIB_ITERATE_PUT(&fit);
|
2017-11-28 22:11:41 +08:00
|
|
|
babel_announce_retraction(p, e);
|
2016-04-29 00:01:40 +08:00
|
|
|
goto loop;
|
|
|
|
}
|
|
|
|
|
2017-10-27 18:20:58 +08:00
|
|
|
babel_expire_sources(p, e);
|
2017-11-08 21:35:52 +08:00
|
|
|
babel_expire_requests(p, e);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
/* Remove empty entries */
|
2017-11-28 22:11:41 +08:00
|
|
|
if (!e->valid && EMPTY_LIST(e->routes) && EMPTY_LIST(e->sources) && EMPTY_LIST(e->requests))
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
2016-12-10 07:11:26 +08:00
|
|
|
FIB_ITERATE_PUT(&fit);
|
2017-06-08 18:18:16 +08:00
|
|
|
fib_delete(rtable, e);
|
2016-04-29 00:01:40 +08:00
|
|
|
goto loop;
|
|
|
|
}
|
|
|
|
}
|
2016-12-10 07:11:26 +08:00
|
|
|
FIB_ITERATE_END;
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
|
2017-06-08 18:18:16 +08:00
|
|
|
static void
|
|
|
|
babel_expire_routes(struct babel_proto *p)
|
|
|
|
{
|
|
|
|
babel_expire_routes_(p, &p->ip4_rtable);
|
|
|
|
babel_expire_routes_(p, &p->ip6_rtable);
|
|
|
|
}
|
|
|
|
|
2017-11-08 21:35:52 +08:00
|
|
|
static inline int seqno_request_valid(struct babel_seqno_request *sr)
|
|
|
|
{ return !sr->nbr || sr->nbr->ifa; }
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add seqno request to the table of pending requests (RFC 6216 3.2.6) and send
|
|
|
|
* it to network. Do nothing if it is already in the table.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
babel_add_seqno_request(struct babel_proto *p, struct babel_entry *e,
|
|
|
|
u64 router_id, u16 seqno, u8 hop_count,
|
|
|
|
struct babel_neighbor *nbr)
|
|
|
|
{
|
|
|
|
struct babel_seqno_request *sr;
|
|
|
|
|
|
|
|
WALK_LIST(sr, e->requests)
|
2022-05-12 19:50:18 +08:00
|
|
|
if (sr->router_id == router_id && sr->nbr == nbr)
|
2017-11-08 21:35:52 +08:00
|
|
|
{
|
|
|
|
/* Found matching or newer */
|
|
|
|
if (ge_mod64k(sr->seqno, seqno) && seqno_request_valid(sr))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Found older */
|
|
|
|
rem_node(NODE sr);
|
2022-05-12 19:50:18 +08:00
|
|
|
if (sr->nbr)
|
|
|
|
rem_node(&sr->nbr_node);
|
2021-05-30 19:07:16 +08:00
|
|
|
|
2017-11-08 21:35:52 +08:00
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No entries found */
|
2020-11-24 09:32:13 +08:00
|
|
|
sr = sl_allocz(p->seqno_slab);
|
2017-11-08 21:35:52 +08:00
|
|
|
|
|
|
|
found:
|
|
|
|
sr->router_id = router_id;
|
|
|
|
sr->seqno = seqno;
|
|
|
|
sr->hop_count = hop_count;
|
|
|
|
sr->count = 0;
|
|
|
|
sr->expires = current_time() + BABEL_SEQNO_REQUEST_EXPIRY;
|
2021-05-30 19:07:16 +08:00
|
|
|
|
|
|
|
if (sr->nbr = nbr)
|
|
|
|
add_tail(&nbr->requests, &sr->nbr_node);
|
|
|
|
|
2017-11-08 21:35:52 +08:00
|
|
|
add_tail(&e->requests, NODE sr);
|
|
|
|
|
|
|
|
babel_send_seqno_request(p, e, sr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
babel_remove_seqno_request(struct babel_proto *p, struct babel_seqno_request *sr)
|
|
|
|
{
|
2021-05-30 19:07:16 +08:00
|
|
|
if (sr->nbr)
|
|
|
|
rem_node(&sr->nbr_node);
|
|
|
|
|
2017-11-08 21:35:52 +08:00
|
|
|
rem_node(NODE sr);
|
|
|
|
sl_free(p->seqno_slab, sr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
babel_satisfy_seqno_request(struct babel_proto *p, struct babel_entry *e,
|
|
|
|
u64 router_id, u16 seqno)
|
|
|
|
{
|
2022-05-12 19:50:18 +08:00
|
|
|
struct babel_seqno_request *sr, *srx;
|
|
|
|
int ret = 0;
|
2017-11-08 21:35:52 +08:00
|
|
|
|
2022-05-12 19:50:18 +08:00
|
|
|
WALK_LIST_DELSAFE(sr, srx, e->requests)
|
2017-11-08 21:35:52 +08:00
|
|
|
if ((sr->router_id == router_id) && ge_mod64k(seqno, sr->seqno))
|
|
|
|
{
|
2022-05-12 19:50:18 +08:00
|
|
|
/* Found a matching request, remove it; there may be multiple outstanding
|
|
|
|
* requests, so continue looping
|
|
|
|
*/
|
2017-11-08 21:35:52 +08:00
|
|
|
babel_remove_seqno_request(p, sr);
|
2022-05-12 19:50:18 +08:00
|
|
|
ret = 1;
|
2017-11-08 21:35:52 +08:00
|
|
|
}
|
|
|
|
|
2022-05-12 19:50:18 +08:00
|
|
|
return ret;
|
2017-11-08 21:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
babel_expire_requests(struct babel_proto *p, struct babel_entry *e)
|
|
|
|
{
|
|
|
|
struct babel_seqno_request *sr, *srx;
|
|
|
|
btime now_ = current_time();
|
|
|
|
|
|
|
|
WALK_LIST_DELSAFE(sr, srx, e->requests)
|
|
|
|
{
|
|
|
|
/* Remove seqno requests sent to dead neighbors */
|
|
|
|
if (!seqno_request_valid(sr))
|
|
|
|
{
|
|
|
|
babel_remove_seqno_request(p, sr);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle expired requests - resend or remove */
|
|
|
|
if (sr->expires && sr->expires <= now_)
|
|
|
|
{
|
|
|
|
if (sr->count < BABEL_SEQNO_REQUEST_RETRY)
|
|
|
|
{
|
|
|
|
sr->count++;
|
|
|
|
sr->expires += (BABEL_SEQNO_REQUEST_EXPIRY << sr->count);
|
|
|
|
babel_send_seqno_request(p, e, sr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE(D_EVENTS, "Seqno request for %N router-id %lR expired",
|
|
|
|
e->n.addr, sr->router_id);
|
|
|
|
|
|
|
|
babel_remove_seqno_request(p, sr);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-29 00:01:40 +08:00
|
|
|
static struct babel_neighbor *
|
|
|
|
babel_find_neighbor(struct babel_iface *ifa, ip_addr addr)
|
|
|
|
{
|
|
|
|
struct babel_neighbor *nbr;
|
|
|
|
|
|
|
|
WALK_LIST(nbr, ifa->neigh_list)
|
|
|
|
if (ipa_equal(nbr->addr, addr))
|
|
|
|
return nbr;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct babel_neighbor *
|
|
|
|
babel_get_neighbor(struct babel_iface *ifa, ip_addr addr)
|
|
|
|
{
|
2017-10-25 23:14:08 +08:00
|
|
|
struct babel_proto *p = ifa->proto;
|
2016-04-29 00:01:40 +08:00
|
|
|
struct babel_neighbor *nbr = babel_find_neighbor(ifa, addr);
|
|
|
|
|
|
|
|
if (nbr)
|
|
|
|
return nbr;
|
|
|
|
|
2017-10-25 23:14:08 +08:00
|
|
|
TRACE(D_EVENTS, "New neighbor %I on %s", addr, ifa->iface->name);
|
|
|
|
|
2016-04-29 00:01:40 +08:00
|
|
|
nbr = mb_allocz(ifa->pool, sizeof(struct babel_neighbor));
|
|
|
|
nbr->ifa = ifa;
|
|
|
|
nbr->addr = addr;
|
2017-10-25 23:14:08 +08:00
|
|
|
nbr->rxcost = BABEL_INFINITY;
|
2016-04-29 00:01:40 +08:00
|
|
|
nbr->txcost = BABEL_INFINITY;
|
2017-10-25 23:14:08 +08:00
|
|
|
nbr->cost = BABEL_INFINITY;
|
2021-06-10 01:31:55 +08:00
|
|
|
nbr->init_expiry = current_time() + BABEL_INITIAL_NEIGHBOR_TIMEOUT;
|
2016-04-29 00:01:40 +08:00
|
|
|
init_list(&nbr->routes);
|
2021-05-30 19:07:16 +08:00
|
|
|
init_list(&nbr->requests);
|
2016-04-29 00:01:40 +08:00
|
|
|
add_tail(&ifa->neigh_list, NODE nbr);
|
|
|
|
|
|
|
|
return nbr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-10-25 23:14:08 +08:00
|
|
|
babel_flush_neighbor(struct babel_proto *p, struct babel_neighbor *nbr)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
2017-11-28 22:11:41 +08:00
|
|
|
struct babel_route *r;
|
2016-04-29 00:01:40 +08:00
|
|
|
node *n;
|
|
|
|
|
2017-10-25 23:14:08 +08:00
|
|
|
TRACE(D_EVENTS, "Removing neighbor %I on %s", nbr->addr, nbr->ifa->iface->name);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
WALK_LIST_FIRST(n, nbr->routes)
|
|
|
|
{
|
2017-11-28 22:11:41 +08:00
|
|
|
r = SKIP_BACK(struct babel_route, neigh_route, n);
|
|
|
|
babel_retract_route(p, r);
|
2017-10-27 18:20:58 +08:00
|
|
|
babel_flush_route(p, r);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
|
2021-05-30 19:07:16 +08:00
|
|
|
struct babel_seqno_request *sr;
|
|
|
|
WALK_LIST_FIRST2(sr, nbr_node, nbr->requests)
|
|
|
|
{
|
|
|
|
sr->nbr = NULL;
|
|
|
|
rem_node(&sr->nbr_node);
|
|
|
|
}
|
|
|
|
|
2017-11-08 21:35:52 +08:00
|
|
|
nbr->ifa = NULL;
|
2016-04-29 00:01:40 +08:00
|
|
|
rem_node(NODE nbr);
|
2021-05-30 19:07:16 +08:00
|
|
|
mb_free(nbr);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-10-25 23:14:08 +08:00
|
|
|
babel_expire_ihu(struct babel_proto *p, struct babel_neighbor *nbr)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
2017-10-25 23:14:08 +08:00
|
|
|
TRACE(D_EVENTS, "IHU from nbr %I on %s expired", nbr->addr, nbr->ifa->iface->name);
|
|
|
|
|
2016-04-29 00:01:40 +08:00
|
|
|
nbr->txcost = BABEL_INFINITY;
|
2017-10-14 01:33:42 +08:00
|
|
|
nbr->ihu_expiry = 0;
|
2017-10-25 23:14:08 +08:00
|
|
|
babel_update_cost(nbr);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-10-25 23:59:57 +08:00
|
|
|
babel_expire_hello(struct babel_proto *p, struct babel_neighbor *nbr, btime now_)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
2017-10-25 23:59:57 +08:00
|
|
|
again:
|
2016-04-29 00:01:40 +08:00
|
|
|
nbr->hello_map <<= 1;
|
|
|
|
|
|
|
|
if (nbr->hello_cnt < 16)
|
|
|
|
nbr->hello_cnt++;
|
|
|
|
|
2017-10-25 23:59:57 +08:00
|
|
|
nbr->hello_expiry += nbr->last_hello_int;
|
|
|
|
|
|
|
|
/* We may expire multiple hellos if last_hello_int is too short */
|
|
|
|
if (nbr->hello_map && nbr->hello_expiry <= now_)
|
|
|
|
goto again;
|
|
|
|
|
2017-10-25 23:14:08 +08:00
|
|
|
TRACE(D_EVENTS, "Hello from nbr %I on %s expired, %d left",
|
|
|
|
nbr->addr, nbr->ifa->iface->name, u32_popcount(nbr->hello_map));
|
|
|
|
|
2017-10-14 01:33:42 +08:00
|
|
|
if (nbr->hello_map)
|
2017-10-25 23:14:08 +08:00
|
|
|
babel_update_cost(nbr);
|
2017-10-14 01:33:42 +08:00
|
|
|
else
|
2017-10-25 23:14:08 +08:00
|
|
|
babel_flush_neighbor(p, nbr);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
babel_expire_neighbors(struct babel_proto *p)
|
|
|
|
{
|
|
|
|
struct babel_iface *ifa;
|
|
|
|
struct babel_neighbor *nbr, *nbx;
|
2017-10-13 18:34:08 +08:00
|
|
|
btime now_ = current_time();
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
WALK_LIST(ifa, p->interfaces)
|
|
|
|
{
|
|
|
|
WALK_LIST_DELSAFE(nbr, nbx, ifa->neigh_list)
|
|
|
|
{
|
2017-10-13 18:34:08 +08:00
|
|
|
if (nbr->ihu_expiry && nbr->ihu_expiry <= now_)
|
2017-10-25 23:14:08 +08:00
|
|
|
babel_expire_ihu(p, nbr);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2021-06-10 01:31:55 +08:00
|
|
|
if (nbr->init_expiry && nbr->init_expiry <= now_)
|
|
|
|
{ babel_flush_neighbor(p, nbr); continue; }
|
2021-04-17 21:04:16 +08:00
|
|
|
|
2021-06-10 01:31:55 +08:00
|
|
|
if (nbr->hello_expiry && nbr->hello_expiry <= now_)
|
|
|
|
{ babel_expire_hello(p, nbr, now_); continue; }
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Best route selection
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* From the RFC (section 3.5.1):
|
|
|
|
*
|
|
|
|
* a route advertisement carrying the quintuple (prefix, plen, router-id, seqno,
|
|
|
|
* metric) is feasible if one of the following conditions holds:
|
|
|
|
*
|
|
|
|
* - metric is infinite; or
|
|
|
|
*
|
|
|
|
* - no entry exists in the source table indexed by (id, prefix, plen); or
|
|
|
|
*
|
|
|
|
* - an entry (prefix, plen, router-id, seqno', metric') exists in the source
|
|
|
|
* table, and either
|
|
|
|
* - seqno' < seqno or
|
|
|
|
* - seqno = seqno' and metric < metric'.
|
|
|
|
*/
|
|
|
|
static inline int
|
|
|
|
babel_is_feasible(struct babel_source *s, u16 seqno, u16 metric)
|
|
|
|
{
|
|
|
|
return !s ||
|
|
|
|
(metric == BABEL_INFINITY) ||
|
|
|
|
(seqno > s->seqno) ||
|
|
|
|
((seqno == s->seqno) && (metric < s->metric));
|
|
|
|
}
|
|
|
|
|
2017-10-25 23:14:08 +08:00
|
|
|
/* Simple additive metric - Appendix 3.1 in the RFC */
|
|
|
|
static inline u16
|
|
|
|
babel_compute_metric(struct babel_neighbor *n, uint metric)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
2017-10-25 23:14:08 +08:00
|
|
|
return MIN(metric + n->cost, BABEL_INFINITY);
|
|
|
|
}
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2017-10-25 23:14:08 +08:00
|
|
|
static void
|
|
|
|
babel_update_cost(struct babel_neighbor *nbr)
|
|
|
|
{
|
|
|
|
struct babel_proto *p = nbr->ifa->proto;
|
|
|
|
struct babel_iface_config *cf = nbr->ifa->cf;
|
|
|
|
uint rcv = u32_popcount(nbr->hello_map); // number of bits set
|
|
|
|
uint max = nbr->hello_cnt;
|
|
|
|
uint rxcost = BABEL_INFINITY; /* Cost to announce in IHU */
|
|
|
|
uint txcost = BABEL_INFINITY; /* Effective cost for route selection */
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2017-10-25 23:14:08 +08:00
|
|
|
if (!rcv || !nbr->ifa->up)
|
|
|
|
goto done;
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2017-10-25 23:14:08 +08:00
|
|
|
switch (cf->type)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
2017-10-25 23:14:08 +08:00
|
|
|
case BABEL_IFACE_TYPE_WIRED:
|
2022-04-18 07:03:01 +08:00
|
|
|
case BABEL_IFACE_TYPE_TUNNEL:
|
2016-04-29 00:01:40 +08:00
|
|
|
/* k-out-of-j selection - Appendix 2.1 in the RFC. */
|
|
|
|
|
2017-10-25 23:14:08 +08:00
|
|
|
/* Link is bad if less than cf->limit/16 of expected hellos were received */
|
|
|
|
if (rcv * 16 < cf->limit * max)
|
|
|
|
break;
|
|
|
|
|
|
|
|
rxcost = cf->rxcost;
|
|
|
|
txcost = nbr->txcost;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BABEL_IFACE_TYPE_WIRELESS:
|
|
|
|
/*
|
|
|
|
* ETX - Appendix 2.2 in the RFC.
|
|
|
|
*
|
|
|
|
* alpha = prob. of successful transmission estimated by the neighbor
|
|
|
|
* beta = prob. of successful transmission estimated by the router
|
|
|
|
* rxcost = nominal rxcost of the router / beta
|
|
|
|
* txcost = nominal rxcost of the neighbor / (alpha * beta)
|
|
|
|
* = received txcost / beta
|
|
|
|
*
|
|
|
|
* Note that received txcost is just neighbor's rxcost. Beta is rcv/max,
|
|
|
|
* we use inverse values of beta (i.e. max/rcv) to stay in integers.
|
|
|
|
*/
|
|
|
|
rxcost = MIN( cf->rxcost * max / rcv, BABEL_INFINITY);
|
|
|
|
txcost = MIN(nbr->txcost * max / rcv, BABEL_INFINITY);
|
|
|
|
break;
|
|
|
|
}
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2022-04-18 07:03:01 +08:00
|
|
|
if (cf->rtt_cost && nbr->srtt > cf->rtt_min)
|
|
|
|
{
|
|
|
|
uint rtt_cost = cf->rtt_cost;
|
|
|
|
|
|
|
|
if (nbr->srtt < cf->rtt_max)
|
|
|
|
{
|
|
|
|
uint rtt_interval = cf->rtt_max TO_US - cf->rtt_min TO_US;
|
|
|
|
uint rtt_diff = (nbr->srtt TO_US - cf->rtt_min TO_US);
|
|
|
|
|
|
|
|
rtt_cost = (rtt_cost * rtt_diff) / rtt_interval;
|
|
|
|
}
|
|
|
|
|
|
|
|
txcost = MIN(txcost + rtt_cost, BABEL_INFINITY);
|
|
|
|
rxcost = MIN(rxcost + rtt_cost, BABEL_INFINITY);
|
|
|
|
|
|
|
|
TRACE(D_EVENTS, "Added RTT cost %u to nbr %I on %s with srtt %u.%03u ms",
|
|
|
|
rtt_cost, nbr->addr, nbr->ifa->iface->name, nbr->srtt/1000, nbr->srtt%1000);
|
|
|
|
}
|
|
|
|
|
2017-10-25 23:14:08 +08:00
|
|
|
done:
|
|
|
|
/* If RX cost changed, send IHU with next Hello */
|
|
|
|
if (rxcost != nbr->rxcost)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
2017-10-25 23:14:08 +08:00
|
|
|
nbr->rxcost = rxcost;
|
|
|
|
nbr->ihu_cnt = 0;
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
2017-10-25 23:14:08 +08:00
|
|
|
|
|
|
|
/* If link cost changed, run route selection */
|
|
|
|
if (txcost != nbr->cost)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
2017-10-25 23:14:08 +08:00
|
|
|
TRACE(D_EVENTS, "Cost of nbr %I on %s changed from %u to %u",
|
|
|
|
nbr->addr, nbr->ifa->iface->name, nbr->cost, txcost);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2017-10-25 23:14:08 +08:00
|
|
|
nbr->cost = txcost;
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2017-10-25 23:14:08 +08:00
|
|
|
struct babel_route *r; node *n;
|
|
|
|
WALK_LIST2(r, n, nbr->routes, neigh_route)
|
|
|
|
{
|
2022-04-21 06:57:23 +08:00
|
|
|
babel_update_metric(p, r, babel_compute_metric(nbr, r->advert_metric));
|
2017-11-28 22:11:41 +08:00
|
|
|
babel_select_route(p, r->e, r);
|
2017-10-25 23:14:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* babel_announce_rte - announce selected route to the core
|
|
|
|
* @p: Babel protocol instance
|
|
|
|
* @e: Babel route entry to announce
|
|
|
|
*
|
|
|
|
* This function announces a Babel entry to the core if it has a selected
|
2017-11-28 22:11:41 +08:00
|
|
|
* incoming path, and retracts it otherwise. If there is no selected route but
|
|
|
|
* the entry is valid and ours, the unreachable route is announced instead.
|
2016-04-29 00:01:40 +08:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
babel_announce_rte(struct babel_proto *p, struct babel_entry *e)
|
|
|
|
{
|
2017-11-28 22:11:41 +08:00
|
|
|
struct babel_route *r = e->selected;
|
2017-06-08 18:18:16 +08:00
|
|
|
struct channel *c = (e->n.addr->type == NET_IP4) ? p->ip4_channel : p->ip6_channel;
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
if (r)
|
|
|
|
{
|
2017-11-28 22:11:41 +08:00
|
|
|
rta a0 = {
|
2016-04-29 00:01:40 +08:00
|
|
|
.src = p->p.main_source,
|
|
|
|
.source = RTS_BABEL,
|
|
|
|
.scope = SCOPE_UNIVERSE,
|
2017-11-28 22:11:41 +08:00
|
|
|
.dest = RTD_UNICAST,
|
2016-04-29 00:01:40 +08:00
|
|
|
.from = r->neigh->addr,
|
2017-11-28 22:11:41 +08:00
|
|
|
.nh.gw = r->next_hop,
|
2017-02-22 19:02:28 +08:00
|
|
|
.nh.iface = r->neigh->ifa->iface,
|
2016-04-29 00:01:40 +08:00
|
|
|
};
|
|
|
|
|
2020-05-27 05:43:13 +08:00
|
|
|
/*
|
|
|
|
* If we cannot find a reachable neighbour, set the entry to be onlink. This
|
|
|
|
* makes it possible to, e.g., assign /32 addresses on a mesh interface and
|
|
|
|
* have routing work.
|
|
|
|
*/
|
|
|
|
if (!neigh_find(&p->p, r->next_hop, r->neigh->ifa->iface, 0))
|
|
|
|
a0.nh.flags = RNF_ONLINK;
|
|
|
|
|
2017-11-28 22:11:41 +08:00
|
|
|
rta *a = rta_lookup(&a0);
|
2016-04-29 00:01:40 +08:00
|
|
|
rte *rte = rte_get_temp(a);
|
2017-11-28 22:11:41 +08:00
|
|
|
rte->u.babel.seqno = r->seqno;
|
2016-04-29 00:01:40 +08:00
|
|
|
rte->u.babel.metric = r->metric;
|
|
|
|
rte->u.babel.router_id = r->router_id;
|
2019-03-15 00:22:22 +08:00
|
|
|
rte->pflags = EA_ID_FLAG(EA_BABEL_METRIC) | EA_ID_FLAG(EA_BABEL_ROUTER_ID);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2017-11-28 22:11:41 +08:00
|
|
|
e->unreachable = 0;
|
|
|
|
rte_update2(c, e->n.addr, rte, p->p.main_source);
|
|
|
|
}
|
|
|
|
else if (e->valid && (e->router_id != p->router_id))
|
|
|
|
{
|
|
|
|
/* Unreachable */
|
|
|
|
rta a0 = {
|
|
|
|
.src = p->p.main_source,
|
|
|
|
.source = RTS_BABEL,
|
|
|
|
.scope = SCOPE_UNIVERSE,
|
|
|
|
.dest = RTD_UNREACHABLE,
|
|
|
|
};
|
|
|
|
|
|
|
|
rta *a = rta_lookup(&a0);
|
|
|
|
rte *rte = rte_get_temp(a);
|
|
|
|
memset(&rte->u.babel, 0, sizeof(rte->u.babel));
|
|
|
|
rte->pflags = 0;
|
|
|
|
rte->pref = 1;
|
|
|
|
|
|
|
|
e->unreachable = 1;
|
2017-06-08 18:18:16 +08:00
|
|
|
rte_update2(c, e->n.addr, rte, p->p.main_source);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Retraction */
|
2017-11-28 22:11:41 +08:00
|
|
|
e->unreachable = 0;
|
2017-06-08 18:18:16 +08:00
|
|
|
rte_update2(c, e->n.addr, NULL, p->p.main_source);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-28 22:11:41 +08:00
|
|
|
/* Special case of babel_announce_rte() just for retraction */
|
|
|
|
static inline void
|
|
|
|
babel_announce_retraction(struct babel_proto *p, struct babel_entry *e)
|
|
|
|
{
|
|
|
|
struct channel *c = (e->n.addr->type == NET_IP4) ? p->ip4_channel : p->ip6_channel;
|
|
|
|
e->unreachable = 0;
|
|
|
|
rte_update2(c, e->n.addr, NULL, p->p.main_source);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-29 00:01:40 +08:00
|
|
|
/**
|
|
|
|
* babel_select_route - select best route for given route entry
|
2017-11-28 22:11:41 +08:00
|
|
|
* @p: Babel protocol instance
|
2016-04-29 00:01:40 +08:00
|
|
|
* @e: Babel entry to select the best route for
|
2017-11-28 22:11:41 +08:00
|
|
|
* @mod: Babel route that was modified or NULL if unspecified
|
2016-04-29 00:01:40 +08:00
|
|
|
*
|
2017-11-28 22:11:41 +08:00
|
|
|
* Select the best reachable and feasible route for a given prefix among the
|
|
|
|
* routes received from peers, and propagate it to the nest. This just selects
|
|
|
|
* the reachable and feasible route with the lowest metric, but keeps selected
|
|
|
|
* the old one in case of tie.
|
2016-04-29 00:01:40 +08:00
|
|
|
*
|
|
|
|
* If no feasible route is available for a prefix that previously had a route
|
2017-11-28 22:11:41 +08:00
|
|
|
* selected, a seqno request is sent to try to get a valid route. If the entry
|
|
|
|
* is valid and not owned by us, the unreachable route is announced to the nest
|
|
|
|
* (to blackhole packets going to it, as per section 2.8). It is later removed
|
|
|
|
* by babel_expire_routes(). Otherwise, the route is just removed from the nest.
|
|
|
|
*
|
|
|
|
* Argument @mod is used to optimize best route calculation. When specified, the
|
|
|
|
* function can assume that only the @mod route was modified to avoid full best
|
|
|
|
* route selection and announcement when non-best route was modified in minor
|
|
|
|
* way. The caller is advised to not call babel_select_route() when no change is
|
|
|
|
* done (e.g. periodic route updates) to avoid unnecessary announcements of the
|
|
|
|
* same best route. The caller is not required to call the function in case of a
|
|
|
|
* retraction of a non-best route.
|
2016-04-29 00:01:40 +08:00
|
|
|
*
|
2017-11-28 22:11:41 +08:00
|
|
|
* Note that the function does not active triggered updates. That is done by
|
|
|
|
* babel_rt_notify() when the change is propagated back to Babel.
|
2016-04-29 00:01:40 +08:00
|
|
|
*/
|
|
|
|
static void
|
2017-11-28 22:11:41 +08:00
|
|
|
babel_select_route(struct babel_proto *p, struct babel_entry *e, struct babel_route *mod)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
2017-11-28 22:11:41 +08:00
|
|
|
struct babel_route *r, *best = e->selected;
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2017-11-28 22:11:41 +08:00
|
|
|
/* Shortcut if only non-best was modified */
|
|
|
|
if (mod && (mod != best))
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
2022-04-21 06:57:23 +08:00
|
|
|
if (babel_route_better(p, mod, best))
|
2017-11-28 22:11:41 +08:00
|
|
|
best = mod;
|
|
|
|
else
|
|
|
|
return;
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
2017-11-28 22:11:41 +08:00
|
|
|
else
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
2017-11-28 22:11:41 +08:00
|
|
|
/* Selected route may be modified and no longer admissible */
|
|
|
|
if (!best || (best->metric == BABEL_INFINITY) || !best->feasible)
|
|
|
|
best = NULL;
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2022-04-21 06:57:23 +08:00
|
|
|
/* best will be compared to many routes below, make sure it's up-to-date */
|
|
|
|
if (best)
|
|
|
|
babel_update_smoothed_metric(p, best);
|
|
|
|
|
2017-11-28 22:11:41 +08:00
|
|
|
/* Find the best feasible route from all routes */
|
|
|
|
WALK_LIST(r, e->routes)
|
2022-04-21 06:57:23 +08:00
|
|
|
if (babel_route_better(p, r, best))
|
2017-11-28 22:11:41 +08:00
|
|
|
best = r;
|
|
|
|
}
|
2016-07-19 20:28:53 +08:00
|
|
|
|
2017-11-28 22:11:41 +08:00
|
|
|
if (best)
|
|
|
|
{
|
|
|
|
if (best != e->selected)
|
2022-04-21 06:57:23 +08:00
|
|
|
{
|
|
|
|
u16 smoothed = babel_update_smoothed_metric(p, best);
|
|
|
|
TRACE(D_EVENTS, "Picked new route for prefix %N: router-id %lR metric %d/%d",
|
|
|
|
e->n.addr, best->router_id, best->metric, smoothed);
|
|
|
|
}
|
2017-11-28 22:11:41 +08:00
|
|
|
}
|
|
|
|
else if (e->selected)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We have lost all feasible routes. We have to broadcast seqno request
|
|
|
|
* (Section 3.8.2.1) and keep unreachable route for a while (section 2.8).
|
|
|
|
* The later is done automatically by babel_announce_rte().
|
|
|
|
*/
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2017-11-28 22:11:41 +08:00
|
|
|
TRACE(D_EVENTS, "Lost feasible route for prefix %N", e->n.addr);
|
|
|
|
if (e->valid && (e->selected->router_id == e->router_id))
|
|
|
|
babel_add_seqno_request(p, e, e->selected->router_id, e->selected->seqno + 1, 0, NULL);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
2017-11-28 22:11:41 +08:00
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
|
|
|
e->selected = best;
|
|
|
|
babel_announce_rte(p, e);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Functions to send replies
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
babel_send_ack(struct babel_iface *ifa, ip_addr dest, u16 nonce)
|
|
|
|
{
|
|
|
|
struct babel_proto *p = ifa->proto;
|
|
|
|
union babel_msg msg = {};
|
|
|
|
|
|
|
|
TRACE(D_PACKETS, "Sending ACK to %I with nonce %d", dest, nonce);
|
|
|
|
|
|
|
|
msg.type = BABEL_TLV_ACK;
|
|
|
|
msg.ack.nonce = nonce;
|
|
|
|
|
|
|
|
babel_send_unicast(&msg, ifa, dest);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
babel_build_ihu(union babel_msg *msg, struct babel_iface *ifa, struct babel_neighbor *n)
|
|
|
|
{
|
|
|
|
struct babel_proto *p = ifa->proto;
|
|
|
|
|
|
|
|
msg->type = BABEL_TLV_IHU;
|
|
|
|
msg->ihu.addr = n->addr;
|
2017-10-25 23:14:08 +08:00
|
|
|
msg->ihu.rxcost = n->rxcost;
|
2016-04-29 00:01:40 +08:00
|
|
|
msg->ihu.interval = ifa->cf->ihu_interval;
|
|
|
|
|
2022-04-18 07:03:01 +08:00
|
|
|
if (n->last_tstamp_rcvd && ifa->cf->rtt_send)
|
|
|
|
{
|
|
|
|
msg->ihu.tstamp = n->last_tstamp;
|
|
|
|
msg->ihu.tstamp_rcvd = n->last_tstamp_rcvd TO_US;
|
|
|
|
}
|
|
|
|
|
2017-10-13 18:34:08 +08:00
|
|
|
TRACE(D_PACKETS, "Sending IHU for %I with rxcost %d interval %t",
|
|
|
|
msg->ihu.addr, msg->ihu.rxcost, (btime) msg->ihu.interval);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
babel_send_ihu(struct babel_iface *ifa, struct babel_neighbor *n)
|
|
|
|
{
|
|
|
|
union babel_msg msg = {};
|
|
|
|
babel_build_ihu(&msg, ifa, n);
|
|
|
|
babel_send_unicast(&msg, ifa, n->addr);
|
2017-10-25 23:14:08 +08:00
|
|
|
n->ihu_cnt = BABEL_IHU_INTERVAL_FACTOR;
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
babel_send_ihus(struct babel_iface *ifa)
|
|
|
|
{
|
|
|
|
struct babel_neighbor *n;
|
|
|
|
WALK_LIST(n, ifa->neigh_list)
|
|
|
|
{
|
2017-10-25 23:14:08 +08:00
|
|
|
if (n->hello_cnt && (--n->ihu_cnt <= 0))
|
|
|
|
{
|
|
|
|
union babel_msg msg = {};
|
|
|
|
babel_build_ihu(&msg, ifa, n);
|
|
|
|
babel_enqueue(&msg, ifa);
|
|
|
|
n->ihu_cnt = BABEL_IHU_INTERVAL_FACTOR;
|
|
|
|
}
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-04-22 22:41:52 +08:00
|
|
|
babel_send_hello(struct babel_iface *ifa, uint interval)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
|
|
|
struct babel_proto *p = ifa->proto;
|
|
|
|
union babel_msg msg = {};
|
|
|
|
|
|
|
|
msg.type = BABEL_TLV_HELLO;
|
|
|
|
msg.hello.seqno = ifa->hello_seqno++;
|
2022-04-22 22:41:52 +08:00
|
|
|
msg.hello.interval = interval ?: ifa->cf->hello_interval;
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2022-04-18 07:03:01 +08:00
|
|
|
if (ifa->cf->rtt_send)
|
|
|
|
msg.hello.tstamp = 1; /* real timestamp will be set on TLV write */
|
|
|
|
|
2017-10-13 18:34:08 +08:00
|
|
|
TRACE(D_PACKETS, "Sending hello on %s with seqno %d interval %t",
|
|
|
|
ifa->ifname, msg.hello.seqno, (btime) msg.hello.interval);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
babel_enqueue(&msg, ifa);
|
|
|
|
|
2017-10-25 23:14:08 +08:00
|
|
|
babel_send_ihus(ifa);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-10-27 18:20:58 +08:00
|
|
|
babel_send_route_request(struct babel_proto *p, struct babel_entry *e, struct babel_neighbor *n)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
|
|
|
union babel_msg msg = {};
|
|
|
|
|
2018-11-28 23:43:17 +08:00
|
|
|
TRACE(D_PACKETS, "Sending route request for %N to %I", e->n.addr, n->addr);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
msg.type = BABEL_TLV_ROUTE_REQUEST;
|
2016-12-10 07:11:26 +08:00
|
|
|
net_copy(&msg.route_request.net, e->n.addr);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2017-11-08 21:35:52 +08:00
|
|
|
babel_send_unicast(&msg, n->ifa, n->addr);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
babel_send_wildcard_request(struct babel_iface *ifa)
|
|
|
|
{
|
|
|
|
struct babel_proto *p = ifa->proto;
|
|
|
|
union babel_msg msg = {};
|
|
|
|
|
2018-11-28 23:43:17 +08:00
|
|
|
TRACE(D_PACKETS, "Sending wildcard route request on %s", ifa->ifname);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
msg.type = BABEL_TLV_ROUTE_REQUEST;
|
|
|
|
msg.route_request.full = 1;
|
|
|
|
|
|
|
|
babel_enqueue(&msg, ifa);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-11-08 21:35:52 +08:00
|
|
|
babel_send_seqno_request(struct babel_proto *p, struct babel_entry *e, struct babel_seqno_request *sr)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
|
|
|
union babel_msg msg = {};
|
|
|
|
|
|
|
|
msg.type = BABEL_TLV_SEQNO_REQUEST;
|
2017-11-08 21:35:52 +08:00
|
|
|
msg.seqno_request.hop_count = sr->hop_count ?: BABEL_INITIAL_HOP_COUNT;
|
|
|
|
msg.seqno_request.seqno = sr->seqno;
|
|
|
|
msg.seqno_request.router_id = sr->router_id;
|
2016-12-10 07:11:26 +08:00
|
|
|
net_copy(&msg.seqno_request.net, e->n.addr);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2017-11-08 21:35:52 +08:00
|
|
|
if (sr->nbr)
|
|
|
|
{
|
|
|
|
TRACE(D_PACKETS, "Sending seqno request for %N router-id %lR seqno %d to %I on %s",
|
|
|
|
e->n.addr, sr->router_id, sr->seqno, sr->nbr->addr, sr->nbr->ifa->ifname);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2017-11-08 21:35:52 +08:00
|
|
|
babel_send_unicast(&msg, sr->nbr->ifa, sr->nbr->addr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE(D_PACKETS, "Sending broadcast seqno request for %N router-id %lR seqno %d",
|
|
|
|
e->n.addr, sr->router_id, sr->seqno);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2017-11-08 21:35:52 +08:00
|
|
|
struct babel_iface *ifa;
|
|
|
|
WALK_LIST(ifa, p->interfaces)
|
|
|
|
babel_enqueue(&msg, ifa);
|
|
|
|
}
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* babel_send_update - send route table updates
|
|
|
|
* @ifa: Interface to transmit on
|
|
|
|
* @changed: Only send entries changed since this time
|
|
|
|
*
|
|
|
|
* This function produces update TLVs for all entries changed since the time
|
|
|
|
* indicated by the &changed parameter and queues them for transmission on the
|
|
|
|
* selected interface. During the process, the feasibility distance for each
|
|
|
|
* transmitted entry is updated.
|
|
|
|
*/
|
|
|
|
static void
|
2017-10-13 18:34:08 +08:00
|
|
|
babel_send_update_(struct babel_iface *ifa, btime changed, struct fib *rtable)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
|
|
|
struct babel_proto *p = ifa->proto;
|
|
|
|
|
2017-10-14 01:34:34 +08:00
|
|
|
/* Update increase was requested */
|
|
|
|
if (p->update_seqno_inc)
|
|
|
|
{
|
|
|
|
p->update_seqno++;
|
|
|
|
p->update_seqno_inc = 0;
|
|
|
|
}
|
|
|
|
|
2017-06-08 18:18:16 +08:00
|
|
|
FIB_WALK(rtable, struct babel_entry, e)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
2017-11-28 22:11:41 +08:00
|
|
|
if (!e->valid)
|
2016-04-29 00:01:40 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Our own seqno might have changed, in which case we update the routes we
|
|
|
|
originate. */
|
2017-11-28 22:11:41 +08:00
|
|
|
if ((e->router_id == p->router_id) && (e->seqno < p->update_seqno))
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
2017-11-28 22:11:41 +08:00
|
|
|
e->seqno = p->update_seqno;
|
2017-10-13 18:34:08 +08:00
|
|
|
e->updated = current_time();
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Skip routes that weren't updated since 'changed' time */
|
|
|
|
if (e->updated < changed)
|
|
|
|
continue;
|
|
|
|
|
2016-12-10 07:11:26 +08:00
|
|
|
TRACE(D_PACKETS, "Sending update for %N router-id %lR seqno %d metric %d",
|
2017-11-28 22:11:41 +08:00
|
|
|
e->n.addr, e->router_id, e->seqno, e->metric);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
union babel_msg msg = {};
|
|
|
|
msg.type = BABEL_TLV_UPDATE;
|
|
|
|
msg.update.interval = ifa->cf->update_interval;
|
2017-11-28 22:11:41 +08:00
|
|
|
msg.update.seqno = e->seqno;
|
|
|
|
msg.update.metric = e->metric;
|
|
|
|
msg.update.router_id = e->router_id;
|
2016-12-10 07:11:26 +08:00
|
|
|
net_copy(&msg.update.net, e->n.addr);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2017-06-08 18:18:16 +08:00
|
|
|
msg.update.next_hop = ((e->n.addr->type == NET_IP4) ?
|
|
|
|
ifa->next_hop_ip4 : ifa->next_hop_ip6);
|
|
|
|
|
2018-06-13 21:22:29 +08:00
|
|
|
/* Do not send route if next hop is unknown, e.g. no configured IPv4 address */
|
|
|
|
if (ipa_zero(msg.update.next_hop))
|
|
|
|
continue;
|
|
|
|
|
2016-07-19 20:38:36 +08:00
|
|
|
babel_enqueue(&msg, ifa);
|
|
|
|
|
|
|
|
/* Update feasibility distance for redistributed routes */
|
2017-11-28 22:11:41 +08:00
|
|
|
if (e->router_id != p->router_id)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
2017-11-28 22:11:41 +08:00
|
|
|
struct babel_source *s = babel_get_source(p, e, e->router_id);
|
2017-10-13 18:34:08 +08:00
|
|
|
s->expires = current_time() + BABEL_GARBAGE_INTERVAL;
|
2016-07-19 20:38:36 +08:00
|
|
|
|
|
|
|
if ((msg.update.seqno > s->seqno) ||
|
|
|
|
((msg.update.seqno == s->seqno) && (msg.update.metric < s->metric)))
|
|
|
|
{
|
|
|
|
s->seqno = msg.update.seqno;
|
|
|
|
s->metric = msg.update.metric;
|
|
|
|
}
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
FIB_WALK_END;
|
|
|
|
}
|
|
|
|
|
2017-06-08 18:18:16 +08:00
|
|
|
static void
|
2017-10-13 18:34:08 +08:00
|
|
|
babel_send_update(struct babel_iface *ifa, btime changed)
|
2017-06-08 18:18:16 +08:00
|
|
|
{
|
|
|
|
struct babel_proto *p = ifa->proto;
|
|
|
|
|
|
|
|
babel_send_update_(ifa, changed, &p->ip4_rtable);
|
|
|
|
babel_send_update_(ifa, changed, &p->ip6_rtable);
|
|
|
|
}
|
|
|
|
|
2016-04-29 00:01:40 +08:00
|
|
|
static void
|
|
|
|
babel_trigger_iface_update(struct babel_iface *ifa)
|
|
|
|
{
|
|
|
|
struct babel_proto *p = ifa->proto;
|
|
|
|
|
|
|
|
/* Interface not active or already scheduled */
|
|
|
|
if (!ifa->up || ifa->want_triggered)
|
|
|
|
return;
|
|
|
|
|
|
|
|
TRACE(D_EVENTS, "Scheduling triggered updates for %s seqno %d",
|
|
|
|
ifa->iface->name, p->update_seqno);
|
|
|
|
|
2017-10-13 18:34:08 +08:00
|
|
|
ifa->want_triggered = current_time();
|
2016-04-29 00:01:40 +08:00
|
|
|
babel_iface_kick_timer(ifa);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sends and update on all interfaces. */
|
|
|
|
static void
|
|
|
|
babel_trigger_update(struct babel_proto *p)
|
|
|
|
{
|
|
|
|
if (p->triggered)
|
|
|
|
return;
|
|
|
|
|
|
|
|
struct babel_iface *ifa;
|
|
|
|
WALK_LIST(ifa, p->interfaces)
|
|
|
|
babel_trigger_iface_update(ifa);
|
|
|
|
|
|
|
|
p->triggered = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* A retraction is an update with an infinite metric */
|
|
|
|
static void
|
2016-12-10 07:11:26 +08:00
|
|
|
babel_send_retraction(struct babel_iface *ifa, net_addr *n)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
|
|
|
struct babel_proto *p = ifa->proto;
|
|
|
|
union babel_msg msg = {};
|
|
|
|
|
2016-12-10 07:11:26 +08:00
|
|
|
TRACE(D_PACKETS, "Sending retraction for %N seqno %d", n, p->update_seqno);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
msg.type = BABEL_TLV_UPDATE;
|
|
|
|
msg.update.interval = ifa->cf->update_interval;
|
|
|
|
msg.update.seqno = p->update_seqno;
|
|
|
|
msg.update.metric = BABEL_INFINITY;
|
2016-12-10 07:11:26 +08:00
|
|
|
msg.update.net = *n;
|
2016-07-19 20:23:41 +08:00
|
|
|
|
|
|
|
babel_enqueue(&msg, ifa);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
babel_send_wildcard_retraction(struct babel_iface *ifa)
|
|
|
|
{
|
|
|
|
struct babel_proto *p = ifa->proto;
|
|
|
|
union babel_msg msg = {};
|
|
|
|
|
|
|
|
TRACE(D_PACKETS, "Sending wildcard retraction on %s", ifa->ifname);
|
|
|
|
|
|
|
|
msg.type = BABEL_TLV_UPDATE;
|
|
|
|
msg.update.wildcard = 1;
|
|
|
|
msg.update.interval = ifa->cf->update_interval;
|
|
|
|
msg.update.seqno = p->update_seqno;
|
|
|
|
msg.update.metric = BABEL_INFINITY;
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
babel_enqueue(&msg, ifa);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TLV handler helpers
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Update hello history according to Appendix A1 of the RFC */
|
|
|
|
static void
|
2017-10-13 18:34:08 +08:00
|
|
|
babel_update_hello_history(struct babel_neighbor *n, u16 seqno, uint interval)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Compute the difference between expected and received seqno (modulo 2^16).
|
|
|
|
* If the expected and received seqnos are within 16 of each other, the modular
|
|
|
|
* difference is going to be less than 16 for one of the directions. Otherwise,
|
|
|
|
* the values differ too much, so just reset the state.
|
|
|
|
*/
|
|
|
|
|
|
|
|
u16 delta = ((uint) seqno - (uint) n->next_hello_seqno);
|
|
|
|
|
2017-10-25 23:14:08 +08:00
|
|
|
if ((delta == 0) || (n->hello_cnt == 0))
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
|
|
|
/* Do nothing */
|
|
|
|
}
|
|
|
|
else if (delta <= 16)
|
|
|
|
{
|
|
|
|
/* Sending node decreased interval; fast-forward */
|
|
|
|
n->hello_map <<= delta;
|
|
|
|
n->hello_cnt = MIN(n->hello_cnt + delta, 16);
|
|
|
|
}
|
|
|
|
else if (delta >= 0xfff0)
|
|
|
|
{
|
|
|
|
u8 diff = (0xffff - delta);
|
|
|
|
/* Sending node increased interval; undo history */
|
|
|
|
n->hello_map >>= diff;
|
|
|
|
n->hello_cnt = (diff < n->hello_cnt) ? n->hello_cnt - diff : 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Note state reset - flush entries */
|
|
|
|
n->hello_map = n->hello_cnt = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Current entry */
|
|
|
|
n->hello_map = (n->hello_map << 1) | 1;
|
|
|
|
n->next_hello_seqno = seqno+1;
|
|
|
|
if (n->hello_cnt < 16) n->hello_cnt++;
|
2017-10-25 23:14:08 +08:00
|
|
|
|
|
|
|
/* Update expiration */
|
2017-10-13 18:34:08 +08:00
|
|
|
n->hello_expiry = current_time() + BABEL_HELLO_EXPIRY_FACTOR(interval);
|
2017-10-14 01:33:42 +08:00
|
|
|
n->last_hello_int = interval;
|
2021-06-10 01:31:55 +08:00
|
|
|
|
|
|
|
/* Disable initial timeout */
|
|
|
|
n->init_expiry = 0;
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TLV handlers
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
babel_handle_ack_req(union babel_msg *m, struct babel_iface *ifa)
|
|
|
|
{
|
|
|
|
struct babel_proto *p = ifa->proto;
|
|
|
|
struct babel_msg_ack_req *msg = &m->ack_req;
|
|
|
|
|
2017-10-13 18:34:08 +08:00
|
|
|
TRACE(D_PACKETS, "Handling ACK request nonce %d interval %t",
|
|
|
|
msg->nonce, (btime) msg->interval);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
babel_send_ack(ifa, msg->sender, msg->nonce);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
babel_handle_hello(union babel_msg *m, struct babel_iface *ifa)
|
|
|
|
{
|
|
|
|
struct babel_proto *p = ifa->proto;
|
|
|
|
struct babel_msg_hello *msg = &m->hello;
|
|
|
|
|
2017-10-13 18:34:08 +08:00
|
|
|
TRACE(D_PACKETS, "Handling hello seqno %d interval %t",
|
|
|
|
msg->seqno, (btime) msg->interval);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
struct babel_neighbor *n = babel_get_neighbor(ifa, msg->sender);
|
2022-04-18 07:03:01 +08:00
|
|
|
struct babel_iface_config *cf = n->ifa->cf;
|
2017-10-25 23:14:08 +08:00
|
|
|
int first_hello = !n->hello_cnt;
|
|
|
|
|
2022-04-18 07:03:01 +08:00
|
|
|
if (msg->tstamp)
|
|
|
|
{
|
|
|
|
n->last_tstamp = msg->tstamp;
|
|
|
|
n->last_tstamp_rcvd = msg->pkt_received;
|
|
|
|
}
|
2016-04-29 00:01:40 +08:00
|
|
|
babel_update_hello_history(n, msg->seqno, msg->interval);
|
2017-10-25 23:14:08 +08:00
|
|
|
babel_update_cost(n);
|
|
|
|
|
|
|
|
/* Speed up session establishment by sending IHU immediately */
|
|
|
|
if (first_hello)
|
2022-04-18 07:03:01 +08:00
|
|
|
{
|
|
|
|
/* if using RTT, all IHUs must be paired with hellos */
|
|
|
|
if(cf->rtt_send)
|
|
|
|
babel_send_hello(ifa, 0);
|
|
|
|
else
|
|
|
|
babel_send_ihu(ifa, n);
|
|
|
|
}
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
babel_handle_ihu(union babel_msg *m, struct babel_iface *ifa)
|
|
|
|
{
|
|
|
|
struct babel_proto *p = ifa->proto;
|
|
|
|
struct babel_msg_ihu *msg = &m->ihu;
|
|
|
|
|
|
|
|
/* Ignore IHUs that are not about us */
|
|
|
|
if ((msg->ae != BABEL_AE_WILDCARD) && !ipa_equal(msg->addr, ifa->addr))
|
|
|
|
return;
|
|
|
|
|
2017-10-13 18:34:08 +08:00
|
|
|
TRACE(D_PACKETS, "Handling IHU rxcost %d interval %t",
|
|
|
|
msg->rxcost, (btime) msg->interval);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
struct babel_neighbor *n = babel_get_neighbor(ifa, msg->sender);
|
|
|
|
n->txcost = msg->rxcost;
|
2017-10-13 18:34:08 +08:00
|
|
|
n->ihu_expiry = current_time() + BABEL_IHU_EXPIRY_FACTOR(msg->interval);
|
2022-04-18 07:03:01 +08:00
|
|
|
|
|
|
|
if (msg->tstamp)
|
|
|
|
{
|
|
|
|
u32 rtt_sample = 0, pkt_received = msg->pkt_received TO_US;
|
|
|
|
int remote_time, full_time;
|
|
|
|
|
|
|
|
/* processing time reported by peer */
|
|
|
|
remote_time = (n->last_tstamp - msg->tstamp_rcvd);
|
|
|
|
/* time since we sent the last timestamp - RTT including remote time */
|
|
|
|
full_time = (pkt_received - msg->tstamp);
|
|
|
|
|
|
|
|
/* sanity checks */
|
|
|
|
if (remote_time < 0 || full_time < 0 ||
|
|
|
|
remote_time US_ > BABEL_RTT_MAX_VALUE || full_time US_ > BABEL_RTT_MAX_VALUE)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (remote_time < full_time)
|
|
|
|
rtt_sample = full_time - remote_time;
|
|
|
|
|
|
|
|
if (n->srtt)
|
|
|
|
{
|
|
|
|
uint decay = n->ifa->cf->rtt_decay;
|
|
|
|
|
|
|
|
n->srtt = (decay * rtt_sample + (256 - decay) * n->srtt) / 256;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
n->srtt = rtt_sample;
|
|
|
|
|
|
|
|
TRACE(D_EVENTS, "RTT sample for neighbour %I on %s: %u us (srtt %u.%03u ms)",
|
|
|
|
n->addr, ifa->ifname, rtt_sample, n->srtt/1000, n->srtt%1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2017-10-25 23:14:08 +08:00
|
|
|
babel_update_cost(n);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* babel_handle_update - handle incoming route updates
|
|
|
|
* @m: Incoming update TLV
|
|
|
|
* @ifa: Interface the update was received on
|
|
|
|
*
|
|
|
|
* This function is called as a handler for update TLVs and handles the updating
|
|
|
|
* and maintenance of route entries in Babel's internal routing cache. The
|
|
|
|
* handling follows the actions described in the Babel RFC, and at the end of
|
|
|
|
* each update handling, babel_select_route() is called on the affected entry to
|
|
|
|
* optionally update the selected routes and propagate them to the core.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
babel_handle_update(union babel_msg *m, struct babel_iface *ifa)
|
|
|
|
{
|
|
|
|
struct babel_proto *p = ifa->proto;
|
|
|
|
struct babel_msg_update *msg = &m->update;
|
|
|
|
|
2016-07-19 19:33:02 +08:00
|
|
|
struct babel_neighbor *nbr;
|
2016-04-29 00:01:40 +08:00
|
|
|
struct babel_entry *e;
|
|
|
|
struct babel_source *s;
|
2017-10-14 05:46:41 +08:00
|
|
|
struct babel_route *r, *best;
|
2016-07-19 19:33:02 +08:00
|
|
|
node *n;
|
2017-10-14 05:46:41 +08:00
|
|
|
int feasible, metric;
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2016-12-10 07:11:26 +08:00
|
|
|
if (msg->wildcard)
|
|
|
|
TRACE(D_PACKETS, "Handling wildcard retraction", msg->seqno);
|
|
|
|
else
|
|
|
|
TRACE(D_PACKETS, "Handling update for %N with seqno %d metric %d",
|
|
|
|
&msg->net, msg->seqno, msg->metric);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2016-07-19 19:33:02 +08:00
|
|
|
nbr = babel_find_neighbor(ifa, msg->sender);
|
|
|
|
if (!nbr)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
|
|
|
DBG("Babel: Haven't heard from neighbor %I; ignoring update.\n", msg->sender);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msg->router_id == p->router_id)
|
|
|
|
{
|
|
|
|
DBG("Babel: Ignoring update for our own router ID.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-08 18:18:16 +08:00
|
|
|
struct channel *c = (msg->net.type == NET_IP4) ? p->ip4_channel : p->ip6_channel;
|
|
|
|
if (!c || (c->channel_state != CS_UP))
|
|
|
|
{
|
|
|
|
DBG("Babel: Ignoring update for inactive address family.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-19 19:33:02 +08:00
|
|
|
/* Retraction */
|
2016-04-29 00:01:40 +08:00
|
|
|
if (msg->metric == BABEL_INFINITY)
|
2016-07-19 19:33:02 +08:00
|
|
|
{
|
2016-07-19 20:23:41 +08:00
|
|
|
if (msg->wildcard)
|
2016-07-19 19:33:02 +08:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Special case: This is a retraction of all prefixes announced by this
|
|
|
|
* neighbour (see second-to-last paragraph of section 4.4.9 in the RFC).
|
|
|
|
*/
|
|
|
|
WALK_LIST(n, nbr->routes)
|
|
|
|
{
|
|
|
|
r = SKIP_BACK(struct babel_route, neigh_route, n);
|
2017-11-28 22:11:41 +08:00
|
|
|
babel_retract_route(p, r);
|
2016-07-19 19:33:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-12-10 07:11:26 +08:00
|
|
|
e = babel_find_entry(p, &msg->net);
|
2016-07-19 19:33:02 +08:00
|
|
|
|
|
|
|
if (!e)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* The route entry indexed by neighbour */
|
|
|
|
r = babel_find_route(e, nbr);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2016-07-19 19:33:02 +08:00
|
|
|
if (!r)
|
|
|
|
return;
|
|
|
|
|
2017-11-28 22:11:41 +08:00
|
|
|
/* Router-id, next-hop and seqno are ignored for retractions */
|
|
|
|
babel_retract_route(p, r);
|
2016-07-19 19:33:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Done with retractions */
|
2016-04-29 00:01:40 +08:00
|
|
|
return;
|
2016-07-19 19:33:02 +08:00
|
|
|
}
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2017-11-28 22:11:41 +08:00
|
|
|
/* Regular update */
|
2016-12-10 07:11:26 +08:00
|
|
|
e = babel_get_entry(p, &msg->net);
|
2017-11-28 22:11:41 +08:00
|
|
|
r = babel_get_route(p, e, nbr); /* the route entry indexed by neighbour */
|
2016-04-29 00:01:40 +08:00
|
|
|
s = babel_find_source(e, msg->router_id); /* for feasibility */
|
|
|
|
feasible = babel_is_feasible(s, msg->seqno, msg->metric);
|
2017-10-14 05:46:41 +08:00
|
|
|
metric = babel_compute_metric(nbr, msg->metric);
|
2017-11-28 22:11:41 +08:00
|
|
|
best = e->selected;
|
2017-10-14 05:46:41 +08:00
|
|
|
|
|
|
|
/* RFC section 3.8.2.2 - Dealing with unfeasible updates */
|
|
|
|
if (!feasible && (metric != BABEL_INFINITY) &&
|
|
|
|
(!best || (r == best) || (metric < best->metric)))
|
2017-11-08 21:35:52 +08:00
|
|
|
babel_add_seqno_request(p, e, s->router_id, s->seqno + 1, 0, nbr);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2017-11-28 22:11:41 +08:00
|
|
|
/* Special case - ignore unfeasible update to best route */
|
|
|
|
if (r == best && !feasible && (msg->router_id == r->router_id))
|
|
|
|
return;
|
2016-07-19 19:33:02 +08:00
|
|
|
|
2017-11-28 22:11:41 +08:00
|
|
|
r->expires = current_time() + BABEL_ROUTE_EXPIRY_FACTOR(msg->interval);
|
|
|
|
r->refresh_time = current_time() + BABEL_ROUTE_REFRESH_FACTOR(msg->interval);
|
2016-07-19 19:33:02 +08:00
|
|
|
|
2017-11-28 22:11:41 +08:00
|
|
|
/* No further processing if there is no change */
|
|
|
|
if ((r->feasible == feasible) && (r->seqno == msg->seqno) &&
|
|
|
|
(r->metric == metric) && (r->advert_metric == msg->metric) &&
|
|
|
|
(r->router_id == msg->router_id) && ipa_equal(r->next_hop, msg->next_hop))
|
|
|
|
return;
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2017-11-28 22:11:41 +08:00
|
|
|
/* Last paragraph above - update the entry */
|
2022-04-21 06:57:23 +08:00
|
|
|
babel_update_metric(p, r, metric);
|
2017-11-28 22:11:41 +08:00
|
|
|
r->feasible = feasible;
|
|
|
|
r->seqno = msg->seqno;
|
|
|
|
r->advert_metric = msg->metric;
|
|
|
|
r->router_id = msg->router_id;
|
|
|
|
r->next_hop = msg->next_hop;
|
2017-11-08 21:35:52 +08:00
|
|
|
|
2017-11-28 22:11:41 +08:00
|
|
|
/* If received update satisfies seqno request, we send triggered updates */
|
|
|
|
if (babel_satisfy_seqno_request(p, e, msg->router_id, msg->seqno))
|
|
|
|
{
|
|
|
|
babel_trigger_update(p);
|
|
|
|
e->updated = current_time();
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
|
2017-11-28 22:11:41 +08:00
|
|
|
babel_select_route(p, e, r);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
babel_handle_route_request(union babel_msg *m, struct babel_iface *ifa)
|
|
|
|
{
|
|
|
|
struct babel_proto *p = ifa->proto;
|
|
|
|
struct babel_msg_route_request *msg = &m->route_request;
|
|
|
|
|
|
|
|
/* RFC 6126 3.8.1.1 */
|
|
|
|
|
|
|
|
/* Wildcard request - full update on the interface */
|
|
|
|
if (msg->full)
|
|
|
|
{
|
|
|
|
TRACE(D_PACKETS, "Handling wildcard route request");
|
|
|
|
ifa->want_triggered = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-10 07:11:26 +08:00
|
|
|
TRACE(D_PACKETS, "Handling route request for %N", &msg->net);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
/* Non-wildcard request - see if we have an entry for the route.
|
|
|
|
If not, send a retraction, otherwise send an update. */
|
2016-12-10 07:11:26 +08:00
|
|
|
struct babel_entry *e = babel_find_entry(p, &msg->net);
|
2016-04-29 00:01:40 +08:00
|
|
|
if (!e)
|
|
|
|
{
|
2016-12-10 07:11:26 +08:00
|
|
|
babel_send_retraction(ifa, &msg->net);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
babel_trigger_iface_update(ifa);
|
2017-10-13 18:34:08 +08:00
|
|
|
e->updated = current_time();
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
babel_handle_seqno_request(union babel_msg *m, struct babel_iface *ifa)
|
|
|
|
{
|
|
|
|
struct babel_proto *p = ifa->proto;
|
|
|
|
struct babel_msg_seqno_request *msg = &m->seqno_request;
|
|
|
|
|
|
|
|
/* RFC 6126 3.8.1.2 */
|
|
|
|
|
2016-12-10 07:11:26 +08:00
|
|
|
TRACE(D_PACKETS, "Handling seqno request for %N router-id %lR seqno %d hop count %d",
|
|
|
|
&msg->net, msg->router_id, msg->seqno, msg->hop_count);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
/* Ignore if we have no such entry or entry has infinite metric */
|
2016-12-10 07:11:26 +08:00
|
|
|
struct babel_entry *e = babel_find_entry(p, &msg->net);
|
2017-11-28 22:11:41 +08:00
|
|
|
if (!e || !e->valid || (e->metric == BABEL_INFINITY))
|
2016-04-29 00:01:40 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Trigger update on incoming interface if we have a selected route with
|
|
|
|
different router id or seqno no smaller than requested */
|
2017-11-28 22:11:41 +08:00
|
|
|
if ((e->router_id != msg->router_id) || ge_mod64k(e->seqno, msg->seqno))
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
|
|
|
babel_trigger_iface_update(ifa);
|
2017-10-13 18:34:08 +08:00
|
|
|
e->updated = current_time();
|
2016-04-29 00:01:40 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Seqno is larger; check if we own the router id */
|
|
|
|
if (msg->router_id == p->router_id)
|
|
|
|
{
|
2017-10-14 01:34:34 +08:00
|
|
|
/* Ours; seqno increase and trigger global update */
|
|
|
|
p->update_seqno_inc = 1;
|
2016-04-29 00:01:40 +08:00
|
|
|
babel_trigger_update(p);
|
|
|
|
}
|
2017-11-08 21:35:52 +08:00
|
|
|
else if (msg->hop_count > 1)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
|
|
|
/* Not ours; forward if TTL allows it */
|
2017-11-08 21:35:52 +08:00
|
|
|
|
|
|
|
/* Find best admissible route */
|
|
|
|
struct babel_route *r, *best1 = NULL, *best2 = NULL;
|
|
|
|
WALK_LIST(r, e->routes)
|
2017-11-28 22:11:41 +08:00
|
|
|
if ((r->router_id == msg->router_id) && !ipa_equal(r->neigh->addr, msg->sender))
|
2017-11-08 21:35:52 +08:00
|
|
|
{
|
|
|
|
/* Find best feasible route */
|
2017-11-28 22:11:41 +08:00
|
|
|
if ((!best1 || r->metric < best1->metric) && r->feasible)
|
2017-11-08 21:35:52 +08:00
|
|
|
best1 = r;
|
|
|
|
|
|
|
|
/* Find best not necessary feasible route */
|
|
|
|
if (!best2 || r->metric < best2->metric)
|
|
|
|
best2 = r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If no route is found, do nothing */
|
|
|
|
r = best1 ?: best2;
|
|
|
|
if (!r)
|
|
|
|
return;
|
|
|
|
|
|
|
|
babel_add_seqno_request(p, e, msg->router_id, msg->seqno, msg->hop_count-1, r->neigh);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-17 21:04:16 +08:00
|
|
|
/*
|
|
|
|
* Authentication functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* babel_auth_reset_index - Reset authentication index on interface
|
|
|
|
* @ifa: Interface to reset
|
|
|
|
*
|
|
|
|
* This function resets the authentication index and packet counter for an
|
|
|
|
* interface, and should be called on interface configuration, or when the
|
|
|
|
* packet counter overflows.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
babel_auth_reset_index(struct babel_iface *ifa)
|
|
|
|
{
|
|
|
|
random_bytes(ifa->auth_index, BABEL_AUTH_INDEX_LEN);
|
|
|
|
ifa->auth_pc = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-06-06 21:22:59 +08:00
|
|
|
babel_auth_send_challenge_request(struct babel_iface *ifa, struct babel_neighbor *n)
|
2021-04-17 21:04:16 +08:00
|
|
|
{
|
|
|
|
struct babel_proto *p = ifa->proto;
|
|
|
|
union babel_msg msg = {};
|
|
|
|
|
2021-06-06 21:22:59 +08:00
|
|
|
TRACE(D_PACKETS, "Sending challenge request to %I on %s",
|
2021-04-17 21:04:16 +08:00
|
|
|
n->addr, ifa->ifname);
|
|
|
|
|
|
|
|
random_bytes(n->auth_nonce, BABEL_AUTH_NONCE_LEN);
|
|
|
|
n->auth_nonce_expiry = current_time() + BABEL_AUTH_CHALLENGE_TIMEOUT;
|
|
|
|
n->auth_next_challenge = current_time() + BABEL_AUTH_CHALLENGE_INTERVAL;
|
|
|
|
|
2021-06-06 21:22:59 +08:00
|
|
|
msg.type = BABEL_TLV_CHALLENGE_REQUEST;
|
2021-04-17 21:04:16 +08:00
|
|
|
msg.challenge.nonce_len = BABEL_AUTH_NONCE_LEN;
|
|
|
|
msg.challenge.nonce = n->auth_nonce;
|
|
|
|
|
|
|
|
babel_send_unicast(&msg, ifa, n->addr);
|
|
|
|
}
|
|
|
|
|
2021-06-06 21:22:59 +08:00
|
|
|
static void
|
|
|
|
babel_auth_send_challenge_reply(struct babel_iface *ifa, struct babel_neighbor *n, struct babel_msg_auth *rcv)
|
|
|
|
{
|
|
|
|
struct babel_proto *p = ifa->proto;
|
|
|
|
union babel_msg msg = {};
|
|
|
|
|
|
|
|
TRACE(D_PACKETS, "Sending challenge reply to %I on %s",
|
|
|
|
n->addr, ifa->ifname);
|
|
|
|
|
|
|
|
n->auth_next_challenge_reply = current_time() + BABEL_AUTH_CHALLENGE_INTERVAL;
|
|
|
|
|
|
|
|
msg.type = BABEL_TLV_CHALLENGE_REPLY;
|
|
|
|
msg.challenge.nonce_len = rcv->challenge_len;
|
|
|
|
msg.challenge.nonce = rcv->challenge;
|
|
|
|
|
|
|
|
babel_send_unicast(&msg, ifa, n->addr);
|
|
|
|
}
|
|
|
|
|
2021-04-17 21:04:16 +08:00
|
|
|
int
|
|
|
|
babel_auth_check_pc(struct babel_iface *ifa, struct babel_msg_auth *msg)
|
|
|
|
{
|
|
|
|
struct babel_proto *p = ifa->proto;
|
|
|
|
struct babel_neighbor *n;
|
|
|
|
|
2021-06-06 21:22:59 +08:00
|
|
|
/*
|
|
|
|
* We create the neighbour entry at this point because it makes it easier to
|
2021-04-17 21:04:16 +08:00
|
|
|
* rate limit challenge replies; this is explicitly allowed by the spec (see
|
2021-06-06 21:22:59 +08:00
|
|
|
* Section 4.3).
|
2021-04-17 21:04:16 +08:00
|
|
|
*/
|
|
|
|
n = babel_get_neighbor(ifa, msg->sender);
|
|
|
|
|
2021-06-06 21:22:59 +08:00
|
|
|
/* (3b) Handle challenge request */
|
|
|
|
if (msg->challenge_seen && (n->auth_next_challenge_reply <= current_time()))
|
|
|
|
babel_auth_send_challenge_reply(ifa, n, msg);
|
2021-04-17 21:04:16 +08:00
|
|
|
|
2021-06-06 21:22:59 +08:00
|
|
|
/* (4a) If PC TLV is missing, drop the packet */
|
|
|
|
if (!msg->pc_seen)
|
2021-04-17 21:04:16 +08:00
|
|
|
{
|
2021-06-06 21:22:59 +08:00
|
|
|
LOG_PKT_AUTH("Authentication failed for %I on %s - missing or invalid PC",
|
2021-04-17 21:04:16 +08:00
|
|
|
msg->sender, ifa->ifname);
|
2021-06-06 21:22:59 +08:00
|
|
|
return 0;
|
2021-04-17 21:04:16 +08:00
|
|
|
}
|
|
|
|
|
2021-06-06 21:22:59 +08:00
|
|
|
/* (4b) On successful challenge, update PC and index to current values */
|
2021-04-17 21:04:16 +08:00
|
|
|
if (msg->challenge_reply_seen &&
|
2021-06-06 21:22:59 +08:00
|
|
|
(n->auth_nonce_expiry > current_time()) &&
|
2021-04-17 21:04:16 +08:00
|
|
|
!memcmp(msg->challenge_reply, n->auth_nonce, BABEL_AUTH_NONCE_LEN))
|
|
|
|
{
|
|
|
|
n->auth_index_len = msg->index_len;
|
|
|
|
memcpy(n->auth_index, msg->index, msg->index_len);
|
2021-06-06 21:22:59 +08:00
|
|
|
|
2021-04-17 21:04:16 +08:00
|
|
|
n->auth_pc = msg->pc;
|
2021-06-06 21:22:59 +08:00
|
|
|
n->auth_passed = 1;
|
|
|
|
|
|
|
|
return 1;
|
2021-04-17 21:04:16 +08:00
|
|
|
}
|
|
|
|
|
2021-06-06 21:22:59 +08:00
|
|
|
/* (5) If index differs, send challenge and drop the packet */
|
|
|
|
if ((n->auth_index_len != msg->index_len) ||
|
|
|
|
memcmp(n->auth_index, msg->index, msg->index_len))
|
2021-04-17 21:04:16 +08:00
|
|
|
{
|
2021-06-06 21:22:59 +08:00
|
|
|
TRACE(D_PACKETS, "Index mismatch for packet from %I via %s",
|
|
|
|
msg->sender, ifa->ifname);
|
|
|
|
|
|
|
|
if (n->auth_next_challenge <= current_time())
|
|
|
|
babel_auth_send_challenge_request(ifa, n);
|
|
|
|
|
|
|
|
return 0;
|
2021-04-17 21:04:16 +08:00
|
|
|
}
|
|
|
|
|
2021-06-06 21:22:59 +08:00
|
|
|
/* (6) Index matches; only accept if PC is greater than last */
|
2021-04-17 21:04:16 +08:00
|
|
|
if (n->auth_pc >= msg->pc)
|
|
|
|
{
|
2021-06-06 21:22:59 +08:00
|
|
|
LOG_PKT_AUTH("Authentication failed for %I on %s - "
|
|
|
|
"lower packet counter (rcv %u, old %u)",
|
|
|
|
msg->sender, ifa->ifname, msg->pc, n->auth_pc);
|
|
|
|
return 0;
|
2021-04-17 21:04:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
n->auth_pc = msg->pc;
|
|
|
|
n->auth_passed = 1;
|
2021-06-06 21:22:59 +08:00
|
|
|
|
|
|
|
return 1;
|
2021-04-17 21:04:16 +08:00
|
|
|
}
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2021-06-06 21:22:59 +08:00
|
|
|
|
2016-04-29 00:01:40 +08:00
|
|
|
/*
|
|
|
|
* Babel interfaces
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* babel_iface_timer - Babel interface timer handler
|
|
|
|
* @t: Timer
|
|
|
|
*
|
|
|
|
* This function is called by the per-interface timer and triggers sending of
|
|
|
|
* periodic Hello's and both triggered and periodic updates. Periodic Hello's
|
|
|
|
* and updates are simply handled by setting the next_{hello,regular} variables
|
|
|
|
* on the interface, and triggering an update (and resetting the variable)
|
|
|
|
* whenever 'now' exceeds that value.
|
|
|
|
*
|
|
|
|
* For triggered updates, babel_trigger_iface_update() will set the
|
|
|
|
* want_triggered field on the interface to a timestamp value. If this is set
|
|
|
|
* (and the next_triggered time has passed; this is a rate limiting mechanism),
|
|
|
|
* babel_send_update() will be called with this timestamp as the second
|
|
|
|
* parameter. This causes updates to be send consisting of only the routes that
|
|
|
|
* have changed since the time saved in want_triggered.
|
|
|
|
*
|
|
|
|
* Mostly when an update is triggered, the route being modified will be set to
|
|
|
|
* the value of 'now' at the time of the trigger; the >= comparison for
|
|
|
|
* selecting which routes to send in the update will make sure this is included.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
babel_iface_timer(timer *t)
|
|
|
|
{
|
|
|
|
struct babel_iface *ifa = t->data;
|
|
|
|
struct babel_proto *p = ifa->proto;
|
2017-10-13 18:34:08 +08:00
|
|
|
btime hello_period = ifa->cf->hello_interval;
|
|
|
|
btime update_period = ifa->cf->update_interval;
|
|
|
|
btime now_ = current_time();
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2017-10-13 18:34:08 +08:00
|
|
|
if (now_ >= ifa->next_hello)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
2022-04-22 22:41:52 +08:00
|
|
|
babel_send_hello(ifa, 0);
|
2017-10-13 18:34:08 +08:00
|
|
|
ifa->next_hello += hello_period * (1 + (now_ - ifa->next_hello) / hello_period);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
|
2017-10-13 18:34:08 +08:00
|
|
|
if (now_ >= ifa->next_regular)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
|
|
|
TRACE(D_EVENTS, "Sending regular updates on %s", ifa->ifname);
|
|
|
|
babel_send_update(ifa, 0);
|
2017-10-13 18:34:08 +08:00
|
|
|
ifa->next_regular += update_period * (1 + (now_ - ifa->next_regular) / update_period);
|
2016-04-29 00:01:40 +08:00
|
|
|
ifa->want_triggered = 0;
|
|
|
|
p->triggered = 0;
|
|
|
|
}
|
2017-10-13 18:34:08 +08:00
|
|
|
else if (ifa->want_triggered && (now_ >= ifa->next_triggered))
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
|
|
|
TRACE(D_EVENTS, "Sending triggered updates on %s", ifa->ifname);
|
|
|
|
babel_send_update(ifa, ifa->want_triggered);
|
2017-11-08 21:35:52 +08:00
|
|
|
ifa->next_triggered = now_ + MIN(1 S, update_period / 2);
|
2016-04-29 00:01:40 +08:00
|
|
|
ifa->want_triggered = 0;
|
|
|
|
p->triggered = 0;
|
|
|
|
}
|
|
|
|
|
2017-10-13 18:34:08 +08:00
|
|
|
btime next_event = MIN(ifa->next_hello, ifa->next_regular);
|
|
|
|
if (ifa->want_triggered) next_event = MIN(next_event, ifa->next_triggered);
|
2017-11-29 00:43:20 +08:00
|
|
|
tm_set(ifa->timer, next_event);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
babel_iface_kick_timer(struct babel_iface *ifa)
|
|
|
|
{
|
2017-10-13 18:34:08 +08:00
|
|
|
if (ifa->timer->expires > (current_time() + 100 MS))
|
2017-11-29 00:43:20 +08:00
|
|
|
tm_start(ifa->timer, 100 MS);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
babel_iface_start(struct babel_iface *ifa)
|
|
|
|
{
|
|
|
|
struct babel_proto *p = ifa->proto;
|
|
|
|
|
|
|
|
TRACE(D_EVENTS, "Starting interface %s", ifa->ifname);
|
|
|
|
|
2017-10-13 18:34:08 +08:00
|
|
|
ifa->next_hello = current_time() + (random() % ifa->cf->hello_interval);
|
|
|
|
ifa->next_regular = current_time() + (random() % ifa->cf->update_interval);
|
2017-11-08 21:35:52 +08:00
|
|
|
ifa->next_triggered = current_time() + MIN(1 S, ifa->cf->update_interval / 2);
|
2016-04-29 00:01:40 +08:00
|
|
|
ifa->want_triggered = 0; /* We send an immediate update (below) */
|
2017-11-29 00:43:20 +08:00
|
|
|
tm_start(ifa->timer, 100 MS);
|
2016-04-29 00:01:40 +08:00
|
|
|
ifa->up = 1;
|
|
|
|
|
2022-04-22 22:41:52 +08:00
|
|
|
babel_send_hello(ifa, 0);
|
2016-07-19 20:23:41 +08:00
|
|
|
babel_send_wildcard_retraction(ifa);
|
2016-04-29 00:01:40 +08:00
|
|
|
babel_send_wildcard_request(ifa);
|
|
|
|
babel_send_update(ifa, 0); /* Full update */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
babel_iface_stop(struct babel_iface *ifa)
|
|
|
|
{
|
|
|
|
struct babel_proto *p = ifa->proto;
|
|
|
|
struct babel_neighbor *nbr;
|
|
|
|
struct babel_route *r;
|
|
|
|
node *n;
|
|
|
|
|
|
|
|
TRACE(D_EVENTS, "Stopping interface %s", ifa->ifname);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Rather than just flushing the neighbours, we set the metric of their routes
|
|
|
|
* to infinity. This allows us to keep the neighbour hello state for when the
|
|
|
|
* interface comes back up. The routes will also be kept until they expire.
|
|
|
|
*/
|
|
|
|
WALK_LIST(nbr, ifa->neigh_list)
|
|
|
|
{
|
|
|
|
WALK_LIST(n, nbr->routes)
|
|
|
|
{
|
|
|
|
r = SKIP_BACK(struct babel_route, neigh_route, n);
|
2017-11-28 22:11:41 +08:00
|
|
|
babel_retract_route(p, r);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-29 00:43:20 +08:00
|
|
|
tm_stop(ifa->timer);
|
2016-04-29 00:01:40 +08:00
|
|
|
ifa->up = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
babel_iface_link_up(struct babel_iface *ifa)
|
|
|
|
{
|
|
|
|
return !ifa->cf->check_link || (ifa->iface->flags & IF_LINK_UP);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
babel_iface_update_state(struct babel_iface *ifa)
|
|
|
|
{
|
|
|
|
int up = ifa->sk && babel_iface_link_up(ifa);
|
|
|
|
|
|
|
|
if (up == ifa->up)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (up)
|
|
|
|
babel_iface_start(ifa);
|
|
|
|
else
|
|
|
|
babel_iface_stop(ifa);
|
|
|
|
}
|
|
|
|
|
2018-11-28 23:43:17 +08:00
|
|
|
static void
|
|
|
|
babel_iface_update_addr4(struct babel_iface *ifa)
|
|
|
|
{
|
|
|
|
struct babel_proto *p = ifa->proto;
|
|
|
|
|
|
|
|
ip_addr addr4 = ifa->iface->addr4 ? ifa->iface->addr4->ip : IPA_NONE;
|
|
|
|
ifa->next_hop_ip4 = ipa_nonzero(ifa->cf->next_hop_ip4) ? ifa->cf->next_hop_ip4 : addr4;
|
|
|
|
|
|
|
|
if (ipa_zero(ifa->next_hop_ip4) && p->ip4_channel)
|
|
|
|
log(L_WARN "%s: Missing IPv4 next hop address for %s", p->p.name, ifa->ifname);
|
|
|
|
|
|
|
|
if (ifa->up)
|
|
|
|
babel_iface_kick_timer(ifa);
|
|
|
|
}
|
|
|
|
|
2016-04-29 00:01:40 +08:00
|
|
|
static void
|
|
|
|
babel_iface_update_buffers(struct babel_iface *ifa)
|
|
|
|
{
|
|
|
|
if (!ifa->sk)
|
|
|
|
return;
|
|
|
|
|
|
|
|
uint mtu = MAX(BABEL_MIN_MTU, ifa->iface->mtu);
|
|
|
|
uint rbsize = ifa->cf->rx_buffer ?: mtu;
|
|
|
|
uint tbsize = ifa->cf->tx_length ?: mtu;
|
|
|
|
rbsize = MAX(rbsize, tbsize);
|
|
|
|
|
|
|
|
sk_set_rbsize(ifa->sk, rbsize);
|
|
|
|
sk_set_tbsize(ifa->sk, tbsize);
|
|
|
|
|
|
|
|
ifa->tx_length = tbsize - BABEL_OVERHEAD;
|
2021-04-17 21:04:16 +08:00
|
|
|
|
|
|
|
babel_auth_set_tx_overhead(ifa);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct babel_iface*
|
|
|
|
babel_find_iface(struct babel_proto *p, struct iface *what)
|
|
|
|
{
|
|
|
|
struct babel_iface *ifa;
|
|
|
|
|
|
|
|
WALK_LIST (ifa, p->interfaces)
|
|
|
|
if (ifa->iface == what)
|
|
|
|
return ifa;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
babel_iface_locked(struct object_lock *lock)
|
|
|
|
{
|
|
|
|
struct babel_iface *ifa = lock->data;
|
|
|
|
struct babel_proto *p = ifa->proto;
|
|
|
|
|
|
|
|
if (!babel_open_socket(ifa))
|
|
|
|
{
|
|
|
|
log(L_ERR "%s: Cannot open socket for %s", p->p.name, ifa->iface->name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
babel_iface_update_buffers(ifa);
|
|
|
|
babel_iface_update_state(ifa);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
babel_add_iface(struct babel_proto *p, struct iface *new, struct babel_iface_config *ic)
|
|
|
|
{
|
|
|
|
struct babel_iface *ifa;
|
|
|
|
|
|
|
|
TRACE(D_EVENTS, "Adding interface %s", new->name);
|
|
|
|
|
|
|
|
pool *pool = rp_new(p->p.pool, new->name);
|
|
|
|
|
|
|
|
ifa = mb_allocz(pool, sizeof(struct babel_iface));
|
|
|
|
ifa->proto = p;
|
|
|
|
ifa->iface = new;
|
|
|
|
ifa->cf = ic;
|
|
|
|
ifa->pool = pool;
|
|
|
|
ifa->ifname = new->name;
|
2017-12-07 20:06:01 +08:00
|
|
|
ifa->addr = new->llv6->ip;
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
add_tail(&p->interfaces, NODE ifa);
|
|
|
|
|
2017-12-07 20:06:01 +08:00
|
|
|
ip_addr addr4 = new->addr4 ? new->addr4->ip : IPA_NONE;
|
2017-06-08 18:18:16 +08:00
|
|
|
ifa->next_hop_ip4 = ipa_nonzero(ic->next_hop_ip4) ? ic->next_hop_ip4 : addr4;
|
|
|
|
ifa->next_hop_ip6 = ipa_nonzero(ic->next_hop_ip6) ? ic->next_hop_ip6 : ifa->addr;
|
|
|
|
|
|
|
|
if (ipa_zero(ifa->next_hop_ip4) && p->ip4_channel)
|
2018-06-13 21:22:29 +08:00
|
|
|
log(L_WARN "%s: Missing IPv4 next hop address for %s", p->p.name, new->name);
|
2017-06-08 18:18:16 +08:00
|
|
|
|
2016-04-29 00:01:40 +08:00
|
|
|
init_list(&ifa->neigh_list);
|
|
|
|
ifa->hello_seqno = 1;
|
|
|
|
|
2021-04-17 21:04:16 +08:00
|
|
|
if (ic->auth_type != BABEL_AUTH_NONE)
|
|
|
|
babel_auth_reset_index(ifa);
|
|
|
|
|
2017-11-29 00:43:20 +08:00
|
|
|
ifa->timer = tm_new_init(ifa->pool, babel_iface_timer, ifa, 0, 0);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
init_list(&ifa->msg_queue);
|
2018-10-01 21:55:23 +08:00
|
|
|
ifa->send_event = ev_new_init(ifa->pool, babel_send_queue, ifa);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
struct object_lock *lock = olock_new(ifa->pool);
|
|
|
|
lock->type = OBJLOCK_UDP;
|
|
|
|
lock->addr = IP6_BABEL_ROUTERS;
|
|
|
|
lock->port = ifa->cf->port;
|
|
|
|
lock->iface = ifa->iface;
|
|
|
|
lock->hook = babel_iface_locked;
|
|
|
|
lock->data = ifa;
|
|
|
|
|
|
|
|
olock_acquire(lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
babel_remove_iface(struct babel_proto *p, struct babel_iface *ifa)
|
|
|
|
{
|
|
|
|
TRACE(D_EVENTS, "Removing interface %s", ifa->iface->name);
|
|
|
|
|
|
|
|
struct babel_neighbor *n;
|
|
|
|
WALK_LIST_FIRST(n, ifa->neigh_list)
|
2017-10-25 23:14:08 +08:00
|
|
|
babel_flush_neighbor(p, n);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
rem_node(NODE ifa);
|
|
|
|
|
|
|
|
rfree(ifa->pool); /* contains ifa itself, locks, socket, etc */
|
|
|
|
}
|
|
|
|
|
2021-05-11 02:09:31 +08:00
|
|
|
static int
|
|
|
|
iface_is_valid(struct babel_proto *p, struct iface *iface)
|
|
|
|
{
|
|
|
|
if (!(iface->flags & IF_MULTICAST))
|
|
|
|
{
|
|
|
|
log(L_ERR "%s: Interface %s does not support multicast",
|
|
|
|
p->p.name, iface->name);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-04-29 00:01:40 +08:00
|
|
|
static void
|
|
|
|
babel_if_notify(struct proto *P, unsigned flags, struct iface *iface)
|
|
|
|
{
|
|
|
|
struct babel_proto *p = (void *) P;
|
|
|
|
struct babel_config *cf = (void *) P->cf;
|
2018-11-28 23:43:17 +08:00
|
|
|
struct babel_iface *ifa = babel_find_iface(p, iface);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
if (iface->flags & IF_IGNORE)
|
|
|
|
return;
|
|
|
|
|
2018-11-28 23:43:17 +08:00
|
|
|
/* Add, remove or restart interface */
|
|
|
|
if (flags & (IF_CHANGE_UPDOWN | IF_CHANGE_LLV6))
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
2018-11-28 23:43:17 +08:00
|
|
|
if (ifa)
|
|
|
|
babel_remove_iface(p, ifa);
|
|
|
|
|
|
|
|
if (!(iface->flags & IF_UP))
|
|
|
|
return;
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2017-12-07 20:06:01 +08:00
|
|
|
/* Ignore ifaces without link-local address */
|
|
|
|
if (!iface->llv6)
|
|
|
|
return;
|
|
|
|
|
2018-11-28 23:43:17 +08:00
|
|
|
struct babel_iface_config *ic = (void *) iface_patt_find(&cf->iface_list, iface, NULL);
|
2021-05-11 02:09:31 +08:00
|
|
|
|
|
|
|
if (ic && iface_is_valid(p, iface))
|
2016-04-29 00:01:40 +08:00
|
|
|
babel_add_iface(p, iface, ic);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ifa)
|
|
|
|
return;
|
|
|
|
|
2018-11-28 23:43:17 +08:00
|
|
|
if (flags & IF_CHANGE_ADDR4)
|
|
|
|
babel_iface_update_addr4(ifa);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
if (flags & IF_CHANGE_MTU)
|
|
|
|
babel_iface_update_buffers(ifa);
|
|
|
|
|
|
|
|
if (flags & IF_CHANGE_LINK)
|
|
|
|
babel_iface_update_state(ifa);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
babel_reconfigure_iface(struct babel_proto *p, struct babel_iface *ifa, struct babel_iface_config *new)
|
|
|
|
{
|
|
|
|
struct babel_iface_config *old = ifa->cf;
|
|
|
|
|
|
|
|
/* Change of these options would require to reset the iface socket */
|
|
|
|
if ((new->port != old->port) ||
|
|
|
|
(new->tx_tos != old->tx_tos) ||
|
|
|
|
(new->tx_priority != old->tx_priority))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
TRACE(D_EVENTS, "Reconfiguring interface %s", ifa->iface->name);
|
|
|
|
|
|
|
|
ifa->cf = new;
|
|
|
|
|
2017-12-07 20:06:01 +08:00
|
|
|
ip_addr addr4 = ifa->iface->addr4 ? ifa->iface->addr4->ip : IPA_NONE;
|
|
|
|
ifa->next_hop_ip4 = ipa_nonzero(new->next_hop_ip4) ? new->next_hop_ip4 : addr4;
|
2017-06-08 18:18:16 +08:00
|
|
|
ifa->next_hop_ip6 = ipa_nonzero(new->next_hop_ip6) ? new->next_hop_ip6 : ifa->addr;
|
|
|
|
|
2021-06-06 21:22:59 +08:00
|
|
|
babel_iface_update_buffers(ifa);
|
|
|
|
|
|
|
|
if ((new->auth_type != BABEL_AUTH_NONE) && (new->auth_type != old->auth_type))
|
2021-04-17 21:04:16 +08:00
|
|
|
babel_auth_reset_index(ifa);
|
|
|
|
|
2017-06-08 18:18:16 +08:00
|
|
|
if (ipa_zero(ifa->next_hop_ip4) && p->ip4_channel)
|
2018-06-13 21:22:29 +08:00
|
|
|
log(L_WARN "%s: Missing IPv4 next hop address for %s", p->p.name, ifa->ifname);
|
2017-06-08 18:18:16 +08:00
|
|
|
|
2017-10-13 18:34:08 +08:00
|
|
|
if (ifa->next_hello > (current_time() + new->hello_interval))
|
|
|
|
ifa->next_hello = current_time() + (random() % new->hello_interval);
|
2016-07-20 21:55:45 +08:00
|
|
|
|
2017-10-13 18:34:08 +08:00
|
|
|
if (ifa->next_regular > (current_time() + new->update_interval))
|
|
|
|
ifa->next_regular = current_time() + (random() % new->update_interval);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
if (new->check_link != old->check_link)
|
|
|
|
babel_iface_update_state(ifa);
|
|
|
|
|
|
|
|
if (ifa->up)
|
|
|
|
babel_iface_kick_timer(ifa);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
babel_reconfigure_ifaces(struct babel_proto *p, struct babel_config *cf)
|
|
|
|
{
|
|
|
|
struct iface *iface;
|
|
|
|
|
|
|
|
WALK_LIST(iface, iface_list)
|
|
|
|
{
|
2017-12-07 20:06:01 +08:00
|
|
|
if (!(iface->flags & IF_UP))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Ignore ifaces without link-local address */
|
|
|
|
if (!iface->llv6)
|
2016-04-29 00:01:40 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
struct babel_iface *ifa = babel_find_iface(p, iface);
|
|
|
|
struct babel_iface_config *ic = (void *) iface_patt_find(&cf->iface_list, iface, NULL);
|
|
|
|
|
2022-02-27 10:10:38 +08:00
|
|
|
if (ic && !iface_is_valid(p, iface))
|
2021-05-11 02:09:31 +08:00
|
|
|
ic = NULL;
|
|
|
|
|
2016-04-29 00:01:40 +08:00
|
|
|
if (ifa && ic)
|
|
|
|
{
|
|
|
|
if (babel_reconfigure_iface(p, ifa, ic))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Hard restart */
|
|
|
|
log(L_INFO "%s: Restarting interface %s", p->p.name, ifa->iface->name);
|
|
|
|
babel_remove_iface(p, ifa);
|
|
|
|
babel_add_iface(p, iface, ic);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ifa && !ic)
|
|
|
|
babel_remove_iface(p, ifa);
|
|
|
|
|
|
|
|
if (!ifa && ic)
|
|
|
|
babel_add_iface(p, iface, ic);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Debugging and info output functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
babel_dump_source(struct babel_source *s)
|
|
|
|
{
|
2017-10-13 18:34:08 +08:00
|
|
|
debug("Source router_id %lR seqno %d metric %d expires %t\n",
|
|
|
|
s->router_id, s->seqno, s->metric,
|
|
|
|
s->expires ? s->expires - current_time() : 0);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
babel_dump_route(struct babel_route *r)
|
|
|
|
{
|
2017-10-13 18:34:08 +08:00
|
|
|
debug("Route neigh %I if %s seqno %d metric %d/%d router_id %lR expires %t\n",
|
2017-11-28 22:11:41 +08:00
|
|
|
r->neigh->addr, r->neigh->ifa->ifname, r->seqno, r->advert_metric, r->metric,
|
|
|
|
r->router_id, r->expires ? r->expires - current_time() : 0);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
babel_dump_entry(struct babel_entry *e)
|
|
|
|
{
|
|
|
|
struct babel_source *s;
|
|
|
|
struct babel_route *r;
|
|
|
|
|
2016-12-10 07:11:26 +08:00
|
|
|
debug("Babel: Entry %N:\n", e->n.addr);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
WALK_LIST(s,e->sources)
|
|
|
|
{ debug(" "); babel_dump_source(s); }
|
|
|
|
|
|
|
|
WALK_LIST(r,e->routes)
|
|
|
|
{
|
|
|
|
debug(" ");
|
2017-11-28 22:11:41 +08:00
|
|
|
if (r == e->selected) debug("*");
|
2016-04-29 00:01:40 +08:00
|
|
|
babel_dump_route(r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
babel_dump_neighbor(struct babel_neighbor *n)
|
|
|
|
{
|
2017-10-13 18:34:08 +08:00
|
|
|
debug("Neighbor %I txcost %d hello_map %x next seqno %d expires %t/%t\n",
|
2016-04-29 00:01:40 +08:00
|
|
|
n->addr, n->txcost, n->hello_map, n->next_hello_seqno,
|
2017-10-13 18:34:08 +08:00
|
|
|
n->hello_expiry ? n->hello_expiry - current_time() : 0,
|
|
|
|
n->ihu_expiry ? n->ihu_expiry - current_time() : 0);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
babel_dump_iface(struct babel_iface *ifa)
|
|
|
|
{
|
|
|
|
struct babel_neighbor *n;
|
|
|
|
|
2017-10-13 18:34:08 +08:00
|
|
|
debug("Babel: Interface %s addr %I rxcost %d type %d hello seqno %d intervals %t %t",
|
2016-04-29 00:01:40 +08:00
|
|
|
ifa->ifname, ifa->addr, ifa->cf->rxcost, ifa->cf->type, ifa->hello_seqno,
|
|
|
|
ifa->cf->hello_interval, ifa->cf->update_interval);
|
2017-06-08 18:18:16 +08:00
|
|
|
debug(" next hop v4 %I next hop v6 %I\n", ifa->next_hop_ip4, ifa->next_hop_ip6);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
WALK_LIST(n, ifa->neigh_list)
|
|
|
|
{ debug(" "); babel_dump_neighbor(n); }
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
babel_dump(struct proto *P)
|
|
|
|
{
|
|
|
|
struct babel_proto *p = (struct babel_proto *) P;
|
|
|
|
struct babel_iface *ifa;
|
|
|
|
|
|
|
|
debug("Babel: router id %lR update seqno %d\n", p->router_id, p->update_seqno);
|
|
|
|
|
|
|
|
WALK_LIST(ifa, p->interfaces)
|
|
|
|
babel_dump_iface(ifa);
|
|
|
|
|
2017-06-08 18:18:16 +08:00
|
|
|
FIB_WALK(&p->ip4_rtable, struct babel_entry, e)
|
|
|
|
{
|
|
|
|
babel_dump_entry(e);
|
|
|
|
}
|
|
|
|
FIB_WALK_END;
|
|
|
|
FIB_WALK(&p->ip6_rtable, struct babel_entry, e)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
2016-12-10 07:11:26 +08:00
|
|
|
babel_dump_entry(e);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
FIB_WALK_END;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-05-29 18:08:12 +08:00
|
|
|
babel_get_route_info(rte *rte, byte *buf)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
|
|
|
buf += bsprintf(buf, " (%d/%d) [%lR]", rte->pref, rte->u.babel.metric, rte->u.babel.router_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2019-08-17 19:36:36 +08:00
|
|
|
babel_get_attr(const eattr *a, byte *buf, int buflen UNUSED)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
|
|
|
switch (a->id)
|
|
|
|
{
|
|
|
|
case EA_BABEL_METRIC:
|
|
|
|
bsprintf(buf, "metric: %d", a->u.data);
|
|
|
|
return GA_FULL;
|
|
|
|
|
|
|
|
case EA_BABEL_ROUTER_ID:
|
|
|
|
{
|
|
|
|
u64 rid = 0;
|
|
|
|
memcpy(&rid, a->u.ptr->data, sizeof(u64));
|
|
|
|
bsprintf(buf, "router_id: %lR", rid);
|
|
|
|
return GA_FULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return GA_UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-04-09 04:25:15 +08:00
|
|
|
babel_show_interfaces(struct proto *P, const char *iff)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
|
|
|
struct babel_proto *p = (void *) P;
|
|
|
|
struct babel_iface *ifa = NULL;
|
|
|
|
struct babel_neighbor *nbr = NULL;
|
|
|
|
|
|
|
|
if (p->p.proto_state != PS_UP)
|
|
|
|
{
|
|
|
|
cli_msg(-1023, "%s: is not up", p->p.name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cli_msg(-1023, "%s:", p->p.name);
|
2021-04-17 21:04:16 +08:00
|
|
|
cli_msg(-1023, "%-10s %-6s %-5s %7s %6s %7s %-15s %s",
|
|
|
|
"Interface", "State", "Auth", "RX cost", "Nbrs", "Timer",
|
2017-06-08 18:18:16 +08:00
|
|
|
"Next hop (v4)", "Next hop (v6)");
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
WALK_LIST(ifa, p->interfaces)
|
|
|
|
{
|
|
|
|
if (iff && !patmatch(iff, ifa->iface->name))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int nbrs = 0;
|
|
|
|
WALK_LIST(nbr, ifa->neigh_list)
|
|
|
|
nbrs++;
|
|
|
|
|
2017-10-13 18:34:08 +08:00
|
|
|
btime timer = MIN(ifa->next_regular, ifa->next_hello) - current_time();
|
2021-04-17 21:04:16 +08:00
|
|
|
cli_msg(-1023, "%-10s %-6s %-5s %7u %6u %7t %-15I %I",
|
2017-06-08 18:18:16 +08:00
|
|
|
ifa->iface->name, (ifa->up ? "Up" : "Down"),
|
2021-04-17 21:04:16 +08:00
|
|
|
(ifa->cf->auth_type == BABEL_AUTH_MAC ?
|
|
|
|
(ifa->cf->auth_permissive ? "Perm" : "Yes") : "No"),
|
2017-06-08 18:18:16 +08:00
|
|
|
ifa->cf->rxcost, nbrs, MAX(timer, 0),
|
|
|
|
ifa->next_hop_ip4, ifa->next_hop_ip6);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-04-09 04:25:15 +08:00
|
|
|
babel_show_neighbors(struct proto *P, const char *iff)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
|
|
|
struct babel_proto *p = (void *) P;
|
|
|
|
struct babel_iface *ifa = NULL;
|
|
|
|
struct babel_neighbor *n = NULL;
|
|
|
|
struct babel_route *r = NULL;
|
|
|
|
|
|
|
|
if (p->p.proto_state != PS_UP)
|
|
|
|
{
|
|
|
|
cli_msg(-1024, "%s: is not up", p->p.name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cli_msg(-1024, "%s:", p->p.name);
|
2022-04-18 07:03:01 +08:00
|
|
|
cli_msg(-1024, "%-25s %-10s %6s %6s %6s %7s %4s %11s",
|
|
|
|
"IP address", "Interface", "Metric", "Routes", "Hellos", "Expires", "Auth", "RTT");
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
WALK_LIST(ifa, p->interfaces)
|
|
|
|
{
|
|
|
|
if (iff && !patmatch(iff, ifa->iface->name))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
WALK_LIST(n, ifa->neigh_list)
|
|
|
|
{
|
|
|
|
int rts = 0;
|
|
|
|
WALK_LIST(r, n->routes)
|
|
|
|
rts++;
|
|
|
|
|
2017-10-13 18:34:08 +08:00
|
|
|
uint hellos = u32_popcount(n->hello_map);
|
2021-06-10 01:31:55 +08:00
|
|
|
btime timer = (n->hello_expiry ?: n->init_expiry) - current_time();
|
2022-04-18 07:03:01 +08:00
|
|
|
cli_msg(-1024, "%-25I %-10s %6u %6u %6u %7t %-4s %5u.%03ums",
|
2021-04-17 21:04:16 +08:00
|
|
|
n->addr, ifa->iface->name, n->cost, rts, hellos, MAX(timer, 0),
|
2022-04-18 07:03:01 +08:00
|
|
|
n->auth_passed ? "Yes" : "No",
|
|
|
|
n->srtt/1000, n->srtt%1000);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-08 18:18:16 +08:00
|
|
|
static void
|
2018-02-13 23:39:36 +08:00
|
|
|
babel_show_entries_(struct babel_proto *p, struct fib *rtable)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
2018-02-13 23:39:36 +08:00
|
|
|
int width = babel_sadr_enabled(p) ? -54 : -24;
|
|
|
|
|
2017-06-08 18:18:16 +08:00
|
|
|
FIB_WALK(rtable, struct babel_entry, e)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
2017-11-28 22:11:41 +08:00
|
|
|
struct babel_route *r = NULL;
|
|
|
|
uint rts = 0, srcs = 0;
|
|
|
|
node *n;
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2017-11-28 22:11:41 +08:00
|
|
|
WALK_LIST(n, e->routes)
|
|
|
|
rts++;
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2017-11-28 22:11:41 +08:00
|
|
|
WALK_LIST(n, e->sources)
|
|
|
|
srcs++;
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2017-11-28 22:11:41 +08:00
|
|
|
if (e->valid)
|
2018-02-13 23:39:36 +08:00
|
|
|
cli_msg(-1025, "%-*N %-23lR %6u %5u %7u %7u", width,
|
2017-11-28 22:11:41 +08:00
|
|
|
e->n.addr, e->router_id, e->metric, e->seqno, rts, srcs);
|
|
|
|
else if (r = e->selected)
|
2018-02-13 23:39:36 +08:00
|
|
|
cli_msg(-1025, "%-*N %-23lR %6u %5u %7u %7u", width,
|
2017-11-28 22:11:41 +08:00
|
|
|
e->n.addr, r->router_id, r->metric, r->seqno, rts, srcs);
|
2016-04-29 00:01:40 +08:00
|
|
|
else
|
2018-02-13 23:39:36 +08:00
|
|
|
cli_msg(-1025, "%-*N %-23s %6s %5s %7u %7u", width,
|
2017-11-28 22:11:41 +08:00
|
|
|
e->n.addr, "<none>", "-", "-", rts, srcs);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
FIB_WALK_END;
|
2017-06-08 18:18:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
babel_show_entries(struct proto *P)
|
|
|
|
{
|
|
|
|
struct babel_proto *p = (void *) P;
|
2018-02-13 23:39:36 +08:00
|
|
|
int width = babel_sadr_enabled(p) ? -54 : -24;
|
2017-06-08 18:18:16 +08:00
|
|
|
|
|
|
|
if (p->p.proto_state != PS_UP)
|
|
|
|
{
|
|
|
|
cli_msg(-1025, "%s: is not up", p->p.name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cli_msg(-1025, "%s:", p->p.name);
|
2018-02-13 23:39:36 +08:00
|
|
|
cli_msg(-1025, "%-*s %-23s %6s %5s %7s %7s", width,
|
2017-11-28 22:11:41 +08:00
|
|
|
"Prefix", "Router ID", "Metric", "Seqno", "Routes", "Sources");
|
2017-06-08 18:18:16 +08:00
|
|
|
|
|
|
|
babel_show_entries_(p, &p->ip4_rtable);
|
|
|
|
babel_show_entries_(p, &p->ip6_rtable);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
|
2017-11-28 22:11:41 +08:00
|
|
|
static void
|
2018-02-13 23:39:36 +08:00
|
|
|
babel_show_routes_(struct babel_proto *p, struct fib *rtable)
|
2017-11-28 22:11:41 +08:00
|
|
|
{
|
2018-02-13 23:39:36 +08:00
|
|
|
int width = babel_sadr_enabled(p) ? -54 : -24;
|
|
|
|
|
2017-11-28 22:11:41 +08:00
|
|
|
FIB_WALK(rtable, struct babel_entry, e)
|
|
|
|
{
|
|
|
|
struct babel_route *r;
|
|
|
|
WALK_LIST(r, e->routes)
|
|
|
|
{
|
|
|
|
char c = (r == e->selected) ? '*' : (r->feasible ? '+' : ' ');
|
|
|
|
btime time = r->expires ? r->expires - current_time() : 0;
|
2018-02-13 23:39:36 +08:00
|
|
|
cli_msg(-1025, "%-*N %-25I %-10s %5u %c %5u %7t", width,
|
2017-11-28 22:11:41 +08:00
|
|
|
e->n.addr, r->next_hop, r->neigh->ifa->ifname,
|
|
|
|
r->metric, c, r->seqno, MAX(time, 0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FIB_WALK_END;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
babel_show_routes(struct proto *P)
|
|
|
|
{
|
|
|
|
struct babel_proto *p = (void *) P;
|
2018-02-13 23:39:36 +08:00
|
|
|
int width = babel_sadr_enabled(p) ? -54 : -24;
|
2017-11-28 22:11:41 +08:00
|
|
|
|
|
|
|
if (p->p.proto_state != PS_UP)
|
|
|
|
{
|
|
|
|
cli_msg(-1025, "%s: is not up", p->p.name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cli_msg(-1025, "%s:", p->p.name);
|
2018-02-13 23:39:36 +08:00
|
|
|
cli_msg(-1025, "%-*s %-25s %-9s %6s F %5s %7s", width,
|
2017-11-28 22:11:41 +08:00
|
|
|
"Prefix", "Nexthop", "Interface", "Metric", "Seqno", "Expires");
|
|
|
|
|
|
|
|
babel_show_routes_(p, &p->ip4_rtable);
|
|
|
|
babel_show_routes_(p, &p->ip6_rtable);
|
|
|
|
}
|
|
|
|
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Babel protocol glue
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* babel_timer - global timer hook
|
|
|
|
* @t: Timer
|
|
|
|
*
|
|
|
|
* This function is called by the global protocol instance timer and handles
|
|
|
|
* expiration of routes and neighbours as well as pruning of the seqno request
|
|
|
|
* cache.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
babel_timer(timer *t)
|
|
|
|
{
|
|
|
|
struct babel_proto *p = t->data;
|
|
|
|
|
|
|
|
babel_expire_routes(p);
|
|
|
|
babel_expire_neighbors(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
babel_kick_timer(struct babel_proto *p)
|
|
|
|
{
|
2017-10-13 18:34:08 +08:00
|
|
|
if (p->timer->expires > (current_time() + 100 MS))
|
2017-11-29 00:43:20 +08:00
|
|
|
tm_start(p->timer, 100 MS);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
Terminology cleanup: The import_control hook is now called preexport.
Once upon a time, far far away, there were the old Bird developers
discussing what direction of route flow shall be called import and
export. They decided to say "import to protocol" and "export to table"
when speaking about a protocol. When speaking about a table, they
spoke about "importing to table" and "exporting to protocol".
The latter terminology was adopted in configuration, then also the
bird CLI in commit ea2ae6dd0 started to use it (in year 2009). Now
it's 2018 and the terminology is the latter. Import is from protocol to
table, export is from table to protocol. Anyway, there was still an
import_control hook which executed right before route export.
One thing is funny. There are two commits in April 1999 with just two
minutes between them. The older announces the final settlement
on config terminology, the newer uses the other definition. Let's see
their commit messages as the git-log tool shows them (the newer first):
commit 9e0e485e50ea74c4f1c5cb65bdfe6ce819c2cee2
Author: Martin Mares <mj@ucw.cz>
Date: Mon Apr 5 20:17:59 1999 +0000
Added some new protocol hooks (look at the comments for better explanation):
make_tmp_attrs Convert inline attributes to ea_list
store_tmp_attrs Convert ea_list to inline attributes
import_control Pre-import decisions
commit 5056c559c4eb253a4eee10cf35b694faec5265eb
Author: Martin Mares <mj@ucw.cz>
Date: Mon Apr 5 20:15:31 1999 +0000
Changed syntax of attaching filters to protocols to hopefully the final
version:
EXPORT <filter-spec> for outbound routes (i.e., those announced
by BIRD to the rest of the world).
IMPORT <filter-spec> for inbound routes (i.e., those imported
by BIRD from the rest of the world).
where <filter-spec> is one of:
ALL pass all routes
NONE drop all routes
FILTER <name> use named filter
FILTER { <filter> } use explicitly defined filter
For all protocols, the default is IMPORT ALL, EXPORT NONE. This includes
the kernel protocol, so that you need to add EXPORT ALL to get the previous
configuration of kernel syncer (as usually, see doc/bird.conf.example for
a bird.conf example :)).
Let's say RIP to this almost 19-years-old inconsistency. For now, if you
import a route, it is always from protocol to table. If you export a
route, it is always from table to protocol.
And they lived happily ever after.
2018-02-14 20:42:53 +08:00
|
|
|
babel_preexport(struct proto *P, struct rte **new, struct linpool *pool UNUSED)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
2018-05-29 18:08:12 +08:00
|
|
|
struct rta *a = (*new)->attrs;
|
2017-11-28 22:11:41 +08:00
|
|
|
|
|
|
|
/* Reject our own unreachable routes */
|
2018-05-29 18:08:12 +08:00
|
|
|
if ((a->dest == RTD_UNREACHABLE) && (a->src->proto == P))
|
2017-11-28 22:11:41 +08:00
|
|
|
return -1;
|
|
|
|
|
2016-04-29 00:01:40 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-15 00:22:22 +08:00
|
|
|
static void
|
2016-04-29 00:01:40 +08:00
|
|
|
babel_make_tmp_attrs(struct rte *rt, struct linpool *pool)
|
|
|
|
{
|
2019-03-15 00:22:22 +08:00
|
|
|
struct adata *id = lp_alloc_adata(pool, sizeof(u64));
|
|
|
|
memcpy(id->data, &rt->u.babel.router_id, sizeof(u64));
|
|
|
|
|
|
|
|
rte_init_tmp_attrs(rt, pool, 2);
|
|
|
|
rte_make_tmp_attr(rt, EA_BABEL_METRIC, EAF_TYPE_INT, rt->u.babel.metric);
|
|
|
|
rte_make_tmp_attr(rt, EA_BABEL_ROUTER_ID, EAF_TYPE_OPAQUE, (uintptr_t) id);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-03-15 00:22:22 +08:00
|
|
|
babel_store_tmp_attrs(struct rte *rt, struct linpool *pool)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
2019-03-15 00:22:22 +08:00
|
|
|
rte_init_tmp_attrs(rt, pool, 2);
|
|
|
|
rt->u.babel.metric = rte_store_tmp_attr(rt, EA_BABEL_METRIC);
|
|
|
|
|
|
|
|
/* EA_BABEL_ROUTER_ID is read-only, we do not really save the value */
|
|
|
|
rte_store_tmp_attr(rt, EA_BABEL_ROUTER_ID);
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* babel_rt_notify - core tells us about new route (possibly our own),
|
|
|
|
* so store it into our data structures.
|
|
|
|
*/
|
|
|
|
static void
|
2016-12-10 07:11:26 +08:00
|
|
|
babel_rt_notify(struct proto *P, struct channel *c UNUSED, struct network *net,
|
2018-05-29 18:08:12 +08:00
|
|
|
struct rte *new, struct rte *old UNUSED)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
|
|
|
struct babel_proto *p = (void *) P;
|
|
|
|
struct babel_entry *e;
|
|
|
|
|
|
|
|
if (new)
|
|
|
|
{
|
|
|
|
/* Update */
|
2017-11-28 22:11:41 +08:00
|
|
|
uint internal = (new->attrs->src->proto == P);
|
|
|
|
uint rt_seqno = internal ? new->u.babel.seqno : p->update_seqno;
|
2018-05-29 18:08:12 +08:00
|
|
|
uint rt_metric = ea_get_int(new->attrs->eattrs, EA_BABEL_METRIC, 0);
|
2018-05-03 22:02:29 +08:00
|
|
|
u64 rt_router_id = internal ? new->u.babel.router_id : p->router_id;
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2017-11-28 22:11:41 +08:00
|
|
|
if (rt_metric > BABEL_INFINITY)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
2017-11-28 22:11:41 +08:00
|
|
|
log(L_WARN "%s: Invalid babel_metric value %u for route %N",
|
|
|
|
p->p.name, rt_metric, net->n.addr);
|
|
|
|
rt_metric = BABEL_INFINITY;
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
|
2017-11-28 22:11:41 +08:00
|
|
|
e = babel_get_entry(p, net->n.addr);
|
|
|
|
|
|
|
|
/* Activate triggered updates */
|
2018-02-13 23:42:03 +08:00
|
|
|
if ((e->valid != BABEL_ENTRY_VALID) ||
|
2017-11-28 22:11:41 +08:00
|
|
|
(e->router_id != rt_router_id))
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
|
|
|
babel_trigger_update(p);
|
2017-10-13 18:34:08 +08:00
|
|
|
e->updated = current_time();
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
2017-11-28 22:11:41 +08:00
|
|
|
|
|
|
|
e->valid = BABEL_ENTRY_VALID;
|
|
|
|
e->seqno = rt_seqno;
|
|
|
|
e->metric = rt_metric;
|
|
|
|
e->router_id = rt_router_id;
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Withdraw */
|
2016-12-10 07:11:26 +08:00
|
|
|
e = babel_find_entry(p, net->n.addr);
|
2017-11-28 22:11:41 +08:00
|
|
|
|
|
|
|
if (!e || e->valid != BABEL_ENTRY_VALID)
|
2016-04-29 00:01:40 +08:00
|
|
|
return;
|
|
|
|
|
2017-11-28 22:11:41 +08:00
|
|
|
e->valid = BABEL_ENTRY_STALE;
|
|
|
|
e->metric = BABEL_INFINITY;
|
|
|
|
|
|
|
|
babel_trigger_update(p);
|
|
|
|
e->updated = current_time();
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
babel_rte_better(struct rte *new, struct rte *old)
|
|
|
|
{
|
|
|
|
return new->u.babel.metric < old->u.babel.metric;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
babel_rte_same(struct rte *new, struct rte *old)
|
|
|
|
{
|
2017-11-28 22:11:41 +08:00
|
|
|
return ((new->u.babel.seqno == old->u.babel.seqno) &&
|
|
|
|
(new->u.babel.metric == old->u.babel.metric) &&
|
|
|
|
(new->u.babel.router_id == old->u.babel.router_id));
|
2016-04-29 00:01:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-13 23:39:36 +08:00
|
|
|
static void
|
|
|
|
babel_postconfig(struct proto_config *CF)
|
|
|
|
{
|
|
|
|
struct babel_config *cf = (void *) CF;
|
|
|
|
struct channel_config *ip4, *ip6, *ip6_sadr;
|
|
|
|
|
|
|
|
ip4 = proto_cf_find_channel(CF, NET_IP4);
|
|
|
|
ip6 = proto_cf_find_channel(CF, NET_IP6);
|
|
|
|
ip6_sadr = proto_cf_find_channel(CF, NET_IP6_SADR);
|
|
|
|
|
|
|
|
if (ip6 && ip6_sadr)
|
|
|
|
cf_error("Both ipv6 and ipv6-sadr channels");
|
|
|
|
|
|
|
|
cf->ip4_channel = ip4;
|
|
|
|
cf->ip6_channel = ip6 ?: ip6_sadr;
|
|
|
|
}
|
|
|
|
|
2016-04-29 00:01:40 +08:00
|
|
|
static struct proto *
|
2016-12-10 07:11:26 +08:00
|
|
|
babel_init(struct proto_config *CF)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
2016-12-10 07:11:26 +08:00
|
|
|
struct proto *P = proto_new(CF);
|
2017-06-08 18:18:16 +08:00
|
|
|
struct babel_proto *p = (void *) P;
|
2018-02-13 23:39:36 +08:00
|
|
|
struct babel_config *cf = (void *) CF;
|
2016-12-10 07:11:26 +08:00
|
|
|
|
2018-02-13 23:39:36 +08:00
|
|
|
proto_configure_channel(P, &p->ip4_channel, cf->ip4_channel);
|
|
|
|
proto_configure_channel(P, &p->ip6_channel, cf->ip6_channel);
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
P->if_notify = babel_if_notify;
|
|
|
|
P->rt_notify = babel_rt_notify;
|
Terminology cleanup: The import_control hook is now called preexport.
Once upon a time, far far away, there were the old Bird developers
discussing what direction of route flow shall be called import and
export. They decided to say "import to protocol" and "export to table"
when speaking about a protocol. When speaking about a table, they
spoke about "importing to table" and "exporting to protocol".
The latter terminology was adopted in configuration, then also the
bird CLI in commit ea2ae6dd0 started to use it (in year 2009). Now
it's 2018 and the terminology is the latter. Import is from protocol to
table, export is from table to protocol. Anyway, there was still an
import_control hook which executed right before route export.
One thing is funny. There are two commits in April 1999 with just two
minutes between them. The older announces the final settlement
on config terminology, the newer uses the other definition. Let's see
their commit messages as the git-log tool shows them (the newer first):
commit 9e0e485e50ea74c4f1c5cb65bdfe6ce819c2cee2
Author: Martin Mares <mj@ucw.cz>
Date: Mon Apr 5 20:17:59 1999 +0000
Added some new protocol hooks (look at the comments for better explanation):
make_tmp_attrs Convert inline attributes to ea_list
store_tmp_attrs Convert ea_list to inline attributes
import_control Pre-import decisions
commit 5056c559c4eb253a4eee10cf35b694faec5265eb
Author: Martin Mares <mj@ucw.cz>
Date: Mon Apr 5 20:15:31 1999 +0000
Changed syntax of attaching filters to protocols to hopefully the final
version:
EXPORT <filter-spec> for outbound routes (i.e., those announced
by BIRD to the rest of the world).
IMPORT <filter-spec> for inbound routes (i.e., those imported
by BIRD from the rest of the world).
where <filter-spec> is one of:
ALL pass all routes
NONE drop all routes
FILTER <name> use named filter
FILTER { <filter> } use explicitly defined filter
For all protocols, the default is IMPORT ALL, EXPORT NONE. This includes
the kernel protocol, so that you need to add EXPORT ALL to get the previous
configuration of kernel syncer (as usually, see doc/bird.conf.example for
a bird.conf example :)).
Let's say RIP to this almost 19-years-old inconsistency. For now, if you
import a route, it is always from protocol to table. If you export a
route, it is always from table to protocol.
And they lived happily ever after.
2018-02-14 20:42:53 +08:00
|
|
|
P->preexport = babel_preexport;
|
2016-04-29 00:01:40 +08:00
|
|
|
P->make_tmp_attrs = babel_make_tmp_attrs;
|
|
|
|
P->store_tmp_attrs = babel_store_tmp_attrs;
|
|
|
|
P->rte_better = babel_rte_better;
|
|
|
|
P->rte_same = babel_rte_same;
|
|
|
|
|
|
|
|
return P;
|
|
|
|
}
|
|
|
|
|
2018-05-03 22:55:11 +08:00
|
|
|
static inline void
|
|
|
|
babel_randomize_router_id(struct babel_proto *p)
|
|
|
|
{
|
|
|
|
p->router_id &= (u64) 0xffffffff;
|
|
|
|
p->router_id |= ((u64) random()) << 32;
|
|
|
|
TRACE(D_EVENTS, "Randomized router ID to %lR", p->router_id);
|
|
|
|
}
|
|
|
|
|
2016-04-29 00:01:40 +08:00
|
|
|
static int
|
|
|
|
babel_start(struct proto *P)
|
|
|
|
{
|
|
|
|
struct babel_proto *p = (void *) P;
|
|
|
|
struct babel_config *cf = (void *) P->cf;
|
2018-02-13 23:39:36 +08:00
|
|
|
u8 ip6_type = cf->ip6_channel ? cf->ip6_channel->net_type : NET_IP6;
|
2016-04-29 00:01:40 +08:00
|
|
|
|
2017-06-08 18:18:16 +08:00
|
|
|
fib_init(&p->ip4_rtable, P->pool, NET_IP4, sizeof(struct babel_entry),
|
2016-12-10 07:11:26 +08:00
|
|
|
OFFSETOF(struct babel_entry, n), 0, babel_init_entry);
|
2018-02-13 23:39:36 +08:00
|
|
|
fib_init(&p->ip6_rtable, P->pool, ip6_type, sizeof(struct babel_entry),
|
2017-06-08 18:18:16 +08:00
|
|
|
OFFSETOF(struct babel_entry, n), 0, babel_init_entry);
|
|
|
|
|
2016-04-29 00:01:40 +08:00
|
|
|
init_list(&p->interfaces);
|
2017-11-29 00:43:20 +08:00
|
|
|
p->timer = tm_new_init(P->pool, babel_timer, p, 1 S, 0);
|
|
|
|
tm_start(p->timer, 1 S);
|
2016-04-29 00:01:40 +08:00
|
|
|
p->update_seqno = 1;
|
|
|
|
p->router_id = proto_get_router_id(&cf->c);
|
|
|
|
|
2018-05-03 22:55:11 +08:00
|
|
|
if (cf->randomize_router_id)
|
|
|
|
babel_randomize_router_id(p);
|
|
|
|
|
2016-04-29 00:01:40 +08:00
|
|
|
p->route_slab = sl_new(P->pool, sizeof(struct babel_route));
|
|
|
|
p->source_slab = sl_new(P->pool, sizeof(struct babel_source));
|
|
|
|
p->msg_slab = sl_new(P->pool, sizeof(struct babel_msg_node));
|
|
|
|
p->seqno_slab = sl_new(P->pool, sizeof(struct babel_seqno_request));
|
|
|
|
|
|
|
|
p->log_pkt_tbf = (struct tbf){ .rate = 1, .burst = 5 };
|
|
|
|
|
|
|
|
return PS_UP;
|
|
|
|
}
|
|
|
|
|
2016-07-19 20:23:41 +08:00
|
|
|
static inline void
|
|
|
|
babel_iface_shutdown(struct babel_iface *ifa)
|
|
|
|
{
|
|
|
|
if (ifa->sk)
|
|
|
|
{
|
2022-04-22 22:41:52 +08:00
|
|
|
/*
|
|
|
|
* Retract all our routes and lower the hello interval so peers' neighbour
|
|
|
|
* state expires quickly
|
|
|
|
*/
|
|
|
|
babel_send_hello(ifa, BABEL_MIN_INTERVAL);
|
2016-07-19 20:23:41 +08:00
|
|
|
babel_send_wildcard_retraction(ifa);
|
|
|
|
babel_send_queue(ifa);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
babel_shutdown(struct proto *P)
|
|
|
|
{
|
|
|
|
struct babel_proto *p = (void *) P;
|
|
|
|
struct babel_iface *ifa;
|
|
|
|
|
|
|
|
TRACE(D_EVENTS, "Shutdown requested");
|
|
|
|
|
|
|
|
WALK_LIST(ifa, p->interfaces)
|
|
|
|
babel_iface_shutdown(ifa);
|
|
|
|
|
|
|
|
return PS_DOWN;
|
|
|
|
}
|
|
|
|
|
2016-04-29 00:01:40 +08:00
|
|
|
static int
|
2016-12-10 07:11:26 +08:00
|
|
|
babel_reconfigure(struct proto *P, struct proto_config *CF)
|
2016-04-29 00:01:40 +08:00
|
|
|
{
|
|
|
|
struct babel_proto *p = (void *) P;
|
2016-12-10 07:11:26 +08:00
|
|
|
struct babel_config *new = (void *) CF;
|
2018-02-13 23:39:36 +08:00
|
|
|
u8 ip6_type = new->ip6_channel ? new->ip6_channel->net_type : NET_IP6;
|
2016-04-29 00:01:40 +08:00
|
|
|
|
|
|
|
TRACE(D_EVENTS, "Reconfiguring");
|
|
|
|
|
2018-02-13 23:39:36 +08:00
|
|
|
if (p->ip6_rtable.addr_type != ip6_type)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!proto_configure_channel(P, &p->ip4_channel, new->ip4_channel) ||
|
|
|
|
!proto_configure_channel(P, &p->ip6_channel, new->ip6_channel))
|
2016-12-10 07:11:26 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
p->p.cf = CF;
|
2016-04-29 00:01:40 +08:00
|
|
|
babel_reconfigure_ifaces(p, new);
|
|
|
|
|
|
|
|
babel_trigger_update(p);
|
|
|
|
babel_kick_timer(p);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct protocol proto_babel = {
|
|
|
|
.name = "Babel",
|
|
|
|
.template = "babel%d",
|
2018-05-07 20:47:00 +08:00
|
|
|
.class = PROTOCOL_BABEL,
|
2016-04-29 00:01:40 +08:00
|
|
|
.preference = DEF_PREF_BABEL,
|
2018-02-13 23:39:36 +08:00
|
|
|
.channel_mask = NB_IP | NB_IP6_SADR,
|
2016-12-10 07:11:26 +08:00
|
|
|
.proto_size = sizeof(struct babel_proto),
|
2016-04-29 00:01:40 +08:00
|
|
|
.config_size = sizeof(struct babel_config),
|
2018-02-13 23:39:36 +08:00
|
|
|
.postconfig = babel_postconfig,
|
2016-04-29 00:01:40 +08:00
|
|
|
.init = babel_init,
|
|
|
|
.dump = babel_dump,
|
|
|
|
.start = babel_start,
|
2016-07-19 20:23:41 +08:00
|
|
|
.shutdown = babel_shutdown,
|
2016-04-29 00:01:40 +08:00
|
|
|
.reconfigure = babel_reconfigure,
|
|
|
|
.get_route_info = babel_get_route_info,
|
|
|
|
.get_attr = babel_get_attr
|
|
|
|
};
|