1 /* Copyright (C) 2007-2013 B.A.T.M.A.N. contributors:
3 * Marek Lindner, Simon Wunderlich, Antonio Quartulli
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public
7 * License as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #include "translation-table.h"
22 #include "soft-interface.h"
23 #include "hard-interface.h"
26 #include "originator.h"
28 #include "bridge_loop_avoidance.h"
30 #include <linux/crc32c.h>
33 static struct lock_class_key batadv_tt_local_hash_lock_class_key;
34 static struct lock_class_key batadv_tt_global_hash_lock_class_key;
36 static void batadv_send_roam_adv(struct batadv_priv *bat_priv, uint8_t *client,
38 struct batadv_orig_node *orig_node);
39 static void batadv_tt_purge(struct work_struct *work);
41 batadv_tt_global_del_orig_list(struct batadv_tt_global_entry *tt_global_entry);
42 static void batadv_tt_global_del(struct batadv_priv *bat_priv,
43 struct batadv_orig_node *orig_node,
44 const unsigned char *addr,
45 unsigned short vid, const char *message,
48 /* returns 1 if they are the same mac addr */
49 static int batadv_compare_tt(const struct hlist_node *node, const void *data2)
51 const void *data1 = container_of(node, struct batadv_tt_common_entry,
54 return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
58 * batadv_choose_tt - return the index of the tt entry in the hash table
59 * @data: pointer to the tt_common_entry object to map
60 * @size: the size of the hash table
62 * Returns the hash index where the object represented by 'data' should be
65 static inline uint32_t batadv_choose_tt(const void *data, uint32_t size)
67 struct batadv_tt_common_entry *tt;
70 tt = (struct batadv_tt_common_entry *)data;
71 hash = batadv_hash_bytes(hash, &tt->addr, ETH_ALEN);
72 hash = batadv_hash_bytes(hash, &tt->vid, sizeof(tt->vid));
82 * batadv_tt_hash_find - look for a client in the given hash table
83 * @hash: the hash table to search
84 * @addr: the mac address of the client to look for
85 * @vid: VLAN identifier
87 * Returns a pointer to the tt_common struct belonging to the searched client if
88 * found, NULL otherwise.
90 static struct batadv_tt_common_entry *
91 batadv_tt_hash_find(struct batadv_hashtable *hash, const uint8_t *addr,
94 struct hlist_head *head;
95 struct batadv_tt_common_entry to_search, *tt, *tt_tmp = NULL;
101 memcpy(to_search.addr, addr, ETH_ALEN);
104 index = batadv_choose_tt(&to_search, hash->size);
105 head = &hash->table[index];
108 hlist_for_each_entry_rcu(tt, head, hash_entry) {
109 if (!batadv_compare_eth(tt, addr))
115 if (!atomic_inc_not_zero(&tt->refcount))
127 * batadv_tt_local_hash_find - search the local table for a given client
128 * @bat_priv: the bat priv with all the soft interface information
129 * @addr: the mac address of the client to look for
130 * @vid: VLAN identifier
132 * Returns a pointer to the corresponding tt_local_entry struct if the client is
133 * found, NULL otherwise.
135 static struct batadv_tt_local_entry *
136 batadv_tt_local_hash_find(struct batadv_priv *bat_priv, const uint8_t *addr,
139 struct batadv_tt_common_entry *tt_common_entry;
140 struct batadv_tt_local_entry *tt_local_entry = NULL;
142 tt_common_entry = batadv_tt_hash_find(bat_priv->tt.local_hash, addr,
145 tt_local_entry = container_of(tt_common_entry,
146 struct batadv_tt_local_entry,
148 return tt_local_entry;
152 * batadv_tt_global_hash_find - search the global table for a given client
153 * @bat_priv: the bat priv with all the soft interface information
154 * @addr: the mac address of the client to look for
155 * @vid: VLAN identifier
157 * Returns a pointer to the corresponding tt_global_entry struct if the client
158 * is found, NULL otherwise.
160 static struct batadv_tt_global_entry *
161 batadv_tt_global_hash_find(struct batadv_priv *bat_priv, const uint8_t *addr,
164 struct batadv_tt_common_entry *tt_common_entry;
165 struct batadv_tt_global_entry *tt_global_entry = NULL;
167 tt_common_entry = batadv_tt_hash_find(bat_priv->tt.global_hash, addr,
170 tt_global_entry = container_of(tt_common_entry,
171 struct batadv_tt_global_entry,
173 return tt_global_entry;
177 batadv_tt_local_entry_free_ref(struct batadv_tt_local_entry *tt_local_entry)
179 if (atomic_dec_and_test(&tt_local_entry->common.refcount))
180 kfree_rcu(tt_local_entry, common.rcu);
184 * batadv_tt_global_entry_free_ref - decrement the refcounter for a
185 * tt_global_entry and possibly free it
186 * @tt_global_entry: the object to free
189 batadv_tt_global_entry_free_ref(struct batadv_tt_global_entry *tt_global_entry)
191 if (atomic_dec_and_test(&tt_global_entry->common.refcount)) {
192 batadv_tt_global_del_orig_list(tt_global_entry);
193 kfree_rcu(tt_global_entry, common.rcu);
197 static void batadv_tt_orig_list_entry_free_rcu(struct rcu_head *rcu)
199 struct batadv_tt_orig_list_entry *orig_entry;
201 orig_entry = container_of(rcu, struct batadv_tt_orig_list_entry, rcu);
203 /* We are in an rcu callback here, therefore we cannot use
204 * batadv_orig_node_free_ref() and its call_rcu():
205 * An rcu_barrier() wouldn't wait for that to finish
207 batadv_orig_node_free_ref_now(orig_entry->orig_node);
212 batadv_tt_orig_list_entry_free_ref(struct batadv_tt_orig_list_entry *orig_entry)
214 if (!atomic_dec_and_test(&orig_entry->refcount))
216 /* to avoid race conditions, immediately decrease the tt counter */
217 atomic_dec(&orig_entry->orig_node->tt_size);
218 call_rcu(&orig_entry->rcu, batadv_tt_orig_list_entry_free_rcu);
222 * batadv_tt_local_event - store a local TT event (ADD/DEL)
223 * @bat_priv: the bat priv with all the soft interface information
224 * @tt_local_entry: the TT entry involved in the event
225 * @event_flags: flags to store in the event structure
227 static void batadv_tt_local_event(struct batadv_priv *bat_priv,
228 struct batadv_tt_local_entry *tt_local_entry,
231 struct batadv_tt_change_node *tt_change_node, *entry, *safe;
232 struct batadv_tt_common_entry *common = &tt_local_entry->common;
233 uint8_t flags = common->flags | event_flags;
234 bool event_removed = false;
235 bool del_op_requested, del_op_entry;
237 tt_change_node = kmalloc(sizeof(*tt_change_node), GFP_ATOMIC);
241 tt_change_node->change.flags = flags;
242 tt_change_node->change.reserved = 0;
243 memcpy(tt_change_node->change.addr, common->addr, ETH_ALEN);
244 tt_change_node->change.vid = htons(common->vid);
246 del_op_requested = flags & BATADV_TT_CLIENT_DEL;
248 /* check for ADD+DEL or DEL+ADD events */
249 spin_lock_bh(&bat_priv->tt.changes_list_lock);
250 list_for_each_entry_safe(entry, safe, &bat_priv->tt.changes_list,
252 if (!batadv_compare_eth(entry->change.addr, common->addr))
255 /* DEL+ADD in the same orig interval have no effect and can be
256 * removed to avoid silly behaviour on the receiver side. The
257 * other way around (ADD+DEL) can happen in case of roaming of
258 * a client still in the NEW state. Roaming of NEW clients is
259 * now possible due to automatically recognition of "temporary"
262 del_op_entry = entry->change.flags & BATADV_TT_CLIENT_DEL;
263 if (!del_op_requested && del_op_entry)
265 if (del_op_requested && !del_op_entry)
269 list_del(&entry->list);
271 kfree(tt_change_node);
272 event_removed = true;
276 /* track the change in the OGMinterval list */
277 list_add_tail(&tt_change_node->list, &bat_priv->tt.changes_list);
280 spin_unlock_bh(&bat_priv->tt.changes_list_lock);
283 atomic_dec(&bat_priv->tt.local_changes);
285 atomic_inc(&bat_priv->tt.local_changes);
289 * batadv_tt_len - compute length in bytes of given number of tt changes
290 * @changes_num: number of tt changes
292 * Returns computed length in bytes.
294 static int batadv_tt_len(int changes_num)
296 return changes_num * sizeof(struct batadv_tvlv_tt_change);
300 * batadv_tt_entries - compute the number of entries fitting in tt_len bytes
301 * @tt_len: available space
303 * Returns the number of entries.
305 static uint16_t batadv_tt_entries(uint16_t tt_len)
307 return tt_len / batadv_tt_len(1);
310 static int batadv_tt_local_init(struct batadv_priv *bat_priv)
312 if (bat_priv->tt.local_hash)
315 bat_priv->tt.local_hash = batadv_hash_new(1024);
317 if (!bat_priv->tt.local_hash)
320 batadv_hash_set_lock_class(bat_priv->tt.local_hash,
321 &batadv_tt_local_hash_lock_class_key);
326 static void batadv_tt_global_free(struct batadv_priv *bat_priv,
327 struct batadv_tt_global_entry *tt_global,
330 batadv_dbg(BATADV_DBG_TT, bat_priv,
331 "Deleting global tt entry %pM (vid: %d): %s\n",
332 tt_global->common.addr,
333 BATADV_PRINT_VID(tt_global->common.vid), message);
335 batadv_hash_remove(bat_priv->tt.global_hash, batadv_compare_tt,
336 batadv_choose_tt, &tt_global->common);
337 batadv_tt_global_entry_free_ref(tt_global);
341 * batadv_tt_local_add - add a new client to the local table or update an
343 * @soft_iface: netdev struct of the mesh interface
344 * @addr: the mac address of the client to add
345 * @vid: VLAN identifier
346 * @ifindex: index of the interface where the client is connected to (useful to
347 * identify wireless clients)
349 void batadv_tt_local_add(struct net_device *soft_iface, const uint8_t *addr,
350 unsigned short vid, int ifindex)
352 struct batadv_priv *bat_priv = netdev_priv(soft_iface);
353 struct batadv_tt_local_entry *tt_local;
354 struct batadv_tt_global_entry *tt_global;
355 struct hlist_head *head;
356 struct batadv_tt_orig_list_entry *orig_entry;
358 bool roamed_back = false;
360 tt_local = batadv_tt_local_hash_find(bat_priv, addr, vid);
361 tt_global = batadv_tt_global_hash_find(bat_priv, addr, vid);
364 tt_local->last_seen = jiffies;
365 if (tt_local->common.flags & BATADV_TT_CLIENT_PENDING) {
366 batadv_dbg(BATADV_DBG_TT, bat_priv,
367 "Re-adding pending client %pM (vid: %d)\n",
368 addr, BATADV_PRINT_VID(vid));
369 /* whatever the reason why the PENDING flag was set,
370 * this is a client which was enqueued to be removed in
371 * this orig_interval. Since it popped up again, the
372 * flag can be reset like it was never enqueued
374 tt_local->common.flags &= ~BATADV_TT_CLIENT_PENDING;
378 if (tt_local->common.flags & BATADV_TT_CLIENT_ROAM) {
379 batadv_dbg(BATADV_DBG_TT, bat_priv,
380 "Roaming client %pM (vid: %d) came back to its original location\n",
381 addr, BATADV_PRINT_VID(vid));
382 /* the ROAM flag is set because this client roamed away
383 * and the node got a roaming_advertisement message. Now
384 * that the client popped up again at its original
385 * location such flag can be unset
387 tt_local->common.flags &= ~BATADV_TT_CLIENT_ROAM;
393 tt_local = kmalloc(sizeof(*tt_local), GFP_ATOMIC);
397 batadv_dbg(BATADV_DBG_TT, bat_priv,
398 "Creating new local tt entry: %pM (vid: %d, ttvn: %d)\n",
399 addr, BATADV_PRINT_VID(vid),
400 (uint8_t)atomic_read(&bat_priv->tt.vn));
402 memcpy(tt_local->common.addr, addr, ETH_ALEN);
403 /* The local entry has to be marked as NEW to avoid to send it in
404 * a full table response going out before the next ttvn increment
405 * (consistency check)
407 tt_local->common.flags = BATADV_TT_CLIENT_NEW;
408 tt_local->common.vid = vid;
409 if (batadv_is_wifi_iface(ifindex))
410 tt_local->common.flags |= BATADV_TT_CLIENT_WIFI;
411 atomic_set(&tt_local->common.refcount, 2);
412 tt_local->last_seen = jiffies;
413 tt_local->common.added_at = tt_local->last_seen;
415 /* the batman interface mac address should never be purged */
416 if (batadv_compare_eth(addr, soft_iface->dev_addr))
417 tt_local->common.flags |= BATADV_TT_CLIENT_NOPURGE;
419 hash_added = batadv_hash_add(bat_priv->tt.local_hash, batadv_compare_tt,
420 batadv_choose_tt, &tt_local->common,
421 &tt_local->common.hash_entry);
423 if (unlikely(hash_added != 0)) {
424 /* remove the reference for the hash */
425 batadv_tt_local_entry_free_ref(tt_local);
430 batadv_tt_local_event(bat_priv, tt_local, BATADV_NO_FLAGS);
433 /* Check whether it is a roaming, but don't do anything if the roaming
434 * process has already been handled
436 if (tt_global && !(tt_global->common.flags & BATADV_TT_CLIENT_ROAM)) {
437 /* These node are probably going to update their tt table */
438 head = &tt_global->orig_list;
440 hlist_for_each_entry_rcu(orig_entry, head, list) {
441 batadv_send_roam_adv(bat_priv, tt_global->common.addr,
442 tt_global->common.vid,
443 orig_entry->orig_node);
447 batadv_tt_global_free(bat_priv, tt_global,
451 /* The global entry has to be marked as ROAMING and
452 * has to be kept for consistency purpose
454 tt_global->common.flags |= BATADV_TT_CLIENT_ROAM;
455 tt_global->roam_at = jiffies;
461 batadv_tt_local_entry_free_ref(tt_local);
463 batadv_tt_global_entry_free_ref(tt_global);
467 * batadv_tt_tvlv_container_update - update the translation table tvlv container
468 * after local tt changes have been committed
469 * @bat_priv: the bat priv with all the soft interface information
471 static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv)
473 struct batadv_tt_change_node *entry, *safe;
474 struct batadv_tvlv_tt_data *tt_data;
475 struct batadv_tvlv_tt_change *tt_change;
476 int tt_diff_len = 0, tt_change_len = 0;
477 int tt_diff_entries_num = 0, tt_diff_entries_count = 0;
479 tt_diff_len += batadv_tt_len(atomic_read(&bat_priv->tt.local_changes));
481 /* if we have too many changes for one packet don't send any
482 * and wait for the tt table request which will be fragmented
484 if (tt_diff_len > bat_priv->soft_iface->mtu)
487 tt_data = kzalloc(sizeof(*tt_data) + tt_diff_len, GFP_ATOMIC);
491 tt_data->flags = BATADV_TT_OGM_DIFF;
492 tt_data->ttvn = atomic_read(&bat_priv->tt.vn);
493 tt_data->crc = htonl(bat_priv->tt.local_crc);
495 if (tt_diff_len == 0)
496 goto container_register;
498 tt_diff_entries_num = batadv_tt_entries(tt_diff_len);
500 spin_lock_bh(&bat_priv->tt.changes_list_lock);
501 atomic_set(&bat_priv->tt.local_changes, 0);
503 tt_change = (struct batadv_tvlv_tt_change *)(tt_data + 1);
505 list_for_each_entry_safe(entry, safe, &bat_priv->tt.changes_list,
507 if (tt_diff_entries_count < tt_diff_entries_num) {
508 memcpy(tt_change + tt_diff_entries_count,
510 sizeof(struct batadv_tvlv_tt_change));
511 tt_diff_entries_count++;
513 list_del(&entry->list);
516 spin_unlock_bh(&bat_priv->tt.changes_list_lock);
518 /* Keep the buffer for possible tt_request */
519 spin_lock_bh(&bat_priv->tt.last_changeset_lock);
520 kfree(bat_priv->tt.last_changeset);
521 bat_priv->tt.last_changeset_len = 0;
522 bat_priv->tt.last_changeset = NULL;
523 tt_change_len = batadv_tt_len(tt_diff_entries_count);
524 /* check whether this new OGM has no changes due to size problems */
525 if (tt_diff_entries_count > 0) {
526 /* if kmalloc() fails we will reply with the full table
527 * instead of providing the diff
529 bat_priv->tt.last_changeset = kzalloc(tt_diff_len, GFP_ATOMIC);
530 if (bat_priv->tt.last_changeset) {
531 memcpy(bat_priv->tt.last_changeset,
532 tt_change, tt_change_len);
533 bat_priv->tt.last_changeset_len = tt_diff_len;
536 spin_unlock_bh(&bat_priv->tt.last_changeset_lock);
539 batadv_tvlv_container_register(bat_priv, BATADV_TVLV_TT, 1, tt_data,
540 sizeof(*tt_data) + tt_change_len);
544 int batadv_tt_local_seq_print_text(struct seq_file *seq, void *offset)
546 struct net_device *net_dev = (struct net_device *)seq->private;
547 struct batadv_priv *bat_priv = netdev_priv(net_dev);
548 struct batadv_hashtable *hash = bat_priv->tt.local_hash;
549 struct batadv_tt_common_entry *tt_common_entry;
550 struct batadv_tt_local_entry *tt_local;
551 struct batadv_hard_iface *primary_if;
552 struct hlist_head *head;
556 unsigned long last_seen_jiffies;
558 uint16_t np_flag = BATADV_TT_CLIENT_NOPURGE;
560 primary_if = batadv_seq_print_text_primary_if_get(seq);
565 "Locally retrieved addresses (from %s) announced via TT (TTVN: %u CRC: %#.8x):\n",
566 net_dev->name, (uint8_t)atomic_read(&bat_priv->tt.vn),
567 bat_priv->tt.local_crc);
568 seq_printf(seq, " %-13s %s %-7s %-10s\n", "Client", "VID",
569 "Flags", "Last seen");
571 for (i = 0; i < hash->size; i++) {
572 head = &hash->table[i];
575 hlist_for_each_entry_rcu(tt_common_entry,
577 tt_local = container_of(tt_common_entry,
578 struct batadv_tt_local_entry,
580 last_seen_jiffies = jiffies - tt_local->last_seen;
581 last_seen_msecs = jiffies_to_msecs(last_seen_jiffies);
582 last_seen_secs = last_seen_msecs / 1000;
583 last_seen_msecs = last_seen_msecs % 1000;
585 no_purge = tt_common_entry->flags & np_flag;
587 seq_printf(seq, " * %pM %4i [%c%c%c%c%c] %3u.%03u\n",
588 tt_common_entry->addr,
589 BATADV_PRINT_VID(tt_common_entry->vid),
590 (tt_common_entry->flags &
591 BATADV_TT_CLIENT_ROAM ? 'R' : '.'),
592 no_purge ? 'P' : '.',
593 (tt_common_entry->flags &
594 BATADV_TT_CLIENT_NEW ? 'N' : '.'),
595 (tt_common_entry->flags &
596 BATADV_TT_CLIENT_PENDING ? 'X' : '.'),
597 (tt_common_entry->flags &
598 BATADV_TT_CLIENT_WIFI ? 'W' : '.'),
599 no_purge ? 0 : last_seen_secs,
600 no_purge ? 0 : last_seen_msecs);
606 batadv_hardif_free_ref(primary_if);
611 batadv_tt_local_set_pending(struct batadv_priv *bat_priv,
612 struct batadv_tt_local_entry *tt_local_entry,
613 uint16_t flags, const char *message)
615 batadv_tt_local_event(bat_priv, tt_local_entry, flags);
617 /* The local client has to be marked as "pending to be removed" but has
618 * to be kept in the table in order to send it in a full table
619 * response issued before the net ttvn increment (consistency check)
621 tt_local_entry->common.flags |= BATADV_TT_CLIENT_PENDING;
623 batadv_dbg(BATADV_DBG_TT, bat_priv,
624 "Local tt entry (%pM, vid: %d) pending to be removed: %s\n",
625 tt_local_entry->common.addr,
626 BATADV_PRINT_VID(tt_local_entry->common.vid), message);
630 * batadv_tt_local_remove - logically remove an entry from the local table
631 * @bat_priv: the bat priv with all the soft interface information
632 * @addr: the MAC address of the client to remove
633 * @vid: VLAN identifier
634 * @message: message to append to the log on deletion
635 * @roaming: true if the deletion is due to a roaming event
637 * Returns the flags assigned to the local entry before being deleted
639 uint16_t batadv_tt_local_remove(struct batadv_priv *bat_priv,
640 const uint8_t *addr, unsigned short vid,
641 const char *message, bool roaming)
643 struct batadv_tt_local_entry *tt_local_entry;
644 uint16_t flags, curr_flags = BATADV_NO_FLAGS;
646 tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr, vid);
650 curr_flags = tt_local_entry->common.flags;
652 flags = BATADV_TT_CLIENT_DEL;
653 /* if this global entry addition is due to a roaming, the node has to
654 * mark the local entry as "roamed" in order to correctly reroute
658 flags |= BATADV_TT_CLIENT_ROAM;
659 /* mark the local client as ROAMed */
660 tt_local_entry->common.flags |= BATADV_TT_CLIENT_ROAM;
663 if (!(tt_local_entry->common.flags & BATADV_TT_CLIENT_NEW)) {
664 batadv_tt_local_set_pending(bat_priv, tt_local_entry, flags,
668 /* if this client has been added right now, it is possible to
669 * immediately purge it
671 batadv_tt_local_event(bat_priv, tt_local_entry, BATADV_TT_CLIENT_DEL);
672 hlist_del_rcu(&tt_local_entry->common.hash_entry);
673 batadv_tt_local_entry_free_ref(tt_local_entry);
677 batadv_tt_local_entry_free_ref(tt_local_entry);
682 static void batadv_tt_local_purge_list(struct batadv_priv *bat_priv,
683 struct hlist_head *head)
685 struct batadv_tt_local_entry *tt_local_entry;
686 struct batadv_tt_common_entry *tt_common_entry;
687 struct hlist_node *node_tmp;
689 hlist_for_each_entry_safe(tt_common_entry, node_tmp, head,
691 tt_local_entry = container_of(tt_common_entry,
692 struct batadv_tt_local_entry,
694 if (tt_local_entry->common.flags & BATADV_TT_CLIENT_NOPURGE)
697 /* entry already marked for deletion */
698 if (tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING)
701 if (!batadv_has_timed_out(tt_local_entry->last_seen,
702 BATADV_TT_LOCAL_TIMEOUT))
705 batadv_tt_local_set_pending(bat_priv, tt_local_entry,
706 BATADV_TT_CLIENT_DEL, "timed out");
710 static void batadv_tt_local_purge(struct batadv_priv *bat_priv)
712 struct batadv_hashtable *hash = bat_priv->tt.local_hash;
713 struct hlist_head *head;
714 spinlock_t *list_lock; /* protects write access to the hash lists */
717 for (i = 0; i < hash->size; i++) {
718 head = &hash->table[i];
719 list_lock = &hash->list_locks[i];
721 spin_lock_bh(list_lock);
722 batadv_tt_local_purge_list(bat_priv, head);
723 spin_unlock_bh(list_lock);
727 static void batadv_tt_local_table_free(struct batadv_priv *bat_priv)
729 struct batadv_hashtable *hash;
730 spinlock_t *list_lock; /* protects write access to the hash lists */
731 struct batadv_tt_common_entry *tt_common_entry;
732 struct batadv_tt_local_entry *tt_local;
733 struct hlist_node *node_tmp;
734 struct hlist_head *head;
737 if (!bat_priv->tt.local_hash)
740 hash = bat_priv->tt.local_hash;
742 for (i = 0; i < hash->size; i++) {
743 head = &hash->table[i];
744 list_lock = &hash->list_locks[i];
746 spin_lock_bh(list_lock);
747 hlist_for_each_entry_safe(tt_common_entry, node_tmp,
749 hlist_del_rcu(&tt_common_entry->hash_entry);
750 tt_local = container_of(tt_common_entry,
751 struct batadv_tt_local_entry,
753 batadv_tt_local_entry_free_ref(tt_local);
755 spin_unlock_bh(list_lock);
758 batadv_hash_destroy(hash);
760 bat_priv->tt.local_hash = NULL;
763 static int batadv_tt_global_init(struct batadv_priv *bat_priv)
765 if (bat_priv->tt.global_hash)
768 bat_priv->tt.global_hash = batadv_hash_new(1024);
770 if (!bat_priv->tt.global_hash)
773 batadv_hash_set_lock_class(bat_priv->tt.global_hash,
774 &batadv_tt_global_hash_lock_class_key);
779 static void batadv_tt_changes_list_free(struct batadv_priv *bat_priv)
781 struct batadv_tt_change_node *entry, *safe;
783 spin_lock_bh(&bat_priv->tt.changes_list_lock);
785 list_for_each_entry_safe(entry, safe, &bat_priv->tt.changes_list,
787 list_del(&entry->list);
791 atomic_set(&bat_priv->tt.local_changes, 0);
792 spin_unlock_bh(&bat_priv->tt.changes_list_lock);
795 /* retrieves the orig_tt_list_entry belonging to orig_node from the
796 * batadv_tt_global_entry list
798 * returns it with an increased refcounter, NULL if not found
800 static struct batadv_tt_orig_list_entry *
801 batadv_tt_global_orig_entry_find(const struct batadv_tt_global_entry *entry,
802 const struct batadv_orig_node *orig_node)
804 struct batadv_tt_orig_list_entry *tmp_orig_entry, *orig_entry = NULL;
805 const struct hlist_head *head;
808 head = &entry->orig_list;
809 hlist_for_each_entry_rcu(tmp_orig_entry, head, list) {
810 if (tmp_orig_entry->orig_node != orig_node)
812 if (!atomic_inc_not_zero(&tmp_orig_entry->refcount))
815 orig_entry = tmp_orig_entry;
823 /* find out if an orig_node is already in the list of a tt_global_entry.
824 * returns true if found, false otherwise
827 batadv_tt_global_entry_has_orig(const struct batadv_tt_global_entry *entry,
828 const struct batadv_orig_node *orig_node)
830 struct batadv_tt_orig_list_entry *orig_entry;
833 orig_entry = batadv_tt_global_orig_entry_find(entry, orig_node);
836 batadv_tt_orig_list_entry_free_ref(orig_entry);
843 batadv_tt_global_orig_entry_add(struct batadv_tt_global_entry *tt_global,
844 struct batadv_orig_node *orig_node, int ttvn)
846 struct batadv_tt_orig_list_entry *orig_entry;
848 orig_entry = batadv_tt_global_orig_entry_find(tt_global, orig_node);
850 /* refresh the ttvn: the current value could be a bogus one that
851 * was added during a "temporary client detection"
853 orig_entry->ttvn = ttvn;
857 orig_entry = kzalloc(sizeof(*orig_entry), GFP_ATOMIC);
861 INIT_HLIST_NODE(&orig_entry->list);
862 atomic_inc(&orig_node->refcount);
863 atomic_inc(&orig_node->tt_size);
864 orig_entry->orig_node = orig_node;
865 orig_entry->ttvn = ttvn;
866 atomic_set(&orig_entry->refcount, 2);
868 spin_lock_bh(&tt_global->list_lock);
869 hlist_add_head_rcu(&orig_entry->list,
870 &tt_global->orig_list);
871 spin_unlock_bh(&tt_global->list_lock);
874 batadv_tt_orig_list_entry_free_ref(orig_entry);
878 * batadv_tt_global_add - add a new TT global entry or update an existing one
879 * @bat_priv: the bat priv with all the soft interface information
880 * @orig_node: the originator announcing the client
881 * @tt_addr: the mac address of the non-mesh client
882 * @vid: VLAN identifier
883 * @flags: TT flags that have to be set for this non-mesh client
884 * @ttvn: the tt version number ever announcing this non-mesh client
886 * Add a new TT global entry for the given originator. If the entry already
887 * exists add a new reference to the given originator (a global entry can have
888 * references to multiple originators) and adjust the flags attribute to reflect
889 * the function argument.
890 * If a TT local entry exists for this non-mesh client remove it.
892 * The caller must hold orig_node refcount.
894 * Return true if the new entry has been added, false otherwise
896 static bool batadv_tt_global_add(struct batadv_priv *bat_priv,
897 struct batadv_orig_node *orig_node,
898 const unsigned char *tt_addr,
899 unsigned short vid, uint16_t flags,
902 struct batadv_tt_global_entry *tt_global_entry;
903 struct batadv_tt_local_entry *tt_local_entry;
906 struct batadv_tt_common_entry *common;
907 uint16_t local_flags;
909 tt_global_entry = batadv_tt_global_hash_find(bat_priv, tt_addr, vid);
910 tt_local_entry = batadv_tt_local_hash_find(bat_priv, tt_addr, vid);
912 /* if the node already has a local client for this entry, it has to wait
913 * for a roaming advertisement instead of manually messing up the global
916 if ((flags & BATADV_TT_CLIENT_TEMP) && tt_local_entry &&
917 !(tt_local_entry->common.flags & BATADV_TT_CLIENT_NEW))
920 if (!tt_global_entry) {
921 tt_global_entry = kzalloc(sizeof(*tt_global_entry), GFP_ATOMIC);
922 if (!tt_global_entry)
925 common = &tt_global_entry->common;
926 memcpy(common->addr, tt_addr, ETH_ALEN);
929 common->flags = flags;
930 tt_global_entry->roam_at = 0;
931 /* node must store current time in case of roaming. This is
932 * needed to purge this entry out on timeout (if nobody claims
935 if (flags & BATADV_TT_CLIENT_ROAM)
936 tt_global_entry->roam_at = jiffies;
937 atomic_set(&common->refcount, 2);
938 common->added_at = jiffies;
940 INIT_HLIST_HEAD(&tt_global_entry->orig_list);
941 spin_lock_init(&tt_global_entry->list_lock);
943 hash_added = batadv_hash_add(bat_priv->tt.global_hash,
945 batadv_choose_tt, common,
946 &common->hash_entry);
948 if (unlikely(hash_added != 0)) {
949 /* remove the reference for the hash */
950 batadv_tt_global_entry_free_ref(tt_global_entry);
954 common = &tt_global_entry->common;
955 /* If there is already a global entry, we can use this one for
957 * But if we are trying to add a temporary client then here are
958 * two options at this point:
959 * 1) the global client is not a temporary client: the global
960 * client has to be left as it is, temporary information
961 * should never override any already known client state
962 * 2) the global client is a temporary client: purge the
963 * originator list and add the new one orig_entry
965 if (flags & BATADV_TT_CLIENT_TEMP) {
966 if (!(common->flags & BATADV_TT_CLIENT_TEMP))
968 if (batadv_tt_global_entry_has_orig(tt_global_entry,
971 batadv_tt_global_del_orig_list(tt_global_entry);
975 /* if the client was temporary added before receiving the first
976 * OGM announcing it, we have to clear the TEMP flag
978 common->flags &= ~BATADV_TT_CLIENT_TEMP;
980 /* the change can carry possible "attribute" flags like the
981 * TT_CLIENT_WIFI, therefore they have to be copied in the
984 tt_global_entry->common.flags |= flags;
986 /* If there is the BATADV_TT_CLIENT_ROAM flag set, there is only
987 * one originator left in the list and we previously received a
988 * delete + roaming change for this originator.
990 * We should first delete the old originator before adding the
993 if (common->flags & BATADV_TT_CLIENT_ROAM) {
994 batadv_tt_global_del_orig_list(tt_global_entry);
995 common->flags &= ~BATADV_TT_CLIENT_ROAM;
996 tt_global_entry->roam_at = 0;
1000 /* add the new orig_entry (if needed) or update it */
1001 batadv_tt_global_orig_entry_add(tt_global_entry, orig_node, ttvn);
1003 batadv_dbg(BATADV_DBG_TT, bat_priv,
1004 "Creating new global tt entry: %pM (vid: %d, via %pM)\n",
1005 common->addr, BATADV_PRINT_VID(common->vid),
1011 /* remove address from local hash if present */
1012 local_flags = batadv_tt_local_remove(bat_priv, tt_addr, vid,
1013 "global tt received",
1014 flags & BATADV_TT_CLIENT_ROAM);
1015 tt_global_entry->common.flags |= local_flags & BATADV_TT_CLIENT_WIFI;
1017 if (!(flags & BATADV_TT_CLIENT_ROAM))
1018 /* this is a normal global add. Therefore the client is not in a
1019 * roaming state anymore.
1021 tt_global_entry->common.flags &= ~BATADV_TT_CLIENT_ROAM;
1024 if (tt_global_entry)
1025 batadv_tt_global_entry_free_ref(tt_global_entry);
1027 batadv_tt_local_entry_free_ref(tt_local_entry);
1031 /* batadv_transtable_best_orig - Get best originator list entry from tt entry
1032 * @tt_global_entry: global translation table entry to be analyzed
1034 * This functon assumes the caller holds rcu_read_lock().
1035 * Returns best originator list entry or NULL on errors.
1037 static struct batadv_tt_orig_list_entry *
1038 batadv_transtable_best_orig(struct batadv_tt_global_entry *tt_global_entry)
1040 struct batadv_neigh_node *router = NULL;
1041 struct hlist_head *head;
1042 struct batadv_tt_orig_list_entry *orig_entry, *best_entry = NULL;
1045 head = &tt_global_entry->orig_list;
1046 hlist_for_each_entry_rcu(orig_entry, head, list) {
1047 router = batadv_orig_node_get_router(orig_entry->orig_node);
1051 if (router->tq_avg > best_tq) {
1052 best_entry = orig_entry;
1053 best_tq = router->tq_avg;
1056 batadv_neigh_node_free_ref(router);
1062 /* batadv_tt_global_print_entry - print all orig nodes who announce the address
1063 * for this global entry
1064 * @tt_global_entry: global translation table entry to be printed
1065 * @seq: debugfs table seq_file struct
1067 * This functon assumes the caller holds rcu_read_lock().
1070 batadv_tt_global_print_entry(struct batadv_tt_global_entry *tt_global_entry,
1071 struct seq_file *seq)
1073 struct hlist_head *head;
1074 struct batadv_tt_orig_list_entry *orig_entry, *best_entry;
1075 struct batadv_tt_common_entry *tt_common_entry;
1079 tt_common_entry = &tt_global_entry->common;
1080 flags = tt_common_entry->flags;
1082 best_entry = batadv_transtable_best_orig(tt_global_entry);
1084 last_ttvn = atomic_read(&best_entry->orig_node->last_ttvn);
1086 " %c %pM %4i (%3u) via %pM (%3u) (%#.8x) [%c%c%c]\n",
1087 '*', tt_global_entry->common.addr,
1088 BATADV_PRINT_VID(tt_global_entry->common.vid),
1089 best_entry->ttvn, best_entry->orig_node->orig,
1090 last_ttvn, best_entry->orig_node->tt_crc,
1091 (flags & BATADV_TT_CLIENT_ROAM ? 'R' : '.'),
1092 (flags & BATADV_TT_CLIENT_WIFI ? 'W' : '.'),
1093 (flags & BATADV_TT_CLIENT_TEMP ? 'T' : '.'));
1096 head = &tt_global_entry->orig_list;
1098 hlist_for_each_entry_rcu(orig_entry, head, list) {
1099 if (best_entry == orig_entry)
1102 last_ttvn = atomic_read(&orig_entry->orig_node->last_ttvn);
1104 " %c %pM %4d (%3u) via %pM (%3u) [%c%c%c]\n",
1105 '+', tt_global_entry->common.addr,
1106 BATADV_PRINT_VID(tt_global_entry->common.vid),
1107 orig_entry->ttvn, orig_entry->orig_node->orig,
1109 (flags & BATADV_TT_CLIENT_ROAM ? 'R' : '.'),
1110 (flags & BATADV_TT_CLIENT_WIFI ? 'W' : '.'),
1111 (flags & BATADV_TT_CLIENT_TEMP ? 'T' : '.'));
1115 int batadv_tt_global_seq_print_text(struct seq_file *seq, void *offset)
1117 struct net_device *net_dev = (struct net_device *)seq->private;
1118 struct batadv_priv *bat_priv = netdev_priv(net_dev);
1119 struct batadv_hashtable *hash = bat_priv->tt.global_hash;
1120 struct batadv_tt_common_entry *tt_common_entry;
1121 struct batadv_tt_global_entry *tt_global;
1122 struct batadv_hard_iface *primary_if;
1123 struct hlist_head *head;
1126 primary_if = batadv_seq_print_text_primary_if_get(seq);
1131 "Globally announced TT entries received via the mesh %s\n",
1133 seq_printf(seq, " %-13s %s %s %-15s %s (%-10s) %s\n",
1134 "Client", "VID", "(TTVN)", "Originator", "(Curr TTVN)",
1137 for (i = 0; i < hash->size; i++) {
1138 head = &hash->table[i];
1141 hlist_for_each_entry_rcu(tt_common_entry,
1143 tt_global = container_of(tt_common_entry,
1144 struct batadv_tt_global_entry,
1146 batadv_tt_global_print_entry(tt_global, seq);
1152 batadv_hardif_free_ref(primary_if);
1156 /* deletes the orig list of a tt_global_entry */
1158 batadv_tt_global_del_orig_list(struct batadv_tt_global_entry *tt_global_entry)
1160 struct hlist_head *head;
1161 struct hlist_node *safe;
1162 struct batadv_tt_orig_list_entry *orig_entry;
1164 spin_lock_bh(&tt_global_entry->list_lock);
1165 head = &tt_global_entry->orig_list;
1166 hlist_for_each_entry_safe(orig_entry, safe, head, list) {
1167 hlist_del_rcu(&orig_entry->list);
1168 batadv_tt_orig_list_entry_free_ref(orig_entry);
1170 spin_unlock_bh(&tt_global_entry->list_lock);
1174 batadv_tt_global_del_orig_entry(struct batadv_priv *bat_priv,
1175 struct batadv_tt_global_entry *tt_global_entry,
1176 struct batadv_orig_node *orig_node,
1177 const char *message)
1179 struct hlist_head *head;
1180 struct hlist_node *safe;
1181 struct batadv_tt_orig_list_entry *orig_entry;
1184 spin_lock_bh(&tt_global_entry->list_lock);
1185 head = &tt_global_entry->orig_list;
1186 hlist_for_each_entry_safe(orig_entry, safe, head, list) {
1187 if (orig_entry->orig_node == orig_node) {
1188 vid = tt_global_entry->common.vid;
1189 batadv_dbg(BATADV_DBG_TT, bat_priv,
1190 "Deleting %pM from global tt entry %pM (vid: %d): %s\n",
1192 tt_global_entry->common.addr,
1193 BATADV_PRINT_VID(vid), message);
1194 hlist_del_rcu(&orig_entry->list);
1195 batadv_tt_orig_list_entry_free_ref(orig_entry);
1198 spin_unlock_bh(&tt_global_entry->list_lock);
1201 /* If the client is to be deleted, we check if it is the last origantor entry
1202 * within tt_global entry. If yes, we set the BATADV_TT_CLIENT_ROAM flag and the
1203 * timer, otherwise we simply remove the originator scheduled for deletion.
1206 batadv_tt_global_del_roaming(struct batadv_priv *bat_priv,
1207 struct batadv_tt_global_entry *tt_global_entry,
1208 struct batadv_orig_node *orig_node,
1209 const char *message)
1211 bool last_entry = true;
1212 struct hlist_head *head;
1213 struct batadv_tt_orig_list_entry *orig_entry;
1215 /* no local entry exists, case 1:
1216 * Check if this is the last one or if other entries exist.
1220 head = &tt_global_entry->orig_list;
1221 hlist_for_each_entry_rcu(orig_entry, head, list) {
1222 if (orig_entry->orig_node != orig_node) {
1230 /* its the last one, mark for roaming. */
1231 tt_global_entry->common.flags |= BATADV_TT_CLIENT_ROAM;
1232 tt_global_entry->roam_at = jiffies;
1234 /* there is another entry, we can simply delete this
1235 * one and can still use the other one.
1237 batadv_tt_global_del_orig_entry(bat_priv, tt_global_entry,
1238 orig_node, message);
1242 * batadv_tt_global_del - remove a client from the global table
1243 * @bat_priv: the bat priv with all the soft interface information
1244 * @orig_node: an originator serving this client
1245 * @addr: the mac address of the client
1246 * @vid: VLAN identifier
1247 * @message: a message explaining the reason for deleting the client to print
1248 * for debugging purpose
1249 * @roaming: true if the deletion has been triggered by a roaming event
1251 static void batadv_tt_global_del(struct batadv_priv *bat_priv,
1252 struct batadv_orig_node *orig_node,
1253 const unsigned char *addr, unsigned short vid,
1254 const char *message, bool roaming)
1256 struct batadv_tt_global_entry *tt_global_entry;
1257 struct batadv_tt_local_entry *local_entry = NULL;
1259 tt_global_entry = batadv_tt_global_hash_find(bat_priv, addr, vid);
1260 if (!tt_global_entry)
1264 batadv_tt_global_del_orig_entry(bat_priv, tt_global_entry,
1265 orig_node, message);
1267 if (hlist_empty(&tt_global_entry->orig_list))
1268 batadv_tt_global_free(bat_priv, tt_global_entry,
1274 /* if we are deleting a global entry due to a roam
1275 * event, there are two possibilities:
1276 * 1) the client roamed from node A to node B => if there
1277 * is only one originator left for this client, we mark
1278 * it with BATADV_TT_CLIENT_ROAM, we start a timer and we
1279 * wait for node B to claim it. In case of timeout
1280 * the entry is purged.
1282 * If there are other originators left, we directly delete
1284 * 2) the client roamed to us => we can directly delete
1285 * the global entry, since it is useless now.
1287 local_entry = batadv_tt_local_hash_find(bat_priv,
1288 tt_global_entry->common.addr,
1291 /* local entry exists, case 2: client roamed to us. */
1292 batadv_tt_global_del_orig_list(tt_global_entry);
1293 batadv_tt_global_free(bat_priv, tt_global_entry, message);
1295 /* no local entry exists, case 1: check for roaming */
1296 batadv_tt_global_del_roaming(bat_priv, tt_global_entry,
1297 orig_node, message);
1301 if (tt_global_entry)
1302 batadv_tt_global_entry_free_ref(tt_global_entry);
1304 batadv_tt_local_entry_free_ref(local_entry);
1307 void batadv_tt_global_del_orig(struct batadv_priv *bat_priv,
1308 struct batadv_orig_node *orig_node,
1309 const char *message)
1311 struct batadv_tt_global_entry *tt_global;
1312 struct batadv_tt_common_entry *tt_common_entry;
1314 struct batadv_hashtable *hash = bat_priv->tt.global_hash;
1315 struct hlist_node *safe;
1316 struct hlist_head *head;
1317 spinlock_t *list_lock; /* protects write access to the hash lists */
1323 for (i = 0; i < hash->size; i++) {
1324 head = &hash->table[i];
1325 list_lock = &hash->list_locks[i];
1327 spin_lock_bh(list_lock);
1328 hlist_for_each_entry_safe(tt_common_entry, safe,
1330 tt_global = container_of(tt_common_entry,
1331 struct batadv_tt_global_entry,
1334 batadv_tt_global_del_orig_entry(bat_priv, tt_global,
1335 orig_node, message);
1337 if (hlist_empty(&tt_global->orig_list)) {
1338 vid = tt_global->common.vid;
1339 batadv_dbg(BATADV_DBG_TT, bat_priv,
1340 "Deleting global tt entry %pM (vid: %d): %s\n",
1341 tt_global->common.addr,
1342 BATADV_PRINT_VID(vid), message);
1343 hlist_del_rcu(&tt_common_entry->hash_entry);
1344 batadv_tt_global_entry_free_ref(tt_global);
1347 spin_unlock_bh(list_lock);
1349 orig_node->tt_initialised = false;
1352 static bool batadv_tt_global_to_purge(struct batadv_tt_global_entry *tt_global,
1356 unsigned long roam_timeout = BATADV_TT_CLIENT_ROAM_TIMEOUT;
1357 unsigned long temp_timeout = BATADV_TT_CLIENT_TEMP_TIMEOUT;
1359 if ((tt_global->common.flags & BATADV_TT_CLIENT_ROAM) &&
1360 batadv_has_timed_out(tt_global->roam_at, roam_timeout)) {
1362 *msg = "Roaming timeout\n";
1365 if ((tt_global->common.flags & BATADV_TT_CLIENT_TEMP) &&
1366 batadv_has_timed_out(tt_global->common.added_at, temp_timeout)) {
1368 *msg = "Temporary client timeout\n";
1374 static void batadv_tt_global_purge(struct batadv_priv *bat_priv)
1376 struct batadv_hashtable *hash = bat_priv->tt.global_hash;
1377 struct hlist_head *head;
1378 struct hlist_node *node_tmp;
1379 spinlock_t *list_lock; /* protects write access to the hash lists */
1382 struct batadv_tt_common_entry *tt_common;
1383 struct batadv_tt_global_entry *tt_global;
1385 for (i = 0; i < hash->size; i++) {
1386 head = &hash->table[i];
1387 list_lock = &hash->list_locks[i];
1389 spin_lock_bh(list_lock);
1390 hlist_for_each_entry_safe(tt_common, node_tmp, head,
1392 tt_global = container_of(tt_common,
1393 struct batadv_tt_global_entry,
1396 if (!batadv_tt_global_to_purge(tt_global, &msg))
1399 batadv_dbg(BATADV_DBG_TT, bat_priv,
1400 "Deleting global tt entry %pM (vid: %d): %s\n",
1401 tt_global->common.addr,
1402 BATADV_PRINT_VID(tt_global->common.vid),
1405 hlist_del_rcu(&tt_common->hash_entry);
1407 batadv_tt_global_entry_free_ref(tt_global);
1409 spin_unlock_bh(list_lock);
1413 static void batadv_tt_global_table_free(struct batadv_priv *bat_priv)
1415 struct batadv_hashtable *hash;
1416 spinlock_t *list_lock; /* protects write access to the hash lists */
1417 struct batadv_tt_common_entry *tt_common_entry;
1418 struct batadv_tt_global_entry *tt_global;
1419 struct hlist_node *node_tmp;
1420 struct hlist_head *head;
1423 if (!bat_priv->tt.global_hash)
1426 hash = bat_priv->tt.global_hash;
1428 for (i = 0; i < hash->size; i++) {
1429 head = &hash->table[i];
1430 list_lock = &hash->list_locks[i];
1432 spin_lock_bh(list_lock);
1433 hlist_for_each_entry_safe(tt_common_entry, node_tmp,
1435 hlist_del_rcu(&tt_common_entry->hash_entry);
1436 tt_global = container_of(tt_common_entry,
1437 struct batadv_tt_global_entry,
1439 batadv_tt_global_entry_free_ref(tt_global);
1441 spin_unlock_bh(list_lock);
1444 batadv_hash_destroy(hash);
1446 bat_priv->tt.global_hash = NULL;
1450 _batadv_is_ap_isolated(struct batadv_tt_local_entry *tt_local_entry,
1451 struct batadv_tt_global_entry *tt_global_entry)
1455 if (tt_local_entry->common.flags & BATADV_TT_CLIENT_WIFI &&
1456 tt_global_entry->common.flags & BATADV_TT_CLIENT_WIFI)
1463 * batadv_transtable_search - get the mesh destination for a given client
1464 * @bat_priv: the bat priv with all the soft interface information
1465 * @src: mac address of the source client
1466 * @addr: mac address of the destination client
1467 * @vid: VLAN identifier
1469 * Returns a pointer to the originator that was selected as destination in the
1470 * mesh for contacting the client 'addr', NULL otherwise.
1471 * In case of multiple originators serving the same client, the function returns
1472 * the best one (best in terms of metric towards the destination node).
1474 * If the two clients are AP isolated the function returns NULL.
1476 struct batadv_orig_node *batadv_transtable_search(struct batadv_priv *bat_priv,
1478 const uint8_t *addr,
1481 struct batadv_tt_local_entry *tt_local_entry = NULL;
1482 struct batadv_tt_global_entry *tt_global_entry = NULL;
1483 struct batadv_orig_node *orig_node = NULL;
1484 struct batadv_tt_orig_list_entry *best_entry;
1485 bool ap_isolation_enabled = false;
1486 struct batadv_softif_vlan *vlan;
1488 /* if the AP isolation is requested on a VLAN, then check for its
1489 * setting in the proper VLAN private data structure
1491 vlan = batadv_softif_vlan_get(bat_priv, vid);
1493 ap_isolation_enabled = atomic_read(&vlan->ap_isolation);
1494 batadv_softif_vlan_free_ref(vlan);
1497 if (src && ap_isolation_enabled) {
1498 tt_local_entry = batadv_tt_local_hash_find(bat_priv, src, vid);
1499 if (!tt_local_entry ||
1500 (tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING))
1504 tt_global_entry = batadv_tt_global_hash_find(bat_priv, addr, vid);
1505 if (!tt_global_entry)
1508 /* check whether the clients should not communicate due to AP
1511 if (tt_local_entry &&
1512 _batadv_is_ap_isolated(tt_local_entry, tt_global_entry))
1516 best_entry = batadv_transtable_best_orig(tt_global_entry);
1517 /* found anything? */
1519 orig_node = best_entry->orig_node;
1520 if (orig_node && !atomic_inc_not_zero(&orig_node->refcount))
1525 if (tt_global_entry)
1526 batadv_tt_global_entry_free_ref(tt_global_entry);
1528 batadv_tt_local_entry_free_ref(tt_local_entry);
1534 * batadv_tt_global_crc - calculates the checksum of the local table belonging
1535 * to the given orig_node
1536 * @bat_priv: the bat priv with all the soft interface information
1537 * @orig_node: originator for which the CRC should be computed
1539 * This function computes the checksum for the global table corresponding to a
1540 * specific originator. In particular, the checksum is computed as follows: For
1541 * each client connected to the originator the CRC32C of the MAC address and the
1542 * VID is computed and then all the CRC32Cs of the various clients are xor'ed
1545 * The idea behind is that CRC32C should be used as much as possible in order to
1546 * produce a unique hash of the table, but since the order which is used to feed
1547 * the CRC32C function affects the result and since every node in the network
1548 * probably sorts the clients differently, the hash function cannot be directly
1549 * computed over the entire table. Hence the CRC32C is used only on
1550 * the single client entry, while all the results are then xor'ed together
1551 * because the XOR operation can combine them all while trying to reduce the
1552 * noise as much as possible.
1554 * Returns the checksum of the global table of a given originator.
1556 static uint32_t batadv_tt_global_crc(struct batadv_priv *bat_priv,
1557 struct batadv_orig_node *orig_node)
1559 struct batadv_hashtable *hash = bat_priv->tt.global_hash;
1560 struct batadv_tt_common_entry *tt_common;
1561 struct batadv_tt_global_entry *tt_global;
1562 struct hlist_head *head;
1563 uint32_t i, crc_tmp, crc = 0;
1565 for (i = 0; i < hash->size; i++) {
1566 head = &hash->table[i];
1569 hlist_for_each_entry_rcu(tt_common, head, hash_entry) {
1570 tt_global = container_of(tt_common,
1571 struct batadv_tt_global_entry,
1573 /* Roaming clients are in the global table for
1574 * consistency only. They don't have to be
1575 * taken into account while computing the
1578 if (tt_common->flags & BATADV_TT_CLIENT_ROAM)
1580 /* Temporary clients have not been announced yet, so
1581 * they have to be skipped while computing the global
1584 if (tt_common->flags & BATADV_TT_CLIENT_TEMP)
1587 /* find out if this global entry is announced by this
1590 if (!batadv_tt_global_entry_has_orig(tt_global,
1594 crc_tmp = crc32c(0, &tt_common->vid,
1595 sizeof(tt_common->vid));
1596 crc ^= crc32c(crc_tmp, tt_common->addr, ETH_ALEN);
1605 * batadv_tt_local_crc - calculates the checksum of the local table
1606 * @bat_priv: the bat priv with all the soft interface information
1608 * For details about the computation, please refer to the documentation for
1609 * batadv_tt_global_crc().
1611 * Returns the checksum of the local table
1613 static uint32_t batadv_tt_local_crc(struct batadv_priv *bat_priv)
1615 struct batadv_hashtable *hash = bat_priv->tt.local_hash;
1616 struct batadv_tt_common_entry *tt_common;
1617 struct hlist_head *head;
1618 uint32_t i, crc_tmp, crc = 0;
1620 for (i = 0; i < hash->size; i++) {
1621 head = &hash->table[i];
1624 hlist_for_each_entry_rcu(tt_common, head, hash_entry) {
1625 /* not yet committed clients have not to be taken into
1626 * account while computing the CRC
1628 if (tt_common->flags & BATADV_TT_CLIENT_NEW)
1631 crc_tmp = crc32c(0, &tt_common->vid,
1632 sizeof(tt_common->vid));
1633 crc ^= crc32c(crc_tmp, tt_common->addr, ETH_ALEN);
1641 static void batadv_tt_req_list_free(struct batadv_priv *bat_priv)
1643 struct batadv_tt_req_node *node, *safe;
1645 spin_lock_bh(&bat_priv->tt.req_list_lock);
1647 list_for_each_entry_safe(node, safe, &bat_priv->tt.req_list, list) {
1648 list_del(&node->list);
1652 spin_unlock_bh(&bat_priv->tt.req_list_lock);
1655 static void batadv_tt_save_orig_buffer(struct batadv_priv *bat_priv,
1656 struct batadv_orig_node *orig_node,
1657 const void *tt_buff,
1658 uint16_t tt_buff_len)
1660 /* Replace the old buffer only if I received something in the
1661 * last OGM (the OGM could carry no changes)
1663 spin_lock_bh(&orig_node->tt_buff_lock);
1664 if (tt_buff_len > 0) {
1665 kfree(orig_node->tt_buff);
1666 orig_node->tt_buff_len = 0;
1667 orig_node->tt_buff = kmalloc(tt_buff_len, GFP_ATOMIC);
1668 if (orig_node->tt_buff) {
1669 memcpy(orig_node->tt_buff, tt_buff, tt_buff_len);
1670 orig_node->tt_buff_len = tt_buff_len;
1673 spin_unlock_bh(&orig_node->tt_buff_lock);
1676 static void batadv_tt_req_purge(struct batadv_priv *bat_priv)
1678 struct batadv_tt_req_node *node, *safe;
1680 spin_lock_bh(&bat_priv->tt.req_list_lock);
1681 list_for_each_entry_safe(node, safe, &bat_priv->tt.req_list, list) {
1682 if (batadv_has_timed_out(node->issued_at,
1683 BATADV_TT_REQUEST_TIMEOUT)) {
1684 list_del(&node->list);
1688 spin_unlock_bh(&bat_priv->tt.req_list_lock);
1691 /* returns the pointer to the new tt_req_node struct if no request
1692 * has already been issued for this orig_node, NULL otherwise
1694 static struct batadv_tt_req_node *
1695 batadv_new_tt_req_node(struct batadv_priv *bat_priv,
1696 struct batadv_orig_node *orig_node)
1698 struct batadv_tt_req_node *tt_req_node_tmp, *tt_req_node = NULL;
1700 spin_lock_bh(&bat_priv->tt.req_list_lock);
1701 list_for_each_entry(tt_req_node_tmp, &bat_priv->tt.req_list, list) {
1702 if (batadv_compare_eth(tt_req_node_tmp, orig_node) &&
1703 !batadv_has_timed_out(tt_req_node_tmp->issued_at,
1704 BATADV_TT_REQUEST_TIMEOUT))
1708 tt_req_node = kmalloc(sizeof(*tt_req_node), GFP_ATOMIC);
1712 memcpy(tt_req_node->addr, orig_node->orig, ETH_ALEN);
1713 tt_req_node->issued_at = jiffies;
1715 list_add(&tt_req_node->list, &bat_priv->tt.req_list);
1717 spin_unlock_bh(&bat_priv->tt.req_list_lock);
1722 * batadv_tt_local_valid - verify that given tt entry is a valid one
1723 * @entry_ptr: to be checked local tt entry
1724 * @data_ptr: not used but definition required to satisfy the callback prototype
1726 * Returns 1 if the entry is a valid, 0 otherwise.
1728 static int batadv_tt_local_valid(const void *entry_ptr, const void *data_ptr)
1730 const struct batadv_tt_common_entry *tt_common_entry = entry_ptr;
1732 if (tt_common_entry->flags & BATADV_TT_CLIENT_NEW)
1737 static int batadv_tt_global_valid(const void *entry_ptr,
1738 const void *data_ptr)
1740 const struct batadv_tt_common_entry *tt_common_entry = entry_ptr;
1741 const struct batadv_tt_global_entry *tt_global_entry;
1742 const struct batadv_orig_node *orig_node = data_ptr;
1744 if (tt_common_entry->flags & BATADV_TT_CLIENT_ROAM ||
1745 tt_common_entry->flags & BATADV_TT_CLIENT_TEMP)
1748 tt_global_entry = container_of(tt_common_entry,
1749 struct batadv_tt_global_entry,
1752 return batadv_tt_global_entry_has_orig(tt_global_entry, orig_node);
1756 * batadv_tt_tvlv_generate - creates tvlv tt data buffer to fill it with the
1757 * tt entries from the specified tt hash
1758 * @bat_priv: the bat priv with all the soft interface information
1759 * @hash: hash table containing the tt entries
1760 * @tt_len: expected tvlv tt data buffer length in number of bytes
1761 * @valid_cb: function to filter tt change entries
1762 * @cb_data: data passed to the filter function as argument
1764 * Returns pointer to allocated tvlv tt data buffer if operation was
1765 * successful or NULL otherwise.
1767 static struct batadv_tvlv_tt_data *
1768 batadv_tt_tvlv_generate(struct batadv_priv *bat_priv,
1769 struct batadv_hashtable *hash, uint16_t tt_len,
1770 int (*valid_cb)(const void *, const void *),
1773 struct batadv_tt_common_entry *tt_common_entry;
1774 struct batadv_tvlv_tt_data *tvlv_tt_data = NULL;
1775 struct batadv_tvlv_tt_change *tt_change;
1776 struct hlist_head *head;
1777 uint16_t tt_tot, tt_num_entries = 0;
1778 ssize_t tvlv_tt_size = sizeof(struct batadv_tvlv_tt_data);
1781 if (tvlv_tt_size + tt_len > bat_priv->soft_iface->mtu) {
1782 tt_len = bat_priv->soft_iface->mtu - tvlv_tt_size;
1783 tt_len -= tt_len % sizeof(struct batadv_tvlv_tt_change);
1786 tt_tot = batadv_tt_entries(tt_len);
1788 tvlv_tt_data = kzalloc(sizeof(*tvlv_tt_data) + tt_len,
1793 tt_change = (struct batadv_tvlv_tt_change *)(tvlv_tt_data + 1);
1796 for (i = 0; i < hash->size; i++) {
1797 head = &hash->table[i];
1799 hlist_for_each_entry_rcu(tt_common_entry,
1801 if (tt_tot == tt_num_entries)
1804 if ((valid_cb) && (!valid_cb(tt_common_entry, cb_data)))
1807 memcpy(tt_change->addr, tt_common_entry->addr,
1809 tt_change->flags = tt_common_entry->flags;
1810 tt_change->vid = htons(tt_common_entry->vid);
1811 tt_change->reserved = 0;
1820 return tvlv_tt_data;
1824 * batadv_send_tt_request - send a TT Request message to a given node
1825 * @bat_priv: the bat priv with all the soft interface information
1826 * @dst_orig_node: the destination of the message
1827 * @ttvn: the version number that the source of the message is looking for
1828 * @tt_crc: the CRC associated with the version number
1829 * @full_table: ask for the entire translation table if true, while only for the
1830 * last TT diff otherwise
1832 static int batadv_send_tt_request(struct batadv_priv *bat_priv,
1833 struct batadv_orig_node *dst_orig_node,
1834 uint8_t ttvn, uint32_t tt_crc,
1837 struct batadv_tvlv_tt_data *tvlv_tt_data = NULL;
1838 struct batadv_hard_iface *primary_if;
1839 struct batadv_tt_req_node *tt_req_node = NULL;
1842 primary_if = batadv_primary_if_get_selected(bat_priv);
1846 /* The new tt_req will be issued only if I'm not waiting for a
1847 * reply from the same orig_node yet
1849 tt_req_node = batadv_new_tt_req_node(bat_priv, dst_orig_node);
1853 tvlv_tt_data = kzalloc(sizeof(*tvlv_tt_data), GFP_ATOMIC);
1857 tvlv_tt_data->flags = BATADV_TT_REQUEST;
1858 tvlv_tt_data->ttvn = ttvn;
1859 tvlv_tt_data->crc = htonl(tt_crc);
1862 tvlv_tt_data->flags |= BATADV_TT_FULL_TABLE;
1864 batadv_dbg(BATADV_DBG_TT, bat_priv, "Sending TT_REQUEST to %pM [%c]\n",
1865 dst_orig_node->orig, full_table ? 'F' : '.');
1867 batadv_inc_counter(bat_priv, BATADV_CNT_TT_REQUEST_TX);
1868 batadv_tvlv_unicast_send(bat_priv, primary_if->net_dev->dev_addr,
1869 dst_orig_node->orig, BATADV_TVLV_TT, 1,
1870 tvlv_tt_data, sizeof(*tvlv_tt_data));
1875 batadv_hardif_free_ref(primary_if);
1876 if (ret && tt_req_node) {
1877 spin_lock_bh(&bat_priv->tt.req_list_lock);
1878 list_del(&tt_req_node->list);
1879 spin_unlock_bh(&bat_priv->tt.req_list_lock);
1882 kfree(tvlv_tt_data);
1887 * batadv_send_other_tt_response - send reply to tt request concerning another
1888 * node's translation table
1889 * @bat_priv: the bat priv with all the soft interface information
1890 * @tt_data: tt data containing the tt request information
1891 * @req_src: mac address of tt request sender
1892 * @req_dst: mac address of tt request recipient
1894 * Returns true if tt request reply was sent, false otherwise.
1896 static bool batadv_send_other_tt_response(struct batadv_priv *bat_priv,
1897 struct batadv_tvlv_tt_data *tt_data,
1898 uint8_t *req_src, uint8_t *req_dst)
1900 struct batadv_orig_node *req_dst_orig_node;
1901 struct batadv_orig_node *res_dst_orig_node = NULL;
1902 struct batadv_tvlv_tt_data *tvlv_tt_data = NULL;
1903 uint8_t orig_ttvn, req_ttvn;
1905 bool ret = false, full_table;
1907 batadv_dbg(BATADV_DBG_TT, bat_priv,
1908 "Received TT_REQUEST from %pM for ttvn: %u (%pM) [%c]\n",
1909 req_src, tt_data->ttvn, req_dst,
1910 (tt_data->flags & BATADV_TT_FULL_TABLE ? 'F' : '.'));
1912 /* Let's get the orig node of the REAL destination */
1913 req_dst_orig_node = batadv_orig_hash_find(bat_priv, req_dst);
1914 if (!req_dst_orig_node)
1917 res_dst_orig_node = batadv_orig_hash_find(bat_priv, req_src);
1918 if (!res_dst_orig_node)
1921 orig_ttvn = (uint8_t)atomic_read(&req_dst_orig_node->last_ttvn);
1922 req_ttvn = tt_data->ttvn;
1924 /* this node doesn't have the requested data */
1925 if (orig_ttvn != req_ttvn ||
1926 tt_data->crc != htonl(req_dst_orig_node->tt_crc))
1929 /* If the full table has been explicitly requested */
1930 if (tt_data->flags & BATADV_TT_FULL_TABLE ||
1931 !req_dst_orig_node->tt_buff)
1936 /* TT fragmentation hasn't been implemented yet, so send as many
1937 * TT entries fit a single packet as possible only
1940 spin_lock_bh(&req_dst_orig_node->tt_buff_lock);
1941 tt_len = req_dst_orig_node->tt_buff_len;
1943 tvlv_tt_data = kzalloc(sizeof(*tvlv_tt_data) + tt_len,
1948 /* Copy the last orig_node's OGM buffer */
1949 memcpy(tvlv_tt_data + 1, req_dst_orig_node->tt_buff,
1950 req_dst_orig_node->tt_buff_len);
1951 spin_unlock_bh(&req_dst_orig_node->tt_buff_lock);
1953 tt_len = (uint16_t)atomic_read(&req_dst_orig_node->tt_size);
1954 tt_len = batadv_tt_len(tt_len);
1956 tvlv_tt_data = batadv_tt_tvlv_generate(bat_priv,
1957 bat_priv->tt.global_hash,
1959 batadv_tt_global_valid,
1965 tvlv_tt_data->flags = BATADV_TT_RESPONSE;
1966 tvlv_tt_data->ttvn = req_ttvn;
1969 tvlv_tt_data->flags |= BATADV_TT_FULL_TABLE;
1971 batadv_dbg(BATADV_DBG_TT, bat_priv,
1972 "Sending TT_RESPONSE %pM for %pM [%c] (ttvn: %u)\n",
1973 res_dst_orig_node->orig, req_dst_orig_node->orig,
1974 full_table ? 'F' : '.', req_ttvn);
1976 batadv_inc_counter(bat_priv, BATADV_CNT_TT_RESPONSE_TX);
1978 batadv_tvlv_unicast_send(bat_priv, req_dst_orig_node->orig,
1979 req_src, BATADV_TVLV_TT, 1,
1980 tvlv_tt_data, sizeof(*tvlv_tt_data) + tt_len);
1986 spin_unlock_bh(&req_dst_orig_node->tt_buff_lock);
1989 if (res_dst_orig_node)
1990 batadv_orig_node_free_ref(res_dst_orig_node);
1991 if (req_dst_orig_node)
1992 batadv_orig_node_free_ref(req_dst_orig_node);
1993 kfree(tvlv_tt_data);
1998 * batadv_send_my_tt_response - send reply to tt request concerning this node's
2000 * @bat_priv: the bat priv with all the soft interface information
2001 * @tt_data: tt data containing the tt request information
2002 * @req_src: mac address of tt request sender
2004 * Returns true if tt request reply was sent, false otherwise.
2006 static bool batadv_send_my_tt_response(struct batadv_priv *bat_priv,
2007 struct batadv_tvlv_tt_data *tt_data,
2010 struct batadv_tvlv_tt_data *tvlv_tt_data = NULL;
2011 struct batadv_orig_node *orig_node;
2012 struct batadv_hard_iface *primary_if = NULL;
2013 uint8_t my_ttvn, req_ttvn;
2017 batadv_dbg(BATADV_DBG_TT, bat_priv,
2018 "Received TT_REQUEST from %pM for ttvn: %u (me) [%c]\n",
2019 req_src, tt_data->ttvn,
2020 (tt_data->flags & BATADV_TT_FULL_TABLE ? 'F' : '.'));
2023 my_ttvn = (uint8_t)atomic_read(&bat_priv->tt.vn);
2024 req_ttvn = tt_data->ttvn;
2026 orig_node = batadv_orig_hash_find(bat_priv, req_src);
2030 primary_if = batadv_primary_if_get_selected(bat_priv);
2034 /* If the full table has been explicitly requested or the gap
2035 * is too big send the whole local translation table
2037 if (tt_data->flags & BATADV_TT_FULL_TABLE || my_ttvn != req_ttvn ||
2038 !bat_priv->tt.last_changeset)
2043 /* TT fragmentation hasn't been implemented yet, so send as many
2044 * TT entries fit a single packet as possible only
2047 spin_lock_bh(&bat_priv->tt.last_changeset_lock);
2048 tt_len = bat_priv->tt.last_changeset_len;
2050 tvlv_tt_data = kzalloc(sizeof(*tvlv_tt_data) + tt_len,
2055 /* Copy the last orig_node's OGM buffer */
2056 memcpy(tvlv_tt_data + 1, bat_priv->tt.last_changeset,
2057 bat_priv->tt.last_changeset_len);
2058 spin_unlock_bh(&bat_priv->tt.last_changeset_lock);
2060 tt_len = (uint16_t)atomic_read(&bat_priv->tt.local_entry_num);
2061 tt_len = batadv_tt_len(tt_len);
2062 req_ttvn = (uint8_t)atomic_read(&bat_priv->tt.vn);
2064 tvlv_tt_data = batadv_tt_tvlv_generate(bat_priv,
2065 bat_priv->tt.local_hash,
2067 batadv_tt_local_valid,
2073 tvlv_tt_data->flags = BATADV_TT_RESPONSE;
2074 tvlv_tt_data->ttvn = req_ttvn;
2077 tvlv_tt_data->flags |= BATADV_TT_FULL_TABLE;
2079 batadv_dbg(BATADV_DBG_TT, bat_priv,
2080 "Sending TT_RESPONSE to %pM [%c] (ttvn: %u)\n",
2081 orig_node->orig, full_table ? 'F' : '.', req_ttvn);
2083 batadv_inc_counter(bat_priv, BATADV_CNT_TT_RESPONSE_TX);
2085 batadv_tvlv_unicast_send(bat_priv, primary_if->net_dev->dev_addr,
2086 req_src, BATADV_TVLV_TT, 1,
2087 tvlv_tt_data, sizeof(*tvlv_tt_data) + tt_len);
2092 spin_unlock_bh(&bat_priv->tt.last_changeset_lock);
2095 batadv_orig_node_free_ref(orig_node);
2097 batadv_hardif_free_ref(primary_if);
2098 kfree(tvlv_tt_data);
2099 /* The packet was for this host, so it doesn't need to be re-routed */
2104 * batadv_send_tt_response - send reply to tt request
2105 * @bat_priv: the bat priv with all the soft interface information
2106 * @tt_data: tt data containing the tt request information
2107 * @req_src: mac address of tt request sender
2108 * @req_dst: mac address of tt request recipient
2110 * Returns true if tt request reply was sent, false otherwise.
2112 static bool batadv_send_tt_response(struct batadv_priv *bat_priv,
2113 struct batadv_tvlv_tt_data *tt_data,
2114 uint8_t *req_src, uint8_t *req_dst)
2116 if (batadv_is_my_mac(bat_priv, req_dst)) {
2117 /* don't answer backbone gws! */
2118 if (batadv_bla_is_backbone_gw_orig(bat_priv, req_src))
2121 return batadv_send_my_tt_response(bat_priv, tt_data, req_src);
2123 return batadv_send_other_tt_response(bat_priv, tt_data,
2128 static void _batadv_tt_update_changes(struct batadv_priv *bat_priv,
2129 struct batadv_orig_node *orig_node,
2130 struct batadv_tvlv_tt_change *tt_change,
2131 uint16_t tt_num_changes, uint8_t ttvn)
2136 for (i = 0; i < tt_num_changes; i++) {
2137 if ((tt_change + i)->flags & BATADV_TT_CLIENT_DEL) {
2138 roams = (tt_change + i)->flags & BATADV_TT_CLIENT_ROAM;
2139 batadv_tt_global_del(bat_priv, orig_node,
2140 (tt_change + i)->addr,
2141 ntohs((tt_change + i)->vid),
2142 "tt removed by changes",
2145 if (!batadv_tt_global_add(bat_priv, orig_node,
2146 (tt_change + i)->addr,
2147 ntohs((tt_change + i)->vid),
2148 (tt_change + i)->flags, ttvn))
2149 /* In case of problem while storing a
2150 * global_entry, we stop the updating
2151 * procedure without committing the
2152 * ttvn change. This will avoid to send
2153 * corrupted data on tt_request
2158 orig_node->tt_initialised = true;
2161 static void batadv_tt_fill_gtable(struct batadv_priv *bat_priv,
2162 struct batadv_tvlv_tt_data *tt_data,
2163 uint8_t *resp_src, uint16_t num_entries)
2165 struct batadv_orig_node *orig_node;
2167 orig_node = batadv_orig_hash_find(bat_priv, resp_src);
2171 /* Purge the old table first.. */
2172 batadv_tt_global_del_orig(bat_priv, orig_node, "Received full table");
2174 _batadv_tt_update_changes(bat_priv, orig_node,
2175 (struct batadv_tvlv_tt_change *)(tt_data + 1),
2176 num_entries, tt_data->ttvn);
2178 spin_lock_bh(&orig_node->tt_buff_lock);
2179 kfree(orig_node->tt_buff);
2180 orig_node->tt_buff_len = 0;
2181 orig_node->tt_buff = NULL;
2182 spin_unlock_bh(&orig_node->tt_buff_lock);
2184 atomic_set(&orig_node->last_ttvn, tt_data->ttvn);
2188 batadv_orig_node_free_ref(orig_node);
2191 static void batadv_tt_update_changes(struct batadv_priv *bat_priv,
2192 struct batadv_orig_node *orig_node,
2193 uint16_t tt_num_changes, uint8_t ttvn,
2194 struct batadv_tvlv_tt_change *tt_change)
2196 _batadv_tt_update_changes(bat_priv, orig_node, tt_change,
2197 tt_num_changes, ttvn);
2199 batadv_tt_save_orig_buffer(bat_priv, orig_node, tt_change,
2200 batadv_tt_len(tt_num_changes));
2201 atomic_set(&orig_node->last_ttvn, ttvn);
2205 * batadv_is_my_client - check if a client is served by the local node
2206 * @bat_priv: the bat priv with all the soft interface information
2207 * @addr: the mac adress of the client to check
2208 * @vid: VLAN identifier
2210 * Returns true if the client is served by this node, false otherwise.
2212 bool batadv_is_my_client(struct batadv_priv *bat_priv, const uint8_t *addr,
2215 struct batadv_tt_local_entry *tt_local_entry;
2218 tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr, vid);
2219 if (!tt_local_entry)
2221 /* Check if the client has been logically deleted (but is kept for
2222 * consistency purpose)
2224 if ((tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING) ||
2225 (tt_local_entry->common.flags & BATADV_TT_CLIENT_ROAM))
2230 batadv_tt_local_entry_free_ref(tt_local_entry);
2235 * batadv_handle_tt_response - process incoming tt reply
2236 * @bat_priv: the bat priv with all the soft interface information
2237 * @tt_data: tt data containing the tt request information
2238 * @resp_src: mac address of tt reply sender
2239 * @num_entries: number of tt change entries appended to the tt data
2241 static void batadv_handle_tt_response(struct batadv_priv *bat_priv,
2242 struct batadv_tvlv_tt_data *tt_data,
2243 uint8_t *resp_src, uint16_t num_entries)
2245 struct batadv_tt_req_node *node, *safe;
2246 struct batadv_orig_node *orig_node = NULL;
2247 struct batadv_tvlv_tt_change *tt_change;
2249 batadv_dbg(BATADV_DBG_TT, bat_priv,
2250 "Received TT_RESPONSE from %pM for ttvn %d t_size: %d [%c]\n",
2251 resp_src, tt_data->ttvn, num_entries,
2252 (tt_data->flags & BATADV_TT_FULL_TABLE ? 'F' : '.'));
2254 /* we should have never asked a backbone gw */
2255 if (batadv_bla_is_backbone_gw_orig(bat_priv, resp_src))
2258 orig_node = batadv_orig_hash_find(bat_priv, resp_src);
2262 if (tt_data->flags & BATADV_TT_FULL_TABLE) {
2263 batadv_tt_fill_gtable(bat_priv, tt_data, resp_src, num_entries);
2265 tt_change = (struct batadv_tvlv_tt_change *)(tt_data + 1);
2266 batadv_tt_update_changes(bat_priv, orig_node, num_entries,
2267 tt_data->ttvn, tt_change);
2270 /* Delete the tt_req_node from pending tt_requests list */
2271 spin_lock_bh(&bat_priv->tt.req_list_lock);
2272 list_for_each_entry_safe(node, safe, &bat_priv->tt.req_list, list) {
2273 if (!batadv_compare_eth(node->addr, resp_src))
2275 list_del(&node->list);
2278 spin_unlock_bh(&bat_priv->tt.req_list_lock);
2280 /* Recalculate the CRC for this orig_node and store it */
2281 orig_node->tt_crc = batadv_tt_global_crc(bat_priv, orig_node);
2284 batadv_orig_node_free_ref(orig_node);
2287 static void batadv_tt_roam_list_free(struct batadv_priv *bat_priv)
2289 struct batadv_tt_roam_node *node, *safe;
2291 spin_lock_bh(&bat_priv->tt.roam_list_lock);
2293 list_for_each_entry_safe(node, safe, &bat_priv->tt.roam_list, list) {
2294 list_del(&node->list);
2298 spin_unlock_bh(&bat_priv->tt.roam_list_lock);
2301 static void batadv_tt_roam_purge(struct batadv_priv *bat_priv)
2303 struct batadv_tt_roam_node *node, *safe;
2305 spin_lock_bh(&bat_priv->tt.roam_list_lock);
2306 list_for_each_entry_safe(node, safe, &bat_priv->tt.roam_list, list) {
2307 if (!batadv_has_timed_out(node->first_time,
2308 BATADV_ROAMING_MAX_TIME))
2311 list_del(&node->list);
2314 spin_unlock_bh(&bat_priv->tt.roam_list_lock);
2317 /* This function checks whether the client already reached the
2318 * maximum number of possible roaming phases. In this case the ROAMING_ADV
2321 * returns true if the ROAMING_ADV can be sent, false otherwise
2323 static bool batadv_tt_check_roam_count(struct batadv_priv *bat_priv,
2326 struct batadv_tt_roam_node *tt_roam_node;
2329 spin_lock_bh(&bat_priv->tt.roam_list_lock);
2330 /* The new tt_req will be issued only if I'm not waiting for a
2331 * reply from the same orig_node yet
2333 list_for_each_entry(tt_roam_node, &bat_priv->tt.roam_list, list) {
2334 if (!batadv_compare_eth(tt_roam_node->addr, client))
2337 if (batadv_has_timed_out(tt_roam_node->first_time,
2338 BATADV_ROAMING_MAX_TIME))
2341 if (!batadv_atomic_dec_not_zero(&tt_roam_node->counter))
2342 /* Sorry, you roamed too many times! */
2349 tt_roam_node = kmalloc(sizeof(*tt_roam_node), GFP_ATOMIC);
2353 tt_roam_node->first_time = jiffies;
2354 atomic_set(&tt_roam_node->counter,
2355 BATADV_ROAMING_MAX_COUNT - 1);
2356 memcpy(tt_roam_node->addr, client, ETH_ALEN);
2358 list_add(&tt_roam_node->list, &bat_priv->tt.roam_list);
2363 spin_unlock_bh(&bat_priv->tt.roam_list_lock);
2368 * batadv_send_roam_adv - send a roaming advertisement message
2369 * @bat_priv: the bat priv with all the soft interface information
2370 * @client: mac address of the roaming client
2371 * @vid: VLAN identifier
2372 * @orig_node: message destination
2374 * Send a ROAMING_ADV message to the node which was previously serving this
2375 * client. This is done to inform the node that from now on all traffic destined
2376 * for this particular roamed client has to be forwarded to the sender of the
2379 static void batadv_send_roam_adv(struct batadv_priv *bat_priv, uint8_t *client,
2381 struct batadv_orig_node *orig_node)
2383 struct batadv_hard_iface *primary_if;
2384 struct batadv_tvlv_roam_adv tvlv_roam;
2386 primary_if = batadv_primary_if_get_selected(bat_priv);
2390 /* before going on we have to check whether the client has
2391 * already roamed to us too many times
2393 if (!batadv_tt_check_roam_count(bat_priv, client))
2396 batadv_dbg(BATADV_DBG_TT, bat_priv,
2397 "Sending ROAMING_ADV to %pM (client %pM, vid: %d)\n",
2398 orig_node->orig, client, BATADV_PRINT_VID(vid));
2400 batadv_inc_counter(bat_priv, BATADV_CNT_TT_ROAM_ADV_TX);
2402 memcpy(tvlv_roam.client, client, sizeof(tvlv_roam.client));
2403 tvlv_roam.vid = htons(vid);
2405 batadv_tvlv_unicast_send(bat_priv, primary_if->net_dev->dev_addr,
2406 orig_node->orig, BATADV_TVLV_ROAM, 1,
2407 &tvlv_roam, sizeof(tvlv_roam));
2411 batadv_hardif_free_ref(primary_if);
2414 static void batadv_tt_purge(struct work_struct *work)
2416 struct delayed_work *delayed_work;
2417 struct batadv_priv_tt *priv_tt;
2418 struct batadv_priv *bat_priv;
2420 delayed_work = container_of(work, struct delayed_work, work);
2421 priv_tt = container_of(delayed_work, struct batadv_priv_tt, work);
2422 bat_priv = container_of(priv_tt, struct batadv_priv, tt);
2424 batadv_tt_local_purge(bat_priv);
2425 batadv_tt_global_purge(bat_priv);
2426 batadv_tt_req_purge(bat_priv);
2427 batadv_tt_roam_purge(bat_priv);
2429 queue_delayed_work(batadv_event_workqueue, &bat_priv->tt.work,
2430 msecs_to_jiffies(BATADV_TT_WORK_PERIOD));
2433 void batadv_tt_free(struct batadv_priv *bat_priv)
2435 batadv_tvlv_container_unregister(bat_priv, BATADV_TVLV_TT, 1);
2436 batadv_tvlv_handler_unregister(bat_priv, BATADV_TVLV_TT, 1);
2438 cancel_delayed_work_sync(&bat_priv->tt.work);
2440 batadv_tt_local_table_free(bat_priv);
2441 batadv_tt_global_table_free(bat_priv);
2442 batadv_tt_req_list_free(bat_priv);
2443 batadv_tt_changes_list_free(bat_priv);
2444 batadv_tt_roam_list_free(bat_priv);
2446 kfree(bat_priv->tt.last_changeset);
2449 /* This function will enable or disable the specified flags for all the entries
2450 * in the given hash table and returns the number of modified entries
2452 static uint16_t batadv_tt_set_flags(struct batadv_hashtable *hash,
2453 uint16_t flags, bool enable)
2456 uint16_t changed_num = 0;
2457 struct hlist_head *head;
2458 struct batadv_tt_common_entry *tt_common_entry;
2463 for (i = 0; i < hash->size; i++) {
2464 head = &hash->table[i];
2467 hlist_for_each_entry_rcu(tt_common_entry,
2470 if ((tt_common_entry->flags & flags) == flags)
2472 tt_common_entry->flags |= flags;
2474 if (!(tt_common_entry->flags & flags))
2476 tt_common_entry->flags &= ~flags;
2486 /* Purge out all the tt local entries marked with BATADV_TT_CLIENT_PENDING */
2487 static void batadv_tt_local_purge_pending_clients(struct batadv_priv *bat_priv)
2489 struct batadv_hashtable *hash = bat_priv->tt.local_hash;
2490 struct batadv_tt_common_entry *tt_common;
2491 struct batadv_tt_local_entry *tt_local;
2492 struct hlist_node *node_tmp;
2493 struct hlist_head *head;
2494 spinlock_t *list_lock; /* protects write access to the hash lists */
2500 for (i = 0; i < hash->size; i++) {
2501 head = &hash->table[i];
2502 list_lock = &hash->list_locks[i];
2504 spin_lock_bh(list_lock);
2505 hlist_for_each_entry_safe(tt_common, node_tmp, head,
2507 if (!(tt_common->flags & BATADV_TT_CLIENT_PENDING))
2510 batadv_dbg(BATADV_DBG_TT, bat_priv,
2511 "Deleting local tt entry (%pM, vid: %d): pending\n",
2513 BATADV_PRINT_VID(tt_common->vid));
2515 atomic_dec(&bat_priv->tt.local_entry_num);
2516 hlist_del_rcu(&tt_common->hash_entry);
2517 tt_local = container_of(tt_common,
2518 struct batadv_tt_local_entry,
2520 batadv_tt_local_entry_free_ref(tt_local);
2522 spin_unlock_bh(list_lock);
2527 * batadv_tt_local_commit_changes - commit all pending local tt changes which
2528 * have been queued in the time since the last commit
2529 * @bat_priv: the bat priv with all the soft interface information
2531 void batadv_tt_local_commit_changes(struct batadv_priv *bat_priv)
2533 uint16_t changed_num = 0;
2535 if (atomic_read(&bat_priv->tt.local_changes) < 1) {
2536 if (!batadv_atomic_dec_not_zero(&bat_priv->tt.ogm_append_cnt))
2537 batadv_tt_tvlv_container_update(bat_priv);
2541 changed_num = batadv_tt_set_flags(bat_priv->tt.local_hash,
2542 BATADV_TT_CLIENT_NEW, false);
2544 /* all reset entries have to be counted as local entries */
2545 atomic_add(changed_num, &bat_priv->tt.local_entry_num);
2546 batadv_tt_local_purge_pending_clients(bat_priv);
2547 bat_priv->tt.local_crc = batadv_tt_local_crc(bat_priv);
2549 /* Increment the TTVN only once per OGM interval */
2550 atomic_inc(&bat_priv->tt.vn);
2551 batadv_dbg(BATADV_DBG_TT, bat_priv,
2552 "Local changes committed, updating to ttvn %u\n",
2553 (uint8_t)atomic_read(&bat_priv->tt.vn));
2555 /* reset the sending counter */
2556 atomic_set(&bat_priv->tt.ogm_append_cnt, BATADV_TT_OGM_APPEND_MAX);
2557 batadv_tt_tvlv_container_update(bat_priv);
2560 bool batadv_is_ap_isolated(struct batadv_priv *bat_priv, uint8_t *src,
2561 uint8_t *dst, unsigned short vid)
2563 struct batadv_tt_local_entry *tt_local_entry = NULL;
2564 struct batadv_tt_global_entry *tt_global_entry = NULL;
2565 struct batadv_softif_vlan *vlan;
2568 vlan = batadv_softif_vlan_get(bat_priv, vid);
2569 if (!vlan || !atomic_read(&vlan->ap_isolation))
2572 tt_local_entry = batadv_tt_local_hash_find(bat_priv, dst, vid);
2573 if (!tt_local_entry)
2576 tt_global_entry = batadv_tt_global_hash_find(bat_priv, src, vid);
2577 if (!tt_global_entry)
2580 if (!_batadv_is_ap_isolated(tt_local_entry, tt_global_entry))
2587 batadv_softif_vlan_free_ref(vlan);
2588 if (tt_global_entry)
2589 batadv_tt_global_entry_free_ref(tt_global_entry);
2591 batadv_tt_local_entry_free_ref(tt_local_entry);
2596 * batadv_tt_update_orig - update global translation table with new tt
2597 * information received via ogms
2598 * @bat_priv: the bat priv with all the soft interface information
2599 * @orig: the orig_node of the ogm
2600 * @tt_buff: buffer holding the tt information
2601 * @tt_num_changes: number of tt changes inside the tt buffer
2602 * @ttvn: translation table version number of this changeset
2603 * @tt_crc: crc32 checksum of orig node's translation table
2605 static void batadv_tt_update_orig(struct batadv_priv *bat_priv,
2606 struct batadv_orig_node *orig_node,
2607 const unsigned char *tt_buff,
2608 uint16_t tt_num_changes, uint8_t ttvn,
2611 uint8_t orig_ttvn = (uint8_t)atomic_read(&orig_node->last_ttvn);
2612 bool full_table = true;
2613 struct batadv_tvlv_tt_change *tt_change;
2615 /* don't care about a backbone gateways updates. */
2616 if (batadv_bla_is_backbone_gw_orig(bat_priv, orig_node->orig))
2619 /* orig table not initialised AND first diff is in the OGM OR the ttvn
2620 * increased by one -> we can apply the attached changes
2622 if ((!orig_node->tt_initialised && ttvn == 1) ||
2623 ttvn - orig_ttvn == 1) {
2624 /* the OGM could not contain the changes due to their size or
2625 * because they have already been sent BATADV_TT_OGM_APPEND_MAX
2627 * In this case send a tt request
2629 if (!tt_num_changes) {
2634 tt_change = (struct batadv_tvlv_tt_change *)tt_buff;
2635 batadv_tt_update_changes(bat_priv, orig_node, tt_num_changes,
2638 /* Even if we received the precomputed crc with the OGM, we
2639 * prefer to recompute it to spot any possible inconsistency
2640 * in the global table
2642 orig_node->tt_crc = batadv_tt_global_crc(bat_priv, orig_node);
2644 /* The ttvn alone is not enough to guarantee consistency
2645 * because a single value could represent different states
2646 * (due to the wrap around). Thus a node has to check whether
2647 * the resulting table (after applying the changes) is still
2648 * consistent or not. E.g. a node could disconnect while its
2649 * ttvn is X and reconnect on ttvn = X + TTVN_MAX: in this case
2650 * checking the CRC value is mandatory to detect the
2653 if (orig_node->tt_crc != tt_crc)
2656 /* if we missed more than one change or our tables are not
2657 * in sync anymore -> request fresh tt data
2659 if (!orig_node->tt_initialised || ttvn != orig_ttvn ||
2660 orig_node->tt_crc != tt_crc) {
2662 batadv_dbg(BATADV_DBG_TT, bat_priv,
2663 "TT inconsistency for %pM. Need to retrieve the correct information (ttvn: %u last_ttvn: %u crc: %#.8x last_crc: %#.8x num_changes: %u)\n",
2664 orig_node->orig, ttvn, orig_ttvn, tt_crc,
2665 orig_node->tt_crc, tt_num_changes);
2666 batadv_send_tt_request(bat_priv, orig_node, ttvn,
2667 tt_crc, full_table);
2674 * batadv_tt_global_client_is_roaming - check if a client is marked as roaming
2675 * @bat_priv: the bat priv with all the soft interface information
2676 * @addr: the mac address of the client to check
2677 * @vid: VLAN identifier
2679 * Returns true if we know that the client has moved from its old originator
2680 * to another one. This entry is still kept for consistency purposes and will be
2681 * deleted later by a DEL or because of timeout
2683 bool batadv_tt_global_client_is_roaming(struct batadv_priv *bat_priv,
2684 uint8_t *addr, unsigned short vid)
2686 struct batadv_tt_global_entry *tt_global_entry;
2689 tt_global_entry = batadv_tt_global_hash_find(bat_priv, addr, vid);
2690 if (!tt_global_entry)
2693 ret = tt_global_entry->common.flags & BATADV_TT_CLIENT_ROAM;
2694 batadv_tt_global_entry_free_ref(tt_global_entry);
2700 * batadv_tt_local_client_is_roaming - tells whether the client is roaming
2701 * @bat_priv: the bat priv with all the soft interface information
2702 * @addr: the mac address of the local client to query
2703 * @vid: VLAN identifier
2705 * Returns true if the local client is known to be roaming (it is not served by
2706 * this node anymore) or not. If yes, the client is still present in the table
2707 * to keep the latter consistent with the node TTVN
2709 bool batadv_tt_local_client_is_roaming(struct batadv_priv *bat_priv,
2710 uint8_t *addr, unsigned short vid)
2712 struct batadv_tt_local_entry *tt_local_entry;
2715 tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr, vid);
2716 if (!tt_local_entry)
2719 ret = tt_local_entry->common.flags & BATADV_TT_CLIENT_ROAM;
2720 batadv_tt_local_entry_free_ref(tt_local_entry);
2725 bool batadv_tt_add_temporary_global_entry(struct batadv_priv *bat_priv,
2726 struct batadv_orig_node *orig_node,
2727 const unsigned char *addr,
2732 /* if the originator is a backbone node (meaning it belongs to the same
2733 * LAN of this node) the temporary client must not be added because to
2734 * reach such destination the node must use the LAN instead of the mesh
2736 if (batadv_bla_is_backbone_gw_orig(bat_priv, orig_node->orig))
2739 if (!batadv_tt_global_add(bat_priv, orig_node, addr, vid,
2740 BATADV_TT_CLIENT_TEMP,
2741 atomic_read(&orig_node->last_ttvn)))
2744 batadv_dbg(BATADV_DBG_TT, bat_priv,
2745 "Added temporary global client (addr: %pM, vid: %d, orig: %pM)\n",
2746 addr, BATADV_PRINT_VID(vid), orig_node->orig);
2753 * batadv_tt_tvlv_ogm_handler_v1 - process incoming tt tvlv container
2754 * @bat_priv: the bat priv with all the soft interface information
2755 * @orig: the orig_node of the ogm
2756 * @flags: flags indicating the tvlv state (see batadv_tvlv_handler_flags)
2757 * @tvlv_value: tvlv buffer containing the gateway data
2758 * @tvlv_value_len: tvlv buffer length
2760 static void batadv_tt_tvlv_ogm_handler_v1(struct batadv_priv *bat_priv,
2761 struct batadv_orig_node *orig,
2764 uint16_t tvlv_value_len)
2766 struct batadv_tvlv_tt_data *tt_data;
2767 uint16_t num_entries;
2769 if (tvlv_value_len < sizeof(*tt_data))
2772 tt_data = (struct batadv_tvlv_tt_data *)tvlv_value;
2773 tvlv_value_len -= sizeof(*tt_data);
2775 num_entries = batadv_tt_entries(tvlv_value_len);
2777 batadv_tt_update_orig(bat_priv, orig,
2778 (unsigned char *)(tt_data + 1),
2779 num_entries, tt_data->ttvn, ntohl(tt_data->crc));
2783 * batadv_tt_tvlv_unicast_handler_v1 - process incoming (unicast) tt tvlv
2785 * @bat_priv: the bat priv with all the soft interface information
2786 * @src: mac address of tt tvlv sender
2787 * @dst: mac address of tt tvlv recipient
2788 * @tvlv_value: tvlv buffer containing the tt data
2789 * @tvlv_value_len: tvlv buffer length
2791 * Returns NET_RX_DROP if the tt tvlv is to be re-routed, NET_RX_SUCCESS
2794 static int batadv_tt_tvlv_unicast_handler_v1(struct batadv_priv *bat_priv,
2795 uint8_t *src, uint8_t *dst,
2797 uint16_t tvlv_value_len)
2799 struct batadv_tvlv_tt_data *tt_data;
2800 uint16_t num_entries;
2804 if (tvlv_value_len < sizeof(*tt_data))
2805 return NET_RX_SUCCESS;
2807 tt_data = (struct batadv_tvlv_tt_data *)tvlv_value;
2808 tvlv_value_len -= sizeof(*tt_data);
2810 num_entries = batadv_tt_entries(tvlv_value_len);
2812 switch (tt_data->flags & BATADV_TT_DATA_TYPE_MASK) {
2813 case BATADV_TT_REQUEST:
2814 batadv_inc_counter(bat_priv, BATADV_CNT_TT_REQUEST_RX);
2816 /* If this node cannot provide a TT response the tt_request is
2819 ret = batadv_send_tt_response(bat_priv, tt_data, src, dst);
2821 if (tt_data->flags & BATADV_TT_FULL_TABLE)
2826 batadv_dbg(BATADV_DBG_TT, bat_priv,
2827 "Routing TT_REQUEST to %pM [%c]\n",
2829 /* tvlv API will re-route the packet */
2833 case BATADV_TT_RESPONSE:
2834 batadv_inc_counter(bat_priv, BATADV_CNT_TT_RESPONSE_RX);
2836 if (batadv_is_my_mac(bat_priv, dst)) {
2837 batadv_handle_tt_response(bat_priv, tt_data,
2839 return NET_RX_SUCCESS;
2842 if (tt_data->flags & BATADV_TT_FULL_TABLE)
2847 batadv_dbg(BATADV_DBG_TT, bat_priv,
2848 "Routing TT_RESPONSE to %pM [%c]\n", dst, tt_flag);
2850 /* tvlv API will re-route the packet */
2854 return NET_RX_SUCCESS;
2858 * batadv_roam_tvlv_unicast_handler_v1 - process incoming tt roam tvlv container
2859 * @bat_priv: the bat priv with all the soft interface information
2860 * @src: mac address of tt tvlv sender
2861 * @dst: mac address of tt tvlv recipient
2862 * @tvlv_value: tvlv buffer containing the tt data
2863 * @tvlv_value_len: tvlv buffer length
2865 * Returns NET_RX_DROP if the tt roam tvlv is to be re-routed, NET_RX_SUCCESS
2868 static int batadv_roam_tvlv_unicast_handler_v1(struct batadv_priv *bat_priv,
2869 uint8_t *src, uint8_t *dst,
2871 uint16_t tvlv_value_len)
2873 struct batadv_tvlv_roam_adv *roaming_adv;
2874 struct batadv_orig_node *orig_node = NULL;
2876 /* If this node is not the intended recipient of the
2877 * roaming advertisement the packet is forwarded
2878 * (the tvlv API will re-route the packet).
2880 if (!batadv_is_my_mac(bat_priv, dst))
2883 /* check if it is a backbone gateway. we don't accept
2884 * roaming advertisement from it, as it has the same
2885 * entries as we have.
2887 if (batadv_bla_is_backbone_gw_orig(bat_priv, src))
2890 if (tvlv_value_len < sizeof(*roaming_adv))
2893 orig_node = batadv_orig_hash_find(bat_priv, src);
2897 batadv_inc_counter(bat_priv, BATADV_CNT_TT_ROAM_ADV_RX);
2898 roaming_adv = (struct batadv_tvlv_roam_adv *)tvlv_value;
2900 batadv_dbg(BATADV_DBG_TT, bat_priv,
2901 "Received ROAMING_ADV from %pM (client %pM)\n",
2902 src, roaming_adv->client);
2904 batadv_tt_global_add(bat_priv, orig_node, roaming_adv->client,
2905 ntohs(roaming_adv->vid), BATADV_TT_CLIENT_ROAM,
2906 atomic_read(&orig_node->last_ttvn) + 1);
2910 batadv_orig_node_free_ref(orig_node);
2911 return NET_RX_SUCCESS;
2915 * batadv_tt_init - initialise the translation table internals
2916 * @bat_priv: the bat priv with all the soft interface information
2918 * Return 0 on success or negative error number in case of failure.
2920 int batadv_tt_init(struct batadv_priv *bat_priv)
2924 ret = batadv_tt_local_init(bat_priv);
2928 ret = batadv_tt_global_init(bat_priv);
2932 batadv_tvlv_handler_register(bat_priv, batadv_tt_tvlv_ogm_handler_v1,
2933 batadv_tt_tvlv_unicast_handler_v1,
2934 BATADV_TVLV_TT, 1, BATADV_NO_FLAGS);
2936 batadv_tvlv_handler_register(bat_priv, NULL,
2937 batadv_roam_tvlv_unicast_handler_v1,
2938 BATADV_TVLV_ROAM, 1, BATADV_NO_FLAGS);
2940 INIT_DELAYED_WORK(&bat_priv->tt.work, batadv_tt_purge);
2941 queue_delayed_work(batadv_event_workqueue, &bat_priv->tt.work,
2942 msecs_to_jiffies(BATADV_TT_WORK_PERIOD));