1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include "originator.h"
20#include "main.h"
21
22#include <linux/atomic.h>
23#include <linux/errno.h>
24#include <linux/etherdevice.h>
25#include <linux/gfp.h>
26#include <linux/jiffies.h>
27#include <linux/kernel.h>
28#include <linux/kref.h>
29#include <linux/list.h>
30#include <linux/lockdep.h>
31#include <linux/netdevice.h>
32#include <linux/netlink.h>
33#include <linux/rculist.h>
34#include <linux/rcupdate.h>
35#include <linux/seq_file.h>
36#include <linux/skbuff.h>
37#include <linux/slab.h>
38#include <linux/spinlock.h>
39#include <linux/stddef.h>
40#include <linux/workqueue.h>
41#include <net/sock.h>
42#include <uapi/linux/batman_adv.h>
43
44#include "bat_algo.h"
45#include "distributed-arp-table.h"
46#include "fragmentation.h"
47#include "gateway_client.h"
48#include "hard-interface.h"
49#include "hash.h"
50#include "log.h"
51#include "multicast.h"
52#include "netlink.h"
53#include "network-coding.h"
54#include "routing.h"
55#include "soft-interface.h"
56#include "translation-table.h"
57
58
59static struct lock_class_key batadv_orig_hash_lock_class_key;
60
61
62
63
64
65
66
67
68struct batadv_orig_node *
69batadv_orig_hash_find(struct batadv_priv *bat_priv, const void *data)
70{
71 struct batadv_hashtable *hash = bat_priv->orig_hash;
72 struct hlist_head *head;
73 struct batadv_orig_node *orig_node, *orig_node_tmp = NULL;
74 int index;
75
76 if (!hash)
77 return NULL;
78
79 index = batadv_choose_orig(data, hash->size);
80 head = &hash->table[index];
81
82 rcu_read_lock();
83 hlist_for_each_entry_rcu(orig_node, head, hash_entry) {
84 if (!batadv_compare_eth(orig_node, data))
85 continue;
86
87 if (!kref_get_unless_zero(&orig_node->refcount))
88 continue;
89
90 orig_node_tmp = orig_node;
91 break;
92 }
93 rcu_read_unlock();
94
95 return orig_node_tmp;
96}
97
98static void batadv_purge_orig(struct work_struct *work);
99
100
101
102
103
104
105
106
107bool batadv_compare_orig(const struct hlist_node *node, const void *data2)
108{
109 const void *data1 = container_of(node, struct batadv_orig_node,
110 hash_entry);
111
112 return batadv_compare_eth(data1, data2);
113}
114
115
116
117
118
119
120
121
122
123struct batadv_orig_node_vlan *
124batadv_orig_node_vlan_get(struct batadv_orig_node *orig_node,
125 unsigned short vid)
126{
127 struct batadv_orig_node_vlan *vlan = NULL, *tmp;
128
129 rcu_read_lock();
130 hlist_for_each_entry_rcu(tmp, &orig_node->vlan_list, list) {
131 if (tmp->vid != vid)
132 continue;
133
134 if (!kref_get_unless_zero(&tmp->refcount))
135 continue;
136
137 vlan = tmp;
138
139 break;
140 }
141 rcu_read_unlock();
142
143 return vlan;
144}
145
146
147
148
149
150
151
152
153
154
155
156
157
158struct batadv_orig_node_vlan *
159batadv_orig_node_vlan_new(struct batadv_orig_node *orig_node,
160 unsigned short vid)
161{
162 struct batadv_orig_node_vlan *vlan;
163
164 spin_lock_bh(&orig_node->vlan_list_lock);
165
166
167 vlan = batadv_orig_node_vlan_get(orig_node, vid);
168 if (vlan)
169 goto out;
170
171 vlan = kzalloc(sizeof(*vlan), GFP_ATOMIC);
172 if (!vlan)
173 goto out;
174
175 kref_init(&vlan->refcount);
176 vlan->vid = vid;
177
178 kref_get(&vlan->refcount);
179 hlist_add_head_rcu(&vlan->list, &orig_node->vlan_list);
180
181out:
182 spin_unlock_bh(&orig_node->vlan_list_lock);
183
184 return vlan;
185}
186
187
188
189
190
191
192static void batadv_orig_node_vlan_release(struct kref *ref)
193{
194 struct batadv_orig_node_vlan *orig_vlan;
195
196 orig_vlan = container_of(ref, struct batadv_orig_node_vlan, refcount);
197
198 kfree_rcu(orig_vlan, rcu);
199}
200
201
202
203
204
205
206void batadv_orig_node_vlan_put(struct batadv_orig_node_vlan *orig_vlan)
207{
208 kref_put(&orig_vlan->refcount, batadv_orig_node_vlan_release);
209}
210
211
212
213
214
215
216
217int batadv_originator_init(struct batadv_priv *bat_priv)
218{
219 if (bat_priv->orig_hash)
220 return 0;
221
222 bat_priv->orig_hash = batadv_hash_new(1024);
223
224 if (!bat_priv->orig_hash)
225 goto err;
226
227 batadv_hash_set_lock_class(bat_priv->orig_hash,
228 &batadv_orig_hash_lock_class_key);
229
230 INIT_DELAYED_WORK(&bat_priv->orig_work, batadv_purge_orig);
231 queue_delayed_work(batadv_event_workqueue,
232 &bat_priv->orig_work,
233 msecs_to_jiffies(BATADV_ORIG_WORK_PERIOD));
234
235 return 0;
236
237err:
238 return -ENOMEM;
239}
240
241
242
243
244
245
246static void batadv_neigh_ifinfo_release(struct kref *ref)
247{
248 struct batadv_neigh_ifinfo *neigh_ifinfo;
249
250 neigh_ifinfo = container_of(ref, struct batadv_neigh_ifinfo, refcount);
251
252 if (neigh_ifinfo->if_outgoing != BATADV_IF_DEFAULT)
253 batadv_hardif_put(neigh_ifinfo->if_outgoing);
254
255 kfree_rcu(neigh_ifinfo, rcu);
256}
257
258
259
260
261
262
263void batadv_neigh_ifinfo_put(struct batadv_neigh_ifinfo *neigh_ifinfo)
264{
265 kref_put(&neigh_ifinfo->refcount, batadv_neigh_ifinfo_release);
266}
267
268
269
270
271
272
273static void batadv_hardif_neigh_release(struct kref *ref)
274{
275 struct batadv_hardif_neigh_node *hardif_neigh;
276
277 hardif_neigh = container_of(ref, struct batadv_hardif_neigh_node,
278 refcount);
279
280 spin_lock_bh(&hardif_neigh->if_incoming->neigh_list_lock);
281 hlist_del_init_rcu(&hardif_neigh->list);
282 spin_unlock_bh(&hardif_neigh->if_incoming->neigh_list_lock);
283
284 batadv_hardif_put(hardif_neigh->if_incoming);
285 kfree_rcu(hardif_neigh, rcu);
286}
287
288
289
290
291
292
293void batadv_hardif_neigh_put(struct batadv_hardif_neigh_node *hardif_neigh)
294{
295 kref_put(&hardif_neigh->refcount, batadv_hardif_neigh_release);
296}
297
298
299
300
301
302
303static void batadv_neigh_node_release(struct kref *ref)
304{
305 struct hlist_node *node_tmp;
306 struct batadv_neigh_node *neigh_node;
307 struct batadv_neigh_ifinfo *neigh_ifinfo;
308
309 neigh_node = container_of(ref, struct batadv_neigh_node, refcount);
310
311 hlist_for_each_entry_safe(neigh_ifinfo, node_tmp,
312 &neigh_node->ifinfo_list, list) {
313 batadv_neigh_ifinfo_put(neigh_ifinfo);
314 }
315
316 batadv_hardif_neigh_put(neigh_node->hardif_neigh);
317
318 batadv_hardif_put(neigh_node->if_incoming);
319
320 kfree_rcu(neigh_node, rcu);
321}
322
323
324
325
326
327
328void batadv_neigh_node_put(struct batadv_neigh_node *neigh_node)
329{
330 kref_put(&neigh_node->refcount, batadv_neigh_node_release);
331}
332
333
334
335
336
337
338
339
340
341
342
343struct batadv_neigh_node *
344batadv_orig_router_get(struct batadv_orig_node *orig_node,
345 const struct batadv_hard_iface *if_outgoing)
346{
347 struct batadv_orig_ifinfo *orig_ifinfo;
348 struct batadv_neigh_node *router = NULL;
349
350 rcu_read_lock();
351 hlist_for_each_entry_rcu(orig_ifinfo, &orig_node->ifinfo_list, list) {
352 if (orig_ifinfo->if_outgoing != if_outgoing)
353 continue;
354
355 router = rcu_dereference(orig_ifinfo->router);
356 break;
357 }
358
359 if (router && !kref_get_unless_zero(&router->refcount))
360 router = NULL;
361
362 rcu_read_unlock();
363 return router;
364}
365
366
367
368
369
370
371
372
373
374
375struct batadv_orig_ifinfo *
376batadv_orig_ifinfo_get(struct batadv_orig_node *orig_node,
377 struct batadv_hard_iface *if_outgoing)
378{
379 struct batadv_orig_ifinfo *tmp, *orig_ifinfo = NULL;
380
381 rcu_read_lock();
382 hlist_for_each_entry_rcu(tmp, &orig_node->ifinfo_list,
383 list) {
384 if (tmp->if_outgoing != if_outgoing)
385 continue;
386
387 if (!kref_get_unless_zero(&tmp->refcount))
388 continue;
389
390 orig_ifinfo = tmp;
391 break;
392 }
393 rcu_read_unlock();
394
395 return orig_ifinfo;
396}
397
398
399
400
401
402
403
404
405
406
407
408
409struct batadv_orig_ifinfo *
410batadv_orig_ifinfo_new(struct batadv_orig_node *orig_node,
411 struct batadv_hard_iface *if_outgoing)
412{
413 struct batadv_orig_ifinfo *orig_ifinfo;
414 unsigned long reset_time;
415
416 spin_lock_bh(&orig_node->neigh_list_lock);
417
418 orig_ifinfo = batadv_orig_ifinfo_get(orig_node, if_outgoing);
419 if (orig_ifinfo)
420 goto out;
421
422 orig_ifinfo = kzalloc(sizeof(*orig_ifinfo), GFP_ATOMIC);
423 if (!orig_ifinfo)
424 goto out;
425
426 if (if_outgoing != BATADV_IF_DEFAULT)
427 kref_get(&if_outgoing->refcount);
428
429 reset_time = jiffies - 1;
430 reset_time -= msecs_to_jiffies(BATADV_RESET_PROTECTION_MS);
431 orig_ifinfo->batman_seqno_reset = reset_time;
432 orig_ifinfo->if_outgoing = if_outgoing;
433 INIT_HLIST_NODE(&orig_ifinfo->list);
434 kref_init(&orig_ifinfo->refcount);
435
436 kref_get(&orig_ifinfo->refcount);
437 hlist_add_head_rcu(&orig_ifinfo->list,
438 &orig_node->ifinfo_list);
439out:
440 spin_unlock_bh(&orig_node->neigh_list_lock);
441 return orig_ifinfo;
442}
443
444
445
446
447
448
449
450
451
452
453struct batadv_neigh_ifinfo *
454batadv_neigh_ifinfo_get(struct batadv_neigh_node *neigh,
455 struct batadv_hard_iface *if_outgoing)
456{
457 struct batadv_neigh_ifinfo *neigh_ifinfo = NULL,
458 *tmp_neigh_ifinfo;
459
460 rcu_read_lock();
461 hlist_for_each_entry_rcu(tmp_neigh_ifinfo, &neigh->ifinfo_list,
462 list) {
463 if (tmp_neigh_ifinfo->if_outgoing != if_outgoing)
464 continue;
465
466 if (!kref_get_unless_zero(&tmp_neigh_ifinfo->refcount))
467 continue;
468
469 neigh_ifinfo = tmp_neigh_ifinfo;
470 break;
471 }
472 rcu_read_unlock();
473
474 return neigh_ifinfo;
475}
476
477
478
479
480
481
482
483
484
485
486
487
488struct batadv_neigh_ifinfo *
489batadv_neigh_ifinfo_new(struct batadv_neigh_node *neigh,
490 struct batadv_hard_iface *if_outgoing)
491{
492 struct batadv_neigh_ifinfo *neigh_ifinfo;
493
494 spin_lock_bh(&neigh->ifinfo_lock);
495
496 neigh_ifinfo = batadv_neigh_ifinfo_get(neigh, if_outgoing);
497 if (neigh_ifinfo)
498 goto out;
499
500 neigh_ifinfo = kzalloc(sizeof(*neigh_ifinfo), GFP_ATOMIC);
501 if (!neigh_ifinfo)
502 goto out;
503
504 if (if_outgoing)
505 kref_get(&if_outgoing->refcount);
506
507 INIT_HLIST_NODE(&neigh_ifinfo->list);
508 kref_init(&neigh_ifinfo->refcount);
509 neigh_ifinfo->if_outgoing = if_outgoing;
510
511 kref_get(&neigh_ifinfo->refcount);
512 hlist_add_head_rcu(&neigh_ifinfo->list, &neigh->ifinfo_list);
513
514out:
515 spin_unlock_bh(&neigh->ifinfo_lock);
516
517 return neigh_ifinfo;
518}
519
520
521
522
523
524
525
526
527
528
529
530
531static struct batadv_neigh_node *
532batadv_neigh_node_get(const struct batadv_orig_node *orig_node,
533 const struct batadv_hard_iface *hard_iface,
534 const u8 *addr)
535{
536 struct batadv_neigh_node *tmp_neigh_node, *res = NULL;
537
538 rcu_read_lock();
539 hlist_for_each_entry_rcu(tmp_neigh_node, &orig_node->neigh_list, list) {
540 if (!batadv_compare_eth(tmp_neigh_node->addr, addr))
541 continue;
542
543 if (tmp_neigh_node->if_incoming != hard_iface)
544 continue;
545
546 if (!kref_get_unless_zero(&tmp_neigh_node->refcount))
547 continue;
548
549 res = tmp_neigh_node;
550 break;
551 }
552 rcu_read_unlock();
553
554 return res;
555}
556
557
558
559
560
561
562
563
564
565static struct batadv_hardif_neigh_node *
566batadv_hardif_neigh_create(struct batadv_hard_iface *hard_iface,
567 const u8 *neigh_addr,
568 struct batadv_orig_node *orig_node)
569{
570 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
571 struct batadv_hardif_neigh_node *hardif_neigh;
572
573 spin_lock_bh(&hard_iface->neigh_list_lock);
574
575
576 hardif_neigh = batadv_hardif_neigh_get(hard_iface, neigh_addr);
577 if (hardif_neigh)
578 goto out;
579
580 hardif_neigh = kzalloc(sizeof(*hardif_neigh), GFP_ATOMIC);
581 if (!hardif_neigh)
582 goto out;
583
584 kref_get(&hard_iface->refcount);
585 INIT_HLIST_NODE(&hardif_neigh->list);
586 ether_addr_copy(hardif_neigh->addr, neigh_addr);
587 ether_addr_copy(hardif_neigh->orig, orig_node->orig);
588 hardif_neigh->if_incoming = hard_iface;
589 hardif_neigh->last_seen = jiffies;
590
591 kref_init(&hardif_neigh->refcount);
592
593 if (bat_priv->algo_ops->neigh.hardif_init)
594 bat_priv->algo_ops->neigh.hardif_init(hardif_neigh);
595
596 hlist_add_head_rcu(&hardif_neigh->list, &hard_iface->neigh_list);
597
598out:
599 spin_unlock_bh(&hard_iface->neigh_list_lock);
600 return hardif_neigh;
601}
602
603
604
605
606
607
608
609
610
611
612static struct batadv_hardif_neigh_node *
613batadv_hardif_neigh_get_or_create(struct batadv_hard_iface *hard_iface,
614 const u8 *neigh_addr,
615 struct batadv_orig_node *orig_node)
616{
617 struct batadv_hardif_neigh_node *hardif_neigh;
618
619
620 hardif_neigh = batadv_hardif_neigh_get(hard_iface, neigh_addr);
621 if (hardif_neigh)
622 return hardif_neigh;
623
624 return batadv_hardif_neigh_create(hard_iface, neigh_addr, orig_node);
625}
626
627
628
629
630
631
632
633
634
635
636struct batadv_hardif_neigh_node *
637batadv_hardif_neigh_get(const struct batadv_hard_iface *hard_iface,
638 const u8 *neigh_addr)
639{
640 struct batadv_hardif_neigh_node *tmp_hardif_neigh, *hardif_neigh = NULL;
641
642 rcu_read_lock();
643 hlist_for_each_entry_rcu(tmp_hardif_neigh,
644 &hard_iface->neigh_list, list) {
645 if (!batadv_compare_eth(tmp_hardif_neigh->addr, neigh_addr))
646 continue;
647
648 if (!kref_get_unless_zero(&tmp_hardif_neigh->refcount))
649 continue;
650
651 hardif_neigh = tmp_hardif_neigh;
652 break;
653 }
654 rcu_read_unlock();
655
656 return hardif_neigh;
657}
658
659
660
661
662
663
664
665
666
667
668
669static struct batadv_neigh_node *
670batadv_neigh_node_create(struct batadv_orig_node *orig_node,
671 struct batadv_hard_iface *hard_iface,
672 const u8 *neigh_addr)
673{
674 struct batadv_neigh_node *neigh_node;
675 struct batadv_hardif_neigh_node *hardif_neigh = NULL;
676
677 spin_lock_bh(&orig_node->neigh_list_lock);
678
679 neigh_node = batadv_neigh_node_get(orig_node, hard_iface, neigh_addr);
680 if (neigh_node)
681 goto out;
682
683 hardif_neigh = batadv_hardif_neigh_get_or_create(hard_iface,
684 neigh_addr, orig_node);
685 if (!hardif_neigh)
686 goto out;
687
688 neigh_node = kzalloc(sizeof(*neigh_node), GFP_ATOMIC);
689 if (!neigh_node)
690 goto out;
691
692 INIT_HLIST_NODE(&neigh_node->list);
693 INIT_HLIST_HEAD(&neigh_node->ifinfo_list);
694 spin_lock_init(&neigh_node->ifinfo_lock);
695
696 kref_get(&hard_iface->refcount);
697 ether_addr_copy(neigh_node->addr, neigh_addr);
698 neigh_node->if_incoming = hard_iface;
699 neigh_node->orig_node = orig_node;
700 neigh_node->last_seen = jiffies;
701
702
703 kref_get(&hardif_neigh->refcount);
704 neigh_node->hardif_neigh = hardif_neigh;
705
706
707 kref_init(&neigh_node->refcount);
708
709 kref_get(&neigh_node->refcount);
710 hlist_add_head_rcu(&neigh_node->list, &orig_node->neigh_list);
711
712 batadv_dbg(BATADV_DBG_BATMAN, orig_node->bat_priv,
713 "Creating new neighbor %pM for orig_node %pM on interface %s\n",
714 neigh_addr, orig_node->orig, hard_iface->net_dev->name);
715
716out:
717 spin_unlock_bh(&orig_node->neigh_list_lock);
718
719 if (hardif_neigh)
720 batadv_hardif_neigh_put(hardif_neigh);
721 return neigh_node;
722}
723
724
725
726
727
728
729
730
731
732struct batadv_neigh_node *
733batadv_neigh_node_get_or_create(struct batadv_orig_node *orig_node,
734 struct batadv_hard_iface *hard_iface,
735 const u8 *neigh_addr)
736{
737 struct batadv_neigh_node *neigh_node;
738
739
740 neigh_node = batadv_neigh_node_get(orig_node, hard_iface, neigh_addr);
741 if (neigh_node)
742 return neigh_node;
743
744 return batadv_neigh_node_create(orig_node, hard_iface, neigh_addr);
745}
746
747#ifdef CONFIG_BATMAN_ADV_DEBUGFS
748
749
750
751
752
753
754
755int batadv_hardif_neigh_seq_print_text(struct seq_file *seq, void *offset)
756{
757 struct net_device *net_dev = (struct net_device *)seq->private;
758 struct batadv_priv *bat_priv = netdev_priv(net_dev);
759 struct batadv_hard_iface *primary_if;
760
761 primary_if = batadv_seq_print_text_primary_if_get(seq);
762 if (!primary_if)
763 return 0;
764
765 seq_printf(seq, "[B.A.T.M.A.N. adv %s, MainIF/MAC: %s/%pM (%s %s)]\n",
766 BATADV_SOURCE_VERSION, primary_if->net_dev->name,
767 primary_if->net_dev->dev_addr, net_dev->name,
768 bat_priv->algo_ops->name);
769
770 batadv_hardif_put(primary_if);
771
772 if (!bat_priv->algo_ops->neigh.print) {
773 seq_puts(seq,
774 "No printing function for this routing protocol\n");
775 return 0;
776 }
777
778 bat_priv->algo_ops->neigh.print(bat_priv, seq);
779 return 0;
780}
781#endif
782
783
784
785
786
787
788
789
790
791int batadv_hardif_neigh_dump(struct sk_buff *msg, struct netlink_callback *cb)
792{
793 struct net *net = sock_net(cb->skb->sk);
794 struct net_device *soft_iface;
795 struct net_device *hard_iface = NULL;
796 struct batadv_hard_iface *hardif = BATADV_IF_DEFAULT;
797 struct batadv_priv *bat_priv;
798 struct batadv_hard_iface *primary_if = NULL;
799 int ret;
800 int ifindex, hard_ifindex;
801
802 ifindex = batadv_netlink_get_ifindex(cb->nlh, BATADV_ATTR_MESH_IFINDEX);
803 if (!ifindex)
804 return -EINVAL;
805
806 soft_iface = dev_get_by_index(net, ifindex);
807 if (!soft_iface || !batadv_softif_is_valid(soft_iface)) {
808 ret = -ENODEV;
809 goto out;
810 }
811
812 bat_priv = netdev_priv(soft_iface);
813
814 primary_if = batadv_primary_if_get_selected(bat_priv);
815 if (!primary_if || primary_if->if_status != BATADV_IF_ACTIVE) {
816 ret = -ENOENT;
817 goto out;
818 }
819
820 hard_ifindex = batadv_netlink_get_ifindex(cb->nlh,
821 BATADV_ATTR_HARD_IFINDEX);
822 if (hard_ifindex) {
823 hard_iface = dev_get_by_index(net, hard_ifindex);
824 if (hard_iface)
825 hardif = batadv_hardif_get_by_netdev(hard_iface);
826
827 if (!hardif) {
828 ret = -ENODEV;
829 goto out;
830 }
831
832 if (hardif->soft_iface != soft_iface) {
833 ret = -ENOENT;
834 goto out;
835 }
836 }
837
838 if (!bat_priv->algo_ops->neigh.dump) {
839 ret = -EOPNOTSUPP;
840 goto out;
841 }
842
843 bat_priv->algo_ops->neigh.dump(msg, cb, bat_priv, hardif);
844
845 ret = msg->len;
846
847 out:
848 if (hardif)
849 batadv_hardif_put(hardif);
850 if (hard_iface)
851 dev_put(hard_iface);
852 if (primary_if)
853 batadv_hardif_put(primary_if);
854 if (soft_iface)
855 dev_put(soft_iface);
856
857 return ret;
858}
859
860
861
862
863
864
865static void batadv_orig_ifinfo_release(struct kref *ref)
866{
867 struct batadv_orig_ifinfo *orig_ifinfo;
868 struct batadv_neigh_node *router;
869
870 orig_ifinfo = container_of(ref, struct batadv_orig_ifinfo, refcount);
871
872 if (orig_ifinfo->if_outgoing != BATADV_IF_DEFAULT)
873 batadv_hardif_put(orig_ifinfo->if_outgoing);
874
875
876 router = rcu_dereference_protected(orig_ifinfo->router, true);
877 if (router)
878 batadv_neigh_node_put(router);
879
880 kfree_rcu(orig_ifinfo, rcu);
881}
882
883
884
885
886
887
888void batadv_orig_ifinfo_put(struct batadv_orig_ifinfo *orig_ifinfo)
889{
890 kref_put(&orig_ifinfo->refcount, batadv_orig_ifinfo_release);
891}
892
893
894
895
896
897static void batadv_orig_node_free_rcu(struct rcu_head *rcu)
898{
899 struct batadv_orig_node *orig_node;
900
901 orig_node = container_of(rcu, struct batadv_orig_node, rcu);
902
903 batadv_mcast_purge_orig(orig_node);
904
905 batadv_frag_purge_orig(orig_node, NULL);
906
907 if (orig_node->bat_priv->algo_ops->orig.free)
908 orig_node->bat_priv->algo_ops->orig.free(orig_node);
909
910 kfree(orig_node->tt_buff);
911 kfree(orig_node);
912}
913
914
915
916
917
918
919static void batadv_orig_node_release(struct kref *ref)
920{
921 struct hlist_node *node_tmp;
922 struct batadv_neigh_node *neigh_node;
923 struct batadv_orig_node *orig_node;
924 struct batadv_orig_ifinfo *orig_ifinfo;
925 struct batadv_orig_node_vlan *vlan;
926 struct batadv_orig_ifinfo *last_candidate;
927
928 orig_node = container_of(ref, struct batadv_orig_node, refcount);
929
930 spin_lock_bh(&orig_node->neigh_list_lock);
931
932
933 hlist_for_each_entry_safe(neigh_node, node_tmp,
934 &orig_node->neigh_list, list) {
935 hlist_del_rcu(&neigh_node->list);
936 batadv_neigh_node_put(neigh_node);
937 }
938
939 hlist_for_each_entry_safe(orig_ifinfo, node_tmp,
940 &orig_node->ifinfo_list, list) {
941 hlist_del_rcu(&orig_ifinfo->list);
942 batadv_orig_ifinfo_put(orig_ifinfo);
943 }
944
945 last_candidate = orig_node->last_bonding_candidate;
946 orig_node->last_bonding_candidate = NULL;
947 spin_unlock_bh(&orig_node->neigh_list_lock);
948
949 if (last_candidate)
950 batadv_orig_ifinfo_put(last_candidate);
951
952 spin_lock_bh(&orig_node->vlan_list_lock);
953 hlist_for_each_entry_safe(vlan, node_tmp, &orig_node->vlan_list, list) {
954 hlist_del_rcu(&vlan->list);
955 batadv_orig_node_vlan_put(vlan);
956 }
957 spin_unlock_bh(&orig_node->vlan_list_lock);
958
959
960 batadv_nc_purge_orig(orig_node->bat_priv, orig_node, NULL);
961
962 call_rcu(&orig_node->rcu, batadv_orig_node_free_rcu);
963}
964
965
966
967
968
969
970void batadv_orig_node_put(struct batadv_orig_node *orig_node)
971{
972 kref_put(&orig_node->refcount, batadv_orig_node_release);
973}
974
975
976
977
978
979void batadv_originator_free(struct batadv_priv *bat_priv)
980{
981 struct batadv_hashtable *hash = bat_priv->orig_hash;
982 struct hlist_node *node_tmp;
983 struct hlist_head *head;
984 spinlock_t *list_lock;
985 struct batadv_orig_node *orig_node;
986 u32 i;
987
988 if (!hash)
989 return;
990
991 cancel_delayed_work_sync(&bat_priv->orig_work);
992
993 bat_priv->orig_hash = NULL;
994
995 for (i = 0; i < hash->size; i++) {
996 head = &hash->table[i];
997 list_lock = &hash->list_locks[i];
998
999 spin_lock_bh(list_lock);
1000 hlist_for_each_entry_safe(orig_node, node_tmp,
1001 head, hash_entry) {
1002 hlist_del_rcu(&orig_node->hash_entry);
1003 batadv_orig_node_put(orig_node);
1004 }
1005 spin_unlock_bh(list_lock);
1006 }
1007
1008 batadv_hash_destroy(hash);
1009}
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021struct batadv_orig_node *batadv_orig_node_new(struct batadv_priv *bat_priv,
1022 const u8 *addr)
1023{
1024 struct batadv_orig_node *orig_node;
1025 struct batadv_orig_node_vlan *vlan;
1026 unsigned long reset_time;
1027 int i;
1028
1029 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1030 "Creating new originator: %pM\n", addr);
1031
1032 orig_node = kzalloc(sizeof(*orig_node), GFP_ATOMIC);
1033 if (!orig_node)
1034 return NULL;
1035
1036 INIT_HLIST_HEAD(&orig_node->neigh_list);
1037 INIT_HLIST_HEAD(&orig_node->vlan_list);
1038 INIT_HLIST_HEAD(&orig_node->ifinfo_list);
1039 spin_lock_init(&orig_node->bcast_seqno_lock);
1040 spin_lock_init(&orig_node->neigh_list_lock);
1041 spin_lock_init(&orig_node->tt_buff_lock);
1042 spin_lock_init(&orig_node->tt_lock);
1043 spin_lock_init(&orig_node->vlan_list_lock);
1044
1045 batadv_nc_init_orig(orig_node);
1046
1047
1048 kref_init(&orig_node->refcount);
1049
1050 orig_node->bat_priv = bat_priv;
1051 ether_addr_copy(orig_node->orig, addr);
1052 batadv_dat_init_orig_node_addr(orig_node);
1053 atomic_set(&orig_node->last_ttvn, 0);
1054 orig_node->tt_buff = NULL;
1055 orig_node->tt_buff_len = 0;
1056 orig_node->last_seen = jiffies;
1057 reset_time = jiffies - 1 - msecs_to_jiffies(BATADV_RESET_PROTECTION_MS);
1058 orig_node->bcast_seqno_reset = reset_time;
1059
1060#ifdef CONFIG_BATMAN_ADV_MCAST
1061 orig_node->mcast_flags = BATADV_NO_FLAGS;
1062 INIT_HLIST_NODE(&orig_node->mcast_want_all_unsnoopables_node);
1063 INIT_HLIST_NODE(&orig_node->mcast_want_all_ipv4_node);
1064 INIT_HLIST_NODE(&orig_node->mcast_want_all_ipv6_node);
1065 spin_lock_init(&orig_node->mcast_handler_lock);
1066#endif
1067
1068
1069 vlan = batadv_orig_node_vlan_new(orig_node, BATADV_NO_FLAGS);
1070 if (!vlan)
1071 goto free_orig_node;
1072
1073
1074
1075
1076 batadv_orig_node_vlan_put(vlan);
1077
1078 for (i = 0; i < BATADV_FRAG_BUFFER_COUNT; i++) {
1079 INIT_HLIST_HEAD(&orig_node->fragments[i].fragment_list);
1080 spin_lock_init(&orig_node->fragments[i].lock);
1081 orig_node->fragments[i].size = 0;
1082 }
1083
1084 return orig_node;
1085free_orig_node:
1086 kfree(orig_node);
1087 return NULL;
1088}
1089
1090
1091
1092
1093
1094
1095static void
1096batadv_purge_neigh_ifinfo(struct batadv_priv *bat_priv,
1097 struct batadv_neigh_node *neigh)
1098{
1099 struct batadv_neigh_ifinfo *neigh_ifinfo;
1100 struct batadv_hard_iface *if_outgoing;
1101 struct hlist_node *node_tmp;
1102
1103 spin_lock_bh(&neigh->ifinfo_lock);
1104
1105
1106 hlist_for_each_entry_safe(neigh_ifinfo, node_tmp,
1107 &neigh->ifinfo_list, list) {
1108 if_outgoing = neigh_ifinfo->if_outgoing;
1109
1110
1111 if (if_outgoing == BATADV_IF_DEFAULT)
1112 continue;
1113
1114
1115 if (if_outgoing->if_status != BATADV_IF_INACTIVE &&
1116 if_outgoing->if_status != BATADV_IF_NOT_IN_USE &&
1117 if_outgoing->if_status != BATADV_IF_TO_BE_REMOVED)
1118 continue;
1119
1120 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1121 "neighbor/ifinfo purge: neighbor %pM, iface: %s\n",
1122 neigh->addr, if_outgoing->net_dev->name);
1123
1124 hlist_del_rcu(&neigh_ifinfo->list);
1125 batadv_neigh_ifinfo_put(neigh_ifinfo);
1126 }
1127
1128 spin_unlock_bh(&neigh->ifinfo_lock);
1129}
1130
1131
1132
1133
1134
1135
1136
1137
1138static bool
1139batadv_purge_orig_ifinfo(struct batadv_priv *bat_priv,
1140 struct batadv_orig_node *orig_node)
1141{
1142 struct batadv_orig_ifinfo *orig_ifinfo;
1143 struct batadv_hard_iface *if_outgoing;
1144 struct hlist_node *node_tmp;
1145 bool ifinfo_purged = false;
1146
1147 spin_lock_bh(&orig_node->neigh_list_lock);
1148
1149
1150 hlist_for_each_entry_safe(orig_ifinfo, node_tmp,
1151 &orig_node->ifinfo_list, list) {
1152 if_outgoing = orig_ifinfo->if_outgoing;
1153
1154
1155 if (if_outgoing == BATADV_IF_DEFAULT)
1156 continue;
1157
1158
1159 if (if_outgoing->if_status != BATADV_IF_INACTIVE &&
1160 if_outgoing->if_status != BATADV_IF_NOT_IN_USE &&
1161 if_outgoing->if_status != BATADV_IF_TO_BE_REMOVED)
1162 continue;
1163
1164 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1165 "router/ifinfo purge: originator %pM, iface: %s\n",
1166 orig_node->orig, if_outgoing->net_dev->name);
1167
1168 ifinfo_purged = true;
1169
1170 hlist_del_rcu(&orig_ifinfo->list);
1171 batadv_orig_ifinfo_put(orig_ifinfo);
1172 if (orig_node->last_bonding_candidate == orig_ifinfo) {
1173 orig_node->last_bonding_candidate = NULL;
1174 batadv_orig_ifinfo_put(orig_ifinfo);
1175 }
1176 }
1177
1178 spin_unlock_bh(&orig_node->neigh_list_lock);
1179
1180 return ifinfo_purged;
1181}
1182
1183
1184
1185
1186
1187
1188
1189
1190static bool
1191batadv_purge_orig_neighbors(struct batadv_priv *bat_priv,
1192 struct batadv_orig_node *orig_node)
1193{
1194 struct hlist_node *node_tmp;
1195 struct batadv_neigh_node *neigh_node;
1196 bool neigh_purged = false;
1197 unsigned long last_seen;
1198 struct batadv_hard_iface *if_incoming;
1199
1200 spin_lock_bh(&orig_node->neigh_list_lock);
1201
1202
1203 hlist_for_each_entry_safe(neigh_node, node_tmp,
1204 &orig_node->neigh_list, list) {
1205 last_seen = neigh_node->last_seen;
1206 if_incoming = neigh_node->if_incoming;
1207
1208 if (batadv_has_timed_out(last_seen, BATADV_PURGE_TIMEOUT) ||
1209 if_incoming->if_status == BATADV_IF_INACTIVE ||
1210 if_incoming->if_status == BATADV_IF_NOT_IN_USE ||
1211 if_incoming->if_status == BATADV_IF_TO_BE_REMOVED) {
1212 if (if_incoming->if_status == BATADV_IF_INACTIVE ||
1213 if_incoming->if_status == BATADV_IF_NOT_IN_USE ||
1214 if_incoming->if_status == BATADV_IF_TO_BE_REMOVED)
1215 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1216 "neighbor purge: originator %pM, neighbor: %pM, iface: %s\n",
1217 orig_node->orig, neigh_node->addr,
1218 if_incoming->net_dev->name);
1219 else
1220 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1221 "neighbor timeout: originator %pM, neighbor: %pM, last_seen: %u\n",
1222 orig_node->orig, neigh_node->addr,
1223 jiffies_to_msecs(last_seen));
1224
1225 neigh_purged = true;
1226
1227 hlist_del_rcu(&neigh_node->list);
1228 batadv_neigh_node_put(neigh_node);
1229 } else {
1230
1231
1232
1233 batadv_purge_neigh_ifinfo(bat_priv, neigh_node);
1234 }
1235 }
1236
1237 spin_unlock_bh(&orig_node->neigh_list_lock);
1238 return neigh_purged;
1239}
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249static struct batadv_neigh_node *
1250batadv_find_best_neighbor(struct batadv_priv *bat_priv,
1251 struct batadv_orig_node *orig_node,
1252 struct batadv_hard_iface *if_outgoing)
1253{
1254 struct batadv_neigh_node *best = NULL, *neigh;
1255 struct batadv_algo_ops *bao = bat_priv->algo_ops;
1256
1257 rcu_read_lock();
1258 hlist_for_each_entry_rcu(neigh, &orig_node->neigh_list, list) {
1259 if (best && (bao->neigh.cmp(neigh, if_outgoing, best,
1260 if_outgoing) <= 0))
1261 continue;
1262
1263 if (!kref_get_unless_zero(&neigh->refcount))
1264 continue;
1265
1266 if (best)
1267 batadv_neigh_node_put(best);
1268
1269 best = neigh;
1270 }
1271 rcu_read_unlock();
1272
1273 return best;
1274}
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286static bool batadv_purge_orig_node(struct batadv_priv *bat_priv,
1287 struct batadv_orig_node *orig_node)
1288{
1289 struct batadv_neigh_node *best_neigh_node;
1290 struct batadv_hard_iface *hard_iface;
1291 bool changed_ifinfo, changed_neigh;
1292
1293 if (batadv_has_timed_out(orig_node->last_seen,
1294 2 * BATADV_PURGE_TIMEOUT)) {
1295 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1296 "Originator timeout: originator %pM, last_seen %u\n",
1297 orig_node->orig,
1298 jiffies_to_msecs(orig_node->last_seen));
1299 return true;
1300 }
1301 changed_ifinfo = batadv_purge_orig_ifinfo(bat_priv, orig_node);
1302 changed_neigh = batadv_purge_orig_neighbors(bat_priv, orig_node);
1303
1304 if (!changed_ifinfo && !changed_neigh)
1305 return false;
1306
1307
1308 best_neigh_node = batadv_find_best_neighbor(bat_priv, orig_node,
1309 BATADV_IF_DEFAULT);
1310 batadv_update_route(bat_priv, orig_node, BATADV_IF_DEFAULT,
1311 best_neigh_node);
1312 if (best_neigh_node)
1313 batadv_neigh_node_put(best_neigh_node);
1314
1315
1316 rcu_read_lock();
1317 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
1318 if (hard_iface->if_status != BATADV_IF_ACTIVE)
1319 continue;
1320
1321 if (hard_iface->soft_iface != bat_priv->soft_iface)
1322 continue;
1323
1324 if (!kref_get_unless_zero(&hard_iface->refcount))
1325 continue;
1326
1327 best_neigh_node = batadv_find_best_neighbor(bat_priv,
1328 orig_node,
1329 hard_iface);
1330 batadv_update_route(bat_priv, orig_node, hard_iface,
1331 best_neigh_node);
1332 if (best_neigh_node)
1333 batadv_neigh_node_put(best_neigh_node);
1334
1335 batadv_hardif_put(hard_iface);
1336 }
1337 rcu_read_unlock();
1338
1339 return false;
1340}
1341
1342static void _batadv_purge_orig(struct batadv_priv *bat_priv)
1343{
1344 struct batadv_hashtable *hash = bat_priv->orig_hash;
1345 struct hlist_node *node_tmp;
1346 struct hlist_head *head;
1347 spinlock_t *list_lock;
1348 struct batadv_orig_node *orig_node;
1349 u32 i;
1350
1351 if (!hash)
1352 return;
1353
1354
1355 for (i = 0; i < hash->size; i++) {
1356 head = &hash->table[i];
1357 list_lock = &hash->list_locks[i];
1358
1359 spin_lock_bh(list_lock);
1360 hlist_for_each_entry_safe(orig_node, node_tmp,
1361 head, hash_entry) {
1362 if (batadv_purge_orig_node(bat_priv, orig_node)) {
1363 batadv_gw_node_delete(bat_priv, orig_node);
1364 hlist_del_rcu(&orig_node->hash_entry);
1365 batadv_tt_global_del_orig(orig_node->bat_priv,
1366 orig_node, -1,
1367 "originator timed out");
1368 batadv_orig_node_put(orig_node);
1369 continue;
1370 }
1371
1372 batadv_frag_purge_orig(orig_node,
1373 batadv_frag_check_entry);
1374 }
1375 spin_unlock_bh(list_lock);
1376 }
1377
1378 batadv_gw_election(bat_priv);
1379}
1380
1381static void batadv_purge_orig(struct work_struct *work)
1382{
1383 struct delayed_work *delayed_work;
1384 struct batadv_priv *bat_priv;
1385
1386 delayed_work = to_delayed_work(work);
1387 bat_priv = container_of(delayed_work, struct batadv_priv, orig_work);
1388 _batadv_purge_orig(bat_priv);
1389 queue_delayed_work(batadv_event_workqueue,
1390 &bat_priv->orig_work,
1391 msecs_to_jiffies(BATADV_ORIG_WORK_PERIOD));
1392}
1393
1394
1395
1396
1397
1398void batadv_purge_orig_ref(struct batadv_priv *bat_priv)
1399{
1400 _batadv_purge_orig(bat_priv);
1401}
1402
1403#ifdef CONFIG_BATMAN_ADV_DEBUGFS
1404
1405
1406
1407
1408
1409
1410
1411
1412int batadv_orig_seq_print_text(struct seq_file *seq, void *offset)
1413{
1414 struct net_device *net_dev = (struct net_device *)seq->private;
1415 struct batadv_priv *bat_priv = netdev_priv(net_dev);
1416 struct batadv_hard_iface *primary_if;
1417
1418 primary_if = batadv_seq_print_text_primary_if_get(seq);
1419 if (!primary_if)
1420 return 0;
1421
1422 seq_printf(seq, "[B.A.T.M.A.N. adv %s, MainIF/MAC: %s/%pM (%s %s)]\n",
1423 BATADV_SOURCE_VERSION, primary_if->net_dev->name,
1424 primary_if->net_dev->dev_addr, net_dev->name,
1425 bat_priv->algo_ops->name);
1426
1427 batadv_hardif_put(primary_if);
1428
1429 if (!bat_priv->algo_ops->orig.print) {
1430 seq_puts(seq,
1431 "No printing function for this routing protocol\n");
1432 return 0;
1433 }
1434
1435 bat_priv->algo_ops->orig.print(bat_priv, seq, BATADV_IF_DEFAULT);
1436
1437 return 0;
1438}
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448int batadv_orig_hardif_seq_print_text(struct seq_file *seq, void *offset)
1449{
1450 struct net_device *net_dev = (struct net_device *)seq->private;
1451 struct batadv_hard_iface *hard_iface;
1452 struct batadv_priv *bat_priv;
1453
1454 hard_iface = batadv_hardif_get_by_netdev(net_dev);
1455
1456 if (!hard_iface || !hard_iface->soft_iface) {
1457 seq_puts(seq, "Interface not known to B.A.T.M.A.N.\n");
1458 goto out;
1459 }
1460
1461 bat_priv = netdev_priv(hard_iface->soft_iface);
1462 if (!bat_priv->algo_ops->orig.print) {
1463 seq_puts(seq,
1464 "No printing function for this routing protocol\n");
1465 goto out;
1466 }
1467
1468 if (hard_iface->if_status != BATADV_IF_ACTIVE) {
1469 seq_puts(seq, "Interface not active\n");
1470 goto out;
1471 }
1472
1473 seq_printf(seq, "[B.A.T.M.A.N. adv %s, IF/MAC: %s/%pM (%s %s)]\n",
1474 BATADV_SOURCE_VERSION, hard_iface->net_dev->name,
1475 hard_iface->net_dev->dev_addr,
1476 hard_iface->soft_iface->name, bat_priv->algo_ops->name);
1477
1478 bat_priv->algo_ops->orig.print(bat_priv, seq, hard_iface);
1479
1480out:
1481 if (hard_iface)
1482 batadv_hardif_put(hard_iface);
1483 return 0;
1484}
1485#endif
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495int batadv_orig_dump(struct sk_buff *msg, struct netlink_callback *cb)
1496{
1497 struct net *net = sock_net(cb->skb->sk);
1498 struct net_device *soft_iface;
1499 struct net_device *hard_iface = NULL;
1500 struct batadv_hard_iface *hardif = BATADV_IF_DEFAULT;
1501 struct batadv_priv *bat_priv;
1502 struct batadv_hard_iface *primary_if = NULL;
1503 int ret;
1504 int ifindex, hard_ifindex;
1505
1506 ifindex = batadv_netlink_get_ifindex(cb->nlh, BATADV_ATTR_MESH_IFINDEX);
1507 if (!ifindex)
1508 return -EINVAL;
1509
1510 soft_iface = dev_get_by_index(net, ifindex);
1511 if (!soft_iface || !batadv_softif_is_valid(soft_iface)) {
1512 ret = -ENODEV;
1513 goto out;
1514 }
1515
1516 bat_priv = netdev_priv(soft_iface);
1517
1518 primary_if = batadv_primary_if_get_selected(bat_priv);
1519 if (!primary_if || primary_if->if_status != BATADV_IF_ACTIVE) {
1520 ret = -ENOENT;
1521 goto out;
1522 }
1523
1524 hard_ifindex = batadv_netlink_get_ifindex(cb->nlh,
1525 BATADV_ATTR_HARD_IFINDEX);
1526 if (hard_ifindex) {
1527 hard_iface = dev_get_by_index(net, hard_ifindex);
1528 if (hard_iface)
1529 hardif = batadv_hardif_get_by_netdev(hard_iface);
1530
1531 if (!hardif) {
1532 ret = -ENODEV;
1533 goto out;
1534 }
1535
1536 if (hardif->soft_iface != soft_iface) {
1537 ret = -ENOENT;
1538 goto out;
1539 }
1540 }
1541
1542 if (!bat_priv->algo_ops->orig.dump) {
1543 ret = -EOPNOTSUPP;
1544 goto out;
1545 }
1546
1547 bat_priv->algo_ops->orig.dump(msg, cb, bat_priv, hardif);
1548
1549 ret = msg->len;
1550
1551 out:
1552 if (hardif)
1553 batadv_hardif_put(hardif);
1554 if (hard_iface)
1555 dev_put(hard_iface);
1556 if (primary_if)
1557 batadv_hardif_put(primary_if);
1558 if (soft_iface)
1559 dev_put(soft_iface);
1560
1561 return ret;
1562}
1563
1564
1565
1566
1567
1568
1569
1570
1571int batadv_orig_hash_add_if(struct batadv_hard_iface *hard_iface,
1572 unsigned int max_if_num)
1573{
1574 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
1575 struct batadv_algo_ops *bao = bat_priv->algo_ops;
1576 struct batadv_hashtable *hash = bat_priv->orig_hash;
1577 struct hlist_head *head;
1578 struct batadv_orig_node *orig_node;
1579 u32 i;
1580 int ret;
1581
1582
1583
1584
1585 for (i = 0; i < hash->size; i++) {
1586 head = &hash->table[i];
1587
1588 rcu_read_lock();
1589 hlist_for_each_entry_rcu(orig_node, head, hash_entry) {
1590 ret = 0;
1591 if (bao->orig.add_if)
1592 ret = bao->orig.add_if(orig_node, max_if_num);
1593 if (ret == -ENOMEM)
1594 goto err;
1595 }
1596 rcu_read_unlock();
1597 }
1598
1599 return 0;
1600
1601err:
1602 rcu_read_unlock();
1603 return -ENOMEM;
1604}
1605
1606
1607
1608
1609
1610
1611
1612
1613int batadv_orig_hash_del_if(struct batadv_hard_iface *hard_iface,
1614 unsigned int max_if_num)
1615{
1616 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
1617 struct batadv_hashtable *hash = bat_priv->orig_hash;
1618 struct hlist_head *head;
1619 struct batadv_hard_iface *hard_iface_tmp;
1620 struct batadv_orig_node *orig_node;
1621 struct batadv_algo_ops *bao = bat_priv->algo_ops;
1622 u32 i;
1623 int ret;
1624
1625
1626
1627
1628 for (i = 0; i < hash->size; i++) {
1629 head = &hash->table[i];
1630
1631 rcu_read_lock();
1632 hlist_for_each_entry_rcu(orig_node, head, hash_entry) {
1633 ret = 0;
1634 if (bao->orig.del_if)
1635 ret = bao->orig.del_if(orig_node, max_if_num,
1636 hard_iface->if_num);
1637 if (ret == -ENOMEM)
1638 goto err;
1639 }
1640 rcu_read_unlock();
1641 }
1642
1643
1644 rcu_read_lock();
1645 list_for_each_entry_rcu(hard_iface_tmp, &batadv_hardif_list, list) {
1646 if (hard_iface_tmp->if_status == BATADV_IF_NOT_IN_USE)
1647 continue;
1648
1649 if (hard_iface == hard_iface_tmp)
1650 continue;
1651
1652 if (hard_iface->soft_iface != hard_iface_tmp->soft_iface)
1653 continue;
1654
1655 if (hard_iface_tmp->if_num > hard_iface->if_num)
1656 hard_iface_tmp->if_num--;
1657 }
1658 rcu_read_unlock();
1659
1660 hard_iface->if_num = -1;
1661 return 0;
1662
1663err:
1664 rcu_read_unlock();
1665 return -ENOMEM;
1666}
1667