1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2013-2020 B.A.T.M.A.N. contributors:
4 * Linus Lüssing, Marek Lindner
10 #include <linux/atomic.h>
11 #include <linux/cache.h>
12 #include <linux/errno.h>
13 #include <linux/if_ether.h>
14 #include <linux/init.h>
15 #include <linux/jiffies.h>
16 #include <linux/kref.h>
17 #include <linux/list.h>
18 #include <linux/minmax.h>
19 #include <linux/netdevice.h>
20 #include <linux/netlink.h>
21 #include <linux/rculist.h>
22 #include <linux/rcupdate.h>
23 #include <linux/skbuff.h>
24 #include <linux/spinlock.h>
25 #include <linux/stddef.h>
26 #include <linux/types.h>
27 #include <linux/workqueue.h>
28 #include <net/genetlink.h>
29 #include <net/netlink.h>
30 #include <uapi/linux/batadv_packet.h>
31 #include <uapi/linux/batman_adv.h>
34 #include "bat_v_elp.h"
35 #include "bat_v_ogm.h"
36 #include "gateway_client.h"
37 #include "gateway_common.h"
38 #include "hard-interface.h"
42 #include "originator.h"
44 static void batadv_v_iface_activate(struct batadv_hard_iface
*hard_iface
)
46 struct batadv_priv
*bat_priv
= netdev_priv(hard_iface
->soft_iface
);
47 struct batadv_hard_iface
*primary_if
;
49 primary_if
= batadv_primary_if_get_selected(bat_priv
);
52 batadv_v_elp_iface_activate(primary_if
, hard_iface
);
53 batadv_hardif_put(primary_if
);
56 /* B.A.T.M.A.N. V does not use any queuing mechanism, therefore it can
57 * set the interface as ACTIVE right away, without any risk of race
60 if (hard_iface
->if_status
== BATADV_IF_TO_BE_ACTIVATED
)
61 hard_iface
->if_status
= BATADV_IF_ACTIVE
;
64 static int batadv_v_iface_enable(struct batadv_hard_iface
*hard_iface
)
68 ret
= batadv_v_elp_iface_enable(hard_iface
);
72 ret
= batadv_v_ogm_iface_enable(hard_iface
);
74 batadv_v_elp_iface_disable(hard_iface
);
79 static void batadv_v_iface_disable(struct batadv_hard_iface
*hard_iface
)
81 batadv_v_ogm_iface_disable(hard_iface
);
82 batadv_v_elp_iface_disable(hard_iface
);
85 static void batadv_v_primary_iface_set(struct batadv_hard_iface
*hard_iface
)
87 batadv_v_elp_primary_iface_set(hard_iface
);
88 batadv_v_ogm_primary_iface_set(hard_iface
);
92 * batadv_v_iface_update_mac() - react to hard-interface MAC address change
93 * @hard_iface: the modified interface
95 * If the modified interface is the primary one, update the originator
96 * address in the ELP and OGM messages to reflect the new MAC address.
98 static void batadv_v_iface_update_mac(struct batadv_hard_iface
*hard_iface
)
100 struct batadv_priv
*bat_priv
= netdev_priv(hard_iface
->soft_iface
);
101 struct batadv_hard_iface
*primary_if
;
103 primary_if
= batadv_primary_if_get_selected(bat_priv
);
104 if (primary_if
!= hard_iface
)
107 batadv_v_primary_iface_set(hard_iface
);
110 batadv_hardif_put(primary_if
);
114 batadv_v_hardif_neigh_init(struct batadv_hardif_neigh_node
*hardif_neigh
)
116 ewma_throughput_init(&hardif_neigh
->bat_v
.throughput
);
117 INIT_WORK(&hardif_neigh
->bat_v
.metric_work
,
118 batadv_v_elp_throughput_metric_update
);
122 * batadv_v_neigh_dump_neigh() - Dump a neighbour into a message
123 * @msg: Netlink message to dump into
124 * @portid: Port making netlink request
125 * @seq: Sequence number of netlink message
126 * @hardif_neigh: Neighbour to dump
128 * Return: Error code, or 0 on success
131 batadv_v_neigh_dump_neigh(struct sk_buff
*msg
, u32 portid
, u32 seq
,
132 struct batadv_hardif_neigh_node
*hardif_neigh
)
135 unsigned int last_seen_msecs
;
138 last_seen_msecs
= jiffies_to_msecs(jiffies
- hardif_neigh
->last_seen
);
139 throughput
= ewma_throughput_read(&hardif_neigh
->bat_v
.throughput
);
140 throughput
= throughput
* 100;
142 hdr
= genlmsg_put(msg
, portid
, seq
, &batadv_netlink_family
, NLM_F_MULTI
,
143 BATADV_CMD_GET_NEIGHBORS
);
147 if (nla_put(msg
, BATADV_ATTR_NEIGH_ADDRESS
, ETH_ALEN
,
148 hardif_neigh
->addr
) ||
149 nla_put_u32(msg
, BATADV_ATTR_HARD_IFINDEX
,
150 hardif_neigh
->if_incoming
->net_dev
->ifindex
) ||
151 nla_put_u32(msg
, BATADV_ATTR_LAST_SEEN_MSECS
,
153 nla_put_u32(msg
, BATADV_ATTR_THROUGHPUT
, throughput
))
154 goto nla_put_failure
;
156 genlmsg_end(msg
, hdr
);
160 genlmsg_cancel(msg
, hdr
);
165 * batadv_v_neigh_dump_hardif() - Dump the neighbours of a hard interface into
167 * @msg: Netlink message to dump into
168 * @portid: Port making netlink request
169 * @seq: Sequence number of netlink message
170 * @bat_priv: The bat priv with all the soft interface information
171 * @hard_iface: The hard interface to be dumped
172 * @idx_s: Entries to be skipped
174 * This function assumes the caller holds rcu_read_lock().
176 * Return: Error code, or 0 on success
179 batadv_v_neigh_dump_hardif(struct sk_buff
*msg
, u32 portid
, u32 seq
,
180 struct batadv_priv
*bat_priv
,
181 struct batadv_hard_iface
*hard_iface
,
184 struct batadv_hardif_neigh_node
*hardif_neigh
;
187 hlist_for_each_entry_rcu(hardif_neigh
,
188 &hard_iface
->neigh_list
, list
) {
192 if (batadv_v_neigh_dump_neigh(msg
, portid
, seq
, hardif_neigh
)) {
203 * batadv_v_neigh_dump() - Dump the neighbours of a hard interface into a
205 * @msg: Netlink message to dump into
206 * @cb: Control block containing additional options
207 * @bat_priv: The bat priv with all the soft interface information
208 * @single_hardif: Limit dumping to this hard interface
211 batadv_v_neigh_dump(struct sk_buff
*msg
, struct netlink_callback
*cb
,
212 struct batadv_priv
*bat_priv
,
213 struct batadv_hard_iface
*single_hardif
)
215 struct batadv_hard_iface
*hard_iface
;
217 int i_hardif_s
= cb
->args
[0];
218 int idx
= cb
->args
[1];
219 int portid
= NETLINK_CB(cb
->skb
).portid
;
223 if (i_hardif_s
== 0) {
224 if (batadv_v_neigh_dump_hardif(msg
, portid
,
226 bat_priv
, single_hardif
,
231 list_for_each_entry_rcu(hard_iface
, &batadv_hardif_list
, list
) {
232 if (hard_iface
->soft_iface
!= bat_priv
->soft_iface
)
235 if (i_hardif
++ < i_hardif_s
)
238 if (batadv_v_neigh_dump_hardif(msg
, portid
,
240 bat_priv
, hard_iface
,
249 cb
->args
[0] = i_hardif
;
254 * batadv_v_orig_dump_subentry() - Dump an originator subentry into a message
255 * @msg: Netlink message to dump into
256 * @portid: Port making netlink request
257 * @seq: Sequence number of netlink message
258 * @bat_priv: The bat priv with all the soft interface information
259 * @if_outgoing: Limit dump to entries with this outgoing interface
260 * @orig_node: Originator to dump
261 * @neigh_node: Single hops neighbour
262 * @best: Is the best originator
264 * Return: Error code, or 0 on success
267 batadv_v_orig_dump_subentry(struct sk_buff
*msg
, u32 portid
, u32 seq
,
268 struct batadv_priv
*bat_priv
,
269 struct batadv_hard_iface
*if_outgoing
,
270 struct batadv_orig_node
*orig_node
,
271 struct batadv_neigh_node
*neigh_node
,
274 struct batadv_neigh_ifinfo
*n_ifinfo
;
275 unsigned int last_seen_msecs
;
279 n_ifinfo
= batadv_neigh_ifinfo_get(neigh_node
, if_outgoing
);
283 throughput
= n_ifinfo
->bat_v
.throughput
* 100;
285 batadv_neigh_ifinfo_put(n_ifinfo
);
287 last_seen_msecs
= jiffies_to_msecs(jiffies
- orig_node
->last_seen
);
289 if (if_outgoing
!= BATADV_IF_DEFAULT
&&
290 if_outgoing
!= neigh_node
->if_incoming
)
293 hdr
= genlmsg_put(msg
, portid
, seq
, &batadv_netlink_family
, NLM_F_MULTI
,
294 BATADV_CMD_GET_ORIGINATORS
);
298 if (nla_put(msg
, BATADV_ATTR_ORIG_ADDRESS
, ETH_ALEN
, orig_node
->orig
) ||
299 nla_put(msg
, BATADV_ATTR_NEIGH_ADDRESS
, ETH_ALEN
,
301 nla_put_u32(msg
, BATADV_ATTR_HARD_IFINDEX
,
302 neigh_node
->if_incoming
->net_dev
->ifindex
) ||
303 nla_put_u32(msg
, BATADV_ATTR_THROUGHPUT
, throughput
) ||
304 nla_put_u32(msg
, BATADV_ATTR_LAST_SEEN_MSECS
,
306 goto nla_put_failure
;
308 if (best
&& nla_put_flag(msg
, BATADV_ATTR_FLAG_BEST
))
309 goto nla_put_failure
;
311 genlmsg_end(msg
, hdr
);
315 genlmsg_cancel(msg
, hdr
);
320 * batadv_v_orig_dump_entry() - Dump an originator entry into a message
321 * @msg: Netlink message to dump into
322 * @portid: Port making netlink request
323 * @seq: Sequence number of netlink message
324 * @bat_priv: The bat priv with all the soft interface information
325 * @if_outgoing: Limit dump to entries with this outgoing interface
326 * @orig_node: Originator to dump
327 * @sub_s: Number of sub entries to skip
329 * This function assumes the caller holds rcu_read_lock().
331 * Return: Error code, or 0 on success
334 batadv_v_orig_dump_entry(struct sk_buff
*msg
, u32 portid
, u32 seq
,
335 struct batadv_priv
*bat_priv
,
336 struct batadv_hard_iface
*if_outgoing
,
337 struct batadv_orig_node
*orig_node
, int *sub_s
)
339 struct batadv_neigh_node
*neigh_node_best
;
340 struct batadv_neigh_node
*neigh_node
;
344 neigh_node_best
= batadv_orig_router_get(orig_node
, if_outgoing
);
345 if (!neigh_node_best
)
348 hlist_for_each_entry_rcu(neigh_node
, &orig_node
->neigh_list
, list
) {
352 best
= (neigh_node
== neigh_node_best
);
354 if (batadv_v_orig_dump_subentry(msg
, portid
, seq
, bat_priv
,
355 if_outgoing
, orig_node
,
357 batadv_neigh_node_put(neigh_node_best
);
366 batadv_neigh_node_put(neigh_node_best
);
373 * batadv_v_orig_dump_bucket() - Dump an originator bucket into a message
374 * @msg: Netlink message to dump into
375 * @portid: Port making netlink request
376 * @seq: Sequence number of netlink message
377 * @bat_priv: The bat priv with all the soft interface information
378 * @if_outgoing: Limit dump to entries with this outgoing interface
379 * @head: Bucket to be dumped
380 * @idx_s: Number of entries to be skipped
381 * @sub: Number of sub entries to be skipped
383 * Return: Error code, or 0 on success
386 batadv_v_orig_dump_bucket(struct sk_buff
*msg
, u32 portid
, u32 seq
,
387 struct batadv_priv
*bat_priv
,
388 struct batadv_hard_iface
*if_outgoing
,
389 struct hlist_head
*head
, int *idx_s
, int *sub
)
391 struct batadv_orig_node
*orig_node
;
395 hlist_for_each_entry_rcu(orig_node
, head
, hash_entry
) {
399 if (batadv_v_orig_dump_entry(msg
, portid
, seq
, bat_priv
,
400 if_outgoing
, orig_node
, sub
)) {
414 * batadv_v_orig_dump() - Dump the originators into a message
415 * @msg: Netlink message to dump into
416 * @cb: Control block containing additional options
417 * @bat_priv: The bat priv with all the soft interface information
418 * @if_outgoing: Limit dump to entries with this outgoing interface
421 batadv_v_orig_dump(struct sk_buff
*msg
, struct netlink_callback
*cb
,
422 struct batadv_priv
*bat_priv
,
423 struct batadv_hard_iface
*if_outgoing
)
425 struct batadv_hashtable
*hash
= bat_priv
->orig_hash
;
426 struct hlist_head
*head
;
427 int bucket
= cb
->args
[0];
428 int idx
= cb
->args
[1];
429 int sub
= cb
->args
[2];
430 int portid
= NETLINK_CB(cb
->skb
).portid
;
432 while (bucket
< hash
->size
) {
433 head
= &hash
->table
[bucket
];
435 if (batadv_v_orig_dump_bucket(msg
, portid
,
437 bat_priv
, if_outgoing
, head
, &idx
,
444 cb
->args
[0] = bucket
;
449 static int batadv_v_neigh_cmp(struct batadv_neigh_node
*neigh1
,
450 struct batadv_hard_iface
*if_outgoing1
,
451 struct batadv_neigh_node
*neigh2
,
452 struct batadv_hard_iface
*if_outgoing2
)
454 struct batadv_neigh_ifinfo
*ifinfo1
, *ifinfo2
;
457 ifinfo1
= batadv_neigh_ifinfo_get(neigh1
, if_outgoing1
);
461 ifinfo2
= batadv_neigh_ifinfo_get(neigh2
, if_outgoing2
);
465 ret
= ifinfo1
->bat_v
.throughput
- ifinfo2
->bat_v
.throughput
;
467 batadv_neigh_ifinfo_put(ifinfo2
);
469 batadv_neigh_ifinfo_put(ifinfo1
);
474 static bool batadv_v_neigh_is_sob(struct batadv_neigh_node
*neigh1
,
475 struct batadv_hard_iface
*if_outgoing1
,
476 struct batadv_neigh_node
*neigh2
,
477 struct batadv_hard_iface
*if_outgoing2
)
479 struct batadv_neigh_ifinfo
*ifinfo1
, *ifinfo2
;
483 ifinfo1
= batadv_neigh_ifinfo_get(neigh1
, if_outgoing1
);
487 ifinfo2
= batadv_neigh_ifinfo_get(neigh2
, if_outgoing2
);
491 threshold
= ifinfo1
->bat_v
.throughput
/ 4;
492 threshold
= ifinfo1
->bat_v
.throughput
- threshold
;
494 ret
= ifinfo2
->bat_v
.throughput
> threshold
;
496 batadv_neigh_ifinfo_put(ifinfo2
);
498 batadv_neigh_ifinfo_put(ifinfo1
);
504 * batadv_v_init_sel_class() - initialize GW selection class
505 * @bat_priv: the bat priv with all the soft interface information
507 static void batadv_v_init_sel_class(struct batadv_priv
*bat_priv
)
509 /* set default throughput difference threshold to 5Mbps */
510 atomic_set(&bat_priv
->gw
.sel_class
, 50);
513 static ssize_t
batadv_v_store_sel_class(struct batadv_priv
*bat_priv
,
514 char *buff
, size_t count
)
516 u32 old_class
, class;
518 if (!batadv_parse_throughput(bat_priv
->soft_iface
, buff
,
519 "B.A.T.M.A.N. V GW selection class",
523 old_class
= atomic_read(&bat_priv
->gw
.sel_class
);
524 atomic_set(&bat_priv
->gw
.sel_class
, class);
526 if (old_class
!= class)
527 batadv_gw_reselect(bat_priv
);
533 * batadv_v_gw_throughput_get() - retrieve the GW-bandwidth for a given GW
534 * @gw_node: the GW to retrieve the metric for
535 * @bw: the pointer where the metric will be stored. The metric is computed as
536 * the minimum between the GW advertised throughput and the path throughput to
539 * Return: 0 on success, -1 on failure
541 static int batadv_v_gw_throughput_get(struct batadv_gw_node
*gw_node
, u32
*bw
)
543 struct batadv_neigh_ifinfo
*router_ifinfo
= NULL
;
544 struct batadv_orig_node
*orig_node
;
545 struct batadv_neigh_node
*router
;
548 orig_node
= gw_node
->orig_node
;
549 router
= batadv_orig_router_get(orig_node
, BATADV_IF_DEFAULT
);
553 router_ifinfo
= batadv_neigh_ifinfo_get(router
, BATADV_IF_DEFAULT
);
557 /* the GW metric is computed as the minimum between the path throughput
558 * to reach the GW itself and the advertised bandwidth.
559 * This gives us an approximation of the effective throughput that the
560 * client can expect via this particular GW node
562 *bw
= router_ifinfo
->bat_v
.throughput
;
563 *bw
= min_t(u32
, *bw
, gw_node
->bandwidth_down
);
568 batadv_neigh_node_put(router
);
570 batadv_neigh_ifinfo_put(router_ifinfo
);
576 * batadv_v_gw_get_best_gw_node() - retrieve the best GW node
577 * @bat_priv: the bat priv with all the soft interface information
579 * Return: the GW node having the best GW-metric, NULL if no GW is known
581 static struct batadv_gw_node
*
582 batadv_v_gw_get_best_gw_node(struct batadv_priv
*bat_priv
)
584 struct batadv_gw_node
*gw_node
, *curr_gw
= NULL
;
588 hlist_for_each_entry_rcu(gw_node
, &bat_priv
->gw
.gateway_list
, list
) {
589 if (!kref_get_unless_zero(&gw_node
->refcount
))
592 if (batadv_v_gw_throughput_get(gw_node
, &bw
) < 0)
595 if (curr_gw
&& bw
<= max_bw
)
599 batadv_gw_node_put(curr_gw
);
602 kref_get(&curr_gw
->refcount
);
606 batadv_gw_node_put(gw_node
);
614 * batadv_v_gw_is_eligible() - check if a originator would be selected as GW
615 * @bat_priv: the bat priv with all the soft interface information
616 * @curr_gw_orig: originator representing the currently selected GW
617 * @orig_node: the originator representing the new candidate
619 * Return: true if orig_node can be selected as current GW, false otherwise
621 static bool batadv_v_gw_is_eligible(struct batadv_priv
*bat_priv
,
622 struct batadv_orig_node
*curr_gw_orig
,
623 struct batadv_orig_node
*orig_node
)
625 struct batadv_gw_node
*curr_gw
, *orig_gw
= NULL
;
626 u32 gw_throughput
, orig_throughput
, threshold
;
629 threshold
= atomic_read(&bat_priv
->gw
.sel_class
);
631 curr_gw
= batadv_gw_node_get(bat_priv
, curr_gw_orig
);
637 if (batadv_v_gw_throughput_get(curr_gw
, &gw_throughput
) < 0) {
642 orig_gw
= batadv_gw_node_get(bat_priv
, orig_node
);
646 if (batadv_v_gw_throughput_get(orig_gw
, &orig_throughput
) < 0)
649 if (orig_throughput
< gw_throughput
)
652 if ((orig_throughput
- gw_throughput
) < threshold
)
655 batadv_dbg(BATADV_DBG_BATMAN
, bat_priv
,
656 "Restarting gateway selection: better gateway found (throughput curr: %u, throughput new: %u)\n",
657 gw_throughput
, orig_throughput
);
662 batadv_gw_node_put(curr_gw
);
664 batadv_gw_node_put(orig_gw
);
670 * batadv_v_gw_dump_entry() - Dump a gateway into a message
671 * @msg: Netlink message to dump into
672 * @portid: Port making netlink request
673 * @cb: Control block containing additional options
674 * @bat_priv: The bat priv with all the soft interface information
675 * @gw_node: Gateway to be dumped
677 * Return: Error code, or 0 on success
679 static int batadv_v_gw_dump_entry(struct sk_buff
*msg
, u32 portid
,
680 struct netlink_callback
*cb
,
681 struct batadv_priv
*bat_priv
,
682 struct batadv_gw_node
*gw_node
)
684 struct batadv_neigh_ifinfo
*router_ifinfo
= NULL
;
685 struct batadv_neigh_node
*router
;
686 struct batadv_gw_node
*curr_gw
= NULL
;
690 router
= batadv_orig_router_get(gw_node
->orig_node
, BATADV_IF_DEFAULT
);
694 router_ifinfo
= batadv_neigh_ifinfo_get(router
, BATADV_IF_DEFAULT
);
698 curr_gw
= batadv_gw_get_selected_gw_node(bat_priv
);
700 hdr
= genlmsg_put(msg
, portid
, cb
->nlh
->nlmsg_seq
,
701 &batadv_netlink_family
, NLM_F_MULTI
,
702 BATADV_CMD_GET_GATEWAYS
);
708 genl_dump_check_consistent(cb
, hdr
);
712 if (curr_gw
== gw_node
) {
713 if (nla_put_flag(msg
, BATADV_ATTR_FLAG_BEST
)) {
714 genlmsg_cancel(msg
, hdr
);
719 if (nla_put(msg
, BATADV_ATTR_ORIG_ADDRESS
, ETH_ALEN
,
720 gw_node
->orig_node
->orig
)) {
721 genlmsg_cancel(msg
, hdr
);
725 if (nla_put_u32(msg
, BATADV_ATTR_THROUGHPUT
,
726 router_ifinfo
->bat_v
.throughput
)) {
727 genlmsg_cancel(msg
, hdr
);
731 if (nla_put(msg
, BATADV_ATTR_ROUTER
, ETH_ALEN
, router
->addr
)) {
732 genlmsg_cancel(msg
, hdr
);
736 if (nla_put_string(msg
, BATADV_ATTR_HARD_IFNAME
,
737 router
->if_incoming
->net_dev
->name
)) {
738 genlmsg_cancel(msg
, hdr
);
742 if (nla_put_u32(msg
, BATADV_ATTR_BANDWIDTH_DOWN
,
743 gw_node
->bandwidth_down
)) {
744 genlmsg_cancel(msg
, hdr
);
748 if (nla_put_u32(msg
, BATADV_ATTR_BANDWIDTH_UP
, gw_node
->bandwidth_up
)) {
749 genlmsg_cancel(msg
, hdr
);
753 genlmsg_end(msg
, hdr
);
758 batadv_gw_node_put(curr_gw
);
760 batadv_neigh_ifinfo_put(router_ifinfo
);
762 batadv_neigh_node_put(router
);
767 * batadv_v_gw_dump() - Dump gateways into a message
768 * @msg: Netlink message to dump into
769 * @cb: Control block containing additional options
770 * @bat_priv: The bat priv with all the soft interface information
772 static void batadv_v_gw_dump(struct sk_buff
*msg
, struct netlink_callback
*cb
,
773 struct batadv_priv
*bat_priv
)
775 int portid
= NETLINK_CB(cb
->skb
).portid
;
776 struct batadv_gw_node
*gw_node
;
777 int idx_skip
= cb
->args
[0];
780 spin_lock_bh(&bat_priv
->gw
.list_lock
);
781 cb
->seq
= bat_priv
->gw
.generation
<< 1 | 1;
783 hlist_for_each_entry(gw_node
, &bat_priv
->gw
.gateway_list
, list
) {
784 if (idx
++ < idx_skip
)
787 if (batadv_v_gw_dump_entry(msg
, portid
, cb
, bat_priv
,
796 spin_unlock_bh(&bat_priv
->gw
.list_lock
);
798 cb
->args
[0] = idx_skip
;
801 static struct batadv_algo_ops batadv_batman_v __read_mostly
= {
804 .activate
= batadv_v_iface_activate
,
805 .enable
= batadv_v_iface_enable
,
806 .disable
= batadv_v_iface_disable
,
807 .update_mac
= batadv_v_iface_update_mac
,
808 .primary_set
= batadv_v_primary_iface_set
,
811 .hardif_init
= batadv_v_hardif_neigh_init
,
812 .cmp
= batadv_v_neigh_cmp
,
813 .is_similar_or_better
= batadv_v_neigh_is_sob
,
814 .dump
= batadv_v_neigh_dump
,
817 .dump
= batadv_v_orig_dump
,
820 .init_sel_class
= batadv_v_init_sel_class
,
821 .store_sel_class
= batadv_v_store_sel_class
,
822 .get_best_gw_node
= batadv_v_gw_get_best_gw_node
,
823 .is_eligible
= batadv_v_gw_is_eligible
,
824 .dump
= batadv_v_gw_dump
,
829 * batadv_v_hardif_init() - initialize the algorithm specific fields in the
830 * hard-interface object
831 * @hard_iface: the hard-interface to initialize
833 void batadv_v_hardif_init(struct batadv_hard_iface
*hard_iface
)
835 /* enable link throughput auto-detection by setting the throughput
838 atomic_set(&hard_iface
->bat_v
.throughput_override
, 0);
839 atomic_set(&hard_iface
->bat_v
.elp_interval
, 500);
841 hard_iface
->bat_v
.aggr_len
= 0;
842 skb_queue_head_init(&hard_iface
->bat_v
.aggr_list
);
843 INIT_DELAYED_WORK(&hard_iface
->bat_v
.aggr_wq
,
844 batadv_v_ogm_aggr_work
);
848 * batadv_v_mesh_init() - initialize the B.A.T.M.A.N. V private resources for a
850 * @bat_priv: the object representing the mesh interface to initialise
852 * Return: 0 on success or a negative error code otherwise
854 int batadv_v_mesh_init(struct batadv_priv
*bat_priv
)
858 ret
= batadv_v_ogm_init(bat_priv
);
866 * batadv_v_mesh_free() - free the B.A.T.M.A.N. V private resources for a mesh
867 * @bat_priv: the object representing the mesh interface to free
869 void batadv_v_mesh_free(struct batadv_priv
*bat_priv
)
871 batadv_v_ogm_free(bat_priv
);
875 * batadv_v_init() - B.A.T.M.A.N. V initialization function
877 * Description: Takes care of initializing all the subcomponents.
878 * It is invoked upon module load only.
880 * Return: 0 on success or a negative error code otherwise
882 int __init
batadv_v_init(void)
886 /* B.A.T.M.A.N. V echo location protocol packet */
887 ret
= batadv_recv_handler_register(BATADV_ELP
,
888 batadv_v_elp_packet_recv
);
892 ret
= batadv_recv_handler_register(BATADV_OGM2
,
893 batadv_v_ogm_packet_recv
);
897 ret
= batadv_algo_register(&batadv_batman_v
);
904 batadv_recv_handler_unregister(BATADV_OGM2
);
907 batadv_recv_handler_unregister(BATADV_ELP
);