1 /* Copyright (C) 2009-2016 B.A.T.M.A.N. contributors:
3 * Marek Lindner, Simon Wunderlich
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public
7 * License as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 #include "originator.h"
21 #include <linux/atomic.h>
22 #include <linux/errno.h>
23 #include <linux/etherdevice.h>
25 #include <linux/jiffies.h>
26 #include <linux/kernel.h>
27 #include <linux/kref.h>
28 #include <linux/list.h>
29 #include <linux/lockdep.h>
30 #include <linux/netdevice.h>
31 #include <linux/netlink.h>
32 #include <linux/rculist.h>
33 #include <linux/seq_file.h>
34 #include <linux/skbuff.h>
35 #include <linux/slab.h>
36 #include <linux/spinlock.h>
37 #include <linux/workqueue.h>
39 #include <uapi/linux/batman_adv.h>
42 #include "distributed-arp-table.h"
43 #include "fragmentation.h"
44 #include "gateway_client.h"
45 #include "hard-interface.h"
48 #include "multicast.h"
50 #include "network-coding.h"
52 #include "soft-interface.h"
53 #include "translation-table.h"
56 static struct lock_class_key batadv_orig_hash_lock_class_key
;
58 static void batadv_purge_orig(struct work_struct
*work
);
61 * batadv_compare_orig - comparing function used in the originator hash table
62 * @node: node in the local table
63 * @data2: second object to compare the node to
65 * Return: true if they are the same originator
67 bool batadv_compare_orig(const struct hlist_node
*node
, const void *data2
)
69 const void *data1
= container_of(node
, struct batadv_orig_node
,
72 return batadv_compare_eth(data1
, data2
);
76 * batadv_orig_node_vlan_get - get an orig_node_vlan object
77 * @orig_node: the originator serving the VLAN
78 * @vid: the VLAN identifier
80 * Return: the vlan object identified by vid and belonging to orig_node or NULL
81 * if it does not exist.
83 struct batadv_orig_node_vlan
*
84 batadv_orig_node_vlan_get(struct batadv_orig_node
*orig_node
,
87 struct batadv_orig_node_vlan
*vlan
= NULL
, *tmp
;
90 hlist_for_each_entry_rcu(tmp
, &orig_node
->vlan_list
, list
) {
94 if (!kref_get_unless_zero(&tmp
->refcount
))
107 * batadv_orig_node_vlan_new - search and possibly create an orig_node_vlan
109 * @orig_node: the originator serving the VLAN
110 * @vid: the VLAN identifier
112 * Return: NULL in case of failure or the vlan object identified by vid and
113 * belonging to orig_node otherwise. The object is created and added to the list
114 * if it does not exist.
116 * The object is returned with refcounter increased by 1.
118 struct batadv_orig_node_vlan
*
119 batadv_orig_node_vlan_new(struct batadv_orig_node
*orig_node
,
122 struct batadv_orig_node_vlan
*vlan
;
124 spin_lock_bh(&orig_node
->vlan_list_lock
);
126 /* first look if an object for this vid already exists */
127 vlan
= batadv_orig_node_vlan_get(orig_node
, vid
);
131 vlan
= kzalloc(sizeof(*vlan
), GFP_ATOMIC
);
135 kref_init(&vlan
->refcount
);
138 kref_get(&vlan
->refcount
);
139 hlist_add_head_rcu(&vlan
->list
, &orig_node
->vlan_list
);
142 spin_unlock_bh(&orig_node
->vlan_list_lock
);
148 * batadv_orig_node_vlan_release - release originator-vlan object from lists
149 * and queue for free after rcu grace period
150 * @ref: kref pointer of the originator-vlan object
152 static void batadv_orig_node_vlan_release(struct kref
*ref
)
154 struct batadv_orig_node_vlan
*orig_vlan
;
156 orig_vlan
= container_of(ref
, struct batadv_orig_node_vlan
, refcount
);
158 kfree_rcu(orig_vlan
, rcu
);
162 * batadv_orig_node_vlan_put - decrement the refcounter and possibly release
163 * the originator-vlan object
164 * @orig_vlan: the originator-vlan object to release
166 void batadv_orig_node_vlan_put(struct batadv_orig_node_vlan
*orig_vlan
)
168 kref_put(&orig_vlan
->refcount
, batadv_orig_node_vlan_release
);
171 int batadv_originator_init(struct batadv_priv
*bat_priv
)
173 if (bat_priv
->orig_hash
)
176 bat_priv
->orig_hash
= batadv_hash_new(1024);
178 if (!bat_priv
->orig_hash
)
181 batadv_hash_set_lock_class(bat_priv
->orig_hash
,
182 &batadv_orig_hash_lock_class_key
);
184 INIT_DELAYED_WORK(&bat_priv
->orig_work
, batadv_purge_orig
);
185 queue_delayed_work(batadv_event_workqueue
,
186 &bat_priv
->orig_work
,
187 msecs_to_jiffies(BATADV_ORIG_WORK_PERIOD
));
196 * batadv_neigh_ifinfo_release - release neigh_ifinfo from lists and queue for
197 * free after rcu grace period
198 * @ref: kref pointer of the neigh_ifinfo
200 static void batadv_neigh_ifinfo_release(struct kref
*ref
)
202 struct batadv_neigh_ifinfo
*neigh_ifinfo
;
204 neigh_ifinfo
= container_of(ref
, struct batadv_neigh_ifinfo
, refcount
);
206 if (neigh_ifinfo
->if_outgoing
!= BATADV_IF_DEFAULT
)
207 batadv_hardif_put(neigh_ifinfo
->if_outgoing
);
209 kfree_rcu(neigh_ifinfo
, rcu
);
213 * batadv_neigh_ifinfo_put - decrement the refcounter and possibly release
215 * @neigh_ifinfo: the neigh_ifinfo object to release
217 void batadv_neigh_ifinfo_put(struct batadv_neigh_ifinfo
*neigh_ifinfo
)
219 kref_put(&neigh_ifinfo
->refcount
, batadv_neigh_ifinfo_release
);
223 * batadv_hardif_neigh_release - release hardif neigh node from lists and
224 * queue for free after rcu grace period
225 * @ref: kref pointer of the neigh_node
227 static void batadv_hardif_neigh_release(struct kref
*ref
)
229 struct batadv_hardif_neigh_node
*hardif_neigh
;
231 hardif_neigh
= container_of(ref
, struct batadv_hardif_neigh_node
,
234 spin_lock_bh(&hardif_neigh
->if_incoming
->neigh_list_lock
);
235 hlist_del_init_rcu(&hardif_neigh
->list
);
236 spin_unlock_bh(&hardif_neigh
->if_incoming
->neigh_list_lock
);
238 batadv_hardif_put(hardif_neigh
->if_incoming
);
239 kfree_rcu(hardif_neigh
, rcu
);
243 * batadv_hardif_neigh_put - decrement the hardif neighbors refcounter
244 * and possibly release it
245 * @hardif_neigh: hardif neigh neighbor to free
247 void batadv_hardif_neigh_put(struct batadv_hardif_neigh_node
*hardif_neigh
)
249 kref_put(&hardif_neigh
->refcount
, batadv_hardif_neigh_release
);
253 * batadv_neigh_node_release - release neigh_node from lists and queue for
254 * free after rcu grace period
255 * @ref: kref pointer of the neigh_node
257 static void batadv_neigh_node_release(struct kref
*ref
)
259 struct hlist_node
*node_tmp
;
260 struct batadv_neigh_node
*neigh_node
;
261 struct batadv_neigh_ifinfo
*neigh_ifinfo
;
263 neigh_node
= container_of(ref
, struct batadv_neigh_node
, refcount
);
265 hlist_for_each_entry_safe(neigh_ifinfo
, node_tmp
,
266 &neigh_node
->ifinfo_list
, list
) {
267 batadv_neigh_ifinfo_put(neigh_ifinfo
);
270 batadv_hardif_neigh_put(neigh_node
->hardif_neigh
);
272 batadv_hardif_put(neigh_node
->if_incoming
);
274 kfree_rcu(neigh_node
, rcu
);
278 * batadv_neigh_node_put - decrement the neighbors refcounter and possibly
280 * @neigh_node: neigh neighbor to free
282 void batadv_neigh_node_put(struct batadv_neigh_node
*neigh_node
)
284 kref_put(&neigh_node
->refcount
, batadv_neigh_node_release
);
288 * batadv_orig_router_get - router to the originator depending on iface
289 * @orig_node: the orig node for the router
290 * @if_outgoing: the interface where the payload packet has been received or
291 * the OGM should be sent to
293 * Return: the neighbor which should be router for this orig_node/iface.
295 * The object is returned with refcounter increased by 1.
297 struct batadv_neigh_node
*
298 batadv_orig_router_get(struct batadv_orig_node
*orig_node
,
299 const struct batadv_hard_iface
*if_outgoing
)
301 struct batadv_orig_ifinfo
*orig_ifinfo
;
302 struct batadv_neigh_node
*router
= NULL
;
305 hlist_for_each_entry_rcu(orig_ifinfo
, &orig_node
->ifinfo_list
, list
) {
306 if (orig_ifinfo
->if_outgoing
!= if_outgoing
)
309 router
= rcu_dereference(orig_ifinfo
->router
);
313 if (router
&& !kref_get_unless_zero(&router
->refcount
))
321 * batadv_orig_ifinfo_get - find the ifinfo from an orig_node
322 * @orig_node: the orig node to be queried
323 * @if_outgoing: the interface for which the ifinfo should be acquired
325 * Return: the requested orig_ifinfo or NULL if not found.
327 * The object is returned with refcounter increased by 1.
329 struct batadv_orig_ifinfo
*
330 batadv_orig_ifinfo_get(struct batadv_orig_node
*orig_node
,
331 struct batadv_hard_iface
*if_outgoing
)
333 struct batadv_orig_ifinfo
*tmp
, *orig_ifinfo
= NULL
;
336 hlist_for_each_entry_rcu(tmp
, &orig_node
->ifinfo_list
,
338 if (tmp
->if_outgoing
!= if_outgoing
)
341 if (!kref_get_unless_zero(&tmp
->refcount
))
353 * batadv_orig_ifinfo_new - search and possibly create an orig_ifinfo object
354 * @orig_node: the orig node to be queried
355 * @if_outgoing: the interface for which the ifinfo should be acquired
357 * Return: NULL in case of failure or the orig_ifinfo object for the if_outgoing
358 * interface otherwise. The object is created and added to the list
359 * if it does not exist.
361 * The object is returned with refcounter increased by 1.
363 struct batadv_orig_ifinfo
*
364 batadv_orig_ifinfo_new(struct batadv_orig_node
*orig_node
,
365 struct batadv_hard_iface
*if_outgoing
)
367 struct batadv_orig_ifinfo
*orig_ifinfo
= NULL
;
368 unsigned long reset_time
;
370 spin_lock_bh(&orig_node
->neigh_list_lock
);
372 orig_ifinfo
= batadv_orig_ifinfo_get(orig_node
, if_outgoing
);
376 orig_ifinfo
= kzalloc(sizeof(*orig_ifinfo
), GFP_ATOMIC
);
380 if (if_outgoing
!= BATADV_IF_DEFAULT
)
381 kref_get(&if_outgoing
->refcount
);
383 reset_time
= jiffies
- 1;
384 reset_time
-= msecs_to_jiffies(BATADV_RESET_PROTECTION_MS
);
385 orig_ifinfo
->batman_seqno_reset
= reset_time
;
386 orig_ifinfo
->if_outgoing
= if_outgoing
;
387 INIT_HLIST_NODE(&orig_ifinfo
->list
);
388 kref_init(&orig_ifinfo
->refcount
);
390 kref_get(&orig_ifinfo
->refcount
);
391 hlist_add_head_rcu(&orig_ifinfo
->list
,
392 &orig_node
->ifinfo_list
);
394 spin_unlock_bh(&orig_node
->neigh_list_lock
);
399 * batadv_neigh_ifinfo_get - find the ifinfo from an neigh_node
400 * @neigh: the neigh node to be queried
401 * @if_outgoing: the interface for which the ifinfo should be acquired
403 * The object is returned with refcounter increased by 1.
405 * Return: the requested neigh_ifinfo or NULL if not found
407 struct batadv_neigh_ifinfo
*
408 batadv_neigh_ifinfo_get(struct batadv_neigh_node
*neigh
,
409 struct batadv_hard_iface
*if_outgoing
)
411 struct batadv_neigh_ifinfo
*neigh_ifinfo
= NULL
,
415 hlist_for_each_entry_rcu(tmp_neigh_ifinfo
, &neigh
->ifinfo_list
,
417 if (tmp_neigh_ifinfo
->if_outgoing
!= if_outgoing
)
420 if (!kref_get_unless_zero(&tmp_neigh_ifinfo
->refcount
))
423 neigh_ifinfo
= tmp_neigh_ifinfo
;
432 * batadv_neigh_ifinfo_new - search and possibly create an neigh_ifinfo object
433 * @neigh: the neigh node to be queried
434 * @if_outgoing: the interface for which the ifinfo should be acquired
436 * Return: NULL in case of failure or the neigh_ifinfo object for the
437 * if_outgoing interface otherwise. The object is created and added to the list
438 * if it does not exist.
440 * The object is returned with refcounter increased by 1.
442 struct batadv_neigh_ifinfo
*
443 batadv_neigh_ifinfo_new(struct batadv_neigh_node
*neigh
,
444 struct batadv_hard_iface
*if_outgoing
)
446 struct batadv_neigh_ifinfo
*neigh_ifinfo
;
448 spin_lock_bh(&neigh
->ifinfo_lock
);
450 neigh_ifinfo
= batadv_neigh_ifinfo_get(neigh
, if_outgoing
);
454 neigh_ifinfo
= kzalloc(sizeof(*neigh_ifinfo
), GFP_ATOMIC
);
459 kref_get(&if_outgoing
->refcount
);
461 INIT_HLIST_NODE(&neigh_ifinfo
->list
);
462 kref_init(&neigh_ifinfo
->refcount
);
463 neigh_ifinfo
->if_outgoing
= if_outgoing
;
465 kref_get(&neigh_ifinfo
->refcount
);
466 hlist_add_head_rcu(&neigh_ifinfo
->list
, &neigh
->ifinfo_list
);
469 spin_unlock_bh(&neigh
->ifinfo_lock
);
475 * batadv_neigh_node_get - retrieve a neighbour from the list
476 * @orig_node: originator which the neighbour belongs to
477 * @hard_iface: the interface where this neighbour is connected to
478 * @addr: the address of the neighbour
480 * Looks for and possibly returns a neighbour belonging to this originator list
481 * which is connected through the provided hard interface.
483 * Return: neighbor when found. Othwerwise NULL
485 static struct batadv_neigh_node
*
486 batadv_neigh_node_get(const struct batadv_orig_node
*orig_node
,
487 const struct batadv_hard_iface
*hard_iface
,
490 struct batadv_neigh_node
*tmp_neigh_node
, *res
= NULL
;
493 hlist_for_each_entry_rcu(tmp_neigh_node
, &orig_node
->neigh_list
, list
) {
494 if (!batadv_compare_eth(tmp_neigh_node
->addr
, addr
))
497 if (tmp_neigh_node
->if_incoming
!= hard_iface
)
500 if (!kref_get_unless_zero(&tmp_neigh_node
->refcount
))
503 res
= tmp_neigh_node
;
512 * batadv_hardif_neigh_create - create a hardif neighbour node
513 * @hard_iface: the interface this neighbour is connected to
514 * @neigh_addr: the interface address of the neighbour to retrieve
516 * Return: the hardif neighbour node if found or created or NULL otherwise.
518 static struct batadv_hardif_neigh_node
*
519 batadv_hardif_neigh_create(struct batadv_hard_iface
*hard_iface
,
520 const u8
*neigh_addr
)
522 struct batadv_priv
*bat_priv
= netdev_priv(hard_iface
->soft_iface
);
523 struct batadv_hardif_neigh_node
*hardif_neigh
= NULL
;
525 spin_lock_bh(&hard_iface
->neigh_list_lock
);
527 /* check if neighbor hasn't been added in the meantime */
528 hardif_neigh
= batadv_hardif_neigh_get(hard_iface
, neigh_addr
);
532 hardif_neigh
= kzalloc(sizeof(*hardif_neigh
), GFP_ATOMIC
);
536 kref_get(&hard_iface
->refcount
);
537 INIT_HLIST_NODE(&hardif_neigh
->list
);
538 ether_addr_copy(hardif_neigh
->addr
, neigh_addr
);
539 hardif_neigh
->if_incoming
= hard_iface
;
540 hardif_neigh
->last_seen
= jiffies
;
542 kref_init(&hardif_neigh
->refcount
);
544 if (bat_priv
->algo_ops
->neigh
.hardif_init
)
545 bat_priv
->algo_ops
->neigh
.hardif_init(hardif_neigh
);
547 hlist_add_head_rcu(&hardif_neigh
->list
, &hard_iface
->neigh_list
);
550 spin_unlock_bh(&hard_iface
->neigh_list_lock
);
555 * batadv_hardif_neigh_get_or_create - retrieve or create a hardif neighbour
557 * @hard_iface: the interface this neighbour is connected to
558 * @neigh_addr: the interface address of the neighbour to retrieve
560 * Return: the hardif neighbour node if found or created or NULL otherwise.
562 static struct batadv_hardif_neigh_node
*
563 batadv_hardif_neigh_get_or_create(struct batadv_hard_iface
*hard_iface
,
564 const u8
*neigh_addr
)
566 struct batadv_hardif_neigh_node
*hardif_neigh
= NULL
;
568 /* first check without locking to avoid the overhead */
569 hardif_neigh
= batadv_hardif_neigh_get(hard_iface
, neigh_addr
);
573 return batadv_hardif_neigh_create(hard_iface
, neigh_addr
);
577 * batadv_hardif_neigh_get - retrieve a hardif neighbour from the list
578 * @hard_iface: the interface where this neighbour is connected to
579 * @neigh_addr: the address of the neighbour
581 * Looks for and possibly returns a neighbour belonging to this hard interface.
583 * Return: neighbor when found. Othwerwise NULL
585 struct batadv_hardif_neigh_node
*
586 batadv_hardif_neigh_get(const struct batadv_hard_iface
*hard_iface
,
587 const u8
*neigh_addr
)
589 struct batadv_hardif_neigh_node
*tmp_hardif_neigh
, *hardif_neigh
= NULL
;
592 hlist_for_each_entry_rcu(tmp_hardif_neigh
,
593 &hard_iface
->neigh_list
, list
) {
594 if (!batadv_compare_eth(tmp_hardif_neigh
->addr
, neigh_addr
))
597 if (!kref_get_unless_zero(&tmp_hardif_neigh
->refcount
))
600 hardif_neigh
= tmp_hardif_neigh
;
609 * batadv_neigh_node_create - create a neigh node object
610 * @orig_node: originator object representing the neighbour
611 * @hard_iface: the interface where the neighbour is connected to
612 * @neigh_addr: the mac address of the neighbour interface
614 * Allocates a new neigh_node object and initialises all the generic fields.
616 * Return: the neighbour node if found or created or NULL otherwise.
618 static struct batadv_neigh_node
*
619 batadv_neigh_node_create(struct batadv_orig_node
*orig_node
,
620 struct batadv_hard_iface
*hard_iface
,
621 const u8
*neigh_addr
)
623 struct batadv_neigh_node
*neigh_node
;
624 struct batadv_hardif_neigh_node
*hardif_neigh
= NULL
;
626 spin_lock_bh(&orig_node
->neigh_list_lock
);
628 neigh_node
= batadv_neigh_node_get(orig_node
, hard_iface
, neigh_addr
);
632 hardif_neigh
= batadv_hardif_neigh_get_or_create(hard_iface
,
637 neigh_node
= kzalloc(sizeof(*neigh_node
), GFP_ATOMIC
);
641 INIT_HLIST_NODE(&neigh_node
->list
);
642 INIT_HLIST_HEAD(&neigh_node
->ifinfo_list
);
643 spin_lock_init(&neigh_node
->ifinfo_lock
);
645 kref_get(&hard_iface
->refcount
);
646 ether_addr_copy(neigh_node
->addr
, neigh_addr
);
647 neigh_node
->if_incoming
= hard_iface
;
648 neigh_node
->orig_node
= orig_node
;
649 neigh_node
->last_seen
= jiffies
;
651 /* increment unique neighbor refcount */
652 kref_get(&hardif_neigh
->refcount
);
653 neigh_node
->hardif_neigh
= hardif_neigh
;
655 /* extra reference for return */
656 kref_init(&neigh_node
->refcount
);
658 kref_get(&neigh_node
->refcount
);
659 hlist_add_head_rcu(&neigh_node
->list
, &orig_node
->neigh_list
);
661 batadv_dbg(BATADV_DBG_BATMAN
, orig_node
->bat_priv
,
662 "Creating new neighbor %pM for orig_node %pM on interface %s\n",
663 neigh_addr
, orig_node
->orig
, hard_iface
->net_dev
->name
);
666 spin_unlock_bh(&orig_node
->neigh_list_lock
);
669 batadv_hardif_neigh_put(hardif_neigh
);
674 * batadv_neigh_node_get_or_create - retrieve or create a neigh node object
675 * @orig_node: originator object representing the neighbour
676 * @hard_iface: the interface where the neighbour is connected to
677 * @neigh_addr: the mac address of the neighbour interface
679 * Return: the neighbour node if found or created or NULL otherwise.
681 struct batadv_neigh_node
*
682 batadv_neigh_node_get_or_create(struct batadv_orig_node
*orig_node
,
683 struct batadv_hard_iface
*hard_iface
,
684 const u8
*neigh_addr
)
686 struct batadv_neigh_node
*neigh_node
= NULL
;
688 /* first check without locking to avoid the overhead */
689 neigh_node
= batadv_neigh_node_get(orig_node
, hard_iface
, neigh_addr
);
693 return batadv_neigh_node_create(orig_node
, hard_iface
, neigh_addr
);
696 #ifdef CONFIG_BATMAN_ADV_DEBUGFS
698 * batadv_hardif_neigh_seq_print_text - print the single hop neighbour list
699 * @seq: neighbour table seq_file struct
704 int batadv_hardif_neigh_seq_print_text(struct seq_file
*seq
, void *offset
)
706 struct net_device
*net_dev
= (struct net_device
*)seq
->private;
707 struct batadv_priv
*bat_priv
= netdev_priv(net_dev
);
708 struct batadv_hard_iface
*primary_if
;
710 primary_if
= batadv_seq_print_text_primary_if_get(seq
);
714 seq_printf(seq
, "[B.A.T.M.A.N. adv %s, MainIF/MAC: %s/%pM (%s %s)]\n",
715 BATADV_SOURCE_VERSION
, primary_if
->net_dev
->name
,
716 primary_if
->net_dev
->dev_addr
, net_dev
->name
,
717 bat_priv
->algo_ops
->name
);
719 batadv_hardif_put(primary_if
);
721 if (!bat_priv
->algo_ops
->neigh
.print
) {
723 "No printing function for this routing protocol\n");
727 bat_priv
->algo_ops
->neigh
.print(bat_priv
, seq
);
733 * batadv_hardif_neigh_dump - Dump to netlink the neighbor infos for a specific
735 * @msg: message to dump into
736 * @cb: parameters for the dump
738 * Return: 0 or error value
740 int batadv_hardif_neigh_dump(struct sk_buff
*msg
, struct netlink_callback
*cb
)
742 struct net
*net
= sock_net(cb
->skb
->sk
);
743 struct net_device
*soft_iface
;
744 struct net_device
*hard_iface
= NULL
;
745 struct batadv_hard_iface
*hardif
= BATADV_IF_DEFAULT
;
746 struct batadv_priv
*bat_priv
;
747 struct batadv_hard_iface
*primary_if
= NULL
;
749 int ifindex
, hard_ifindex
;
751 ifindex
= batadv_netlink_get_ifindex(cb
->nlh
, BATADV_ATTR_MESH_IFINDEX
);
755 soft_iface
= dev_get_by_index(net
, ifindex
);
756 if (!soft_iface
|| !batadv_softif_is_valid(soft_iface
)) {
761 bat_priv
= netdev_priv(soft_iface
);
763 primary_if
= batadv_primary_if_get_selected(bat_priv
);
764 if (!primary_if
|| primary_if
->if_status
!= BATADV_IF_ACTIVE
) {
769 hard_ifindex
= batadv_netlink_get_ifindex(cb
->nlh
,
770 BATADV_ATTR_HARD_IFINDEX
);
772 hard_iface
= dev_get_by_index(net
, hard_ifindex
);
774 hardif
= batadv_hardif_get_by_netdev(hard_iface
);
781 if (hardif
->soft_iface
!= soft_iface
) {
787 if (!bat_priv
->algo_ops
->neigh
.dump
) {
792 bat_priv
->algo_ops
->neigh
.dump(msg
, cb
, bat_priv
, hardif
);
798 batadv_hardif_put(hardif
);
802 batadv_hardif_put(primary_if
);
810 * batadv_orig_ifinfo_release - release orig_ifinfo from lists and queue for
811 * free after rcu grace period
812 * @ref: kref pointer of the orig_ifinfo
814 static void batadv_orig_ifinfo_release(struct kref
*ref
)
816 struct batadv_orig_ifinfo
*orig_ifinfo
;
817 struct batadv_neigh_node
*router
;
819 orig_ifinfo
= container_of(ref
, struct batadv_orig_ifinfo
, refcount
);
821 if (orig_ifinfo
->if_outgoing
!= BATADV_IF_DEFAULT
)
822 batadv_hardif_put(orig_ifinfo
->if_outgoing
);
824 /* this is the last reference to this object */
825 router
= rcu_dereference_protected(orig_ifinfo
->router
, true);
827 batadv_neigh_node_put(router
);
829 kfree_rcu(orig_ifinfo
, rcu
);
833 * batadv_orig_ifinfo_put - decrement the refcounter and possibly release
835 * @orig_ifinfo: the orig_ifinfo object to release
837 void batadv_orig_ifinfo_put(struct batadv_orig_ifinfo
*orig_ifinfo
)
839 kref_put(&orig_ifinfo
->refcount
, batadv_orig_ifinfo_release
);
843 * batadv_orig_node_free_rcu - free the orig_node
844 * @rcu: rcu pointer of the orig_node
846 static void batadv_orig_node_free_rcu(struct rcu_head
*rcu
)
848 struct batadv_orig_node
*orig_node
;
850 orig_node
= container_of(rcu
, struct batadv_orig_node
, rcu
);
852 batadv_mcast_purge_orig(orig_node
);
854 batadv_frag_purge_orig(orig_node
, NULL
);
856 if (orig_node
->bat_priv
->algo_ops
->orig
.free
)
857 orig_node
->bat_priv
->algo_ops
->orig
.free(orig_node
);
859 kfree(orig_node
->tt_buff
);
864 * batadv_orig_node_release - release orig_node from lists and queue for
865 * free after rcu grace period
866 * @ref: kref pointer of the orig_node
868 static void batadv_orig_node_release(struct kref
*ref
)
870 struct hlist_node
*node_tmp
;
871 struct batadv_neigh_node
*neigh_node
;
872 struct batadv_orig_node
*orig_node
;
873 struct batadv_orig_ifinfo
*orig_ifinfo
;
874 struct batadv_orig_node_vlan
*vlan
;
875 struct batadv_orig_ifinfo
*last_candidate
;
877 orig_node
= container_of(ref
, struct batadv_orig_node
, refcount
);
879 spin_lock_bh(&orig_node
->neigh_list_lock
);
881 /* for all neighbors towards this originator ... */
882 hlist_for_each_entry_safe(neigh_node
, node_tmp
,
883 &orig_node
->neigh_list
, list
) {
884 hlist_del_rcu(&neigh_node
->list
);
885 batadv_neigh_node_put(neigh_node
);
888 hlist_for_each_entry_safe(orig_ifinfo
, node_tmp
,
889 &orig_node
->ifinfo_list
, list
) {
890 hlist_del_rcu(&orig_ifinfo
->list
);
891 batadv_orig_ifinfo_put(orig_ifinfo
);
894 last_candidate
= orig_node
->last_bonding_candidate
;
895 orig_node
->last_bonding_candidate
= NULL
;
896 spin_unlock_bh(&orig_node
->neigh_list_lock
);
899 batadv_orig_ifinfo_put(last_candidate
);
901 spin_lock_bh(&orig_node
->vlan_list_lock
);
902 hlist_for_each_entry_safe(vlan
, node_tmp
, &orig_node
->vlan_list
, list
) {
903 hlist_del_rcu(&vlan
->list
);
904 batadv_orig_node_vlan_put(vlan
);
906 spin_unlock_bh(&orig_node
->vlan_list_lock
);
909 batadv_nc_purge_orig(orig_node
->bat_priv
, orig_node
, NULL
);
911 call_rcu(&orig_node
->rcu
, batadv_orig_node_free_rcu
);
915 * batadv_orig_node_put - decrement the orig node refcounter and possibly
917 * @orig_node: the orig node to free
919 void batadv_orig_node_put(struct batadv_orig_node
*orig_node
)
921 kref_put(&orig_node
->refcount
, batadv_orig_node_release
);
924 void batadv_originator_free(struct batadv_priv
*bat_priv
)
926 struct batadv_hashtable
*hash
= bat_priv
->orig_hash
;
927 struct hlist_node
*node_tmp
;
928 struct hlist_head
*head
;
929 spinlock_t
*list_lock
; /* spinlock to protect write access */
930 struct batadv_orig_node
*orig_node
;
936 cancel_delayed_work_sync(&bat_priv
->orig_work
);
938 bat_priv
->orig_hash
= NULL
;
940 for (i
= 0; i
< hash
->size
; i
++) {
941 head
= &hash
->table
[i
];
942 list_lock
= &hash
->list_locks
[i
];
944 spin_lock_bh(list_lock
);
945 hlist_for_each_entry_safe(orig_node
, node_tmp
,
947 hlist_del_rcu(&orig_node
->hash_entry
);
948 batadv_orig_node_put(orig_node
);
950 spin_unlock_bh(list_lock
);
953 batadv_hash_destroy(hash
);
957 * batadv_orig_node_new - creates a new orig_node
958 * @bat_priv: the bat priv with all the soft interface information
959 * @addr: the mac address of the originator
961 * Creates a new originator object and initialise all the generic fields.
962 * The new object is not added to the originator list.
964 * Return: the newly created object or NULL on failure.
966 struct batadv_orig_node
*batadv_orig_node_new(struct batadv_priv
*bat_priv
,
969 struct batadv_orig_node
*orig_node
;
970 struct batadv_orig_node_vlan
*vlan
;
971 unsigned long reset_time
;
974 batadv_dbg(BATADV_DBG_BATMAN
, bat_priv
,
975 "Creating new originator: %pM\n", addr
);
977 orig_node
= kzalloc(sizeof(*orig_node
), GFP_ATOMIC
);
981 INIT_HLIST_HEAD(&orig_node
->neigh_list
);
982 INIT_HLIST_HEAD(&orig_node
->vlan_list
);
983 INIT_HLIST_HEAD(&orig_node
->ifinfo_list
);
984 spin_lock_init(&orig_node
->bcast_seqno_lock
);
985 spin_lock_init(&orig_node
->neigh_list_lock
);
986 spin_lock_init(&orig_node
->tt_buff_lock
);
987 spin_lock_init(&orig_node
->tt_lock
);
988 spin_lock_init(&orig_node
->vlan_list_lock
);
990 batadv_nc_init_orig(orig_node
);
992 /* extra reference for return */
993 kref_init(&orig_node
->refcount
);
995 orig_node
->bat_priv
= bat_priv
;
996 ether_addr_copy(orig_node
->orig
, addr
);
997 batadv_dat_init_orig_node_addr(orig_node
);
998 atomic_set(&orig_node
->last_ttvn
, 0);
999 orig_node
->tt_buff
= NULL
;
1000 orig_node
->tt_buff_len
= 0;
1001 orig_node
->last_seen
= jiffies
;
1002 reset_time
= jiffies
- 1 - msecs_to_jiffies(BATADV_RESET_PROTECTION_MS
);
1003 orig_node
->bcast_seqno_reset
= reset_time
;
1005 #ifdef CONFIG_BATMAN_ADV_MCAST
1006 orig_node
->mcast_flags
= BATADV_NO_FLAGS
;
1007 INIT_HLIST_NODE(&orig_node
->mcast_want_all_unsnoopables_node
);
1008 INIT_HLIST_NODE(&orig_node
->mcast_want_all_ipv4_node
);
1009 INIT_HLIST_NODE(&orig_node
->mcast_want_all_ipv6_node
);
1010 spin_lock_init(&orig_node
->mcast_handler_lock
);
1013 /* create a vlan object for the "untagged" LAN */
1014 vlan
= batadv_orig_node_vlan_new(orig_node
, BATADV_NO_FLAGS
);
1016 goto free_orig_node
;
1017 /* batadv_orig_node_vlan_new() increases the refcounter.
1018 * Immediately release vlan since it is not needed anymore in this
1021 batadv_orig_node_vlan_put(vlan
);
1023 for (i
= 0; i
< BATADV_FRAG_BUFFER_COUNT
; i
++) {
1024 INIT_HLIST_HEAD(&orig_node
->fragments
[i
].head
);
1025 spin_lock_init(&orig_node
->fragments
[i
].lock
);
1026 orig_node
->fragments
[i
].size
= 0;
1036 * batadv_purge_neigh_ifinfo - purge obsolete ifinfo entries from neighbor
1037 * @bat_priv: the bat priv with all the soft interface information
1038 * @neigh: orig node which is to be checked
1041 batadv_purge_neigh_ifinfo(struct batadv_priv
*bat_priv
,
1042 struct batadv_neigh_node
*neigh
)
1044 struct batadv_neigh_ifinfo
*neigh_ifinfo
;
1045 struct batadv_hard_iface
*if_outgoing
;
1046 struct hlist_node
*node_tmp
;
1048 spin_lock_bh(&neigh
->ifinfo_lock
);
1050 /* for all ifinfo objects for this neighinator */
1051 hlist_for_each_entry_safe(neigh_ifinfo
, node_tmp
,
1052 &neigh
->ifinfo_list
, list
) {
1053 if_outgoing
= neigh_ifinfo
->if_outgoing
;
1055 /* always keep the default interface */
1056 if (if_outgoing
== BATADV_IF_DEFAULT
)
1059 /* don't purge if the interface is not (going) down */
1060 if ((if_outgoing
->if_status
!= BATADV_IF_INACTIVE
) &&
1061 (if_outgoing
->if_status
!= BATADV_IF_NOT_IN_USE
) &&
1062 (if_outgoing
->if_status
!= BATADV_IF_TO_BE_REMOVED
))
1065 batadv_dbg(BATADV_DBG_BATMAN
, bat_priv
,
1066 "neighbor/ifinfo purge: neighbor %pM, iface: %s\n",
1067 neigh
->addr
, if_outgoing
->net_dev
->name
);
1069 hlist_del_rcu(&neigh_ifinfo
->list
);
1070 batadv_neigh_ifinfo_put(neigh_ifinfo
);
1073 spin_unlock_bh(&neigh
->ifinfo_lock
);
1077 * batadv_purge_orig_ifinfo - purge obsolete ifinfo entries from originator
1078 * @bat_priv: the bat priv with all the soft interface information
1079 * @orig_node: orig node which is to be checked
1081 * Return: true if any ifinfo entry was purged, false otherwise.
1084 batadv_purge_orig_ifinfo(struct batadv_priv
*bat_priv
,
1085 struct batadv_orig_node
*orig_node
)
1087 struct batadv_orig_ifinfo
*orig_ifinfo
;
1088 struct batadv_hard_iface
*if_outgoing
;
1089 struct hlist_node
*node_tmp
;
1090 bool ifinfo_purged
= false;
1092 spin_lock_bh(&orig_node
->neigh_list_lock
);
1094 /* for all ifinfo objects for this originator */
1095 hlist_for_each_entry_safe(orig_ifinfo
, node_tmp
,
1096 &orig_node
->ifinfo_list
, list
) {
1097 if_outgoing
= orig_ifinfo
->if_outgoing
;
1099 /* always keep the default interface */
1100 if (if_outgoing
== BATADV_IF_DEFAULT
)
1103 /* don't purge if the interface is not (going) down */
1104 if ((if_outgoing
->if_status
!= BATADV_IF_INACTIVE
) &&
1105 (if_outgoing
->if_status
!= BATADV_IF_NOT_IN_USE
) &&
1106 (if_outgoing
->if_status
!= BATADV_IF_TO_BE_REMOVED
))
1109 batadv_dbg(BATADV_DBG_BATMAN
, bat_priv
,
1110 "router/ifinfo purge: originator %pM, iface: %s\n",
1111 orig_node
->orig
, if_outgoing
->net_dev
->name
);
1113 ifinfo_purged
= true;
1115 hlist_del_rcu(&orig_ifinfo
->list
);
1116 batadv_orig_ifinfo_put(orig_ifinfo
);
1117 if (orig_node
->last_bonding_candidate
== orig_ifinfo
) {
1118 orig_node
->last_bonding_candidate
= NULL
;
1119 batadv_orig_ifinfo_put(orig_ifinfo
);
1123 spin_unlock_bh(&orig_node
->neigh_list_lock
);
1125 return ifinfo_purged
;
1129 * batadv_purge_orig_neighbors - purges neighbors from originator
1130 * @bat_priv: the bat priv with all the soft interface information
1131 * @orig_node: orig node which is to be checked
1133 * Return: true if any neighbor was purged, false otherwise
1136 batadv_purge_orig_neighbors(struct batadv_priv
*bat_priv
,
1137 struct batadv_orig_node
*orig_node
)
1139 struct hlist_node
*node_tmp
;
1140 struct batadv_neigh_node
*neigh_node
;
1141 bool neigh_purged
= false;
1142 unsigned long last_seen
;
1143 struct batadv_hard_iface
*if_incoming
;
1145 spin_lock_bh(&orig_node
->neigh_list_lock
);
1147 /* for all neighbors towards this originator ... */
1148 hlist_for_each_entry_safe(neigh_node
, node_tmp
,
1149 &orig_node
->neigh_list
, list
) {
1150 last_seen
= neigh_node
->last_seen
;
1151 if_incoming
= neigh_node
->if_incoming
;
1153 if ((batadv_has_timed_out(last_seen
, BATADV_PURGE_TIMEOUT
)) ||
1154 (if_incoming
->if_status
== BATADV_IF_INACTIVE
) ||
1155 (if_incoming
->if_status
== BATADV_IF_NOT_IN_USE
) ||
1156 (if_incoming
->if_status
== BATADV_IF_TO_BE_REMOVED
)) {
1157 if ((if_incoming
->if_status
== BATADV_IF_INACTIVE
) ||
1158 (if_incoming
->if_status
== BATADV_IF_NOT_IN_USE
) ||
1159 (if_incoming
->if_status
== BATADV_IF_TO_BE_REMOVED
))
1160 batadv_dbg(BATADV_DBG_BATMAN
, bat_priv
,
1161 "neighbor purge: originator %pM, neighbor: %pM, iface: %s\n",
1162 orig_node
->orig
, neigh_node
->addr
,
1163 if_incoming
->net_dev
->name
);
1165 batadv_dbg(BATADV_DBG_BATMAN
, bat_priv
,
1166 "neighbor timeout: originator %pM, neighbor: %pM, last_seen: %u\n",
1167 orig_node
->orig
, neigh_node
->addr
,
1168 jiffies_to_msecs(last_seen
));
1170 neigh_purged
= true;
1172 hlist_del_rcu(&neigh_node
->list
);
1173 batadv_neigh_node_put(neigh_node
);
1175 /* only necessary if not the whole neighbor is to be
1176 * deleted, but some interface has been removed.
1178 batadv_purge_neigh_ifinfo(bat_priv
, neigh_node
);
1182 spin_unlock_bh(&orig_node
->neigh_list_lock
);
1183 return neigh_purged
;
1187 * batadv_find_best_neighbor - finds the best neighbor after purging
1188 * @bat_priv: the bat priv with all the soft interface information
1189 * @orig_node: orig node which is to be checked
1190 * @if_outgoing: the interface for which the metric should be compared
1192 * Return: the current best neighbor, with refcount increased.
1194 static struct batadv_neigh_node
*
1195 batadv_find_best_neighbor(struct batadv_priv
*bat_priv
,
1196 struct batadv_orig_node
*orig_node
,
1197 struct batadv_hard_iface
*if_outgoing
)
1199 struct batadv_neigh_node
*best
= NULL
, *neigh
;
1200 struct batadv_algo_ops
*bao
= bat_priv
->algo_ops
;
1203 hlist_for_each_entry_rcu(neigh
, &orig_node
->neigh_list
, list
) {
1204 if (best
&& (bao
->neigh
.cmp(neigh
, if_outgoing
, best
,
1208 if (!kref_get_unless_zero(&neigh
->refcount
))
1212 batadv_neigh_node_put(best
);
1222 * batadv_purge_orig_node - purges obsolete information from an orig_node
1223 * @bat_priv: the bat priv with all the soft interface information
1224 * @orig_node: orig node which is to be checked
1226 * This function checks if the orig_node or substructures of it have become
1227 * obsolete, and purges this information if that's the case.
1229 * Return: true if the orig_node is to be removed, false otherwise.
1231 static bool batadv_purge_orig_node(struct batadv_priv
*bat_priv
,
1232 struct batadv_orig_node
*orig_node
)
1234 struct batadv_neigh_node
*best_neigh_node
;
1235 struct batadv_hard_iface
*hard_iface
;
1236 bool changed_ifinfo
, changed_neigh
;
1238 if (batadv_has_timed_out(orig_node
->last_seen
,
1239 2 * BATADV_PURGE_TIMEOUT
)) {
1240 batadv_dbg(BATADV_DBG_BATMAN
, bat_priv
,
1241 "Originator timeout: originator %pM, last_seen %u\n",
1243 jiffies_to_msecs(orig_node
->last_seen
));
1246 changed_ifinfo
= batadv_purge_orig_ifinfo(bat_priv
, orig_node
);
1247 changed_neigh
= batadv_purge_orig_neighbors(bat_priv
, orig_node
);
1249 if (!changed_ifinfo
&& !changed_neigh
)
1252 /* first for NULL ... */
1253 best_neigh_node
= batadv_find_best_neighbor(bat_priv
, orig_node
,
1255 batadv_update_route(bat_priv
, orig_node
, BATADV_IF_DEFAULT
,
1257 if (best_neigh_node
)
1258 batadv_neigh_node_put(best_neigh_node
);
1260 /* ... then for all other interfaces. */
1262 list_for_each_entry_rcu(hard_iface
, &batadv_hardif_list
, list
) {
1263 if (hard_iface
->if_status
!= BATADV_IF_ACTIVE
)
1266 if (hard_iface
->soft_iface
!= bat_priv
->soft_iface
)
1269 if (!kref_get_unless_zero(&hard_iface
->refcount
))
1272 best_neigh_node
= batadv_find_best_neighbor(bat_priv
,
1275 batadv_update_route(bat_priv
, orig_node
, hard_iface
,
1277 if (best_neigh_node
)
1278 batadv_neigh_node_put(best_neigh_node
);
1280 batadv_hardif_put(hard_iface
);
1287 static void _batadv_purge_orig(struct batadv_priv
*bat_priv
)
1289 struct batadv_hashtable
*hash
= bat_priv
->orig_hash
;
1290 struct hlist_node
*node_tmp
;
1291 struct hlist_head
*head
;
1292 spinlock_t
*list_lock
; /* spinlock to protect write access */
1293 struct batadv_orig_node
*orig_node
;
1299 /* for all origins... */
1300 for (i
= 0; i
< hash
->size
; i
++) {
1301 head
= &hash
->table
[i
];
1302 list_lock
= &hash
->list_locks
[i
];
1304 spin_lock_bh(list_lock
);
1305 hlist_for_each_entry_safe(orig_node
, node_tmp
,
1307 if (batadv_purge_orig_node(bat_priv
, orig_node
)) {
1308 batadv_gw_node_delete(bat_priv
, orig_node
);
1309 hlist_del_rcu(&orig_node
->hash_entry
);
1310 batadv_tt_global_del_orig(orig_node
->bat_priv
,
1312 "originator timed out");
1313 batadv_orig_node_put(orig_node
);
1317 batadv_frag_purge_orig(orig_node
,
1318 batadv_frag_check_entry
);
1320 spin_unlock_bh(list_lock
);
1323 batadv_gw_election(bat_priv
);
1326 static void batadv_purge_orig(struct work_struct
*work
)
1328 struct delayed_work
*delayed_work
;
1329 struct batadv_priv
*bat_priv
;
1331 delayed_work
= to_delayed_work(work
);
1332 bat_priv
= container_of(delayed_work
, struct batadv_priv
, orig_work
);
1333 _batadv_purge_orig(bat_priv
);
1334 queue_delayed_work(batadv_event_workqueue
,
1335 &bat_priv
->orig_work
,
1336 msecs_to_jiffies(BATADV_ORIG_WORK_PERIOD
));
1339 void batadv_purge_orig_ref(struct batadv_priv
*bat_priv
)
1341 _batadv_purge_orig(bat_priv
);
1344 #ifdef CONFIG_BATMAN_ADV_DEBUGFS
1345 int batadv_orig_seq_print_text(struct seq_file
*seq
, void *offset
)
1347 struct net_device
*net_dev
= (struct net_device
*)seq
->private;
1348 struct batadv_priv
*bat_priv
= netdev_priv(net_dev
);
1349 struct batadv_hard_iface
*primary_if
;
1351 primary_if
= batadv_seq_print_text_primary_if_get(seq
);
1355 seq_printf(seq
, "[B.A.T.M.A.N. adv %s, MainIF/MAC: %s/%pM (%s %s)]\n",
1356 BATADV_SOURCE_VERSION
, primary_if
->net_dev
->name
,
1357 primary_if
->net_dev
->dev_addr
, net_dev
->name
,
1358 bat_priv
->algo_ops
->name
);
1360 batadv_hardif_put(primary_if
);
1362 if (!bat_priv
->algo_ops
->orig
.print
) {
1364 "No printing function for this routing protocol\n");
1368 bat_priv
->algo_ops
->orig
.print(bat_priv
, seq
, BATADV_IF_DEFAULT
);
1374 * batadv_orig_hardif_seq_print_text - writes originator infos for a specific
1375 * outgoing interface
1376 * @seq: debugfs table seq_file struct
1381 int batadv_orig_hardif_seq_print_text(struct seq_file
*seq
, void *offset
)
1383 struct net_device
*net_dev
= (struct net_device
*)seq
->private;
1384 struct batadv_hard_iface
*hard_iface
;
1385 struct batadv_priv
*bat_priv
;
1387 hard_iface
= batadv_hardif_get_by_netdev(net_dev
);
1389 if (!hard_iface
|| !hard_iface
->soft_iface
) {
1390 seq_puts(seq
, "Interface not known to B.A.T.M.A.N.\n");
1394 bat_priv
= netdev_priv(hard_iface
->soft_iface
);
1395 if (!bat_priv
->algo_ops
->orig
.print
) {
1397 "No printing function for this routing protocol\n");
1401 if (hard_iface
->if_status
!= BATADV_IF_ACTIVE
) {
1402 seq_puts(seq
, "Interface not active\n");
1406 seq_printf(seq
, "[B.A.T.M.A.N. adv %s, IF/MAC: %s/%pM (%s %s)]\n",
1407 BATADV_SOURCE_VERSION
, hard_iface
->net_dev
->name
,
1408 hard_iface
->net_dev
->dev_addr
,
1409 hard_iface
->soft_iface
->name
, bat_priv
->algo_ops
->name
);
1411 bat_priv
->algo_ops
->orig
.print(bat_priv
, seq
, hard_iface
);
1415 batadv_hardif_put(hard_iface
);
1421 * batadv_orig_dump - Dump to netlink the originator infos for a specific
1422 * outgoing interface
1423 * @msg: message to dump into
1424 * @cb: parameters for the dump
1426 * Return: 0 or error value
1428 int batadv_orig_dump(struct sk_buff
*msg
, struct netlink_callback
*cb
)
1430 struct net
*net
= sock_net(cb
->skb
->sk
);
1431 struct net_device
*soft_iface
;
1432 struct net_device
*hard_iface
= NULL
;
1433 struct batadv_hard_iface
*hardif
= BATADV_IF_DEFAULT
;
1434 struct batadv_priv
*bat_priv
;
1435 struct batadv_hard_iface
*primary_if
= NULL
;
1437 int ifindex
, hard_ifindex
;
1439 ifindex
= batadv_netlink_get_ifindex(cb
->nlh
, BATADV_ATTR_MESH_IFINDEX
);
1443 soft_iface
= dev_get_by_index(net
, ifindex
);
1444 if (!soft_iface
|| !batadv_softif_is_valid(soft_iface
)) {
1449 bat_priv
= netdev_priv(soft_iface
);
1451 primary_if
= batadv_primary_if_get_selected(bat_priv
);
1452 if (!primary_if
|| primary_if
->if_status
!= BATADV_IF_ACTIVE
) {
1457 hard_ifindex
= batadv_netlink_get_ifindex(cb
->nlh
,
1458 BATADV_ATTR_HARD_IFINDEX
);
1460 hard_iface
= dev_get_by_index(net
, hard_ifindex
);
1462 hardif
= batadv_hardif_get_by_netdev(hard_iface
);
1469 if (hardif
->soft_iface
!= soft_iface
) {
1475 if (!bat_priv
->algo_ops
->orig
.dump
) {
1480 bat_priv
->algo_ops
->orig
.dump(msg
, cb
, bat_priv
, hardif
);
1486 batadv_hardif_put(hardif
);
1488 dev_put(hard_iface
);
1490 batadv_hardif_put(primary_if
);
1492 dev_put(soft_iface
);
1497 int batadv_orig_hash_add_if(struct batadv_hard_iface
*hard_iface
,
1500 struct batadv_priv
*bat_priv
= netdev_priv(hard_iface
->soft_iface
);
1501 struct batadv_algo_ops
*bao
= bat_priv
->algo_ops
;
1502 struct batadv_hashtable
*hash
= bat_priv
->orig_hash
;
1503 struct hlist_head
*head
;
1504 struct batadv_orig_node
*orig_node
;
1508 /* resize all orig nodes because orig_node->bcast_own(_sum) depend on
1511 for (i
= 0; i
< hash
->size
; i
++) {
1512 head
= &hash
->table
[i
];
1515 hlist_for_each_entry_rcu(orig_node
, head
, hash_entry
) {
1517 if (bao
->orig
.add_if
)
1518 ret
= bao
->orig
.add_if(orig_node
, max_if_num
);
1532 int batadv_orig_hash_del_if(struct batadv_hard_iface
*hard_iface
,
1535 struct batadv_priv
*bat_priv
= netdev_priv(hard_iface
->soft_iface
);
1536 struct batadv_hashtable
*hash
= bat_priv
->orig_hash
;
1537 struct hlist_head
*head
;
1538 struct batadv_hard_iface
*hard_iface_tmp
;
1539 struct batadv_orig_node
*orig_node
;
1540 struct batadv_algo_ops
*bao
= bat_priv
->algo_ops
;
1544 /* resize all orig nodes because orig_node->bcast_own(_sum) depend on
1547 for (i
= 0; i
< hash
->size
; i
++) {
1548 head
= &hash
->table
[i
];
1551 hlist_for_each_entry_rcu(orig_node
, head
, hash_entry
) {
1553 if (bao
->orig
.del_if
)
1554 ret
= bao
->orig
.del_if(orig_node
, max_if_num
,
1555 hard_iface
->if_num
);
1562 /* renumber remaining batman interfaces _inside_ of orig_hash_lock */
1564 list_for_each_entry_rcu(hard_iface_tmp
, &batadv_hardif_list
, list
) {
1565 if (hard_iface_tmp
->if_status
== BATADV_IF_NOT_IN_USE
)
1568 if (hard_iface
== hard_iface_tmp
)
1571 if (hard_iface
->soft_iface
!= hard_iface_tmp
->soft_iface
)
1574 if (hard_iface_tmp
->if_num
> hard_iface
->if_num
)
1575 hard_iface_tmp
->if_num
--;
1579 hard_iface
->if_num
= -1;