1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2007-2020 B.A.T.M.A.N. contributors:
4 * Marek Lindner, Simon Wunderlich, Antonio Quartulli
7 #include "translation-table.h"
10 #include <linux/atomic.h>
11 #include <linux/bitops.h>
12 #include <linux/build_bug.h>
13 #include <linux/byteorder/generic.h>
14 #include <linux/cache.h>
15 #include <linux/compiler.h>
16 #include <linux/crc32c.h>
17 #include <linux/errno.h>
18 #include <linux/etherdevice.h>
19 #include <linux/gfp.h>
20 #include <linux/if_ether.h>
21 #include <linux/init.h>
22 #include <linux/jhash.h>
23 #include <linux/jiffies.h>
24 #include <linux/kernel.h>
25 #include <linux/kref.h>
26 #include <linux/list.h>
27 #include <linux/lockdep.h>
28 #include <linux/net.h>
29 #include <linux/netdevice.h>
30 #include <linux/netlink.h>
31 #include <linux/rculist.h>
32 #include <linux/rcupdate.h>
33 #include <linux/skbuff.h>
34 #include <linux/slab.h>
35 #include <linux/spinlock.h>
36 #include <linux/stddef.h>
37 #include <linux/string.h>
38 #include <linux/workqueue.h>
39 #include <net/genetlink.h>
40 #include <net/netlink.h>
42 #include <uapi/linux/batadv_packet.h>
43 #include <uapi/linux/batman_adv.h>
45 #include "bridge_loop_avoidance.h"
46 #include "hard-interface.h"
50 #include "originator.h"
51 #include "soft-interface.h"
54 static struct kmem_cache
*batadv_tl_cache __read_mostly
;
55 static struct kmem_cache
*batadv_tg_cache __read_mostly
;
56 static struct kmem_cache
*batadv_tt_orig_cache __read_mostly
;
57 static struct kmem_cache
*batadv_tt_change_cache __read_mostly
;
58 static struct kmem_cache
*batadv_tt_req_cache __read_mostly
;
59 static struct kmem_cache
*batadv_tt_roam_cache __read_mostly
;
62 static struct lock_class_key batadv_tt_local_hash_lock_class_key
;
63 static struct lock_class_key batadv_tt_global_hash_lock_class_key
;
65 static void batadv_send_roam_adv(struct batadv_priv
*bat_priv
, u8
*client
,
67 struct batadv_orig_node
*orig_node
);
68 static void batadv_tt_purge(struct work_struct
*work
);
70 batadv_tt_global_del_orig_list(struct batadv_tt_global_entry
*tt_global_entry
);
71 static void batadv_tt_global_del(struct batadv_priv
*bat_priv
,
72 struct batadv_orig_node
*orig_node
,
73 const unsigned char *addr
,
74 unsigned short vid
, const char *message
,
78 * batadv_compare_tt() - check if two TT entries are the same
79 * @node: the list element pointer of the first TT entry
80 * @data2: pointer to the tt_common_entry of the second TT entry
82 * Compare the MAC address and the VLAN ID of the two TT entries and check if
83 * they are the same TT client.
84 * Return: true if the two TT clients are the same, false otherwise
86 static bool batadv_compare_tt(const struct hlist_node
*node
, const void *data2
)
88 const void *data1
= container_of(node
, struct batadv_tt_common_entry
,
90 const struct batadv_tt_common_entry
*tt1
= data1
;
91 const struct batadv_tt_common_entry
*tt2
= data2
;
93 return (tt1
->vid
== tt2
->vid
) && batadv_compare_eth(data1
, data2
);
97 * batadv_choose_tt() - return the index of the tt entry in the hash table
98 * @data: pointer to the tt_common_entry object to map
99 * @size: the size of the hash table
101 * Return: the hash index where the object represented by 'data' should be
104 static inline u32
batadv_choose_tt(const void *data
, u32 size
)
106 struct batadv_tt_common_entry
*tt
;
109 tt
= (struct batadv_tt_common_entry
*)data
;
110 hash
= jhash(&tt
->addr
, ETH_ALEN
, hash
);
111 hash
= jhash(&tt
->vid
, sizeof(tt
->vid
), hash
);
117 * batadv_tt_hash_find() - look for a client in the given hash table
118 * @hash: the hash table to search
119 * @addr: the mac address of the client to look for
120 * @vid: VLAN identifier
122 * Return: a pointer to the tt_common struct belonging to the searched client if
123 * found, NULL otherwise.
125 static struct batadv_tt_common_entry
*
126 batadv_tt_hash_find(struct batadv_hashtable
*hash
, const u8
*addr
,
129 struct hlist_head
*head
;
130 struct batadv_tt_common_entry to_search
, *tt
, *tt_tmp
= NULL
;
136 ether_addr_copy(to_search
.addr
, addr
);
139 index
= batadv_choose_tt(&to_search
, hash
->size
);
140 head
= &hash
->table
[index
];
143 hlist_for_each_entry_rcu(tt
, head
, hash_entry
) {
144 if (!batadv_compare_eth(tt
, addr
))
150 if (!kref_get_unless_zero(&tt
->refcount
))
162 * batadv_tt_local_hash_find() - search the local table for a given client
163 * @bat_priv: the bat priv with all the soft interface information
164 * @addr: the mac address of the client to look for
165 * @vid: VLAN identifier
167 * Return: a pointer to the corresponding tt_local_entry struct if the client is
168 * found, NULL otherwise.
170 static struct batadv_tt_local_entry
*
171 batadv_tt_local_hash_find(struct batadv_priv
*bat_priv
, const u8
*addr
,
174 struct batadv_tt_common_entry
*tt_common_entry
;
175 struct batadv_tt_local_entry
*tt_local_entry
= NULL
;
177 tt_common_entry
= batadv_tt_hash_find(bat_priv
->tt
.local_hash
, addr
,
180 tt_local_entry
= container_of(tt_common_entry
,
181 struct batadv_tt_local_entry
,
183 return tt_local_entry
;
187 * batadv_tt_global_hash_find() - search the global table for a given client
188 * @bat_priv: the bat priv with all the soft interface information
189 * @addr: the mac address of the client to look for
190 * @vid: VLAN identifier
192 * Return: a pointer to the corresponding tt_global_entry struct if the client
193 * is found, NULL otherwise.
195 struct batadv_tt_global_entry
*
196 batadv_tt_global_hash_find(struct batadv_priv
*bat_priv
, const u8
*addr
,
199 struct batadv_tt_common_entry
*tt_common_entry
;
200 struct batadv_tt_global_entry
*tt_global_entry
= NULL
;
202 tt_common_entry
= batadv_tt_hash_find(bat_priv
->tt
.global_hash
, addr
,
205 tt_global_entry
= container_of(tt_common_entry
,
206 struct batadv_tt_global_entry
,
208 return tt_global_entry
;
212 * batadv_tt_local_entry_free_rcu() - free the tt_local_entry
213 * @rcu: rcu pointer of the tt_local_entry
215 static void batadv_tt_local_entry_free_rcu(struct rcu_head
*rcu
)
217 struct batadv_tt_local_entry
*tt_local_entry
;
219 tt_local_entry
= container_of(rcu
, struct batadv_tt_local_entry
,
222 kmem_cache_free(batadv_tl_cache
, tt_local_entry
);
226 * batadv_tt_local_entry_release() - release tt_local_entry from lists and queue
227 * for free after rcu grace period
228 * @ref: kref pointer of the nc_node
230 static void batadv_tt_local_entry_release(struct kref
*ref
)
232 struct batadv_tt_local_entry
*tt_local_entry
;
234 tt_local_entry
= container_of(ref
, struct batadv_tt_local_entry
,
237 batadv_softif_vlan_put(tt_local_entry
->vlan
);
239 call_rcu(&tt_local_entry
->common
.rcu
, batadv_tt_local_entry_free_rcu
);
243 * batadv_tt_local_entry_put() - decrement the tt_local_entry refcounter and
244 * possibly release it
245 * @tt_local_entry: tt_local_entry to be free'd
248 batadv_tt_local_entry_put(struct batadv_tt_local_entry
*tt_local_entry
)
250 kref_put(&tt_local_entry
->common
.refcount
,
251 batadv_tt_local_entry_release
);
255 * batadv_tt_global_entry_free_rcu() - free the tt_global_entry
256 * @rcu: rcu pointer of the tt_global_entry
258 static void batadv_tt_global_entry_free_rcu(struct rcu_head
*rcu
)
260 struct batadv_tt_global_entry
*tt_global_entry
;
262 tt_global_entry
= container_of(rcu
, struct batadv_tt_global_entry
,
265 kmem_cache_free(batadv_tg_cache
, tt_global_entry
);
269 * batadv_tt_global_entry_release() - release tt_global_entry from lists and
270 * queue for free after rcu grace period
271 * @ref: kref pointer of the nc_node
273 static void batadv_tt_global_entry_release(struct kref
*ref
)
275 struct batadv_tt_global_entry
*tt_global_entry
;
277 tt_global_entry
= container_of(ref
, struct batadv_tt_global_entry
,
280 batadv_tt_global_del_orig_list(tt_global_entry
);
282 call_rcu(&tt_global_entry
->common
.rcu
, batadv_tt_global_entry_free_rcu
);
286 * batadv_tt_global_entry_put() - decrement the tt_global_entry refcounter and
287 * possibly release it
288 * @tt_global_entry: tt_global_entry to be free'd
290 void batadv_tt_global_entry_put(struct batadv_tt_global_entry
*tt_global_entry
)
292 kref_put(&tt_global_entry
->common
.refcount
,
293 batadv_tt_global_entry_release
);
297 * batadv_tt_global_hash_count() - count the number of orig entries
298 * @bat_priv: the bat priv with all the soft interface information
299 * @addr: the mac address of the client to count entries for
300 * @vid: VLAN identifier
302 * Return: the number of originators advertising the given address/data
303 * (excluding our self).
305 int batadv_tt_global_hash_count(struct batadv_priv
*bat_priv
,
306 const u8
*addr
, unsigned short vid
)
308 struct batadv_tt_global_entry
*tt_global_entry
;
311 tt_global_entry
= batadv_tt_global_hash_find(bat_priv
, addr
, vid
);
312 if (!tt_global_entry
)
315 count
= atomic_read(&tt_global_entry
->orig_list_count
);
316 batadv_tt_global_entry_put(tt_global_entry
);
322 * batadv_tt_local_size_mod() - change the size by v of the local table
324 * @bat_priv: the bat priv with all the soft interface information
325 * @vid: the VLAN identifier of the sub-table to change
326 * @v: the amount to sum to the local table size
328 static void batadv_tt_local_size_mod(struct batadv_priv
*bat_priv
,
329 unsigned short vid
, int v
)
331 struct batadv_softif_vlan
*vlan
;
333 vlan
= batadv_softif_vlan_get(bat_priv
, vid
);
337 atomic_add(v
, &vlan
->tt
.num_entries
);
339 batadv_softif_vlan_put(vlan
);
343 * batadv_tt_local_size_inc() - increase by one the local table size for the
345 * @bat_priv: the bat priv with all the soft interface information
346 * @vid: the VLAN identifier
348 static void batadv_tt_local_size_inc(struct batadv_priv
*bat_priv
,
351 batadv_tt_local_size_mod(bat_priv
, vid
, 1);
355 * batadv_tt_local_size_dec() - decrease by one the local table size for the
357 * @bat_priv: the bat priv with all the soft interface information
358 * @vid: the VLAN identifier
360 static void batadv_tt_local_size_dec(struct batadv_priv
*bat_priv
,
363 batadv_tt_local_size_mod(bat_priv
, vid
, -1);
367 * batadv_tt_global_size_mod() - change the size by v of the global table
368 * for orig_node identified by vid
369 * @orig_node: the originator for which the table has to be modified
370 * @vid: the VLAN identifier
371 * @v: the amount to sum to the global table size
373 static void batadv_tt_global_size_mod(struct batadv_orig_node
*orig_node
,
374 unsigned short vid
, int v
)
376 struct batadv_orig_node_vlan
*vlan
;
378 vlan
= batadv_orig_node_vlan_new(orig_node
, vid
);
382 if (atomic_add_return(v
, &vlan
->tt
.num_entries
) == 0) {
383 spin_lock_bh(&orig_node
->vlan_list_lock
);
384 if (!hlist_unhashed(&vlan
->list
)) {
385 hlist_del_init_rcu(&vlan
->list
);
386 batadv_orig_node_vlan_put(vlan
);
388 spin_unlock_bh(&orig_node
->vlan_list_lock
);
391 batadv_orig_node_vlan_put(vlan
);
395 * batadv_tt_global_size_inc() - increase by one the global table size for the
397 * @orig_node: the originator which global table size has to be decreased
398 * @vid: the vlan identifier
400 static void batadv_tt_global_size_inc(struct batadv_orig_node
*orig_node
,
403 batadv_tt_global_size_mod(orig_node
, vid
, 1);
407 * batadv_tt_global_size_dec() - decrease by one the global table size for the
409 * @orig_node: the originator which global table size has to be decreased
410 * @vid: the vlan identifier
412 static void batadv_tt_global_size_dec(struct batadv_orig_node
*orig_node
,
415 batadv_tt_global_size_mod(orig_node
, vid
, -1);
419 * batadv_tt_orig_list_entry_free_rcu() - free the orig_entry
420 * @rcu: rcu pointer of the orig_entry
422 static void batadv_tt_orig_list_entry_free_rcu(struct rcu_head
*rcu
)
424 struct batadv_tt_orig_list_entry
*orig_entry
;
426 orig_entry
= container_of(rcu
, struct batadv_tt_orig_list_entry
, rcu
);
428 kmem_cache_free(batadv_tt_orig_cache
, orig_entry
);
432 * batadv_tt_orig_list_entry_release() - release tt orig entry from lists and
433 * queue for free after rcu grace period
434 * @ref: kref pointer of the tt orig entry
436 static void batadv_tt_orig_list_entry_release(struct kref
*ref
)
438 struct batadv_tt_orig_list_entry
*orig_entry
;
440 orig_entry
= container_of(ref
, struct batadv_tt_orig_list_entry
,
443 batadv_orig_node_put(orig_entry
->orig_node
);
444 call_rcu(&orig_entry
->rcu
, batadv_tt_orig_list_entry_free_rcu
);
448 * batadv_tt_orig_list_entry_put() - decrement the tt orig entry refcounter and
449 * possibly release it
450 * @orig_entry: tt orig entry to be free'd
453 batadv_tt_orig_list_entry_put(struct batadv_tt_orig_list_entry
*orig_entry
)
455 kref_put(&orig_entry
->refcount
, batadv_tt_orig_list_entry_release
);
459 * batadv_tt_local_event() - store a local TT event (ADD/DEL)
460 * @bat_priv: the bat priv with all the soft interface information
461 * @tt_local_entry: the TT entry involved in the event
462 * @event_flags: flags to store in the event structure
464 static void batadv_tt_local_event(struct batadv_priv
*bat_priv
,
465 struct batadv_tt_local_entry
*tt_local_entry
,
468 struct batadv_tt_change_node
*tt_change_node
, *entry
, *safe
;
469 struct batadv_tt_common_entry
*common
= &tt_local_entry
->common
;
470 u8 flags
= common
->flags
| event_flags
;
471 bool event_removed
= false;
472 bool del_op_requested
, del_op_entry
;
474 tt_change_node
= kmem_cache_alloc(batadv_tt_change_cache
, GFP_ATOMIC
);
478 tt_change_node
->change
.flags
= flags
;
479 memset(tt_change_node
->change
.reserved
, 0,
480 sizeof(tt_change_node
->change
.reserved
));
481 ether_addr_copy(tt_change_node
->change
.addr
, common
->addr
);
482 tt_change_node
->change
.vid
= htons(common
->vid
);
484 del_op_requested
= flags
& BATADV_TT_CLIENT_DEL
;
486 /* check for ADD+DEL or DEL+ADD events */
487 spin_lock_bh(&bat_priv
->tt
.changes_list_lock
);
488 list_for_each_entry_safe(entry
, safe
, &bat_priv
->tt
.changes_list
,
490 if (!batadv_compare_eth(entry
->change
.addr
, common
->addr
))
493 /* DEL+ADD in the same orig interval have no effect and can be
494 * removed to avoid silly behaviour on the receiver side. The
495 * other way around (ADD+DEL) can happen in case of roaming of
496 * a client still in the NEW state. Roaming of NEW clients is
497 * now possible due to automatically recognition of "temporary"
500 del_op_entry
= entry
->change
.flags
& BATADV_TT_CLIENT_DEL
;
501 if (!del_op_requested
&& del_op_entry
)
503 if (del_op_requested
&& !del_op_entry
)
506 /* this is a second add in the same originator interval. It
507 * means that flags have been changed: update them!
509 if (!del_op_requested
&& !del_op_entry
)
510 entry
->change
.flags
= flags
;
514 list_del(&entry
->list
);
515 kmem_cache_free(batadv_tt_change_cache
, entry
);
516 kmem_cache_free(batadv_tt_change_cache
, tt_change_node
);
517 event_removed
= true;
521 /* track the change in the OGMinterval list */
522 list_add_tail(&tt_change_node
->list
, &bat_priv
->tt
.changes_list
);
525 spin_unlock_bh(&bat_priv
->tt
.changes_list_lock
);
528 atomic_dec(&bat_priv
->tt
.local_changes
);
530 atomic_inc(&bat_priv
->tt
.local_changes
);
534 * batadv_tt_len() - compute length in bytes of given number of tt changes
535 * @changes_num: number of tt changes
537 * Return: computed length in bytes.
539 static int batadv_tt_len(int changes_num
)
541 return changes_num
* sizeof(struct batadv_tvlv_tt_change
);
545 * batadv_tt_entries() - compute the number of entries fitting in tt_len bytes
546 * @tt_len: available space
548 * Return: the number of entries.
550 static u16
batadv_tt_entries(u16 tt_len
)
552 return tt_len
/ batadv_tt_len(1);
556 * batadv_tt_local_table_transmit_size() - calculates the local translation
557 * table size when transmitted over the air
558 * @bat_priv: the bat priv with all the soft interface information
560 * Return: local translation table size in bytes.
562 static int batadv_tt_local_table_transmit_size(struct batadv_priv
*bat_priv
)
565 u16 tt_local_entries
= 0;
566 struct batadv_softif_vlan
*vlan
;
570 hlist_for_each_entry_rcu(vlan
, &bat_priv
->softif_vlan_list
, list
) {
572 tt_local_entries
+= atomic_read(&vlan
->tt
.num_entries
);
576 /* header size of tvlv encapsulated tt response payload */
577 hdr_size
= sizeof(struct batadv_unicast_tvlv_packet
);
578 hdr_size
+= sizeof(struct batadv_tvlv_hdr
);
579 hdr_size
+= sizeof(struct batadv_tvlv_tt_data
);
580 hdr_size
+= num_vlan
* sizeof(struct batadv_tvlv_tt_vlan_data
);
582 return hdr_size
+ batadv_tt_len(tt_local_entries
);
585 static int batadv_tt_local_init(struct batadv_priv
*bat_priv
)
587 if (bat_priv
->tt
.local_hash
)
590 bat_priv
->tt
.local_hash
= batadv_hash_new(1024);
592 if (!bat_priv
->tt
.local_hash
)
595 batadv_hash_set_lock_class(bat_priv
->tt
.local_hash
,
596 &batadv_tt_local_hash_lock_class_key
);
601 static void batadv_tt_global_free(struct batadv_priv
*bat_priv
,
602 struct batadv_tt_global_entry
*tt_global
,
605 struct batadv_tt_global_entry
*tt_removed_entry
;
606 struct hlist_node
*tt_removed_node
;
608 batadv_dbg(BATADV_DBG_TT
, bat_priv
,
609 "Deleting global tt entry %pM (vid: %d): %s\n",
610 tt_global
->common
.addr
,
611 batadv_print_vid(tt_global
->common
.vid
), message
);
613 tt_removed_node
= batadv_hash_remove(bat_priv
->tt
.global_hash
,
617 if (!tt_removed_node
)
620 /* drop reference of remove hash entry */
621 tt_removed_entry
= hlist_entry(tt_removed_node
,
622 struct batadv_tt_global_entry
,
624 batadv_tt_global_entry_put(tt_removed_entry
);
628 * batadv_tt_local_add() - add a new client to the local table or update an
630 * @soft_iface: netdev struct of the mesh interface
631 * @addr: the mac address of the client to add
632 * @vid: VLAN identifier
633 * @ifindex: index of the interface where the client is connected to (useful to
634 * identify wireless clients)
635 * @mark: the value contained in the skb->mark field of the received packet (if
638 * Return: true if the client was successfully added, false otherwise.
640 bool batadv_tt_local_add(struct net_device
*soft_iface
, const u8
*addr
,
641 unsigned short vid
, int ifindex
, u32 mark
)
643 struct batadv_priv
*bat_priv
= netdev_priv(soft_iface
);
644 struct batadv_tt_local_entry
*tt_local
;
645 struct batadv_tt_global_entry
*tt_global
= NULL
;
646 struct net
*net
= dev_net(soft_iface
);
647 struct batadv_softif_vlan
*vlan
;
648 struct net_device
*in_dev
= NULL
;
649 struct batadv_hard_iface
*in_hardif
= NULL
;
650 struct hlist_head
*head
;
651 struct batadv_tt_orig_list_entry
*orig_entry
;
652 int hash_added
, table_size
, packet_size_max
;
654 bool roamed_back
= false;
658 if (ifindex
!= BATADV_NULL_IFINDEX
)
659 in_dev
= dev_get_by_index(net
, ifindex
);
662 in_hardif
= batadv_hardif_get_by_netdev(in_dev
);
664 tt_local
= batadv_tt_local_hash_find(bat_priv
, addr
, vid
);
666 if (!is_multicast_ether_addr(addr
))
667 tt_global
= batadv_tt_global_hash_find(bat_priv
, addr
, vid
);
670 tt_local
->last_seen
= jiffies
;
671 if (tt_local
->common
.flags
& BATADV_TT_CLIENT_PENDING
) {
672 batadv_dbg(BATADV_DBG_TT
, bat_priv
,
673 "Re-adding pending client %pM (vid: %d)\n",
674 addr
, batadv_print_vid(vid
));
675 /* whatever the reason why the PENDING flag was set,
676 * this is a client which was enqueued to be removed in
677 * this orig_interval. Since it popped up again, the
678 * flag can be reset like it was never enqueued
680 tt_local
->common
.flags
&= ~BATADV_TT_CLIENT_PENDING
;
684 if (tt_local
->common
.flags
& BATADV_TT_CLIENT_ROAM
) {
685 batadv_dbg(BATADV_DBG_TT
, bat_priv
,
686 "Roaming client %pM (vid: %d) came back to its original location\n",
687 addr
, batadv_print_vid(vid
));
688 /* the ROAM flag is set because this client roamed away
689 * and the node got a roaming_advertisement message. Now
690 * that the client popped up again at its original
691 * location such flag can be unset
693 tt_local
->common
.flags
&= ~BATADV_TT_CLIENT_ROAM
;
699 /* Ignore the client if we cannot send it in a full table response. */
700 table_size
= batadv_tt_local_table_transmit_size(bat_priv
);
701 table_size
+= batadv_tt_len(1);
702 packet_size_max
= atomic_read(&bat_priv
->packet_size_max
);
703 if (table_size
> packet_size_max
) {
704 net_ratelimited_function(batadv_info
, soft_iface
,
705 "Local translation table size (%i) exceeds maximum packet size (%i); Ignoring new local tt entry: %pM\n",
706 table_size
, packet_size_max
, addr
);
710 tt_local
= kmem_cache_alloc(batadv_tl_cache
, GFP_ATOMIC
);
714 /* increase the refcounter of the related vlan */
715 vlan
= batadv_softif_vlan_get(bat_priv
, vid
);
717 net_ratelimited_function(batadv_info
, soft_iface
,
718 "adding TT local entry %pM to non-existent VLAN %d\n",
719 addr
, batadv_print_vid(vid
));
720 kmem_cache_free(batadv_tl_cache
, tt_local
);
725 batadv_dbg(BATADV_DBG_TT
, bat_priv
,
726 "Creating new local tt entry: %pM (vid: %d, ttvn: %d)\n",
727 addr
, batadv_print_vid(vid
),
728 (u8
)atomic_read(&bat_priv
->tt
.vn
));
730 ether_addr_copy(tt_local
->common
.addr
, addr
);
731 /* The local entry has to be marked as NEW to avoid to send it in
732 * a full table response going out before the next ttvn increment
733 * (consistency check)
735 tt_local
->common
.flags
= BATADV_TT_CLIENT_NEW
;
736 tt_local
->common
.vid
= vid
;
737 if (batadv_is_wifi_hardif(in_hardif
))
738 tt_local
->common
.flags
|= BATADV_TT_CLIENT_WIFI
;
739 kref_init(&tt_local
->common
.refcount
);
740 tt_local
->last_seen
= jiffies
;
741 tt_local
->common
.added_at
= tt_local
->last_seen
;
742 tt_local
->vlan
= vlan
;
744 /* the batman interface mac and multicast addresses should never be
747 if (batadv_compare_eth(addr
, soft_iface
->dev_addr
) ||
748 is_multicast_ether_addr(addr
))
749 tt_local
->common
.flags
|= BATADV_TT_CLIENT_NOPURGE
;
751 kref_get(&tt_local
->common
.refcount
);
752 hash_added
= batadv_hash_add(bat_priv
->tt
.local_hash
, batadv_compare_tt
,
753 batadv_choose_tt
, &tt_local
->common
,
754 &tt_local
->common
.hash_entry
);
756 if (unlikely(hash_added
!= 0)) {
757 /* remove the reference for the hash */
758 batadv_tt_local_entry_put(tt_local
);
763 batadv_tt_local_event(bat_priv
, tt_local
, BATADV_NO_FLAGS
);
766 /* Check whether it is a roaming, but don't do anything if the roaming
767 * process has already been handled
769 if (tt_global
&& !(tt_global
->common
.flags
& BATADV_TT_CLIENT_ROAM
)) {
770 /* These node are probably going to update their tt table */
771 head
= &tt_global
->orig_list
;
773 hlist_for_each_entry_rcu(orig_entry
, head
, list
) {
774 batadv_send_roam_adv(bat_priv
, tt_global
->common
.addr
,
775 tt_global
->common
.vid
,
776 orig_entry
->orig_node
);
780 batadv_tt_global_free(bat_priv
, tt_global
,
784 /* The global entry has to be marked as ROAMING and
785 * has to be kept for consistency purpose
787 tt_global
->common
.flags
|= BATADV_TT_CLIENT_ROAM
;
788 tt_global
->roam_at
= jiffies
;
792 /* store the current remote flags before altering them. This helps
793 * understanding is flags are changing or not
795 remote_flags
= tt_local
->common
.flags
& BATADV_TT_REMOTE_MASK
;
797 if (batadv_is_wifi_hardif(in_hardif
))
798 tt_local
->common
.flags
|= BATADV_TT_CLIENT_WIFI
;
800 tt_local
->common
.flags
&= ~BATADV_TT_CLIENT_WIFI
;
802 /* check the mark in the skb: if it's equal to the configured
803 * isolation_mark, it means the packet is coming from an isolated
806 match_mark
= (mark
& bat_priv
->isolation_mark_mask
);
807 if (bat_priv
->isolation_mark_mask
&&
808 match_mark
== bat_priv
->isolation_mark
)
809 tt_local
->common
.flags
|= BATADV_TT_CLIENT_ISOLA
;
811 tt_local
->common
.flags
&= ~BATADV_TT_CLIENT_ISOLA
;
813 /* if any "dynamic" flag has been modified, resend an ADD event for this
814 * entry so that all the nodes can get the new flags
816 if (remote_flags
^ (tt_local
->common
.flags
& BATADV_TT_REMOTE_MASK
))
817 batadv_tt_local_event(bat_priv
, tt_local
, BATADV_NO_FLAGS
);
822 batadv_hardif_put(in_hardif
);
826 batadv_tt_local_entry_put(tt_local
);
828 batadv_tt_global_entry_put(tt_global
);
833 * batadv_tt_prepare_tvlv_global_data() - prepare the TVLV TT header to send
834 * within a TT Response directed to another node
835 * @orig_node: originator for which the TT data has to be prepared
836 * @tt_data: uninitialised pointer to the address of the TVLV buffer
837 * @tt_change: uninitialised pointer to the address of the area where the TT
838 * changed can be stored
839 * @tt_len: pointer to the length to reserve to the tt_change. if -1 this
840 * function reserves the amount of space needed to send the entire global TT
841 * table. In case of success the value is updated with the real amount of
843 * Allocate the needed amount of memory for the entire TT TVLV and write its
844 * header made up of one tvlv_tt_data object and a series of tvlv_tt_vlan_data
845 * objects, one per active VLAN served by the originator node.
847 * Return: the size of the allocated buffer or 0 in case of failure.
850 batadv_tt_prepare_tvlv_global_data(struct batadv_orig_node
*orig_node
,
851 struct batadv_tvlv_tt_data
**tt_data
,
852 struct batadv_tvlv_tt_change
**tt_change
,
859 struct batadv_tvlv_tt_vlan_data
*tt_vlan
;
860 struct batadv_orig_node_vlan
*vlan
;
863 spin_lock_bh(&orig_node
->vlan_list_lock
);
864 hlist_for_each_entry(vlan
, &orig_node
->vlan_list
, list
) {
866 num_entries
+= atomic_read(&vlan
->tt
.num_entries
);
869 change_offset
= sizeof(**tt_data
);
870 change_offset
+= num_vlan
* sizeof(*tt_vlan
);
872 /* if tt_len is negative, allocate the space needed by the full table */
874 *tt_len
= batadv_tt_len(num_entries
);
877 tvlv_len
+= change_offset
;
879 *tt_data
= kmalloc(tvlv_len
, GFP_ATOMIC
);
885 (*tt_data
)->flags
= BATADV_NO_FLAGS
;
886 (*tt_data
)->ttvn
= atomic_read(&orig_node
->last_ttvn
);
887 (*tt_data
)->num_vlan
= htons(num_vlan
);
889 tt_vlan
= (struct batadv_tvlv_tt_vlan_data
*)(*tt_data
+ 1);
890 hlist_for_each_entry(vlan
, &orig_node
->vlan_list
, list
) {
891 tt_vlan
->vid
= htons(vlan
->vid
);
892 tt_vlan
->crc
= htonl(vlan
->tt
.crc
);
897 tt_change_ptr
= (u8
*)*tt_data
+ change_offset
;
898 *tt_change
= (struct batadv_tvlv_tt_change
*)tt_change_ptr
;
901 spin_unlock_bh(&orig_node
->vlan_list_lock
);
906 * batadv_tt_prepare_tvlv_local_data() - allocate and prepare the TT TVLV for
908 * @bat_priv: the bat priv with all the soft interface information
909 * @tt_data: uninitialised pointer to the address of the TVLV buffer
910 * @tt_change: uninitialised pointer to the address of the area where the TT
911 * changes can be stored
912 * @tt_len: pointer to the length to reserve to the tt_change. if -1 this
913 * function reserves the amount of space needed to send the entire local TT
914 * table. In case of success the value is updated with the real amount of
917 * Allocate the needed amount of memory for the entire TT TVLV and write its
918 * header made up by one tvlv_tt_data object and a series of tvlv_tt_vlan_data
919 * objects, one per active VLAN.
921 * Return: the size of the allocated buffer or 0 in case of failure.
924 batadv_tt_prepare_tvlv_local_data(struct batadv_priv
*bat_priv
,
925 struct batadv_tvlv_tt_data
**tt_data
,
926 struct batadv_tvlv_tt_change
**tt_change
,
929 struct batadv_tvlv_tt_vlan_data
*tt_vlan
;
930 struct batadv_softif_vlan
*vlan
;
932 u16 vlan_entries
= 0;
933 u16 total_entries
= 0;
938 spin_lock_bh(&bat_priv
->softif_vlan_list_lock
);
939 hlist_for_each_entry(vlan
, &bat_priv
->softif_vlan_list
, list
) {
940 vlan_entries
= atomic_read(&vlan
->tt
.num_entries
);
941 if (vlan_entries
< 1)
945 total_entries
+= vlan_entries
;
948 change_offset
= sizeof(**tt_data
);
949 change_offset
+= num_vlan
* sizeof(*tt_vlan
);
951 /* if tt_len is negative, allocate the space needed by the full table */
953 *tt_len
= batadv_tt_len(total_entries
);
956 tvlv_len
+= change_offset
;
958 *tt_data
= kmalloc(tvlv_len
, GFP_ATOMIC
);
964 (*tt_data
)->flags
= BATADV_NO_FLAGS
;
965 (*tt_data
)->ttvn
= atomic_read(&bat_priv
->tt
.vn
);
966 (*tt_data
)->num_vlan
= htons(num_vlan
);
968 tt_vlan
= (struct batadv_tvlv_tt_vlan_data
*)(*tt_data
+ 1);
969 hlist_for_each_entry(vlan
, &bat_priv
->softif_vlan_list
, list
) {
970 vlan_entries
= atomic_read(&vlan
->tt
.num_entries
);
971 if (vlan_entries
< 1)
974 tt_vlan
->vid
= htons(vlan
->vid
);
975 tt_vlan
->crc
= htonl(vlan
->tt
.crc
);
980 tt_change_ptr
= (u8
*)*tt_data
+ change_offset
;
981 *tt_change
= (struct batadv_tvlv_tt_change
*)tt_change_ptr
;
984 spin_unlock_bh(&bat_priv
->softif_vlan_list_lock
);
989 * batadv_tt_tvlv_container_update() - update the translation table tvlv
990 * container after local tt changes have been committed
991 * @bat_priv: the bat priv with all the soft interface information
993 static void batadv_tt_tvlv_container_update(struct batadv_priv
*bat_priv
)
995 struct batadv_tt_change_node
*entry
, *safe
;
996 struct batadv_tvlv_tt_data
*tt_data
;
997 struct batadv_tvlv_tt_change
*tt_change
;
998 int tt_diff_len
, tt_change_len
= 0;
999 int tt_diff_entries_num
= 0;
1000 int tt_diff_entries_count
= 0;
1003 tt_diff_entries_num
= atomic_read(&bat_priv
->tt
.local_changes
);
1004 tt_diff_len
= batadv_tt_len(tt_diff_entries_num
);
1006 /* if we have too many changes for one packet don't send any
1007 * and wait for the tt table request which will be fragmented
1009 if (tt_diff_len
> bat_priv
->soft_iface
->mtu
)
1012 tvlv_len
= batadv_tt_prepare_tvlv_local_data(bat_priv
, &tt_data
,
1013 &tt_change
, &tt_diff_len
);
1017 tt_data
->flags
= BATADV_TT_OGM_DIFF
;
1019 if (tt_diff_len
== 0)
1020 goto container_register
;
1022 spin_lock_bh(&bat_priv
->tt
.changes_list_lock
);
1023 atomic_set(&bat_priv
->tt
.local_changes
, 0);
1025 list_for_each_entry_safe(entry
, safe
, &bat_priv
->tt
.changes_list
,
1027 if (tt_diff_entries_count
< tt_diff_entries_num
) {
1028 memcpy(tt_change
+ tt_diff_entries_count
,
1030 sizeof(struct batadv_tvlv_tt_change
));
1031 tt_diff_entries_count
++;
1033 list_del(&entry
->list
);
1034 kmem_cache_free(batadv_tt_change_cache
, entry
);
1036 spin_unlock_bh(&bat_priv
->tt
.changes_list_lock
);
1038 /* Keep the buffer for possible tt_request */
1039 spin_lock_bh(&bat_priv
->tt
.last_changeset_lock
);
1040 kfree(bat_priv
->tt
.last_changeset
);
1041 bat_priv
->tt
.last_changeset_len
= 0;
1042 bat_priv
->tt
.last_changeset
= NULL
;
1043 tt_change_len
= batadv_tt_len(tt_diff_entries_count
);
1044 /* check whether this new OGM has no changes due to size problems */
1045 if (tt_diff_entries_count
> 0) {
1046 /* if kmalloc() fails we will reply with the full table
1047 * instead of providing the diff
1049 bat_priv
->tt
.last_changeset
= kzalloc(tt_diff_len
, GFP_ATOMIC
);
1050 if (bat_priv
->tt
.last_changeset
) {
1051 memcpy(bat_priv
->tt
.last_changeset
,
1052 tt_change
, tt_change_len
);
1053 bat_priv
->tt
.last_changeset_len
= tt_diff_len
;
1056 spin_unlock_bh(&bat_priv
->tt
.last_changeset_lock
);
1059 batadv_tvlv_container_register(bat_priv
, BATADV_TVLV_TT
, 1, tt_data
,
1065 * batadv_tt_local_dump_entry() - Dump one TT local entry into a message
1066 * @msg :Netlink message to dump into
1067 * @portid: Port making netlink request
1068 * @cb: Control block containing additional options
1069 * @bat_priv: The bat priv with all the soft interface information
1070 * @common: tt local & tt global common data
1072 * Return: Error code, or 0 on success
1075 batadv_tt_local_dump_entry(struct sk_buff
*msg
, u32 portid
,
1076 struct netlink_callback
*cb
,
1077 struct batadv_priv
*bat_priv
,
1078 struct batadv_tt_common_entry
*common
)
1081 struct batadv_softif_vlan
*vlan
;
1082 struct batadv_tt_local_entry
*local
;
1083 unsigned int last_seen_msecs
;
1086 local
= container_of(common
, struct batadv_tt_local_entry
, common
);
1087 last_seen_msecs
= jiffies_to_msecs(jiffies
- local
->last_seen
);
1089 vlan
= batadv_softif_vlan_get(bat_priv
, common
->vid
);
1095 batadv_softif_vlan_put(vlan
);
1097 hdr
= genlmsg_put(msg
, portid
, cb
->nlh
->nlmsg_seq
,
1098 &batadv_netlink_family
, NLM_F_MULTI
,
1099 BATADV_CMD_GET_TRANSTABLE_LOCAL
);
1103 genl_dump_check_consistent(cb
, hdr
);
1105 if (nla_put(msg
, BATADV_ATTR_TT_ADDRESS
, ETH_ALEN
, common
->addr
) ||
1106 nla_put_u32(msg
, BATADV_ATTR_TT_CRC32
, crc
) ||
1107 nla_put_u16(msg
, BATADV_ATTR_TT_VID
, common
->vid
) ||
1108 nla_put_u32(msg
, BATADV_ATTR_TT_FLAGS
, common
->flags
))
1109 goto nla_put_failure
;
1111 if (!(common
->flags
& BATADV_TT_CLIENT_NOPURGE
) &&
1112 nla_put_u32(msg
, BATADV_ATTR_LAST_SEEN_MSECS
, last_seen_msecs
))
1113 goto nla_put_failure
;
1115 genlmsg_end(msg
, hdr
);
1119 genlmsg_cancel(msg
, hdr
);
1124 * batadv_tt_local_dump_bucket() - Dump one TT local bucket into a message
1125 * @msg: Netlink message to dump into
1126 * @portid: Port making netlink request
1127 * @cb: Control block containing additional options
1128 * @bat_priv: The bat priv with all the soft interface information
1129 * @hash: hash to dump
1130 * @bucket: bucket index to dump
1131 * @idx_s: Number of entries to skip
1133 * Return: Error code, or 0 on success
1136 batadv_tt_local_dump_bucket(struct sk_buff
*msg
, u32 portid
,
1137 struct netlink_callback
*cb
,
1138 struct batadv_priv
*bat_priv
,
1139 struct batadv_hashtable
*hash
, unsigned int bucket
,
1142 struct batadv_tt_common_entry
*common
;
1145 spin_lock_bh(&hash
->list_locks
[bucket
]);
1146 cb
->seq
= atomic_read(&hash
->generation
) << 1 | 1;
1148 hlist_for_each_entry(common
, &hash
->table
[bucket
], hash_entry
) {
1152 if (batadv_tt_local_dump_entry(msg
, portid
, cb
, bat_priv
,
1154 spin_unlock_bh(&hash
->list_locks
[bucket
]);
1159 spin_unlock_bh(&hash
->list_locks
[bucket
]);
1166 * batadv_tt_local_dump() - Dump TT local entries into a message
1167 * @msg: Netlink message to dump into
1168 * @cb: Parameters from query
1170 * Return: Error code, or 0 on success
1172 int batadv_tt_local_dump(struct sk_buff
*msg
, struct netlink_callback
*cb
)
1174 struct net
*net
= sock_net(cb
->skb
->sk
);
1175 struct net_device
*soft_iface
;
1176 struct batadv_priv
*bat_priv
;
1177 struct batadv_hard_iface
*primary_if
= NULL
;
1178 struct batadv_hashtable
*hash
;
1181 int bucket
= cb
->args
[0];
1182 int idx
= cb
->args
[1];
1183 int portid
= NETLINK_CB(cb
->skb
).portid
;
1185 ifindex
= batadv_netlink_get_ifindex(cb
->nlh
, BATADV_ATTR_MESH_IFINDEX
);
1189 soft_iface
= dev_get_by_index(net
, ifindex
);
1190 if (!soft_iface
|| !batadv_softif_is_valid(soft_iface
)) {
1195 bat_priv
= netdev_priv(soft_iface
);
1197 primary_if
= batadv_primary_if_get_selected(bat_priv
);
1198 if (!primary_if
|| primary_if
->if_status
!= BATADV_IF_ACTIVE
) {
1203 hash
= bat_priv
->tt
.local_hash
;
1205 while (bucket
< hash
->size
) {
1206 if (batadv_tt_local_dump_bucket(msg
, portid
, cb
, bat_priv
,
1207 hash
, bucket
, &idx
))
1217 batadv_hardif_put(primary_if
);
1219 dev_put(soft_iface
);
1221 cb
->args
[0] = bucket
;
1228 batadv_tt_local_set_pending(struct batadv_priv
*bat_priv
,
1229 struct batadv_tt_local_entry
*tt_local_entry
,
1230 u16 flags
, const char *message
)
1232 batadv_tt_local_event(bat_priv
, tt_local_entry
, flags
);
1234 /* The local client has to be marked as "pending to be removed" but has
1235 * to be kept in the table in order to send it in a full table
1236 * response issued before the net ttvn increment (consistency check)
1238 tt_local_entry
->common
.flags
|= BATADV_TT_CLIENT_PENDING
;
1240 batadv_dbg(BATADV_DBG_TT
, bat_priv
,
1241 "Local tt entry (%pM, vid: %d) pending to be removed: %s\n",
1242 tt_local_entry
->common
.addr
,
1243 batadv_print_vid(tt_local_entry
->common
.vid
), message
);
1247 * batadv_tt_local_remove() - logically remove an entry from the local table
1248 * @bat_priv: the bat priv with all the soft interface information
1249 * @addr: the MAC address of the client to remove
1250 * @vid: VLAN identifier
1251 * @message: message to append to the log on deletion
1252 * @roaming: true if the deletion is due to a roaming event
1254 * Return: the flags assigned to the local entry before being deleted
1256 u16
batadv_tt_local_remove(struct batadv_priv
*bat_priv
, const u8
*addr
,
1257 unsigned short vid
, const char *message
,
1260 struct batadv_tt_local_entry
*tt_removed_entry
;
1261 struct batadv_tt_local_entry
*tt_local_entry
;
1262 u16 flags
, curr_flags
= BATADV_NO_FLAGS
;
1263 struct hlist_node
*tt_removed_node
;
1265 tt_local_entry
= batadv_tt_local_hash_find(bat_priv
, addr
, vid
);
1266 if (!tt_local_entry
)
1269 curr_flags
= tt_local_entry
->common
.flags
;
1271 flags
= BATADV_TT_CLIENT_DEL
;
1272 /* if this global entry addition is due to a roaming, the node has to
1273 * mark the local entry as "roamed" in order to correctly reroute
1277 flags
|= BATADV_TT_CLIENT_ROAM
;
1278 /* mark the local client as ROAMed */
1279 tt_local_entry
->common
.flags
|= BATADV_TT_CLIENT_ROAM
;
1282 if (!(tt_local_entry
->common
.flags
& BATADV_TT_CLIENT_NEW
)) {
1283 batadv_tt_local_set_pending(bat_priv
, tt_local_entry
, flags
,
1287 /* if this client has been added right now, it is possible to
1288 * immediately purge it
1290 batadv_tt_local_event(bat_priv
, tt_local_entry
, BATADV_TT_CLIENT_DEL
);
1292 tt_removed_node
= batadv_hash_remove(bat_priv
->tt
.local_hash
,
1295 &tt_local_entry
->common
);
1296 if (!tt_removed_node
)
1299 /* drop reference of remove hash entry */
1300 tt_removed_entry
= hlist_entry(tt_removed_node
,
1301 struct batadv_tt_local_entry
,
1303 batadv_tt_local_entry_put(tt_removed_entry
);
1307 batadv_tt_local_entry_put(tt_local_entry
);
1313 * batadv_tt_local_purge_list() - purge inactive tt local entries
1314 * @bat_priv: the bat priv with all the soft interface information
1315 * @head: pointer to the list containing the local tt entries
1316 * @timeout: parameter deciding whether a given tt local entry is considered
1319 static void batadv_tt_local_purge_list(struct batadv_priv
*bat_priv
,
1320 struct hlist_head
*head
,
1323 struct batadv_tt_local_entry
*tt_local_entry
;
1324 struct batadv_tt_common_entry
*tt_common_entry
;
1325 struct hlist_node
*node_tmp
;
1327 hlist_for_each_entry_safe(tt_common_entry
, node_tmp
, head
,
1329 tt_local_entry
= container_of(tt_common_entry
,
1330 struct batadv_tt_local_entry
,
1332 if (tt_local_entry
->common
.flags
& BATADV_TT_CLIENT_NOPURGE
)
1335 /* entry already marked for deletion */
1336 if (tt_local_entry
->common
.flags
& BATADV_TT_CLIENT_PENDING
)
1339 if (!batadv_has_timed_out(tt_local_entry
->last_seen
, timeout
))
1342 batadv_tt_local_set_pending(bat_priv
, tt_local_entry
,
1343 BATADV_TT_CLIENT_DEL
, "timed out");
1348 * batadv_tt_local_purge() - purge inactive tt local entries
1349 * @bat_priv: the bat priv with all the soft interface information
1350 * @timeout: parameter deciding whether a given tt local entry is considered
1353 static void batadv_tt_local_purge(struct batadv_priv
*bat_priv
,
1356 struct batadv_hashtable
*hash
= bat_priv
->tt
.local_hash
;
1357 struct hlist_head
*head
;
1358 spinlock_t
*list_lock
; /* protects write access to the hash lists */
1361 for (i
= 0; i
< hash
->size
; i
++) {
1362 head
= &hash
->table
[i
];
1363 list_lock
= &hash
->list_locks
[i
];
1365 spin_lock_bh(list_lock
);
1366 batadv_tt_local_purge_list(bat_priv
, head
, timeout
);
1367 spin_unlock_bh(list_lock
);
1371 static void batadv_tt_local_table_free(struct batadv_priv
*bat_priv
)
1373 struct batadv_hashtable
*hash
;
1374 spinlock_t
*list_lock
; /* protects write access to the hash lists */
1375 struct batadv_tt_common_entry
*tt_common_entry
;
1376 struct batadv_tt_local_entry
*tt_local
;
1377 struct hlist_node
*node_tmp
;
1378 struct hlist_head
*head
;
1381 if (!bat_priv
->tt
.local_hash
)
1384 hash
= bat_priv
->tt
.local_hash
;
1386 for (i
= 0; i
< hash
->size
; i
++) {
1387 head
= &hash
->table
[i
];
1388 list_lock
= &hash
->list_locks
[i
];
1390 spin_lock_bh(list_lock
);
1391 hlist_for_each_entry_safe(tt_common_entry
, node_tmp
,
1393 hlist_del_rcu(&tt_common_entry
->hash_entry
);
1394 tt_local
= container_of(tt_common_entry
,
1395 struct batadv_tt_local_entry
,
1398 batadv_tt_local_entry_put(tt_local
);
1400 spin_unlock_bh(list_lock
);
1403 batadv_hash_destroy(hash
);
1405 bat_priv
->tt
.local_hash
= NULL
;
1408 static int batadv_tt_global_init(struct batadv_priv
*bat_priv
)
1410 if (bat_priv
->tt
.global_hash
)
1413 bat_priv
->tt
.global_hash
= batadv_hash_new(1024);
1415 if (!bat_priv
->tt
.global_hash
)
1418 batadv_hash_set_lock_class(bat_priv
->tt
.global_hash
,
1419 &batadv_tt_global_hash_lock_class_key
);
1424 static void batadv_tt_changes_list_free(struct batadv_priv
*bat_priv
)
1426 struct batadv_tt_change_node
*entry
, *safe
;
1428 spin_lock_bh(&bat_priv
->tt
.changes_list_lock
);
1430 list_for_each_entry_safe(entry
, safe
, &bat_priv
->tt
.changes_list
,
1432 list_del(&entry
->list
);
1433 kmem_cache_free(batadv_tt_change_cache
, entry
);
1436 atomic_set(&bat_priv
->tt
.local_changes
, 0);
1437 spin_unlock_bh(&bat_priv
->tt
.changes_list_lock
);
1441 * batadv_tt_global_orig_entry_find() - find a TT orig_list_entry
1442 * @entry: the TT global entry where the orig_list_entry has to be
1444 * @orig_node: the originator for which the orig_list_entry has to be found
1446 * retrieve the orig_tt_list_entry belonging to orig_node from the
1447 * batadv_tt_global_entry list
1449 * Return: it with an increased refcounter, NULL if not found
1451 static struct batadv_tt_orig_list_entry
*
1452 batadv_tt_global_orig_entry_find(const struct batadv_tt_global_entry
*entry
,
1453 const struct batadv_orig_node
*orig_node
)
1455 struct batadv_tt_orig_list_entry
*tmp_orig_entry
, *orig_entry
= NULL
;
1456 const struct hlist_head
*head
;
1459 head
= &entry
->orig_list
;
1460 hlist_for_each_entry_rcu(tmp_orig_entry
, head
, list
) {
1461 if (tmp_orig_entry
->orig_node
!= orig_node
)
1463 if (!kref_get_unless_zero(&tmp_orig_entry
->refcount
))
1466 orig_entry
= tmp_orig_entry
;
1475 * batadv_tt_global_entry_has_orig() - check if a TT global entry is also
1476 * handled by a given originator
1477 * @entry: the TT global entry to check
1478 * @orig_node: the originator to search in the list
1479 * @flags: a pointer to store TT flags for the given @entry received
1482 * find out if an orig_node is already in the list of a tt_global_entry.
1484 * Return: true if found, false otherwise
1487 batadv_tt_global_entry_has_orig(const struct batadv_tt_global_entry
*entry
,
1488 const struct batadv_orig_node
*orig_node
,
1491 struct batadv_tt_orig_list_entry
*orig_entry
;
1494 orig_entry
= batadv_tt_global_orig_entry_find(entry
, orig_node
);
1499 *flags
= orig_entry
->flags
;
1501 batadv_tt_orig_list_entry_put(orig_entry
);
1508 * batadv_tt_global_sync_flags() - update TT sync flags
1509 * @tt_global: the TT global entry to update sync flags in
1511 * Updates the sync flag bits in the tt_global flag attribute with a logical
1512 * OR of all sync flags from any of its TT orig entries.
1515 batadv_tt_global_sync_flags(struct batadv_tt_global_entry
*tt_global
)
1517 struct batadv_tt_orig_list_entry
*orig_entry
;
1518 const struct hlist_head
*head
;
1519 u16 flags
= BATADV_NO_FLAGS
;
1522 head
= &tt_global
->orig_list
;
1523 hlist_for_each_entry_rcu(orig_entry
, head
, list
)
1524 flags
|= orig_entry
->flags
;
1527 flags
|= tt_global
->common
.flags
& (~BATADV_TT_SYNC_MASK
);
1528 tt_global
->common
.flags
= flags
;
1532 * batadv_tt_global_orig_entry_add() - add or update a TT orig entry
1533 * @tt_global: the TT global entry to add an orig entry in
1534 * @orig_node: the originator to add an orig entry for
1535 * @ttvn: translation table version number of this changeset
1536 * @flags: TT sync flags
1539 batadv_tt_global_orig_entry_add(struct batadv_tt_global_entry
*tt_global
,
1540 struct batadv_orig_node
*orig_node
, int ttvn
,
1543 struct batadv_tt_orig_list_entry
*orig_entry
;
1545 spin_lock_bh(&tt_global
->list_lock
);
1547 orig_entry
= batadv_tt_global_orig_entry_find(tt_global
, orig_node
);
1549 /* refresh the ttvn: the current value could be a bogus one that
1550 * was added during a "temporary client detection"
1552 orig_entry
->ttvn
= ttvn
;
1553 orig_entry
->flags
= flags
;
1557 orig_entry
= kmem_cache_zalloc(batadv_tt_orig_cache
, GFP_ATOMIC
);
1561 INIT_HLIST_NODE(&orig_entry
->list
);
1562 kref_get(&orig_node
->refcount
);
1563 batadv_tt_global_size_inc(orig_node
, tt_global
->common
.vid
);
1564 orig_entry
->orig_node
= orig_node
;
1565 orig_entry
->ttvn
= ttvn
;
1566 orig_entry
->flags
= flags
;
1567 kref_init(&orig_entry
->refcount
);
1569 kref_get(&orig_entry
->refcount
);
1570 hlist_add_head_rcu(&orig_entry
->list
,
1571 &tt_global
->orig_list
);
1572 atomic_inc(&tt_global
->orig_list_count
);
1575 batadv_tt_global_sync_flags(tt_global
);
1578 batadv_tt_orig_list_entry_put(orig_entry
);
1580 spin_unlock_bh(&tt_global
->list_lock
);
1584 * batadv_tt_global_add() - add a new TT global entry or update an existing one
1585 * @bat_priv: the bat priv with all the soft interface information
1586 * @orig_node: the originator announcing the client
1587 * @tt_addr: the mac address of the non-mesh client
1588 * @vid: VLAN identifier
1589 * @flags: TT flags that have to be set for this non-mesh client
1590 * @ttvn: the tt version number ever announcing this non-mesh client
1592 * Add a new TT global entry for the given originator. If the entry already
1593 * exists add a new reference to the given originator (a global entry can have
1594 * references to multiple originators) and adjust the flags attribute to reflect
1595 * the function argument.
1596 * If a TT local entry exists for this non-mesh client remove it.
1598 * The caller must hold the orig_node refcount.
1600 * Return: true if the new entry has been added, false otherwise
1602 static bool batadv_tt_global_add(struct batadv_priv
*bat_priv
,
1603 struct batadv_orig_node
*orig_node
,
1604 const unsigned char *tt_addr
,
1605 unsigned short vid
, u16 flags
, u8 ttvn
)
1607 struct batadv_tt_global_entry
*tt_global_entry
;
1608 struct batadv_tt_local_entry
*tt_local_entry
;
1611 struct batadv_tt_common_entry
*common
;
1614 /* ignore global entries from backbone nodes */
1615 if (batadv_bla_is_backbone_gw_orig(bat_priv
, orig_node
->orig
, vid
))
1618 tt_global_entry
= batadv_tt_global_hash_find(bat_priv
, tt_addr
, vid
);
1619 tt_local_entry
= batadv_tt_local_hash_find(bat_priv
, tt_addr
, vid
);
1621 /* if the node already has a local client for this entry, it has to wait
1622 * for a roaming advertisement instead of manually messing up the global
1625 if ((flags
& BATADV_TT_CLIENT_TEMP
) && tt_local_entry
&&
1626 !(tt_local_entry
->common
.flags
& BATADV_TT_CLIENT_NEW
))
1629 if (!tt_global_entry
) {
1630 tt_global_entry
= kmem_cache_zalloc(batadv_tg_cache
,
1632 if (!tt_global_entry
)
1635 common
= &tt_global_entry
->common
;
1636 ether_addr_copy(common
->addr
, tt_addr
);
1639 if (!is_multicast_ether_addr(common
->addr
))
1640 common
->flags
= flags
& (~BATADV_TT_SYNC_MASK
);
1642 tt_global_entry
->roam_at
= 0;
1643 /* node must store current time in case of roaming. This is
1644 * needed to purge this entry out on timeout (if nobody claims
1647 if (flags
& BATADV_TT_CLIENT_ROAM
)
1648 tt_global_entry
->roam_at
= jiffies
;
1649 kref_init(&common
->refcount
);
1650 common
->added_at
= jiffies
;
1652 INIT_HLIST_HEAD(&tt_global_entry
->orig_list
);
1653 atomic_set(&tt_global_entry
->orig_list_count
, 0);
1654 spin_lock_init(&tt_global_entry
->list_lock
);
1656 kref_get(&common
->refcount
);
1657 hash_added
= batadv_hash_add(bat_priv
->tt
.global_hash
,
1659 batadv_choose_tt
, common
,
1660 &common
->hash_entry
);
1662 if (unlikely(hash_added
!= 0)) {
1663 /* remove the reference for the hash */
1664 batadv_tt_global_entry_put(tt_global_entry
);
1668 common
= &tt_global_entry
->common
;
1669 /* If there is already a global entry, we can use this one for
1671 * But if we are trying to add a temporary client then here are
1672 * two options at this point:
1673 * 1) the global client is not a temporary client: the global
1674 * client has to be left as it is, temporary information
1675 * should never override any already known client state
1676 * 2) the global client is a temporary client: purge the
1677 * originator list and add the new one orig_entry
1679 if (flags
& BATADV_TT_CLIENT_TEMP
) {
1680 if (!(common
->flags
& BATADV_TT_CLIENT_TEMP
))
1682 if (batadv_tt_global_entry_has_orig(tt_global_entry
,
1685 batadv_tt_global_del_orig_list(tt_global_entry
);
1686 goto add_orig_entry
;
1689 /* if the client was temporary added before receiving the first
1690 * OGM announcing it, we have to clear the TEMP flag. Also,
1691 * remove the previous temporary orig node and re-add it
1692 * if required. If the orig entry changed, the new one which
1693 * is a non-temporary entry is preferred.
1695 if (common
->flags
& BATADV_TT_CLIENT_TEMP
) {
1696 batadv_tt_global_del_orig_list(tt_global_entry
);
1697 common
->flags
&= ~BATADV_TT_CLIENT_TEMP
;
1700 /* the change can carry possible "attribute" flags like the
1701 * TT_CLIENT_TEMP, therefore they have to be copied in the
1704 if (!is_multicast_ether_addr(common
->addr
))
1705 common
->flags
|= flags
& (~BATADV_TT_SYNC_MASK
);
1707 /* If there is the BATADV_TT_CLIENT_ROAM flag set, there is only
1708 * one originator left in the list and we previously received a
1709 * delete + roaming change for this originator.
1711 * We should first delete the old originator before adding the
1714 if (common
->flags
& BATADV_TT_CLIENT_ROAM
) {
1715 batadv_tt_global_del_orig_list(tt_global_entry
);
1716 common
->flags
&= ~BATADV_TT_CLIENT_ROAM
;
1717 tt_global_entry
->roam_at
= 0;
1721 /* add the new orig_entry (if needed) or update it */
1722 batadv_tt_global_orig_entry_add(tt_global_entry
, orig_node
, ttvn
,
1723 flags
& BATADV_TT_SYNC_MASK
);
1725 batadv_dbg(BATADV_DBG_TT
, bat_priv
,
1726 "Creating new global tt entry: %pM (vid: %d, via %pM)\n",
1727 common
->addr
, batadv_print_vid(common
->vid
),
1732 /* Do not remove multicast addresses from the local hash on
1735 if (is_multicast_ether_addr(tt_addr
))
1738 /* remove address from local hash if present */
1739 local_flags
= batadv_tt_local_remove(bat_priv
, tt_addr
, vid
,
1740 "global tt received",
1741 flags
& BATADV_TT_CLIENT_ROAM
);
1742 tt_global_entry
->common
.flags
|= local_flags
& BATADV_TT_CLIENT_WIFI
;
1744 if (!(flags
& BATADV_TT_CLIENT_ROAM
))
1745 /* this is a normal global add. Therefore the client is not in a
1746 * roaming state anymore.
1748 tt_global_entry
->common
.flags
&= ~BATADV_TT_CLIENT_ROAM
;
1751 if (tt_global_entry
)
1752 batadv_tt_global_entry_put(tt_global_entry
);
1754 batadv_tt_local_entry_put(tt_local_entry
);
1759 * batadv_transtable_best_orig() - Get best originator list entry from tt entry
1760 * @bat_priv: the bat priv with all the soft interface information
1761 * @tt_global_entry: global translation table entry to be analyzed
1763 * This function assumes the caller holds rcu_read_lock().
1764 * Return: best originator list entry or NULL on errors.
1766 static struct batadv_tt_orig_list_entry
*
1767 batadv_transtable_best_orig(struct batadv_priv
*bat_priv
,
1768 struct batadv_tt_global_entry
*tt_global_entry
)
1770 struct batadv_neigh_node
*router
, *best_router
= NULL
;
1771 struct batadv_algo_ops
*bao
= bat_priv
->algo_ops
;
1772 struct hlist_head
*head
;
1773 struct batadv_tt_orig_list_entry
*orig_entry
, *best_entry
= NULL
;
1775 head
= &tt_global_entry
->orig_list
;
1776 hlist_for_each_entry_rcu(orig_entry
, head
, list
) {
1777 router
= batadv_orig_router_get(orig_entry
->orig_node
,
1783 bao
->neigh
.cmp(router
, BATADV_IF_DEFAULT
, best_router
,
1784 BATADV_IF_DEFAULT
) <= 0) {
1785 batadv_neigh_node_put(router
);
1789 /* release the refcount for the "old" best */
1791 batadv_neigh_node_put(best_router
);
1793 best_entry
= orig_entry
;
1794 best_router
= router
;
1798 batadv_neigh_node_put(best_router
);
1804 * batadv_tt_global_dump_subentry() - Dump all TT local entries into a message
1805 * @msg: Netlink message to dump into
1806 * @portid: Port making netlink request
1807 * @seq: Sequence number of netlink message
1808 * @common: tt local & tt global common data
1809 * @orig: Originator node announcing a non-mesh client
1810 * @best: Is the best originator for the TT entry
1812 * Return: Error code, or 0 on success
1815 batadv_tt_global_dump_subentry(struct sk_buff
*msg
, u32 portid
, u32 seq
,
1816 struct batadv_tt_common_entry
*common
,
1817 struct batadv_tt_orig_list_entry
*orig
,
1820 u16 flags
= (common
->flags
& (~BATADV_TT_SYNC_MASK
)) | orig
->flags
;
1822 struct batadv_orig_node_vlan
*vlan
;
1826 vlan
= batadv_orig_node_vlan_get(orig
->orig_node
,
1833 batadv_orig_node_vlan_put(vlan
);
1835 hdr
= genlmsg_put(msg
, portid
, seq
, &batadv_netlink_family
,
1837 BATADV_CMD_GET_TRANSTABLE_GLOBAL
);
1841 last_ttvn
= atomic_read(&orig
->orig_node
->last_ttvn
);
1843 if (nla_put(msg
, BATADV_ATTR_TT_ADDRESS
, ETH_ALEN
, common
->addr
) ||
1844 nla_put(msg
, BATADV_ATTR_ORIG_ADDRESS
, ETH_ALEN
,
1845 orig
->orig_node
->orig
) ||
1846 nla_put_u8(msg
, BATADV_ATTR_TT_TTVN
, orig
->ttvn
) ||
1847 nla_put_u8(msg
, BATADV_ATTR_TT_LAST_TTVN
, last_ttvn
) ||
1848 nla_put_u32(msg
, BATADV_ATTR_TT_CRC32
, crc
) ||
1849 nla_put_u16(msg
, BATADV_ATTR_TT_VID
, common
->vid
) ||
1850 nla_put_u32(msg
, BATADV_ATTR_TT_FLAGS
, flags
))
1851 goto nla_put_failure
;
1853 if (best
&& nla_put_flag(msg
, BATADV_ATTR_FLAG_BEST
))
1854 goto nla_put_failure
;
1856 genlmsg_end(msg
, hdr
);
1860 genlmsg_cancel(msg
, hdr
);
1865 * batadv_tt_global_dump_entry() - Dump one TT global entry into a message
1866 * @msg: Netlink message to dump into
1867 * @portid: Port making netlink request
1868 * @seq: Sequence number of netlink message
1869 * @bat_priv: The bat priv with all the soft interface information
1870 * @common: tt local & tt global common data
1871 * @sub_s: Number of entries to skip
1873 * This function assumes the caller holds rcu_read_lock().
1875 * Return: Error code, or 0 on success
1878 batadv_tt_global_dump_entry(struct sk_buff
*msg
, u32 portid
, u32 seq
,
1879 struct batadv_priv
*bat_priv
,
1880 struct batadv_tt_common_entry
*common
, int *sub_s
)
1882 struct batadv_tt_orig_list_entry
*orig_entry
, *best_entry
;
1883 struct batadv_tt_global_entry
*global
;
1884 struct hlist_head
*head
;
1888 global
= container_of(common
, struct batadv_tt_global_entry
, common
);
1889 best_entry
= batadv_transtable_best_orig(bat_priv
, global
);
1890 head
= &global
->orig_list
;
1892 hlist_for_each_entry_rcu(orig_entry
, head
, list
) {
1896 best
= (orig_entry
== best_entry
);
1898 if (batadv_tt_global_dump_subentry(msg
, portid
, seq
, common
,
1899 orig_entry
, best
)) {
1910 * batadv_tt_global_dump_bucket() - Dump one TT local bucket into a message
1911 * @msg: Netlink message to dump into
1912 * @portid: Port making netlink request
1913 * @seq: Sequence number of netlink message
1914 * @bat_priv: The bat priv with all the soft interface information
1915 * @head: Pointer to the list containing the global tt entries
1916 * @idx_s: Number of entries to skip
1917 * @sub: Number of entries to skip
1919 * Return: Error code, or 0 on success
1922 batadv_tt_global_dump_bucket(struct sk_buff
*msg
, u32 portid
, u32 seq
,
1923 struct batadv_priv
*bat_priv
,
1924 struct hlist_head
*head
, int *idx_s
, int *sub
)
1926 struct batadv_tt_common_entry
*common
;
1930 hlist_for_each_entry_rcu(common
, head
, hash_entry
) {
1934 if (batadv_tt_global_dump_entry(msg
, portid
, seq
, bat_priv
,
1949 * batadv_tt_global_dump() - Dump TT global entries into a message
1950 * @msg: Netlink message to dump into
1951 * @cb: Parameters from query
1953 * Return: Error code, or length of message on success
1955 int batadv_tt_global_dump(struct sk_buff
*msg
, struct netlink_callback
*cb
)
1957 struct net
*net
= sock_net(cb
->skb
->sk
);
1958 struct net_device
*soft_iface
;
1959 struct batadv_priv
*bat_priv
;
1960 struct batadv_hard_iface
*primary_if
= NULL
;
1961 struct batadv_hashtable
*hash
;
1962 struct hlist_head
*head
;
1965 int bucket
= cb
->args
[0];
1966 int idx
= cb
->args
[1];
1967 int sub
= cb
->args
[2];
1968 int portid
= NETLINK_CB(cb
->skb
).portid
;
1970 ifindex
= batadv_netlink_get_ifindex(cb
->nlh
, BATADV_ATTR_MESH_IFINDEX
);
1974 soft_iface
= dev_get_by_index(net
, ifindex
);
1975 if (!soft_iface
|| !batadv_softif_is_valid(soft_iface
)) {
1980 bat_priv
= netdev_priv(soft_iface
);
1982 primary_if
= batadv_primary_if_get_selected(bat_priv
);
1983 if (!primary_if
|| primary_if
->if_status
!= BATADV_IF_ACTIVE
) {
1988 hash
= bat_priv
->tt
.global_hash
;
1990 while (bucket
< hash
->size
) {
1991 head
= &hash
->table
[bucket
];
1993 if (batadv_tt_global_dump_bucket(msg
, portid
,
1994 cb
->nlh
->nlmsg_seq
, bat_priv
,
2005 batadv_hardif_put(primary_if
);
2007 dev_put(soft_iface
);
2009 cb
->args
[0] = bucket
;
2017 * _batadv_tt_global_del_orig_entry() - remove and free an orig_entry
2018 * @tt_global_entry: the global entry to remove the orig_entry from
2019 * @orig_entry: the orig entry to remove and free
2021 * Remove an orig_entry from its list in the given tt_global_entry and
2022 * free this orig_entry afterwards.
2024 * Caller must hold tt_global_entry->list_lock and ensure orig_entry->list is
2028 _batadv_tt_global_del_orig_entry(struct batadv_tt_global_entry
*tt_global_entry
,
2029 struct batadv_tt_orig_list_entry
*orig_entry
)
2031 lockdep_assert_held(&tt_global_entry
->list_lock
);
2033 batadv_tt_global_size_dec(orig_entry
->orig_node
,
2034 tt_global_entry
->common
.vid
);
2035 atomic_dec(&tt_global_entry
->orig_list_count
);
2036 /* requires holding tt_global_entry->list_lock and orig_entry->list
2037 * being part of a list
2039 hlist_del_rcu(&orig_entry
->list
);
2040 batadv_tt_orig_list_entry_put(orig_entry
);
2043 /* deletes the orig list of a tt_global_entry */
2045 batadv_tt_global_del_orig_list(struct batadv_tt_global_entry
*tt_global_entry
)
2047 struct hlist_head
*head
;
2048 struct hlist_node
*safe
;
2049 struct batadv_tt_orig_list_entry
*orig_entry
;
2051 spin_lock_bh(&tt_global_entry
->list_lock
);
2052 head
= &tt_global_entry
->orig_list
;
2053 hlist_for_each_entry_safe(orig_entry
, safe
, head
, list
)
2054 _batadv_tt_global_del_orig_entry(tt_global_entry
, orig_entry
);
2055 spin_unlock_bh(&tt_global_entry
->list_lock
);
2059 * batadv_tt_global_del_orig_node() - remove orig_node from a global tt entry
2060 * @bat_priv: the bat priv with all the soft interface information
2061 * @tt_global_entry: the global entry to remove the orig_node from
2062 * @orig_node: the originator announcing the client
2063 * @message: message to append to the log on deletion
2065 * Remove the given orig_node and its according orig_entry from the given
2069 batadv_tt_global_del_orig_node(struct batadv_priv
*bat_priv
,
2070 struct batadv_tt_global_entry
*tt_global_entry
,
2071 struct batadv_orig_node
*orig_node
,
2072 const char *message
)
2074 struct hlist_head
*head
;
2075 struct hlist_node
*safe
;
2076 struct batadv_tt_orig_list_entry
*orig_entry
;
2079 spin_lock_bh(&tt_global_entry
->list_lock
);
2080 head
= &tt_global_entry
->orig_list
;
2081 hlist_for_each_entry_safe(orig_entry
, safe
, head
, list
) {
2082 if (orig_entry
->orig_node
== orig_node
) {
2083 vid
= tt_global_entry
->common
.vid
;
2084 batadv_dbg(BATADV_DBG_TT
, bat_priv
,
2085 "Deleting %pM from global tt entry %pM (vid: %d): %s\n",
2087 tt_global_entry
->common
.addr
,
2088 batadv_print_vid(vid
), message
);
2089 _batadv_tt_global_del_orig_entry(tt_global_entry
,
2093 spin_unlock_bh(&tt_global_entry
->list_lock
);
2096 /* If the client is to be deleted, we check if it is the last origantor entry
2097 * within tt_global entry. If yes, we set the BATADV_TT_CLIENT_ROAM flag and the
2098 * timer, otherwise we simply remove the originator scheduled for deletion.
2101 batadv_tt_global_del_roaming(struct batadv_priv
*bat_priv
,
2102 struct batadv_tt_global_entry
*tt_global_entry
,
2103 struct batadv_orig_node
*orig_node
,
2104 const char *message
)
2106 bool last_entry
= true;
2107 struct hlist_head
*head
;
2108 struct batadv_tt_orig_list_entry
*orig_entry
;
2110 /* no local entry exists, case 1:
2111 * Check if this is the last one or if other entries exist.
2115 head
= &tt_global_entry
->orig_list
;
2116 hlist_for_each_entry_rcu(orig_entry
, head
, list
) {
2117 if (orig_entry
->orig_node
!= orig_node
) {
2125 /* its the last one, mark for roaming. */
2126 tt_global_entry
->common
.flags
|= BATADV_TT_CLIENT_ROAM
;
2127 tt_global_entry
->roam_at
= jiffies
;
2129 /* there is another entry, we can simply delete this
2130 * one and can still use the other one.
2132 batadv_tt_global_del_orig_node(bat_priv
, tt_global_entry
,
2133 orig_node
, message
);
2138 * batadv_tt_global_del() - remove a client from the global table
2139 * @bat_priv: the bat priv with all the soft interface information
2140 * @orig_node: an originator serving this client
2141 * @addr: the mac address of the client
2142 * @vid: VLAN identifier
2143 * @message: a message explaining the reason for deleting the client to print
2144 * for debugging purpose
2145 * @roaming: true if the deletion has been triggered by a roaming event
2147 static void batadv_tt_global_del(struct batadv_priv
*bat_priv
,
2148 struct batadv_orig_node
*orig_node
,
2149 const unsigned char *addr
, unsigned short vid
,
2150 const char *message
, bool roaming
)
2152 struct batadv_tt_global_entry
*tt_global_entry
;
2153 struct batadv_tt_local_entry
*local_entry
= NULL
;
2155 tt_global_entry
= batadv_tt_global_hash_find(bat_priv
, addr
, vid
);
2156 if (!tt_global_entry
)
2160 batadv_tt_global_del_orig_node(bat_priv
, tt_global_entry
,
2161 orig_node
, message
);
2163 if (hlist_empty(&tt_global_entry
->orig_list
))
2164 batadv_tt_global_free(bat_priv
, tt_global_entry
,
2170 /* if we are deleting a global entry due to a roam
2171 * event, there are two possibilities:
2172 * 1) the client roamed from node A to node B => if there
2173 * is only one originator left for this client, we mark
2174 * it with BATADV_TT_CLIENT_ROAM, we start a timer and we
2175 * wait for node B to claim it. In case of timeout
2176 * the entry is purged.
2178 * If there are other originators left, we directly delete
2180 * 2) the client roamed to us => we can directly delete
2181 * the global entry, since it is useless now.
2183 local_entry
= batadv_tt_local_hash_find(bat_priv
,
2184 tt_global_entry
->common
.addr
,
2187 /* local entry exists, case 2: client roamed to us. */
2188 batadv_tt_global_del_orig_list(tt_global_entry
);
2189 batadv_tt_global_free(bat_priv
, tt_global_entry
, message
);
2191 /* no local entry exists, case 1: check for roaming */
2192 batadv_tt_global_del_roaming(bat_priv
, tt_global_entry
,
2193 orig_node
, message
);
2197 if (tt_global_entry
)
2198 batadv_tt_global_entry_put(tt_global_entry
);
2200 batadv_tt_local_entry_put(local_entry
);
2204 * batadv_tt_global_del_orig() - remove all the TT global entries belonging to
2205 * the given originator matching the provided vid
2206 * @bat_priv: the bat priv with all the soft interface information
2207 * @orig_node: the originator owning the entries to remove
2208 * @match_vid: the VLAN identifier to match. If negative all the entries will be
2210 * @message: debug message to print as "reason"
2212 void batadv_tt_global_del_orig(struct batadv_priv
*bat_priv
,
2213 struct batadv_orig_node
*orig_node
,
2215 const char *message
)
2217 struct batadv_tt_global_entry
*tt_global
;
2218 struct batadv_tt_common_entry
*tt_common_entry
;
2220 struct batadv_hashtable
*hash
= bat_priv
->tt
.global_hash
;
2221 struct hlist_node
*safe
;
2222 struct hlist_head
*head
;
2223 spinlock_t
*list_lock
; /* protects write access to the hash lists */
2229 for (i
= 0; i
< hash
->size
; i
++) {
2230 head
= &hash
->table
[i
];
2231 list_lock
= &hash
->list_locks
[i
];
2233 spin_lock_bh(list_lock
);
2234 hlist_for_each_entry_safe(tt_common_entry
, safe
,
2236 /* remove only matching entries */
2237 if (match_vid
>= 0 && tt_common_entry
->vid
!= match_vid
)
2240 tt_global
= container_of(tt_common_entry
,
2241 struct batadv_tt_global_entry
,
2244 batadv_tt_global_del_orig_node(bat_priv
, tt_global
,
2245 orig_node
, message
);
2247 if (hlist_empty(&tt_global
->orig_list
)) {
2248 vid
= tt_global
->common
.vid
;
2249 batadv_dbg(BATADV_DBG_TT
, bat_priv
,
2250 "Deleting global tt entry %pM (vid: %d): %s\n",
2251 tt_global
->common
.addr
,
2252 batadv_print_vid(vid
), message
);
2253 hlist_del_rcu(&tt_common_entry
->hash_entry
);
2254 batadv_tt_global_entry_put(tt_global
);
2257 spin_unlock_bh(list_lock
);
2259 clear_bit(BATADV_ORIG_CAPA_HAS_TT
, &orig_node
->capa_initialized
);
2262 static bool batadv_tt_global_to_purge(struct batadv_tt_global_entry
*tt_global
,
2266 unsigned long roam_timeout
= BATADV_TT_CLIENT_ROAM_TIMEOUT
;
2267 unsigned long temp_timeout
= BATADV_TT_CLIENT_TEMP_TIMEOUT
;
2269 if ((tt_global
->common
.flags
& BATADV_TT_CLIENT_ROAM
) &&
2270 batadv_has_timed_out(tt_global
->roam_at
, roam_timeout
)) {
2272 *msg
= "Roaming timeout\n";
2275 if ((tt_global
->common
.flags
& BATADV_TT_CLIENT_TEMP
) &&
2276 batadv_has_timed_out(tt_global
->common
.added_at
, temp_timeout
)) {
2278 *msg
= "Temporary client timeout\n";
2284 static void batadv_tt_global_purge(struct batadv_priv
*bat_priv
)
2286 struct batadv_hashtable
*hash
= bat_priv
->tt
.global_hash
;
2287 struct hlist_head
*head
;
2288 struct hlist_node
*node_tmp
;
2289 spinlock_t
*list_lock
; /* protects write access to the hash lists */
2292 struct batadv_tt_common_entry
*tt_common
;
2293 struct batadv_tt_global_entry
*tt_global
;
2295 for (i
= 0; i
< hash
->size
; i
++) {
2296 head
= &hash
->table
[i
];
2297 list_lock
= &hash
->list_locks
[i
];
2299 spin_lock_bh(list_lock
);
2300 hlist_for_each_entry_safe(tt_common
, node_tmp
, head
,
2302 tt_global
= container_of(tt_common
,
2303 struct batadv_tt_global_entry
,
2306 if (!batadv_tt_global_to_purge(tt_global
, &msg
))
2309 batadv_dbg(BATADV_DBG_TT
, bat_priv
,
2310 "Deleting global tt entry %pM (vid: %d): %s\n",
2311 tt_global
->common
.addr
,
2312 batadv_print_vid(tt_global
->common
.vid
),
2315 hlist_del_rcu(&tt_common
->hash_entry
);
2317 batadv_tt_global_entry_put(tt_global
);
2319 spin_unlock_bh(list_lock
);
2323 static void batadv_tt_global_table_free(struct batadv_priv
*bat_priv
)
2325 struct batadv_hashtable
*hash
;
2326 spinlock_t
*list_lock
; /* protects write access to the hash lists */
2327 struct batadv_tt_common_entry
*tt_common_entry
;
2328 struct batadv_tt_global_entry
*tt_global
;
2329 struct hlist_node
*node_tmp
;
2330 struct hlist_head
*head
;
2333 if (!bat_priv
->tt
.global_hash
)
2336 hash
= bat_priv
->tt
.global_hash
;
2338 for (i
= 0; i
< hash
->size
; i
++) {
2339 head
= &hash
->table
[i
];
2340 list_lock
= &hash
->list_locks
[i
];
2342 spin_lock_bh(list_lock
);
2343 hlist_for_each_entry_safe(tt_common_entry
, node_tmp
,
2345 hlist_del_rcu(&tt_common_entry
->hash_entry
);
2346 tt_global
= container_of(tt_common_entry
,
2347 struct batadv_tt_global_entry
,
2349 batadv_tt_global_entry_put(tt_global
);
2351 spin_unlock_bh(list_lock
);
2354 batadv_hash_destroy(hash
);
2356 bat_priv
->tt
.global_hash
= NULL
;
2360 _batadv_is_ap_isolated(struct batadv_tt_local_entry
*tt_local_entry
,
2361 struct batadv_tt_global_entry
*tt_global_entry
)
2363 if (tt_local_entry
->common
.flags
& BATADV_TT_CLIENT_WIFI
&&
2364 tt_global_entry
->common
.flags
& BATADV_TT_CLIENT_WIFI
)
2367 /* check if the two clients are marked as isolated */
2368 if (tt_local_entry
->common
.flags
& BATADV_TT_CLIENT_ISOLA
&&
2369 tt_global_entry
->common
.flags
& BATADV_TT_CLIENT_ISOLA
)
2376 * batadv_transtable_search() - get the mesh destination for a given client
2377 * @bat_priv: the bat priv with all the soft interface information
2378 * @src: mac address of the source client
2379 * @addr: mac address of the destination client
2380 * @vid: VLAN identifier
2382 * Return: a pointer to the originator that was selected as destination in the
2383 * mesh for contacting the client 'addr', NULL otherwise.
2384 * In case of multiple originators serving the same client, the function returns
2385 * the best one (best in terms of metric towards the destination node).
2387 * If the two clients are AP isolated the function returns NULL.
2389 struct batadv_orig_node
*batadv_transtable_search(struct batadv_priv
*bat_priv
,
2394 struct batadv_tt_local_entry
*tt_local_entry
= NULL
;
2395 struct batadv_tt_global_entry
*tt_global_entry
= NULL
;
2396 struct batadv_orig_node
*orig_node
= NULL
;
2397 struct batadv_tt_orig_list_entry
*best_entry
;
2399 if (src
&& batadv_vlan_ap_isola_get(bat_priv
, vid
)) {
2400 tt_local_entry
= batadv_tt_local_hash_find(bat_priv
, src
, vid
);
2401 if (!tt_local_entry
||
2402 (tt_local_entry
->common
.flags
& BATADV_TT_CLIENT_PENDING
))
2406 tt_global_entry
= batadv_tt_global_hash_find(bat_priv
, addr
, vid
);
2407 if (!tt_global_entry
)
2410 /* check whether the clients should not communicate due to AP
2413 if (tt_local_entry
&&
2414 _batadv_is_ap_isolated(tt_local_entry
, tt_global_entry
))
2418 best_entry
= batadv_transtable_best_orig(bat_priv
, tt_global_entry
);
2419 /* found anything? */
2421 orig_node
= best_entry
->orig_node
;
2422 if (orig_node
&& !kref_get_unless_zero(&orig_node
->refcount
))
2427 if (tt_global_entry
)
2428 batadv_tt_global_entry_put(tt_global_entry
);
2430 batadv_tt_local_entry_put(tt_local_entry
);
2436 * batadv_tt_global_crc() - calculates the checksum of the local table belonging
2437 * to the given orig_node
2438 * @bat_priv: the bat priv with all the soft interface information
2439 * @orig_node: originator for which the CRC should be computed
2440 * @vid: VLAN identifier for which the CRC32 has to be computed
2442 * This function computes the checksum for the global table corresponding to a
2443 * specific originator. In particular, the checksum is computed as follows: For
2444 * each client connected to the originator the CRC32C of the MAC address and the
2445 * VID is computed and then all the CRC32Cs of the various clients are xor'ed
2448 * The idea behind is that CRC32C should be used as much as possible in order to
2449 * produce a unique hash of the table, but since the order which is used to feed
2450 * the CRC32C function affects the result and since every node in the network
2451 * probably sorts the clients differently, the hash function cannot be directly
2452 * computed over the entire table. Hence the CRC32C is used only on
2453 * the single client entry, while all the results are then xor'ed together
2454 * because the XOR operation can combine them all while trying to reduce the
2455 * noise as much as possible.
2457 * Return: the checksum of the global table of a given originator.
2459 static u32
batadv_tt_global_crc(struct batadv_priv
*bat_priv
,
2460 struct batadv_orig_node
*orig_node
,
2463 struct batadv_hashtable
*hash
= bat_priv
->tt
.global_hash
;
2464 struct batadv_tt_orig_list_entry
*tt_orig
;
2465 struct batadv_tt_common_entry
*tt_common
;
2466 struct batadv_tt_global_entry
*tt_global
;
2467 struct hlist_head
*head
;
2468 u32 i
, crc_tmp
, crc
= 0;
2472 for (i
= 0; i
< hash
->size
; i
++) {
2473 head
= &hash
->table
[i
];
2476 hlist_for_each_entry_rcu(tt_common
, head
, hash_entry
) {
2477 tt_global
= container_of(tt_common
,
2478 struct batadv_tt_global_entry
,
2480 /* compute the CRC only for entries belonging to the
2481 * VLAN identified by the vid passed as parameter
2483 if (tt_common
->vid
!= vid
)
2486 /* Roaming clients are in the global table for
2487 * consistency only. They don't have to be
2488 * taken into account while computing the
2491 if (tt_common
->flags
& BATADV_TT_CLIENT_ROAM
)
2493 /* Temporary clients have not been announced yet, so
2494 * they have to be skipped while computing the global
2497 if (tt_common
->flags
& BATADV_TT_CLIENT_TEMP
)
2500 /* find out if this global entry is announced by this
2503 tt_orig
= batadv_tt_global_orig_entry_find(tt_global
,
2508 /* use network order to read the VID: this ensures that
2509 * every node reads the bytes in the same order.
2511 tmp_vid
= htons(tt_common
->vid
);
2512 crc_tmp
= crc32c(0, &tmp_vid
, sizeof(tmp_vid
));
2514 /* compute the CRC on flags that have to be kept in sync
2517 flags
= tt_orig
->flags
;
2518 crc_tmp
= crc32c(crc_tmp
, &flags
, sizeof(flags
));
2520 crc
^= crc32c(crc_tmp
, tt_common
->addr
, ETH_ALEN
);
2522 batadv_tt_orig_list_entry_put(tt_orig
);
2531 * batadv_tt_local_crc() - calculates the checksum of the local table
2532 * @bat_priv: the bat priv with all the soft interface information
2533 * @vid: VLAN identifier for which the CRC32 has to be computed
2535 * For details about the computation, please refer to the documentation for
2536 * batadv_tt_global_crc().
2538 * Return: the checksum of the local table
2540 static u32
batadv_tt_local_crc(struct batadv_priv
*bat_priv
,
2543 struct batadv_hashtable
*hash
= bat_priv
->tt
.local_hash
;
2544 struct batadv_tt_common_entry
*tt_common
;
2545 struct hlist_head
*head
;
2546 u32 i
, crc_tmp
, crc
= 0;
2550 for (i
= 0; i
< hash
->size
; i
++) {
2551 head
= &hash
->table
[i
];
2554 hlist_for_each_entry_rcu(tt_common
, head
, hash_entry
) {
2555 /* compute the CRC only for entries belonging to the
2556 * VLAN identified by vid
2558 if (tt_common
->vid
!= vid
)
2561 /* not yet committed clients have not to be taken into
2562 * account while computing the CRC
2564 if (tt_common
->flags
& BATADV_TT_CLIENT_NEW
)
2567 /* use network order to read the VID: this ensures that
2568 * every node reads the bytes in the same order.
2570 tmp_vid
= htons(tt_common
->vid
);
2571 crc_tmp
= crc32c(0, &tmp_vid
, sizeof(tmp_vid
));
2573 /* compute the CRC on flags that have to be kept in sync
2576 flags
= tt_common
->flags
& BATADV_TT_SYNC_MASK
;
2577 crc_tmp
= crc32c(crc_tmp
, &flags
, sizeof(flags
));
2579 crc
^= crc32c(crc_tmp
, tt_common
->addr
, ETH_ALEN
);
2588 * batadv_tt_req_node_release() - free tt_req node entry
2589 * @ref: kref pointer of the tt req_node entry
2591 static void batadv_tt_req_node_release(struct kref
*ref
)
2593 struct batadv_tt_req_node
*tt_req_node
;
2595 tt_req_node
= container_of(ref
, struct batadv_tt_req_node
, refcount
);
2597 kmem_cache_free(batadv_tt_req_cache
, tt_req_node
);
2601 * batadv_tt_req_node_put() - decrement the tt_req_node refcounter and
2602 * possibly release it
2603 * @tt_req_node: tt_req_node to be free'd
2605 static void batadv_tt_req_node_put(struct batadv_tt_req_node
*tt_req_node
)
2607 kref_put(&tt_req_node
->refcount
, batadv_tt_req_node_release
);
2610 static void batadv_tt_req_list_free(struct batadv_priv
*bat_priv
)
2612 struct batadv_tt_req_node
*node
;
2613 struct hlist_node
*safe
;
2615 spin_lock_bh(&bat_priv
->tt
.req_list_lock
);
2617 hlist_for_each_entry_safe(node
, safe
, &bat_priv
->tt
.req_list
, list
) {
2618 hlist_del_init(&node
->list
);
2619 batadv_tt_req_node_put(node
);
2622 spin_unlock_bh(&bat_priv
->tt
.req_list_lock
);
2625 static void batadv_tt_save_orig_buffer(struct batadv_priv
*bat_priv
,
2626 struct batadv_orig_node
*orig_node
,
2627 const void *tt_buff
,
2630 /* Replace the old buffer only if I received something in the
2631 * last OGM (the OGM could carry no changes)
2633 spin_lock_bh(&orig_node
->tt_buff_lock
);
2634 if (tt_buff_len
> 0) {
2635 kfree(orig_node
->tt_buff
);
2636 orig_node
->tt_buff_len
= 0;
2637 orig_node
->tt_buff
= kmalloc(tt_buff_len
, GFP_ATOMIC
);
2638 if (orig_node
->tt_buff
) {
2639 memcpy(orig_node
->tt_buff
, tt_buff
, tt_buff_len
);
2640 orig_node
->tt_buff_len
= tt_buff_len
;
2643 spin_unlock_bh(&orig_node
->tt_buff_lock
);
2646 static void batadv_tt_req_purge(struct batadv_priv
*bat_priv
)
2648 struct batadv_tt_req_node
*node
;
2649 struct hlist_node
*safe
;
2651 spin_lock_bh(&bat_priv
->tt
.req_list_lock
);
2652 hlist_for_each_entry_safe(node
, safe
, &bat_priv
->tt
.req_list
, list
) {
2653 if (batadv_has_timed_out(node
->issued_at
,
2654 BATADV_TT_REQUEST_TIMEOUT
)) {
2655 hlist_del_init(&node
->list
);
2656 batadv_tt_req_node_put(node
);
2659 spin_unlock_bh(&bat_priv
->tt
.req_list_lock
);
2663 * batadv_tt_req_node_new() - search and possibly create a tt_req_node object
2664 * @bat_priv: the bat priv with all the soft interface information
2665 * @orig_node: orig node this request is being issued for
2667 * Return: the pointer to the new tt_req_node struct if no request
2668 * has already been issued for this orig_node, NULL otherwise.
2670 static struct batadv_tt_req_node
*
2671 batadv_tt_req_node_new(struct batadv_priv
*bat_priv
,
2672 struct batadv_orig_node
*orig_node
)
2674 struct batadv_tt_req_node
*tt_req_node_tmp
, *tt_req_node
= NULL
;
2676 spin_lock_bh(&bat_priv
->tt
.req_list_lock
);
2677 hlist_for_each_entry(tt_req_node_tmp
, &bat_priv
->tt
.req_list
, list
) {
2678 if (batadv_compare_eth(tt_req_node_tmp
, orig_node
) &&
2679 !batadv_has_timed_out(tt_req_node_tmp
->issued_at
,
2680 BATADV_TT_REQUEST_TIMEOUT
))
2684 tt_req_node
= kmem_cache_alloc(batadv_tt_req_cache
, GFP_ATOMIC
);
2688 kref_init(&tt_req_node
->refcount
);
2689 ether_addr_copy(tt_req_node
->addr
, orig_node
->orig
);
2690 tt_req_node
->issued_at
= jiffies
;
2692 kref_get(&tt_req_node
->refcount
);
2693 hlist_add_head(&tt_req_node
->list
, &bat_priv
->tt
.req_list
);
2695 spin_unlock_bh(&bat_priv
->tt
.req_list_lock
);
2700 * batadv_tt_local_valid() - verify local tt entry and get flags
2701 * @entry_ptr: to be checked local tt entry
2702 * @data_ptr: not used but definition required to satisfy the callback prototype
2703 * @flags: a pointer to store TT flags for this client to
2705 * Checks the validity of the given local TT entry. If it is, then the provided
2706 * flags pointer is updated.
2708 * Return: true if the entry is a valid, false otherwise.
2710 static bool batadv_tt_local_valid(const void *entry_ptr
,
2711 const void *data_ptr
,
2714 const struct batadv_tt_common_entry
*tt_common_entry
= entry_ptr
;
2716 if (tt_common_entry
->flags
& BATADV_TT_CLIENT_NEW
)
2720 *flags
= tt_common_entry
->flags
;
2726 * batadv_tt_global_valid() - verify global tt entry and get flags
2727 * @entry_ptr: to be checked global tt entry
2728 * @data_ptr: an orig_node object (may be NULL)
2729 * @flags: a pointer to store TT flags for this client to
2731 * Checks the validity of the given global TT entry. If it is, then the provided
2732 * flags pointer is updated either with the common (summed) TT flags if data_ptr
2733 * is NULL or the specific, per originator TT flags otherwise.
2735 * Return: true if the entry is a valid, false otherwise.
2737 static bool batadv_tt_global_valid(const void *entry_ptr
,
2738 const void *data_ptr
,
2741 const struct batadv_tt_common_entry
*tt_common_entry
= entry_ptr
;
2742 const struct batadv_tt_global_entry
*tt_global_entry
;
2743 const struct batadv_orig_node
*orig_node
= data_ptr
;
2745 if (tt_common_entry
->flags
& BATADV_TT_CLIENT_ROAM
||
2746 tt_common_entry
->flags
& BATADV_TT_CLIENT_TEMP
)
2749 tt_global_entry
= container_of(tt_common_entry
,
2750 struct batadv_tt_global_entry
,
2753 return batadv_tt_global_entry_has_orig(tt_global_entry
, orig_node
,
2758 * batadv_tt_tvlv_generate() - fill the tvlv buff with the tt entries from the
2760 * @bat_priv: the bat priv with all the soft interface information
2761 * @hash: hash table containing the tt entries
2762 * @tt_len: expected tvlv tt data buffer length in number of bytes
2763 * @tvlv_buff: pointer to the buffer to fill with the TT data
2764 * @valid_cb: function to filter tt change entries and to return TT flags
2765 * @cb_data: data passed to the filter function as argument
2767 * Fills the tvlv buff with the tt entries from the specified hash. If valid_cb
2768 * is not provided then this becomes a no-op.
2770 static void batadv_tt_tvlv_generate(struct batadv_priv
*bat_priv
,
2771 struct batadv_hashtable
*hash
,
2772 void *tvlv_buff
, u16 tt_len
,
2773 bool (*valid_cb
)(const void *,
2778 struct batadv_tt_common_entry
*tt_common_entry
;
2779 struct batadv_tvlv_tt_change
*tt_change
;
2780 struct hlist_head
*head
;
2781 u16 tt_tot
, tt_num_entries
= 0;
2786 tt_tot
= batadv_tt_entries(tt_len
);
2787 tt_change
= (struct batadv_tvlv_tt_change
*)tvlv_buff
;
2793 for (i
= 0; i
< hash
->size
; i
++) {
2794 head
= &hash
->table
[i
];
2796 hlist_for_each_entry_rcu(tt_common_entry
,
2798 if (tt_tot
== tt_num_entries
)
2801 ret
= valid_cb(tt_common_entry
, cb_data
, &flags
);
2805 ether_addr_copy(tt_change
->addr
, tt_common_entry
->addr
);
2806 tt_change
->flags
= flags
;
2807 tt_change
->vid
= htons(tt_common_entry
->vid
);
2808 memset(tt_change
->reserved
, 0,
2809 sizeof(tt_change
->reserved
));
2819 * batadv_tt_global_check_crc() - check if all the CRCs are correct
2820 * @orig_node: originator for which the CRCs have to be checked
2821 * @tt_vlan: pointer to the first tvlv VLAN entry
2822 * @num_vlan: number of tvlv VLAN entries
2824 * Return: true if all the received CRCs match the locally stored ones, false
2827 static bool batadv_tt_global_check_crc(struct batadv_orig_node
*orig_node
,
2828 struct batadv_tvlv_tt_vlan_data
*tt_vlan
,
2831 struct batadv_tvlv_tt_vlan_data
*tt_vlan_tmp
;
2832 struct batadv_orig_node_vlan
*vlan
;
2833 int i
, orig_num_vlan
;
2836 /* check if each received CRC matches the locally stored one */
2837 for (i
= 0; i
< num_vlan
; i
++) {
2838 tt_vlan_tmp
= tt_vlan
+ i
;
2840 /* if orig_node is a backbone node for this VLAN, don't check
2841 * the CRC as we ignore all the global entries over it
2843 if (batadv_bla_is_backbone_gw_orig(orig_node
->bat_priv
,
2845 ntohs(tt_vlan_tmp
->vid
)))
2848 vlan
= batadv_orig_node_vlan_get(orig_node
,
2849 ntohs(tt_vlan_tmp
->vid
));
2854 batadv_orig_node_vlan_put(vlan
);
2856 if (crc
!= ntohl(tt_vlan_tmp
->crc
))
2860 /* check if any excess VLANs exist locally for the originator
2861 * which are not mentioned in the TVLV from the originator.
2865 hlist_for_each_entry_rcu(vlan
, &orig_node
->vlan_list
, list
)
2869 if (orig_num_vlan
> num_vlan
)
2876 * batadv_tt_local_update_crc() - update all the local CRCs
2877 * @bat_priv: the bat priv with all the soft interface information
2879 static void batadv_tt_local_update_crc(struct batadv_priv
*bat_priv
)
2881 struct batadv_softif_vlan
*vlan
;
2883 /* recompute the global CRC for each VLAN */
2885 hlist_for_each_entry_rcu(vlan
, &bat_priv
->softif_vlan_list
, list
) {
2886 vlan
->tt
.crc
= batadv_tt_local_crc(bat_priv
, vlan
->vid
);
2892 * batadv_tt_global_update_crc() - update all the global CRCs for this orig_node
2893 * @bat_priv: the bat priv with all the soft interface information
2894 * @orig_node: the orig_node for which the CRCs have to be updated
2896 static void batadv_tt_global_update_crc(struct batadv_priv
*bat_priv
,
2897 struct batadv_orig_node
*orig_node
)
2899 struct batadv_orig_node_vlan
*vlan
;
2902 /* recompute the global CRC for each VLAN */
2904 hlist_for_each_entry_rcu(vlan
, &orig_node
->vlan_list
, list
) {
2905 /* if orig_node is a backbone node for this VLAN, don't compute
2906 * the CRC as we ignore all the global entries over it
2908 if (batadv_bla_is_backbone_gw_orig(bat_priv
, orig_node
->orig
,
2912 crc
= batadv_tt_global_crc(bat_priv
, orig_node
, vlan
->vid
);
2919 * batadv_send_tt_request() - send a TT Request message to a given node
2920 * @bat_priv: the bat priv with all the soft interface information
2921 * @dst_orig_node: the destination of the message
2922 * @ttvn: the version number that the source of the message is looking for
2923 * @tt_vlan: pointer to the first tvlv VLAN object to request
2924 * @num_vlan: number of tvlv VLAN entries
2925 * @full_table: ask for the entire translation table if true, while only for the
2926 * last TT diff otherwise
2928 * Return: true if the TT Request was sent, false otherwise
2930 static bool batadv_send_tt_request(struct batadv_priv
*bat_priv
,
2931 struct batadv_orig_node
*dst_orig_node
,
2933 struct batadv_tvlv_tt_vlan_data
*tt_vlan
,
2934 u16 num_vlan
, bool full_table
)
2936 struct batadv_tvlv_tt_data
*tvlv_tt_data
= NULL
;
2937 struct batadv_tt_req_node
*tt_req_node
= NULL
;
2938 struct batadv_tvlv_tt_vlan_data
*tt_vlan_req
;
2939 struct batadv_hard_iface
*primary_if
;
2943 primary_if
= batadv_primary_if_get_selected(bat_priv
);
2947 /* The new tt_req will be issued only if I'm not waiting for a
2948 * reply from the same orig_node yet
2950 tt_req_node
= batadv_tt_req_node_new(bat_priv
, dst_orig_node
);
2954 size
= sizeof(*tvlv_tt_data
) + sizeof(*tt_vlan_req
) * num_vlan
;
2955 tvlv_tt_data
= kzalloc(size
, GFP_ATOMIC
);
2959 tvlv_tt_data
->flags
= BATADV_TT_REQUEST
;
2960 tvlv_tt_data
->ttvn
= ttvn
;
2961 tvlv_tt_data
->num_vlan
= htons(num_vlan
);
2963 /* send all the CRCs within the request. This is needed by intermediate
2964 * nodes to ensure they have the correct table before replying
2966 tt_vlan_req
= (struct batadv_tvlv_tt_vlan_data
*)(tvlv_tt_data
+ 1);
2967 for (i
= 0; i
< num_vlan
; i
++) {
2968 tt_vlan_req
->vid
= tt_vlan
->vid
;
2969 tt_vlan_req
->crc
= tt_vlan
->crc
;
2976 tvlv_tt_data
->flags
|= BATADV_TT_FULL_TABLE
;
2978 batadv_dbg(BATADV_DBG_TT
, bat_priv
, "Sending TT_REQUEST to %pM [%c]\n",
2979 dst_orig_node
->orig
, full_table
? 'F' : '.');
2981 batadv_inc_counter(bat_priv
, BATADV_CNT_TT_REQUEST_TX
);
2982 batadv_tvlv_unicast_send(bat_priv
, primary_if
->net_dev
->dev_addr
,
2983 dst_orig_node
->orig
, BATADV_TVLV_TT
, 1,
2984 tvlv_tt_data
, size
);
2989 batadv_hardif_put(primary_if
);
2991 if (ret
&& tt_req_node
) {
2992 spin_lock_bh(&bat_priv
->tt
.req_list_lock
);
2993 if (!hlist_unhashed(&tt_req_node
->list
)) {
2994 hlist_del_init(&tt_req_node
->list
);
2995 batadv_tt_req_node_put(tt_req_node
);
2997 spin_unlock_bh(&bat_priv
->tt
.req_list_lock
);
3001 batadv_tt_req_node_put(tt_req_node
);
3003 kfree(tvlv_tt_data
);
3008 * batadv_send_other_tt_response() - send reply to tt request concerning another
3009 * node's translation table
3010 * @bat_priv: the bat priv with all the soft interface information
3011 * @tt_data: tt data containing the tt request information
3012 * @req_src: mac address of tt request sender
3013 * @req_dst: mac address of tt request recipient
3015 * Return: true if tt request reply was sent, false otherwise.
3017 static bool batadv_send_other_tt_response(struct batadv_priv
*bat_priv
,
3018 struct batadv_tvlv_tt_data
*tt_data
,
3019 u8
*req_src
, u8
*req_dst
)
3021 struct batadv_orig_node
*req_dst_orig_node
;
3022 struct batadv_orig_node
*res_dst_orig_node
= NULL
;
3023 struct batadv_tvlv_tt_change
*tt_change
;
3024 struct batadv_tvlv_tt_data
*tvlv_tt_data
= NULL
;
3025 struct batadv_tvlv_tt_vlan_data
*tt_vlan
;
3026 bool ret
= false, full_table
;
3027 u8 orig_ttvn
, req_ttvn
;
3031 batadv_dbg(BATADV_DBG_TT
, bat_priv
,
3032 "Received TT_REQUEST from %pM for ttvn: %u (%pM) [%c]\n",
3033 req_src
, tt_data
->ttvn
, req_dst
,
3034 ((tt_data
->flags
& BATADV_TT_FULL_TABLE
) ? 'F' : '.'));
3036 /* Let's get the orig node of the REAL destination */
3037 req_dst_orig_node
= batadv_orig_hash_find(bat_priv
, req_dst
);
3038 if (!req_dst_orig_node
)
3041 res_dst_orig_node
= batadv_orig_hash_find(bat_priv
, req_src
);
3042 if (!res_dst_orig_node
)
3045 orig_ttvn
= (u8
)atomic_read(&req_dst_orig_node
->last_ttvn
);
3046 req_ttvn
= tt_data
->ttvn
;
3048 tt_vlan
= (struct batadv_tvlv_tt_vlan_data
*)(tt_data
+ 1);
3049 /* this node doesn't have the requested data */
3050 if (orig_ttvn
!= req_ttvn
||
3051 !batadv_tt_global_check_crc(req_dst_orig_node
, tt_vlan
,
3052 ntohs(tt_data
->num_vlan
)))
3055 /* If the full table has been explicitly requested */
3056 if (tt_data
->flags
& BATADV_TT_FULL_TABLE
||
3057 !req_dst_orig_node
->tt_buff
)
3062 /* TT fragmentation hasn't been implemented yet, so send as many
3063 * TT entries fit a single packet as possible only
3066 spin_lock_bh(&req_dst_orig_node
->tt_buff_lock
);
3067 tt_len
= req_dst_orig_node
->tt_buff_len
;
3069 tvlv_len
= batadv_tt_prepare_tvlv_global_data(req_dst_orig_node
,
3076 /* Copy the last orig_node's OGM buffer */
3077 memcpy(tt_change
, req_dst_orig_node
->tt_buff
,
3078 req_dst_orig_node
->tt_buff_len
);
3079 spin_unlock_bh(&req_dst_orig_node
->tt_buff_lock
);
3081 /* allocate the tvlv, put the tt_data and all the tt_vlan_data
3082 * in the initial part
3085 tvlv_len
= batadv_tt_prepare_tvlv_global_data(req_dst_orig_node
,
3092 /* fill the rest of the tvlv with the real TT entries */
3093 batadv_tt_tvlv_generate(bat_priv
, bat_priv
->tt
.global_hash
,
3095 batadv_tt_global_valid
,
3099 /* Don't send the response, if larger than fragmented packet. */
3100 tt_len
= sizeof(struct batadv_unicast_tvlv_packet
) + tvlv_len
;
3101 if (tt_len
> atomic_read(&bat_priv
->packet_size_max
)) {
3102 net_ratelimited_function(batadv_info
, bat_priv
->soft_iface
,
3103 "Ignoring TT_REQUEST from %pM; Response size exceeds max packet size.\n",
3104 res_dst_orig_node
->orig
);
3108 tvlv_tt_data
->flags
= BATADV_TT_RESPONSE
;
3109 tvlv_tt_data
->ttvn
= req_ttvn
;
3112 tvlv_tt_data
->flags
|= BATADV_TT_FULL_TABLE
;
3114 batadv_dbg(BATADV_DBG_TT
, bat_priv
,
3115 "Sending TT_RESPONSE %pM for %pM [%c] (ttvn: %u)\n",
3116 res_dst_orig_node
->orig
, req_dst_orig_node
->orig
,
3117 full_table
? 'F' : '.', req_ttvn
);
3119 batadv_inc_counter(bat_priv
, BATADV_CNT_TT_RESPONSE_TX
);
3121 batadv_tvlv_unicast_send(bat_priv
, req_dst_orig_node
->orig
,
3122 req_src
, BATADV_TVLV_TT
, 1, tvlv_tt_data
,
3129 spin_unlock_bh(&req_dst_orig_node
->tt_buff_lock
);
3132 if (res_dst_orig_node
)
3133 batadv_orig_node_put(res_dst_orig_node
);
3134 if (req_dst_orig_node
)
3135 batadv_orig_node_put(req_dst_orig_node
);
3136 kfree(tvlv_tt_data
);
3141 * batadv_send_my_tt_response() - send reply to tt request concerning this
3142 * node's translation table
3143 * @bat_priv: the bat priv with all the soft interface information
3144 * @tt_data: tt data containing the tt request information
3145 * @req_src: mac address of tt request sender
3147 * Return: true if tt request reply was sent, false otherwise.
3149 static bool batadv_send_my_tt_response(struct batadv_priv
*bat_priv
,
3150 struct batadv_tvlv_tt_data
*tt_data
,
3153 struct batadv_tvlv_tt_data
*tvlv_tt_data
= NULL
;
3154 struct batadv_hard_iface
*primary_if
= NULL
;
3155 struct batadv_tvlv_tt_change
*tt_change
;
3156 struct batadv_orig_node
*orig_node
;
3157 u8 my_ttvn
, req_ttvn
;
3162 batadv_dbg(BATADV_DBG_TT
, bat_priv
,
3163 "Received TT_REQUEST from %pM for ttvn: %u (me) [%c]\n",
3164 req_src
, tt_data
->ttvn
,
3165 ((tt_data
->flags
& BATADV_TT_FULL_TABLE
) ? 'F' : '.'));
3167 spin_lock_bh(&bat_priv
->tt
.commit_lock
);
3169 my_ttvn
= (u8
)atomic_read(&bat_priv
->tt
.vn
);
3170 req_ttvn
= tt_data
->ttvn
;
3172 orig_node
= batadv_orig_hash_find(bat_priv
, req_src
);
3176 primary_if
= batadv_primary_if_get_selected(bat_priv
);
3180 /* If the full table has been explicitly requested or the gap
3181 * is too big send the whole local translation table
3183 if (tt_data
->flags
& BATADV_TT_FULL_TABLE
|| my_ttvn
!= req_ttvn
||
3184 !bat_priv
->tt
.last_changeset
)
3189 /* TT fragmentation hasn't been implemented yet, so send as many
3190 * TT entries fit a single packet as possible only
3193 spin_lock_bh(&bat_priv
->tt
.last_changeset_lock
);
3195 tt_len
= bat_priv
->tt
.last_changeset_len
;
3196 tvlv_len
= batadv_tt_prepare_tvlv_local_data(bat_priv
,
3200 if (!tt_len
|| !tvlv_len
)
3203 /* Copy the last orig_node's OGM buffer */
3204 memcpy(tt_change
, bat_priv
->tt
.last_changeset
,
3205 bat_priv
->tt
.last_changeset_len
);
3206 spin_unlock_bh(&bat_priv
->tt
.last_changeset_lock
);
3208 req_ttvn
= (u8
)atomic_read(&bat_priv
->tt
.vn
);
3210 /* allocate the tvlv, put the tt_data and all the tt_vlan_data
3211 * in the initial part
3214 tvlv_len
= batadv_tt_prepare_tvlv_local_data(bat_priv
,
3218 if (!tt_len
|| !tvlv_len
)
3221 /* fill the rest of the tvlv with the real TT entries */
3222 batadv_tt_tvlv_generate(bat_priv
, bat_priv
->tt
.local_hash
,
3224 batadv_tt_local_valid
, NULL
);
3227 tvlv_tt_data
->flags
= BATADV_TT_RESPONSE
;
3228 tvlv_tt_data
->ttvn
= req_ttvn
;
3231 tvlv_tt_data
->flags
|= BATADV_TT_FULL_TABLE
;
3233 batadv_dbg(BATADV_DBG_TT
, bat_priv
,
3234 "Sending TT_RESPONSE to %pM [%c] (ttvn: %u)\n",
3235 orig_node
->orig
, full_table
? 'F' : '.', req_ttvn
);
3237 batadv_inc_counter(bat_priv
, BATADV_CNT_TT_RESPONSE_TX
);
3239 batadv_tvlv_unicast_send(bat_priv
, primary_if
->net_dev
->dev_addr
,
3240 req_src
, BATADV_TVLV_TT
, 1, tvlv_tt_data
,
3246 spin_unlock_bh(&bat_priv
->tt
.last_changeset_lock
);
3248 spin_unlock_bh(&bat_priv
->tt
.commit_lock
);
3250 batadv_orig_node_put(orig_node
);
3252 batadv_hardif_put(primary_if
);
3253 kfree(tvlv_tt_data
);
3254 /* The packet was for this host, so it doesn't need to be re-routed */
3259 * batadv_send_tt_response() - send reply to tt request
3260 * @bat_priv: the bat priv with all the soft interface information
3261 * @tt_data: tt data containing the tt request information
3262 * @req_src: mac address of tt request sender
3263 * @req_dst: mac address of tt request recipient
3265 * Return: true if tt request reply was sent, false otherwise.
3267 static bool batadv_send_tt_response(struct batadv_priv
*bat_priv
,
3268 struct batadv_tvlv_tt_data
*tt_data
,
3269 u8
*req_src
, u8
*req_dst
)
3271 if (batadv_is_my_mac(bat_priv
, req_dst
))
3272 return batadv_send_my_tt_response(bat_priv
, tt_data
, req_src
);
3273 return batadv_send_other_tt_response(bat_priv
, tt_data
, req_src
,
3277 static void _batadv_tt_update_changes(struct batadv_priv
*bat_priv
,
3278 struct batadv_orig_node
*orig_node
,
3279 struct batadv_tvlv_tt_change
*tt_change
,
3280 u16 tt_num_changes
, u8 ttvn
)
3285 for (i
= 0; i
< tt_num_changes
; i
++) {
3286 if ((tt_change
+ i
)->flags
& BATADV_TT_CLIENT_DEL
) {
3287 roams
= (tt_change
+ i
)->flags
& BATADV_TT_CLIENT_ROAM
;
3288 batadv_tt_global_del(bat_priv
, orig_node
,
3289 (tt_change
+ i
)->addr
,
3290 ntohs((tt_change
+ i
)->vid
),
3291 "tt removed by changes",
3294 if (!batadv_tt_global_add(bat_priv
, orig_node
,
3295 (tt_change
+ i
)->addr
,
3296 ntohs((tt_change
+ i
)->vid
),
3297 (tt_change
+ i
)->flags
, ttvn
))
3298 /* In case of problem while storing a
3299 * global_entry, we stop the updating
3300 * procedure without committing the
3301 * ttvn change. This will avoid to send
3302 * corrupted data on tt_request
3307 set_bit(BATADV_ORIG_CAPA_HAS_TT
, &orig_node
->capa_initialized
);
3310 static void batadv_tt_fill_gtable(struct batadv_priv
*bat_priv
,
3311 struct batadv_tvlv_tt_change
*tt_change
,
3312 u8 ttvn
, u8
*resp_src
,
3315 struct batadv_orig_node
*orig_node
;
3317 orig_node
= batadv_orig_hash_find(bat_priv
, resp_src
);
3321 /* Purge the old table first.. */
3322 batadv_tt_global_del_orig(bat_priv
, orig_node
, -1,
3323 "Received full table");
3325 _batadv_tt_update_changes(bat_priv
, orig_node
, tt_change
, num_entries
,
3328 spin_lock_bh(&orig_node
->tt_buff_lock
);
3329 kfree(orig_node
->tt_buff
);
3330 orig_node
->tt_buff_len
= 0;
3331 orig_node
->tt_buff
= NULL
;
3332 spin_unlock_bh(&orig_node
->tt_buff_lock
);
3334 atomic_set(&orig_node
->last_ttvn
, ttvn
);
3338 batadv_orig_node_put(orig_node
);
3341 static void batadv_tt_update_changes(struct batadv_priv
*bat_priv
,
3342 struct batadv_orig_node
*orig_node
,
3343 u16 tt_num_changes
, u8 ttvn
,
3344 struct batadv_tvlv_tt_change
*tt_change
)
3346 _batadv_tt_update_changes(bat_priv
, orig_node
, tt_change
,
3347 tt_num_changes
, ttvn
);
3349 batadv_tt_save_orig_buffer(bat_priv
, orig_node
, tt_change
,
3350 batadv_tt_len(tt_num_changes
));
3351 atomic_set(&orig_node
->last_ttvn
, ttvn
);
3355 * batadv_is_my_client() - check if a client is served by the local node
3356 * @bat_priv: the bat priv with all the soft interface information
3357 * @addr: the mac address of the client to check
3358 * @vid: VLAN identifier
3360 * Return: true if the client is served by this node, false otherwise.
3362 bool batadv_is_my_client(struct batadv_priv
*bat_priv
, const u8
*addr
,
3365 struct batadv_tt_local_entry
*tt_local_entry
;
3368 tt_local_entry
= batadv_tt_local_hash_find(bat_priv
, addr
, vid
);
3369 if (!tt_local_entry
)
3371 /* Check if the client has been logically deleted (but is kept for
3372 * consistency purpose)
3374 if ((tt_local_entry
->common
.flags
& BATADV_TT_CLIENT_PENDING
) ||
3375 (tt_local_entry
->common
.flags
& BATADV_TT_CLIENT_ROAM
))
3380 batadv_tt_local_entry_put(tt_local_entry
);
3385 * batadv_handle_tt_response() - process incoming tt reply
3386 * @bat_priv: the bat priv with all the soft interface information
3387 * @tt_data: tt data containing the tt request information
3388 * @resp_src: mac address of tt reply sender
3389 * @num_entries: number of tt change entries appended to the tt data
3391 static void batadv_handle_tt_response(struct batadv_priv
*bat_priv
,
3392 struct batadv_tvlv_tt_data
*tt_data
,
3393 u8
*resp_src
, u16 num_entries
)
3395 struct batadv_tt_req_node
*node
;
3396 struct hlist_node
*safe
;
3397 struct batadv_orig_node
*orig_node
= NULL
;
3398 struct batadv_tvlv_tt_change
*tt_change
;
3399 u8
*tvlv_ptr
= (u8
*)tt_data
;
3402 batadv_dbg(BATADV_DBG_TT
, bat_priv
,
3403 "Received TT_RESPONSE from %pM for ttvn %d t_size: %d [%c]\n",
3404 resp_src
, tt_data
->ttvn
, num_entries
,
3405 ((tt_data
->flags
& BATADV_TT_FULL_TABLE
) ? 'F' : '.'));
3407 orig_node
= batadv_orig_hash_find(bat_priv
, resp_src
);
3411 spin_lock_bh(&orig_node
->tt_lock
);
3413 change_offset
= sizeof(struct batadv_tvlv_tt_vlan_data
);
3414 change_offset
*= ntohs(tt_data
->num_vlan
);
3415 change_offset
+= sizeof(*tt_data
);
3416 tvlv_ptr
+= change_offset
;
3418 tt_change
= (struct batadv_tvlv_tt_change
*)tvlv_ptr
;
3419 if (tt_data
->flags
& BATADV_TT_FULL_TABLE
) {
3420 batadv_tt_fill_gtable(bat_priv
, tt_change
, tt_data
->ttvn
,
3421 resp_src
, num_entries
);
3423 batadv_tt_update_changes(bat_priv
, orig_node
, num_entries
,
3424 tt_data
->ttvn
, tt_change
);
3427 /* Recalculate the CRC for this orig_node and store it */
3428 batadv_tt_global_update_crc(bat_priv
, orig_node
);
3430 spin_unlock_bh(&orig_node
->tt_lock
);
3432 /* Delete the tt_req_node from pending tt_requests list */
3433 spin_lock_bh(&bat_priv
->tt
.req_list_lock
);
3434 hlist_for_each_entry_safe(node
, safe
, &bat_priv
->tt
.req_list
, list
) {
3435 if (!batadv_compare_eth(node
->addr
, resp_src
))
3437 hlist_del_init(&node
->list
);
3438 batadv_tt_req_node_put(node
);
3441 spin_unlock_bh(&bat_priv
->tt
.req_list_lock
);
3444 batadv_orig_node_put(orig_node
);
3447 static void batadv_tt_roam_list_free(struct batadv_priv
*bat_priv
)
3449 struct batadv_tt_roam_node
*node
, *safe
;
3451 spin_lock_bh(&bat_priv
->tt
.roam_list_lock
);
3453 list_for_each_entry_safe(node
, safe
, &bat_priv
->tt
.roam_list
, list
) {
3454 list_del(&node
->list
);
3455 kmem_cache_free(batadv_tt_roam_cache
, node
);
3458 spin_unlock_bh(&bat_priv
->tt
.roam_list_lock
);
3461 static void batadv_tt_roam_purge(struct batadv_priv
*bat_priv
)
3463 struct batadv_tt_roam_node
*node
, *safe
;
3465 spin_lock_bh(&bat_priv
->tt
.roam_list_lock
);
3466 list_for_each_entry_safe(node
, safe
, &bat_priv
->tt
.roam_list
, list
) {
3467 if (!batadv_has_timed_out(node
->first_time
,
3468 BATADV_ROAMING_MAX_TIME
))
3471 list_del(&node
->list
);
3472 kmem_cache_free(batadv_tt_roam_cache
, node
);
3474 spin_unlock_bh(&bat_priv
->tt
.roam_list_lock
);
3478 * batadv_tt_check_roam_count() - check if a client has roamed too frequently
3479 * @bat_priv: the bat priv with all the soft interface information
3480 * @client: mac address of the roaming client
3482 * This function checks whether the client already reached the
3483 * maximum number of possible roaming phases. In this case the ROAMING_ADV
3486 * Return: true if the ROAMING_ADV can be sent, false otherwise
3488 static bool batadv_tt_check_roam_count(struct batadv_priv
*bat_priv
, u8
*client
)
3490 struct batadv_tt_roam_node
*tt_roam_node
;
3493 spin_lock_bh(&bat_priv
->tt
.roam_list_lock
);
3494 /* The new tt_req will be issued only if I'm not waiting for a
3495 * reply from the same orig_node yet
3497 list_for_each_entry(tt_roam_node
, &bat_priv
->tt
.roam_list
, list
) {
3498 if (!batadv_compare_eth(tt_roam_node
->addr
, client
))
3501 if (batadv_has_timed_out(tt_roam_node
->first_time
,
3502 BATADV_ROAMING_MAX_TIME
))
3505 if (!batadv_atomic_dec_not_zero(&tt_roam_node
->counter
))
3506 /* Sorry, you roamed too many times! */
3513 tt_roam_node
= kmem_cache_alloc(batadv_tt_roam_cache
,
3518 tt_roam_node
->first_time
= jiffies
;
3519 atomic_set(&tt_roam_node
->counter
,
3520 BATADV_ROAMING_MAX_COUNT
- 1);
3521 ether_addr_copy(tt_roam_node
->addr
, client
);
3523 list_add(&tt_roam_node
->list
, &bat_priv
->tt
.roam_list
);
3528 spin_unlock_bh(&bat_priv
->tt
.roam_list_lock
);
3533 * batadv_send_roam_adv() - send a roaming advertisement message
3534 * @bat_priv: the bat priv with all the soft interface information
3535 * @client: mac address of the roaming client
3536 * @vid: VLAN identifier
3537 * @orig_node: message destination
3539 * Send a ROAMING_ADV message to the node which was previously serving this
3540 * client. This is done to inform the node that from now on all traffic destined
3541 * for this particular roamed client has to be forwarded to the sender of the
3544 static void batadv_send_roam_adv(struct batadv_priv
*bat_priv
, u8
*client
,
3546 struct batadv_orig_node
*orig_node
)
3548 struct batadv_hard_iface
*primary_if
;
3549 struct batadv_tvlv_roam_adv tvlv_roam
;
3551 primary_if
= batadv_primary_if_get_selected(bat_priv
);
3555 /* before going on we have to check whether the client has
3556 * already roamed to us too many times
3558 if (!batadv_tt_check_roam_count(bat_priv
, client
))
3561 batadv_dbg(BATADV_DBG_TT
, bat_priv
,
3562 "Sending ROAMING_ADV to %pM (client %pM, vid: %d)\n",
3563 orig_node
->orig
, client
, batadv_print_vid(vid
));
3565 batadv_inc_counter(bat_priv
, BATADV_CNT_TT_ROAM_ADV_TX
);
3567 memcpy(tvlv_roam
.client
, client
, sizeof(tvlv_roam
.client
));
3568 tvlv_roam
.vid
= htons(vid
);
3570 batadv_tvlv_unicast_send(bat_priv
, primary_if
->net_dev
->dev_addr
,
3571 orig_node
->orig
, BATADV_TVLV_ROAM
, 1,
3572 &tvlv_roam
, sizeof(tvlv_roam
));
3576 batadv_hardif_put(primary_if
);
3579 static void batadv_tt_purge(struct work_struct
*work
)
3581 struct delayed_work
*delayed_work
;
3582 struct batadv_priv_tt
*priv_tt
;
3583 struct batadv_priv
*bat_priv
;
3585 delayed_work
= to_delayed_work(work
);
3586 priv_tt
= container_of(delayed_work
, struct batadv_priv_tt
, work
);
3587 bat_priv
= container_of(priv_tt
, struct batadv_priv
, tt
);
3589 batadv_tt_local_purge(bat_priv
, BATADV_TT_LOCAL_TIMEOUT
);
3590 batadv_tt_global_purge(bat_priv
);
3591 batadv_tt_req_purge(bat_priv
);
3592 batadv_tt_roam_purge(bat_priv
);
3594 queue_delayed_work(batadv_event_workqueue
, &bat_priv
->tt
.work
,
3595 msecs_to_jiffies(BATADV_TT_WORK_PERIOD
));
3599 * batadv_tt_free() - Free translation table of soft interface
3600 * @bat_priv: the bat priv with all the soft interface information
3602 void batadv_tt_free(struct batadv_priv
*bat_priv
)
3604 batadv_tvlv_handler_unregister(bat_priv
, BATADV_TVLV_ROAM
, 1);
3606 batadv_tvlv_container_unregister(bat_priv
, BATADV_TVLV_TT
, 1);
3607 batadv_tvlv_handler_unregister(bat_priv
, BATADV_TVLV_TT
, 1);
3609 cancel_delayed_work_sync(&bat_priv
->tt
.work
);
3611 batadv_tt_local_table_free(bat_priv
);
3612 batadv_tt_global_table_free(bat_priv
);
3613 batadv_tt_req_list_free(bat_priv
);
3614 batadv_tt_changes_list_free(bat_priv
);
3615 batadv_tt_roam_list_free(bat_priv
);
3617 kfree(bat_priv
->tt
.last_changeset
);
3621 * batadv_tt_local_set_flags() - set or unset the specified flags on the local
3622 * table and possibly count them in the TT size
3623 * @bat_priv: the bat priv with all the soft interface information
3624 * @flags: the flag to switch
3625 * @enable: whether to set or unset the flag
3626 * @count: whether to increase the TT size by the number of changed entries
3628 static void batadv_tt_local_set_flags(struct batadv_priv
*bat_priv
, u16 flags
,
3629 bool enable
, bool count
)
3631 struct batadv_hashtable
*hash
= bat_priv
->tt
.local_hash
;
3632 struct batadv_tt_common_entry
*tt_common_entry
;
3633 struct hlist_head
*head
;
3639 for (i
= 0; i
< hash
->size
; i
++) {
3640 head
= &hash
->table
[i
];
3643 hlist_for_each_entry_rcu(tt_common_entry
,
3646 if ((tt_common_entry
->flags
& flags
) == flags
)
3648 tt_common_entry
->flags
|= flags
;
3650 if (!(tt_common_entry
->flags
& flags
))
3652 tt_common_entry
->flags
&= ~flags
;
3658 batadv_tt_local_size_inc(bat_priv
,
3659 tt_common_entry
->vid
);
3665 /* Purge out all the tt local entries marked with BATADV_TT_CLIENT_PENDING */
3666 static void batadv_tt_local_purge_pending_clients(struct batadv_priv
*bat_priv
)
3668 struct batadv_hashtable
*hash
= bat_priv
->tt
.local_hash
;
3669 struct batadv_tt_common_entry
*tt_common
;
3670 struct batadv_tt_local_entry
*tt_local
;
3671 struct hlist_node
*node_tmp
;
3672 struct hlist_head
*head
;
3673 spinlock_t
*list_lock
; /* protects write access to the hash lists */
3679 for (i
= 0; i
< hash
->size
; i
++) {
3680 head
= &hash
->table
[i
];
3681 list_lock
= &hash
->list_locks
[i
];
3683 spin_lock_bh(list_lock
);
3684 hlist_for_each_entry_safe(tt_common
, node_tmp
, head
,
3686 if (!(tt_common
->flags
& BATADV_TT_CLIENT_PENDING
))
3689 batadv_dbg(BATADV_DBG_TT
, bat_priv
,
3690 "Deleting local tt entry (%pM, vid: %d): pending\n",
3692 batadv_print_vid(tt_common
->vid
));
3694 batadv_tt_local_size_dec(bat_priv
, tt_common
->vid
);
3695 hlist_del_rcu(&tt_common
->hash_entry
);
3696 tt_local
= container_of(tt_common
,
3697 struct batadv_tt_local_entry
,
3700 batadv_tt_local_entry_put(tt_local
);
3702 spin_unlock_bh(list_lock
);
3707 * batadv_tt_local_commit_changes_nolock() - commit all pending local tt changes
3708 * which have been queued in the time since the last commit
3709 * @bat_priv: the bat priv with all the soft interface information
3711 * Caller must hold tt->commit_lock.
3713 static void batadv_tt_local_commit_changes_nolock(struct batadv_priv
*bat_priv
)
3715 lockdep_assert_held(&bat_priv
->tt
.commit_lock
);
3717 if (atomic_read(&bat_priv
->tt
.local_changes
) < 1) {
3718 if (!batadv_atomic_dec_not_zero(&bat_priv
->tt
.ogm_append_cnt
))
3719 batadv_tt_tvlv_container_update(bat_priv
);
3723 batadv_tt_local_set_flags(bat_priv
, BATADV_TT_CLIENT_NEW
, false, true);
3725 batadv_tt_local_purge_pending_clients(bat_priv
);
3726 batadv_tt_local_update_crc(bat_priv
);
3728 /* Increment the TTVN only once per OGM interval */
3729 atomic_inc(&bat_priv
->tt
.vn
);
3730 batadv_dbg(BATADV_DBG_TT
, bat_priv
,
3731 "Local changes committed, updating to ttvn %u\n",
3732 (u8
)atomic_read(&bat_priv
->tt
.vn
));
3734 /* reset the sending counter */
3735 atomic_set(&bat_priv
->tt
.ogm_append_cnt
, BATADV_TT_OGM_APPEND_MAX
);
3736 batadv_tt_tvlv_container_update(bat_priv
);
3740 * batadv_tt_local_commit_changes() - commit all pending local tt changes which
3741 * have been queued in the time since the last commit
3742 * @bat_priv: the bat priv with all the soft interface information
3744 void batadv_tt_local_commit_changes(struct batadv_priv
*bat_priv
)
3746 spin_lock_bh(&bat_priv
->tt
.commit_lock
);
3747 batadv_tt_local_commit_changes_nolock(bat_priv
);
3748 spin_unlock_bh(&bat_priv
->tt
.commit_lock
);
3752 * batadv_is_ap_isolated() - Check if packet from upper layer should be dropped
3753 * @bat_priv: the bat priv with all the soft interface information
3754 * @src: source mac address of packet
3755 * @dst: destination mac address of packet
3756 * @vid: vlan id of packet
3758 * Return: true when src+dst(+vid) pair should be isolated, false otherwise
3760 bool batadv_is_ap_isolated(struct batadv_priv
*bat_priv
, u8
*src
, u8
*dst
,
3763 struct batadv_tt_local_entry
*tt_local_entry
;
3764 struct batadv_tt_global_entry
*tt_global_entry
;
3765 struct batadv_softif_vlan
*vlan
;
3768 vlan
= batadv_softif_vlan_get(bat_priv
, vid
);
3772 if (!atomic_read(&vlan
->ap_isolation
))
3775 tt_local_entry
= batadv_tt_local_hash_find(bat_priv
, dst
, vid
);
3776 if (!tt_local_entry
)
3779 tt_global_entry
= batadv_tt_global_hash_find(bat_priv
, src
, vid
);
3780 if (!tt_global_entry
)
3781 goto local_entry_put
;
3783 if (_batadv_is_ap_isolated(tt_local_entry
, tt_global_entry
))
3786 batadv_tt_global_entry_put(tt_global_entry
);
3788 batadv_tt_local_entry_put(tt_local_entry
);
3790 batadv_softif_vlan_put(vlan
);
3795 * batadv_tt_update_orig() - update global translation table with new tt
3796 * information received via ogms
3797 * @bat_priv: the bat priv with all the soft interface information
3798 * @orig_node: the orig_node of the ogm
3799 * @tt_buff: pointer to the first tvlv VLAN entry
3800 * @tt_num_vlan: number of tvlv VLAN entries
3801 * @tt_change: pointer to the first entry in the TT buffer
3802 * @tt_num_changes: number of tt changes inside the tt buffer
3803 * @ttvn: translation table version number of this changeset
3805 static void batadv_tt_update_orig(struct batadv_priv
*bat_priv
,
3806 struct batadv_orig_node
*orig_node
,
3807 const void *tt_buff
, u16 tt_num_vlan
,
3808 struct batadv_tvlv_tt_change
*tt_change
,
3809 u16 tt_num_changes
, u8 ttvn
)
3811 u8 orig_ttvn
= (u8
)atomic_read(&orig_node
->last_ttvn
);
3812 struct batadv_tvlv_tt_vlan_data
*tt_vlan
;
3813 bool full_table
= true;
3816 tt_vlan
= (struct batadv_tvlv_tt_vlan_data
*)tt_buff
;
3817 has_tt_init
= test_bit(BATADV_ORIG_CAPA_HAS_TT
,
3818 &orig_node
->capa_initialized
);
3820 /* orig table not initialised AND first diff is in the OGM OR the ttvn
3821 * increased by one -> we can apply the attached changes
3823 if ((!has_tt_init
&& ttvn
== 1) || ttvn
- orig_ttvn
== 1) {
3824 /* the OGM could not contain the changes due to their size or
3825 * because they have already been sent BATADV_TT_OGM_APPEND_MAX
3827 * In this case send a tt request
3829 if (!tt_num_changes
) {
3834 spin_lock_bh(&orig_node
->tt_lock
);
3836 batadv_tt_update_changes(bat_priv
, orig_node
, tt_num_changes
,
3839 /* Even if we received the precomputed crc with the OGM, we
3840 * prefer to recompute it to spot any possible inconsistency
3841 * in the global table
3843 batadv_tt_global_update_crc(bat_priv
, orig_node
);
3845 spin_unlock_bh(&orig_node
->tt_lock
);
3847 /* The ttvn alone is not enough to guarantee consistency
3848 * because a single value could represent different states
3849 * (due to the wrap around). Thus a node has to check whether
3850 * the resulting table (after applying the changes) is still
3851 * consistent or not. E.g. a node could disconnect while its
3852 * ttvn is X and reconnect on ttvn = X + TTVN_MAX: in this case
3853 * checking the CRC value is mandatory to detect the
3856 if (!batadv_tt_global_check_crc(orig_node
, tt_vlan
,
3860 /* if we missed more than one change or our tables are not
3861 * in sync anymore -> request fresh tt data
3863 if (!has_tt_init
|| ttvn
!= orig_ttvn
||
3864 !batadv_tt_global_check_crc(orig_node
, tt_vlan
,
3867 batadv_dbg(BATADV_DBG_TT
, bat_priv
,
3868 "TT inconsistency for %pM. Need to retrieve the correct information (ttvn: %u last_ttvn: %u num_changes: %u)\n",
3869 orig_node
->orig
, ttvn
, orig_ttvn
,
3871 batadv_send_tt_request(bat_priv
, orig_node
, ttvn
,
3872 tt_vlan
, tt_num_vlan
,
3880 * batadv_tt_global_client_is_roaming() - check if a client is marked as roaming
3881 * @bat_priv: the bat priv with all the soft interface information
3882 * @addr: the mac address of the client to check
3883 * @vid: VLAN identifier
3885 * Return: true if we know that the client has moved from its old originator
3886 * to another one. This entry is still kept for consistency purposes and will be
3887 * deleted later by a DEL or because of timeout
3889 bool batadv_tt_global_client_is_roaming(struct batadv_priv
*bat_priv
,
3890 u8
*addr
, unsigned short vid
)
3892 struct batadv_tt_global_entry
*tt_global_entry
;
3895 tt_global_entry
= batadv_tt_global_hash_find(bat_priv
, addr
, vid
);
3896 if (!tt_global_entry
)
3899 ret
= tt_global_entry
->common
.flags
& BATADV_TT_CLIENT_ROAM
;
3900 batadv_tt_global_entry_put(tt_global_entry
);
3906 * batadv_tt_local_client_is_roaming() - tells whether the client is roaming
3907 * @bat_priv: the bat priv with all the soft interface information
3908 * @addr: the mac address of the local client to query
3909 * @vid: VLAN identifier
3911 * Return: true if the local client is known to be roaming (it is not served by
3912 * this node anymore) or not. If yes, the client is still present in the table
3913 * to keep the latter consistent with the node TTVN
3915 bool batadv_tt_local_client_is_roaming(struct batadv_priv
*bat_priv
,
3916 u8
*addr
, unsigned short vid
)
3918 struct batadv_tt_local_entry
*tt_local_entry
;
3921 tt_local_entry
= batadv_tt_local_hash_find(bat_priv
, addr
, vid
);
3922 if (!tt_local_entry
)
3925 ret
= tt_local_entry
->common
.flags
& BATADV_TT_CLIENT_ROAM
;
3926 batadv_tt_local_entry_put(tt_local_entry
);
3932 * batadv_tt_add_temporary_global_entry() - Add temporary entry to global TT
3933 * @bat_priv: the bat priv with all the soft interface information
3934 * @orig_node: orig node which the temporary entry should be associated with
3935 * @addr: mac address of the client
3936 * @vid: VLAN id of the new temporary global translation table
3938 * Return: true when temporary tt entry could be added, false otherwise
3940 bool batadv_tt_add_temporary_global_entry(struct batadv_priv
*bat_priv
,
3941 struct batadv_orig_node
*orig_node
,
3942 const unsigned char *addr
,
3945 /* ignore loop detect macs, they are not supposed to be in the tt local
3948 if (batadv_bla_is_loopdetect_mac(addr
))
3951 if (!batadv_tt_global_add(bat_priv
, orig_node
, addr
, vid
,
3952 BATADV_TT_CLIENT_TEMP
,
3953 atomic_read(&orig_node
->last_ttvn
)))
3956 batadv_dbg(BATADV_DBG_TT
, bat_priv
,
3957 "Added temporary global client (addr: %pM, vid: %d, orig: %pM)\n",
3958 addr
, batadv_print_vid(vid
), orig_node
->orig
);
3964 * batadv_tt_local_resize_to_mtu() - resize the local translation table fit the
3965 * maximum packet size that can be transported through the mesh
3966 * @soft_iface: netdev struct of the mesh interface
3968 * Remove entries older than 'timeout' and half timeout if more entries need
3971 void batadv_tt_local_resize_to_mtu(struct net_device
*soft_iface
)
3973 struct batadv_priv
*bat_priv
= netdev_priv(soft_iface
);
3974 int packet_size_max
= atomic_read(&bat_priv
->packet_size_max
);
3975 int table_size
, timeout
= BATADV_TT_LOCAL_TIMEOUT
/ 2;
3976 bool reduced
= false;
3978 spin_lock_bh(&bat_priv
->tt
.commit_lock
);
3981 table_size
= batadv_tt_local_table_transmit_size(bat_priv
);
3982 if (packet_size_max
>= table_size
)
3985 batadv_tt_local_purge(bat_priv
, timeout
);
3986 batadv_tt_local_purge_pending_clients(bat_priv
);
3990 net_ratelimited_function(batadv_info
, soft_iface
,
3991 "Forced to purge local tt entries to fit new maximum fragment MTU (%i)\n",
3995 /* commit these changes immediately, to avoid synchronization problem
3999 batadv_tt_local_commit_changes_nolock(bat_priv
);
4001 spin_unlock_bh(&bat_priv
->tt
.commit_lock
);
4005 * batadv_tt_tvlv_ogm_handler_v1() - process incoming tt tvlv container
4006 * @bat_priv: the bat priv with all the soft interface information
4007 * @orig: the orig_node of the ogm
4008 * @flags: flags indicating the tvlv state (see batadv_tvlv_handler_flags)
4009 * @tvlv_value: tvlv buffer containing the gateway data
4010 * @tvlv_value_len: tvlv buffer length
4012 static void batadv_tt_tvlv_ogm_handler_v1(struct batadv_priv
*bat_priv
,
4013 struct batadv_orig_node
*orig
,
4014 u8 flags
, void *tvlv_value
,
4017 struct batadv_tvlv_tt_vlan_data
*tt_vlan
;
4018 struct batadv_tvlv_tt_change
*tt_change
;
4019 struct batadv_tvlv_tt_data
*tt_data
;
4020 u16 num_entries
, num_vlan
;
4022 if (tvlv_value_len
< sizeof(*tt_data
))
4025 tt_data
= (struct batadv_tvlv_tt_data
*)tvlv_value
;
4026 tvlv_value_len
-= sizeof(*tt_data
);
4028 num_vlan
= ntohs(tt_data
->num_vlan
);
4030 if (tvlv_value_len
< sizeof(*tt_vlan
) * num_vlan
)
4033 tt_vlan
= (struct batadv_tvlv_tt_vlan_data
*)(tt_data
+ 1);
4034 tt_change
= (struct batadv_tvlv_tt_change
*)(tt_vlan
+ num_vlan
);
4035 tvlv_value_len
-= sizeof(*tt_vlan
) * num_vlan
;
4037 num_entries
= batadv_tt_entries(tvlv_value_len
);
4039 batadv_tt_update_orig(bat_priv
, orig
, tt_vlan
, num_vlan
, tt_change
,
4040 num_entries
, tt_data
->ttvn
);
4044 * batadv_tt_tvlv_unicast_handler_v1() - process incoming (unicast) tt tvlv
4046 * @bat_priv: the bat priv with all the soft interface information
4047 * @src: mac address of tt tvlv sender
4048 * @dst: mac address of tt tvlv recipient
4049 * @tvlv_value: tvlv buffer containing the tt data
4050 * @tvlv_value_len: tvlv buffer length
4052 * Return: NET_RX_DROP if the tt tvlv is to be re-routed, NET_RX_SUCCESS
4055 static int batadv_tt_tvlv_unicast_handler_v1(struct batadv_priv
*bat_priv
,
4060 struct batadv_tvlv_tt_data
*tt_data
;
4061 u16 tt_vlan_len
, tt_num_entries
;
4065 if (tvlv_value_len
< sizeof(*tt_data
))
4066 return NET_RX_SUCCESS
;
4068 tt_data
= (struct batadv_tvlv_tt_data
*)tvlv_value
;
4069 tvlv_value_len
-= sizeof(*tt_data
);
4071 tt_vlan_len
= sizeof(struct batadv_tvlv_tt_vlan_data
);
4072 tt_vlan_len
*= ntohs(tt_data
->num_vlan
);
4074 if (tvlv_value_len
< tt_vlan_len
)
4075 return NET_RX_SUCCESS
;
4077 tvlv_value_len
-= tt_vlan_len
;
4078 tt_num_entries
= batadv_tt_entries(tvlv_value_len
);
4080 switch (tt_data
->flags
& BATADV_TT_DATA_TYPE_MASK
) {
4081 case BATADV_TT_REQUEST
:
4082 batadv_inc_counter(bat_priv
, BATADV_CNT_TT_REQUEST_RX
);
4084 /* If this node cannot provide a TT response the tt_request is
4087 ret
= batadv_send_tt_response(bat_priv
, tt_data
, src
, dst
);
4089 if (tt_data
->flags
& BATADV_TT_FULL_TABLE
)
4094 batadv_dbg(BATADV_DBG_TT
, bat_priv
,
4095 "Routing TT_REQUEST to %pM [%c]\n",
4097 /* tvlv API will re-route the packet */
4101 case BATADV_TT_RESPONSE
:
4102 batadv_inc_counter(bat_priv
, BATADV_CNT_TT_RESPONSE_RX
);
4104 if (batadv_is_my_mac(bat_priv
, dst
)) {
4105 batadv_handle_tt_response(bat_priv
, tt_data
,
4106 src
, tt_num_entries
);
4107 return NET_RX_SUCCESS
;
4110 if (tt_data
->flags
& BATADV_TT_FULL_TABLE
)
4115 batadv_dbg(BATADV_DBG_TT
, bat_priv
,
4116 "Routing TT_RESPONSE to %pM [%c]\n", dst
, tt_flag
);
4118 /* tvlv API will re-route the packet */
4122 return NET_RX_SUCCESS
;
4126 * batadv_roam_tvlv_unicast_handler_v1() - process incoming tt roam tvlv
4128 * @bat_priv: the bat priv with all the soft interface information
4129 * @src: mac address of tt tvlv sender
4130 * @dst: mac address of tt tvlv recipient
4131 * @tvlv_value: tvlv buffer containing the tt data
4132 * @tvlv_value_len: tvlv buffer length
4134 * Return: NET_RX_DROP if the tt roam tvlv is to be re-routed, NET_RX_SUCCESS
4137 static int batadv_roam_tvlv_unicast_handler_v1(struct batadv_priv
*bat_priv
,
4142 struct batadv_tvlv_roam_adv
*roaming_adv
;
4143 struct batadv_orig_node
*orig_node
= NULL
;
4145 /* If this node is not the intended recipient of the
4146 * roaming advertisement the packet is forwarded
4147 * (the tvlv API will re-route the packet).
4149 if (!batadv_is_my_mac(bat_priv
, dst
))
4152 if (tvlv_value_len
< sizeof(*roaming_adv
))
4155 orig_node
= batadv_orig_hash_find(bat_priv
, src
);
4159 batadv_inc_counter(bat_priv
, BATADV_CNT_TT_ROAM_ADV_RX
);
4160 roaming_adv
= (struct batadv_tvlv_roam_adv
*)tvlv_value
;
4162 batadv_dbg(BATADV_DBG_TT
, bat_priv
,
4163 "Received ROAMING_ADV from %pM (client %pM)\n",
4164 src
, roaming_adv
->client
);
4166 batadv_tt_global_add(bat_priv
, orig_node
, roaming_adv
->client
,
4167 ntohs(roaming_adv
->vid
), BATADV_TT_CLIENT_ROAM
,
4168 atomic_read(&orig_node
->last_ttvn
) + 1);
4172 batadv_orig_node_put(orig_node
);
4173 return NET_RX_SUCCESS
;
4177 * batadv_tt_init() - initialise the translation table internals
4178 * @bat_priv: the bat priv with all the soft interface information
4180 * Return: 0 on success or negative error number in case of failure.
4182 int batadv_tt_init(struct batadv_priv
*bat_priv
)
4186 /* synchronized flags must be remote */
4187 BUILD_BUG_ON(!(BATADV_TT_SYNC_MASK
& BATADV_TT_REMOTE_MASK
));
4189 ret
= batadv_tt_local_init(bat_priv
);
4193 ret
= batadv_tt_global_init(bat_priv
);
4197 batadv_tvlv_handler_register(bat_priv
, batadv_tt_tvlv_ogm_handler_v1
,
4198 batadv_tt_tvlv_unicast_handler_v1
,
4199 BATADV_TVLV_TT
, 1, BATADV_NO_FLAGS
);
4201 batadv_tvlv_handler_register(bat_priv
, NULL
,
4202 batadv_roam_tvlv_unicast_handler_v1
,
4203 BATADV_TVLV_ROAM
, 1, BATADV_NO_FLAGS
);
4205 INIT_DELAYED_WORK(&bat_priv
->tt
.work
, batadv_tt_purge
);
4206 queue_delayed_work(batadv_event_workqueue
, &bat_priv
->tt
.work
,
4207 msecs_to_jiffies(BATADV_TT_WORK_PERIOD
));
4213 * batadv_tt_global_is_isolated() - check if a client is marked as isolated
4214 * @bat_priv: the bat priv with all the soft interface information
4215 * @addr: the mac address of the client
4216 * @vid: the identifier of the VLAN where this client is connected
4218 * Return: true if the client is marked with the TT_CLIENT_ISOLA flag, false
4221 bool batadv_tt_global_is_isolated(struct batadv_priv
*bat_priv
,
4222 const u8
*addr
, unsigned short vid
)
4224 struct batadv_tt_global_entry
*tt
;
4227 tt
= batadv_tt_global_hash_find(bat_priv
, addr
, vid
);
4231 ret
= tt
->common
.flags
& BATADV_TT_CLIENT_ISOLA
;
4233 batadv_tt_global_entry_put(tt
);
4239 * batadv_tt_cache_init() - Initialize tt memory object cache
4241 * Return: 0 on success or negative error number in case of failure.
4243 int __init
batadv_tt_cache_init(void)
4245 size_t tl_size
= sizeof(struct batadv_tt_local_entry
);
4246 size_t tg_size
= sizeof(struct batadv_tt_global_entry
);
4247 size_t tt_orig_size
= sizeof(struct batadv_tt_orig_list_entry
);
4248 size_t tt_change_size
= sizeof(struct batadv_tt_change_node
);
4249 size_t tt_req_size
= sizeof(struct batadv_tt_req_node
);
4250 size_t tt_roam_size
= sizeof(struct batadv_tt_roam_node
);
4252 batadv_tl_cache
= kmem_cache_create("batadv_tl_cache", tl_size
, 0,
4253 SLAB_HWCACHE_ALIGN
, NULL
);
4254 if (!batadv_tl_cache
)
4257 batadv_tg_cache
= kmem_cache_create("batadv_tg_cache", tg_size
, 0,
4258 SLAB_HWCACHE_ALIGN
, NULL
);
4259 if (!batadv_tg_cache
)
4260 goto err_tt_tl_destroy
;
4262 batadv_tt_orig_cache
= kmem_cache_create("batadv_tt_orig_cache",
4264 SLAB_HWCACHE_ALIGN
, NULL
);
4265 if (!batadv_tt_orig_cache
)
4266 goto err_tt_tg_destroy
;
4268 batadv_tt_change_cache
= kmem_cache_create("batadv_tt_change_cache",
4270 SLAB_HWCACHE_ALIGN
, NULL
);
4271 if (!batadv_tt_change_cache
)
4272 goto err_tt_orig_destroy
;
4274 batadv_tt_req_cache
= kmem_cache_create("batadv_tt_req_cache",
4276 SLAB_HWCACHE_ALIGN
, NULL
);
4277 if (!batadv_tt_req_cache
)
4278 goto err_tt_change_destroy
;
4280 batadv_tt_roam_cache
= kmem_cache_create("batadv_tt_roam_cache",
4282 SLAB_HWCACHE_ALIGN
, NULL
);
4283 if (!batadv_tt_roam_cache
)
4284 goto err_tt_req_destroy
;
4289 kmem_cache_destroy(batadv_tt_req_cache
);
4290 batadv_tt_req_cache
= NULL
;
4291 err_tt_change_destroy
:
4292 kmem_cache_destroy(batadv_tt_change_cache
);
4293 batadv_tt_change_cache
= NULL
;
4294 err_tt_orig_destroy
:
4295 kmem_cache_destroy(batadv_tt_orig_cache
);
4296 batadv_tt_orig_cache
= NULL
;
4298 kmem_cache_destroy(batadv_tg_cache
);
4299 batadv_tg_cache
= NULL
;
4301 kmem_cache_destroy(batadv_tl_cache
);
4302 batadv_tl_cache
= NULL
;
4308 * batadv_tt_cache_destroy() - Destroy tt memory object cache
4310 void batadv_tt_cache_destroy(void)
4312 kmem_cache_destroy(batadv_tl_cache
);
4313 kmem_cache_destroy(batadv_tg_cache
);
4314 kmem_cache_destroy(batadv_tt_orig_cache
);
4315 kmem_cache_destroy(batadv_tt_change_cache
);
4316 kmem_cache_destroy(batadv_tt_req_cache
);
4317 kmem_cache_destroy(batadv_tt_roam_cache
);