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.c728
1 files changed, 354 insertions, 374 deletions
diff --git a/net/batman-adv/vis.c b/net/batman-adv/vis.c
index cec216fb77c7..2a2ea0681469 100644
--- a/net/batman-adv/vis.c
+++ b/net/batman-adv/vis.c
@@ -1,5 +1,4 @@
1/* 1/* Copyright (C) 2008-2012 B.A.T.M.A.N. contributors:
2 * Copyright (C) 2008-2012 B.A.T.M.A.N. contributors:
3 * 2 *
4 * Simon Wunderlich 3 * Simon Wunderlich
5 * 4 *
@@ -16,7 +15,6 @@
16 * along with this program; if not, write to the Free Software 15 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA 17 * 02110-1301, USA
19 *
20 */ 18 */
21 19
22#include "main.h" 20#include "main.h"
@@ -28,16 +26,19 @@
28#include "hash.h" 26#include "hash.h"
29#include "originator.h" 27#include "originator.h"
30 28
31#define MAX_VIS_PACKET_SIZE 1000 29#define BATADV_MAX_VIS_PACKET_SIZE 1000
32 30
33static void start_vis_timer(struct bat_priv *bat_priv); 31static void batadv_start_vis_timer(struct batadv_priv *bat_priv);
34 32
35/* free the info */ 33/* free the info */
36static void free_info(struct kref *ref) 34static void batadv_free_info(struct kref *ref)
37{ 35{
38 struct vis_info *info = container_of(ref, struct vis_info, refcount); 36 struct batadv_vis_info *info;
39 struct bat_priv *bat_priv = info->bat_priv; 37 struct batadv_priv *bat_priv;
40 struct recvlist_node *entry, *tmp; 38 struct batadv_recvlist_node *entry, *tmp;
39
40 info = container_of(ref, struct batadv_vis_info, refcount);
41 bat_priv = info->bat_priv;
41 42
42 list_del_init(&info->send_list); 43 list_del_init(&info->send_list);
43 spin_lock_bh(&bat_priv->vis_list_lock); 44 spin_lock_bh(&bat_priv->vis_list_lock);
@@ -52,29 +53,30 @@ static void free_info(struct kref *ref)
52} 53}
53 54
54/* Compare two vis packets, used by the hashing algorithm */ 55/* Compare two vis packets, used by the hashing algorithm */
55static int vis_info_cmp(const struct hlist_node *node, const void *data2) 56static int batadv_vis_info_cmp(const struct hlist_node *node, const void *data2)
56{ 57{
57 const struct vis_info *d1, *d2; 58 const struct batadv_vis_info *d1, *d2;
58 const struct vis_packet *p1, *p2; 59 const struct batadv_vis_packet *p1, *p2;
59 60
60 d1 = container_of(node, struct vis_info, hash_entry); 61 d1 = container_of(node, struct batadv_vis_info, hash_entry);
61 d2 = data2; 62 d2 = data2;
62 p1 = (struct vis_packet *)d1->skb_packet->data; 63 p1 = (struct batadv_vis_packet *)d1->skb_packet->data;
63 p2 = (struct vis_packet *)d2->skb_packet->data; 64 p2 = (struct batadv_vis_packet *)d2->skb_packet->data;
64 return compare_eth(p1->vis_orig, p2->vis_orig); 65 return batadv_compare_eth(p1->vis_orig, p2->vis_orig);
65} 66}
66 67
67/* hash function to choose an entry in a hash table of given size */ 68/* hash function to choose an entry in a hash table of given size
68/* hash algorithm from http://en.wikipedia.org/wiki/Hash_table */ 69 * hash algorithm from http://en.wikipedia.org/wiki/Hash_table
69static uint32_t vis_info_choose(const void *data, uint32_t size) 70 */
71static uint32_t batadv_vis_info_choose(const void *data, uint32_t size)
70{ 72{
71 const struct vis_info *vis_info = data; 73 const struct batadv_vis_info *vis_info = data;
72 const struct vis_packet *packet; 74 const struct batadv_vis_packet *packet;
73 const unsigned char *key; 75 const unsigned char *key;
74 uint32_t hash = 0; 76 uint32_t hash = 0;
75 size_t i; 77 size_t i;
76 78
77 packet = (struct vis_packet *)vis_info->skb_packet->data; 79 packet = (struct batadv_vis_packet *)vis_info->skb_packet->data;
78 key = packet->vis_orig; 80 key = packet->vis_orig;
79 for (i = 0; i < ETH_ALEN; i++) { 81 for (i = 0; i < ETH_ALEN; i++) {
80 hash += key[i]; 82 hash += key[i];
@@ -89,24 +91,24 @@ static uint32_t vis_info_choose(const void *data, uint32_t size)
89 return hash % size; 91 return hash % size;
90} 92}
91 93
92static struct vis_info *vis_hash_find(struct bat_priv *bat_priv, 94static struct batadv_vis_info *
93 const void *data) 95batadv_vis_hash_find(struct batadv_priv *bat_priv, const void *data)
94{ 96{
95 struct hashtable_t *hash = bat_priv->vis_hash; 97 struct batadv_hashtable *hash = bat_priv->vis_hash;
96 struct hlist_head *head; 98 struct hlist_head *head;
97 struct hlist_node *node; 99 struct hlist_node *node;
98 struct vis_info *vis_info, *vis_info_tmp = NULL; 100 struct batadv_vis_info *vis_info, *vis_info_tmp = NULL;
99 uint32_t index; 101 uint32_t index;
100 102
101 if (!hash) 103 if (!hash)
102 return NULL; 104 return NULL;
103 105
104 index = vis_info_choose(data, hash->size); 106 index = batadv_vis_info_choose(data, hash->size);
105 head = &hash->table[index]; 107 head = &hash->table[index];
106 108
107 rcu_read_lock(); 109 rcu_read_lock();
108 hlist_for_each_entry_rcu(vis_info, node, head, hash_entry) { 110 hlist_for_each_entry_rcu(vis_info, node, head, hash_entry) {
109 if (!vis_info_cmp(node, data)) 111 if (!batadv_vis_info_cmp(node, data))
110 continue; 112 continue;
111 113
112 vis_info_tmp = vis_info; 114 vis_info_tmp = vis_info;
@@ -118,16 +120,17 @@ static struct vis_info *vis_hash_find(struct bat_priv *bat_priv,
118} 120}
119 121
120/* insert interface to the list of interfaces of one originator, if it 122/* insert interface to the list of interfaces of one originator, if it
121 * does not already exist in the list */ 123 * does not already exist in the list
122static void vis_data_insert_interface(const uint8_t *interface, 124 */
123 struct hlist_head *if_list, 125static void batadv_vis_data_insert_interface(const uint8_t *interface,
124 bool primary) 126 struct hlist_head *if_list,
127 bool primary)
125{ 128{
126 struct if_list_entry *entry; 129 struct batadv_if_list_entry *entry;
127 struct hlist_node *pos; 130 struct hlist_node *pos;
128 131
129 hlist_for_each_entry(entry, pos, if_list, list) { 132 hlist_for_each_entry(entry, pos, if_list, list) {
130 if (compare_eth(entry->addr, interface)) 133 if (batadv_compare_eth(entry->addr, interface))
131 return; 134 return;
132 } 135 }
133 136
@@ -140,195 +143,145 @@ static void vis_data_insert_interface(const uint8_t *interface,
140 hlist_add_head(&entry->list, if_list); 143 hlist_add_head(&entry->list, if_list);
141} 144}
142 145
143static ssize_t vis_data_read_prim_sec(char *buff, 146static void batadv_vis_data_read_prim_sec(struct seq_file *seq,
144 const struct hlist_head *if_list) 147 const struct hlist_head *if_list)
145{ 148{
146 struct if_list_entry *entry; 149 struct batadv_if_list_entry *entry;
147 struct hlist_node *pos; 150 struct hlist_node *pos;
148 size_t len = 0;
149 151
150 hlist_for_each_entry(entry, pos, if_list, list) { 152 hlist_for_each_entry(entry, pos, if_list, list) {
151 if (entry->primary) 153 if (entry->primary)
152 len += sprintf(buff + len, "PRIMARY, "); 154 seq_printf(seq, "PRIMARY, ");
153 else 155 else
154 len += sprintf(buff + len, "SEC %pM, ", entry->addr); 156 seq_printf(seq, "SEC %pM, ", entry->addr);
155 } 157 }
158}
156 159
157 return len; 160/* read an entry */
161static ssize_t
162batadv_vis_data_read_entry(struct seq_file *seq,
163 const struct batadv_vis_info_entry *entry,
164 const uint8_t *src, bool primary)
165{
166 if (primary && entry->quality == 0)
167 return seq_printf(seq, "TT %pM, ", entry->dest);
168 else if (batadv_compare_eth(entry->src, src))
169 return seq_printf(seq, "TQ %pM %d, ", entry->dest,
170 entry->quality);
171
172 return 0;
158} 173}
159 174
160static size_t vis_data_count_prim_sec(struct hlist_head *if_list) 175static void
176batadv_vis_data_insert_interfaces(struct hlist_head *list,
177 struct batadv_vis_packet *packet,
178 struct batadv_vis_info_entry *entries)
161{ 179{
162 struct if_list_entry *entry; 180 int i;
163 struct hlist_node *pos;
164 size_t count = 0;
165 181
166 hlist_for_each_entry(entry, pos, if_list, list) { 182 for (i = 0; i < packet->entries; i++) {
167 if (entry->primary) 183 if (entries[i].quality == 0)
168 count += 9; 184 continue;
169 else
170 count += 23;
171 }
172 185
173 return count; 186 if (batadv_compare_eth(entries[i].src, packet->vis_orig))
187 continue;
188
189 batadv_vis_data_insert_interface(entries[i].src, list, false);
190 }
174} 191}
175 192
176/* read an entry */ 193static void batadv_vis_data_read_entries(struct seq_file *seq,
177static ssize_t vis_data_read_entry(char *buff, 194 struct hlist_head *list,
178 const struct vis_info_entry *entry, 195 struct batadv_vis_packet *packet,
179 const uint8_t *src, bool primary) 196 struct batadv_vis_info_entry *entries)
180{ 197{
181 /* maximal length: max(4+17+2, 3+17+1+3+2) == 26 */ 198 int i;
182 if (primary && entry->quality == 0) 199 struct batadv_if_list_entry *entry;
183 return sprintf(buff, "TT %pM, ", entry->dest); 200 struct hlist_node *pos;
184 else if (compare_eth(entry->src, src))
185 return sprintf(buff, "TQ %pM %d, ", entry->dest,
186 entry->quality);
187 201
188 return 0; 202 hlist_for_each_entry(entry, pos, list, list) {
203 seq_printf(seq, "%pM,", entry->addr);
204
205 for (i = 0; i < packet->entries; i++)
206 batadv_vis_data_read_entry(seq, &entries[i],
207 entry->addr, entry->primary);
208
209 /* add primary/secondary records */
210 if (batadv_compare_eth(entry->addr, packet->vis_orig))
211 batadv_vis_data_read_prim_sec(seq, list);
212
213 seq_printf(seq, "\n");
214 }
189} 215}
190 216
191int vis_seq_print_text(struct seq_file *seq, void *offset) 217static void batadv_vis_seq_print_text_bucket(struct seq_file *seq,
218 const struct hlist_head *head)
192{ 219{
193 struct hard_iface *primary_if;
194 struct hlist_node *node; 220 struct hlist_node *node;
221 struct batadv_vis_info *info;
222 struct batadv_vis_packet *packet;
223 uint8_t *entries_pos;
224 struct batadv_vis_info_entry *entries;
225 struct batadv_if_list_entry *entry;
226 struct hlist_node *pos, *n;
227
228 HLIST_HEAD(vis_if_list);
229
230 hlist_for_each_entry_rcu(info, node, head, hash_entry) {
231 packet = (struct batadv_vis_packet *)info->skb_packet->data;
232 entries_pos = (uint8_t *)packet + sizeof(*packet);
233 entries = (struct batadv_vis_info_entry *)entries_pos;
234
235 batadv_vis_data_insert_interface(packet->vis_orig, &vis_if_list,
236 true);
237 batadv_vis_data_insert_interfaces(&vis_if_list, packet,
238 entries);
239 batadv_vis_data_read_entries(seq, &vis_if_list, packet,
240 entries);
241
242 hlist_for_each_entry_safe(entry, pos, n, &vis_if_list, list) {
243 hlist_del(&entry->list);
244 kfree(entry);
245 }
246 }
247}
248
249int batadv_vis_seq_print_text(struct seq_file *seq, void *offset)
250{
251 struct batadv_hard_iface *primary_if;
195 struct hlist_head *head; 252 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; 253 struct net_device *net_dev = (struct net_device *)seq->private;
200 struct bat_priv *bat_priv = netdev_priv(net_dev); 254 struct batadv_priv *bat_priv = netdev_priv(net_dev);
201 struct hashtable_t *hash = bat_priv->vis_hash; 255 struct batadv_hashtable *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; 256 uint32_t i;
206 int j, ret = 0; 257 int ret = 0;
207 int vis_server = atomic_read(&bat_priv->vis_mode); 258 int vis_server = atomic_read(&bat_priv->vis_mode);
208 size_t buff_pos, buf_size;
209 char *buff;
210 int compare;
211 259
212 primary_if = primary_if_get_selected(bat_priv); 260 primary_if = batadv_primary_if_get_selected(bat_priv);
213 if (!primary_if) 261 if (!primary_if)
214 goto out; 262 goto out;
215 263
216 if (vis_server == VIS_TYPE_CLIENT_UPDATE) 264 if (vis_server == BATADV_VIS_TYPE_CLIENT_UPDATE)
217 goto out; 265 goto out;
218 266
219 buf_size = 1;
220 /* Estimate length */
221 spin_lock_bh(&bat_priv->vis_hash_lock); 267 spin_lock_bh(&bat_priv->vis_hash_lock);
222 for (i = 0; i < hash->size; i++) { 268 for (i = 0; i < hash->size; i++) {
223 head = &hash->table[i]; 269 head = &hash->table[i];
224 270 batadv_vis_seq_print_text_bucket(seq, head);
225 rcu_read_lock();
226 hlist_for_each_entry_rcu(info, node, head, hash_entry) {
227 packet = (struct vis_packet *)info->skb_packet->data;
228 entries = (struct vis_info_entry *)
229 ((char *)packet + sizeof(*packet));
230
231 for (j = 0; j < packet->entries; j++) {
232 if (entries[j].quality == 0)
233 continue;
234 compare =
235 compare_eth(entries[j].src, packet->vis_orig);
236 vis_data_insert_interface(entries[j].src,
237 &vis_if_list,
238 compare);
239 }
240
241 hlist_for_each_entry(entry, pos, &vis_if_list, list) {
242 buf_size += 18 + 26 * packet->entries;
243
244 /* add primary/secondary records */
245 if (compare_eth(entry->addr, packet->vis_orig))
246 buf_size +=
247 vis_data_count_prim_sec(&vis_if_list);
248
249 buf_size += 1;
250 }
251
252 hlist_for_each_entry_safe(entry, pos, n, &vis_if_list,
253 list) {
254 hlist_del(&entry->list);
255 kfree(entry);
256 }
257 }
258 rcu_read_unlock();
259 }
260
261 buff = kmalloc(buf_size, GFP_ATOMIC);
262 if (!buff) {
263 spin_unlock_bh(&bat_priv->vis_hash_lock);
264 ret = -ENOMEM;
265 goto out;
266 }
267 buff[0] = '\0';
268 buff_pos = 0;
269
270 for (i = 0; i < hash->size; i++) {
271 head = &hash->table[i];
272
273 rcu_read_lock();
274 hlist_for_each_entry_rcu(info, node, head, hash_entry) {
275 packet = (struct vis_packet *)info->skb_packet->data;
276 entries = (struct vis_info_entry *)
277 ((char *)packet + sizeof(*packet));
278
279 for (j = 0; j < packet->entries; j++) {
280 if (entries[j].quality == 0)
281 continue;
282 compare =
283 compare_eth(entries[j].src, packet->vis_orig);
284 vis_data_insert_interface(entries[j].src,
285 &vis_if_list,
286 compare);
287 }
288
289 hlist_for_each_entry(entry, pos, &vis_if_list, list) {
290 buff_pos += sprintf(buff + buff_pos, "%pM,",
291 entry->addr);
292
293 for (j = 0; j < packet->entries; j++)
294 buff_pos += vis_data_read_entry(
295 buff + buff_pos,
296 &entries[j],
297 entry->addr,
298 entry->primary);
299
300 /* add primary/secondary records */
301 if (compare_eth(entry->addr, packet->vis_orig))
302 buff_pos +=
303 vis_data_read_prim_sec(buff + buff_pos,
304 &vis_if_list);
305
306 buff_pos += sprintf(buff + buff_pos, "\n");
307 }
308
309 hlist_for_each_entry_safe(entry, pos, n, &vis_if_list,
310 list) {
311 hlist_del(&entry->list);
312 kfree(entry);
313 }
314 }
315 rcu_read_unlock();
316 } 271 }
317
318 spin_unlock_bh(&bat_priv->vis_hash_lock); 272 spin_unlock_bh(&bat_priv->vis_hash_lock);
319 273
320 seq_printf(seq, "%s", buff);
321 kfree(buff);
322
323out: 274out:
324 if (primary_if) 275 if (primary_if)
325 hardif_free_ref(primary_if); 276 batadv_hardif_free_ref(primary_if);
326 return ret; 277 return ret;
327} 278}
328 279
329/* add the info packet to the send list, if it was not 280/* add the info packet to the send list, if it was not
330 * already linked in. */ 281 * already linked in.
331static void send_list_add(struct bat_priv *bat_priv, struct vis_info *info) 282 */
283static void batadv_send_list_add(struct batadv_priv *bat_priv,
284 struct batadv_vis_info *info)
332{ 285{
333 if (list_empty(&info->send_list)) { 286 if (list_empty(&info->send_list)) {
334 kref_get(&info->refcount); 287 kref_get(&info->refcount);
@@ -337,20 +290,21 @@ static void send_list_add(struct bat_priv *bat_priv, struct vis_info *info)
337} 290}
338 291
339/* delete the info packet from the send list, if it was 292/* delete the info packet from the send list, if it was
340 * linked in. */ 293 * linked in.
341static void send_list_del(struct vis_info *info) 294 */
295static void batadv_send_list_del(struct batadv_vis_info *info)
342{ 296{
343 if (!list_empty(&info->send_list)) { 297 if (!list_empty(&info->send_list)) {
344 list_del_init(&info->send_list); 298 list_del_init(&info->send_list);
345 kref_put(&info->refcount, free_info); 299 kref_put(&info->refcount, batadv_free_info);
346 } 300 }
347} 301}
348 302
349/* tries to add one entry to the receive list. */ 303/* tries to add one entry to the receive list. */
350static void recv_list_add(struct bat_priv *bat_priv, 304static void batadv_recv_list_add(struct batadv_priv *bat_priv,
351 struct list_head *recv_list, const char *mac) 305 struct list_head *recv_list, const char *mac)
352{ 306{
353 struct recvlist_node *entry; 307 struct batadv_recvlist_node *entry;
354 308
355 entry = kmalloc(sizeof(*entry), GFP_ATOMIC); 309 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
356 if (!entry) 310 if (!entry)
@@ -363,14 +317,15 @@ static void recv_list_add(struct bat_priv *bat_priv,
363} 317}
364 318
365/* returns 1 if this mac is in the recv_list */ 319/* returns 1 if this mac is in the recv_list */
366static int recv_list_is_in(struct bat_priv *bat_priv, 320static int batadv_recv_list_is_in(struct batadv_priv *bat_priv,
367 const struct list_head *recv_list, const char *mac) 321 const struct list_head *recv_list,
322 const char *mac)
368{ 323{
369 const struct recvlist_node *entry; 324 const struct batadv_recvlist_node *entry;
370 325
371 spin_lock_bh(&bat_priv->vis_list_lock); 326 spin_lock_bh(&bat_priv->vis_list_lock);
372 list_for_each_entry(entry, recv_list, list) { 327 list_for_each_entry(entry, recv_list, list) {
373 if (compare_eth(entry->mac, mac)) { 328 if (batadv_compare_eth(entry->mac, mac)) {
374 spin_unlock_bh(&bat_priv->vis_list_lock); 329 spin_unlock_bh(&bat_priv->vis_list_lock);
375 return 1; 330 return 1;
376 } 331 }
@@ -381,17 +336,21 @@ static int recv_list_is_in(struct bat_priv *bat_priv,
381 336
382/* try to add the packet to the vis_hash. return NULL if invalid (e.g. too old, 337/* try to add the packet to the vis_hash. return NULL if invalid (e.g. too old,
383 * broken.. ). vis hash must be locked outside. is_new is set when the packet 338 * broken.. ). vis hash must be locked outside. is_new is set when the packet
384 * is newer than old entries in the hash. */ 339 * is newer than old entries in the hash.
385static struct vis_info *add_packet(struct bat_priv *bat_priv, 340 */
386 struct vis_packet *vis_packet, 341static struct batadv_vis_info *
387 int vis_info_len, int *is_new, 342batadv_add_packet(struct batadv_priv *bat_priv,
388 int make_broadcast) 343 struct batadv_vis_packet *vis_packet, int vis_info_len,
344 int *is_new, int make_broadcast)
389{ 345{
390 struct vis_info *info, *old_info; 346 struct batadv_vis_info *info, *old_info;
391 struct vis_packet *search_packet, *old_packet; 347 struct batadv_vis_packet *search_packet, *old_packet;
392 struct vis_info search_elem; 348 struct batadv_vis_info search_elem;
393 struct vis_packet *packet; 349 struct batadv_vis_packet *packet;
350 struct sk_buff *tmp_skb;
394 int hash_added; 351 int hash_added;
352 size_t len;
353 size_t max_entries;
395 354
396 *is_new = 0; 355 *is_new = 0;
397 /* sanity check */ 356 /* sanity check */
@@ -402,20 +361,23 @@ static struct vis_info *add_packet(struct bat_priv *bat_priv,
402 search_elem.skb_packet = dev_alloc_skb(sizeof(*search_packet)); 361 search_elem.skb_packet = dev_alloc_skb(sizeof(*search_packet));
403 if (!search_elem.skb_packet) 362 if (!search_elem.skb_packet)
404 return NULL; 363 return NULL;
405 search_packet = (struct vis_packet *)skb_put(search_elem.skb_packet, 364 len = sizeof(*search_packet);
406 sizeof(*search_packet)); 365 tmp_skb = search_elem.skb_packet;
366 search_packet = (struct batadv_vis_packet *)skb_put(tmp_skb, len);
407 367
408 memcpy(search_packet->vis_orig, vis_packet->vis_orig, ETH_ALEN); 368 memcpy(search_packet->vis_orig, vis_packet->vis_orig, ETH_ALEN);
409 old_info = vis_hash_find(bat_priv, &search_elem); 369 old_info = batadv_vis_hash_find(bat_priv, &search_elem);
410 kfree_skb(search_elem.skb_packet); 370 kfree_skb(search_elem.skb_packet);
411 371
412 if (old_info) { 372 if (old_info) {
413 old_packet = (struct vis_packet *)old_info->skb_packet->data; 373 tmp_skb = old_info->skb_packet;
414 if (!seq_after(ntohl(vis_packet->seqno), 374 old_packet = (struct batadv_vis_packet *)tmp_skb->data;
415 ntohl(old_packet->seqno))) { 375 if (!batadv_seq_after(ntohl(vis_packet->seqno),
376 ntohl(old_packet->seqno))) {
416 if (old_packet->seqno == vis_packet->seqno) { 377 if (old_packet->seqno == vis_packet->seqno) {
417 recv_list_add(bat_priv, &old_info->recv_list, 378 batadv_recv_list_add(bat_priv,
418 vis_packet->sender_orig); 379 &old_info->recv_list,
380 vis_packet->sender_orig);
419 return old_info; 381 return old_info;
420 } else { 382 } else {
421 /* newer packet is already in hash. */ 383 /* newer packet is already in hash. */
@@ -423,52 +385,53 @@ static struct vis_info *add_packet(struct bat_priv *bat_priv,
423 } 385 }
424 } 386 }
425 /* remove old entry */ 387 /* remove old entry */
426 hash_remove(bat_priv->vis_hash, vis_info_cmp, vis_info_choose, 388 batadv_hash_remove(bat_priv->vis_hash, batadv_vis_info_cmp,
427 old_info); 389 batadv_vis_info_choose, old_info);
428 send_list_del(old_info); 390 batadv_send_list_del(old_info);
429 kref_put(&old_info->refcount, free_info); 391 kref_put(&old_info->refcount, batadv_free_info);
430 } 392 }
431 393
432 info = kmalloc(sizeof(*info), GFP_ATOMIC); 394 info = kmalloc(sizeof(*info), GFP_ATOMIC);
433 if (!info) 395 if (!info)
434 return NULL; 396 return NULL;
435 397
436 info->skb_packet = dev_alloc_skb(sizeof(*packet) + vis_info_len + 398 len = sizeof(*packet) + vis_info_len;
437 ETH_HLEN); 399 info->skb_packet = dev_alloc_skb(len + ETH_HLEN);
438 if (!info->skb_packet) { 400 if (!info->skb_packet) {
439 kfree(info); 401 kfree(info);
440 return NULL; 402 return NULL;
441 } 403 }
442 skb_reserve(info->skb_packet, ETH_HLEN); 404 skb_reserve(info->skb_packet, ETH_HLEN);
443 packet = (struct vis_packet *)skb_put(info->skb_packet, sizeof(*packet) 405 packet = (struct batadv_vis_packet *)skb_put(info->skb_packet, len);
444 + vis_info_len);
445 406
446 kref_init(&info->refcount); 407 kref_init(&info->refcount);
447 INIT_LIST_HEAD(&info->send_list); 408 INIT_LIST_HEAD(&info->send_list);
448 INIT_LIST_HEAD(&info->recv_list); 409 INIT_LIST_HEAD(&info->recv_list);
449 info->first_seen = jiffies; 410 info->first_seen = jiffies;
450 info->bat_priv = bat_priv; 411 info->bat_priv = bat_priv;
451 memcpy(packet, vis_packet, sizeof(*packet) + vis_info_len); 412 memcpy(packet, vis_packet, len);
452 413
453 /* initialize and add new packet. */ 414 /* initialize and add new packet. */
454 *is_new = 1; 415 *is_new = 1;
455 416
456 /* Make it a broadcast packet, if required */ 417 /* Make it a broadcast packet, if required */
457 if (make_broadcast) 418 if (make_broadcast)
458 memcpy(packet->target_orig, broadcast_addr, ETH_ALEN); 419 memcpy(packet->target_orig, batadv_broadcast_addr, ETH_ALEN);
459 420
460 /* repair if entries is longer than packet. */ 421 /* repair if entries is longer than packet. */
461 if (packet->entries * sizeof(struct vis_info_entry) > vis_info_len) 422 max_entries = vis_info_len / sizeof(struct batadv_vis_info_entry);
462 packet->entries = vis_info_len / sizeof(struct vis_info_entry); 423 if (packet->entries > max_entries)
424 packet->entries = max_entries;
463 425
464 recv_list_add(bat_priv, &info->recv_list, packet->sender_orig); 426 batadv_recv_list_add(bat_priv, &info->recv_list, packet->sender_orig);
465 427
466 /* try to add it */ 428 /* try to add it */
467 hash_added = hash_add(bat_priv->vis_hash, vis_info_cmp, vis_info_choose, 429 hash_added = batadv_hash_add(bat_priv->vis_hash, batadv_vis_info_cmp,
468 info, &info->hash_entry); 430 batadv_vis_info_choose, info,
431 &info->hash_entry);
469 if (hash_added != 0) { 432 if (hash_added != 0) {
470 /* did not work (for some reason) */ 433 /* did not work (for some reason) */
471 kref_put(&info->refcount, free_info); 434 kref_put(&info->refcount, batadv_free_info);
472 info = NULL; 435 info = NULL;
473 } 436 }
474 437
@@ -476,37 +439,38 @@ static struct vis_info *add_packet(struct bat_priv *bat_priv,
476} 439}
477 440
478/* handle the server sync packet, forward if needed. */ 441/* handle the server sync packet, forward if needed. */
479void receive_server_sync_packet(struct bat_priv *bat_priv, 442void batadv_receive_server_sync_packet(struct batadv_priv *bat_priv,
480 struct vis_packet *vis_packet, 443 struct batadv_vis_packet *vis_packet,
481 int vis_info_len) 444 int vis_info_len)
482{ 445{
483 struct vis_info *info; 446 struct batadv_vis_info *info;
484 int is_new, make_broadcast; 447 int is_new, make_broadcast;
485 int vis_server = atomic_read(&bat_priv->vis_mode); 448 int vis_server = atomic_read(&bat_priv->vis_mode);
486 449
487 make_broadcast = (vis_server == VIS_TYPE_SERVER_SYNC); 450 make_broadcast = (vis_server == BATADV_VIS_TYPE_SERVER_SYNC);
488 451
489 spin_lock_bh(&bat_priv->vis_hash_lock); 452 spin_lock_bh(&bat_priv->vis_hash_lock);
490 info = add_packet(bat_priv, vis_packet, vis_info_len, 453 info = batadv_add_packet(bat_priv, vis_packet, vis_info_len,
491 &is_new, make_broadcast); 454 &is_new, make_broadcast);
492 if (!info) 455 if (!info)
493 goto end; 456 goto end;
494 457
495 /* only if we are server ourselves and packet is newer than the one in 458 /* only if we are server ourselves and packet is newer than the one in
496 * hash.*/ 459 * hash.
497 if (vis_server == VIS_TYPE_SERVER_SYNC && is_new) 460 */
498 send_list_add(bat_priv, info); 461 if (vis_server == BATADV_VIS_TYPE_SERVER_SYNC && is_new)
462 batadv_send_list_add(bat_priv, info);
499end: 463end:
500 spin_unlock_bh(&bat_priv->vis_hash_lock); 464 spin_unlock_bh(&bat_priv->vis_hash_lock);
501} 465}
502 466
503/* handle an incoming client update packet and schedule forward if needed. */ 467/* handle an incoming client update packet and schedule forward if needed. */
504void receive_client_update_packet(struct bat_priv *bat_priv, 468void batadv_receive_client_update_packet(struct batadv_priv *bat_priv,
505 struct vis_packet *vis_packet, 469 struct batadv_vis_packet *vis_packet,
506 int vis_info_len) 470 int vis_info_len)
507{ 471{
508 struct vis_info *info; 472 struct batadv_vis_info *info;
509 struct vis_packet *packet; 473 struct batadv_vis_packet *packet;
510 int is_new; 474 int is_new;
511 int vis_server = atomic_read(&bat_priv->vis_mode); 475 int vis_server = atomic_read(&bat_priv->vis_mode);
512 int are_target = 0; 476 int are_target = 0;
@@ -516,28 +480,28 @@ void receive_client_update_packet(struct bat_priv *bat_priv,
516 return; 480 return;
517 481
518 /* Are we the target for this VIS packet? */ 482 /* Are we the target for this VIS packet? */
519 if (vis_server == VIS_TYPE_SERVER_SYNC && 483 if (vis_server == BATADV_VIS_TYPE_SERVER_SYNC &&
520 is_my_mac(vis_packet->target_orig)) 484 batadv_is_my_mac(vis_packet->target_orig))
521 are_target = 1; 485 are_target = 1;
522 486
523 spin_lock_bh(&bat_priv->vis_hash_lock); 487 spin_lock_bh(&bat_priv->vis_hash_lock);
524 info = add_packet(bat_priv, vis_packet, vis_info_len, 488 info = batadv_add_packet(bat_priv, vis_packet, vis_info_len,
525 &is_new, are_target); 489 &is_new, are_target);
526 490
527 if (!info) 491 if (!info)
528 goto end; 492 goto end;
529 /* note that outdated packets will be dropped at this point. */ 493 /* note that outdated packets will be dropped at this point. */
530 494
531 packet = (struct vis_packet *)info->skb_packet->data; 495 packet = (struct batadv_vis_packet *)info->skb_packet->data;
532 496
533 /* send only if we're the target server or ... */ 497 /* send only if we're the target server or ... */
534 if (are_target && is_new) { 498 if (are_target && is_new) {
535 packet->vis_type = VIS_TYPE_SERVER_SYNC; /* upgrade! */ 499 packet->vis_type = BATADV_VIS_TYPE_SERVER_SYNC; /* upgrade! */
536 send_list_add(bat_priv, info); 500 batadv_send_list_add(bat_priv, info);
537 501
538 /* ... we're not the recipient (and thus need to forward). */ 502 /* ... we're not the recipient (and thus need to forward). */
539 } else if (!is_my_mac(packet->target_orig)) { 503 } else if (!batadv_is_my_mac(packet->target_orig)) {
540 send_list_add(bat_priv, info); 504 batadv_send_list_add(bat_priv, info);
541 } 505 }
542 506
543end: 507end:
@@ -547,37 +511,38 @@ end:
547/* Walk the originators and find the VIS server with the best tq. Set the packet 511/* Walk the originators and find the VIS server with the best tq. Set the packet
548 * address to its address and return the best_tq. 512 * address to its address and return the best_tq.
549 * 513 *
550 * Must be called with the originator hash locked */ 514 * Must be called with the originator hash locked
551static int find_best_vis_server(struct bat_priv *bat_priv, 515 */
552 struct vis_info *info) 516static int batadv_find_best_vis_server(struct batadv_priv *bat_priv,
517 struct batadv_vis_info *info)
553{ 518{
554 struct hashtable_t *hash = bat_priv->orig_hash; 519 struct batadv_hashtable *hash = bat_priv->orig_hash;
555 struct neigh_node *router; 520 struct batadv_neigh_node *router;
556 struct hlist_node *node; 521 struct hlist_node *node;
557 struct hlist_head *head; 522 struct hlist_head *head;
558 struct orig_node *orig_node; 523 struct batadv_orig_node *orig_node;
559 struct vis_packet *packet; 524 struct batadv_vis_packet *packet;
560 int best_tq = -1; 525 int best_tq = -1;
561 uint32_t i; 526 uint32_t i;
562 527
563 packet = (struct vis_packet *)info->skb_packet->data; 528 packet = (struct batadv_vis_packet *)info->skb_packet->data;
564 529
565 for (i = 0; i < hash->size; i++) { 530 for (i = 0; i < hash->size; i++) {
566 head = &hash->table[i]; 531 head = &hash->table[i];
567 532
568 rcu_read_lock(); 533 rcu_read_lock();
569 hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) { 534 hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
570 router = orig_node_get_router(orig_node); 535 router = batadv_orig_node_get_router(orig_node);
571 if (!router) 536 if (!router)
572 continue; 537 continue;
573 538
574 if ((orig_node->flags & VIS_SERVER) && 539 if ((orig_node->flags & BATADV_VIS_SERVER) &&
575 (router->tq_avg > best_tq)) { 540 (router->tq_avg > best_tq)) {
576 best_tq = router->tq_avg; 541 best_tq = router->tq_avg;
577 memcpy(packet->target_orig, orig_node->orig, 542 memcpy(packet->target_orig, orig_node->orig,
578 ETH_ALEN); 543 ETH_ALEN);
579 } 544 }
580 neigh_node_free_ref(router); 545 batadv_neigh_node_free_ref(router);
581 } 546 }
582 rcu_read_unlock(); 547 rcu_read_unlock();
583 } 548 }
@@ -586,47 +551,52 @@ static int find_best_vis_server(struct bat_priv *bat_priv,
586} 551}
587 552
588/* Return true if the vis packet is full. */ 553/* Return true if the vis packet is full. */
589static bool vis_packet_full(const struct vis_info *info) 554static bool batadv_vis_packet_full(const struct batadv_vis_info *info)
590{ 555{
591 const struct vis_packet *packet; 556 const struct batadv_vis_packet *packet;
592 packet = (struct vis_packet *)info->skb_packet->data; 557 size_t num;
558
559 packet = (struct batadv_vis_packet *)info->skb_packet->data;
560 num = BATADV_MAX_VIS_PACKET_SIZE / sizeof(struct batadv_vis_info_entry);
593 561
594 if (MAX_VIS_PACKET_SIZE / sizeof(struct vis_info_entry) 562 if (num < packet->entries + 1)
595 < packet->entries + 1)
596 return true; 563 return true;
597 return false; 564 return false;
598} 565}
599 566
600/* generates a packet of own vis data, 567/* generates a packet of own vis data,
601 * returns 0 on success, -1 if no packet could be generated */ 568 * returns 0 on success, -1 if no packet could be generated
602static int generate_vis_packet(struct bat_priv *bat_priv) 569 */
570static int batadv_generate_vis_packet(struct batadv_priv *bat_priv)
603{ 571{
604 struct hashtable_t *hash = bat_priv->orig_hash; 572 struct batadv_hashtable *hash = bat_priv->orig_hash;
605 struct hlist_node *node; 573 struct hlist_node *node;
606 struct hlist_head *head; 574 struct hlist_head *head;
607 struct orig_node *orig_node; 575 struct batadv_orig_node *orig_node;
608 struct neigh_node *router; 576 struct batadv_neigh_node *router;
609 struct vis_info *info = bat_priv->my_vis_info; 577 struct batadv_vis_info *info = bat_priv->my_vis_info;
610 struct vis_packet *packet = (struct vis_packet *)info->skb_packet->data; 578 struct batadv_vis_packet *packet;
611 struct vis_info_entry *entry; 579 struct batadv_vis_info_entry *entry;
612 struct tt_common_entry *tt_common_entry; 580 struct batadv_tt_common_entry *tt_common_entry;
613 int best_tq = -1; 581 int best_tq = -1;
614 uint32_t i; 582 uint32_t i;
615 583
616 info->first_seen = jiffies; 584 info->first_seen = jiffies;
585 packet = (struct batadv_vis_packet *)info->skb_packet->data;
617 packet->vis_type = atomic_read(&bat_priv->vis_mode); 586 packet->vis_type = atomic_read(&bat_priv->vis_mode);
618 587
619 memcpy(packet->target_orig, broadcast_addr, ETH_ALEN); 588 memcpy(packet->target_orig, batadv_broadcast_addr, ETH_ALEN);
620 packet->header.ttl = TTL; 589 packet->header.ttl = BATADV_TTL;
621 packet->seqno = htonl(ntohl(packet->seqno) + 1); 590 packet->seqno = htonl(ntohl(packet->seqno) + 1);
622 packet->entries = 0; 591 packet->entries = 0;
592 packet->reserved = 0;
623 skb_trim(info->skb_packet, sizeof(*packet)); 593 skb_trim(info->skb_packet, sizeof(*packet));
624 594
625 if (packet->vis_type == VIS_TYPE_CLIENT_UPDATE) { 595 if (packet->vis_type == BATADV_VIS_TYPE_CLIENT_UPDATE) {
626 best_tq = find_best_vis_server(bat_priv, info); 596 best_tq = batadv_find_best_vis_server(bat_priv, info);
627 597
628 if (best_tq < 0) 598 if (best_tq < 0)
629 return -1; 599 return best_tq;
630 } 600 }
631 601
632 for (i = 0; i < hash->size; i++) { 602 for (i = 0; i < hash->size; i++) {
@@ -634,21 +604,21 @@ static int generate_vis_packet(struct bat_priv *bat_priv)
634 604
635 rcu_read_lock(); 605 rcu_read_lock();
636 hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) { 606 hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
637 router = orig_node_get_router(orig_node); 607 router = batadv_orig_node_get_router(orig_node);
638 if (!router) 608 if (!router)
639 continue; 609 continue;
640 610
641 if (!compare_eth(router->addr, orig_node->orig)) 611 if (!batadv_compare_eth(router->addr, orig_node->orig))
642 goto next; 612 goto next;
643 613
644 if (router->if_incoming->if_status != IF_ACTIVE) 614 if (router->if_incoming->if_status != BATADV_IF_ACTIVE)
645 goto next; 615 goto next;
646 616
647 if (router->tq_avg < 1) 617 if (router->tq_avg < 1)
648 goto next; 618 goto next;
649 619
650 /* fill one entry into buffer. */ 620 /* fill one entry into buffer. */
651 entry = (struct vis_info_entry *) 621 entry = (struct batadv_vis_info_entry *)
652 skb_put(info->skb_packet, sizeof(*entry)); 622 skb_put(info->skb_packet, sizeof(*entry));
653 memcpy(entry->src, 623 memcpy(entry->src,
654 router->if_incoming->net_dev->dev_addr, 624 router->if_incoming->net_dev->dev_addr,
@@ -658,9 +628,9 @@ static int generate_vis_packet(struct bat_priv *bat_priv)
658 packet->entries++; 628 packet->entries++;
659 629
660next: 630next:
661 neigh_node_free_ref(router); 631 batadv_neigh_node_free_ref(router);
662 632
663 if (vis_packet_full(info)) 633 if (batadv_vis_packet_full(info))
664 goto unlock; 634 goto unlock;
665 } 635 }
666 rcu_read_unlock(); 636 rcu_read_unlock();
@@ -674,7 +644,7 @@ next:
674 rcu_read_lock(); 644 rcu_read_lock();
675 hlist_for_each_entry_rcu(tt_common_entry, node, head, 645 hlist_for_each_entry_rcu(tt_common_entry, node, head,
676 hash_entry) { 646 hash_entry) {
677 entry = (struct vis_info_entry *) 647 entry = (struct batadv_vis_info_entry *)
678 skb_put(info->skb_packet, 648 skb_put(info->skb_packet,
679 sizeof(*entry)); 649 sizeof(*entry));
680 memset(entry->src, 0, ETH_ALEN); 650 memset(entry->src, 0, ETH_ALEN);
@@ -682,7 +652,7 @@ next:
682 entry->quality = 0; /* 0 means TT */ 652 entry->quality = 0; /* 0 means TT */
683 packet->entries++; 653 packet->entries++;
684 654
685 if (vis_packet_full(info)) 655 if (batadv_vis_packet_full(info))
686 goto unlock; 656 goto unlock;
687 } 657 }
688 rcu_read_unlock(); 658 rcu_read_unlock();
@@ -696,14 +666,15 @@ unlock:
696} 666}
697 667
698/* free old vis packets. Must be called with this vis_hash_lock 668/* free old vis packets. Must be called with this vis_hash_lock
699 * held */ 669 * held
700static void purge_vis_packets(struct bat_priv *bat_priv) 670 */
671static void batadv_purge_vis_packets(struct batadv_priv *bat_priv)
701{ 672{
702 uint32_t i; 673 uint32_t i;
703 struct hashtable_t *hash = bat_priv->vis_hash; 674 struct batadv_hashtable *hash = bat_priv->vis_hash;
704 struct hlist_node *node, *node_tmp; 675 struct hlist_node *node, *node_tmp;
705 struct hlist_head *head; 676 struct hlist_head *head;
706 struct vis_info *info; 677 struct batadv_vis_info *info;
707 678
708 for (i = 0; i < hash->size; i++) { 679 for (i = 0; i < hash->size; i++) {
709 head = &hash->table[i]; 680 head = &hash->table[i];
@@ -714,31 +685,32 @@ static void purge_vis_packets(struct bat_priv *bat_priv)
714 if (info == bat_priv->my_vis_info) 685 if (info == bat_priv->my_vis_info)
715 continue; 686 continue;
716 687
717 if (has_timed_out(info->first_seen, VIS_TIMEOUT)) { 688 if (batadv_has_timed_out(info->first_seen,
689 BATADV_VIS_TIMEOUT)) {
718 hlist_del(node); 690 hlist_del(node);
719 send_list_del(info); 691 batadv_send_list_del(info);
720 kref_put(&info->refcount, free_info); 692 kref_put(&info->refcount, batadv_free_info);
721 } 693 }
722 } 694 }
723 } 695 }
724} 696}
725 697
726static void broadcast_vis_packet(struct bat_priv *bat_priv, 698static void batadv_broadcast_vis_packet(struct batadv_priv *bat_priv,
727 struct vis_info *info) 699 struct batadv_vis_info *info)
728{ 700{
729 struct neigh_node *router; 701 struct batadv_neigh_node *router;
730 struct hashtable_t *hash = bat_priv->orig_hash; 702 struct batadv_hashtable *hash = bat_priv->orig_hash;
731 struct hlist_node *node; 703 struct hlist_node *node;
732 struct hlist_head *head; 704 struct hlist_head *head;
733 struct orig_node *orig_node; 705 struct batadv_orig_node *orig_node;
734 struct vis_packet *packet; 706 struct batadv_vis_packet *packet;
735 struct sk_buff *skb; 707 struct sk_buff *skb;
736 struct hard_iface *hard_iface; 708 struct batadv_hard_iface *hard_iface;
737 uint8_t dstaddr[ETH_ALEN]; 709 uint8_t dstaddr[ETH_ALEN];
738 uint32_t i; 710 uint32_t i;
739 711
740 712
741 packet = (struct vis_packet *)info->skb_packet->data; 713 packet = (struct batadv_vis_packet *)info->skb_packet->data;
742 714
743 /* send to all routers in range. */ 715 /* send to all routers in range. */
744 for (i = 0; i < hash->size; i++) { 716 for (i = 0; i < hash->size; i++) {
@@ -747,18 +719,19 @@ static void broadcast_vis_packet(struct bat_priv *bat_priv,
747 rcu_read_lock(); 719 rcu_read_lock();
748 hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) { 720 hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
749 /* if it's a vis server and reachable, send it. */ 721 /* if it's a vis server and reachable, send it. */
750 if (!(orig_node->flags & VIS_SERVER)) 722 if (!(orig_node->flags & BATADV_VIS_SERVER))
751 continue; 723 continue;
752 724
753 router = orig_node_get_router(orig_node); 725 router = batadv_orig_node_get_router(orig_node);
754 if (!router) 726 if (!router)
755 continue; 727 continue;
756 728
757 /* don't send it if we already received the packet from 729 /* don't send it if we already received the packet from
758 * this node. */ 730 * this node.
759 if (recv_list_is_in(bat_priv, &info->recv_list, 731 */
760 orig_node->orig)) { 732 if (batadv_recv_list_is_in(bat_priv, &info->recv_list,
761 neigh_node_free_ref(router); 733 orig_node->orig)) {
734 batadv_neigh_node_free_ref(router);
762 continue; 735 continue;
763 } 736 }
764 737
@@ -766,57 +739,59 @@ static void broadcast_vis_packet(struct bat_priv *bat_priv,
766 hard_iface = router->if_incoming; 739 hard_iface = router->if_incoming;
767 memcpy(dstaddr, router->addr, ETH_ALEN); 740 memcpy(dstaddr, router->addr, ETH_ALEN);
768 741
769 neigh_node_free_ref(router); 742 batadv_neigh_node_free_ref(router);
770 743
771 skb = skb_clone(info->skb_packet, GFP_ATOMIC); 744 skb = skb_clone(info->skb_packet, GFP_ATOMIC);
772 if (skb) 745 if (skb)
773 send_skb_packet(skb, hard_iface, dstaddr); 746 batadv_send_skb_packet(skb, hard_iface,
747 dstaddr);
774 748
775 } 749 }
776 rcu_read_unlock(); 750 rcu_read_unlock();
777 } 751 }
778} 752}
779 753
780static void unicast_vis_packet(struct bat_priv *bat_priv, 754static void batadv_unicast_vis_packet(struct batadv_priv *bat_priv,
781 struct vis_info *info) 755 struct batadv_vis_info *info)
782{ 756{
783 struct orig_node *orig_node; 757 struct batadv_orig_node *orig_node;
784 struct neigh_node *router = NULL; 758 struct batadv_neigh_node *router = NULL;
785 struct sk_buff *skb; 759 struct sk_buff *skb;
786 struct vis_packet *packet; 760 struct batadv_vis_packet *packet;
787 761
788 packet = (struct vis_packet *)info->skb_packet->data; 762 packet = (struct batadv_vis_packet *)info->skb_packet->data;
789 763
790 orig_node = orig_hash_find(bat_priv, packet->target_orig); 764 orig_node = batadv_orig_hash_find(bat_priv, packet->target_orig);
791 if (!orig_node) 765 if (!orig_node)
792 goto out; 766 goto out;
793 767
794 router = orig_node_get_router(orig_node); 768 router = batadv_orig_node_get_router(orig_node);
795 if (!router) 769 if (!router)
796 goto out; 770 goto out;
797 771
798 skb = skb_clone(info->skb_packet, GFP_ATOMIC); 772 skb = skb_clone(info->skb_packet, GFP_ATOMIC);
799 if (skb) 773 if (skb)
800 send_skb_packet(skb, router->if_incoming, router->addr); 774 batadv_send_skb_packet(skb, router->if_incoming, router->addr);
801 775
802out: 776out:
803 if (router) 777 if (router)
804 neigh_node_free_ref(router); 778 batadv_neigh_node_free_ref(router);
805 if (orig_node) 779 if (orig_node)
806 orig_node_free_ref(orig_node); 780 batadv_orig_node_free_ref(orig_node);
807} 781}
808 782
809/* only send one vis packet. called from send_vis_packets() */ 783/* only send one vis packet. called from batadv_send_vis_packets() */
810static void send_vis_packet(struct bat_priv *bat_priv, struct vis_info *info) 784static void batadv_send_vis_packet(struct batadv_priv *bat_priv,
785 struct batadv_vis_info *info)
811{ 786{
812 struct hard_iface *primary_if; 787 struct batadv_hard_iface *primary_if;
813 struct vis_packet *packet; 788 struct batadv_vis_packet *packet;
814 789
815 primary_if = primary_if_get_selected(bat_priv); 790 primary_if = batadv_primary_if_get_selected(bat_priv);
816 if (!primary_if) 791 if (!primary_if)
817 goto out; 792 goto out;
818 793
819 packet = (struct vis_packet *)info->skb_packet->data; 794 packet = (struct batadv_vis_packet *)info->skb_packet->data;
820 if (packet->header.ttl < 2) { 795 if (packet->header.ttl < 2) {
821 pr_debug("Error - can't send vis packet: ttl exceeded\n"); 796 pr_debug("Error - can't send vis packet: ttl exceeded\n");
822 goto out; 797 goto out;
@@ -826,31 +801,31 @@ static void send_vis_packet(struct bat_priv *bat_priv, struct vis_info *info)
826 packet->header.ttl--; 801 packet->header.ttl--;
827 802
828 if (is_broadcast_ether_addr(packet->target_orig)) 803 if (is_broadcast_ether_addr(packet->target_orig))
829 broadcast_vis_packet(bat_priv, info); 804 batadv_broadcast_vis_packet(bat_priv, info);
830 else 805 else
831 unicast_vis_packet(bat_priv, info); 806 batadv_unicast_vis_packet(bat_priv, info);
832 packet->header.ttl++; /* restore TTL */ 807 packet->header.ttl++; /* restore TTL */
833 808
834out: 809out:
835 if (primary_if) 810 if (primary_if)
836 hardif_free_ref(primary_if); 811 batadv_hardif_free_ref(primary_if);
837} 812}
838 813
839/* called from timer; send (and maybe generate) vis packet. */ 814/* called from timer; send (and maybe generate) vis packet. */
840static void send_vis_packets(struct work_struct *work) 815static void batadv_send_vis_packets(struct work_struct *work)
841{ 816{
842 struct delayed_work *delayed_work = 817 struct delayed_work *delayed_work =
843 container_of(work, struct delayed_work, work); 818 container_of(work, struct delayed_work, work);
844 struct bat_priv *bat_priv = 819 struct batadv_priv *bat_priv;
845 container_of(delayed_work, struct bat_priv, vis_work); 820 struct batadv_vis_info *info;
846 struct vis_info *info;
847 821
822 bat_priv = container_of(delayed_work, struct batadv_priv, vis_work);
848 spin_lock_bh(&bat_priv->vis_hash_lock); 823 spin_lock_bh(&bat_priv->vis_hash_lock);
849 purge_vis_packets(bat_priv); 824 batadv_purge_vis_packets(bat_priv);
850 825
851 if (generate_vis_packet(bat_priv) == 0) { 826 if (batadv_generate_vis_packet(bat_priv) == 0) {
852 /* schedule if generation was successful */ 827 /* schedule if generation was successful */
853 send_list_add(bat_priv, bat_priv->my_vis_info); 828 batadv_send_list_add(bat_priv, bat_priv->my_vis_info);
854 } 829 }
855 830
856 while (!list_empty(&bat_priv->vis_send_list)) { 831 while (!list_empty(&bat_priv->vis_send_list)) {
@@ -860,98 +835,103 @@ static void send_vis_packets(struct work_struct *work)
860 kref_get(&info->refcount); 835 kref_get(&info->refcount);
861 spin_unlock_bh(&bat_priv->vis_hash_lock); 836 spin_unlock_bh(&bat_priv->vis_hash_lock);
862 837
863 send_vis_packet(bat_priv, info); 838 batadv_send_vis_packet(bat_priv, info);
864 839
865 spin_lock_bh(&bat_priv->vis_hash_lock); 840 spin_lock_bh(&bat_priv->vis_hash_lock);
866 send_list_del(info); 841 batadv_send_list_del(info);
867 kref_put(&info->refcount, free_info); 842 kref_put(&info->refcount, batadv_free_info);
868 } 843 }
869 spin_unlock_bh(&bat_priv->vis_hash_lock); 844 spin_unlock_bh(&bat_priv->vis_hash_lock);
870 start_vis_timer(bat_priv); 845 batadv_start_vis_timer(bat_priv);
871} 846}
872 847
873/* init the vis server. this may only be called when if_list is already 848/* init the vis server. this may only be called when if_list is already
874 * initialized (e.g. bat0 is initialized, interfaces have been added) */ 849 * initialized (e.g. bat0 is initialized, interfaces have been added)
875int vis_init(struct bat_priv *bat_priv) 850 */
851int batadv_vis_init(struct batadv_priv *bat_priv)
876{ 852{
877 struct vis_packet *packet; 853 struct batadv_vis_packet *packet;
878 int hash_added; 854 int hash_added;
855 unsigned int len;
856 unsigned long first_seen;
857 struct sk_buff *tmp_skb;
879 858
880 if (bat_priv->vis_hash) 859 if (bat_priv->vis_hash)
881 return 1; 860 return 0;
882 861
883 spin_lock_bh(&bat_priv->vis_hash_lock); 862 spin_lock_bh(&bat_priv->vis_hash_lock);
884 863
885 bat_priv->vis_hash = hash_new(256); 864 bat_priv->vis_hash = batadv_hash_new(256);
886 if (!bat_priv->vis_hash) { 865 if (!bat_priv->vis_hash) {
887 pr_err("Can't initialize vis_hash\n"); 866 pr_err("Can't initialize vis_hash\n");
888 goto err; 867 goto err;
889 } 868 }
890 869
891 bat_priv->my_vis_info = kmalloc(MAX_VIS_PACKET_SIZE, GFP_ATOMIC); 870 bat_priv->my_vis_info = kmalloc(BATADV_MAX_VIS_PACKET_SIZE, GFP_ATOMIC);
892 if (!bat_priv->my_vis_info) 871 if (!bat_priv->my_vis_info)
893 goto err; 872 goto err;
894 873
895 bat_priv->my_vis_info->skb_packet = dev_alloc_skb(sizeof(*packet) + 874 len = sizeof(*packet) + BATADV_MAX_VIS_PACKET_SIZE + ETH_HLEN;
896 MAX_VIS_PACKET_SIZE + 875 bat_priv->my_vis_info->skb_packet = dev_alloc_skb(len);
897 ETH_HLEN);
898 if (!bat_priv->my_vis_info->skb_packet) 876 if (!bat_priv->my_vis_info->skb_packet)
899 goto free_info; 877 goto free_info;
900 878
901 skb_reserve(bat_priv->my_vis_info->skb_packet, ETH_HLEN); 879 skb_reserve(bat_priv->my_vis_info->skb_packet, ETH_HLEN);
902 packet = (struct vis_packet *)skb_put(bat_priv->my_vis_info->skb_packet, 880 tmp_skb = bat_priv->my_vis_info->skb_packet;
903 sizeof(*packet)); 881 packet = (struct batadv_vis_packet *)skb_put(tmp_skb, sizeof(*packet));
904 882
905 /* prefill the vis info */ 883 /* prefill the vis info */
906 bat_priv->my_vis_info->first_seen = jiffies - 884 first_seen = jiffies - msecs_to_jiffies(BATADV_VIS_INTERVAL);
907 msecs_to_jiffies(VIS_INTERVAL); 885 bat_priv->my_vis_info->first_seen = first_seen;
908 INIT_LIST_HEAD(&bat_priv->my_vis_info->recv_list); 886 INIT_LIST_HEAD(&bat_priv->my_vis_info->recv_list);
909 INIT_LIST_HEAD(&bat_priv->my_vis_info->send_list); 887 INIT_LIST_HEAD(&bat_priv->my_vis_info->send_list);
910 kref_init(&bat_priv->my_vis_info->refcount); 888 kref_init(&bat_priv->my_vis_info->refcount);
911 bat_priv->my_vis_info->bat_priv = bat_priv; 889 bat_priv->my_vis_info->bat_priv = bat_priv;
912 packet->header.version = COMPAT_VERSION; 890 packet->header.version = BATADV_COMPAT_VERSION;
913 packet->header.packet_type = BAT_VIS; 891 packet->header.packet_type = BATADV_VIS;
914 packet->header.ttl = TTL; 892 packet->header.ttl = BATADV_TTL;
915 packet->seqno = 0; 893 packet->seqno = 0;
894 packet->reserved = 0;
916 packet->entries = 0; 895 packet->entries = 0;
917 896
918 INIT_LIST_HEAD(&bat_priv->vis_send_list); 897 INIT_LIST_HEAD(&bat_priv->vis_send_list);
919 898
920 hash_added = hash_add(bat_priv->vis_hash, vis_info_cmp, vis_info_choose, 899 hash_added = batadv_hash_add(bat_priv->vis_hash, batadv_vis_info_cmp,
921 bat_priv->my_vis_info, 900 batadv_vis_info_choose,
922 &bat_priv->my_vis_info->hash_entry); 901 bat_priv->my_vis_info,
902 &bat_priv->my_vis_info->hash_entry);
923 if (hash_added != 0) { 903 if (hash_added != 0) {
924 pr_err("Can't add own vis packet into hash\n"); 904 pr_err("Can't add own vis packet into hash\n");
925 /* not in hash, need to remove it manually. */ 905 /* not in hash, need to remove it manually. */
926 kref_put(&bat_priv->my_vis_info->refcount, free_info); 906 kref_put(&bat_priv->my_vis_info->refcount, batadv_free_info);
927 goto err; 907 goto err;
928 } 908 }
929 909
930 spin_unlock_bh(&bat_priv->vis_hash_lock); 910 spin_unlock_bh(&bat_priv->vis_hash_lock);
931 start_vis_timer(bat_priv); 911 batadv_start_vis_timer(bat_priv);
932 return 1; 912 return 0;
933 913
934free_info: 914free_info:
935 kfree(bat_priv->my_vis_info); 915 kfree(bat_priv->my_vis_info);
936 bat_priv->my_vis_info = NULL; 916 bat_priv->my_vis_info = NULL;
937err: 917err:
938 spin_unlock_bh(&bat_priv->vis_hash_lock); 918 spin_unlock_bh(&bat_priv->vis_hash_lock);
939 vis_quit(bat_priv); 919 batadv_vis_quit(bat_priv);
940 return 0; 920 return -ENOMEM;
941} 921}
942 922
943/* Decrease the reference count on a hash item info */ 923/* Decrease the reference count on a hash item info */
944static void free_info_ref(struct hlist_node *node, void *arg) 924static void batadv_free_info_ref(struct hlist_node *node, void *arg)
945{ 925{
946 struct vis_info *info; 926 struct batadv_vis_info *info;
947 927
948 info = container_of(node, struct vis_info, hash_entry); 928 info = container_of(node, struct batadv_vis_info, hash_entry);
949 send_list_del(info); 929 batadv_send_list_del(info);
950 kref_put(&info->refcount, free_info); 930 kref_put(&info->refcount, batadv_free_info);
951} 931}
952 932
953/* shutdown vis-server */ 933/* shutdown vis-server */
954void vis_quit(struct bat_priv *bat_priv) 934void batadv_vis_quit(struct batadv_priv *bat_priv)
955{ 935{
956 if (!bat_priv->vis_hash) 936 if (!bat_priv->vis_hash)
957 return; 937 return;
@@ -960,16 +940,16 @@ void vis_quit(struct bat_priv *bat_priv)
960 940
961 spin_lock_bh(&bat_priv->vis_hash_lock); 941 spin_lock_bh(&bat_priv->vis_hash_lock);
962 /* properly remove, kill timers ... */ 942 /* properly remove, kill timers ... */
963 hash_delete(bat_priv->vis_hash, free_info_ref, NULL); 943 batadv_hash_delete(bat_priv->vis_hash, batadv_free_info_ref, NULL);
964 bat_priv->vis_hash = NULL; 944 bat_priv->vis_hash = NULL;
965 bat_priv->my_vis_info = NULL; 945 bat_priv->my_vis_info = NULL;
966 spin_unlock_bh(&bat_priv->vis_hash_lock); 946 spin_unlock_bh(&bat_priv->vis_hash_lock);
967} 947}
968 948
969/* schedule packets for (re)transmission */ 949/* schedule packets for (re)transmission */
970static void start_vis_timer(struct bat_priv *bat_priv) 950static void batadv_start_vis_timer(struct batadv_priv *bat_priv)
971{ 951{
972 INIT_DELAYED_WORK(&bat_priv->vis_work, send_vis_packets); 952 INIT_DELAYED_WORK(&bat_priv->vis_work, batadv_send_vis_packets);
973 queue_delayed_work(bat_event_workqueue, &bat_priv->vis_work, 953 queue_delayed_work(batadv_event_workqueue, &bat_priv->vis_work,
974 msecs_to_jiffies(VIS_INTERVAL)); 954 msecs_to_jiffies(BATADV_VIS_INTERVAL));
975} 955}