2 * Bridge multicast support.
4 * Copyright (c) 2010 Herbert Xu <herbert@gondor.apana.org.au>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
13 #include <linux/err.h>
14 #include <linux/if_ether.h>
15 #include <linux/igmp.h>
16 #include <linux/jhash.h>
17 #include <linux/kernel.h>
18 #include <linux/log2.h>
19 #include <linux/netdevice.h>
20 #include <linux/netfilter_bridge.h>
21 #include <linux/random.h>
22 #include <linux/rculist.h>
23 #include <linux/skbuff.h>
24 #include <linux/slab.h>
25 #include <linux/timer.h>
26 #include <linux/inetdevice.h>
28 #if IS_ENABLED(CONFIG_IPV6)
31 #include <net/ip6_checksum.h>
34 #include "br_private.h"
36 static void br_multicast_start_querier(struct net_bridge
*br
);
37 unsigned int br_mdb_rehash_seq
;
39 static inline int br_ip_equal(const struct br_ip
*a
, const struct br_ip
*b
)
41 if (a
->proto
!= b
->proto
)
47 return a
->u
.ip4
== b
->u
.ip4
;
48 #if IS_ENABLED(CONFIG_IPV6)
49 case htons(ETH_P_IPV6
):
50 return ipv6_addr_equal(&a
->u
.ip6
, &b
->u
.ip6
);
56 static inline int __br_ip4_hash(struct net_bridge_mdb_htable
*mdb
, __be32 ip
,
59 return jhash_2words((__force u32
)ip
, vid
, mdb
->secret
) & (mdb
->max
- 1);
62 #if IS_ENABLED(CONFIG_IPV6)
63 static inline int __br_ip6_hash(struct net_bridge_mdb_htable
*mdb
,
64 const struct in6_addr
*ip
,
67 return jhash_2words(ipv6_addr_hash(ip
), vid
,
68 mdb
->secret
) & (mdb
->max
- 1);
72 static inline int br_ip_hash(struct net_bridge_mdb_htable
*mdb
,
77 return __br_ip4_hash(mdb
, ip
->u
.ip4
, ip
->vid
);
78 #if IS_ENABLED(CONFIG_IPV6)
79 case htons(ETH_P_IPV6
):
80 return __br_ip6_hash(mdb
, &ip
->u
.ip6
, ip
->vid
);
86 static struct net_bridge_mdb_entry
*__br_mdb_ip_get(
87 struct net_bridge_mdb_htable
*mdb
, struct br_ip
*dst
, int hash
)
89 struct net_bridge_mdb_entry
*mp
;
91 hlist_for_each_entry_rcu(mp
, &mdb
->mhash
[hash
], hlist
[mdb
->ver
]) {
92 if (br_ip_equal(&mp
->addr
, dst
))
99 struct net_bridge_mdb_entry
*br_mdb_ip_get(struct net_bridge_mdb_htable
*mdb
,
105 return __br_mdb_ip_get(mdb
, dst
, br_ip_hash(mdb
, dst
));
108 static struct net_bridge_mdb_entry
*br_mdb_ip4_get(
109 struct net_bridge_mdb_htable
*mdb
, __be32 dst
, __u16 vid
)
114 br_dst
.proto
= htons(ETH_P_IP
);
117 return br_mdb_ip_get(mdb
, &br_dst
);
120 #if IS_ENABLED(CONFIG_IPV6)
121 static struct net_bridge_mdb_entry
*br_mdb_ip6_get(
122 struct net_bridge_mdb_htable
*mdb
, const struct in6_addr
*dst
,
128 br_dst
.proto
= htons(ETH_P_IPV6
);
131 return br_mdb_ip_get(mdb
, &br_dst
);
135 struct net_bridge_mdb_entry
*br_mdb_get(struct net_bridge
*br
,
136 struct sk_buff
*skb
, u16 vid
)
138 struct net_bridge_mdb_htable
*mdb
= rcu_dereference(br
->mdb
);
141 if (br
->multicast_disabled
)
144 if (BR_INPUT_SKB_CB(skb
)->igmp
)
147 ip
.proto
= skb
->protocol
;
150 switch (skb
->protocol
) {
151 case htons(ETH_P_IP
):
152 ip
.u
.ip4
= ip_hdr(skb
)->daddr
;
154 #if IS_ENABLED(CONFIG_IPV6)
155 case htons(ETH_P_IPV6
):
156 ip
.u
.ip6
= ipv6_hdr(skb
)->daddr
;
163 return br_mdb_ip_get(mdb
, &ip
);
166 static void br_mdb_free(struct rcu_head
*head
)
168 struct net_bridge_mdb_htable
*mdb
=
169 container_of(head
, struct net_bridge_mdb_htable
, rcu
);
170 struct net_bridge_mdb_htable
*old
= mdb
->old
;
177 static int br_mdb_copy(struct net_bridge_mdb_htable
*new,
178 struct net_bridge_mdb_htable
*old
,
181 struct net_bridge_mdb_entry
*mp
;
186 for (i
= 0; i
< old
->max
; i
++)
187 hlist_for_each_entry(mp
, &old
->mhash
[i
], hlist
[old
->ver
])
188 hlist_add_head(&mp
->hlist
[new->ver
],
189 &new->mhash
[br_ip_hash(new, &mp
->addr
)]);
195 for (i
= 0; i
< new->max
; i
++) {
197 hlist_for_each_entry(mp
, &new->mhash
[i
], hlist
[new->ver
])
203 return maxlen
> elasticity
? -EINVAL
: 0;
206 void br_multicast_free_pg(struct rcu_head
*head
)
208 struct net_bridge_port_group
*p
=
209 container_of(head
, struct net_bridge_port_group
, rcu
);
214 static void br_multicast_free_group(struct rcu_head
*head
)
216 struct net_bridge_mdb_entry
*mp
=
217 container_of(head
, struct net_bridge_mdb_entry
, rcu
);
222 static void br_multicast_group_expired(unsigned long data
)
224 struct net_bridge_mdb_entry
*mp
= (void *)data
;
225 struct net_bridge
*br
= mp
->br
;
226 struct net_bridge_mdb_htable
*mdb
;
228 spin_lock(&br
->multicast_lock
);
229 if (!netif_running(br
->dev
) || timer_pending(&mp
->timer
))
237 mdb
= mlock_dereference(br
->mdb
, br
);
239 hlist_del_rcu(&mp
->hlist
[mdb
->ver
]);
242 call_rcu_bh(&mp
->rcu
, br_multicast_free_group
);
245 spin_unlock(&br
->multicast_lock
);
248 static void br_multicast_del_pg(struct net_bridge
*br
,
249 struct net_bridge_port_group
*pg
)
251 struct net_bridge_mdb_htable
*mdb
;
252 struct net_bridge_mdb_entry
*mp
;
253 struct net_bridge_port_group
*p
;
254 struct net_bridge_port_group __rcu
**pp
;
256 mdb
= mlock_dereference(br
->mdb
, br
);
258 mp
= br_mdb_ip_get(mdb
, &pg
->addr
);
262 for (pp
= &mp
->ports
;
263 (p
= mlock_dereference(*pp
, br
)) != NULL
;
268 rcu_assign_pointer(*pp
, p
->next
);
269 hlist_del_init(&p
->mglist
);
270 del_timer(&p
->timer
);
271 call_rcu_bh(&p
->rcu
, br_multicast_free_pg
);
273 if (!mp
->ports
&& !mp
->mglist
&& mp
->timer_armed
&&
274 netif_running(br
->dev
))
275 mod_timer(&mp
->timer
, jiffies
);
283 static void br_multicast_port_group_expired(unsigned long data
)
285 struct net_bridge_port_group
*pg
= (void *)data
;
286 struct net_bridge
*br
= pg
->port
->br
;
288 spin_lock(&br
->multicast_lock
);
289 if (!netif_running(br
->dev
) || timer_pending(&pg
->timer
) ||
290 hlist_unhashed(&pg
->mglist
) || pg
->state
& MDB_PERMANENT
)
293 br_multicast_del_pg(br
, pg
);
296 spin_unlock(&br
->multicast_lock
);
299 static int br_mdb_rehash(struct net_bridge_mdb_htable __rcu
**mdbp
, int max
,
302 struct net_bridge_mdb_htable
*old
= rcu_dereference_protected(*mdbp
, 1);
303 struct net_bridge_mdb_htable
*mdb
;
306 mdb
= kmalloc(sizeof(*mdb
), GFP_ATOMIC
);
313 mdb
->mhash
= kzalloc(max
* sizeof(*mdb
->mhash
), GFP_ATOMIC
);
319 mdb
->size
= old
? old
->size
: 0;
320 mdb
->ver
= old
? old
->ver
^ 1 : 0;
322 if (!old
|| elasticity
)
323 get_random_bytes(&mdb
->secret
, sizeof(mdb
->secret
));
325 mdb
->secret
= old
->secret
;
330 err
= br_mdb_copy(mdb
, old
, elasticity
);
338 call_rcu_bh(&mdb
->rcu
, br_mdb_free
);
341 rcu_assign_pointer(*mdbp
, mdb
);
346 static struct sk_buff
*br_ip4_multicast_alloc_query(struct net_bridge
*br
,
354 skb
= netdev_alloc_skb_ip_align(br
->dev
, sizeof(*eth
) + sizeof(*iph
) +
359 skb
->protocol
= htons(ETH_P_IP
);
361 skb_reset_mac_header(skb
);
364 memcpy(eth
->h_source
, br
->dev
->dev_addr
, 6);
367 eth
->h_dest
[2] = 0x5e;
371 eth
->h_proto
= htons(ETH_P_IP
);
372 skb_put(skb
, sizeof(*eth
));
374 skb_set_network_header(skb
, skb
->len
);
380 iph
->tot_len
= htons(sizeof(*iph
) + sizeof(*ih
) + 4);
382 iph
->frag_off
= htons(IP_DF
);
384 iph
->protocol
= IPPROTO_IGMP
;
385 iph
->saddr
= br
->multicast_query_use_ifaddr
?
386 inet_select_addr(br
->dev
, 0, RT_SCOPE_LINK
) : 0;
387 iph
->daddr
= htonl(INADDR_ALLHOSTS_GROUP
);
388 ((u8
*)&iph
[1])[0] = IPOPT_RA
;
389 ((u8
*)&iph
[1])[1] = 4;
390 ((u8
*)&iph
[1])[2] = 0;
391 ((u8
*)&iph
[1])[3] = 0;
395 skb_set_transport_header(skb
, skb
->len
);
397 ih
->type
= IGMP_HOST_MEMBERSHIP_QUERY
;
398 ih
->code
= (group
? br
->multicast_last_member_interval
:
399 br
->multicast_query_response_interval
) /
400 (HZ
/ IGMP_TIMER_SCALE
);
403 ih
->csum
= ip_compute_csum((void *)ih
, sizeof(struct igmphdr
));
404 skb_put(skb
, sizeof(*ih
));
406 __skb_pull(skb
, sizeof(*eth
));
412 #if IS_ENABLED(CONFIG_IPV6)
413 static struct sk_buff
*br_ip6_multicast_alloc_query(struct net_bridge
*br
,
414 const struct in6_addr
*group
)
417 struct ipv6hdr
*ip6h
;
418 struct mld_msg
*mldq
;
421 unsigned long interval
;
423 skb
= netdev_alloc_skb_ip_align(br
->dev
, sizeof(*eth
) + sizeof(*ip6h
) +
428 skb
->protocol
= htons(ETH_P_IPV6
);
430 /* Ethernet header */
431 skb_reset_mac_header(skb
);
434 memcpy(eth
->h_source
, br
->dev
->dev_addr
, 6);
435 eth
->h_proto
= htons(ETH_P_IPV6
);
436 skb_put(skb
, sizeof(*eth
));
438 /* IPv6 header + HbH option */
439 skb_set_network_header(skb
, skb
->len
);
440 ip6h
= ipv6_hdr(skb
);
442 *(__force __be32
*)ip6h
= htonl(0x60000000);
443 ip6h
->payload_len
= htons(8 + sizeof(*mldq
));
444 ip6h
->nexthdr
= IPPROTO_HOPOPTS
;
446 ipv6_addr_set(&ip6h
->daddr
, htonl(0xff020000), 0, 0, htonl(1));
447 if (ipv6_dev_get_saddr(dev_net(br
->dev
), br
->dev
, &ip6h
->daddr
, 0,
452 ipv6_eth_mc_map(&ip6h
->daddr
, eth
->h_dest
);
454 hopopt
= (u8
*)(ip6h
+ 1);
455 hopopt
[0] = IPPROTO_ICMPV6
; /* next hdr */
456 hopopt
[1] = 0; /* length of HbH */
457 hopopt
[2] = IPV6_TLV_ROUTERALERT
; /* Router Alert */
458 hopopt
[3] = 2; /* Length of RA Option */
459 hopopt
[4] = 0; /* Type = 0x0000 (MLD) */
461 hopopt
[6] = IPV6_TLV_PAD1
; /* Pad1 */
462 hopopt
[7] = IPV6_TLV_PAD1
; /* Pad1 */
464 skb_put(skb
, sizeof(*ip6h
) + 8);
467 skb_set_transport_header(skb
, skb
->len
);
468 mldq
= (struct mld_msg
*) icmp6_hdr(skb
);
470 interval
= ipv6_addr_any(group
) ?
471 br
->multicast_query_response_interval
:
472 br
->multicast_last_member_interval
;
474 mldq
->mld_type
= ICMPV6_MGM_QUERY
;
477 mldq
->mld_maxdelay
= htons((u16
)jiffies_to_msecs(interval
));
478 mldq
->mld_reserved
= 0;
479 mldq
->mld_mca
= *group
;
482 mldq
->mld_cksum
= csum_ipv6_magic(&ip6h
->saddr
, &ip6h
->daddr
,
483 sizeof(*mldq
), IPPROTO_ICMPV6
,
486 skb_put(skb
, sizeof(*mldq
));
488 __skb_pull(skb
, sizeof(*eth
));
495 static struct sk_buff
*br_multicast_alloc_query(struct net_bridge
*br
,
498 switch (addr
->proto
) {
499 case htons(ETH_P_IP
):
500 return br_ip4_multicast_alloc_query(br
, addr
->u
.ip4
);
501 #if IS_ENABLED(CONFIG_IPV6)
502 case htons(ETH_P_IPV6
):
503 return br_ip6_multicast_alloc_query(br
, &addr
->u
.ip6
);
509 static struct net_bridge_mdb_entry
*br_multicast_get_group(
510 struct net_bridge
*br
, struct net_bridge_port
*port
,
511 struct br_ip
*group
, int hash
)
513 struct net_bridge_mdb_htable
*mdb
;
514 struct net_bridge_mdb_entry
*mp
;
515 unsigned int count
= 0;
520 mdb
= rcu_dereference_protected(br
->mdb
, 1);
521 hlist_for_each_entry(mp
, &mdb
->mhash
[hash
], hlist
[mdb
->ver
]) {
523 if (unlikely(br_ip_equal(group
, &mp
->addr
)))
530 if (unlikely(count
> br
->hash_elasticity
&& count
)) {
532 br_info(br
, "Multicast hash table "
533 "chain limit reached: %s\n",
534 port
? port
->dev
->name
: br
->dev
->name
);
536 elasticity
= br
->hash_elasticity
;
539 if (mdb
->size
>= max
) {
541 if (unlikely(max
> br
->hash_max
)) {
542 br_warn(br
, "Multicast hash table maximum of %d "
543 "reached, disabling snooping: %s\n",
545 port
? port
->dev
->name
: br
->dev
->name
);
548 br
->multicast_disabled
= 1;
553 if (max
> mdb
->max
|| elasticity
) {
556 br_info(br
, "Multicast hash table "
558 port
? port
->dev
->name
: br
->dev
->name
);
563 err
= br_mdb_rehash(&br
->mdb
, max
, elasticity
);
565 br_warn(br
, "Cannot rehash multicast "
566 "hash table, disabling snooping: %s, %d, %d\n",
567 port
? port
->dev
->name
: br
->dev
->name
,
583 struct net_bridge_mdb_entry
*br_multicast_new_group(struct net_bridge
*br
,
584 struct net_bridge_port
*port
, struct br_ip
*group
)
586 struct net_bridge_mdb_htable
*mdb
;
587 struct net_bridge_mdb_entry
*mp
;
591 mdb
= rcu_dereference_protected(br
->mdb
, 1);
593 err
= br_mdb_rehash(&br
->mdb
, BR_HASH_SIZE
, 0);
599 hash
= br_ip_hash(mdb
, group
);
600 mp
= br_multicast_get_group(br
, port
, group
, hash
);
601 switch (PTR_ERR(mp
)) {
607 mdb
= rcu_dereference_protected(br
->mdb
, 1);
608 hash
= br_ip_hash(mdb
, group
);
615 mp
= kzalloc(sizeof(*mp
), GFP_ATOMIC
);
617 return ERR_PTR(-ENOMEM
);
622 hlist_add_head_rcu(&mp
->hlist
[mdb
->ver
], &mdb
->mhash
[hash
]);
629 struct net_bridge_port_group
*br_multicast_new_port_group(
630 struct net_bridge_port
*port
,
632 struct net_bridge_port_group __rcu
*next
,
635 struct net_bridge_port_group
*p
;
637 p
= kzalloc(sizeof(*p
), GFP_ATOMIC
);
644 rcu_assign_pointer(p
->next
, next
);
645 hlist_add_head(&p
->mglist
, &port
->mglist
);
646 setup_timer(&p
->timer
, br_multicast_port_group_expired
,
651 static int br_multicast_add_group(struct net_bridge
*br
,
652 struct net_bridge_port
*port
,
655 struct net_bridge_mdb_entry
*mp
;
656 struct net_bridge_port_group
*p
;
657 struct net_bridge_port_group __rcu
**pp
;
660 spin_lock(&br
->multicast_lock
);
661 if (!netif_running(br
->dev
) ||
662 (port
&& port
->state
== BR_STATE_DISABLED
))
665 mp
= br_multicast_new_group(br
, port
, group
);
675 for (pp
= &mp
->ports
;
676 (p
= mlock_dereference(*pp
, br
)) != NULL
;
680 if ((unsigned long)p
->port
< (unsigned long)port
)
684 p
= br_multicast_new_port_group(port
, group
, *pp
, MDB_TEMPORARY
);
687 rcu_assign_pointer(*pp
, p
);
688 br_mdb_notify(br
->dev
, port
, group
, RTM_NEWMDB
);
694 spin_unlock(&br
->multicast_lock
);
698 static int br_ip4_multicast_add_group(struct net_bridge
*br
,
699 struct net_bridge_port
*port
,
703 struct br_ip br_group
;
705 if (ipv4_is_local_multicast(group
))
708 br_group
.u
.ip4
= group
;
709 br_group
.proto
= htons(ETH_P_IP
);
712 return br_multicast_add_group(br
, port
, &br_group
);
715 #if IS_ENABLED(CONFIG_IPV6)
716 static int br_ip6_multicast_add_group(struct net_bridge
*br
,
717 struct net_bridge_port
*port
,
718 const struct in6_addr
*group
,
721 struct br_ip br_group
;
723 if (!ipv6_is_transient_multicast(group
))
726 br_group
.u
.ip6
= *group
;
727 br_group
.proto
= htons(ETH_P_IPV6
);
730 return br_multicast_add_group(br
, port
, &br_group
);
734 static void br_multicast_router_expired(unsigned long data
)
736 struct net_bridge_port
*port
= (void *)data
;
737 struct net_bridge
*br
= port
->br
;
739 spin_lock(&br
->multicast_lock
);
740 if (port
->multicast_router
!= 1 ||
741 timer_pending(&port
->multicast_router_timer
) ||
742 hlist_unhashed(&port
->rlist
))
745 hlist_del_init_rcu(&port
->rlist
);
748 spin_unlock(&br
->multicast_lock
);
751 static void br_multicast_local_router_expired(unsigned long data
)
755 static void br_multicast_querier_expired(unsigned long data
)
757 struct net_bridge
*br
= (void *)data
;
759 spin_lock(&br
->multicast_lock
);
760 if (!netif_running(br
->dev
) || br
->multicast_disabled
)
763 br_multicast_start_querier(br
);
766 spin_unlock(&br
->multicast_lock
);
769 static void __br_multicast_send_query(struct net_bridge
*br
,
770 struct net_bridge_port
*port
,
775 skb
= br_multicast_alloc_query(br
, ip
);
780 __skb_push(skb
, sizeof(struct ethhdr
));
781 skb
->dev
= port
->dev
;
782 NF_HOOK(NFPROTO_BRIDGE
, NF_BR_LOCAL_OUT
, skb
, NULL
, skb
->dev
,
788 static void br_multicast_send_query(struct net_bridge
*br
,
789 struct net_bridge_port
*port
, u32 sent
)
792 struct br_ip br_group
;
794 if (!netif_running(br
->dev
) || br
->multicast_disabled
||
795 !br
->multicast_querier
||
796 timer_pending(&br
->multicast_querier_timer
))
799 memset(&br_group
.u
, 0, sizeof(br_group
.u
));
801 br_group
.proto
= htons(ETH_P_IP
);
802 __br_multicast_send_query(br
, port
, &br_group
);
804 #if IS_ENABLED(CONFIG_IPV6)
805 br_group
.proto
= htons(ETH_P_IPV6
);
806 __br_multicast_send_query(br
, port
, &br_group
);
810 time
+= sent
< br
->multicast_startup_query_count
?
811 br
->multicast_startup_query_interval
:
812 br
->multicast_query_interval
;
813 mod_timer(port
? &port
->multicast_query_timer
:
814 &br
->multicast_query_timer
, time
);
817 static void br_multicast_port_query_expired(unsigned long data
)
819 struct net_bridge_port
*port
= (void *)data
;
820 struct net_bridge
*br
= port
->br
;
822 spin_lock(&br
->multicast_lock
);
823 if (port
->state
== BR_STATE_DISABLED
||
824 port
->state
== BR_STATE_BLOCKING
)
827 if (port
->multicast_startup_queries_sent
<
828 br
->multicast_startup_query_count
)
829 port
->multicast_startup_queries_sent
++;
831 br_multicast_send_query(port
->br
, port
,
832 port
->multicast_startup_queries_sent
);
835 spin_unlock(&br
->multicast_lock
);
838 void br_multicast_add_port(struct net_bridge_port
*port
)
840 port
->multicast_router
= 1;
842 setup_timer(&port
->multicast_router_timer
, br_multicast_router_expired
,
843 (unsigned long)port
);
844 setup_timer(&port
->multicast_query_timer
,
845 br_multicast_port_query_expired
, (unsigned long)port
);
848 void br_multicast_del_port(struct net_bridge_port
*port
)
850 del_timer_sync(&port
->multicast_router_timer
);
853 static void __br_multicast_enable_port(struct net_bridge_port
*port
)
855 port
->multicast_startup_queries_sent
= 0;
857 if (try_to_del_timer_sync(&port
->multicast_query_timer
) >= 0 ||
858 del_timer(&port
->multicast_query_timer
))
859 mod_timer(&port
->multicast_query_timer
, jiffies
);
862 void br_multicast_enable_port(struct net_bridge_port
*port
)
864 struct net_bridge
*br
= port
->br
;
866 spin_lock(&br
->multicast_lock
);
867 if (br
->multicast_disabled
|| !netif_running(br
->dev
))
870 __br_multicast_enable_port(port
);
873 spin_unlock(&br
->multicast_lock
);
876 void br_multicast_disable_port(struct net_bridge_port
*port
)
878 struct net_bridge
*br
= port
->br
;
879 struct net_bridge_port_group
*pg
;
880 struct hlist_node
*n
;
882 spin_lock(&br
->multicast_lock
);
883 hlist_for_each_entry_safe(pg
, n
, &port
->mglist
, mglist
)
884 br_multicast_del_pg(br
, pg
);
886 if (!hlist_unhashed(&port
->rlist
))
887 hlist_del_init_rcu(&port
->rlist
);
888 del_timer(&port
->multicast_router_timer
);
889 del_timer(&port
->multicast_query_timer
);
890 spin_unlock(&br
->multicast_lock
);
893 static int br_ip4_multicast_igmp3_report(struct net_bridge
*br
,
894 struct net_bridge_port
*port
,
897 struct igmpv3_report
*ih
;
898 struct igmpv3_grec
*grec
;
907 if (!pskb_may_pull(skb
, sizeof(*ih
)))
910 br_vlan_get_tag(skb
, &vid
);
911 ih
= igmpv3_report_hdr(skb
);
912 num
= ntohs(ih
->ngrec
);
915 for (i
= 0; i
< num
; i
++) {
916 len
+= sizeof(*grec
);
917 if (!pskb_may_pull(skb
, len
))
920 grec
= (void *)(skb
->data
+ len
- sizeof(*grec
));
921 group
= grec
->grec_mca
;
922 type
= grec
->grec_type
;
924 len
+= ntohs(grec
->grec_nsrcs
) * 4;
925 if (!pskb_may_pull(skb
, len
))
928 /* We treat this as an IGMPv2 report for now. */
930 case IGMPV3_MODE_IS_INCLUDE
:
931 case IGMPV3_MODE_IS_EXCLUDE
:
932 case IGMPV3_CHANGE_TO_INCLUDE
:
933 case IGMPV3_CHANGE_TO_EXCLUDE
:
934 case IGMPV3_ALLOW_NEW_SOURCES
:
935 case IGMPV3_BLOCK_OLD_SOURCES
:
942 err
= br_ip4_multicast_add_group(br
, port
, group
, vid
);
950 #if IS_ENABLED(CONFIG_IPV6)
951 static int br_ip6_multicast_mld2_report(struct net_bridge
*br
,
952 struct net_bridge_port
*port
,
955 struct icmp6hdr
*icmp6h
;
956 struct mld2_grec
*grec
;
963 if (!pskb_may_pull(skb
, sizeof(*icmp6h
)))
966 br_vlan_get_tag(skb
, &vid
);
967 icmp6h
= icmp6_hdr(skb
);
968 num
= ntohs(icmp6h
->icmp6_dataun
.un_data16
[1]);
969 len
= sizeof(*icmp6h
);
971 for (i
= 0; i
< num
; i
++) {
972 __be16
*nsrcs
, _nsrcs
;
974 nsrcs
= skb_header_pointer(skb
,
975 len
+ offsetof(struct mld2_grec
,
977 sizeof(_nsrcs
), &_nsrcs
);
981 if (!pskb_may_pull(skb
,
982 len
+ sizeof(*grec
) +
983 sizeof(struct in6_addr
) * ntohs(*nsrcs
)))
986 grec
= (struct mld2_grec
*)(skb
->data
+ len
);
987 len
+= sizeof(*grec
) +
988 sizeof(struct in6_addr
) * ntohs(*nsrcs
);
990 /* We treat these as MLDv1 reports for now. */
991 switch (grec
->grec_type
) {
992 case MLD2_MODE_IS_INCLUDE
:
993 case MLD2_MODE_IS_EXCLUDE
:
994 case MLD2_CHANGE_TO_INCLUDE
:
995 case MLD2_CHANGE_TO_EXCLUDE
:
996 case MLD2_ALLOW_NEW_SOURCES
:
997 case MLD2_BLOCK_OLD_SOURCES
:
1004 err
= br_ip6_multicast_add_group(br
, port
, &grec
->grec_mca
,
1015 * Add port to router_list
1016 * list is maintained ordered by pointer value
1017 * and locked by br->multicast_lock and RCU
1019 static void br_multicast_add_router(struct net_bridge
*br
,
1020 struct net_bridge_port
*port
)
1022 struct net_bridge_port
*p
;
1023 struct hlist_node
*slot
= NULL
;
1025 hlist_for_each_entry(p
, &br
->router_list
, rlist
) {
1026 if ((unsigned long) port
>= (unsigned long) p
)
1032 hlist_add_after_rcu(slot
, &port
->rlist
);
1034 hlist_add_head_rcu(&port
->rlist
, &br
->router_list
);
1037 static void br_multicast_mark_router(struct net_bridge
*br
,
1038 struct net_bridge_port
*port
)
1040 unsigned long now
= jiffies
;
1043 if (br
->multicast_router
== 1)
1044 mod_timer(&br
->multicast_router_timer
,
1045 now
+ br
->multicast_querier_interval
);
1049 if (port
->multicast_router
!= 1)
1052 if (!hlist_unhashed(&port
->rlist
))
1055 br_multicast_add_router(br
, port
);
1058 mod_timer(&port
->multicast_router_timer
,
1059 now
+ br
->multicast_querier_interval
);
1062 static void br_multicast_query_received(struct net_bridge
*br
,
1063 struct net_bridge_port
*port
,
1067 mod_timer(&br
->multicast_querier_timer
,
1068 jiffies
+ br
->multicast_querier_interval
);
1069 else if (timer_pending(&br
->multicast_querier_timer
))
1072 br_multicast_mark_router(br
, port
);
1075 static int br_ip4_multicast_query(struct net_bridge
*br
,
1076 struct net_bridge_port
*port
,
1077 struct sk_buff
*skb
)
1079 const struct iphdr
*iph
= ip_hdr(skb
);
1080 struct igmphdr
*ih
= igmp_hdr(skb
);
1081 struct net_bridge_mdb_entry
*mp
;
1082 struct igmpv3_query
*ih3
;
1083 struct net_bridge_port_group
*p
;
1084 struct net_bridge_port_group __rcu
**pp
;
1085 unsigned long max_delay
;
1086 unsigned long now
= jiffies
;
1091 spin_lock(&br
->multicast_lock
);
1092 if (!netif_running(br
->dev
) ||
1093 (port
&& port
->state
== BR_STATE_DISABLED
))
1096 br_multicast_query_received(br
, port
, !!iph
->saddr
);
1100 if (skb
->len
== sizeof(*ih
)) {
1101 max_delay
= ih
->code
* (HZ
/ IGMP_TIMER_SCALE
);
1104 max_delay
= 10 * HZ
;
1108 if (!pskb_may_pull(skb
, sizeof(struct igmpv3_query
))) {
1113 ih3
= igmpv3_query_hdr(skb
);
1117 max_delay
= ih3
->code
?
1118 IGMPV3_MRC(ih3
->code
) * (HZ
/ IGMP_TIMER_SCALE
) : 1;
1124 br_vlan_get_tag(skb
, &vid
);
1125 mp
= br_mdb_ip4_get(mlock_dereference(br
->mdb
, br
), group
, vid
);
1129 setup_timer(&mp
->timer
, br_multicast_group_expired
, (unsigned long)mp
);
1130 mod_timer(&mp
->timer
, now
+ br
->multicast_membership_interval
);
1131 mp
->timer_armed
= true;
1133 max_delay
*= br
->multicast_last_member_count
;
1136 (timer_pending(&mp
->timer
) ?
1137 time_after(mp
->timer
.expires
, now
+ max_delay
) :
1138 try_to_del_timer_sync(&mp
->timer
) >= 0))
1139 mod_timer(&mp
->timer
, now
+ max_delay
);
1141 for (pp
= &mp
->ports
;
1142 (p
= mlock_dereference(*pp
, br
)) != NULL
;
1144 if (timer_pending(&p
->timer
) ?
1145 time_after(p
->timer
.expires
, now
+ max_delay
) :
1146 try_to_del_timer_sync(&p
->timer
) >= 0)
1147 mod_timer(&p
->timer
, now
+ max_delay
);
1151 spin_unlock(&br
->multicast_lock
);
1155 #if IS_ENABLED(CONFIG_IPV6)
1156 static int br_ip6_multicast_query(struct net_bridge
*br
,
1157 struct net_bridge_port
*port
,
1158 struct sk_buff
*skb
)
1160 const struct ipv6hdr
*ip6h
= ipv6_hdr(skb
);
1161 struct mld_msg
*mld
;
1162 struct net_bridge_mdb_entry
*mp
;
1163 struct mld2_query
*mld2q
;
1164 struct net_bridge_port_group
*p
;
1165 struct net_bridge_port_group __rcu
**pp
;
1166 unsigned long max_delay
;
1167 unsigned long now
= jiffies
;
1168 const struct in6_addr
*group
= NULL
;
1172 spin_lock(&br
->multicast_lock
);
1173 if (!netif_running(br
->dev
) ||
1174 (port
&& port
->state
== BR_STATE_DISABLED
))
1177 br_multicast_query_received(br
, port
, !ipv6_addr_any(&ip6h
->saddr
));
1179 if (skb
->len
== sizeof(*mld
)) {
1180 if (!pskb_may_pull(skb
, sizeof(*mld
))) {
1184 mld
= (struct mld_msg
*) icmp6_hdr(skb
);
1185 max_delay
= msecs_to_jiffies(ntohs(mld
->mld_maxdelay
));
1187 group
= &mld
->mld_mca
;
1188 } else if (skb
->len
>= sizeof(*mld2q
)) {
1189 if (!pskb_may_pull(skb
, sizeof(*mld2q
))) {
1193 mld2q
= (struct mld2_query
*)icmp6_hdr(skb
);
1194 if (!mld2q
->mld2q_nsrcs
)
1195 group
= &mld2q
->mld2q_mca
;
1196 max_delay
= mld2q
->mld2q_mrc
? MLDV2_MRC(ntohs(mld2q
->mld2q_mrc
)) : 1;
1202 br_vlan_get_tag(skb
, &vid
);
1203 mp
= br_mdb_ip6_get(mlock_dereference(br
->mdb
, br
), group
, vid
);
1207 setup_timer(&mp
->timer
, br_multicast_group_expired
, (unsigned long)mp
);
1208 mod_timer(&mp
->timer
, now
+ br
->multicast_membership_interval
);
1209 mp
->timer_armed
= true;
1211 max_delay
*= br
->multicast_last_member_count
;
1213 (timer_pending(&mp
->timer
) ?
1214 time_after(mp
->timer
.expires
, now
+ max_delay
) :
1215 try_to_del_timer_sync(&mp
->timer
) >= 0))
1216 mod_timer(&mp
->timer
, now
+ max_delay
);
1218 for (pp
= &mp
->ports
;
1219 (p
= mlock_dereference(*pp
, br
)) != NULL
;
1221 if (timer_pending(&p
->timer
) ?
1222 time_after(p
->timer
.expires
, now
+ max_delay
) :
1223 try_to_del_timer_sync(&p
->timer
) >= 0)
1224 mod_timer(&p
->timer
, now
+ max_delay
);
1228 spin_unlock(&br
->multicast_lock
);
1233 static void br_multicast_leave_group(struct net_bridge
*br
,
1234 struct net_bridge_port
*port
,
1235 struct br_ip
*group
)
1237 struct net_bridge_mdb_htable
*mdb
;
1238 struct net_bridge_mdb_entry
*mp
;
1239 struct net_bridge_port_group
*p
;
1243 spin_lock(&br
->multicast_lock
);
1244 if (!netif_running(br
->dev
) ||
1245 (port
&& port
->state
== BR_STATE_DISABLED
) ||
1246 timer_pending(&br
->multicast_querier_timer
))
1249 mdb
= mlock_dereference(br
->mdb
, br
);
1250 mp
= br_mdb_ip_get(mdb
, group
);
1254 if (br
->multicast_querier
&&
1255 !timer_pending(&br
->multicast_querier_timer
)) {
1256 __br_multicast_send_query(br
, port
, &mp
->addr
);
1258 time
= jiffies
+ br
->multicast_last_member_count
*
1259 br
->multicast_last_member_interval
;
1260 mod_timer(port
? &port
->multicast_query_timer
:
1261 &br
->multicast_query_timer
, time
);
1263 for (p
= mlock_dereference(mp
->ports
, br
);
1265 p
= mlock_dereference(p
->next
, br
)) {
1266 if (p
->port
!= port
)
1269 if (!hlist_unhashed(&p
->mglist
) &&
1270 (timer_pending(&p
->timer
) ?
1271 time_after(p
->timer
.expires
, time
) :
1272 try_to_del_timer_sync(&p
->timer
) >= 0)) {
1273 mod_timer(&p
->timer
, time
);
1280 if (port
&& (port
->flags
& BR_MULTICAST_FAST_LEAVE
)) {
1281 struct net_bridge_port_group __rcu
**pp
;
1283 for (pp
= &mp
->ports
;
1284 (p
= mlock_dereference(*pp
, br
)) != NULL
;
1286 if (p
->port
!= port
)
1289 rcu_assign_pointer(*pp
, p
->next
);
1290 hlist_del_init(&p
->mglist
);
1291 del_timer(&p
->timer
);
1292 call_rcu_bh(&p
->rcu
, br_multicast_free_pg
);
1293 br_mdb_notify(br
->dev
, port
, group
, RTM_DELMDB
);
1295 if (!mp
->ports
&& !mp
->mglist
&& mp
->timer_armed
&&
1296 netif_running(br
->dev
))
1297 mod_timer(&mp
->timer
, jiffies
);
1303 time
= now
+ br
->multicast_last_member_count
*
1304 br
->multicast_last_member_interval
;
1307 if (mp
->mglist
&& mp
->timer_armed
&&
1308 (timer_pending(&mp
->timer
) ?
1309 time_after(mp
->timer
.expires
, time
) :
1310 try_to_del_timer_sync(&mp
->timer
) >= 0)) {
1311 mod_timer(&mp
->timer
, time
);
1316 spin_unlock(&br
->multicast_lock
);
1319 static void br_ip4_multicast_leave_group(struct net_bridge
*br
,
1320 struct net_bridge_port
*port
,
1324 struct br_ip br_group
;
1326 if (ipv4_is_local_multicast(group
))
1329 br_group
.u
.ip4
= group
;
1330 br_group
.proto
= htons(ETH_P_IP
);
1333 br_multicast_leave_group(br
, port
, &br_group
);
1336 #if IS_ENABLED(CONFIG_IPV6)
1337 static void br_ip6_multicast_leave_group(struct net_bridge
*br
,
1338 struct net_bridge_port
*port
,
1339 const struct in6_addr
*group
,
1342 struct br_ip br_group
;
1344 if (!ipv6_is_transient_multicast(group
))
1347 br_group
.u
.ip6
= *group
;
1348 br_group
.proto
= htons(ETH_P_IPV6
);
1351 br_multicast_leave_group(br
, port
, &br_group
);
1355 static int br_multicast_ipv4_rcv(struct net_bridge
*br
,
1356 struct net_bridge_port
*port
,
1357 struct sk_buff
*skb
)
1359 struct sk_buff
*skb2
= skb
;
1360 const struct iphdr
*iph
;
1363 unsigned int offset
;
1367 /* We treat OOM as packet loss for now. */
1368 if (!pskb_may_pull(skb
, sizeof(*iph
)))
1373 if (iph
->ihl
< 5 || iph
->version
!= 4)
1376 if (!pskb_may_pull(skb
, ip_hdrlen(skb
)))
1381 if (unlikely(ip_fast_csum((u8
*)iph
, iph
->ihl
)))
1384 if (iph
->protocol
!= IPPROTO_IGMP
) {
1385 if (!ipv4_is_local_multicast(iph
->daddr
))
1386 BR_INPUT_SKB_CB(skb
)->mrouters_only
= 1;
1390 len
= ntohs(iph
->tot_len
);
1391 if (skb
->len
< len
|| len
< ip_hdrlen(skb
))
1394 if (skb
->len
> len
) {
1395 skb2
= skb_clone(skb
, GFP_ATOMIC
);
1399 err
= pskb_trim_rcsum(skb2
, len
);
1404 len
-= ip_hdrlen(skb2
);
1405 offset
= skb_network_offset(skb2
) + ip_hdrlen(skb2
);
1406 __skb_pull(skb2
, offset
);
1407 skb_reset_transport_header(skb2
);
1410 if (!pskb_may_pull(skb2
, sizeof(*ih
)))
1413 switch (skb2
->ip_summed
) {
1414 case CHECKSUM_COMPLETE
:
1415 if (!csum_fold(skb2
->csum
))
1420 if (skb_checksum_complete(skb2
))
1426 br_vlan_get_tag(skb2
, &vid
);
1427 BR_INPUT_SKB_CB(skb
)->igmp
= 1;
1428 ih
= igmp_hdr(skb2
);
1431 case IGMP_HOST_MEMBERSHIP_REPORT
:
1432 case IGMPV2_HOST_MEMBERSHIP_REPORT
:
1433 BR_INPUT_SKB_CB(skb
)->mrouters_only
= 1;
1434 err
= br_ip4_multicast_add_group(br
, port
, ih
->group
, vid
);
1436 case IGMPV3_HOST_MEMBERSHIP_REPORT
:
1437 err
= br_ip4_multicast_igmp3_report(br
, port
, skb2
);
1439 case IGMP_HOST_MEMBERSHIP_QUERY
:
1440 err
= br_ip4_multicast_query(br
, port
, skb2
);
1442 case IGMP_HOST_LEAVE_MESSAGE
:
1443 br_ip4_multicast_leave_group(br
, port
, ih
->group
, vid
);
1448 __skb_push(skb2
, offset
);
1455 #if IS_ENABLED(CONFIG_IPV6)
1456 static int br_multicast_ipv6_rcv(struct net_bridge
*br
,
1457 struct net_bridge_port
*port
,
1458 struct sk_buff
*skb
)
1460 struct sk_buff
*skb2
;
1461 const struct ipv6hdr
*ip6h
;
1470 if (!pskb_may_pull(skb
, sizeof(*ip6h
)))
1473 ip6h
= ipv6_hdr(skb
);
1476 * We're interested in MLD messages only.
1478 * - MLD has always Router Alert hop-by-hop option
1479 * - But we do not support jumbrograms.
1481 if (ip6h
->version
!= 6 ||
1482 ip6h
->nexthdr
!= IPPROTO_HOPOPTS
||
1483 ip6h
->payload_len
== 0)
1486 len
= ntohs(ip6h
->payload_len
) + sizeof(*ip6h
);
1490 nexthdr
= ip6h
->nexthdr
;
1491 offset
= ipv6_skip_exthdr(skb
, sizeof(*ip6h
), &nexthdr
, &frag_off
);
1493 if (offset
< 0 || nexthdr
!= IPPROTO_ICMPV6
)
1496 /* Okay, we found ICMPv6 header */
1497 skb2
= skb_clone(skb
, GFP_ATOMIC
);
1502 if (!pskb_may_pull(skb2
, offset
+ sizeof(struct icmp6hdr
)))
1505 len
-= offset
- skb_network_offset(skb2
);
1507 __skb_pull(skb2
, offset
);
1508 skb_reset_transport_header(skb2
);
1509 skb_postpull_rcsum(skb2
, skb_network_header(skb2
),
1510 skb_network_header_len(skb2
));
1512 icmp6_type
= icmp6_hdr(skb2
)->icmp6_type
;
1514 switch (icmp6_type
) {
1515 case ICMPV6_MGM_QUERY
:
1516 case ICMPV6_MGM_REPORT
:
1517 case ICMPV6_MGM_REDUCTION
:
1518 case ICMPV6_MLD2_REPORT
:
1525 /* Okay, we found MLD message. Check further. */
1526 if (skb2
->len
> len
) {
1527 err
= pskb_trim_rcsum(skb2
, len
);
1533 ip6h
= ipv6_hdr(skb2
);
1535 switch (skb2
->ip_summed
) {
1536 case CHECKSUM_COMPLETE
:
1537 if (!csum_ipv6_magic(&ip6h
->saddr
, &ip6h
->daddr
, skb2
->len
,
1538 IPPROTO_ICMPV6
, skb2
->csum
))
1542 skb2
->csum
= ~csum_unfold(csum_ipv6_magic(&ip6h
->saddr
,
1545 IPPROTO_ICMPV6
, 0));
1546 if (__skb_checksum_complete(skb2
))
1552 br_vlan_get_tag(skb
, &vid
);
1553 BR_INPUT_SKB_CB(skb
)->igmp
= 1;
1555 switch (icmp6_type
) {
1556 case ICMPV6_MGM_REPORT
:
1558 struct mld_msg
*mld
;
1559 if (!pskb_may_pull(skb2
, sizeof(*mld
))) {
1563 mld
= (struct mld_msg
*)skb_transport_header(skb2
);
1564 BR_INPUT_SKB_CB(skb
)->mrouters_only
= 1;
1565 err
= br_ip6_multicast_add_group(br
, port
, &mld
->mld_mca
, vid
);
1568 case ICMPV6_MLD2_REPORT
:
1569 err
= br_ip6_multicast_mld2_report(br
, port
, skb2
);
1571 case ICMPV6_MGM_QUERY
:
1572 err
= br_ip6_multicast_query(br
, port
, skb2
);
1574 case ICMPV6_MGM_REDUCTION
:
1576 struct mld_msg
*mld
;
1577 if (!pskb_may_pull(skb2
, sizeof(*mld
))) {
1581 mld
= (struct mld_msg
*)skb_transport_header(skb2
);
1582 br_ip6_multicast_leave_group(br
, port
, &mld
->mld_mca
, vid
);
1592 int br_multicast_rcv(struct net_bridge
*br
, struct net_bridge_port
*port
,
1593 struct sk_buff
*skb
)
1595 BR_INPUT_SKB_CB(skb
)->igmp
= 0;
1596 BR_INPUT_SKB_CB(skb
)->mrouters_only
= 0;
1598 if (br
->multicast_disabled
)
1601 switch (skb
->protocol
) {
1602 case htons(ETH_P_IP
):
1603 return br_multicast_ipv4_rcv(br
, port
, skb
);
1604 #if IS_ENABLED(CONFIG_IPV6)
1605 case htons(ETH_P_IPV6
):
1606 return br_multicast_ipv6_rcv(br
, port
, skb
);
1613 static void br_multicast_query_expired(unsigned long data
)
1615 struct net_bridge
*br
= (void *)data
;
1617 spin_lock(&br
->multicast_lock
);
1618 if (br
->multicast_startup_queries_sent
<
1619 br
->multicast_startup_query_count
)
1620 br
->multicast_startup_queries_sent
++;
1622 br_multicast_send_query(br
, NULL
, br
->multicast_startup_queries_sent
);
1624 spin_unlock(&br
->multicast_lock
);
1627 void br_multicast_init(struct net_bridge
*br
)
1629 br
->hash_elasticity
= 4;
1632 br
->multicast_router
= 1;
1633 br
->multicast_querier
= 0;
1634 br
->multicast_query_use_ifaddr
= 0;
1635 br
->multicast_last_member_count
= 2;
1636 br
->multicast_startup_query_count
= 2;
1638 br
->multicast_last_member_interval
= HZ
;
1639 br
->multicast_query_response_interval
= 10 * HZ
;
1640 br
->multicast_startup_query_interval
= 125 * HZ
/ 4;
1641 br
->multicast_query_interval
= 125 * HZ
;
1642 br
->multicast_querier_interval
= 255 * HZ
;
1643 br
->multicast_membership_interval
= 260 * HZ
;
1645 spin_lock_init(&br
->multicast_lock
);
1646 setup_timer(&br
->multicast_router_timer
,
1647 br_multicast_local_router_expired
, 0);
1648 setup_timer(&br
->multicast_querier_timer
,
1649 br_multicast_querier_expired
, (unsigned long)br
);
1650 setup_timer(&br
->multicast_query_timer
, br_multicast_query_expired
,
1654 void br_multicast_open(struct net_bridge
*br
)
1656 br
->multicast_startup_queries_sent
= 0;
1658 if (br
->multicast_disabled
)
1661 mod_timer(&br
->multicast_query_timer
, jiffies
);
1664 void br_multicast_stop(struct net_bridge
*br
)
1666 struct net_bridge_mdb_htable
*mdb
;
1667 struct net_bridge_mdb_entry
*mp
;
1668 struct hlist_node
*n
;
1672 del_timer_sync(&br
->multicast_router_timer
);
1673 del_timer_sync(&br
->multicast_querier_timer
);
1674 del_timer_sync(&br
->multicast_query_timer
);
1676 spin_lock_bh(&br
->multicast_lock
);
1677 mdb
= mlock_dereference(br
->mdb
, br
);
1684 for (i
= 0; i
< mdb
->max
; i
++) {
1685 hlist_for_each_entry_safe(mp
, n
, &mdb
->mhash
[i
],
1687 del_timer(&mp
->timer
);
1688 mp
->timer_armed
= false;
1689 call_rcu_bh(&mp
->rcu
, br_multicast_free_group
);
1694 spin_unlock_bh(&br
->multicast_lock
);
1696 spin_lock_bh(&br
->multicast_lock
);
1701 call_rcu_bh(&mdb
->rcu
, br_mdb_free
);
1704 spin_unlock_bh(&br
->multicast_lock
);
1707 int br_multicast_set_router(struct net_bridge
*br
, unsigned long val
)
1711 spin_lock_bh(&br
->multicast_lock
);
1712 if (!netif_running(br
->dev
))
1718 del_timer(&br
->multicast_router_timer
);
1721 br
->multicast_router
= val
;
1731 spin_unlock_bh(&br
->multicast_lock
);
1736 int br_multicast_set_port_router(struct net_bridge_port
*p
, unsigned long val
)
1738 struct net_bridge
*br
= p
->br
;
1741 spin_lock(&br
->multicast_lock
);
1742 if (!netif_running(br
->dev
) || p
->state
== BR_STATE_DISABLED
)
1749 p
->multicast_router
= val
;
1752 if (val
< 2 && !hlist_unhashed(&p
->rlist
))
1753 hlist_del_init_rcu(&p
->rlist
);
1758 del_timer(&p
->multicast_router_timer
);
1763 br_multicast_add_router(br
, p
);
1772 spin_unlock(&br
->multicast_lock
);
1777 static void br_multicast_start_querier(struct net_bridge
*br
)
1779 struct net_bridge_port
*port
;
1781 br_multicast_open(br
);
1783 list_for_each_entry(port
, &br
->port_list
, list
) {
1784 if (port
->state
== BR_STATE_DISABLED
||
1785 port
->state
== BR_STATE_BLOCKING
)
1788 __br_multicast_enable_port(port
);
1792 int br_multicast_toggle(struct net_bridge
*br
, unsigned long val
)
1795 struct net_bridge_mdb_htable
*mdb
;
1797 spin_lock_bh(&br
->multicast_lock
);
1798 if (br
->multicast_disabled
== !val
)
1801 br
->multicast_disabled
= !val
;
1802 if (br
->multicast_disabled
)
1805 if (!netif_running(br
->dev
))
1808 mdb
= mlock_dereference(br
->mdb
, br
);
1813 br
->multicast_disabled
= !!val
;
1817 err
= br_mdb_rehash(&br
->mdb
, mdb
->max
,
1818 br
->hash_elasticity
);
1823 br_multicast_start_querier(br
);
1826 spin_unlock_bh(&br
->multicast_lock
);
1831 int br_multicast_set_querier(struct net_bridge
*br
, unsigned long val
)
1835 spin_lock_bh(&br
->multicast_lock
);
1836 if (br
->multicast_querier
== val
)
1839 br
->multicast_querier
= val
;
1841 br_multicast_start_querier(br
);
1844 spin_unlock_bh(&br
->multicast_lock
);
1849 int br_multicast_set_hash_max(struct net_bridge
*br
, unsigned long val
)
1853 struct net_bridge_mdb_htable
*mdb
;
1855 spin_lock(&br
->multicast_lock
);
1856 if (!netif_running(br
->dev
))
1860 if (!is_power_of_2(val
))
1863 mdb
= mlock_dereference(br
->mdb
, br
);
1864 if (mdb
&& val
< mdb
->size
)
1880 err
= br_mdb_rehash(&br
->mdb
, br
->hash_max
,
1881 br
->hash_elasticity
);
1887 spin_unlock(&br
->multicast_lock
);