batman-adv: add patches from 2018.1-maint 2018-06-03
[feed/routing.git] / batman-adv / patches / 0004-batman-adv-prevent-TT-request-storms-by-not-sending-.patch
1 From: Marek Lindner <mareklindner@neomailbox.ch>
2 Date: Sat, 12 May 2018 00:23:07 +0800
3 Subject: [PATCH] batman-adv: prevent TT request storms by not sending inconsistent TT TLVLs
4
5 A translation table TVLV changset sent with an OGM consists
6 of a number of headers (one per VLAN) plus the changeset
7 itself (addition and/or deletion of entries).
8
9 The per-VLAN headers are used by OGM recipients for consistency
10 checks. Said consistency check might determine that a full
11 translation table request is needed to restore consistency. If
12 the TT sender adds per-VLAN headers of empty VLANs into the OGM,
13 recipients are led to believe to have reached an inconsistent
14 state and thus request a full table update. The full table does
15 not contain empty VLANs (due to missing entries) the cycle
16 restarts when the next OGM is issued.
17
18 Consequently, when the translation table TVLV headers are
19 composed, empty VLANs are to be excluded.
20
21 Fixes: 21a57f6e7a3b ("batman-adv: make the TT CRC logic VLAN specific")
22 Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
23 Signed-off-by: Sven Eckelmann <sven@narfation.org>
24
25 Origin: upstream, https://git.open-mesh.org/batman-adv.git/commit/e4687b4be274da6180fc15b327419851fb681ec9
26 ---
27 net/batman-adv/translation-table.c | 15 ++++++++++++---
28 1 file changed, 12 insertions(+), 3 deletions(-)
29
30 diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
31 index 23f9c212ab1e27be429645a85f7b5d6a02585de9..3986551397caa5ffb6ba7338eeb4769c8b8f99fb 100644
32 --- a/net/batman-adv/translation-table.c
33 +++ b/net/batman-adv/translation-table.c
34 @@ -931,15 +931,20 @@ batadv_tt_prepare_tvlv_local_data(struct batadv_priv *bat_priv,
35 struct batadv_tvlv_tt_vlan_data *tt_vlan;
36 struct batadv_softif_vlan *vlan;
37 u16 num_vlan = 0;
38 - u16 num_entries = 0;
39 + u16 vlan_entries = 0;
40 + u16 total_entries = 0;
41 u16 tvlv_len;
42 u8 *tt_change_ptr;
43 int change_offset;
44
45 spin_lock_bh(&bat_priv->softif_vlan_list_lock);
46 hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list) {
47 + vlan_entries = atomic_read(&vlan->tt.num_entries);
48 + if (vlan_entries < 1)
49 + continue;
50 +
51 num_vlan++;
52 - num_entries += atomic_read(&vlan->tt.num_entries);
53 + total_entries += vlan_entries;
54 }
55
56 change_offset = sizeof(**tt_data);
57 @@ -947,7 +952,7 @@ batadv_tt_prepare_tvlv_local_data(struct batadv_priv *bat_priv,
58
59 /* if tt_len is negative, allocate the space needed by the full table */
60 if (*tt_len < 0)
61 - *tt_len = batadv_tt_len(num_entries);
62 + *tt_len = batadv_tt_len(total_entries);
63
64 tvlv_len = *tt_len;
65 tvlv_len += change_offset;
66 @@ -964,6 +969,10 @@ batadv_tt_prepare_tvlv_local_data(struct batadv_priv *bat_priv,
67
68 tt_vlan = (struct batadv_tvlv_tt_vlan_data *)(*tt_data + 1);
69 hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list) {
70 + vlan_entries = atomic_read(&vlan->tt.num_entries);
71 + if (vlan_entries < 1)
72 + continue;
73 +
74 tt_vlan->vid = htons(vlan->vid);
75 tt_vlan->crc = htonl(vlan->tt.crc);
76