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
)
46 return a
->u
.ip4
== b
->u
.ip4
;
47 #if IS_ENABLED(CONFIG_IPV6)
48 case htons(ETH_P_IPV6
):
49 return ipv6_addr_equal(&a
->u
.ip6
, &b
->u
.ip6
);
55 static inline int __br_ip4_hash(struct net_bridge_mdb_htable
*mdb
, __be32 ip
,
58 return jhash_2words((__force u32
)ip
, vid
, mdb
->secret
) & (mdb
->max
- 1);
61 #if IS_ENABLED(CONFIG_IPV6)
62 static inline int __br_ip6_hash(struct net_bridge_mdb_htable
*mdb
,
63 const struct in6_addr
*ip
,
66 return jhash_2words(ipv6_addr_hash(ip
), vid
,
67 mdb
->secret
) & (mdb
->max
- 1);
71 static inline int br_ip_hash(struct net_bridge_mdb_htable
*mdb
,
76 return __br_ip4_hash(mdb
, ip
->u
.ip4
, ip
->vid
);
77 #if IS_ENABLED(CONFIG_IPV6)
78 case htons(ETH_P_IPV6
):
79 return __br_ip6_hash(mdb
, &ip
->u
.ip6
, ip
->vid
);
85 static struct net_bridge_mdb_entry
*__br_mdb_ip_get(
86 struct net_bridge_mdb_htable
*mdb
, struct br_ip
*dst
, int hash
)
88 struct net_bridge_mdb_entry
*mp
;
90 hlist_for_each_entry_rcu(mp
, &mdb
->mhash
[hash
], hlist
[mdb
->ver
]) {
91 if (br_ip_equal(&mp
->addr
, dst
))
98 struct net_bridge_mdb_entry
*br_mdb_ip_get(struct net_bridge_mdb_htable
*mdb
,
104 return __br_mdb_ip_get(mdb
, dst
, br_ip_hash(mdb
, dst
));
107 static struct net_bridge_mdb_entry
*br_mdb_ip4_get(
108 struct net_bridge_mdb_htable
*mdb
, __be32 dst
, __u16 vid
)
113 br_dst
.proto
= htons(ETH_P_IP
);
116 return br_mdb_ip_get(mdb
, &br_dst
);
119 #if IS_ENABLED(CONFIG_IPV6)
120 static struct net_bridge_mdb_entry
*br_mdb_ip6_get(
121 struct net_bridge_mdb_htable
*mdb
, const struct in6_addr
*dst
,
127 br_dst
.proto
= htons(ETH_P_IPV6
);
130 return br_mdb_ip_get(mdb
, &br_dst
);
134 struct net_bridge_mdb_entry
*br_mdb_get(struct net_bridge
*br
,
135 struct sk_buff
*skb
, u16 vid
)
137 struct net_bridge_mdb_htable
*mdb
= rcu_dereference(br
->mdb
);
140 if (br
->multicast_disabled
)
143 if (BR_INPUT_SKB_CB(skb
)->igmp
)
146 ip
.proto
= skb
->protocol
;
149 switch (skb
->protocol
) {
150 case htons(ETH_P_IP
):
151 ip
.u
.ip4
= ip_hdr(skb
)->daddr
;
153 #if IS_ENABLED(CONFIG_IPV6)
154 case htons(ETH_P_IPV6
):
155 ip
.u
.ip6
= ipv6_hdr(skb
)->daddr
;
162 return br_mdb_ip_get(mdb
, &ip
);
165 static void br_mdb_free(struct rcu_head
*head
)
167 struct net_bridge_mdb_htable
*mdb
=
168 container_of(head
, struct net_bridge_mdb_htable
, rcu
);
169 struct net_bridge_mdb_htable
*old
= mdb
->old
;
176 static int br_mdb_copy(struct net_bridge_mdb_htable
*new,
177 struct net_bridge_mdb_htable
*old
,
180 struct net_bridge_mdb_entry
*mp
;
185 for (i
= 0; i
< old
->max
; i
++)
186 hlist_for_each_entry(mp
, &old
->mhash
[i
], hlist
[old
->ver
])
187 hlist_add_head(&mp
->hlist
[new->ver
],
188 &new->mhash
[br_ip_hash(new, &mp
->addr
)]);
194 for (i
= 0; i
< new->max
; i
++) {
196 hlist_for_each_entry(mp
, &new->mhash
[i
], hlist
[new->ver
])
202 return maxlen
> elasticity
? -EINVAL
: 0;
205 void br_multicast_free_pg(struct rcu_head
*head
)
207 struct net_bridge_port_group
*p
=
208 container_of(head
, struct net_bridge_port_group
, rcu
);
213 static void br_multicast_free_group(struct rcu_head
*head
)
215 struct net_bridge_mdb_entry
*mp
=
216 container_of(head
, struct net_bridge_mdb_entry
, rcu
);
221 static void br_multicast_group_expired(unsigned long data
)
223 struct net_bridge_mdb_entry
*mp
= (void *)data
;
224 struct net_bridge
*br
= mp
->br
;
225 struct net_bridge_mdb_htable
*mdb
;
227 spin_lock(&br
->multicast_lock
);
228 if (!netif_running(br
->dev
) || timer_pending(&mp
->timer
))
236 mdb
= mlock_dereference(br
->mdb
, br
);
238 hlist_del_rcu(&mp
->hlist
[mdb
->ver
]);
241 call_rcu_bh(&mp
->rcu
, br_multicast_free_group
);
244 spin_unlock(&br
->multicast_lock
);
247 static void br_multicast_del_pg(struct net_bridge
*br
,
248 struct net_bridge_port_group
*pg
)
250 struct net_bridge_mdb_htable
*mdb
;
251 struct net_bridge_mdb_entry
*mp
;
252 struct net_bridge_port_group
*p
;
253 struct net_bridge_port_group __rcu
**pp
;
255 mdb
= mlock_dereference(br
->mdb
, br
);
257 mp
= br_mdb_ip_get(mdb
, &pg
->addr
);
261 for (pp
= &mp
->ports
;
262 (p
= mlock_dereference(*pp
, br
)) != NULL
;
267 rcu_assign_pointer(*pp
, p
->next
);
268 hlist_del_init(&p
->mglist
);
269 del_timer(&p
->timer
);
270 call_rcu_bh(&p
->rcu
, br_multicast_free_pg
);
272 if (!mp
->ports
&& !mp
->mglist
&&
273 netif_running(br
->dev
))
274 mod_timer(&mp
->timer
, jiffies
);
282 static void br_multicast_port_group_expired(unsigned long data
)
284 struct net_bridge_port_group
*pg
= (void *)data
;
285 struct net_bridge
*br
= pg
->port
->br
;
287 spin_lock(&br
->multicast_lock
);
288 if (!netif_running(br
->dev
) || timer_pending(&pg
->timer
) ||
289 hlist_unhashed(&pg
->mglist
) || pg
->state
& MDB_PERMANENT
)
292 br_multicast_del_pg(br
, pg
);
295 spin_unlock(&br
->multicast_lock
);
298 static int br_mdb_rehash(struct net_bridge_mdb_htable __rcu
**mdbp
, int max
,
301 struct net_bridge_mdb_htable
*old
= rcu_dereference_protected(*mdbp
, 1);
302 struct net_bridge_mdb_htable
*mdb
;
305 mdb
= kmalloc(sizeof(*mdb
), GFP_ATOMIC
);
312 mdb
->mhash
= kzalloc(max
* sizeof(*mdb
->mhash
), GFP_ATOMIC
);
318 mdb
->size
= old
? old
->size
: 0;
319 mdb
->ver
= old
? old
->ver
^ 1 : 0;
321 if (!old
|| elasticity
)
322 get_random_bytes(&mdb
->secret
, sizeof(mdb
->secret
));
324 mdb
->secret
= old
->secret
;
329 err
= br_mdb_copy(mdb
, old
, elasticity
);
337 call_rcu_bh(&mdb
->rcu
, br_mdb_free
);
340 rcu_assign_pointer(*mdbp
, mdb
);
345 static struct sk_buff
*br_ip4_multicast_alloc_query(struct net_bridge
*br
,
353 skb
= netdev_alloc_skb_ip_align(br
->dev
, sizeof(*eth
) + sizeof(*iph
) +
358 skb
->protocol
= htons(ETH_P_IP
);
360 skb_reset_mac_header(skb
);
363 memcpy(eth
->h_source
, br
->dev
->dev_addr
, 6);
366 eth
->h_dest
[2] = 0x5e;
370 eth
->h_proto
= htons(ETH_P_IP
);
371 skb_put(skb
, sizeof(*eth
));
373 skb_set_network_header(skb
, skb
->len
);
379 iph
->tot_len
= htons(sizeof(*iph
) + sizeof(*ih
) + 4);
381 iph
->frag_off
= htons(IP_DF
);
383 iph
->protocol
= IPPROTO_IGMP
;
385 iph
->daddr
= htonl(INADDR_ALLHOSTS_GROUP
);
386 ((u8
*)&iph
[1])[0] = IPOPT_RA
;
387 ((u8
*)&iph
[1])[1] = 4;
388 ((u8
*)&iph
[1])[2] = 0;
389 ((u8
*)&iph
[1])[3] = 0;
393 skb_set_transport_header(skb
, skb
->len
);
395 ih
->type
= IGMP_HOST_MEMBERSHIP_QUERY
;
396 ih
->code
= (group
? br
->multicast_last_member_interval
:
397 br
->multicast_query_response_interval
) /
398 (HZ
/ IGMP_TIMER_SCALE
);
401 ih
->csum
= ip_compute_csum((void *)ih
, sizeof(struct igmphdr
));
402 skb_put(skb
, sizeof(*ih
));
404 __skb_pull(skb
, sizeof(*eth
));
410 #if IS_ENABLED(CONFIG_IPV6)
411 static struct sk_buff
*br_ip6_multicast_alloc_query(struct net_bridge
*br
,
412 const struct in6_addr
*group
)
415 struct ipv6hdr
*ip6h
;
416 struct mld_msg
*mldq
;
419 unsigned long interval
;
421 skb
= netdev_alloc_skb_ip_align(br
->dev
, sizeof(*eth
) + sizeof(*ip6h
) +
426 skb
->protocol
= htons(ETH_P_IPV6
);
428 /* Ethernet header */
429 skb_reset_mac_header(skb
);
432 memcpy(eth
->h_source
, br
->dev
->dev_addr
, 6);
433 eth
->h_proto
= htons(ETH_P_IPV6
);
434 skb_put(skb
, sizeof(*eth
));
436 /* IPv6 header + HbH option */
437 skb_set_network_header(skb
, skb
->len
);
438 ip6h
= ipv6_hdr(skb
);
440 *(__force __be32
*)ip6h
= htonl(0x60000000);
441 ip6h
->payload_len
= htons(8 + sizeof(*mldq
));
442 ip6h
->nexthdr
= IPPROTO_HOPOPTS
;
444 ipv6_addr_set(&ip6h
->daddr
, htonl(0xff020000), 0, 0, htonl(1));
445 if (ipv6_dev_get_saddr(dev_net(br
->dev
), br
->dev
, &ip6h
->daddr
, 0,
450 ipv6_eth_mc_map(&ip6h
->daddr
, eth
->h_dest
);
452 hopopt
= (u8
*)(ip6h
+ 1);
453 hopopt
[0] = IPPROTO_ICMPV6
; /* next hdr */
454 hopopt
[1] = 0; /* length of HbH */
455 hopopt
[2] = IPV6_TLV_ROUTERALERT
; /* Router Alert */
456 hopopt
[3] = 2; /* Length of RA Option */
457 hopopt
[4] = 0; /* Type = 0x0000 (MLD) */
459 hopopt
[6] = IPV6_TLV_PAD1
; /* Pad1 */
460 hopopt
[7] = IPV6_TLV_PAD1
; /* Pad1 */
462 skb_put(skb
, sizeof(*ip6h
) + 8);
465 skb_set_transport_header(skb
, skb
->len
);
466 mldq
= (struct mld_msg
*) icmp6_hdr(skb
);
468 interval
= ipv6_addr_any(group
) ? br
->multicast_last_member_interval
:
469 br
->multicast_query_response_interval
;
471 mldq
->mld_type
= ICMPV6_MGM_QUERY
;
474 mldq
->mld_maxdelay
= htons((u16
)jiffies_to_msecs(interval
));
475 mldq
->mld_reserved
= 0;
476 mldq
->mld_mca
= *group
;
479 mldq
->mld_cksum
= csum_ipv6_magic(&ip6h
->saddr
, &ip6h
->daddr
,
480 sizeof(*mldq
), IPPROTO_ICMPV6
,
483 skb_put(skb
, sizeof(*mldq
));
485 __skb_pull(skb
, sizeof(*eth
));
492 static struct sk_buff
*br_multicast_alloc_query(struct net_bridge
*br
,
495 switch (addr
->proto
) {
496 case htons(ETH_P_IP
):
497 return br_ip4_multicast_alloc_query(br
, addr
->u
.ip4
);
498 #if IS_ENABLED(CONFIG_IPV6)
499 case htons(ETH_P_IPV6
):
500 return br_ip6_multicast_alloc_query(br
, &addr
->u
.ip6
);
506 static struct net_bridge_mdb_entry
*br_multicast_get_group(
507 struct net_bridge
*br
, struct net_bridge_port
*port
,
508 struct br_ip
*group
, int hash
)
510 struct net_bridge_mdb_htable
*mdb
;
511 struct net_bridge_mdb_entry
*mp
;
512 unsigned int count
= 0;
517 mdb
= rcu_dereference_protected(br
->mdb
, 1);
518 hlist_for_each_entry(mp
, &mdb
->mhash
[hash
], hlist
[mdb
->ver
]) {
520 if (unlikely(br_ip_equal(group
, &mp
->addr
)))
527 if (unlikely(count
> br
->hash_elasticity
&& count
)) {
529 br_info(br
, "Multicast hash table "
530 "chain limit reached: %s\n",
531 port
? port
->dev
->name
: br
->dev
->name
);
533 elasticity
= br
->hash_elasticity
;
536 if (mdb
->size
>= max
) {
538 if (unlikely(max
> br
->hash_max
)) {
539 br_warn(br
, "Multicast hash table maximum of %d "
540 "reached, disabling snooping: %s\n",
542 port
? port
->dev
->name
: br
->dev
->name
);
545 br
->multicast_disabled
= 1;
550 if (max
> mdb
->max
|| elasticity
) {
553 br_info(br
, "Multicast hash table "
555 port
? port
->dev
->name
: br
->dev
->name
);
560 err
= br_mdb_rehash(&br
->mdb
, max
, elasticity
);
562 br_warn(br
, "Cannot rehash multicast "
563 "hash table, disabling snooping: %s, %d, %d\n",
564 port
? port
->dev
->name
: br
->dev
->name
,
580 struct net_bridge_mdb_entry
*br_multicast_new_group(struct net_bridge
*br
,
581 struct net_bridge_port
*port
, struct br_ip
*group
)
583 struct net_bridge_mdb_htable
*mdb
;
584 struct net_bridge_mdb_entry
*mp
;
588 mdb
= rcu_dereference_protected(br
->mdb
, 1);
590 err
= br_mdb_rehash(&br
->mdb
, BR_HASH_SIZE
, 0);
596 hash
= br_ip_hash(mdb
, group
);
597 mp
= br_multicast_get_group(br
, port
, group
, hash
);
598 switch (PTR_ERR(mp
)) {
604 mdb
= rcu_dereference_protected(br
->mdb
, 1);
605 hash
= br_ip_hash(mdb
, group
);
612 mp
= kzalloc(sizeof(*mp
), GFP_ATOMIC
);
614 return ERR_PTR(-ENOMEM
);
618 setup_timer(&mp
->timer
, br_multicast_group_expired
,
621 hlist_add_head_rcu(&mp
->hlist
[mdb
->ver
], &mdb
->mhash
[hash
]);
628 struct net_bridge_port_group
*br_multicast_new_port_group(
629 struct net_bridge_port
*port
,
631 struct net_bridge_port_group __rcu
*next
,
634 struct net_bridge_port_group
*p
;
636 p
= kzalloc(sizeof(*p
), GFP_ATOMIC
);
643 rcu_assign_pointer(p
->next
, next
);
644 hlist_add_head(&p
->mglist
, &port
->mglist
);
645 setup_timer(&p
->timer
, br_multicast_port_group_expired
,
650 static int br_multicast_add_group(struct net_bridge
*br
,
651 struct net_bridge_port
*port
,
654 struct net_bridge_mdb_entry
*mp
;
655 struct net_bridge_port_group
*p
;
656 struct net_bridge_port_group __rcu
**pp
;
657 unsigned long now
= jiffies
;
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
);
672 mod_timer(&mp
->timer
, now
+ br
->multicast_membership_interval
);
676 for (pp
= &mp
->ports
;
677 (p
= mlock_dereference(*pp
, br
)) != NULL
;
681 if ((unsigned long)p
->port
< (unsigned long)port
)
685 p
= br_multicast_new_port_group(port
, group
, *pp
, MDB_TEMPORARY
);
688 rcu_assign_pointer(*pp
, p
);
689 br_mdb_notify(br
->dev
, port
, group
, RTM_NEWMDB
);
692 mod_timer(&p
->timer
, now
+ br
->multicast_membership_interval
);
697 spin_unlock(&br
->multicast_lock
);
701 static int br_ip4_multicast_add_group(struct net_bridge
*br
,
702 struct net_bridge_port
*port
,
706 struct br_ip br_group
;
708 if (ipv4_is_local_multicast(group
))
711 br_group
.u
.ip4
= group
;
712 br_group
.proto
= htons(ETH_P_IP
);
715 return br_multicast_add_group(br
, port
, &br_group
);
718 #if IS_ENABLED(CONFIG_IPV6)
719 static int br_ip6_multicast_add_group(struct net_bridge
*br
,
720 struct net_bridge_port
*port
,
721 const struct in6_addr
*group
,
724 struct br_ip br_group
;
726 if (!ipv6_is_transient_multicast(group
))
729 br_group
.u
.ip6
= *group
;
730 br_group
.proto
= htons(ETH_P_IPV6
);
733 return br_multicast_add_group(br
, port
, &br_group
);
737 static void br_multicast_router_expired(unsigned long data
)
739 struct net_bridge_port
*port
= (void *)data
;
740 struct net_bridge
*br
= port
->br
;
742 spin_lock(&br
->multicast_lock
);
743 if (port
->multicast_router
!= 1 ||
744 timer_pending(&port
->multicast_router_timer
) ||
745 hlist_unhashed(&port
->rlist
))
748 hlist_del_init_rcu(&port
->rlist
);
751 spin_unlock(&br
->multicast_lock
);
754 static void br_multicast_local_router_expired(unsigned long data
)
758 static void br_multicast_querier_expired(unsigned long data
)
760 struct net_bridge
*br
= (void *)data
;
762 spin_lock(&br
->multicast_lock
);
763 if (!netif_running(br
->dev
) || br
->multicast_disabled
)
766 br_multicast_start_querier(br
);
769 spin_unlock(&br
->multicast_lock
);
772 static void __br_multicast_send_query(struct net_bridge
*br
,
773 struct net_bridge_port
*port
,
778 skb
= br_multicast_alloc_query(br
, ip
);
783 __skb_push(skb
, sizeof(struct ethhdr
));
784 skb
->dev
= port
->dev
;
785 NF_HOOK(NFPROTO_BRIDGE
, NF_BR_LOCAL_OUT
, skb
, NULL
, skb
->dev
,
791 static void br_multicast_send_query(struct net_bridge
*br
,
792 struct net_bridge_port
*port
, u32 sent
)
795 struct br_ip br_group
;
797 if (!netif_running(br
->dev
) || br
->multicast_disabled
||
798 !br
->multicast_querier
||
799 timer_pending(&br
->multicast_querier_timer
))
802 memset(&br_group
.u
, 0, sizeof(br_group
.u
));
804 br_group
.proto
= htons(ETH_P_IP
);
805 __br_multicast_send_query(br
, port
, &br_group
);
807 #if IS_ENABLED(CONFIG_IPV6)
808 br_group
.proto
= htons(ETH_P_IPV6
);
809 __br_multicast_send_query(br
, port
, &br_group
);
813 time
+= sent
< br
->multicast_startup_query_count
?
814 br
->multicast_startup_query_interval
:
815 br
->multicast_query_interval
;
816 mod_timer(port
? &port
->multicast_query_timer
:
817 &br
->multicast_query_timer
, time
);
820 static void br_multicast_port_query_expired(unsigned long data
)
822 struct net_bridge_port
*port
= (void *)data
;
823 struct net_bridge
*br
= port
->br
;
825 spin_lock(&br
->multicast_lock
);
826 if (port
->state
== BR_STATE_DISABLED
||
827 port
->state
== BR_STATE_BLOCKING
)
830 if (port
->multicast_startup_queries_sent
<
831 br
->multicast_startup_query_count
)
832 port
->multicast_startup_queries_sent
++;
834 br_multicast_send_query(port
->br
, port
,
835 port
->multicast_startup_queries_sent
);
838 spin_unlock(&br
->multicast_lock
);
841 void br_multicast_add_port(struct net_bridge_port
*port
)
843 port
->multicast_router
= 1;
845 setup_timer(&port
->multicast_router_timer
, br_multicast_router_expired
,
846 (unsigned long)port
);
847 setup_timer(&port
->multicast_query_timer
,
848 br_multicast_port_query_expired
, (unsigned long)port
);
851 void br_multicast_del_port(struct net_bridge_port
*port
)
853 del_timer_sync(&port
->multicast_router_timer
);
856 static void __br_multicast_enable_port(struct net_bridge_port
*port
)
858 port
->multicast_startup_queries_sent
= 0;
860 if (try_to_del_timer_sync(&port
->multicast_query_timer
) >= 0 ||
861 del_timer(&port
->multicast_query_timer
))
862 mod_timer(&port
->multicast_query_timer
, jiffies
);
865 void br_multicast_enable_port(struct net_bridge_port
*port
)
867 struct net_bridge
*br
= port
->br
;
869 spin_lock(&br
->multicast_lock
);
870 if (br
->multicast_disabled
|| !netif_running(br
->dev
))
873 __br_multicast_enable_port(port
);
876 spin_unlock(&br
->multicast_lock
);
879 void br_multicast_disable_port(struct net_bridge_port
*port
)
881 struct net_bridge
*br
= port
->br
;
882 struct net_bridge_port_group
*pg
;
883 struct hlist_node
*n
;
885 spin_lock(&br
->multicast_lock
);
886 hlist_for_each_entry_safe(pg
, n
, &port
->mglist
, mglist
)
887 br_multicast_del_pg(br
, pg
);
889 if (!hlist_unhashed(&port
->rlist
))
890 hlist_del_init_rcu(&port
->rlist
);
891 del_timer(&port
->multicast_router_timer
);
892 del_timer(&port
->multicast_query_timer
);
893 spin_unlock(&br
->multicast_lock
);
896 static int br_ip4_multicast_igmp3_report(struct net_bridge
*br
,
897 struct net_bridge_port
*port
,
900 struct igmpv3_report
*ih
;
901 struct igmpv3_grec
*grec
;
910 if (!pskb_may_pull(skb
, sizeof(*ih
)))
913 br_vlan_get_tag(skb
, &vid
);
914 ih
= igmpv3_report_hdr(skb
);
915 num
= ntohs(ih
->ngrec
);
918 for (i
= 0; i
< num
; i
++) {
919 len
+= sizeof(*grec
);
920 if (!pskb_may_pull(skb
, len
))
923 grec
= (void *)(skb
->data
+ len
- sizeof(*grec
));
924 group
= grec
->grec_mca
;
925 type
= grec
->grec_type
;
927 len
+= ntohs(grec
->grec_nsrcs
) * 4;
928 if (!pskb_may_pull(skb
, len
))
931 /* We treat this as an IGMPv2 report for now. */
933 case IGMPV3_MODE_IS_INCLUDE
:
934 case IGMPV3_MODE_IS_EXCLUDE
:
935 case IGMPV3_CHANGE_TO_INCLUDE
:
936 case IGMPV3_CHANGE_TO_EXCLUDE
:
937 case IGMPV3_ALLOW_NEW_SOURCES
:
938 case IGMPV3_BLOCK_OLD_SOURCES
:
945 err
= br_ip4_multicast_add_group(br
, port
, group
, vid
);
953 #if IS_ENABLED(CONFIG_IPV6)
954 static int br_ip6_multicast_mld2_report(struct net_bridge
*br
,
955 struct net_bridge_port
*port
,
958 struct icmp6hdr
*icmp6h
;
959 struct mld2_grec
*grec
;
966 if (!pskb_may_pull(skb
, sizeof(*icmp6h
)))
969 br_vlan_get_tag(skb
, &vid
);
970 icmp6h
= icmp6_hdr(skb
);
971 num
= ntohs(icmp6h
->icmp6_dataun
.un_data16
[1]);
972 len
= sizeof(*icmp6h
);
974 for (i
= 0; i
< num
; i
++) {
975 __be16
*nsrcs
, _nsrcs
;
977 nsrcs
= skb_header_pointer(skb
,
978 len
+ offsetof(struct mld2_grec
,
980 sizeof(_nsrcs
), &_nsrcs
);
984 if (!pskb_may_pull(skb
,
985 len
+ sizeof(*grec
) +
986 sizeof(struct in6_addr
) * ntohs(*nsrcs
)))
989 grec
= (struct mld2_grec
*)(skb
->data
+ len
);
990 len
+= sizeof(*grec
) +
991 sizeof(struct in6_addr
) * ntohs(*nsrcs
);
993 /* We treat these as MLDv1 reports for now. */
994 switch (grec
->grec_type
) {
995 case MLD2_MODE_IS_INCLUDE
:
996 case MLD2_MODE_IS_EXCLUDE
:
997 case MLD2_CHANGE_TO_INCLUDE
:
998 case MLD2_CHANGE_TO_EXCLUDE
:
999 case MLD2_ALLOW_NEW_SOURCES
:
1000 case MLD2_BLOCK_OLD_SOURCES
:
1007 err
= br_ip6_multicast_add_group(br
, port
, &grec
->grec_mca
,
1018 * Add port to rotuer_list
1019 * list is maintained ordered by pointer value
1020 * and locked by br->multicast_lock and RCU
1022 static void br_multicast_add_router(struct net_bridge
*br
,
1023 struct net_bridge_port
*port
)
1025 struct net_bridge_port
*p
;
1026 struct hlist_node
*slot
= NULL
;
1028 hlist_for_each_entry(p
, &br
->router_list
, rlist
) {
1029 if ((unsigned long) port
>= (unsigned long) p
)
1035 hlist_add_after_rcu(slot
, &port
->rlist
);
1037 hlist_add_head_rcu(&port
->rlist
, &br
->router_list
);
1040 static void br_multicast_mark_router(struct net_bridge
*br
,
1041 struct net_bridge_port
*port
)
1043 unsigned long now
= jiffies
;
1046 if (br
->multicast_router
== 1)
1047 mod_timer(&br
->multicast_router_timer
,
1048 now
+ br
->multicast_querier_interval
);
1052 if (port
->multicast_router
!= 1)
1055 if (!hlist_unhashed(&port
->rlist
))
1058 br_multicast_add_router(br
, port
);
1061 mod_timer(&port
->multicast_router_timer
,
1062 now
+ br
->multicast_querier_interval
);
1065 static void br_multicast_query_received(struct net_bridge
*br
,
1066 struct net_bridge_port
*port
,
1070 mod_timer(&br
->multicast_querier_timer
,
1071 jiffies
+ br
->multicast_querier_interval
);
1072 else if (timer_pending(&br
->multicast_querier_timer
))
1075 br_multicast_mark_router(br
, port
);
1078 static int br_ip4_multicast_query(struct net_bridge
*br
,
1079 struct net_bridge_port
*port
,
1080 struct sk_buff
*skb
)
1082 const struct iphdr
*iph
= ip_hdr(skb
);
1083 struct igmphdr
*ih
= igmp_hdr(skb
);
1084 struct net_bridge_mdb_entry
*mp
;
1085 struct igmpv3_query
*ih3
;
1086 struct net_bridge_port_group
*p
;
1087 struct net_bridge_port_group __rcu
**pp
;
1088 unsigned long max_delay
;
1089 unsigned long now
= jiffies
;
1094 spin_lock(&br
->multicast_lock
);
1095 if (!netif_running(br
->dev
) ||
1096 (port
&& port
->state
== BR_STATE_DISABLED
))
1099 br_multicast_query_received(br
, port
, !!iph
->saddr
);
1103 if (skb
->len
== sizeof(*ih
)) {
1104 max_delay
= ih
->code
* (HZ
/ IGMP_TIMER_SCALE
);
1107 max_delay
= 10 * HZ
;
1111 if (!pskb_may_pull(skb
, sizeof(struct igmpv3_query
))) {
1116 ih3
= igmpv3_query_hdr(skb
);
1120 max_delay
= ih3
->code
?
1121 IGMPV3_MRC(ih3
->code
) * (HZ
/ IGMP_TIMER_SCALE
) : 1;
1127 br_vlan_get_tag(skb
, &vid
);
1128 mp
= br_mdb_ip4_get(mlock_dereference(br
->mdb
, br
), group
, vid
);
1132 max_delay
*= br
->multicast_last_member_count
;
1135 (timer_pending(&mp
->timer
) ?
1136 time_after(mp
->timer
.expires
, now
+ max_delay
) :
1137 try_to_del_timer_sync(&mp
->timer
) >= 0))
1138 mod_timer(&mp
->timer
, now
+ max_delay
);
1140 for (pp
= &mp
->ports
;
1141 (p
= mlock_dereference(*pp
, br
)) != NULL
;
1143 if (timer_pending(&p
->timer
) ?
1144 time_after(p
->timer
.expires
, now
+ max_delay
) :
1145 try_to_del_timer_sync(&p
->timer
) >= 0)
1146 mod_timer(&p
->timer
, now
+ max_delay
);
1150 spin_unlock(&br
->multicast_lock
);
1154 #if IS_ENABLED(CONFIG_IPV6)
1155 static int br_ip6_multicast_query(struct net_bridge
*br
,
1156 struct net_bridge_port
*port
,
1157 struct sk_buff
*skb
)
1159 const struct ipv6hdr
*ip6h
= ipv6_hdr(skb
);
1160 struct mld_msg
*mld
;
1161 struct net_bridge_mdb_entry
*mp
;
1162 struct mld2_query
*mld2q
;
1163 struct net_bridge_port_group
*p
;
1164 struct net_bridge_port_group __rcu
**pp
;
1165 unsigned long max_delay
;
1166 unsigned long now
= jiffies
;
1167 const struct in6_addr
*group
= NULL
;
1171 spin_lock(&br
->multicast_lock
);
1172 if (!netif_running(br
->dev
) ||
1173 (port
&& port
->state
== BR_STATE_DISABLED
))
1176 br_multicast_query_received(br
, port
, !ipv6_addr_any(&ip6h
->saddr
));
1178 if (skb
->len
== sizeof(*mld
)) {
1179 if (!pskb_may_pull(skb
, sizeof(*mld
))) {
1183 mld
= (struct mld_msg
*) icmp6_hdr(skb
);
1184 max_delay
= msecs_to_jiffies(ntohs(mld
->mld_maxdelay
));
1186 group
= &mld
->mld_mca
;
1187 } else if (skb
->len
>= sizeof(*mld2q
)) {
1188 if (!pskb_may_pull(skb
, sizeof(*mld2q
))) {
1192 mld2q
= (struct mld2_query
*)icmp6_hdr(skb
);
1193 if (!mld2q
->mld2q_nsrcs
)
1194 group
= &mld2q
->mld2q_mca
;
1195 max_delay
= mld2q
->mld2q_mrc
? MLDV2_MRC(ntohs(mld2q
->mld2q_mrc
)) : 1;
1201 br_vlan_get_tag(skb
, &vid
);
1202 mp
= br_mdb_ip6_get(mlock_dereference(br
->mdb
, br
), group
, vid
);
1206 max_delay
*= br
->multicast_last_member_count
;
1208 (timer_pending(&mp
->timer
) ?
1209 time_after(mp
->timer
.expires
, now
+ max_delay
) :
1210 try_to_del_timer_sync(&mp
->timer
) >= 0))
1211 mod_timer(&mp
->timer
, now
+ max_delay
);
1213 for (pp
= &mp
->ports
;
1214 (p
= mlock_dereference(*pp
, br
)) != NULL
;
1216 if (timer_pending(&p
->timer
) ?
1217 time_after(p
->timer
.expires
, now
+ max_delay
) :
1218 try_to_del_timer_sync(&p
->timer
) >= 0)
1219 mod_timer(&p
->timer
, now
+ max_delay
);
1223 spin_unlock(&br
->multicast_lock
);
1228 static void br_multicast_leave_group(struct net_bridge
*br
,
1229 struct net_bridge_port
*port
,
1230 struct br_ip
*group
)
1232 struct net_bridge_mdb_htable
*mdb
;
1233 struct net_bridge_mdb_entry
*mp
;
1234 struct net_bridge_port_group
*p
;
1238 spin_lock(&br
->multicast_lock
);
1239 if (!netif_running(br
->dev
) ||
1240 (port
&& port
->state
== BR_STATE_DISABLED
) ||
1241 timer_pending(&br
->multicast_querier_timer
))
1244 mdb
= mlock_dereference(br
->mdb
, br
);
1245 mp
= br_mdb_ip_get(mdb
, group
);
1249 if (port
&& (port
->flags
& BR_MULTICAST_FAST_LEAVE
)) {
1250 struct net_bridge_port_group __rcu
**pp
;
1252 for (pp
= &mp
->ports
;
1253 (p
= mlock_dereference(*pp
, br
)) != NULL
;
1255 if (p
->port
!= port
)
1258 rcu_assign_pointer(*pp
, p
->next
);
1259 hlist_del_init(&p
->mglist
);
1260 del_timer(&p
->timer
);
1261 call_rcu_bh(&p
->rcu
, br_multicast_free_pg
);
1262 br_mdb_notify(br
->dev
, port
, group
, RTM_DELMDB
);
1264 if (!mp
->ports
&& !mp
->mglist
&&
1265 netif_running(br
->dev
))
1266 mod_timer(&mp
->timer
, jiffies
);
1272 time
= now
+ br
->multicast_last_member_count
*
1273 br
->multicast_last_member_interval
;
1277 (timer_pending(&mp
->timer
) ?
1278 time_after(mp
->timer
.expires
, time
) :
1279 try_to_del_timer_sync(&mp
->timer
) >= 0)) {
1280 mod_timer(&mp
->timer
, time
);
1286 for (p
= mlock_dereference(mp
->ports
, br
);
1288 p
= mlock_dereference(p
->next
, br
)) {
1289 if (p
->port
!= port
)
1292 if (!hlist_unhashed(&p
->mglist
) &&
1293 (timer_pending(&p
->timer
) ?
1294 time_after(p
->timer
.expires
, time
) :
1295 try_to_del_timer_sync(&p
->timer
) >= 0)) {
1296 mod_timer(&p
->timer
, time
);
1303 spin_unlock(&br
->multicast_lock
);
1306 static void br_ip4_multicast_leave_group(struct net_bridge
*br
,
1307 struct net_bridge_port
*port
,
1311 struct br_ip br_group
;
1313 if (ipv4_is_local_multicast(group
))
1316 br_group
.u
.ip4
= group
;
1317 br_group
.proto
= htons(ETH_P_IP
);
1320 br_multicast_leave_group(br
, port
, &br_group
);
1323 #if IS_ENABLED(CONFIG_IPV6)
1324 static void br_ip6_multicast_leave_group(struct net_bridge
*br
,
1325 struct net_bridge_port
*port
,
1326 const struct in6_addr
*group
,
1329 struct br_ip br_group
;
1331 if (!ipv6_is_transient_multicast(group
))
1334 br_group
.u
.ip6
= *group
;
1335 br_group
.proto
= htons(ETH_P_IPV6
);
1338 br_multicast_leave_group(br
, port
, &br_group
);
1342 static int br_multicast_ipv4_rcv(struct net_bridge
*br
,
1343 struct net_bridge_port
*port
,
1344 struct sk_buff
*skb
)
1346 struct sk_buff
*skb2
= skb
;
1347 const struct iphdr
*iph
;
1350 unsigned int offset
;
1354 /* We treat OOM as packet loss for now. */
1355 if (!pskb_may_pull(skb
, sizeof(*iph
)))
1360 if (iph
->ihl
< 5 || iph
->version
!= 4)
1363 if (!pskb_may_pull(skb
, ip_hdrlen(skb
)))
1368 if (unlikely(ip_fast_csum((u8
*)iph
, iph
->ihl
)))
1371 if (iph
->protocol
!= IPPROTO_IGMP
) {
1372 if ((iph
->daddr
& IGMP_LOCAL_GROUP_MASK
) != IGMP_LOCAL_GROUP
)
1373 BR_INPUT_SKB_CB(skb
)->mrouters_only
= 1;
1377 len
= ntohs(iph
->tot_len
);
1378 if (skb
->len
< len
|| len
< ip_hdrlen(skb
))
1381 if (skb
->len
> len
) {
1382 skb2
= skb_clone(skb
, GFP_ATOMIC
);
1386 err
= pskb_trim_rcsum(skb2
, len
);
1391 len
-= ip_hdrlen(skb2
);
1392 offset
= skb_network_offset(skb2
) + ip_hdrlen(skb2
);
1393 __skb_pull(skb2
, offset
);
1394 skb_reset_transport_header(skb2
);
1397 if (!pskb_may_pull(skb2
, sizeof(*ih
)))
1400 switch (skb2
->ip_summed
) {
1401 case CHECKSUM_COMPLETE
:
1402 if (!csum_fold(skb2
->csum
))
1407 if (skb_checksum_complete(skb2
))
1413 br_vlan_get_tag(skb2
, &vid
);
1414 BR_INPUT_SKB_CB(skb
)->igmp
= 1;
1415 ih
= igmp_hdr(skb2
);
1418 case IGMP_HOST_MEMBERSHIP_REPORT
:
1419 case IGMPV2_HOST_MEMBERSHIP_REPORT
:
1420 BR_INPUT_SKB_CB(skb
)->mrouters_only
= 1;
1421 err
= br_ip4_multicast_add_group(br
, port
, ih
->group
, vid
);
1423 case IGMPV3_HOST_MEMBERSHIP_REPORT
:
1424 err
= br_ip4_multicast_igmp3_report(br
, port
, skb2
);
1426 case IGMP_HOST_MEMBERSHIP_QUERY
:
1427 err
= br_ip4_multicast_query(br
, port
, skb2
);
1429 case IGMP_HOST_LEAVE_MESSAGE
:
1430 br_ip4_multicast_leave_group(br
, port
, ih
->group
, vid
);
1435 __skb_push(skb2
, offset
);
1442 #if IS_ENABLED(CONFIG_IPV6)
1443 static int br_multicast_ipv6_rcv(struct net_bridge
*br
,
1444 struct net_bridge_port
*port
,
1445 struct sk_buff
*skb
)
1447 struct sk_buff
*skb2
;
1448 const struct ipv6hdr
*ip6h
;
1457 if (!pskb_may_pull(skb
, sizeof(*ip6h
)))
1460 ip6h
= ipv6_hdr(skb
);
1463 * We're interested in MLD messages only.
1465 * - MLD has always Router Alert hop-by-hop option
1466 * - But we do not support jumbrograms.
1468 if (ip6h
->version
!= 6 ||
1469 ip6h
->nexthdr
!= IPPROTO_HOPOPTS
||
1470 ip6h
->payload_len
== 0)
1473 len
= ntohs(ip6h
->payload_len
) + sizeof(*ip6h
);
1477 nexthdr
= ip6h
->nexthdr
;
1478 offset
= ipv6_skip_exthdr(skb
, sizeof(*ip6h
), &nexthdr
, &frag_off
);
1480 if (offset
< 0 || nexthdr
!= IPPROTO_ICMPV6
)
1483 /* Okay, we found ICMPv6 header */
1484 skb2
= skb_clone(skb
, GFP_ATOMIC
);
1489 if (!pskb_may_pull(skb2
, offset
+ sizeof(struct icmp6hdr
)))
1492 len
-= offset
- skb_network_offset(skb2
);
1494 __skb_pull(skb2
, offset
);
1495 skb_reset_transport_header(skb2
);
1496 skb_postpull_rcsum(skb2
, skb_network_header(skb2
),
1497 skb_network_header_len(skb2
));
1499 icmp6_type
= icmp6_hdr(skb2
)->icmp6_type
;
1501 switch (icmp6_type
) {
1502 case ICMPV6_MGM_QUERY
:
1503 case ICMPV6_MGM_REPORT
:
1504 case ICMPV6_MGM_REDUCTION
:
1505 case ICMPV6_MLD2_REPORT
:
1512 /* Okay, we found MLD message. Check further. */
1513 if (skb2
->len
> len
) {
1514 err
= pskb_trim_rcsum(skb2
, len
);
1520 ip6h
= ipv6_hdr(skb2
);
1522 switch (skb2
->ip_summed
) {
1523 case CHECKSUM_COMPLETE
:
1524 if (!csum_ipv6_magic(&ip6h
->saddr
, &ip6h
->daddr
, skb2
->len
,
1525 IPPROTO_ICMPV6
, skb2
->csum
))
1529 skb2
->csum
= ~csum_unfold(csum_ipv6_magic(&ip6h
->saddr
,
1532 IPPROTO_ICMPV6
, 0));
1533 if (__skb_checksum_complete(skb2
))
1539 br_vlan_get_tag(skb
, &vid
);
1540 BR_INPUT_SKB_CB(skb
)->igmp
= 1;
1542 switch (icmp6_type
) {
1543 case ICMPV6_MGM_REPORT
:
1545 struct mld_msg
*mld
;
1546 if (!pskb_may_pull(skb2
, sizeof(*mld
))) {
1550 mld
= (struct mld_msg
*)skb_transport_header(skb2
);
1551 BR_INPUT_SKB_CB(skb
)->mrouters_only
= 1;
1552 err
= br_ip6_multicast_add_group(br
, port
, &mld
->mld_mca
, vid
);
1555 case ICMPV6_MLD2_REPORT
:
1556 err
= br_ip6_multicast_mld2_report(br
, port
, skb2
);
1558 case ICMPV6_MGM_QUERY
:
1559 err
= br_ip6_multicast_query(br
, port
, skb2
);
1561 case ICMPV6_MGM_REDUCTION
:
1563 struct mld_msg
*mld
;
1564 if (!pskb_may_pull(skb2
, sizeof(*mld
))) {
1568 mld
= (struct mld_msg
*)skb_transport_header(skb2
);
1569 br_ip6_multicast_leave_group(br
, port
, &mld
->mld_mca
, vid
);
1579 int br_multicast_rcv(struct net_bridge
*br
, struct net_bridge_port
*port
,
1580 struct sk_buff
*skb
)
1582 BR_INPUT_SKB_CB(skb
)->igmp
= 0;
1583 BR_INPUT_SKB_CB(skb
)->mrouters_only
= 0;
1585 if (br
->multicast_disabled
)
1588 switch (skb
->protocol
) {
1589 case htons(ETH_P_IP
):
1590 return br_multicast_ipv4_rcv(br
, port
, skb
);
1591 #if IS_ENABLED(CONFIG_IPV6)
1592 case htons(ETH_P_IPV6
):
1593 return br_multicast_ipv6_rcv(br
, port
, skb
);
1600 static void br_multicast_query_expired(unsigned long data
)
1602 struct net_bridge
*br
= (void *)data
;
1604 spin_lock(&br
->multicast_lock
);
1605 if (br
->multicast_startup_queries_sent
<
1606 br
->multicast_startup_query_count
)
1607 br
->multicast_startup_queries_sent
++;
1609 br_multicast_send_query(br
, NULL
, br
->multicast_startup_queries_sent
);
1611 spin_unlock(&br
->multicast_lock
);
1614 void br_multicast_init(struct net_bridge
*br
)
1616 br
->hash_elasticity
= 4;
1619 br
->multicast_router
= 1;
1620 br
->multicast_querier
= 0;
1621 br
->multicast_last_member_count
= 2;
1622 br
->multicast_startup_query_count
= 2;
1624 br
->multicast_last_member_interval
= HZ
;
1625 br
->multicast_query_response_interval
= 10 * HZ
;
1626 br
->multicast_startup_query_interval
= 125 * HZ
/ 4;
1627 br
->multicast_query_interval
= 125 * HZ
;
1628 br
->multicast_querier_interval
= 255 * HZ
;
1629 br
->multicast_membership_interval
= 260 * HZ
;
1631 spin_lock_init(&br
->multicast_lock
);
1632 setup_timer(&br
->multicast_router_timer
,
1633 br_multicast_local_router_expired
, 0);
1634 setup_timer(&br
->multicast_querier_timer
,
1635 br_multicast_querier_expired
, (unsigned long)br
);
1636 setup_timer(&br
->multicast_query_timer
, br_multicast_query_expired
,
1640 void br_multicast_open(struct net_bridge
*br
)
1642 br
->multicast_startup_queries_sent
= 0;
1644 if (br
->multicast_disabled
)
1647 mod_timer(&br
->multicast_query_timer
, jiffies
);
1650 void br_multicast_stop(struct net_bridge
*br
)
1652 struct net_bridge_mdb_htable
*mdb
;
1653 struct net_bridge_mdb_entry
*mp
;
1654 struct hlist_node
*n
;
1658 del_timer_sync(&br
->multicast_router_timer
);
1659 del_timer_sync(&br
->multicast_querier_timer
);
1660 del_timer_sync(&br
->multicast_query_timer
);
1662 spin_lock_bh(&br
->multicast_lock
);
1663 mdb
= mlock_dereference(br
->mdb
, br
);
1670 for (i
= 0; i
< mdb
->max
; i
++) {
1671 hlist_for_each_entry_safe(mp
, n
, &mdb
->mhash
[i
],
1673 del_timer(&mp
->timer
);
1674 call_rcu_bh(&mp
->rcu
, br_multicast_free_group
);
1679 spin_unlock_bh(&br
->multicast_lock
);
1681 spin_lock_bh(&br
->multicast_lock
);
1686 call_rcu_bh(&mdb
->rcu
, br_mdb_free
);
1689 spin_unlock_bh(&br
->multicast_lock
);
1692 int br_multicast_set_router(struct net_bridge
*br
, unsigned long val
)
1696 spin_lock_bh(&br
->multicast_lock
);
1697 if (!netif_running(br
->dev
))
1703 del_timer(&br
->multicast_router_timer
);
1706 br
->multicast_router
= val
;
1716 spin_unlock_bh(&br
->multicast_lock
);
1721 int br_multicast_set_port_router(struct net_bridge_port
*p
, unsigned long val
)
1723 struct net_bridge
*br
= p
->br
;
1726 spin_lock(&br
->multicast_lock
);
1727 if (!netif_running(br
->dev
) || p
->state
== BR_STATE_DISABLED
)
1734 p
->multicast_router
= val
;
1737 if (val
< 2 && !hlist_unhashed(&p
->rlist
))
1738 hlist_del_init_rcu(&p
->rlist
);
1743 del_timer(&p
->multicast_router_timer
);
1748 br_multicast_add_router(br
, p
);
1757 spin_unlock(&br
->multicast_lock
);
1762 static void br_multicast_start_querier(struct net_bridge
*br
)
1764 struct net_bridge_port
*port
;
1766 br_multicast_open(br
);
1768 list_for_each_entry(port
, &br
->port_list
, list
) {
1769 if (port
->state
== BR_STATE_DISABLED
||
1770 port
->state
== BR_STATE_BLOCKING
)
1773 __br_multicast_enable_port(port
);
1777 int br_multicast_toggle(struct net_bridge
*br
, unsigned long val
)
1780 struct net_bridge_mdb_htable
*mdb
;
1782 spin_lock_bh(&br
->multicast_lock
);
1783 if (br
->multicast_disabled
== !val
)
1786 br
->multicast_disabled
= !val
;
1787 if (br
->multicast_disabled
)
1790 if (!netif_running(br
->dev
))
1793 mdb
= mlock_dereference(br
->mdb
, br
);
1798 br
->multicast_disabled
= !!val
;
1802 err
= br_mdb_rehash(&br
->mdb
, mdb
->max
,
1803 br
->hash_elasticity
);
1808 br_multicast_start_querier(br
);
1811 spin_unlock_bh(&br
->multicast_lock
);
1816 int br_multicast_set_querier(struct net_bridge
*br
, unsigned long val
)
1820 spin_lock_bh(&br
->multicast_lock
);
1821 if (br
->multicast_querier
== val
)
1824 br
->multicast_querier
= val
;
1826 br_multicast_start_querier(br
);
1829 spin_unlock_bh(&br
->multicast_lock
);
1834 int br_multicast_set_hash_max(struct net_bridge
*br
, unsigned long val
)
1838 struct net_bridge_mdb_htable
*mdb
;
1840 spin_lock(&br
->multicast_lock
);
1841 if (!netif_running(br
->dev
))
1845 if (!is_power_of_2(val
))
1848 mdb
= mlock_dereference(br
->mdb
, br
);
1849 if (mdb
&& val
< mdb
->size
)
1865 err
= br_mdb_rehash(&br
->mdb
, br
->hash_max
,
1866 br
->hash_elasticity
);
1872 spin_unlock(&br
->multicast_lock
);