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"
25 * batadv_mcast_mla_softif_get - get softif multicast listeners
26 * @dev: the device to collect multicast addresses from
27 * @mcast_list: a list to put found addresses into
29 * Collect multicast addresses of the local multicast listeners
30 * on the given soft interface, dev, in the given mcast_list.
32 * Returns -ENOMEM on memory allocation error or the number of
33 * items added to the mcast_list otherwise.
35 static int batadv_mcast_mla_softif_get(struct net_device
*dev
,
36 struct hlist_head
*mcast_list
)
38 struct netdev_hw_addr
*mc_list_entry
;
39 struct batadv_hw_addr
*new;
42 netif_addr_lock_bh(dev
);
43 netdev_for_each_mc_addr(mc_list_entry
, dev
) {
44 new = kmalloc(sizeof(*new), GFP_ATOMIC
);
50 ether_addr_copy(new->addr
, mc_list_entry
->addr
);
51 hlist_add_head(&new->list
, mcast_list
);
54 netif_addr_unlock_bh(dev
);
60 * batadv_mcast_mla_is_duplicate - check whether an address is in a list
61 * @mcast_addr: the multicast address to check
62 * @mcast_list: the list with multicast addresses to search in
64 * Returns true if the given address is already in the given list.
65 * Otherwise returns false.
67 static bool batadv_mcast_mla_is_duplicate(uint8_t *mcast_addr
,
68 struct hlist_head
*mcast_list
)
70 struct batadv_hw_addr
*mcast_entry
;
72 hlist_for_each_entry(mcast_entry
, mcast_list
, list
)
73 if (batadv_compare_eth(mcast_entry
->addr
, mcast_addr
))
80 * batadv_mcast_mla_list_free - free a list of multicast addresses
81 * @mcast_list: the list to free
83 * Removes and frees all items in the given mcast_list.
85 static void batadv_mcast_mla_list_free(struct hlist_head
*mcast_list
)
87 struct batadv_hw_addr
*mcast_entry
;
88 struct hlist_node
*tmp
;
90 hlist_for_each_entry_safe(mcast_entry
, tmp
, mcast_list
, list
) {
91 hlist_del(&mcast_entry
->list
);
97 * batadv_mcast_mla_tt_retract - clean up multicast listener announcements
98 * @bat_priv: the bat priv with all the soft interface information
99 * @mcast_list: a list of addresses which should _not_ be removed
101 * Retracts the announcement of any multicast listener from the
102 * translation table except the ones listed in the given mcast_list.
104 * If mcast_list is NULL then all are retracted.
106 static void batadv_mcast_mla_tt_retract(struct batadv_priv
*bat_priv
,
107 struct hlist_head
*mcast_list
)
109 struct batadv_hw_addr
*mcast_entry
;
110 struct hlist_node
*tmp
;
112 hlist_for_each_entry_safe(mcast_entry
, tmp
, &bat_priv
->mcast
.mla_list
,
115 batadv_mcast_mla_is_duplicate(mcast_entry
->addr
,
119 batadv_tt_local_remove(bat_priv
, mcast_entry
->addr
,
121 "mcast TT outdated", false);
123 hlist_del(&mcast_entry
->list
);
129 * batadv_mcast_mla_tt_add - add multicast listener announcements
130 * @bat_priv: the bat priv with all the soft interface information
131 * @mcast_list: a list of addresses which are going to get added
133 * Adds multicast listener announcements from the given mcast_list to the
134 * translation table if they have not been added yet.
136 static void batadv_mcast_mla_tt_add(struct batadv_priv
*bat_priv
,
137 struct hlist_head
*mcast_list
)
139 struct batadv_hw_addr
*mcast_entry
;
140 struct hlist_node
*tmp
;
145 hlist_for_each_entry_safe(mcast_entry
, tmp
, mcast_list
, list
) {
146 if (batadv_mcast_mla_is_duplicate(mcast_entry
->addr
,
147 &bat_priv
->mcast
.mla_list
))
150 if (!batadv_tt_local_add(bat_priv
->soft_iface
,
151 mcast_entry
->addr
, BATADV_NO_FLAGS
,
152 BATADV_NULL_IFINDEX
, BATADV_NO_MARK
))
155 hlist_del(&mcast_entry
->list
);
156 hlist_add_head(&mcast_entry
->list
, &bat_priv
->mcast
.mla_list
);
161 * batadv_mcast_has_bridge - check whether the soft-iface is bridged
162 * @bat_priv: the bat priv with all the soft interface information
164 * Checks whether there is a bridge on top of our soft interface. Returns
165 * true if so, false otherwise.
167 static bool batadv_mcast_has_bridge(struct batadv_priv
*bat_priv
)
169 struct net_device
*upper
= bat_priv
->soft_iface
;
173 upper
= netdev_master_upper_dev_get_rcu(upper
);
174 } while (upper
&& !(upper
->priv_flags
& IFF_EBRIDGE
));
181 * batadv_mcast_mla_tvlv_update - update multicast tvlv
182 * @bat_priv: the bat priv with all the soft interface information
184 * Updates the own multicast tvlv with our current multicast related settings,
185 * capabilities and inabilities.
187 * Returns true if the tvlv container is registered afterwards. Otherwise
190 static bool batadv_mcast_mla_tvlv_update(struct batadv_priv
*bat_priv
)
192 struct batadv_tvlv_mcast_data mcast_data
;
194 mcast_data
.flags
= BATADV_NO_FLAGS
;
195 memset(mcast_data
.reserved
, 0, sizeof(mcast_data
.reserved
));
197 /* Avoid attaching MLAs, if there is a bridge on top of our soft
198 * interface, we don't support that yet (TODO)
200 if (batadv_mcast_has_bridge(bat_priv
)) {
201 if (bat_priv
->mcast
.enabled
) {
202 batadv_tvlv_container_unregister(bat_priv
,
203 BATADV_TVLV_MCAST
, 1);
204 bat_priv
->mcast
.enabled
= false;
210 if (!bat_priv
->mcast
.enabled
||
211 mcast_data
.flags
!= bat_priv
->mcast
.flags
) {
212 batadv_tvlv_container_register(bat_priv
, BATADV_TVLV_MCAST
, 1,
213 &mcast_data
, sizeof(mcast_data
));
214 bat_priv
->mcast
.flags
= mcast_data
.flags
;
215 bat_priv
->mcast
.enabled
= true;
222 * batadv_mcast_mla_update - update the own MLAs
223 * @bat_priv: the bat priv with all the soft interface information
225 * Updates the own multicast listener announcements in the translation
226 * table as well as the own, announced multicast tvlv container.
228 void batadv_mcast_mla_update(struct batadv_priv
*bat_priv
)
230 struct net_device
*soft_iface
= bat_priv
->soft_iface
;
231 struct hlist_head mcast_list
= HLIST_HEAD_INIT
;
234 if (!batadv_mcast_mla_tvlv_update(bat_priv
))
237 ret
= batadv_mcast_mla_softif_get(soft_iface
, &mcast_list
);
242 batadv_mcast_mla_tt_retract(bat_priv
, &mcast_list
);
243 batadv_mcast_mla_tt_add(bat_priv
, &mcast_list
);
246 batadv_mcast_mla_list_free(&mcast_list
);
250 * batadv_mcast_forw_mode_check_ipv4 - check for optimized forwarding potential
251 * @bat_priv: the bat priv with all the soft interface information
252 * @skb: the IPv4 packet to check
253 * @is_unsnoopable: stores whether the destination is snoopable
255 * Checks whether the given IPv4 packet has the potential to be forwarded with a
256 * mode more optimal than classic flooding.
258 * If so then returns 0. Otherwise -EINVAL is returned or -ENOMEM in case of
259 * memory allocation failure.
261 static int batadv_mcast_forw_mode_check_ipv4(struct batadv_priv
*bat_priv
,
263 bool *is_unsnoopable
)
267 /* We might fail due to out-of-memory -> drop it */
268 if (!pskb_may_pull(skb
, sizeof(struct ethhdr
) + sizeof(*iphdr
)))
273 /* TODO: Implement Multicast Router Discovery (RFC4286),
274 * then allow scope > link local, too
276 if (!ipv4_is_local_multicast(iphdr
->daddr
))
279 /* link-local multicast listeners behind a bridge are
280 * not snoopable (see RFC4541, section 2.1.2.2)
282 *is_unsnoopable
= true;
288 * batadv_mcast_forw_mode_check_ipv6 - check for optimized forwarding potential
289 * @bat_priv: the bat priv with all the soft interface information
290 * @skb: the IPv6 packet to check
291 * @is_unsnoopable: stores whether the destination is snoopable
293 * Checks whether the given IPv6 packet has the potential to be forwarded with a
294 * mode more optimal than classic flooding.
296 * If so then returns 0. Otherwise -EINVAL is returned or -ENOMEM if we are out
299 static int batadv_mcast_forw_mode_check_ipv6(struct batadv_priv
*bat_priv
,
301 bool *is_unsnoopable
)
303 struct ipv6hdr
*ip6hdr
;
305 /* We might fail due to out-of-memory -> drop it */
306 if (!pskb_may_pull(skb
, sizeof(struct ethhdr
) + sizeof(*ip6hdr
)))
309 ip6hdr
= ipv6_hdr(skb
);
311 /* TODO: Implement Multicast Router Discovery (RFC4286),
312 * then allow scope > link local, too
314 if (IPV6_ADDR_MC_SCOPE(&ip6hdr
->daddr
) != IPV6_ADDR_SCOPE_LINKLOCAL
)
317 /* link-local-all-nodes multicast listeners behind a bridge are
318 * not snoopable (see RFC4541, section 3, paragraph 3)
320 if (ipv6_addr_is_ll_all_nodes(&ip6hdr
->daddr
))
321 *is_unsnoopable
= true;
327 * batadv_mcast_forw_mode_check - check for optimized forwarding potential
328 * @bat_priv: the bat priv with all the soft interface information
329 * @skb: the multicast frame to check
330 * @is_unsnoopable: stores whether the destination is snoopable
332 * Checks whether the given multicast ethernet frame has the potential to be
333 * forwarded with a mode more optimal than classic flooding.
335 * If so then returns 0. Otherwise -EINVAL is returned or -ENOMEM if we are out
338 static int batadv_mcast_forw_mode_check(struct batadv_priv
*bat_priv
,
340 bool *is_unsnoopable
)
342 struct ethhdr
*ethhdr
= eth_hdr(skb
);
344 if (!atomic_read(&bat_priv
->multicast_mode
))
347 if (atomic_read(&bat_priv
->mcast
.num_disabled
))
350 switch (ntohs(ethhdr
->h_proto
)) {
352 return batadv_mcast_forw_mode_check_ipv4(bat_priv
, skb
,
355 return batadv_mcast_forw_mode_check_ipv6(bat_priv
, skb
,
363 * batadv_mcast_want_all_ip_count - count nodes with unspecific mcast interest
364 * @bat_priv: the bat priv with all the soft interface information
365 * @ethhdr: ethernet header of a packet
367 * Returns the number of nodes which want all IPv4 multicast traffic if the
368 * given ethhdr is from an IPv4 packet or the number of nodes which want all
369 * IPv6 traffic if it matches an IPv6 packet.
371 static int batadv_mcast_forw_want_all_ip_count(struct batadv_priv
*bat_priv
,
372 struct ethhdr
*ethhdr
)
374 switch (ntohs(ethhdr
->h_proto
)) {
376 return atomic_read(&bat_priv
->mcast
.num_want_all_ipv4
);
378 return atomic_read(&bat_priv
->mcast
.num_want_all_ipv6
);
380 /* we shouldn't be here... */
386 * batadv_mcast_forw_tt_node_get - get a multicast tt node
387 * @bat_priv: the bat priv with all the soft interface information
388 * @ethhdr: the ether header containing the multicast destination
390 * Returns an orig_node matching the multicast address provided by ethhdr
391 * via a translation table lookup. This increases the returned nodes refcount.
393 static struct batadv_orig_node
*
394 batadv_mcast_forw_tt_node_get(struct batadv_priv
*bat_priv
,
395 struct ethhdr
*ethhdr
)
397 return batadv_transtable_search(bat_priv
, ethhdr
->h_source
,
398 ethhdr
->h_dest
, BATADV_NO_FLAGS
);
402 * batadv_mcast_want_forw_ipv4_node_get - get a node with an ipv4 flag
403 * @bat_priv: the bat priv with all the soft interface information
405 * Returns an orig_node which has the BATADV_MCAST_WANT_ALL_IPV4 flag set and
406 * increases its refcount.
408 static struct batadv_orig_node
*
409 batadv_mcast_forw_ipv4_node_get(struct batadv_priv
*bat_priv
)
411 struct batadv_orig_node
*tmp_orig_node
, *orig_node
= NULL
;
414 hlist_for_each_entry_rcu(tmp_orig_node
,
415 &bat_priv
->mcast
.want_all_ipv4_list
,
416 mcast_want_all_ipv4_node
) {
417 if (!atomic_inc_not_zero(&tmp_orig_node
->refcount
))
420 orig_node
= tmp_orig_node
;
429 * batadv_mcast_want_forw_ipv6_node_get - get a node with an ipv6 flag
430 * @bat_priv: the bat priv with all the soft interface information
432 * Returns an orig_node which has the BATADV_MCAST_WANT_ALL_IPV6 flag set
433 * and increases its refcount.
435 static struct batadv_orig_node
*
436 batadv_mcast_forw_ipv6_node_get(struct batadv_priv
*bat_priv
)
438 struct batadv_orig_node
*tmp_orig_node
, *orig_node
= NULL
;
441 hlist_for_each_entry_rcu(tmp_orig_node
,
442 &bat_priv
->mcast
.want_all_ipv6_list
,
443 mcast_want_all_ipv6_node
) {
444 if (!atomic_inc_not_zero(&tmp_orig_node
->refcount
))
447 orig_node
= tmp_orig_node
;
456 * batadv_mcast_want_forw_ip_node_get - get a node with an ipv4/ipv6 flag
457 * @bat_priv: the bat priv with all the soft interface information
458 * @ethhdr: an ethernet header to determine the protocol family from
460 * Returns an orig_node which has the BATADV_MCAST_WANT_ALL_IPV4 or
461 * BATADV_MCAST_WANT_ALL_IPV6 flag, depending on the provided ethhdr, set and
462 * increases its refcount.
464 static struct batadv_orig_node
*
465 batadv_mcast_forw_ip_node_get(struct batadv_priv
*bat_priv
,
466 struct ethhdr
*ethhdr
)
468 switch (ntohs(ethhdr
->h_proto
)) {
470 return batadv_mcast_forw_ipv4_node_get(bat_priv
);
472 return batadv_mcast_forw_ipv6_node_get(bat_priv
);
474 /* we shouldn't be here... */
480 * batadv_mcast_want_forw_unsnoop_node_get - get a node with an unsnoopable flag
481 * @bat_priv: the bat priv with all the soft interface information
483 * Returns an orig_node which has the BATADV_MCAST_WANT_ALL_UNSNOOPABLES flag
484 * set and increases its refcount.
486 static struct batadv_orig_node
*
487 batadv_mcast_forw_unsnoop_node_get(struct batadv_priv
*bat_priv
)
489 struct batadv_orig_node
*tmp_orig_node
, *orig_node
= NULL
;
492 hlist_for_each_entry_rcu(tmp_orig_node
,
493 &bat_priv
->mcast
.want_all_unsnoopables_list
,
494 mcast_want_all_unsnoopables_node
) {
495 if (!atomic_inc_not_zero(&tmp_orig_node
->refcount
))
498 orig_node
= tmp_orig_node
;
507 * batadv_mcast_forw_mode - check on how to forward a multicast packet
508 * @bat_priv: the bat priv with all the soft interface information
509 * @skb: The multicast packet to check
510 * @orig: an originator to be set to forward the skb to
512 * Returns the forwarding mode as enum batadv_forw_mode and in case of
513 * BATADV_FORW_SINGLE set the orig to the single originator the skb
514 * should be forwarded to.
516 enum batadv_forw_mode
517 batadv_mcast_forw_mode(struct batadv_priv
*bat_priv
, struct sk_buff
*skb
,
518 struct batadv_orig_node
**orig
)
520 int ret
, tt_count
, ip_count
, unsnoop_count
, total_count
;
521 bool is_unsnoopable
= false;
522 struct ethhdr
*ethhdr
;
524 ret
= batadv_mcast_forw_mode_check(bat_priv
, skb
, &is_unsnoopable
);
526 return BATADV_FORW_NONE
;
528 return BATADV_FORW_ALL
;
530 ethhdr
= eth_hdr(skb
);
532 tt_count
= batadv_tt_global_hash_count(bat_priv
, ethhdr
->h_dest
,
534 ip_count
= batadv_mcast_forw_want_all_ip_count(bat_priv
, ethhdr
);
535 unsnoop_count
= !is_unsnoopable
? 0 :
536 atomic_read(&bat_priv
->mcast
.num_want_all_unsnoopables
);
538 total_count
= tt_count
+ ip_count
+ unsnoop_count
;
540 switch (total_count
) {
543 *orig
= batadv_mcast_forw_tt_node_get(bat_priv
, ethhdr
);
545 *orig
= batadv_mcast_forw_ip_node_get(bat_priv
, ethhdr
);
546 else if (unsnoop_count
)
547 *orig
= batadv_mcast_forw_unsnoop_node_get(bat_priv
);
550 return BATADV_FORW_SINGLE
;
554 return BATADV_FORW_NONE
;
556 return BATADV_FORW_ALL
;
561 * batadv_mcast_want_unsnoop_update - update unsnoop counter and list
562 * @bat_priv: the bat priv with all the soft interface information
563 * @orig: the orig_node which multicast state might have changed of
564 * @mcast_flags: flags indicating the new multicast state
566 * If the BATADV_MCAST_WANT_ALL_UNSNOOPABLES flag of this originator,
567 * orig, has toggled then this method updates counter and list accordingly.
569 static void batadv_mcast_want_unsnoop_update(struct batadv_priv
*bat_priv
,
570 struct batadv_orig_node
*orig
,
573 /* switched from flag unset to set */
574 if (mcast_flags
& BATADV_MCAST_WANT_ALL_UNSNOOPABLES
&&
575 !(orig
->mcast_flags
& BATADV_MCAST_WANT_ALL_UNSNOOPABLES
)) {
576 atomic_inc(&bat_priv
->mcast
.num_want_all_unsnoopables
);
578 spin_lock_bh(&bat_priv
->mcast
.want_lists_lock
);
579 hlist_add_head_rcu(&orig
->mcast_want_all_unsnoopables_node
,
580 &bat_priv
->mcast
.want_all_unsnoopables_list
);
581 spin_unlock_bh(&bat_priv
->mcast
.want_lists_lock
);
582 /* switched from flag set to unset */
583 } else if (!(mcast_flags
& BATADV_MCAST_WANT_ALL_UNSNOOPABLES
) &&
584 orig
->mcast_flags
& BATADV_MCAST_WANT_ALL_UNSNOOPABLES
) {
585 atomic_dec(&bat_priv
->mcast
.num_want_all_unsnoopables
);
587 spin_lock_bh(&bat_priv
->mcast
.want_lists_lock
);
588 hlist_del_rcu(&orig
->mcast_want_all_unsnoopables_node
);
589 spin_unlock_bh(&bat_priv
->mcast
.want_lists_lock
);
594 * batadv_mcast_want_ipv4_update - update want-all-ipv4 counter and list
595 * @bat_priv: the bat priv with all the soft interface information
596 * @orig: the orig_node which multicast state might have changed of
597 * @mcast_flags: flags indicating the new multicast state
599 * If the BATADV_MCAST_WANT_ALL_IPV4 flag of this originator, orig, has
600 * toggled then this method updates counter and list accordingly.
602 static void batadv_mcast_want_ipv4_update(struct batadv_priv
*bat_priv
,
603 struct batadv_orig_node
*orig
,
606 /* switched from flag unset to set */
607 if (mcast_flags
& BATADV_MCAST_WANT_ALL_IPV4
&&
608 !(orig
->mcast_flags
& BATADV_MCAST_WANT_ALL_IPV4
)) {
609 atomic_inc(&bat_priv
->mcast
.num_want_all_ipv4
);
611 spin_lock_bh(&bat_priv
->mcast
.want_lists_lock
);
612 hlist_add_head_rcu(&orig
->mcast_want_all_ipv4_node
,
613 &bat_priv
->mcast
.want_all_ipv4_list
);
614 spin_unlock_bh(&bat_priv
->mcast
.want_lists_lock
);
615 /* switched from flag set to unset */
616 } else if (!(mcast_flags
& BATADV_MCAST_WANT_ALL_IPV4
) &&
617 orig
->mcast_flags
& BATADV_MCAST_WANT_ALL_IPV4
) {
618 atomic_dec(&bat_priv
->mcast
.num_want_all_ipv4
);
620 spin_lock_bh(&bat_priv
->mcast
.want_lists_lock
);
621 hlist_del_rcu(&orig
->mcast_want_all_ipv4_node
);
622 spin_unlock_bh(&bat_priv
->mcast
.want_lists_lock
);
627 * batadv_mcast_want_ipv6_update - update want-all-ipv6 counter and list
628 * @bat_priv: the bat priv with all the soft interface information
629 * @orig: the orig_node which multicast state might have changed of
630 * @mcast_flags: flags indicating the new multicast state
632 * If the BATADV_MCAST_WANT_ALL_IPV6 flag of this originator, orig, has
633 * toggled then this method updates counter and list accordingly.
635 static void batadv_mcast_want_ipv6_update(struct batadv_priv
*bat_priv
,
636 struct batadv_orig_node
*orig
,
639 /* switched from flag unset to set */
640 if (mcast_flags
& BATADV_MCAST_WANT_ALL_IPV6
&&
641 !(orig
->mcast_flags
& BATADV_MCAST_WANT_ALL_IPV6
)) {
642 atomic_inc(&bat_priv
->mcast
.num_want_all_ipv6
);
644 spin_lock_bh(&bat_priv
->mcast
.want_lists_lock
);
645 hlist_add_head_rcu(&orig
->mcast_want_all_ipv6_node
,
646 &bat_priv
->mcast
.want_all_ipv6_list
);
647 spin_unlock_bh(&bat_priv
->mcast
.want_lists_lock
);
648 /* switched from flag set to unset */
649 } else if (!(mcast_flags
& BATADV_MCAST_WANT_ALL_IPV6
) &&
650 orig
->mcast_flags
& BATADV_MCAST_WANT_ALL_IPV6
) {
651 atomic_dec(&bat_priv
->mcast
.num_want_all_ipv6
);
653 spin_lock_bh(&bat_priv
->mcast
.want_lists_lock
);
654 hlist_del_rcu(&orig
->mcast_want_all_ipv6_node
);
655 spin_unlock_bh(&bat_priv
->mcast
.want_lists_lock
);
660 * batadv_mcast_tvlv_ogm_handler_v1 - process incoming multicast tvlv container
661 * @bat_priv: the bat priv with all the soft interface information
662 * @orig: the orig_node of the ogm
663 * @flags: flags indicating the tvlv state (see batadv_tvlv_handler_flags)
664 * @tvlv_value: tvlv buffer containing the multicast data
665 * @tvlv_value_len: tvlv buffer length
667 static void batadv_mcast_tvlv_ogm_handler_v1(struct batadv_priv
*bat_priv
,
668 struct batadv_orig_node
*orig
,
671 uint16_t tvlv_value_len
)
673 bool orig_mcast_enabled
= !(flags
& BATADV_TVLV_HANDLER_OGM_CIFNOTFND
);
674 uint8_t mcast_flags
= BATADV_NO_FLAGS
;
675 bool orig_initialized
;
677 orig_initialized
= orig
->capa_initialized
& BATADV_ORIG_CAPA_HAS_MCAST
;
679 /* If mcast support is turned on decrease the disabled mcast node
680 * counter only if we had increased it for this node before. If this
681 * is a completely new orig_node no need to decrease the counter.
683 if (orig_mcast_enabled
&&
684 !(orig
->capabilities
& BATADV_ORIG_CAPA_HAS_MCAST
)) {
685 if (orig_initialized
)
686 atomic_dec(&bat_priv
->mcast
.num_disabled
);
687 orig
->capabilities
|= BATADV_ORIG_CAPA_HAS_MCAST
;
688 /* If mcast support is being switched off increase the disabled
689 * mcast node counter.
691 } else if (!orig_mcast_enabled
&&
692 orig
->capabilities
& BATADV_ORIG_CAPA_HAS_MCAST
) {
693 atomic_inc(&bat_priv
->mcast
.num_disabled
);
694 orig
->capabilities
&= ~BATADV_ORIG_CAPA_HAS_MCAST
;
697 orig
->capa_initialized
|= BATADV_ORIG_CAPA_HAS_MCAST
;
699 if (orig_mcast_enabled
&& tvlv_value
&&
700 (tvlv_value_len
>= sizeof(mcast_flags
)))
701 mcast_flags
= *(uint8_t *)tvlv_value
;
703 batadv_mcast_want_unsnoop_update(bat_priv
, orig
, mcast_flags
);
704 batadv_mcast_want_ipv4_update(bat_priv
, orig
, mcast_flags
);
705 batadv_mcast_want_ipv6_update(bat_priv
, orig
, mcast_flags
);
707 orig
->mcast_flags
= mcast_flags
;
711 * batadv_mcast_init - initialize the multicast optimizations structures
712 * @bat_priv: the bat priv with all the soft interface information
714 void batadv_mcast_init(struct batadv_priv
*bat_priv
)
716 batadv_tvlv_handler_register(bat_priv
, batadv_mcast_tvlv_ogm_handler_v1
,
717 NULL
, BATADV_TVLV_MCAST
, 1,
718 BATADV_TVLV_HANDLER_OGM_CIFNOTFND
);
722 * batadv_mcast_free - free the multicast optimizations structures
723 * @bat_priv: the bat priv with all the soft interface information
725 void batadv_mcast_free(struct batadv_priv
*bat_priv
)
727 batadv_tvlv_container_unregister(bat_priv
, BATADV_TVLV_MCAST
, 1);
728 batadv_tvlv_handler_unregister(bat_priv
, BATADV_TVLV_MCAST
, 1);
730 batadv_mcast_mla_tt_retract(bat_priv
, NULL
);
734 * batadv_mcast_purge_orig - reset originator global mcast state modifications
735 * @orig: the originator which is going to get purged
737 void batadv_mcast_purge_orig(struct batadv_orig_node
*orig
)
739 struct batadv_priv
*bat_priv
= orig
->bat_priv
;
741 if (!(orig
->capabilities
& BATADV_ORIG_CAPA_HAS_MCAST
))
742 atomic_dec(&bat_priv
->mcast
.num_disabled
);
744 batadv_mcast_want_unsnoop_update(bat_priv
, orig
, BATADV_NO_FLAGS
);
745 batadv_mcast_want_ipv4_update(bat_priv
, orig
, BATADV_NO_FLAGS
);
746 batadv_mcast_want_ipv6_update(bat_priv
, orig
, BATADV_NO_FLAGS
);