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/>.
18 #include <linux/bitops.h>
19 #include <linux/bug.h>
21 #include "multicast.h"
22 #include "originator.h"
23 #include "hard-interface.h"
24 #include "translation-table.h"
27 * batadv_mcast_mla_softif_get - get softif multicast listeners
28 * @dev: the device to collect multicast addresses from
29 * @mcast_list: a list to put found addresses into
31 * Collect multicast addresses of the local multicast listeners
32 * on the given soft interface, dev, in the given mcast_list.
34 * Returns -ENOMEM on memory allocation error or the number of
35 * items added to the mcast_list otherwise.
37 static int batadv_mcast_mla_softif_get(struct net_device
*dev
,
38 struct hlist_head
*mcast_list
)
40 struct netdev_hw_addr
*mc_list_entry
;
41 struct batadv_hw_addr
*new;
44 netif_addr_lock_bh(dev
);
45 netdev_for_each_mc_addr(mc_list_entry
, dev
) {
46 new = kmalloc(sizeof(*new), GFP_ATOMIC
);
52 ether_addr_copy(new->addr
, mc_list_entry
->addr
);
53 hlist_add_head(&new->list
, mcast_list
);
56 netif_addr_unlock_bh(dev
);
62 * batadv_mcast_mla_is_duplicate - check whether an address is in a list
63 * @mcast_addr: the multicast address to check
64 * @mcast_list: the list with multicast addresses to search in
66 * Returns true if the given address is already in the given list.
67 * Otherwise returns false.
69 static bool batadv_mcast_mla_is_duplicate(uint8_t *mcast_addr
,
70 struct hlist_head
*mcast_list
)
72 struct batadv_hw_addr
*mcast_entry
;
74 hlist_for_each_entry(mcast_entry
, mcast_list
, list
)
75 if (batadv_compare_eth(mcast_entry
->addr
, mcast_addr
))
82 * batadv_mcast_mla_list_free - free a list of multicast addresses
83 * @mcast_list: the list to free
85 * Removes and frees all items in the given mcast_list.
87 static void batadv_mcast_mla_list_free(struct hlist_head
*mcast_list
)
89 struct batadv_hw_addr
*mcast_entry
;
90 struct hlist_node
*tmp
;
92 hlist_for_each_entry_safe(mcast_entry
, tmp
, mcast_list
, list
) {
93 hlist_del(&mcast_entry
->list
);
99 * batadv_mcast_mla_tt_retract - clean up multicast listener announcements
100 * @bat_priv: the bat priv with all the soft interface information
101 * @mcast_list: a list of addresses which should _not_ be removed
103 * Retracts the announcement of any multicast listener from the
104 * translation table except the ones listed in the given mcast_list.
106 * If mcast_list is NULL then all are retracted.
108 static void batadv_mcast_mla_tt_retract(struct batadv_priv
*bat_priv
,
109 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
, &bat_priv
->mcast
.mla_list
,
117 batadv_mcast_mla_is_duplicate(mcast_entry
->addr
,
121 batadv_tt_local_remove(bat_priv
, mcast_entry
->addr
,
123 "mcast TT outdated", false);
125 hlist_del(&mcast_entry
->list
);
131 * batadv_mcast_mla_tt_add - add multicast listener announcements
132 * @bat_priv: the bat priv with all the soft interface information
133 * @mcast_list: a list of addresses which are going to get added
135 * Adds multicast listener announcements from the given mcast_list to the
136 * translation table if they have not been added yet.
138 static void batadv_mcast_mla_tt_add(struct batadv_priv
*bat_priv
,
139 struct hlist_head
*mcast_list
)
141 struct batadv_hw_addr
*mcast_entry
;
142 struct hlist_node
*tmp
;
147 hlist_for_each_entry_safe(mcast_entry
, tmp
, mcast_list
, list
) {
148 if (batadv_mcast_mla_is_duplicate(mcast_entry
->addr
,
149 &bat_priv
->mcast
.mla_list
))
152 if (!batadv_tt_local_add(bat_priv
->soft_iface
,
153 mcast_entry
->addr
, BATADV_NO_FLAGS
,
154 BATADV_NULL_IFINDEX
, BATADV_NO_MARK
))
157 hlist_del(&mcast_entry
->list
);
158 hlist_add_head(&mcast_entry
->list
, &bat_priv
->mcast
.mla_list
);
163 * batadv_mcast_has_bridge - check whether the soft-iface is bridged
164 * @bat_priv: the bat priv with all the soft interface information
166 * Checks whether there is a bridge on top of our soft interface. Returns
167 * true if so, false otherwise.
169 static bool batadv_mcast_has_bridge(struct batadv_priv
*bat_priv
)
171 struct net_device
*upper
= bat_priv
->soft_iface
;
175 upper
= netdev_master_upper_dev_get_rcu(upper
);
176 } while (upper
&& !(upper
->priv_flags
& IFF_EBRIDGE
));
183 * batadv_mcast_mla_tvlv_update - update multicast tvlv
184 * @bat_priv: the bat priv with all the soft interface information
186 * Updates the own multicast tvlv with our current multicast related settings,
187 * capabilities and inabilities.
189 * Returns true if the tvlv container is registered afterwards. Otherwise
192 static bool batadv_mcast_mla_tvlv_update(struct batadv_priv
*bat_priv
)
194 struct batadv_tvlv_mcast_data mcast_data
;
196 mcast_data
.flags
= BATADV_NO_FLAGS
;
197 memset(mcast_data
.reserved
, 0, sizeof(mcast_data
.reserved
));
199 /* Avoid attaching MLAs, if there is a bridge on top of our soft
200 * interface, we don't support that yet (TODO)
202 if (batadv_mcast_has_bridge(bat_priv
)) {
203 if (bat_priv
->mcast
.enabled
) {
204 batadv_tvlv_container_unregister(bat_priv
,
205 BATADV_TVLV_MCAST
, 1);
206 bat_priv
->mcast
.enabled
= false;
212 if (!bat_priv
->mcast
.enabled
||
213 mcast_data
.flags
!= bat_priv
->mcast
.flags
) {
214 batadv_tvlv_container_register(bat_priv
, BATADV_TVLV_MCAST
, 1,
215 &mcast_data
, sizeof(mcast_data
));
216 bat_priv
->mcast
.flags
= mcast_data
.flags
;
217 bat_priv
->mcast
.enabled
= true;
224 * batadv_mcast_mla_update - update the own MLAs
225 * @bat_priv: the bat priv with all the soft interface information
227 * Updates the own multicast listener announcements in the translation
228 * table as well as the own, announced multicast tvlv container.
230 void batadv_mcast_mla_update(struct batadv_priv
*bat_priv
)
232 struct net_device
*soft_iface
= bat_priv
->soft_iface
;
233 struct hlist_head mcast_list
= HLIST_HEAD_INIT
;
236 if (!batadv_mcast_mla_tvlv_update(bat_priv
))
239 ret
= batadv_mcast_mla_softif_get(soft_iface
, &mcast_list
);
244 batadv_mcast_mla_tt_retract(bat_priv
, &mcast_list
);
245 batadv_mcast_mla_tt_add(bat_priv
, &mcast_list
);
248 batadv_mcast_mla_list_free(&mcast_list
);
252 * batadv_mcast_forw_mode_check_ipv4 - check for optimized forwarding potential
253 * @bat_priv: the bat priv with all the soft interface information
254 * @skb: the IPv4 packet to check
255 * @is_unsnoopable: stores whether the destination is snoopable
257 * Checks whether the given IPv4 packet has the potential to be forwarded with a
258 * mode more optimal than classic flooding.
260 * If so then returns 0. Otherwise -EINVAL is returned or -ENOMEM in case of
261 * memory allocation failure.
263 static int batadv_mcast_forw_mode_check_ipv4(struct batadv_priv
*bat_priv
,
265 bool *is_unsnoopable
)
269 /* We might fail due to out-of-memory -> drop it */
270 if (!pskb_may_pull(skb
, sizeof(struct ethhdr
) + sizeof(*iphdr
)))
275 /* TODO: Implement Multicast Router Discovery (RFC4286),
276 * then allow scope > link local, too
278 if (!ipv4_is_local_multicast(iphdr
->daddr
))
281 /* link-local multicast listeners behind a bridge are
282 * not snoopable (see RFC4541, section 2.1.2.2)
284 *is_unsnoopable
= true;
290 * batadv_mcast_forw_mode_check_ipv6 - check for optimized forwarding potential
291 * @bat_priv: the bat priv with all the soft interface information
292 * @skb: the IPv6 packet to check
293 * @is_unsnoopable: stores whether the destination is snoopable
295 * Checks whether the given IPv6 packet has the potential to be forwarded with a
296 * mode more optimal than classic flooding.
298 * If so then returns 0. Otherwise -EINVAL is returned or -ENOMEM if we are out
301 static int batadv_mcast_forw_mode_check_ipv6(struct batadv_priv
*bat_priv
,
303 bool *is_unsnoopable
)
305 struct ipv6hdr
*ip6hdr
;
307 /* We might fail due to out-of-memory -> drop it */
308 if (!pskb_may_pull(skb
, sizeof(struct ethhdr
) + sizeof(*ip6hdr
)))
311 ip6hdr
= ipv6_hdr(skb
);
313 /* TODO: Implement Multicast Router Discovery (RFC4286),
314 * then allow scope > link local, too
316 if (IPV6_ADDR_MC_SCOPE(&ip6hdr
->daddr
) != IPV6_ADDR_SCOPE_LINKLOCAL
)
319 /* link-local-all-nodes multicast listeners behind a bridge are
320 * not snoopable (see RFC4541, section 3, paragraph 3)
322 if (ipv6_addr_is_ll_all_nodes(&ip6hdr
->daddr
))
323 *is_unsnoopable
= true;
329 * batadv_mcast_forw_mode_check - check for optimized forwarding potential
330 * @bat_priv: the bat priv with all the soft interface information
331 * @skb: the multicast frame to check
332 * @is_unsnoopable: stores whether the destination is snoopable
334 * Checks whether the given multicast ethernet frame has the potential to be
335 * forwarded with a mode more optimal than classic flooding.
337 * If so then returns 0. Otherwise -EINVAL is returned or -ENOMEM if we are out
340 static int batadv_mcast_forw_mode_check(struct batadv_priv
*bat_priv
,
342 bool *is_unsnoopable
)
344 struct ethhdr
*ethhdr
= eth_hdr(skb
);
346 if (!atomic_read(&bat_priv
->multicast_mode
))
349 if (atomic_read(&bat_priv
->mcast
.num_disabled
))
352 switch (ntohs(ethhdr
->h_proto
)) {
354 return batadv_mcast_forw_mode_check_ipv4(bat_priv
, skb
,
357 return batadv_mcast_forw_mode_check_ipv6(bat_priv
, skb
,
365 * batadv_mcast_want_all_ip_count - count nodes with unspecific mcast interest
366 * @bat_priv: the bat priv with all the soft interface information
367 * @ethhdr: ethernet header of a packet
369 * Returns the number of nodes which want all IPv4 multicast traffic if the
370 * given ethhdr is from an IPv4 packet or the number of nodes which want all
371 * IPv6 traffic if it matches an IPv6 packet.
373 static int batadv_mcast_forw_want_all_ip_count(struct batadv_priv
*bat_priv
,
374 struct ethhdr
*ethhdr
)
376 switch (ntohs(ethhdr
->h_proto
)) {
378 return atomic_read(&bat_priv
->mcast
.num_want_all_ipv4
);
380 return atomic_read(&bat_priv
->mcast
.num_want_all_ipv6
);
382 /* we shouldn't be here... */
388 * batadv_mcast_forw_tt_node_get - get a multicast tt node
389 * @bat_priv: the bat priv with all the soft interface information
390 * @ethhdr: the ether header containing the multicast destination
392 * Returns an orig_node matching the multicast address provided by ethhdr
393 * via a translation table lookup. This increases the returned nodes refcount.
395 static struct batadv_orig_node
*
396 batadv_mcast_forw_tt_node_get(struct batadv_priv
*bat_priv
,
397 struct ethhdr
*ethhdr
)
399 return batadv_transtable_search(bat_priv
, ethhdr
->h_source
,
400 ethhdr
->h_dest
, BATADV_NO_FLAGS
);
404 * batadv_mcast_want_forw_ipv4_node_get - get a node with an ipv4 flag
405 * @bat_priv: the bat priv with all the soft interface information
407 * Returns an orig_node which has the BATADV_MCAST_WANT_ALL_IPV4 flag set and
408 * increases its refcount.
410 static struct batadv_orig_node
*
411 batadv_mcast_forw_ipv4_node_get(struct batadv_priv
*bat_priv
)
413 struct batadv_orig_node
*tmp_orig_node
, *orig_node
= NULL
;
416 hlist_for_each_entry_rcu(tmp_orig_node
,
417 &bat_priv
->mcast
.want_all_ipv4_list
,
418 mcast_want_all_ipv4_node
) {
419 if (!atomic_inc_not_zero(&tmp_orig_node
->refcount
))
422 orig_node
= tmp_orig_node
;
431 * batadv_mcast_want_forw_ipv6_node_get - get a node with an ipv6 flag
432 * @bat_priv: the bat priv with all the soft interface information
434 * Returns an orig_node which has the BATADV_MCAST_WANT_ALL_IPV6 flag set
435 * and increases its refcount.
437 static struct batadv_orig_node
*
438 batadv_mcast_forw_ipv6_node_get(struct batadv_priv
*bat_priv
)
440 struct batadv_orig_node
*tmp_orig_node
, *orig_node
= NULL
;
443 hlist_for_each_entry_rcu(tmp_orig_node
,
444 &bat_priv
->mcast
.want_all_ipv6_list
,
445 mcast_want_all_ipv6_node
) {
446 if (!atomic_inc_not_zero(&tmp_orig_node
->refcount
))
449 orig_node
= tmp_orig_node
;
458 * batadv_mcast_want_forw_ip_node_get - get a node with an ipv4/ipv6 flag
459 * @bat_priv: the bat priv with all the soft interface information
460 * @ethhdr: an ethernet header to determine the protocol family from
462 * Returns an orig_node which has the BATADV_MCAST_WANT_ALL_IPV4 or
463 * BATADV_MCAST_WANT_ALL_IPV6 flag, depending on the provided ethhdr, set and
464 * increases its refcount.
466 static struct batadv_orig_node
*
467 batadv_mcast_forw_ip_node_get(struct batadv_priv
*bat_priv
,
468 struct ethhdr
*ethhdr
)
470 switch (ntohs(ethhdr
->h_proto
)) {
472 return batadv_mcast_forw_ipv4_node_get(bat_priv
);
474 return batadv_mcast_forw_ipv6_node_get(bat_priv
);
476 /* we shouldn't be here... */
482 * batadv_mcast_want_forw_unsnoop_node_get - get a node with an unsnoopable flag
483 * @bat_priv: the bat priv with all the soft interface information
485 * Returns an orig_node which has the BATADV_MCAST_WANT_ALL_UNSNOOPABLES flag
486 * set and increases its refcount.
488 static struct batadv_orig_node
*
489 batadv_mcast_forw_unsnoop_node_get(struct batadv_priv
*bat_priv
)
491 struct batadv_orig_node
*tmp_orig_node
, *orig_node
= NULL
;
494 hlist_for_each_entry_rcu(tmp_orig_node
,
495 &bat_priv
->mcast
.want_all_unsnoopables_list
,
496 mcast_want_all_unsnoopables_node
) {
497 if (!atomic_inc_not_zero(&tmp_orig_node
->refcount
))
500 orig_node
= tmp_orig_node
;
509 * batadv_mcast_forw_mode - check on how to forward a multicast packet
510 * @bat_priv: the bat priv with all the soft interface information
511 * @skb: The multicast packet to check
512 * @orig: an originator to be set to forward the skb to
514 * Returns the forwarding mode as enum batadv_forw_mode and in case of
515 * BATADV_FORW_SINGLE set the orig to the single originator the skb
516 * should be forwarded to.
518 enum batadv_forw_mode
519 batadv_mcast_forw_mode(struct batadv_priv
*bat_priv
, struct sk_buff
*skb
,
520 struct batadv_orig_node
**orig
)
522 int ret
, tt_count
, ip_count
, unsnoop_count
, total_count
;
523 bool is_unsnoopable
= false;
524 struct ethhdr
*ethhdr
;
526 ret
= batadv_mcast_forw_mode_check(bat_priv
, skb
, &is_unsnoopable
);
528 return BATADV_FORW_NONE
;
530 return BATADV_FORW_ALL
;
532 ethhdr
= eth_hdr(skb
);
534 tt_count
= batadv_tt_global_hash_count(bat_priv
, ethhdr
->h_dest
,
536 ip_count
= batadv_mcast_forw_want_all_ip_count(bat_priv
, ethhdr
);
537 unsnoop_count
= !is_unsnoopable
? 0 :
538 atomic_read(&bat_priv
->mcast
.num_want_all_unsnoopables
);
540 total_count
= tt_count
+ ip_count
+ unsnoop_count
;
542 switch (total_count
) {
545 *orig
= batadv_mcast_forw_tt_node_get(bat_priv
, ethhdr
);
547 *orig
= batadv_mcast_forw_ip_node_get(bat_priv
, ethhdr
);
548 else if (unsnoop_count
)
549 *orig
= batadv_mcast_forw_unsnoop_node_get(bat_priv
);
552 return BATADV_FORW_SINGLE
;
556 return BATADV_FORW_NONE
;
558 return BATADV_FORW_ALL
;
563 * batadv_mcast_want_unsnoop_update - update unsnoop counter and list
564 * @bat_priv: the bat priv with all the soft interface information
565 * @orig: the orig_node which multicast state might have changed of
566 * @mcast_flags: flags indicating the new multicast state
568 * If the BATADV_MCAST_WANT_ALL_UNSNOOPABLES flag of this originator,
569 * orig, has toggled then this method updates counter and list accordingly.
571 * Caller needs to hold orig->mcast_handler_lock.
573 static void batadv_mcast_want_unsnoop_update(struct batadv_priv
*bat_priv
,
574 struct batadv_orig_node
*orig
,
577 struct hlist_node
*node
= &orig
->mcast_want_all_unsnoopables_node
;
578 struct hlist_head
*head
= &bat_priv
->mcast
.want_all_unsnoopables_list
;
580 /* switched from flag unset to set */
581 if (mcast_flags
& BATADV_MCAST_WANT_ALL_UNSNOOPABLES
&&
582 !(orig
->mcast_flags
& BATADV_MCAST_WANT_ALL_UNSNOOPABLES
)) {
583 atomic_inc(&bat_priv
->mcast
.num_want_all_unsnoopables
);
585 spin_lock_bh(&bat_priv
->mcast
.want_lists_lock
);
586 /* flag checks above + mcast_handler_lock prevents this */
587 WARN_ON(!hlist_unhashed(node
));
589 hlist_add_head_rcu(node
, head
);
590 spin_unlock_bh(&bat_priv
->mcast
.want_lists_lock
);
591 /* switched from flag set to unset */
592 } else if (!(mcast_flags
& BATADV_MCAST_WANT_ALL_UNSNOOPABLES
) &&
593 orig
->mcast_flags
& BATADV_MCAST_WANT_ALL_UNSNOOPABLES
) {
594 atomic_dec(&bat_priv
->mcast
.num_want_all_unsnoopables
);
596 spin_lock_bh(&bat_priv
->mcast
.want_lists_lock
);
597 /* flag checks above + mcast_handler_lock prevents this */
598 WARN_ON(hlist_unhashed(node
));
600 hlist_del_init_rcu(node
);
601 spin_unlock_bh(&bat_priv
->mcast
.want_lists_lock
);
606 * batadv_mcast_want_ipv4_update - update want-all-ipv4 counter and list
607 * @bat_priv: the bat priv with all the soft interface information
608 * @orig: the orig_node which multicast state might have changed of
609 * @mcast_flags: flags indicating the new multicast state
611 * If the BATADV_MCAST_WANT_ALL_IPV4 flag of this originator, orig, has
612 * toggled then this method updates counter and list accordingly.
614 * Caller needs to hold orig->mcast_handler_lock.
616 static void batadv_mcast_want_ipv4_update(struct batadv_priv
*bat_priv
,
617 struct batadv_orig_node
*orig
,
620 struct hlist_node
*node
= &orig
->mcast_want_all_ipv4_node
;
621 struct hlist_head
*head
= &bat_priv
->mcast
.want_all_ipv4_list
;
623 /* switched from flag unset to set */
624 if (mcast_flags
& BATADV_MCAST_WANT_ALL_IPV4
&&
625 !(orig
->mcast_flags
& BATADV_MCAST_WANT_ALL_IPV4
)) {
626 atomic_inc(&bat_priv
->mcast
.num_want_all_ipv4
);
628 spin_lock_bh(&bat_priv
->mcast
.want_lists_lock
);
629 /* flag checks above + mcast_handler_lock prevents this */
630 WARN_ON(!hlist_unhashed(node
));
632 hlist_add_head_rcu(node
, head
);
633 spin_unlock_bh(&bat_priv
->mcast
.want_lists_lock
);
634 /* switched from flag set to unset */
635 } else if (!(mcast_flags
& BATADV_MCAST_WANT_ALL_IPV4
) &&
636 orig
->mcast_flags
& BATADV_MCAST_WANT_ALL_IPV4
) {
637 atomic_dec(&bat_priv
->mcast
.num_want_all_ipv4
);
639 spin_lock_bh(&bat_priv
->mcast
.want_lists_lock
);
640 /* flag checks above + mcast_handler_lock prevents this */
641 WARN_ON(hlist_unhashed(node
));
643 hlist_del_init_rcu(node
);
644 spin_unlock_bh(&bat_priv
->mcast
.want_lists_lock
);
649 * batadv_mcast_want_ipv6_update - update want-all-ipv6 counter and list
650 * @bat_priv: the bat priv with all the soft interface information
651 * @orig: the orig_node which multicast state might have changed of
652 * @mcast_flags: flags indicating the new multicast state
654 * If the BATADV_MCAST_WANT_ALL_IPV6 flag of this originator, orig, has
655 * toggled then this method updates counter and list accordingly.
657 * Caller needs to hold orig->mcast_handler_lock.
659 static void batadv_mcast_want_ipv6_update(struct batadv_priv
*bat_priv
,
660 struct batadv_orig_node
*orig
,
663 struct hlist_node
*node
= &orig
->mcast_want_all_ipv6_node
;
664 struct hlist_head
*head
= &bat_priv
->mcast
.want_all_ipv6_list
;
666 /* switched from flag unset to set */
667 if (mcast_flags
& BATADV_MCAST_WANT_ALL_IPV6
&&
668 !(orig
->mcast_flags
& BATADV_MCAST_WANT_ALL_IPV6
)) {
669 atomic_inc(&bat_priv
->mcast
.num_want_all_ipv6
);
671 spin_lock_bh(&bat_priv
->mcast
.want_lists_lock
);
672 /* flag checks above + mcast_handler_lock prevents this */
673 WARN_ON(!hlist_unhashed(node
));
675 hlist_add_head_rcu(node
, head
);
676 spin_unlock_bh(&bat_priv
->mcast
.want_lists_lock
);
677 /* switched from flag set to unset */
678 } else if (!(mcast_flags
& BATADV_MCAST_WANT_ALL_IPV6
) &&
679 orig
->mcast_flags
& BATADV_MCAST_WANT_ALL_IPV6
) {
680 atomic_dec(&bat_priv
->mcast
.num_want_all_ipv6
);
682 spin_lock_bh(&bat_priv
->mcast
.want_lists_lock
);
683 /* flag checks above + mcast_handler_lock prevents this */
684 WARN_ON(hlist_unhashed(node
));
686 hlist_del_init_rcu(node
);
687 spin_unlock_bh(&bat_priv
->mcast
.want_lists_lock
);
692 * batadv_mcast_tvlv_ogm_handler_v1 - process incoming multicast tvlv container
693 * @bat_priv: the bat priv with all the soft interface information
694 * @orig: the orig_node of the ogm
695 * @flags: flags indicating the tvlv state (see batadv_tvlv_handler_flags)
696 * @tvlv_value: tvlv buffer containing the multicast data
697 * @tvlv_value_len: tvlv buffer length
699 static void batadv_mcast_tvlv_ogm_handler_v1(struct batadv_priv
*bat_priv
,
700 struct batadv_orig_node
*orig
,
703 uint16_t tvlv_value_len
)
705 bool orig_mcast_enabled
= !(flags
& BATADV_TVLV_HANDLER_OGM_CIFNOTFND
);
706 uint8_t mcast_flags
= BATADV_NO_FLAGS
;
707 bool orig_initialized
;
709 if (orig_mcast_enabled
&& tvlv_value
&&
710 (tvlv_value_len
>= sizeof(mcast_flags
)))
711 mcast_flags
= *(uint8_t *)tvlv_value
;
713 spin_lock_bh(&orig
->mcast_handler_lock
);
714 orig_initialized
= test_bit(BATADV_ORIG_CAPA_HAS_MCAST
,
715 &orig
->capa_initialized
);
717 /* If mcast support is turned on decrease the disabled mcast node
718 * counter only if we had increased it for this node before. If this
719 * is a completely new orig_node no need to decrease the counter.
721 if (orig_mcast_enabled
&&
722 !test_bit(BATADV_ORIG_CAPA_HAS_MCAST
, &orig
->capabilities
)) {
723 if (orig_initialized
)
724 atomic_dec(&bat_priv
->mcast
.num_disabled
);
725 set_bit(BATADV_ORIG_CAPA_HAS_MCAST
, &orig
->capabilities
);
726 /* If mcast support is being switched off or if this is an initial
727 * OGM without mcast support then increase the disabled mcast
730 } else if (!orig_mcast_enabled
&&
731 (test_bit(BATADV_ORIG_CAPA_HAS_MCAST
, &orig
->capabilities
) ||
732 !orig_initialized
)) {
733 atomic_inc(&bat_priv
->mcast
.num_disabled
);
734 clear_bit(BATADV_ORIG_CAPA_HAS_MCAST
, &orig
->capabilities
);
737 set_bit(BATADV_ORIG_CAPA_HAS_MCAST
, &orig
->capa_initialized
);
739 batadv_mcast_want_unsnoop_update(bat_priv
, orig
, mcast_flags
);
740 batadv_mcast_want_ipv4_update(bat_priv
, orig
, mcast_flags
);
741 batadv_mcast_want_ipv6_update(bat_priv
, orig
, mcast_flags
);
743 orig
->mcast_flags
= mcast_flags
;
744 spin_unlock_bh(&orig
->mcast_handler_lock
);
748 * batadv_mcast_init - initialize the multicast optimizations structures
749 * @bat_priv: the bat priv with all the soft interface information
751 void batadv_mcast_init(struct batadv_priv
*bat_priv
)
753 batadv_tvlv_handler_register(bat_priv
, batadv_mcast_tvlv_ogm_handler_v1
,
754 NULL
, BATADV_TVLV_MCAST
, 1,
755 BATADV_TVLV_HANDLER_OGM_CIFNOTFND
);
759 * batadv_mcast_free - free the multicast optimizations structures
760 * @bat_priv: the bat priv with all the soft interface information
762 void batadv_mcast_free(struct batadv_priv
*bat_priv
)
764 batadv_tvlv_container_unregister(bat_priv
, BATADV_TVLV_MCAST
, 1);
765 batadv_tvlv_handler_unregister(bat_priv
, BATADV_TVLV_MCAST
, 1);
767 batadv_mcast_mla_tt_retract(bat_priv
, NULL
);
771 * batadv_mcast_purge_orig - reset originator global mcast state modifications
772 * @orig: the originator which is going to get purged
774 void batadv_mcast_purge_orig(struct batadv_orig_node
*orig
)
776 struct batadv_priv
*bat_priv
= orig
->bat_priv
;
778 spin_lock_bh(&orig
->mcast_handler_lock
);
780 if (!test_bit(BATADV_ORIG_CAPA_HAS_MCAST
, &orig
->capabilities
) &&
781 test_bit(BATADV_ORIG_CAPA_HAS_MCAST
, &orig
->capa_initialized
))
782 atomic_dec(&bat_priv
->mcast
.num_disabled
);
784 batadv_mcast_want_unsnoop_update(bat_priv
, orig
, BATADV_NO_FLAGS
);
785 batadv_mcast_want_ipv4_update(bat_priv
, orig
, BATADV_NO_FLAGS
);
786 batadv_mcast_want_ipv6_update(bat_priv
, orig
, BATADV_NO_FLAGS
);
788 spin_unlock_bh(&orig
->mcast_handler_lock
);