Merge pull request #437 from rogerpueyo/luci-app-bmx6-graph-sys-exec
[feed/routing.git] / bird2 / patches / 0004-Babel-Add-option-to-randomize-router-ID.patch
1 From 70fab17837dbb4c5848681e4c6b9b90891891130 Mon Sep 17 00:00:00 2001
2 From: "Ondrej Zajicek (work)" <santiago@crfreenet.org>
3 Date: Thu, 3 May 2018 16:55:11 +0200
4 Subject: [PATCH 1/2] Babel: Add option to randomize router ID
5
6 When a Babel node restarts, it loses its sequence number, which can cause
7 its routes to be rejected by peers until the state is cleared out by other
8 nodes in the network (which can take on the order of minutes).
9
10 There are two ways to fix this: Having stable storage to keep the sequence
11 number across restarts, or picking a different router ID each time.
12
13 This implements the latter, by introducing a new option that will cause
14 BIRD to randomize a high 32 bits of router ID every time it starts up.
15 This avoids the problem at the cost of not having stable router IDs in
16 the network.
17
18 Thanks to Toke Hoiland-Jorgensen for the patch.
19 ---
20 doc/bird.sgml | 10 ++++++++++
21 proto/babel/babel.c | 11 +++++++++++
22 proto/babel/babel.h | 1 +
23 proto/babel/config.Y | 3 ++-
24 4 files changed, 24 insertions(+), 1 deletion(-)
25
26 diff --git a/doc/bird.sgml b/doc/bird.sgml
27 index 1191fa03..ae308d4c 100644
28 --- a/doc/bird.sgml
29 +++ b/doc/bird.sgml
30 @@ -1691,6 +1691,7 @@ supports the following per-interface configuration options:
31 protocol babel [<name>] {
32 ipv4 { <channel config> };
33 ipv6 [sadr] { <channel config> };
34 + randomize router id <switch>;
35 interface <interface pattern> {
36 type <wired|wireless>;
37 rxcost <number>;
38 @@ -1713,6 +1714,15 @@ protocol babel [<name>] {
39 <tag><label id="babel-channel">ipv4 | ipv6 [sadr] <m/channel config/</tag>
40 The supported channels are IPv4, IPv6, and IPv6 SADR.
41
42 + <tag><label id="babel-random-router-id">randomize router id <m/switch/</tag>
43 + If enabled, Bird will randomize the top 32 bits of its router ID whenever
44 + the protocol instance starts up. If a Babel node restarts, it loses its
45 + sequence number, which can cause its routes to be rejected by peers until
46 + the state is cleared out by other nodes in the network (which can take on
47 + the order of minutes). Enabling this option causes Bird to pick a random
48 + router ID every time it starts up, which avoids this problem at the cost
49 + of not having stable router IDs in the network. Default: no.
50 +
51 <tag><label id="babel-type">type wired|wireless </tag>
52 This option specifies the interface type: Wired or wireless. On wired
53 interfaces a neighbor is considered unreachable after a small number of
54 diff --git a/proto/babel/babel.c b/proto/babel/babel.c
55 index 797a83d4..ce05191c 100644
56 --- a/proto/babel/babel.c
57 +++ b/proto/babel/babel.c
58 @@ -2226,6 +2226,14 @@ babel_init(struct proto_config *CF)
59 return P;
60 }
61
62 +static inline void
63 +babel_randomize_router_id(struct babel_proto *p)
64 +{
65 + p->router_id &= (u64) 0xffffffff;
66 + p->router_id |= ((u64) random()) << 32;
67 + TRACE(D_EVENTS, "Randomized router ID to %lR", p->router_id);
68 +}
69 +
70 static int
71 babel_start(struct proto *P)
72 {
73 @@ -2244,6 +2252,9 @@ babel_start(struct proto *P)
74 p->update_seqno = 1;
75 p->router_id = proto_get_router_id(&cf->c);
76
77 + if (cf->randomize_router_id)
78 + babel_randomize_router_id(p);
79 +
80 p->route_slab = sl_new(P->pool, sizeof(struct babel_route));
81 p->source_slab = sl_new(P->pool, sizeof(struct babel_source));
82 p->msg_slab = sl_new(P->pool, sizeof(struct babel_msg_node));
83 diff --git a/proto/babel/babel.h b/proto/babel/babel.h
84 index b194ce30..e5c9cd5b 100644
85 --- a/proto/babel/babel.h
86 +++ b/proto/babel/babel.h
87 @@ -112,6 +112,7 @@ struct babel_config {
88 struct proto_config c;
89 list iface_list; /* List of iface configs (struct babel_iface_config) */
90 uint hold_time; /* Time to hold stale entries and unreachable routes */
91 + u8 randomize_router_id;
92
93 struct channel_config *ip4_channel;
94 struct channel_config *ip6_channel;
95 diff --git a/proto/babel/config.Y b/proto/babel/config.Y
96 index 7adfb4bb..205b4e4f 100644
97 --- a/proto/babel/config.Y
98 +++ b/proto/babel/config.Y
99 @@ -25,7 +25,7 @@ CF_DECLS
100 CF_KEYWORDS(BABEL, INTERFACE, METRIC, RXCOST, HELLO, UPDATE, INTERVAL, PORT,
101 TYPE, WIRED, WIRELESS, RX, TX, BUFFER, PRIORITY, LENGTH, CHECK, LINK,
102 NEXT, HOP, IPV4, IPV6, BABEL_METRIC, SHOW, INTERFACES, NEIGHBORS,
103 - ENTRIES)
104 + ENTRIES, RANDOMIZE, ROUTER, ID)
105
106 CF_GRAMMAR
107
108 @@ -42,6 +42,7 @@ babel_proto_item:
109 proto_item
110 | proto_channel
111 | INTERFACE babel_iface
112 + | RANDOMIZE ROUTER ID bool { BABEL_CFG->randomize_router_id = $4; }
113 ;
114
115 babel_proto_opts:
116 --
117 2.17.0
118