This source file includes following definitions.
- batadv_mcast_start_timer
- batadv_mcast_get_bridge
- batadv_mcast_mla_rtr_flags_softif_get_ipv4
- batadv_mcast_mla_rtr_flags_softif_get_ipv6
- batadv_mcast_mla_rtr_flags_softif_get_ipv6
- batadv_mcast_mla_rtr_flags_softif_get
- batadv_mcast_mla_rtr_flags_bridge_get
- batadv_mcast_mla_rtr_flags_bridge_get
- batadv_mcast_mla_rtr_flags_get
- batadv_mcast_mla_flags_get
- batadv_mcast_mla_is_duplicate
- batadv_mcast_mla_softif_get_ipv4
- batadv_mcast_mla_softif_get_ipv6
- batadv_mcast_mla_softif_get_ipv6
- batadv_mcast_mla_softif_get
- batadv_mcast_mla_br_addr_cpy
- batadv_mcast_mla_bridge_get
- batadv_mcast_mla_list_free
- batadv_mcast_mla_tt_retract
- batadv_mcast_mla_tt_add
- batadv_mcast_querier_log
- batadv_mcast_bridge_log
- batadv_mcast_flags_log
- batadv_mcast_mla_flags_update
- __batadv_mcast_mla_update
- batadv_mcast_mla_update
- batadv_mcast_is_report_ipv4
- batadv_mcast_forw_mode_check_ipv4
- batadv_mcast_is_report_ipv6
- batadv_mcast_forw_mode_check_ipv6
- batadv_mcast_forw_mode_check
- batadv_mcast_forw_want_all_ip_count
- batadv_mcast_forw_rtr_count
- batadv_mcast_forw_tt_node_get
- batadv_mcast_forw_ipv4_node_get
- batadv_mcast_forw_ipv6_node_get
- batadv_mcast_forw_ip_node_get
- batadv_mcast_forw_unsnoop_node_get
- batadv_mcast_forw_rtr4_node_get
- batadv_mcast_forw_rtr6_node_get
- batadv_mcast_forw_rtr_node_get
- batadv_mcast_forw_mode
- batadv_mcast_forw_tt
- batadv_mcast_forw_want_all_ipv4
- batadv_mcast_forw_want_all_ipv6
- batadv_mcast_forw_want_all
- batadv_mcast_forw_want_all_rtr4
- batadv_mcast_forw_want_all_rtr6
- batadv_mcast_forw_want_rtr
- batadv_mcast_forw_send
- batadv_mcast_want_unsnoop_update
- batadv_mcast_want_ipv4_update
- batadv_mcast_want_ipv6_update
- batadv_mcast_want_rtr4_update
- batadv_mcast_want_rtr6_update
- batadv_mcast_tvlv_flags_get
- batadv_mcast_tvlv_ogm_handler
- batadv_mcast_init
- batadv_mcast_flags_print_header
- batadv_mcast_flags_seq_print_text
- batadv_mcast_mesh_info_put
- batadv_mcast_flags_dump_entry
- batadv_mcast_flags_dump_bucket
- __batadv_mcast_flags_dump
- batadv_mcast_netlink_get_primary
- batadv_mcast_flags_dump
- batadv_mcast_free
- batadv_mcast_purge_orig
1
2
3
4
5
6
7 #include "multicast.h"
8 #include "main.h"
9
10 #include <linux/atomic.h>
11 #include <linux/bitops.h>
12 #include <linux/bug.h>
13 #include <linux/byteorder/generic.h>
14 #include <linux/errno.h>
15 #include <linux/etherdevice.h>
16 #include <linux/gfp.h>
17 #include <linux/icmpv6.h>
18 #include <linux/if_bridge.h>
19 #include <linux/if_ether.h>
20 #include <linux/igmp.h>
21 #include <linux/in.h>
22 #include <linux/in6.h>
23 #include <linux/inetdevice.h>
24 #include <linux/ip.h>
25 #include <linux/ipv6.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/printk.h>
34 #include <linux/rculist.h>
35 #include <linux/rcupdate.h>
36 #include <linux/seq_file.h>
37 #include <linux/skbuff.h>
38 #include <linux/slab.h>
39 #include <linux/spinlock.h>
40 #include <linux/stddef.h>
41 #include <linux/string.h>
42 #include <linux/types.h>
43 #include <linux/workqueue.h>
44 #include <net/addrconf.h>
45 #include <net/genetlink.h>
46 #include <net/if_inet6.h>
47 #include <net/ip.h>
48 #include <net/ipv6.h>
49 #include <net/netlink.h>
50 #include <net/sock.h>
51 #include <uapi/linux/batadv_packet.h>
52 #include <uapi/linux/batman_adv.h>
53
54 #include "hard-interface.h"
55 #include "hash.h"
56 #include "log.h"
57 #include "netlink.h"
58 #include "send.h"
59 #include "soft-interface.h"
60 #include "translation-table.h"
61 #include "tvlv.h"
62
63 static void batadv_mcast_mla_update(struct work_struct *work);
64
65
66
67
68
69 static void batadv_mcast_start_timer(struct batadv_priv *bat_priv)
70 {
71 queue_delayed_work(batadv_event_workqueue, &bat_priv->mcast.work,
72 msecs_to_jiffies(BATADV_MCAST_WORK_PERIOD));
73 }
74
75
76
77
78
79
80
81
82
83
84
85 static struct net_device *batadv_mcast_get_bridge(struct net_device *soft_iface)
86 {
87 struct net_device *upper = soft_iface;
88
89 rcu_read_lock();
90 do {
91 upper = netdev_master_upper_dev_get_rcu(upper);
92 } while (upper && !(upper->priv_flags & IFF_EBRIDGE));
93
94 if (upper)
95 dev_hold(upper);
96 rcu_read_unlock();
97
98 return upper;
99 }
100
101
102
103
104
105
106
107
108
109
110
111
112 static u8 batadv_mcast_mla_rtr_flags_softif_get_ipv4(struct net_device *dev)
113 {
114 struct in_device *in_dev = __in_dev_get_rcu(dev);
115
116 if (in_dev && IN_DEV_MFORWARD(in_dev))
117 return BATADV_NO_FLAGS;
118 else
119 return BATADV_MCAST_WANT_NO_RTR4;
120 }
121
122
123
124
125
126
127
128
129
130
131
132
133 #if IS_ENABLED(CONFIG_IPV6_MROUTE)
134 static u8 batadv_mcast_mla_rtr_flags_softif_get_ipv6(struct net_device *dev)
135 {
136 struct inet6_dev *in6_dev = __in6_dev_get(dev);
137
138 if (in6_dev && in6_dev->cnf.mc_forwarding)
139 return BATADV_NO_FLAGS;
140 else
141 return BATADV_MCAST_WANT_NO_RTR6;
142 }
143 #else
144 static inline u8
145 batadv_mcast_mla_rtr_flags_softif_get_ipv6(struct net_device *dev)
146 {
147 return BATADV_MCAST_WANT_NO_RTR6;
148 }
149 #endif
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166 static u8 batadv_mcast_mla_rtr_flags_softif_get(struct batadv_priv *bat_priv,
167 struct net_device *bridge)
168 {
169 struct net_device *dev = bridge ? bridge : bat_priv->soft_iface;
170 u8 flags = BATADV_NO_FLAGS;
171
172 rcu_read_lock();
173
174 flags |= batadv_mcast_mla_rtr_flags_softif_get_ipv4(dev);
175 flags |= batadv_mcast_mla_rtr_flags_softif_get_ipv6(dev);
176
177 rcu_read_unlock();
178
179 return flags;
180 }
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196 #if IS_ENABLED(CONFIG_IPV6)
197 static u8 batadv_mcast_mla_rtr_flags_bridge_get(struct batadv_priv *bat_priv,
198 struct net_device *bridge)
199 {
200 struct list_head bridge_mcast_list = LIST_HEAD_INIT(bridge_mcast_list);
201 struct net_device *dev = bat_priv->soft_iface;
202 struct br_ip_list *br_ip_entry, *tmp;
203 u8 flags = BATADV_MCAST_WANT_NO_RTR6;
204 int ret;
205
206 if (!bridge)
207 return BATADV_MCAST_WANT_NO_RTR4 | BATADV_MCAST_WANT_NO_RTR6;
208
209
210
211
212
213 ret = br_multicast_list_adjacent(dev, &bridge_mcast_list);
214 if (ret < 0)
215 return BATADV_NO_FLAGS;
216
217 list_for_each_entry_safe(br_ip_entry, tmp, &bridge_mcast_list, list) {
218
219
220
221
222 if (br_ip_entry->addr.proto == htons(ETH_P_IPV6) &&
223 ipv6_addr_is_ll_all_routers(&br_ip_entry->addr.u.ip6))
224 flags &= ~BATADV_MCAST_WANT_NO_RTR6;
225
226 list_del(&br_ip_entry->list);
227 kfree(br_ip_entry);
228 }
229
230 return flags;
231 }
232 #else
233 static inline u8
234 batadv_mcast_mla_rtr_flags_bridge_get(struct batadv_priv *bat_priv,
235 struct net_device *bridge)
236 {
237 if (bridge)
238 return BATADV_NO_FLAGS;
239 else
240 return BATADV_MCAST_WANT_NO_RTR4 | BATADV_MCAST_WANT_NO_RTR6;
241 }
242 #endif
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259 static u8 batadv_mcast_mla_rtr_flags_get(struct batadv_priv *bat_priv,
260 struct net_device *bridge)
261 {
262 u8 flags = BATADV_MCAST_WANT_NO_RTR4 | BATADV_MCAST_WANT_NO_RTR6;
263
264 flags &= batadv_mcast_mla_rtr_flags_softif_get(bat_priv, bridge);
265 flags &= batadv_mcast_mla_rtr_flags_bridge_get(bat_priv, bridge);
266
267 return flags;
268 }
269
270
271
272
273
274
275
276
277 static struct batadv_mcast_mla_flags
278 batadv_mcast_mla_flags_get(struct batadv_priv *bat_priv)
279 {
280 struct net_device *dev = bat_priv->soft_iface;
281 struct batadv_mcast_querier_state *qr4, *qr6;
282 struct batadv_mcast_mla_flags mla_flags;
283 struct net_device *bridge;
284
285 bridge = batadv_mcast_get_bridge(dev);
286
287 memset(&mla_flags, 0, sizeof(mla_flags));
288 mla_flags.enabled = 1;
289 mla_flags.tvlv_flags |= batadv_mcast_mla_rtr_flags_get(bat_priv,
290 bridge);
291
292 if (!bridge)
293 return mla_flags;
294
295 dev_put(bridge);
296
297 mla_flags.bridged = 1;
298 qr4 = &mla_flags.querier_ipv4;
299 qr6 = &mla_flags.querier_ipv6;
300
301 if (!IS_ENABLED(CONFIG_BRIDGE_IGMP_SNOOPING))
302 pr_warn_once("No bridge IGMP snooping compiled - multicast optimizations disabled\n");
303
304 qr4->exists = br_multicast_has_querier_anywhere(dev, ETH_P_IP);
305 qr4->shadowing = br_multicast_has_querier_adjacent(dev, ETH_P_IP);
306
307 qr6->exists = br_multicast_has_querier_anywhere(dev, ETH_P_IPV6);
308 qr6->shadowing = br_multicast_has_querier_adjacent(dev, ETH_P_IPV6);
309
310 mla_flags.tvlv_flags |= BATADV_MCAST_WANT_ALL_UNSNOOPABLES;
311
312
313
314
315
316
317
318
319
320
321 if (!qr4->exists || qr4->shadowing) {
322 mla_flags.tvlv_flags |= BATADV_MCAST_WANT_ALL_IPV4;
323 mla_flags.tvlv_flags &= ~BATADV_MCAST_WANT_NO_RTR4;
324 }
325
326 if (!qr6->exists || qr6->shadowing) {
327 mla_flags.tvlv_flags |= BATADV_MCAST_WANT_ALL_IPV6;
328 mla_flags.tvlv_flags &= ~BATADV_MCAST_WANT_NO_RTR6;
329 }
330
331 return mla_flags;
332 }
333
334
335
336
337
338
339
340
341
342 static bool batadv_mcast_mla_is_duplicate(u8 *mcast_addr,
343 struct hlist_head *mcast_list)
344 {
345 struct batadv_hw_addr *mcast_entry;
346
347 hlist_for_each_entry(mcast_entry, mcast_list, list)
348 if (batadv_compare_eth(mcast_entry->addr, mcast_addr))
349 return true;
350
351 return false;
352 }
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368 static int
369 batadv_mcast_mla_softif_get_ipv4(struct net_device *dev,
370 struct hlist_head *mcast_list,
371 struct batadv_mcast_mla_flags *flags)
372 {
373 struct batadv_hw_addr *new;
374 struct in_device *in_dev;
375 u8 mcast_addr[ETH_ALEN];
376 struct ip_mc_list *pmc;
377 int ret = 0;
378
379 if (flags->tvlv_flags & BATADV_MCAST_WANT_ALL_IPV4)
380 return 0;
381
382 rcu_read_lock();
383
384 in_dev = __in_dev_get_rcu(dev);
385 if (!in_dev) {
386 rcu_read_unlock();
387 return 0;
388 }
389
390 for (pmc = rcu_dereference(in_dev->mc_list); pmc;
391 pmc = rcu_dereference(pmc->next_rcu)) {
392 if (flags->tvlv_flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES &&
393 ipv4_is_local_multicast(pmc->multiaddr))
394 continue;
395
396 if (!(flags->tvlv_flags & BATADV_MCAST_WANT_NO_RTR4) &&
397 !ipv4_is_local_multicast(pmc->multiaddr))
398 continue;
399
400 ip_eth_mc_map(pmc->multiaddr, mcast_addr);
401
402 if (batadv_mcast_mla_is_duplicate(mcast_addr, mcast_list))
403 continue;
404
405 new = kmalloc(sizeof(*new), GFP_ATOMIC);
406 if (!new) {
407 ret = -ENOMEM;
408 break;
409 }
410
411 ether_addr_copy(new->addr, mcast_addr);
412 hlist_add_head(&new->list, mcast_list);
413 ret++;
414 }
415 rcu_read_unlock();
416
417 return ret;
418 }
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434 #if IS_ENABLED(CONFIG_IPV6)
435 static int
436 batadv_mcast_mla_softif_get_ipv6(struct net_device *dev,
437 struct hlist_head *mcast_list,
438 struct batadv_mcast_mla_flags *flags)
439 {
440 struct batadv_hw_addr *new;
441 struct inet6_dev *in6_dev;
442 u8 mcast_addr[ETH_ALEN];
443 struct ifmcaddr6 *pmc6;
444 int ret = 0;
445
446 if (flags->tvlv_flags & BATADV_MCAST_WANT_ALL_IPV6)
447 return 0;
448
449 rcu_read_lock();
450
451 in6_dev = __in6_dev_get(dev);
452 if (!in6_dev) {
453 rcu_read_unlock();
454 return 0;
455 }
456
457 read_lock_bh(&in6_dev->lock);
458 for (pmc6 = in6_dev->mc_list; pmc6; pmc6 = pmc6->next) {
459 if (IPV6_ADDR_MC_SCOPE(&pmc6->mca_addr) <
460 IPV6_ADDR_SCOPE_LINKLOCAL)
461 continue;
462
463 if (flags->tvlv_flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES &&
464 ipv6_addr_is_ll_all_nodes(&pmc6->mca_addr))
465 continue;
466
467 if (!(flags->tvlv_flags & BATADV_MCAST_WANT_NO_RTR6) &&
468 IPV6_ADDR_MC_SCOPE(&pmc6->mca_addr) >
469 IPV6_ADDR_SCOPE_LINKLOCAL)
470 continue;
471
472 ipv6_eth_mc_map(&pmc6->mca_addr, mcast_addr);
473
474 if (batadv_mcast_mla_is_duplicate(mcast_addr, mcast_list))
475 continue;
476
477 new = kmalloc(sizeof(*new), GFP_ATOMIC);
478 if (!new) {
479 ret = -ENOMEM;
480 break;
481 }
482
483 ether_addr_copy(new->addr, mcast_addr);
484 hlist_add_head(&new->list, mcast_list);
485 ret++;
486 }
487 read_unlock_bh(&in6_dev->lock);
488 rcu_read_unlock();
489
490 return ret;
491 }
492 #else
493 static inline int
494 batadv_mcast_mla_softif_get_ipv6(struct net_device *dev,
495 struct hlist_head *mcast_list,
496 struct batadv_mcast_mla_flags *flags)
497 {
498 return 0;
499 }
500 #endif
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521 static int
522 batadv_mcast_mla_softif_get(struct net_device *dev,
523 struct hlist_head *mcast_list,
524 struct batadv_mcast_mla_flags *flags)
525 {
526 struct net_device *bridge = batadv_mcast_get_bridge(dev);
527 int ret4, ret6 = 0;
528
529 if (bridge)
530 dev = bridge;
531
532 ret4 = batadv_mcast_mla_softif_get_ipv4(dev, mcast_list, flags);
533 if (ret4 < 0)
534 goto out;
535
536 ret6 = batadv_mcast_mla_softif_get_ipv6(dev, mcast_list, flags);
537 if (ret6 < 0) {
538 ret4 = 0;
539 goto out;
540 }
541
542 out:
543 if (bridge)
544 dev_put(bridge);
545
546 return ret4 + ret6;
547 }
548
549
550
551
552
553
554
555
556
557
558
559
560
561 static void batadv_mcast_mla_br_addr_cpy(char *dst, const struct br_ip *src)
562 {
563 if (src->proto == htons(ETH_P_IP))
564 ip_eth_mc_map(src->u.ip4, dst);
565 #if IS_ENABLED(CONFIG_IPV6)
566 else if (src->proto == htons(ETH_P_IPV6))
567 ipv6_eth_mc_map(&src->u.ip6, dst);
568 #endif
569 else
570 eth_zero_addr(dst);
571 }
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587 static int batadv_mcast_mla_bridge_get(struct net_device *dev,
588 struct hlist_head *mcast_list,
589 struct batadv_mcast_mla_flags *flags)
590 {
591 struct list_head bridge_mcast_list = LIST_HEAD_INIT(bridge_mcast_list);
592 struct br_ip_list *br_ip_entry, *tmp;
593 u8 tvlv_flags = flags->tvlv_flags;
594 struct batadv_hw_addr *new;
595 u8 mcast_addr[ETH_ALEN];
596 int ret;
597
598
599
600
601 ret = br_multicast_list_adjacent(dev, &bridge_mcast_list);
602 if (ret < 0)
603 goto out;
604
605 list_for_each_entry(br_ip_entry, &bridge_mcast_list, list) {
606 if (br_ip_entry->addr.proto == htons(ETH_P_IP)) {
607 if (tvlv_flags & BATADV_MCAST_WANT_ALL_IPV4)
608 continue;
609
610 if (tvlv_flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES &&
611 ipv4_is_local_multicast(br_ip_entry->addr.u.ip4))
612 continue;
613
614 if (!(tvlv_flags & BATADV_MCAST_WANT_NO_RTR4) &&
615 !ipv4_is_local_multicast(br_ip_entry->addr.u.ip4))
616 continue;
617 }
618
619 #if IS_ENABLED(CONFIG_IPV6)
620 if (br_ip_entry->addr.proto == htons(ETH_P_IPV6)) {
621 if (tvlv_flags & BATADV_MCAST_WANT_ALL_IPV6)
622 continue;
623
624 if (tvlv_flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES &&
625 ipv6_addr_is_ll_all_nodes(&br_ip_entry->addr.u.ip6))
626 continue;
627
628 if (!(tvlv_flags & BATADV_MCAST_WANT_NO_RTR6) &&
629 IPV6_ADDR_MC_SCOPE(&br_ip_entry->addr.u.ip6) >
630 IPV6_ADDR_SCOPE_LINKLOCAL)
631 continue;
632 }
633 #endif
634
635 batadv_mcast_mla_br_addr_cpy(mcast_addr, &br_ip_entry->addr);
636 if (batadv_mcast_mla_is_duplicate(mcast_addr, mcast_list))
637 continue;
638
639 new = kmalloc(sizeof(*new), GFP_ATOMIC);
640 if (!new) {
641 ret = -ENOMEM;
642 break;
643 }
644
645 ether_addr_copy(new->addr, mcast_addr);
646 hlist_add_head(&new->list, mcast_list);
647 }
648
649 out:
650 list_for_each_entry_safe(br_ip_entry, tmp, &bridge_mcast_list, list) {
651 list_del(&br_ip_entry->list);
652 kfree(br_ip_entry);
653 }
654
655 return ret;
656 }
657
658
659
660
661
662
663
664 static void batadv_mcast_mla_list_free(struct hlist_head *mcast_list)
665 {
666 struct batadv_hw_addr *mcast_entry;
667 struct hlist_node *tmp;
668
669 hlist_for_each_entry_safe(mcast_entry, tmp, mcast_list, list) {
670 hlist_del(&mcast_entry->list);
671 kfree(mcast_entry);
672 }
673 }
674
675
676
677
678
679
680
681
682
683
684
685 static void batadv_mcast_mla_tt_retract(struct batadv_priv *bat_priv,
686 struct hlist_head *mcast_list)
687 {
688 struct batadv_hw_addr *mcast_entry;
689 struct hlist_node *tmp;
690
691 hlist_for_each_entry_safe(mcast_entry, tmp, &bat_priv->mcast.mla_list,
692 list) {
693 if (mcast_list &&
694 batadv_mcast_mla_is_duplicate(mcast_entry->addr,
695 mcast_list))
696 continue;
697
698 batadv_tt_local_remove(bat_priv, mcast_entry->addr,
699 BATADV_NO_FLAGS,
700 "mcast TT outdated", false);
701
702 hlist_del(&mcast_entry->list);
703 kfree(mcast_entry);
704 }
705 }
706
707
708
709
710
711
712
713
714
715 static void batadv_mcast_mla_tt_add(struct batadv_priv *bat_priv,
716 struct hlist_head *mcast_list)
717 {
718 struct batadv_hw_addr *mcast_entry;
719 struct hlist_node *tmp;
720
721 if (!mcast_list)
722 return;
723
724 hlist_for_each_entry_safe(mcast_entry, tmp, mcast_list, list) {
725 if (batadv_mcast_mla_is_duplicate(mcast_entry->addr,
726 &bat_priv->mcast.mla_list))
727 continue;
728
729 if (!batadv_tt_local_add(bat_priv->soft_iface,
730 mcast_entry->addr, BATADV_NO_FLAGS,
731 BATADV_NULL_IFINDEX, BATADV_NO_MARK))
732 continue;
733
734 hlist_del(&mcast_entry->list);
735 hlist_add_head(&mcast_entry->list, &bat_priv->mcast.mla_list);
736 }
737 }
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761 static void
762 batadv_mcast_querier_log(struct batadv_priv *bat_priv, char *str_proto,
763 struct batadv_mcast_querier_state *old_state,
764 struct batadv_mcast_querier_state *new_state)
765 {
766 if (!old_state->exists && new_state->exists)
767 batadv_info(bat_priv->soft_iface, "%s Querier appeared\n",
768 str_proto);
769 else if (old_state->exists && !new_state->exists)
770 batadv_info(bat_priv->soft_iface,
771 "%s Querier disappeared - multicast optimizations disabled\n",
772 str_proto);
773 else if (!bat_priv->mcast.mla_flags.bridged && !new_state->exists)
774 batadv_info(bat_priv->soft_iface,
775 "No %s Querier present - multicast optimizations disabled\n",
776 str_proto);
777
778 if (new_state->exists) {
779 if ((!old_state->shadowing && new_state->shadowing) ||
780 (!old_state->exists && new_state->shadowing))
781 batadv_dbg(BATADV_DBG_MCAST, bat_priv,
782 "%s Querier is behind our bridged segment: Might shadow listeners\n",
783 str_proto);
784 else if (old_state->shadowing && !new_state->shadowing)
785 batadv_dbg(BATADV_DBG_MCAST, bat_priv,
786 "%s Querier is not behind our bridged segment\n",
787 str_proto);
788 }
789 }
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807 static void
808 batadv_mcast_bridge_log(struct batadv_priv *bat_priv,
809 struct batadv_mcast_mla_flags *new_flags)
810 {
811 struct batadv_mcast_mla_flags *old_flags = &bat_priv->mcast.mla_flags;
812
813 if (!old_flags->bridged && new_flags->bridged)
814 batadv_dbg(BATADV_DBG_MCAST, bat_priv,
815 "Bridge added: Setting Unsnoopables(U)-flag\n");
816 else if (old_flags->bridged && !new_flags->bridged)
817 batadv_dbg(BATADV_DBG_MCAST, bat_priv,
818 "Bridge removed: Unsetting Unsnoopables(U)-flag\n");
819
820 if (new_flags->bridged) {
821 batadv_mcast_querier_log(bat_priv, "IGMP",
822 &old_flags->querier_ipv4,
823 &new_flags->querier_ipv4);
824 batadv_mcast_querier_log(bat_priv, "MLD",
825 &old_flags->querier_ipv6,
826 &new_flags->querier_ipv6);
827 }
828 }
829
830
831
832
833
834
835
836
837
838 static void batadv_mcast_flags_log(struct batadv_priv *bat_priv, u8 flags)
839 {
840 bool old_enabled = bat_priv->mcast.mla_flags.enabled;
841 u8 old_flags = bat_priv->mcast.mla_flags.tvlv_flags;
842 char str_old_flags[] = "[.... . ]";
843
844 sprintf(str_old_flags, "[%c%c%c%s%s]",
845 (old_flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES) ? 'U' : '.',
846 (old_flags & BATADV_MCAST_WANT_ALL_IPV4) ? '4' : '.',
847 (old_flags & BATADV_MCAST_WANT_ALL_IPV6) ? '6' : '.',
848 !(old_flags & BATADV_MCAST_WANT_NO_RTR4) ? "R4" : ". ",
849 !(old_flags & BATADV_MCAST_WANT_NO_RTR6) ? "R6" : ". ");
850
851 batadv_dbg(BATADV_DBG_MCAST, bat_priv,
852 "Changing multicast flags from '%s' to '[%c%c%c%s%s]'\n",
853 old_enabled ? str_old_flags : "<undefined>",
854 (flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES) ? 'U' : '.',
855 (flags & BATADV_MCAST_WANT_ALL_IPV4) ? '4' : '.',
856 (flags & BATADV_MCAST_WANT_ALL_IPV6) ? '6' : '.',
857 !(flags & BATADV_MCAST_WANT_NO_RTR4) ? "R4" : ". ",
858 !(flags & BATADV_MCAST_WANT_NO_RTR6) ? "R6" : ". ");
859 }
860
861
862
863
864
865
866
867
868
869 static void
870 batadv_mcast_mla_flags_update(struct batadv_priv *bat_priv,
871 struct batadv_mcast_mla_flags *flags)
872 {
873 struct batadv_tvlv_mcast_data mcast_data;
874
875 if (!memcmp(flags, &bat_priv->mcast.mla_flags, sizeof(*flags)))
876 return;
877
878 batadv_mcast_bridge_log(bat_priv, flags);
879 batadv_mcast_flags_log(bat_priv, flags->tvlv_flags);
880
881 mcast_data.flags = flags->tvlv_flags;
882 memset(mcast_data.reserved, 0, sizeof(mcast_data.reserved));
883
884 batadv_tvlv_container_register(bat_priv, BATADV_TVLV_MCAST, 2,
885 &mcast_data, sizeof(mcast_data));
886
887 bat_priv->mcast.mla_flags = *flags;
888 }
889
890
891
892
893
894
895
896
897
898
899
900
901
902 static void __batadv_mcast_mla_update(struct batadv_priv *bat_priv)
903 {
904 struct net_device *soft_iface = bat_priv->soft_iface;
905 struct hlist_head mcast_list = HLIST_HEAD_INIT;
906 struct batadv_mcast_mla_flags flags;
907 int ret;
908
909 flags = batadv_mcast_mla_flags_get(bat_priv);
910
911 ret = batadv_mcast_mla_softif_get(soft_iface, &mcast_list, &flags);
912 if (ret < 0)
913 goto out;
914
915 ret = batadv_mcast_mla_bridge_get(soft_iface, &mcast_list, &flags);
916 if (ret < 0)
917 goto out;
918
919 spin_lock(&bat_priv->mcast.mla_lock);
920 batadv_mcast_mla_tt_retract(bat_priv, &mcast_list);
921 batadv_mcast_mla_tt_add(bat_priv, &mcast_list);
922 batadv_mcast_mla_flags_update(bat_priv, &flags);
923 spin_unlock(&bat_priv->mcast.mla_lock);
924
925 out:
926 batadv_mcast_mla_list_free(&mcast_list);
927 }
928
929
930
931
932
933
934
935
936
937
938 static void batadv_mcast_mla_update(struct work_struct *work)
939 {
940 struct delayed_work *delayed_work;
941 struct batadv_priv_mcast *priv_mcast;
942 struct batadv_priv *bat_priv;
943
944 delayed_work = to_delayed_work(work);
945 priv_mcast = container_of(delayed_work, struct batadv_priv_mcast, work);
946 bat_priv = container_of(priv_mcast, struct batadv_priv, mcast);
947
948 __batadv_mcast_mla_update(bat_priv);
949 batadv_mcast_start_timer(bat_priv);
950 }
951
952
953
954
955
956
957
958
959
960
961
962 static bool batadv_mcast_is_report_ipv4(struct sk_buff *skb)
963 {
964 if (ip_mc_check_igmp(skb) < 0)
965 return false;
966
967 switch (igmp_hdr(skb)->type) {
968 case IGMP_HOST_MEMBERSHIP_REPORT:
969 case IGMPV2_HOST_MEMBERSHIP_REPORT:
970 case IGMPV3_HOST_MEMBERSHIP_REPORT:
971 return true;
972 }
973
974 return false;
975 }
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991 static int batadv_mcast_forw_mode_check_ipv4(struct batadv_priv *bat_priv,
992 struct sk_buff *skb,
993 bool *is_unsnoopable,
994 int *is_routable)
995 {
996 struct iphdr *iphdr;
997
998
999 if (!pskb_may_pull(skb, sizeof(struct ethhdr) + sizeof(*iphdr)))
1000 return -ENOMEM;
1001
1002 if (batadv_mcast_is_report_ipv4(skb))
1003 return -EINVAL;
1004
1005 iphdr = ip_hdr(skb);
1006
1007
1008
1009
1010 if (ipv4_is_local_multicast(iphdr->daddr))
1011 *is_unsnoopable = true;
1012 else
1013 *is_routable = ETH_P_IP;
1014
1015 return 0;
1016 }
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028 static bool batadv_mcast_is_report_ipv6(struct sk_buff *skb)
1029 {
1030 if (ipv6_mc_check_mld(skb) < 0)
1031 return false;
1032
1033 switch (icmp6_hdr(skb)->icmp6_type) {
1034 case ICMPV6_MGM_REPORT:
1035 case ICMPV6_MLD2_REPORT:
1036 return true;
1037 }
1038
1039 return false;
1040 }
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055 static int batadv_mcast_forw_mode_check_ipv6(struct batadv_priv *bat_priv,
1056 struct sk_buff *skb,
1057 bool *is_unsnoopable,
1058 int *is_routable)
1059 {
1060 struct ipv6hdr *ip6hdr;
1061
1062
1063 if (!pskb_may_pull(skb, sizeof(struct ethhdr) + sizeof(*ip6hdr)))
1064 return -ENOMEM;
1065
1066 if (batadv_mcast_is_report_ipv6(skb))
1067 return -EINVAL;
1068
1069 ip6hdr = ipv6_hdr(skb);
1070
1071 if (IPV6_ADDR_MC_SCOPE(&ip6hdr->daddr) < IPV6_ADDR_SCOPE_LINKLOCAL)
1072 return -EINVAL;
1073
1074
1075
1076
1077 if (ipv6_addr_is_ll_all_nodes(&ip6hdr->daddr))
1078 *is_unsnoopable = true;
1079 else if (IPV6_ADDR_MC_SCOPE(&ip6hdr->daddr) > IPV6_ADDR_SCOPE_LINKLOCAL)
1080 *is_routable = ETH_P_IPV6;
1081
1082 return 0;
1083 }
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097 static int batadv_mcast_forw_mode_check(struct batadv_priv *bat_priv,
1098 struct sk_buff *skb,
1099 bool *is_unsnoopable,
1100 int *is_routable)
1101 {
1102 struct ethhdr *ethhdr = eth_hdr(skb);
1103
1104 if (!atomic_read(&bat_priv->multicast_mode))
1105 return -EINVAL;
1106
1107 switch (ntohs(ethhdr->h_proto)) {
1108 case ETH_P_IP:
1109 return batadv_mcast_forw_mode_check_ipv4(bat_priv, skb,
1110 is_unsnoopable,
1111 is_routable);
1112 case ETH_P_IPV6:
1113 if (!IS_ENABLED(CONFIG_IPV6))
1114 return -EINVAL;
1115
1116 return batadv_mcast_forw_mode_check_ipv6(bat_priv, skb,
1117 is_unsnoopable,
1118 is_routable);
1119 default:
1120 return -EINVAL;
1121 }
1122 }
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134 static int batadv_mcast_forw_want_all_ip_count(struct batadv_priv *bat_priv,
1135 struct ethhdr *ethhdr)
1136 {
1137 switch (ntohs(ethhdr->h_proto)) {
1138 case ETH_P_IP:
1139 return atomic_read(&bat_priv->mcast.num_want_all_ipv4);
1140 case ETH_P_IPV6:
1141 return atomic_read(&bat_priv->mcast.num_want_all_ipv6);
1142 default:
1143
1144 return 0;
1145 }
1146 }
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158 static int batadv_mcast_forw_rtr_count(struct batadv_priv *bat_priv,
1159 int protocol)
1160 {
1161 switch (protocol) {
1162 case ETH_P_IP:
1163 return atomic_read(&bat_priv->mcast.num_want_all_rtr4);
1164 case ETH_P_IPV6:
1165 return atomic_read(&bat_priv->mcast.num_want_all_rtr6);
1166 default:
1167 return 0;
1168 }
1169 }
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179 static struct batadv_orig_node *
1180 batadv_mcast_forw_tt_node_get(struct batadv_priv *bat_priv,
1181 struct ethhdr *ethhdr)
1182 {
1183 return batadv_transtable_search(bat_priv, NULL, ethhdr->h_dest,
1184 BATADV_NO_FLAGS);
1185 }
1186
1187
1188
1189
1190
1191
1192
1193
1194 static struct batadv_orig_node *
1195 batadv_mcast_forw_ipv4_node_get(struct batadv_priv *bat_priv)
1196 {
1197 struct batadv_orig_node *tmp_orig_node, *orig_node = NULL;
1198
1199 rcu_read_lock();
1200 hlist_for_each_entry_rcu(tmp_orig_node,
1201 &bat_priv->mcast.want_all_ipv4_list,
1202 mcast_want_all_ipv4_node) {
1203 if (!kref_get_unless_zero(&tmp_orig_node->refcount))
1204 continue;
1205
1206 orig_node = tmp_orig_node;
1207 break;
1208 }
1209 rcu_read_unlock();
1210
1211 return orig_node;
1212 }
1213
1214
1215
1216
1217
1218
1219
1220
1221 static struct batadv_orig_node *
1222 batadv_mcast_forw_ipv6_node_get(struct batadv_priv *bat_priv)
1223 {
1224 struct batadv_orig_node *tmp_orig_node, *orig_node = NULL;
1225
1226 rcu_read_lock();
1227 hlist_for_each_entry_rcu(tmp_orig_node,
1228 &bat_priv->mcast.want_all_ipv6_list,
1229 mcast_want_all_ipv6_node) {
1230 if (!kref_get_unless_zero(&tmp_orig_node->refcount))
1231 continue;
1232
1233 orig_node = tmp_orig_node;
1234 break;
1235 }
1236 rcu_read_unlock();
1237
1238 return orig_node;
1239 }
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250 static struct batadv_orig_node *
1251 batadv_mcast_forw_ip_node_get(struct batadv_priv *bat_priv,
1252 struct ethhdr *ethhdr)
1253 {
1254 switch (ntohs(ethhdr->h_proto)) {
1255 case ETH_P_IP:
1256 return batadv_mcast_forw_ipv4_node_get(bat_priv);
1257 case ETH_P_IPV6:
1258 return batadv_mcast_forw_ipv6_node_get(bat_priv);
1259 default:
1260
1261 return NULL;
1262 }
1263 }
1264
1265
1266
1267
1268
1269
1270
1271
1272 static struct batadv_orig_node *
1273 batadv_mcast_forw_unsnoop_node_get(struct batadv_priv *bat_priv)
1274 {
1275 struct batadv_orig_node *tmp_orig_node, *orig_node = NULL;
1276
1277 rcu_read_lock();
1278 hlist_for_each_entry_rcu(tmp_orig_node,
1279 &bat_priv->mcast.want_all_unsnoopables_list,
1280 mcast_want_all_unsnoopables_node) {
1281 if (!kref_get_unless_zero(&tmp_orig_node->refcount))
1282 continue;
1283
1284 orig_node = tmp_orig_node;
1285 break;
1286 }
1287 rcu_read_unlock();
1288
1289 return orig_node;
1290 }
1291
1292
1293
1294
1295
1296
1297
1298
1299 static struct batadv_orig_node *
1300 batadv_mcast_forw_rtr4_node_get(struct batadv_priv *bat_priv)
1301 {
1302 struct batadv_orig_node *tmp_orig_node, *orig_node = NULL;
1303
1304 rcu_read_lock();
1305 hlist_for_each_entry_rcu(tmp_orig_node,
1306 &bat_priv->mcast.want_all_rtr4_list,
1307 mcast_want_all_rtr4_node) {
1308 if (!kref_get_unless_zero(&tmp_orig_node->refcount))
1309 continue;
1310
1311 orig_node = tmp_orig_node;
1312 break;
1313 }
1314 rcu_read_unlock();
1315
1316 return orig_node;
1317 }
1318
1319
1320
1321
1322
1323
1324
1325
1326 static struct batadv_orig_node *
1327 batadv_mcast_forw_rtr6_node_get(struct batadv_priv *bat_priv)
1328 {
1329 struct batadv_orig_node *tmp_orig_node, *orig_node = NULL;
1330
1331 rcu_read_lock();
1332 hlist_for_each_entry_rcu(tmp_orig_node,
1333 &bat_priv->mcast.want_all_rtr6_list,
1334 mcast_want_all_rtr6_node) {
1335 if (!kref_get_unless_zero(&tmp_orig_node->refcount))
1336 continue;
1337
1338 orig_node = tmp_orig_node;
1339 break;
1340 }
1341 rcu_read_unlock();
1342
1343 return orig_node;
1344 }
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355 static struct batadv_orig_node *
1356 batadv_mcast_forw_rtr_node_get(struct batadv_priv *bat_priv,
1357 struct ethhdr *ethhdr)
1358 {
1359 switch (ntohs(ethhdr->h_proto)) {
1360 case ETH_P_IP:
1361 return batadv_mcast_forw_rtr4_node_get(bat_priv);
1362 case ETH_P_IPV6:
1363 return batadv_mcast_forw_rtr6_node_get(bat_priv);
1364 default:
1365
1366 return NULL;
1367 }
1368 }
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380 enum batadv_forw_mode
1381 batadv_mcast_forw_mode(struct batadv_priv *bat_priv, struct sk_buff *skb,
1382 struct batadv_orig_node **orig)
1383 {
1384 int ret, tt_count, ip_count, unsnoop_count, total_count;
1385 bool is_unsnoopable = false;
1386 unsigned int mcast_fanout;
1387 struct ethhdr *ethhdr;
1388 int is_routable = 0;
1389 int rtr_count = 0;
1390
1391 ret = batadv_mcast_forw_mode_check(bat_priv, skb, &is_unsnoopable,
1392 &is_routable);
1393 if (ret == -ENOMEM)
1394 return BATADV_FORW_NONE;
1395 else if (ret < 0)
1396 return BATADV_FORW_ALL;
1397
1398 ethhdr = eth_hdr(skb);
1399
1400 tt_count = batadv_tt_global_hash_count(bat_priv, ethhdr->h_dest,
1401 BATADV_NO_FLAGS);
1402 ip_count = batadv_mcast_forw_want_all_ip_count(bat_priv, ethhdr);
1403 unsnoop_count = !is_unsnoopable ? 0 :
1404 atomic_read(&bat_priv->mcast.num_want_all_unsnoopables);
1405 rtr_count = batadv_mcast_forw_rtr_count(bat_priv, is_routable);
1406
1407 total_count = tt_count + ip_count + unsnoop_count + rtr_count;
1408
1409 switch (total_count) {
1410 case 1:
1411 if (tt_count)
1412 *orig = batadv_mcast_forw_tt_node_get(bat_priv, ethhdr);
1413 else if (ip_count)
1414 *orig = batadv_mcast_forw_ip_node_get(bat_priv, ethhdr);
1415 else if (unsnoop_count)
1416 *orig = batadv_mcast_forw_unsnoop_node_get(bat_priv);
1417 else if (rtr_count)
1418 *orig = batadv_mcast_forw_rtr_node_get(bat_priv,
1419 ethhdr);
1420
1421 if (*orig)
1422 return BATADV_FORW_SINGLE;
1423
1424
1425 case 0:
1426 return BATADV_FORW_NONE;
1427 default:
1428 mcast_fanout = atomic_read(&bat_priv->multicast_fanout);
1429
1430 if (!unsnoop_count && total_count <= mcast_fanout)
1431 return BATADV_FORW_SOME;
1432 }
1433
1434 return BATADV_FORW_ALL;
1435 }
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450 static int
1451 batadv_mcast_forw_tt(struct batadv_priv *bat_priv, struct sk_buff *skb,
1452 unsigned short vid)
1453 {
1454 int ret = NET_XMIT_SUCCESS;
1455 struct sk_buff *newskb;
1456
1457 struct batadv_tt_orig_list_entry *orig_entry;
1458
1459 struct batadv_tt_global_entry *tt_global;
1460 const u8 *addr = eth_hdr(skb)->h_dest;
1461
1462 tt_global = batadv_tt_global_hash_find(bat_priv, addr, vid);
1463 if (!tt_global)
1464 goto out;
1465
1466 rcu_read_lock();
1467 hlist_for_each_entry_rcu(orig_entry, &tt_global->orig_list, list) {
1468 newskb = skb_copy(skb, GFP_ATOMIC);
1469 if (!newskb) {
1470 ret = NET_XMIT_DROP;
1471 break;
1472 }
1473
1474 batadv_send_skb_unicast(bat_priv, newskb, BATADV_UNICAST, 0,
1475 orig_entry->orig_node, vid);
1476 }
1477 rcu_read_unlock();
1478
1479 batadv_tt_global_entry_put(tt_global);
1480
1481 out:
1482 return ret;
1483 }
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498 static int
1499 batadv_mcast_forw_want_all_ipv4(struct batadv_priv *bat_priv,
1500 struct sk_buff *skb, unsigned short vid)
1501 {
1502 struct batadv_orig_node *orig_node;
1503 int ret = NET_XMIT_SUCCESS;
1504 struct sk_buff *newskb;
1505
1506 rcu_read_lock();
1507 hlist_for_each_entry_rcu(orig_node,
1508 &bat_priv->mcast.want_all_ipv4_list,
1509 mcast_want_all_ipv4_node) {
1510 newskb = skb_copy(skb, GFP_ATOMIC);
1511 if (!newskb) {
1512 ret = NET_XMIT_DROP;
1513 break;
1514 }
1515
1516 batadv_send_skb_unicast(bat_priv, newskb, BATADV_UNICAST, 0,
1517 orig_node, vid);
1518 }
1519 rcu_read_unlock();
1520 return ret;
1521 }
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536 static int
1537 batadv_mcast_forw_want_all_ipv6(struct batadv_priv *bat_priv,
1538 struct sk_buff *skb, unsigned short vid)
1539 {
1540 struct batadv_orig_node *orig_node;
1541 int ret = NET_XMIT_SUCCESS;
1542 struct sk_buff *newskb;
1543
1544 rcu_read_lock();
1545 hlist_for_each_entry_rcu(orig_node,
1546 &bat_priv->mcast.want_all_ipv6_list,
1547 mcast_want_all_ipv6_node) {
1548 newskb = skb_copy(skb, GFP_ATOMIC);
1549 if (!newskb) {
1550 ret = NET_XMIT_DROP;
1551 break;
1552 }
1553
1554 batadv_send_skb_unicast(bat_priv, newskb, BATADV_UNICAST, 0,
1555 orig_node, vid);
1556 }
1557 rcu_read_unlock();
1558 return ret;
1559 }
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575 static int
1576 batadv_mcast_forw_want_all(struct batadv_priv *bat_priv,
1577 struct sk_buff *skb, unsigned short vid)
1578 {
1579 switch (ntohs(eth_hdr(skb)->h_proto)) {
1580 case ETH_P_IP:
1581 return batadv_mcast_forw_want_all_ipv4(bat_priv, skb, vid);
1582 case ETH_P_IPV6:
1583 return batadv_mcast_forw_want_all_ipv6(bat_priv, skb, vid);
1584 default:
1585
1586 return NET_XMIT_DROP;
1587 }
1588 }
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603 static int
1604 batadv_mcast_forw_want_all_rtr4(struct batadv_priv *bat_priv,
1605 struct sk_buff *skb, unsigned short vid)
1606 {
1607 struct batadv_orig_node *orig_node;
1608 int ret = NET_XMIT_SUCCESS;
1609 struct sk_buff *newskb;
1610
1611 rcu_read_lock();
1612 hlist_for_each_entry_rcu(orig_node,
1613 &bat_priv->mcast.want_all_rtr4_list,
1614 mcast_want_all_rtr4_node) {
1615 newskb = skb_copy(skb, GFP_ATOMIC);
1616 if (!newskb) {
1617 ret = NET_XMIT_DROP;
1618 break;
1619 }
1620
1621 batadv_send_skb_unicast(bat_priv, newskb, BATADV_UNICAST, 0,
1622 orig_node, vid);
1623 }
1624 rcu_read_unlock();
1625 return ret;
1626 }
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641 static int
1642 batadv_mcast_forw_want_all_rtr6(struct batadv_priv *bat_priv,
1643 struct sk_buff *skb, unsigned short vid)
1644 {
1645 struct batadv_orig_node *orig_node;
1646 int ret = NET_XMIT_SUCCESS;
1647 struct sk_buff *newskb;
1648
1649 rcu_read_lock();
1650 hlist_for_each_entry_rcu(orig_node,
1651 &bat_priv->mcast.want_all_rtr6_list,
1652 mcast_want_all_rtr6_node) {
1653 newskb = skb_copy(skb, GFP_ATOMIC);
1654 if (!newskb) {
1655 ret = NET_XMIT_DROP;
1656 break;
1657 }
1658
1659 batadv_send_skb_unicast(bat_priv, newskb, BATADV_UNICAST, 0,
1660 orig_node, vid);
1661 }
1662 rcu_read_unlock();
1663 return ret;
1664 }
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680 static int
1681 batadv_mcast_forw_want_rtr(struct batadv_priv *bat_priv,
1682 struct sk_buff *skb, unsigned short vid)
1683 {
1684 switch (ntohs(eth_hdr(skb)->h_proto)) {
1685 case ETH_P_IP:
1686 return batadv_mcast_forw_want_all_rtr4(bat_priv, skb, vid);
1687 case ETH_P_IPV6:
1688 return batadv_mcast_forw_want_all_rtr6(bat_priv, skb, vid);
1689 default:
1690
1691 return NET_XMIT_DROP;
1692 }
1693 }
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711 int batadv_mcast_forw_send(struct batadv_priv *bat_priv, struct sk_buff *skb,
1712 unsigned short vid)
1713 {
1714 int ret;
1715
1716 ret = batadv_mcast_forw_tt(bat_priv, skb, vid);
1717 if (ret != NET_XMIT_SUCCESS) {
1718 kfree_skb(skb);
1719 return ret;
1720 }
1721
1722 ret = batadv_mcast_forw_want_all(bat_priv, skb, vid);
1723 if (ret != NET_XMIT_SUCCESS) {
1724 kfree_skb(skb);
1725 return ret;
1726 }
1727
1728 ret = batadv_mcast_forw_want_rtr(bat_priv, skb, vid);
1729 if (ret != NET_XMIT_SUCCESS) {
1730 kfree_skb(skb);
1731 return ret;
1732 }
1733
1734 consume_skb(skb);
1735 return ret;
1736 }
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749 static void batadv_mcast_want_unsnoop_update(struct batadv_priv *bat_priv,
1750 struct batadv_orig_node *orig,
1751 u8 mcast_flags)
1752 {
1753 struct hlist_node *node = &orig->mcast_want_all_unsnoopables_node;
1754 struct hlist_head *head = &bat_priv->mcast.want_all_unsnoopables_list;
1755
1756 lockdep_assert_held(&orig->mcast_handler_lock);
1757
1758
1759 if (mcast_flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES &&
1760 !(orig->mcast_flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES)) {
1761 atomic_inc(&bat_priv->mcast.num_want_all_unsnoopables);
1762
1763 spin_lock_bh(&bat_priv->mcast.want_lists_lock);
1764
1765 WARN_ON(!hlist_unhashed(node));
1766
1767 hlist_add_head_rcu(node, head);
1768 spin_unlock_bh(&bat_priv->mcast.want_lists_lock);
1769
1770 } else if (!(mcast_flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES) &&
1771 orig->mcast_flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES) {
1772 atomic_dec(&bat_priv->mcast.num_want_all_unsnoopables);
1773
1774 spin_lock_bh(&bat_priv->mcast.want_lists_lock);
1775
1776 WARN_ON(hlist_unhashed(node));
1777
1778 hlist_del_init_rcu(node);
1779 spin_unlock_bh(&bat_priv->mcast.want_lists_lock);
1780 }
1781 }
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794 static void batadv_mcast_want_ipv4_update(struct batadv_priv *bat_priv,
1795 struct batadv_orig_node *orig,
1796 u8 mcast_flags)
1797 {
1798 struct hlist_node *node = &orig->mcast_want_all_ipv4_node;
1799 struct hlist_head *head = &bat_priv->mcast.want_all_ipv4_list;
1800
1801 lockdep_assert_held(&orig->mcast_handler_lock);
1802
1803
1804 if (mcast_flags & BATADV_MCAST_WANT_ALL_IPV4 &&
1805 !(orig->mcast_flags & BATADV_MCAST_WANT_ALL_IPV4)) {
1806 atomic_inc(&bat_priv->mcast.num_want_all_ipv4);
1807
1808 spin_lock_bh(&bat_priv->mcast.want_lists_lock);
1809
1810 WARN_ON(!hlist_unhashed(node));
1811
1812 hlist_add_head_rcu(node, head);
1813 spin_unlock_bh(&bat_priv->mcast.want_lists_lock);
1814
1815 } else if (!(mcast_flags & BATADV_MCAST_WANT_ALL_IPV4) &&
1816 orig->mcast_flags & BATADV_MCAST_WANT_ALL_IPV4) {
1817 atomic_dec(&bat_priv->mcast.num_want_all_ipv4);
1818
1819 spin_lock_bh(&bat_priv->mcast.want_lists_lock);
1820
1821 WARN_ON(hlist_unhashed(node));
1822
1823 hlist_del_init_rcu(node);
1824 spin_unlock_bh(&bat_priv->mcast.want_lists_lock);
1825 }
1826 }
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839 static void batadv_mcast_want_ipv6_update(struct batadv_priv *bat_priv,
1840 struct batadv_orig_node *orig,
1841 u8 mcast_flags)
1842 {
1843 struct hlist_node *node = &orig->mcast_want_all_ipv6_node;
1844 struct hlist_head *head = &bat_priv->mcast.want_all_ipv6_list;
1845
1846 lockdep_assert_held(&orig->mcast_handler_lock);
1847
1848
1849 if (mcast_flags & BATADV_MCAST_WANT_ALL_IPV6 &&
1850 !(orig->mcast_flags & BATADV_MCAST_WANT_ALL_IPV6)) {
1851 atomic_inc(&bat_priv->mcast.num_want_all_ipv6);
1852
1853 spin_lock_bh(&bat_priv->mcast.want_lists_lock);
1854
1855 WARN_ON(!hlist_unhashed(node));
1856
1857 hlist_add_head_rcu(node, head);
1858 spin_unlock_bh(&bat_priv->mcast.want_lists_lock);
1859
1860 } else if (!(mcast_flags & BATADV_MCAST_WANT_ALL_IPV6) &&
1861 orig->mcast_flags & BATADV_MCAST_WANT_ALL_IPV6) {
1862 atomic_dec(&bat_priv->mcast.num_want_all_ipv6);
1863
1864 spin_lock_bh(&bat_priv->mcast.want_lists_lock);
1865
1866 WARN_ON(hlist_unhashed(node));
1867
1868 hlist_del_init_rcu(node);
1869 spin_unlock_bh(&bat_priv->mcast.want_lists_lock);
1870 }
1871 }
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884 static void batadv_mcast_want_rtr4_update(struct batadv_priv *bat_priv,
1885 struct batadv_orig_node *orig,
1886 u8 mcast_flags)
1887 {
1888 struct hlist_node *node = &orig->mcast_want_all_rtr4_node;
1889 struct hlist_head *head = &bat_priv->mcast.want_all_rtr4_list;
1890
1891 lockdep_assert_held(&orig->mcast_handler_lock);
1892
1893
1894 if (!(mcast_flags & BATADV_MCAST_WANT_NO_RTR4) &&
1895 orig->mcast_flags & BATADV_MCAST_WANT_NO_RTR4) {
1896 atomic_inc(&bat_priv->mcast.num_want_all_rtr4);
1897
1898 spin_lock_bh(&bat_priv->mcast.want_lists_lock);
1899
1900 WARN_ON(!hlist_unhashed(node));
1901
1902 hlist_add_head_rcu(node, head);
1903 spin_unlock_bh(&bat_priv->mcast.want_lists_lock);
1904
1905 } else if (mcast_flags & BATADV_MCAST_WANT_NO_RTR4 &&
1906 !(orig->mcast_flags & BATADV_MCAST_WANT_NO_RTR4)) {
1907 atomic_dec(&bat_priv->mcast.num_want_all_rtr4);
1908
1909 spin_lock_bh(&bat_priv->mcast.want_lists_lock);
1910
1911 WARN_ON(hlist_unhashed(node));
1912
1913 hlist_del_init_rcu(node);
1914 spin_unlock_bh(&bat_priv->mcast.want_lists_lock);
1915 }
1916 }
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929 static void batadv_mcast_want_rtr6_update(struct batadv_priv *bat_priv,
1930 struct batadv_orig_node *orig,
1931 u8 mcast_flags)
1932 {
1933 struct hlist_node *node = &orig->mcast_want_all_rtr6_node;
1934 struct hlist_head *head = &bat_priv->mcast.want_all_rtr6_list;
1935
1936 lockdep_assert_held(&orig->mcast_handler_lock);
1937
1938
1939 if (!(mcast_flags & BATADV_MCAST_WANT_NO_RTR6) &&
1940 orig->mcast_flags & BATADV_MCAST_WANT_NO_RTR6) {
1941 atomic_inc(&bat_priv->mcast.num_want_all_rtr6);
1942
1943 spin_lock_bh(&bat_priv->mcast.want_lists_lock);
1944
1945 WARN_ON(!hlist_unhashed(node));
1946
1947 hlist_add_head_rcu(node, head);
1948 spin_unlock_bh(&bat_priv->mcast.want_lists_lock);
1949
1950 } else if (mcast_flags & BATADV_MCAST_WANT_NO_RTR6 &&
1951 !(orig->mcast_flags & BATADV_MCAST_WANT_NO_RTR6)) {
1952 atomic_dec(&bat_priv->mcast.num_want_all_rtr6);
1953
1954 spin_lock_bh(&bat_priv->mcast.want_lists_lock);
1955
1956 WARN_ON(hlist_unhashed(node));
1957
1958 hlist_del_init_rcu(node);
1959 spin_unlock_bh(&bat_priv->mcast.want_lists_lock);
1960 }
1961 }
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971 static u8
1972 batadv_mcast_tvlv_flags_get(bool enabled, void *tvlv_value, u16 tvlv_value_len)
1973 {
1974 u8 mcast_flags = BATADV_NO_FLAGS;
1975
1976 if (enabled && tvlv_value && tvlv_value_len >= sizeof(mcast_flags))
1977 mcast_flags = *(u8 *)tvlv_value;
1978
1979 if (!enabled) {
1980 mcast_flags |= BATADV_MCAST_WANT_ALL_IPV4;
1981 mcast_flags |= BATADV_MCAST_WANT_ALL_IPV6;
1982 }
1983
1984
1985 if (mcast_flags & BATADV_MCAST_WANT_ALL_IPV4)
1986 mcast_flags |= BATADV_MCAST_WANT_NO_RTR4;
1987
1988 if (mcast_flags & BATADV_MCAST_WANT_ALL_IPV6)
1989 mcast_flags |= BATADV_MCAST_WANT_NO_RTR6;
1990
1991 return mcast_flags;
1992 }
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002 static void batadv_mcast_tvlv_ogm_handler(struct batadv_priv *bat_priv,
2003 struct batadv_orig_node *orig,
2004 u8 flags,
2005 void *tvlv_value,
2006 u16 tvlv_value_len)
2007 {
2008 bool orig_mcast_enabled = !(flags & BATADV_TVLV_HANDLER_OGM_CIFNOTFND);
2009 u8 mcast_flags;
2010
2011 mcast_flags = batadv_mcast_tvlv_flags_get(orig_mcast_enabled,
2012 tvlv_value, tvlv_value_len);
2013
2014 spin_lock_bh(&orig->mcast_handler_lock);
2015
2016 if (orig_mcast_enabled &&
2017 !test_bit(BATADV_ORIG_CAPA_HAS_MCAST, &orig->capabilities)) {
2018 set_bit(BATADV_ORIG_CAPA_HAS_MCAST, &orig->capabilities);
2019 } else if (!orig_mcast_enabled &&
2020 test_bit(BATADV_ORIG_CAPA_HAS_MCAST, &orig->capabilities)) {
2021 clear_bit(BATADV_ORIG_CAPA_HAS_MCAST, &orig->capabilities);
2022 }
2023
2024 set_bit(BATADV_ORIG_CAPA_HAS_MCAST, &orig->capa_initialized);
2025
2026 batadv_mcast_want_unsnoop_update(bat_priv, orig, mcast_flags);
2027 batadv_mcast_want_ipv4_update(bat_priv, orig, mcast_flags);
2028 batadv_mcast_want_ipv6_update(bat_priv, orig, mcast_flags);
2029 batadv_mcast_want_rtr4_update(bat_priv, orig, mcast_flags);
2030 batadv_mcast_want_rtr6_update(bat_priv, orig, mcast_flags);
2031
2032 orig->mcast_flags = mcast_flags;
2033 spin_unlock_bh(&orig->mcast_handler_lock);
2034 }
2035
2036
2037
2038
2039
2040 void batadv_mcast_init(struct batadv_priv *bat_priv)
2041 {
2042 batadv_tvlv_handler_register(bat_priv, batadv_mcast_tvlv_ogm_handler,
2043 NULL, BATADV_TVLV_MCAST, 2,
2044 BATADV_TVLV_HANDLER_OGM_CIFNOTFND);
2045
2046 INIT_DELAYED_WORK(&bat_priv->mcast.work, batadv_mcast_mla_update);
2047 batadv_mcast_start_timer(bat_priv);
2048 }
2049
2050 #ifdef CONFIG_BATMAN_ADV_DEBUGFS
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060 static void batadv_mcast_flags_print_header(struct batadv_priv *bat_priv,
2061 struct seq_file *seq)
2062 {
2063 struct batadv_mcast_mla_flags *mla_flags = &bat_priv->mcast.mla_flags;
2064 char querier4, querier6, shadowing4, shadowing6;
2065 bool bridged = mla_flags->bridged;
2066 u8 flags = mla_flags->tvlv_flags;
2067
2068 if (bridged) {
2069 querier4 = mla_flags->querier_ipv4.exists ? '.' : '4';
2070 querier6 = mla_flags->querier_ipv6.exists ? '.' : '6';
2071 shadowing4 = mla_flags->querier_ipv4.shadowing ? '4' : '.';
2072 shadowing6 = mla_flags->querier_ipv6.shadowing ? '6' : '.';
2073 } else {
2074 querier4 = '?';
2075 querier6 = '?';
2076 shadowing4 = '?';
2077 shadowing6 = '?';
2078 }
2079
2080 seq_printf(seq, "Multicast flags (own flags: [%c%c%c%s%s])\n",
2081 (flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES) ? 'U' : '.',
2082 (flags & BATADV_MCAST_WANT_ALL_IPV4) ? '4' : '.',
2083 (flags & BATADV_MCAST_WANT_ALL_IPV6) ? '6' : '.',
2084 !(flags & BATADV_MCAST_WANT_NO_RTR4) ? "R4" : ". ",
2085 !(flags & BATADV_MCAST_WANT_NO_RTR6) ? "R6" : ". ");
2086 seq_printf(seq, "* Bridged [U]\t\t\t\t%c\n", bridged ? 'U' : '.');
2087 seq_printf(seq, "* No IGMP/MLD Querier [4/6]:\t\t%c/%c\n",
2088 querier4, querier6);
2089 seq_printf(seq, "* Shadowing IGMP/MLD Querier [4/6]:\t%c/%c\n",
2090 shadowing4, shadowing6);
2091 seq_puts(seq, "-------------------------------------------\n");
2092 seq_printf(seq, " %-10s %s\n", "Originator", "Flags");
2093 }
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105 int batadv_mcast_flags_seq_print_text(struct seq_file *seq, void *offset)
2106 {
2107 struct net_device *net_dev = (struct net_device *)seq->private;
2108 struct batadv_priv *bat_priv = netdev_priv(net_dev);
2109 struct batadv_hard_iface *primary_if;
2110 struct batadv_hashtable *hash = bat_priv->orig_hash;
2111 struct batadv_orig_node *orig_node;
2112 struct hlist_head *head;
2113 u8 flags;
2114 u32 i;
2115
2116 primary_if = batadv_seq_print_text_primary_if_get(seq);
2117 if (!primary_if)
2118 return 0;
2119
2120 batadv_mcast_flags_print_header(bat_priv, seq);
2121
2122 for (i = 0; i < hash->size; i++) {
2123 head = &hash->table[i];
2124
2125 rcu_read_lock();
2126 hlist_for_each_entry_rcu(orig_node, head, hash_entry) {
2127 if (!test_bit(BATADV_ORIG_CAPA_HAS_MCAST,
2128 &orig_node->capa_initialized))
2129 continue;
2130
2131 if (!test_bit(BATADV_ORIG_CAPA_HAS_MCAST,
2132 &orig_node->capabilities)) {
2133 seq_printf(seq, "%pM -\n", orig_node->orig);
2134 continue;
2135 }
2136
2137 flags = orig_node->mcast_flags;
2138
2139 seq_printf(seq, "%pM [%c%c%c%s%s]\n", orig_node->orig,
2140 (flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES)
2141 ? 'U' : '.',
2142 (flags & BATADV_MCAST_WANT_ALL_IPV4)
2143 ? '4' : '.',
2144 (flags & BATADV_MCAST_WANT_ALL_IPV6)
2145 ? '6' : '.',
2146 !(flags & BATADV_MCAST_WANT_NO_RTR4)
2147 ? "R4" : ". ",
2148 !(flags & BATADV_MCAST_WANT_NO_RTR6)
2149 ? "R6" : ". ");
2150 }
2151 rcu_read_unlock();
2152 }
2153
2154 batadv_hardif_put(primary_if);
2155
2156 return 0;
2157 }
2158 #endif
2159
2160
2161
2162
2163
2164
2165
2166
2167 int batadv_mcast_mesh_info_put(struct sk_buff *msg,
2168 struct batadv_priv *bat_priv)
2169 {
2170 u32 flags = bat_priv->mcast.mla_flags.tvlv_flags;
2171 u32 flags_priv = BATADV_NO_FLAGS;
2172
2173 if (bat_priv->mcast.mla_flags.bridged) {
2174 flags_priv |= BATADV_MCAST_FLAGS_BRIDGED;
2175
2176 if (bat_priv->mcast.mla_flags.querier_ipv4.exists)
2177 flags_priv |= BATADV_MCAST_FLAGS_QUERIER_IPV4_EXISTS;
2178 if (bat_priv->mcast.mla_flags.querier_ipv6.exists)
2179 flags_priv |= BATADV_MCAST_FLAGS_QUERIER_IPV6_EXISTS;
2180 if (bat_priv->mcast.mla_flags.querier_ipv4.shadowing)
2181 flags_priv |= BATADV_MCAST_FLAGS_QUERIER_IPV4_SHADOWING;
2182 if (bat_priv->mcast.mla_flags.querier_ipv6.shadowing)
2183 flags_priv |= BATADV_MCAST_FLAGS_QUERIER_IPV6_SHADOWING;
2184 }
2185
2186 if (nla_put_u32(msg, BATADV_ATTR_MCAST_FLAGS, flags) ||
2187 nla_put_u32(msg, BATADV_ATTR_MCAST_FLAGS_PRIV, flags_priv))
2188 return -EMSGSIZE;
2189
2190 return 0;
2191 }
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203 static int
2204 batadv_mcast_flags_dump_entry(struct sk_buff *msg, u32 portid,
2205 struct netlink_callback *cb,
2206 struct batadv_orig_node *orig_node)
2207 {
2208 void *hdr;
2209
2210 hdr = genlmsg_put(msg, portid, cb->nlh->nlmsg_seq,
2211 &batadv_netlink_family, NLM_F_MULTI,
2212 BATADV_CMD_GET_MCAST_FLAGS);
2213 if (!hdr)
2214 return -ENOBUFS;
2215
2216 genl_dump_check_consistent(cb, hdr);
2217
2218 if (nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN,
2219 orig_node->orig)) {
2220 genlmsg_cancel(msg, hdr);
2221 return -EMSGSIZE;
2222 }
2223
2224 if (test_bit(BATADV_ORIG_CAPA_HAS_MCAST,
2225 &orig_node->capabilities)) {
2226 if (nla_put_u32(msg, BATADV_ATTR_MCAST_FLAGS,
2227 orig_node->mcast_flags)) {
2228 genlmsg_cancel(msg, hdr);
2229 return -EMSGSIZE;
2230 }
2231 }
2232
2233 genlmsg_end(msg, hdr);
2234 return 0;
2235 }
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249 static int
2250 batadv_mcast_flags_dump_bucket(struct sk_buff *msg, u32 portid,
2251 struct netlink_callback *cb,
2252 struct batadv_hashtable *hash,
2253 unsigned int bucket, long *idx_skip)
2254 {
2255 struct batadv_orig_node *orig_node;
2256 long idx = 0;
2257
2258 spin_lock_bh(&hash->list_locks[bucket]);
2259 cb->seq = atomic_read(&hash->generation) << 1 | 1;
2260
2261 hlist_for_each_entry(orig_node, &hash->table[bucket], hash_entry) {
2262 if (!test_bit(BATADV_ORIG_CAPA_HAS_MCAST,
2263 &orig_node->capa_initialized))
2264 continue;
2265
2266 if (idx < *idx_skip)
2267 goto skip;
2268
2269 if (batadv_mcast_flags_dump_entry(msg, portid, cb, orig_node)) {
2270 spin_unlock_bh(&hash->list_locks[bucket]);
2271 *idx_skip = idx;
2272
2273 return -EMSGSIZE;
2274 }
2275
2276 skip:
2277 idx++;
2278 }
2279 spin_unlock_bh(&hash->list_locks[bucket]);
2280
2281 return 0;
2282 }
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295 static int
2296 __batadv_mcast_flags_dump(struct sk_buff *msg, u32 portid,
2297 struct netlink_callback *cb,
2298 struct batadv_priv *bat_priv, long *bucket, long *idx)
2299 {
2300 struct batadv_hashtable *hash = bat_priv->orig_hash;
2301 long bucket_tmp = *bucket;
2302 long idx_tmp = *idx;
2303
2304 while (bucket_tmp < hash->size) {
2305 if (batadv_mcast_flags_dump_bucket(msg, portid, cb, hash,
2306 bucket_tmp, &idx_tmp))
2307 break;
2308
2309 bucket_tmp++;
2310 idx_tmp = 0;
2311 }
2312
2313 *bucket = bucket_tmp;
2314 *idx = idx_tmp;
2315
2316 return msg->len;
2317 }
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327 static int
2328 batadv_mcast_netlink_get_primary(struct netlink_callback *cb,
2329 struct batadv_hard_iface **primary_if)
2330 {
2331 struct batadv_hard_iface *hard_iface = NULL;
2332 struct net *net = sock_net(cb->skb->sk);
2333 struct net_device *soft_iface;
2334 struct batadv_priv *bat_priv;
2335 int ifindex;
2336 int ret = 0;
2337
2338 ifindex = batadv_netlink_get_ifindex(cb->nlh, BATADV_ATTR_MESH_IFINDEX);
2339 if (!ifindex)
2340 return -EINVAL;
2341
2342 soft_iface = dev_get_by_index(net, ifindex);
2343 if (!soft_iface || !batadv_softif_is_valid(soft_iface)) {
2344 ret = -ENODEV;
2345 goto out;
2346 }
2347
2348 bat_priv = netdev_priv(soft_iface);
2349
2350 hard_iface = batadv_primary_if_get_selected(bat_priv);
2351 if (!hard_iface || hard_iface->if_status != BATADV_IF_ACTIVE) {
2352 ret = -ENOENT;
2353 goto out;
2354 }
2355
2356 out:
2357 if (soft_iface)
2358 dev_put(soft_iface);
2359
2360 if (!ret && primary_if)
2361 *primary_if = hard_iface;
2362 else if (hard_iface)
2363 batadv_hardif_put(hard_iface);
2364
2365 return ret;
2366 }
2367
2368
2369
2370
2371
2372
2373
2374
2375 int batadv_mcast_flags_dump(struct sk_buff *msg, struct netlink_callback *cb)
2376 {
2377 struct batadv_hard_iface *primary_if = NULL;
2378 int portid = NETLINK_CB(cb->skb).portid;
2379 struct batadv_priv *bat_priv;
2380 long *bucket = &cb->args[0];
2381 long *idx = &cb->args[1];
2382 int ret;
2383
2384 ret = batadv_mcast_netlink_get_primary(cb, &primary_if);
2385 if (ret)
2386 return ret;
2387
2388 bat_priv = netdev_priv(primary_if->soft_iface);
2389 ret = __batadv_mcast_flags_dump(msg, portid, cb, bat_priv, bucket, idx);
2390
2391 batadv_hardif_put(primary_if);
2392 return ret;
2393 }
2394
2395
2396
2397
2398
2399 void batadv_mcast_free(struct batadv_priv *bat_priv)
2400 {
2401 cancel_delayed_work_sync(&bat_priv->mcast.work);
2402
2403 batadv_tvlv_container_unregister(bat_priv, BATADV_TVLV_MCAST, 2);
2404 batadv_tvlv_handler_unregister(bat_priv, BATADV_TVLV_MCAST, 2);
2405
2406
2407 batadv_mcast_mla_tt_retract(bat_priv, NULL);
2408 }
2409
2410
2411
2412
2413
2414 void batadv_mcast_purge_orig(struct batadv_orig_node *orig)
2415 {
2416 struct batadv_priv *bat_priv = orig->bat_priv;
2417
2418 spin_lock_bh(&orig->mcast_handler_lock);
2419
2420 batadv_mcast_want_unsnoop_update(bat_priv, orig, BATADV_NO_FLAGS);
2421 batadv_mcast_want_ipv4_update(bat_priv, orig, BATADV_NO_FLAGS);
2422 batadv_mcast_want_ipv6_update(bat_priv, orig, BATADV_NO_FLAGS);
2423 batadv_mcast_want_rtr4_update(bat_priv, orig,
2424 BATADV_MCAST_WANT_NO_RTR4);
2425 batadv_mcast_want_rtr6_update(bat_priv, orig,
2426 BATADV_MCAST_WANT_NO_RTR6);
2427
2428 spin_unlock_bh(&orig->mcast_handler_lock);
2429 }