batman-adv: add patches from 2018.1-maint 2018-06-03
[feed/routing.git] / batman-adv / patches / 0003-batman-adv-Fix-TT-sync-flags-for-intermediate-TT-res.patch
1 From: Linus Lüssing <linus.luessing@c0d3.blue>
2 Date: Thu, 10 May 2018 19:44:28 +0200
3 Subject: [PATCH] batman-adv: Fix TT sync flags for intermediate TT responses
4
5 The previous TT sync fix so far only fixed TT responses issued by the
6 target node directly. So far, TT responses issued by intermediate nodes
7 still lead to the wrong flags being added, leading to CRC mismatches.
8
9 This behaviour was observed at Freifunk Hannover in a 800 nodes setup
10 where a considerable amount of nodes were still infected with 'WI'
11 TT flags even with (most) nodes having the previous TT sync fix applied.
12
13 I was able to reproduce the issue with intermediate TT responses in a
14 four node test setup and this patch fixes this issue by ensuring to
15 use the per originator instead of the summarized, OR'd ones.
16
17 Fixes: fa614fd04692 ("batman-adv: fix tt_global_entries flags update")
18 Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
19 Signed-off-by: Sven Eckelmann <sven@narfation.org>
20
21 Origin: upstream, https://git.open-mesh.org/batman-adv.git/commit/d65daee8617b29c1ddcc949ce3a5ec24f7a1e1af
22 ---
23 net/batman-adv/translation-table.c | 61 +++++++++++++++++++++++++-----
24 1 file changed, 51 insertions(+), 10 deletions(-)
25
26 diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
27 index 7fa3a0a0524a1da63e92d081b443c302900bf0c3..23f9c212ab1e27be429645a85f7b5d6a02585de9 100644
28 --- a/net/batman-adv/translation-table.c
29 +++ b/net/batman-adv/translation-table.c
30 @@ -1538,6 +1538,8 @@ batadv_tt_global_orig_entry_find(const struct batadv_tt_global_entry *entry,
31 * handled by a given originator
32 * @entry: the TT global entry to check
33 * @orig_node: the originator to search in the list
34 + * @flags: a pointer to store TT flags for the given @entry received
35 + * from @orig_node
36 *
37 * find out if an orig_node is already in the list of a tt_global_entry.
38 *
39 @@ -1545,7 +1547,8 @@ batadv_tt_global_orig_entry_find(const struct batadv_tt_global_entry *entry,
40 */
41 static bool
42 batadv_tt_global_entry_has_orig(const struct batadv_tt_global_entry *entry,
43 - const struct batadv_orig_node *orig_node)
44 + const struct batadv_orig_node *orig_node,
45 + u8 *flags)
46 {
47 struct batadv_tt_orig_list_entry *orig_entry;
48 bool found = false;
49 @@ -1553,6 +1556,10 @@ batadv_tt_global_entry_has_orig(const struct batadv_tt_global_entry *entry,
50 orig_entry = batadv_tt_global_orig_entry_find(entry, orig_node);
51 if (orig_entry) {
52 found = true;
53 +
54 + if (flags)
55 + *flags = orig_entry->flags;
56 +
57 batadv_tt_orig_list_entry_put(orig_entry);
58 }
59
60 @@ -1731,7 +1738,7 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv,
61 if (!(common->flags & BATADV_TT_CLIENT_TEMP))
62 goto out;
63 if (batadv_tt_global_entry_has_orig(tt_global_entry,
64 - orig_node))
65 + orig_node, NULL))
66 goto out_remove;
67 batadv_tt_global_del_orig_list(tt_global_entry);
68 goto add_orig_entry;
69 @@ -2880,23 +2887,46 @@ batadv_tt_req_node_new(struct batadv_priv *bat_priv,
70 }
71
72 /**
73 - * batadv_tt_local_valid() - verify that given tt entry is a valid one
74 + * batadv_tt_local_valid() - verify local tt entry and get flags
75 * @entry_ptr: to be checked local tt entry
76 * @data_ptr: not used but definition required to satisfy the callback prototype
77 + * @flags: a pointer to store TT flags for this client to
78 + *
79 + * Checks the validity of the given local TT entry. If it is, then the provided
80 + * flags pointer is updated.
81 *
82 * Return: true if the entry is a valid, false otherwise.
83 */
84 -static bool batadv_tt_local_valid(const void *entry_ptr, const void *data_ptr)
85 +static bool batadv_tt_local_valid(const void *entry_ptr,
86 + const void *data_ptr,
87 + u8 *flags)
88 {
89 const struct batadv_tt_common_entry *tt_common_entry = entry_ptr;
90
91 if (tt_common_entry->flags & BATADV_TT_CLIENT_NEW)
92 return false;
93 +
94 + if (flags)
95 + *flags = tt_common_entry->flags;
96 +
97 return true;
98 }
99
100 +/**
101 + * batadv_tt_global_valid() - verify global tt entry and get flags
102 + * @entry_ptr: to be checked global tt entry
103 + * @data_ptr: an orig_node object (may be NULL)
104 + * @flags: a pointer to store TT flags for this client to
105 + *
106 + * Checks the validity of the given global TT entry. If it is, then the provided
107 + * flags pointer is updated either with the common (summed) TT flags if data_ptr
108 + * is NULL or the specific, per originator TT flags otherwise.
109 + *
110 + * Return: true if the entry is a valid, false otherwise.
111 + */
112 static bool batadv_tt_global_valid(const void *entry_ptr,
113 - const void *data_ptr)
114 + const void *data_ptr,
115 + u8 *flags)
116 {
117 const struct batadv_tt_common_entry *tt_common_entry = entry_ptr;
118 const struct batadv_tt_global_entry *tt_global_entry;
119 @@ -2910,7 +2940,8 @@ static bool batadv_tt_global_valid(const void *entry_ptr,
120 struct batadv_tt_global_entry,
121 common);
122
123 - return batadv_tt_global_entry_has_orig(tt_global_entry, orig_node);
124 + return batadv_tt_global_entry_has_orig(tt_global_entry, orig_node,
125 + flags);
126 }
127
128 /**
129 @@ -2920,25 +2951,34 @@ static bool batadv_tt_global_valid(const void *entry_ptr,
130 * @hash: hash table containing the tt entries
131 * @tt_len: expected tvlv tt data buffer length in number of bytes
132 * @tvlv_buff: pointer to the buffer to fill with the TT data
133 - * @valid_cb: function to filter tt change entries
134 + * @valid_cb: function to filter tt change entries and to return TT flags
135 * @cb_data: data passed to the filter function as argument
136 + *
137 + * Fills the tvlv buff with the tt entries from the specified hash. If valid_cb
138 + * is not provided then this becomes a no-op.
139 */
140 static void batadv_tt_tvlv_generate(struct batadv_priv *bat_priv,
141 struct batadv_hashtable *hash,
142 void *tvlv_buff, u16 tt_len,
143 bool (*valid_cb)(const void *,
144 - const void *),
145 + const void *,
146 + u8 *flags),
147 void *cb_data)
148 {
149 struct batadv_tt_common_entry *tt_common_entry;
150 struct batadv_tvlv_tt_change *tt_change;
151 struct hlist_head *head;
152 u16 tt_tot, tt_num_entries = 0;
153 + u8 flags;
154 + bool ret;
155 u32 i;
156
157 tt_tot = batadv_tt_entries(tt_len);
158 tt_change = (struct batadv_tvlv_tt_change *)tvlv_buff;
159
160 + if (!valid_cb)
161 + return;
162 +
163 rcu_read_lock();
164 for (i = 0; i < hash->size; i++) {
165 head = &hash->table[i];
166 @@ -2948,11 +2988,12 @@ static void batadv_tt_tvlv_generate(struct batadv_priv *bat_priv,
167 if (tt_tot == tt_num_entries)
168 break;
169
170 - if ((valid_cb) && (!valid_cb(tt_common_entry, cb_data)))
171 + ret = valid_cb(tt_common_entry, cb_data, &flags);
172 + if (!ret)
173 continue;
174
175 ether_addr_copy(tt_change->addr, tt_common_entry->addr);
176 - tt_change->flags = tt_common_entry->flags;
177 + tt_change->flags = flags;
178 tt_change->vid = htons(tt_common_entry->vid);
179 memset(tt_change->reserved, 0,
180 sizeof(tt_change->reserved));