1 /* Copyright (C) 2014 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/>.
19 #include "multicast.h"
20 #include "originator.h"
21 #include "hard-interface.h"
22 #include "translation-table.h"
23 #include "multicast.h"
26 * batadv_mcast_mla_softif_get - get softif multicast listeners
27 * @dev: the device to collect multicast addresses from
28 * @mcast_list: a list to put found addresses into
30 * Collect multicast addresses of the local multicast listeners
31 * on the given soft interface, dev, in the given mcast_list.
33 * Returns -ENOMEM on memory allocation error or the number of
34 * items added to the mcast_list otherwise.
36 static int batadv_mcast_mla_softif_get(struct net_device
*dev
,
37 struct hlist_head
*mcast_list
)
39 struct netdev_hw_addr
*mc_list_entry
;
40 struct batadv_hw_addr
*new;
43 netif_addr_lock_bh(dev
);
44 netdev_for_each_mc_addr(mc_list_entry
, dev
) {
45 new = kmalloc(sizeof(*new), GFP_ATOMIC
);
51 ether_addr_copy(new->addr
, mc_list_entry
->addr
);
52 hlist_add_head(&new->list
, mcast_list
);
55 netif_addr_unlock_bh(dev
);
61 * batadv_mcast_mla_is_duplicate - check whether an address is in a list
62 * @mcast_addr: the multicast address to check
63 * @mcast_list: the list with multicast addresses to search in
65 * Returns true if the given address is already in the given list.
66 * Otherwise returns false.
68 static bool batadv_mcast_mla_is_duplicate(uint8_t *mcast_addr
,
69 struct hlist_head
*mcast_list
)
71 struct batadv_hw_addr
*mcast_entry
;
73 hlist_for_each_entry(mcast_entry
, mcast_list
, list
)
74 if (batadv_compare_eth(mcast_entry
->addr
, mcast_addr
))
81 * batadv_mcast_mla_list_free - free a list of multicast addresses
82 * @mcast_list: the list to free
84 * Removes and frees all items in the given mcast_list.
86 static void batadv_mcast_mla_list_free(struct hlist_head
*mcast_list
)
88 struct batadv_hw_addr
*mcast_entry
;
89 struct hlist_node
*tmp
;
91 hlist_for_each_entry_safe(mcast_entry
, tmp
, mcast_list
, list
) {
92 hlist_del(&mcast_entry
->list
);
98 * batadv_mcast_mla_tt_retract - clean up multicast listener announcements
99 * @bat_priv: the bat priv with all the soft interface information
100 * @mcast_list: a list of addresses which should _not_ be removed
102 * Retracts the announcement of any multicast listener from the
103 * translation table except the ones listed in the given mcast_list.
105 * If mcast_list is NULL then all are retracted.
107 static void batadv_mcast_mla_tt_retract(struct batadv_priv
*bat_priv
,
108 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
, &bat_priv
->mcast
.mla_list
,
116 batadv_mcast_mla_is_duplicate(mcast_entry
->addr
,
120 batadv_tt_local_remove(bat_priv
, mcast_entry
->addr
,
122 "mcast TT outdated", false);
124 hlist_del(&mcast_entry
->list
);
130 * batadv_mcast_mla_tt_add - add multicast listener announcements
131 * @bat_priv: the bat priv with all the soft interface information
132 * @mcast_list: a list of addresses which are going to get added
134 * Adds multicast listener announcements from the given mcast_list to the
135 * translation table if they have not been added yet.
137 static void batadv_mcast_mla_tt_add(struct batadv_priv
*bat_priv
,
138 struct hlist_head
*mcast_list
)
140 struct batadv_hw_addr
*mcast_entry
;
141 struct hlist_node
*tmp
;
146 hlist_for_each_entry_safe(mcast_entry
, tmp
, mcast_list
, list
) {
147 if (batadv_mcast_mla_is_duplicate(mcast_entry
->addr
,
148 &bat_priv
->mcast
.mla_list
))
151 if (!batadv_tt_local_add(bat_priv
->soft_iface
,
152 mcast_entry
->addr
, BATADV_NO_FLAGS
,
153 BATADV_NULL_IFINDEX
, BATADV_NO_MARK
))
156 hlist_del(&mcast_entry
->list
);
157 hlist_add_head(&mcast_entry
->list
, &bat_priv
->mcast
.mla_list
);
162 * batadv_mcast_has_bridge - check whether the soft-iface is bridged
163 * @bat_priv: the bat priv with all the soft interface information
165 * Checks whether there is a bridge on top of our soft interface. Returns
166 * true if so, false otherwise.
168 static bool batadv_mcast_has_bridge(struct batadv_priv
*bat_priv
)
170 struct net_device
*upper
= bat_priv
->soft_iface
;
174 upper
= netdev_master_upper_dev_get_rcu(upper
);
175 } while (upper
&& !(upper
->priv_flags
& IFF_EBRIDGE
));
182 * batadv_mcast_mla_tvlv_update - update multicast tvlv
183 * @bat_priv: the bat priv with all the soft interface information
185 * Updates the own multicast tvlv with our current multicast related settings,
186 * capabilities and inabilities.
188 * Returns true if the tvlv container is registered afterwards. Otherwise
191 static bool batadv_mcast_mla_tvlv_update(struct batadv_priv
*bat_priv
)
193 struct batadv_tvlv_mcast_data mcast_data
;
195 mcast_data
.flags
= BATADV_NO_FLAGS
;
196 memset(mcast_data
.reserved
, 0, sizeof(mcast_data
.reserved
));
198 /* Avoid attaching MLAs, if there is a bridge on top of our soft
199 * interface, we don't support that yet (TODO)
201 if (batadv_mcast_has_bridge(bat_priv
)) {
202 if (bat_priv
->mcast
.enabled
) {
203 batadv_tvlv_container_unregister(bat_priv
,
204 BATADV_TVLV_MCAST
, 1);
205 bat_priv
->mcast
.enabled
= false;
211 if (!bat_priv
->mcast
.enabled
||
212 mcast_data
.flags
!= bat_priv
->mcast
.flags
) {
213 batadv_tvlv_container_register(bat_priv
, BATADV_TVLV_MCAST
, 1,
214 &mcast_data
, sizeof(mcast_data
));
215 bat_priv
->mcast
.flags
= mcast_data
.flags
;
216 bat_priv
->mcast
.enabled
= true;
223 * batadv_mcast_mla_update - update the own MLAs
224 * @bat_priv: the bat priv with all the soft interface information
226 * Updates the own multicast listener announcements in the translation
227 * table as well as the own, announced multicast tvlv container.
229 void batadv_mcast_mla_update(struct batadv_priv
*bat_priv
)
231 struct net_device
*soft_iface
= bat_priv
->soft_iface
;
232 struct hlist_head mcast_list
= HLIST_HEAD_INIT
;
235 if (!batadv_mcast_mla_tvlv_update(bat_priv
))
238 ret
= batadv_mcast_mla_softif_get(soft_iface
, &mcast_list
);
243 batadv_mcast_mla_tt_retract(bat_priv
, &mcast_list
);
244 batadv_mcast_mla_tt_add(bat_priv
, &mcast_list
);
247 batadv_mcast_mla_list_free(&mcast_list
);
251 * batadv_mcast_forw_mode_check_ipv4 - check for optimized forwarding potential
252 * @bat_priv: the bat priv with all the soft interface information
253 * @skb: the IPv4 packet to check
254 * @is_unsnoopable: stores whether the destination is snoopable
256 * Checks whether the given IPv4 packet has the potential to be forwarded with a
257 * mode more optimal than classic flooding.
259 * If so then returns 0. Otherwise -EINVAL is returned or -ENOMEM in case of
260 * memory allocation failure.
262 static int batadv_mcast_forw_mode_check_ipv4(struct batadv_priv
*bat_priv
,
264 bool *is_unsnoopable
)
268 /* We might fail due to out-of-memory -> drop it */
269 if (!pskb_may_pull(skb
, sizeof(struct ethhdr
) + sizeof(*iphdr
)))
274 /* TODO: Implement Multicast Router Discovery (RFC4286),
275 * then allow scope > link local, too
277 if (!ipv4_is_local_multicast(iphdr
->daddr
))
280 /* link-local multicast listeners behind a bridge are
281 * not snoopable (see RFC4541, section 2.1.2.2)
283 *is_unsnoopable
= true;
289 * batadv_mcast_forw_mode_check_ipv6 - check for optimized forwarding potential
290 * @bat_priv: the bat priv with all the soft interface information
291 * @skb: the IPv6 packet to check
292 * @is_unsnoopable: stores whether the destination is snoopable
294 * Checks whether the given IPv6 packet has the potential to be forwarded with a
295 * mode more optimal than classic flooding.
297 * If so then returns 0. Otherwise -EINVAL is returned or -ENOMEM if we are out
300 static int batadv_mcast_forw_mode_check_ipv6(struct batadv_priv
*bat_priv
,
302 bool *is_unsnoopable
)
304 struct ipv6hdr
*ip6hdr
;
306 /* We might fail due to out-of-memory -> drop it */
307 if (!pskb_may_pull(skb
, sizeof(struct ethhdr
) + sizeof(*ip6hdr
)))
310 ip6hdr
= ipv6_hdr(skb
);
312 /* TODO: Implement Multicast Router Discovery (RFC4286),
313 * then allow scope > link local, too
315 if (IPV6_ADDR_MC_SCOPE(&ip6hdr
->daddr
) != IPV6_ADDR_SCOPE_LINKLOCAL
)
318 /* link-local-all-nodes multicast listeners behind a bridge are
319 * not snoopable (see RFC4541, section 3, paragraph 3)
321 if (ipv6_addr_is_ll_all_nodes(&ip6hdr
->daddr
))
322 *is_unsnoopable
= true;
328 * batadv_mcast_forw_mode_check - check for optimized forwarding potential
329 * @bat_priv: the bat priv with all the soft interface information
330 * @skb: the multicast frame to check
331 * @is_unsnoopable: stores whether the destination is snoopable
333 * Checks whether the given multicast ethernet frame has the potential to be
334 * forwarded with a mode more optimal than classic flooding.
336 * If so then returns 0. Otherwise -EINVAL is returned or -ENOMEM if we are out
339 static int batadv_mcast_forw_mode_check(struct batadv_priv
*bat_priv
,
341 bool *is_unsnoopable
)
343 struct ethhdr
*ethhdr
= eth_hdr(skb
);
345 if (!atomic_read(&bat_priv
->multicast_mode
))
348 if (atomic_read(&bat_priv
->mcast
.num_disabled
))
351 switch (ntohs(ethhdr
->h_proto
)) {
353 return batadv_mcast_forw_mode_check_ipv4(bat_priv
, skb
,
356 return batadv_mcast_forw_mode_check_ipv6(bat_priv
, skb
,
364 * batadv_mcast_want_all_ip_count - count nodes with unspecific mcast interest
365 * @bat_priv: the bat priv with all the soft interface information
366 * @ethhdr: ethernet header of a packet
368 * Returns the number of nodes which want all IPv4 multicast traffic if the
369 * given ethhdr is from an IPv4 packet or the number of nodes which want all
370 * IPv6 traffic if it matches an IPv6 packet.
372 static int batadv_mcast_forw_want_all_ip_count(struct batadv_priv
*bat_priv
,
373 struct ethhdr
*ethhdr
)
375 switch (ntohs(ethhdr
->h_proto
)) {
377 return atomic_read(&bat_priv
->mcast
.num_want_all_ipv4
);
379 return atomic_read(&bat_priv
->mcast
.num_want_all_ipv6
);
381 /* we shouldn't be here... */
387 * batadv_mcast_forw_tt_node_get - get a multicast tt node
388 * @bat_priv: the bat priv with all the soft interface information
389 * @ethhdr: the ether header containing the multicast destination
391 * Returns an orig_node matching the multicast address provided by ethhdr
392 * via a translation table lookup. This increases the returned nodes refcount.
394 static struct batadv_orig_node
*
395 batadv_mcast_forw_tt_node_get(struct batadv_priv
*bat_priv
,
396 struct ethhdr
*ethhdr
)
398 return batadv_transtable_search(bat_priv
, ethhdr
->h_source
,
399 ethhdr
->h_dest
, BATADV_NO_FLAGS
);
403 * batadv_mcast_want_forw_ipv4_node_get - get a node with an ipv4 flag
404 * @bat_priv: the bat priv with all the soft interface information
406 * Returns an orig_node which has the BATADV_MCAST_WANT_ALL_IPV4 flag set and
407 * increases its refcount.
409 static struct batadv_orig_node
*
410 batadv_mcast_forw_ipv4_node_get(struct batadv_priv
*bat_priv
)
412 struct batadv_orig_node
*tmp_orig_node
, *orig_node
= NULL
;
415 hlist_for_each_entry_rcu(tmp_orig_node
,
416 &bat_priv
->mcast
.want_all_ipv4_list
,
417 mcast_want_all_ipv4_node
) {
418 if (!atomic_inc_not_zero(&tmp_orig_node
->refcount
))
421 orig_node
= tmp_orig_node
;
430 * batadv_mcast_want_forw_ipv6_node_get - get a node with an ipv6 flag
431 * @bat_priv: the bat priv with all the soft interface information
433 * Returns an orig_node which has the BATADV_MCAST_WANT_ALL_IPV6 flag set
434 * and increases its refcount.
436 static struct batadv_orig_node
*
437 batadv_mcast_forw_ipv6_node_get(struct batadv_priv
*bat_priv
)
439 struct batadv_orig_node
*tmp_orig_node
, *orig_node
= NULL
;
442 hlist_for_each_entry_rcu(tmp_orig_node
,
443 &bat_priv
->mcast
.want_all_ipv6_list
,
444 mcast_want_all_ipv6_node
) {
445 if (!atomic_inc_not_zero(&tmp_orig_node
->refcount
))
448 orig_node
= tmp_orig_node
;
457 * batadv_mcast_want_forw_ip_node_get - get a node with an ipv4/ipv6 flag
458 * @bat_priv: the bat priv with all the soft interface information
459 * @ethhdr: an ethernet header to determine the protocol family from
461 * Returns an orig_node which has the BATADV_MCAST_WANT_ALL_IPV4 or
462 * BATADV_MCAST_WANT_ALL_IPV6 flag, depending on the provided ethhdr, set and
463 * increases its refcount.
465 static struct batadv_orig_node
*
466 batadv_mcast_forw_ip_node_get(struct batadv_priv
*bat_priv
,
467 struct ethhdr
*ethhdr
)
469 switch (ntohs(ethhdr
->h_proto
)) {
471 return batadv_mcast_forw_ipv4_node_get(bat_priv
);
473 return batadv_mcast_forw_ipv6_node_get(bat_priv
);
475 /* we shouldn't be here... */
481 * batadv_mcast_want_forw_unsnoop_node_get - get a node with an unsnoopable flag
482 * @bat_priv: the bat priv with all the soft interface information
484 * Returns an orig_node which has the BATADV_MCAST_WANT_ALL_UNSNOOPABLES flag
485 * set and increases its refcount.
487 static struct batadv_orig_node
*
488 batadv_mcast_forw_unsnoop_node_get(struct batadv_priv
*bat_priv
)
490 struct batadv_orig_node
*tmp_orig_node
, *orig_node
= NULL
;
493 hlist_for_each_entry_rcu(tmp_orig_node
,
494 &bat_priv
->mcast
.want_all_unsnoopables_list
,
495 mcast_want_all_unsnoopables_node
) {
496 if (!atomic_inc_not_zero(&tmp_orig_node
->refcount
))
499 orig_node
= tmp_orig_node
;
508 * batadv_mcast_forw_mode - check on how to forward a multicast packet
509 * @bat_priv: the bat priv with all the soft interface information
510 * @skb: The multicast packet to check
511 * @orig: an originator to be set to forward the skb to
513 * Returns the forwarding mode as enum batadv_forw_mode and in case of
514 * BATADV_FORW_SINGLE set the orig to the single originator the skb
515 * should be forwarded to.
517 enum batadv_forw_mode
518 batadv_mcast_forw_mode(struct batadv_priv
*bat_priv
, struct sk_buff
*skb
,
519 struct batadv_orig_node
**orig
)
521 int ret
, tt_count
, ip_count
, unsnoop_count
, total_count
;
522 bool is_unsnoopable
= false;
523 struct ethhdr
*ethhdr
;
525 ret
= batadv_mcast_forw_mode_check(bat_priv
, skb
, &is_unsnoopable
);
527 return BATADV_FORW_NONE
;
529 return BATADV_FORW_ALL
;
531 ethhdr
= eth_hdr(skb
);
533 tt_count
= batadv_tt_global_hash_count(bat_priv
, ethhdr
->h_dest
,
535 ip_count
= batadv_mcast_forw_want_all_ip_count(bat_priv
, ethhdr
);
536 unsnoop_count
= !is_unsnoopable
? 0 :
537 atomic_read(&bat_priv
->mcast
.num_want_all_unsnoopables
);
539 total_count
= tt_count
+ ip_count
+ unsnoop_count
;
541 switch (total_count
) {
544 *orig
= batadv_mcast_forw_tt_node_get(bat_priv
, ethhdr
);
546 *orig
= batadv_mcast_forw_ip_node_get(bat_priv
, ethhdr
);
547 else if (unsnoop_count
)
548 *orig
= batadv_mcast_forw_unsnoop_node_get(bat_priv
);
551 return BATADV_FORW_SINGLE
;
555 return BATADV_FORW_NONE
;
557 return BATADV_FORW_ALL
;
562 * batadv_mcast_want_unsnoop_update - update unsnoop counter and list
563 * @bat_priv: the bat priv with all the soft interface information
564 * @orig: the orig_node which multicast state might have changed of
565 * @mcast_flags: flags indicating the new multicast state
567 * If the BATADV_MCAST_WANT_ALL_UNSNOOPABLES flag of this originator,
568 * orig, has toggled then this method updates counter and list accordingly.
570 static void batadv_mcast_want_unsnoop_update(struct batadv_priv
*bat_priv
,
571 struct batadv_orig_node
*orig
,
574 /* switched from flag unset to set */
575 if (mcast_flags
& BATADV_MCAST_WANT_ALL_UNSNOOPABLES
&&
576 !(orig
->mcast_flags
& BATADV_MCAST_WANT_ALL_UNSNOOPABLES
)) {
577 atomic_inc(&bat_priv
->mcast
.num_want_all_unsnoopables
);
579 spin_lock_bh(&bat_priv
->mcast
.want_lists_lock
);
580 hlist_add_head_rcu(&orig
->mcast_want_all_unsnoopables_node
,
581 &bat_priv
->mcast
.want_all_unsnoopables_list
);
582 spin_unlock_bh(&bat_priv
->mcast
.want_lists_lock
);
583 /* switched from flag set to unset */
584 } else if (!(mcast_flags
& BATADV_MCAST_WANT_ALL_UNSNOOPABLES
) &&
585 orig
->mcast_flags
& BATADV_MCAST_WANT_ALL_UNSNOOPABLES
) {
586 atomic_dec(&bat_priv
->mcast
.num_want_all_unsnoopables
);
588 spin_lock_bh(&bat_priv
->mcast
.want_lists_lock
);
589 hlist_del_rcu(&orig
->mcast_want_all_unsnoopables_node
);
590 spin_unlock_bh(&bat_priv
->mcast
.want_lists_lock
);
595 * batadv_mcast_want_ipv4_update - update want-all-ipv4 counter and list
596 * @bat_priv: the bat priv with all the soft interface information
597 * @orig: the orig_node which multicast state might have changed of
598 * @mcast_flags: flags indicating the new multicast state
600 * If the BATADV_MCAST_WANT_ALL_IPV4 flag of this originator, orig, has
601 * toggled then this method updates counter and list accordingly.
603 static void batadv_mcast_want_ipv4_update(struct batadv_priv
*bat_priv
,
604 struct batadv_orig_node
*orig
,
607 /* switched from flag unset to set */
608 if (mcast_flags
& BATADV_MCAST_WANT_ALL_IPV4
&&
609 !(orig
->mcast_flags
& BATADV_MCAST_WANT_ALL_IPV4
)) {
610 atomic_inc(&bat_priv
->mcast
.num_want_all_ipv4
);
612 spin_lock_bh(&bat_priv
->mcast
.want_lists_lock
);
613 hlist_add_head_rcu(&orig
->mcast_want_all_ipv4_node
,
614 &bat_priv
->mcast
.want_all_ipv4_list
);
615 spin_unlock_bh(&bat_priv
->mcast
.want_lists_lock
);
616 /* switched from flag set to unset */
617 } else if (!(mcast_flags
& BATADV_MCAST_WANT_ALL_IPV4
) &&
618 orig
->mcast_flags
& BATADV_MCAST_WANT_ALL_IPV4
) {
619 atomic_dec(&bat_priv
->mcast
.num_want_all_ipv4
);
621 spin_lock_bh(&bat_priv
->mcast
.want_lists_lock
);
622 hlist_del_rcu(&orig
->mcast_want_all_ipv4_node
);
623 spin_unlock_bh(&bat_priv
->mcast
.want_lists_lock
);
628 * batadv_mcast_want_ipv6_update - update want-all-ipv6 counter and list
629 * @bat_priv: the bat priv with all the soft interface information
630 * @orig: the orig_node which multicast state might have changed of
631 * @mcast_flags: flags indicating the new multicast state
633 * If the BATADV_MCAST_WANT_ALL_IPV6 flag of this originator, orig, has
634 * toggled then this method updates counter and list accordingly.
636 static void batadv_mcast_want_ipv6_update(struct batadv_priv
*bat_priv
,
637 struct batadv_orig_node
*orig
,
640 /* switched from flag unset to set */
641 if (mcast_flags
& BATADV_MCAST_WANT_ALL_IPV6
&&
642 !(orig
->mcast_flags
& BATADV_MCAST_WANT_ALL_IPV6
)) {
643 atomic_inc(&bat_priv
->mcast
.num_want_all_ipv6
);
645 spin_lock_bh(&bat_priv
->mcast
.want_lists_lock
);
646 hlist_add_head_rcu(&orig
->mcast_want_all_ipv6_node
,
647 &bat_priv
->mcast
.want_all_ipv6_list
);
648 spin_unlock_bh(&bat_priv
->mcast
.want_lists_lock
);
649 /* switched from flag set to unset */
650 } else if (!(mcast_flags
& BATADV_MCAST_WANT_ALL_IPV6
) &&
651 orig
->mcast_flags
& BATADV_MCAST_WANT_ALL_IPV6
) {
652 atomic_dec(&bat_priv
->mcast
.num_want_all_ipv6
);
654 spin_lock_bh(&bat_priv
->mcast
.want_lists_lock
);
655 hlist_del_rcu(&orig
->mcast_want_all_ipv6_node
);
656 spin_unlock_bh(&bat_priv
->mcast
.want_lists_lock
);
661 * batadv_mcast_tvlv_ogm_handler_v1 - process incoming multicast tvlv container
662 * @bat_priv: the bat priv with all the soft interface information
663 * @orig: the orig_node of the ogm
664 * @flags: flags indicating the tvlv state (see batadv_tvlv_handler_flags)
665 * @tvlv_value: tvlv buffer containing the multicast data
666 * @tvlv_value_len: tvlv buffer length
668 static void batadv_mcast_tvlv_ogm_handler_v1(struct batadv_priv
*bat_priv
,
669 struct batadv_orig_node
*orig
,
672 uint16_t tvlv_value_len
)
674 bool orig_mcast_enabled
= !(flags
& BATADV_TVLV_HANDLER_OGM_CIFNOTFND
);
675 uint8_t mcast_flags
= BATADV_NO_FLAGS
;
676 bool orig_initialized
;
678 orig_initialized
= orig
->capa_initialized
& BATADV_ORIG_CAPA_HAS_MCAST
;
680 /* If mcast support is turned on decrease the disabled mcast node
681 * counter only if we had increased it for this node before. If this
682 * is a completely new orig_node no need to decrease the counter.
684 if (orig_mcast_enabled
&&
685 !(orig
->capabilities
& BATADV_ORIG_CAPA_HAS_MCAST
)) {
686 if (orig_initialized
)
687 atomic_dec(&bat_priv
->mcast
.num_disabled
);
688 orig
->capabilities
|= BATADV_ORIG_CAPA_HAS_MCAST
;
689 /* If mcast support is being switched off increase the disabled
690 * mcast node counter.
692 } else if (!orig_mcast_enabled
&&
693 orig
->capabilities
& BATADV_ORIG_CAPA_HAS_MCAST
) {
694 atomic_inc(&bat_priv
->mcast
.num_disabled
);
695 orig
->capabilities
&= ~BATADV_ORIG_CAPA_HAS_MCAST
;
698 orig
->capa_initialized
|= BATADV_ORIG_CAPA_HAS_MCAST
;
700 if (orig_mcast_enabled
&& tvlv_value
&&
701 (tvlv_value_len
>= sizeof(mcast_flags
)))
702 mcast_flags
= *(uint8_t *)tvlv_value
;
704 batadv_mcast_want_unsnoop_update(bat_priv
, orig
, mcast_flags
);
705 batadv_mcast_want_ipv4_update(bat_priv
, orig
, mcast_flags
);
706 batadv_mcast_want_ipv6_update(bat_priv
, orig
, mcast_flags
);
708 orig
->mcast_flags
= mcast_flags
;
712 * batadv_mcast_init - initialize the multicast optimizations structures
713 * @bat_priv: the bat priv with all the soft interface information
715 void batadv_mcast_init(struct batadv_priv
*bat_priv
)
717 batadv_tvlv_handler_register(bat_priv
, batadv_mcast_tvlv_ogm_handler_v1
,
718 NULL
, BATADV_TVLV_MCAST
, 1,
719 BATADV_TVLV_HANDLER_OGM_CIFNOTFND
);
723 * batadv_mcast_free - free the multicast optimizations structures
724 * @bat_priv: the bat priv with all the soft interface information
726 void batadv_mcast_free(struct batadv_priv
*bat_priv
)
728 batadv_tvlv_container_unregister(bat_priv
, BATADV_TVLV_MCAST
, 1);
729 batadv_tvlv_handler_unregister(bat_priv
, BATADV_TVLV_MCAST
, 1);
731 batadv_mcast_mla_tt_retract(bat_priv
, NULL
);
735 * batadv_mcast_purge_orig - reset originator global mcast state modifications
736 * @orig: the originator which is going to get purged
738 void batadv_mcast_purge_orig(struct batadv_orig_node
*orig
)
740 struct batadv_priv
*bat_priv
= orig
->bat_priv
;
742 if (!(orig
->capabilities
& BATADV_ORIG_CAPA_HAS_MCAST
))
743 atomic_dec(&bat_priv
->mcast
.num_disabled
);
745 batadv_mcast_want_unsnoop_update(bat_priv
, orig
, BATADV_NO_FLAGS
);
746 batadv_mcast_want_ipv4_update(bat_priv
, orig
, BATADV_NO_FLAGS
);
747 batadv_mcast_want_ipv6_update(bat_priv
, orig
, BATADV_NO_FLAGS
);