1 /* Copyright (C) 2007-2016 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"
59 #include "multicast.h"
61 #include "originator.h"
63 #include "soft-interface.h"
66 static struct kmem_cache *batadv_tl_cache __read_mostly;
67 static struct kmem_cache *batadv_tg_cache __read_mostly;
68 static struct kmem_cache *batadv_tt_orig_cache __read_mostly;
69 static struct kmem_cache *batadv_tt_change_cache __read_mostly;
70 static struct kmem_cache *batadv_tt_req_cache __read_mostly;
71 static struct kmem_cache *batadv_tt_roam_cache __read_mostly;
74 static struct lock_class_key batadv_tt_local_hash_lock_class_key;
75 static struct lock_class_key batadv_tt_global_hash_lock_class_key;
77 static void batadv_send_roam_adv(struct batadv_priv *bat_priv, u8 *client,
79 struct batadv_orig_node *orig_node);
80 static void batadv_tt_purge(struct work_struct *work);
82 batadv_tt_global_del_orig_list(struct batadv_tt_global_entry *tt_global_entry);
83 static void batadv_tt_global_del(struct batadv_priv *bat_priv,
84 struct batadv_orig_node *orig_node,
85 const unsigned char *addr,
86 unsigned short vid, const char *message,
90 * batadv_compare_tt - check if two TT entries are the same
91 * @node: the list element pointer of the first TT entry
92 * @data2: pointer to the tt_common_entry of the second TT entry
94 * Compare the MAC address and the VLAN ID of the two TT entries and check if
95 * they are the same TT client.
96 * Return: true if the two TT clients are the same, false otherwise
98 static bool batadv_compare_tt(const struct hlist_node *node, const void *data2)
100 const void *data1 = container_of(node, struct batadv_tt_common_entry,
102 const struct batadv_tt_common_entry *tt1 = data1;
103 const struct batadv_tt_common_entry *tt2 = data2;
105 return (tt1->vid == tt2->vid) && batadv_compare_eth(data1, data2);
109 * batadv_choose_tt - return the index of the tt entry in the hash table
110 * @data: pointer to the tt_common_entry object to map
111 * @size: the size of the hash table
113 * Return: the hash index where the object represented by 'data' should be
116 static inline u32 batadv_choose_tt(const void *data, u32 size)
118 struct batadv_tt_common_entry *tt;
121 tt = (struct batadv_tt_common_entry *)data;
122 hash = jhash(&tt->addr, ETH_ALEN, hash);
123 hash = jhash(&tt->vid, sizeof(tt->vid), hash);
129 * batadv_tt_hash_find - look for a client in the given hash table
130 * @hash: the hash table to search
131 * @addr: the mac address of the client to look for
132 * @vid: VLAN identifier
134 * Return: a pointer to the tt_common struct belonging to the searched client if
135 * found, NULL otherwise.
137 static struct batadv_tt_common_entry *
138 batadv_tt_hash_find(struct batadv_hashtable *hash, const u8 *addr,
141 struct hlist_head *head;
142 struct batadv_tt_common_entry to_search, *tt, *tt_tmp = NULL;
148 ether_addr_copy(to_search.addr, addr);
151 index = batadv_choose_tt(&to_search, hash->size);
152 head = &hash->table[index];
155 hlist_for_each_entry_rcu(tt, head, hash_entry) {
156 if (!batadv_compare_eth(tt, addr))
162 if (!kref_get_unless_zero(&tt->refcount))
174 * batadv_tt_local_hash_find - search the local table for a given client
175 * @bat_priv: the bat priv with all the soft interface information
176 * @addr: the mac address of the client to look for
177 * @vid: VLAN identifier
179 * Return: a pointer to the corresponding tt_local_entry struct if the client is
180 * found, NULL otherwise.
182 static struct batadv_tt_local_entry *
183 batadv_tt_local_hash_find(struct batadv_priv *bat_priv, const u8 *addr,
186 struct batadv_tt_common_entry *tt_common_entry;
187 struct batadv_tt_local_entry *tt_local_entry = NULL;
189 tt_common_entry = batadv_tt_hash_find(bat_priv->tt.local_hash, addr,
192 tt_local_entry = container_of(tt_common_entry,
193 struct batadv_tt_local_entry,
195 return tt_local_entry;
199 * batadv_tt_global_hash_find - search the global table for a given client
200 * @bat_priv: the bat priv with all the soft interface information
201 * @addr: the mac address of the client to look for
202 * @vid: VLAN identifier
204 * Return: a pointer to the corresponding tt_global_entry struct if the client
205 * is found, NULL otherwise.
207 static struct batadv_tt_global_entry *
208 batadv_tt_global_hash_find(struct batadv_priv *bat_priv, const u8 *addr,
211 struct batadv_tt_common_entry *tt_common_entry;
212 struct batadv_tt_global_entry *tt_global_entry = NULL;
214 tt_common_entry = batadv_tt_hash_find(bat_priv->tt.global_hash, addr,
217 tt_global_entry = container_of(tt_common_entry,
218 struct batadv_tt_global_entry,
220 return tt_global_entry;
224 * batadv_tt_local_entry_free_rcu - free the tt_local_entry
225 * @rcu: rcu pointer of the tt_local_entry
227 static void batadv_tt_local_entry_free_rcu(struct rcu_head *rcu)
229 struct batadv_tt_local_entry *tt_local_entry;
231 tt_local_entry = container_of(rcu, struct batadv_tt_local_entry,
234 kmem_cache_free(batadv_tl_cache, tt_local_entry);
238 * batadv_tt_local_entry_release - release tt_local_entry from lists and queue
239 * for free after rcu grace period
240 * @ref: kref pointer of the nc_node
242 static void batadv_tt_local_entry_release(struct kref *ref)
244 struct batadv_tt_local_entry *tt_local_entry;
246 tt_local_entry = container_of(ref, struct batadv_tt_local_entry,
249 batadv_softif_vlan_put(tt_local_entry->vlan);
251 call_rcu(&tt_local_entry->common.rcu, batadv_tt_local_entry_free_rcu);
255 * batadv_tt_local_entry_put - decrement the tt_local_entry refcounter and
256 * possibly release it
257 * @tt_local_entry: tt_local_entry to be free'd
260 batadv_tt_local_entry_put(struct batadv_tt_local_entry *tt_local_entry)
262 kref_put(&tt_local_entry->common.refcount,
263 batadv_tt_local_entry_release);
267 * batadv_tt_global_entry_free_rcu - free the tt_global_entry
268 * @rcu: rcu pointer of the tt_global_entry
270 static void batadv_tt_global_entry_free_rcu(struct rcu_head *rcu)
272 struct batadv_tt_global_entry *tt_global_entry;
274 tt_global_entry = container_of(rcu, struct batadv_tt_global_entry,
277 kmem_cache_free(batadv_tg_cache, tt_global_entry);
281 * batadv_tt_global_entry_release - release tt_global_entry from lists and queue
282 * for free after rcu grace period
283 * @ref: kref pointer of the nc_node
285 static void batadv_tt_global_entry_release(struct kref *ref)
287 struct batadv_tt_global_entry *tt_global_entry;
289 tt_global_entry = container_of(ref, struct batadv_tt_global_entry,
292 batadv_tt_global_del_orig_list(tt_global_entry);
294 call_rcu(&tt_global_entry->common.rcu, batadv_tt_global_entry_free_rcu);
298 * batadv_tt_global_entry_put - decrement the tt_global_entry refcounter and
299 * possibly release it
300 * @tt_global_entry: tt_global_entry to be free'd
303 batadv_tt_global_entry_put(struct batadv_tt_global_entry *tt_global_entry)
305 kref_put(&tt_global_entry->common.refcount,
306 batadv_tt_global_entry_release);
310 * batadv_tt_global_hash_count - count the number of orig entries
311 * @bat_priv: the bat priv with all the soft interface information
312 * @addr: the mac address of the client to count entries for
313 * @vid: VLAN identifier
315 * Return: the number of originators advertising the given address/data
316 * (excluding ourself).
318 int batadv_tt_global_hash_count(struct batadv_priv *bat_priv,
319 const u8 *addr, unsigned short vid)
321 struct batadv_tt_global_entry *tt_global_entry;
324 tt_global_entry = batadv_tt_global_hash_find(bat_priv, addr, vid);
325 if (!tt_global_entry)
328 count = atomic_read(&tt_global_entry->orig_list_count);
329 batadv_tt_global_entry_put(tt_global_entry);
335 * batadv_tt_local_size_mod - change the size by v of the local table identified
337 * @bat_priv: the bat priv with all the soft interface information
338 * @vid: the VLAN identifier of the sub-table to change
339 * @v: the amount to sum to the local table size
341 static void batadv_tt_local_size_mod(struct batadv_priv *bat_priv,
342 unsigned short vid, int v)
344 struct batadv_softif_vlan *vlan;
346 vlan = batadv_softif_vlan_get(bat_priv, vid);
350 atomic_add(v, &vlan->tt.num_entries);
352 batadv_softif_vlan_put(vlan);
356 * batadv_tt_local_size_inc - increase by one the local table size for the given
358 * @bat_priv: the bat priv with all the soft interface information
359 * @vid: the VLAN identifier
361 static void batadv_tt_local_size_inc(struct batadv_priv *bat_priv,
364 batadv_tt_local_size_mod(bat_priv, vid, 1);
368 * batadv_tt_local_size_dec - decrease by one the local table size for the given
370 * @bat_priv: the bat priv with all the soft interface information
371 * @vid: the VLAN identifier
373 static void batadv_tt_local_size_dec(struct batadv_priv *bat_priv,
376 batadv_tt_local_size_mod(bat_priv, vid, -1);
380 * batadv_tt_global_size_mod - change the size by v of the global table
381 * for orig_node identified by vid
382 * @orig_node: the originator for which the table has to be modified
383 * @vid: the VLAN identifier
384 * @v: the amount to sum to the global table size
386 static void batadv_tt_global_size_mod(struct batadv_orig_node *orig_node,
387 unsigned short vid, int v)
389 struct batadv_orig_node_vlan *vlan;
391 vlan = batadv_orig_node_vlan_new(orig_node, vid);
395 if (atomic_add_return(v, &vlan->tt.num_entries) == 0) {
396 spin_lock_bh(&orig_node->vlan_list_lock);
397 if (!hlist_unhashed(&vlan->list)) {
398 hlist_del_init_rcu(&vlan->list);
399 batadv_orig_node_vlan_put(vlan);
401 spin_unlock_bh(&orig_node->vlan_list_lock);
404 batadv_orig_node_vlan_put(vlan);
408 * batadv_tt_global_size_inc - increase by one the global table size for the
410 * @orig_node: the originator which global table size has to be decreased
411 * @vid: the vlan identifier
413 static void batadv_tt_global_size_inc(struct batadv_orig_node *orig_node,
416 batadv_tt_global_size_mod(orig_node, vid, 1);
420 * batadv_tt_global_size_dec - decrease by one the global table size for the
422 * @orig_node: the originator which global table size has to be decreased
423 * @vid: the vlan identifier
425 static void batadv_tt_global_size_dec(struct batadv_orig_node *orig_node,
428 batadv_tt_global_size_mod(orig_node, vid, -1);
432 * batadv_tt_orig_list_entry_free_rcu - free the orig_entry
433 * @rcu: rcu pointer of the orig_entry
435 static void batadv_tt_orig_list_entry_free_rcu(struct rcu_head *rcu)
437 struct batadv_tt_orig_list_entry *orig_entry;
439 orig_entry = container_of(rcu, struct batadv_tt_orig_list_entry, rcu);
441 kmem_cache_free(batadv_tt_orig_cache, orig_entry);
445 * batadv_tt_orig_list_entry_release - release tt orig entry from lists and
446 * queue for free after rcu grace period
447 * @ref: kref pointer of the tt orig entry
449 static void batadv_tt_orig_list_entry_release(struct kref *ref)
451 struct batadv_tt_orig_list_entry *orig_entry;
453 orig_entry = container_of(ref, struct batadv_tt_orig_list_entry,
456 batadv_orig_node_put(orig_entry->orig_node);
457 call_rcu(&orig_entry->rcu, batadv_tt_orig_list_entry_free_rcu);
461 * batadv_tt_orig_list_entry_put - decrement the tt orig entry refcounter and
462 * possibly release it
463 * @orig_entry: tt orig entry to be free'd
466 batadv_tt_orig_list_entry_put(struct batadv_tt_orig_list_entry *orig_entry)
468 kref_put(&orig_entry->refcount, batadv_tt_orig_list_entry_release);
472 * batadv_tt_local_event - store a local TT event (ADD/DEL)
473 * @bat_priv: the bat priv with all the soft interface information
474 * @tt_local_entry: the TT entry involved in the event
475 * @event_flags: flags to store in the event structure
477 static void batadv_tt_local_event(struct batadv_priv *bat_priv,
478 struct batadv_tt_local_entry *tt_local_entry,
481 struct batadv_tt_change_node *tt_change_node, *entry, *safe;
482 struct batadv_tt_common_entry *common = &tt_local_entry->common;
483 u8 flags = common->flags | event_flags;
484 bool event_removed = false;
485 bool del_op_requested, del_op_entry;
487 tt_change_node = kmem_cache_alloc(batadv_tt_change_cache, GFP_ATOMIC);
491 tt_change_node->change.flags = flags;
492 memset(tt_change_node->change.reserved, 0,
493 sizeof(tt_change_node->change.reserved));
494 ether_addr_copy(tt_change_node->change.addr, common->addr);
495 tt_change_node->change.vid = htons(common->vid);
497 del_op_requested = flags & BATADV_TT_CLIENT_DEL;
499 /* check for ADD+DEL or DEL+ADD events */
500 spin_lock_bh(&bat_priv->tt.changes_list_lock);
501 list_for_each_entry_safe(entry, safe, &bat_priv->tt.changes_list,
503 if (!batadv_compare_eth(entry->change.addr, common->addr))
506 /* DEL+ADD in the same orig interval have no effect and can be
507 * removed to avoid silly behaviour on the receiver side. The
508 * other way around (ADD+DEL) can happen in case of roaming of
509 * a client still in the NEW state. Roaming of NEW clients is
510 * now possible due to automatically recognition of "temporary"
513 del_op_entry = entry->change.flags & BATADV_TT_CLIENT_DEL;
514 if (!del_op_requested && del_op_entry)
516 if (del_op_requested && !del_op_entry)
519 /* this is a second add in the same originator interval. It
520 * means that flags have been changed: update them!
522 if (!del_op_requested && !del_op_entry)
523 entry->change.flags = flags;
527 list_del(&entry->list);
528 kmem_cache_free(batadv_tt_change_cache, entry);
529 kmem_cache_free(batadv_tt_change_cache, tt_change_node);
530 event_removed = true;
534 /* track the change in the OGMinterval list */
535 list_add_tail(&tt_change_node->list, &bat_priv->tt.changes_list);
538 spin_unlock_bh(&bat_priv->tt.changes_list_lock);
541 atomic_dec(&bat_priv->tt.local_changes);
543 atomic_inc(&bat_priv->tt.local_changes);
547 * batadv_tt_len - compute length in bytes of given number of tt changes
548 * @changes_num: number of tt changes
550 * Return: computed length in bytes.
552 static int batadv_tt_len(int changes_num)
554 return changes_num * sizeof(struct batadv_tvlv_tt_change);
558 * batadv_tt_entries - compute the number of entries fitting in tt_len bytes
559 * @tt_len: available space
561 * Return: the number of entries.
563 static u16 batadv_tt_entries(u16 tt_len)
565 return tt_len / batadv_tt_len(1);
569 * batadv_tt_local_table_transmit_size - calculates the local translation table
570 * size when transmitted over the air
571 * @bat_priv: the bat priv with all the soft interface information
573 * Return: local translation table size in bytes.
575 static int batadv_tt_local_table_transmit_size(struct batadv_priv *bat_priv)
578 u16 tt_local_entries = 0;
579 struct batadv_softif_vlan *vlan;
583 hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list) {
585 tt_local_entries += atomic_read(&vlan->tt.num_entries);
589 /* header size of tvlv encapsulated tt response payload */
590 hdr_size = sizeof(struct batadv_unicast_tvlv_packet);
591 hdr_size += sizeof(struct batadv_tvlv_hdr);
592 hdr_size += sizeof(struct batadv_tvlv_tt_data);
593 hdr_size += num_vlan * sizeof(struct batadv_tvlv_tt_vlan_data);
595 return hdr_size + batadv_tt_len(tt_local_entries);
598 static int batadv_tt_local_init(struct batadv_priv *bat_priv)
600 if (bat_priv->tt.local_hash)
603 bat_priv->tt.local_hash = batadv_hash_new(1024);
605 if (!bat_priv->tt.local_hash)
608 batadv_hash_set_lock_class(bat_priv->tt.local_hash,
609 &batadv_tt_local_hash_lock_class_key);
614 static void batadv_tt_global_free(struct batadv_priv *bat_priv,
615 struct batadv_tt_global_entry *tt_global,
618 struct batadv_tt_global_entry *tt_removed_entry;
619 struct hlist_node *tt_removed_node;
621 batadv_dbg(BATADV_DBG_TT, bat_priv,
622 "Deleting global tt entry %pM (vid: %d): %s\n",
623 tt_global->common.addr,
624 BATADV_PRINT_VID(tt_global->common.vid), message);
626 tt_removed_node = batadv_hash_remove(bat_priv->tt.global_hash,
630 if (!tt_removed_node)
633 /* drop reference of remove hash entry */
634 tt_removed_entry = hlist_entry(tt_removed_node,
635 struct batadv_tt_global_entry,
637 batadv_tt_global_entry_put(tt_removed_entry);
641 * batadv_tt_local_add - add a new client to the local table or update an
643 * @soft_iface: netdev struct of the mesh interface
644 * @addr: the mac address of the client to add
645 * @vid: VLAN identifier
646 * @ifindex: index of the interface where the client is connected to (useful to
647 * identify wireless clients)
648 * @mark: the value contained in the skb->mark field of the received packet (if
651 * Return: true if the client was successfully added, false otherwise.
653 bool batadv_tt_local_add(struct net_device *soft_iface, const u8 *addr,
654 unsigned short vid, int ifindex, u32 mark)
656 struct batadv_priv *bat_priv = netdev_priv(soft_iface);
657 struct batadv_tt_local_entry *tt_local;
658 struct batadv_tt_global_entry *tt_global = NULL;
659 struct net *net = dev_net(soft_iface);
660 struct batadv_softif_vlan *vlan;
661 struct net_device *in_dev = 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);
673 tt_local = batadv_tt_local_hash_find(bat_priv, addr, vid);
675 if (!is_multicast_ether_addr(addr))
676 tt_global = batadv_tt_global_hash_find(bat_priv, addr, vid);
679 tt_local->last_seen = jiffies;
680 if (tt_local->common.flags & BATADV_TT_CLIENT_PENDING) {
681 batadv_dbg(BATADV_DBG_TT, bat_priv,
682 "Re-adding pending client %pM (vid: %d)\n",
683 addr, BATADV_PRINT_VID(vid));
684 /* whatever the reason why the PENDING flag was set,
685 * this is a client which was enqueued to be removed in
686 * this orig_interval. Since it popped up again, the
687 * flag can be reset like it was never enqueued
689 tt_local->common.flags &= ~BATADV_TT_CLIENT_PENDING;
693 if (tt_local->common.flags & BATADV_TT_CLIENT_ROAM) {
694 batadv_dbg(BATADV_DBG_TT, bat_priv,
695 "Roaming client %pM (vid: %d) came back to its original location\n",
696 addr, BATADV_PRINT_VID(vid));
697 /* the ROAM flag is set because this client roamed away
698 * and the node got a roaming_advertisement message. Now
699 * that the client popped up again at its original
700 * location such flag can be unset
702 tt_local->common.flags &= ~BATADV_TT_CLIENT_ROAM;
708 /* Ignore the client if we cannot send it in a full table response. */
709 table_size = batadv_tt_local_table_transmit_size(bat_priv);
710 table_size += batadv_tt_len(1);
711 packet_size_max = atomic_read(&bat_priv->packet_size_max);
712 if (table_size > packet_size_max) {
713 net_ratelimited_function(batadv_info, soft_iface,
714 "Local translation table size (%i) exceeds maximum packet size (%i); Ignoring new local tt entry: %pM\n",
715 table_size, packet_size_max, addr);
719 tt_local = kmem_cache_alloc(batadv_tl_cache, GFP_ATOMIC);
723 /* increase the refcounter of the related vlan */
724 vlan = batadv_softif_vlan_get(bat_priv, vid);
726 net_ratelimited_function(batadv_info, soft_iface,
727 "adding TT local entry %pM to non-existent VLAN %d\n",
728 addr, BATADV_PRINT_VID(vid));
729 kmem_cache_free(batadv_tl_cache, tt_local);
734 batadv_dbg(BATADV_DBG_TT, bat_priv,
735 "Creating new local tt entry: %pM (vid: %d, ttvn: %d)\n",
736 addr, BATADV_PRINT_VID(vid),
737 (u8)atomic_read(&bat_priv->tt.vn));
739 ether_addr_copy(tt_local->common.addr, addr);
740 /* The local entry has to be marked as NEW to avoid to send it in
741 * a full table response going out before the next ttvn increment
742 * (consistency check)
744 tt_local->common.flags = BATADV_TT_CLIENT_NEW;
745 tt_local->common.vid = vid;
746 if (batadv_is_wifi_netdev(in_dev))
747 tt_local->common.flags |= BATADV_TT_CLIENT_WIFI;
748 kref_init(&tt_local->common.refcount);
749 tt_local->last_seen = jiffies;
750 tt_local->common.added_at = tt_local->last_seen;
751 tt_local->vlan = vlan;
753 /* the batman interface mac and multicast addresses should never be
756 if (batadv_compare_eth(addr, soft_iface->dev_addr) ||
757 is_multicast_ether_addr(addr))
758 tt_local->common.flags |= BATADV_TT_CLIENT_NOPURGE;
760 kref_get(&tt_local->common.refcount);
761 hash_added = batadv_hash_add(bat_priv->tt.local_hash, batadv_compare_tt,
762 batadv_choose_tt, &tt_local->common,
763 &tt_local->common.hash_entry);
765 if (unlikely(hash_added != 0)) {
766 /* remove the reference for the hash */
767 batadv_tt_local_entry_put(tt_local);
772 batadv_tt_local_event(bat_priv, tt_local, BATADV_NO_FLAGS);
775 /* Check whether it is a roaming, but don't do anything if the roaming
776 * process has already been handled
778 if (tt_global && !(tt_global->common.flags & BATADV_TT_CLIENT_ROAM)) {
779 /* These node are probably going to update their tt table */
780 head = &tt_global->orig_list;
782 hlist_for_each_entry_rcu(orig_entry, head, list) {
783 batadv_send_roam_adv(bat_priv, tt_global->common.addr,
784 tt_global->common.vid,
785 orig_entry->orig_node);
789 batadv_tt_global_free(bat_priv, tt_global,
793 /* The global entry has to be marked as ROAMING and
794 * has to be kept for consistency purpose
796 tt_global->common.flags |= BATADV_TT_CLIENT_ROAM;
797 tt_global->roam_at = jiffies;
801 /* store the current remote flags before altering them. This helps
802 * understanding is flags are changing or not
804 remote_flags = tt_local->common.flags & BATADV_TT_REMOTE_MASK;
806 if (batadv_is_wifi_netdev(in_dev))
807 tt_local->common.flags |= BATADV_TT_CLIENT_WIFI;
809 tt_local->common.flags &= ~BATADV_TT_CLIENT_WIFI;
811 /* check the mark in the skb: if it's equal to the configured
812 * isolation_mark, it means the packet is coming from an isolated
815 match_mark = (mark & bat_priv->isolation_mark_mask);
816 if (bat_priv->isolation_mark_mask &&
817 match_mark == bat_priv->isolation_mark)
818 tt_local->common.flags |= BATADV_TT_CLIENT_ISOLA;
820 tt_local->common.flags &= ~BATADV_TT_CLIENT_ISOLA;
822 /* if any "dynamic" flag has been modified, resend an ADD event for this
823 * entry so that all the nodes can get the new flags
825 if (remote_flags ^ (tt_local->common.flags & BATADV_TT_REMOTE_MASK))
826 batadv_tt_local_event(bat_priv, tt_local, BATADV_NO_FLAGS);
833 batadv_tt_local_entry_put(tt_local);
835 batadv_tt_global_entry_put(tt_global);
840 * batadv_tt_prepare_tvlv_global_data - prepare the TVLV TT header to send
841 * within a TT Response directed to another node
842 * @orig_node: originator for which the TT data has to be prepared
843 * @tt_data: uninitialised pointer to the address of the TVLV buffer
844 * @tt_change: uninitialised pointer to the address of the area where the TT
845 * changed can be stored
846 * @tt_len: pointer to the length to reserve to the tt_change. if -1 this
847 * function reserves the amount of space needed to send the entire global TT
848 * table. In case of success the value is updated with the real amount of
850 * Allocate the needed amount of memory for the entire TT TVLV and write its
851 * header made up by one tvlv_tt_data object and a series of tvlv_tt_vlan_data
852 * objects, one per active VLAN served by the originator node.
854 * Return: the size of the allocated buffer or 0 in case of failure.
857 batadv_tt_prepare_tvlv_global_data(struct batadv_orig_node *orig_node,
858 struct batadv_tvlv_tt_data **tt_data,
859 struct batadv_tvlv_tt_change **tt_change,
866 struct batadv_tvlv_tt_vlan_data *tt_vlan;
867 struct batadv_orig_node_vlan *vlan;
870 spin_lock_bh(&orig_node->vlan_list_lock);
871 hlist_for_each_entry_rcu(vlan, &orig_node->vlan_list, list) {
873 num_entries += atomic_read(&vlan->tt.num_entries);
876 change_offset = sizeof(**tt_data);
877 change_offset += num_vlan * sizeof(*tt_vlan);
879 /* if tt_len is negative, allocate the space needed by the full table */
881 *tt_len = batadv_tt_len(num_entries);
884 tvlv_len += change_offset;
886 *tt_data = kmalloc(tvlv_len, GFP_ATOMIC);
892 (*tt_data)->flags = BATADV_NO_FLAGS;
893 (*tt_data)->ttvn = atomic_read(&orig_node->last_ttvn);
894 (*tt_data)->num_vlan = htons(num_vlan);
896 tt_vlan = (struct batadv_tvlv_tt_vlan_data *)(*tt_data + 1);
897 hlist_for_each_entry_rcu(vlan, &orig_node->vlan_list, list) {
898 tt_vlan->vid = htons(vlan->vid);
899 tt_vlan->crc = htonl(vlan->tt.crc);
900 tt_vlan->reserved = 0;
905 tt_change_ptr = (u8 *)*tt_data + change_offset;
906 *tt_change = (struct batadv_tvlv_tt_change *)tt_change_ptr;
909 spin_unlock_bh(&orig_node->vlan_list_lock);
914 * batadv_tt_prepare_tvlv_local_data - allocate and prepare the TT TVLV for this
916 * @bat_priv: the bat priv with all the soft interface information
917 * @tt_data: uninitialised pointer to the address of the TVLV buffer
918 * @tt_change: uninitialised pointer to the address of the area where the TT
919 * changes can be stored
920 * @tt_len: pointer to the length to reserve to the tt_change. if -1 this
921 * function reserves the amount of space needed to send the entire local TT
922 * table. In case of success the value is updated with the real amount of
925 * Allocate the needed amount of memory for the entire TT TVLV and write its
926 * header made up by one tvlv_tt_data object and a series of tvlv_tt_vlan_data
927 * objects, one per active VLAN.
929 * Return: the size of the allocated buffer or 0 in case of failure.
932 batadv_tt_prepare_tvlv_local_data(struct batadv_priv *bat_priv,
933 struct batadv_tvlv_tt_data **tt_data,
934 struct batadv_tvlv_tt_change **tt_change,
937 struct batadv_tvlv_tt_vlan_data *tt_vlan;
938 struct batadv_softif_vlan *vlan;
940 u16 vlan_entries = 0;
941 u16 total_entries = 0;
946 spin_lock_bh(&bat_priv->softif_vlan_list_lock);
947 hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list) {
948 vlan_entries = atomic_read(&vlan->tt.num_entries);
949 if (vlan_entries < 1)
953 total_entries += vlan_entries;
956 change_offset = sizeof(**tt_data);
957 change_offset += num_vlan * sizeof(*tt_vlan);
959 /* if tt_len is negative, allocate the space needed by the full table */
961 *tt_len = batadv_tt_len(total_entries);
964 tvlv_len += change_offset;
966 *tt_data = kmalloc(tvlv_len, GFP_ATOMIC);
972 (*tt_data)->flags = BATADV_NO_FLAGS;
973 (*tt_data)->ttvn = atomic_read(&bat_priv->tt.vn);
974 (*tt_data)->num_vlan = htons(num_vlan);
976 tt_vlan = (struct batadv_tvlv_tt_vlan_data *)(*tt_data + 1);
977 hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list) {
978 vlan_entries = atomic_read(&vlan->tt.num_entries);
979 if (vlan_entries < 1)
982 tt_vlan->vid = htons(vlan->vid);
983 tt_vlan->crc = htonl(vlan->tt.crc);
984 tt_vlan->reserved = 0;
989 tt_change_ptr = (u8 *)*tt_data + change_offset;
990 *tt_change = (struct batadv_tvlv_tt_change *)tt_change_ptr;
993 spin_unlock_bh(&bat_priv->softif_vlan_list_lock);
998 * batadv_tt_tvlv_container_update - update the translation table tvlv container
999 * after local tt changes have been committed
1000 * @bat_priv: the bat priv with all the soft interface information
1002 static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv)
1004 struct batadv_tt_change_node *entry, *safe;
1005 struct batadv_tvlv_tt_data *tt_data;
1006 struct batadv_tvlv_tt_change *tt_change;
1007 int tt_diff_len, tt_change_len = 0;
1008 int tt_diff_entries_num = 0;
1009 int tt_diff_entries_count = 0;
1012 tt_diff_entries_num = atomic_read(&bat_priv->tt.local_changes);
1013 tt_diff_len = batadv_tt_len(tt_diff_entries_num);
1015 /* if we have too many changes for one packet don't send any
1016 * and wait for the tt table request which will be fragmented
1018 if (tt_diff_len > bat_priv->soft_iface->mtu)
1021 tvlv_len = batadv_tt_prepare_tvlv_local_data(bat_priv, &tt_data,
1022 &tt_change, &tt_diff_len);
1026 tt_data->flags = BATADV_TT_OGM_DIFF;
1028 if (tt_diff_len == 0)
1029 goto container_register;
1031 spin_lock_bh(&bat_priv->tt.changes_list_lock);
1032 atomic_set(&bat_priv->tt.local_changes, 0);
1034 list_for_each_entry_safe(entry, safe, &bat_priv->tt.changes_list,
1036 if (tt_diff_entries_count < tt_diff_entries_num) {
1037 memcpy(tt_change + tt_diff_entries_count,
1039 sizeof(struct batadv_tvlv_tt_change));
1040 tt_diff_entries_count++;
1042 list_del(&entry->list);
1043 kmem_cache_free(batadv_tt_change_cache, entry);
1045 spin_unlock_bh(&bat_priv->tt.changes_list_lock);
1047 /* Keep the buffer for possible tt_request */
1048 spin_lock_bh(&bat_priv->tt.last_changeset_lock);
1049 kfree(bat_priv->tt.last_changeset);
1050 bat_priv->tt.last_changeset_len = 0;
1051 bat_priv->tt.last_changeset = NULL;
1052 tt_change_len = batadv_tt_len(tt_diff_entries_count);
1053 /* check whether this new OGM has no changes due to size problems */
1054 if (tt_diff_entries_count > 0) {
1055 /* if kmalloc() fails we will reply with the full table
1056 * instead of providing the diff
1058 bat_priv->tt.last_changeset = kzalloc(tt_diff_len, GFP_ATOMIC);
1059 if (bat_priv->tt.last_changeset) {
1060 memcpy(bat_priv->tt.last_changeset,
1061 tt_change, tt_change_len);
1062 bat_priv->tt.last_changeset_len = tt_diff_len;
1065 spin_unlock_bh(&bat_priv->tt.last_changeset_lock);
1068 batadv_tvlv_container_register(bat_priv, BATADV_TVLV_TT, 1, tt_data,
1073 #ifdef CONFIG_BATMAN_ADV_DEBUGFS
1074 int batadv_tt_local_seq_print_text(struct seq_file *seq, void *offset)
1076 struct net_device *net_dev = (struct net_device *)seq->private;
1077 struct batadv_priv *bat_priv = netdev_priv(net_dev);
1078 struct batadv_hashtable *hash = bat_priv->tt.local_hash;
1079 struct batadv_tt_common_entry *tt_common_entry;
1080 struct batadv_tt_local_entry *tt_local;
1081 struct batadv_hard_iface *primary_if;
1082 struct hlist_head *head;
1085 int last_seen_msecs;
1086 unsigned long last_seen_jiffies;
1088 u16 np_flag = BATADV_TT_CLIENT_NOPURGE;
1090 primary_if = batadv_seq_print_text_primary_if_get(seq);
1095 "Locally retrieved addresses (from %s) announced via TT (TTVN: %u):\n",
1096 net_dev->name, (u8)atomic_read(&bat_priv->tt.vn));
1098 " Client VID Flags Last seen (CRC )\n");
1100 for (i = 0; i < hash->size; i++) {
1101 head = &hash->table[i];
1104 hlist_for_each_entry_rcu(tt_common_entry,
1106 tt_local = container_of(tt_common_entry,
1107 struct batadv_tt_local_entry,
1109 last_seen_jiffies = jiffies - tt_local->last_seen;
1110 last_seen_msecs = jiffies_to_msecs(last_seen_jiffies);
1111 last_seen_secs = last_seen_msecs / 1000;
1112 last_seen_msecs = last_seen_msecs % 1000;
1114 no_purge = tt_common_entry->flags & np_flag;
1116 " * %pM %4i [%c%c%c%c%c%c] %3u.%03u (%#.8x)\n",
1117 tt_common_entry->addr,
1118 BATADV_PRINT_VID(tt_common_entry->vid),
1119 ((tt_common_entry->flags &
1120 BATADV_TT_CLIENT_ROAM) ? 'R' : '.'),
1121 no_purge ? 'P' : '.',
1122 ((tt_common_entry->flags &
1123 BATADV_TT_CLIENT_NEW) ? 'N' : '.'),
1124 ((tt_common_entry->flags &
1125 BATADV_TT_CLIENT_PENDING) ? 'X' : '.'),
1126 ((tt_common_entry->flags &
1127 BATADV_TT_CLIENT_WIFI) ? 'W' : '.'),
1128 ((tt_common_entry->flags &
1129 BATADV_TT_CLIENT_ISOLA) ? 'I' : '.'),
1130 no_purge ? 0 : last_seen_secs,
1131 no_purge ? 0 : last_seen_msecs,
1132 tt_local->vlan->tt.crc);
1138 batadv_hardif_put(primary_if);
1144 * batadv_tt_local_dump_entry - Dump one TT local entry into a message
1145 * @msg :Netlink message to dump into
1146 * @portid: Port making netlink request
1147 * @seq: Sequence number of netlink message
1148 * @bat_priv: The bat priv with all the soft interface information
1149 * @common: tt local & tt global common data
1151 * Return: Error code, or 0 on success
1154 batadv_tt_local_dump_entry(struct sk_buff *msg, u32 portid, u32 seq,
1155 struct batadv_priv *bat_priv,
1156 struct batadv_tt_common_entry *common)
1159 struct batadv_softif_vlan *vlan;
1160 struct batadv_tt_local_entry *local;
1161 unsigned int last_seen_msecs;
1164 local = container_of(common, struct batadv_tt_local_entry, common);
1165 last_seen_msecs = jiffies_to_msecs(jiffies - local->last_seen);
1167 vlan = batadv_softif_vlan_get(bat_priv, common->vid);
1173 batadv_softif_vlan_put(vlan);
1175 hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family,
1177 BATADV_CMD_GET_TRANSTABLE_LOCAL);
1181 if (nla_put(msg, BATADV_ATTR_TT_ADDRESS, ETH_ALEN, common->addr) ||
1182 nla_put_u32(msg, BATADV_ATTR_TT_CRC32, crc) ||
1183 nla_put_u16(msg, BATADV_ATTR_TT_VID, common->vid) ||
1184 nla_put_u32(msg, BATADV_ATTR_TT_FLAGS, common->flags))
1185 goto nla_put_failure;
1187 if (!(common->flags & BATADV_TT_CLIENT_NOPURGE) &&
1188 nla_put_u32(msg, BATADV_ATTR_LAST_SEEN_MSECS, last_seen_msecs))
1189 goto nla_put_failure;
1191 genlmsg_end(msg, hdr);
1195 genlmsg_cancel(msg, hdr);
1200 * batadv_tt_local_dump_bucket - Dump one TT local bucket into a message
1201 * @msg: Netlink message to dump into
1202 * @portid: Port making netlink request
1203 * @seq: Sequence number of netlink message
1204 * @bat_priv: The bat priv with all the soft interface information
1205 * @head: Pointer to the list containing the local tt entries
1206 * @idx_s: Number of entries to skip
1208 * Return: Error code, or 0 on success
1211 batadv_tt_local_dump_bucket(struct sk_buff *msg, u32 portid, u32 seq,
1212 struct batadv_priv *bat_priv,
1213 struct hlist_head *head, int *idx_s)
1215 struct batadv_tt_common_entry *common;
1219 hlist_for_each_entry_rcu(common, head, hash_entry) {
1223 if (batadv_tt_local_dump_entry(msg, portid, seq, bat_priv,
1237 * batadv_tt_local_dump - Dump TT local entries into a message
1238 * @msg: Netlink message to dump into
1239 * @cb: Parameters from query
1241 * Return: Error code, or 0 on success
1243 int batadv_tt_local_dump(struct sk_buff *msg, struct netlink_callback *cb)
1245 struct net *net = sock_net(cb->skb->sk);
1246 struct net_device *soft_iface;
1247 struct batadv_priv *bat_priv;
1248 struct batadv_hard_iface *primary_if = NULL;
1249 struct batadv_hashtable *hash;
1250 struct hlist_head *head;
1253 int bucket = cb->args[0];
1254 int idx = cb->args[1];
1255 int portid = NETLINK_CB(cb->skb).portid;
1257 ifindex = batadv_netlink_get_ifindex(cb->nlh, BATADV_ATTR_MESH_IFINDEX);
1261 soft_iface = dev_get_by_index(net, ifindex);
1262 if (!soft_iface || !batadv_softif_is_valid(soft_iface)) {
1267 bat_priv = netdev_priv(soft_iface);
1269 primary_if = batadv_primary_if_get_selected(bat_priv);
1270 if (!primary_if || primary_if->if_status != BATADV_IF_ACTIVE) {
1275 hash = bat_priv->tt.local_hash;
1277 while (bucket < hash->size) {
1278 head = &hash->table[bucket];
1280 if (batadv_tt_local_dump_bucket(msg, portid, cb->nlh->nlmsg_seq,
1281 bat_priv, head, &idx))
1291 batadv_hardif_put(primary_if);
1293 dev_put(soft_iface);
1295 cb->args[0] = bucket;
1302 batadv_tt_local_set_pending(struct batadv_priv *bat_priv,
1303 struct batadv_tt_local_entry *tt_local_entry,
1304 u16 flags, const char *message)
1306 batadv_tt_local_event(bat_priv, tt_local_entry, flags);
1308 /* The local client has to be marked as "pending to be removed" but has
1309 * to be kept in the table in order to send it in a full table
1310 * response issued before the net ttvn increment (consistency check)
1312 tt_local_entry->common.flags |= BATADV_TT_CLIENT_PENDING;
1314 batadv_dbg(BATADV_DBG_TT, bat_priv,
1315 "Local tt entry (%pM, vid: %d) pending to be removed: %s\n",
1316 tt_local_entry->common.addr,
1317 BATADV_PRINT_VID(tt_local_entry->common.vid), message);
1321 * batadv_tt_local_remove - logically remove an entry from the local table
1322 * @bat_priv: the bat priv with all the soft interface information
1323 * @addr: the MAC address of the client to remove
1324 * @vid: VLAN identifier
1325 * @message: message to append to the log on deletion
1326 * @roaming: true if the deletion is due to a roaming event
1328 * Return: the flags assigned to the local entry before being deleted
1330 u16 batadv_tt_local_remove(struct batadv_priv *bat_priv, const u8 *addr,
1331 unsigned short vid, const char *message,
1334 struct batadv_tt_local_entry *tt_removed_entry;
1335 struct batadv_tt_local_entry *tt_local_entry;
1336 u16 flags, curr_flags = BATADV_NO_FLAGS;
1337 struct hlist_node *tt_removed_node;
1339 tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr, vid);
1340 if (!tt_local_entry)
1343 curr_flags = tt_local_entry->common.flags;
1345 flags = BATADV_TT_CLIENT_DEL;
1346 /* if this global entry addition is due to a roaming, the node has to
1347 * mark the local entry as "roamed" in order to correctly reroute
1351 flags |= BATADV_TT_CLIENT_ROAM;
1352 /* mark the local client as ROAMed */
1353 tt_local_entry->common.flags |= BATADV_TT_CLIENT_ROAM;
1356 if (!(tt_local_entry->common.flags & BATADV_TT_CLIENT_NEW)) {
1357 batadv_tt_local_set_pending(bat_priv, tt_local_entry, flags,
1361 /* if this client has been added right now, it is possible to
1362 * immediately purge it
1364 batadv_tt_local_event(bat_priv, tt_local_entry, BATADV_TT_CLIENT_DEL);
1366 tt_removed_node = batadv_hash_remove(bat_priv->tt.local_hash,
1369 &tt_local_entry->common);
1370 if (!tt_removed_node)
1373 /* drop reference of remove hash entry */
1374 tt_removed_entry = hlist_entry(tt_removed_node,
1375 struct batadv_tt_local_entry,
1377 batadv_tt_local_entry_put(tt_removed_entry);
1381 batadv_tt_local_entry_put(tt_local_entry);
1387 * batadv_tt_local_purge_list - purge inactive tt local entries
1388 * @bat_priv: the bat priv with all the soft interface information
1389 * @head: pointer to the list containing the local tt entries
1390 * @timeout: parameter deciding whether a given tt local entry is considered
1393 static void batadv_tt_local_purge_list(struct batadv_priv *bat_priv,
1394 struct hlist_head *head,
1397 struct batadv_tt_local_entry *tt_local_entry;
1398 struct batadv_tt_common_entry *tt_common_entry;
1399 struct hlist_node *node_tmp;
1401 hlist_for_each_entry_safe(tt_common_entry, node_tmp, head,
1403 tt_local_entry = container_of(tt_common_entry,
1404 struct batadv_tt_local_entry,
1406 if (tt_local_entry->common.flags & BATADV_TT_CLIENT_NOPURGE)
1409 /* entry already marked for deletion */
1410 if (tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING)
1413 if (!batadv_has_timed_out(tt_local_entry->last_seen, timeout))
1416 batadv_tt_local_set_pending(bat_priv, tt_local_entry,
1417 BATADV_TT_CLIENT_DEL, "timed out");
1422 * batadv_tt_local_purge - purge inactive tt local entries
1423 * @bat_priv: the bat priv with all the soft interface information
1424 * @timeout: parameter deciding whether a given tt local entry is considered
1427 static void batadv_tt_local_purge(struct batadv_priv *bat_priv,
1430 struct batadv_hashtable *hash = bat_priv->tt.local_hash;
1431 struct hlist_head *head;
1432 spinlock_t *list_lock; /* protects write access to the hash lists */
1435 for (i = 0; i < hash->size; i++) {
1436 head = &hash->table[i];
1437 list_lock = &hash->list_locks[i];
1439 spin_lock_bh(list_lock);
1440 batadv_tt_local_purge_list(bat_priv, head, timeout);
1441 spin_unlock_bh(list_lock);
1445 static void batadv_tt_local_table_free(struct batadv_priv *bat_priv)
1447 struct batadv_hashtable *hash;
1448 spinlock_t *list_lock; /* protects write access to the hash lists */
1449 struct batadv_tt_common_entry *tt_common_entry;
1450 struct batadv_tt_local_entry *tt_local;
1451 struct hlist_node *node_tmp;
1452 struct hlist_head *head;
1455 if (!bat_priv->tt.local_hash)
1458 hash = bat_priv->tt.local_hash;
1460 for (i = 0; i < hash->size; i++) {
1461 head = &hash->table[i];
1462 list_lock = &hash->list_locks[i];
1464 spin_lock_bh(list_lock);
1465 hlist_for_each_entry_safe(tt_common_entry, node_tmp,
1467 hlist_del_rcu(&tt_common_entry->hash_entry);
1468 tt_local = container_of(tt_common_entry,
1469 struct batadv_tt_local_entry,
1472 batadv_tt_local_entry_put(tt_local);
1474 spin_unlock_bh(list_lock);
1477 batadv_hash_destroy(hash);
1479 bat_priv->tt.local_hash = NULL;
1482 static int batadv_tt_global_init(struct batadv_priv *bat_priv)
1484 if (bat_priv->tt.global_hash)
1487 bat_priv->tt.global_hash = batadv_hash_new(1024);
1489 if (!bat_priv->tt.global_hash)
1492 batadv_hash_set_lock_class(bat_priv->tt.global_hash,
1493 &batadv_tt_global_hash_lock_class_key);
1498 static void batadv_tt_changes_list_free(struct batadv_priv *bat_priv)
1500 struct batadv_tt_change_node *entry, *safe;
1502 spin_lock_bh(&bat_priv->tt.changes_list_lock);
1504 list_for_each_entry_safe(entry, safe, &bat_priv->tt.changes_list,
1506 list_del(&entry->list);
1507 kmem_cache_free(batadv_tt_change_cache, entry);
1510 atomic_set(&bat_priv->tt.local_changes, 0);
1511 spin_unlock_bh(&bat_priv->tt.changes_list_lock);
1515 * batadv_tt_global_orig_entry_find - find a TT orig_list_entry
1516 * @entry: the TT global entry where the orig_list_entry has to be
1518 * @orig_node: the originator for which the orig_list_entry has to be found
1520 * retrieve the orig_tt_list_entry belonging to orig_node from the
1521 * batadv_tt_global_entry list
1523 * Return: it with an increased refcounter, NULL if not found
1525 static struct batadv_tt_orig_list_entry *
1526 batadv_tt_global_orig_entry_find(const struct batadv_tt_global_entry *entry,
1527 const struct batadv_orig_node *orig_node)
1529 struct batadv_tt_orig_list_entry *tmp_orig_entry, *orig_entry = NULL;
1530 const struct hlist_head *head;
1533 head = &entry->orig_list;
1534 hlist_for_each_entry_rcu(tmp_orig_entry, head, list) {
1535 if (tmp_orig_entry->orig_node != orig_node)
1537 if (!kref_get_unless_zero(&tmp_orig_entry->refcount))
1540 orig_entry = tmp_orig_entry;
1549 * batadv_tt_global_entry_has_orig - check if a TT global entry is also handled
1550 * by a given originator
1551 * @entry: the TT global entry to check
1552 * @orig_node: the originator to search in the list
1553 * @flags: a pointer to store TT flags for the given @entry received
1556 * find out if an orig_node is already in the list of a tt_global_entry.
1558 * Return: true if found, false otherwise
1561 batadv_tt_global_entry_has_orig(const struct batadv_tt_global_entry *entry,
1562 const struct batadv_orig_node *orig_node,
1565 struct batadv_tt_orig_list_entry *orig_entry;
1568 orig_entry = batadv_tt_global_orig_entry_find(entry, orig_node);
1573 *flags = orig_entry->flags;
1575 batadv_tt_orig_list_entry_put(orig_entry);
1582 * batadv_tt_global_sync_flags - update TT sync flags
1583 * @tt_global: the TT global entry to update sync flags in
1585 * Updates the sync flag bits in the tt_global flag attribute with a logical
1586 * OR of all sync flags from any of its TT orig entries.
1589 batadv_tt_global_sync_flags(struct batadv_tt_global_entry *tt_global)
1591 struct batadv_tt_orig_list_entry *orig_entry;
1592 const struct hlist_head *head;
1593 u16 flags = BATADV_NO_FLAGS;
1596 head = &tt_global->orig_list;
1597 hlist_for_each_entry_rcu(orig_entry, head, list)
1598 flags |= orig_entry->flags;
1601 flags |= tt_global->common.flags & (~BATADV_TT_SYNC_MASK);
1602 tt_global->common.flags = flags;
1606 * batadv_tt_global_orig_entry_add - add or update a TT orig entry
1607 * @tt_global: the TT global entry to add an orig entry in
1608 * @orig_node: the originator to add an orig entry for
1609 * @ttvn: translation table version number of this changeset
1610 * @flags: TT sync flags
1613 batadv_tt_global_orig_entry_add(struct batadv_tt_global_entry *tt_global,
1614 struct batadv_orig_node *orig_node, int ttvn,
1617 struct batadv_tt_orig_list_entry *orig_entry;
1619 spin_lock_bh(&tt_global->list_lock);
1621 orig_entry = batadv_tt_global_orig_entry_find(tt_global, orig_node);
1623 /* refresh the ttvn: the current value could be a bogus one that
1624 * was added during a "temporary client detection"
1626 orig_entry->ttvn = ttvn;
1627 orig_entry->flags = flags;
1631 orig_entry = kmem_cache_zalloc(batadv_tt_orig_cache, GFP_ATOMIC);
1635 INIT_HLIST_NODE(&orig_entry->list);
1636 kref_get(&orig_node->refcount);
1637 batadv_tt_global_size_inc(orig_node, tt_global->common.vid);
1638 orig_entry->orig_node = orig_node;
1639 orig_entry->ttvn = ttvn;
1640 orig_entry->flags = flags;
1641 kref_init(&orig_entry->refcount);
1643 kref_get(&orig_entry->refcount);
1644 hlist_add_head_rcu(&orig_entry->list,
1645 &tt_global->orig_list);
1646 atomic_inc(&tt_global->orig_list_count);
1649 batadv_tt_global_sync_flags(tt_global);
1652 batadv_tt_orig_list_entry_put(orig_entry);
1654 spin_unlock_bh(&tt_global->list_lock);
1658 * batadv_tt_global_add - add a new TT global entry or update an existing one
1659 * @bat_priv: the bat priv with all the soft interface information
1660 * @orig_node: the originator announcing the client
1661 * @tt_addr: the mac address of the non-mesh client
1662 * @vid: VLAN identifier
1663 * @flags: TT flags that have to be set for this non-mesh client
1664 * @ttvn: the tt version number ever announcing this non-mesh client
1666 * Add a new TT global entry for the given originator. If the entry already
1667 * exists add a new reference to the given originator (a global entry can have
1668 * references to multiple originators) and adjust the flags attribute to reflect
1669 * the function argument.
1670 * If a TT local entry exists for this non-mesh client remove it.
1672 * The caller must hold orig_node refcount.
1674 * Return: true if the new entry has been added, false otherwise
1676 static bool batadv_tt_global_add(struct batadv_priv *bat_priv,
1677 struct batadv_orig_node *orig_node,
1678 const unsigned char *tt_addr,
1679 unsigned short vid, u16 flags, u8 ttvn)
1681 struct batadv_tt_global_entry *tt_global_entry;
1682 struct batadv_tt_local_entry *tt_local_entry;
1685 struct batadv_tt_common_entry *common;
1688 /* ignore global entries from backbone nodes */
1689 if (batadv_bla_is_backbone_gw_orig(bat_priv, orig_node->orig, vid))
1692 tt_global_entry = batadv_tt_global_hash_find(bat_priv, tt_addr, vid);
1693 tt_local_entry = batadv_tt_local_hash_find(bat_priv, tt_addr, vid);
1695 /* if the node already has a local client for this entry, it has to wait
1696 * for a roaming advertisement instead of manually messing up the global
1699 if ((flags & BATADV_TT_CLIENT_TEMP) && tt_local_entry &&
1700 !(tt_local_entry->common.flags & BATADV_TT_CLIENT_NEW))
1703 if (!tt_global_entry) {
1704 tt_global_entry = kmem_cache_zalloc(batadv_tg_cache,
1706 if (!tt_global_entry)
1709 common = &tt_global_entry->common;
1710 ether_addr_copy(common->addr, tt_addr);
1713 if (!is_multicast_ether_addr(common->addr))
1714 common->flags = flags & (~BATADV_TT_SYNC_MASK);
1716 tt_global_entry->roam_at = 0;
1717 /* node must store current time in case of roaming. This is
1718 * needed to purge this entry out on timeout (if nobody claims
1721 if (flags & BATADV_TT_CLIENT_ROAM)
1722 tt_global_entry->roam_at = jiffies;
1723 kref_init(&common->refcount);
1724 common->added_at = jiffies;
1726 INIT_HLIST_HEAD(&tt_global_entry->orig_list);
1727 atomic_set(&tt_global_entry->orig_list_count, 0);
1728 spin_lock_init(&tt_global_entry->list_lock);
1730 kref_get(&common->refcount);
1731 hash_added = batadv_hash_add(bat_priv->tt.global_hash,
1733 batadv_choose_tt, common,
1734 &common->hash_entry);
1736 if (unlikely(hash_added != 0)) {
1737 /* remove the reference for the hash */
1738 batadv_tt_global_entry_put(tt_global_entry);
1742 common = &tt_global_entry->common;
1743 /* If there is already a global entry, we can use this one for
1745 * But if we are trying to add a temporary client then here are
1746 * two options at this point:
1747 * 1) the global client is not a temporary client: the global
1748 * client has to be left as it is, temporary information
1749 * should never override any already known client state
1750 * 2) the global client is a temporary client: purge the
1751 * originator list and add the new one orig_entry
1753 if (flags & BATADV_TT_CLIENT_TEMP) {
1754 if (!(common->flags & BATADV_TT_CLIENT_TEMP))
1756 if (batadv_tt_global_entry_has_orig(tt_global_entry,
1759 batadv_tt_global_del_orig_list(tt_global_entry);
1760 goto add_orig_entry;
1763 /* if the client was temporary added before receiving the first
1764 * OGM announcing it, we have to clear the TEMP flag. Also,
1765 * remove the previous temporary orig node and re-add it
1766 * if required. If the orig entry changed, the new one which
1767 * is a non-temporary entry is preferred.
1769 if (common->flags & BATADV_TT_CLIENT_TEMP) {
1770 batadv_tt_global_del_orig_list(tt_global_entry);
1771 common->flags &= ~BATADV_TT_CLIENT_TEMP;
1774 /* the change can carry possible "attribute" flags like the
1775 * TT_CLIENT_TEMP, therefore they have to be copied in the
1778 if (!is_multicast_ether_addr(common->addr))
1779 common->flags |= flags & (~BATADV_TT_SYNC_MASK);
1781 /* If there is the BATADV_TT_CLIENT_ROAM flag set, there is only
1782 * one originator left in the list and we previously received a
1783 * delete + roaming change for this originator.
1785 * We should first delete the old originator before adding the
1788 if (common->flags & BATADV_TT_CLIENT_ROAM) {
1789 batadv_tt_global_del_orig_list(tt_global_entry);
1790 common->flags &= ~BATADV_TT_CLIENT_ROAM;
1791 tt_global_entry->roam_at = 0;
1795 /* add the new orig_entry (if needed) or update it */
1796 batadv_tt_global_orig_entry_add(tt_global_entry, orig_node, ttvn,
1797 flags & BATADV_TT_SYNC_MASK);
1799 batadv_dbg(BATADV_DBG_TT, bat_priv,
1800 "Creating new global tt entry: %pM (vid: %d, via %pM)\n",
1801 common->addr, BATADV_PRINT_VID(common->vid),
1806 /* Do not remove multicast addresses from the local hash on
1809 if (is_multicast_ether_addr(tt_addr))
1812 /* remove address from local hash if present */
1813 local_flags = batadv_tt_local_remove(bat_priv, tt_addr, vid,
1814 "global tt received",
1815 flags & BATADV_TT_CLIENT_ROAM);
1816 tt_global_entry->common.flags |= local_flags & BATADV_TT_CLIENT_WIFI;
1818 if (!(flags & BATADV_TT_CLIENT_ROAM))
1819 /* this is a normal global add. Therefore the client is not in a
1820 * roaming state anymore.
1822 tt_global_entry->common.flags &= ~BATADV_TT_CLIENT_ROAM;
1825 if (tt_global_entry)
1826 batadv_tt_global_entry_put(tt_global_entry);
1828 batadv_tt_local_entry_put(tt_local_entry);
1833 * batadv_transtable_best_orig - Get best originator list entry from tt entry
1834 * @bat_priv: the bat priv with all the soft interface information
1835 * @tt_global_entry: global translation table entry to be analyzed
1837 * This functon assumes the caller holds rcu_read_lock().
1838 * Return: best originator list entry or NULL on errors.
1840 static struct batadv_tt_orig_list_entry *
1841 batadv_transtable_best_orig(struct batadv_priv *bat_priv,
1842 struct batadv_tt_global_entry *tt_global_entry)
1844 struct batadv_neigh_node *router, *best_router = NULL;
1845 struct batadv_algo_ops *bao = bat_priv->algo_ops;
1846 struct hlist_head *head;
1847 struct batadv_tt_orig_list_entry *orig_entry, *best_entry = NULL;
1849 head = &tt_global_entry->orig_list;
1850 hlist_for_each_entry_rcu(orig_entry, head, list) {
1851 router = batadv_orig_router_get(orig_entry->orig_node,
1857 bao->neigh.cmp(router, BATADV_IF_DEFAULT, best_router,
1858 BATADV_IF_DEFAULT) <= 0) {
1859 batadv_neigh_node_put(router);
1863 /* release the refcount for the "old" best */
1865 batadv_neigh_node_put(best_router);
1867 best_entry = orig_entry;
1868 best_router = router;
1872 batadv_neigh_node_put(best_router);
1877 #ifdef CONFIG_BATMAN_ADV_DEBUGFS
1879 * batadv_tt_global_print_entry - print all orig nodes who announce the address
1880 * for this global entry
1881 * @bat_priv: the bat priv with all the soft interface information
1882 * @tt_global_entry: global translation table entry to be printed
1883 * @seq: debugfs table seq_file struct
1885 * This functon assumes the caller holds rcu_read_lock().
1888 batadv_tt_global_print_entry(struct batadv_priv *bat_priv,
1889 struct batadv_tt_global_entry *tt_global_entry,
1890 struct seq_file *seq)
1892 struct batadv_tt_orig_list_entry *orig_entry, *best_entry;
1893 struct batadv_tt_common_entry *tt_common_entry;
1894 struct batadv_orig_node_vlan *vlan;
1895 struct hlist_head *head;
1899 tt_common_entry = &tt_global_entry->common;
1900 flags = tt_common_entry->flags;
1902 best_entry = batadv_transtable_best_orig(bat_priv, tt_global_entry);
1904 vlan = batadv_orig_node_vlan_get(best_entry->orig_node,
1905 tt_common_entry->vid);
1908 " * Cannot retrieve VLAN %d for originator %pM\n",
1909 BATADV_PRINT_VID(tt_common_entry->vid),
1910 best_entry->orig_node->orig);
1914 last_ttvn = atomic_read(&best_entry->orig_node->last_ttvn);
1916 " %c %pM %4i (%3u) via %pM (%3u) (%#.8x) [%c%c%c%c]\n",
1917 '*', tt_global_entry->common.addr,
1918 BATADV_PRINT_VID(tt_global_entry->common.vid),
1919 best_entry->ttvn, best_entry->orig_node->orig,
1920 last_ttvn, vlan->tt.crc,
1921 ((flags & BATADV_TT_CLIENT_ROAM) ? 'R' : '.'),
1922 ((flags & BATADV_TT_CLIENT_WIFI) ? 'W' : '.'),
1923 ((flags & BATADV_TT_CLIENT_ISOLA) ? 'I' : '.'),
1924 ((flags & BATADV_TT_CLIENT_TEMP) ? 'T' : '.'));
1926 batadv_orig_node_vlan_put(vlan);
1930 head = &tt_global_entry->orig_list;
1932 hlist_for_each_entry_rcu(orig_entry, head, list) {
1933 if (best_entry == orig_entry)
1936 vlan = batadv_orig_node_vlan_get(orig_entry->orig_node,
1937 tt_common_entry->vid);
1940 " + Cannot retrieve VLAN %d for originator %pM\n",
1941 BATADV_PRINT_VID(tt_common_entry->vid),
1942 orig_entry->orig_node->orig);
1946 last_ttvn = atomic_read(&orig_entry->orig_node->last_ttvn);
1948 " %c %pM %4d (%3u) via %pM (%3u) (%#.8x) [%c%c%c%c]\n",
1949 '+', tt_global_entry->common.addr,
1950 BATADV_PRINT_VID(tt_global_entry->common.vid),
1951 orig_entry->ttvn, orig_entry->orig_node->orig,
1952 last_ttvn, vlan->tt.crc,
1953 ((flags & BATADV_TT_CLIENT_ROAM) ? 'R' : '.'),
1954 ((flags & BATADV_TT_CLIENT_WIFI) ? 'W' : '.'),
1955 ((flags & BATADV_TT_CLIENT_ISOLA) ? 'I' : '.'),
1956 ((flags & BATADV_TT_CLIENT_TEMP) ? 'T' : '.'));
1958 batadv_orig_node_vlan_put(vlan);
1962 int batadv_tt_global_seq_print_text(struct seq_file *seq, void *offset)
1964 struct net_device *net_dev = (struct net_device *)seq->private;
1965 struct batadv_priv *bat_priv = netdev_priv(net_dev);
1966 struct batadv_hashtable *hash = bat_priv->tt.global_hash;
1967 struct batadv_tt_common_entry *tt_common_entry;
1968 struct batadv_tt_global_entry *tt_global;
1969 struct batadv_hard_iface *primary_if;
1970 struct hlist_head *head;
1973 primary_if = batadv_seq_print_text_primary_if_get(seq);
1978 "Globally announced TT entries received via the mesh %s\n",
1981 " Client VID (TTVN) Originator (Curr TTVN) (CRC ) Flags\n");
1983 for (i = 0; i < hash->size; i++) {
1984 head = &hash->table[i];
1987 hlist_for_each_entry_rcu(tt_common_entry,
1989 tt_global = container_of(tt_common_entry,
1990 struct batadv_tt_global_entry,
1992 batadv_tt_global_print_entry(bat_priv, tt_global, seq);
1998 batadv_hardif_put(primary_if);
2004 * batadv_tt_global_dump_subentry - Dump all TT local entries into a message
2005 * @msg: Netlink message to dump into
2006 * @portid: Port making netlink request
2007 * @seq: Sequence number of netlink message
2008 * @common: tt local & tt global common data
2009 * @orig: Originator node announcing a non-mesh client
2010 * @best: Is the best originator for the TT entry
2012 * Return: Error code, or 0 on success
2015 batadv_tt_global_dump_subentry(struct sk_buff *msg, u32 portid, u32 seq,
2016 struct batadv_tt_common_entry *common,
2017 struct batadv_tt_orig_list_entry *orig,
2020 u16 flags = (common->flags & (~BATADV_TT_SYNC_MASK)) | orig->flags;
2022 struct batadv_orig_node_vlan *vlan;
2026 vlan = batadv_orig_node_vlan_get(orig->orig_node,
2033 batadv_orig_node_vlan_put(vlan);
2035 hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family,
2037 BATADV_CMD_GET_TRANSTABLE_GLOBAL);
2041 last_ttvn = atomic_read(&orig->orig_node->last_ttvn);
2043 if (nla_put(msg, BATADV_ATTR_TT_ADDRESS, ETH_ALEN, common->addr) ||
2044 nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN,
2045 orig->orig_node->orig) ||
2046 nla_put_u8(msg, BATADV_ATTR_TT_TTVN, orig->ttvn) ||
2047 nla_put_u8(msg, BATADV_ATTR_TT_LAST_TTVN, last_ttvn) ||
2048 nla_put_u32(msg, BATADV_ATTR_TT_CRC32, crc) ||
2049 nla_put_u16(msg, BATADV_ATTR_TT_VID, common->vid) ||
2050 nla_put_u32(msg, BATADV_ATTR_TT_FLAGS, flags))
2051 goto nla_put_failure;
2053 if (best && nla_put_flag(msg, BATADV_ATTR_FLAG_BEST))
2054 goto nla_put_failure;
2056 genlmsg_end(msg, hdr);
2060 genlmsg_cancel(msg, hdr);
2065 * batadv_tt_global_dump_entry - Dump one TT global entry into a message
2066 * @msg: Netlink message to dump into
2067 * @portid: Port making netlink request
2068 * @seq: Sequence number of netlink message
2069 * @bat_priv: The bat priv with all the soft interface information
2070 * @common: tt local & tt global common data
2071 * @sub_s: Number of entries to skip
2073 * This function assumes the caller holds rcu_read_lock().
2075 * Return: Error code, or 0 on success
2078 batadv_tt_global_dump_entry(struct sk_buff *msg, u32 portid, u32 seq,
2079 struct batadv_priv *bat_priv,
2080 struct batadv_tt_common_entry *common, int *sub_s)
2082 struct batadv_tt_orig_list_entry *orig_entry, *best_entry;
2083 struct batadv_tt_global_entry *global;
2084 struct hlist_head *head;
2088 global = container_of(common, struct batadv_tt_global_entry, common);
2089 best_entry = batadv_transtable_best_orig(bat_priv, global);
2090 head = &global->orig_list;
2092 hlist_for_each_entry_rcu(orig_entry, head, list) {
2096 best = (orig_entry == best_entry);
2098 if (batadv_tt_global_dump_subentry(msg, portid, seq, common,
2099 orig_entry, best)) {
2110 * batadv_tt_global_dump_bucket - Dump one TT local bucket into a message
2111 * @msg: Netlink message to dump into
2112 * @portid: Port making netlink request
2113 * @seq: Sequence number of netlink message
2114 * @bat_priv: The bat priv with all the soft interface information
2115 * @head: Pointer to the list containing the global tt entries
2116 * @idx_s: Number of entries to skip
2117 * @sub: Number of entries to skip
2119 * Return: Error code, or 0 on success
2122 batadv_tt_global_dump_bucket(struct sk_buff *msg, u32 portid, u32 seq,
2123 struct batadv_priv *bat_priv,
2124 struct hlist_head *head, int *idx_s, int *sub)
2126 struct batadv_tt_common_entry *common;
2130 hlist_for_each_entry_rcu(common, head, hash_entry) {
2134 if (batadv_tt_global_dump_entry(msg, portid, seq, bat_priv,
2149 * batadv_tt_global_dump - Dump TT global entries into a message
2150 * @msg: Netlink message to dump into
2151 * @cb: Parameters from query
2153 * Return: Error code, or length of message on success
2155 int batadv_tt_global_dump(struct sk_buff *msg, struct netlink_callback *cb)
2157 struct net *net = sock_net(cb->skb->sk);
2158 struct net_device *soft_iface;
2159 struct batadv_priv *bat_priv;
2160 struct batadv_hard_iface *primary_if = NULL;
2161 struct batadv_hashtable *hash;
2162 struct hlist_head *head;
2165 int bucket = cb->args[0];
2166 int idx = cb->args[1];
2167 int sub = cb->args[2];
2168 int portid = NETLINK_CB(cb->skb).portid;
2170 ifindex = batadv_netlink_get_ifindex(cb->nlh, BATADV_ATTR_MESH_IFINDEX);
2174 soft_iface = dev_get_by_index(net, ifindex);
2175 if (!soft_iface || !batadv_softif_is_valid(soft_iface)) {
2180 bat_priv = netdev_priv(soft_iface);
2182 primary_if = batadv_primary_if_get_selected(bat_priv);
2183 if (!primary_if || primary_if->if_status != BATADV_IF_ACTIVE) {
2188 hash = bat_priv->tt.global_hash;
2190 while (bucket < hash->size) {
2191 head = &hash->table[bucket];
2193 if (batadv_tt_global_dump_bucket(msg, portid,
2194 cb->nlh->nlmsg_seq, bat_priv,
2205 batadv_hardif_put(primary_if);
2207 dev_put(soft_iface);
2209 cb->args[0] = bucket;
2217 * _batadv_tt_global_del_orig_entry - remove and free an orig_entry
2218 * @tt_global_entry: the global entry to remove the orig_entry from
2219 * @orig_entry: the orig entry to remove and free
2221 * Remove an orig_entry from its list in the given tt_global_entry and
2222 * free this orig_entry afterwards.
2224 * Caller must hold tt_global_entry->list_lock and ensure orig_entry->list is
2228 _batadv_tt_global_del_orig_entry(struct batadv_tt_global_entry *tt_global_entry,
2229 struct batadv_tt_orig_list_entry *orig_entry)
2231 lockdep_assert_held(&tt_global_entry->list_lock);
2233 batadv_tt_global_size_dec(orig_entry->orig_node,
2234 tt_global_entry->common.vid);
2235 atomic_dec(&tt_global_entry->orig_list_count);
2236 /* requires holding tt_global_entry->list_lock and orig_entry->list
2237 * being part of a list
2239 hlist_del_rcu(&orig_entry->list);
2240 batadv_tt_orig_list_entry_put(orig_entry);
2243 /* deletes the orig list of a tt_global_entry */
2245 batadv_tt_global_del_orig_list(struct batadv_tt_global_entry *tt_global_entry)
2247 struct hlist_head *head;
2248 struct hlist_node *safe;
2249 struct batadv_tt_orig_list_entry *orig_entry;
2251 spin_lock_bh(&tt_global_entry->list_lock);
2252 head = &tt_global_entry->orig_list;
2253 hlist_for_each_entry_safe(orig_entry, safe, head, list)
2254 _batadv_tt_global_del_orig_entry(tt_global_entry, orig_entry);
2255 spin_unlock_bh(&tt_global_entry->list_lock);
2259 * batadv_tt_global_del_orig_node - remove orig_node from a global tt entry
2260 * @bat_priv: the bat priv with all the soft interface information
2261 * @tt_global_entry: the global entry to remove the orig_node from
2262 * @orig_node: the originator announcing the client
2263 * @message: message to append to the log on deletion
2265 * Remove the given orig_node and its according orig_entry from the given
2269 batadv_tt_global_del_orig_node(struct batadv_priv *bat_priv,
2270 struct batadv_tt_global_entry *tt_global_entry,
2271 struct batadv_orig_node *orig_node,
2272 const char *message)
2274 struct hlist_head *head;
2275 struct hlist_node *safe;
2276 struct batadv_tt_orig_list_entry *orig_entry;
2279 spin_lock_bh(&tt_global_entry->list_lock);
2280 head = &tt_global_entry->orig_list;
2281 hlist_for_each_entry_safe(orig_entry, safe, head, list) {
2282 if (orig_entry->orig_node == orig_node) {
2283 vid = tt_global_entry->common.vid;
2284 batadv_dbg(BATADV_DBG_TT, bat_priv,
2285 "Deleting %pM from global tt entry %pM (vid: %d): %s\n",
2287 tt_global_entry->common.addr,
2288 BATADV_PRINT_VID(vid), message);
2289 _batadv_tt_global_del_orig_entry(tt_global_entry,
2293 spin_unlock_bh(&tt_global_entry->list_lock);
2296 /* If the client is to be deleted, we check if it is the last origantor entry
2297 * within tt_global entry. If yes, we set the BATADV_TT_CLIENT_ROAM flag and the
2298 * timer, otherwise we simply remove the originator scheduled for deletion.
2301 batadv_tt_global_del_roaming(struct batadv_priv *bat_priv,
2302 struct batadv_tt_global_entry *tt_global_entry,
2303 struct batadv_orig_node *orig_node,
2304 const char *message)
2306 bool last_entry = true;
2307 struct hlist_head *head;
2308 struct batadv_tt_orig_list_entry *orig_entry;
2310 /* no local entry exists, case 1:
2311 * Check if this is the last one or if other entries exist.
2315 head = &tt_global_entry->orig_list;
2316 hlist_for_each_entry_rcu(orig_entry, head, list) {
2317 if (orig_entry->orig_node != orig_node) {
2325 /* its the last one, mark for roaming. */
2326 tt_global_entry->common.flags |= BATADV_TT_CLIENT_ROAM;
2327 tt_global_entry->roam_at = jiffies;
2329 /* there is another entry, we can simply delete this
2330 * one and can still use the other one.
2332 batadv_tt_global_del_orig_node(bat_priv, tt_global_entry,
2333 orig_node, message);
2337 * batadv_tt_global_del - remove a client from the global table
2338 * @bat_priv: the bat priv with all the soft interface information
2339 * @orig_node: an originator serving this client
2340 * @addr: the mac address of the client
2341 * @vid: VLAN identifier
2342 * @message: a message explaining the reason for deleting the client to print
2343 * for debugging purpose
2344 * @roaming: true if the deletion has been triggered by a roaming event
2346 static void batadv_tt_global_del(struct batadv_priv *bat_priv,
2347 struct batadv_orig_node *orig_node,
2348 const unsigned char *addr, unsigned short vid,
2349 const char *message, bool roaming)
2351 struct batadv_tt_global_entry *tt_global_entry;
2352 struct batadv_tt_local_entry *local_entry = NULL;
2354 tt_global_entry = batadv_tt_global_hash_find(bat_priv, addr, vid);
2355 if (!tt_global_entry)
2359 batadv_tt_global_del_orig_node(bat_priv, tt_global_entry,
2360 orig_node, message);
2362 if (hlist_empty(&tt_global_entry->orig_list))
2363 batadv_tt_global_free(bat_priv, tt_global_entry,
2369 /* if we are deleting a global entry due to a roam
2370 * event, there are two possibilities:
2371 * 1) the client roamed from node A to node B => if there
2372 * is only one originator left for this client, we mark
2373 * it with BATADV_TT_CLIENT_ROAM, we start a timer and we
2374 * wait for node B to claim it. In case of timeout
2375 * the entry is purged.
2377 * If there are other originators left, we directly delete
2379 * 2) the client roamed to us => we can directly delete
2380 * the global entry, since it is useless now.
2382 local_entry = batadv_tt_local_hash_find(bat_priv,
2383 tt_global_entry->common.addr,
2386 /* local entry exists, case 2: client roamed to us. */
2387 batadv_tt_global_del_orig_list(tt_global_entry);
2388 batadv_tt_global_free(bat_priv, tt_global_entry, message);
2390 /* no local entry exists, case 1: check for roaming */
2391 batadv_tt_global_del_roaming(bat_priv, tt_global_entry,
2392 orig_node, message);
2395 if (tt_global_entry)
2396 batadv_tt_global_entry_put(tt_global_entry);
2398 batadv_tt_local_entry_put(local_entry);
2402 * batadv_tt_global_del_orig - remove all the TT global entries belonging to the
2403 * given originator matching the provided vid
2404 * @bat_priv: the bat priv with all the soft interface information
2405 * @orig_node: the originator owning the entries to remove
2406 * @match_vid: the VLAN identifier to match. If negative all the entries will be
2408 * @message: debug message to print as "reason"
2410 void batadv_tt_global_del_orig(struct batadv_priv *bat_priv,
2411 struct batadv_orig_node *orig_node,
2413 const char *message)
2415 struct batadv_tt_global_entry *tt_global;
2416 struct batadv_tt_common_entry *tt_common_entry;
2418 struct batadv_hashtable *hash = bat_priv->tt.global_hash;
2419 struct hlist_node *safe;
2420 struct hlist_head *head;
2421 spinlock_t *list_lock; /* protects write access to the hash lists */
2427 for (i = 0; i < hash->size; i++) {
2428 head = &hash->table[i];
2429 list_lock = &hash->list_locks[i];
2431 spin_lock_bh(list_lock);
2432 hlist_for_each_entry_safe(tt_common_entry, safe,
2434 /* remove only matching entries */
2435 if (match_vid >= 0 && tt_common_entry->vid != match_vid)
2438 tt_global = container_of(tt_common_entry,
2439 struct batadv_tt_global_entry,
2442 batadv_tt_global_del_orig_node(bat_priv, tt_global,
2443 orig_node, message);
2445 if (hlist_empty(&tt_global->orig_list)) {
2446 vid = tt_global->common.vid;
2447 batadv_dbg(BATADV_DBG_TT, bat_priv,
2448 "Deleting global tt entry %pM (vid: %d): %s\n",
2449 tt_global->common.addr,
2450 BATADV_PRINT_VID(vid), message);
2451 hlist_del_rcu(&tt_common_entry->hash_entry);
2452 batadv_tt_global_entry_put(tt_global);
2455 spin_unlock_bh(list_lock);
2457 clear_bit(BATADV_ORIG_CAPA_HAS_TT, &orig_node->capa_initialized);
2460 static bool batadv_tt_global_to_purge(struct batadv_tt_global_entry *tt_global,
2464 unsigned long roam_timeout = BATADV_TT_CLIENT_ROAM_TIMEOUT;
2465 unsigned long temp_timeout = BATADV_TT_CLIENT_TEMP_TIMEOUT;
2467 if ((tt_global->common.flags & BATADV_TT_CLIENT_ROAM) &&
2468 batadv_has_timed_out(tt_global->roam_at, roam_timeout)) {
2470 *msg = "Roaming timeout\n";
2473 if ((tt_global->common.flags & BATADV_TT_CLIENT_TEMP) &&
2474 batadv_has_timed_out(tt_global->common.added_at, temp_timeout)) {
2476 *msg = "Temporary client timeout\n";
2482 static void batadv_tt_global_purge(struct batadv_priv *bat_priv)
2484 struct batadv_hashtable *hash = bat_priv->tt.global_hash;
2485 struct hlist_head *head;
2486 struct hlist_node *node_tmp;
2487 spinlock_t *list_lock; /* protects write access to the hash lists */
2490 struct batadv_tt_common_entry *tt_common;
2491 struct batadv_tt_global_entry *tt_global;
2493 for (i = 0; i < hash->size; i++) {
2494 head = &hash->table[i];
2495 list_lock = &hash->list_locks[i];
2497 spin_lock_bh(list_lock);
2498 hlist_for_each_entry_safe(tt_common, node_tmp, head,
2500 tt_global = container_of(tt_common,
2501 struct batadv_tt_global_entry,
2504 if (!batadv_tt_global_to_purge(tt_global, &msg))
2507 batadv_dbg(BATADV_DBG_TT, bat_priv,
2508 "Deleting global tt entry %pM (vid: %d): %s\n",
2509 tt_global->common.addr,
2510 BATADV_PRINT_VID(tt_global->common.vid),
2513 hlist_del_rcu(&tt_common->hash_entry);
2515 batadv_tt_global_entry_put(tt_global);
2517 spin_unlock_bh(list_lock);
2521 static void batadv_tt_global_table_free(struct batadv_priv *bat_priv)
2523 struct batadv_hashtable *hash;
2524 spinlock_t *list_lock; /* protects write access to the hash lists */
2525 struct batadv_tt_common_entry *tt_common_entry;
2526 struct batadv_tt_global_entry *tt_global;
2527 struct hlist_node *node_tmp;
2528 struct hlist_head *head;
2531 if (!bat_priv->tt.global_hash)
2534 hash = bat_priv->tt.global_hash;
2536 for (i = 0; i < hash->size; i++) {
2537 head = &hash->table[i];
2538 list_lock = &hash->list_locks[i];
2540 spin_lock_bh(list_lock);
2541 hlist_for_each_entry_safe(tt_common_entry, node_tmp,
2543 hlist_del_rcu(&tt_common_entry->hash_entry);
2544 tt_global = container_of(tt_common_entry,
2545 struct batadv_tt_global_entry,
2547 batadv_tt_global_entry_put(tt_global);
2549 spin_unlock_bh(list_lock);
2552 batadv_hash_destroy(hash);
2554 bat_priv->tt.global_hash = NULL;
2558 _batadv_is_ap_isolated(struct batadv_tt_local_entry *tt_local_entry,
2559 struct batadv_tt_global_entry *tt_global_entry)
2563 if (tt_local_entry->common.flags & BATADV_TT_CLIENT_WIFI &&
2564 tt_global_entry->common.flags & BATADV_TT_CLIENT_WIFI)
2567 /* check if the two clients are marked as isolated */
2568 if (tt_local_entry->common.flags & BATADV_TT_CLIENT_ISOLA &&
2569 tt_global_entry->common.flags & BATADV_TT_CLIENT_ISOLA)
2576 * batadv_transtable_search - get the mesh destination for a given client
2577 * @bat_priv: the bat priv with all the soft interface information
2578 * @src: mac address of the source client
2579 * @addr: mac address of the destination client
2580 * @vid: VLAN identifier
2582 * Return: a pointer to the originator that was selected as destination in the
2583 * mesh for contacting the client 'addr', NULL otherwise.
2584 * In case of multiple originators serving the same client, the function returns
2585 * the best one (best in terms of metric towards the destination node).
2587 * If the two clients are AP isolated the function returns NULL.
2589 struct batadv_orig_node *batadv_transtable_search(struct batadv_priv *bat_priv,
2594 struct batadv_tt_local_entry *tt_local_entry = NULL;
2595 struct batadv_tt_global_entry *tt_global_entry = NULL;
2596 struct batadv_orig_node *orig_node = NULL;
2597 struct batadv_tt_orig_list_entry *best_entry;
2599 if (src && batadv_vlan_ap_isola_get(bat_priv, vid)) {
2600 tt_local_entry = batadv_tt_local_hash_find(bat_priv, src, vid);
2601 if (!tt_local_entry ||
2602 (tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING))
2606 tt_global_entry = batadv_tt_global_hash_find(bat_priv, addr, vid);
2607 if (!tt_global_entry)
2610 /* check whether the clients should not communicate due to AP
2613 if (tt_local_entry &&
2614 _batadv_is_ap_isolated(tt_local_entry, tt_global_entry))
2618 best_entry = batadv_transtable_best_orig(bat_priv, tt_global_entry);
2619 /* found anything? */
2621 orig_node = best_entry->orig_node;
2622 if (orig_node && !kref_get_unless_zero(&orig_node->refcount))
2627 if (tt_global_entry)
2628 batadv_tt_global_entry_put(tt_global_entry);
2630 batadv_tt_local_entry_put(tt_local_entry);
2636 * batadv_tt_global_crc - calculates the checksum of the local table belonging
2637 * to the given orig_node
2638 * @bat_priv: the bat priv with all the soft interface information
2639 * @orig_node: originator for which the CRC should be computed
2640 * @vid: VLAN identifier for which the CRC32 has to be computed
2642 * This function computes the checksum for the global table corresponding to a
2643 * specific originator. In particular, the checksum is computed as follows: For
2644 * each client connected to the originator the CRC32C of the MAC address and the
2645 * VID is computed and then all the CRC32Cs of the various clients are xor'ed
2648 * The idea behind is that CRC32C should be used as much as possible in order to
2649 * produce a unique hash of the table, but since the order which is used to feed
2650 * the CRC32C function affects the result and since every node in the network
2651 * probably sorts the clients differently, the hash function cannot be directly
2652 * computed over the entire table. Hence the CRC32C is used only on
2653 * the single client entry, while all the results are then xor'ed together
2654 * because the XOR operation can combine them all while trying to reduce the
2655 * noise as much as possible.
2657 * Return: the checksum of the global table of a given originator.
2659 static u32 batadv_tt_global_crc(struct batadv_priv *bat_priv,
2660 struct batadv_orig_node *orig_node,
2663 struct batadv_hashtable *hash = bat_priv->tt.global_hash;
2664 struct batadv_tt_orig_list_entry *tt_orig;
2665 struct batadv_tt_common_entry *tt_common;
2666 struct batadv_tt_global_entry *tt_global;
2667 struct hlist_head *head;
2668 u32 i, crc_tmp, crc = 0;
2672 for (i = 0; i < hash->size; i++) {
2673 head = &hash->table[i];
2676 hlist_for_each_entry_rcu(tt_common, head, hash_entry) {
2677 tt_global = container_of(tt_common,
2678 struct batadv_tt_global_entry,
2680 /* compute the CRC only for entries belonging to the
2681 * VLAN identified by the vid passed as parameter
2683 if (tt_common->vid != vid)
2686 /* Roaming clients are in the global table for
2687 * consistency only. They don't have to be
2688 * taken into account while computing the
2691 if (tt_common->flags & BATADV_TT_CLIENT_ROAM)
2693 /* Temporary clients have not been announced yet, so
2694 * they have to be skipped while computing the global
2697 if (tt_common->flags & BATADV_TT_CLIENT_TEMP)
2700 /* find out if this global entry is announced by this
2703 tt_orig = batadv_tt_global_orig_entry_find(tt_global,
2708 /* use network order to read the VID: this ensures that
2709 * every node reads the bytes in the same order.
2711 tmp_vid = htons(tt_common->vid);
2712 crc_tmp = crc32c(0, &tmp_vid, sizeof(tmp_vid));
2714 /* compute the CRC on flags that have to be kept in sync
2717 flags = tt_orig->flags;
2718 crc_tmp = crc32c(crc_tmp, &flags, sizeof(flags));
2720 crc ^= crc32c(crc_tmp, tt_common->addr, ETH_ALEN);
2722 batadv_tt_orig_list_entry_put(tt_orig);
2731 * batadv_tt_local_crc - calculates the checksum of the local table
2732 * @bat_priv: the bat priv with all the soft interface information
2733 * @vid: VLAN identifier for which the CRC32 has to be computed
2735 * For details about the computation, please refer to the documentation for
2736 * batadv_tt_global_crc().
2738 * Return: the checksum of the local table
2740 static u32 batadv_tt_local_crc(struct batadv_priv *bat_priv,
2743 struct batadv_hashtable *hash = bat_priv->tt.local_hash;
2744 struct batadv_tt_common_entry *tt_common;
2745 struct hlist_head *head;
2746 u32 i, crc_tmp, crc = 0;
2750 for (i = 0; i < hash->size; i++) {
2751 head = &hash->table[i];
2754 hlist_for_each_entry_rcu(tt_common, head, hash_entry) {
2755 /* compute the CRC only for entries belonging to the
2756 * VLAN identified by vid
2758 if (tt_common->vid != vid)
2761 /* not yet committed clients have not to be taken into
2762 * account while computing the CRC
2764 if (tt_common->flags & BATADV_TT_CLIENT_NEW)
2767 /* use network order to read the VID: this ensures that
2768 * every node reads the bytes in the same order.
2770 tmp_vid = htons(tt_common->vid);
2771 crc_tmp = crc32c(0, &tmp_vid, sizeof(tmp_vid));
2773 /* compute the CRC on flags that have to be kept in sync
2776 flags = tt_common->flags & BATADV_TT_SYNC_MASK;
2777 crc_tmp = crc32c(crc_tmp, &flags, sizeof(flags));
2779 crc ^= crc32c(crc_tmp, tt_common->addr, ETH_ALEN);
2788 * batadv_tt_req_node_release - free tt_req node entry
2789 * @ref: kref pointer of the tt req_node entry
2791 static void batadv_tt_req_node_release(struct kref *ref)
2793 struct batadv_tt_req_node *tt_req_node;
2795 tt_req_node = container_of(ref, struct batadv_tt_req_node, refcount);
2797 kmem_cache_free(batadv_tt_req_cache, tt_req_node);
2801 * batadv_tt_req_node_put - decrement the tt_req_node refcounter and
2802 * possibly release it
2803 * @tt_req_node: tt_req_node to be free'd
2805 static void batadv_tt_req_node_put(struct batadv_tt_req_node *tt_req_node)
2807 kref_put(&tt_req_node->refcount, batadv_tt_req_node_release);
2810 static void batadv_tt_req_list_free(struct batadv_priv *bat_priv)
2812 struct batadv_tt_req_node *node;
2813 struct hlist_node *safe;
2815 spin_lock_bh(&bat_priv->tt.req_list_lock);
2817 hlist_for_each_entry_safe(node, safe, &bat_priv->tt.req_list, list) {
2818 hlist_del_init(&node->list);
2819 batadv_tt_req_node_put(node);
2822 spin_unlock_bh(&bat_priv->tt.req_list_lock);
2825 static void batadv_tt_save_orig_buffer(struct batadv_priv *bat_priv,
2826 struct batadv_orig_node *orig_node,
2827 const void *tt_buff,
2830 /* Replace the old buffer only if I received something in the
2831 * last OGM (the OGM could carry no changes)
2833 spin_lock_bh(&orig_node->tt_buff_lock);
2834 if (tt_buff_len > 0) {
2835 kfree(orig_node->tt_buff);
2836 orig_node->tt_buff_len = 0;
2837 orig_node->tt_buff = kmalloc(tt_buff_len, GFP_ATOMIC);
2838 if (orig_node->tt_buff) {
2839 memcpy(orig_node->tt_buff, tt_buff, tt_buff_len);
2840 orig_node->tt_buff_len = tt_buff_len;
2843 spin_unlock_bh(&orig_node->tt_buff_lock);
2846 static void batadv_tt_req_purge(struct batadv_priv *bat_priv)
2848 struct batadv_tt_req_node *node;
2849 struct hlist_node *safe;
2851 spin_lock_bh(&bat_priv->tt.req_list_lock);
2852 hlist_for_each_entry_safe(node, safe, &bat_priv->tt.req_list, list) {
2853 if (batadv_has_timed_out(node->issued_at,
2854 BATADV_TT_REQUEST_TIMEOUT)) {
2855 hlist_del_init(&node->list);
2856 batadv_tt_req_node_put(node);
2859 spin_unlock_bh(&bat_priv->tt.req_list_lock);
2863 * batadv_tt_req_node_new - search and possibly create a tt_req_node object
2864 * @bat_priv: the bat priv with all the soft interface information
2865 * @orig_node: orig node this request is being issued for
2867 * Return: the pointer to the new tt_req_node struct if no request
2868 * has already been issued for this orig_node, NULL otherwise.
2870 static struct batadv_tt_req_node *
2871 batadv_tt_req_node_new(struct batadv_priv *bat_priv,
2872 struct batadv_orig_node *orig_node)
2874 struct batadv_tt_req_node *tt_req_node_tmp, *tt_req_node = NULL;
2876 spin_lock_bh(&bat_priv->tt.req_list_lock);
2877 hlist_for_each_entry(tt_req_node_tmp, &bat_priv->tt.req_list, list) {
2878 if (batadv_compare_eth(tt_req_node_tmp, orig_node) &&
2879 !batadv_has_timed_out(tt_req_node_tmp->issued_at,
2880 BATADV_TT_REQUEST_TIMEOUT))
2884 tt_req_node = kmem_cache_alloc(batadv_tt_req_cache, GFP_ATOMIC);
2888 kref_init(&tt_req_node->refcount);
2889 ether_addr_copy(tt_req_node->addr, orig_node->orig);
2890 tt_req_node->issued_at = jiffies;
2892 kref_get(&tt_req_node->refcount);
2893 hlist_add_head(&tt_req_node->list, &bat_priv->tt.req_list);
2895 spin_unlock_bh(&bat_priv->tt.req_list_lock);
2900 * batadv_tt_local_valid() - verify local tt entry and get flags
2901 * @entry_ptr: to be checked local tt entry
2902 * @data_ptr: not used but definition required to satisfy the callback prototype
2903 * @flags: a pointer to store TT flags for this client to
2905 * Checks the validity of the given local TT entry. If it is, then the provided
2906 * flags pointer is updated.
2908 * Return: true if the entry is a valid, false otherwise.
2910 static bool batadv_tt_local_valid(const void *entry_ptr,
2911 const void *data_ptr,
2914 const struct batadv_tt_common_entry *tt_common_entry = entry_ptr;
2916 if (tt_common_entry->flags & BATADV_TT_CLIENT_NEW)
2920 *flags = tt_common_entry->flags;
2926 * batadv_tt_global_valid() - verify global tt entry and get flags
2927 * @entry_ptr: to be checked global tt entry
2928 * @data_ptr: an orig_node object (may be NULL)
2929 * @flags: a pointer to store TT flags for this client to
2931 * Checks the validity of the given global TT entry. If it is, then the provided
2932 * flags pointer is updated either with the common (summed) TT flags if data_ptr
2933 * is NULL or the specific, per originator TT flags otherwise.
2935 * Return: true if the entry is a valid, false otherwise.
2937 static bool batadv_tt_global_valid(const void *entry_ptr,
2938 const void *data_ptr,
2941 const struct batadv_tt_common_entry *tt_common_entry = entry_ptr;
2942 const struct batadv_tt_global_entry *tt_global_entry;
2943 const struct batadv_orig_node *orig_node = data_ptr;
2945 if (tt_common_entry->flags & BATADV_TT_CLIENT_ROAM ||
2946 tt_common_entry->flags & BATADV_TT_CLIENT_TEMP)
2949 tt_global_entry = container_of(tt_common_entry,
2950 struct batadv_tt_global_entry,
2953 return batadv_tt_global_entry_has_orig(tt_global_entry, orig_node,
2958 * batadv_tt_tvlv_generate - fill the tvlv buff with the tt entries from the
2960 * @bat_priv: the bat priv with all the soft interface information
2961 * @hash: hash table containing the tt entries
2962 * @tt_len: expected tvlv tt data buffer length in number of bytes
2963 * @tvlv_buff: pointer to the buffer to fill with the TT data
2964 * @valid_cb: function to filter tt change entries and to return TT flags
2965 * @cb_data: data passed to the filter function as argument
2967 * Fills the tvlv buff with the tt entries from the specified hash. If valid_cb
2968 * is not provided then this becomes a no-op.
2970 static void batadv_tt_tvlv_generate(struct batadv_priv *bat_priv,
2971 struct batadv_hashtable *hash,
2972 void *tvlv_buff, u16 tt_len,
2973 bool (*valid_cb)(const void *,
2978 struct batadv_tt_common_entry *tt_common_entry;
2979 struct batadv_tvlv_tt_change *tt_change;
2980 struct hlist_head *head;
2981 u16 tt_tot, tt_num_entries = 0;
2986 tt_tot = batadv_tt_entries(tt_len);
2987 tt_change = (struct batadv_tvlv_tt_change *)tvlv_buff;
2993 for (i = 0; i < hash->size; i++) {
2994 head = &hash->table[i];
2996 hlist_for_each_entry_rcu(tt_common_entry,
2998 if (tt_tot == tt_num_entries)
3001 ret = valid_cb(tt_common_entry, cb_data, &flags);
3005 ether_addr_copy(tt_change->addr, tt_common_entry->addr);
3006 tt_change->flags = flags;
3007 tt_change->vid = htons(tt_common_entry->vid);
3008 memset(tt_change->reserved, 0,
3009 sizeof(tt_change->reserved));
3019 * batadv_tt_global_check_crc - check if all the CRCs are correct
3020 * @orig_node: originator for which the CRCs have to be checked
3021 * @tt_vlan: pointer to the first tvlv VLAN entry
3022 * @num_vlan: number of tvlv VLAN entries
3024 * Return: true if all the received CRCs match the locally stored ones, false
3027 static bool batadv_tt_global_check_crc(struct batadv_orig_node *orig_node,
3028 struct batadv_tvlv_tt_vlan_data *tt_vlan,
3031 struct batadv_tvlv_tt_vlan_data *tt_vlan_tmp;
3032 struct batadv_orig_node_vlan *vlan;
3033 int i, orig_num_vlan;
3036 /* check if each received CRC matches the locally stored one */
3037 for (i = 0; i < num_vlan; i++) {
3038 tt_vlan_tmp = tt_vlan + i;
3040 /* if orig_node is a backbone node for this VLAN, don't check
3041 * the CRC as we ignore all the global entries over it
3043 if (batadv_bla_is_backbone_gw_orig(orig_node->bat_priv,
3045 ntohs(tt_vlan_tmp->vid)))
3048 vlan = batadv_orig_node_vlan_get(orig_node,
3049 ntohs(tt_vlan_tmp->vid));
3054 batadv_orig_node_vlan_put(vlan);
3056 if (crc != ntohl(tt_vlan_tmp->crc))
3060 /* check if any excess VLANs exist locally for the originator
3061 * which are not mentioned in the TVLV from the originator.
3065 hlist_for_each_entry_rcu(vlan, &orig_node->vlan_list, list)
3069 if (orig_num_vlan > num_vlan)
3076 * batadv_tt_local_update_crc - update all the local CRCs
3077 * @bat_priv: the bat priv with all the soft interface information
3079 static void batadv_tt_local_update_crc(struct batadv_priv *bat_priv)
3081 struct batadv_softif_vlan *vlan;
3083 /* recompute the global CRC for each VLAN */
3085 hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list) {
3086 vlan->tt.crc = batadv_tt_local_crc(bat_priv, vlan->vid);
3092 * batadv_tt_global_update_crc - update all the global CRCs for this orig_node
3093 * @bat_priv: the bat priv with all the soft interface information
3094 * @orig_node: the orig_node for which the CRCs have to be updated
3096 static void batadv_tt_global_update_crc(struct batadv_priv *bat_priv,
3097 struct batadv_orig_node *orig_node)
3099 struct batadv_orig_node_vlan *vlan;
3102 /* recompute the global CRC for each VLAN */
3104 hlist_for_each_entry_rcu(vlan, &orig_node->vlan_list, list) {
3105 /* if orig_node is a backbone node for this VLAN, don't compute
3106 * the CRC as we ignore all the global entries over it
3108 if (batadv_bla_is_backbone_gw_orig(bat_priv, orig_node->orig,
3112 crc = batadv_tt_global_crc(bat_priv, orig_node, vlan->vid);
3119 * batadv_send_tt_request - send a TT Request message to a given node
3120 * @bat_priv: the bat priv with all the soft interface information
3121 * @dst_orig_node: the destination of the message
3122 * @ttvn: the version number that the source of the message is looking for
3123 * @tt_vlan: pointer to the first tvlv VLAN object to request
3124 * @num_vlan: number of tvlv VLAN entries
3125 * @full_table: ask for the entire translation table if true, while only for the
3126 * last TT diff otherwise
3128 * Return: true if the TT Request was sent, false otherwise
3130 static bool batadv_send_tt_request(struct batadv_priv *bat_priv,
3131 struct batadv_orig_node *dst_orig_node,
3133 struct batadv_tvlv_tt_vlan_data *tt_vlan,
3134 u16 num_vlan, bool full_table)
3136 struct batadv_tvlv_tt_data *tvlv_tt_data = NULL;
3137 struct batadv_tt_req_node *tt_req_node = NULL;
3138 struct batadv_tvlv_tt_vlan_data *tt_vlan_req;
3139 struct batadv_hard_iface *primary_if;
3143 primary_if = batadv_primary_if_get_selected(bat_priv);
3147 /* The new tt_req will be issued only if I'm not waiting for a
3148 * reply from the same orig_node yet
3150 tt_req_node = batadv_tt_req_node_new(bat_priv, dst_orig_node);
3154 size = sizeof(*tvlv_tt_data) + sizeof(*tt_vlan_req) * num_vlan;
3155 tvlv_tt_data = kzalloc(size, GFP_ATOMIC);
3159 tvlv_tt_data->flags = BATADV_TT_REQUEST;
3160 tvlv_tt_data->ttvn = ttvn;
3161 tvlv_tt_data->num_vlan = htons(num_vlan);
3163 /* send all the CRCs within the request. This is needed by intermediate
3164 * nodes to ensure they have the correct table before replying
3166 tt_vlan_req = (struct batadv_tvlv_tt_vlan_data *)(tvlv_tt_data + 1);
3167 for (i = 0; i < num_vlan; i++) {
3168 tt_vlan_req->vid = tt_vlan->vid;
3169 tt_vlan_req->crc = tt_vlan->crc;
3176 tvlv_tt_data->flags |= BATADV_TT_FULL_TABLE;
3178 batadv_dbg(BATADV_DBG_TT, bat_priv, "Sending TT_REQUEST to %pM [%c]\n",
3179 dst_orig_node->orig, full_table ? 'F' : '.');
3181 batadv_inc_counter(bat_priv, BATADV_CNT_TT_REQUEST_TX);
3182 batadv_tvlv_unicast_send(bat_priv, primary_if->net_dev->dev_addr,
3183 dst_orig_node->orig, BATADV_TVLV_TT, 1,
3184 tvlv_tt_data, size);
3189 batadv_hardif_put(primary_if);
3191 if (ret && tt_req_node) {
3192 spin_lock_bh(&bat_priv->tt.req_list_lock);
3193 if (!hlist_unhashed(&tt_req_node->list)) {
3194 hlist_del_init(&tt_req_node->list);
3195 batadv_tt_req_node_put(tt_req_node);
3197 spin_unlock_bh(&bat_priv->tt.req_list_lock);
3201 batadv_tt_req_node_put(tt_req_node);
3203 kfree(tvlv_tt_data);
3208 * batadv_send_other_tt_response - send reply to tt request concerning another
3209 * node's translation table
3210 * @bat_priv: the bat priv with all the soft interface information
3211 * @tt_data: tt data containing the tt request information
3212 * @req_src: mac address of tt request sender
3213 * @req_dst: mac address of tt request recipient
3215 * Return: true if tt request reply was sent, false otherwise.
3217 static bool batadv_send_other_tt_response(struct batadv_priv *bat_priv,
3218 struct batadv_tvlv_tt_data *tt_data,
3219 u8 *req_src, u8 *req_dst)
3221 struct batadv_orig_node *req_dst_orig_node;
3222 struct batadv_orig_node *res_dst_orig_node = NULL;
3223 struct batadv_tvlv_tt_change *tt_change;
3224 struct batadv_tvlv_tt_data *tvlv_tt_data = NULL;
3225 struct batadv_tvlv_tt_vlan_data *tt_vlan;
3226 bool ret = false, full_table;
3227 u8 orig_ttvn, req_ttvn;
3231 batadv_dbg(BATADV_DBG_TT, bat_priv,
3232 "Received TT_REQUEST from %pM for ttvn: %u (%pM) [%c]\n",
3233 req_src, tt_data->ttvn, req_dst,
3234 ((tt_data->flags & BATADV_TT_FULL_TABLE) ? 'F' : '.'));
3236 /* Let's get the orig node of the REAL destination */
3237 req_dst_orig_node = batadv_orig_hash_find(bat_priv, req_dst);
3238 if (!req_dst_orig_node)
3241 res_dst_orig_node = batadv_orig_hash_find(bat_priv, req_src);
3242 if (!res_dst_orig_node)
3245 orig_ttvn = (u8)atomic_read(&req_dst_orig_node->last_ttvn);
3246 req_ttvn = tt_data->ttvn;
3248 tt_vlan = (struct batadv_tvlv_tt_vlan_data *)(tt_data + 1);
3249 /* this node doesn't have the requested data */
3250 if (orig_ttvn != req_ttvn ||
3251 !batadv_tt_global_check_crc(req_dst_orig_node, tt_vlan,
3252 ntohs(tt_data->num_vlan)))
3255 /* If the full table has been explicitly requested */
3256 if (tt_data->flags & BATADV_TT_FULL_TABLE ||
3257 !req_dst_orig_node->tt_buff)
3262 /* TT fragmentation hasn't been implemented yet, so send as many
3263 * TT entries fit a single packet as possible only
3266 spin_lock_bh(&req_dst_orig_node->tt_buff_lock);
3267 tt_len = req_dst_orig_node->tt_buff_len;
3269 tvlv_len = batadv_tt_prepare_tvlv_global_data(req_dst_orig_node,
3276 /* Copy the last orig_node's OGM buffer */
3277 memcpy(tt_change, req_dst_orig_node->tt_buff,
3278 req_dst_orig_node->tt_buff_len);
3279 spin_unlock_bh(&req_dst_orig_node->tt_buff_lock);
3281 /* allocate the tvlv, put the tt_data and all the tt_vlan_data
3282 * in the initial part
3285 tvlv_len = batadv_tt_prepare_tvlv_global_data(req_dst_orig_node,
3292 /* fill the rest of the tvlv with the real TT entries */
3293 batadv_tt_tvlv_generate(bat_priv, bat_priv->tt.global_hash,
3295 batadv_tt_global_valid,
3299 /* Don't send the response, if larger than fragmented packet. */
3300 tt_len = sizeof(struct batadv_unicast_tvlv_packet) + tvlv_len;
3301 if (tt_len > atomic_read(&bat_priv->packet_size_max)) {
3302 net_ratelimited_function(batadv_info, bat_priv->soft_iface,
3303 "Ignoring TT_REQUEST from %pM; Response size exceeds max packet size.\n",
3304 res_dst_orig_node->orig);
3308 tvlv_tt_data->flags = BATADV_TT_RESPONSE;
3309 tvlv_tt_data->ttvn = req_ttvn;
3312 tvlv_tt_data->flags |= BATADV_TT_FULL_TABLE;
3314 batadv_dbg(BATADV_DBG_TT, bat_priv,
3315 "Sending TT_RESPONSE %pM for %pM [%c] (ttvn: %u)\n",
3316 res_dst_orig_node->orig, req_dst_orig_node->orig,
3317 full_table ? 'F' : '.', req_ttvn);
3319 batadv_inc_counter(bat_priv, BATADV_CNT_TT_RESPONSE_TX);
3321 batadv_tvlv_unicast_send(bat_priv, req_dst_orig_node->orig,
3322 req_src, BATADV_TVLV_TT, 1, tvlv_tt_data,
3329 spin_unlock_bh(&req_dst_orig_node->tt_buff_lock);
3332 if (res_dst_orig_node)
3333 batadv_orig_node_put(res_dst_orig_node);
3334 if (req_dst_orig_node)
3335 batadv_orig_node_put(req_dst_orig_node);
3336 kfree(tvlv_tt_data);
3341 * batadv_send_my_tt_response - send reply to tt request concerning this node's
3343 * @bat_priv: the bat priv with all the soft interface information
3344 * @tt_data: tt data containing the tt request information
3345 * @req_src: mac address of tt request sender
3347 * Return: true if tt request reply was sent, false otherwise.
3349 static bool batadv_send_my_tt_response(struct batadv_priv *bat_priv,
3350 struct batadv_tvlv_tt_data *tt_data,
3353 struct batadv_tvlv_tt_data *tvlv_tt_data = NULL;
3354 struct batadv_hard_iface *primary_if = NULL;
3355 struct batadv_tvlv_tt_change *tt_change;
3356 struct batadv_orig_node *orig_node;
3357 u8 my_ttvn, req_ttvn;
3362 batadv_dbg(BATADV_DBG_TT, bat_priv,
3363 "Received TT_REQUEST from %pM for ttvn: %u (me) [%c]\n",
3364 req_src, tt_data->ttvn,
3365 ((tt_data->flags & BATADV_TT_FULL_TABLE) ? 'F' : '.'));
3367 spin_lock_bh(&bat_priv->tt.commit_lock);
3369 my_ttvn = (u8)atomic_read(&bat_priv->tt.vn);
3370 req_ttvn = tt_data->ttvn;
3372 orig_node = batadv_orig_hash_find(bat_priv, req_src);
3376 primary_if = batadv_primary_if_get_selected(bat_priv);
3380 /* If the full table has been explicitly requested or the gap
3381 * is too big send the whole local translation table
3383 if (tt_data->flags & BATADV_TT_FULL_TABLE || my_ttvn != req_ttvn ||
3384 !bat_priv->tt.last_changeset)
3389 /* TT fragmentation hasn't been implemented yet, so send as many
3390 * TT entries fit a single packet as possible only
3393 spin_lock_bh(&bat_priv->tt.last_changeset_lock);
3395 tt_len = bat_priv->tt.last_changeset_len;
3396 tvlv_len = batadv_tt_prepare_tvlv_local_data(bat_priv,
3400 if (!tt_len || !tvlv_len)
3403 /* Copy the last orig_node's OGM buffer */
3404 memcpy(tt_change, bat_priv->tt.last_changeset,
3405 bat_priv->tt.last_changeset_len);
3406 spin_unlock_bh(&bat_priv->tt.last_changeset_lock);
3408 req_ttvn = (u8)atomic_read(&bat_priv->tt.vn);
3410 /* allocate the tvlv, put the tt_data and all the tt_vlan_data
3411 * in the initial part
3414 tvlv_len = batadv_tt_prepare_tvlv_local_data(bat_priv,
3418 if (!tt_len || !tvlv_len)
3421 /* fill the rest of the tvlv with the real TT entries */
3422 batadv_tt_tvlv_generate(bat_priv, bat_priv->tt.local_hash,
3424 batadv_tt_local_valid, NULL);
3427 tvlv_tt_data->flags = BATADV_TT_RESPONSE;
3428 tvlv_tt_data->ttvn = req_ttvn;
3431 tvlv_tt_data->flags |= BATADV_TT_FULL_TABLE;
3433 batadv_dbg(BATADV_DBG_TT, bat_priv,
3434 "Sending TT_RESPONSE to %pM [%c] (ttvn: %u)\n",
3435 orig_node->orig, full_table ? 'F' : '.', req_ttvn);
3437 batadv_inc_counter(bat_priv, BATADV_CNT_TT_RESPONSE_TX);
3439 batadv_tvlv_unicast_send(bat_priv, primary_if->net_dev->dev_addr,
3440 req_src, BATADV_TVLV_TT, 1, tvlv_tt_data,
3446 spin_unlock_bh(&bat_priv->tt.last_changeset_lock);
3448 spin_unlock_bh(&bat_priv->tt.commit_lock);
3450 batadv_orig_node_put(orig_node);
3452 batadv_hardif_put(primary_if);
3453 kfree(tvlv_tt_data);
3454 /* The packet was for this host, so it doesn't need to be re-routed */
3459 * batadv_send_tt_response - send reply to tt request
3460 * @bat_priv: the bat priv with all the soft interface information
3461 * @tt_data: tt data containing the tt request information
3462 * @req_src: mac address of tt request sender
3463 * @req_dst: mac address of tt request recipient
3465 * Return: true if tt request reply was sent, false otherwise.
3467 static bool batadv_send_tt_response(struct batadv_priv *bat_priv,
3468 struct batadv_tvlv_tt_data *tt_data,
3469 u8 *req_src, u8 *req_dst)
3471 if (batadv_is_my_mac(bat_priv, req_dst))
3472 return batadv_send_my_tt_response(bat_priv, tt_data, req_src);
3473 return batadv_send_other_tt_response(bat_priv, tt_data, req_src,
3477 static void _batadv_tt_update_changes(struct batadv_priv *bat_priv,
3478 struct batadv_orig_node *orig_node,
3479 struct batadv_tvlv_tt_change *tt_change,
3480 u16 tt_num_changes, u8 ttvn)
3485 for (i = 0; i < tt_num_changes; i++) {
3486 if ((tt_change + i)->flags & BATADV_TT_CLIENT_DEL) {
3487 roams = (tt_change + i)->flags & BATADV_TT_CLIENT_ROAM;
3488 batadv_tt_global_del(bat_priv, orig_node,
3489 (tt_change + i)->addr,
3490 ntohs((tt_change + i)->vid),
3491 "tt removed by changes",
3494 if (!batadv_tt_global_add(bat_priv, orig_node,
3495 (tt_change + i)->addr,
3496 ntohs((tt_change + i)->vid),
3497 (tt_change + i)->flags, ttvn))
3498 /* In case of problem while storing a
3499 * global_entry, we stop the updating
3500 * procedure without committing the
3501 * ttvn change. This will avoid to send
3502 * corrupted data on tt_request
3507 set_bit(BATADV_ORIG_CAPA_HAS_TT, &orig_node->capa_initialized);
3510 static void batadv_tt_fill_gtable(struct batadv_priv *bat_priv,
3511 struct batadv_tvlv_tt_change *tt_change,
3512 u8 ttvn, u8 *resp_src,
3515 struct batadv_orig_node *orig_node;
3517 orig_node = batadv_orig_hash_find(bat_priv, resp_src);
3521 /* Purge the old table first.. */
3522 batadv_tt_global_del_orig(bat_priv, orig_node, -1,
3523 "Received full table");
3525 _batadv_tt_update_changes(bat_priv, orig_node, tt_change, num_entries,
3528 spin_lock_bh(&orig_node->tt_buff_lock);
3529 kfree(orig_node->tt_buff);
3530 orig_node->tt_buff_len = 0;
3531 orig_node->tt_buff = NULL;
3532 spin_unlock_bh(&orig_node->tt_buff_lock);
3534 atomic_set(&orig_node->last_ttvn, ttvn);
3538 batadv_orig_node_put(orig_node);
3541 static void batadv_tt_update_changes(struct batadv_priv *bat_priv,
3542 struct batadv_orig_node *orig_node,
3543 u16 tt_num_changes, u8 ttvn,
3544 struct batadv_tvlv_tt_change *tt_change)
3546 _batadv_tt_update_changes(bat_priv, orig_node, tt_change,
3547 tt_num_changes, ttvn);
3549 batadv_tt_save_orig_buffer(bat_priv, orig_node, tt_change,
3550 batadv_tt_len(tt_num_changes));
3551 atomic_set(&orig_node->last_ttvn, ttvn);
3555 * batadv_is_my_client - check if a client is served by the local node
3556 * @bat_priv: the bat priv with all the soft interface information
3557 * @addr: the mac address of the client to check
3558 * @vid: VLAN identifier
3560 * Return: true if the client is served by this node, false otherwise.
3562 bool batadv_is_my_client(struct batadv_priv *bat_priv, const u8 *addr,
3565 struct batadv_tt_local_entry *tt_local_entry;
3568 tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr, vid);
3569 if (!tt_local_entry)
3571 /* Check if the client has been logically deleted (but is kept for
3572 * consistency purpose)
3574 if ((tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING) ||
3575 (tt_local_entry->common.flags & BATADV_TT_CLIENT_ROAM))
3580 batadv_tt_local_entry_put(tt_local_entry);
3585 * batadv_handle_tt_response - process incoming tt reply
3586 * @bat_priv: the bat priv with all the soft interface information
3587 * @tt_data: tt data containing the tt request information
3588 * @resp_src: mac address of tt reply sender
3589 * @num_entries: number of tt change entries appended to the tt data
3591 static void batadv_handle_tt_response(struct batadv_priv *bat_priv,
3592 struct batadv_tvlv_tt_data *tt_data,
3593 u8 *resp_src, u16 num_entries)
3595 struct batadv_tt_req_node *node;
3596 struct hlist_node *safe;
3597 struct batadv_orig_node *orig_node = NULL;
3598 struct batadv_tvlv_tt_change *tt_change;
3599 u8 *tvlv_ptr = (u8 *)tt_data;
3602 batadv_dbg(BATADV_DBG_TT, bat_priv,
3603 "Received TT_RESPONSE from %pM for ttvn %d t_size: %d [%c]\n",
3604 resp_src, tt_data->ttvn, num_entries,
3605 ((tt_data->flags & BATADV_TT_FULL_TABLE) ? 'F' : '.'));
3607 orig_node = batadv_orig_hash_find(bat_priv, resp_src);
3611 spin_lock_bh(&orig_node->tt_lock);
3613 change_offset = sizeof(struct batadv_tvlv_tt_vlan_data);
3614 change_offset *= ntohs(tt_data->num_vlan);
3615 change_offset += sizeof(*tt_data);
3616 tvlv_ptr += change_offset;
3618 tt_change = (struct batadv_tvlv_tt_change *)tvlv_ptr;
3619 if (tt_data->flags & BATADV_TT_FULL_TABLE) {
3620 batadv_tt_fill_gtable(bat_priv, tt_change, tt_data->ttvn,
3621 resp_src, num_entries);
3623 batadv_tt_update_changes(bat_priv, orig_node, num_entries,
3624 tt_data->ttvn, tt_change);
3627 /* Recalculate the CRC for this orig_node and store it */
3628 batadv_tt_global_update_crc(bat_priv, orig_node);
3630 spin_unlock_bh(&orig_node->tt_lock);
3632 /* Delete the tt_req_node from pending tt_requests list */
3633 spin_lock_bh(&bat_priv->tt.req_list_lock);
3634 hlist_for_each_entry_safe(node, safe, &bat_priv->tt.req_list, list) {
3635 if (!batadv_compare_eth(node->addr, resp_src))
3637 hlist_del_init(&node->list);
3638 batadv_tt_req_node_put(node);
3641 spin_unlock_bh(&bat_priv->tt.req_list_lock);
3644 batadv_orig_node_put(orig_node);
3647 static void batadv_tt_roam_list_free(struct batadv_priv *bat_priv)
3649 struct batadv_tt_roam_node *node, *safe;
3651 spin_lock_bh(&bat_priv->tt.roam_list_lock);
3653 list_for_each_entry_safe(node, safe, &bat_priv->tt.roam_list, list) {
3654 list_del(&node->list);
3655 kmem_cache_free(batadv_tt_roam_cache, node);
3658 spin_unlock_bh(&bat_priv->tt.roam_list_lock);
3661 static void batadv_tt_roam_purge(struct batadv_priv *bat_priv)
3663 struct batadv_tt_roam_node *node, *safe;
3665 spin_lock_bh(&bat_priv->tt.roam_list_lock);
3666 list_for_each_entry_safe(node, safe, &bat_priv->tt.roam_list, list) {
3667 if (!batadv_has_timed_out(node->first_time,
3668 BATADV_ROAMING_MAX_TIME))
3671 list_del(&node->list);
3672 kmem_cache_free(batadv_tt_roam_cache, node);
3674 spin_unlock_bh(&bat_priv->tt.roam_list_lock);
3678 * batadv_tt_check_roam_count - check if a client has roamed too frequently
3679 * @bat_priv: the bat priv with all the soft interface information
3680 * @client: mac address of the roaming client
3682 * This function checks whether the client already reached the
3683 * maximum number of possible roaming phases. In this case the ROAMING_ADV
3686 * Return: true if the ROAMING_ADV can be sent, false otherwise
3688 static bool batadv_tt_check_roam_count(struct batadv_priv *bat_priv, u8 *client)
3690 struct batadv_tt_roam_node *tt_roam_node;
3693 spin_lock_bh(&bat_priv->tt.roam_list_lock);
3694 /* The new tt_req will be issued only if I'm not waiting for a
3695 * reply from the same orig_node yet
3697 list_for_each_entry(tt_roam_node, &bat_priv->tt.roam_list, list) {
3698 if (!batadv_compare_eth(tt_roam_node->addr, client))
3701 if (batadv_has_timed_out(tt_roam_node->first_time,
3702 BATADV_ROAMING_MAX_TIME))
3705 if (!batadv_atomic_dec_not_zero(&tt_roam_node->counter))
3706 /* Sorry, you roamed too many times! */
3713 tt_roam_node = kmem_cache_alloc(batadv_tt_roam_cache,
3718 tt_roam_node->first_time = jiffies;
3719 atomic_set(&tt_roam_node->counter,
3720 BATADV_ROAMING_MAX_COUNT - 1);
3721 ether_addr_copy(tt_roam_node->addr, client);
3723 list_add(&tt_roam_node->list, &bat_priv->tt.roam_list);
3728 spin_unlock_bh(&bat_priv->tt.roam_list_lock);
3733 * batadv_send_roam_adv - send a roaming advertisement message
3734 * @bat_priv: the bat priv with all the soft interface information
3735 * @client: mac address of the roaming client
3736 * @vid: VLAN identifier
3737 * @orig_node: message destination
3739 * Send a ROAMING_ADV message to the node which was previously serving this
3740 * client. This is done to inform the node that from now on all traffic destined
3741 * for this particular roamed client has to be forwarded to the sender of the
3744 static void batadv_send_roam_adv(struct batadv_priv *bat_priv, u8 *client,
3746 struct batadv_orig_node *orig_node)
3748 struct batadv_hard_iface *primary_if;
3749 struct batadv_tvlv_roam_adv tvlv_roam;
3751 primary_if = batadv_primary_if_get_selected(bat_priv);
3755 /* before going on we have to check whether the client has
3756 * already roamed to us too many times
3758 if (!batadv_tt_check_roam_count(bat_priv, client))
3761 batadv_dbg(BATADV_DBG_TT, bat_priv,
3762 "Sending ROAMING_ADV to %pM (client %pM, vid: %d)\n",
3763 orig_node->orig, client, BATADV_PRINT_VID(vid));
3765 batadv_inc_counter(bat_priv, BATADV_CNT_TT_ROAM_ADV_TX);
3767 memcpy(tvlv_roam.client, client, sizeof(tvlv_roam.client));
3768 tvlv_roam.vid = htons(vid);
3770 batadv_tvlv_unicast_send(bat_priv, primary_if->net_dev->dev_addr,
3771 orig_node->orig, BATADV_TVLV_ROAM, 1,
3772 &tvlv_roam, sizeof(tvlv_roam));
3776 batadv_hardif_put(primary_if);
3779 static void batadv_tt_purge(struct work_struct *work)
3781 struct delayed_work *delayed_work;
3782 struct batadv_priv_tt *priv_tt;
3783 struct batadv_priv *bat_priv;
3785 delayed_work = to_delayed_work(work);
3786 priv_tt = container_of(delayed_work, struct batadv_priv_tt, work);
3787 bat_priv = container_of(priv_tt, struct batadv_priv, tt);
3789 batadv_tt_local_purge(bat_priv, BATADV_TT_LOCAL_TIMEOUT);
3790 batadv_tt_global_purge(bat_priv);
3791 batadv_tt_req_purge(bat_priv);
3792 batadv_tt_roam_purge(bat_priv);
3794 queue_delayed_work(batadv_event_workqueue, &bat_priv->tt.work,
3795 msecs_to_jiffies(BATADV_TT_WORK_PERIOD));
3798 void batadv_tt_free(struct batadv_priv *bat_priv)
3800 batadv_tvlv_handler_unregister(bat_priv, BATADV_TVLV_ROAM, 1);
3802 batadv_tvlv_container_unregister(bat_priv, BATADV_TVLV_TT, 1);
3803 batadv_tvlv_handler_unregister(bat_priv, BATADV_TVLV_TT, 1);
3805 cancel_delayed_work_sync(&bat_priv->tt.work);
3807 batadv_tt_local_table_free(bat_priv);
3808 batadv_tt_global_table_free(bat_priv);
3809 batadv_tt_req_list_free(bat_priv);
3810 batadv_tt_changes_list_free(bat_priv);
3811 batadv_tt_roam_list_free(bat_priv);
3813 kfree(bat_priv->tt.last_changeset);
3817 * batadv_tt_local_set_flags - set or unset the specified flags on the local
3818 * table and possibly count them in the TT size
3819 * @bat_priv: the bat priv with all the soft interface information
3820 * @flags: the flag to switch
3821 * @enable: whether to set or unset the flag
3822 * @count: whether to increase the TT size by the number of changed entries
3824 static void batadv_tt_local_set_flags(struct batadv_priv *bat_priv, u16 flags,
3825 bool enable, bool count)
3827 struct batadv_hashtable *hash = bat_priv->tt.local_hash;
3828 struct batadv_tt_common_entry *tt_common_entry;
3829 u16 changed_num = 0;
3830 struct hlist_head *head;
3836 for (i = 0; i < hash->size; i++) {
3837 head = &hash->table[i];
3840 hlist_for_each_entry_rcu(tt_common_entry,
3843 if ((tt_common_entry->flags & flags) == flags)
3845 tt_common_entry->flags |= flags;
3847 if (!(tt_common_entry->flags & flags))
3849 tt_common_entry->flags &= ~flags;
3856 batadv_tt_local_size_inc(bat_priv,
3857 tt_common_entry->vid);
3863 /* Purge out all the tt local entries marked with BATADV_TT_CLIENT_PENDING */
3864 static void batadv_tt_local_purge_pending_clients(struct batadv_priv *bat_priv)
3866 struct batadv_hashtable *hash = bat_priv->tt.local_hash;
3867 struct batadv_tt_common_entry *tt_common;
3868 struct batadv_tt_local_entry *tt_local;
3869 struct hlist_node *node_tmp;
3870 struct hlist_head *head;
3871 spinlock_t *list_lock; /* protects write access to the hash lists */
3877 for (i = 0; i < hash->size; i++) {
3878 head = &hash->table[i];
3879 list_lock = &hash->list_locks[i];
3881 spin_lock_bh(list_lock);
3882 hlist_for_each_entry_safe(tt_common, node_tmp, head,
3884 if (!(tt_common->flags & BATADV_TT_CLIENT_PENDING))
3887 batadv_dbg(BATADV_DBG_TT, bat_priv,
3888 "Deleting local tt entry (%pM, vid: %d): pending\n",
3890 BATADV_PRINT_VID(tt_common->vid));
3892 batadv_tt_local_size_dec(bat_priv, tt_common->vid);
3893 hlist_del_rcu(&tt_common->hash_entry);
3894 tt_local = container_of(tt_common,
3895 struct batadv_tt_local_entry,
3898 batadv_tt_local_entry_put(tt_local);
3900 spin_unlock_bh(list_lock);
3905 * batadv_tt_local_commit_changes_nolock - commit all pending local tt changes
3906 * which have been queued in the time since the last commit
3907 * @bat_priv: the bat priv with all the soft interface information
3909 * Caller must hold tt->commit_lock.
3911 static void batadv_tt_local_commit_changes_nolock(struct batadv_priv *bat_priv)
3913 lockdep_assert_held(&bat_priv->tt.commit_lock);
3915 /* Update multicast addresses in local translation table */
3916 batadv_mcast_mla_update(bat_priv);
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 = NULL;
3956 struct batadv_tt_global_entry *tt_global_entry = NULL;
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)
3975 if (!_batadv_is_ap_isolated(tt_local_entry, tt_global_entry))
3981 batadv_softif_vlan_put(vlan);
3982 if (tt_global_entry)
3983 batadv_tt_global_entry_put(tt_global_entry);
3985 batadv_tt_local_entry_put(tt_local_entry);
3990 * batadv_tt_update_orig - update global translation table with new tt
3991 * information received via ogms
3992 * @bat_priv: the bat priv with all the soft interface information
3993 * @orig_node: the orig_node of the ogm
3994 * @tt_buff: pointer to the first tvlv VLAN entry
3995 * @tt_num_vlan: number of tvlv VLAN entries
3996 * @tt_change: pointer to the first entry in the TT buffer
3997 * @tt_num_changes: number of tt changes inside the tt buffer
3998 * @ttvn: translation table version number of this changeset
4000 static void batadv_tt_update_orig(struct batadv_priv *bat_priv,
4001 struct batadv_orig_node *orig_node,
4002 const void *tt_buff, u16 tt_num_vlan,
4003 struct batadv_tvlv_tt_change *tt_change,
4004 u16 tt_num_changes, u8 ttvn)
4006 u8 orig_ttvn = (u8)atomic_read(&orig_node->last_ttvn);
4007 struct batadv_tvlv_tt_vlan_data *tt_vlan;
4008 bool full_table = true;
4011 tt_vlan = (struct batadv_tvlv_tt_vlan_data *)tt_buff;
4012 has_tt_init = test_bit(BATADV_ORIG_CAPA_HAS_TT,
4013 &orig_node->capa_initialized);
4015 /* orig table not initialised AND first diff is in the OGM OR the ttvn
4016 * increased by one -> we can apply the attached changes
4018 if ((!has_tt_init && ttvn == 1) || ttvn - orig_ttvn == 1) {
4019 /* the OGM could not contain the changes due to their size or
4020 * because they have already been sent BATADV_TT_OGM_APPEND_MAX
4022 * In this case send a tt request
4024 if (!tt_num_changes) {
4029 spin_lock_bh(&orig_node->tt_lock);
4031 batadv_tt_update_changes(bat_priv, orig_node, tt_num_changes,
4034 /* Even if we received the precomputed crc with the OGM, we
4035 * prefer to recompute it to spot any possible inconsistency
4036 * in the global table
4038 batadv_tt_global_update_crc(bat_priv, orig_node);
4040 spin_unlock_bh(&orig_node->tt_lock);
4042 /* The ttvn alone is not enough to guarantee consistency
4043 * because a single value could represent different states
4044 * (due to the wrap around). Thus a node has to check whether
4045 * the resulting table (after applying the changes) is still
4046 * consistent or not. E.g. a node could disconnect while its
4047 * ttvn is X and reconnect on ttvn = X + TTVN_MAX: in this case
4048 * checking the CRC value is mandatory to detect the
4051 if (!batadv_tt_global_check_crc(orig_node, tt_vlan,
4055 /* if we missed more than one change or our tables are not
4056 * in sync anymore -> request fresh tt data
4058 if (!has_tt_init || ttvn != orig_ttvn ||
4059 !batadv_tt_global_check_crc(orig_node, tt_vlan,
4062 batadv_dbg(BATADV_DBG_TT, bat_priv,
4063 "TT inconsistency for %pM. Need to retrieve the correct information (ttvn: %u last_ttvn: %u num_changes: %u)\n",
4064 orig_node->orig, ttvn, orig_ttvn,
4066 batadv_send_tt_request(bat_priv, orig_node, ttvn,
4067 tt_vlan, tt_num_vlan,
4075 * batadv_tt_global_client_is_roaming - check if a client is marked as roaming
4076 * @bat_priv: the bat priv with all the soft interface information
4077 * @addr: the mac address of the client to check
4078 * @vid: VLAN identifier
4080 * Return: true if we know that the client has moved from its old originator
4081 * to another one. This entry is still kept for consistency purposes and will be
4082 * deleted later by a DEL or because of timeout
4084 bool batadv_tt_global_client_is_roaming(struct batadv_priv *bat_priv,
4085 u8 *addr, unsigned short vid)
4087 struct batadv_tt_global_entry *tt_global_entry;
4090 tt_global_entry = batadv_tt_global_hash_find(bat_priv, addr, vid);
4091 if (!tt_global_entry)
4094 ret = tt_global_entry->common.flags & BATADV_TT_CLIENT_ROAM;
4095 batadv_tt_global_entry_put(tt_global_entry);
4101 * batadv_tt_local_client_is_roaming - tells whether the client is roaming
4102 * @bat_priv: the bat priv with all the soft interface information
4103 * @addr: the mac address of the local client to query
4104 * @vid: VLAN identifier
4106 * Return: true if the local client is known to be roaming (it is not served by
4107 * this node anymore) or not. If yes, the client is still present in the table
4108 * to keep the latter consistent with the node TTVN
4110 bool batadv_tt_local_client_is_roaming(struct batadv_priv *bat_priv,
4111 u8 *addr, unsigned short vid)
4113 struct batadv_tt_local_entry *tt_local_entry;
4116 tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr, vid);
4117 if (!tt_local_entry)
4120 ret = tt_local_entry->common.flags & BATADV_TT_CLIENT_ROAM;
4121 batadv_tt_local_entry_put(tt_local_entry);
4126 bool batadv_tt_add_temporary_global_entry(struct batadv_priv *bat_priv,
4127 struct batadv_orig_node *orig_node,
4128 const unsigned char *addr,
4133 if (!batadv_tt_global_add(bat_priv, orig_node, addr, vid,
4134 BATADV_TT_CLIENT_TEMP,
4135 atomic_read(&orig_node->last_ttvn)))
4138 batadv_dbg(BATADV_DBG_TT, bat_priv,
4139 "Added temporary global client (addr: %pM, vid: %d, orig: %pM)\n",
4140 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);