summaryrefslogtreecommitdiff
path: root/proto/babel
diff options
context:
space:
mode:
authorOndrej Zajicek (work) <santiago@crfreenet.org>2016-11-08 17:03:31 +0100
committerOndrej Zajicek (work) <santiago@crfreenet.org>2016-11-08 17:04:29 +0100
commitcc5b93f72db80abd1262a0a5e1d8400ceef54385 (patch)
tree42d75cb7898c6b6077e9cfbb04074cfc84e38930 /proto/babel
parent5de0e848de06a9187046dbc380d9ce6a6f8b21a2 (diff)
parentf51b1f556595108d53b9f4580bfcb96bfbc85442 (diff)
Merge tag 'v1.6.2' into int-new
Diffstat (limited to 'proto/babel')
-rw-r--r--proto/babel/babel.c159
-rw-r--r--proto/babel/babel.h6
-rw-r--r--proto/babel/config.Y9
-rw-r--r--proto/babel/packets.c27
4 files changed, 153 insertions, 48 deletions
diff --git a/proto/babel/babel.c b/proto/babel/babel.c
index 8e104d60..9d73a264 100644
--- a/proto/babel/babel.c
+++ b/proto/babel/babel.c
@@ -565,6 +565,11 @@ babel_select_route(struct babel_entry *e)
babel_send_seqno_request(e);
babel_announce_rte(p, e);
+
+ /* Section 3.6 of the RFC forbids an infeasible from being selected. This
+ is cleared after announcing the route to the core to make sure an
+ unreachable route is propagated first. */
+ e->selected_in = NULL;
}
else
{
@@ -783,16 +788,21 @@ babel_send_update(struct babel_iface *ifa, bird_clock_t changed)
msg.update.prefix = e->n.prefix;
msg.update.router_id = r->router_id;
- /* Update feasibility distance */
- struct babel_source *s = babel_get_source(e, r->router_id);
- s->expires = now + BABEL_GARBAGE_INTERVAL;
- if ((msg.update.seqno > s->seqno) ||
- ((msg.update.seqno == s->seqno) && (msg.update.metric < s->metric)))
+ babel_enqueue(&msg, ifa);
+
+ /* Update feasibility distance for redistributed routes */
+ if (!OUR_ROUTE(r))
{
- s->seqno = msg.update.seqno;
- s->metric = msg.update.metric;
+ struct babel_source *s = babel_get_source(e, r->router_id);
+ s->expires = now + BABEL_GARBAGE_INTERVAL;
+
+ 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;
+ }
}
- babel_enqueue(&msg, ifa);
}
FIB_WALK_END;
}
@@ -834,8 +844,8 @@ babel_send_retraction(struct babel_iface *ifa, ip_addr prefix, int plen)
struct babel_proto *p = ifa->proto;
union babel_msg msg = {};
- TRACE(D_PACKETS, "Sending retraction for %I/%d router-id %lR seqno %d",
- prefix, plen, p->router_id, p->update_seqno);
+ TRACE(D_PACKETS, "Sending retraction for %I/%d seqno %d",
+ prefix, plen, p->update_seqno);
msg.type = BABEL_TLV_UPDATE;
msg.update.plen = plen;
@@ -843,7 +853,23 @@ babel_send_retraction(struct babel_iface *ifa, ip_addr prefix, int plen)
msg.update.seqno = p->update_seqno;
msg.update.metric = BABEL_INFINITY;
msg.update.prefix = prefix;
- msg.update.router_id = p->router_id;
+
+ 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;
babel_enqueue(&msg, ifa);
}
@@ -1040,17 +1066,18 @@ babel_handle_update(union babel_msg *m, struct babel_iface *ifa)
struct babel_proto *p = ifa->proto;
struct babel_msg_update *msg = &m->update;
- struct babel_neighbor *n;
+ struct babel_neighbor *nbr;
struct babel_entry *e;
struct babel_source *s;
struct babel_route *r;
+ node *n;
int feasible;
TRACE(D_PACKETS, "Handling update for %I/%d with seqno %d metric %d",
msg->prefix, msg->plen, msg->seqno, msg->metric);
- n = babel_find_neighbor(ifa, msg->sender);
- if (!n)
+ nbr = babel_find_neighbor(ifa, msg->sender);
+ if (!nbr)
{
DBG("Babel: Haven't heard from neighbor %I; ignoring update.\n", msg->sender);
return;
@@ -1095,55 +1122,88 @@ babel_handle_update(union babel_msg *m, struct babel_iface *ifa)
* of the Interval value included in the update.
*/
+ /* Retraction */
if (msg->metric == BABEL_INFINITY)
- e = babel_find_entry(p, msg->prefix, msg->plen);
- else
- e = babel_get_entry(p, msg->prefix, msg->plen);
+ {
+ if (msg->wildcard)
+ {
+ /*
+ * 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);
+ r->metric = BABEL_INFINITY;
+ babel_select_route(r->e);
+ }
+ }
+ else
+ {
+ e = babel_find_entry(p, msg->prefix, msg->plen);
- if (!e)
+ if (!e)
+ return;
+
+ /* The route entry indexed by neighbour */
+ r = babel_find_route(e, nbr);
+
+ if (!r)
+ return;
+
+ r->metric = BABEL_INFINITY;
+ babel_select_route(e);
+ }
+
+ /* Done with retractions */
return;
+ }
+ e = babel_get_entry(p, msg->prefix, msg->plen);
+ r = babel_find_route(e, nbr); /* the route entry indexed by neighbour */
s = babel_find_source(e, msg->router_id); /* for feasibility */
- r = babel_find_route(e, n); /* the route entry indexed by neighbour */
feasible = babel_is_feasible(s, msg->seqno, msg->metric);
if (!r)
{
- if (!feasible || (msg->metric == BABEL_INFINITY))
+ if (!feasible)
return;
- r = babel_get_route(e, n);
+ r = babel_get_route(e, nbr);
r->advert_metric = msg->metric;
r->router_id = msg->router_id;
- r->metric = babel_compute_metric(n, msg->metric);
+ r->metric = babel_compute_metric(nbr, msg->metric);
r->next_hop = msg->next_hop;
r->seqno = msg->seqno;
}
else if (r == r->e->selected_in && !feasible)
{
- /* Route is installed and update is infeasible - we may lose the route, so
- send a unicast seqno request (section 3.8.2.2 second paragraph). */
+ /*
+ * Route is installed and update is infeasible - we may lose the route,
+ * so send a unicast seqno request (section 3.8.2.2 second paragraph).
+ */
babel_unicast_seqno_request(r);
- if (msg->router_id == r->router_id) return;
- r->metric = BABEL_INFINITY; /* retraction */
+ if (msg->router_id == r->router_id)
+ return;
+
+ /* Treat as retraction */
+ r->metric = BABEL_INFINITY;
}
else
{
/* Last paragraph above - update the entry */
r->advert_metric = msg->metric;
- r->metric = babel_compute_metric(n, msg->metric);
- r->router_id = msg->router_id;
+ r->metric = babel_compute_metric(nbr, msg->metric);
r->next_hop = msg->next_hop;
+
+ r->router_id = msg->router_id;
r->seqno = msg->seqno;
- if (msg->metric != BABEL_INFINITY)
- {
- r->expiry_interval = BABEL_ROUTE_EXPIRY_FACTOR(msg->interval);
- r->expires = now + r->expiry_interval;
- if (r->expiry_interval > BABEL_ROUTE_REFRESH_INTERVAL)
- r->refresh_time = now + r->expiry_interval - BABEL_ROUTE_REFRESH_INTERVAL;
- }
+ r->expiry_interval = BABEL_ROUTE_EXPIRY_FACTOR(msg->interval);
+ r->expires = now + r->expiry_interval;
+ if (r->expiry_interval > BABEL_ROUTE_REFRESH_INTERVAL)
+ r->refresh_time = now + r->expiry_interval - BABEL_ROUTE_REFRESH_INTERVAL;
/* If the route is not feasible at this point, it means it is from another
neighbour than the one currently selected; so send a unicast seqno
@@ -1313,6 +1373,7 @@ babel_iface_start(struct babel_iface *ifa)
ifa->up = 1;
babel_send_hello(ifa, 0);
+ babel_send_wildcard_retraction(ifa);
babel_send_wildcard_request(ifa);
babel_send_update(ifa, 0); /* Full update */
}
@@ -1529,6 +1590,9 @@ babel_reconfigure_iface(struct babel_proto *p, struct babel_iface *ifa, struct b
ifa->cf = new;
+ if (ifa->next_hello > (now + new->hello_interval))
+ ifa->next_hello = now + (random() % new->hello_interval) + 1;
+
if (ifa->next_regular > (now + new->update_interval))
ifa->next_regular = now + (random() % new->update_interval) + 1;
@@ -2022,6 +2086,30 @@ babel_start(struct proto *P)
return PS_UP;
}
+static inline void
+babel_iface_shutdown(struct babel_iface *ifa)
+{
+ if (ifa->sk)
+ {
+ 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;
+}
+
static int
babel_reconfigure(struct proto *P, struct proto_config *c)
{
@@ -2049,6 +2137,7 @@ struct protocol proto_babel = {
.init = babel_init,
.dump = babel_dump,
.start = babel_start,
+ .shutdown = babel_shutdown,
.reconfigure = babel_reconfigure,
.get_route_info = babel_get_route_info,
.get_attr = babel_get_attr
diff --git a/proto/babel/babel.h b/proto/babel/babel.h
index aea0dd88..481c88a7 100644
--- a/proto/babel/babel.h
+++ b/proto/babel/babel.h
@@ -50,10 +50,12 @@
#define BABEL_INITIAL_HOP_COUNT 255
#define BABEL_MAX_SEND_INTERVAL 5
#define BABEL_TIME_UNITS 100 /* On-wire times are counted in centiseconds */
-
#define BABEL_SEQNO_REQUEST_EXPIRY 60
#define BABEL_GARBAGE_INTERVAL 300
+/* Max interval that will not overflow when carried as 16-bit centiseconds */
+#define BABEL_MAX_INTERVAL (0xFFFF/BABEL_TIME_UNITS)
+
#define BABEL_OVERHEAD (SIZE_OF_IP_HEADER+UDP_HEADER_LENGTH)
#define BABEL_MIN_MTU (512 + BABEL_OVERHEAD)
@@ -266,7 +268,7 @@ struct babel_msg_ihu {
struct babel_msg_update {
u8 type;
- u8 ae;
+ u8 wildcard;
u8 plen;
u16 interval;
u16 seqno;
diff --git a/proto/babel/config.Y b/proto/babel/config.Y
index e7ce6a93..b6170852 100644
--- a/proto/babel/config.Y
+++ b/proto/babel/config.Y
@@ -77,17 +77,18 @@ babel_iface_finish:
BABEL_IFACE->rxcost = BABEL_RXCOST_WIRED;
}
+ /* Make sure we do not overflow the 16-bit centisec fields */
if (!BABEL_IFACE->update_interval)
- BABEL_IFACE->update_interval = BABEL_IFACE->hello_interval*BABEL_UPDATE_INTERVAL_FACTOR;
- BABEL_IFACE->ihu_interval = BABEL_IFACE->hello_interval*BABEL_IHU_INTERVAL_FACTOR;
+ BABEL_IFACE->update_interval = MIN_(BABEL_IFACE->hello_interval*BABEL_UPDATE_INTERVAL_FACTOR, BABEL_MAX_INTERVAL);
+ BABEL_IFACE->ihu_interval = MIN_(BABEL_IFACE->hello_interval*BABEL_IHU_INTERVAL_FACTOR, BABEL_MAX_INTERVAL);
};
babel_iface_item:
| PORT expr { BABEL_IFACE->port = $2; if (($2<1) || ($2>65535)) cf_error("Invalid port number"); }
| RXCOST expr { BABEL_IFACE->rxcost = $2; if (($2<1) || ($2>65535)) cf_error("Invalid rxcost"); }
- | HELLO INTERVAL expr { BABEL_IFACE->hello_interval = $3; if (($3<1) || ($3>65535)) cf_error("Invalid hello interval"); }
- | UPDATE INTERVAL expr { BABEL_IFACE->update_interval = $3; if (($3<1) || ($3>65535)) cf_error("Invalid hello interval"); }
+ | HELLO INTERVAL expr { BABEL_IFACE->hello_interval = $3; if (($3<1) || ($3>BABEL_MAX_INTERVAL)) cf_error("Invalid hello interval"); }
+ | UPDATE INTERVAL expr { BABEL_IFACE->update_interval = $3; if (($3<1) || ($3>BABEL_MAX_INTERVAL)) cf_error("Invalid update interval"); }
| TYPE WIRED { BABEL_IFACE->type = BABEL_IFACE_TYPE_WIRED; }
| TYPE WIRELESS { BABEL_IFACE->type = BABEL_IFACE_TYPE_WIRELESS; }
| RX BUFFER expr { BABEL_IFACE->rx_buffer = $3; if (($3<256) || ($3>65535)) cf_error("RX buffer must be in range 256-65535"); }
diff --git a/proto/babel/packets.c b/proto/babel/packets.c
index be47aa75..65dd6853 100644
--- a/proto/babel/packets.c
+++ b/proto/babel/packets.c
@@ -462,7 +462,6 @@ babel_read_update(struct babel_tlv *hdr, union babel_msg *m,
struct babel_msg_update *msg = &m->update;
msg->type = BABEL_TLV_UPDATE;
- msg->ae = tlv->ae;
msg->interval = get_time16(&tlv->interval);
msg->seqno = get_u16(&tlv->seqno);
msg->metric = get_u16(&tlv->metric);
@@ -480,7 +479,7 @@ babel_read_update(struct babel_tlv *hdr, union babel_msg *m,
if (tlv->plen > 0)
return PARSE_ERROR;
- msg->prefix = IPA_NONE;
+ msg->wildcard = 1;
break;
case BABEL_AE_IP4:
@@ -523,7 +522,8 @@ babel_read_update(struct babel_tlv *hdr, union babel_msg *m,
return PARSE_IGNORE;
}
- if (!state->router_id_seen)
+ /* Update must have Router ID, unless it is retraction */
+ if (!state->router_id_seen && (msg->metric != BABEL_INFINITY))
{
DBG("Babel: No router ID seen before update\n");
return PARSE_ERROR;
@@ -548,8 +548,11 @@ babel_write_update(struct babel_tlv *hdr, union babel_msg *m,
* When needed, we write Router-ID TLV before Update TLV and return size of
* both of them. There is enough space for the Router-ID TLV, because
* sizeof(struct babel_tlv_router_id) == sizeof(struct babel_tlv_update).
+ *
+ * Router ID is not used for retractions, so do not us it in such case.
*/
- if (!state->router_id_seen || (msg->router_id != state->router_id))
+ if ((msg->metric < BABEL_INFINITY) &&
+ (!state->router_id_seen || (msg->router_id != state->router_id)))
{
len0 = babel_write_router_id(hdr, msg->router_id, state, max_len);
tlv = (struct babel_tlv_update *) NEXT_TLV(tlv);
@@ -562,12 +565,22 @@ babel_write_update(struct babel_tlv *hdr, union babel_msg *m,
memset(tlv, 0, sizeof(struct babel_tlv_update));
TLV_HDR(tlv, BABEL_TLV_UPDATE, len);
- tlv->ae = BABEL_AE_IP6;
- tlv->plen = msg->plen;
+
+ if (msg->wildcard)
+ {
+ tlv->ae = BABEL_AE_WILDCARD;
+ tlv->plen = 0;
+ }
+ else
+ {
+ tlv->ae = BABEL_AE_IP6;
+ tlv->plen = msg->plen;
+ put_ip6_px(tlv->addr, msg->prefix, msg->plen);
+ }
+
put_time16(&tlv->interval, msg->interval);
put_u16(&tlv->seqno, msg->seqno);
put_u16(&tlv->metric, msg->metric);
- put_ip6_px(tlv->addr, msg->prefix, msg->plen);
return len0 + len;
}