1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2009-2019 B.A.T.M.A.N. contributors:
4 * Marek Lindner, Simon Wunderlich
7 #include "originator.h"
10 #include <linux/atomic.h>
11 #include <linux/errno.h>
12 #include <linux/etherdevice.h>
13 #include <linux/gfp.h>
14 #include <linux/jiffies.h>
15 #include <linux/kernel.h>
16 #include <linux/kref.h>
17 #include <linux/list.h>
18 #include <linux/lockdep.h>
19 #include <linux/netdevice.h>
20 #include <linux/netlink.h>
21 #include <linux/rculist.h>
22 #include <linux/rcupdate.h>
23 #include <linux/seq_file.h>
24 #include <linux/skbuff.h>
25 #include <linux/slab.h>
26 #include <linux/spinlock.h>
27 #include <linux/stddef.h>
28 #include <linux/workqueue.h>
30 #include <uapi/linux/batman_adv.h>
33 #include "distributed-arp-table.h"
34 #include "fragmentation.h"
35 #include "gateway_client.h"
36 #include "hard-interface.h"
39 #include "multicast.h"
41 #include "network-coding.h"
43 #include "soft-interface.h"
44 #include "translation-table.h"
47 static struct lock_class_key batadv_orig_hash_lock_class_key
;
50 * batadv_orig_hash_find() - Find and return originator from orig_hash
51 * @bat_priv: the bat priv with all the soft interface information
52 * @data: mac address of the originator
54 * Return: orig_node (with increased refcnt), NULL on errors
56 struct batadv_orig_node
*
57 batadv_orig_hash_find(struct batadv_priv
*bat_priv
, const void *data
)
59 struct batadv_hashtable
*hash
= bat_priv
->orig_hash
;
60 struct hlist_head
*head
;
61 struct batadv_orig_node
*orig_node
, *orig_node_tmp
= NULL
;
67 index
= batadv_choose_orig(data
, hash
->size
);
68 head
= &hash
->table
[index
];
71 hlist_for_each_entry_rcu(orig_node
, head
, hash_entry
) {
72 if (!batadv_compare_eth(orig_node
, data
))
75 if (!kref_get_unless_zero(&orig_node
->refcount
))
78 orig_node_tmp
= orig_node
;
86 static void batadv_purge_orig(struct work_struct
*work
);
89 * batadv_compare_orig() - comparing function used in the originator hash table
90 * @node: node in the local table
91 * @data2: second object to compare the node to
93 * Return: true if they are the same originator
95 bool batadv_compare_orig(const struct hlist_node
*node
, const void *data2
)
97 const void *data1
= container_of(node
, struct batadv_orig_node
,
100 return batadv_compare_eth(data1
, data2
);
104 * batadv_orig_node_vlan_get() - get an orig_node_vlan object
105 * @orig_node: the originator serving the VLAN
106 * @vid: the VLAN identifier
108 * Return: the vlan object identified by vid and belonging to orig_node or NULL
109 * if it does not exist.
111 struct batadv_orig_node_vlan
*
112 batadv_orig_node_vlan_get(struct batadv_orig_node
*orig_node
,
115 struct batadv_orig_node_vlan
*vlan
= NULL
, *tmp
;
118 hlist_for_each_entry_rcu(tmp
, &orig_node
->vlan_list
, list
) {
122 if (!kref_get_unless_zero(&tmp
->refcount
))
135 * batadv_orig_node_vlan_new() - search and possibly create an orig_node_vlan
137 * @orig_node: the originator serving the VLAN
138 * @vid: the VLAN identifier
140 * Return: NULL in case of failure or the vlan object identified by vid and
141 * belonging to orig_node otherwise. The object is created and added to the list
142 * if it does not exist.
144 * The object is returned with refcounter increased by 1.
146 struct batadv_orig_node_vlan
*
147 batadv_orig_node_vlan_new(struct batadv_orig_node
*orig_node
,
150 struct batadv_orig_node_vlan
*vlan
;
152 spin_lock_bh(&orig_node
->vlan_list_lock
);
154 /* first look if an object for this vid already exists */
155 vlan
= batadv_orig_node_vlan_get(orig_node
, vid
);
159 vlan
= kzalloc(sizeof(*vlan
), GFP_ATOMIC
);
163 kref_init(&vlan
->refcount
);
166 kref_get(&vlan
->refcount
);
167 hlist_add_head_rcu(&vlan
->list
, &orig_node
->vlan_list
);
170 spin_unlock_bh(&orig_node
->vlan_list_lock
);
176 * batadv_orig_node_vlan_release() - release originator-vlan object from lists
177 * and queue for free after rcu grace period
178 * @ref: kref pointer of the originator-vlan object
180 static void batadv_orig_node_vlan_release(struct kref
*ref
)
182 struct batadv_orig_node_vlan
*orig_vlan
;
184 orig_vlan
= container_of(ref
, struct batadv_orig_node_vlan
, refcount
);
186 kfree_rcu(orig_vlan
, rcu
);
190 * batadv_orig_node_vlan_put() - decrement the refcounter and possibly release
191 * the originator-vlan object
192 * @orig_vlan: the originator-vlan object to release
194 void batadv_orig_node_vlan_put(struct batadv_orig_node_vlan
*orig_vlan
)
196 kref_put(&orig_vlan
->refcount
, batadv_orig_node_vlan_release
);
200 * batadv_originator_init() - Initialize all originator structures
201 * @bat_priv: the bat priv with all the soft interface information
203 * Return: 0 on success or negative error number in case of failure
205 int batadv_originator_init(struct batadv_priv
*bat_priv
)
207 if (bat_priv
->orig_hash
)
210 bat_priv
->orig_hash
= batadv_hash_new(1024);
212 if (!bat_priv
->orig_hash
)
215 batadv_hash_set_lock_class(bat_priv
->orig_hash
,
216 &batadv_orig_hash_lock_class_key
);
218 INIT_DELAYED_WORK(&bat_priv
->orig_work
, batadv_purge_orig
);
219 queue_delayed_work(batadv_event_workqueue
,
220 &bat_priv
->orig_work
,
221 msecs_to_jiffies(BATADV_ORIG_WORK_PERIOD
));
230 * batadv_neigh_ifinfo_release() - release neigh_ifinfo from lists and queue for
231 * free after rcu grace period
232 * @ref: kref pointer of the neigh_ifinfo
234 static void batadv_neigh_ifinfo_release(struct kref
*ref
)
236 struct batadv_neigh_ifinfo
*neigh_ifinfo
;
238 neigh_ifinfo
= container_of(ref
, struct batadv_neigh_ifinfo
, refcount
);
240 if (neigh_ifinfo
->if_outgoing
!= BATADV_IF_DEFAULT
)
241 batadv_hardif_put(neigh_ifinfo
->if_outgoing
);
243 kfree_rcu(neigh_ifinfo
, rcu
);
247 * batadv_neigh_ifinfo_put() - decrement the refcounter and possibly release
249 * @neigh_ifinfo: the neigh_ifinfo object to release
251 void batadv_neigh_ifinfo_put(struct batadv_neigh_ifinfo
*neigh_ifinfo
)
253 kref_put(&neigh_ifinfo
->refcount
, batadv_neigh_ifinfo_release
);
257 * batadv_hardif_neigh_release() - release hardif neigh node from lists and
258 * queue for free after rcu grace period
259 * @ref: kref pointer of the neigh_node
261 static void batadv_hardif_neigh_release(struct kref
*ref
)
263 struct batadv_hardif_neigh_node
*hardif_neigh
;
265 hardif_neigh
= container_of(ref
, struct batadv_hardif_neigh_node
,
268 spin_lock_bh(&hardif_neigh
->if_incoming
->neigh_list_lock
);
269 hlist_del_init_rcu(&hardif_neigh
->list
);
270 spin_unlock_bh(&hardif_neigh
->if_incoming
->neigh_list_lock
);
272 batadv_hardif_put(hardif_neigh
->if_incoming
);
273 kfree_rcu(hardif_neigh
, rcu
);
277 * batadv_hardif_neigh_put() - decrement the hardif neighbors refcounter
278 * and possibly release it
279 * @hardif_neigh: hardif neigh neighbor to free
281 void batadv_hardif_neigh_put(struct batadv_hardif_neigh_node
*hardif_neigh
)
283 kref_put(&hardif_neigh
->refcount
, batadv_hardif_neigh_release
);
287 * batadv_neigh_node_release() - release neigh_node from lists and queue for
288 * free after rcu grace period
289 * @ref: kref pointer of the neigh_node
291 static void batadv_neigh_node_release(struct kref
*ref
)
293 struct hlist_node
*node_tmp
;
294 struct batadv_neigh_node
*neigh_node
;
295 struct batadv_neigh_ifinfo
*neigh_ifinfo
;
297 neigh_node
= container_of(ref
, struct batadv_neigh_node
, refcount
);
299 hlist_for_each_entry_safe(neigh_ifinfo
, node_tmp
,
300 &neigh_node
->ifinfo_list
, list
) {
301 batadv_neigh_ifinfo_put(neigh_ifinfo
);
304 batadv_hardif_neigh_put(neigh_node
->hardif_neigh
);
306 batadv_hardif_put(neigh_node
->if_incoming
);
308 kfree_rcu(neigh_node
, rcu
);
312 * batadv_neigh_node_put() - decrement the neighbors refcounter and possibly
314 * @neigh_node: neigh neighbor to free
316 void batadv_neigh_node_put(struct batadv_neigh_node
*neigh_node
)
318 kref_put(&neigh_node
->refcount
, batadv_neigh_node_release
);
322 * batadv_orig_router_get() - router to the originator depending on iface
323 * @orig_node: the orig node for the router
324 * @if_outgoing: the interface where the payload packet has been received or
325 * the OGM should be sent to
327 * Return: the neighbor which should be router for this orig_node/iface.
329 * The object is returned with refcounter increased by 1.
331 struct batadv_neigh_node
*
332 batadv_orig_router_get(struct batadv_orig_node
*orig_node
,
333 const struct batadv_hard_iface
*if_outgoing
)
335 struct batadv_orig_ifinfo
*orig_ifinfo
;
336 struct batadv_neigh_node
*router
= NULL
;
339 hlist_for_each_entry_rcu(orig_ifinfo
, &orig_node
->ifinfo_list
, list
) {
340 if (orig_ifinfo
->if_outgoing
!= if_outgoing
)
343 router
= rcu_dereference(orig_ifinfo
->router
);
347 if (router
&& !kref_get_unless_zero(&router
->refcount
))
355 * batadv_orig_ifinfo_get() - find the ifinfo from an orig_node
356 * @orig_node: the orig node to be queried
357 * @if_outgoing: the interface for which the ifinfo should be acquired
359 * Return: the requested orig_ifinfo or NULL if not found.
361 * The object is returned with refcounter increased by 1.
363 struct batadv_orig_ifinfo
*
364 batadv_orig_ifinfo_get(struct batadv_orig_node
*orig_node
,
365 struct batadv_hard_iface
*if_outgoing
)
367 struct batadv_orig_ifinfo
*tmp
, *orig_ifinfo
= NULL
;
370 hlist_for_each_entry_rcu(tmp
, &orig_node
->ifinfo_list
,
372 if (tmp
->if_outgoing
!= if_outgoing
)
375 if (!kref_get_unless_zero(&tmp
->refcount
))
387 * batadv_orig_ifinfo_new() - search and possibly create an orig_ifinfo object
388 * @orig_node: the orig node to be queried
389 * @if_outgoing: the interface for which the ifinfo should be acquired
391 * Return: NULL in case of failure or the orig_ifinfo object for the if_outgoing
392 * interface otherwise. The object is created and added to the list
393 * if it does not exist.
395 * The object is returned with refcounter increased by 1.
397 struct batadv_orig_ifinfo
*
398 batadv_orig_ifinfo_new(struct batadv_orig_node
*orig_node
,
399 struct batadv_hard_iface
*if_outgoing
)
401 struct batadv_orig_ifinfo
*orig_ifinfo
;
402 unsigned long reset_time
;
404 spin_lock_bh(&orig_node
->neigh_list_lock
);
406 orig_ifinfo
= batadv_orig_ifinfo_get(orig_node
, if_outgoing
);
410 orig_ifinfo
= kzalloc(sizeof(*orig_ifinfo
), GFP_ATOMIC
);
414 if (if_outgoing
!= BATADV_IF_DEFAULT
)
415 kref_get(&if_outgoing
->refcount
);
417 reset_time
= jiffies
- 1;
418 reset_time
-= msecs_to_jiffies(BATADV_RESET_PROTECTION_MS
);
419 orig_ifinfo
->batman_seqno_reset
= reset_time
;
420 orig_ifinfo
->if_outgoing
= if_outgoing
;
421 INIT_HLIST_NODE(&orig_ifinfo
->list
);
422 kref_init(&orig_ifinfo
->refcount
);
424 kref_get(&orig_ifinfo
->refcount
);
425 hlist_add_head_rcu(&orig_ifinfo
->list
,
426 &orig_node
->ifinfo_list
);
428 spin_unlock_bh(&orig_node
->neigh_list_lock
);
433 * batadv_neigh_ifinfo_get() - find the ifinfo from an neigh_node
434 * @neigh: the neigh node to be queried
435 * @if_outgoing: the interface for which the ifinfo should be acquired
437 * The object is returned with refcounter increased by 1.
439 * Return: the requested neigh_ifinfo or NULL if not found
441 struct batadv_neigh_ifinfo
*
442 batadv_neigh_ifinfo_get(struct batadv_neigh_node
*neigh
,
443 struct batadv_hard_iface
*if_outgoing
)
445 struct batadv_neigh_ifinfo
*neigh_ifinfo
= NULL
,
449 hlist_for_each_entry_rcu(tmp_neigh_ifinfo
, &neigh
->ifinfo_list
,
451 if (tmp_neigh_ifinfo
->if_outgoing
!= if_outgoing
)
454 if (!kref_get_unless_zero(&tmp_neigh_ifinfo
->refcount
))
457 neigh_ifinfo
= tmp_neigh_ifinfo
;
466 * batadv_neigh_ifinfo_new() - search and possibly create an neigh_ifinfo object
467 * @neigh: the neigh node to be queried
468 * @if_outgoing: the interface for which the ifinfo should be acquired
470 * Return: NULL in case of failure or the neigh_ifinfo object for the
471 * if_outgoing interface otherwise. The object is created and added to the list
472 * if it does not exist.
474 * The object is returned with refcounter increased by 1.
476 struct batadv_neigh_ifinfo
*
477 batadv_neigh_ifinfo_new(struct batadv_neigh_node
*neigh
,
478 struct batadv_hard_iface
*if_outgoing
)
480 struct batadv_neigh_ifinfo
*neigh_ifinfo
;
482 spin_lock_bh(&neigh
->ifinfo_lock
);
484 neigh_ifinfo
= batadv_neigh_ifinfo_get(neigh
, if_outgoing
);
488 neigh_ifinfo
= kzalloc(sizeof(*neigh_ifinfo
), GFP_ATOMIC
);
493 kref_get(&if_outgoing
->refcount
);
495 INIT_HLIST_NODE(&neigh_ifinfo
->list
);
496 kref_init(&neigh_ifinfo
->refcount
);
497 neigh_ifinfo
->if_outgoing
= if_outgoing
;
499 kref_get(&neigh_ifinfo
->refcount
);
500 hlist_add_head_rcu(&neigh_ifinfo
->list
, &neigh
->ifinfo_list
);
503 spin_unlock_bh(&neigh
->ifinfo_lock
);
509 * batadv_neigh_node_get() - retrieve a neighbour from the list
510 * @orig_node: originator which the neighbour belongs to
511 * @hard_iface: the interface where this neighbour is connected to
512 * @addr: the address of the neighbour
514 * Looks for and possibly returns a neighbour belonging to this originator list
515 * which is connected through the provided hard interface.
517 * Return: neighbor when found. Othwerwise NULL
519 static struct batadv_neigh_node
*
520 batadv_neigh_node_get(const struct batadv_orig_node
*orig_node
,
521 const struct batadv_hard_iface
*hard_iface
,
524 struct batadv_neigh_node
*tmp_neigh_node
, *res
= NULL
;
527 hlist_for_each_entry_rcu(tmp_neigh_node
, &orig_node
->neigh_list
, list
) {
528 if (!batadv_compare_eth(tmp_neigh_node
->addr
, addr
))
531 if (tmp_neigh_node
->if_incoming
!= hard_iface
)
534 if (!kref_get_unless_zero(&tmp_neigh_node
->refcount
))
537 res
= tmp_neigh_node
;
546 * batadv_hardif_neigh_create() - create a hardif neighbour node
547 * @hard_iface: the interface this neighbour is connected to
548 * @neigh_addr: the interface address of the neighbour to retrieve
549 * @orig_node: originator object representing the neighbour
551 * Return: the hardif neighbour node if found or created or NULL otherwise.
553 static struct batadv_hardif_neigh_node
*
554 batadv_hardif_neigh_create(struct batadv_hard_iface
*hard_iface
,
555 const u8
*neigh_addr
,
556 struct batadv_orig_node
*orig_node
)
558 struct batadv_priv
*bat_priv
= netdev_priv(hard_iface
->soft_iface
);
559 struct batadv_hardif_neigh_node
*hardif_neigh
;
561 spin_lock_bh(&hard_iface
->neigh_list_lock
);
563 /* check if neighbor hasn't been added in the meantime */
564 hardif_neigh
= batadv_hardif_neigh_get(hard_iface
, neigh_addr
);
568 hardif_neigh
= kzalloc(sizeof(*hardif_neigh
), GFP_ATOMIC
);
572 kref_get(&hard_iface
->refcount
);
573 INIT_HLIST_NODE(&hardif_neigh
->list
);
574 ether_addr_copy(hardif_neigh
->addr
, neigh_addr
);
575 ether_addr_copy(hardif_neigh
->orig
, orig_node
->orig
);
576 hardif_neigh
->if_incoming
= hard_iface
;
577 hardif_neigh
->last_seen
= jiffies
;
579 kref_init(&hardif_neigh
->refcount
);
581 if (bat_priv
->algo_ops
->neigh
.hardif_init
)
582 bat_priv
->algo_ops
->neigh
.hardif_init(hardif_neigh
);
584 hlist_add_head_rcu(&hardif_neigh
->list
, &hard_iface
->neigh_list
);
587 spin_unlock_bh(&hard_iface
->neigh_list_lock
);
592 * batadv_hardif_neigh_get_or_create() - retrieve or create a hardif neighbour
594 * @hard_iface: the interface this neighbour is connected to
595 * @neigh_addr: the interface address of the neighbour to retrieve
596 * @orig_node: originator object representing the neighbour
598 * Return: the hardif neighbour node if found or created or NULL otherwise.
600 static struct batadv_hardif_neigh_node
*
601 batadv_hardif_neigh_get_or_create(struct batadv_hard_iface
*hard_iface
,
602 const u8
*neigh_addr
,
603 struct batadv_orig_node
*orig_node
)
605 struct batadv_hardif_neigh_node
*hardif_neigh
;
607 /* first check without locking to avoid the overhead */
608 hardif_neigh
= batadv_hardif_neigh_get(hard_iface
, neigh_addr
);
612 return batadv_hardif_neigh_create(hard_iface
, neigh_addr
, orig_node
);
616 * batadv_hardif_neigh_get() - retrieve a hardif neighbour from the list
617 * @hard_iface: the interface where this neighbour is connected to
618 * @neigh_addr: the address of the neighbour
620 * Looks for and possibly returns a neighbour belonging to this hard interface.
622 * Return: neighbor when found. Othwerwise NULL
624 struct batadv_hardif_neigh_node
*
625 batadv_hardif_neigh_get(const struct batadv_hard_iface
*hard_iface
,
626 const u8
*neigh_addr
)
628 struct batadv_hardif_neigh_node
*tmp_hardif_neigh
, *hardif_neigh
= NULL
;
631 hlist_for_each_entry_rcu(tmp_hardif_neigh
,
632 &hard_iface
->neigh_list
, list
) {
633 if (!batadv_compare_eth(tmp_hardif_neigh
->addr
, neigh_addr
))
636 if (!kref_get_unless_zero(&tmp_hardif_neigh
->refcount
))
639 hardif_neigh
= tmp_hardif_neigh
;
648 * batadv_neigh_node_create() - create a neigh node object
649 * @orig_node: originator object representing the neighbour
650 * @hard_iface: the interface where the neighbour is connected to
651 * @neigh_addr: the mac address of the neighbour interface
653 * Allocates a new neigh_node object and initialises all the generic fields.
655 * Return: the neighbour node if found or created or NULL otherwise.
657 static struct batadv_neigh_node
*
658 batadv_neigh_node_create(struct batadv_orig_node
*orig_node
,
659 struct batadv_hard_iface
*hard_iface
,
660 const u8
*neigh_addr
)
662 struct batadv_neigh_node
*neigh_node
;
663 struct batadv_hardif_neigh_node
*hardif_neigh
= NULL
;
665 spin_lock_bh(&orig_node
->neigh_list_lock
);
667 neigh_node
= batadv_neigh_node_get(orig_node
, hard_iface
, neigh_addr
);
671 hardif_neigh
= batadv_hardif_neigh_get_or_create(hard_iface
,
672 neigh_addr
, orig_node
);
676 neigh_node
= kzalloc(sizeof(*neigh_node
), GFP_ATOMIC
);
680 INIT_HLIST_NODE(&neigh_node
->list
);
681 INIT_HLIST_HEAD(&neigh_node
->ifinfo_list
);
682 spin_lock_init(&neigh_node
->ifinfo_lock
);
684 kref_get(&hard_iface
->refcount
);
685 ether_addr_copy(neigh_node
->addr
, neigh_addr
);
686 neigh_node
->if_incoming
= hard_iface
;
687 neigh_node
->orig_node
= orig_node
;
688 neigh_node
->last_seen
= jiffies
;
690 /* increment unique neighbor refcount */
691 kref_get(&hardif_neigh
->refcount
);
692 neigh_node
->hardif_neigh
= hardif_neigh
;
694 /* extra reference for return */
695 kref_init(&neigh_node
->refcount
);
697 kref_get(&neigh_node
->refcount
);
698 hlist_add_head_rcu(&neigh_node
->list
, &orig_node
->neigh_list
);
700 batadv_dbg(BATADV_DBG_BATMAN
, orig_node
->bat_priv
,
701 "Creating new neighbor %pM for orig_node %pM on interface %s\n",
702 neigh_addr
, orig_node
->orig
, hard_iface
->net_dev
->name
);
705 spin_unlock_bh(&orig_node
->neigh_list_lock
);
708 batadv_hardif_neigh_put(hardif_neigh
);
713 * batadv_neigh_node_get_or_create() - retrieve or create a neigh node object
714 * @orig_node: originator object representing the neighbour
715 * @hard_iface: the interface where the neighbour is connected to
716 * @neigh_addr: the mac address of the neighbour interface
718 * Return: the neighbour node if found or created or NULL otherwise.
720 struct batadv_neigh_node
*
721 batadv_neigh_node_get_or_create(struct batadv_orig_node
*orig_node
,
722 struct batadv_hard_iface
*hard_iface
,
723 const u8
*neigh_addr
)
725 struct batadv_neigh_node
*neigh_node
;
727 /* first check without locking to avoid the overhead */
728 neigh_node
= batadv_neigh_node_get(orig_node
, hard_iface
, neigh_addr
);
732 return batadv_neigh_node_create(orig_node
, hard_iface
, neigh_addr
);
735 #ifdef CONFIG_BATMAN_ADV_DEBUGFS
737 * batadv_hardif_neigh_seq_print_text() - print the single hop neighbour list
738 * @seq: neighbour table seq_file struct
743 int batadv_hardif_neigh_seq_print_text(struct seq_file
*seq
, void *offset
)
745 struct net_device
*net_dev
= (struct net_device
*)seq
->private;
746 struct batadv_priv
*bat_priv
= netdev_priv(net_dev
);
747 struct batadv_hard_iface
*primary_if
;
749 primary_if
= batadv_seq_print_text_primary_if_get(seq
);
753 seq_printf(seq
, "[B.A.T.M.A.N. adv %s, MainIF/MAC: %s/%pM (%s %s)]\n",
754 BATADV_SOURCE_VERSION
, primary_if
->net_dev
->name
,
755 primary_if
->net_dev
->dev_addr
, net_dev
->name
,
756 bat_priv
->algo_ops
->name
);
758 batadv_hardif_put(primary_if
);
760 if (!bat_priv
->algo_ops
->neigh
.print
) {
762 "No printing function for this routing protocol\n");
766 bat_priv
->algo_ops
->neigh
.print(bat_priv
, seq
);
772 * batadv_hardif_neigh_dump() - Dump to netlink the neighbor infos for a
773 * specific outgoing interface
774 * @msg: message to dump into
775 * @cb: parameters for the dump
777 * Return: 0 or error value
779 int batadv_hardif_neigh_dump(struct sk_buff
*msg
, struct netlink_callback
*cb
)
781 struct net
*net
= sock_net(cb
->skb
->sk
);
782 struct net_device
*soft_iface
;
783 struct net_device
*hard_iface
= NULL
;
784 struct batadv_hard_iface
*hardif
= BATADV_IF_DEFAULT
;
785 struct batadv_priv
*bat_priv
;
786 struct batadv_hard_iface
*primary_if
= NULL
;
788 int ifindex
, hard_ifindex
;
790 ifindex
= batadv_netlink_get_ifindex(cb
->nlh
, BATADV_ATTR_MESH_IFINDEX
);
794 soft_iface
= dev_get_by_index(net
, ifindex
);
795 if (!soft_iface
|| !batadv_softif_is_valid(soft_iface
)) {
800 bat_priv
= netdev_priv(soft_iface
);
802 primary_if
= batadv_primary_if_get_selected(bat_priv
);
803 if (!primary_if
|| primary_if
->if_status
!= BATADV_IF_ACTIVE
) {
808 hard_ifindex
= batadv_netlink_get_ifindex(cb
->nlh
,
809 BATADV_ATTR_HARD_IFINDEX
);
811 hard_iface
= dev_get_by_index(net
, hard_ifindex
);
813 hardif
= batadv_hardif_get_by_netdev(hard_iface
);
820 if (hardif
->soft_iface
!= soft_iface
) {
826 if (!bat_priv
->algo_ops
->neigh
.dump
) {
831 bat_priv
->algo_ops
->neigh
.dump(msg
, cb
, bat_priv
, hardif
);
837 batadv_hardif_put(hardif
);
841 batadv_hardif_put(primary_if
);
849 * batadv_orig_ifinfo_release() - release orig_ifinfo from lists and queue for
850 * free after rcu grace period
851 * @ref: kref pointer of the orig_ifinfo
853 static void batadv_orig_ifinfo_release(struct kref
*ref
)
855 struct batadv_orig_ifinfo
*orig_ifinfo
;
856 struct batadv_neigh_node
*router
;
858 orig_ifinfo
= container_of(ref
, struct batadv_orig_ifinfo
, refcount
);
860 if (orig_ifinfo
->if_outgoing
!= BATADV_IF_DEFAULT
)
861 batadv_hardif_put(orig_ifinfo
->if_outgoing
);
863 /* this is the last reference to this object */
864 router
= rcu_dereference_protected(orig_ifinfo
->router
, true);
866 batadv_neigh_node_put(router
);
868 kfree_rcu(orig_ifinfo
, rcu
);
872 * batadv_orig_ifinfo_put() - decrement the refcounter and possibly release
874 * @orig_ifinfo: the orig_ifinfo object to release
876 void batadv_orig_ifinfo_put(struct batadv_orig_ifinfo
*orig_ifinfo
)
878 kref_put(&orig_ifinfo
->refcount
, batadv_orig_ifinfo_release
);
882 * batadv_orig_node_free_rcu() - free the orig_node
883 * @rcu: rcu pointer of the orig_node
885 static void batadv_orig_node_free_rcu(struct rcu_head
*rcu
)
887 struct batadv_orig_node
*orig_node
;
889 orig_node
= container_of(rcu
, struct batadv_orig_node
, rcu
);
891 batadv_mcast_purge_orig(orig_node
);
893 batadv_frag_purge_orig(orig_node
, NULL
);
895 kfree(orig_node
->tt_buff
);
900 * batadv_orig_node_release() - release orig_node from lists and queue for
901 * free after rcu grace period
902 * @ref: kref pointer of the orig_node
904 static void batadv_orig_node_release(struct kref
*ref
)
906 struct hlist_node
*node_tmp
;
907 struct batadv_neigh_node
*neigh_node
;
908 struct batadv_orig_node
*orig_node
;
909 struct batadv_orig_ifinfo
*orig_ifinfo
;
910 struct batadv_orig_node_vlan
*vlan
;
911 struct batadv_orig_ifinfo
*last_candidate
;
913 orig_node
= container_of(ref
, struct batadv_orig_node
, refcount
);
915 spin_lock_bh(&orig_node
->neigh_list_lock
);
917 /* for all neighbors towards this originator ... */
918 hlist_for_each_entry_safe(neigh_node
, node_tmp
,
919 &orig_node
->neigh_list
, list
) {
920 hlist_del_rcu(&neigh_node
->list
);
921 batadv_neigh_node_put(neigh_node
);
924 hlist_for_each_entry_safe(orig_ifinfo
, node_tmp
,
925 &orig_node
->ifinfo_list
, list
) {
926 hlist_del_rcu(&orig_ifinfo
->list
);
927 batadv_orig_ifinfo_put(orig_ifinfo
);
930 last_candidate
= orig_node
->last_bonding_candidate
;
931 orig_node
->last_bonding_candidate
= NULL
;
932 spin_unlock_bh(&orig_node
->neigh_list_lock
);
935 batadv_orig_ifinfo_put(last_candidate
);
937 spin_lock_bh(&orig_node
->vlan_list_lock
);
938 hlist_for_each_entry_safe(vlan
, node_tmp
, &orig_node
->vlan_list
, list
) {
939 hlist_del_rcu(&vlan
->list
);
940 batadv_orig_node_vlan_put(vlan
);
942 spin_unlock_bh(&orig_node
->vlan_list_lock
);
945 batadv_nc_purge_orig(orig_node
->bat_priv
, orig_node
, NULL
);
947 call_rcu(&orig_node
->rcu
, batadv_orig_node_free_rcu
);
951 * batadv_orig_node_put() - decrement the orig node refcounter and possibly
953 * @orig_node: the orig node to free
955 void batadv_orig_node_put(struct batadv_orig_node
*orig_node
)
957 kref_put(&orig_node
->refcount
, batadv_orig_node_release
);
961 * batadv_originator_free() - Free all originator structures
962 * @bat_priv: the bat priv with all the soft interface information
964 void batadv_originator_free(struct batadv_priv
*bat_priv
)
966 struct batadv_hashtable
*hash
= bat_priv
->orig_hash
;
967 struct hlist_node
*node_tmp
;
968 struct hlist_head
*head
;
969 spinlock_t
*list_lock
; /* spinlock to protect write access */
970 struct batadv_orig_node
*orig_node
;
976 cancel_delayed_work_sync(&bat_priv
->orig_work
);
978 bat_priv
->orig_hash
= NULL
;
980 for (i
= 0; i
< hash
->size
; i
++) {
981 head
= &hash
->table
[i
];
982 list_lock
= &hash
->list_locks
[i
];
984 spin_lock_bh(list_lock
);
985 hlist_for_each_entry_safe(orig_node
, node_tmp
,
987 hlist_del_rcu(&orig_node
->hash_entry
);
988 batadv_orig_node_put(orig_node
);
990 spin_unlock_bh(list_lock
);
993 batadv_hash_destroy(hash
);
997 * batadv_orig_node_new() - creates a new orig_node
998 * @bat_priv: the bat priv with all the soft interface information
999 * @addr: the mac address of the originator
1001 * Creates a new originator object and initialise all the generic fields.
1002 * The new object is not added to the originator list.
1004 * Return: the newly created object or NULL on failure.
1006 struct batadv_orig_node
*batadv_orig_node_new(struct batadv_priv
*bat_priv
,
1009 struct batadv_orig_node
*orig_node
;
1010 struct batadv_orig_node_vlan
*vlan
;
1011 unsigned long reset_time
;
1014 batadv_dbg(BATADV_DBG_BATMAN
, bat_priv
,
1015 "Creating new originator: %pM\n", addr
);
1017 orig_node
= kzalloc(sizeof(*orig_node
), GFP_ATOMIC
);
1021 INIT_HLIST_HEAD(&orig_node
->neigh_list
);
1022 INIT_HLIST_HEAD(&orig_node
->vlan_list
);
1023 INIT_HLIST_HEAD(&orig_node
->ifinfo_list
);
1024 spin_lock_init(&orig_node
->bcast_seqno_lock
);
1025 spin_lock_init(&orig_node
->neigh_list_lock
);
1026 spin_lock_init(&orig_node
->tt_buff_lock
);
1027 spin_lock_init(&orig_node
->tt_lock
);
1028 spin_lock_init(&orig_node
->vlan_list_lock
);
1030 batadv_nc_init_orig(orig_node
);
1032 /* extra reference for return */
1033 kref_init(&orig_node
->refcount
);
1035 orig_node
->bat_priv
= bat_priv
;
1036 ether_addr_copy(orig_node
->orig
, addr
);
1037 batadv_dat_init_orig_node_addr(orig_node
);
1038 atomic_set(&orig_node
->last_ttvn
, 0);
1039 orig_node
->tt_buff
= NULL
;
1040 orig_node
->tt_buff_len
= 0;
1041 orig_node
->last_seen
= jiffies
;
1042 reset_time
= jiffies
- 1 - msecs_to_jiffies(BATADV_RESET_PROTECTION_MS
);
1043 orig_node
->bcast_seqno_reset
= reset_time
;
1045 #ifdef CONFIG_BATMAN_ADV_MCAST
1046 orig_node
->mcast_flags
= BATADV_NO_FLAGS
;
1047 INIT_HLIST_NODE(&orig_node
->mcast_want_all_unsnoopables_node
);
1048 INIT_HLIST_NODE(&orig_node
->mcast_want_all_ipv4_node
);
1049 INIT_HLIST_NODE(&orig_node
->mcast_want_all_ipv6_node
);
1050 spin_lock_init(&orig_node
->mcast_handler_lock
);
1053 /* create a vlan object for the "untagged" LAN */
1054 vlan
= batadv_orig_node_vlan_new(orig_node
, BATADV_NO_FLAGS
);
1056 goto free_orig_node
;
1057 /* batadv_orig_node_vlan_new() increases the refcounter.
1058 * Immediately release vlan since it is not needed anymore in this
1061 batadv_orig_node_vlan_put(vlan
);
1063 for (i
= 0; i
< BATADV_FRAG_BUFFER_COUNT
; i
++) {
1064 INIT_HLIST_HEAD(&orig_node
->fragments
[i
].fragment_list
);
1065 spin_lock_init(&orig_node
->fragments
[i
].lock
);
1066 orig_node
->fragments
[i
].size
= 0;
1076 * batadv_purge_neigh_ifinfo() - purge obsolete ifinfo entries from neighbor
1077 * @bat_priv: the bat priv with all the soft interface information
1078 * @neigh: orig node which is to be checked
1081 batadv_purge_neigh_ifinfo(struct batadv_priv
*bat_priv
,
1082 struct batadv_neigh_node
*neigh
)
1084 struct batadv_neigh_ifinfo
*neigh_ifinfo
;
1085 struct batadv_hard_iface
*if_outgoing
;
1086 struct hlist_node
*node_tmp
;
1088 spin_lock_bh(&neigh
->ifinfo_lock
);
1090 /* for all ifinfo objects for this neighinator */
1091 hlist_for_each_entry_safe(neigh_ifinfo
, node_tmp
,
1092 &neigh
->ifinfo_list
, list
) {
1093 if_outgoing
= neigh_ifinfo
->if_outgoing
;
1095 /* always keep the default interface */
1096 if (if_outgoing
== BATADV_IF_DEFAULT
)
1099 /* don't purge if the interface is not (going) down */
1100 if (if_outgoing
->if_status
!= BATADV_IF_INACTIVE
&&
1101 if_outgoing
->if_status
!= BATADV_IF_NOT_IN_USE
&&
1102 if_outgoing
->if_status
!= BATADV_IF_TO_BE_REMOVED
)
1105 batadv_dbg(BATADV_DBG_BATMAN
, bat_priv
,
1106 "neighbor/ifinfo purge: neighbor %pM, iface: %s\n",
1107 neigh
->addr
, if_outgoing
->net_dev
->name
);
1109 hlist_del_rcu(&neigh_ifinfo
->list
);
1110 batadv_neigh_ifinfo_put(neigh_ifinfo
);
1113 spin_unlock_bh(&neigh
->ifinfo_lock
);
1117 * batadv_purge_orig_ifinfo() - purge obsolete ifinfo entries from originator
1118 * @bat_priv: the bat priv with all the soft interface information
1119 * @orig_node: orig node which is to be checked
1121 * Return: true if any ifinfo entry was purged, false otherwise.
1124 batadv_purge_orig_ifinfo(struct batadv_priv
*bat_priv
,
1125 struct batadv_orig_node
*orig_node
)
1127 struct batadv_orig_ifinfo
*orig_ifinfo
;
1128 struct batadv_hard_iface
*if_outgoing
;
1129 struct hlist_node
*node_tmp
;
1130 bool ifinfo_purged
= false;
1132 spin_lock_bh(&orig_node
->neigh_list_lock
);
1134 /* for all ifinfo objects for this originator */
1135 hlist_for_each_entry_safe(orig_ifinfo
, node_tmp
,
1136 &orig_node
->ifinfo_list
, list
) {
1137 if_outgoing
= orig_ifinfo
->if_outgoing
;
1139 /* always keep the default interface */
1140 if (if_outgoing
== BATADV_IF_DEFAULT
)
1143 /* don't purge if the interface is not (going) down */
1144 if (if_outgoing
->if_status
!= BATADV_IF_INACTIVE
&&
1145 if_outgoing
->if_status
!= BATADV_IF_NOT_IN_USE
&&
1146 if_outgoing
->if_status
!= BATADV_IF_TO_BE_REMOVED
)
1149 batadv_dbg(BATADV_DBG_BATMAN
, bat_priv
,
1150 "router/ifinfo purge: originator %pM, iface: %s\n",
1151 orig_node
->orig
, if_outgoing
->net_dev
->name
);
1153 ifinfo_purged
= true;
1155 hlist_del_rcu(&orig_ifinfo
->list
);
1156 batadv_orig_ifinfo_put(orig_ifinfo
);
1157 if (orig_node
->last_bonding_candidate
== orig_ifinfo
) {
1158 orig_node
->last_bonding_candidate
= NULL
;
1159 batadv_orig_ifinfo_put(orig_ifinfo
);
1163 spin_unlock_bh(&orig_node
->neigh_list_lock
);
1165 return ifinfo_purged
;
1169 * batadv_purge_orig_neighbors() - purges neighbors from originator
1170 * @bat_priv: the bat priv with all the soft interface information
1171 * @orig_node: orig node which is to be checked
1173 * Return: true if any neighbor was purged, false otherwise
1176 batadv_purge_orig_neighbors(struct batadv_priv
*bat_priv
,
1177 struct batadv_orig_node
*orig_node
)
1179 struct hlist_node
*node_tmp
;
1180 struct batadv_neigh_node
*neigh_node
;
1181 bool neigh_purged
= false;
1182 unsigned long last_seen
;
1183 struct batadv_hard_iface
*if_incoming
;
1185 spin_lock_bh(&orig_node
->neigh_list_lock
);
1187 /* for all neighbors towards this originator ... */
1188 hlist_for_each_entry_safe(neigh_node
, node_tmp
,
1189 &orig_node
->neigh_list
, list
) {
1190 last_seen
= neigh_node
->last_seen
;
1191 if_incoming
= neigh_node
->if_incoming
;
1193 if (batadv_has_timed_out(last_seen
, BATADV_PURGE_TIMEOUT
) ||
1194 if_incoming
->if_status
== BATADV_IF_INACTIVE
||
1195 if_incoming
->if_status
== BATADV_IF_NOT_IN_USE
||
1196 if_incoming
->if_status
== BATADV_IF_TO_BE_REMOVED
) {
1197 if (if_incoming
->if_status
== BATADV_IF_INACTIVE
||
1198 if_incoming
->if_status
== BATADV_IF_NOT_IN_USE
||
1199 if_incoming
->if_status
== BATADV_IF_TO_BE_REMOVED
)
1200 batadv_dbg(BATADV_DBG_BATMAN
, bat_priv
,
1201 "neighbor purge: originator %pM, neighbor: %pM, iface: %s\n",
1202 orig_node
->orig
, neigh_node
->addr
,
1203 if_incoming
->net_dev
->name
);
1205 batadv_dbg(BATADV_DBG_BATMAN
, bat_priv
,
1206 "neighbor timeout: originator %pM, neighbor: %pM, last_seen: %u\n",
1207 orig_node
->orig
, neigh_node
->addr
,
1208 jiffies_to_msecs(last_seen
));
1210 neigh_purged
= true;
1212 hlist_del_rcu(&neigh_node
->list
);
1213 batadv_neigh_node_put(neigh_node
);
1215 /* only necessary if not the whole neighbor is to be
1216 * deleted, but some interface has been removed.
1218 batadv_purge_neigh_ifinfo(bat_priv
, neigh_node
);
1222 spin_unlock_bh(&orig_node
->neigh_list_lock
);
1223 return neigh_purged
;
1227 * batadv_find_best_neighbor() - finds the best neighbor after purging
1228 * @bat_priv: the bat priv with all the soft interface information
1229 * @orig_node: orig node which is to be checked
1230 * @if_outgoing: the interface for which the metric should be compared
1232 * Return: the current best neighbor, with refcount increased.
1234 static struct batadv_neigh_node
*
1235 batadv_find_best_neighbor(struct batadv_priv
*bat_priv
,
1236 struct batadv_orig_node
*orig_node
,
1237 struct batadv_hard_iface
*if_outgoing
)
1239 struct batadv_neigh_node
*best
= NULL
, *neigh
;
1240 struct batadv_algo_ops
*bao
= bat_priv
->algo_ops
;
1243 hlist_for_each_entry_rcu(neigh
, &orig_node
->neigh_list
, list
) {
1244 if (best
&& (bao
->neigh
.cmp(neigh
, if_outgoing
, best
,
1248 if (!kref_get_unless_zero(&neigh
->refcount
))
1252 batadv_neigh_node_put(best
);
1262 * batadv_purge_orig_node() - purges obsolete information from an orig_node
1263 * @bat_priv: the bat priv with all the soft interface information
1264 * @orig_node: orig node which is to be checked
1266 * This function checks if the orig_node or substructures of it have become
1267 * obsolete, and purges this information if that's the case.
1269 * Return: true if the orig_node is to be removed, false otherwise.
1271 static bool batadv_purge_orig_node(struct batadv_priv
*bat_priv
,
1272 struct batadv_orig_node
*orig_node
)
1274 struct batadv_neigh_node
*best_neigh_node
;
1275 struct batadv_hard_iface
*hard_iface
;
1276 bool changed_ifinfo
, changed_neigh
;
1278 if (batadv_has_timed_out(orig_node
->last_seen
,
1279 2 * BATADV_PURGE_TIMEOUT
)) {
1280 batadv_dbg(BATADV_DBG_BATMAN
, bat_priv
,
1281 "Originator timeout: originator %pM, last_seen %u\n",
1283 jiffies_to_msecs(orig_node
->last_seen
));
1286 changed_ifinfo
= batadv_purge_orig_ifinfo(bat_priv
, orig_node
);
1287 changed_neigh
= batadv_purge_orig_neighbors(bat_priv
, orig_node
);
1289 if (!changed_ifinfo
&& !changed_neigh
)
1292 /* first for NULL ... */
1293 best_neigh_node
= batadv_find_best_neighbor(bat_priv
, orig_node
,
1295 batadv_update_route(bat_priv
, orig_node
, BATADV_IF_DEFAULT
,
1297 if (best_neigh_node
)
1298 batadv_neigh_node_put(best_neigh_node
);
1300 /* ... then for all other interfaces. */
1302 list_for_each_entry_rcu(hard_iface
, &batadv_hardif_list
, list
) {
1303 if (hard_iface
->if_status
!= BATADV_IF_ACTIVE
)
1306 if (hard_iface
->soft_iface
!= bat_priv
->soft_iface
)
1309 if (!kref_get_unless_zero(&hard_iface
->refcount
))
1312 best_neigh_node
= batadv_find_best_neighbor(bat_priv
,
1315 batadv_update_route(bat_priv
, orig_node
, hard_iface
,
1317 if (best_neigh_node
)
1318 batadv_neigh_node_put(best_neigh_node
);
1320 batadv_hardif_put(hard_iface
);
1328 * batadv_purge_orig_ref() - Purge all outdated originators
1329 * @bat_priv: the bat priv with all the soft interface information
1331 void batadv_purge_orig_ref(struct batadv_priv
*bat_priv
)
1333 struct batadv_hashtable
*hash
= bat_priv
->orig_hash
;
1334 struct hlist_node
*node_tmp
;
1335 struct hlist_head
*head
;
1336 spinlock_t
*list_lock
; /* spinlock to protect write access */
1337 struct batadv_orig_node
*orig_node
;
1343 /* for all origins... */
1344 for (i
= 0; i
< hash
->size
; i
++) {
1345 head
= &hash
->table
[i
];
1346 list_lock
= &hash
->list_locks
[i
];
1348 spin_lock_bh(list_lock
);
1349 hlist_for_each_entry_safe(orig_node
, node_tmp
,
1351 if (batadv_purge_orig_node(bat_priv
, orig_node
)) {
1352 batadv_gw_node_delete(bat_priv
, orig_node
);
1353 hlist_del_rcu(&orig_node
->hash_entry
);
1354 batadv_tt_global_del_orig(orig_node
->bat_priv
,
1356 "originator timed out");
1357 batadv_orig_node_put(orig_node
);
1361 batadv_frag_purge_orig(orig_node
,
1362 batadv_frag_check_entry
);
1364 spin_unlock_bh(list_lock
);
1367 batadv_gw_election(bat_priv
);
1370 static void batadv_purge_orig(struct work_struct
*work
)
1372 struct delayed_work
*delayed_work
;
1373 struct batadv_priv
*bat_priv
;
1375 delayed_work
= to_delayed_work(work
);
1376 bat_priv
= container_of(delayed_work
, struct batadv_priv
, orig_work
);
1377 batadv_purge_orig_ref(bat_priv
);
1378 queue_delayed_work(batadv_event_workqueue
,
1379 &bat_priv
->orig_work
,
1380 msecs_to_jiffies(BATADV_ORIG_WORK_PERIOD
));
1383 #ifdef CONFIG_BATMAN_ADV_DEBUGFS
1386 * batadv_orig_seq_print_text() - Print the originator table in a seq file
1387 * @seq: seq file to print on
1392 int batadv_orig_seq_print_text(struct seq_file
*seq
, void *offset
)
1394 struct net_device
*net_dev
= (struct net_device
*)seq
->private;
1395 struct batadv_priv
*bat_priv
= netdev_priv(net_dev
);
1396 struct batadv_hard_iface
*primary_if
;
1398 primary_if
= batadv_seq_print_text_primary_if_get(seq
);
1402 seq_printf(seq
, "[B.A.T.M.A.N. adv %s, MainIF/MAC: %s/%pM (%s %s)]\n",
1403 BATADV_SOURCE_VERSION
, primary_if
->net_dev
->name
,
1404 primary_if
->net_dev
->dev_addr
, net_dev
->name
,
1405 bat_priv
->algo_ops
->name
);
1407 batadv_hardif_put(primary_if
);
1409 if (!bat_priv
->algo_ops
->orig
.print
) {
1411 "No printing function for this routing protocol\n");
1415 bat_priv
->algo_ops
->orig
.print(bat_priv
, seq
, BATADV_IF_DEFAULT
);
1421 * batadv_orig_hardif_seq_print_text() - writes originator infos for a specific
1422 * outgoing interface
1423 * @seq: debugfs table seq_file struct
1428 int batadv_orig_hardif_seq_print_text(struct seq_file
*seq
, void *offset
)
1430 struct net_device
*net_dev
= (struct net_device
*)seq
->private;
1431 struct batadv_hard_iface
*hard_iface
;
1432 struct batadv_priv
*bat_priv
;
1434 hard_iface
= batadv_hardif_get_by_netdev(net_dev
);
1436 if (!hard_iface
|| !hard_iface
->soft_iface
) {
1437 seq_puts(seq
, "Interface not known to B.A.T.M.A.N.\n");
1441 bat_priv
= netdev_priv(hard_iface
->soft_iface
);
1442 if (!bat_priv
->algo_ops
->orig
.print
) {
1444 "No printing function for this routing protocol\n");
1448 if (hard_iface
->if_status
!= BATADV_IF_ACTIVE
) {
1449 seq_puts(seq
, "Interface not active\n");
1453 seq_printf(seq
, "[B.A.T.M.A.N. adv %s, IF/MAC: %s/%pM (%s %s)]\n",
1454 BATADV_SOURCE_VERSION
, hard_iface
->net_dev
->name
,
1455 hard_iface
->net_dev
->dev_addr
,
1456 hard_iface
->soft_iface
->name
, bat_priv
->algo_ops
->name
);
1458 bat_priv
->algo_ops
->orig
.print(bat_priv
, seq
, hard_iface
);
1462 batadv_hardif_put(hard_iface
);
1468 * batadv_orig_dump() - Dump to netlink the originator infos for a specific
1469 * outgoing interface
1470 * @msg: message to dump into
1471 * @cb: parameters for the dump
1473 * Return: 0 or error value
1475 int batadv_orig_dump(struct sk_buff
*msg
, struct netlink_callback
*cb
)
1477 struct net
*net
= sock_net(cb
->skb
->sk
);
1478 struct net_device
*soft_iface
;
1479 struct net_device
*hard_iface
= NULL
;
1480 struct batadv_hard_iface
*hardif
= BATADV_IF_DEFAULT
;
1481 struct batadv_priv
*bat_priv
;
1482 struct batadv_hard_iface
*primary_if
= NULL
;
1484 int ifindex
, hard_ifindex
;
1486 ifindex
= batadv_netlink_get_ifindex(cb
->nlh
, BATADV_ATTR_MESH_IFINDEX
);
1490 soft_iface
= dev_get_by_index(net
, ifindex
);
1491 if (!soft_iface
|| !batadv_softif_is_valid(soft_iface
)) {
1496 bat_priv
= netdev_priv(soft_iface
);
1498 primary_if
= batadv_primary_if_get_selected(bat_priv
);
1499 if (!primary_if
|| primary_if
->if_status
!= BATADV_IF_ACTIVE
) {
1504 hard_ifindex
= batadv_netlink_get_ifindex(cb
->nlh
,
1505 BATADV_ATTR_HARD_IFINDEX
);
1507 hard_iface
= dev_get_by_index(net
, hard_ifindex
);
1509 hardif
= batadv_hardif_get_by_netdev(hard_iface
);
1516 if (hardif
->soft_iface
!= soft_iface
) {
1522 if (!bat_priv
->algo_ops
->orig
.dump
) {
1527 bat_priv
->algo_ops
->orig
.dump(msg
, cb
, bat_priv
, hardif
);
1533 batadv_hardif_put(hardif
);
1535 dev_put(hard_iface
);
1537 batadv_hardif_put(primary_if
);
1539 dev_put(soft_iface
);