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/bitops.h>
23 #include <linux/byteorder/generic.h>
24 #include <linux/errno.h>
25 #include <linux/etherdevice.h>
27 #include <linux/if_ether.h>
28 #include <linux/in6.h>
31 #include <linux/ipv6.h>
32 #include <linux/list.h>
33 #include <linux/netdevice.h>
34 #include <linux/rculist.h>
35 #include <linux/rcupdate.h>
36 #include <linux/skbuff.h>
37 #include <linux/slab.h>
38 #include <linux/spinlock.h>
39 #include <linux/stddef.h>
40 #include <linux/string.h>
41 #include <linux/types.h>
42 #include <net/addrconf.h>
46 #include "translation-table.h"
49 * batadv_mcast_mla_softif_get - get softif multicast listeners
50 * @dev: the device to collect multicast addresses from
51 * @mcast_list: a list to put found addresses into
53 * Collect multicast addresses of the local multicast listeners
54 * on the given soft interface, dev, in the given mcast_list.
56 * Returns -ENOMEM on memory allocation error or the number of
57 * items added to the mcast_list otherwise.
59 static int batadv_mcast_mla_softif_get(struct net_device *dev,
60 struct hlist_head *mcast_list)
62 struct netdev_hw_addr *mc_list_entry;
63 struct batadv_hw_addr *new;
66 netif_addr_lock_bh(dev);
67 netdev_for_each_mc_addr(mc_list_entry, dev) {
68 new = kmalloc(sizeof(*new), GFP_ATOMIC);
74 ether_addr_copy(new->addr, mc_list_entry->addr);
75 hlist_add_head(&new->list, mcast_list);
78 netif_addr_unlock_bh(dev);
84 * batadv_mcast_mla_is_duplicate - check whether an address is in a list
85 * @mcast_addr: the multicast address to check
86 * @mcast_list: the list with multicast addresses to search in
88 * Returns true if the given address is already in the given list.
89 * Otherwise returns false.
91 static bool batadv_mcast_mla_is_duplicate(uint8_t *mcast_addr,
92 struct hlist_head *mcast_list)
94 struct batadv_hw_addr *mcast_entry;
96 hlist_for_each_entry(mcast_entry, mcast_list, list)
97 if (batadv_compare_eth(mcast_entry->addr, mcast_addr))
104 * batadv_mcast_mla_list_free - free a list of multicast addresses
105 * @mcast_list: the list to free
107 * Removes and frees all items in the given mcast_list.
109 static void batadv_mcast_mla_list_free(struct hlist_head *mcast_list)
111 struct batadv_hw_addr *mcast_entry;
112 struct hlist_node *tmp;
114 hlist_for_each_entry_safe(mcast_entry, tmp, mcast_list, list) {
115 hlist_del(&mcast_entry->list);
121 * batadv_mcast_mla_tt_retract - clean up multicast listener announcements
122 * @bat_priv: the bat priv with all the soft interface information
123 * @mcast_list: a list of addresses which should _not_ be removed
125 * Retracts the announcement of any multicast listener from the
126 * translation table except the ones listed in the given mcast_list.
128 * If mcast_list is NULL then all are retracted.
130 static void batadv_mcast_mla_tt_retract(struct batadv_priv *bat_priv,
131 struct hlist_head *mcast_list)
133 struct batadv_hw_addr *mcast_entry;
134 struct hlist_node *tmp;
136 hlist_for_each_entry_safe(mcast_entry, tmp, &bat_priv->mcast.mla_list,
139 batadv_mcast_mla_is_duplicate(mcast_entry->addr,
143 batadv_tt_local_remove(bat_priv, mcast_entry->addr,
145 "mcast TT outdated", false);
147 hlist_del(&mcast_entry->list);
153 * batadv_mcast_mla_tt_add - add multicast listener announcements
154 * @bat_priv: the bat priv with all the soft interface information
155 * @mcast_list: a list of addresses which are going to get added
157 * Adds multicast listener announcements from the given mcast_list to the
158 * translation table if they have not been added yet.
160 static void batadv_mcast_mla_tt_add(struct batadv_priv *bat_priv,
161 struct hlist_head *mcast_list)
163 struct batadv_hw_addr *mcast_entry;
164 struct hlist_node *tmp;
169 hlist_for_each_entry_safe(mcast_entry, tmp, mcast_list, list) {
170 if (batadv_mcast_mla_is_duplicate(mcast_entry->addr,
171 &bat_priv->mcast.mla_list))
174 if (!batadv_tt_local_add(bat_priv->soft_iface,
175 mcast_entry->addr, BATADV_NO_FLAGS,
176 BATADV_NULL_IFINDEX, BATADV_NO_MARK))
179 hlist_del(&mcast_entry->list);
180 hlist_add_head(&mcast_entry->list, &bat_priv->mcast.mla_list);
185 * batadv_mcast_has_bridge - check whether the soft-iface is bridged
186 * @bat_priv: the bat priv with all the soft interface information
188 * Checks whether there is a bridge on top of our soft interface. Returns
189 * true if so, false otherwise.
191 static bool batadv_mcast_has_bridge(struct batadv_priv *bat_priv)
193 struct net_device *upper = bat_priv->soft_iface;
197 upper = netdev_master_upper_dev_get_rcu(upper);
198 } while (upper && !(upper->priv_flags & IFF_EBRIDGE));
205 * batadv_mcast_mla_tvlv_update - update multicast tvlv
206 * @bat_priv: the bat priv with all the soft interface information
208 * Updates the own multicast tvlv with our current multicast related settings,
209 * capabilities and inabilities.
211 * Returns true if the tvlv container is registered afterwards. Otherwise
214 static bool batadv_mcast_mla_tvlv_update(struct batadv_priv *bat_priv)
216 struct batadv_tvlv_mcast_data mcast_data;
218 mcast_data.flags = BATADV_NO_FLAGS;
219 memset(mcast_data.reserved, 0, sizeof(mcast_data.reserved));
221 /* Avoid attaching MLAs, if there is a bridge on top of our soft
222 * interface, we don't support that yet (TODO)
224 if (batadv_mcast_has_bridge(bat_priv)) {
225 if (bat_priv->mcast.enabled) {
226 batadv_tvlv_container_unregister(bat_priv,
227 BATADV_TVLV_MCAST, 1);
228 bat_priv->mcast.enabled = false;
234 if (!bat_priv->mcast.enabled ||
235 mcast_data.flags != bat_priv->mcast.flags) {
236 batadv_tvlv_container_register(bat_priv, BATADV_TVLV_MCAST, 1,
237 &mcast_data, sizeof(mcast_data));
238 bat_priv->mcast.flags = mcast_data.flags;
239 bat_priv->mcast.enabled = true;
246 * batadv_mcast_mla_update - update the own MLAs
247 * @bat_priv: the bat priv with all the soft interface information
249 * Updates the own multicast listener announcements in the translation
250 * table as well as the own, announced multicast tvlv container.
252 void batadv_mcast_mla_update(struct batadv_priv *bat_priv)
254 struct net_device *soft_iface = bat_priv->soft_iface;
255 struct hlist_head mcast_list = HLIST_HEAD_INIT;
258 if (!batadv_mcast_mla_tvlv_update(bat_priv))
261 ret = batadv_mcast_mla_softif_get(soft_iface, &mcast_list);
266 batadv_mcast_mla_tt_retract(bat_priv, &mcast_list);
267 batadv_mcast_mla_tt_add(bat_priv, &mcast_list);
270 batadv_mcast_mla_list_free(&mcast_list);
274 * batadv_mcast_forw_mode_check_ipv4 - check for optimized forwarding potential
275 * @bat_priv: the bat priv with all the soft interface information
276 * @skb: the IPv4 packet to check
277 * @is_unsnoopable: stores whether the destination is snoopable
279 * Checks whether the given IPv4 packet has the potential to be forwarded with a
280 * mode more optimal than classic flooding.
282 * If so then returns 0. Otherwise -EINVAL is returned or -ENOMEM in case of
283 * memory allocation failure.
285 static int batadv_mcast_forw_mode_check_ipv4(struct batadv_priv *bat_priv,
287 bool *is_unsnoopable)
291 /* We might fail due to out-of-memory -> drop it */
292 if (!pskb_may_pull(skb, sizeof(struct ethhdr) + sizeof(*iphdr)))
297 /* TODO: Implement Multicast Router Discovery (RFC4286),
298 * then allow scope > link local, too
300 if (!ipv4_is_local_multicast(iphdr->daddr))
303 /* link-local multicast listeners behind a bridge are
304 * not snoopable (see RFC4541, section 2.1.2.2)
306 *is_unsnoopable = true;
312 * batadv_mcast_forw_mode_check_ipv6 - check for optimized forwarding potential
313 * @bat_priv: the bat priv with all the soft interface information
314 * @skb: the IPv6 packet to check
315 * @is_unsnoopable: stores whether the destination is snoopable
317 * Checks whether the given IPv6 packet has the potential to be forwarded with a
318 * mode more optimal than classic flooding.
320 * If so then returns 0. Otherwise -EINVAL is returned or -ENOMEM if we are out
323 static int batadv_mcast_forw_mode_check_ipv6(struct batadv_priv *bat_priv,
325 bool *is_unsnoopable)
327 struct ipv6hdr *ip6hdr;
329 /* We might fail due to out-of-memory -> drop it */
330 if (!pskb_may_pull(skb, sizeof(struct ethhdr) + sizeof(*ip6hdr)))
333 ip6hdr = ipv6_hdr(skb);
335 /* TODO: Implement Multicast Router Discovery (RFC4286),
336 * then allow scope > link local, too
338 if (IPV6_ADDR_MC_SCOPE(&ip6hdr->daddr) != IPV6_ADDR_SCOPE_LINKLOCAL)
341 /* link-local-all-nodes multicast listeners behind a bridge are
342 * not snoopable (see RFC4541, section 3, paragraph 3)
344 if (ipv6_addr_is_ll_all_nodes(&ip6hdr->daddr))
345 *is_unsnoopable = true;
351 * batadv_mcast_forw_mode_check - check for optimized forwarding potential
352 * @bat_priv: the bat priv with all the soft interface information
353 * @skb: the multicast frame to check
354 * @is_unsnoopable: stores whether the destination is snoopable
356 * Checks whether the given multicast ethernet frame has the potential to be
357 * forwarded with a mode more optimal than classic flooding.
359 * If so then returns 0. Otherwise -EINVAL is returned or -ENOMEM if we are out
362 static int batadv_mcast_forw_mode_check(struct batadv_priv *bat_priv,
364 bool *is_unsnoopable)
366 struct ethhdr *ethhdr = eth_hdr(skb);
368 if (!atomic_read(&bat_priv->multicast_mode))
371 if (atomic_read(&bat_priv->mcast.num_disabled))
374 switch (ntohs(ethhdr->h_proto)) {
376 return batadv_mcast_forw_mode_check_ipv4(bat_priv, skb,
379 return batadv_mcast_forw_mode_check_ipv6(bat_priv, skb,
387 * batadv_mcast_want_all_ip_count - count nodes with unspecific mcast interest
388 * @bat_priv: the bat priv with all the soft interface information
389 * @ethhdr: ethernet header of a packet
391 * Returns the number of nodes which want all IPv4 multicast traffic if the
392 * given ethhdr is from an IPv4 packet or the number of nodes which want all
393 * IPv6 traffic if it matches an IPv6 packet.
395 static int batadv_mcast_forw_want_all_ip_count(struct batadv_priv *bat_priv,
396 struct ethhdr *ethhdr)
398 switch (ntohs(ethhdr->h_proto)) {
400 return atomic_read(&bat_priv->mcast.num_want_all_ipv4);
402 return atomic_read(&bat_priv->mcast.num_want_all_ipv6);
404 /* we shouldn't be here... */
410 * batadv_mcast_forw_tt_node_get - get a multicast tt node
411 * @bat_priv: the bat priv with all the soft interface information
412 * @ethhdr: the ether header containing the multicast destination
414 * Returns an orig_node matching the multicast address provided by ethhdr
415 * via a translation table lookup. This increases the returned nodes refcount.
417 static struct batadv_orig_node *
418 batadv_mcast_forw_tt_node_get(struct batadv_priv *bat_priv,
419 struct ethhdr *ethhdr)
421 return batadv_transtable_search(bat_priv, ethhdr->h_source,
422 ethhdr->h_dest, BATADV_NO_FLAGS);
426 * batadv_mcast_want_forw_ipv4_node_get - get a node with an ipv4 flag
427 * @bat_priv: the bat priv with all the soft interface information
429 * Returns an orig_node which has the BATADV_MCAST_WANT_ALL_IPV4 flag set and
430 * increases its refcount.
432 static struct batadv_orig_node *
433 batadv_mcast_forw_ipv4_node_get(struct batadv_priv *bat_priv)
435 struct batadv_orig_node *tmp_orig_node, *orig_node = NULL;
438 hlist_for_each_entry_rcu(tmp_orig_node,
439 &bat_priv->mcast.want_all_ipv4_list,
440 mcast_want_all_ipv4_node) {
441 if (!atomic_inc_not_zero(&tmp_orig_node->refcount))
444 orig_node = tmp_orig_node;
453 * batadv_mcast_want_forw_ipv6_node_get - get a node with an ipv6 flag
454 * @bat_priv: the bat priv with all the soft interface information
456 * Returns an orig_node which has the BATADV_MCAST_WANT_ALL_IPV6 flag set
457 * and increases its refcount.
459 static struct batadv_orig_node *
460 batadv_mcast_forw_ipv6_node_get(struct batadv_priv *bat_priv)
462 struct batadv_orig_node *tmp_orig_node, *orig_node = NULL;
465 hlist_for_each_entry_rcu(tmp_orig_node,
466 &bat_priv->mcast.want_all_ipv6_list,
467 mcast_want_all_ipv6_node) {
468 if (!atomic_inc_not_zero(&tmp_orig_node->refcount))
471 orig_node = tmp_orig_node;
480 * batadv_mcast_want_forw_ip_node_get - get a node with an ipv4/ipv6 flag
481 * @bat_priv: the bat priv with all the soft interface information
482 * @ethhdr: an ethernet header to determine the protocol family from
484 * Returns an orig_node which has the BATADV_MCAST_WANT_ALL_IPV4 or
485 * BATADV_MCAST_WANT_ALL_IPV6 flag, depending on the provided ethhdr, set and
486 * increases its refcount.
488 static struct batadv_orig_node *
489 batadv_mcast_forw_ip_node_get(struct batadv_priv *bat_priv,
490 struct ethhdr *ethhdr)
492 switch (ntohs(ethhdr->h_proto)) {
494 return batadv_mcast_forw_ipv4_node_get(bat_priv);
496 return batadv_mcast_forw_ipv6_node_get(bat_priv);
498 /* we shouldn't be here... */
504 * batadv_mcast_want_forw_unsnoop_node_get - get a node with an unsnoopable flag
505 * @bat_priv: the bat priv with all the soft interface information
507 * Returns an orig_node which has the BATADV_MCAST_WANT_ALL_UNSNOOPABLES flag
508 * set and increases its refcount.
510 static struct batadv_orig_node *
511 batadv_mcast_forw_unsnoop_node_get(struct batadv_priv *bat_priv)
513 struct batadv_orig_node *tmp_orig_node, *orig_node = NULL;
516 hlist_for_each_entry_rcu(tmp_orig_node,
517 &bat_priv->mcast.want_all_unsnoopables_list,
518 mcast_want_all_unsnoopables_node) {
519 if (!atomic_inc_not_zero(&tmp_orig_node->refcount))
522 orig_node = tmp_orig_node;
531 * batadv_mcast_forw_mode - check on how to forward a multicast packet
532 * @bat_priv: the bat priv with all the soft interface information
533 * @skb: The multicast packet to check
534 * @orig: an originator to be set to forward the skb to
536 * Returns the forwarding mode as enum batadv_forw_mode and in case of
537 * BATADV_FORW_SINGLE set the orig to the single originator the skb
538 * should be forwarded to.
540 enum batadv_forw_mode
541 batadv_mcast_forw_mode(struct batadv_priv *bat_priv, struct sk_buff *skb,
542 struct batadv_orig_node **orig)
544 int ret, tt_count, ip_count, unsnoop_count, total_count;
545 bool is_unsnoopable = false;
546 struct ethhdr *ethhdr;
548 ret = batadv_mcast_forw_mode_check(bat_priv, skb, &is_unsnoopable);
550 return BATADV_FORW_NONE;
552 return BATADV_FORW_ALL;
554 ethhdr = eth_hdr(skb);
556 tt_count = batadv_tt_global_hash_count(bat_priv, ethhdr->h_dest,
558 ip_count = batadv_mcast_forw_want_all_ip_count(bat_priv, ethhdr);
559 unsnoop_count = !is_unsnoopable ? 0 :
560 atomic_read(&bat_priv->mcast.num_want_all_unsnoopables);
562 total_count = tt_count + ip_count + unsnoop_count;
564 switch (total_count) {
567 *orig = batadv_mcast_forw_tt_node_get(bat_priv, ethhdr);
569 *orig = batadv_mcast_forw_ip_node_get(bat_priv, ethhdr);
570 else if (unsnoop_count)
571 *orig = batadv_mcast_forw_unsnoop_node_get(bat_priv);
574 return BATADV_FORW_SINGLE;
578 return BATADV_FORW_NONE;
580 return BATADV_FORW_ALL;
585 * batadv_mcast_want_unsnoop_update - update unsnoop counter and list
586 * @bat_priv: the bat priv with all the soft interface information
587 * @orig: the orig_node which multicast state might have changed of
588 * @mcast_flags: flags indicating the new multicast state
590 * If the BATADV_MCAST_WANT_ALL_UNSNOOPABLES flag of this originator,
591 * orig, has toggled then this method updates counter and list accordingly.
593 static void batadv_mcast_want_unsnoop_update(struct batadv_priv *bat_priv,
594 struct batadv_orig_node *orig,
597 /* switched from flag unset to set */
598 if (mcast_flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES &&
599 !(orig->mcast_flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES)) {
600 atomic_inc(&bat_priv->mcast.num_want_all_unsnoopables);
602 spin_lock_bh(&bat_priv->mcast.want_lists_lock);
603 hlist_add_head_rcu(&orig->mcast_want_all_unsnoopables_node,
604 &bat_priv->mcast.want_all_unsnoopables_list);
605 spin_unlock_bh(&bat_priv->mcast.want_lists_lock);
606 /* switched from flag set to unset */
607 } else if (!(mcast_flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES) &&
608 orig->mcast_flags & BATADV_MCAST_WANT_ALL_UNSNOOPABLES) {
609 atomic_dec(&bat_priv->mcast.num_want_all_unsnoopables);
611 spin_lock_bh(&bat_priv->mcast.want_lists_lock);
612 hlist_del_rcu(&orig->mcast_want_all_unsnoopables_node);
613 spin_unlock_bh(&bat_priv->mcast.want_lists_lock);
618 * batadv_mcast_want_ipv4_update - update want-all-ipv4 counter and list
619 * @bat_priv: the bat priv with all the soft interface information
620 * @orig: the orig_node which multicast state might have changed of
621 * @mcast_flags: flags indicating the new multicast state
623 * If the BATADV_MCAST_WANT_ALL_IPV4 flag of this originator, orig, has
624 * toggled then this method updates counter and list accordingly.
626 static void batadv_mcast_want_ipv4_update(struct batadv_priv *bat_priv,
627 struct batadv_orig_node *orig,
630 /* switched from flag unset to set */
631 if (mcast_flags & BATADV_MCAST_WANT_ALL_IPV4 &&
632 !(orig->mcast_flags & BATADV_MCAST_WANT_ALL_IPV4)) {
633 atomic_inc(&bat_priv->mcast.num_want_all_ipv4);
635 spin_lock_bh(&bat_priv->mcast.want_lists_lock);
636 hlist_add_head_rcu(&orig->mcast_want_all_ipv4_node,
637 &bat_priv->mcast.want_all_ipv4_list);
638 spin_unlock_bh(&bat_priv->mcast.want_lists_lock);
639 /* switched from flag set to unset */
640 } else if (!(mcast_flags & BATADV_MCAST_WANT_ALL_IPV4) &&
641 orig->mcast_flags & BATADV_MCAST_WANT_ALL_IPV4) {
642 atomic_dec(&bat_priv->mcast.num_want_all_ipv4);
644 spin_lock_bh(&bat_priv->mcast.want_lists_lock);
645 hlist_del_rcu(&orig->mcast_want_all_ipv4_node);
646 spin_unlock_bh(&bat_priv->mcast.want_lists_lock);
651 * batadv_mcast_want_ipv6_update - update want-all-ipv6 counter and list
652 * @bat_priv: the bat priv with all the soft interface information
653 * @orig: the orig_node which multicast state might have changed of
654 * @mcast_flags: flags indicating the new multicast state
656 * If the BATADV_MCAST_WANT_ALL_IPV6 flag of this originator, orig, has
657 * toggled then this method updates counter and list accordingly.
659 static void batadv_mcast_want_ipv6_update(struct batadv_priv *bat_priv,
660 struct batadv_orig_node *orig,
663 /* switched from flag unset to set */
664 if (mcast_flags & BATADV_MCAST_WANT_ALL_IPV6 &&
665 !(orig->mcast_flags & BATADV_MCAST_WANT_ALL_IPV6)) {
666 atomic_inc(&bat_priv->mcast.num_want_all_ipv6);
668 spin_lock_bh(&bat_priv->mcast.want_lists_lock);
669 hlist_add_head_rcu(&orig->mcast_want_all_ipv6_node,
670 &bat_priv->mcast.want_all_ipv6_list);
671 spin_unlock_bh(&bat_priv->mcast.want_lists_lock);
672 /* switched from flag set to unset */
673 } else if (!(mcast_flags & BATADV_MCAST_WANT_ALL_IPV6) &&
674 orig->mcast_flags & BATADV_MCAST_WANT_ALL_IPV6) {
675 atomic_dec(&bat_priv->mcast.num_want_all_ipv6);
677 spin_lock_bh(&bat_priv->mcast.want_lists_lock);
678 hlist_del_rcu(&orig->mcast_want_all_ipv6_node);
679 spin_unlock_bh(&bat_priv->mcast.want_lists_lock);
684 * batadv_mcast_tvlv_ogm_handler_v1 - process incoming multicast tvlv container
685 * @bat_priv: the bat priv with all the soft interface information
686 * @orig: the orig_node of the ogm
687 * @flags: flags indicating the tvlv state (see batadv_tvlv_handler_flags)
688 * @tvlv_value: tvlv buffer containing the multicast data
689 * @tvlv_value_len: tvlv buffer length
691 static void batadv_mcast_tvlv_ogm_handler_v1(struct batadv_priv *bat_priv,
692 struct batadv_orig_node *orig,
695 uint16_t tvlv_value_len)
697 bool orig_mcast_enabled = !(flags & BATADV_TVLV_HANDLER_OGM_CIFNOTFND);
698 uint8_t mcast_flags = BATADV_NO_FLAGS;
699 bool orig_initialized;
701 orig_initialized = test_bit(BATADV_ORIG_CAPA_HAS_MCAST,
702 &orig->capa_initialized);
704 /* If mcast support is turned on decrease the disabled mcast node
705 * counter only if we had increased it for this node before. If this
706 * is a completely new orig_node no need to decrease the counter.
708 if (orig_mcast_enabled &&
709 !test_bit(BATADV_ORIG_CAPA_HAS_MCAST, &orig->capabilities)) {
710 if (orig_initialized)
711 atomic_dec(&bat_priv->mcast.num_disabled);
712 set_bit(BATADV_ORIG_CAPA_HAS_MCAST, &orig->capabilities);
713 /* If mcast support is being switched off or if this is an initial
714 * OGM without mcast support then increase the disabled mcast
717 } else if (!orig_mcast_enabled &&
718 (test_bit(BATADV_ORIG_CAPA_HAS_MCAST, &orig->capabilities) ||
719 !orig_initialized)) {
720 atomic_inc(&bat_priv->mcast.num_disabled);
721 clear_bit(BATADV_ORIG_CAPA_HAS_MCAST, &orig->capabilities);
724 set_bit(BATADV_ORIG_CAPA_HAS_MCAST, &orig->capa_initialized);
726 if (orig_mcast_enabled && tvlv_value &&
727 (tvlv_value_len >= sizeof(mcast_flags)))
728 mcast_flags = *(uint8_t *)tvlv_value;
730 batadv_mcast_want_unsnoop_update(bat_priv, orig, mcast_flags);
731 batadv_mcast_want_ipv4_update(bat_priv, orig, mcast_flags);
732 batadv_mcast_want_ipv6_update(bat_priv, orig, mcast_flags);
734 orig->mcast_flags = mcast_flags;
738 * batadv_mcast_init - initialize the multicast optimizations structures
739 * @bat_priv: the bat priv with all the soft interface information
741 void batadv_mcast_init(struct batadv_priv *bat_priv)
743 batadv_tvlv_handler_register(bat_priv, batadv_mcast_tvlv_ogm_handler_v1,
744 NULL, BATADV_TVLV_MCAST, 1,
745 BATADV_TVLV_HANDLER_OGM_CIFNOTFND);
749 * batadv_mcast_free - free the multicast optimizations structures
750 * @bat_priv: the bat priv with all the soft interface information
752 void batadv_mcast_free(struct batadv_priv *bat_priv)
754 batadv_tvlv_container_unregister(bat_priv, BATADV_TVLV_MCAST, 1);
755 batadv_tvlv_handler_unregister(bat_priv, BATADV_TVLV_MCAST, 1);
757 batadv_mcast_mla_tt_retract(bat_priv, NULL);
761 * batadv_mcast_purge_orig - reset originator global mcast state modifications
762 * @orig: the originator which is going to get purged
764 void batadv_mcast_purge_orig(struct batadv_orig_node *orig)
766 struct batadv_priv *bat_priv = orig->bat_priv;
768 if (!test_bit(BATADV_ORIG_CAPA_HAS_MCAST, &orig->capabilities) &&
769 test_bit(BATADV_ORIG_CAPA_HAS_MCAST, &orig->capa_initialized))
770 atomic_dec(&bat_priv->mcast.num_disabled);
772 batadv_mcast_want_unsnoop_update(bat_priv, orig, BATADV_NO_FLAGS);
773 batadv_mcast_want_ipv4_update(bat_priv, orig, BATADV_NO_FLAGS);
774 batadv_mcast_want_ipv6_update(bat_priv, orig, BATADV_NO_FLAGS);