1 /* Copyright (C) 2007-2017 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, see <http://www.gnu.org/licenses/>.
18 #include "translation-table.h"
21 #include <linux/atomic.h>
22 #include <linux/bitops.h>
23 #include <linux/bug.h>
24 #include <linux/byteorder/generic.h>
25 #include <linux/cache.h>
26 #include <linux/compiler.h>
27 #include <linux/crc32c.h>
28 #include <linux/errno.h>
29 #include <linux/etherdevice.h>
31 #include <linux/if_ether.h>
32 #include <linux/init.h>
33 #include <linux/jhash.h>
34 #include <linux/jiffies.h>
35 #include <linux/kernel.h>
36 #include <linux/kref.h>
37 #include <linux/list.h>
38 #include <linux/lockdep.h>
39 #include <linux/netdevice.h>
40 #include <linux/netlink.h>
41 #include <linux/rculist.h>
42 #include <linux/rcupdate.h>
43 #include <linux/seq_file.h>
44 #include <linux/skbuff.h>
45 #include <linux/slab.h>
46 #include <linux/spinlock.h>
47 #include <linux/stddef.h>
48 #include <linux/string.h>
49 #include <linux/workqueue.h>
50 #include <net/genetlink.h>
51 #include <net/netlink.h>
53 #include <uapi/linux/batman_adv.h>
55 #include "bridge_loop_avoidance.h"
56 #include "hard-interface.h"
60 #include "originator.h"
62 #include "soft-interface.h"
65 static struct kmem_cache *batadv_tl_cache __read_mostly;
66 static struct kmem_cache *batadv_tg_cache __read_mostly;
67 static struct kmem_cache *batadv_tt_orig_cache __read_mostly;
68 static struct kmem_cache *batadv_tt_change_cache __read_mostly;
69 static struct kmem_cache *batadv_tt_req_cache __read_mostly;
70 static struct kmem_cache *batadv_tt_roam_cache __read_mostly;
73 static struct lock_class_key batadv_tt_local_hash_lock_class_key;
74 static struct lock_class_key batadv_tt_global_hash_lock_class_key;
76 static void batadv_send_roam_adv(struct batadv_priv *bat_priv, u8 *client,
78 struct batadv_orig_node *orig_node);
79 static void batadv_tt_purge(struct work_struct *work);
81 batadv_tt_global_del_orig_list(struct batadv_tt_global_entry *tt_global_entry);
82 static void batadv_tt_global_del(struct batadv_priv *bat_priv,
83 struct batadv_orig_node *orig_node,
84 const unsigned char *addr,
85 unsigned short vid, const char *message,
89 * batadv_compare_tt - check if two TT entries are the same
90 * @node: the list element pointer of the first TT entry
91 * @data2: pointer to the tt_common_entry of the second TT entry
93 * Compare the MAC address and the VLAN ID of the two TT entries and check if
94 * they are the same TT client.
95 * Return: true if the two TT clients are the same, false otherwise
97 static bool batadv_compare_tt(const struct hlist_node *node, const void *data2)
99 const void *data1 = container_of(node, struct batadv_tt_common_entry,
101 const struct batadv_tt_common_entry *tt1 = data1;
102 const struct batadv_tt_common_entry *tt2 = data2;
104 return (tt1->vid == tt2->vid) && batadv_compare_eth(data1, data2);
108 * batadv_choose_tt - return the index of the tt entry in the hash table
109 * @data: pointer to the tt_common_entry object to map
110 * @size: the size of the hash table
112 * Return: the hash index where the object represented by 'data' should be
115 static inline u32 batadv_choose_tt(const void *data, u32 size)
117 struct batadv_tt_common_entry *tt;
120 tt = (struct batadv_tt_common_entry *)data;
121 hash = jhash(&tt->addr, ETH_ALEN, hash);
122 hash = jhash(&tt->vid, sizeof(tt->vid), hash);
128 * batadv_tt_hash_find - look for a client in the given hash table
129 * @hash: the hash table to search
130 * @addr: the mac address of the client to look for
131 * @vid: VLAN identifier
133 * Return: a pointer to the tt_common struct belonging to the searched client if
134 * found, NULL otherwise.
136 static struct batadv_tt_common_entry *
137 batadv_tt_hash_find(struct batadv_hashtable *hash, const u8 *addr,
140 struct hlist_head *head;
141 struct batadv_tt_common_entry to_search, *tt, *tt_tmp = NULL;
147 ether_addr_copy(to_search.addr, addr);
150 index = batadv_choose_tt(&to_search, hash->size);
151 head = &hash->table[index];
154 hlist_for_each_entry_rcu(tt, head, hash_entry) {
155 if (!batadv_compare_eth(tt, addr))
161 if (!kref_get_unless_zero(&tt->refcount))
173 * batadv_tt_local_hash_find - search the local table for a given client
174 * @bat_priv: the bat priv with all the soft interface information
175 * @addr: the mac address of the client to look for
176 * @vid: VLAN identifier
178 * Return: a pointer to the corresponding tt_local_entry struct if the client is
179 * found, NULL otherwise.
181 static struct batadv_tt_local_entry *
182 batadv_tt_local_hash_find(struct batadv_priv *bat_priv, const u8 *addr,
185 struct batadv_tt_common_entry *tt_common_entry;
186 struct batadv_tt_local_entry *tt_local_entry = NULL;
188 tt_common_entry = batadv_tt_hash_find(bat_priv->tt.local_hash, addr,
191 tt_local_entry = container_of(tt_common_entry,
192 struct batadv_tt_local_entry,
194 return tt_local_entry;
198 * batadv_tt_global_hash_find - search the global table for a given client
199 * @bat_priv: the bat priv with all the soft interface information
200 * @addr: the mac address of the client to look for
201 * @vid: VLAN identifier
203 * Return: a pointer to the corresponding tt_global_entry struct if the client
204 * is found, NULL otherwise.
206 static struct batadv_tt_global_entry *
207 batadv_tt_global_hash_find(struct batadv_priv *bat_priv, const u8 *addr,
210 struct batadv_tt_common_entry *tt_common_entry;
211 struct batadv_tt_global_entry *tt_global_entry = NULL;
213 tt_common_entry = batadv_tt_hash_find(bat_priv->tt.global_hash, addr,
216 tt_global_entry = container_of(tt_common_entry,
217 struct batadv_tt_global_entry,
219 return tt_global_entry;
223 * batadv_tt_local_entry_free_rcu - free the tt_local_entry
224 * @rcu: rcu pointer of the tt_local_entry
226 static void batadv_tt_local_entry_free_rcu(struct rcu_head *rcu)
228 struct batadv_tt_local_entry *tt_local_entry;
230 tt_local_entry = container_of(rcu, struct batadv_tt_local_entry,
233 kmem_cache_free(batadv_tl_cache, tt_local_entry);
237 * batadv_tt_local_entry_release - release tt_local_entry from lists and queue
238 * for free after rcu grace period
239 * @ref: kref pointer of the nc_node
241 static void batadv_tt_local_entry_release(struct kref *ref)
243 struct batadv_tt_local_entry *tt_local_entry;
245 tt_local_entry = container_of(ref, struct batadv_tt_local_entry,
248 batadv_softif_vlan_put(tt_local_entry->vlan);
250 call_rcu(&tt_local_entry->common.rcu, batadv_tt_local_entry_free_rcu);
254 * batadv_tt_local_entry_put - decrement the tt_local_entry refcounter and
255 * possibly release it
256 * @tt_local_entry: tt_local_entry to be free'd
259 batadv_tt_local_entry_put(struct batadv_tt_local_entry *tt_local_entry)
261 kref_put(&tt_local_entry->common.refcount,
262 batadv_tt_local_entry_release);
266 * batadv_tt_global_entry_free_rcu - free the tt_global_entry
267 * @rcu: rcu pointer of the tt_global_entry
269 static void batadv_tt_global_entry_free_rcu(struct rcu_head *rcu)
271 struct batadv_tt_global_entry *tt_global_entry;
273 tt_global_entry = container_of(rcu, struct batadv_tt_global_entry,
276 kmem_cache_free(batadv_tg_cache, tt_global_entry);
280 * batadv_tt_global_entry_release - release tt_global_entry from lists and queue
281 * for free after rcu grace period
282 * @ref: kref pointer of the nc_node
284 static void batadv_tt_global_entry_release(struct kref *ref)
286 struct batadv_tt_global_entry *tt_global_entry;
288 tt_global_entry = container_of(ref, struct batadv_tt_global_entry,
291 batadv_tt_global_del_orig_list(tt_global_entry);
293 call_rcu(&tt_global_entry->common.rcu, batadv_tt_global_entry_free_rcu);
297 * batadv_tt_global_entry_put - decrement the tt_global_entry refcounter and
298 * possibly release it
299 * @tt_global_entry: tt_global_entry to be free'd
302 batadv_tt_global_entry_put(struct batadv_tt_global_entry *tt_global_entry)
304 kref_put(&tt_global_entry->common.refcount,
305 batadv_tt_global_entry_release);
309 * batadv_tt_global_hash_count - count the number of orig entries
310 * @bat_priv: the bat priv with all the soft interface information
311 * @addr: the mac address of the client to count entries for
312 * @vid: VLAN identifier
314 * Return: the number of originators advertising the given address/data
315 * (excluding ourself).
317 int batadv_tt_global_hash_count(struct batadv_priv *bat_priv,
318 const u8 *addr, unsigned short vid)
320 struct batadv_tt_global_entry *tt_global_entry;
323 tt_global_entry = batadv_tt_global_hash_find(bat_priv, addr, vid);
324 if (!tt_global_entry)
327 count = atomic_read(&tt_global_entry->orig_list_count);
328 batadv_tt_global_entry_put(tt_global_entry);
334 * batadv_tt_local_size_mod - change the size by v of the local table identified
336 * @bat_priv: the bat priv with all the soft interface information
337 * @vid: the VLAN identifier of the sub-table to change
338 * @v: the amount to sum to the local table size
340 static void batadv_tt_local_size_mod(struct batadv_priv *bat_priv,
341 unsigned short vid, int v)
343 struct batadv_softif_vlan *vlan;
345 vlan = batadv_softif_vlan_get(bat_priv, vid);
349 atomic_add(v, &vlan->tt.num_entries);
351 batadv_softif_vlan_put(vlan);
355 * batadv_tt_local_size_inc - increase by one the local table size for the given
357 * @bat_priv: the bat priv with all the soft interface information
358 * @vid: the VLAN identifier
360 static void batadv_tt_local_size_inc(struct batadv_priv *bat_priv,
363 batadv_tt_local_size_mod(bat_priv, vid, 1);
367 * batadv_tt_local_size_dec - decrease by one the local table size for the given
369 * @bat_priv: the bat priv with all the soft interface information
370 * @vid: the VLAN identifier
372 static void batadv_tt_local_size_dec(struct batadv_priv *bat_priv,
375 batadv_tt_local_size_mod(bat_priv, vid, -1);
379 * batadv_tt_global_size_mod - change the size by v of the global table
380 * for orig_node identified by vid
381 * @orig_node: the originator for which the table has to be modified
382 * @vid: the VLAN identifier
383 * @v: the amount to sum to the global table size
385 static void batadv_tt_global_size_mod(struct batadv_orig_node *orig_node,
386 unsigned short vid, int v)
388 struct batadv_orig_node_vlan *vlan;
390 vlan = batadv_orig_node_vlan_new(orig_node, vid);
394 if (atomic_add_return(v, &vlan->tt.num_entries) == 0) {
395 spin_lock_bh(&orig_node->vlan_list_lock);
396 if (!hlist_unhashed(&vlan->list)) {
397 hlist_del_init_rcu(&vlan->list);
398 batadv_orig_node_vlan_put(vlan);
400 spin_unlock_bh(&orig_node->vlan_list_lock);
403 batadv_orig_node_vlan_put(vlan);
407 * batadv_tt_global_size_inc - increase by one the global table size for the
409 * @orig_node: the originator which global table size has to be decreased
410 * @vid: the vlan identifier
412 static void batadv_tt_global_size_inc(struct batadv_orig_node *orig_node,
415 batadv_tt_global_size_mod(orig_node, vid, 1);
419 * batadv_tt_global_size_dec - decrease by one the global table size for the
421 * @orig_node: the originator which global table size has to be decreased
422 * @vid: the vlan identifier
424 static void batadv_tt_global_size_dec(struct batadv_orig_node *orig_node,
427 batadv_tt_global_size_mod(orig_node, vid, -1);
431 * batadv_tt_orig_list_entry_free_rcu - free the orig_entry
432 * @rcu: rcu pointer of the orig_entry
434 static void batadv_tt_orig_list_entry_free_rcu(struct rcu_head *rcu)
436 struct batadv_tt_orig_list_entry *orig_entry;
438 orig_entry = container_of(rcu, struct batadv_tt_orig_list_entry, rcu);
440 kmem_cache_free(batadv_tt_orig_cache, orig_entry);
444 * batadv_tt_orig_list_entry_release - release tt orig entry from lists and
445 * queue for free after rcu grace period
446 * @ref: kref pointer of the tt orig entry
448 static void batadv_tt_orig_list_entry_release(struct kref *ref)
450 struct batadv_tt_orig_list_entry *orig_entry;
452 orig_entry = container_of(ref, struct batadv_tt_orig_list_entry,
455 batadv_orig_node_put(orig_entry->orig_node);
456 call_rcu(&orig_entry->rcu, batadv_tt_orig_list_entry_free_rcu);
460 * batadv_tt_orig_list_entry_put - decrement the tt orig entry refcounter and
461 * possibly release it
462 * @orig_entry: tt orig entry to be free'd
465 batadv_tt_orig_list_entry_put(struct batadv_tt_orig_list_entry *orig_entry)
467 kref_put(&orig_entry->refcount, batadv_tt_orig_list_entry_release);
471 * batadv_tt_local_event - store a local TT event (ADD/DEL)
472 * @bat_priv: the bat priv with all the soft interface information
473 * @tt_local_entry: the TT entry involved in the event
474 * @event_flags: flags to store in the event structure
476 static void batadv_tt_local_event(struct batadv_priv *bat_priv,
477 struct batadv_tt_local_entry *tt_local_entry,
480 struct batadv_tt_change_node *tt_change_node, *entry, *safe;
481 struct batadv_tt_common_entry *common = &tt_local_entry->common;
482 u8 flags = common->flags | event_flags;
483 bool event_removed = false;
484 bool del_op_requested, del_op_entry;
486 tt_change_node = kmem_cache_alloc(batadv_tt_change_cache, GFP_ATOMIC);
490 tt_change_node->change.flags = flags;
491 memset(tt_change_node->change.reserved, 0,
492 sizeof(tt_change_node->change.reserved));
493 ether_addr_copy(tt_change_node->change.addr, common->addr);
494 tt_change_node->change.vid = htons(common->vid);
496 del_op_requested = flags & BATADV_TT_CLIENT_DEL;
498 /* check for ADD+DEL or DEL+ADD events */
499 spin_lock_bh(&bat_priv->tt.changes_list_lock);
500 list_for_each_entry_safe(entry, safe, &bat_priv->tt.changes_list,
502 if (!batadv_compare_eth(entry->change.addr, common->addr))
505 /* DEL+ADD in the same orig interval have no effect and can be
506 * removed to avoid silly behaviour on the receiver side. The
507 * other way around (ADD+DEL) can happen in case of roaming of
508 * a client still in the NEW state. Roaming of NEW clients is
509 * now possible due to automatically recognition of "temporary"
512 del_op_entry = entry->change.flags & BATADV_TT_CLIENT_DEL;
513 if (!del_op_requested && del_op_entry)
515 if (del_op_requested && !del_op_entry)
518 /* this is a second add in the same originator interval. It
519 * means that flags have been changed: update them!
521 if (!del_op_requested && !del_op_entry)
522 entry->change.flags = flags;
526 list_del(&entry->list);
527 kmem_cache_free(batadv_tt_change_cache, entry);
528 kmem_cache_free(batadv_tt_change_cache, tt_change_node);
529 event_removed = true;
533 /* track the change in the OGMinterval list */
534 list_add_tail(&tt_change_node->list, &bat_priv->tt.changes_list);
537 spin_unlock_bh(&bat_priv->tt.changes_list_lock);
540 atomic_dec(&bat_priv->tt.local_changes);
542 atomic_inc(&bat_priv->tt.local_changes);
546 * batadv_tt_len - compute length in bytes of given number of tt changes
547 * @changes_num: number of tt changes
549 * Return: computed length in bytes.
551 static int batadv_tt_len(int changes_num)
553 return changes_num * sizeof(struct batadv_tvlv_tt_change);
557 * batadv_tt_entries - compute the number of entries fitting in tt_len bytes
558 * @tt_len: available space
560 * Return: the number of entries.
562 static u16 batadv_tt_entries(u16 tt_len)
564 return tt_len / batadv_tt_len(1);
568 * batadv_tt_local_table_transmit_size - calculates the local translation table
569 * size when transmitted over the air
570 * @bat_priv: the bat priv with all the soft interface information
572 * Return: local translation table size in bytes.
574 static int batadv_tt_local_table_transmit_size(struct batadv_priv *bat_priv)
577 u16 tt_local_entries = 0;
578 struct batadv_softif_vlan *vlan;
582 hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list) {
584 tt_local_entries += atomic_read(&vlan->tt.num_entries);
588 /* header size of tvlv encapsulated tt response payload */
589 hdr_size = sizeof(struct batadv_unicast_tvlv_packet);
590 hdr_size += sizeof(struct batadv_tvlv_hdr);
591 hdr_size += sizeof(struct batadv_tvlv_tt_data);
592 hdr_size += num_vlan * sizeof(struct batadv_tvlv_tt_vlan_data);
594 return hdr_size + batadv_tt_len(tt_local_entries);
597 static int batadv_tt_local_init(struct batadv_priv *bat_priv)
599 if (bat_priv->tt.local_hash)
602 bat_priv->tt.local_hash = batadv_hash_new(1024);
604 if (!bat_priv->tt.local_hash)
607 batadv_hash_set_lock_class(bat_priv->tt.local_hash,
608 &batadv_tt_local_hash_lock_class_key);
613 static void batadv_tt_global_free(struct batadv_priv *bat_priv,
614 struct batadv_tt_global_entry *tt_global,
617 struct batadv_tt_global_entry *tt_removed_entry;
618 struct hlist_node *tt_removed_node;
620 batadv_dbg(BATADV_DBG_TT, bat_priv,
621 "Deleting global tt entry %pM (vid: %d): %s\n",
622 tt_global->common.addr,
623 batadv_print_vid(tt_global->common.vid), message);
625 tt_removed_node = batadv_hash_remove(bat_priv->tt.global_hash,
629 if (!tt_removed_node)
632 /* drop reference of remove hash entry */
633 tt_removed_entry = hlist_entry(tt_removed_node,
634 struct batadv_tt_global_entry,
636 batadv_tt_global_entry_put(tt_removed_entry);
640 * batadv_tt_local_add - add a new client to the local table or update an
642 * @soft_iface: netdev struct of the mesh interface
643 * @addr: the mac address of the client to add
644 * @vid: VLAN identifier
645 * @ifindex: index of the interface where the client is connected to (useful to
646 * identify wireless clients)
647 * @mark: the value contained in the skb->mark field of the received packet (if
650 * Return: true if the client was successfully added, false otherwise.
652 bool batadv_tt_local_add(struct net_device *soft_iface, const u8 *addr,
653 unsigned short vid, int ifindex, u32 mark)
655 struct batadv_priv *bat_priv = netdev_priv(soft_iface);
656 struct batadv_tt_local_entry *tt_local;
657 struct batadv_tt_global_entry *tt_global = NULL;
658 struct net *net = dev_net(soft_iface);
659 struct batadv_softif_vlan *vlan;
660 struct net_device *in_dev = NULL;
661 struct batadv_hard_iface *in_hardif = NULL;
662 struct hlist_head *head;
663 struct batadv_tt_orig_list_entry *orig_entry;
664 int hash_added, table_size, packet_size_max;
666 bool roamed_back = false;
670 if (ifindex != BATADV_NULL_IFINDEX)
671 in_dev = dev_get_by_index(net, ifindex);
674 in_hardif = batadv_hardif_get_by_netdev(in_dev);
676 tt_local = batadv_tt_local_hash_find(bat_priv, addr, vid);
678 if (!is_multicast_ether_addr(addr))
679 tt_global = batadv_tt_global_hash_find(bat_priv, addr, vid);
682 tt_local->last_seen = jiffies;
683 if (tt_local->common.flags & BATADV_TT_CLIENT_PENDING) {
684 batadv_dbg(BATADV_DBG_TT, bat_priv,
685 "Re-adding pending client %pM (vid: %d)\n",
686 addr, batadv_print_vid(vid));
687 /* whatever the reason why the PENDING flag was set,
688 * this is a client which was enqueued to be removed in
689 * this orig_interval. Since it popped up again, the
690 * flag can be reset like it was never enqueued
692 tt_local->common.flags &= ~BATADV_TT_CLIENT_PENDING;
696 if (tt_local->common.flags & BATADV_TT_CLIENT_ROAM) {
697 batadv_dbg(BATADV_DBG_TT, bat_priv,
698 "Roaming client %pM (vid: %d) came back to its original location\n",
699 addr, batadv_print_vid(vid));
700 /* the ROAM flag is set because this client roamed away
701 * and the node got a roaming_advertisement message. Now
702 * that the client popped up again at its original
703 * location such flag can be unset
705 tt_local->common.flags &= ~BATADV_TT_CLIENT_ROAM;
711 /* Ignore the client if we cannot send it in a full table response. */
712 table_size = batadv_tt_local_table_transmit_size(bat_priv);
713 table_size += batadv_tt_len(1);
714 packet_size_max = atomic_read(&bat_priv->packet_size_max);
715 if (table_size > packet_size_max) {
716 net_ratelimited_function(batadv_info, soft_iface,
717 "Local translation table size (%i) exceeds maximum packet size (%i); Ignoring new local tt entry: %pM\n",
718 table_size, packet_size_max, addr);
722 tt_local = kmem_cache_alloc(batadv_tl_cache, GFP_ATOMIC);
726 /* increase the refcounter of the related vlan */
727 vlan = batadv_softif_vlan_get(bat_priv, vid);
729 net_ratelimited_function(batadv_info, soft_iface,
730 "adding TT local entry %pM to non-existent VLAN %d\n",
731 addr, batadv_print_vid(vid));
732 kmem_cache_free(batadv_tl_cache, tt_local);
737 batadv_dbg(BATADV_DBG_TT, bat_priv,
738 "Creating new local tt entry: %pM (vid: %d, ttvn: %d)\n",
739 addr, batadv_print_vid(vid),
740 (u8)atomic_read(&bat_priv->tt.vn));
742 ether_addr_copy(tt_local->common.addr, addr);
743 /* The local entry has to be marked as NEW to avoid to send it in
744 * a full table response going out before the next ttvn increment
745 * (consistency check)
747 tt_local->common.flags = BATADV_TT_CLIENT_NEW;
748 tt_local->common.vid = vid;
749 if (batadv_is_wifi_hardif(in_hardif))
750 tt_local->common.flags |= BATADV_TT_CLIENT_WIFI;
751 kref_init(&tt_local->common.refcount);
752 tt_local->last_seen = jiffies;
753 tt_local->common.added_at = tt_local->last_seen;
754 tt_local->vlan = vlan;
756 /* the batman interface mac and multicast addresses should never be
759 if (batadv_compare_eth(addr, soft_iface->dev_addr) ||
760 is_multicast_ether_addr(addr))
761 tt_local->common.flags |= BATADV_TT_CLIENT_NOPURGE;
763 kref_get(&tt_local->common.refcount);
764 hash_added = batadv_hash_add(bat_priv->tt.local_hash, batadv_compare_tt,
765 batadv_choose_tt, &tt_local->common,
766 &tt_local->common.hash_entry);
768 if (unlikely(hash_added != 0)) {
769 /* remove the reference for the hash */
770 batadv_tt_local_entry_put(tt_local);
775 batadv_tt_local_event(bat_priv, tt_local, BATADV_NO_FLAGS);
778 /* Check whether it is a roaming, but don't do anything if the roaming
779 * process has already been handled
781 if (tt_global && !(tt_global->common.flags & BATADV_TT_CLIENT_ROAM)) {
782 /* These node are probably going to update their tt table */
783 head = &tt_global->orig_list;
785 hlist_for_each_entry_rcu(orig_entry, head, list) {
786 batadv_send_roam_adv(bat_priv, tt_global->common.addr,
787 tt_global->common.vid,
788 orig_entry->orig_node);
792 batadv_tt_global_free(bat_priv, tt_global,
796 /* The global entry has to be marked as ROAMING and
797 * has to be kept for consistency purpose
799 tt_global->common.flags |= BATADV_TT_CLIENT_ROAM;
800 tt_global->roam_at = jiffies;
804 /* store the current remote flags before altering them. This helps
805 * understanding is flags are changing or not
807 remote_flags = tt_local->common.flags & BATADV_TT_REMOTE_MASK;
809 if (batadv_is_wifi_hardif(in_hardif))
810 tt_local->common.flags |= BATADV_TT_CLIENT_WIFI;
812 tt_local->common.flags &= ~BATADV_TT_CLIENT_WIFI;
814 /* check the mark in the skb: if it's equal to the configured
815 * isolation_mark, it means the packet is coming from an isolated
818 match_mark = (mark & bat_priv->isolation_mark_mask);
819 if (bat_priv->isolation_mark_mask &&
820 match_mark == bat_priv->isolation_mark)
821 tt_local->common.flags |= BATADV_TT_CLIENT_ISOLA;
823 tt_local->common.flags &= ~BATADV_TT_CLIENT_ISOLA;
825 /* if any "dynamic" flag has been modified, resend an ADD event for this
826 * entry so that all the nodes can get the new flags
828 if (remote_flags ^ (tt_local->common.flags & BATADV_TT_REMOTE_MASK))
829 batadv_tt_local_event(bat_priv, tt_local, BATADV_NO_FLAGS);
834 batadv_hardif_put(in_hardif);
838 batadv_tt_local_entry_put(tt_local);
840 batadv_tt_global_entry_put(tt_global);
845 * batadv_tt_prepare_tvlv_global_data - prepare the TVLV TT header to send
846 * within a TT Response directed to another node
847 * @orig_node: originator for which the TT data has to be prepared
848 * @tt_data: uninitialised pointer to the address of the TVLV buffer
849 * @tt_change: uninitialised pointer to the address of the area where the TT
850 * changed can be stored
851 * @tt_len: pointer to the length to reserve to the tt_change. if -1 this
852 * function reserves the amount of space needed to send the entire global TT
853 * table. In case of success the value is updated with the real amount of
855 * Allocate the needed amount of memory for the entire TT TVLV and write its
856 * header made up by one tvlv_tt_data object and a series of tvlv_tt_vlan_data
857 * objects, one per active VLAN served by the originator node.
859 * Return: the size of the allocated buffer or 0 in case of failure.
862 batadv_tt_prepare_tvlv_global_data(struct batadv_orig_node *orig_node,
863 struct batadv_tvlv_tt_data **tt_data,
864 struct batadv_tvlv_tt_change **tt_change,
871 struct batadv_tvlv_tt_vlan_data *tt_vlan;
872 struct batadv_orig_node_vlan *vlan;
875 spin_lock_bh(&orig_node->vlan_list_lock);
876 hlist_for_each_entry_rcu(vlan, &orig_node->vlan_list, list) {
878 num_entries += atomic_read(&vlan->tt.num_entries);
881 change_offset = sizeof(**tt_data);
882 change_offset += num_vlan * sizeof(*tt_vlan);
884 /* if tt_len is negative, allocate the space needed by the full table */
886 *tt_len = batadv_tt_len(num_entries);
889 tvlv_len += change_offset;
891 *tt_data = kmalloc(tvlv_len, GFP_ATOMIC);
897 (*tt_data)->flags = BATADV_NO_FLAGS;
898 (*tt_data)->ttvn = atomic_read(&orig_node->last_ttvn);
899 (*tt_data)->num_vlan = htons(num_vlan);
901 tt_vlan = (struct batadv_tvlv_tt_vlan_data *)(*tt_data + 1);
902 hlist_for_each_entry_rcu(vlan, &orig_node->vlan_list, list) {
903 tt_vlan->vid = htons(vlan->vid);
904 tt_vlan->crc = htonl(vlan->tt.crc);
905 tt_vlan->reserved = 0;
910 tt_change_ptr = (u8 *)*tt_data + change_offset;
911 *tt_change = (struct batadv_tvlv_tt_change *)tt_change_ptr;
914 spin_unlock_bh(&orig_node->vlan_list_lock);
919 * batadv_tt_prepare_tvlv_local_data - allocate and prepare the TT TVLV for this
921 * @bat_priv: the bat priv with all the soft interface information
922 * @tt_data: uninitialised pointer to the address of the TVLV buffer
923 * @tt_change: uninitialised pointer to the address of the area where the TT
924 * changes can be stored
925 * @tt_len: pointer to the length to reserve to the tt_change. if -1 this
926 * function reserves the amount of space needed to send the entire local TT
927 * table. In case of success the value is updated with the real amount of
930 * Allocate the needed amount of memory for the entire TT TVLV and write its
931 * header made up by one tvlv_tt_data object and a series of tvlv_tt_vlan_data
932 * objects, one per active VLAN.
934 * Return: the size of the allocated buffer or 0 in case of failure.
937 batadv_tt_prepare_tvlv_local_data(struct batadv_priv *bat_priv,
938 struct batadv_tvlv_tt_data **tt_data,
939 struct batadv_tvlv_tt_change **tt_change,
942 struct batadv_tvlv_tt_vlan_data *tt_vlan;
943 struct batadv_softif_vlan *vlan;
945 u16 vlan_entries = 0;
946 u16 total_entries = 0;
951 spin_lock_bh(&bat_priv->softif_vlan_list_lock);
952 hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list) {
953 vlan_entries = atomic_read(&vlan->tt.num_entries);
954 if (vlan_entries < 1)
958 total_entries += vlan_entries;
961 change_offset = sizeof(**tt_data);
962 change_offset += num_vlan * sizeof(*tt_vlan);
964 /* if tt_len is negative, allocate the space needed by the full table */
966 *tt_len = batadv_tt_len(total_entries);
969 tvlv_len += change_offset;
971 *tt_data = kmalloc(tvlv_len, GFP_ATOMIC);
977 (*tt_data)->flags = BATADV_NO_FLAGS;
978 (*tt_data)->ttvn = atomic_read(&bat_priv->tt.vn);
979 (*tt_data)->num_vlan = htons(num_vlan);
981 tt_vlan = (struct batadv_tvlv_tt_vlan_data *)(*tt_data + 1);
982 hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list) {
983 vlan_entries = atomic_read(&vlan->tt.num_entries);
984 if (vlan_entries < 1)
987 tt_vlan->vid = htons(vlan->vid);
988 tt_vlan->crc = htonl(vlan->tt.crc);
989 tt_vlan->reserved = 0;
994 tt_change_ptr = (u8 *)*tt_data + change_offset;
995 *tt_change = (struct batadv_tvlv_tt_change *)tt_change_ptr;
998 spin_unlock_bh(&bat_priv->softif_vlan_list_lock);
1003 * batadv_tt_tvlv_container_update - update the translation table tvlv container
1004 * after local tt changes have been committed
1005 * @bat_priv: the bat priv with all the soft interface information
1007 static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv)
1009 struct batadv_tt_change_node *entry, *safe;
1010 struct batadv_tvlv_tt_data *tt_data;
1011 struct batadv_tvlv_tt_change *tt_change;
1012 int tt_diff_len, tt_change_len = 0;
1013 int tt_diff_entries_num = 0;
1014 int tt_diff_entries_count = 0;
1017 tt_diff_entries_num = atomic_read(&bat_priv->tt.local_changes);
1018 tt_diff_len = batadv_tt_len(tt_diff_entries_num);
1020 /* if we have too many changes for one packet don't send any
1021 * and wait for the tt table request which will be fragmented
1023 if (tt_diff_len > bat_priv->soft_iface->mtu)
1026 tvlv_len = batadv_tt_prepare_tvlv_local_data(bat_priv, &tt_data,
1027 &tt_change, &tt_diff_len);
1031 tt_data->flags = BATADV_TT_OGM_DIFF;
1033 if (tt_diff_len == 0)
1034 goto container_register;
1036 spin_lock_bh(&bat_priv->tt.changes_list_lock);
1037 atomic_set(&bat_priv->tt.local_changes, 0);
1039 list_for_each_entry_safe(entry, safe, &bat_priv->tt.changes_list,
1041 if (tt_diff_entries_count < tt_diff_entries_num) {
1042 memcpy(tt_change + tt_diff_entries_count,
1044 sizeof(struct batadv_tvlv_tt_change));
1045 tt_diff_entries_count++;
1047 list_del(&entry->list);
1048 kmem_cache_free(batadv_tt_change_cache, entry);
1050 spin_unlock_bh(&bat_priv->tt.changes_list_lock);
1052 /* Keep the buffer for possible tt_request */
1053 spin_lock_bh(&bat_priv->tt.last_changeset_lock);
1054 kfree(bat_priv->tt.last_changeset);
1055 bat_priv->tt.last_changeset_len = 0;
1056 bat_priv->tt.last_changeset = NULL;
1057 tt_change_len = batadv_tt_len(tt_diff_entries_count);
1058 /* check whether this new OGM has no changes due to size problems */
1059 if (tt_diff_entries_count > 0) {
1060 /* if kmalloc() fails we will reply with the full table
1061 * instead of providing the diff
1063 bat_priv->tt.last_changeset = kzalloc(tt_diff_len, GFP_ATOMIC);
1064 if (bat_priv->tt.last_changeset) {
1065 memcpy(bat_priv->tt.last_changeset,
1066 tt_change, tt_change_len);
1067 bat_priv->tt.last_changeset_len = tt_diff_len;
1070 spin_unlock_bh(&bat_priv->tt.last_changeset_lock);
1073 batadv_tvlv_container_register(bat_priv, BATADV_TVLV_TT, 1, tt_data,
1078 #ifdef CONFIG_BATMAN_ADV_DEBUGFS
1079 int batadv_tt_local_seq_print_text(struct seq_file *seq, void *offset)
1081 struct net_device *net_dev = (struct net_device *)seq->private;
1082 struct batadv_priv *bat_priv = netdev_priv(net_dev);
1083 struct batadv_hashtable *hash = bat_priv->tt.local_hash;
1084 struct batadv_tt_common_entry *tt_common_entry;
1085 struct batadv_tt_local_entry *tt_local;
1086 struct batadv_hard_iface *primary_if;
1087 struct hlist_head *head;
1090 int last_seen_msecs;
1091 unsigned long last_seen_jiffies;
1093 u16 np_flag = BATADV_TT_CLIENT_NOPURGE;
1095 primary_if = batadv_seq_print_text_primary_if_get(seq);
1100 "Locally retrieved addresses (from %s) announced via TT (TTVN: %u):\n",
1101 net_dev->name, (u8)atomic_read(&bat_priv->tt.vn));
1103 " Client VID Flags Last seen (CRC )\n");
1105 for (i = 0; i < hash->size; i++) {
1106 head = &hash->table[i];
1109 hlist_for_each_entry_rcu(tt_common_entry,
1111 tt_local = container_of(tt_common_entry,
1112 struct batadv_tt_local_entry,
1114 last_seen_jiffies = jiffies - tt_local->last_seen;
1115 last_seen_msecs = jiffies_to_msecs(last_seen_jiffies);
1116 last_seen_secs = last_seen_msecs / 1000;
1117 last_seen_msecs = last_seen_msecs % 1000;
1119 no_purge = tt_common_entry->flags & np_flag;
1121 " * %pM %4i [%c%c%c%c%c%c] %3u.%03u (%#.8x)\n",
1122 tt_common_entry->addr,
1123 batadv_print_vid(tt_common_entry->vid),
1124 ((tt_common_entry->flags &
1125 BATADV_TT_CLIENT_ROAM) ? 'R' : '.'),
1126 no_purge ? 'P' : '.',
1127 ((tt_common_entry->flags &
1128 BATADV_TT_CLIENT_NEW) ? 'N' : '.'),
1129 ((tt_common_entry->flags &
1130 BATADV_TT_CLIENT_PENDING) ? 'X' : '.'),
1131 ((tt_common_entry->flags &
1132 BATADV_TT_CLIENT_WIFI) ? 'W' : '.'),
1133 ((tt_common_entry->flags &
1134 BATADV_TT_CLIENT_ISOLA) ? 'I' : '.'),
1135 no_purge ? 0 : last_seen_secs,
1136 no_purge ? 0 : last_seen_msecs,
1137 tt_local->vlan->tt.crc);
1143 batadv_hardif_put(primary_if);
1149 * batadv_tt_local_dump_entry - Dump one TT local entry into a message
1150 * @msg :Netlink message to dump into
1151 * @portid: Port making netlink request
1152 * @seq: Sequence number of netlink message
1153 * @bat_priv: The bat priv with all the soft interface information
1154 * @common: tt local & tt global common data
1156 * Return: Error code, or 0 on success
1159 batadv_tt_local_dump_entry(struct sk_buff *msg, u32 portid, u32 seq,
1160 struct batadv_priv *bat_priv,
1161 struct batadv_tt_common_entry *common)
1164 struct batadv_softif_vlan *vlan;
1165 struct batadv_tt_local_entry *local;
1166 unsigned int last_seen_msecs;
1169 local = container_of(common, struct batadv_tt_local_entry, common);
1170 last_seen_msecs = jiffies_to_msecs(jiffies - local->last_seen);
1172 vlan = batadv_softif_vlan_get(bat_priv, common->vid);
1178 batadv_softif_vlan_put(vlan);
1180 hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family,
1182 BATADV_CMD_GET_TRANSTABLE_LOCAL);
1186 if (nla_put(msg, BATADV_ATTR_TT_ADDRESS, ETH_ALEN, common->addr) ||
1187 nla_put_u32(msg, BATADV_ATTR_TT_CRC32, crc) ||
1188 nla_put_u16(msg, BATADV_ATTR_TT_VID, common->vid) ||
1189 nla_put_u32(msg, BATADV_ATTR_TT_FLAGS, common->flags))
1190 goto nla_put_failure;
1192 if (!(common->flags & BATADV_TT_CLIENT_NOPURGE) &&
1193 nla_put_u32(msg, BATADV_ATTR_LAST_SEEN_MSECS, last_seen_msecs))
1194 goto nla_put_failure;
1196 genlmsg_end(msg, hdr);
1200 genlmsg_cancel(msg, hdr);
1205 * batadv_tt_local_dump_bucket - Dump one TT local bucket into a message
1206 * @msg: Netlink message to dump into
1207 * @portid: Port making netlink request
1208 * @seq: Sequence number of netlink message
1209 * @bat_priv: The bat priv with all the soft interface information
1210 * @head: Pointer to the list containing the local tt entries
1211 * @idx_s: Number of entries to skip
1213 * Return: Error code, or 0 on success
1216 batadv_tt_local_dump_bucket(struct sk_buff *msg, u32 portid, u32 seq,
1217 struct batadv_priv *bat_priv,
1218 struct hlist_head *head, int *idx_s)
1220 struct batadv_tt_common_entry *common;
1224 hlist_for_each_entry_rcu(common, head, hash_entry) {
1228 if (batadv_tt_local_dump_entry(msg, portid, seq, bat_priv,
1242 * batadv_tt_local_dump - Dump TT local entries into a message
1243 * @msg: Netlink message to dump into
1244 * @cb: Parameters from query
1246 * Return: Error code, or 0 on success
1248 int batadv_tt_local_dump(struct sk_buff *msg, struct netlink_callback *cb)
1250 struct net *net = sock_net(cb->skb->sk);
1251 struct net_device *soft_iface;
1252 struct batadv_priv *bat_priv;
1253 struct batadv_hard_iface *primary_if = NULL;
1254 struct batadv_hashtable *hash;
1255 struct hlist_head *head;
1258 int bucket = cb->args[0];
1259 int idx = cb->args[1];
1260 int portid = NETLINK_CB(cb->skb).portid;
1262 ifindex = batadv_netlink_get_ifindex(cb->nlh, BATADV_ATTR_MESH_IFINDEX);
1266 soft_iface = dev_get_by_index(net, ifindex);
1267 if (!soft_iface || !batadv_softif_is_valid(soft_iface)) {
1272 bat_priv = netdev_priv(soft_iface);
1274 primary_if = batadv_primary_if_get_selected(bat_priv);
1275 if (!primary_if || primary_if->if_status != BATADV_IF_ACTIVE) {
1280 hash = bat_priv->tt.local_hash;
1282 while (bucket < hash->size) {
1283 head = &hash->table[bucket];
1285 if (batadv_tt_local_dump_bucket(msg, portid, cb->nlh->nlmsg_seq,
1286 bat_priv, head, &idx))
1296 batadv_hardif_put(primary_if);
1298 dev_put(soft_iface);
1300 cb->args[0] = bucket;
1307 batadv_tt_local_set_pending(struct batadv_priv *bat_priv,
1308 struct batadv_tt_local_entry *tt_local_entry,
1309 u16 flags, const char *message)
1311 batadv_tt_local_event(bat_priv, tt_local_entry, flags);
1313 /* The local client has to be marked as "pending to be removed" but has
1314 * to be kept in the table in order to send it in a full table
1315 * response issued before the net ttvn increment (consistency check)
1317 tt_local_entry->common.flags |= BATADV_TT_CLIENT_PENDING;
1319 batadv_dbg(BATADV_DBG_TT, bat_priv,
1320 "Local tt entry (%pM, vid: %d) pending to be removed: %s\n",
1321 tt_local_entry->common.addr,
1322 batadv_print_vid(tt_local_entry->common.vid), message);
1326 * batadv_tt_local_remove - logically remove an entry from the local table
1327 * @bat_priv: the bat priv with all the soft interface information
1328 * @addr: the MAC address of the client to remove
1329 * @vid: VLAN identifier
1330 * @message: message to append to the log on deletion
1331 * @roaming: true if the deletion is due to a roaming event
1333 * Return: the flags assigned to the local entry before being deleted
1335 u16 batadv_tt_local_remove(struct batadv_priv *bat_priv, const u8 *addr,
1336 unsigned short vid, const char *message,
1339 struct batadv_tt_local_entry *tt_removed_entry;
1340 struct batadv_tt_local_entry *tt_local_entry;
1341 u16 flags, curr_flags = BATADV_NO_FLAGS;
1342 struct hlist_node *tt_removed_node;
1344 tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr, vid);
1345 if (!tt_local_entry)
1348 curr_flags = tt_local_entry->common.flags;
1350 flags = BATADV_TT_CLIENT_DEL;
1351 /* if this global entry addition is due to a roaming, the node has to
1352 * mark the local entry as "roamed" in order to correctly reroute
1356 flags |= BATADV_TT_CLIENT_ROAM;
1357 /* mark the local client as ROAMed */
1358 tt_local_entry->common.flags |= BATADV_TT_CLIENT_ROAM;
1361 if (!(tt_local_entry->common.flags & BATADV_TT_CLIENT_NEW)) {
1362 batadv_tt_local_set_pending(bat_priv, tt_local_entry, flags,
1366 /* if this client has been added right now, it is possible to
1367 * immediately purge it
1369 batadv_tt_local_event(bat_priv, tt_local_entry, BATADV_TT_CLIENT_DEL);
1371 tt_removed_node = batadv_hash_remove(bat_priv->tt.local_hash,
1374 &tt_local_entry->common);
1375 if (!tt_removed_node)
1378 /* drop reference of remove hash entry */
1379 tt_removed_entry = hlist_entry(tt_removed_node,
1380 struct batadv_tt_local_entry,
1382 batadv_tt_local_entry_put(tt_removed_entry);
1386 batadv_tt_local_entry_put(tt_local_entry);
1392 * batadv_tt_local_purge_list - purge inactive tt local entries
1393 * @bat_priv: the bat priv with all the soft interface information
1394 * @head: pointer to the list containing the local tt entries
1395 * @timeout: parameter deciding whether a given tt local entry is considered
1398 static void batadv_tt_local_purge_list(struct batadv_priv *bat_priv,
1399 struct hlist_head *head,
1402 struct batadv_tt_local_entry *tt_local_entry;
1403 struct batadv_tt_common_entry *tt_common_entry;
1404 struct hlist_node *node_tmp;
1406 hlist_for_each_entry_safe(tt_common_entry, node_tmp, head,
1408 tt_local_entry = container_of(tt_common_entry,
1409 struct batadv_tt_local_entry,
1411 if (tt_local_entry->common.flags & BATADV_TT_CLIENT_NOPURGE)
1414 /* entry already marked for deletion */
1415 if (tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING)
1418 if (!batadv_has_timed_out(tt_local_entry->last_seen, timeout))
1421 batadv_tt_local_set_pending(bat_priv, tt_local_entry,
1422 BATADV_TT_CLIENT_DEL, "timed out");
1427 * batadv_tt_local_purge - purge inactive tt local entries
1428 * @bat_priv: the bat priv with all the soft interface information
1429 * @timeout: parameter deciding whether a given tt local entry is considered
1432 static void batadv_tt_local_purge(struct batadv_priv *bat_priv,
1435 struct batadv_hashtable *hash = bat_priv->tt.local_hash;
1436 struct hlist_head *head;
1437 spinlock_t *list_lock; /* protects write access to the hash lists */
1440 for (i = 0; i < hash->size; i++) {
1441 head = &hash->table[i];
1442 list_lock = &hash->list_locks[i];
1444 spin_lock_bh(list_lock);
1445 batadv_tt_local_purge_list(bat_priv, head, timeout);
1446 spin_unlock_bh(list_lock);
1450 static void batadv_tt_local_table_free(struct batadv_priv *bat_priv)
1452 struct batadv_hashtable *hash;
1453 spinlock_t *list_lock; /* protects write access to the hash lists */
1454 struct batadv_tt_common_entry *tt_common_entry;
1455 struct batadv_tt_local_entry *tt_local;
1456 struct hlist_node *node_tmp;
1457 struct hlist_head *head;
1460 if (!bat_priv->tt.local_hash)
1463 hash = bat_priv->tt.local_hash;
1465 for (i = 0; i < hash->size; i++) {
1466 head = &hash->table[i];
1467 list_lock = &hash->list_locks[i];
1469 spin_lock_bh(list_lock);
1470 hlist_for_each_entry_safe(tt_common_entry, node_tmp,
1472 hlist_del_rcu(&tt_common_entry->hash_entry);
1473 tt_local = container_of(tt_common_entry,
1474 struct batadv_tt_local_entry,
1477 batadv_tt_local_entry_put(tt_local);
1479 spin_unlock_bh(list_lock);
1482 batadv_hash_destroy(hash);
1484 bat_priv->tt.local_hash = NULL;
1487 static int batadv_tt_global_init(struct batadv_priv *bat_priv)
1489 if (bat_priv->tt.global_hash)
1492 bat_priv->tt.global_hash = batadv_hash_new(1024);
1494 if (!bat_priv->tt.global_hash)
1497 batadv_hash_set_lock_class(bat_priv->tt.global_hash,
1498 &batadv_tt_global_hash_lock_class_key);
1503 static void batadv_tt_changes_list_free(struct batadv_priv *bat_priv)
1505 struct batadv_tt_change_node *entry, *safe;
1507 spin_lock_bh(&bat_priv->tt.changes_list_lock);
1509 list_for_each_entry_safe(entry, safe, &bat_priv->tt.changes_list,
1511 list_del(&entry->list);
1512 kmem_cache_free(batadv_tt_change_cache, entry);
1515 atomic_set(&bat_priv->tt.local_changes, 0);
1516 spin_unlock_bh(&bat_priv->tt.changes_list_lock);
1520 * batadv_tt_global_orig_entry_find - find a TT orig_list_entry
1521 * @entry: the TT global entry where the orig_list_entry has to be
1523 * @orig_node: the originator for which the orig_list_entry has to be found
1525 * retrieve the orig_tt_list_entry belonging to orig_node from the
1526 * batadv_tt_global_entry list
1528 * Return: it with an increased refcounter, NULL if not found
1530 static struct batadv_tt_orig_list_entry *
1531 batadv_tt_global_orig_entry_find(const struct batadv_tt_global_entry *entry,
1532 const struct batadv_orig_node *orig_node)
1534 struct batadv_tt_orig_list_entry *tmp_orig_entry, *orig_entry = NULL;
1535 const struct hlist_head *head;
1538 head = &entry->orig_list;
1539 hlist_for_each_entry_rcu(tmp_orig_entry, head, list) {
1540 if (tmp_orig_entry->orig_node != orig_node)
1542 if (!kref_get_unless_zero(&tmp_orig_entry->refcount))
1545 orig_entry = tmp_orig_entry;
1554 * batadv_tt_global_entry_has_orig - check if a TT global entry is also handled
1555 * by a given originator
1556 * @entry: the TT global entry to check
1557 * @orig_node: the originator to search in the list
1558 * @flags: a pointer to store TT flags for the given @entry received
1561 * find out if an orig_node is already in the list of a tt_global_entry.
1563 * Return: true if found, false otherwise
1566 batadv_tt_global_entry_has_orig(const struct batadv_tt_global_entry *entry,
1567 const struct batadv_orig_node *orig_node,
1570 struct batadv_tt_orig_list_entry *orig_entry;
1573 orig_entry = batadv_tt_global_orig_entry_find(entry, orig_node);
1578 *flags = orig_entry->flags;
1580 batadv_tt_orig_list_entry_put(orig_entry);
1587 * batadv_tt_global_sync_flags - update TT sync flags
1588 * @tt_global: the TT global entry to update sync flags in
1590 * Updates the sync flag bits in the tt_global flag attribute with a logical
1591 * OR of all sync flags from any of its TT orig entries.
1594 batadv_tt_global_sync_flags(struct batadv_tt_global_entry *tt_global)
1596 struct batadv_tt_orig_list_entry *orig_entry;
1597 const struct hlist_head *head;
1598 u16 flags = BATADV_NO_FLAGS;
1601 head = &tt_global->orig_list;
1602 hlist_for_each_entry_rcu(orig_entry, head, list)
1603 flags |= orig_entry->flags;
1606 flags |= tt_global->common.flags & (~BATADV_TT_SYNC_MASK);
1607 tt_global->common.flags = flags;
1611 * batadv_tt_global_orig_entry_add - add or update a TT orig entry
1612 * @tt_global: the TT global entry to add an orig entry in
1613 * @orig_node: the originator to add an orig entry for
1614 * @ttvn: translation table version number of this changeset
1615 * @flags: TT sync flags
1618 batadv_tt_global_orig_entry_add(struct batadv_tt_global_entry *tt_global,
1619 struct batadv_orig_node *orig_node, int ttvn,
1622 struct batadv_tt_orig_list_entry *orig_entry;
1624 spin_lock_bh(&tt_global->list_lock);
1626 orig_entry = batadv_tt_global_orig_entry_find(tt_global, orig_node);
1628 /* refresh the ttvn: the current value could be a bogus one that
1629 * was added during a "temporary client detection"
1631 orig_entry->ttvn = ttvn;
1632 orig_entry->flags = flags;
1636 orig_entry = kmem_cache_zalloc(batadv_tt_orig_cache, GFP_ATOMIC);
1640 INIT_HLIST_NODE(&orig_entry->list);
1641 kref_get(&orig_node->refcount);
1642 batadv_tt_global_size_inc(orig_node, tt_global->common.vid);
1643 orig_entry->orig_node = orig_node;
1644 orig_entry->ttvn = ttvn;
1645 orig_entry->flags = flags;
1646 kref_init(&orig_entry->refcount);
1648 kref_get(&orig_entry->refcount);
1649 hlist_add_head_rcu(&orig_entry->list,
1650 &tt_global->orig_list);
1651 atomic_inc(&tt_global->orig_list_count);
1654 batadv_tt_global_sync_flags(tt_global);
1657 batadv_tt_orig_list_entry_put(orig_entry);
1659 spin_unlock_bh(&tt_global->list_lock);
1663 * batadv_tt_global_add - add a new TT global entry or update an existing one
1664 * @bat_priv: the bat priv with all the soft interface information
1665 * @orig_node: the originator announcing the client
1666 * @tt_addr: the mac address of the non-mesh client
1667 * @vid: VLAN identifier
1668 * @flags: TT flags that have to be set for this non-mesh client
1669 * @ttvn: the tt version number ever announcing this non-mesh client
1671 * Add a new TT global entry for the given originator. If the entry already
1672 * exists add a new reference to the given originator (a global entry can have
1673 * references to multiple originators) and adjust the flags attribute to reflect
1674 * the function argument.
1675 * If a TT local entry exists for this non-mesh client remove it.
1677 * The caller must hold orig_node refcount.
1679 * Return: true if the new entry has been added, false otherwise
1681 static bool batadv_tt_global_add(struct batadv_priv *bat_priv,
1682 struct batadv_orig_node *orig_node,
1683 const unsigned char *tt_addr,
1684 unsigned short vid, u16 flags, u8 ttvn)
1686 struct batadv_tt_global_entry *tt_global_entry;
1687 struct batadv_tt_local_entry *tt_local_entry;
1690 struct batadv_tt_common_entry *common;
1693 /* ignore global entries from backbone nodes */
1694 if (batadv_bla_is_backbone_gw_orig(bat_priv, orig_node->orig, vid))
1697 tt_global_entry = batadv_tt_global_hash_find(bat_priv, tt_addr, vid);
1698 tt_local_entry = batadv_tt_local_hash_find(bat_priv, tt_addr, vid);
1700 /* if the node already has a local client for this entry, it has to wait
1701 * for a roaming advertisement instead of manually messing up the global
1704 if ((flags & BATADV_TT_CLIENT_TEMP) && tt_local_entry &&
1705 !(tt_local_entry->common.flags & BATADV_TT_CLIENT_NEW))
1708 if (!tt_global_entry) {
1709 tt_global_entry = kmem_cache_zalloc(batadv_tg_cache,
1711 if (!tt_global_entry)
1714 common = &tt_global_entry->common;
1715 ether_addr_copy(common->addr, tt_addr);
1718 if (!is_multicast_ether_addr(common->addr))
1719 common->flags = flags & (~BATADV_TT_SYNC_MASK);
1721 tt_global_entry->roam_at = 0;
1722 /* node must store current time in case of roaming. This is
1723 * needed to purge this entry out on timeout (if nobody claims
1726 if (flags & BATADV_TT_CLIENT_ROAM)
1727 tt_global_entry->roam_at = jiffies;
1728 kref_init(&common->refcount);
1729 common->added_at = jiffies;
1731 INIT_HLIST_HEAD(&tt_global_entry->orig_list);
1732 atomic_set(&tt_global_entry->orig_list_count, 0);
1733 spin_lock_init(&tt_global_entry->list_lock);
1735 kref_get(&common->refcount);
1736 hash_added = batadv_hash_add(bat_priv->tt.global_hash,
1738 batadv_choose_tt, common,
1739 &common->hash_entry);
1741 if (unlikely(hash_added != 0)) {
1742 /* remove the reference for the hash */
1743 batadv_tt_global_entry_put(tt_global_entry);
1747 common = &tt_global_entry->common;
1748 /* If there is already a global entry, we can use this one for
1750 * But if we are trying to add a temporary client then here are
1751 * two options at this point:
1752 * 1) the global client is not a temporary client: the global
1753 * client has to be left as it is, temporary information
1754 * should never override any already known client state
1755 * 2) the global client is a temporary client: purge the
1756 * originator list and add the new one orig_entry
1758 if (flags & BATADV_TT_CLIENT_TEMP) {
1759 if (!(common->flags & BATADV_TT_CLIENT_TEMP))
1761 if (batadv_tt_global_entry_has_orig(tt_global_entry,
1764 batadv_tt_global_del_orig_list(tt_global_entry);
1765 goto add_orig_entry;
1768 /* if the client was temporary added before receiving the first
1769 * OGM announcing it, we have to clear the TEMP flag. Also,
1770 * remove the previous temporary orig node and re-add it
1771 * if required. If the orig entry changed, the new one which
1772 * is a non-temporary entry is preferred.
1774 if (common->flags & BATADV_TT_CLIENT_TEMP) {
1775 batadv_tt_global_del_orig_list(tt_global_entry);
1776 common->flags &= ~BATADV_TT_CLIENT_TEMP;
1779 /* the change can carry possible "attribute" flags like the
1780 * TT_CLIENT_TEMP, therefore they have to be copied in the
1783 if (!is_multicast_ether_addr(common->addr))
1784 common->flags |= flags & (~BATADV_TT_SYNC_MASK);
1786 /* If there is the BATADV_TT_CLIENT_ROAM flag set, there is only
1787 * one originator left in the list and we previously received a
1788 * delete + roaming change for this originator.
1790 * We should first delete the old originator before adding the
1793 if (common->flags & BATADV_TT_CLIENT_ROAM) {
1794 batadv_tt_global_del_orig_list(tt_global_entry);
1795 common->flags &= ~BATADV_TT_CLIENT_ROAM;
1796 tt_global_entry->roam_at = 0;
1800 /* add the new orig_entry (if needed) or update it */
1801 batadv_tt_global_orig_entry_add(tt_global_entry, orig_node, ttvn,
1802 flags & BATADV_TT_SYNC_MASK);
1804 batadv_dbg(BATADV_DBG_TT, bat_priv,
1805 "Creating new global tt entry: %pM (vid: %d, via %pM)\n",
1806 common->addr, batadv_print_vid(common->vid),
1811 /* Do not remove multicast addresses from the local hash on
1814 if (is_multicast_ether_addr(tt_addr))
1817 /* remove address from local hash if present */
1818 local_flags = batadv_tt_local_remove(bat_priv, tt_addr, vid,
1819 "global tt received",
1820 flags & BATADV_TT_CLIENT_ROAM);
1821 tt_global_entry->common.flags |= local_flags & BATADV_TT_CLIENT_WIFI;
1823 if (!(flags & BATADV_TT_CLIENT_ROAM))
1824 /* this is a normal global add. Therefore the client is not in a
1825 * roaming state anymore.
1827 tt_global_entry->common.flags &= ~BATADV_TT_CLIENT_ROAM;
1830 if (tt_global_entry)
1831 batadv_tt_global_entry_put(tt_global_entry);
1833 batadv_tt_local_entry_put(tt_local_entry);
1838 * batadv_transtable_best_orig - Get best originator list entry from tt entry
1839 * @bat_priv: the bat priv with all the soft interface information
1840 * @tt_global_entry: global translation table entry to be analyzed
1842 * This functon assumes the caller holds rcu_read_lock().
1843 * Return: best originator list entry or NULL on errors.
1845 static struct batadv_tt_orig_list_entry *
1846 batadv_transtable_best_orig(struct batadv_priv *bat_priv,
1847 struct batadv_tt_global_entry *tt_global_entry)
1849 struct batadv_neigh_node *router, *best_router = NULL;
1850 struct batadv_algo_ops *bao = bat_priv->algo_ops;
1851 struct hlist_head *head;
1852 struct batadv_tt_orig_list_entry *orig_entry, *best_entry = NULL;
1854 head = &tt_global_entry->orig_list;
1855 hlist_for_each_entry_rcu(orig_entry, head, list) {
1856 router = batadv_orig_router_get(orig_entry->orig_node,
1862 bao->neigh.cmp(router, BATADV_IF_DEFAULT, best_router,
1863 BATADV_IF_DEFAULT) <= 0) {
1864 batadv_neigh_node_put(router);
1868 /* release the refcount for the "old" best */
1870 batadv_neigh_node_put(best_router);
1872 best_entry = orig_entry;
1873 best_router = router;
1877 batadv_neigh_node_put(best_router);
1882 #ifdef CONFIG_BATMAN_ADV_DEBUGFS
1884 * batadv_tt_global_print_entry - print all orig nodes who announce the address
1885 * for this global entry
1886 * @bat_priv: the bat priv with all the soft interface information
1887 * @tt_global_entry: global translation table entry to be printed
1888 * @seq: debugfs table seq_file struct
1890 * This functon assumes the caller holds rcu_read_lock().
1893 batadv_tt_global_print_entry(struct batadv_priv *bat_priv,
1894 struct batadv_tt_global_entry *tt_global_entry,
1895 struct seq_file *seq)
1897 struct batadv_tt_orig_list_entry *orig_entry, *best_entry;
1898 struct batadv_tt_common_entry *tt_common_entry;
1899 struct batadv_orig_node_vlan *vlan;
1900 struct hlist_head *head;
1904 tt_common_entry = &tt_global_entry->common;
1905 flags = tt_common_entry->flags;
1907 best_entry = batadv_transtable_best_orig(bat_priv, tt_global_entry);
1909 vlan = batadv_orig_node_vlan_get(best_entry->orig_node,
1910 tt_common_entry->vid);
1913 " * Cannot retrieve VLAN %d for originator %pM\n",
1914 batadv_print_vid(tt_common_entry->vid),
1915 best_entry->orig_node->orig);
1919 last_ttvn = atomic_read(&best_entry->orig_node->last_ttvn);
1921 " %c %pM %4i (%3u) via %pM (%3u) (%#.8x) [%c%c%c%c]\n",
1922 '*', tt_global_entry->common.addr,
1923 batadv_print_vid(tt_global_entry->common.vid),
1924 best_entry->ttvn, best_entry->orig_node->orig,
1925 last_ttvn, vlan->tt.crc,
1926 ((flags & BATADV_TT_CLIENT_ROAM) ? 'R' : '.'),
1927 ((flags & BATADV_TT_CLIENT_WIFI) ? 'W' : '.'),
1928 ((flags & BATADV_TT_CLIENT_ISOLA) ? 'I' : '.'),
1929 ((flags & BATADV_TT_CLIENT_TEMP) ? 'T' : '.'));
1931 batadv_orig_node_vlan_put(vlan);
1935 head = &tt_global_entry->orig_list;
1937 hlist_for_each_entry_rcu(orig_entry, head, list) {
1938 if (best_entry == orig_entry)
1941 vlan = batadv_orig_node_vlan_get(orig_entry->orig_node,
1942 tt_common_entry->vid);
1945 " + Cannot retrieve VLAN %d for originator %pM\n",
1946 batadv_print_vid(tt_common_entry->vid),
1947 orig_entry->orig_node->orig);
1951 last_ttvn = atomic_read(&orig_entry->orig_node->last_ttvn);
1953 " %c %pM %4d (%3u) via %pM (%3u) (%#.8x) [%c%c%c%c]\n",
1954 '+', tt_global_entry->common.addr,
1955 batadv_print_vid(tt_global_entry->common.vid),
1956 orig_entry->ttvn, orig_entry->orig_node->orig,
1957 last_ttvn, vlan->tt.crc,
1958 ((flags & BATADV_TT_CLIENT_ROAM) ? 'R' : '.'),
1959 ((flags & BATADV_TT_CLIENT_WIFI) ? 'W' : '.'),
1960 ((flags & BATADV_TT_CLIENT_ISOLA) ? 'I' : '.'),
1961 ((flags & BATADV_TT_CLIENT_TEMP) ? 'T' : '.'));
1963 batadv_orig_node_vlan_put(vlan);
1967 int batadv_tt_global_seq_print_text(struct seq_file *seq, void *offset)
1969 struct net_device *net_dev = (struct net_device *)seq->private;
1970 struct batadv_priv *bat_priv = netdev_priv(net_dev);
1971 struct batadv_hashtable *hash = bat_priv->tt.global_hash;
1972 struct batadv_tt_common_entry *tt_common_entry;
1973 struct batadv_tt_global_entry *tt_global;
1974 struct batadv_hard_iface *primary_if;
1975 struct hlist_head *head;
1978 primary_if = batadv_seq_print_text_primary_if_get(seq);
1983 "Globally announced TT entries received via the mesh %s\n",
1986 " Client VID (TTVN) Originator (Curr TTVN) (CRC ) Flags\n");
1988 for (i = 0; i < hash->size; i++) {
1989 head = &hash->table[i];
1992 hlist_for_each_entry_rcu(tt_common_entry,
1994 tt_global = container_of(tt_common_entry,
1995 struct batadv_tt_global_entry,
1997 batadv_tt_global_print_entry(bat_priv, tt_global, seq);
2003 batadv_hardif_put(primary_if);
2009 * batadv_tt_global_dump_subentry - Dump all TT local entries into a message
2010 * @msg: Netlink message to dump into
2011 * @portid: Port making netlink request
2012 * @seq: Sequence number of netlink message
2013 * @common: tt local & tt global common data
2014 * @orig: Originator node announcing a non-mesh client
2015 * @best: Is the best originator for the TT entry
2017 * Return: Error code, or 0 on success
2020 batadv_tt_global_dump_subentry(struct sk_buff *msg, u32 portid, u32 seq,
2021 struct batadv_tt_common_entry *common,
2022 struct batadv_tt_orig_list_entry *orig,
2025 u16 flags = (common->flags & (~BATADV_TT_SYNC_MASK)) | orig->flags;
2027 struct batadv_orig_node_vlan *vlan;
2031 vlan = batadv_orig_node_vlan_get(orig->orig_node,
2038 batadv_orig_node_vlan_put(vlan);
2040 hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family,
2042 BATADV_CMD_GET_TRANSTABLE_GLOBAL);
2046 last_ttvn = atomic_read(&orig->orig_node->last_ttvn);
2048 if (nla_put(msg, BATADV_ATTR_TT_ADDRESS, ETH_ALEN, common->addr) ||
2049 nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN,
2050 orig->orig_node->orig) ||
2051 nla_put_u8(msg, BATADV_ATTR_TT_TTVN, orig->ttvn) ||
2052 nla_put_u8(msg, BATADV_ATTR_TT_LAST_TTVN, last_ttvn) ||
2053 nla_put_u32(msg, BATADV_ATTR_TT_CRC32, crc) ||
2054 nla_put_u16(msg, BATADV_ATTR_TT_VID, common->vid) ||
2055 nla_put_u32(msg, BATADV_ATTR_TT_FLAGS, flags))
2056 goto nla_put_failure;
2058 if (best && nla_put_flag(msg, BATADV_ATTR_FLAG_BEST))
2059 goto nla_put_failure;
2061 genlmsg_end(msg, hdr);
2065 genlmsg_cancel(msg, hdr);
2070 * batadv_tt_global_dump_entry - Dump one TT global entry into a message
2071 * @msg: Netlink message to dump into
2072 * @portid: Port making netlink request
2073 * @seq: Sequence number of netlink message
2074 * @bat_priv: The bat priv with all the soft interface information
2075 * @common: tt local & tt global common data
2076 * @sub_s: Number of entries to skip
2078 * This function assumes the caller holds rcu_read_lock().
2080 * Return: Error code, or 0 on success
2083 batadv_tt_global_dump_entry(struct sk_buff *msg, u32 portid, u32 seq,
2084 struct batadv_priv *bat_priv,
2085 struct batadv_tt_common_entry *common, int *sub_s)
2087 struct batadv_tt_orig_list_entry *orig_entry, *best_entry;
2088 struct batadv_tt_global_entry *global;
2089 struct hlist_head *head;
2093 global = container_of(common, struct batadv_tt_global_entry, common);
2094 best_entry = batadv_transtable_best_orig(bat_priv, global);
2095 head = &global->orig_list;
2097 hlist_for_each_entry_rcu(orig_entry, head, list) {
2101 best = (orig_entry == best_entry);
2103 if (batadv_tt_global_dump_subentry(msg, portid, seq, common,
2104 orig_entry, best)) {
2115 * batadv_tt_global_dump_bucket - Dump one TT local bucket into a message
2116 * @msg: Netlink message to dump into
2117 * @portid: Port making netlink request
2118 * @seq: Sequence number of netlink message
2119 * @bat_priv: The bat priv with all the soft interface information
2120 * @head: Pointer to the list containing the global tt entries
2121 * @idx_s: Number of entries to skip
2122 * @sub: Number of entries to skip
2124 * Return: Error code, or 0 on success
2127 batadv_tt_global_dump_bucket(struct sk_buff *msg, u32 portid, u32 seq,
2128 struct batadv_priv *bat_priv,
2129 struct hlist_head *head, int *idx_s, int *sub)
2131 struct batadv_tt_common_entry *common;
2135 hlist_for_each_entry_rcu(common, head, hash_entry) {
2139 if (batadv_tt_global_dump_entry(msg, portid, seq, bat_priv,
2154 * batadv_tt_global_dump - Dump TT global entries into a message
2155 * @msg: Netlink message to dump into
2156 * @cb: Parameters from query
2158 * Return: Error code, or length of message on success
2160 int batadv_tt_global_dump(struct sk_buff *msg, struct netlink_callback *cb)
2162 struct net *net = sock_net(cb->skb->sk);
2163 struct net_device *soft_iface;
2164 struct batadv_priv *bat_priv;
2165 struct batadv_hard_iface *primary_if = NULL;
2166 struct batadv_hashtable *hash;
2167 struct hlist_head *head;
2170 int bucket = cb->args[0];
2171 int idx = cb->args[1];
2172 int sub = cb->args[2];
2173 int portid = NETLINK_CB(cb->skb).portid;
2175 ifindex = batadv_netlink_get_ifindex(cb->nlh, BATADV_ATTR_MESH_IFINDEX);
2179 soft_iface = dev_get_by_index(net, ifindex);
2180 if (!soft_iface || !batadv_softif_is_valid(soft_iface)) {
2185 bat_priv = netdev_priv(soft_iface);
2187 primary_if = batadv_primary_if_get_selected(bat_priv);
2188 if (!primary_if || primary_if->if_status != BATADV_IF_ACTIVE) {
2193 hash = bat_priv->tt.global_hash;
2195 while (bucket < hash->size) {
2196 head = &hash->table[bucket];
2198 if (batadv_tt_global_dump_bucket(msg, portid,
2199 cb->nlh->nlmsg_seq, bat_priv,
2210 batadv_hardif_put(primary_if);
2212 dev_put(soft_iface);
2214 cb->args[0] = bucket;
2222 * _batadv_tt_global_del_orig_entry - remove and free an orig_entry
2223 * @tt_global_entry: the global entry to remove the orig_entry from
2224 * @orig_entry: the orig entry to remove and free
2226 * Remove an orig_entry from its list in the given tt_global_entry and
2227 * free this orig_entry afterwards.
2229 * Caller must hold tt_global_entry->list_lock and ensure orig_entry->list is
2233 _batadv_tt_global_del_orig_entry(struct batadv_tt_global_entry *tt_global_entry,
2234 struct batadv_tt_orig_list_entry *orig_entry)
2236 lockdep_assert_held(&tt_global_entry->list_lock);
2238 batadv_tt_global_size_dec(orig_entry->orig_node,
2239 tt_global_entry->common.vid);
2240 atomic_dec(&tt_global_entry->orig_list_count);
2241 /* requires holding tt_global_entry->list_lock and orig_entry->list
2242 * being part of a list
2244 hlist_del_rcu(&orig_entry->list);
2245 batadv_tt_orig_list_entry_put(orig_entry);
2248 /* deletes the orig list of a tt_global_entry */
2250 batadv_tt_global_del_orig_list(struct batadv_tt_global_entry *tt_global_entry)
2252 struct hlist_head *head;
2253 struct hlist_node *safe;
2254 struct batadv_tt_orig_list_entry *orig_entry;
2256 spin_lock_bh(&tt_global_entry->list_lock);
2257 head = &tt_global_entry->orig_list;
2258 hlist_for_each_entry_safe(orig_entry, safe, head, list)
2259 _batadv_tt_global_del_orig_entry(tt_global_entry, orig_entry);
2260 spin_unlock_bh(&tt_global_entry->list_lock);
2264 * batadv_tt_global_del_orig_node - remove orig_node from a global tt entry
2265 * @bat_priv: the bat priv with all the soft interface information
2266 * @tt_global_entry: the global entry to remove the orig_node from
2267 * @orig_node: the originator announcing the client
2268 * @message: message to append to the log on deletion
2270 * Remove the given orig_node and its according orig_entry from the given
2274 batadv_tt_global_del_orig_node(struct batadv_priv *bat_priv,
2275 struct batadv_tt_global_entry *tt_global_entry,
2276 struct batadv_orig_node *orig_node,
2277 const char *message)
2279 struct hlist_head *head;
2280 struct hlist_node *safe;
2281 struct batadv_tt_orig_list_entry *orig_entry;
2284 spin_lock_bh(&tt_global_entry->list_lock);
2285 head = &tt_global_entry->orig_list;
2286 hlist_for_each_entry_safe(orig_entry, safe, head, list) {
2287 if (orig_entry->orig_node == orig_node) {
2288 vid = tt_global_entry->common.vid;
2289 batadv_dbg(BATADV_DBG_TT, bat_priv,
2290 "Deleting %pM from global tt entry %pM (vid: %d): %s\n",
2292 tt_global_entry->common.addr,
2293 batadv_print_vid(vid), message);
2294 _batadv_tt_global_del_orig_entry(tt_global_entry,
2298 spin_unlock_bh(&tt_global_entry->list_lock);
2301 /* If the client is to be deleted, we check if it is the last origantor entry
2302 * within tt_global entry. If yes, we set the BATADV_TT_CLIENT_ROAM flag and the
2303 * timer, otherwise we simply remove the originator scheduled for deletion.
2306 batadv_tt_global_del_roaming(struct batadv_priv *bat_priv,
2307 struct batadv_tt_global_entry *tt_global_entry,
2308 struct batadv_orig_node *orig_node,
2309 const char *message)
2311 bool last_entry = true;
2312 struct hlist_head *head;
2313 struct batadv_tt_orig_list_entry *orig_entry;
2315 /* no local entry exists, case 1:
2316 * Check if this is the last one or if other entries exist.
2320 head = &tt_global_entry->orig_list;
2321 hlist_for_each_entry_rcu(orig_entry, head, list) {
2322 if (orig_entry->orig_node != orig_node) {
2330 /* its the last one, mark for roaming. */
2331 tt_global_entry->common.flags |= BATADV_TT_CLIENT_ROAM;
2332 tt_global_entry->roam_at = jiffies;
2334 /* there is another entry, we can simply delete this
2335 * one and can still use the other one.
2337 batadv_tt_global_del_orig_node(bat_priv, tt_global_entry,
2338 orig_node, message);
2343 * batadv_tt_global_del - remove a client from the global table
2344 * @bat_priv: the bat priv with all the soft interface information
2345 * @orig_node: an originator serving this client
2346 * @addr: the mac address of the client
2347 * @vid: VLAN identifier
2348 * @message: a message explaining the reason for deleting the client to print
2349 * for debugging purpose
2350 * @roaming: true if the deletion has been triggered by a roaming event
2352 static void batadv_tt_global_del(struct batadv_priv *bat_priv,
2353 struct batadv_orig_node *orig_node,
2354 const unsigned char *addr, unsigned short vid,
2355 const char *message, bool roaming)
2357 struct batadv_tt_global_entry *tt_global_entry;
2358 struct batadv_tt_local_entry *local_entry = NULL;
2360 tt_global_entry = batadv_tt_global_hash_find(bat_priv, addr, vid);
2361 if (!tt_global_entry)
2365 batadv_tt_global_del_orig_node(bat_priv, tt_global_entry,
2366 orig_node, message);
2368 if (hlist_empty(&tt_global_entry->orig_list))
2369 batadv_tt_global_free(bat_priv, tt_global_entry,
2375 /* if we are deleting a global entry due to a roam
2376 * event, there are two possibilities:
2377 * 1) the client roamed from node A to node B => if there
2378 * is only one originator left for this client, we mark
2379 * it with BATADV_TT_CLIENT_ROAM, we start a timer and we
2380 * wait for node B to claim it. In case of timeout
2381 * the entry is purged.
2383 * If there are other originators left, we directly delete
2385 * 2) the client roamed to us => we can directly delete
2386 * the global entry, since it is useless now.
2388 local_entry = batadv_tt_local_hash_find(bat_priv,
2389 tt_global_entry->common.addr,
2392 /* local entry exists, case 2: client roamed to us. */
2393 batadv_tt_global_del_orig_list(tt_global_entry);
2394 batadv_tt_global_free(bat_priv, tt_global_entry, message);
2396 /* no local entry exists, case 1: check for roaming */
2397 batadv_tt_global_del_roaming(bat_priv, tt_global_entry,
2398 orig_node, message);
2402 if (tt_global_entry)
2403 batadv_tt_global_entry_put(tt_global_entry);
2405 batadv_tt_local_entry_put(local_entry);
2409 * batadv_tt_global_del_orig - remove all the TT global entries belonging to the
2410 * given originator matching the provided vid
2411 * @bat_priv: the bat priv with all the soft interface information
2412 * @orig_node: the originator owning the entries to remove
2413 * @match_vid: the VLAN identifier to match. If negative all the entries will be
2415 * @message: debug message to print as "reason"
2417 void batadv_tt_global_del_orig(struct batadv_priv *bat_priv,
2418 struct batadv_orig_node *orig_node,
2420 const char *message)
2422 struct batadv_tt_global_entry *tt_global;
2423 struct batadv_tt_common_entry *tt_common_entry;
2425 struct batadv_hashtable *hash = bat_priv->tt.global_hash;
2426 struct hlist_node *safe;
2427 struct hlist_head *head;
2428 spinlock_t *list_lock; /* protects write access to the hash lists */
2434 for (i = 0; i < hash->size; i++) {
2435 head = &hash->table[i];
2436 list_lock = &hash->list_locks[i];
2438 spin_lock_bh(list_lock);
2439 hlist_for_each_entry_safe(tt_common_entry, safe,
2441 /* remove only matching entries */
2442 if (match_vid >= 0 && tt_common_entry->vid != match_vid)
2445 tt_global = container_of(tt_common_entry,
2446 struct batadv_tt_global_entry,
2449 batadv_tt_global_del_orig_node(bat_priv, tt_global,
2450 orig_node, message);
2452 if (hlist_empty(&tt_global->orig_list)) {
2453 vid = tt_global->common.vid;
2454 batadv_dbg(BATADV_DBG_TT, bat_priv,
2455 "Deleting global tt entry %pM (vid: %d): %s\n",
2456 tt_global->common.addr,
2457 batadv_print_vid(vid), message);
2458 hlist_del_rcu(&tt_common_entry->hash_entry);
2459 batadv_tt_global_entry_put(tt_global);
2462 spin_unlock_bh(list_lock);
2464 clear_bit(BATADV_ORIG_CAPA_HAS_TT, &orig_node->capa_initialized);
2467 static bool batadv_tt_global_to_purge(struct batadv_tt_global_entry *tt_global,
2471 unsigned long roam_timeout = BATADV_TT_CLIENT_ROAM_TIMEOUT;
2472 unsigned long temp_timeout = BATADV_TT_CLIENT_TEMP_TIMEOUT;
2474 if ((tt_global->common.flags & BATADV_TT_CLIENT_ROAM) &&
2475 batadv_has_timed_out(tt_global->roam_at, roam_timeout)) {
2477 *msg = "Roaming timeout\n";
2480 if ((tt_global->common.flags & BATADV_TT_CLIENT_TEMP) &&
2481 batadv_has_timed_out(tt_global->common.added_at, temp_timeout)) {
2483 *msg = "Temporary client timeout\n";
2489 static void batadv_tt_global_purge(struct batadv_priv *bat_priv)
2491 struct batadv_hashtable *hash = bat_priv->tt.global_hash;
2492 struct hlist_head *head;
2493 struct hlist_node *node_tmp;
2494 spinlock_t *list_lock; /* protects write access to the hash lists */
2497 struct batadv_tt_common_entry *tt_common;
2498 struct batadv_tt_global_entry *tt_global;
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 tt_global = container_of(tt_common,
2508 struct batadv_tt_global_entry,
2511 if (!batadv_tt_global_to_purge(tt_global, &msg))
2514 batadv_dbg(BATADV_DBG_TT, bat_priv,
2515 "Deleting global tt entry %pM (vid: %d): %s\n",
2516 tt_global->common.addr,
2517 batadv_print_vid(tt_global->common.vid),
2520 hlist_del_rcu(&tt_common->hash_entry);
2522 batadv_tt_global_entry_put(tt_global);
2524 spin_unlock_bh(list_lock);
2528 static void batadv_tt_global_table_free(struct batadv_priv *bat_priv)
2530 struct batadv_hashtable *hash;
2531 spinlock_t *list_lock; /* protects write access to the hash lists */
2532 struct batadv_tt_common_entry *tt_common_entry;
2533 struct batadv_tt_global_entry *tt_global;
2534 struct hlist_node *node_tmp;
2535 struct hlist_head *head;
2538 if (!bat_priv->tt.global_hash)
2541 hash = bat_priv->tt.global_hash;
2543 for (i = 0; i < hash->size; i++) {
2544 head = &hash->table[i];
2545 list_lock = &hash->list_locks[i];
2547 spin_lock_bh(list_lock);
2548 hlist_for_each_entry_safe(tt_common_entry, node_tmp,
2550 hlist_del_rcu(&tt_common_entry->hash_entry);
2551 tt_global = container_of(tt_common_entry,
2552 struct batadv_tt_global_entry,
2554 batadv_tt_global_entry_put(tt_global);
2556 spin_unlock_bh(list_lock);
2559 batadv_hash_destroy(hash);
2561 bat_priv->tt.global_hash = NULL;
2565 _batadv_is_ap_isolated(struct batadv_tt_local_entry *tt_local_entry,
2566 struct batadv_tt_global_entry *tt_global_entry)
2568 if (tt_local_entry->common.flags & BATADV_TT_CLIENT_WIFI &&
2569 tt_global_entry->common.flags & BATADV_TT_CLIENT_WIFI)
2572 /* check if the two clients are marked as isolated */
2573 if (tt_local_entry->common.flags & BATADV_TT_CLIENT_ISOLA &&
2574 tt_global_entry->common.flags & BATADV_TT_CLIENT_ISOLA)
2581 * batadv_transtable_search - get the mesh destination for a given client
2582 * @bat_priv: the bat priv with all the soft interface information
2583 * @src: mac address of the source client
2584 * @addr: mac address of the destination client
2585 * @vid: VLAN identifier
2587 * Return: a pointer to the originator that was selected as destination in the
2588 * mesh for contacting the client 'addr', NULL otherwise.
2589 * In case of multiple originators serving the same client, the function returns
2590 * the best one (best in terms of metric towards the destination node).
2592 * If the two clients are AP isolated the function returns NULL.
2594 struct batadv_orig_node *batadv_transtable_search(struct batadv_priv *bat_priv,
2599 struct batadv_tt_local_entry *tt_local_entry = NULL;
2600 struct batadv_tt_global_entry *tt_global_entry = NULL;
2601 struct batadv_orig_node *orig_node = NULL;
2602 struct batadv_tt_orig_list_entry *best_entry;
2604 if (src && batadv_vlan_ap_isola_get(bat_priv, vid)) {
2605 tt_local_entry = batadv_tt_local_hash_find(bat_priv, src, vid);
2606 if (!tt_local_entry ||
2607 (tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING))
2611 tt_global_entry = batadv_tt_global_hash_find(bat_priv, addr, vid);
2612 if (!tt_global_entry)
2615 /* check whether the clients should not communicate due to AP
2618 if (tt_local_entry &&
2619 _batadv_is_ap_isolated(tt_local_entry, tt_global_entry))
2623 best_entry = batadv_transtable_best_orig(bat_priv, tt_global_entry);
2624 /* found anything? */
2626 orig_node = best_entry->orig_node;
2627 if (orig_node && !kref_get_unless_zero(&orig_node->refcount))
2632 if (tt_global_entry)
2633 batadv_tt_global_entry_put(tt_global_entry);
2635 batadv_tt_local_entry_put(tt_local_entry);
2641 * batadv_tt_global_crc - calculates the checksum of the local table belonging
2642 * to the given orig_node
2643 * @bat_priv: the bat priv with all the soft interface information
2644 * @orig_node: originator for which the CRC should be computed
2645 * @vid: VLAN identifier for which the CRC32 has to be computed
2647 * This function computes the checksum for the global table corresponding to a
2648 * specific originator. In particular, the checksum is computed as follows: For
2649 * each client connected to the originator the CRC32C of the MAC address and the
2650 * VID is computed and then all the CRC32Cs of the various clients are xor'ed
2653 * The idea behind is that CRC32C should be used as much as possible in order to
2654 * produce a unique hash of the table, but since the order which is used to feed
2655 * the CRC32C function affects the result and since every node in the network
2656 * probably sorts the clients differently, the hash function cannot be directly
2657 * computed over the entire table. Hence the CRC32C is used only on
2658 * the single client entry, while all the results are then xor'ed together
2659 * because the XOR operation can combine them all while trying to reduce the
2660 * noise as much as possible.
2662 * Return: the checksum of the global table of a given originator.
2664 static u32 batadv_tt_global_crc(struct batadv_priv *bat_priv,
2665 struct batadv_orig_node *orig_node,
2668 struct batadv_hashtable *hash = bat_priv->tt.global_hash;
2669 struct batadv_tt_orig_list_entry *tt_orig;
2670 struct batadv_tt_common_entry *tt_common;
2671 struct batadv_tt_global_entry *tt_global;
2672 struct hlist_head *head;
2673 u32 i, crc_tmp, crc = 0;
2677 for (i = 0; i < hash->size; i++) {
2678 head = &hash->table[i];
2681 hlist_for_each_entry_rcu(tt_common, head, hash_entry) {
2682 tt_global = container_of(tt_common,
2683 struct batadv_tt_global_entry,
2685 /* compute the CRC only for entries belonging to the
2686 * VLAN identified by the vid passed as parameter
2688 if (tt_common->vid != vid)
2691 /* Roaming clients are in the global table for
2692 * consistency only. They don't have to be
2693 * taken into account while computing the
2696 if (tt_common->flags & BATADV_TT_CLIENT_ROAM)
2698 /* Temporary clients have not been announced yet, so
2699 * they have to be skipped while computing the global
2702 if (tt_common->flags & BATADV_TT_CLIENT_TEMP)
2705 /* find out if this global entry is announced by this
2708 tt_orig = batadv_tt_global_orig_entry_find(tt_global,
2713 /* use network order to read the VID: this ensures that
2714 * every node reads the bytes in the same order.
2716 tmp_vid = htons(tt_common->vid);
2717 crc_tmp = crc32c(0, &tmp_vid, sizeof(tmp_vid));
2719 /* compute the CRC on flags that have to be kept in sync
2722 flags = tt_orig->flags;
2723 crc_tmp = crc32c(crc_tmp, &flags, sizeof(flags));
2725 crc ^= crc32c(crc_tmp, tt_common->addr, ETH_ALEN);
2727 batadv_tt_orig_list_entry_put(tt_orig);
2736 * batadv_tt_local_crc - calculates the checksum of the local table
2737 * @bat_priv: the bat priv with all the soft interface information
2738 * @vid: VLAN identifier for which the CRC32 has to be computed
2740 * For details about the computation, please refer to the documentation for
2741 * batadv_tt_global_crc().
2743 * Return: the checksum of the local table
2745 static u32 batadv_tt_local_crc(struct batadv_priv *bat_priv,
2748 struct batadv_hashtable *hash = bat_priv->tt.local_hash;
2749 struct batadv_tt_common_entry *tt_common;
2750 struct hlist_head *head;
2751 u32 i, crc_tmp, crc = 0;
2755 for (i = 0; i < hash->size; i++) {
2756 head = &hash->table[i];
2759 hlist_for_each_entry_rcu(tt_common, head, hash_entry) {
2760 /* compute the CRC only for entries belonging to the
2761 * VLAN identified by vid
2763 if (tt_common->vid != vid)
2766 /* not yet committed clients have not to be taken into
2767 * account while computing the CRC
2769 if (tt_common->flags & BATADV_TT_CLIENT_NEW)
2772 /* use network order to read the VID: this ensures that
2773 * every node reads the bytes in the same order.
2775 tmp_vid = htons(tt_common->vid);
2776 crc_tmp = crc32c(0, &tmp_vid, sizeof(tmp_vid));
2778 /* compute the CRC on flags that have to be kept in sync
2781 flags = tt_common->flags & BATADV_TT_SYNC_MASK;
2782 crc_tmp = crc32c(crc_tmp, &flags, sizeof(flags));
2784 crc ^= crc32c(crc_tmp, tt_common->addr, ETH_ALEN);
2793 * batadv_tt_req_node_release - free tt_req node entry
2794 * @ref: kref pointer of the tt req_node entry
2796 static void batadv_tt_req_node_release(struct kref *ref)
2798 struct batadv_tt_req_node *tt_req_node;
2800 tt_req_node = container_of(ref, struct batadv_tt_req_node, refcount);
2802 kmem_cache_free(batadv_tt_req_cache, tt_req_node);
2806 * batadv_tt_req_node_put - decrement the tt_req_node refcounter and
2807 * possibly release it
2808 * @tt_req_node: tt_req_node to be free'd
2810 static void batadv_tt_req_node_put(struct batadv_tt_req_node *tt_req_node)
2812 kref_put(&tt_req_node->refcount, batadv_tt_req_node_release);
2815 static void batadv_tt_req_list_free(struct batadv_priv *bat_priv)
2817 struct batadv_tt_req_node *node;
2818 struct hlist_node *safe;
2820 spin_lock_bh(&bat_priv->tt.req_list_lock);
2822 hlist_for_each_entry_safe(node, safe, &bat_priv->tt.req_list, list) {
2823 hlist_del_init(&node->list);
2824 batadv_tt_req_node_put(node);
2827 spin_unlock_bh(&bat_priv->tt.req_list_lock);
2830 static void batadv_tt_save_orig_buffer(struct batadv_priv *bat_priv,
2831 struct batadv_orig_node *orig_node,
2832 const void *tt_buff,
2835 /* Replace the old buffer only if I received something in the
2836 * last OGM (the OGM could carry no changes)
2838 spin_lock_bh(&orig_node->tt_buff_lock);
2839 if (tt_buff_len > 0) {
2840 kfree(orig_node->tt_buff);
2841 orig_node->tt_buff_len = 0;
2842 orig_node->tt_buff = kmalloc(tt_buff_len, GFP_ATOMIC);
2843 if (orig_node->tt_buff) {
2844 memcpy(orig_node->tt_buff, tt_buff, tt_buff_len);
2845 orig_node->tt_buff_len = tt_buff_len;
2848 spin_unlock_bh(&orig_node->tt_buff_lock);
2851 static void batadv_tt_req_purge(struct batadv_priv *bat_priv)
2853 struct batadv_tt_req_node *node;
2854 struct hlist_node *safe;
2856 spin_lock_bh(&bat_priv->tt.req_list_lock);
2857 hlist_for_each_entry_safe(node, safe, &bat_priv->tt.req_list, list) {
2858 if (batadv_has_timed_out(node->issued_at,
2859 BATADV_TT_REQUEST_TIMEOUT)) {
2860 hlist_del_init(&node->list);
2861 batadv_tt_req_node_put(node);
2864 spin_unlock_bh(&bat_priv->tt.req_list_lock);
2868 * batadv_tt_req_node_new - search and possibly create a tt_req_node object
2869 * @bat_priv: the bat priv with all the soft interface information
2870 * @orig_node: orig node this request is being issued for
2872 * Return: the pointer to the new tt_req_node struct if no request
2873 * has already been issued for this orig_node, NULL otherwise.
2875 static struct batadv_tt_req_node *
2876 batadv_tt_req_node_new(struct batadv_priv *bat_priv,
2877 struct batadv_orig_node *orig_node)
2879 struct batadv_tt_req_node *tt_req_node_tmp, *tt_req_node = NULL;
2881 spin_lock_bh(&bat_priv->tt.req_list_lock);
2882 hlist_for_each_entry(tt_req_node_tmp, &bat_priv->tt.req_list, list) {
2883 if (batadv_compare_eth(tt_req_node_tmp, orig_node) &&
2884 !batadv_has_timed_out(tt_req_node_tmp->issued_at,
2885 BATADV_TT_REQUEST_TIMEOUT))
2889 tt_req_node = kmem_cache_alloc(batadv_tt_req_cache, GFP_ATOMIC);
2893 kref_init(&tt_req_node->refcount);
2894 ether_addr_copy(tt_req_node->addr, orig_node->orig);
2895 tt_req_node->issued_at = jiffies;
2897 kref_get(&tt_req_node->refcount);
2898 hlist_add_head(&tt_req_node->list, &bat_priv->tt.req_list);
2900 spin_unlock_bh(&bat_priv->tt.req_list_lock);
2905 * batadv_tt_local_valid() - verify local tt entry and get flags
2906 * @entry_ptr: to be checked local tt entry
2907 * @data_ptr: not used but definition required to satisfy the callback prototype
2908 * @flags: a pointer to store TT flags for this client to
2910 * Checks the validity of the given local TT entry. If it is, then the provided
2911 * flags pointer is updated.
2913 * Return: true if the entry is a valid, false otherwise.
2915 static bool batadv_tt_local_valid(const void *entry_ptr,
2916 const void *data_ptr,
2919 const struct batadv_tt_common_entry *tt_common_entry = entry_ptr;
2921 if (tt_common_entry->flags & BATADV_TT_CLIENT_NEW)
2925 *flags = tt_common_entry->flags;
2931 * batadv_tt_global_valid() - verify global tt entry and get flags
2932 * @entry_ptr: to be checked global tt entry
2933 * @data_ptr: an orig_node object (may be NULL)
2934 * @flags: a pointer to store TT flags for this client to
2936 * Checks the validity of the given global TT entry. If it is, then the provided
2937 * flags pointer is updated either with the common (summed) TT flags if data_ptr
2938 * is NULL or the specific, per originator TT flags otherwise.
2940 * Return: true if the entry is a valid, false otherwise.
2942 static bool batadv_tt_global_valid(const void *entry_ptr,
2943 const void *data_ptr,
2946 const struct batadv_tt_common_entry *tt_common_entry = entry_ptr;
2947 const struct batadv_tt_global_entry *tt_global_entry;
2948 const struct batadv_orig_node *orig_node = data_ptr;
2950 if (tt_common_entry->flags & BATADV_TT_CLIENT_ROAM ||
2951 tt_common_entry->flags & BATADV_TT_CLIENT_TEMP)
2954 tt_global_entry = container_of(tt_common_entry,
2955 struct batadv_tt_global_entry,
2958 return batadv_tt_global_entry_has_orig(tt_global_entry, orig_node,
2963 * batadv_tt_tvlv_generate - fill the tvlv buff with the tt entries from the
2965 * @bat_priv: the bat priv with all the soft interface information
2966 * @hash: hash table containing the tt entries
2967 * @tt_len: expected tvlv tt data buffer length in number of bytes
2968 * @tvlv_buff: pointer to the buffer to fill with the TT data
2969 * @valid_cb: function to filter tt change entries and to return TT flags
2970 * @cb_data: data passed to the filter function as argument
2972 * Fills the tvlv buff with the tt entries from the specified hash. If valid_cb
2973 * is not provided then this becomes a no-op.
2975 static void batadv_tt_tvlv_generate(struct batadv_priv *bat_priv,
2976 struct batadv_hashtable *hash,
2977 void *tvlv_buff, u16 tt_len,
2978 bool (*valid_cb)(const void *,
2983 struct batadv_tt_common_entry *tt_common_entry;
2984 struct batadv_tvlv_tt_change *tt_change;
2985 struct hlist_head *head;
2986 u16 tt_tot, tt_num_entries = 0;
2991 tt_tot = batadv_tt_entries(tt_len);
2992 tt_change = (struct batadv_tvlv_tt_change *)tvlv_buff;
2998 for (i = 0; i < hash->size; i++) {
2999 head = &hash->table[i];
3001 hlist_for_each_entry_rcu(tt_common_entry,
3003 if (tt_tot == tt_num_entries)
3006 ret = valid_cb(tt_common_entry, cb_data, &flags);
3010 ether_addr_copy(tt_change->addr, tt_common_entry->addr);
3011 tt_change->flags = flags;
3012 tt_change->vid = htons(tt_common_entry->vid);
3013 memset(tt_change->reserved, 0,
3014 sizeof(tt_change->reserved));
3024 * batadv_tt_global_check_crc - check if all the CRCs are correct
3025 * @orig_node: originator for which the CRCs have to be checked
3026 * @tt_vlan: pointer to the first tvlv VLAN entry
3027 * @num_vlan: number of tvlv VLAN entries
3029 * Return: true if all the received CRCs match the locally stored ones, false
3032 static bool batadv_tt_global_check_crc(struct batadv_orig_node *orig_node,
3033 struct batadv_tvlv_tt_vlan_data *tt_vlan,
3036 struct batadv_tvlv_tt_vlan_data *tt_vlan_tmp;
3037 struct batadv_orig_node_vlan *vlan;
3038 int i, orig_num_vlan;
3041 /* check if each received CRC matches the locally stored one */
3042 for (i = 0; i < num_vlan; i++) {
3043 tt_vlan_tmp = tt_vlan + i;
3045 /* if orig_node is a backbone node for this VLAN, don't check
3046 * the CRC as we ignore all the global entries over it
3048 if (batadv_bla_is_backbone_gw_orig(orig_node->bat_priv,
3050 ntohs(tt_vlan_tmp->vid)))
3053 vlan = batadv_orig_node_vlan_get(orig_node,
3054 ntohs(tt_vlan_tmp->vid));
3059 batadv_orig_node_vlan_put(vlan);
3061 if (crc != ntohl(tt_vlan_tmp->crc))
3065 /* check if any excess VLANs exist locally for the originator
3066 * which are not mentioned in the TVLV from the originator.
3070 hlist_for_each_entry_rcu(vlan, &orig_node->vlan_list, list)
3074 if (orig_num_vlan > num_vlan)
3081 * batadv_tt_local_update_crc - update all the local CRCs
3082 * @bat_priv: the bat priv with all the soft interface information
3084 static void batadv_tt_local_update_crc(struct batadv_priv *bat_priv)
3086 struct batadv_softif_vlan *vlan;
3088 /* recompute the global CRC for each VLAN */
3090 hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list) {
3091 vlan->tt.crc = batadv_tt_local_crc(bat_priv, vlan->vid);
3097 * batadv_tt_global_update_crc - update all the global CRCs for this orig_node
3098 * @bat_priv: the bat priv with all the soft interface information
3099 * @orig_node: the orig_node for which the CRCs have to be updated
3101 static void batadv_tt_global_update_crc(struct batadv_priv *bat_priv,
3102 struct batadv_orig_node *orig_node)
3104 struct batadv_orig_node_vlan *vlan;
3107 /* recompute the global CRC for each VLAN */
3109 hlist_for_each_entry_rcu(vlan, &orig_node->vlan_list, list) {
3110 /* if orig_node is a backbone node for this VLAN, don't compute
3111 * the CRC as we ignore all the global entries over it
3113 if (batadv_bla_is_backbone_gw_orig(bat_priv, orig_node->orig,
3117 crc = batadv_tt_global_crc(bat_priv, orig_node, vlan->vid);
3124 * batadv_send_tt_request - send a TT Request message to a given node
3125 * @bat_priv: the bat priv with all the soft interface information
3126 * @dst_orig_node: the destination of the message
3127 * @ttvn: the version number that the source of the message is looking for
3128 * @tt_vlan: pointer to the first tvlv VLAN object to request
3129 * @num_vlan: number of tvlv VLAN entries
3130 * @full_table: ask for the entire translation table if true, while only for the
3131 * last TT diff otherwise
3133 * Return: true if the TT Request was sent, false otherwise
3135 static bool batadv_send_tt_request(struct batadv_priv *bat_priv,
3136 struct batadv_orig_node *dst_orig_node,
3138 struct batadv_tvlv_tt_vlan_data *tt_vlan,
3139 u16 num_vlan, bool full_table)
3141 struct batadv_tvlv_tt_data *tvlv_tt_data = NULL;
3142 struct batadv_tt_req_node *tt_req_node = NULL;
3143 struct batadv_tvlv_tt_vlan_data *tt_vlan_req;
3144 struct batadv_hard_iface *primary_if;
3148 primary_if = batadv_primary_if_get_selected(bat_priv);
3152 /* The new tt_req will be issued only if I'm not waiting for a
3153 * reply from the same orig_node yet
3155 tt_req_node = batadv_tt_req_node_new(bat_priv, dst_orig_node);
3159 size = sizeof(*tvlv_tt_data) + sizeof(*tt_vlan_req) * num_vlan;
3160 tvlv_tt_data = kzalloc(size, GFP_ATOMIC);
3164 tvlv_tt_data->flags = BATADV_TT_REQUEST;
3165 tvlv_tt_data->ttvn = ttvn;
3166 tvlv_tt_data->num_vlan = htons(num_vlan);
3168 /* send all the CRCs within the request. This is needed by intermediate
3169 * nodes to ensure they have the correct table before replying
3171 tt_vlan_req = (struct batadv_tvlv_tt_vlan_data *)(tvlv_tt_data + 1);
3172 for (i = 0; i < num_vlan; i++) {
3173 tt_vlan_req->vid = tt_vlan->vid;
3174 tt_vlan_req->crc = tt_vlan->crc;
3181 tvlv_tt_data->flags |= BATADV_TT_FULL_TABLE;
3183 batadv_dbg(BATADV_DBG_TT, bat_priv, "Sending TT_REQUEST to %pM [%c]\n",
3184 dst_orig_node->orig, full_table ? 'F' : '.');
3186 batadv_inc_counter(bat_priv, BATADV_CNT_TT_REQUEST_TX);
3187 batadv_tvlv_unicast_send(bat_priv, primary_if->net_dev->dev_addr,
3188 dst_orig_node->orig, BATADV_TVLV_TT, 1,
3189 tvlv_tt_data, size);
3194 batadv_hardif_put(primary_if);
3196 if (ret && tt_req_node) {
3197 spin_lock_bh(&bat_priv->tt.req_list_lock);
3198 if (!hlist_unhashed(&tt_req_node->list)) {
3199 hlist_del_init(&tt_req_node->list);
3200 batadv_tt_req_node_put(tt_req_node);
3202 spin_unlock_bh(&bat_priv->tt.req_list_lock);
3206 batadv_tt_req_node_put(tt_req_node);
3208 kfree(tvlv_tt_data);
3213 * batadv_send_other_tt_response - send reply to tt request concerning another
3214 * node's translation table
3215 * @bat_priv: the bat priv with all the soft interface information
3216 * @tt_data: tt data containing the tt request information
3217 * @req_src: mac address of tt request sender
3218 * @req_dst: mac address of tt request recipient
3220 * Return: true if tt request reply was sent, false otherwise.
3222 static bool batadv_send_other_tt_response(struct batadv_priv *bat_priv,
3223 struct batadv_tvlv_tt_data *tt_data,
3224 u8 *req_src, u8 *req_dst)
3226 struct batadv_orig_node *req_dst_orig_node;
3227 struct batadv_orig_node *res_dst_orig_node = NULL;
3228 struct batadv_tvlv_tt_change *tt_change;
3229 struct batadv_tvlv_tt_data *tvlv_tt_data = NULL;
3230 struct batadv_tvlv_tt_vlan_data *tt_vlan;
3231 bool ret = false, full_table;
3232 u8 orig_ttvn, req_ttvn;
3236 batadv_dbg(BATADV_DBG_TT, bat_priv,
3237 "Received TT_REQUEST from %pM for ttvn: %u (%pM) [%c]\n",
3238 req_src, tt_data->ttvn, req_dst,
3239 ((tt_data->flags & BATADV_TT_FULL_TABLE) ? 'F' : '.'));
3241 /* Let's get the orig node of the REAL destination */
3242 req_dst_orig_node = batadv_orig_hash_find(bat_priv, req_dst);
3243 if (!req_dst_orig_node)
3246 res_dst_orig_node = batadv_orig_hash_find(bat_priv, req_src);
3247 if (!res_dst_orig_node)
3250 orig_ttvn = (u8)atomic_read(&req_dst_orig_node->last_ttvn);
3251 req_ttvn = tt_data->ttvn;
3253 tt_vlan = (struct batadv_tvlv_tt_vlan_data *)(tt_data + 1);
3254 /* this node doesn't have the requested data */
3255 if (orig_ttvn != req_ttvn ||
3256 !batadv_tt_global_check_crc(req_dst_orig_node, tt_vlan,
3257 ntohs(tt_data->num_vlan)))
3260 /* If the full table has been explicitly requested */
3261 if (tt_data->flags & BATADV_TT_FULL_TABLE ||
3262 !req_dst_orig_node->tt_buff)
3267 /* TT fragmentation hasn't been implemented yet, so send as many
3268 * TT entries fit a single packet as possible only
3271 spin_lock_bh(&req_dst_orig_node->tt_buff_lock);
3272 tt_len = req_dst_orig_node->tt_buff_len;
3274 tvlv_len = batadv_tt_prepare_tvlv_global_data(req_dst_orig_node,
3281 /* Copy the last orig_node's OGM buffer */
3282 memcpy(tt_change, req_dst_orig_node->tt_buff,
3283 req_dst_orig_node->tt_buff_len);
3284 spin_unlock_bh(&req_dst_orig_node->tt_buff_lock);
3286 /* allocate the tvlv, put the tt_data and all the tt_vlan_data
3287 * in the initial part
3290 tvlv_len = batadv_tt_prepare_tvlv_global_data(req_dst_orig_node,
3297 /* fill the rest of the tvlv with the real TT entries */
3298 batadv_tt_tvlv_generate(bat_priv, bat_priv->tt.global_hash,
3300 batadv_tt_global_valid,
3304 /* Don't send the response, if larger than fragmented packet. */
3305 tt_len = sizeof(struct batadv_unicast_tvlv_packet) + tvlv_len;
3306 if (tt_len > atomic_read(&bat_priv->packet_size_max)) {
3307 net_ratelimited_function(batadv_info, bat_priv->soft_iface,
3308 "Ignoring TT_REQUEST from %pM; Response size exceeds max packet size.\n",
3309 res_dst_orig_node->orig);
3313 tvlv_tt_data->flags = BATADV_TT_RESPONSE;
3314 tvlv_tt_data->ttvn = req_ttvn;
3317 tvlv_tt_data->flags |= BATADV_TT_FULL_TABLE;
3319 batadv_dbg(BATADV_DBG_TT, bat_priv,
3320 "Sending TT_RESPONSE %pM for %pM [%c] (ttvn: %u)\n",
3321 res_dst_orig_node->orig, req_dst_orig_node->orig,
3322 full_table ? 'F' : '.', req_ttvn);
3324 batadv_inc_counter(bat_priv, BATADV_CNT_TT_RESPONSE_TX);
3326 batadv_tvlv_unicast_send(bat_priv, req_dst_orig_node->orig,
3327 req_src, BATADV_TVLV_TT, 1, tvlv_tt_data,
3334 spin_unlock_bh(&req_dst_orig_node->tt_buff_lock);
3337 if (res_dst_orig_node)
3338 batadv_orig_node_put(res_dst_orig_node);
3339 if (req_dst_orig_node)
3340 batadv_orig_node_put(req_dst_orig_node);
3341 kfree(tvlv_tt_data);
3346 * batadv_send_my_tt_response - send reply to tt request concerning this node's
3348 * @bat_priv: the bat priv with all the soft interface information
3349 * @tt_data: tt data containing the tt request information
3350 * @req_src: mac address of tt request sender
3352 * Return: true if tt request reply was sent, false otherwise.
3354 static bool batadv_send_my_tt_response(struct batadv_priv *bat_priv,
3355 struct batadv_tvlv_tt_data *tt_data,
3358 struct batadv_tvlv_tt_data *tvlv_tt_data = NULL;
3359 struct batadv_hard_iface *primary_if = NULL;
3360 struct batadv_tvlv_tt_change *tt_change;
3361 struct batadv_orig_node *orig_node;
3362 u8 my_ttvn, req_ttvn;
3367 batadv_dbg(BATADV_DBG_TT, bat_priv,
3368 "Received TT_REQUEST from %pM for ttvn: %u (me) [%c]\n",
3369 req_src, tt_data->ttvn,
3370 ((tt_data->flags & BATADV_TT_FULL_TABLE) ? 'F' : '.'));
3372 spin_lock_bh(&bat_priv->tt.commit_lock);
3374 my_ttvn = (u8)atomic_read(&bat_priv->tt.vn);
3375 req_ttvn = tt_data->ttvn;
3377 orig_node = batadv_orig_hash_find(bat_priv, req_src);
3381 primary_if = batadv_primary_if_get_selected(bat_priv);
3385 /* If the full table has been explicitly requested or the gap
3386 * is too big send the whole local translation table
3388 if (tt_data->flags & BATADV_TT_FULL_TABLE || my_ttvn != req_ttvn ||
3389 !bat_priv->tt.last_changeset)
3394 /* TT fragmentation hasn't been implemented yet, so send as many
3395 * TT entries fit a single packet as possible only
3398 spin_lock_bh(&bat_priv->tt.last_changeset_lock);
3400 tt_len = bat_priv->tt.last_changeset_len;
3401 tvlv_len = batadv_tt_prepare_tvlv_local_data(bat_priv,
3405 if (!tt_len || !tvlv_len)
3408 /* Copy the last orig_node's OGM buffer */
3409 memcpy(tt_change, bat_priv->tt.last_changeset,
3410 bat_priv->tt.last_changeset_len);
3411 spin_unlock_bh(&bat_priv->tt.last_changeset_lock);
3413 req_ttvn = (u8)atomic_read(&bat_priv->tt.vn);
3415 /* allocate the tvlv, put the tt_data and all the tt_vlan_data
3416 * in the initial part
3419 tvlv_len = batadv_tt_prepare_tvlv_local_data(bat_priv,
3423 if (!tt_len || !tvlv_len)
3426 /* fill the rest of the tvlv with the real TT entries */
3427 batadv_tt_tvlv_generate(bat_priv, bat_priv->tt.local_hash,
3429 batadv_tt_local_valid, NULL);
3432 tvlv_tt_data->flags = BATADV_TT_RESPONSE;
3433 tvlv_tt_data->ttvn = req_ttvn;
3436 tvlv_tt_data->flags |= BATADV_TT_FULL_TABLE;
3438 batadv_dbg(BATADV_DBG_TT, bat_priv,
3439 "Sending TT_RESPONSE to %pM [%c] (ttvn: %u)\n",
3440 orig_node->orig, full_table ? 'F' : '.', req_ttvn);
3442 batadv_inc_counter(bat_priv, BATADV_CNT_TT_RESPONSE_TX);
3444 batadv_tvlv_unicast_send(bat_priv, primary_if->net_dev->dev_addr,
3445 req_src, BATADV_TVLV_TT, 1, tvlv_tt_data,
3451 spin_unlock_bh(&bat_priv->tt.last_changeset_lock);
3453 spin_unlock_bh(&bat_priv->tt.commit_lock);
3455 batadv_orig_node_put(orig_node);
3457 batadv_hardif_put(primary_if);
3458 kfree(tvlv_tt_data);
3459 /* The packet was for this host, so it doesn't need to be re-routed */
3464 * batadv_send_tt_response - send reply to tt request
3465 * @bat_priv: the bat priv with all the soft interface information
3466 * @tt_data: tt data containing the tt request information
3467 * @req_src: mac address of tt request sender
3468 * @req_dst: mac address of tt request recipient
3470 * Return: true if tt request reply was sent, false otherwise.
3472 static bool batadv_send_tt_response(struct batadv_priv *bat_priv,
3473 struct batadv_tvlv_tt_data *tt_data,
3474 u8 *req_src, u8 *req_dst)
3476 if (batadv_is_my_mac(bat_priv, req_dst))
3477 return batadv_send_my_tt_response(bat_priv, tt_data, req_src);
3478 return batadv_send_other_tt_response(bat_priv, tt_data, req_src,
3482 static void _batadv_tt_update_changes(struct batadv_priv *bat_priv,
3483 struct batadv_orig_node *orig_node,
3484 struct batadv_tvlv_tt_change *tt_change,
3485 u16 tt_num_changes, u8 ttvn)
3490 for (i = 0; i < tt_num_changes; i++) {
3491 if ((tt_change + i)->flags & BATADV_TT_CLIENT_DEL) {
3492 roams = (tt_change + i)->flags & BATADV_TT_CLIENT_ROAM;
3493 batadv_tt_global_del(bat_priv, orig_node,
3494 (tt_change + i)->addr,
3495 ntohs((tt_change + i)->vid),
3496 "tt removed by changes",
3499 if (!batadv_tt_global_add(bat_priv, orig_node,
3500 (tt_change + i)->addr,
3501 ntohs((tt_change + i)->vid),
3502 (tt_change + i)->flags, ttvn))
3503 /* In case of problem while storing a
3504 * global_entry, we stop the updating
3505 * procedure without committing the
3506 * ttvn change. This will avoid to send
3507 * corrupted data on tt_request
3512 set_bit(BATADV_ORIG_CAPA_HAS_TT, &orig_node->capa_initialized);
3515 static void batadv_tt_fill_gtable(struct batadv_priv *bat_priv,
3516 struct batadv_tvlv_tt_change *tt_change,
3517 u8 ttvn, u8 *resp_src,
3520 struct batadv_orig_node *orig_node;
3522 orig_node = batadv_orig_hash_find(bat_priv, resp_src);
3526 /* Purge the old table first.. */
3527 batadv_tt_global_del_orig(bat_priv, orig_node, -1,
3528 "Received full table");
3530 _batadv_tt_update_changes(bat_priv, orig_node, tt_change, num_entries,
3533 spin_lock_bh(&orig_node->tt_buff_lock);
3534 kfree(orig_node->tt_buff);
3535 orig_node->tt_buff_len = 0;
3536 orig_node->tt_buff = NULL;
3537 spin_unlock_bh(&orig_node->tt_buff_lock);
3539 atomic_set(&orig_node->last_ttvn, ttvn);
3543 batadv_orig_node_put(orig_node);
3546 static void batadv_tt_update_changes(struct batadv_priv *bat_priv,
3547 struct batadv_orig_node *orig_node,
3548 u16 tt_num_changes, u8 ttvn,
3549 struct batadv_tvlv_tt_change *tt_change)
3551 _batadv_tt_update_changes(bat_priv, orig_node, tt_change,
3552 tt_num_changes, ttvn);
3554 batadv_tt_save_orig_buffer(bat_priv, orig_node, tt_change,
3555 batadv_tt_len(tt_num_changes));
3556 atomic_set(&orig_node->last_ttvn, ttvn);
3560 * batadv_is_my_client - check if a client is served by the local node
3561 * @bat_priv: the bat priv with all the soft interface information
3562 * @addr: the mac address of the client to check
3563 * @vid: VLAN identifier
3565 * Return: true if the client is served by this node, false otherwise.
3567 bool batadv_is_my_client(struct batadv_priv *bat_priv, const u8 *addr,
3570 struct batadv_tt_local_entry *tt_local_entry;
3573 tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr, vid);
3574 if (!tt_local_entry)
3576 /* Check if the client has been logically deleted (but is kept for
3577 * consistency purpose)
3579 if ((tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING) ||
3580 (tt_local_entry->common.flags & BATADV_TT_CLIENT_ROAM))
3585 batadv_tt_local_entry_put(tt_local_entry);
3590 * batadv_handle_tt_response - process incoming tt reply
3591 * @bat_priv: the bat priv with all the soft interface information
3592 * @tt_data: tt data containing the tt request information
3593 * @resp_src: mac address of tt reply sender
3594 * @num_entries: number of tt change entries appended to the tt data
3596 static void batadv_handle_tt_response(struct batadv_priv *bat_priv,
3597 struct batadv_tvlv_tt_data *tt_data,
3598 u8 *resp_src, u16 num_entries)
3600 struct batadv_tt_req_node *node;
3601 struct hlist_node *safe;
3602 struct batadv_orig_node *orig_node = NULL;
3603 struct batadv_tvlv_tt_change *tt_change;
3604 u8 *tvlv_ptr = (u8 *)tt_data;
3607 batadv_dbg(BATADV_DBG_TT, bat_priv,
3608 "Received TT_RESPONSE from %pM for ttvn %d t_size: %d [%c]\n",
3609 resp_src, tt_data->ttvn, num_entries,
3610 ((tt_data->flags & BATADV_TT_FULL_TABLE) ? 'F' : '.'));
3612 orig_node = batadv_orig_hash_find(bat_priv, resp_src);
3616 spin_lock_bh(&orig_node->tt_lock);
3618 change_offset = sizeof(struct batadv_tvlv_tt_vlan_data);
3619 change_offset *= ntohs(tt_data->num_vlan);
3620 change_offset += sizeof(*tt_data);
3621 tvlv_ptr += change_offset;
3623 tt_change = (struct batadv_tvlv_tt_change *)tvlv_ptr;
3624 if (tt_data->flags & BATADV_TT_FULL_TABLE) {
3625 batadv_tt_fill_gtable(bat_priv, tt_change, tt_data->ttvn,
3626 resp_src, num_entries);
3628 batadv_tt_update_changes(bat_priv, orig_node, num_entries,
3629 tt_data->ttvn, tt_change);
3632 /* Recalculate the CRC for this orig_node and store it */
3633 batadv_tt_global_update_crc(bat_priv, orig_node);
3635 spin_unlock_bh(&orig_node->tt_lock);
3637 /* Delete the tt_req_node from pending tt_requests list */
3638 spin_lock_bh(&bat_priv->tt.req_list_lock);
3639 hlist_for_each_entry_safe(node, safe, &bat_priv->tt.req_list, list) {
3640 if (!batadv_compare_eth(node->addr, resp_src))
3642 hlist_del_init(&node->list);
3643 batadv_tt_req_node_put(node);
3646 spin_unlock_bh(&bat_priv->tt.req_list_lock);
3649 batadv_orig_node_put(orig_node);
3652 static void batadv_tt_roam_list_free(struct batadv_priv *bat_priv)
3654 struct batadv_tt_roam_node *node, *safe;
3656 spin_lock_bh(&bat_priv->tt.roam_list_lock);
3658 list_for_each_entry_safe(node, safe, &bat_priv->tt.roam_list, list) {
3659 list_del(&node->list);
3660 kmem_cache_free(batadv_tt_roam_cache, node);
3663 spin_unlock_bh(&bat_priv->tt.roam_list_lock);
3666 static void batadv_tt_roam_purge(struct batadv_priv *bat_priv)
3668 struct batadv_tt_roam_node *node, *safe;
3670 spin_lock_bh(&bat_priv->tt.roam_list_lock);
3671 list_for_each_entry_safe(node, safe, &bat_priv->tt.roam_list, list) {
3672 if (!batadv_has_timed_out(node->first_time,
3673 BATADV_ROAMING_MAX_TIME))
3676 list_del(&node->list);
3677 kmem_cache_free(batadv_tt_roam_cache, node);
3679 spin_unlock_bh(&bat_priv->tt.roam_list_lock);
3683 * batadv_tt_check_roam_count - check if a client has roamed too frequently
3684 * @bat_priv: the bat priv with all the soft interface information
3685 * @client: mac address of the roaming client
3687 * This function checks whether the client already reached the
3688 * maximum number of possible roaming phases. In this case the ROAMING_ADV
3691 * Return: true if the ROAMING_ADV can be sent, false otherwise
3693 static bool batadv_tt_check_roam_count(struct batadv_priv *bat_priv, u8 *client)
3695 struct batadv_tt_roam_node *tt_roam_node;
3698 spin_lock_bh(&bat_priv->tt.roam_list_lock);
3699 /* The new tt_req will be issued only if I'm not waiting for a
3700 * reply from the same orig_node yet
3702 list_for_each_entry(tt_roam_node, &bat_priv->tt.roam_list, list) {
3703 if (!batadv_compare_eth(tt_roam_node->addr, client))
3706 if (batadv_has_timed_out(tt_roam_node->first_time,
3707 BATADV_ROAMING_MAX_TIME))
3710 if (!batadv_atomic_dec_not_zero(&tt_roam_node->counter))
3711 /* Sorry, you roamed too many times! */
3718 tt_roam_node = kmem_cache_alloc(batadv_tt_roam_cache,
3723 tt_roam_node->first_time = jiffies;
3724 atomic_set(&tt_roam_node->counter,
3725 BATADV_ROAMING_MAX_COUNT - 1);
3726 ether_addr_copy(tt_roam_node->addr, client);
3728 list_add(&tt_roam_node->list, &bat_priv->tt.roam_list);
3733 spin_unlock_bh(&bat_priv->tt.roam_list_lock);
3738 * batadv_send_roam_adv - send a roaming advertisement message
3739 * @bat_priv: the bat priv with all the soft interface information
3740 * @client: mac address of the roaming client
3741 * @vid: VLAN identifier
3742 * @orig_node: message destination
3744 * Send a ROAMING_ADV message to the node which was previously serving this
3745 * client. This is done to inform the node that from now on all traffic destined
3746 * for this particular roamed client has to be forwarded to the sender of the
3749 static void batadv_send_roam_adv(struct batadv_priv *bat_priv, u8 *client,
3751 struct batadv_orig_node *orig_node)
3753 struct batadv_hard_iface *primary_if;
3754 struct batadv_tvlv_roam_adv tvlv_roam;
3756 primary_if = batadv_primary_if_get_selected(bat_priv);
3760 /* before going on we have to check whether the client has
3761 * already roamed to us too many times
3763 if (!batadv_tt_check_roam_count(bat_priv, client))
3766 batadv_dbg(BATADV_DBG_TT, bat_priv,
3767 "Sending ROAMING_ADV to %pM (client %pM, vid: %d)\n",
3768 orig_node->orig, client, batadv_print_vid(vid));
3770 batadv_inc_counter(bat_priv, BATADV_CNT_TT_ROAM_ADV_TX);
3772 memcpy(tvlv_roam.client, client, sizeof(tvlv_roam.client));
3773 tvlv_roam.vid = htons(vid);
3775 batadv_tvlv_unicast_send(bat_priv, primary_if->net_dev->dev_addr,
3776 orig_node->orig, BATADV_TVLV_ROAM, 1,
3777 &tvlv_roam, sizeof(tvlv_roam));
3781 batadv_hardif_put(primary_if);
3784 static void batadv_tt_purge(struct work_struct *work)
3786 struct delayed_work *delayed_work;
3787 struct batadv_priv_tt *priv_tt;
3788 struct batadv_priv *bat_priv;
3790 delayed_work = to_delayed_work(work);
3791 priv_tt = container_of(delayed_work, struct batadv_priv_tt, work);
3792 bat_priv = container_of(priv_tt, struct batadv_priv, tt);
3794 batadv_tt_local_purge(bat_priv, BATADV_TT_LOCAL_TIMEOUT);
3795 batadv_tt_global_purge(bat_priv);
3796 batadv_tt_req_purge(bat_priv);
3797 batadv_tt_roam_purge(bat_priv);
3799 queue_delayed_work(batadv_event_workqueue, &bat_priv->tt.work,
3800 msecs_to_jiffies(BATADV_TT_WORK_PERIOD));
3803 void batadv_tt_free(struct batadv_priv *bat_priv)
3805 batadv_tvlv_handler_unregister(bat_priv, BATADV_TVLV_ROAM, 1);
3807 batadv_tvlv_container_unregister(bat_priv, BATADV_TVLV_TT, 1);
3808 batadv_tvlv_handler_unregister(bat_priv, BATADV_TVLV_TT, 1);
3810 cancel_delayed_work_sync(&bat_priv->tt.work);
3812 batadv_tt_local_table_free(bat_priv);
3813 batadv_tt_global_table_free(bat_priv);
3814 batadv_tt_req_list_free(bat_priv);
3815 batadv_tt_changes_list_free(bat_priv);
3816 batadv_tt_roam_list_free(bat_priv);
3818 kfree(bat_priv->tt.last_changeset);
3822 * batadv_tt_local_set_flags - set or unset the specified flags on the local
3823 * table and possibly count them in the TT size
3824 * @bat_priv: the bat priv with all the soft interface information
3825 * @flags: the flag to switch
3826 * @enable: whether to set or unset the flag
3827 * @count: whether to increase the TT size by the number of changed entries
3829 static void batadv_tt_local_set_flags(struct batadv_priv *bat_priv, u16 flags,
3830 bool enable, bool count)
3832 struct batadv_hashtable *hash = bat_priv->tt.local_hash;
3833 struct batadv_tt_common_entry *tt_common_entry;
3834 struct hlist_head *head;
3840 for (i = 0; i < hash->size; i++) {
3841 head = &hash->table[i];
3844 hlist_for_each_entry_rcu(tt_common_entry,
3847 if ((tt_common_entry->flags & flags) == flags)
3849 tt_common_entry->flags |= flags;
3851 if (!(tt_common_entry->flags & flags))
3853 tt_common_entry->flags &= ~flags;
3859 batadv_tt_local_size_inc(bat_priv,
3860 tt_common_entry->vid);
3866 /* Purge out all the tt local entries marked with BATADV_TT_CLIENT_PENDING */
3867 static void batadv_tt_local_purge_pending_clients(struct batadv_priv *bat_priv)
3869 struct batadv_hashtable *hash = bat_priv->tt.local_hash;
3870 struct batadv_tt_common_entry *tt_common;
3871 struct batadv_tt_local_entry *tt_local;
3872 struct hlist_node *node_tmp;
3873 struct hlist_head *head;
3874 spinlock_t *list_lock; /* protects write access to the hash lists */
3880 for (i = 0; i < hash->size; i++) {
3881 head = &hash->table[i];
3882 list_lock = &hash->list_locks[i];
3884 spin_lock_bh(list_lock);
3885 hlist_for_each_entry_safe(tt_common, node_tmp, head,
3887 if (!(tt_common->flags & BATADV_TT_CLIENT_PENDING))
3890 batadv_dbg(BATADV_DBG_TT, bat_priv,
3891 "Deleting local tt entry (%pM, vid: %d): pending\n",
3893 batadv_print_vid(tt_common->vid));
3895 batadv_tt_local_size_dec(bat_priv, tt_common->vid);
3896 hlist_del_rcu(&tt_common->hash_entry);
3897 tt_local = container_of(tt_common,
3898 struct batadv_tt_local_entry,
3901 batadv_tt_local_entry_put(tt_local);
3903 spin_unlock_bh(list_lock);
3908 * batadv_tt_local_commit_changes_nolock - commit all pending local tt changes
3909 * which have been queued in the time since the last commit
3910 * @bat_priv: the bat priv with all the soft interface information
3912 * Caller must hold tt->commit_lock.
3914 static void batadv_tt_local_commit_changes_nolock(struct batadv_priv *bat_priv)
3916 lockdep_assert_held(&bat_priv->tt.commit_lock);
3918 if (atomic_read(&bat_priv->tt.local_changes) < 1) {
3919 if (!batadv_atomic_dec_not_zero(&bat_priv->tt.ogm_append_cnt))
3920 batadv_tt_tvlv_container_update(bat_priv);
3924 batadv_tt_local_set_flags(bat_priv, BATADV_TT_CLIENT_NEW, false, true);
3926 batadv_tt_local_purge_pending_clients(bat_priv);
3927 batadv_tt_local_update_crc(bat_priv);
3929 /* Increment the TTVN only once per OGM interval */
3930 atomic_inc(&bat_priv->tt.vn);
3931 batadv_dbg(BATADV_DBG_TT, bat_priv,
3932 "Local changes committed, updating to ttvn %u\n",
3933 (u8)atomic_read(&bat_priv->tt.vn));
3935 /* reset the sending counter */
3936 atomic_set(&bat_priv->tt.ogm_append_cnt, BATADV_TT_OGM_APPEND_MAX);
3937 batadv_tt_tvlv_container_update(bat_priv);
3941 * batadv_tt_local_commit_changes - commit all pending local tt changes which
3942 * have been queued in the time since the last commit
3943 * @bat_priv: the bat priv with all the soft interface information
3945 void batadv_tt_local_commit_changes(struct batadv_priv *bat_priv)
3947 spin_lock_bh(&bat_priv->tt.commit_lock);
3948 batadv_tt_local_commit_changes_nolock(bat_priv);
3949 spin_unlock_bh(&bat_priv->tt.commit_lock);
3952 bool batadv_is_ap_isolated(struct batadv_priv *bat_priv, u8 *src, u8 *dst,
3955 struct batadv_tt_local_entry *tt_local_entry;
3956 struct batadv_tt_global_entry *tt_global_entry;
3957 struct batadv_softif_vlan *vlan;
3960 vlan = batadv_softif_vlan_get(bat_priv, vid);
3964 if (!atomic_read(&vlan->ap_isolation))
3967 tt_local_entry = batadv_tt_local_hash_find(bat_priv, dst, vid);
3968 if (!tt_local_entry)
3971 tt_global_entry = batadv_tt_global_hash_find(bat_priv, src, vid);
3972 if (!tt_global_entry)
3973 goto local_entry_put;
3975 if (_batadv_is_ap_isolated(tt_local_entry, tt_global_entry))
3978 batadv_tt_global_entry_put(tt_global_entry);
3980 batadv_tt_local_entry_put(tt_local_entry);
3982 batadv_softif_vlan_put(vlan);
3987 * batadv_tt_update_orig - update global translation table with new tt
3988 * information received via ogms
3989 * @bat_priv: the bat priv with all the soft interface information
3990 * @orig_node: the orig_node of the ogm
3991 * @tt_buff: pointer to the first tvlv VLAN entry
3992 * @tt_num_vlan: number of tvlv VLAN entries
3993 * @tt_change: pointer to the first entry in the TT buffer
3994 * @tt_num_changes: number of tt changes inside the tt buffer
3995 * @ttvn: translation table version number of this changeset
3997 static void batadv_tt_update_orig(struct batadv_priv *bat_priv,
3998 struct batadv_orig_node *orig_node,
3999 const void *tt_buff, u16 tt_num_vlan,
4000 struct batadv_tvlv_tt_change *tt_change,
4001 u16 tt_num_changes, u8 ttvn)
4003 u8 orig_ttvn = (u8)atomic_read(&orig_node->last_ttvn);
4004 struct batadv_tvlv_tt_vlan_data *tt_vlan;
4005 bool full_table = true;
4008 tt_vlan = (struct batadv_tvlv_tt_vlan_data *)tt_buff;
4009 has_tt_init = test_bit(BATADV_ORIG_CAPA_HAS_TT,
4010 &orig_node->capa_initialized);
4012 /* orig table not initialised AND first diff is in the OGM OR the ttvn
4013 * increased by one -> we can apply the attached changes
4015 if ((!has_tt_init && ttvn == 1) || ttvn - orig_ttvn == 1) {
4016 /* the OGM could not contain the changes due to their size or
4017 * because they have already been sent BATADV_TT_OGM_APPEND_MAX
4019 * In this case send a tt request
4021 if (!tt_num_changes) {
4026 spin_lock_bh(&orig_node->tt_lock);
4028 batadv_tt_update_changes(bat_priv, orig_node, tt_num_changes,
4031 /* Even if we received the precomputed crc with the OGM, we
4032 * prefer to recompute it to spot any possible inconsistency
4033 * in the global table
4035 batadv_tt_global_update_crc(bat_priv, orig_node);
4037 spin_unlock_bh(&orig_node->tt_lock);
4039 /* The ttvn alone is not enough to guarantee consistency
4040 * because a single value could represent different states
4041 * (due to the wrap around). Thus a node has to check whether
4042 * the resulting table (after applying the changes) is still
4043 * consistent or not. E.g. a node could disconnect while its
4044 * ttvn is X and reconnect on ttvn = X + TTVN_MAX: in this case
4045 * checking the CRC value is mandatory to detect the
4048 if (!batadv_tt_global_check_crc(orig_node, tt_vlan,
4052 /* if we missed more than one change or our tables are not
4053 * in sync anymore -> request fresh tt data
4055 if (!has_tt_init || ttvn != orig_ttvn ||
4056 !batadv_tt_global_check_crc(orig_node, tt_vlan,
4059 batadv_dbg(BATADV_DBG_TT, bat_priv,
4060 "TT inconsistency for %pM. Need to retrieve the correct information (ttvn: %u last_ttvn: %u num_changes: %u)\n",
4061 orig_node->orig, ttvn, orig_ttvn,
4063 batadv_send_tt_request(bat_priv, orig_node, ttvn,
4064 tt_vlan, tt_num_vlan,
4072 * batadv_tt_global_client_is_roaming - check if a client is marked as roaming
4073 * @bat_priv: the bat priv with all the soft interface information
4074 * @addr: the mac address of the client to check
4075 * @vid: VLAN identifier
4077 * Return: true if we know that the client has moved from its old originator
4078 * to another one. This entry is still kept for consistency purposes and will be
4079 * deleted later by a DEL or because of timeout
4081 bool batadv_tt_global_client_is_roaming(struct batadv_priv *bat_priv,
4082 u8 *addr, unsigned short vid)
4084 struct batadv_tt_global_entry *tt_global_entry;
4087 tt_global_entry = batadv_tt_global_hash_find(bat_priv, addr, vid);
4088 if (!tt_global_entry)
4091 ret = tt_global_entry->common.flags & BATADV_TT_CLIENT_ROAM;
4092 batadv_tt_global_entry_put(tt_global_entry);
4098 * batadv_tt_local_client_is_roaming - tells whether the client is roaming
4099 * @bat_priv: the bat priv with all the soft interface information
4100 * @addr: the mac address of the local client to query
4101 * @vid: VLAN identifier
4103 * Return: true if the local client is known to be roaming (it is not served by
4104 * this node anymore) or not. If yes, the client is still present in the table
4105 * to keep the latter consistent with the node TTVN
4107 bool batadv_tt_local_client_is_roaming(struct batadv_priv *bat_priv,
4108 u8 *addr, unsigned short vid)
4110 struct batadv_tt_local_entry *tt_local_entry;
4113 tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr, vid);
4114 if (!tt_local_entry)
4117 ret = tt_local_entry->common.flags & BATADV_TT_CLIENT_ROAM;
4118 batadv_tt_local_entry_put(tt_local_entry);
4123 bool batadv_tt_add_temporary_global_entry(struct batadv_priv *bat_priv,
4124 struct batadv_orig_node *orig_node,
4125 const unsigned char *addr,
4128 /* ignore loop detect macs, they are not supposed to be in the tt local
4131 if (batadv_bla_is_loopdetect_mac(addr))
4134 if (!batadv_tt_global_add(bat_priv, orig_node, addr, vid,
4135 BATADV_TT_CLIENT_TEMP,
4136 atomic_read(&orig_node->last_ttvn)))
4139 batadv_dbg(BATADV_DBG_TT, bat_priv,
4140 "Added temporary global client (addr: %pM, vid: %d, orig: %pM)\n",
4141 addr, batadv_print_vid(vid), orig_node->orig);
4147 * batadv_tt_local_resize_to_mtu - resize the local translation table fit the
4148 * maximum packet size that can be transported through the mesh
4149 * @soft_iface: netdev struct of the mesh interface
4151 * Remove entries older than 'timeout' and half timeout if more entries need
4154 void batadv_tt_local_resize_to_mtu(struct net_device *soft_iface)
4156 struct batadv_priv *bat_priv = netdev_priv(soft_iface);
4157 int packet_size_max = atomic_read(&bat_priv->packet_size_max);
4158 int table_size, timeout = BATADV_TT_LOCAL_TIMEOUT / 2;
4159 bool reduced = false;
4161 spin_lock_bh(&bat_priv->tt.commit_lock);
4164 table_size = batadv_tt_local_table_transmit_size(bat_priv);
4165 if (packet_size_max >= table_size)
4168 batadv_tt_local_purge(bat_priv, timeout);
4169 batadv_tt_local_purge_pending_clients(bat_priv);
4173 net_ratelimited_function(batadv_info, soft_iface,
4174 "Forced to purge local tt entries to fit new maximum fragment MTU (%i)\n",
4178 /* commit these changes immediately, to avoid synchronization problem
4182 batadv_tt_local_commit_changes_nolock(bat_priv);
4184 spin_unlock_bh(&bat_priv->tt.commit_lock);
4188 * batadv_tt_tvlv_ogm_handler_v1 - process incoming tt tvlv container
4189 * @bat_priv: the bat priv with all the soft interface information
4190 * @orig: the orig_node of the ogm
4191 * @flags: flags indicating the tvlv state (see batadv_tvlv_handler_flags)
4192 * @tvlv_value: tvlv buffer containing the gateway data
4193 * @tvlv_value_len: tvlv buffer length
4195 static void batadv_tt_tvlv_ogm_handler_v1(struct batadv_priv *bat_priv,
4196 struct batadv_orig_node *orig,
4197 u8 flags, void *tvlv_value,
4200 struct batadv_tvlv_tt_vlan_data *tt_vlan;
4201 struct batadv_tvlv_tt_change *tt_change;
4202 struct batadv_tvlv_tt_data *tt_data;
4203 u16 num_entries, num_vlan;
4205 if (tvlv_value_len < sizeof(*tt_data))
4208 tt_data = (struct batadv_tvlv_tt_data *)tvlv_value;
4209 tvlv_value_len -= sizeof(*tt_data);
4211 num_vlan = ntohs(tt_data->num_vlan);
4213 if (tvlv_value_len < sizeof(*tt_vlan) * num_vlan)
4216 tt_vlan = (struct batadv_tvlv_tt_vlan_data *)(tt_data + 1);
4217 tt_change = (struct batadv_tvlv_tt_change *)(tt_vlan + num_vlan);
4218 tvlv_value_len -= sizeof(*tt_vlan) * num_vlan;
4220 num_entries = batadv_tt_entries(tvlv_value_len);
4222 batadv_tt_update_orig(bat_priv, orig, tt_vlan, num_vlan, tt_change,
4223 num_entries, tt_data->ttvn);
4227 * batadv_tt_tvlv_unicast_handler_v1 - process incoming (unicast) tt tvlv
4229 * @bat_priv: the bat priv with all the soft interface information
4230 * @src: mac address of tt tvlv sender
4231 * @dst: mac address of tt tvlv recipient
4232 * @tvlv_value: tvlv buffer containing the tt data
4233 * @tvlv_value_len: tvlv buffer length
4235 * Return: NET_RX_DROP if the tt tvlv is to be re-routed, NET_RX_SUCCESS
4238 static int batadv_tt_tvlv_unicast_handler_v1(struct batadv_priv *bat_priv,
4243 struct batadv_tvlv_tt_data *tt_data;
4244 u16 tt_vlan_len, tt_num_entries;
4248 if (tvlv_value_len < sizeof(*tt_data))
4249 return NET_RX_SUCCESS;
4251 tt_data = (struct batadv_tvlv_tt_data *)tvlv_value;
4252 tvlv_value_len -= sizeof(*tt_data);
4254 tt_vlan_len = sizeof(struct batadv_tvlv_tt_vlan_data);
4255 tt_vlan_len *= ntohs(tt_data->num_vlan);
4257 if (tvlv_value_len < tt_vlan_len)
4258 return NET_RX_SUCCESS;
4260 tvlv_value_len -= tt_vlan_len;
4261 tt_num_entries = batadv_tt_entries(tvlv_value_len);
4263 switch (tt_data->flags & BATADV_TT_DATA_TYPE_MASK) {
4264 case BATADV_TT_REQUEST:
4265 batadv_inc_counter(bat_priv, BATADV_CNT_TT_REQUEST_RX);
4267 /* If this node cannot provide a TT response the tt_request is
4270 ret = batadv_send_tt_response(bat_priv, tt_data, src, dst);
4272 if (tt_data->flags & BATADV_TT_FULL_TABLE)
4277 batadv_dbg(BATADV_DBG_TT, bat_priv,
4278 "Routing TT_REQUEST to %pM [%c]\n",
4280 /* tvlv API will re-route the packet */
4284 case BATADV_TT_RESPONSE:
4285 batadv_inc_counter(bat_priv, BATADV_CNT_TT_RESPONSE_RX);
4287 if (batadv_is_my_mac(bat_priv, dst)) {
4288 batadv_handle_tt_response(bat_priv, tt_data,
4289 src, tt_num_entries);
4290 return NET_RX_SUCCESS;
4293 if (tt_data->flags & BATADV_TT_FULL_TABLE)
4298 batadv_dbg(BATADV_DBG_TT, bat_priv,
4299 "Routing TT_RESPONSE to %pM [%c]\n", dst, tt_flag);
4301 /* tvlv API will re-route the packet */
4305 return NET_RX_SUCCESS;
4309 * batadv_roam_tvlv_unicast_handler_v1 - process incoming tt roam tvlv container
4310 * @bat_priv: the bat priv with all the soft interface information
4311 * @src: mac address of tt tvlv sender
4312 * @dst: mac address of tt tvlv recipient
4313 * @tvlv_value: tvlv buffer containing the tt data
4314 * @tvlv_value_len: tvlv buffer length
4316 * Return: NET_RX_DROP if the tt roam tvlv is to be re-routed, NET_RX_SUCCESS
4319 static int batadv_roam_tvlv_unicast_handler_v1(struct batadv_priv *bat_priv,
4324 struct batadv_tvlv_roam_adv *roaming_adv;
4325 struct batadv_orig_node *orig_node = NULL;
4327 /* If this node is not the intended recipient of the
4328 * roaming advertisement the packet is forwarded
4329 * (the tvlv API will re-route the packet).
4331 if (!batadv_is_my_mac(bat_priv, dst))
4334 if (tvlv_value_len < sizeof(*roaming_adv))
4337 orig_node = batadv_orig_hash_find(bat_priv, src);
4341 batadv_inc_counter(bat_priv, BATADV_CNT_TT_ROAM_ADV_RX);
4342 roaming_adv = (struct batadv_tvlv_roam_adv *)tvlv_value;
4344 batadv_dbg(BATADV_DBG_TT, bat_priv,
4345 "Received ROAMING_ADV from %pM (client %pM)\n",
4346 src, roaming_adv->client);
4348 batadv_tt_global_add(bat_priv, orig_node, roaming_adv->client,
4349 ntohs(roaming_adv->vid), BATADV_TT_CLIENT_ROAM,
4350 atomic_read(&orig_node->last_ttvn) + 1);
4354 batadv_orig_node_put(orig_node);
4355 return NET_RX_SUCCESS;
4359 * batadv_tt_init - initialise the translation table internals
4360 * @bat_priv: the bat priv with all the soft interface information
4362 * Return: 0 on success or negative error number in case of failure.
4364 int batadv_tt_init(struct batadv_priv *bat_priv)
4368 /* synchronized flags must be remote */
4369 BUILD_BUG_ON(!(BATADV_TT_SYNC_MASK & BATADV_TT_REMOTE_MASK));
4371 ret = batadv_tt_local_init(bat_priv);
4375 ret = batadv_tt_global_init(bat_priv);
4377 batadv_tt_local_table_free(bat_priv);
4381 batadv_tvlv_handler_register(bat_priv, batadv_tt_tvlv_ogm_handler_v1,
4382 batadv_tt_tvlv_unicast_handler_v1,
4383 BATADV_TVLV_TT, 1, BATADV_NO_FLAGS);
4385 batadv_tvlv_handler_register(bat_priv, NULL,
4386 batadv_roam_tvlv_unicast_handler_v1,
4387 BATADV_TVLV_ROAM, 1, BATADV_NO_FLAGS);
4389 INIT_DELAYED_WORK(&bat_priv->tt.work, batadv_tt_purge);
4390 queue_delayed_work(batadv_event_workqueue, &bat_priv->tt.work,
4391 msecs_to_jiffies(BATADV_TT_WORK_PERIOD));
4397 * batadv_tt_global_is_isolated - check if a client is marked as isolated
4398 * @bat_priv: the bat priv with all the soft interface information
4399 * @addr: the mac address of the client
4400 * @vid: the identifier of the VLAN where this client is connected
4402 * Return: true if the client is marked with the TT_CLIENT_ISOLA flag, false
4405 bool batadv_tt_global_is_isolated(struct batadv_priv *bat_priv,
4406 const u8 *addr, unsigned short vid)
4408 struct batadv_tt_global_entry *tt;
4411 tt = batadv_tt_global_hash_find(bat_priv, addr, vid);
4415 ret = tt->common.flags & BATADV_TT_CLIENT_ISOLA;
4417 batadv_tt_global_entry_put(tt);
4423 * batadv_tt_cache_init - Initialize tt memory object cache
4425 * Return: 0 on success or negative error number in case of failure.
4427 int __init batadv_tt_cache_init(void)
4429 size_t tl_size = sizeof(struct batadv_tt_local_entry);
4430 size_t tg_size = sizeof(struct batadv_tt_global_entry);
4431 size_t tt_orig_size = sizeof(struct batadv_tt_orig_list_entry);
4432 size_t tt_change_size = sizeof(struct batadv_tt_change_node);
4433 size_t tt_req_size = sizeof(struct batadv_tt_req_node);
4434 size_t tt_roam_size = sizeof(struct batadv_tt_roam_node);
4436 batadv_tl_cache = kmem_cache_create("batadv_tl_cache", tl_size, 0,
4437 SLAB_HWCACHE_ALIGN, NULL);
4438 if (!batadv_tl_cache)
4441 batadv_tg_cache = kmem_cache_create("batadv_tg_cache", tg_size, 0,
4442 SLAB_HWCACHE_ALIGN, NULL);
4443 if (!batadv_tg_cache)
4444 goto err_tt_tl_destroy;
4446 batadv_tt_orig_cache = kmem_cache_create("batadv_tt_orig_cache",
4448 SLAB_HWCACHE_ALIGN, NULL);
4449 if (!batadv_tt_orig_cache)
4450 goto err_tt_tg_destroy;
4452 batadv_tt_change_cache = kmem_cache_create("batadv_tt_change_cache",
4454 SLAB_HWCACHE_ALIGN, NULL);
4455 if (!batadv_tt_change_cache)
4456 goto err_tt_orig_destroy;
4458 batadv_tt_req_cache = kmem_cache_create("batadv_tt_req_cache",
4460 SLAB_HWCACHE_ALIGN, NULL);
4461 if (!batadv_tt_req_cache)
4462 goto err_tt_change_destroy;
4464 batadv_tt_roam_cache = kmem_cache_create("batadv_tt_roam_cache",
4466 SLAB_HWCACHE_ALIGN, NULL);
4467 if (!batadv_tt_roam_cache)
4468 goto err_tt_req_destroy;
4473 kmem_cache_destroy(batadv_tt_req_cache);
4474 batadv_tt_req_cache = NULL;
4475 err_tt_change_destroy:
4476 kmem_cache_destroy(batadv_tt_change_cache);
4477 batadv_tt_change_cache = NULL;
4478 err_tt_orig_destroy:
4479 kmem_cache_destroy(batadv_tt_orig_cache);
4480 batadv_tt_orig_cache = NULL;
4482 kmem_cache_destroy(batadv_tg_cache);
4483 batadv_tg_cache = NULL;
4485 kmem_cache_destroy(batadv_tl_cache);
4486 batadv_tl_cache = NULL;
4492 * batadv_tt_cache_destroy - Destroy tt memory object cache
4494 void batadv_tt_cache_destroy(void)
4496 kmem_cache_destroy(batadv_tl_cache);
4497 kmem_cache_destroy(batadv_tg_cache);
4498 kmem_cache_destroy(batadv_tt_orig_cache);
4499 kmem_cache_destroy(batadv_tt_change_cache);
4500 kmem_cache_destroy(batadv_tt_req_cache);
4501 kmem_cache_destroy(batadv_tt_roam_cache);