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>
27 #if IS_ENABLED(CONFIG_IPV6)
30 #include <net/ip6_checksum.h>
33 #include "br_private.h"
35 static void br_multicast_start_querier(struct net_bridge
*br
);
36 unsigned int br_mdb_rehash_seq
;
38 static inline int br_ip_equal(const struct br_ip
*a
, const struct br_ip
*b
)
40 if (a
->proto
!= b
->proto
)
44 return a
->u
.ip4
== b
->u
.ip4
;
45 #if IS_ENABLED(CONFIG_IPV6)
46 case htons(ETH_P_IPV6
):
47 return ipv6_addr_equal(&a
->u
.ip6
, &b
->u
.ip6
);
53 static inline int __br_ip4_hash(struct net_bridge_mdb_htable
*mdb
, __be32 ip
)
55 return jhash_1word(mdb
->secret
, (__force u32
)ip
) & (mdb
->max
- 1);
58 #if IS_ENABLED(CONFIG_IPV6)
59 static inline int __br_ip6_hash(struct net_bridge_mdb_htable
*mdb
,
60 const struct in6_addr
*ip
)
62 return jhash2((__force u32
*)ip
->s6_addr32
, 4, mdb
->secret
) & (mdb
->max
- 1);
66 static inline int br_ip_hash(struct net_bridge_mdb_htable
*mdb
,
71 return __br_ip4_hash(mdb
, ip
->u
.ip4
);
72 #if IS_ENABLED(CONFIG_IPV6)
73 case htons(ETH_P_IPV6
):
74 return __br_ip6_hash(mdb
, &ip
->u
.ip6
);
80 static struct net_bridge_mdb_entry
*__br_mdb_ip_get(
81 struct net_bridge_mdb_htable
*mdb
, struct br_ip
*dst
, int hash
)
83 struct net_bridge_mdb_entry
*mp
;
86 hlist_for_each_entry_rcu(mp
, p
, &mdb
->mhash
[hash
], hlist
[mdb
->ver
]) {
87 if (br_ip_equal(&mp
->addr
, dst
))
94 struct net_bridge_mdb_entry
*br_mdb_ip_get(struct net_bridge_mdb_htable
*mdb
,
100 return __br_mdb_ip_get(mdb
, dst
, br_ip_hash(mdb
, dst
));
103 static struct net_bridge_mdb_entry
*br_mdb_ip4_get(
104 struct net_bridge_mdb_htable
*mdb
, __be32 dst
)
109 br_dst
.proto
= htons(ETH_P_IP
);
111 return br_mdb_ip_get(mdb
, &br_dst
);
114 #if IS_ENABLED(CONFIG_IPV6)
115 static struct net_bridge_mdb_entry
*br_mdb_ip6_get(
116 struct net_bridge_mdb_htable
*mdb
, const struct in6_addr
*dst
)
121 br_dst
.proto
= htons(ETH_P_IPV6
);
123 return br_mdb_ip_get(mdb
, &br_dst
);
127 struct net_bridge_mdb_entry
*br_mdb_get(struct net_bridge
*br
,
130 struct net_bridge_mdb_htable
*mdb
= rcu_dereference(br
->mdb
);
133 if (br
->multicast_disabled
)
136 if (BR_INPUT_SKB_CB(skb
)->igmp
)
139 ip
.proto
= skb
->protocol
;
141 switch (skb
->protocol
) {
142 case htons(ETH_P_IP
):
143 ip
.u
.ip4
= ip_hdr(skb
)->daddr
;
145 #if IS_ENABLED(CONFIG_IPV6)
146 case htons(ETH_P_IPV6
):
147 ip
.u
.ip6
= ipv6_hdr(skb
)->daddr
;
154 return br_mdb_ip_get(mdb
, &ip
);
157 static void br_mdb_free(struct rcu_head
*head
)
159 struct net_bridge_mdb_htable
*mdb
=
160 container_of(head
, struct net_bridge_mdb_htable
, rcu
);
161 struct net_bridge_mdb_htable
*old
= mdb
->old
;
168 static int br_mdb_copy(struct net_bridge_mdb_htable
*new,
169 struct net_bridge_mdb_htable
*old
,
172 struct net_bridge_mdb_entry
*mp
;
173 struct hlist_node
*p
;
178 for (i
= 0; i
< old
->max
; i
++)
179 hlist_for_each_entry(mp
, p
, &old
->mhash
[i
], hlist
[old
->ver
])
180 hlist_add_head(&mp
->hlist
[new->ver
],
181 &new->mhash
[br_ip_hash(new, &mp
->addr
)]);
187 for (i
= 0; i
< new->max
; i
++) {
189 hlist_for_each_entry(mp
, p
, &new->mhash
[i
], hlist
[new->ver
])
195 return maxlen
> elasticity
? -EINVAL
: 0;
198 void br_multicast_free_pg(struct rcu_head
*head
)
200 struct net_bridge_port_group
*p
=
201 container_of(head
, struct net_bridge_port_group
, rcu
);
206 static void br_multicast_free_group(struct rcu_head
*head
)
208 struct net_bridge_mdb_entry
*mp
=
209 container_of(head
, struct net_bridge_mdb_entry
, rcu
);
214 static void br_multicast_group_expired(unsigned long data
)
216 struct net_bridge_mdb_entry
*mp
= (void *)data
;
217 struct net_bridge
*br
= mp
->br
;
218 struct net_bridge_mdb_htable
*mdb
;
220 spin_lock(&br
->multicast_lock
);
221 if (!netif_running(br
->dev
) || timer_pending(&mp
->timer
))
229 mdb
= mlock_dereference(br
->mdb
, br
);
231 hlist_del_rcu(&mp
->hlist
[mdb
->ver
]);
234 call_rcu_bh(&mp
->rcu
, br_multicast_free_group
);
237 spin_unlock(&br
->multicast_lock
);
240 static void br_multicast_del_pg(struct net_bridge
*br
,
241 struct net_bridge_port_group
*pg
)
243 struct net_bridge_mdb_htable
*mdb
;
244 struct net_bridge_mdb_entry
*mp
;
245 struct net_bridge_port_group
*p
;
246 struct net_bridge_port_group __rcu
**pp
;
248 mdb
= mlock_dereference(br
->mdb
, br
);
250 mp
= br_mdb_ip_get(mdb
, &pg
->addr
);
254 for (pp
= &mp
->ports
;
255 (p
= mlock_dereference(*pp
, br
)) != NULL
;
260 rcu_assign_pointer(*pp
, p
->next
);
261 hlist_del_init(&p
->mglist
);
262 del_timer(&p
->timer
);
263 call_rcu_bh(&p
->rcu
, br_multicast_free_pg
);
265 if (!mp
->ports
&& !mp
->mglist
&&
266 netif_running(br
->dev
))
267 mod_timer(&mp
->timer
, jiffies
);
275 static void br_multicast_port_group_expired(unsigned long data
)
277 struct net_bridge_port_group
*pg
= (void *)data
;
278 struct net_bridge
*br
= pg
->port
->br
;
280 spin_lock(&br
->multicast_lock
);
281 if (!netif_running(br
->dev
) || timer_pending(&pg
->timer
) ||
282 hlist_unhashed(&pg
->mglist
) || pg
->state
& MDB_PERMANENT
)
285 br_multicast_del_pg(br
, pg
);
288 spin_unlock(&br
->multicast_lock
);
291 static int br_mdb_rehash(struct net_bridge_mdb_htable __rcu
**mdbp
, int max
,
294 struct net_bridge_mdb_htable
*old
= rcu_dereference_protected(*mdbp
, 1);
295 struct net_bridge_mdb_htable
*mdb
;
298 mdb
= kmalloc(sizeof(*mdb
), GFP_ATOMIC
);
305 mdb
->mhash
= kzalloc(max
* sizeof(*mdb
->mhash
), GFP_ATOMIC
);
311 mdb
->size
= old
? old
->size
: 0;
312 mdb
->ver
= old
? old
->ver
^ 1 : 0;
314 if (!old
|| elasticity
)
315 get_random_bytes(&mdb
->secret
, sizeof(mdb
->secret
));
317 mdb
->secret
= old
->secret
;
322 err
= br_mdb_copy(mdb
, old
, elasticity
);
330 call_rcu_bh(&mdb
->rcu
, br_mdb_free
);
333 rcu_assign_pointer(*mdbp
, mdb
);
338 static struct sk_buff
*br_ip4_multicast_alloc_query(struct net_bridge
*br
,
346 skb
= netdev_alloc_skb_ip_align(br
->dev
, sizeof(*eth
) + sizeof(*iph
) +
351 skb
->protocol
= htons(ETH_P_IP
);
353 skb_reset_mac_header(skb
);
356 memcpy(eth
->h_source
, br
->dev
->dev_addr
, 6);
359 eth
->h_dest
[2] = 0x5e;
363 eth
->h_proto
= htons(ETH_P_IP
);
364 skb_put(skb
, sizeof(*eth
));
366 skb_set_network_header(skb
, skb
->len
);
372 iph
->tot_len
= htons(sizeof(*iph
) + sizeof(*ih
) + 4);
374 iph
->frag_off
= htons(IP_DF
);
376 iph
->protocol
= IPPROTO_IGMP
;
378 iph
->daddr
= htonl(INADDR_ALLHOSTS_GROUP
);
379 ((u8
*)&iph
[1])[0] = IPOPT_RA
;
380 ((u8
*)&iph
[1])[1] = 4;
381 ((u8
*)&iph
[1])[2] = 0;
382 ((u8
*)&iph
[1])[3] = 0;
386 skb_set_transport_header(skb
, skb
->len
);
388 ih
->type
= IGMP_HOST_MEMBERSHIP_QUERY
;
389 ih
->code
= (group
? br
->multicast_last_member_interval
:
390 br
->multicast_query_response_interval
) /
391 (HZ
/ IGMP_TIMER_SCALE
);
394 ih
->csum
= ip_compute_csum((void *)ih
, sizeof(struct igmphdr
));
395 skb_put(skb
, sizeof(*ih
));
397 __skb_pull(skb
, sizeof(*eth
));
403 #if IS_ENABLED(CONFIG_IPV6)
404 static struct sk_buff
*br_ip6_multicast_alloc_query(struct net_bridge
*br
,
405 const struct in6_addr
*group
)
408 struct ipv6hdr
*ip6h
;
409 struct mld_msg
*mldq
;
412 unsigned long interval
;
414 skb
= netdev_alloc_skb_ip_align(br
->dev
, sizeof(*eth
) + sizeof(*ip6h
) +
419 skb
->protocol
= htons(ETH_P_IPV6
);
421 /* Ethernet header */
422 skb_reset_mac_header(skb
);
425 memcpy(eth
->h_source
, br
->dev
->dev_addr
, 6);
426 eth
->h_proto
= htons(ETH_P_IPV6
);
427 skb_put(skb
, sizeof(*eth
));
429 /* IPv6 header + HbH option */
430 skb_set_network_header(skb
, skb
->len
);
431 ip6h
= ipv6_hdr(skb
);
433 *(__force __be32
*)ip6h
= htonl(0x60000000);
434 ip6h
->payload_len
= htons(8 + sizeof(*mldq
));
435 ip6h
->nexthdr
= IPPROTO_HOPOPTS
;
437 ipv6_addr_set(&ip6h
->daddr
, htonl(0xff020000), 0, 0, htonl(1));
438 if (ipv6_dev_get_saddr(dev_net(br
->dev
), br
->dev
, &ip6h
->daddr
, 0,
443 ipv6_eth_mc_map(&ip6h
->daddr
, eth
->h_dest
);
445 hopopt
= (u8
*)(ip6h
+ 1);
446 hopopt
[0] = IPPROTO_ICMPV6
; /* next hdr */
447 hopopt
[1] = 0; /* length of HbH */
448 hopopt
[2] = IPV6_TLV_ROUTERALERT
; /* Router Alert */
449 hopopt
[3] = 2; /* Length of RA Option */
450 hopopt
[4] = 0; /* Type = 0x0000 (MLD) */
452 hopopt
[6] = IPV6_TLV_PAD1
; /* Pad1 */
453 hopopt
[7] = IPV6_TLV_PAD1
; /* Pad1 */
455 skb_put(skb
, sizeof(*ip6h
) + 8);
458 skb_set_transport_header(skb
, skb
->len
);
459 mldq
= (struct mld_msg
*) icmp6_hdr(skb
);
461 interval
= ipv6_addr_any(group
) ? br
->multicast_last_member_interval
:
462 br
->multicast_query_response_interval
;
464 mldq
->mld_type
= ICMPV6_MGM_QUERY
;
467 mldq
->mld_maxdelay
= htons((u16
)jiffies_to_msecs(interval
));
468 mldq
->mld_reserved
= 0;
469 mldq
->mld_mca
= *group
;
472 mldq
->mld_cksum
= csum_ipv6_magic(&ip6h
->saddr
, &ip6h
->daddr
,
473 sizeof(*mldq
), IPPROTO_ICMPV6
,
476 skb_put(skb
, sizeof(*mldq
));
478 __skb_pull(skb
, sizeof(*eth
));
485 static struct sk_buff
*br_multicast_alloc_query(struct net_bridge
*br
,
488 switch (addr
->proto
) {
489 case htons(ETH_P_IP
):
490 return br_ip4_multicast_alloc_query(br
, addr
->u
.ip4
);
491 #if IS_ENABLED(CONFIG_IPV6)
492 case htons(ETH_P_IPV6
):
493 return br_ip6_multicast_alloc_query(br
, &addr
->u
.ip6
);
499 static struct net_bridge_mdb_entry
*br_multicast_get_group(
500 struct net_bridge
*br
, struct net_bridge_port
*port
,
501 struct br_ip
*group
, int hash
)
503 struct net_bridge_mdb_htable
*mdb
;
504 struct net_bridge_mdb_entry
*mp
;
505 struct hlist_node
*p
;
506 unsigned int count
= 0;
511 mdb
= rcu_dereference_protected(br
->mdb
, 1);
512 hlist_for_each_entry(mp
, p
, &mdb
->mhash
[hash
], hlist
[mdb
->ver
]) {
514 if (unlikely(br_ip_equal(group
, &mp
->addr
)))
521 if (unlikely(count
> br
->hash_elasticity
&& count
)) {
523 br_info(br
, "Multicast hash table "
524 "chain limit reached: %s\n",
525 port
? port
->dev
->name
: br
->dev
->name
);
527 elasticity
= br
->hash_elasticity
;
530 if (mdb
->size
>= max
) {
532 if (unlikely(max
> br
->hash_max
)) {
533 br_warn(br
, "Multicast hash table maximum of %d "
534 "reached, disabling snooping: %s\n",
536 port
? port
->dev
->name
: br
->dev
->name
);
539 br
->multicast_disabled
= 1;
544 if (max
> mdb
->max
|| elasticity
) {
547 br_info(br
, "Multicast hash table "
549 port
? port
->dev
->name
: br
->dev
->name
);
554 err
= br_mdb_rehash(&br
->mdb
, max
, elasticity
);
556 br_warn(br
, "Cannot rehash multicast "
557 "hash table, disabling snooping: %s, %d, %d\n",
558 port
? port
->dev
->name
: br
->dev
->name
,
574 struct net_bridge_mdb_entry
*br_multicast_new_group(struct net_bridge
*br
,
575 struct net_bridge_port
*port
, struct br_ip
*group
)
577 struct net_bridge_mdb_htable
*mdb
;
578 struct net_bridge_mdb_entry
*mp
;
582 mdb
= rcu_dereference_protected(br
->mdb
, 1);
584 err
= br_mdb_rehash(&br
->mdb
, BR_HASH_SIZE
, 0);
590 hash
= br_ip_hash(mdb
, group
);
591 mp
= br_multicast_get_group(br
, port
, group
, hash
);
592 switch (PTR_ERR(mp
)) {
598 mdb
= rcu_dereference_protected(br
->mdb
, 1);
599 hash
= br_ip_hash(mdb
, group
);
606 mp
= kzalloc(sizeof(*mp
), GFP_ATOMIC
);
608 return ERR_PTR(-ENOMEM
);
612 setup_timer(&mp
->timer
, br_multicast_group_expired
,
615 hlist_add_head_rcu(&mp
->hlist
[mdb
->ver
], &mdb
->mhash
[hash
]);
622 struct net_bridge_port_group
*br_multicast_new_port_group(
623 struct net_bridge_port
*port
,
625 struct net_bridge_port_group __rcu
*next
,
628 struct net_bridge_port_group
*p
;
630 p
= kzalloc(sizeof(*p
), GFP_ATOMIC
);
637 rcu_assign_pointer(p
->next
, next
);
638 hlist_add_head(&p
->mglist
, &port
->mglist
);
639 setup_timer(&p
->timer
, br_multicast_port_group_expired
,
644 static int br_multicast_add_group(struct net_bridge
*br
,
645 struct net_bridge_port
*port
,
648 struct net_bridge_mdb_entry
*mp
;
649 struct net_bridge_port_group
*p
;
650 struct net_bridge_port_group __rcu
**pp
;
651 unsigned long now
= jiffies
;
654 spin_lock(&br
->multicast_lock
);
655 if (!netif_running(br
->dev
) ||
656 (port
&& port
->state
== BR_STATE_DISABLED
))
659 mp
= br_multicast_new_group(br
, port
, group
);
666 mod_timer(&mp
->timer
, now
+ br
->multicast_membership_interval
);
670 for (pp
= &mp
->ports
;
671 (p
= mlock_dereference(*pp
, br
)) != NULL
;
675 if ((unsigned long)p
->port
< (unsigned long)port
)
679 p
= br_multicast_new_port_group(port
, group
, *pp
, MDB_TEMPORARY
);
682 rcu_assign_pointer(*pp
, p
);
683 br_mdb_notify(br
->dev
, port
, group
, RTM_NEWMDB
);
686 mod_timer(&p
->timer
, now
+ br
->multicast_membership_interval
);
691 spin_unlock(&br
->multicast_lock
);
695 static int br_ip4_multicast_add_group(struct net_bridge
*br
,
696 struct net_bridge_port
*port
,
699 struct br_ip br_group
;
701 if (ipv4_is_local_multicast(group
))
704 br_group
.u
.ip4
= group
;
705 br_group
.proto
= htons(ETH_P_IP
);
707 return br_multicast_add_group(br
, port
, &br_group
);
710 #if IS_ENABLED(CONFIG_IPV6)
711 static int br_ip6_multicast_add_group(struct net_bridge
*br
,
712 struct net_bridge_port
*port
,
713 const struct in6_addr
*group
)
715 struct br_ip br_group
;
717 if (!ipv6_is_transient_multicast(group
))
720 br_group
.u
.ip6
= *group
;
721 br_group
.proto
= htons(ETH_P_IPV6
);
723 return br_multicast_add_group(br
, port
, &br_group
);
727 static void br_multicast_router_expired(unsigned long data
)
729 struct net_bridge_port
*port
= (void *)data
;
730 struct net_bridge
*br
= port
->br
;
732 spin_lock(&br
->multicast_lock
);
733 if (port
->multicast_router
!= 1 ||
734 timer_pending(&port
->multicast_router_timer
) ||
735 hlist_unhashed(&port
->rlist
))
738 hlist_del_init_rcu(&port
->rlist
);
741 spin_unlock(&br
->multicast_lock
);
744 static void br_multicast_local_router_expired(unsigned long data
)
748 static void br_multicast_querier_expired(unsigned long data
)
750 struct net_bridge
*br
= (void *)data
;
752 spin_lock(&br
->multicast_lock
);
753 if (!netif_running(br
->dev
) || br
->multicast_disabled
)
756 br_multicast_start_querier(br
);
759 spin_unlock(&br
->multicast_lock
);
762 static void __br_multicast_send_query(struct net_bridge
*br
,
763 struct net_bridge_port
*port
,
768 skb
= br_multicast_alloc_query(br
, ip
);
773 __skb_push(skb
, sizeof(struct ethhdr
));
774 skb
->dev
= port
->dev
;
775 NF_HOOK(NFPROTO_BRIDGE
, NF_BR_LOCAL_OUT
, skb
, NULL
, skb
->dev
,
781 static void br_multicast_send_query(struct net_bridge
*br
,
782 struct net_bridge_port
*port
, u32 sent
)
785 struct br_ip br_group
;
787 if (!netif_running(br
->dev
) || br
->multicast_disabled
||
788 !br
->multicast_querier
||
789 timer_pending(&br
->multicast_querier_timer
))
792 memset(&br_group
.u
, 0, sizeof(br_group
.u
));
794 br_group
.proto
= htons(ETH_P_IP
);
795 __br_multicast_send_query(br
, port
, &br_group
);
797 #if IS_ENABLED(CONFIG_IPV6)
798 br_group
.proto
= htons(ETH_P_IPV6
);
799 __br_multicast_send_query(br
, port
, &br_group
);
803 time
+= sent
< br
->multicast_startup_query_count
?
804 br
->multicast_startup_query_interval
:
805 br
->multicast_query_interval
;
806 mod_timer(port
? &port
->multicast_query_timer
:
807 &br
->multicast_query_timer
, time
);
810 static void br_multicast_port_query_expired(unsigned long data
)
812 struct net_bridge_port
*port
= (void *)data
;
813 struct net_bridge
*br
= port
->br
;
815 spin_lock(&br
->multicast_lock
);
816 if (port
->state
== BR_STATE_DISABLED
||
817 port
->state
== BR_STATE_BLOCKING
)
820 if (port
->multicast_startup_queries_sent
<
821 br
->multicast_startup_query_count
)
822 port
->multicast_startup_queries_sent
++;
824 br_multicast_send_query(port
->br
, port
,
825 port
->multicast_startup_queries_sent
);
828 spin_unlock(&br
->multicast_lock
);
831 void br_multicast_add_port(struct net_bridge_port
*port
)
833 port
->multicast_router
= 1;
835 setup_timer(&port
->multicast_router_timer
, br_multicast_router_expired
,
836 (unsigned long)port
);
837 setup_timer(&port
->multicast_query_timer
,
838 br_multicast_port_query_expired
, (unsigned long)port
);
841 void br_multicast_del_port(struct net_bridge_port
*port
)
843 del_timer_sync(&port
->multicast_router_timer
);
846 static void __br_multicast_enable_port(struct net_bridge_port
*port
)
848 port
->multicast_startup_queries_sent
= 0;
850 if (try_to_del_timer_sync(&port
->multicast_query_timer
) >= 0 ||
851 del_timer(&port
->multicast_query_timer
))
852 mod_timer(&port
->multicast_query_timer
, jiffies
);
855 void br_multicast_enable_port(struct net_bridge_port
*port
)
857 struct net_bridge
*br
= port
->br
;
859 spin_lock(&br
->multicast_lock
);
860 if (br
->multicast_disabled
|| !netif_running(br
->dev
))
863 __br_multicast_enable_port(port
);
866 spin_unlock(&br
->multicast_lock
);
869 void br_multicast_disable_port(struct net_bridge_port
*port
)
871 struct net_bridge
*br
= port
->br
;
872 struct net_bridge_port_group
*pg
;
873 struct hlist_node
*p
, *n
;
875 spin_lock(&br
->multicast_lock
);
876 hlist_for_each_entry_safe(pg
, p
, n
, &port
->mglist
, mglist
)
877 br_multicast_del_pg(br
, pg
);
879 if (!hlist_unhashed(&port
->rlist
))
880 hlist_del_init_rcu(&port
->rlist
);
881 del_timer(&port
->multicast_router_timer
);
882 del_timer(&port
->multicast_query_timer
);
883 spin_unlock(&br
->multicast_lock
);
886 static int br_ip4_multicast_igmp3_report(struct net_bridge
*br
,
887 struct net_bridge_port
*port
,
890 struct igmpv3_report
*ih
;
891 struct igmpv3_grec
*grec
;
899 if (!pskb_may_pull(skb
, sizeof(*ih
)))
902 ih
= igmpv3_report_hdr(skb
);
903 num
= ntohs(ih
->ngrec
);
906 for (i
= 0; i
< num
; i
++) {
907 len
+= sizeof(*grec
);
908 if (!pskb_may_pull(skb
, len
))
911 grec
= (void *)(skb
->data
+ len
- sizeof(*grec
));
912 group
= grec
->grec_mca
;
913 type
= grec
->grec_type
;
915 len
+= ntohs(grec
->grec_nsrcs
) * 4;
916 if (!pskb_may_pull(skb
, len
))
919 /* We treat this as an IGMPv2 report for now. */
921 case IGMPV3_MODE_IS_INCLUDE
:
922 case IGMPV3_MODE_IS_EXCLUDE
:
923 case IGMPV3_CHANGE_TO_INCLUDE
:
924 case IGMPV3_CHANGE_TO_EXCLUDE
:
925 case IGMPV3_ALLOW_NEW_SOURCES
:
926 case IGMPV3_BLOCK_OLD_SOURCES
:
933 err
= br_ip4_multicast_add_group(br
, port
, group
);
941 #if IS_ENABLED(CONFIG_IPV6)
942 static int br_ip6_multicast_mld2_report(struct net_bridge
*br
,
943 struct net_bridge_port
*port
,
946 struct icmp6hdr
*icmp6h
;
947 struct mld2_grec
*grec
;
953 if (!pskb_may_pull(skb
, sizeof(*icmp6h
)))
956 icmp6h
= icmp6_hdr(skb
);
957 num
= ntohs(icmp6h
->icmp6_dataun
.un_data16
[1]);
958 len
= sizeof(*icmp6h
);
960 for (i
= 0; i
< num
; i
++) {
961 __be16
*nsrcs
, _nsrcs
;
963 nsrcs
= skb_header_pointer(skb
,
964 len
+ offsetof(struct mld2_grec
,
966 sizeof(_nsrcs
), &_nsrcs
);
970 if (!pskb_may_pull(skb
,
971 len
+ sizeof(*grec
) +
972 sizeof(struct in6_addr
) * ntohs(*nsrcs
)))
975 grec
= (struct mld2_grec
*)(skb
->data
+ len
);
976 len
+= sizeof(*grec
) +
977 sizeof(struct in6_addr
) * ntohs(*nsrcs
);
979 /* We treat these as MLDv1 reports for now. */
980 switch (grec
->grec_type
) {
981 case MLD2_MODE_IS_INCLUDE
:
982 case MLD2_MODE_IS_EXCLUDE
:
983 case MLD2_CHANGE_TO_INCLUDE
:
984 case MLD2_CHANGE_TO_EXCLUDE
:
985 case MLD2_ALLOW_NEW_SOURCES
:
986 case MLD2_BLOCK_OLD_SOURCES
:
993 err
= br_ip6_multicast_add_group(br
, port
, &grec
->grec_mca
);
1003 * Add port to rotuer_list
1004 * list is maintained ordered by pointer value
1005 * and locked by br->multicast_lock and RCU
1007 static void br_multicast_add_router(struct net_bridge
*br
,
1008 struct net_bridge_port
*port
)
1010 struct net_bridge_port
*p
;
1011 struct hlist_node
*n
, *slot
= NULL
;
1013 hlist_for_each_entry(p
, n
, &br
->router_list
, rlist
) {
1014 if ((unsigned long) port
>= (unsigned long) p
)
1020 hlist_add_after_rcu(slot
, &port
->rlist
);
1022 hlist_add_head_rcu(&port
->rlist
, &br
->router_list
);
1025 static void br_multicast_mark_router(struct net_bridge
*br
,
1026 struct net_bridge_port
*port
)
1028 unsigned long now
= jiffies
;
1031 if (br
->multicast_router
== 1)
1032 mod_timer(&br
->multicast_router_timer
,
1033 now
+ br
->multicast_querier_interval
);
1037 if (port
->multicast_router
!= 1)
1040 if (!hlist_unhashed(&port
->rlist
))
1043 br_multicast_add_router(br
, port
);
1046 mod_timer(&port
->multicast_router_timer
,
1047 now
+ br
->multicast_querier_interval
);
1050 static void br_multicast_query_received(struct net_bridge
*br
,
1051 struct net_bridge_port
*port
,
1055 mod_timer(&br
->multicast_querier_timer
,
1056 jiffies
+ br
->multicast_querier_interval
);
1057 else if (timer_pending(&br
->multicast_querier_timer
))
1060 br_multicast_mark_router(br
, port
);
1063 static int br_ip4_multicast_query(struct net_bridge
*br
,
1064 struct net_bridge_port
*port
,
1065 struct sk_buff
*skb
)
1067 const struct iphdr
*iph
= ip_hdr(skb
);
1068 struct igmphdr
*ih
= igmp_hdr(skb
);
1069 struct net_bridge_mdb_entry
*mp
;
1070 struct igmpv3_query
*ih3
;
1071 struct net_bridge_port_group
*p
;
1072 struct net_bridge_port_group __rcu
**pp
;
1073 unsigned long max_delay
;
1074 unsigned long now
= jiffies
;
1078 spin_lock(&br
->multicast_lock
);
1079 if (!netif_running(br
->dev
) ||
1080 (port
&& port
->state
== BR_STATE_DISABLED
))
1083 br_multicast_query_received(br
, port
, !!iph
->saddr
);
1087 if (skb
->len
== sizeof(*ih
)) {
1088 max_delay
= ih
->code
* (HZ
/ IGMP_TIMER_SCALE
);
1091 max_delay
= 10 * HZ
;
1095 if (!pskb_may_pull(skb
, sizeof(struct igmpv3_query
))) {
1100 ih3
= igmpv3_query_hdr(skb
);
1104 max_delay
= ih3
->code
?
1105 IGMPV3_MRC(ih3
->code
) * (HZ
/ IGMP_TIMER_SCALE
) : 1;
1111 mp
= br_mdb_ip4_get(mlock_dereference(br
->mdb
, br
), group
);
1115 max_delay
*= br
->multicast_last_member_count
;
1118 (timer_pending(&mp
->timer
) ?
1119 time_after(mp
->timer
.expires
, now
+ max_delay
) :
1120 try_to_del_timer_sync(&mp
->timer
) >= 0))
1121 mod_timer(&mp
->timer
, now
+ max_delay
);
1123 for (pp
= &mp
->ports
;
1124 (p
= mlock_dereference(*pp
, br
)) != NULL
;
1126 if (timer_pending(&p
->timer
) ?
1127 time_after(p
->timer
.expires
, now
+ max_delay
) :
1128 try_to_del_timer_sync(&p
->timer
) >= 0)
1129 mod_timer(&p
->timer
, now
+ max_delay
);
1133 spin_unlock(&br
->multicast_lock
);
1137 #if IS_ENABLED(CONFIG_IPV6)
1138 static int br_ip6_multicast_query(struct net_bridge
*br
,
1139 struct net_bridge_port
*port
,
1140 struct sk_buff
*skb
)
1142 const struct ipv6hdr
*ip6h
= ipv6_hdr(skb
);
1143 struct mld_msg
*mld
;
1144 struct net_bridge_mdb_entry
*mp
;
1145 struct mld2_query
*mld2q
;
1146 struct net_bridge_port_group
*p
;
1147 struct net_bridge_port_group __rcu
**pp
;
1148 unsigned long max_delay
;
1149 unsigned long now
= jiffies
;
1150 const struct in6_addr
*group
= NULL
;
1153 spin_lock(&br
->multicast_lock
);
1154 if (!netif_running(br
->dev
) ||
1155 (port
&& port
->state
== BR_STATE_DISABLED
))
1158 br_multicast_query_received(br
, port
, !ipv6_addr_any(&ip6h
->saddr
));
1160 if (skb
->len
== sizeof(*mld
)) {
1161 if (!pskb_may_pull(skb
, sizeof(*mld
))) {
1165 mld
= (struct mld_msg
*) icmp6_hdr(skb
);
1166 max_delay
= msecs_to_jiffies(ntohs(mld
->mld_maxdelay
));
1168 group
= &mld
->mld_mca
;
1169 } else if (skb
->len
>= sizeof(*mld2q
)) {
1170 if (!pskb_may_pull(skb
, sizeof(*mld2q
))) {
1174 mld2q
= (struct mld2_query
*)icmp6_hdr(skb
);
1175 if (!mld2q
->mld2q_nsrcs
)
1176 group
= &mld2q
->mld2q_mca
;
1177 max_delay
= mld2q
->mld2q_mrc
? MLDV2_MRC(ntohs(mld2q
->mld2q_mrc
)) : 1;
1183 mp
= br_mdb_ip6_get(mlock_dereference(br
->mdb
, br
), group
);
1187 max_delay
*= br
->multicast_last_member_count
;
1189 (timer_pending(&mp
->timer
) ?
1190 time_after(mp
->timer
.expires
, now
+ max_delay
) :
1191 try_to_del_timer_sync(&mp
->timer
) >= 0))
1192 mod_timer(&mp
->timer
, now
+ max_delay
);
1194 for (pp
= &mp
->ports
;
1195 (p
= mlock_dereference(*pp
, br
)) != NULL
;
1197 if (timer_pending(&p
->timer
) ?
1198 time_after(p
->timer
.expires
, now
+ max_delay
) :
1199 try_to_del_timer_sync(&p
->timer
) >= 0)
1200 mod_timer(&p
->timer
, now
+ max_delay
);
1204 spin_unlock(&br
->multicast_lock
);
1209 static void br_multicast_leave_group(struct net_bridge
*br
,
1210 struct net_bridge_port
*port
,
1211 struct br_ip
*group
)
1213 struct net_bridge_mdb_htable
*mdb
;
1214 struct net_bridge_mdb_entry
*mp
;
1215 struct net_bridge_port_group
*p
;
1219 spin_lock(&br
->multicast_lock
);
1220 if (!netif_running(br
->dev
) ||
1221 (port
&& port
->state
== BR_STATE_DISABLED
) ||
1222 timer_pending(&br
->multicast_querier_timer
))
1225 mdb
= mlock_dereference(br
->mdb
, br
);
1226 mp
= br_mdb_ip_get(mdb
, group
);
1230 if (port
&& (port
->flags
& BR_MULTICAST_FAST_LEAVE
)) {
1231 struct net_bridge_port_group __rcu
**pp
;
1233 for (pp
= &mp
->ports
;
1234 (p
= mlock_dereference(*pp
, br
)) != NULL
;
1236 if (p
->port
!= port
)
1239 rcu_assign_pointer(*pp
, p
->next
);
1240 hlist_del_init(&p
->mglist
);
1241 del_timer(&p
->timer
);
1242 call_rcu_bh(&p
->rcu
, br_multicast_free_pg
);
1243 br_mdb_notify(br
->dev
, port
, group
, RTM_DELMDB
);
1245 if (!mp
->ports
&& !mp
->mglist
&&
1246 netif_running(br
->dev
))
1247 mod_timer(&mp
->timer
, jiffies
);
1253 time
= now
+ br
->multicast_last_member_count
*
1254 br
->multicast_last_member_interval
;
1258 (timer_pending(&mp
->timer
) ?
1259 time_after(mp
->timer
.expires
, time
) :
1260 try_to_del_timer_sync(&mp
->timer
) >= 0)) {
1261 mod_timer(&mp
->timer
, time
);
1267 for (p
= mlock_dereference(mp
->ports
, br
);
1269 p
= mlock_dereference(p
->next
, br
)) {
1270 if (p
->port
!= port
)
1273 if (!hlist_unhashed(&p
->mglist
) &&
1274 (timer_pending(&p
->timer
) ?
1275 time_after(p
->timer
.expires
, time
) :
1276 try_to_del_timer_sync(&p
->timer
) >= 0)) {
1277 mod_timer(&p
->timer
, time
);
1284 spin_unlock(&br
->multicast_lock
);
1287 static void br_ip4_multicast_leave_group(struct net_bridge
*br
,
1288 struct net_bridge_port
*port
,
1291 struct br_ip br_group
;
1293 if (ipv4_is_local_multicast(group
))
1296 br_group
.u
.ip4
= group
;
1297 br_group
.proto
= htons(ETH_P_IP
);
1299 br_multicast_leave_group(br
, port
, &br_group
);
1302 #if IS_ENABLED(CONFIG_IPV6)
1303 static void br_ip6_multicast_leave_group(struct net_bridge
*br
,
1304 struct net_bridge_port
*port
,
1305 const struct in6_addr
*group
)
1307 struct br_ip br_group
;
1309 if (!ipv6_is_transient_multicast(group
))
1312 br_group
.u
.ip6
= *group
;
1313 br_group
.proto
= htons(ETH_P_IPV6
);
1315 br_multicast_leave_group(br
, port
, &br_group
);
1319 static int br_multicast_ipv4_rcv(struct net_bridge
*br
,
1320 struct net_bridge_port
*port
,
1321 struct sk_buff
*skb
)
1323 struct sk_buff
*skb2
= skb
;
1324 const struct iphdr
*iph
;
1327 unsigned int offset
;
1330 /* We treat OOM as packet loss for now. */
1331 if (!pskb_may_pull(skb
, sizeof(*iph
)))
1336 if (iph
->ihl
< 5 || iph
->version
!= 4)
1339 if (!pskb_may_pull(skb
, ip_hdrlen(skb
)))
1344 if (unlikely(ip_fast_csum((u8
*)iph
, iph
->ihl
)))
1347 if (iph
->protocol
!= IPPROTO_IGMP
) {
1348 if ((iph
->daddr
& IGMP_LOCAL_GROUP_MASK
) != IGMP_LOCAL_GROUP
)
1349 BR_INPUT_SKB_CB(skb
)->mrouters_only
= 1;
1353 len
= ntohs(iph
->tot_len
);
1354 if (skb
->len
< len
|| len
< ip_hdrlen(skb
))
1357 if (skb
->len
> len
) {
1358 skb2
= skb_clone(skb
, GFP_ATOMIC
);
1362 err
= pskb_trim_rcsum(skb2
, len
);
1367 len
-= ip_hdrlen(skb2
);
1368 offset
= skb_network_offset(skb2
) + ip_hdrlen(skb2
);
1369 __skb_pull(skb2
, offset
);
1370 skb_reset_transport_header(skb2
);
1373 if (!pskb_may_pull(skb2
, sizeof(*ih
)))
1376 switch (skb2
->ip_summed
) {
1377 case CHECKSUM_COMPLETE
:
1378 if (!csum_fold(skb2
->csum
))
1383 if (skb_checksum_complete(skb2
))
1389 BR_INPUT_SKB_CB(skb
)->igmp
= 1;
1390 ih
= igmp_hdr(skb2
);
1393 case IGMP_HOST_MEMBERSHIP_REPORT
:
1394 case IGMPV2_HOST_MEMBERSHIP_REPORT
:
1395 BR_INPUT_SKB_CB(skb
)->mrouters_only
= 1;
1396 err
= br_ip4_multicast_add_group(br
, port
, ih
->group
);
1398 case IGMPV3_HOST_MEMBERSHIP_REPORT
:
1399 err
= br_ip4_multicast_igmp3_report(br
, port
, skb2
);
1401 case IGMP_HOST_MEMBERSHIP_QUERY
:
1402 err
= br_ip4_multicast_query(br
, port
, skb2
);
1404 case IGMP_HOST_LEAVE_MESSAGE
:
1405 br_ip4_multicast_leave_group(br
, port
, ih
->group
);
1410 __skb_push(skb2
, offset
);
1417 #if IS_ENABLED(CONFIG_IPV6)
1418 static int br_multicast_ipv6_rcv(struct net_bridge
*br
,
1419 struct net_bridge_port
*port
,
1420 struct sk_buff
*skb
)
1422 struct sk_buff
*skb2
;
1423 const struct ipv6hdr
*ip6h
;
1431 if (!pskb_may_pull(skb
, sizeof(*ip6h
)))
1434 ip6h
= ipv6_hdr(skb
);
1437 * We're interested in MLD messages only.
1439 * - MLD has always Router Alert hop-by-hop option
1440 * - But we do not support jumbrograms.
1442 if (ip6h
->version
!= 6 ||
1443 ip6h
->nexthdr
!= IPPROTO_HOPOPTS
||
1444 ip6h
->payload_len
== 0)
1447 len
= ntohs(ip6h
->payload_len
) + sizeof(*ip6h
);
1451 nexthdr
= ip6h
->nexthdr
;
1452 offset
= ipv6_skip_exthdr(skb
, sizeof(*ip6h
), &nexthdr
, &frag_off
);
1454 if (offset
< 0 || nexthdr
!= IPPROTO_ICMPV6
)
1457 /* Okay, we found ICMPv6 header */
1458 skb2
= skb_clone(skb
, GFP_ATOMIC
);
1463 if (!pskb_may_pull(skb2
, offset
+ sizeof(struct icmp6hdr
)))
1466 len
-= offset
- skb_network_offset(skb2
);
1468 __skb_pull(skb2
, offset
);
1469 skb_reset_transport_header(skb2
);
1470 skb_postpull_rcsum(skb2
, skb_network_header(skb2
),
1471 skb_network_header_len(skb2
));
1473 icmp6_type
= icmp6_hdr(skb2
)->icmp6_type
;
1475 switch (icmp6_type
) {
1476 case ICMPV6_MGM_QUERY
:
1477 case ICMPV6_MGM_REPORT
:
1478 case ICMPV6_MGM_REDUCTION
:
1479 case ICMPV6_MLD2_REPORT
:
1486 /* Okay, we found MLD message. Check further. */
1487 if (skb2
->len
> len
) {
1488 err
= pskb_trim_rcsum(skb2
, len
);
1494 ip6h
= ipv6_hdr(skb2
);
1496 switch (skb2
->ip_summed
) {
1497 case CHECKSUM_COMPLETE
:
1498 if (!csum_ipv6_magic(&ip6h
->saddr
, &ip6h
->daddr
, skb2
->len
,
1499 IPPROTO_ICMPV6
, skb2
->csum
))
1503 skb2
->csum
= ~csum_unfold(csum_ipv6_magic(&ip6h
->saddr
,
1506 IPPROTO_ICMPV6
, 0));
1507 if (__skb_checksum_complete(skb2
))
1513 BR_INPUT_SKB_CB(skb
)->igmp
= 1;
1515 switch (icmp6_type
) {
1516 case ICMPV6_MGM_REPORT
:
1518 struct mld_msg
*mld
;
1519 if (!pskb_may_pull(skb2
, sizeof(*mld
))) {
1523 mld
= (struct mld_msg
*)skb_transport_header(skb2
);
1524 BR_INPUT_SKB_CB(skb
)->mrouters_only
= 1;
1525 err
= br_ip6_multicast_add_group(br
, port
, &mld
->mld_mca
);
1528 case ICMPV6_MLD2_REPORT
:
1529 err
= br_ip6_multicast_mld2_report(br
, port
, skb2
);
1531 case ICMPV6_MGM_QUERY
:
1532 err
= br_ip6_multicast_query(br
, port
, skb2
);
1534 case ICMPV6_MGM_REDUCTION
:
1536 struct mld_msg
*mld
;
1537 if (!pskb_may_pull(skb2
, sizeof(*mld
))) {
1541 mld
= (struct mld_msg
*)skb_transport_header(skb2
);
1542 br_ip6_multicast_leave_group(br
, port
, &mld
->mld_mca
);
1552 int br_multicast_rcv(struct net_bridge
*br
, struct net_bridge_port
*port
,
1553 struct sk_buff
*skb
)
1555 BR_INPUT_SKB_CB(skb
)->igmp
= 0;
1556 BR_INPUT_SKB_CB(skb
)->mrouters_only
= 0;
1558 if (br
->multicast_disabled
)
1561 switch (skb
->protocol
) {
1562 case htons(ETH_P_IP
):
1563 return br_multicast_ipv4_rcv(br
, port
, skb
);
1564 #if IS_ENABLED(CONFIG_IPV6)
1565 case htons(ETH_P_IPV6
):
1566 return br_multicast_ipv6_rcv(br
, port
, skb
);
1573 static void br_multicast_query_expired(unsigned long data
)
1575 struct net_bridge
*br
= (void *)data
;
1577 spin_lock(&br
->multicast_lock
);
1578 if (br
->multicast_startup_queries_sent
<
1579 br
->multicast_startup_query_count
)
1580 br
->multicast_startup_queries_sent
++;
1582 br_multicast_send_query(br
, NULL
, br
->multicast_startup_queries_sent
);
1584 spin_unlock(&br
->multicast_lock
);
1587 void br_multicast_init(struct net_bridge
*br
)
1589 br
->hash_elasticity
= 4;
1592 br
->multicast_router
= 1;
1593 br
->multicast_querier
= 0;
1594 br
->multicast_last_member_count
= 2;
1595 br
->multicast_startup_query_count
= 2;
1597 br
->multicast_last_member_interval
= HZ
;
1598 br
->multicast_query_response_interval
= 10 * HZ
;
1599 br
->multicast_startup_query_interval
= 125 * HZ
/ 4;
1600 br
->multicast_query_interval
= 125 * HZ
;
1601 br
->multicast_querier_interval
= 255 * HZ
;
1602 br
->multicast_membership_interval
= 260 * HZ
;
1604 spin_lock_init(&br
->multicast_lock
);
1605 setup_timer(&br
->multicast_router_timer
,
1606 br_multicast_local_router_expired
, 0);
1607 setup_timer(&br
->multicast_querier_timer
,
1608 br_multicast_querier_expired
, (unsigned long)br
);
1609 setup_timer(&br
->multicast_query_timer
, br_multicast_query_expired
,
1613 void br_multicast_open(struct net_bridge
*br
)
1615 br
->multicast_startup_queries_sent
= 0;
1617 if (br
->multicast_disabled
)
1620 mod_timer(&br
->multicast_query_timer
, jiffies
);
1623 void br_multicast_stop(struct net_bridge
*br
)
1625 struct net_bridge_mdb_htable
*mdb
;
1626 struct net_bridge_mdb_entry
*mp
;
1627 struct hlist_node
*p
, *n
;
1631 del_timer_sync(&br
->multicast_router_timer
);
1632 del_timer_sync(&br
->multicast_querier_timer
);
1633 del_timer_sync(&br
->multicast_query_timer
);
1635 spin_lock_bh(&br
->multicast_lock
);
1636 mdb
= mlock_dereference(br
->mdb
, br
);
1643 for (i
= 0; i
< mdb
->max
; i
++) {
1644 hlist_for_each_entry_safe(mp
, p
, n
, &mdb
->mhash
[i
],
1646 del_timer(&mp
->timer
);
1647 call_rcu_bh(&mp
->rcu
, br_multicast_free_group
);
1652 spin_unlock_bh(&br
->multicast_lock
);
1654 spin_lock_bh(&br
->multicast_lock
);
1659 call_rcu_bh(&mdb
->rcu
, br_mdb_free
);
1662 spin_unlock_bh(&br
->multicast_lock
);
1665 int br_multicast_set_router(struct net_bridge
*br
, unsigned long val
)
1669 spin_lock_bh(&br
->multicast_lock
);
1670 if (!netif_running(br
->dev
))
1676 del_timer(&br
->multicast_router_timer
);
1679 br
->multicast_router
= val
;
1689 spin_unlock_bh(&br
->multicast_lock
);
1694 int br_multicast_set_port_router(struct net_bridge_port
*p
, unsigned long val
)
1696 struct net_bridge
*br
= p
->br
;
1699 spin_lock(&br
->multicast_lock
);
1700 if (!netif_running(br
->dev
) || p
->state
== BR_STATE_DISABLED
)
1707 p
->multicast_router
= val
;
1710 if (val
< 2 && !hlist_unhashed(&p
->rlist
))
1711 hlist_del_init_rcu(&p
->rlist
);
1716 del_timer(&p
->multicast_router_timer
);
1721 br_multicast_add_router(br
, p
);
1730 spin_unlock(&br
->multicast_lock
);
1735 static void br_multicast_start_querier(struct net_bridge
*br
)
1737 struct net_bridge_port
*port
;
1739 br_multicast_open(br
);
1741 list_for_each_entry(port
, &br
->port_list
, list
) {
1742 if (port
->state
== BR_STATE_DISABLED
||
1743 port
->state
== BR_STATE_BLOCKING
)
1746 __br_multicast_enable_port(port
);
1750 int br_multicast_toggle(struct net_bridge
*br
, unsigned long val
)
1753 struct net_bridge_mdb_htable
*mdb
;
1755 spin_lock_bh(&br
->multicast_lock
);
1756 if (br
->multicast_disabled
== !val
)
1759 br
->multicast_disabled
= !val
;
1760 if (br
->multicast_disabled
)
1763 if (!netif_running(br
->dev
))
1766 mdb
= mlock_dereference(br
->mdb
, br
);
1771 br
->multicast_disabled
= !!val
;
1775 err
= br_mdb_rehash(&br
->mdb
, mdb
->max
,
1776 br
->hash_elasticity
);
1781 br_multicast_start_querier(br
);
1784 spin_unlock_bh(&br
->multicast_lock
);
1789 int br_multicast_set_querier(struct net_bridge
*br
, unsigned long val
)
1793 spin_lock_bh(&br
->multicast_lock
);
1794 if (br
->multicast_querier
== val
)
1797 br
->multicast_querier
= val
;
1799 br_multicast_start_querier(br
);
1802 spin_unlock_bh(&br
->multicast_lock
);
1807 int br_multicast_set_hash_max(struct net_bridge
*br
, unsigned long val
)
1811 struct net_bridge_mdb_htable
*mdb
;
1813 spin_lock(&br
->multicast_lock
);
1814 if (!netif_running(br
->dev
))
1818 if (!is_power_of_2(val
))
1821 mdb
= mlock_dereference(br
->mdb
, br
);
1822 if (mdb
&& val
< mdb
->size
)
1838 err
= br_mdb_rehash(&br
->mdb
, br
->hash_max
,
1839 br
->hash_elasticity
);
1845 spin_unlock(&br
->multicast_lock
);