blob: 8d15b48d1692455c7a71c34c8d1031fc426bca14 [file] [log] [blame]
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001/*
Sven Eckelmann64afe352011-01-27 10:38:15 +01002 * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00003 *
4 * Marek Lindner, 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 "translation-table.h"
24#include "soft-interface.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000025#include "hash.h"
26#include "originator.h"
27
28static void hna_local_purge(struct work_struct *work);
29static void _hna_global_del_orig(struct bat_priv *bat_priv,
30 struct hna_global_entry *hna_global_entry,
31 char *message);
32
Marek Lindner7aadf882011-02-18 12:28:09 +000033/* returns 1 if they are the same mac addr */
34static int compare_lhna(struct hlist_node *node, void *data2)
35{
36 void *data1 = container_of(node, struct hna_local_entry, hash_entry);
37
38 return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
39}
40
41/* returns 1 if they are the same mac addr */
42static int compare_ghna(struct hlist_node *node, void *data2)
43{
44 void *data1 = container_of(node, struct hna_global_entry, hash_entry);
45
46 return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
47}
48
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000049static void hna_local_start_timer(struct bat_priv *bat_priv)
50{
51 INIT_DELAYED_WORK(&bat_priv->hna_work, hna_local_purge);
52 queue_delayed_work(bat_event_workqueue, &bat_priv->hna_work, 10 * HZ);
53}
54
Marek Lindner7aadf882011-02-18 12:28:09 +000055static struct hna_local_entry *hna_local_hash_find(struct bat_priv *bat_priv,
56 void *data)
57{
58 struct hashtable_t *hash = bat_priv->hna_local_hash;
59 struct hlist_head *head;
60 struct hlist_node *node;
61 struct hna_local_entry *hna_local_entry, *hna_local_entry_tmp = NULL;
62 int index;
63
64 if (!hash)
65 return NULL;
66
67 index = choose_orig(data, hash->size);
68 head = &hash->table[index];
69
70 rcu_read_lock();
71 hlist_for_each_entry_rcu(hna_local_entry, node, head, hash_entry) {
72 if (!compare_eth(hna_local_entry, data))
73 continue;
74
75 hna_local_entry_tmp = hna_local_entry;
76 break;
77 }
78 rcu_read_unlock();
79
80 return hna_local_entry_tmp;
81}
82
83static struct hna_global_entry *hna_global_hash_find(struct bat_priv *bat_priv,
84 void *data)
85{
86 struct hashtable_t *hash = bat_priv->hna_global_hash;
87 struct hlist_head *head;
88 struct hlist_node *node;
89 struct hna_global_entry *hna_global_entry;
90 struct hna_global_entry *hna_global_entry_tmp = NULL;
91 int index;
92
93 if (!hash)
94 return NULL;
95
96 index = choose_orig(data, hash->size);
97 head = &hash->table[index];
98
99 rcu_read_lock();
100 hlist_for_each_entry_rcu(hna_global_entry, node, head, hash_entry) {
101 if (!compare_eth(hna_global_entry, data))
102 continue;
103
104 hna_global_entry_tmp = hna_global_entry;
105 break;
106 }
107 rcu_read_unlock();
108
109 return hna_global_entry_tmp;
110}
111
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000112int hna_local_init(struct bat_priv *bat_priv)
113{
114 if (bat_priv->hna_local_hash)
115 return 1;
116
117 bat_priv->hna_local_hash = hash_new(1024);
118
119 if (!bat_priv->hna_local_hash)
120 return 0;
121
122 atomic_set(&bat_priv->hna_local_changed, 0);
123 hna_local_start_timer(bat_priv);
124
125 return 1;
126}
127
128void hna_local_add(struct net_device *soft_iface, uint8_t *addr)
129{
130 struct bat_priv *bat_priv = netdev_priv(soft_iface);
131 struct hna_local_entry *hna_local_entry;
132 struct hna_global_entry *hna_global_entry;
133 int required_bytes;
134
135 spin_lock_bh(&bat_priv->hna_lhash_lock);
Marek Lindner7aadf882011-02-18 12:28:09 +0000136 hna_local_entry = hna_local_hash_find(bat_priv, addr);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000137 spin_unlock_bh(&bat_priv->hna_lhash_lock);
138
139 if (hna_local_entry) {
140 hna_local_entry->last_seen = jiffies;
141 return;
142 }
143
144 /* only announce as many hosts as possible in the batman-packet and
145 space in batman_packet->num_hna That also should give a limit to
146 MAC-flooding. */
147 required_bytes = (bat_priv->num_local_hna + 1) * ETH_ALEN;
148 required_bytes += BAT_PACKET_LEN;
149
150 if ((required_bytes > ETH_DATA_LEN) ||
151 (atomic_read(&bat_priv->aggregated_ogms) &&
152 required_bytes > MAX_AGGREGATION_BYTES) ||
153 (bat_priv->num_local_hna + 1 > 255)) {
154 bat_dbg(DBG_ROUTES, bat_priv,
155 "Can't add new local hna entry (%pM): "
156 "number of local hna entries exceeds packet size\n",
157 addr);
158 return;
159 }
160
161 bat_dbg(DBG_ROUTES, bat_priv,
162 "Creating new local hna entry: %pM\n", addr);
163
164 hna_local_entry = kmalloc(sizeof(struct hna_local_entry), GFP_ATOMIC);
165 if (!hna_local_entry)
166 return;
167
168 memcpy(hna_local_entry->addr, addr, ETH_ALEN);
169 hna_local_entry->last_seen = jiffies;
170
171 /* the batman interface mac address should never be purged */
Marek Lindner39901e72011-02-18 12:28:08 +0000172 if (compare_eth(addr, soft_iface->dev_addr))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000173 hna_local_entry->never_purge = 1;
174 else
175 hna_local_entry->never_purge = 0;
176
177 spin_lock_bh(&bat_priv->hna_lhash_lock);
178
Marek Lindner7aadf882011-02-18 12:28:09 +0000179 hash_add(bat_priv->hna_local_hash, compare_lhna, choose_orig,
180 hna_local_entry, &hna_local_entry->hash_entry);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000181 bat_priv->num_local_hna++;
182 atomic_set(&bat_priv->hna_local_changed, 1);
183
184 spin_unlock_bh(&bat_priv->hna_lhash_lock);
185
186 /* remove address from global hash if present */
187 spin_lock_bh(&bat_priv->hna_ghash_lock);
188
Marek Lindner7aadf882011-02-18 12:28:09 +0000189 hna_global_entry = hna_global_hash_find(bat_priv, addr);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000190
191 if (hna_global_entry)
192 _hna_global_del_orig(bat_priv, hna_global_entry,
193 "local hna received");
194
195 spin_unlock_bh(&bat_priv->hna_ghash_lock);
196}
197
198int hna_local_fill_buffer(struct bat_priv *bat_priv,
199 unsigned char *buff, int buff_len)
200{
201 struct hashtable_t *hash = bat_priv->hna_local_hash;
202 struct hna_local_entry *hna_local_entry;
Marek Lindner7aadf882011-02-18 12:28:09 +0000203 struct hlist_node *node;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000204 struct hlist_head *head;
Marek Lindner7aadf882011-02-18 12:28:09 +0000205 int i, count = 0;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000206
207 spin_lock_bh(&bat_priv->hna_lhash_lock);
208
209 for (i = 0; i < hash->size; i++) {
210 head = &hash->table[i];
211
Marek Lindner7aadf882011-02-18 12:28:09 +0000212 rcu_read_lock();
213 hlist_for_each_entry_rcu(hna_local_entry, node,
214 head, hash_entry) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000215 if (buff_len < (count + 1) * ETH_ALEN)
216 break;
217
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000218 memcpy(buff + (count * ETH_ALEN), hna_local_entry->addr,
219 ETH_ALEN);
220
221 count++;
222 }
Marek Lindner7aadf882011-02-18 12:28:09 +0000223 rcu_read_unlock();
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000224 }
225
226 /* if we did not get all new local hnas see you next time ;-) */
227 if (count == bat_priv->num_local_hna)
228 atomic_set(&bat_priv->hna_local_changed, 0);
229
230 spin_unlock_bh(&bat_priv->hna_lhash_lock);
Sven Eckelmann53320fe2010-12-20 10:32:03 -0800231 return count;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000232}
233
234int hna_local_seq_print_text(struct seq_file *seq, void *offset)
235{
236 struct net_device *net_dev = (struct net_device *)seq->private;
237 struct bat_priv *bat_priv = netdev_priv(net_dev);
238 struct hashtable_t *hash = bat_priv->hna_local_hash;
239 struct hna_local_entry *hna_local_entry;
Marek Lindner7aadf882011-02-18 12:28:09 +0000240 struct hlist_node *node;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000241 struct hlist_head *head;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000242 size_t buf_size, pos;
243 char *buff;
Marek Lindner7aadf882011-02-18 12:28:09 +0000244 int i;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000245
246 if (!bat_priv->primary_if) {
247 return seq_printf(seq, "BATMAN mesh %s disabled - "
248 "please specify interfaces to enable it\n",
249 net_dev->name);
250 }
251
252 seq_printf(seq, "Locally retrieved addresses (from %s) "
253 "announced via HNA:\n",
254 net_dev->name);
255
256 spin_lock_bh(&bat_priv->hna_lhash_lock);
257
258 buf_size = 1;
259 /* Estimate length for: " * xx:xx:xx:xx:xx:xx\n" */
260 for (i = 0; i < hash->size; i++) {
261 head = &hash->table[i];
262
Marek Lindner7aadf882011-02-18 12:28:09 +0000263 rcu_read_lock();
264 __hlist_for_each_rcu(node, head)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000265 buf_size += 21;
Marek Lindner7aadf882011-02-18 12:28:09 +0000266 rcu_read_unlock();
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000267 }
268
269 buff = kmalloc(buf_size, GFP_ATOMIC);
270 if (!buff) {
271 spin_unlock_bh(&bat_priv->hna_lhash_lock);
272 return -ENOMEM;
273 }
Marek Lindner7aadf882011-02-18 12:28:09 +0000274
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000275 buff[0] = '\0';
276 pos = 0;
277
278 for (i = 0; i < hash->size; i++) {
279 head = &hash->table[i];
280
Marek Lindner7aadf882011-02-18 12:28:09 +0000281 rcu_read_lock();
282 hlist_for_each_entry_rcu(hna_local_entry, node,
283 head, hash_entry) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000284 pos += snprintf(buff + pos, 22, " * %pM\n",
285 hna_local_entry->addr);
286 }
Marek Lindner7aadf882011-02-18 12:28:09 +0000287 rcu_read_unlock();
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000288 }
289
290 spin_unlock_bh(&bat_priv->hna_lhash_lock);
291
292 seq_printf(seq, "%s", buff);
293 kfree(buff);
294 return 0;
295}
296
Marek Lindner7aadf882011-02-18 12:28:09 +0000297static void _hna_local_del(struct hlist_node *node, void *arg)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000298{
299 struct bat_priv *bat_priv = (struct bat_priv *)arg;
Marek Lindner7aadf882011-02-18 12:28:09 +0000300 void *data = container_of(node, struct hna_local_entry, hash_entry);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000301
302 kfree(data);
303 bat_priv->num_local_hna--;
304 atomic_set(&bat_priv->hna_local_changed, 1);
305}
306
307static void hna_local_del(struct bat_priv *bat_priv,
308 struct hna_local_entry *hna_local_entry,
309 char *message)
310{
311 bat_dbg(DBG_ROUTES, bat_priv, "Deleting local hna entry (%pM): %s\n",
312 hna_local_entry->addr, message);
313
Marek Lindner7aadf882011-02-18 12:28:09 +0000314 hash_remove(bat_priv->hna_local_hash, compare_lhna, choose_orig,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000315 hna_local_entry->addr);
Marek Lindner7aadf882011-02-18 12:28:09 +0000316 _hna_local_del(&hna_local_entry->hash_entry, bat_priv);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000317}
318
319void hna_local_remove(struct bat_priv *bat_priv,
320 uint8_t *addr, char *message)
321{
322 struct hna_local_entry *hna_local_entry;
323
324 spin_lock_bh(&bat_priv->hna_lhash_lock);
325
Marek Lindner7aadf882011-02-18 12:28:09 +0000326 hna_local_entry = hna_local_hash_find(bat_priv, addr);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000327
328 if (hna_local_entry)
329 hna_local_del(bat_priv, hna_local_entry, message);
330
331 spin_unlock_bh(&bat_priv->hna_lhash_lock);
332}
333
334static void hna_local_purge(struct work_struct *work)
335{
336 struct delayed_work *delayed_work =
337 container_of(work, struct delayed_work, work);
338 struct bat_priv *bat_priv =
339 container_of(delayed_work, struct bat_priv, hna_work);
340 struct hashtable_t *hash = bat_priv->hna_local_hash;
341 struct hna_local_entry *hna_local_entry;
Marek Lindner7aadf882011-02-18 12:28:09 +0000342 struct hlist_node *node, *node_tmp;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000343 struct hlist_head *head;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000344 unsigned long timeout;
Marek Lindner7aadf882011-02-18 12:28:09 +0000345 int i;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000346
347 spin_lock_bh(&bat_priv->hna_lhash_lock);
348
349 for (i = 0; i < hash->size; i++) {
350 head = &hash->table[i];
351
Marek Lindner7aadf882011-02-18 12:28:09 +0000352 hlist_for_each_entry_safe(hna_local_entry, node, node_tmp,
353 head, hash_entry) {
354 if (hna_local_entry->never_purge)
355 continue;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000356
357 timeout = hna_local_entry->last_seen;
358 timeout += LOCAL_HNA_TIMEOUT * HZ;
359
Marek Lindner7aadf882011-02-18 12:28:09 +0000360 if (time_before(jiffies, timeout))
361 continue;
362
363 hna_local_del(bat_priv, hna_local_entry,
364 "address timed out");
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000365 }
366 }
367
368 spin_unlock_bh(&bat_priv->hna_lhash_lock);
369 hna_local_start_timer(bat_priv);
370}
371
372void hna_local_free(struct bat_priv *bat_priv)
373{
374 if (!bat_priv->hna_local_hash)
375 return;
376
377 cancel_delayed_work_sync(&bat_priv->hna_work);
378 hash_delete(bat_priv->hna_local_hash, _hna_local_del, bat_priv);
379 bat_priv->hna_local_hash = NULL;
380}
381
382int hna_global_init(struct bat_priv *bat_priv)
383{
384 if (bat_priv->hna_global_hash)
385 return 1;
386
387 bat_priv->hna_global_hash = hash_new(1024);
388
389 if (!bat_priv->hna_global_hash)
390 return 0;
391
392 return 1;
393}
394
395void hna_global_add_orig(struct bat_priv *bat_priv,
396 struct orig_node *orig_node,
397 unsigned char *hna_buff, int hna_buff_len)
398{
399 struct hna_global_entry *hna_global_entry;
400 struct hna_local_entry *hna_local_entry;
401 int hna_buff_count = 0;
402 unsigned char *hna_ptr;
403
404 while ((hna_buff_count + 1) * ETH_ALEN <= hna_buff_len) {
405 spin_lock_bh(&bat_priv->hna_ghash_lock);
406
407 hna_ptr = hna_buff + (hna_buff_count * ETH_ALEN);
Marek Lindner7aadf882011-02-18 12:28:09 +0000408 hna_global_entry = hna_global_hash_find(bat_priv, hna_ptr);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000409
410 if (!hna_global_entry) {
411 spin_unlock_bh(&bat_priv->hna_ghash_lock);
412
413 hna_global_entry =
414 kmalloc(sizeof(struct hna_global_entry),
415 GFP_ATOMIC);
416
417 if (!hna_global_entry)
418 break;
419
420 memcpy(hna_global_entry->addr, hna_ptr, ETH_ALEN);
421
422 bat_dbg(DBG_ROUTES, bat_priv,
423 "Creating new global hna entry: "
424 "%pM (via %pM)\n",
425 hna_global_entry->addr, orig_node->orig);
426
427 spin_lock_bh(&bat_priv->hna_ghash_lock);
Marek Lindner7aadf882011-02-18 12:28:09 +0000428 hash_add(bat_priv->hna_global_hash, compare_ghna,
429 choose_orig, hna_global_entry,
430 &hna_global_entry->hash_entry);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000431
432 }
433
434 hna_global_entry->orig_node = orig_node;
435 spin_unlock_bh(&bat_priv->hna_ghash_lock);
436
437 /* remove address from local hash if present */
438 spin_lock_bh(&bat_priv->hna_lhash_lock);
439
440 hna_ptr = hna_buff + (hna_buff_count * ETH_ALEN);
Marek Lindner7aadf882011-02-18 12:28:09 +0000441 hna_local_entry = hna_local_hash_find(bat_priv, hna_ptr);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000442
443 if (hna_local_entry)
444 hna_local_del(bat_priv, hna_local_entry,
445 "global hna received");
446
447 spin_unlock_bh(&bat_priv->hna_lhash_lock);
448
449 hna_buff_count++;
450 }
451
452 /* initialize, and overwrite if malloc succeeds */
453 orig_node->hna_buff = NULL;
454 orig_node->hna_buff_len = 0;
455
456 if (hna_buff_len > 0) {
457 orig_node->hna_buff = kmalloc(hna_buff_len, GFP_ATOMIC);
458 if (orig_node->hna_buff) {
459 memcpy(orig_node->hna_buff, hna_buff, hna_buff_len);
460 orig_node->hna_buff_len = hna_buff_len;
461 }
462 }
463}
464
465int hna_global_seq_print_text(struct seq_file *seq, void *offset)
466{
467 struct net_device *net_dev = (struct net_device *)seq->private;
468 struct bat_priv *bat_priv = netdev_priv(net_dev);
469 struct hashtable_t *hash = bat_priv->hna_global_hash;
470 struct hna_global_entry *hna_global_entry;
Marek Lindner7aadf882011-02-18 12:28:09 +0000471 struct hlist_node *node;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000472 struct hlist_head *head;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000473 size_t buf_size, pos;
474 char *buff;
Marek Lindner7aadf882011-02-18 12:28:09 +0000475 int i;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000476
477 if (!bat_priv->primary_if) {
478 return seq_printf(seq, "BATMAN mesh %s disabled - "
479 "please specify interfaces to enable it\n",
480 net_dev->name);
481 }
482
483 seq_printf(seq, "Globally announced HNAs received via the mesh %s\n",
484 net_dev->name);
485
486 spin_lock_bh(&bat_priv->hna_ghash_lock);
487
488 buf_size = 1;
489 /* Estimate length for: " * xx:xx:xx:xx:xx:xx via xx:xx:xx:xx:xx:xx\n"*/
490 for (i = 0; i < hash->size; i++) {
491 head = &hash->table[i];
492
Marek Lindner7aadf882011-02-18 12:28:09 +0000493 rcu_read_lock();
494 __hlist_for_each_rcu(node, head)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000495 buf_size += 43;
Marek Lindner7aadf882011-02-18 12:28:09 +0000496 rcu_read_unlock();
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000497 }
498
499 buff = kmalloc(buf_size, GFP_ATOMIC);
500 if (!buff) {
501 spin_unlock_bh(&bat_priv->hna_ghash_lock);
502 return -ENOMEM;
503 }
504 buff[0] = '\0';
505 pos = 0;
506
507 for (i = 0; i < hash->size; i++) {
508 head = &hash->table[i];
509
Marek Lindner7aadf882011-02-18 12:28:09 +0000510 rcu_read_lock();
511 hlist_for_each_entry_rcu(hna_global_entry, node,
512 head, hash_entry) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000513 pos += snprintf(buff + pos, 44,
514 " * %pM via %pM\n",
515 hna_global_entry->addr,
516 hna_global_entry->orig_node->orig);
517 }
Marek Lindner7aadf882011-02-18 12:28:09 +0000518 rcu_read_unlock();
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000519 }
520
521 spin_unlock_bh(&bat_priv->hna_ghash_lock);
522
523 seq_printf(seq, "%s", buff);
524 kfree(buff);
525 return 0;
526}
527
528static void _hna_global_del_orig(struct bat_priv *bat_priv,
529 struct hna_global_entry *hna_global_entry,
530 char *message)
531{
532 bat_dbg(DBG_ROUTES, bat_priv,
533 "Deleting global hna entry %pM (via %pM): %s\n",
534 hna_global_entry->addr, hna_global_entry->orig_node->orig,
535 message);
536
Marek Lindner7aadf882011-02-18 12:28:09 +0000537 hash_remove(bat_priv->hna_global_hash, compare_ghna, choose_orig,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000538 hna_global_entry->addr);
539 kfree(hna_global_entry);
540}
541
542void hna_global_del_orig(struct bat_priv *bat_priv,
543 struct orig_node *orig_node, char *message)
544{
545 struct hna_global_entry *hna_global_entry;
546 int hna_buff_count = 0;
547 unsigned char *hna_ptr;
548
549 if (orig_node->hna_buff_len == 0)
550 return;
551
552 spin_lock_bh(&bat_priv->hna_ghash_lock);
553
554 while ((hna_buff_count + 1) * ETH_ALEN <= orig_node->hna_buff_len) {
555 hna_ptr = orig_node->hna_buff + (hna_buff_count * ETH_ALEN);
Marek Lindner7aadf882011-02-18 12:28:09 +0000556 hna_global_entry = hna_global_hash_find(bat_priv, hna_ptr);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000557
558 if ((hna_global_entry) &&
559 (hna_global_entry->orig_node == orig_node))
560 _hna_global_del_orig(bat_priv, hna_global_entry,
561 message);
562
563 hna_buff_count++;
564 }
565
566 spin_unlock_bh(&bat_priv->hna_ghash_lock);
567
568 orig_node->hna_buff_len = 0;
569 kfree(orig_node->hna_buff);
570 orig_node->hna_buff = NULL;
571}
572
Marek Lindner7aadf882011-02-18 12:28:09 +0000573static void hna_global_del(struct hlist_node *node, void *arg)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000574{
Marek Lindner7aadf882011-02-18 12:28:09 +0000575 void *data = container_of(node, struct hna_global_entry, hash_entry);
576
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000577 kfree(data);
578}
579
580void hna_global_free(struct bat_priv *bat_priv)
581{
582 if (!bat_priv->hna_global_hash)
583 return;
584
585 hash_delete(bat_priv->hna_global_hash, hna_global_del, NULL);
586 bat_priv->hna_global_hash = NULL;
587}
588
589struct orig_node *transtable_search(struct bat_priv *bat_priv, uint8_t *addr)
590{
591 struct hna_global_entry *hna_global_entry;
Marek Lindner7b36e8e2011-02-18 12:28:10 +0000592 struct orig_node *orig_node = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000593
594 spin_lock_bh(&bat_priv->hna_ghash_lock);
Marek Lindner7aadf882011-02-18 12:28:09 +0000595 hna_global_entry = hna_global_hash_find(bat_priv, addr);
596
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000597 if (!hna_global_entry)
Marek Lindner7b36e8e2011-02-18 12:28:10 +0000598 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000599
Marek Lindner7b36e8e2011-02-18 12:28:10 +0000600 if (!atomic_inc_not_zero(&hna_global_entry->orig_node->refcount))
601 goto out;
602
603 orig_node = hna_global_entry->orig_node;
604
605out:
606 spin_unlock_bh(&bat_priv->hna_ghash_lock);
607 return orig_node;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000608}