batman-adv: Refresh patches
[feed/routing.git] / batman-adv / patches / 0039-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: 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 diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
28 index 94527e5e859dcdb443b2fc9c3fbbe06aae3b4a08..743963bf39dca73f7554f9f85fffd57fd6a3c963 100644
29 --- a/net/batman-adv/translation-table.c
30 +++ b/net/batman-adv/translation-table.c
31 @@ -929,15 +929,20 @@ batadv_tt_prepare_tvlv_local_data(struct batadv_priv *bat_priv,
32 struct batadv_tvlv_tt_vlan_data *tt_vlan;
33 struct batadv_softif_vlan *vlan;
34 u16 num_vlan = 0;
35 - u16 num_entries = 0;
36 + u16 vlan_entries = 0;
37 + u16 total_entries = 0;
38 u16 tvlv_len;
39 u8 *tt_change_ptr;
40 int change_offset;
41
42 spin_lock_bh(&bat_priv->softif_vlan_list_lock);
43 hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list) {
44 + vlan_entries = atomic_read(&vlan->tt.num_entries);
45 + if (vlan_entries < 1)
46 + continue;
47 +
48 num_vlan++;
49 - num_entries += atomic_read(&vlan->tt.num_entries);
50 + total_entries += vlan_entries;
51 }
52
53 change_offset = sizeof(**tt_data);
54 @@ -945,7 +950,7 @@ batadv_tt_prepare_tvlv_local_data(struct batadv_priv *bat_priv,
55
56 /* if tt_len is negative, allocate the space needed by the full table */
57 if (*tt_len < 0)
58 - *tt_len = batadv_tt_len(num_entries);
59 + *tt_len = batadv_tt_len(total_entries);
60
61 tvlv_len = *tt_len;
62 tvlv_len += change_offset;
63 @@ -962,6 +967,10 @@ batadv_tt_prepare_tvlv_local_data(struct batadv_priv *bat_priv,
64
65 tt_vlan = (struct batadv_tvlv_tt_vlan_data *)(*tt_data + 1);
66 hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list) {
67 + vlan_entries = atomic_read(&vlan->tt.num_entries);
68 + if (vlan_entries < 1)
69 + continue;
70 +
71 tt_vlan->vid = htons(vlan->vid);
72 tt_vlan->crc = htonl(vlan->tt.crc);
73