1 /* Copyright (C) 2009-2016 B.A.T.M.A.N. contributors:
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 "gateway_client.h"
21 #include <linux/atomic.h>
22 #include <linux/byteorder/generic.h>
23 #include <linux/errno.h>
24 #include <linux/etherdevice.h>
26 #include <linux/if_ether.h>
27 #include <linux/if_vlan.h>
30 #include <linux/ipv6.h>
31 #include <linux/kernel.h>
32 #include <linux/kref.h>
33 #include <linux/list.h>
34 #include <linux/netdevice.h>
35 #include <linux/netlink.h>
36 #include <linux/rculist.h>
37 #include <linux/rcupdate.h>
38 #include <linux/seq_file.h>
39 #include <linux/skbuff.h>
40 #include <linux/slab.h>
41 #include <linux/spinlock.h>
42 #include <linux/stddef.h>
43 #include <linux/udp.h>
45 #include <uapi/linux/batman_adv.h>
47 #include "gateway_common.h"
48 #include "hard-interface.h"
51 #include "originator.h"
54 #include "soft-interface.h"
56 #include "translation-table.h"
58 /* These are the offsets of the "hw type" and "hw address length" in the dhcp
59 * packet starting at the beginning of the dhcp header
61 #define BATADV_DHCP_HTYPE_OFFSET 1
62 #define BATADV_DHCP_HLEN_OFFSET 2
63 /* Value of htype representing Ethernet */
64 #define BATADV_DHCP_HTYPE_ETHERNET 0x01
65 /* This is the offset of the "chaddr" field in the dhcp packet starting at the
66 * beginning of the dhcp header
68 #define BATADV_DHCP_CHADDR_OFFSET 28
71 * batadv_gw_node_release - release gw_node from lists and queue for free after
73 * @ref: kref pointer of the gw_node
75 static void batadv_gw_node_release(struct kref
*ref
)
77 struct batadv_gw_node
*gw_node
;
79 gw_node
= container_of(ref
, struct batadv_gw_node
, refcount
);
81 batadv_orig_node_put(gw_node
->orig_node
);
82 kfree_rcu(gw_node
, rcu
);
86 * batadv_gw_node_put - decrement the gw_node refcounter and possibly release it
87 * @gw_node: gateway node to free
89 void batadv_gw_node_put(struct batadv_gw_node
*gw_node
)
91 kref_put(&gw_node
->refcount
, batadv_gw_node_release
);
94 struct batadv_gw_node
*
95 batadv_gw_get_selected_gw_node(struct batadv_priv
*bat_priv
)
97 struct batadv_gw_node
*gw_node
;
100 gw_node
= rcu_dereference(bat_priv
->gw
.curr_gw
);
104 if (!kref_get_unless_zero(&gw_node
->refcount
))
112 struct batadv_orig_node
*
113 batadv_gw_get_selected_orig(struct batadv_priv
*bat_priv
)
115 struct batadv_gw_node
*gw_node
;
116 struct batadv_orig_node
*orig_node
= NULL
;
118 gw_node
= batadv_gw_get_selected_gw_node(bat_priv
);
123 orig_node
= gw_node
->orig_node
;
127 if (!kref_get_unless_zero(&orig_node
->refcount
))
134 batadv_gw_node_put(gw_node
);
138 static void batadv_gw_select(struct batadv_priv
*bat_priv
,
139 struct batadv_gw_node
*new_gw_node
)
141 struct batadv_gw_node
*curr_gw_node
;
143 spin_lock_bh(&bat_priv
->gw
.list_lock
);
146 kref_get(&new_gw_node
->refcount
);
148 curr_gw_node
= rcu_dereference_protected(bat_priv
->gw
.curr_gw
, 1);
149 rcu_assign_pointer(bat_priv
->gw
.curr_gw
, new_gw_node
);
152 batadv_gw_node_put(curr_gw_node
);
154 spin_unlock_bh(&bat_priv
->gw
.list_lock
);
158 * batadv_gw_reselect - force a gateway reselection
159 * @bat_priv: the bat priv with all the soft interface information
161 * Set a flag to remind the GW component to perform a new gateway reselection.
162 * However this function does not ensure that the current gateway is going to be
163 * deselected. The reselection mechanism may elect the same gateway once again.
165 * This means that invoking batadv_gw_reselect() does not guarantee a gateway
166 * change and therefore a uevent is not necessarily expected.
168 void batadv_gw_reselect(struct batadv_priv
*bat_priv
)
170 atomic_set(&bat_priv
->gw
.reselect
, 1);
174 * batadv_gw_check_client_stop - check if client mode has been switched off
175 * @bat_priv: the bat priv with all the soft interface information
177 * This function assumes the caller has checked that the gw state *is actually
178 * changing*. This function is not supposed to be called when there is no state
181 void batadv_gw_check_client_stop(struct batadv_priv
*bat_priv
)
183 struct batadv_gw_node
*curr_gw
;
185 if (atomic_read(&bat_priv
->gw
.mode
) != BATADV_GW_MODE_CLIENT
)
188 curr_gw
= batadv_gw_get_selected_gw_node(bat_priv
);
192 /* deselect the current gateway so that next time that client mode is
193 * enabled a proper GW_ADD event can be sent
195 batadv_gw_select(bat_priv
, NULL
);
197 /* if batman-adv is switching the gw client mode off and a gateway was
198 * already selected, send a DEL uevent
200 batadv_throw_uevent(bat_priv
, BATADV_UEV_GW
, BATADV_UEV_DEL
, NULL
);
202 batadv_gw_node_put(curr_gw
);
205 void batadv_gw_election(struct batadv_priv
*bat_priv
)
207 struct batadv_gw_node
*curr_gw
= NULL
;
208 struct batadv_gw_node
*next_gw
= NULL
;
209 struct batadv_neigh_node
*router
= NULL
;
210 struct batadv_neigh_ifinfo
*router_ifinfo
= NULL
;
211 char gw_addr
[18] = { '\0' };
213 if (atomic_read(&bat_priv
->gw
.mode
) != BATADV_GW_MODE_CLIENT
)
216 if (!bat_priv
->algo_ops
->gw
.get_best_gw_node
)
219 curr_gw
= batadv_gw_get_selected_gw_node(bat_priv
);
221 if (!batadv_atomic_dec_not_zero(&bat_priv
->gw
.reselect
) && curr_gw
)
224 /* if gw.reselect is set to 1 it means that a previous call to
225 * gw.is_eligible() said that we have a new best GW, therefore it can
226 * now be picked from the list and selected
228 next_gw
= bat_priv
->algo_ops
->gw
.get_best_gw_node(bat_priv
);
230 if (curr_gw
== next_gw
)
234 sprintf(gw_addr
, "%pM", next_gw
->orig_node
->orig
);
236 router
= batadv_orig_router_get(next_gw
->orig_node
,
239 batadv_gw_reselect(bat_priv
);
243 router_ifinfo
= batadv_neigh_ifinfo_get(router
,
245 if (!router_ifinfo
) {
246 batadv_gw_reselect(bat_priv
);
251 if ((curr_gw
) && (!next_gw
)) {
252 batadv_dbg(BATADV_DBG_BATMAN
, bat_priv
,
253 "Removing selected gateway - no gateway in range\n");
254 batadv_throw_uevent(bat_priv
, BATADV_UEV_GW
, BATADV_UEV_DEL
,
256 } else if ((!curr_gw
) && (next_gw
)) {
257 batadv_dbg(BATADV_DBG_BATMAN
, bat_priv
,
258 "Adding route to gateway %pM (bandwidth: %u.%u/%u.%u MBit, tq: %i)\n",
259 next_gw
->orig_node
->orig
,
260 next_gw
->bandwidth_down
/ 10,
261 next_gw
->bandwidth_down
% 10,
262 next_gw
->bandwidth_up
/ 10,
263 next_gw
->bandwidth_up
% 10,
264 router_ifinfo
->bat_iv
.tq_avg
);
265 batadv_throw_uevent(bat_priv
, BATADV_UEV_GW
, BATADV_UEV_ADD
,
268 batadv_dbg(BATADV_DBG_BATMAN
, bat_priv
,
269 "Changing route to gateway %pM (bandwidth: %u.%u/%u.%u MBit, tq: %i)\n",
270 next_gw
->orig_node
->orig
,
271 next_gw
->bandwidth_down
/ 10,
272 next_gw
->bandwidth_down
% 10,
273 next_gw
->bandwidth_up
/ 10,
274 next_gw
->bandwidth_up
% 10,
275 router_ifinfo
->bat_iv
.tq_avg
);
276 batadv_throw_uevent(bat_priv
, BATADV_UEV_GW
, BATADV_UEV_CHANGE
,
280 batadv_gw_select(bat_priv
, next_gw
);
284 batadv_gw_node_put(curr_gw
);
286 batadv_gw_node_put(next_gw
);
288 batadv_neigh_node_put(router
);
290 batadv_neigh_ifinfo_put(router_ifinfo
);
293 void batadv_gw_check_election(struct batadv_priv
*bat_priv
,
294 struct batadv_orig_node
*orig_node
)
296 struct batadv_orig_node
*curr_gw_orig
;
298 /* abort immediately if the routing algorithm does not support gateway
301 if (!bat_priv
->algo_ops
->gw
.is_eligible
)
304 curr_gw_orig
= batadv_gw_get_selected_orig(bat_priv
);
308 /* this node already is the gateway */
309 if (curr_gw_orig
== orig_node
)
312 if (!bat_priv
->algo_ops
->gw
.is_eligible(bat_priv
, curr_gw_orig
,
317 batadv_gw_reselect(bat_priv
);
320 batadv_orig_node_put(curr_gw_orig
);
324 * batadv_gw_node_add - add gateway node to list of available gateways
325 * @bat_priv: the bat priv with all the soft interface information
326 * @orig_node: originator announcing gateway capabilities
327 * @gateway: announced bandwidth information
329 static void batadv_gw_node_add(struct batadv_priv
*bat_priv
,
330 struct batadv_orig_node
*orig_node
,
331 struct batadv_tvlv_gateway_data
*gateway
)
333 struct batadv_gw_node
*gw_node
;
335 if (gateway
->bandwidth_down
== 0)
338 gw_node
= kzalloc(sizeof(*gw_node
), GFP_ATOMIC
);
342 kref_get(&orig_node
->refcount
);
343 INIT_HLIST_NODE(&gw_node
->list
);
344 gw_node
->orig_node
= orig_node
;
345 gw_node
->bandwidth_down
= ntohl(gateway
->bandwidth_down
);
346 gw_node
->bandwidth_up
= ntohl(gateway
->bandwidth_up
);
347 kref_init(&gw_node
->refcount
);
349 spin_lock_bh(&bat_priv
->gw
.list_lock
);
350 hlist_add_head_rcu(&gw_node
->list
, &bat_priv
->gw
.list
);
351 spin_unlock_bh(&bat_priv
->gw
.list_lock
);
353 batadv_dbg(BATADV_DBG_BATMAN
, bat_priv
,
354 "Found new gateway %pM -> gw bandwidth: %u.%u/%u.%u MBit\n",
356 ntohl(gateway
->bandwidth_down
) / 10,
357 ntohl(gateway
->bandwidth_down
) % 10,
358 ntohl(gateway
->bandwidth_up
) / 10,
359 ntohl(gateway
->bandwidth_up
) % 10);
363 * batadv_gw_node_get - retrieve gateway node from list of available gateways
364 * @bat_priv: the bat priv with all the soft interface information
365 * @orig_node: originator announcing gateway capabilities
367 * Return: gateway node if found or NULL otherwise.
369 struct batadv_gw_node
*batadv_gw_node_get(struct batadv_priv
*bat_priv
,
370 struct batadv_orig_node
*orig_node
)
372 struct batadv_gw_node
*gw_node_tmp
, *gw_node
= NULL
;
375 hlist_for_each_entry_rcu(gw_node_tmp
, &bat_priv
->gw
.list
, list
) {
376 if (gw_node_tmp
->orig_node
!= orig_node
)
379 if (!kref_get_unless_zero(&gw_node_tmp
->refcount
))
382 gw_node
= gw_node_tmp
;
391 * batadv_gw_node_update - update list of available gateways with changed
392 * bandwidth information
393 * @bat_priv: the bat priv with all the soft interface information
394 * @orig_node: originator announcing gateway capabilities
395 * @gateway: announced bandwidth information
397 void batadv_gw_node_update(struct batadv_priv
*bat_priv
,
398 struct batadv_orig_node
*orig_node
,
399 struct batadv_tvlv_gateway_data
*gateway
)
401 struct batadv_gw_node
*gw_node
, *curr_gw
= NULL
;
403 gw_node
= batadv_gw_node_get(bat_priv
, orig_node
);
405 batadv_gw_node_add(bat_priv
, orig_node
, gateway
);
409 if ((gw_node
->bandwidth_down
== ntohl(gateway
->bandwidth_down
)) &&
410 (gw_node
->bandwidth_up
== ntohl(gateway
->bandwidth_up
)))
413 batadv_dbg(BATADV_DBG_BATMAN
, bat_priv
,
414 "Gateway bandwidth of originator %pM changed from %u.%u/%u.%u MBit to %u.%u/%u.%u MBit\n",
416 gw_node
->bandwidth_down
/ 10,
417 gw_node
->bandwidth_down
% 10,
418 gw_node
->bandwidth_up
/ 10,
419 gw_node
->bandwidth_up
% 10,
420 ntohl(gateway
->bandwidth_down
) / 10,
421 ntohl(gateway
->bandwidth_down
) % 10,
422 ntohl(gateway
->bandwidth_up
) / 10,
423 ntohl(gateway
->bandwidth_up
) % 10);
425 gw_node
->bandwidth_down
= ntohl(gateway
->bandwidth_down
);
426 gw_node
->bandwidth_up
= ntohl(gateway
->bandwidth_up
);
428 if (ntohl(gateway
->bandwidth_down
) == 0) {
429 batadv_dbg(BATADV_DBG_BATMAN
, bat_priv
,
430 "Gateway %pM removed from gateway list\n",
433 /* Note: We don't need a NULL check here, since curr_gw never
436 spin_lock_bh(&bat_priv
->gw
.list_lock
);
437 if (!hlist_unhashed(&gw_node
->list
)) {
438 hlist_del_init_rcu(&gw_node
->list
);
439 batadv_gw_node_put(gw_node
);
441 spin_unlock_bh(&bat_priv
->gw
.list_lock
);
443 curr_gw
= batadv_gw_get_selected_gw_node(bat_priv
);
444 if (gw_node
== curr_gw
)
445 batadv_gw_reselect(bat_priv
);
448 batadv_gw_node_put(curr_gw
);
453 batadv_gw_node_put(gw_node
);
456 void batadv_gw_node_delete(struct batadv_priv
*bat_priv
,
457 struct batadv_orig_node
*orig_node
)
459 struct batadv_tvlv_gateway_data gateway
;
461 gateway
.bandwidth_down
= 0;
462 gateway
.bandwidth_up
= 0;
464 batadv_gw_node_update(bat_priv
, orig_node
, &gateway
);
467 void batadv_gw_node_free(struct batadv_priv
*bat_priv
)
469 struct batadv_gw_node
*gw_node
;
470 struct hlist_node
*node_tmp
;
472 spin_lock_bh(&bat_priv
->gw
.list_lock
);
473 hlist_for_each_entry_safe(gw_node
, node_tmp
,
474 &bat_priv
->gw
.list
, list
) {
475 hlist_del_init_rcu(&gw_node
->list
);
476 batadv_gw_node_put(gw_node
);
478 spin_unlock_bh(&bat_priv
->gw
.list_lock
);
481 int batadv_gw_client_seq_print_text(struct seq_file
*seq
, void *offset
)
483 struct net_device
*net_dev
= (struct net_device
*)seq
->private;
484 struct batadv_priv
*bat_priv
= netdev_priv(net_dev
);
485 struct batadv_hard_iface
*primary_if
;
487 primary_if
= batadv_seq_print_text_primary_if_get(seq
);
491 seq_printf(seq
, "[B.A.T.M.A.N. adv %s, MainIF/MAC: %s/%pM (%s %s)]\n",
492 BATADV_SOURCE_VERSION
, primary_if
->net_dev
->name
,
493 primary_if
->net_dev
->dev_addr
, net_dev
->name
,
494 bat_priv
->algo_ops
->name
);
496 batadv_hardif_put(primary_if
);
498 if (!bat_priv
->algo_ops
->gw
.print
) {
500 "No printing function for this routing protocol\n");
504 bat_priv
->algo_ops
->gw
.print(bat_priv
, seq
);
510 * batadv_gw_dump - Dump gateways into a message
511 * @msg: Netlink message to dump into
512 * @cb: Control block containing additional options
514 * Return: Error code, or length of message
516 int batadv_gw_dump(struct sk_buff
*msg
, struct netlink_callback
*cb
)
518 struct batadv_hard_iface
*primary_if
= NULL
;
519 struct net
*net
= sock_net(cb
->skb
->sk
);
520 struct net_device
*soft_iface
;
521 struct batadv_priv
*bat_priv
;
525 ifindex
= batadv_netlink_get_ifindex(cb
->nlh
,
526 BATADV_ATTR_MESH_IFINDEX
);
530 soft_iface
= dev_get_by_index(net
, ifindex
);
531 if (!soft_iface
|| !batadv_softif_is_valid(soft_iface
)) {
536 bat_priv
= netdev_priv(soft_iface
);
538 primary_if
= batadv_primary_if_get_selected(bat_priv
);
539 if (!primary_if
|| primary_if
->if_status
!= BATADV_IF_ACTIVE
) {
544 if (!bat_priv
->algo_ops
->gw
.dump
) {
549 bat_priv
->algo_ops
->gw
.dump(msg
, cb
, bat_priv
);
555 batadv_hardif_put(primary_if
);
563 * batadv_gw_dhcp_recipient_get - check if a packet is a DHCP message
564 * @skb: the packet to check
565 * @header_len: a pointer to the batman-adv header size
566 * @chaddr: buffer where the client address will be stored. Valid
567 * only if the function returns BATADV_DHCP_TO_CLIENT
569 * This function may re-allocate the data buffer of the skb passed as argument.
572 * - BATADV_DHCP_NO if the packet is not a dhcp message or if there was an error
574 * - BATADV_DHCP_TO_SERVER if this is a message going to the DHCP server
575 * - BATADV_DHCP_TO_CLIENT if this is a message going to a DHCP client
577 enum batadv_dhcp_recipient
578 batadv_gw_dhcp_recipient_get(struct sk_buff
*skb
, unsigned int *header_len
,
581 enum batadv_dhcp_recipient ret
= BATADV_DHCP_NO
;
582 struct ethhdr
*ethhdr
;
584 struct ipv6hdr
*ipv6hdr
;
585 struct udphdr
*udphdr
;
586 struct vlan_ethhdr
*vhdr
;
591 /* check for ethernet header */
592 if (!pskb_may_pull(skb
, *header_len
+ ETH_HLEN
))
593 return BATADV_DHCP_NO
;
595 ethhdr
= eth_hdr(skb
);
596 proto
= ethhdr
->h_proto
;
597 *header_len
+= ETH_HLEN
;
599 /* check for initial vlan header */
600 if (proto
== htons(ETH_P_8021Q
)) {
601 if (!pskb_may_pull(skb
, *header_len
+ VLAN_HLEN
))
602 return BATADV_DHCP_NO
;
604 vhdr
= vlan_eth_hdr(skb
);
605 proto
= vhdr
->h_vlan_encapsulated_proto
;
606 *header_len
+= VLAN_HLEN
;
609 /* check for ip header */
611 case htons(ETH_P_IP
):
612 if (!pskb_may_pull(skb
, *header_len
+ sizeof(*iphdr
)))
613 return BATADV_DHCP_NO
;
615 iphdr
= (struct iphdr
*)(skb
->data
+ *header_len
);
616 *header_len
+= iphdr
->ihl
* 4;
618 /* check for udp header */
619 if (iphdr
->protocol
!= IPPROTO_UDP
)
620 return BATADV_DHCP_NO
;
623 case htons(ETH_P_IPV6
):
624 if (!pskb_may_pull(skb
, *header_len
+ sizeof(*ipv6hdr
)))
625 return BATADV_DHCP_NO
;
627 ipv6hdr
= (struct ipv6hdr
*)(skb
->data
+ *header_len
);
628 *header_len
+= sizeof(*ipv6hdr
);
630 /* check for udp header */
631 if (ipv6hdr
->nexthdr
!= IPPROTO_UDP
)
632 return BATADV_DHCP_NO
;
636 return BATADV_DHCP_NO
;
639 if (!pskb_may_pull(skb
, *header_len
+ sizeof(*udphdr
)))
640 return BATADV_DHCP_NO
;
642 udphdr
= (struct udphdr
*)(skb
->data
+ *header_len
);
643 *header_len
+= sizeof(*udphdr
);
645 /* check for bootp port */
647 case htons(ETH_P_IP
):
648 if (udphdr
->dest
== htons(67))
649 ret
= BATADV_DHCP_TO_SERVER
;
650 else if (udphdr
->source
== htons(67))
651 ret
= BATADV_DHCP_TO_CLIENT
;
653 case htons(ETH_P_IPV6
):
654 if (udphdr
->dest
== htons(547))
655 ret
= BATADV_DHCP_TO_SERVER
;
656 else if (udphdr
->source
== htons(547))
657 ret
= BATADV_DHCP_TO_CLIENT
;
661 chaddr_offset
= *header_len
+ BATADV_DHCP_CHADDR_OFFSET
;
662 /* store the client address if the message is going to a client */
663 if (ret
== BATADV_DHCP_TO_CLIENT
&&
664 pskb_may_pull(skb
, chaddr_offset
+ ETH_ALEN
)) {
665 /* check if the DHCP packet carries an Ethernet DHCP */
666 p
= skb
->data
+ *header_len
+ BATADV_DHCP_HTYPE_OFFSET
;
667 if (*p
!= BATADV_DHCP_HTYPE_ETHERNET
)
668 return BATADV_DHCP_NO
;
670 /* check if the DHCP packet carries a valid Ethernet address */
671 p
= skb
->data
+ *header_len
+ BATADV_DHCP_HLEN_OFFSET
;
673 return BATADV_DHCP_NO
;
675 ether_addr_copy(chaddr
, skb
->data
+ chaddr_offset
);
682 * batadv_gw_out_of_range - check if the dhcp request destination is the best gw
683 * @bat_priv: the bat priv with all the soft interface information
684 * @skb: the outgoing packet
686 * Check if the skb is a DHCP request and if it is sent to the current best GW
687 * server. Due to topology changes it may be the case that the GW server
688 * previously selected is not the best one anymore.
690 * This call might reallocate skb data.
691 * Must be invoked only when the DHCP packet is going TO a DHCP SERVER.
693 * Return: true if the packet destination is unicast and it is not the best gw,
696 bool batadv_gw_out_of_range(struct batadv_priv
*bat_priv
,
699 struct batadv_neigh_node
*neigh_curr
= NULL
;
700 struct batadv_neigh_node
*neigh_old
= NULL
;
701 struct batadv_orig_node
*orig_dst_node
= NULL
;
702 struct batadv_gw_node
*gw_node
= NULL
;
703 struct batadv_gw_node
*curr_gw
= NULL
;
704 struct batadv_neigh_ifinfo
*curr_ifinfo
, *old_ifinfo
;
705 struct ethhdr
*ethhdr
= (struct ethhdr
*)skb
->data
;
706 bool out_of_range
= false;
710 vid
= batadv_get_vid(skb
, 0);
712 orig_dst_node
= batadv_transtable_search(bat_priv
, ethhdr
->h_source
,
713 ethhdr
->h_dest
, vid
);
717 gw_node
= batadv_gw_node_get(bat_priv
, orig_dst_node
);
721 switch (atomic_read(&bat_priv
->gw
.mode
)) {
722 case BATADV_GW_MODE_SERVER
:
723 /* If we are a GW then we are our best GW. We can artificially
724 * set the tq towards ourself as the maximum value
726 curr_tq_avg
= BATADV_TQ_MAX_VALUE
;
728 case BATADV_GW_MODE_CLIENT
:
729 curr_gw
= batadv_gw_get_selected_gw_node(bat_priv
);
733 /* packet is going to our gateway */
734 if (curr_gw
->orig_node
== orig_dst_node
)
737 /* If the dhcp packet has been sent to a different gw,
738 * we have to evaluate whether the old gw is still
741 neigh_curr
= batadv_find_router(bat_priv
, curr_gw
->orig_node
,
746 curr_ifinfo
= batadv_neigh_ifinfo_get(neigh_curr
,
751 curr_tq_avg
= curr_ifinfo
->bat_iv
.tq_avg
;
752 batadv_neigh_ifinfo_put(curr_ifinfo
);
755 case BATADV_GW_MODE_OFF
:
760 neigh_old
= batadv_find_router(bat_priv
, orig_dst_node
, NULL
);
764 old_ifinfo
= batadv_neigh_ifinfo_get(neigh_old
, BATADV_IF_DEFAULT
);
768 if ((curr_tq_avg
- old_ifinfo
->bat_iv
.tq_avg
) > BATADV_GW_THRESHOLD
)
770 batadv_neigh_ifinfo_put(old_ifinfo
);
774 batadv_orig_node_put(orig_dst_node
);
776 batadv_gw_node_put(curr_gw
);
778 batadv_gw_node_put(gw_node
);
780 batadv_neigh_node_put(neigh_old
);
782 batadv_neigh_node_put(neigh_curr
);