This source file includes following definitions.
- batadv_gw_node_release
- batadv_gw_node_put
- batadv_gw_get_selected_gw_node
- batadv_gw_get_selected_orig
- batadv_gw_select
- batadv_gw_reselect
- batadv_gw_check_client_stop
- batadv_gw_election
- batadv_gw_check_election
- batadv_gw_node_add
- batadv_gw_node_get
- batadv_gw_node_update
- batadv_gw_node_delete
- batadv_gw_node_free
- batadv_gw_client_seq_print_text
- batadv_gw_dump
- batadv_gw_dhcp_recipient_get
- batadv_gw_out_of_range
1
2
3
4
5
6
7 #include "gateway_client.h"
8 #include "main.h"
9
10 #include <linux/atomic.h>
11 #include <linux/byteorder/generic.h>
12 #include <linux/errno.h>
13 #include <linux/etherdevice.h>
14 #include <linux/gfp.h>
15 #include <linux/if_ether.h>
16 #include <linux/if_vlan.h>
17 #include <linux/in.h>
18 #include <linux/ip.h>
19 #include <linux/ipv6.h>
20 #include <linux/kernel.h>
21 #include <linux/kref.h>
22 #include <linux/list.h>
23 #include <linux/lockdep.h>
24 #include <linux/netdevice.h>
25 #include <linux/netlink.h>
26 #include <linux/rculist.h>
27 #include <linux/rcupdate.h>
28 #include <linux/seq_file.h>
29 #include <linux/skbuff.h>
30 #include <linux/slab.h>
31 #include <linux/spinlock.h>
32 #include <linux/stddef.h>
33 #include <linux/udp.h>
34 #include <net/sock.h>
35 #include <uapi/linux/batadv_packet.h>
36 #include <uapi/linux/batman_adv.h>
37
38 #include "hard-interface.h"
39 #include "log.h"
40 #include "netlink.h"
41 #include "originator.h"
42 #include "routing.h"
43 #include "soft-interface.h"
44 #include "translation-table.h"
45
46
47
48
49 #define BATADV_DHCP_HTYPE_OFFSET 1
50 #define BATADV_DHCP_HLEN_OFFSET 2
51
52 #define BATADV_DHCP_HTYPE_ETHERNET 0x01
53
54
55
56 #define BATADV_DHCP_CHADDR_OFFSET 28
57
58
59
60
61
62
63 static void batadv_gw_node_release(struct kref *ref)
64 {
65 struct batadv_gw_node *gw_node;
66
67 gw_node = container_of(ref, struct batadv_gw_node, refcount);
68
69 batadv_orig_node_put(gw_node->orig_node);
70 kfree_rcu(gw_node, rcu);
71 }
72
73
74
75
76
77
78 void batadv_gw_node_put(struct batadv_gw_node *gw_node)
79 {
80 kref_put(&gw_node->refcount, batadv_gw_node_release);
81 }
82
83
84
85
86
87
88
89 struct batadv_gw_node *
90 batadv_gw_get_selected_gw_node(struct batadv_priv *bat_priv)
91 {
92 struct batadv_gw_node *gw_node;
93
94 rcu_read_lock();
95 gw_node = rcu_dereference(bat_priv->gw.curr_gw);
96 if (!gw_node)
97 goto out;
98
99 if (!kref_get_unless_zero(&gw_node->refcount))
100 gw_node = NULL;
101
102 out:
103 rcu_read_unlock();
104 return gw_node;
105 }
106
107
108
109
110
111
112
113 struct batadv_orig_node *
114 batadv_gw_get_selected_orig(struct batadv_priv *bat_priv)
115 {
116 struct batadv_gw_node *gw_node;
117 struct batadv_orig_node *orig_node = NULL;
118
119 gw_node = batadv_gw_get_selected_gw_node(bat_priv);
120 if (!gw_node)
121 goto out;
122
123 rcu_read_lock();
124 orig_node = gw_node->orig_node;
125 if (!orig_node)
126 goto unlock;
127
128 if (!kref_get_unless_zero(&orig_node->refcount))
129 orig_node = NULL;
130
131 unlock:
132 rcu_read_unlock();
133 out:
134 if (gw_node)
135 batadv_gw_node_put(gw_node);
136 return orig_node;
137 }
138
139 static void batadv_gw_select(struct batadv_priv *bat_priv,
140 struct batadv_gw_node *new_gw_node)
141 {
142 struct batadv_gw_node *curr_gw_node;
143
144 spin_lock_bh(&bat_priv->gw.list_lock);
145
146 if (new_gw_node)
147 kref_get(&new_gw_node->refcount);
148
149 curr_gw_node = rcu_dereference_protected(bat_priv->gw.curr_gw, 1);
150 rcu_assign_pointer(bat_priv->gw.curr_gw, new_gw_node);
151
152 if (curr_gw_node)
153 batadv_gw_node_put(curr_gw_node);
154
155 spin_unlock_bh(&bat_priv->gw.list_lock);
156 }
157
158
159
160
161
162
163
164
165
166
167
168
169 void batadv_gw_reselect(struct batadv_priv *bat_priv)
170 {
171 atomic_set(&bat_priv->gw.reselect, 1);
172 }
173
174
175
176
177
178
179
180
181
182 void batadv_gw_check_client_stop(struct batadv_priv *bat_priv)
183 {
184 struct batadv_gw_node *curr_gw;
185
186 if (atomic_read(&bat_priv->gw.mode) != BATADV_GW_MODE_CLIENT)
187 return;
188
189 curr_gw = batadv_gw_get_selected_gw_node(bat_priv);
190 if (!curr_gw)
191 return;
192
193
194
195
196 batadv_gw_select(bat_priv, NULL);
197
198
199
200
201 batadv_throw_uevent(bat_priv, BATADV_UEV_GW, BATADV_UEV_DEL, NULL);
202
203 batadv_gw_node_put(curr_gw);
204 }
205
206
207
208
209
210 void batadv_gw_election(struct batadv_priv *bat_priv)
211 {
212 struct batadv_gw_node *curr_gw = NULL;
213 struct batadv_gw_node *next_gw = NULL;
214 struct batadv_neigh_node *router = NULL;
215 struct batadv_neigh_ifinfo *router_ifinfo = NULL;
216 char gw_addr[18] = { '\0' };
217
218 if (atomic_read(&bat_priv->gw.mode) != BATADV_GW_MODE_CLIENT)
219 goto out;
220
221 if (!bat_priv->algo_ops->gw.get_best_gw_node)
222 goto out;
223
224 curr_gw = batadv_gw_get_selected_gw_node(bat_priv);
225
226 if (!batadv_atomic_dec_not_zero(&bat_priv->gw.reselect) && curr_gw)
227 goto out;
228
229
230
231
232
233 next_gw = bat_priv->algo_ops->gw.get_best_gw_node(bat_priv);
234
235 if (curr_gw == next_gw)
236 goto out;
237
238 if (next_gw) {
239 sprintf(gw_addr, "%pM", next_gw->orig_node->orig);
240
241 router = batadv_orig_router_get(next_gw->orig_node,
242 BATADV_IF_DEFAULT);
243 if (!router) {
244 batadv_gw_reselect(bat_priv);
245 goto out;
246 }
247
248 router_ifinfo = batadv_neigh_ifinfo_get(router,
249 BATADV_IF_DEFAULT);
250 if (!router_ifinfo) {
251 batadv_gw_reselect(bat_priv);
252 goto out;
253 }
254 }
255
256 if (curr_gw && !next_gw) {
257 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
258 "Removing selected gateway - no gateway in range\n");
259 batadv_throw_uevent(bat_priv, BATADV_UEV_GW, BATADV_UEV_DEL,
260 NULL);
261 } else if (!curr_gw && next_gw) {
262 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
263 "Adding route to gateway %pM (bandwidth: %u.%u/%u.%u MBit, tq: %i)\n",
264 next_gw->orig_node->orig,
265 next_gw->bandwidth_down / 10,
266 next_gw->bandwidth_down % 10,
267 next_gw->bandwidth_up / 10,
268 next_gw->bandwidth_up % 10,
269 router_ifinfo->bat_iv.tq_avg);
270 batadv_throw_uevent(bat_priv, BATADV_UEV_GW, BATADV_UEV_ADD,
271 gw_addr);
272 } else {
273 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
274 "Changing route to gateway %pM (bandwidth: %u.%u/%u.%u MBit, tq: %i)\n",
275 next_gw->orig_node->orig,
276 next_gw->bandwidth_down / 10,
277 next_gw->bandwidth_down % 10,
278 next_gw->bandwidth_up / 10,
279 next_gw->bandwidth_up % 10,
280 router_ifinfo->bat_iv.tq_avg);
281 batadv_throw_uevent(bat_priv, BATADV_UEV_GW, BATADV_UEV_CHANGE,
282 gw_addr);
283 }
284
285 batadv_gw_select(bat_priv, next_gw);
286
287 out:
288 if (curr_gw)
289 batadv_gw_node_put(curr_gw);
290 if (next_gw)
291 batadv_gw_node_put(next_gw);
292 if (router)
293 batadv_neigh_node_put(router);
294 if (router_ifinfo)
295 batadv_neigh_ifinfo_put(router_ifinfo);
296 }
297
298
299
300
301
302
303 void batadv_gw_check_election(struct batadv_priv *bat_priv,
304 struct batadv_orig_node *orig_node)
305 {
306 struct batadv_orig_node *curr_gw_orig;
307
308
309
310
311 if (!bat_priv->algo_ops->gw.is_eligible)
312 return;
313
314 curr_gw_orig = batadv_gw_get_selected_orig(bat_priv);
315 if (!curr_gw_orig)
316 goto reselect;
317
318
319 if (curr_gw_orig == orig_node)
320 goto out;
321
322 if (!bat_priv->algo_ops->gw.is_eligible(bat_priv, curr_gw_orig,
323 orig_node))
324 goto out;
325
326 reselect:
327 batadv_gw_reselect(bat_priv);
328 out:
329 if (curr_gw_orig)
330 batadv_orig_node_put(curr_gw_orig);
331 }
332
333
334
335
336
337
338
339
340
341
342 static void batadv_gw_node_add(struct batadv_priv *bat_priv,
343 struct batadv_orig_node *orig_node,
344 struct batadv_tvlv_gateway_data *gateway)
345 {
346 struct batadv_gw_node *gw_node;
347
348 lockdep_assert_held(&bat_priv->gw.list_lock);
349
350 if (gateway->bandwidth_down == 0)
351 return;
352
353 gw_node = kzalloc(sizeof(*gw_node), GFP_ATOMIC);
354 if (!gw_node)
355 return;
356
357 kref_init(&gw_node->refcount);
358 INIT_HLIST_NODE(&gw_node->list);
359 kref_get(&orig_node->refcount);
360 gw_node->orig_node = orig_node;
361 gw_node->bandwidth_down = ntohl(gateway->bandwidth_down);
362 gw_node->bandwidth_up = ntohl(gateway->bandwidth_up);
363
364 kref_get(&gw_node->refcount);
365 hlist_add_head_rcu(&gw_node->list, &bat_priv->gw.gateway_list);
366 bat_priv->gw.generation++;
367
368 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
369 "Found new gateway %pM -> gw bandwidth: %u.%u/%u.%u MBit\n",
370 orig_node->orig,
371 ntohl(gateway->bandwidth_down) / 10,
372 ntohl(gateway->bandwidth_down) % 10,
373 ntohl(gateway->bandwidth_up) / 10,
374 ntohl(gateway->bandwidth_up) % 10);
375
376
377 batadv_gw_node_put(gw_node);
378 }
379
380
381
382
383
384
385
386
387 struct batadv_gw_node *batadv_gw_node_get(struct batadv_priv *bat_priv,
388 struct batadv_orig_node *orig_node)
389 {
390 struct batadv_gw_node *gw_node_tmp, *gw_node = NULL;
391
392 rcu_read_lock();
393 hlist_for_each_entry_rcu(gw_node_tmp, &bat_priv->gw.gateway_list,
394 list) {
395 if (gw_node_tmp->orig_node != orig_node)
396 continue;
397
398 if (!kref_get_unless_zero(&gw_node_tmp->refcount))
399 continue;
400
401 gw_node = gw_node_tmp;
402 break;
403 }
404 rcu_read_unlock();
405
406 return gw_node;
407 }
408
409
410
411
412
413
414
415
416 void batadv_gw_node_update(struct batadv_priv *bat_priv,
417 struct batadv_orig_node *orig_node,
418 struct batadv_tvlv_gateway_data *gateway)
419 {
420 struct batadv_gw_node *gw_node, *curr_gw = NULL;
421
422 spin_lock_bh(&bat_priv->gw.list_lock);
423 gw_node = batadv_gw_node_get(bat_priv, orig_node);
424 if (!gw_node) {
425 batadv_gw_node_add(bat_priv, orig_node, gateway);
426 spin_unlock_bh(&bat_priv->gw.list_lock);
427 goto out;
428 }
429 spin_unlock_bh(&bat_priv->gw.list_lock);
430
431 if (gw_node->bandwidth_down == ntohl(gateway->bandwidth_down) &&
432 gw_node->bandwidth_up == ntohl(gateway->bandwidth_up))
433 goto out;
434
435 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
436 "Gateway bandwidth of originator %pM changed from %u.%u/%u.%u MBit to %u.%u/%u.%u MBit\n",
437 orig_node->orig,
438 gw_node->bandwidth_down / 10,
439 gw_node->bandwidth_down % 10,
440 gw_node->bandwidth_up / 10,
441 gw_node->bandwidth_up % 10,
442 ntohl(gateway->bandwidth_down) / 10,
443 ntohl(gateway->bandwidth_down) % 10,
444 ntohl(gateway->bandwidth_up) / 10,
445 ntohl(gateway->bandwidth_up) % 10);
446
447 gw_node->bandwidth_down = ntohl(gateway->bandwidth_down);
448 gw_node->bandwidth_up = ntohl(gateway->bandwidth_up);
449
450 if (ntohl(gateway->bandwidth_down) == 0) {
451 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
452 "Gateway %pM removed from gateway list\n",
453 orig_node->orig);
454
455
456
457
458 spin_lock_bh(&bat_priv->gw.list_lock);
459 if (!hlist_unhashed(&gw_node->list)) {
460 hlist_del_init_rcu(&gw_node->list);
461 batadv_gw_node_put(gw_node);
462 bat_priv->gw.generation++;
463 }
464 spin_unlock_bh(&bat_priv->gw.list_lock);
465
466 curr_gw = batadv_gw_get_selected_gw_node(bat_priv);
467 if (gw_node == curr_gw)
468 batadv_gw_reselect(bat_priv);
469
470 if (curr_gw)
471 batadv_gw_node_put(curr_gw);
472 }
473
474 out:
475 if (gw_node)
476 batadv_gw_node_put(gw_node);
477 }
478
479
480
481
482
483
484 void batadv_gw_node_delete(struct batadv_priv *bat_priv,
485 struct batadv_orig_node *orig_node)
486 {
487 struct batadv_tvlv_gateway_data gateway;
488
489 gateway.bandwidth_down = 0;
490 gateway.bandwidth_up = 0;
491
492 batadv_gw_node_update(bat_priv, orig_node, &gateway);
493 }
494
495
496
497
498
499 void batadv_gw_node_free(struct batadv_priv *bat_priv)
500 {
501 struct batadv_gw_node *gw_node;
502 struct hlist_node *node_tmp;
503
504 spin_lock_bh(&bat_priv->gw.list_lock);
505 hlist_for_each_entry_safe(gw_node, node_tmp,
506 &bat_priv->gw.gateway_list, list) {
507 hlist_del_init_rcu(&gw_node->list);
508 batadv_gw_node_put(gw_node);
509 bat_priv->gw.generation++;
510 }
511 spin_unlock_bh(&bat_priv->gw.list_lock);
512 }
513
514 #ifdef CONFIG_BATMAN_ADV_DEBUGFS
515
516
517
518
519
520
521
522
523 int batadv_gw_client_seq_print_text(struct seq_file *seq, void *offset)
524 {
525 struct net_device *net_dev = (struct net_device *)seq->private;
526 struct batadv_priv *bat_priv = netdev_priv(net_dev);
527 struct batadv_hard_iface *primary_if;
528
529 primary_if = batadv_seq_print_text_primary_if_get(seq);
530 if (!primary_if)
531 return 0;
532
533 seq_printf(seq, "[B.A.T.M.A.N. adv %s, MainIF/MAC: %s/%pM (%s %s)]\n",
534 BATADV_SOURCE_VERSION, primary_if->net_dev->name,
535 primary_if->net_dev->dev_addr, net_dev->name,
536 bat_priv->algo_ops->name);
537
538 batadv_hardif_put(primary_if);
539
540 if (!bat_priv->algo_ops->gw.print) {
541 seq_puts(seq,
542 "No printing function for this routing protocol\n");
543 return 0;
544 }
545
546 bat_priv->algo_ops->gw.print(bat_priv, seq);
547
548 return 0;
549 }
550 #endif
551
552
553
554
555
556
557
558
559 int batadv_gw_dump(struct sk_buff *msg, struct netlink_callback *cb)
560 {
561 struct batadv_hard_iface *primary_if = NULL;
562 struct net *net = sock_net(cb->skb->sk);
563 struct net_device *soft_iface;
564 struct batadv_priv *bat_priv;
565 int ifindex;
566 int ret;
567
568 ifindex = batadv_netlink_get_ifindex(cb->nlh,
569 BATADV_ATTR_MESH_IFINDEX);
570 if (!ifindex)
571 return -EINVAL;
572
573 soft_iface = dev_get_by_index(net, ifindex);
574 if (!soft_iface || !batadv_softif_is_valid(soft_iface)) {
575 ret = -ENODEV;
576 goto out;
577 }
578
579 bat_priv = netdev_priv(soft_iface);
580
581 primary_if = batadv_primary_if_get_selected(bat_priv);
582 if (!primary_if || primary_if->if_status != BATADV_IF_ACTIVE) {
583 ret = -ENOENT;
584 goto out;
585 }
586
587 if (!bat_priv->algo_ops->gw.dump) {
588 ret = -EOPNOTSUPP;
589 goto out;
590 }
591
592 bat_priv->algo_ops->gw.dump(msg, cb, bat_priv);
593
594 ret = msg->len;
595
596 out:
597 if (primary_if)
598 batadv_hardif_put(primary_if);
599 if (soft_iface)
600 dev_put(soft_iface);
601
602 return ret;
603 }
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620 enum batadv_dhcp_recipient
621 batadv_gw_dhcp_recipient_get(struct sk_buff *skb, unsigned int *header_len,
622 u8 *chaddr)
623 {
624 enum batadv_dhcp_recipient ret = BATADV_DHCP_NO;
625 struct ethhdr *ethhdr;
626 struct iphdr *iphdr;
627 struct ipv6hdr *ipv6hdr;
628 struct udphdr *udphdr;
629 struct vlan_ethhdr *vhdr;
630 int chaddr_offset;
631 __be16 proto;
632 u8 *p;
633
634
635 if (!pskb_may_pull(skb, *header_len + ETH_HLEN))
636 return BATADV_DHCP_NO;
637
638 ethhdr = eth_hdr(skb);
639 proto = ethhdr->h_proto;
640 *header_len += ETH_HLEN;
641
642
643 if (proto == htons(ETH_P_8021Q)) {
644 if (!pskb_may_pull(skb, *header_len + VLAN_HLEN))
645 return BATADV_DHCP_NO;
646
647 vhdr = vlan_eth_hdr(skb);
648 proto = vhdr->h_vlan_encapsulated_proto;
649 *header_len += VLAN_HLEN;
650 }
651
652
653 switch (proto) {
654 case htons(ETH_P_IP):
655 if (!pskb_may_pull(skb, *header_len + sizeof(*iphdr)))
656 return BATADV_DHCP_NO;
657
658 iphdr = (struct iphdr *)(skb->data + *header_len);
659 *header_len += iphdr->ihl * 4;
660
661
662 if (iphdr->protocol != IPPROTO_UDP)
663 return BATADV_DHCP_NO;
664
665 break;
666 case htons(ETH_P_IPV6):
667 if (!pskb_may_pull(skb, *header_len + sizeof(*ipv6hdr)))
668 return BATADV_DHCP_NO;
669
670 ipv6hdr = (struct ipv6hdr *)(skb->data + *header_len);
671 *header_len += sizeof(*ipv6hdr);
672
673
674 if (ipv6hdr->nexthdr != IPPROTO_UDP)
675 return BATADV_DHCP_NO;
676
677 break;
678 default:
679 return BATADV_DHCP_NO;
680 }
681
682 if (!pskb_may_pull(skb, *header_len + sizeof(*udphdr)))
683 return BATADV_DHCP_NO;
684
685 udphdr = (struct udphdr *)(skb->data + *header_len);
686 *header_len += sizeof(*udphdr);
687
688
689 switch (proto) {
690 case htons(ETH_P_IP):
691 if (udphdr->dest == htons(67))
692 ret = BATADV_DHCP_TO_SERVER;
693 else if (udphdr->source == htons(67))
694 ret = BATADV_DHCP_TO_CLIENT;
695 break;
696 case htons(ETH_P_IPV6):
697 if (udphdr->dest == htons(547))
698 ret = BATADV_DHCP_TO_SERVER;
699 else if (udphdr->source == htons(547))
700 ret = BATADV_DHCP_TO_CLIENT;
701 break;
702 }
703
704 chaddr_offset = *header_len + BATADV_DHCP_CHADDR_OFFSET;
705
706 if (ret == BATADV_DHCP_TO_CLIENT &&
707 pskb_may_pull(skb, chaddr_offset + ETH_ALEN)) {
708
709 p = skb->data + *header_len + BATADV_DHCP_HTYPE_OFFSET;
710 if (*p != BATADV_DHCP_HTYPE_ETHERNET)
711 return BATADV_DHCP_NO;
712
713
714 p = skb->data + *header_len + BATADV_DHCP_HLEN_OFFSET;
715 if (*p != ETH_ALEN)
716 return BATADV_DHCP_NO;
717
718 ether_addr_copy(chaddr, skb->data + chaddr_offset);
719 }
720
721 return ret;
722 }
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740 bool batadv_gw_out_of_range(struct batadv_priv *bat_priv,
741 struct sk_buff *skb)
742 {
743 struct batadv_neigh_node *neigh_curr = NULL;
744 struct batadv_neigh_node *neigh_old = NULL;
745 struct batadv_orig_node *orig_dst_node = NULL;
746 struct batadv_gw_node *gw_node = NULL;
747 struct batadv_gw_node *curr_gw = NULL;
748 struct batadv_neigh_ifinfo *curr_ifinfo, *old_ifinfo;
749 struct ethhdr *ethhdr = (struct ethhdr *)skb->data;
750 bool out_of_range = false;
751 u8 curr_tq_avg;
752 unsigned short vid;
753
754 vid = batadv_get_vid(skb, 0);
755
756 if (is_multicast_ether_addr(ethhdr->h_dest))
757 goto out;
758
759 orig_dst_node = batadv_transtable_search(bat_priv, ethhdr->h_source,
760 ethhdr->h_dest, vid);
761 if (!orig_dst_node)
762 goto out;
763
764 gw_node = batadv_gw_node_get(bat_priv, orig_dst_node);
765 if (!gw_node)
766 goto out;
767
768 switch (atomic_read(&bat_priv->gw.mode)) {
769 case BATADV_GW_MODE_SERVER:
770
771
772
773 curr_tq_avg = BATADV_TQ_MAX_VALUE;
774 break;
775 case BATADV_GW_MODE_CLIENT:
776 curr_gw = batadv_gw_get_selected_gw_node(bat_priv);
777 if (!curr_gw)
778 goto out;
779
780
781 if (curr_gw->orig_node == orig_dst_node)
782 goto out;
783
784
785
786
787
788 neigh_curr = batadv_find_router(bat_priv, curr_gw->orig_node,
789 NULL);
790 if (!neigh_curr)
791 goto out;
792
793 curr_ifinfo = batadv_neigh_ifinfo_get(neigh_curr,
794 BATADV_IF_DEFAULT);
795 if (!curr_ifinfo)
796 goto out;
797
798 curr_tq_avg = curr_ifinfo->bat_iv.tq_avg;
799 batadv_neigh_ifinfo_put(curr_ifinfo);
800
801 break;
802 case BATADV_GW_MODE_OFF:
803 default:
804 goto out;
805 }
806
807 neigh_old = batadv_find_router(bat_priv, orig_dst_node, NULL);
808 if (!neigh_old)
809 goto out;
810
811 old_ifinfo = batadv_neigh_ifinfo_get(neigh_old, BATADV_IF_DEFAULT);
812 if (!old_ifinfo)
813 goto out;
814
815 if ((curr_tq_avg - old_ifinfo->bat_iv.tq_avg) > BATADV_GW_THRESHOLD)
816 out_of_range = true;
817 batadv_neigh_ifinfo_put(old_ifinfo);
818
819 out:
820 if (orig_dst_node)
821 batadv_orig_node_put(orig_dst_node);
822 if (curr_gw)
823 batadv_gw_node_put(curr_gw);
824 if (gw_node)
825 batadv_gw_node_put(gw_node);
826 if (neigh_old)
827 batadv_neigh_node_put(neigh_old);
828 if (neigh_curr)
829 batadv_neigh_node_put(neigh_curr);
830 return out_of_range;
831 }