aboutsummaryrefslogtreecommitdiffstats
path: root/net/batman-adv/vis.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/batman-adv/vis.c')
-rw-r--r--net/batman-adv/vis.c422
1 files changed, 184 insertions, 238 deletions
diff --git a/net/batman-adv/vis.c b/net/batman-adv/vis.c
index d45989e0bbd7..74181696eef6 100644
--- a/net/batman-adv/vis.c
+++ b/net/batman-adv/vis.c
@@ -26,12 +26,12 @@
26#include "hash.h" 26#include "hash.h"
27#include "originator.h" 27#include "originator.h"
28 28
29#define MAX_VIS_PACKET_SIZE 1000 29#define BATADV_MAX_VIS_PACKET_SIZE 1000
30 30
31static void start_vis_timer(struct bat_priv *bat_priv); 31static void batadv_start_vis_timer(struct bat_priv *bat_priv);
32 32
33/* free the info */ 33/* free the info */
34static void free_info(struct kref *ref) 34static void batadv_free_info(struct kref *ref)
35{ 35{
36 struct vis_info *info = container_of(ref, struct vis_info, refcount); 36 struct vis_info *info = container_of(ref, struct vis_info, refcount);
37 struct bat_priv *bat_priv = info->bat_priv; 37 struct bat_priv *bat_priv = info->bat_priv;
@@ -50,7 +50,7 @@ static void free_info(struct kref *ref)
50} 50}
51 51
52/* Compare two vis packets, used by the hashing algorithm */ 52/* Compare two vis packets, used by the hashing algorithm */
53static int vis_info_cmp(const struct hlist_node *node, const void *data2) 53static int batadv_vis_info_cmp(const struct hlist_node *node, const void *data2)
54{ 54{
55 const struct vis_info *d1, *d2; 55 const struct vis_info *d1, *d2;
56 const struct vis_packet *p1, *p2; 56 const struct vis_packet *p1, *p2;
@@ -65,7 +65,7 @@ static int vis_info_cmp(const struct hlist_node *node, const void *data2)
65/* hash function to choose an entry in a hash table of given size 65/* hash function to choose an entry in a hash table of given size
66 * hash algorithm from http://en.wikipedia.org/wiki/Hash_table 66 * hash algorithm from http://en.wikipedia.org/wiki/Hash_table
67 */ 67 */
68static uint32_t vis_info_choose(const void *data, uint32_t size) 68static uint32_t batadv_vis_info_choose(const void *data, uint32_t size)
69{ 69{
70 const struct vis_info *vis_info = data; 70 const struct vis_info *vis_info = data;
71 const struct vis_packet *packet; 71 const struct vis_packet *packet;
@@ -88,8 +88,8 @@ static uint32_t vis_info_choose(const void *data, uint32_t size)
88 return hash % size; 88 return hash % size;
89} 89}
90 90
91static struct vis_info *vis_hash_find(struct bat_priv *bat_priv, 91static struct vis_info *batadv_vis_hash_find(struct bat_priv *bat_priv,
92 const void *data) 92 const void *data)
93{ 93{
94 struct hashtable_t *hash = bat_priv->vis_hash; 94 struct hashtable_t *hash = bat_priv->vis_hash;
95 struct hlist_head *head; 95 struct hlist_head *head;
@@ -100,12 +100,12 @@ static struct vis_info *vis_hash_find(struct bat_priv *bat_priv,
100 if (!hash) 100 if (!hash)
101 return NULL; 101 return NULL;
102 102
103 index = vis_info_choose(data, hash->size); 103 index = batadv_vis_info_choose(data, hash->size);
104 head = &hash->table[index]; 104 head = &hash->table[index];
105 105
106 rcu_read_lock(); 106 rcu_read_lock();
107 hlist_for_each_entry_rcu(vis_info, node, head, hash_entry) { 107 hlist_for_each_entry_rcu(vis_info, node, head, hash_entry) {
108 if (!vis_info_cmp(node, data)) 108 if (!batadv_vis_info_cmp(node, data))
109 continue; 109 continue;
110 110
111 vis_info_tmp = vis_info; 111 vis_info_tmp = vis_info;
@@ -119,9 +119,9 @@ static struct vis_info *vis_hash_find(struct bat_priv *bat_priv,
119/* insert interface to the list of interfaces of one originator, if it 119/* insert interface to the list of interfaces of one originator, if it
120 * does not already exist in the list 120 * does not already exist in the list
121 */ 121 */
122static void vis_data_insert_interface(const uint8_t *interface, 122static void batadv_vis_data_insert_interface(const uint8_t *interface,
123 struct hlist_head *if_list, 123 struct hlist_head *if_list,
124 bool primary) 124 bool primary)
125{ 125{
126 struct if_list_entry *entry; 126 struct if_list_entry *entry;
127 struct hlist_node *pos; 127 struct hlist_node *pos;
@@ -140,73 +140,117 @@ static void vis_data_insert_interface(const uint8_t *interface,
140 hlist_add_head(&entry->list, if_list); 140 hlist_add_head(&entry->list, if_list);
141} 141}
142 142
143static ssize_t vis_data_read_prim_sec(char *buff, 143static void batadv_vis_data_read_prim_sec(struct seq_file *seq,
144 const struct hlist_head *if_list) 144 const struct hlist_head *if_list)
145{ 145{
146 struct if_list_entry *entry; 146 struct if_list_entry *entry;
147 struct hlist_node *pos; 147 struct hlist_node *pos;
148 size_t len = 0;
149 148
150 hlist_for_each_entry(entry, pos, if_list, list) { 149 hlist_for_each_entry(entry, pos, if_list, list) {
151 if (entry->primary) 150 if (entry->primary)
152 len += sprintf(buff + len, "PRIMARY, "); 151 seq_printf(seq, "PRIMARY, ");
153 else 152 else
154 len += sprintf(buff + len, "SEC %pM, ", entry->addr); 153 seq_printf(seq, "SEC %pM, ", entry->addr);
155 } 154 }
155}
156
157/* read an entry */
158static ssize_t batadv_vis_data_read_entry(struct seq_file *seq,
159 const struct vis_info_entry *entry,
160 const uint8_t *src, bool primary)
161{
162 if (primary && entry->quality == 0)
163 return seq_printf(seq, "TT %pM, ", entry->dest);
164 else if (batadv_compare_eth(entry->src, src))
165 return seq_printf(seq, "TQ %pM %d, ", entry->dest,
166 entry->quality);
167
168 return 0;
169}
170
171static void batadv_vis_data_insert_interfaces(struct hlist_head *list,
172 struct vis_packet *packet,
173 struct vis_info_entry *entries)
174{
175 int i;
176
177 for (i = 0; i < packet->entries; i++) {
178 if (entries[i].quality == 0)
179 continue;
180
181 if (batadv_compare_eth(entries[i].src, packet->vis_orig))
182 continue;
156 183
157 return len; 184 batadv_vis_data_insert_interface(entries[i].src, list, false);
185 }
158} 186}
159 187
160static size_t vis_data_count_prim_sec(struct hlist_head *if_list) 188static void batadv_vis_data_read_entries(struct seq_file *seq,
189 struct hlist_head *list,
190 struct vis_packet *packet,
191 struct vis_info_entry *entries)
161{ 192{
193 int i;
162 struct if_list_entry *entry; 194 struct if_list_entry *entry;
163 struct hlist_node *pos; 195 struct hlist_node *pos;
164 size_t count = 0;
165 196
166 hlist_for_each_entry(entry, pos, if_list, list) { 197 hlist_for_each_entry(entry, pos, list, list) {
167 if (entry->primary) 198 seq_printf(seq, "%pM,", entry->addr);
168 count += 9;
169 else
170 count += 23;
171 }
172 199
173 return count; 200 for (i = 0; i < packet->entries; i++)
201 batadv_vis_data_read_entry(seq, &entries[i],
202 entry->addr, entry->primary);
203
204 /* add primary/secondary records */
205 if (batadv_compare_eth(entry->addr, packet->vis_orig))
206 batadv_vis_data_read_prim_sec(seq, list);
207
208 seq_printf(seq, "\n");
209 }
174} 210}
175 211
176/* read an entry */ 212static void batadv_vis_seq_print_text_bucket(struct seq_file *seq,
177static ssize_t vis_data_read_entry(char *buff, 213 const struct hlist_head *head)
178 const struct vis_info_entry *entry,
179 const uint8_t *src, bool primary)
180{ 214{
181 /* maximal length: max(4+17+2, 3+17+1+3+2) == 26 */ 215 struct hlist_node *node;
182 if (primary && entry->quality == 0) 216 struct vis_info *info;
183 return sprintf(buff, "TT %pM, ", entry->dest); 217 struct vis_packet *packet;
184 else if (batadv_compare_eth(entry->src, src)) 218 uint8_t *entries_pos;
185 return sprintf(buff, "TQ %pM %d, ", entry->dest, 219 struct vis_info_entry *entries;
186 entry->quality); 220 struct if_list_entry *entry;
221 struct hlist_node *pos, *n;
187 222
188 return 0; 223 HLIST_HEAD(vis_if_list);
224
225 hlist_for_each_entry_rcu(info, node, head, hash_entry) {
226 packet = (struct vis_packet *)info->skb_packet->data;
227 entries_pos = (uint8_t *)packet + sizeof(*packet);
228 entries = (struct vis_info_entry *)entries_pos;
229
230 batadv_vis_data_insert_interface(packet->vis_orig, &vis_if_list,
231 true);
232 batadv_vis_data_insert_interfaces(&vis_if_list, packet,
233 entries);
234 batadv_vis_data_read_entries(seq, &vis_if_list, packet,
235 entries);
236
237 hlist_for_each_entry_safe(entry, pos, n, &vis_if_list, list) {
238 hlist_del(&entry->list);
239 kfree(entry);
240 }
241 }
189} 242}
190 243
191int batadv_vis_seq_print_text(struct seq_file *seq, void *offset) 244int batadv_vis_seq_print_text(struct seq_file *seq, void *offset)
192{ 245{
193 struct hard_iface *primary_if; 246 struct hard_iface *primary_if;
194 struct hlist_node *node;
195 struct hlist_head *head; 247 struct hlist_head *head;
196 struct vis_info *info;
197 struct vis_packet *packet;
198 struct vis_info_entry *entries;
199 struct net_device *net_dev = (struct net_device *)seq->private; 248 struct net_device *net_dev = (struct net_device *)seq->private;
200 struct bat_priv *bat_priv = netdev_priv(net_dev); 249 struct bat_priv *bat_priv = netdev_priv(net_dev);
201 struct hashtable_t *hash = bat_priv->vis_hash; 250 struct hashtable_t *hash = bat_priv->vis_hash;
202 HLIST_HEAD(vis_if_list);
203 struct if_list_entry *entry;
204 struct hlist_node *pos, *n;
205 uint32_t i; 251 uint32_t i;
206 int j, ret = 0; 252 int ret = 0;
207 int vis_server = atomic_read(&bat_priv->vis_mode); 253 int vis_server = atomic_read(&bat_priv->vis_mode);
208 size_t buff_pos, buf_size;
209 char *buff;
210 254
211 primary_if = batadv_primary_if_get_selected(bat_priv); 255 primary_if = batadv_primary_if_get_selected(bat_priv);
212 if (!primary_if) 256 if (!primary_if)
@@ -215,120 +259,13 @@ int batadv_vis_seq_print_text(struct seq_file *seq, void *offset)
215 if (vis_server == VIS_TYPE_CLIENT_UPDATE) 259 if (vis_server == VIS_TYPE_CLIENT_UPDATE)
216 goto out; 260 goto out;
217 261
218 buf_size = 1;
219 /* Estimate length */
220 spin_lock_bh(&bat_priv->vis_hash_lock); 262 spin_lock_bh(&bat_priv->vis_hash_lock);
221 for (i = 0; i < hash->size; i++) { 263 for (i = 0; i < hash->size; i++) {
222 head = &hash->table[i]; 264 head = &hash->table[i];
223 265 batadv_vis_seq_print_text_bucket(seq, head);
224 rcu_read_lock();
225 hlist_for_each_entry_rcu(info, node, head, hash_entry) {
226 packet = (struct vis_packet *)info->skb_packet->data;
227 entries = (struct vis_info_entry *)
228 ((char *)packet + sizeof(*packet));
229
230 vis_data_insert_interface(packet->vis_orig,
231 &vis_if_list, true);
232
233 for (j = 0; j < packet->entries; j++) {
234 if (entries[j].quality == 0)
235 continue;
236 if (batadv_compare_eth(entries[j].src,
237 packet->vis_orig))
238 continue;
239 vis_data_insert_interface(entries[j].src,
240 &vis_if_list,
241 false);
242 }
243
244 hlist_for_each_entry(entry, pos, &vis_if_list, list) {
245 buf_size += 18 + 26 * packet->entries;
246
247 /* add primary/secondary records */
248 if (batadv_compare_eth(entry->addr,
249 packet->vis_orig))
250 buf_size +=
251 vis_data_count_prim_sec(&vis_if_list);
252
253 buf_size += 1;
254 }
255
256 hlist_for_each_entry_safe(entry, pos, n, &vis_if_list,
257 list) {
258 hlist_del(&entry->list);
259 kfree(entry);
260 }
261 }
262 rcu_read_unlock();
263 }
264
265 buff = kmalloc(buf_size, GFP_ATOMIC);
266 if (!buff) {
267 spin_unlock_bh(&bat_priv->vis_hash_lock);
268 ret = -ENOMEM;
269 goto out;
270 }
271 buff[0] = '\0';
272 buff_pos = 0;
273
274 for (i = 0; i < hash->size; i++) {
275 head = &hash->table[i];
276
277 rcu_read_lock();
278 hlist_for_each_entry_rcu(info, node, head, hash_entry) {
279 packet = (struct vis_packet *)info->skb_packet->data;
280 entries = (struct vis_info_entry *)
281 ((char *)packet + sizeof(*packet));
282
283 vis_data_insert_interface(packet->vis_orig,
284 &vis_if_list, true);
285
286 for (j = 0; j < packet->entries; j++) {
287 if (entries[j].quality == 0)
288 continue;
289 if (batadv_compare_eth(entries[j].src,
290 packet->vis_orig))
291 continue;
292 vis_data_insert_interface(entries[j].src,
293 &vis_if_list,
294 false);
295 }
296
297 hlist_for_each_entry(entry, pos, &vis_if_list, list) {
298 buff_pos += sprintf(buff + buff_pos, "%pM,",
299 entry->addr);
300
301 for (j = 0; j < packet->entries; j++)
302 buff_pos += vis_data_read_entry(
303 buff + buff_pos,
304 &entries[j],
305 entry->addr,
306 entry->primary);
307
308 /* add primary/secondary records */
309 if (batadv_compare_eth(entry->addr,
310 packet->vis_orig))
311 buff_pos +=
312 vis_data_read_prim_sec(buff + buff_pos,
313 &vis_if_list);
314
315 buff_pos += sprintf(buff + buff_pos, "\n");
316 }
317
318 hlist_for_each_entry_safe(entry, pos, n, &vis_if_list,
319 list) {
320 hlist_del(&entry->list);
321 kfree(entry);
322 }
323 }
324 rcu_read_unlock();
325 } 266 }
326
327 spin_unlock_bh(&bat_priv->vis_hash_lock); 267 spin_unlock_bh(&bat_priv->vis_hash_lock);
328 268
329 seq_printf(seq, "%s", buff);
330 kfree(buff);
331
332out: 269out:
333 if (primary_if) 270 if (primary_if)
334 batadv_hardif_free_ref(primary_if); 271 batadv_hardif_free_ref(primary_if);
@@ -338,7 +275,8 @@ out:
338/* add the info packet to the send list, if it was not 275/* add the info packet to the send list, if it was not
339 * already linked in. 276 * already linked in.
340 */ 277 */
341static void send_list_add(struct bat_priv *bat_priv, struct vis_info *info) 278static void batadv_send_list_add(struct bat_priv *bat_priv,
279 struct vis_info *info)
342{ 280{
343 if (list_empty(&info->send_list)) { 281 if (list_empty(&info->send_list)) {
344 kref_get(&info->refcount); 282 kref_get(&info->refcount);
@@ -349,17 +287,17 @@ static void send_list_add(struct bat_priv *bat_priv, struct vis_info *info)
349/* delete the info packet from the send list, if it was 287/* delete the info packet from the send list, if it was
350 * linked in. 288 * linked in.
351 */ 289 */
352static void send_list_del(struct vis_info *info) 290static void batadv_send_list_del(struct vis_info *info)
353{ 291{
354 if (!list_empty(&info->send_list)) { 292 if (!list_empty(&info->send_list)) {
355 list_del_init(&info->send_list); 293 list_del_init(&info->send_list);
356 kref_put(&info->refcount, free_info); 294 kref_put(&info->refcount, batadv_free_info);
357 } 295 }
358} 296}
359 297
360/* tries to add one entry to the receive list. */ 298/* tries to add one entry to the receive list. */
361static void recv_list_add(struct bat_priv *bat_priv, 299static void batadv_recv_list_add(struct bat_priv *bat_priv,
362 struct list_head *recv_list, const char *mac) 300 struct list_head *recv_list, const char *mac)
363{ 301{
364 struct recvlist_node *entry; 302 struct recvlist_node *entry;
365 303
@@ -374,8 +312,9 @@ static void recv_list_add(struct bat_priv *bat_priv,
374} 312}
375 313
376/* returns 1 if this mac is in the recv_list */ 314/* returns 1 if this mac is in the recv_list */
377static int recv_list_is_in(struct bat_priv *bat_priv, 315static int batadv_recv_list_is_in(struct bat_priv *bat_priv,
378 const struct list_head *recv_list, const char *mac) 316 const struct list_head *recv_list,
317 const char *mac)
379{ 318{
380 const struct recvlist_node *entry; 319 const struct recvlist_node *entry;
381 320
@@ -394,10 +333,10 @@ static int recv_list_is_in(struct bat_priv *bat_priv,
394 * broken.. ). vis hash must be locked outside. is_new is set when the packet 333 * broken.. ). vis hash must be locked outside. is_new is set when the packet
395 * is newer than old entries in the hash. 334 * is newer than old entries in the hash.
396 */ 335 */
397static struct vis_info *add_packet(struct bat_priv *bat_priv, 336static struct vis_info *batadv_add_packet(struct bat_priv *bat_priv,
398 struct vis_packet *vis_packet, 337 struct vis_packet *vis_packet,
399 int vis_info_len, int *is_new, 338 int vis_info_len, int *is_new,
400 int make_broadcast) 339 int make_broadcast)
401{ 340{
402 struct vis_info *info, *old_info; 341 struct vis_info *info, *old_info;
403 struct vis_packet *search_packet, *old_packet; 342 struct vis_packet *search_packet, *old_packet;
@@ -418,16 +357,17 @@ static struct vis_info *add_packet(struct bat_priv *bat_priv,
418 sizeof(*search_packet)); 357 sizeof(*search_packet));
419 358
420 memcpy(search_packet->vis_orig, vis_packet->vis_orig, ETH_ALEN); 359 memcpy(search_packet->vis_orig, vis_packet->vis_orig, ETH_ALEN);
421 old_info = vis_hash_find(bat_priv, &search_elem); 360 old_info = batadv_vis_hash_find(bat_priv, &search_elem);
422 kfree_skb(search_elem.skb_packet); 361 kfree_skb(search_elem.skb_packet);
423 362
424 if (old_info) { 363 if (old_info) {
425 old_packet = (struct vis_packet *)old_info->skb_packet->data; 364 old_packet = (struct vis_packet *)old_info->skb_packet->data;
426 if (!seq_after(ntohl(vis_packet->seqno), 365 if (!batadv_seq_after(ntohl(vis_packet->seqno),
427 ntohl(old_packet->seqno))) { 366 ntohl(old_packet->seqno))) {
428 if (old_packet->seqno == vis_packet->seqno) { 367 if (old_packet->seqno == vis_packet->seqno) {
429 recv_list_add(bat_priv, &old_info->recv_list, 368 batadv_recv_list_add(bat_priv,
430 vis_packet->sender_orig); 369 &old_info->recv_list,
370 vis_packet->sender_orig);
431 return old_info; 371 return old_info;
432 } else { 372 } else {
433 /* newer packet is already in hash. */ 373 /* newer packet is already in hash. */
@@ -435,10 +375,10 @@ static struct vis_info *add_packet(struct bat_priv *bat_priv,
435 } 375 }
436 } 376 }
437 /* remove old entry */ 377 /* remove old entry */
438 batadv_hash_remove(bat_priv->vis_hash, vis_info_cmp, 378 batadv_hash_remove(bat_priv->vis_hash, batadv_vis_info_cmp,
439 vis_info_choose, old_info); 379 batadv_vis_info_choose, old_info);
440 send_list_del(old_info); 380 batadv_send_list_del(old_info);
441 kref_put(&old_info->refcount, free_info); 381 kref_put(&old_info->refcount, batadv_free_info);
442 } 382 }
443 383
444 info = kmalloc(sizeof(*info), GFP_ATOMIC); 384 info = kmalloc(sizeof(*info), GFP_ATOMIC);
@@ -473,14 +413,15 @@ static struct vis_info *add_packet(struct bat_priv *bat_priv,
473 if (packet->entries * sizeof(struct vis_info_entry) > vis_info_len) 413 if (packet->entries * sizeof(struct vis_info_entry) > vis_info_len)
474 packet->entries = vis_info_len / sizeof(struct vis_info_entry); 414 packet->entries = vis_info_len / sizeof(struct vis_info_entry);
475 415
476 recv_list_add(bat_priv, &info->recv_list, packet->sender_orig); 416 batadv_recv_list_add(bat_priv, &info->recv_list, packet->sender_orig);
477 417
478 /* try to add it */ 418 /* try to add it */
479 hash_added = batadv_hash_add(bat_priv->vis_hash, vis_info_cmp, 419 hash_added = batadv_hash_add(bat_priv->vis_hash, batadv_vis_info_cmp,
480 vis_info_choose, info, &info->hash_entry); 420 batadv_vis_info_choose, info,
421 &info->hash_entry);
481 if (hash_added != 0) { 422 if (hash_added != 0) {
482 /* did not work (for some reason) */ 423 /* did not work (for some reason) */
483 kref_put(&info->refcount, free_info); 424 kref_put(&info->refcount, batadv_free_info);
484 info = NULL; 425 info = NULL;
485 } 426 }
486 427
@@ -499,8 +440,8 @@ void batadv_receive_server_sync_packet(struct bat_priv *bat_priv,
499 make_broadcast = (vis_server == VIS_TYPE_SERVER_SYNC); 440 make_broadcast = (vis_server == VIS_TYPE_SERVER_SYNC);
500 441
501 spin_lock_bh(&bat_priv->vis_hash_lock); 442 spin_lock_bh(&bat_priv->vis_hash_lock);
502 info = add_packet(bat_priv, vis_packet, vis_info_len, 443 info = batadv_add_packet(bat_priv, vis_packet, vis_info_len,
503 &is_new, make_broadcast); 444 &is_new, make_broadcast);
504 if (!info) 445 if (!info)
505 goto end; 446 goto end;
506 447
@@ -508,7 +449,7 @@ void batadv_receive_server_sync_packet(struct bat_priv *bat_priv,
508 * hash. 449 * hash.
509 */ 450 */
510 if (vis_server == VIS_TYPE_SERVER_SYNC && is_new) 451 if (vis_server == VIS_TYPE_SERVER_SYNC && is_new)
511 send_list_add(bat_priv, info); 452 batadv_send_list_add(bat_priv, info);
512end: 453end:
513 spin_unlock_bh(&bat_priv->vis_hash_lock); 454 spin_unlock_bh(&bat_priv->vis_hash_lock);
514} 455}
@@ -534,8 +475,8 @@ void batadv_receive_client_update_packet(struct bat_priv *bat_priv,
534 are_target = 1; 475 are_target = 1;
535 476
536 spin_lock_bh(&bat_priv->vis_hash_lock); 477 spin_lock_bh(&bat_priv->vis_hash_lock);
537 info = add_packet(bat_priv, vis_packet, vis_info_len, 478 info = batadv_add_packet(bat_priv, vis_packet, vis_info_len,
538 &is_new, are_target); 479 &is_new, are_target);
539 480
540 if (!info) 481 if (!info)
541 goto end; 482 goto end;
@@ -546,11 +487,11 @@ void batadv_receive_client_update_packet(struct bat_priv *bat_priv,
546 /* send only if we're the target server or ... */ 487 /* send only if we're the target server or ... */
547 if (are_target && is_new) { 488 if (are_target && is_new) {
548 packet->vis_type = VIS_TYPE_SERVER_SYNC; /* upgrade! */ 489 packet->vis_type = VIS_TYPE_SERVER_SYNC; /* upgrade! */
549 send_list_add(bat_priv, info); 490 batadv_send_list_add(bat_priv, info);
550 491
551 /* ... we're not the recipient (and thus need to forward). */ 492 /* ... we're not the recipient (and thus need to forward). */
552 } else if (!batadv_is_my_mac(packet->target_orig)) { 493 } else if (!batadv_is_my_mac(packet->target_orig)) {
553 send_list_add(bat_priv, info); 494 batadv_send_list_add(bat_priv, info);
554 } 495 }
555 496
556end: 497end:
@@ -562,8 +503,8 @@ end:
562 * 503 *
563 * Must be called with the originator hash locked 504 * Must be called with the originator hash locked
564 */ 505 */
565static int find_best_vis_server(struct bat_priv *bat_priv, 506static int batadv_find_best_vis_server(struct bat_priv *bat_priv,
566 struct vis_info *info) 507 struct vis_info *info)
567{ 508{
568 struct hashtable_t *hash = bat_priv->orig_hash; 509 struct hashtable_t *hash = bat_priv->orig_hash;
569 struct neigh_node *router; 510 struct neigh_node *router;
@@ -600,13 +541,15 @@ static int find_best_vis_server(struct bat_priv *bat_priv,
600} 541}
601 542
602/* Return true if the vis packet is full. */ 543/* Return true if the vis packet is full. */
603static bool vis_packet_full(const struct vis_info *info) 544static bool batadv_vis_packet_full(const struct vis_info *info)
604{ 545{
605 const struct vis_packet *packet; 546 const struct vis_packet *packet;
547 size_t num_items;
548
606 packet = (struct vis_packet *)info->skb_packet->data; 549 packet = (struct vis_packet *)info->skb_packet->data;
550 num_items = BATADV_MAX_VIS_PACKET_SIZE / sizeof(struct vis_info_entry);
607 551
608 if (MAX_VIS_PACKET_SIZE / sizeof(struct vis_info_entry) 552 if (num_items < packet->entries + 1)
609 < packet->entries + 1)
610 return true; 553 return true;
611 return false; 554 return false;
612} 555}
@@ -614,7 +557,7 @@ static bool vis_packet_full(const struct vis_info *info)
614/* generates a packet of own vis data, 557/* generates a packet of own vis data,
615 * returns 0 on success, -1 if no packet could be generated 558 * returns 0 on success, -1 if no packet could be generated
616 */ 559 */
617static int generate_vis_packet(struct bat_priv *bat_priv) 560static int batadv_generate_vis_packet(struct bat_priv *bat_priv)
618{ 561{
619 struct hashtable_t *hash = bat_priv->orig_hash; 562 struct hashtable_t *hash = bat_priv->orig_hash;
620 struct hlist_node *node; 563 struct hlist_node *node;
@@ -632,13 +575,13 @@ static int generate_vis_packet(struct bat_priv *bat_priv)
632 packet->vis_type = atomic_read(&bat_priv->vis_mode); 575 packet->vis_type = atomic_read(&bat_priv->vis_mode);
633 576
634 memcpy(packet->target_orig, batadv_broadcast_addr, ETH_ALEN); 577 memcpy(packet->target_orig, batadv_broadcast_addr, ETH_ALEN);
635 packet->header.ttl = TTL; 578 packet->header.ttl = BATADV_TTL;
636 packet->seqno = htonl(ntohl(packet->seqno) + 1); 579 packet->seqno = htonl(ntohl(packet->seqno) + 1);
637 packet->entries = 0; 580 packet->entries = 0;
638 skb_trim(info->skb_packet, sizeof(*packet)); 581 skb_trim(info->skb_packet, sizeof(*packet));
639 582
640 if (packet->vis_type == VIS_TYPE_CLIENT_UPDATE) { 583 if (packet->vis_type == VIS_TYPE_CLIENT_UPDATE) {
641 best_tq = find_best_vis_server(bat_priv, info); 584 best_tq = batadv_find_best_vis_server(bat_priv, info);
642 585
643 if (best_tq < 0) 586 if (best_tq < 0)
644 return best_tq; 587 return best_tq;
@@ -675,7 +618,7 @@ static int generate_vis_packet(struct bat_priv *bat_priv)
675next: 618next:
676 batadv_neigh_node_free_ref(router); 619 batadv_neigh_node_free_ref(router);
677 620
678 if (vis_packet_full(info)) 621 if (batadv_vis_packet_full(info))
679 goto unlock; 622 goto unlock;
680 } 623 }
681 rcu_read_unlock(); 624 rcu_read_unlock();
@@ -697,7 +640,7 @@ next:
697 entry->quality = 0; /* 0 means TT */ 640 entry->quality = 0; /* 0 means TT */
698 packet->entries++; 641 packet->entries++;
699 642
700 if (vis_packet_full(info)) 643 if (batadv_vis_packet_full(info))
701 goto unlock; 644 goto unlock;
702 } 645 }
703 rcu_read_unlock(); 646 rcu_read_unlock();
@@ -713,7 +656,7 @@ unlock:
713/* free old vis packets. Must be called with this vis_hash_lock 656/* free old vis packets. Must be called with this vis_hash_lock
714 * held 657 * held
715 */ 658 */
716static void purge_vis_packets(struct bat_priv *bat_priv) 659static void batadv_purge_vis_packets(struct bat_priv *bat_priv)
717{ 660{
718 uint32_t i; 661 uint32_t i;
719 struct hashtable_t *hash = bat_priv->vis_hash; 662 struct hashtable_t *hash = bat_priv->vis_hash;
@@ -731,17 +674,17 @@ static void purge_vis_packets(struct bat_priv *bat_priv)
731 continue; 674 continue;
732 675
733 if (batadv_has_timed_out(info->first_seen, 676 if (batadv_has_timed_out(info->first_seen,
734 VIS_TIMEOUT)) { 677 BATADV_VIS_TIMEOUT)) {
735 hlist_del(node); 678 hlist_del(node);
736 send_list_del(info); 679 batadv_send_list_del(info);
737 kref_put(&info->refcount, free_info); 680 kref_put(&info->refcount, batadv_free_info);
738 } 681 }
739 } 682 }
740 } 683 }
741} 684}
742 685
743static void broadcast_vis_packet(struct bat_priv *bat_priv, 686static void batadv_broadcast_vis_packet(struct bat_priv *bat_priv,
744 struct vis_info *info) 687 struct vis_info *info)
745{ 688{
746 struct neigh_node *router; 689 struct neigh_node *router;
747 struct hashtable_t *hash = bat_priv->orig_hash; 690 struct hashtable_t *hash = bat_priv->orig_hash;
@@ -774,8 +717,8 @@ static void broadcast_vis_packet(struct bat_priv *bat_priv,
774 /* don't send it if we already received the packet from 717 /* don't send it if we already received the packet from
775 * this node. 718 * this node.
776 */ 719 */
777 if (recv_list_is_in(bat_priv, &info->recv_list, 720 if (batadv_recv_list_is_in(bat_priv, &info->recv_list,
778 orig_node->orig)) { 721 orig_node->orig)) {
779 batadv_neigh_node_free_ref(router); 722 batadv_neigh_node_free_ref(router);
780 continue; 723 continue;
781 } 724 }
@@ -796,8 +739,8 @@ static void broadcast_vis_packet(struct bat_priv *bat_priv,
796 } 739 }
797} 740}
798 741
799static void unicast_vis_packet(struct bat_priv *bat_priv, 742static void batadv_unicast_vis_packet(struct bat_priv *bat_priv,
800 struct vis_info *info) 743 struct vis_info *info)
801{ 744{
802 struct orig_node *orig_node; 745 struct orig_node *orig_node;
803 struct neigh_node *router = NULL; 746 struct neigh_node *router = NULL;
@@ -825,8 +768,9 @@ out:
825 batadv_orig_node_free_ref(orig_node); 768 batadv_orig_node_free_ref(orig_node);
826} 769}
827 770
828/* only send one vis packet. called from send_vis_packets() */ 771/* only send one vis packet. called from batadv_send_vis_packets() */
829static void send_vis_packet(struct bat_priv *bat_priv, struct vis_info *info) 772static void batadv_send_vis_packet(struct bat_priv *bat_priv,
773 struct vis_info *info)
830{ 774{
831 struct hard_iface *primary_if; 775 struct hard_iface *primary_if;
832 struct vis_packet *packet; 776 struct vis_packet *packet;
@@ -845,9 +789,9 @@ static void send_vis_packet(struct bat_priv *bat_priv, struct vis_info *info)
845 packet->header.ttl--; 789 packet->header.ttl--;
846 790
847 if (is_broadcast_ether_addr(packet->target_orig)) 791 if (is_broadcast_ether_addr(packet->target_orig))
848 broadcast_vis_packet(bat_priv, info); 792 batadv_broadcast_vis_packet(bat_priv, info);
849 else 793 else
850 unicast_vis_packet(bat_priv, info); 794 batadv_unicast_vis_packet(bat_priv, info);
851 packet->header.ttl++; /* restore TTL */ 795 packet->header.ttl++; /* restore TTL */
852 796
853out: 797out:
@@ -856,7 +800,7 @@ out:
856} 800}
857 801
858/* called from timer; send (and maybe generate) vis packet. */ 802/* called from timer; send (and maybe generate) vis packet. */
859static void send_vis_packets(struct work_struct *work) 803static void batadv_send_vis_packets(struct work_struct *work)
860{ 804{
861 struct delayed_work *delayed_work = 805 struct delayed_work *delayed_work =
862 container_of(work, struct delayed_work, work); 806 container_of(work, struct delayed_work, work);
@@ -865,11 +809,11 @@ static void send_vis_packets(struct work_struct *work)
865 struct vis_info *info; 809 struct vis_info *info;
866 810
867 spin_lock_bh(&bat_priv->vis_hash_lock); 811 spin_lock_bh(&bat_priv->vis_hash_lock);
868 purge_vis_packets(bat_priv); 812 batadv_purge_vis_packets(bat_priv);
869 813
870 if (generate_vis_packet(bat_priv) == 0) { 814 if (batadv_generate_vis_packet(bat_priv) == 0) {
871 /* schedule if generation was successful */ 815 /* schedule if generation was successful */
872 send_list_add(bat_priv, bat_priv->my_vis_info); 816 batadv_send_list_add(bat_priv, bat_priv->my_vis_info);
873 } 817 }
874 818
875 while (!list_empty(&bat_priv->vis_send_list)) { 819 while (!list_empty(&bat_priv->vis_send_list)) {
@@ -879,14 +823,14 @@ static void send_vis_packets(struct work_struct *work)
879 kref_get(&info->refcount); 823 kref_get(&info->refcount);
880 spin_unlock_bh(&bat_priv->vis_hash_lock); 824 spin_unlock_bh(&bat_priv->vis_hash_lock);
881 825
882 send_vis_packet(bat_priv, info); 826 batadv_send_vis_packet(bat_priv, info);
883 827
884 spin_lock_bh(&bat_priv->vis_hash_lock); 828 spin_lock_bh(&bat_priv->vis_hash_lock);
885 send_list_del(info); 829 batadv_send_list_del(info);
886 kref_put(&info->refcount, free_info); 830 kref_put(&info->refcount, batadv_free_info);
887 } 831 }
888 spin_unlock_bh(&bat_priv->vis_hash_lock); 832 spin_unlock_bh(&bat_priv->vis_hash_lock);
889 start_vis_timer(bat_priv); 833 batadv_start_vis_timer(bat_priv);
890} 834}
891 835
892/* init the vis server. this may only be called when if_list is already 836/* init the vis server. this may only be called when if_list is already
@@ -896,6 +840,8 @@ int batadv_vis_init(struct bat_priv *bat_priv)
896{ 840{
897 struct vis_packet *packet; 841 struct vis_packet *packet;
898 int hash_added; 842 int hash_added;
843 unsigned int len;
844 unsigned long first_seen;
899 845
900 if (bat_priv->vis_hash) 846 if (bat_priv->vis_hash)
901 return 0; 847 return 0;
@@ -908,13 +854,12 @@ int batadv_vis_init(struct bat_priv *bat_priv)
908 goto err; 854 goto err;
909 } 855 }
910 856
911 bat_priv->my_vis_info = kmalloc(MAX_VIS_PACKET_SIZE, GFP_ATOMIC); 857 bat_priv->my_vis_info = kmalloc(BATADV_MAX_VIS_PACKET_SIZE, GFP_ATOMIC);
912 if (!bat_priv->my_vis_info) 858 if (!bat_priv->my_vis_info)
913 goto err; 859 goto err;
914 860
915 bat_priv->my_vis_info->skb_packet = dev_alloc_skb(sizeof(*packet) + 861 len = sizeof(*packet) + BATADV_MAX_VIS_PACKET_SIZE + ETH_HLEN;
916 MAX_VIS_PACKET_SIZE + 862 bat_priv->my_vis_info->skb_packet = dev_alloc_skb(len);
917 ETH_HLEN);
918 if (!bat_priv->my_vis_info->skb_packet) 863 if (!bat_priv->my_vis_info->skb_packet)
919 goto free_info; 864 goto free_info;
920 865
@@ -923,32 +868,33 @@ int batadv_vis_init(struct bat_priv *bat_priv)
923 sizeof(*packet)); 868 sizeof(*packet));
924 869
925 /* prefill the vis info */ 870 /* prefill the vis info */
926 bat_priv->my_vis_info->first_seen = jiffies - 871 first_seen = jiffies - msecs_to_jiffies(BATADV_VIS_INTERVAL);
927 msecs_to_jiffies(VIS_INTERVAL); 872 bat_priv->my_vis_info->first_seen = first_seen;
928 INIT_LIST_HEAD(&bat_priv->my_vis_info->recv_list); 873 INIT_LIST_HEAD(&bat_priv->my_vis_info->recv_list);
929 INIT_LIST_HEAD(&bat_priv->my_vis_info->send_list); 874 INIT_LIST_HEAD(&bat_priv->my_vis_info->send_list);
930 kref_init(&bat_priv->my_vis_info->refcount); 875 kref_init(&bat_priv->my_vis_info->refcount);
931 bat_priv->my_vis_info->bat_priv = bat_priv; 876 bat_priv->my_vis_info->bat_priv = bat_priv;
932 packet->header.version = COMPAT_VERSION; 877 packet->header.version = BATADV_COMPAT_VERSION;
933 packet->header.packet_type = BAT_VIS; 878 packet->header.packet_type = BAT_VIS;
934 packet->header.ttl = TTL; 879 packet->header.ttl = BATADV_TTL;
935 packet->seqno = 0; 880 packet->seqno = 0;
936 packet->entries = 0; 881 packet->entries = 0;
937 882
938 INIT_LIST_HEAD(&bat_priv->vis_send_list); 883 INIT_LIST_HEAD(&bat_priv->vis_send_list);
939 884
940 hash_added = batadv_hash_add(bat_priv->vis_hash, vis_info_cmp, 885 hash_added = batadv_hash_add(bat_priv->vis_hash, batadv_vis_info_cmp,
941 vis_info_choose, bat_priv->my_vis_info, 886 batadv_vis_info_choose,
887 bat_priv->my_vis_info,
942 &bat_priv->my_vis_info->hash_entry); 888 &bat_priv->my_vis_info->hash_entry);
943 if (hash_added != 0) { 889 if (hash_added != 0) {
944 pr_err("Can't add own vis packet into hash\n"); 890 pr_err("Can't add own vis packet into hash\n");
945 /* not in hash, need to remove it manually. */ 891 /* not in hash, need to remove it manually. */
946 kref_put(&bat_priv->my_vis_info->refcount, free_info); 892 kref_put(&bat_priv->my_vis_info->refcount, batadv_free_info);
947 goto err; 893 goto err;
948 } 894 }
949 895
950 spin_unlock_bh(&bat_priv->vis_hash_lock); 896 spin_unlock_bh(&bat_priv->vis_hash_lock);
951 start_vis_timer(bat_priv); 897 batadv_start_vis_timer(bat_priv);
952 return 0; 898 return 0;
953 899
954free_info: 900free_info:
@@ -961,13 +907,13 @@ err:
961} 907}
962 908
963/* Decrease the reference count on a hash item info */ 909/* Decrease the reference count on a hash item info */
964static void free_info_ref(struct hlist_node *node, void *arg) 910static void batadv_free_info_ref(struct hlist_node *node, void *arg)
965{ 911{
966 struct vis_info *info; 912 struct vis_info *info;
967 913
968 info = container_of(node, struct vis_info, hash_entry); 914 info = container_of(node, struct vis_info, hash_entry);
969 send_list_del(info); 915 batadv_send_list_del(info);
970 kref_put(&info->refcount, free_info); 916 kref_put(&info->refcount, batadv_free_info);
971} 917}
972 918
973/* shutdown vis-server */ 919/* shutdown vis-server */
@@ -980,16 +926,16 @@ void batadv_vis_quit(struct bat_priv *bat_priv)
980 926
981 spin_lock_bh(&bat_priv->vis_hash_lock); 927 spin_lock_bh(&bat_priv->vis_hash_lock);
982 /* properly remove, kill timers ... */ 928 /* properly remove, kill timers ... */
983 batadv_hash_delete(bat_priv->vis_hash, free_info_ref, NULL); 929 batadv_hash_delete(bat_priv->vis_hash, batadv_free_info_ref, NULL);
984 bat_priv->vis_hash = NULL; 930 bat_priv->vis_hash = NULL;
985 bat_priv->my_vis_info = NULL; 931 bat_priv->my_vis_info = NULL;
986 spin_unlock_bh(&bat_priv->vis_hash_lock); 932 spin_unlock_bh(&bat_priv->vis_hash_lock);
987} 933}
988 934
989/* schedule packets for (re)transmission */ 935/* schedule packets for (re)transmission */
990static void start_vis_timer(struct bat_priv *bat_priv) 936static void batadv_start_vis_timer(struct bat_priv *bat_priv)
991{ 937{
992 INIT_DELAYED_WORK(&bat_priv->vis_work, send_vis_packets); 938 INIT_DELAYED_WORK(&bat_priv->vis_work, batadv_send_vis_packets);
993 queue_delayed_work(batadv_event_workqueue, &bat_priv->vis_work, 939 queue_delayed_work(batadv_event_workqueue, &bat_priv->vis_work,
994 msecs_to_jiffies(VIS_INTERVAL)); 940 msecs_to_jiffies(BATADV_VIS_INTERVAL));
995} 941}