batman-adv: Merge bugfixes from 2017.4
[feed/routing.git] / batman-adv / patches / 0014-batman-adv-handle-race-condition-for-claims-between-.patch
1 From: Andreas Pape <APape@phoenixcontact.com>
2 Date: Mon, 5 Sep 2016 13:20:29 +0200
3 Subject: [PATCH] batman-adv: handle race condition for claims between gateways
4
5 Consider the following situation which has been found in a test setup:
6 Gateway B has claimed client C and gateway A has the same backbone
7 network as B. C sends a broad- or multicast to B and directly after
8 this packet decides to send another packet to A due to a better TQ
9 value. B will forward the broad-/multicast into the backbone as it is
10 the responsible gw and after that A will claim C as it has been
11 chosen by C as the best gateway. If it now happens that A claims C
12 before it has received the broad-/multicast forwarded by B (due to
13 backbone topology or due to some delay in B when forwarding the
14 packet) we get a critical situation: in the current code A will
15 immediately unclaim C when receiving the multicast due to the
16 roaming client scenario although the position of C has not changed
17 in the mesh. If this happens the multi-/broadcast forwarded by B
18 will be sent back into the mesh by A and we have looping packets
19 until one of the gateways claims C again.
20 In order to prevent this, unclaiming of a client due to the roaming
21 client scenario is only done after a certain time is expired after
22 the last claim of the client. 100 ms are used here, which should be
23 slow enough for big backbones and slow gateways but fast enough not
24 to break the roaming client use case.
25
26 Acked-by: Simon Wunderlich <sw@simonwunderlich.de>
27 Signed-off-by: Andreas Pape <apape@phoenixcontact.com>
28 [sven@narfation.org: fix conflicts with current version]
29 Signed-off-by: Sven Eckelmann <sven@narfation.org>
30 Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
31
32 Origin: upstream, https://git.open-mesh.org/batman-adv.git/commit/cbb2ccc101e220b339989d5a51c0ca226ceda792
33 ---
34 net/batman-adv/bridge_loop_avoidance.c | 20 ++++++++++++++++----
35 1 file changed, 16 insertions(+), 4 deletions(-)
36
37 diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c
38 index 41ab4a67a07b264bccdc5bccf73920909ff35c40..1e6e5d4468ad50c221ea5a0d436678d16c5e154f 100644
39 --- a/net/batman-adv/bridge_loop_avoidance.c
40 +++ b/net/batman-adv/bridge_loop_avoidance.c
41 @@ -1964,10 +1964,22 @@ bool batadv_bla_tx(struct batadv_priv *bat_priv, struct sk_buff *skb,
42 /* if yes, the client has roamed and we have
43 * to unclaim it.
44 */
45 - batadv_handle_unclaim(bat_priv, primary_if,
46 - primary_if->net_dev->dev_addr,
47 - ethhdr->h_source, vid);
48 - goto allow;
49 + if (batadv_has_timed_out(claim->lasttime, 100)) {
50 + /* only unclaim if the last claim entry is
51 + * older than 100 ms to make sure we really
52 + * have a roaming client here.
53 + */
54 + batadv_dbg(BATADV_DBG_BLA, bat_priv, "bla_tx(): Roaming client %pM detected. Unclaim it.\n",
55 + ethhdr->h_source);
56 + batadv_handle_unclaim(bat_priv, primary_if,
57 + primary_if->net_dev->dev_addr,
58 + ethhdr->h_source, vid);
59 + goto allow;
60 + } else {
61 + batadv_dbg(BATADV_DBG_BLA, bat_priv, "bla_tx(): Race for claim %pM detected. Drop packet.\n",
62 + ethhdr->h_source);
63 + goto handled;
64 + }
65 }
66
67 /* check if it is a multicast/broadcast frame */