1 /* Copyright (C) 2014-2015 B.A.T.M.A.N. contributors:
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public
7 * License as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 #include "multicast.h"
21 #include <linux/atomic.h>
22 #include <linux/byteorder/generic.h>
23 #include <linux/errno.h>
24 #include <linux/etherdevice.h>
26 #include <linux/if_ether.h>
27 #include <linux/in6.h>
30 #include <linux/ipv6.h>
31 #include <linux/list.h>
32 #include <linux/netdevice.h>
33 #include <linux/rculist.h>
34 #include <linux/rcupdate.h>
35 #include <linux/skbuff.h>
36 #include <linux/slab.h>
37 #include <linux/spinlock.h>
38 #include <linux/stddef.h>
39 #include <linux/string.h>
40 #include <linux/types.h>
41 #include <net/addrconf.h>
45 #include "translation-table.h"
48 * batadv_mcast_mla_softif_get - get softif multicast listeners
49 * @dev: the device to collect multicast addresses from
50 * @mcast_list: a list to put found addresses into
52 * Collect multicast addresses of the local multicast listeners
53 * on the given soft interface, dev, in the given mcast_list.
55 * Returns -ENOMEM on memory allocation error or the number of
56 * items added to the mcast_list otherwise.
58 static int batadv_mcast_mla_softif_get(struct net_device
*dev
,
59 struct hlist_head
*mcast_list
)
61 struct netdev_hw_addr
*mc_list_entry
;
62 struct batadv_hw_addr
*new;
65 netif_addr_lock_bh(dev
);
66 netdev_for_each_mc_addr(mc_list_entry
, dev
) {
67 new = kmalloc(sizeof(*new), GFP_ATOMIC
);
73 ether_addr_copy(new->addr
, mc_list_entry
->addr
);
74 hlist_add_head(&new->list
, mcast_list
);
77 netif_addr_unlock_bh(dev
);
83 * batadv_mcast_mla_is_duplicate - check whether an address is in a list
84 * @mcast_addr: the multicast address to check
85 * @mcast_list: the list with multicast addresses to search in
87 * Returns true if the given address is already in the given list.
88 * Otherwise returns false.
90 static bool batadv_mcast_mla_is_duplicate(uint8_t *mcast_addr
,
91 struct hlist_head
*mcast_list
)
93 struct batadv_hw_addr
*mcast_entry
;
95 hlist_for_each_entry(mcast_entry
, mcast_list
, list
)
96 if (batadv_compare_eth(mcast_entry
->addr
, mcast_addr
))
103 * batadv_mcast_mla_list_free - free a list of multicast addresses
104 * @mcast_list: the list to free
106 * Removes and frees all items in the given mcast_list.
108 static void batadv_mcast_mla_list_free(struct hlist_head
*mcast_list
)
110 struct batadv_hw_addr
*mcast_entry
;
111 struct hlist_node
*tmp
;
113 hlist_for_each_entry_safe(mcast_entry
, tmp
, mcast_list
, list
) {
114 hlist_del(&mcast_entry
->list
);
120 * batadv_mcast_mla_tt_retract - clean up multicast listener announcements
121 * @bat_priv: the bat priv with all the soft interface information
122 * @mcast_list: a list of addresses which should _not_ be removed
124 * Retracts the announcement of any multicast listener from the
125 * translation table except the ones listed in the given mcast_list.
127 * If mcast_list is NULL then all are retracted.
129 static void batadv_mcast_mla_tt_retract(struct batadv_priv
*bat_priv
,
130 struct hlist_head
*mcast_list
)
132 struct batadv_hw_addr
*mcast_entry
;
133 struct hlist_node
*tmp
;
135 hlist_for_each_entry_safe(mcast_entry
, tmp
, &bat_priv
->mcast
.mla_list
,
138 batadv_mcast_mla_is_duplicate(mcast_entry
->addr
,
142 batadv_tt_local_remove(bat_priv
, mcast_entry
->addr
,
144 "mcast TT outdated", false);
146 hlist_del(&mcast_entry
->list
);
152 * batadv_mcast_mla_tt_add - add multicast listener announcements
153 * @bat_priv: the bat priv with all the soft interface information
154 * @mcast_list: a list of addresses which are going to get added
156 * Adds multicast listener announcements from the given mcast_list to the
157 * translation table if they have not been added yet.
159 static void batadv_mcast_mla_tt_add(struct batadv_priv
*bat_priv
,
160 struct hlist_head
*mcast_list
)
162 struct batadv_hw_addr
*mcast_entry
;
163 struct hlist_node
*tmp
;
168 hlist_for_each_entry_safe(mcast_entry
, tmp
, mcast_list
, list
) {
169 if (batadv_mcast_mla_is_duplicate(mcast_entry
->addr
,
170 &bat_priv
->mcast
.mla_list
))
173 if (!batadv_tt_local_add(bat_priv
->soft_iface
,
174 mcast_entry
->addr
, BATADV_NO_FLAGS
,
175 BATADV_NULL_IFINDEX
, BATADV_NO_MARK
))
178 hlist_del(&mcast_entry
->list
);
179 hlist_add_head(&mcast_entry
->list
, &bat_priv
->mcast
.mla_list
);
184 * batadv_mcast_has_bridge - check whether the soft-iface is bridged
185 * @bat_priv: the bat priv with all the soft interface information
187 * Checks whether there is a bridge on top of our soft interface. Returns
188 * true if so, false otherwise.
190 static bool batadv_mcast_has_bridge(struct batadv_priv
*bat_priv
)
192 struct net_device
*upper
= bat_priv
->soft_iface
;
196 upper
= netdev_master_upper_dev_get_rcu(upper
);
197 } while (upper
&& !(upper
->priv_flags
& IFF_EBRIDGE
));
204 * batadv_mcast_mla_tvlv_update - update multicast tvlv
205 * @bat_priv: the bat priv with all the soft interface information
207 * Updates the own multicast tvlv with our current multicast related settings,
208 * capabilities and inabilities.
210 * Returns true if the tvlv container is registered afterwards. Otherwise
213 static bool batadv_mcast_mla_tvlv_update(struct batadv_priv
*bat_priv
)
215 struct batadv_tvlv_mcast_data mcast_data
;
217 mcast_data
.flags
= BATADV_NO_FLAGS
;
218 memset(mcast_data
.reserved
, 0, sizeof(mcast_data
.reserved
));
220 /* Avoid attaching MLAs, if there is a bridge on top of our soft
221 * interface, we don't support that yet (TODO)
223 if (batadv_mcast_has_bridge(bat_priv
)) {
224 if (bat_priv
->mcast
.enabled
) {
225 batadv_tvlv_container_unregister(bat_priv
,
226 BATADV_TVLV_MCAST
, 1);
227 bat_priv
->mcast
.enabled
= false;
233 if (!bat_priv
->mcast
.enabled
||
234 mcast_data
.flags
!= bat_priv
->mcast
.flags
) {
235 batadv_tvlv_container_register(bat_priv
, BATADV_TVLV_MCAST
, 1,
236 &mcast_data
, sizeof(mcast_data
));
237 bat_priv
->mcast
.flags
= mcast_data
.flags
;
238 bat_priv
->mcast
.enabled
= true;
245 * batadv_mcast_mla_update - update the own MLAs
246 * @bat_priv: the bat priv with all the soft interface information
248 * Updates the own multicast listener announcements in the translation
249 * table as well as the own, announced multicast tvlv container.
251 void batadv_mcast_mla_update(struct batadv_priv
*bat_priv
)
253 struct net_device
*soft_iface
= bat_priv
->soft_iface
;
254 struct hlist_head mcast_list
= HLIST_HEAD_INIT
;
257 if (!batadv_mcast_mla_tvlv_update(bat_priv
))
260 ret
= batadv_mcast_mla_softif_get(soft_iface
, &mcast_list
);
265 batadv_mcast_mla_tt_retract(bat_priv
, &mcast_list
);
266 batadv_mcast_mla_tt_add(bat_priv
, &mcast_list
);
269 batadv_mcast_mla_list_free(&mcast_list
);
273 * batadv_mcast_forw_mode_check_ipv4 - check for optimized forwarding potential
274 * @bat_priv: the bat priv with all the soft interface information
275 * @skb: the IPv4 packet to check
276 * @is_unsnoopable: stores whether the destination is snoopable
278 * Checks whether the given IPv4 packet has the potential to be forwarded with a
279 * mode more optimal than classic flooding.
281 * If so then returns 0. Otherwise -EINVAL is returned or -ENOMEM in case of
282 * memory allocation failure.
284 static int batadv_mcast_forw_mode_check_ipv4(struct batadv_priv
*bat_priv
,
286 bool *is_unsnoopable
)
290 /* We might fail due to out-of-memory -> drop it */
291 if (!pskb_may_pull(skb
, sizeof(struct ethhdr
) + sizeof(*iphdr
)))
296 /* TODO: Implement Multicast Router Discovery (RFC4286),
297 * then allow scope > link local, too
299 if (!ipv4_is_local_multicast(iphdr
->daddr
))
302 /* link-local multicast listeners behind a bridge are
303 * not snoopable (see RFC4541, section 2.1.2.2)
305 *is_unsnoopable
= true;
311 * batadv_mcast_forw_mode_check_ipv6 - check for optimized forwarding potential
312 * @bat_priv: the bat priv with all the soft interface information
313 * @skb: the IPv6 packet to check
314 * @is_unsnoopable: stores whether the destination is snoopable
316 * Checks whether the given IPv6 packet has the potential to be forwarded with a
317 * mode more optimal than classic flooding.
319 * If so then returns 0. Otherwise -EINVAL is returned or -ENOMEM if we are out
322 static int batadv_mcast_forw_mode_check_ipv6(struct batadv_priv
*bat_priv
,
324 bool *is_unsnoopable
)
326 struct ipv6hdr
*ip6hdr
;
328 /* We might fail due to out-of-memory -> drop it */
329 if (!pskb_may_pull(skb
, sizeof(struct ethhdr
) + sizeof(*ip6hdr
)))
332 ip6hdr
= ipv6_hdr(skb
);
334 /* TODO: Implement Multicast Router Discovery (RFC4286),
335 * then allow scope > link local, too
337 if (IPV6_ADDR_MC_SCOPE(&ip6hdr
->daddr
) != IPV6_ADDR_SCOPE_LINKLOCAL
)
340 /* link-local-all-nodes multicast listeners behind a bridge are
341 * not snoopable (see RFC4541, section 3, paragraph 3)
343 if (ipv6_addr_is_ll_all_nodes(&ip6hdr
->daddr
))
344 *is_unsnoopable
= true;
350 * batadv_mcast_forw_mode_check - check for optimized forwarding potential
351 * @bat_priv: the bat priv with all the soft interface information
352 * @skb: the multicast frame to check
353 * @is_unsnoopable: stores whether the destination is snoopable
355 * Checks whether the given multicast ethernet frame has the potential to be
356 * forwarded with a mode more optimal than classic flooding.
358 * If so then returns 0. Otherwise -EINVAL is returned or -ENOMEM if we are out
361 static int batadv_mcast_forw_mode_check(struct batadv_priv
*bat_priv
,
363 bool *is_unsnoopable
)
365 struct ethhdr
*ethhdr
= eth_hdr(skb
);
367 if (!atomic_read(&bat_priv
->multicast_mode
))
370 if (atomic_read(&bat_priv
->mcast
.num_disabled
))
373 switch (ntohs(ethhdr
->h_proto
)) {
375 return batadv_mcast_forw_mode_check_ipv4(bat_priv
, skb
,
378 return batadv_mcast_forw_mode_check_ipv6(bat_priv
, skb
,
386 * batadv_mcast_want_all_ip_count - count nodes with unspecific mcast interest
387 * @bat_priv: the bat priv with all the soft interface information
388 * @ethhdr: ethernet header of a packet
390 * Returns the number of nodes which want all IPv4 multicast traffic if the
391 * given ethhdr is from an IPv4 packet or the number of nodes which want all
392 * IPv6 traffic if it matches an IPv6 packet.
394 static int batadv_mcast_forw_want_all_ip_count(struct batadv_priv
*bat_priv
,
395 struct ethhdr
*ethhdr
)
397 switch (ntohs(ethhdr
->h_proto
)) {
399 return atomic_read(&bat_priv
->mcast
.num_want_all_ipv4
);
401 return atomic_read(&bat_priv
->mcast
.num_want_all_ipv6
);
403 /* we shouldn't be here... */
409 * batadv_mcast_forw_tt_node_get - get a multicast tt node
410 * @bat_priv: the bat priv with all the soft interface information
411 * @ethhdr: the ether header containing the multicast destination
413 * Returns an orig_node matching the multicast address provided by ethhdr
414 * via a translation table lookup. This increases the returned nodes refcount.
416 static struct batadv_orig_node
*
417 batadv_mcast_forw_tt_node_get(struct batadv_priv
*bat_priv
,
418 struct ethhdr
*ethhdr
)
420 return batadv_transtable_search(bat_priv
, ethhdr
->h_source
,
421 ethhdr
->h_dest
, BATADV_NO_FLAGS
);
425 * batadv_mcast_want_forw_ipv4_node_get - get a node with an ipv4 flag
426 * @bat_priv: the bat priv with all the soft interface information
428 * Returns an orig_node which has the BATADV_MCAST_WANT_ALL_IPV4 flag set and
429 * increases its refcount.
431 static struct batadv_orig_node
*
432 batadv_mcast_forw_ipv4_node_get(struct batadv_priv
*bat_priv
)
434 struct batadv_orig_node
*tmp_orig_node
, *orig_node
= NULL
;
437 hlist_for_each_entry_rcu(tmp_orig_node
,
438 &bat_priv
->mcast
.want_all_ipv4_list
,
439 mcast_want_all_ipv4_node
) {
440 if (!atomic_inc_not_zero(&tmp_orig_node
->refcount
))
443 orig_node
= tmp_orig_node
;
452 * batadv_mcast_want_forw_ipv6_node_get - get a node with an ipv6 flag
453 * @bat_priv: the bat priv with all the soft interface information
455 * Returns an orig_node which has the BATADV_MCAST_WANT_ALL_IPV6 flag set
456 * and increases its refcount.
458 static struct batadv_orig_node
*
459 batadv_mcast_forw_ipv6_node_get(struct batadv_priv
*bat_priv
)
461 struct batadv_orig_node
*tmp_orig_node
, *orig_node
= NULL
;
464 hlist_for_each_entry_rcu(tmp_orig_node
,
465 &bat_priv
->mcast
.want_all_ipv6_list
,
466 mcast_want_all_ipv6_node
) {
467 if (!atomic_inc_not_zero(&tmp_orig_node
->refcount
))
470 orig_node
= tmp_orig_node
;
479 * batadv_mcast_want_forw_ip_node_get - get a node with an ipv4/ipv6 flag
480 * @bat_priv: the bat priv with all the soft interface information
481 * @ethhdr: an ethernet header to determine the protocol family from
483 * Returns an orig_node which has the BATADV_MCAST_WANT_ALL_IPV4 or
484 * BATADV_MCAST_WANT_ALL_IPV6 flag, depending on the provided ethhdr, set and
485 * increases its refcount.
487 static struct batadv_orig_node
*
488 batadv_mcast_forw_ip_node_get(struct batadv_priv
*bat_priv
,
489 struct ethhdr
*ethhdr
)
491 switch (ntohs(ethhdr
->h_proto
)) {
493 return batadv_mcast_forw_ipv4_node_get(bat_priv
);
495 return batadv_mcast_forw_ipv6_node_get(bat_priv
);
497 /* we shouldn't be here... */
503 * batadv_mcast_want_forw_unsnoop_node_get - get a node with an unsnoopable flag
504 * @bat_priv: the bat priv with all the soft interface information
506 * Returns an orig_node which has the BATADV_MCAST_WANT_ALL_UNSNOOPABLES flag
507 * set and increases its refcount.
509 static struct batadv_orig_node
*
510 batadv_mcast_forw_unsnoop_node_get(struct batadv_priv
*bat_priv
)
512 struct batadv_orig_node
*tmp_orig_node
, *orig_node
= NULL
;
515 hlist_for_each_entry_rcu(tmp_orig_node
,
516 &bat_priv
->mcast
.want_all_unsnoopables_list
,
517 mcast_want_all_unsnoopables_node
) {
518 if (!atomic_inc_not_zero(&tmp_orig_node
->refcount
))
521 orig_node
= tmp_orig_node
;
530 * batadv_mcast_forw_mode - check on how to forward a multicast packet
531 * @bat_priv: the bat priv with all the soft interface information
532 * @skb: The multicast packet to check
533 * @orig: an originator to be set to forward the skb to
535 * Returns the forwarding mode as enum batadv_forw_mode and in case of
536 * BATADV_FORW_SINGLE set the orig to the single originator the skb
537 * should be forwarded to.
539 enum batadv_forw_mode
540 batadv_mcast_forw_mode(struct batadv_priv
*bat_priv
, struct sk_buff
*skb
,
541 struct batadv_orig_node
**orig
)
543 int ret
, tt_count
, ip_count
, unsnoop_count
, total_count
;
544 bool is_unsnoopable
= false;
545 struct ethhdr
*ethhdr
;
547 ret
= batadv_mcast_forw_mode_check(bat_priv
, skb
, &is_unsnoopable
);
549 return BATADV_FORW_NONE
;
551 return BATADV_FORW_ALL
;
553 ethhdr
= eth_hdr(skb
);
555 tt_count
= batadv_tt_global_hash_count(bat_priv
, ethhdr
->h_dest
,
557 ip_count
= batadv_mcast_forw_want_all_ip_count(bat_priv
, ethhdr
);
558 unsnoop_count
= !is_unsnoopable
? 0 :
559 atomic_read(&bat_priv
->mcast
.num_want_all_unsnoopables
);
561 total_count
= tt_count
+ ip_count
+ unsnoop_count
;
563 switch (total_count
) {
566 *orig
= batadv_mcast_forw_tt_node_get(bat_priv
, ethhdr
);
568 *orig
= batadv_mcast_forw_ip_node_get(bat_priv
, ethhdr
);
569 else if (unsnoop_count
)
570 *orig
= batadv_mcast_forw_unsnoop_node_get(bat_priv
);
573 return BATADV_FORW_SINGLE
;
577 return BATADV_FORW_NONE
;
579 return BATADV_FORW_ALL
;
584 * batadv_mcast_want_unsnoop_update - update unsnoop counter and list
585 * @bat_priv: the bat priv with all the soft interface information
586 * @orig: the orig_node which multicast state might have changed of
587 * @mcast_flags: flags indicating the new multicast state
589 * If the BATADV_MCAST_WANT_ALL_UNSNOOPABLES flag of this originator,
590 * orig, has toggled then this method updates counter and list accordingly.
592 static void batadv_mcast_want_unsnoop_update(struct batadv_priv
*bat_priv
,
593 struct batadv_orig_node
*orig
,
596 /* switched from flag unset to set */
597 if (mcast_flags
& BATADV_MCAST_WANT_ALL_UNSNOOPABLES
&&
598 !(orig
->mcast_flags
& BATADV_MCAST_WANT_ALL_UNSNOOPABLES
)) {
599 atomic_inc(&bat_priv
->mcast
.num_want_all_unsnoopables
);
601 spin_lock_bh(&bat_priv
->mcast
.want_lists_lock
);
602 hlist_add_head_rcu(&orig
->mcast_want_all_unsnoopables_node
,
603 &bat_priv
->mcast
.want_all_unsnoopables_list
);
604 spin_unlock_bh(&bat_priv
->mcast
.want_lists_lock
);
605 /* switched from flag set to unset */
606 } else if (!(mcast_flags
& BATADV_MCAST_WANT_ALL_UNSNOOPABLES
) &&
607 orig
->mcast_flags
& BATADV_MCAST_WANT_ALL_UNSNOOPABLES
) {
608 atomic_dec(&bat_priv
->mcast
.num_want_all_unsnoopables
);
610 spin_lock_bh(&bat_priv
->mcast
.want_lists_lock
);
611 hlist_del_rcu(&orig
->mcast_want_all_unsnoopables_node
);
612 spin_unlock_bh(&bat_priv
->mcast
.want_lists_lock
);
617 * batadv_mcast_want_ipv4_update - update want-all-ipv4 counter and list
618 * @bat_priv: the bat priv with all the soft interface information
619 * @orig: the orig_node which multicast state might have changed of
620 * @mcast_flags: flags indicating the new multicast state
622 * If the BATADV_MCAST_WANT_ALL_IPV4 flag of this originator, orig, has
623 * toggled then this method updates counter and list accordingly.
625 static void batadv_mcast_want_ipv4_update(struct batadv_priv
*bat_priv
,
626 struct batadv_orig_node
*orig
,
629 /* switched from flag unset to set */
630 if (mcast_flags
& BATADV_MCAST_WANT_ALL_IPV4
&&
631 !(orig
->mcast_flags
& BATADV_MCAST_WANT_ALL_IPV4
)) {
632 atomic_inc(&bat_priv
->mcast
.num_want_all_ipv4
);
634 spin_lock_bh(&bat_priv
->mcast
.want_lists_lock
);
635 hlist_add_head_rcu(&orig
->mcast_want_all_ipv4_node
,
636 &bat_priv
->mcast
.want_all_ipv4_list
);
637 spin_unlock_bh(&bat_priv
->mcast
.want_lists_lock
);
638 /* switched from flag set to unset */
639 } else if (!(mcast_flags
& BATADV_MCAST_WANT_ALL_IPV4
) &&
640 orig
->mcast_flags
& BATADV_MCAST_WANT_ALL_IPV4
) {
641 atomic_dec(&bat_priv
->mcast
.num_want_all_ipv4
);
643 spin_lock_bh(&bat_priv
->mcast
.want_lists_lock
);
644 hlist_del_rcu(&orig
->mcast_want_all_ipv4_node
);
645 spin_unlock_bh(&bat_priv
->mcast
.want_lists_lock
);
650 * batadv_mcast_want_ipv6_update - update want-all-ipv6 counter and list
651 * @bat_priv: the bat priv with all the soft interface information
652 * @orig: the orig_node which multicast state might have changed of
653 * @mcast_flags: flags indicating the new multicast state
655 * If the BATADV_MCAST_WANT_ALL_IPV6 flag of this originator, orig, has
656 * toggled then this method updates counter and list accordingly.
658 static void batadv_mcast_want_ipv6_update(struct batadv_priv
*bat_priv
,
659 struct batadv_orig_node
*orig
,
662 /* switched from flag unset to set */
663 if (mcast_flags
& BATADV_MCAST_WANT_ALL_IPV6
&&
664 !(orig
->mcast_flags
& BATADV_MCAST_WANT_ALL_IPV6
)) {
665 atomic_inc(&bat_priv
->mcast
.num_want_all_ipv6
);
667 spin_lock_bh(&bat_priv
->mcast
.want_lists_lock
);
668 hlist_add_head_rcu(&orig
->mcast_want_all_ipv6_node
,
669 &bat_priv
->mcast
.want_all_ipv6_list
);
670 spin_unlock_bh(&bat_priv
->mcast
.want_lists_lock
);
671 /* switched from flag set to unset */
672 } else if (!(mcast_flags
& BATADV_MCAST_WANT_ALL_IPV6
) &&
673 orig
->mcast_flags
& BATADV_MCAST_WANT_ALL_IPV6
) {
674 atomic_dec(&bat_priv
->mcast
.num_want_all_ipv6
);
676 spin_lock_bh(&bat_priv
->mcast
.want_lists_lock
);
677 hlist_del_rcu(&orig
->mcast_want_all_ipv6_node
);
678 spin_unlock_bh(&bat_priv
->mcast
.want_lists_lock
);
683 * batadv_mcast_tvlv_ogm_handler_v1 - process incoming multicast tvlv container
684 * @bat_priv: the bat priv with all the soft interface information
685 * @orig: the orig_node of the ogm
686 * @flags: flags indicating the tvlv state (see batadv_tvlv_handler_flags)
687 * @tvlv_value: tvlv buffer containing the multicast data
688 * @tvlv_value_len: tvlv buffer length
690 static void batadv_mcast_tvlv_ogm_handler_v1(struct batadv_priv
*bat_priv
,
691 struct batadv_orig_node
*orig
,
694 uint16_t tvlv_value_len
)
696 bool orig_mcast_enabled
= !(flags
& BATADV_TVLV_HANDLER_OGM_CIFNOTFND
);
697 uint8_t mcast_flags
= BATADV_NO_FLAGS
;
698 bool orig_initialized
;
700 orig_initialized
= orig
->capa_initialized
& BATADV_ORIG_CAPA_HAS_MCAST
;
702 /* If mcast support is turned on decrease the disabled mcast node
703 * counter only if we had increased it for this node before. If this
704 * is a completely new orig_node no need to decrease the counter.
706 if (orig_mcast_enabled
&&
707 !(orig
->capabilities
& BATADV_ORIG_CAPA_HAS_MCAST
)) {
708 if (orig_initialized
)
709 atomic_dec(&bat_priv
->mcast
.num_disabled
);
710 orig
->capabilities
|= BATADV_ORIG_CAPA_HAS_MCAST
;
711 /* If mcast support is being switched off or if this is an initial
712 * OGM without mcast support then increase the disabled mcast
715 } else if (!orig_mcast_enabled
&&
716 (orig
->capabilities
& BATADV_ORIG_CAPA_HAS_MCAST
||
717 !orig_initialized
)) {
718 atomic_inc(&bat_priv
->mcast
.num_disabled
);
719 orig
->capabilities
&= ~BATADV_ORIG_CAPA_HAS_MCAST
;
722 orig
->capa_initialized
|= BATADV_ORIG_CAPA_HAS_MCAST
;
724 if (orig_mcast_enabled
&& tvlv_value
&&
725 (tvlv_value_len
>= sizeof(mcast_flags
)))
726 mcast_flags
= *(uint8_t *)tvlv_value
;
728 batadv_mcast_want_unsnoop_update(bat_priv
, orig
, mcast_flags
);
729 batadv_mcast_want_ipv4_update(bat_priv
, orig
, mcast_flags
);
730 batadv_mcast_want_ipv6_update(bat_priv
, orig
, mcast_flags
);
732 orig
->mcast_flags
= mcast_flags
;
736 * batadv_mcast_init - initialize the multicast optimizations structures
737 * @bat_priv: the bat priv with all the soft interface information
739 void batadv_mcast_init(struct batadv_priv
*bat_priv
)
741 batadv_tvlv_handler_register(bat_priv
, batadv_mcast_tvlv_ogm_handler_v1
,
742 NULL
, BATADV_TVLV_MCAST
, 1,
743 BATADV_TVLV_HANDLER_OGM_CIFNOTFND
);
747 * batadv_mcast_free - free the multicast optimizations structures
748 * @bat_priv: the bat priv with all the soft interface information
750 void batadv_mcast_free(struct batadv_priv
*bat_priv
)
752 batadv_tvlv_container_unregister(bat_priv
, BATADV_TVLV_MCAST
, 1);
753 batadv_tvlv_handler_unregister(bat_priv
, BATADV_TVLV_MCAST
, 1);
755 batadv_mcast_mla_tt_retract(bat_priv
, NULL
);
759 * batadv_mcast_purge_orig - reset originator global mcast state modifications
760 * @orig: the originator which is going to get purged
762 void batadv_mcast_purge_orig(struct batadv_orig_node
*orig
)
764 struct batadv_priv
*bat_priv
= orig
->bat_priv
;
766 if (!(orig
->capabilities
& BATADV_ORIG_CAPA_HAS_MCAST
) &&
767 orig
->capa_initialized
& BATADV_ORIG_CAPA_HAS_MCAST
)
768 atomic_dec(&bat_priv
->mcast
.num_disabled
);
770 batadv_mcast_want_unsnoop_update(bat_priv
, orig
, BATADV_NO_FLAGS
);
771 batadv_mcast_want_ipv4_update(bat_priv
, orig
, BATADV_NO_FLAGS
);
772 batadv_mcast_want_ipv6_update(bat_priv
, orig
, BATADV_NO_FLAGS
);