blob: ea8d7e91fcac4fc929f74c57a582757d25fb0ab7 [file] [log] [blame]
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001/*
Sven Eckelmann64afe352011-01-27 10:38:15 +01002 * Copyright (C) 2008-2011 B.A.T.M.A.N. contributors:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00003 *
4 * Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#include "main.h"
23#include "send.h"
24#include "translation-table.h"
25#include "vis.h"
26#include "soft-interface.h"
27#include "hard-interface.h"
28#include "hash.h"
29#include "originator.h"
30
31#define MAX_VIS_PACKET_SIZE 1000
32
33/* Returns the smallest signed integer in two's complement with the sizeof x */
34#define smallest_signed_int(x) (1u << (7u + 8u * (sizeof(x) - 1u)))
35
36/* Checks if a sequence number x is a predecessor/successor of y.
37 * they handle overflows/underflows and can correctly check for a
38 * predecessor/successor unless the variable sequence number has grown by
39 * more then 2**(bitwidth(x)-1)-1.
40 * This means that for a uint8_t with the maximum value 255, it would think:
41 * - when adding nothing - it is neither a predecessor nor a successor
42 * - before adding more than 127 to the starting value - it is a predecessor,
43 * - when adding 128 - it is neither a predecessor nor a successor,
44 * - after adding more than 127 to the starting value - it is a successor */
45#define seq_before(x, y) ({typeof(x) _dummy = (x - y); \
46 _dummy > smallest_signed_int(_dummy); })
47#define seq_after(x, y) seq_before(y, x)
48
49static void start_vis_timer(struct bat_priv *bat_priv);
50
51/* free the info */
52static void free_info(struct kref *ref)
53{
54 struct vis_info *info = container_of(ref, struct vis_info, refcount);
55 struct bat_priv *bat_priv = info->bat_priv;
56 struct recvlist_node *entry, *tmp;
57
58 list_del_init(&info->send_list);
59 spin_lock_bh(&bat_priv->vis_list_lock);
60 list_for_each_entry_safe(entry, tmp, &info->recv_list, list) {
61 list_del(&entry->list);
62 kfree(entry);
63 }
64
65 spin_unlock_bh(&bat_priv->vis_list_lock);
66 kfree_skb(info->skb_packet);
Sven Eckelmanndda9fc62011-01-28 18:34:06 +010067 kfree(info);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000068}
69
70/* Compare two vis packets, used by the hashing algorithm */
Sven Eckelmann747e4222011-05-14 23:14:50 +020071static int vis_info_cmp(const struct hlist_node *node, const void *data2)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000072{
Sven Eckelmann747e4222011-05-14 23:14:50 +020073 const struct vis_info *d1, *d2;
74 const struct vis_packet *p1, *p2;
Marek Lindner7aadf882011-02-18 12:28:09 +000075
76 d1 = container_of(node, struct vis_info, hash_entry);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000077 d2 = data2;
78 p1 = (struct vis_packet *)d1->skb_packet->data;
79 p2 = (struct vis_packet *)d2->skb_packet->data;
Marek Lindner39901e72011-02-18 12:28:08 +000080 return compare_eth(p1->vis_orig, p2->vis_orig);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000081}
82
83/* hash function to choose an entry in a hash table of given size */
84/* hash algorithm from http://en.wikipedia.org/wiki/Hash_table */
Sven Eckelmann747e4222011-05-14 23:14:50 +020085static int vis_info_choose(const void *data, int size)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000086{
Sven Eckelmann747e4222011-05-14 23:14:50 +020087 const struct vis_info *vis_info = data;
88 const struct vis_packet *packet;
89 const unsigned char *key;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000090 uint32_t hash = 0;
91 size_t i;
92
93 packet = (struct vis_packet *)vis_info->skb_packet->data;
94 key = packet->vis_orig;
95 for (i = 0; i < ETH_ALEN; i++) {
96 hash += key[i];
97 hash += (hash << 10);
98 hash ^= (hash >> 6);
99 }
100
101 hash += (hash << 3);
102 hash ^= (hash >> 11);
103 hash += (hash << 15);
104
105 return hash % size;
106}
107
Marek Lindner7aadf882011-02-18 12:28:09 +0000108static struct vis_info *vis_hash_find(struct bat_priv *bat_priv,
Sven Eckelmann747e4222011-05-14 23:14:50 +0200109 const void *data)
Marek Lindner7aadf882011-02-18 12:28:09 +0000110{
111 struct hashtable_t *hash = bat_priv->vis_hash;
112 struct hlist_head *head;
113 struct hlist_node *node;
114 struct vis_info *vis_info, *vis_info_tmp = NULL;
115 int index;
116
117 if (!hash)
118 return NULL;
119
120 index = vis_info_choose(data, hash->size);
121 head = &hash->table[index];
122
123 rcu_read_lock();
124 hlist_for_each_entry_rcu(vis_info, node, head, hash_entry) {
125 if (!vis_info_cmp(node, data))
126 continue;
127
128 vis_info_tmp = vis_info;
129 break;
130 }
131 rcu_read_unlock();
132
133 return vis_info_tmp;
134}
135
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000136/* insert interface to the list of interfaces of one originator, if it
137 * does not already exist in the list */
138static void vis_data_insert_interface(const uint8_t *interface,
139 struct hlist_head *if_list,
140 bool primary)
141{
142 struct if_list_entry *entry;
143 struct hlist_node *pos;
144
145 hlist_for_each_entry(entry, pos, if_list, list) {
Sven Eckelmann747e4222011-05-14 23:14:50 +0200146 if (compare_eth(entry->addr, interface))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000147 return;
148 }
149
150 /* its a new address, add it to the list */
151 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
152 if (!entry)
153 return;
154 memcpy(entry->addr, interface, ETH_ALEN);
155 entry->primary = primary;
156 hlist_add_head(&entry->list, if_list);
157}
158
Sven Eckelmann747e4222011-05-14 23:14:50 +0200159static ssize_t vis_data_read_prim_sec(char *buff,
160 const struct hlist_head *if_list)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000161{
162 struct if_list_entry *entry;
163 struct hlist_node *pos;
164 size_t len = 0;
165
166 hlist_for_each_entry(entry, pos, if_list, list) {
167 if (entry->primary)
168 len += sprintf(buff + len, "PRIMARY, ");
169 else
170 len += sprintf(buff + len, "SEC %pM, ", entry->addr);
171 }
172
173 return len;
174}
175
176static size_t vis_data_count_prim_sec(struct hlist_head *if_list)
177{
178 struct if_list_entry *entry;
179 struct hlist_node *pos;
180 size_t count = 0;
181
182 hlist_for_each_entry(entry, pos, if_list, list) {
183 if (entry->primary)
184 count += 9;
185 else
186 count += 23;
187 }
188
189 return count;
190}
191
192/* read an entry */
Sven Eckelmann747e4222011-05-14 23:14:50 +0200193static ssize_t vis_data_read_entry(char *buff,
194 const struct vis_info_entry *entry,
195 const uint8_t *src, bool primary)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000196{
197 /* maximal length: max(4+17+2, 3+17+1+3+2) == 26 */
198 if (primary && entry->quality == 0)
Antonio Quartulli2dafb492011-05-05 08:42:45 +0200199 return sprintf(buff, "TT %pM, ", entry->dest);
Marek Lindner39901e72011-02-18 12:28:08 +0000200 else if (compare_eth(entry->src, src))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000201 return sprintf(buff, "TQ %pM %d, ", entry->dest,
202 entry->quality);
203
204 return 0;
205}
206
207int vis_seq_print_text(struct seq_file *seq, void *offset)
208{
Marek Lindner32ae9b22011-04-20 15:40:58 +0200209 struct hard_iface *primary_if;
Marek Lindner7aadf882011-02-18 12:28:09 +0000210 struct hlist_node *node;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000211 struct hlist_head *head;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000212 struct vis_info *info;
213 struct vis_packet *packet;
214 struct vis_info_entry *entries;
215 struct net_device *net_dev = (struct net_device *)seq->private;
216 struct bat_priv *bat_priv = netdev_priv(net_dev);
217 struct hashtable_t *hash = bat_priv->vis_hash;
218 HLIST_HEAD(vis_if_list);
219 struct if_list_entry *entry;
220 struct hlist_node *pos, *n;
Marek Lindner32ae9b22011-04-20 15:40:58 +0200221 int i, j, ret = 0;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000222 int vis_server = atomic_read(&bat_priv->vis_mode);
223 size_t buff_pos, buf_size;
224 char *buff;
225 int compare;
226
Marek Lindner32ae9b22011-04-20 15:40:58 +0200227 primary_if = primary_if_get_selected(bat_priv);
228 if (!primary_if)
229 goto out;
230
231 if (vis_server == VIS_TYPE_CLIENT_UPDATE)
232 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000233
234 buf_size = 1;
235 /* Estimate length */
236 spin_lock_bh(&bat_priv->vis_hash_lock);
237 for (i = 0; i < hash->size; i++) {
238 head = &hash->table[i];
239
Marek Lindner7aadf882011-02-18 12:28:09 +0000240 rcu_read_lock();
241 hlist_for_each_entry_rcu(info, node, head, hash_entry) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000242 packet = (struct vis_packet *)info->skb_packet->data;
243 entries = (struct vis_info_entry *)
Sven Eckelmann704509b2011-05-14 23:14:54 +0200244 ((char *)packet + sizeof(*packet));
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000245
246 for (j = 0; j < packet->entries; j++) {
247 if (entries[j].quality == 0)
248 continue;
249 compare =
Marek Lindner39901e72011-02-18 12:28:08 +0000250 compare_eth(entries[j].src, packet->vis_orig);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000251 vis_data_insert_interface(entries[j].src,
252 &vis_if_list,
253 compare);
254 }
255
256 hlist_for_each_entry(entry, pos, &vis_if_list, list) {
257 buf_size += 18 + 26 * packet->entries;
258
259 /* add primary/secondary records */
Marek Lindner39901e72011-02-18 12:28:08 +0000260 if (compare_eth(entry->addr, packet->vis_orig))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000261 buf_size +=
262 vis_data_count_prim_sec(&vis_if_list);
263
264 buf_size += 1;
265 }
266
267 hlist_for_each_entry_safe(entry, pos, n, &vis_if_list,
268 list) {
269 hlist_del(&entry->list);
270 kfree(entry);
271 }
272 }
Marek Lindner7aadf882011-02-18 12:28:09 +0000273 rcu_read_unlock();
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000274 }
275
276 buff = kmalloc(buf_size, GFP_ATOMIC);
277 if (!buff) {
278 spin_unlock_bh(&bat_priv->vis_hash_lock);
Marek Lindner32ae9b22011-04-20 15:40:58 +0200279 ret = -ENOMEM;
280 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000281 }
282 buff[0] = '\0';
283 buff_pos = 0;
284
285 for (i = 0; i < hash->size; i++) {
286 head = &hash->table[i];
287
Marek Lindner7aadf882011-02-18 12:28:09 +0000288 rcu_read_lock();
289 hlist_for_each_entry_rcu(info, node, head, hash_entry) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000290 packet = (struct vis_packet *)info->skb_packet->data;
291 entries = (struct vis_info_entry *)
Sven Eckelmann704509b2011-05-14 23:14:54 +0200292 ((char *)packet + sizeof(*packet));
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000293
294 for (j = 0; j < packet->entries; j++) {
295 if (entries[j].quality == 0)
296 continue;
297 compare =
Marek Lindner39901e72011-02-18 12:28:08 +0000298 compare_eth(entries[j].src, packet->vis_orig);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000299 vis_data_insert_interface(entries[j].src,
300 &vis_if_list,
301 compare);
302 }
303
304 hlist_for_each_entry(entry, pos, &vis_if_list, list) {
305 buff_pos += sprintf(buff + buff_pos, "%pM,",
306 entry->addr);
307
Linus Lüssingdd58ddc2011-01-25 21:56:16 +0000308 for (j = 0; j < packet->entries; j++)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000309 buff_pos += vis_data_read_entry(
310 buff + buff_pos,
Linus Lüssingdd58ddc2011-01-25 21:56:16 +0000311 &entries[j],
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000312 entry->addr,
313 entry->primary);
314
315 /* add primary/secondary records */
Marek Lindner39901e72011-02-18 12:28:08 +0000316 if (compare_eth(entry->addr, packet->vis_orig))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000317 buff_pos +=
318 vis_data_read_prim_sec(buff + buff_pos,
319 &vis_if_list);
320
321 buff_pos += sprintf(buff + buff_pos, "\n");
322 }
323
324 hlist_for_each_entry_safe(entry, pos, n, &vis_if_list,
325 list) {
326 hlist_del(&entry->list);
327 kfree(entry);
328 }
329 }
Marek Lindner7aadf882011-02-18 12:28:09 +0000330 rcu_read_unlock();
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000331 }
332
333 spin_unlock_bh(&bat_priv->vis_hash_lock);
334
335 seq_printf(seq, "%s", buff);
336 kfree(buff);
337
Marek Lindner32ae9b22011-04-20 15:40:58 +0200338out:
339 if (primary_if)
340 hardif_free_ref(primary_if);
341 return ret;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000342}
343
344/* add the info packet to the send list, if it was not
345 * already linked in. */
346static void send_list_add(struct bat_priv *bat_priv, struct vis_info *info)
347{
348 if (list_empty(&info->send_list)) {
349 kref_get(&info->refcount);
350 list_add_tail(&info->send_list, &bat_priv->vis_send_list);
351 }
352}
353
354/* delete the info packet from the send list, if it was
355 * linked in. */
356static void send_list_del(struct vis_info *info)
357{
358 if (!list_empty(&info->send_list)) {
359 list_del_init(&info->send_list);
360 kref_put(&info->refcount, free_info);
361 }
362}
363
364/* tries to add one entry to the receive list. */
365static void recv_list_add(struct bat_priv *bat_priv,
Sven Eckelmann747e4222011-05-14 23:14:50 +0200366 struct list_head *recv_list, const char *mac)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000367{
368 struct recvlist_node *entry;
369
Sven Eckelmann704509b2011-05-14 23:14:54 +0200370 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000371 if (!entry)
372 return;
373
374 memcpy(entry->mac, mac, ETH_ALEN);
375 spin_lock_bh(&bat_priv->vis_list_lock);
376 list_add_tail(&entry->list, recv_list);
377 spin_unlock_bh(&bat_priv->vis_list_lock);
378}
379
380/* returns 1 if this mac is in the recv_list */
381static int recv_list_is_in(struct bat_priv *bat_priv,
Sven Eckelmann747e4222011-05-14 23:14:50 +0200382 const struct list_head *recv_list, const char *mac)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000383{
Sven Eckelmann747e4222011-05-14 23:14:50 +0200384 const struct recvlist_node *entry;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000385
386 spin_lock_bh(&bat_priv->vis_list_lock);
387 list_for_each_entry(entry, recv_list, list) {
Marek Lindner39901e72011-02-18 12:28:08 +0000388 if (compare_eth(entry->mac, mac)) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000389 spin_unlock_bh(&bat_priv->vis_list_lock);
390 return 1;
391 }
392 }
393 spin_unlock_bh(&bat_priv->vis_list_lock);
394 return 0;
395}
396
397/* try to add the packet to the vis_hash. return NULL if invalid (e.g. too old,
398 * broken.. ). vis hash must be locked outside. is_new is set when the packet
399 * is newer than old entries in the hash. */
400static struct vis_info *add_packet(struct bat_priv *bat_priv,
401 struct vis_packet *vis_packet,
402 int vis_info_len, int *is_new,
403 int make_broadcast)
404{
405 struct vis_info *info, *old_info;
406 struct vis_packet *search_packet, *old_packet;
407 struct vis_info search_elem;
408 struct vis_packet *packet;
409 int hash_added;
410
411 *is_new = 0;
412 /* sanity check */
413 if (!bat_priv->vis_hash)
414 return NULL;
415
416 /* see if the packet is already in vis_hash */
Sven Eckelmann704509b2011-05-14 23:14:54 +0200417 search_elem.skb_packet = dev_alloc_skb(sizeof(*search_packet));
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000418 if (!search_elem.skb_packet)
419 return NULL;
420 search_packet = (struct vis_packet *)skb_put(search_elem.skb_packet,
Sven Eckelmann704509b2011-05-14 23:14:54 +0200421 sizeof(*search_packet));
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000422
423 memcpy(search_packet->vis_orig, vis_packet->vis_orig, ETH_ALEN);
Marek Lindner7aadf882011-02-18 12:28:09 +0000424 old_info = vis_hash_find(bat_priv, &search_elem);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000425 kfree_skb(search_elem.skb_packet);
426
427 if (old_info) {
428 old_packet = (struct vis_packet *)old_info->skb_packet->data;
429 if (!seq_after(ntohl(vis_packet->seqno),
430 ntohl(old_packet->seqno))) {
431 if (old_packet->seqno == vis_packet->seqno) {
432 recv_list_add(bat_priv, &old_info->recv_list,
433 vis_packet->sender_orig);
434 return old_info;
435 } else {
436 /* newer packet is already in hash. */
437 return NULL;
438 }
439 }
440 /* remove old entry */
441 hash_remove(bat_priv->vis_hash, vis_info_cmp, vis_info_choose,
442 old_info);
443 send_list_del(old_info);
444 kref_put(&old_info->refcount, free_info);
445 }
446
Sven Eckelmann704509b2011-05-14 23:14:54 +0200447 info = kmalloc(sizeof(*info), GFP_ATOMIC);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000448 if (!info)
449 return NULL;
450
Sven Eckelmann704509b2011-05-14 23:14:54 +0200451 info->skb_packet = dev_alloc_skb(sizeof(*packet) + vis_info_len +
452 sizeof(struct ethhdr));
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000453 if (!info->skb_packet) {
454 kfree(info);
455 return NULL;
456 }
457 skb_reserve(info->skb_packet, sizeof(struct ethhdr));
Sven Eckelmann704509b2011-05-14 23:14:54 +0200458 packet = (struct vis_packet *)skb_put(info->skb_packet, sizeof(*packet)
459 + vis_info_len);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000460
461 kref_init(&info->refcount);
462 INIT_LIST_HEAD(&info->send_list);
463 INIT_LIST_HEAD(&info->recv_list);
464 info->first_seen = jiffies;
465 info->bat_priv = bat_priv;
Sven Eckelmann704509b2011-05-14 23:14:54 +0200466 memcpy(packet, vis_packet, sizeof(*packet) + vis_info_len);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000467
468 /* initialize and add new packet. */
469 *is_new = 1;
470
471 /* Make it a broadcast packet, if required */
472 if (make_broadcast)
473 memcpy(packet->target_orig, broadcast_addr, ETH_ALEN);
474
475 /* repair if entries is longer than packet. */
476 if (packet->entries * sizeof(struct vis_info_entry) > vis_info_len)
477 packet->entries = vis_info_len / sizeof(struct vis_info_entry);
478
479 recv_list_add(bat_priv, &info->recv_list, packet->sender_orig);
480
481 /* try to add it */
482 hash_added = hash_add(bat_priv->vis_hash, vis_info_cmp, vis_info_choose,
Marek Lindner7aadf882011-02-18 12:28:09 +0000483 info, &info->hash_entry);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000484 if (hash_added < 0) {
485 /* did not work (for some reason) */
Sven Eckelmann2674c152011-01-28 18:34:05 +0100486 kref_put(&info->refcount, free_info);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000487 info = NULL;
488 }
489
490 return info;
491}
492
493/* handle the server sync packet, forward if needed. */
494void receive_server_sync_packet(struct bat_priv *bat_priv,
495 struct vis_packet *vis_packet,
496 int vis_info_len)
497{
498 struct vis_info *info;
499 int is_new, make_broadcast;
500 int vis_server = atomic_read(&bat_priv->vis_mode);
501
502 make_broadcast = (vis_server == VIS_TYPE_SERVER_SYNC);
503
504 spin_lock_bh(&bat_priv->vis_hash_lock);
505 info = add_packet(bat_priv, vis_packet, vis_info_len,
506 &is_new, make_broadcast);
507 if (!info)
508 goto end;
509
510 /* only if we are server ourselves and packet is newer than the one in
511 * hash.*/
512 if (vis_server == VIS_TYPE_SERVER_SYNC && is_new)
513 send_list_add(bat_priv, info);
514end:
515 spin_unlock_bh(&bat_priv->vis_hash_lock);
516}
517
518/* handle an incoming client update packet and schedule forward if needed. */
519void receive_client_update_packet(struct bat_priv *bat_priv,
520 struct vis_packet *vis_packet,
521 int vis_info_len)
522{
523 struct vis_info *info;
524 struct vis_packet *packet;
525 int is_new;
526 int vis_server = atomic_read(&bat_priv->vis_mode);
527 int are_target = 0;
528
529 /* clients shall not broadcast. */
530 if (is_broadcast_ether_addr(vis_packet->target_orig))
531 return;
532
533 /* Are we the target for this VIS packet? */
534 if (vis_server == VIS_TYPE_SERVER_SYNC &&
535 is_my_mac(vis_packet->target_orig))
536 are_target = 1;
537
538 spin_lock_bh(&bat_priv->vis_hash_lock);
539 info = add_packet(bat_priv, vis_packet, vis_info_len,
540 &is_new, are_target);
541
542 if (!info)
543 goto end;
544 /* note that outdated packets will be dropped at this point. */
545
546 packet = (struct vis_packet *)info->skb_packet->data;
547
548 /* send only if we're the target server or ... */
549 if (are_target && is_new) {
550 packet->vis_type = VIS_TYPE_SERVER_SYNC; /* upgrade! */
551 send_list_add(bat_priv, info);
552
553 /* ... we're not the recipient (and thus need to forward). */
554 } else if (!is_my_mac(packet->target_orig)) {
555 send_list_add(bat_priv, info);
556 }
557
558end:
559 spin_unlock_bh(&bat_priv->vis_hash_lock);
560}
561
562/* Walk the originators and find the VIS server with the best tq. Set the packet
563 * address to its address and return the best_tq.
564 *
565 * Must be called with the originator hash locked */
566static int find_best_vis_server(struct bat_priv *bat_priv,
567 struct vis_info *info)
568{
569 struct hashtable_t *hash = bat_priv->orig_hash;
Linus Lüssinge1a5382f2011-03-14 22:43:37 +0000570 struct neigh_node *router;
Marek Lindner7aadf882011-02-18 12:28:09 +0000571 struct hlist_node *node;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000572 struct hlist_head *head;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000573 struct orig_node *orig_node;
574 struct vis_packet *packet;
575 int best_tq = -1, i;
576
577 packet = (struct vis_packet *)info->skb_packet->data;
578
579 for (i = 0; i < hash->size; i++) {
580 head = &hash->table[i];
581
Marek Lindnerfb778ea2011-01-19 20:01:40 +0000582 rcu_read_lock();
Marek Lindner7aadf882011-02-18 12:28:09 +0000583 hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
Linus Lüssinge1a5382f2011-03-14 22:43:37 +0000584 router = orig_node_get_router(orig_node);
585 if (!router)
586 continue;
587
588 if ((orig_node->flags & VIS_SERVER) &&
589 (router->tq_avg > best_tq)) {
590 best_tq = router->tq_avg;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000591 memcpy(packet->target_orig, orig_node->orig,
592 ETH_ALEN);
593 }
Linus Lüssinge1a5382f2011-03-14 22:43:37 +0000594 neigh_node_free_ref(router);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000595 }
Marek Lindnerfb778ea2011-01-19 20:01:40 +0000596 rcu_read_unlock();
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000597 }
598
599 return best_tq;
600}
601
602/* Return true if the vis packet is full. */
Sven Eckelmann747e4222011-05-14 23:14:50 +0200603static bool vis_packet_full(const struct vis_info *info)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000604{
Sven Eckelmann747e4222011-05-14 23:14:50 +0200605 const struct vis_packet *packet;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000606 packet = (struct vis_packet *)info->skb_packet->data;
607
608 if (MAX_VIS_PACKET_SIZE / sizeof(struct vis_info_entry)
609 < packet->entries + 1)
610 return true;
611 return false;
612}
613
614/* generates a packet of own vis data,
615 * returns 0 on success, -1 if no packet could be generated */
616static int generate_vis_packet(struct bat_priv *bat_priv)
617{
618 struct hashtable_t *hash = bat_priv->orig_hash;
Marek Lindner7aadf882011-02-18 12:28:09 +0000619 struct hlist_node *node;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000620 struct hlist_head *head;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000621 struct orig_node *orig_node;
Linus Lüssinge1a5382f2011-03-14 22:43:37 +0000622 struct neigh_node *router;
Sven Eckelmann958ca592011-05-14 23:14:53 +0200623 struct vis_info *info = bat_priv->my_vis_info;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000624 struct vis_packet *packet = (struct vis_packet *)info->skb_packet->data;
625 struct vis_info_entry *entry;
Antonio Quartulli2dafb492011-05-05 08:42:45 +0200626 struct tt_local_entry *tt_local_entry;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000627 int best_tq = -1, i;
628
629 info->first_seen = jiffies;
630 packet->vis_type = atomic_read(&bat_priv->vis_mode);
631
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000632 memcpy(packet->target_orig, broadcast_addr, ETH_ALEN);
633 packet->ttl = TTL;
634 packet->seqno = htonl(ntohl(packet->seqno) + 1);
635 packet->entries = 0;
Sven Eckelmann704509b2011-05-14 23:14:54 +0200636 skb_trim(info->skb_packet, sizeof(*packet));
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000637
638 if (packet->vis_type == VIS_TYPE_CLIENT_UPDATE) {
639 best_tq = find_best_vis_server(bat_priv, info);
640
Marek Lindnerd0072602011-01-19 20:01:44 +0000641 if (best_tq < 0)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000642 return -1;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000643 }
644
645 for (i = 0; i < hash->size; i++) {
646 head = &hash->table[i];
647
Marek Lindnerfb778ea2011-01-19 20:01:40 +0000648 rcu_read_lock();
Marek Lindner7aadf882011-02-18 12:28:09 +0000649 hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
Linus Lüssinge1a5382f2011-03-14 22:43:37 +0000650 router = orig_node_get_router(orig_node);
651 if (!router)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000652 continue;
653
Linus Lüssinge1a5382f2011-03-14 22:43:37 +0000654 if (!compare_eth(router->addr, orig_node->orig))
655 goto next;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000656
Linus Lüssinge1a5382f2011-03-14 22:43:37 +0000657 if (router->if_incoming->if_status != IF_ACTIVE)
658 goto next;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000659
Linus Lüssinge1a5382f2011-03-14 22:43:37 +0000660 if (router->tq_avg < 1)
661 goto next;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000662
663 /* fill one entry into buffer. */
664 entry = (struct vis_info_entry *)
665 skb_put(info->skb_packet, sizeof(*entry));
666 memcpy(entry->src,
Linus Lüssinge1a5382f2011-03-14 22:43:37 +0000667 router->if_incoming->net_dev->dev_addr,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000668 ETH_ALEN);
669 memcpy(entry->dest, orig_node->orig, ETH_ALEN);
Linus Lüssinge1a5382f2011-03-14 22:43:37 +0000670 entry->quality = router->tq_avg;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000671 packet->entries++;
672
Linus Lüssinge1a5382f2011-03-14 22:43:37 +0000673next:
674 neigh_node_free_ref(router);
675
Marek Lindnerd0072602011-01-19 20:01:44 +0000676 if (vis_packet_full(info))
677 goto unlock;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000678 }
Marek Lindnerfb778ea2011-01-19 20:01:40 +0000679 rcu_read_unlock();
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000680 }
681
Antonio Quartulli2dafb492011-05-05 08:42:45 +0200682 hash = bat_priv->tt_local_hash;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000683
Antonio Quartulli2dafb492011-05-05 08:42:45 +0200684 spin_lock_bh(&bat_priv->tt_lhash_lock);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000685 for (i = 0; i < hash->size; i++) {
686 head = &hash->table[i];
687
Antonio Quartulli2dafb492011-05-05 08:42:45 +0200688 hlist_for_each_entry(tt_local_entry, node, head, hash_entry) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000689 entry = (struct vis_info_entry *)
690 skb_put(info->skb_packet,
691 sizeof(*entry));
692 memset(entry->src, 0, ETH_ALEN);
Antonio Quartulli2dafb492011-05-05 08:42:45 +0200693 memcpy(entry->dest, tt_local_entry->addr, ETH_ALEN);
694 entry->quality = 0; /* 0 means TT */
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000695 packet->entries++;
696
697 if (vis_packet_full(info)) {
Antonio Quartulli2dafb492011-05-05 08:42:45 +0200698 spin_unlock_bh(&bat_priv->tt_lhash_lock);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000699 return 0;
700 }
701 }
702 }
703
Antonio Quartulli2dafb492011-05-05 08:42:45 +0200704 spin_unlock_bh(&bat_priv->tt_lhash_lock);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000705 return 0;
Marek Lindnerd0072602011-01-19 20:01:44 +0000706
707unlock:
708 rcu_read_unlock();
709 return 0;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000710}
711
712/* free old vis packets. Must be called with this vis_hash_lock
713 * held */
714static void purge_vis_packets(struct bat_priv *bat_priv)
715{
716 int i;
717 struct hashtable_t *hash = bat_priv->vis_hash;
Marek Lindner7aadf882011-02-18 12:28:09 +0000718 struct hlist_node *node, *node_tmp;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000719 struct hlist_head *head;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000720 struct vis_info *info;
721
722 for (i = 0; i < hash->size; i++) {
723 head = &hash->table[i];
724
Marek Lindner7aadf882011-02-18 12:28:09 +0000725 hlist_for_each_entry_safe(info, node, node_tmp,
726 head, hash_entry) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000727 /* never purge own data. */
728 if (info == bat_priv->my_vis_info)
729 continue;
730
731 if (time_after(jiffies,
732 info->first_seen + VIS_TIMEOUT * HZ)) {
Marek Lindner7aadf882011-02-18 12:28:09 +0000733 hlist_del(node);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000734 send_list_del(info);
735 kref_put(&info->refcount, free_info);
736 }
737 }
738 }
739}
740
741static void broadcast_vis_packet(struct bat_priv *bat_priv,
742 struct vis_info *info)
743{
Linus Lüssinge1a5382f2011-03-14 22:43:37 +0000744 struct neigh_node *router;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000745 struct hashtable_t *hash = bat_priv->orig_hash;
Marek Lindner7aadf882011-02-18 12:28:09 +0000746 struct hlist_node *node;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000747 struct hlist_head *head;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000748 struct orig_node *orig_node;
749 struct vis_packet *packet;
750 struct sk_buff *skb;
Marek Lindnere6c10f42011-02-18 12:33:20 +0000751 struct hard_iface *hard_iface;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000752 uint8_t dstaddr[ETH_ALEN];
753 int i;
754
755
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000756 packet = (struct vis_packet *)info->skb_packet->data;
757
758 /* send to all routers in range. */
759 for (i = 0; i < hash->size; i++) {
760 head = &hash->table[i];
761
Marek Lindnerfb778ea2011-01-19 20:01:40 +0000762 rcu_read_lock();
Marek Lindner7aadf882011-02-18 12:28:09 +0000763 hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000764 /* if it's a vis server and reachable, send it. */
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000765 if (!(orig_node->flags & VIS_SERVER))
766 continue;
Linus Lüssinge1a5382f2011-03-14 22:43:37 +0000767
768 router = orig_node_get_router(orig_node);
769 if (!router)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000770 continue;
771
Linus Lüssinge1a5382f2011-03-14 22:43:37 +0000772 /* don't send it if we already received the packet from
773 * this node. */
774 if (recv_list_is_in(bat_priv, &info->recv_list,
775 orig_node->orig)) {
776 neigh_node_free_ref(router);
777 continue;
778 }
779
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000780 memcpy(packet->target_orig, orig_node->orig, ETH_ALEN);
Linus Lüssinge1a5382f2011-03-14 22:43:37 +0000781 hard_iface = router->if_incoming;
782 memcpy(dstaddr, router->addr, ETH_ALEN);
783
784 neigh_node_free_ref(router);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000785
786 skb = skb_clone(info->skb_packet, GFP_ATOMIC);
787 if (skb)
Marek Lindnere6c10f42011-02-18 12:33:20 +0000788 send_skb_packet(skb, hard_iface, dstaddr);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000789
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000790 }
Marek Lindnerfb778ea2011-01-19 20:01:40 +0000791 rcu_read_unlock();
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000792 }
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000793}
794
795static void unicast_vis_packet(struct bat_priv *bat_priv,
796 struct vis_info *info)
797{
798 struct orig_node *orig_node;
Linus Lüssinge1a5382f2011-03-14 22:43:37 +0000799 struct neigh_node *router = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000800 struct sk_buff *skb;
801 struct vis_packet *packet;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000802
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000803 packet = (struct vis_packet *)info->skb_packet->data;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000804
Marek Lindner7aadf882011-02-18 12:28:09 +0000805 orig_node = orig_hash_find(bat_priv, packet->target_orig);
Marek Lindner44524fc2011-02-10 14:33:53 +0000806 if (!orig_node)
Linus Lüssinge1a5382f2011-03-14 22:43:37 +0000807 goto out;
Marek Lindner44524fc2011-02-10 14:33:53 +0000808
Linus Lüssinge1a5382f2011-03-14 22:43:37 +0000809 router = orig_node_get_router(orig_node);
810 if (!router)
811 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000812
813 skb = skb_clone(info->skb_packet, GFP_ATOMIC);
814 if (skb)
Linus Lüssinge1a5382f2011-03-14 22:43:37 +0000815 send_skb_packet(skb, router->if_incoming, router->addr);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000816
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000817out:
Linus Lüssinge1a5382f2011-03-14 22:43:37 +0000818 if (router)
819 neigh_node_free_ref(router);
Marek Lindner44524fc2011-02-10 14:33:53 +0000820 if (orig_node)
Marek Lindner7b36e8e2011-02-18 12:28:10 +0000821 orig_node_free_ref(orig_node);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000822}
823
824/* only send one vis packet. called from send_vis_packets() */
825static void send_vis_packet(struct bat_priv *bat_priv, struct vis_info *info)
826{
Marek Lindner32ae9b22011-04-20 15:40:58 +0200827 struct hard_iface *primary_if;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000828 struct vis_packet *packet;
829
Marek Lindner32ae9b22011-04-20 15:40:58 +0200830 primary_if = primary_if_get_selected(bat_priv);
831 if (!primary_if)
832 goto out;
833
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000834 packet = (struct vis_packet *)info->skb_packet->data;
835 if (packet->ttl < 2) {
836 pr_debug("Error - can't send vis packet: ttl exceeded\n");
Marek Lindner32ae9b22011-04-20 15:40:58 +0200837 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000838 }
839
Marek Lindner32ae9b22011-04-20 15:40:58 +0200840 memcpy(packet->sender_orig, primary_if->net_dev->dev_addr, ETH_ALEN);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000841 packet->ttl--;
842
843 if (is_broadcast_ether_addr(packet->target_orig))
844 broadcast_vis_packet(bat_priv, info);
845 else
846 unicast_vis_packet(bat_priv, info);
847 packet->ttl++; /* restore TTL */
Marek Lindner32ae9b22011-04-20 15:40:58 +0200848
849out:
850 if (primary_if)
851 hardif_free_ref(primary_if);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000852}
853
854/* called from timer; send (and maybe generate) vis packet. */
855static void send_vis_packets(struct work_struct *work)
856{
857 struct delayed_work *delayed_work =
858 container_of(work, struct delayed_work, work);
859 struct bat_priv *bat_priv =
860 container_of(delayed_work, struct bat_priv, vis_work);
Sven Eckelmann1181e1d2011-01-28 18:34:07 +0100861 struct vis_info *info;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000862
863 spin_lock_bh(&bat_priv->vis_hash_lock);
864 purge_vis_packets(bat_priv);
865
866 if (generate_vis_packet(bat_priv) == 0) {
867 /* schedule if generation was successful */
868 send_list_add(bat_priv, bat_priv->my_vis_info);
869 }
870
Sven Eckelmann1181e1d2011-01-28 18:34:07 +0100871 while (!list_empty(&bat_priv->vis_send_list)) {
872 info = list_first_entry(&bat_priv->vis_send_list,
873 typeof(*info), send_list);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000874
875 kref_get(&info->refcount);
876 spin_unlock_bh(&bat_priv->vis_hash_lock);
877
Marek Lindner32ae9b22011-04-20 15:40:58 +0200878 send_vis_packet(bat_priv, info);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000879
880 spin_lock_bh(&bat_priv->vis_hash_lock);
881 send_list_del(info);
882 kref_put(&info->refcount, free_info);
883 }
884 spin_unlock_bh(&bat_priv->vis_hash_lock);
885 start_vis_timer(bat_priv);
886}
887
888/* init the vis server. this may only be called when if_list is already
889 * initialized (e.g. bat0 is initialized, interfaces have been added) */
890int vis_init(struct bat_priv *bat_priv)
891{
892 struct vis_packet *packet;
893 int hash_added;
894
895 if (bat_priv->vis_hash)
896 return 1;
897
898 spin_lock_bh(&bat_priv->vis_hash_lock);
899
900 bat_priv->vis_hash = hash_new(256);
901 if (!bat_priv->vis_hash) {
902 pr_err("Can't initialize vis_hash\n");
903 goto err;
904 }
905
906 bat_priv->my_vis_info = kmalloc(MAX_VIS_PACKET_SIZE, GFP_ATOMIC);
907 if (!bat_priv->my_vis_info) {
908 pr_err("Can't initialize vis packet\n");
909 goto err;
910 }
911
Sven Eckelmann704509b2011-05-14 23:14:54 +0200912 bat_priv->my_vis_info->skb_packet = dev_alloc_skb(sizeof(*packet) +
913 MAX_VIS_PACKET_SIZE +
914 sizeof(struct ethhdr));
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000915 if (!bat_priv->my_vis_info->skb_packet)
916 goto free_info;
917
918 skb_reserve(bat_priv->my_vis_info->skb_packet, sizeof(struct ethhdr));
Sven Eckelmann704509b2011-05-14 23:14:54 +0200919 packet = (struct vis_packet *)skb_put(bat_priv->my_vis_info->skb_packet,
920 sizeof(*packet));
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000921
922 /* prefill the vis info */
923 bat_priv->my_vis_info->first_seen = jiffies -
924 msecs_to_jiffies(VIS_INTERVAL);
925 INIT_LIST_HEAD(&bat_priv->my_vis_info->recv_list);
926 INIT_LIST_HEAD(&bat_priv->my_vis_info->send_list);
927 kref_init(&bat_priv->my_vis_info->refcount);
928 bat_priv->my_vis_info->bat_priv = bat_priv;
929 packet->version = COMPAT_VERSION;
930 packet->packet_type = BAT_VIS;
931 packet->ttl = TTL;
932 packet->seqno = 0;
933 packet->entries = 0;
934
935 INIT_LIST_HEAD(&bat_priv->vis_send_list);
936
937 hash_added = hash_add(bat_priv->vis_hash, vis_info_cmp, vis_info_choose,
Marek Lindner7aadf882011-02-18 12:28:09 +0000938 bat_priv->my_vis_info,
939 &bat_priv->my_vis_info->hash_entry);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000940 if (hash_added < 0) {
941 pr_err("Can't add own vis packet into hash\n");
942 /* not in hash, need to remove it manually. */
943 kref_put(&bat_priv->my_vis_info->refcount, free_info);
944 goto err;
945 }
946
947 spin_unlock_bh(&bat_priv->vis_hash_lock);
948 start_vis_timer(bat_priv);
949 return 1;
950
951free_info:
952 kfree(bat_priv->my_vis_info);
953 bat_priv->my_vis_info = NULL;
954err:
955 spin_unlock_bh(&bat_priv->vis_hash_lock);
956 vis_quit(bat_priv);
957 return 0;
958}
959
960/* Decrease the reference count on a hash item info */
Marek Lindner7aadf882011-02-18 12:28:09 +0000961static void free_info_ref(struct hlist_node *node, void *arg)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000962{
Marek Lindner7aadf882011-02-18 12:28:09 +0000963 struct vis_info *info;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000964
Marek Lindner7aadf882011-02-18 12:28:09 +0000965 info = container_of(node, struct vis_info, hash_entry);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000966 send_list_del(info);
967 kref_put(&info->refcount, free_info);
968}
969
970/* shutdown vis-server */
971void vis_quit(struct bat_priv *bat_priv)
972{
973 if (!bat_priv->vis_hash)
974 return;
975
976 cancel_delayed_work_sync(&bat_priv->vis_work);
977
978 spin_lock_bh(&bat_priv->vis_hash_lock);
979 /* properly remove, kill timers ... */
980 hash_delete(bat_priv->vis_hash, free_info_ref, NULL);
981 bat_priv->vis_hash = NULL;
982 bat_priv->my_vis_info = NULL;
983 spin_unlock_bh(&bat_priv->vis_hash_lock);
984}
985
986/* schedule packets for (re)transmission */
987static void start_vis_timer(struct bat_priv *bat_priv)
988{
989 INIT_DELAYED_WORK(&bat_priv->vis_work, send_vis_packets);
990 queue_delayed_work(bat_event_workqueue, &bat_priv->vis_work,
991 msecs_to_jiffies(VIS_INTERVAL));
992}