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 defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
30 #include <net/addrconf.h>
31 #include <net/ip6_checksum.h>
34 #include "br_private.h"
36 #define mlock_dereference(X, br) \
37 rcu_dereference_protected(X, lockdep_is_held(&br->multicast_lock))
39 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
40 static inline int ipv6_is_local_multicast(const struct in6_addr
*addr
)
42 if (ipv6_addr_is_multicast(addr
) &&
43 IPV6_ADDR_MC_SCOPE(addr
) <= IPV6_ADDR_SCOPE_LINKLOCAL
)
49 static inline int br_ip_equal(const struct br_ip
*a
, const struct br_ip
*b
)
51 if (a
->proto
!= b
->proto
)
55 return a
->u
.ip4
== b
->u
.ip4
;
56 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
57 case htons(ETH_P_IPV6
):
58 return ipv6_addr_equal(&a
->u
.ip6
, &b
->u
.ip6
);
64 static inline int __br_ip4_hash(struct net_bridge_mdb_htable
*mdb
, __be32 ip
)
66 return jhash_1word(mdb
->secret
, (__force u32
)ip
) & (mdb
->max
- 1);
69 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
70 static inline int __br_ip6_hash(struct net_bridge_mdb_htable
*mdb
,
71 const struct in6_addr
*ip
)
73 return jhash2((__force u32
*)ip
->s6_addr32
, 4, mdb
->secret
) & (mdb
->max
- 1);
77 static inline int br_ip_hash(struct net_bridge_mdb_htable
*mdb
,
82 return __br_ip4_hash(mdb
, ip
->u
.ip4
);
83 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
84 case htons(ETH_P_IPV6
):
85 return __br_ip6_hash(mdb
, &ip
->u
.ip6
);
91 static struct net_bridge_mdb_entry
*__br_mdb_ip_get(
92 struct net_bridge_mdb_htable
*mdb
, struct br_ip
*dst
, int hash
)
94 struct net_bridge_mdb_entry
*mp
;
97 hlist_for_each_entry_rcu(mp
, p
, &mdb
->mhash
[hash
], hlist
[mdb
->ver
]) {
98 if (br_ip_equal(&mp
->addr
, dst
))
105 static struct net_bridge_mdb_entry
*br_mdb_ip_get(
106 struct net_bridge_mdb_htable
*mdb
, struct br_ip
*dst
)
111 return __br_mdb_ip_get(mdb
, dst
, br_ip_hash(mdb
, dst
));
114 static struct net_bridge_mdb_entry
*br_mdb_ip4_get(
115 struct net_bridge_mdb_htable
*mdb
, __be32 dst
)
120 br_dst
.proto
= htons(ETH_P_IP
);
122 return br_mdb_ip_get(mdb
, &br_dst
);
125 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
126 static struct net_bridge_mdb_entry
*br_mdb_ip6_get(
127 struct net_bridge_mdb_htable
*mdb
, const struct in6_addr
*dst
)
131 ipv6_addr_copy(&br_dst
.u
.ip6
, dst
);
132 br_dst
.proto
= htons(ETH_P_IPV6
);
134 return br_mdb_ip_get(mdb
, &br_dst
);
138 struct net_bridge_mdb_entry
*br_mdb_get(struct net_bridge
*br
,
141 struct net_bridge_mdb_htable
*mdb
= rcu_dereference(br
->mdb
);
144 if (br
->multicast_disabled
)
147 if (BR_INPUT_SKB_CB(skb
)->igmp
)
150 ip
.proto
= skb
->protocol
;
152 switch (skb
->protocol
) {
153 case htons(ETH_P_IP
):
154 ip
.u
.ip4
= ip_hdr(skb
)->daddr
;
156 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
157 case htons(ETH_P_IPV6
):
158 ipv6_addr_copy(&ip
.u
.ip6
, &ipv6_hdr(skb
)->daddr
);
165 return br_mdb_ip_get(mdb
, &ip
);
168 static void br_mdb_free(struct rcu_head
*head
)
170 struct net_bridge_mdb_htable
*mdb
=
171 container_of(head
, struct net_bridge_mdb_htable
, rcu
);
172 struct net_bridge_mdb_htable
*old
= mdb
->old
;
179 static int br_mdb_copy(struct net_bridge_mdb_htable
*new,
180 struct net_bridge_mdb_htable
*old
,
183 struct net_bridge_mdb_entry
*mp
;
184 struct hlist_node
*p
;
189 for (i
= 0; i
< old
->max
; i
++)
190 hlist_for_each_entry(mp
, p
, &old
->mhash
[i
], hlist
[old
->ver
])
191 hlist_add_head(&mp
->hlist
[new->ver
],
192 &new->mhash
[br_ip_hash(new, &mp
->addr
)]);
198 for (i
= 0; i
< new->max
; i
++) {
200 hlist_for_each_entry(mp
, p
, &new->mhash
[i
], hlist
[new->ver
])
206 return maxlen
> elasticity
? -EINVAL
: 0;
209 static void br_multicast_free_pg(struct rcu_head
*head
)
211 struct net_bridge_port_group
*p
=
212 container_of(head
, struct net_bridge_port_group
, rcu
);
217 static void br_multicast_free_group(struct rcu_head
*head
)
219 struct net_bridge_mdb_entry
*mp
=
220 container_of(head
, struct net_bridge_mdb_entry
, rcu
);
225 static void br_multicast_group_expired(unsigned long data
)
227 struct net_bridge_mdb_entry
*mp
= (void *)data
;
228 struct net_bridge
*br
= mp
->br
;
229 struct net_bridge_mdb_htable
*mdb
;
231 spin_lock(&br
->multicast_lock
);
232 if (!netif_running(br
->dev
) || timer_pending(&mp
->timer
))
235 if (!hlist_unhashed(&mp
->mglist
))
236 hlist_del_init(&mp
->mglist
);
241 mdb
= mlock_dereference(br
->mdb
, br
);
243 hlist_del_rcu(&mp
->hlist
[mdb
->ver
]);
246 del_timer(&mp
->query_timer
);
247 call_rcu_bh(&mp
->rcu
, br_multicast_free_group
);
250 spin_unlock(&br
->multicast_lock
);
253 static void br_multicast_del_pg(struct net_bridge
*br
,
254 struct net_bridge_port_group
*pg
)
256 struct net_bridge_mdb_htable
*mdb
;
257 struct net_bridge_mdb_entry
*mp
;
258 struct net_bridge_port_group
*p
;
259 struct net_bridge_port_group __rcu
**pp
;
261 mdb
= mlock_dereference(br
->mdb
, br
);
263 mp
= br_mdb_ip_get(mdb
, &pg
->addr
);
267 for (pp
= &mp
->ports
;
268 (p
= mlock_dereference(*pp
, br
)) != NULL
;
273 rcu_assign_pointer(*pp
, p
->next
);
274 hlist_del_init(&p
->mglist
);
275 del_timer(&p
->timer
);
276 del_timer(&p
->query_timer
);
277 call_rcu_bh(&p
->rcu
, br_multicast_free_pg
);
279 if (!mp
->ports
&& hlist_unhashed(&mp
->mglist
) &&
280 netif_running(br
->dev
))
281 mod_timer(&mp
->timer
, jiffies
);
289 static void br_multicast_port_group_expired(unsigned long data
)
291 struct net_bridge_port_group
*pg
= (void *)data
;
292 struct net_bridge
*br
= pg
->port
->br
;
294 spin_lock(&br
->multicast_lock
);
295 if (!netif_running(br
->dev
) || timer_pending(&pg
->timer
) ||
296 hlist_unhashed(&pg
->mglist
))
299 br_multicast_del_pg(br
, pg
);
302 spin_unlock(&br
->multicast_lock
);
305 static int br_mdb_rehash(struct net_bridge_mdb_htable __rcu
**mdbp
, int max
,
308 struct net_bridge_mdb_htable
*old
= rcu_dereference_protected(*mdbp
, 1);
309 struct net_bridge_mdb_htable
*mdb
;
312 mdb
= kmalloc(sizeof(*mdb
), GFP_ATOMIC
);
319 mdb
->mhash
= kzalloc(max
* sizeof(*mdb
->mhash
), GFP_ATOMIC
);
325 mdb
->size
= old
? old
->size
: 0;
326 mdb
->ver
= old
? old
->ver
^ 1 : 0;
328 if (!old
|| elasticity
)
329 get_random_bytes(&mdb
->secret
, sizeof(mdb
->secret
));
331 mdb
->secret
= old
->secret
;
336 err
= br_mdb_copy(mdb
, old
, elasticity
);
343 call_rcu_bh(&mdb
->rcu
, br_mdb_free
);
346 rcu_assign_pointer(*mdbp
, mdb
);
351 static struct sk_buff
*br_ip4_multicast_alloc_query(struct net_bridge
*br
,
359 skb
= netdev_alloc_skb_ip_align(br
->dev
, sizeof(*eth
) + sizeof(*iph
) +
364 skb
->protocol
= htons(ETH_P_IP
);
366 skb_reset_mac_header(skb
);
369 memcpy(eth
->h_source
, br
->dev
->dev_addr
, 6);
372 eth
->h_dest
[2] = 0x5e;
376 eth
->h_proto
= htons(ETH_P_IP
);
377 skb_put(skb
, sizeof(*eth
));
379 skb_set_network_header(skb
, skb
->len
);
385 iph
->tot_len
= htons(sizeof(*iph
) + sizeof(*ih
) + 4);
387 iph
->frag_off
= htons(IP_DF
);
389 iph
->protocol
= IPPROTO_IGMP
;
391 iph
->daddr
= htonl(INADDR_ALLHOSTS_GROUP
);
392 ((u8
*)&iph
[1])[0] = IPOPT_RA
;
393 ((u8
*)&iph
[1])[1] = 4;
394 ((u8
*)&iph
[1])[2] = 0;
395 ((u8
*)&iph
[1])[3] = 0;
399 skb_set_transport_header(skb
, skb
->len
);
401 ih
->type
= IGMP_HOST_MEMBERSHIP_QUERY
;
402 ih
->code
= (group
? br
->multicast_last_member_interval
:
403 br
->multicast_query_response_interval
) /
404 (HZ
/ IGMP_TIMER_SCALE
);
407 ih
->csum
= ip_compute_csum((void *)ih
, sizeof(struct igmphdr
));
408 skb_put(skb
, sizeof(*ih
));
410 __skb_pull(skb
, sizeof(*eth
));
416 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
417 static struct sk_buff
*br_ip6_multicast_alloc_query(struct net_bridge
*br
,
418 struct in6_addr
*group
)
421 struct ipv6hdr
*ip6h
;
422 struct mld_msg
*mldq
;
425 unsigned long interval
;
427 skb
= netdev_alloc_skb_ip_align(br
->dev
, sizeof(*eth
) + sizeof(*ip6h
) +
432 skb
->protocol
= htons(ETH_P_IPV6
);
434 /* Ethernet header */
435 skb_reset_mac_header(skb
);
438 memcpy(eth
->h_source
, br
->dev
->dev_addr
, 6);
439 ipv6_eth_mc_map(group
, eth
->h_dest
);
440 eth
->h_proto
= htons(ETH_P_IPV6
);
441 skb_put(skb
, sizeof(*eth
));
443 /* IPv6 header + HbH option */
444 skb_set_network_header(skb
, skb
->len
);
445 ip6h
= ipv6_hdr(skb
);
447 *(__force __be32
*)ip6h
= htonl(0x60000000);
448 ip6h
->payload_len
= htons(8 + sizeof(*mldq
));
449 ip6h
->nexthdr
= IPPROTO_HOPOPTS
;
451 ipv6_addr_set(&ip6h
->saddr
, 0, 0, 0, 0);
452 ipv6_addr_set(&ip6h
->daddr
, htonl(0xff020000), 0, 0, htonl(1));
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_PAD0
; /* Pad0 */
462 hopopt
[7] = IPV6_TLV_PAD0
; /* Pad0 */
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
) ? br
->multicast_last_member_interval
:
471 br
->multicast_query_response_interval
;
473 mldq
->mld_type
= ICMPV6_MGM_QUERY
;
476 mldq
->mld_maxdelay
= htons((u16
)jiffies_to_msecs(interval
));
477 mldq
->mld_reserved
= 0;
478 ipv6_addr_copy(&mldq
->mld_mca
, group
);
481 mldq
->mld_cksum
= csum_ipv6_magic(&ip6h
->saddr
, &ip6h
->daddr
,
482 sizeof(*mldq
), IPPROTO_ICMPV6
,
485 skb_put(skb
, sizeof(*mldq
));
487 __skb_pull(skb
, sizeof(*eth
));
494 static struct sk_buff
*br_multicast_alloc_query(struct net_bridge
*br
,
497 switch (addr
->proto
) {
498 case htons(ETH_P_IP
):
499 return br_ip4_multicast_alloc_query(br
, addr
->u
.ip4
);
500 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
501 case htons(ETH_P_IPV6
):
502 return br_ip6_multicast_alloc_query(br
, &addr
->u
.ip6
);
508 static void br_multicast_send_group_query(struct net_bridge_mdb_entry
*mp
)
510 struct net_bridge
*br
= mp
->br
;
513 skb
= br_multicast_alloc_query(br
, &mp
->addr
);
520 if (++mp
->queries_sent
< br
->multicast_last_member_count
)
521 mod_timer(&mp
->query_timer
,
522 jiffies
+ br
->multicast_last_member_interval
);
525 static void br_multicast_group_query_expired(unsigned long data
)
527 struct net_bridge_mdb_entry
*mp
= (void *)data
;
528 struct net_bridge
*br
= mp
->br
;
530 spin_lock(&br
->multicast_lock
);
531 if (!netif_running(br
->dev
) || hlist_unhashed(&mp
->mglist
) ||
532 mp
->queries_sent
>= br
->multicast_last_member_count
)
535 br_multicast_send_group_query(mp
);
538 spin_unlock(&br
->multicast_lock
);
541 static void br_multicast_send_port_group_query(struct net_bridge_port_group
*pg
)
543 struct net_bridge_port
*port
= pg
->port
;
544 struct net_bridge
*br
= port
->br
;
547 skb
= br_multicast_alloc_query(br
, &pg
->addr
);
551 br_deliver(port
, skb
);
554 if (++pg
->queries_sent
< br
->multicast_last_member_count
)
555 mod_timer(&pg
->query_timer
,
556 jiffies
+ br
->multicast_last_member_interval
);
559 static void br_multicast_port_group_query_expired(unsigned long data
)
561 struct net_bridge_port_group
*pg
= (void *)data
;
562 struct net_bridge_port
*port
= pg
->port
;
563 struct net_bridge
*br
= port
->br
;
565 spin_lock(&br
->multicast_lock
);
566 if (!netif_running(br
->dev
) || hlist_unhashed(&pg
->mglist
) ||
567 pg
->queries_sent
>= br
->multicast_last_member_count
)
570 br_multicast_send_port_group_query(pg
);
573 spin_unlock(&br
->multicast_lock
);
576 static struct net_bridge_mdb_entry
*br_multicast_get_group(
577 struct net_bridge
*br
, struct net_bridge_port
*port
,
578 struct br_ip
*group
, int hash
)
580 struct net_bridge_mdb_htable
*mdb
;
581 struct net_bridge_mdb_entry
*mp
;
582 struct hlist_node
*p
;
588 mdb
= rcu_dereference_protected(br
->mdb
, 1);
589 hlist_for_each_entry(mp
, p
, &mdb
->mhash
[hash
], hlist
[mdb
->ver
]) {
591 if (unlikely(br_ip_equal(group
, &mp
->addr
)))
598 if (unlikely(count
> br
->hash_elasticity
&& count
)) {
600 br_info(br
, "Multicast hash table "
601 "chain limit reached: %s\n",
602 port
? port
->dev
->name
: br
->dev
->name
);
604 elasticity
= br
->hash_elasticity
;
607 if (mdb
->size
>= max
) {
609 if (unlikely(max
>= br
->hash_max
)) {
610 br_warn(br
, "Multicast hash table maximum "
611 "reached, disabling snooping: %s, %d\n",
612 port
? port
->dev
->name
: br
->dev
->name
, max
);
615 br
->multicast_disabled
= 1;
620 if (max
> mdb
->max
|| elasticity
) {
623 br_info(br
, "Multicast hash table "
625 port
? port
->dev
->name
: br
->dev
->name
);
630 err
= br_mdb_rehash(&br
->mdb
, max
, elasticity
);
632 br_warn(br
, "Cannot rehash multicast "
633 "hash table, disabling snooping: %s, %d, %d\n",
634 port
? port
->dev
->name
: br
->dev
->name
,
650 static struct net_bridge_mdb_entry
*br_multicast_new_group(
651 struct net_bridge
*br
, struct net_bridge_port
*port
,
654 struct net_bridge_mdb_htable
*mdb
;
655 struct net_bridge_mdb_entry
*mp
;
659 mdb
= rcu_dereference_protected(br
->mdb
, 1);
661 err
= br_mdb_rehash(&br
->mdb
, BR_HASH_SIZE
, 0);
667 hash
= br_ip_hash(mdb
, group
);
668 mp
= br_multicast_get_group(br
, port
, group
, hash
);
669 switch (PTR_ERR(mp
)) {
675 mdb
= rcu_dereference_protected(br
->mdb
, 1);
676 hash
= br_ip_hash(mdb
, group
);
683 mp
= kzalloc(sizeof(*mp
), GFP_ATOMIC
);
685 return ERR_PTR(-ENOMEM
);
689 setup_timer(&mp
->timer
, br_multicast_group_expired
,
691 setup_timer(&mp
->query_timer
, br_multicast_group_query_expired
,
694 hlist_add_head_rcu(&mp
->hlist
[mdb
->ver
], &mdb
->mhash
[hash
]);
701 static int br_multicast_add_group(struct net_bridge
*br
,
702 struct net_bridge_port
*port
,
705 struct net_bridge_mdb_entry
*mp
;
706 struct net_bridge_port_group
*p
;
707 struct net_bridge_port_group __rcu
**pp
;
708 unsigned long now
= jiffies
;
711 spin_lock(&br
->multicast_lock
);
712 if (!netif_running(br
->dev
) ||
713 (port
&& port
->state
== BR_STATE_DISABLED
))
716 mp
= br_multicast_new_group(br
, port
, group
);
722 hlist_add_head(&mp
->mglist
, &br
->mglist
);
723 mod_timer(&mp
->timer
, now
+ br
->multicast_membership_interval
);
727 for (pp
= &mp
->ports
;
728 (p
= mlock_dereference(*pp
, br
)) != NULL
;
732 if ((unsigned long)p
->port
< (unsigned long)port
)
736 p
= kzalloc(sizeof(*p
), GFP_ATOMIC
);
744 hlist_add_head(&p
->mglist
, &port
->mglist
);
745 setup_timer(&p
->timer
, br_multicast_port_group_expired
,
747 setup_timer(&p
->query_timer
, br_multicast_port_group_query_expired
,
750 rcu_assign_pointer(*pp
, p
);
753 mod_timer(&p
->timer
, now
+ br
->multicast_membership_interval
);
758 spin_unlock(&br
->multicast_lock
);
762 static int br_ip4_multicast_add_group(struct net_bridge
*br
,
763 struct net_bridge_port
*port
,
766 struct br_ip br_group
;
768 if (ipv4_is_local_multicast(group
))
771 br_group
.u
.ip4
= group
;
772 br_group
.proto
= htons(ETH_P_IP
);
774 return br_multicast_add_group(br
, port
, &br_group
);
777 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
778 static int br_ip6_multicast_add_group(struct net_bridge
*br
,
779 struct net_bridge_port
*port
,
780 const struct in6_addr
*group
)
782 struct br_ip br_group
;
784 if (ipv6_is_local_multicast(group
))
787 ipv6_addr_copy(&br_group
.u
.ip6
, group
);
788 br_group
.proto
= htons(ETH_P_IP
);
790 return br_multicast_add_group(br
, port
, &br_group
);
794 static void br_multicast_router_expired(unsigned long data
)
796 struct net_bridge_port
*port
= (void *)data
;
797 struct net_bridge
*br
= port
->br
;
799 spin_lock(&br
->multicast_lock
);
800 if (port
->multicast_router
!= 1 ||
801 timer_pending(&port
->multicast_router_timer
) ||
802 hlist_unhashed(&port
->rlist
))
805 hlist_del_init_rcu(&port
->rlist
);
808 spin_unlock(&br
->multicast_lock
);
811 static void br_multicast_local_router_expired(unsigned long data
)
815 static void __br_multicast_send_query(struct net_bridge
*br
,
816 struct net_bridge_port
*port
,
821 skb
= br_multicast_alloc_query(br
, ip
);
826 __skb_push(skb
, sizeof(struct ethhdr
));
827 skb
->dev
= port
->dev
;
828 NF_HOOK(NFPROTO_BRIDGE
, NF_BR_LOCAL_OUT
, skb
, NULL
, skb
->dev
,
834 static void br_multicast_send_query(struct net_bridge
*br
,
835 struct net_bridge_port
*port
, u32 sent
)
838 struct br_ip br_group
;
840 if (!netif_running(br
->dev
) || br
->multicast_disabled
||
841 timer_pending(&br
->multicast_querier_timer
))
844 memset(&br_group
.u
, 0, sizeof(br_group
.u
));
846 br_group
.proto
= htons(ETH_P_IP
);
847 __br_multicast_send_query(br
, port
, &br_group
);
849 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
850 br_group
.proto
= htons(ETH_P_IPV6
);
851 __br_multicast_send_query(br
, port
, &br_group
);
855 time
+= sent
< br
->multicast_startup_query_count
?
856 br
->multicast_startup_query_interval
:
857 br
->multicast_query_interval
;
858 mod_timer(port
? &port
->multicast_query_timer
:
859 &br
->multicast_query_timer
, time
);
862 static void br_multicast_port_query_expired(unsigned long data
)
864 struct net_bridge_port
*port
= (void *)data
;
865 struct net_bridge
*br
= port
->br
;
867 spin_lock(&br
->multicast_lock
);
868 if (port
->state
== BR_STATE_DISABLED
||
869 port
->state
== BR_STATE_BLOCKING
)
872 if (port
->multicast_startup_queries_sent
<
873 br
->multicast_startup_query_count
)
874 port
->multicast_startup_queries_sent
++;
876 br_multicast_send_query(port
->br
, port
,
877 port
->multicast_startup_queries_sent
);
880 spin_unlock(&br
->multicast_lock
);
883 void br_multicast_add_port(struct net_bridge_port
*port
)
885 port
->multicast_router
= 1;
887 setup_timer(&port
->multicast_router_timer
, br_multicast_router_expired
,
888 (unsigned long)port
);
889 setup_timer(&port
->multicast_query_timer
,
890 br_multicast_port_query_expired
, (unsigned long)port
);
893 void br_multicast_del_port(struct net_bridge_port
*port
)
895 del_timer_sync(&port
->multicast_router_timer
);
898 static void __br_multicast_enable_port(struct net_bridge_port
*port
)
900 port
->multicast_startup_queries_sent
= 0;
902 if (try_to_del_timer_sync(&port
->multicast_query_timer
) >= 0 ||
903 del_timer(&port
->multicast_query_timer
))
904 mod_timer(&port
->multicast_query_timer
, jiffies
);
907 void br_multicast_enable_port(struct net_bridge_port
*port
)
909 struct net_bridge
*br
= port
->br
;
911 spin_lock(&br
->multicast_lock
);
912 if (br
->multicast_disabled
|| !netif_running(br
->dev
))
915 __br_multicast_enable_port(port
);
918 spin_unlock(&br
->multicast_lock
);
921 void br_multicast_disable_port(struct net_bridge_port
*port
)
923 struct net_bridge
*br
= port
->br
;
924 struct net_bridge_port_group
*pg
;
925 struct hlist_node
*p
, *n
;
927 spin_lock(&br
->multicast_lock
);
928 hlist_for_each_entry_safe(pg
, p
, n
, &port
->mglist
, mglist
)
929 br_multicast_del_pg(br
, pg
);
931 if (!hlist_unhashed(&port
->rlist
))
932 hlist_del_init_rcu(&port
->rlist
);
933 del_timer(&port
->multicast_router_timer
);
934 del_timer(&port
->multicast_query_timer
);
935 spin_unlock(&br
->multicast_lock
);
938 static int br_ip4_multicast_igmp3_report(struct net_bridge
*br
,
939 struct net_bridge_port
*port
,
942 struct igmpv3_report
*ih
;
943 struct igmpv3_grec
*grec
;
951 if (!pskb_may_pull(skb
, sizeof(*ih
)))
954 ih
= igmpv3_report_hdr(skb
);
955 num
= ntohs(ih
->ngrec
);
958 for (i
= 0; i
< num
; i
++) {
959 len
+= sizeof(*grec
);
960 if (!pskb_may_pull(skb
, len
))
963 grec
= (void *)(skb
->data
+ len
- sizeof(*grec
));
964 group
= grec
->grec_mca
;
965 type
= grec
->grec_type
;
967 len
+= ntohs(grec
->grec_nsrcs
) * 4;
968 if (!pskb_may_pull(skb
, len
))
971 /* We treat this as an IGMPv2 report for now. */
973 case IGMPV3_MODE_IS_INCLUDE
:
974 case IGMPV3_MODE_IS_EXCLUDE
:
975 case IGMPV3_CHANGE_TO_INCLUDE
:
976 case IGMPV3_CHANGE_TO_EXCLUDE
:
977 case IGMPV3_ALLOW_NEW_SOURCES
:
978 case IGMPV3_BLOCK_OLD_SOURCES
:
985 err
= br_ip4_multicast_add_group(br
, port
, group
);
993 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
994 static int br_ip6_multicast_mld2_report(struct net_bridge
*br
,
995 struct net_bridge_port
*port
,
998 struct icmp6hdr
*icmp6h
;
999 struct mld2_grec
*grec
;
1005 if (!pskb_may_pull(skb
, sizeof(*icmp6h
)))
1008 icmp6h
= icmp6_hdr(skb
);
1009 num
= ntohs(icmp6h
->icmp6_dataun
.un_data16
[1]);
1010 len
= sizeof(*icmp6h
);
1012 for (i
= 0; i
< num
; i
++) {
1013 __be16
*nsrcs
, _nsrcs
;
1015 nsrcs
= skb_header_pointer(skb
,
1016 len
+ offsetof(struct mld2_grec
,
1018 sizeof(_nsrcs
), &_nsrcs
);
1022 if (!pskb_may_pull(skb
,
1023 len
+ sizeof(*grec
) +
1024 sizeof(struct in6_addr
) * (*nsrcs
)))
1027 grec
= (struct mld2_grec
*)(skb
->data
+ len
);
1028 len
+= sizeof(*grec
) + sizeof(struct in6_addr
) * (*nsrcs
);
1030 /* We treat these as MLDv1 reports for now. */
1031 switch (grec
->grec_type
) {
1032 case MLD2_MODE_IS_INCLUDE
:
1033 case MLD2_MODE_IS_EXCLUDE
:
1034 case MLD2_CHANGE_TO_INCLUDE
:
1035 case MLD2_CHANGE_TO_EXCLUDE
:
1036 case MLD2_ALLOW_NEW_SOURCES
:
1037 case MLD2_BLOCK_OLD_SOURCES
:
1044 err
= br_ip6_multicast_add_group(br
, port
, &grec
->grec_mca
);
1054 * Add port to rotuer_list
1055 * list is maintained ordered by pointer value
1056 * and locked by br->multicast_lock and RCU
1058 static void br_multicast_add_router(struct net_bridge
*br
,
1059 struct net_bridge_port
*port
)
1061 struct net_bridge_port
*p
;
1062 struct hlist_node
*n
, *slot
= NULL
;
1064 hlist_for_each_entry(p
, n
, &br
->router_list
, rlist
) {
1065 if ((unsigned long) port
>= (unsigned long) p
)
1071 hlist_add_after_rcu(slot
, &port
->rlist
);
1073 hlist_add_head_rcu(&port
->rlist
, &br
->router_list
);
1076 static void br_multicast_mark_router(struct net_bridge
*br
,
1077 struct net_bridge_port
*port
)
1079 unsigned long now
= jiffies
;
1082 if (br
->multicast_router
== 1)
1083 mod_timer(&br
->multicast_router_timer
,
1084 now
+ br
->multicast_querier_interval
);
1088 if (port
->multicast_router
!= 1)
1091 if (!hlist_unhashed(&port
->rlist
))
1094 br_multicast_add_router(br
, port
);
1097 mod_timer(&port
->multicast_router_timer
,
1098 now
+ br
->multicast_querier_interval
);
1101 static void br_multicast_query_received(struct net_bridge
*br
,
1102 struct net_bridge_port
*port
,
1106 mod_timer(&br
->multicast_querier_timer
,
1107 jiffies
+ br
->multicast_querier_interval
);
1108 else if (timer_pending(&br
->multicast_querier_timer
))
1111 br_multicast_mark_router(br
, port
);
1114 static int br_ip4_multicast_query(struct net_bridge
*br
,
1115 struct net_bridge_port
*port
,
1116 struct sk_buff
*skb
)
1118 struct iphdr
*iph
= ip_hdr(skb
);
1119 struct igmphdr
*ih
= igmp_hdr(skb
);
1120 struct net_bridge_mdb_entry
*mp
;
1121 struct igmpv3_query
*ih3
;
1122 struct net_bridge_port_group
*p
;
1123 struct net_bridge_port_group __rcu
**pp
;
1124 unsigned long max_delay
;
1125 unsigned long now
= jiffies
;
1129 spin_lock(&br
->multicast_lock
);
1130 if (!netif_running(br
->dev
) ||
1131 (port
&& port
->state
== BR_STATE_DISABLED
))
1134 br_multicast_query_received(br
, port
, !!iph
->saddr
);
1138 if (skb
->len
== sizeof(*ih
)) {
1139 max_delay
= ih
->code
* (HZ
/ IGMP_TIMER_SCALE
);
1142 max_delay
= 10 * HZ
;
1146 if (!pskb_may_pull(skb
, sizeof(struct igmpv3_query
))) {
1151 ih3
= igmpv3_query_hdr(skb
);
1155 max_delay
= ih3
->code
?
1156 IGMPV3_MRC(ih3
->code
) * (HZ
/ IGMP_TIMER_SCALE
) : 1;
1162 mp
= br_mdb_ip4_get(mlock_dereference(br
->mdb
, br
), group
);
1166 max_delay
*= br
->multicast_last_member_count
;
1168 if (!hlist_unhashed(&mp
->mglist
) &&
1169 (timer_pending(&mp
->timer
) ?
1170 time_after(mp
->timer
.expires
, now
+ max_delay
) :
1171 try_to_del_timer_sync(&mp
->timer
) >= 0))
1172 mod_timer(&mp
->timer
, now
+ max_delay
);
1174 for (pp
= &mp
->ports
;
1175 (p
= mlock_dereference(*pp
, br
)) != NULL
;
1177 if (timer_pending(&p
->timer
) ?
1178 time_after(p
->timer
.expires
, now
+ max_delay
) :
1179 try_to_del_timer_sync(&p
->timer
) >= 0)
1180 mod_timer(&mp
->timer
, now
+ max_delay
);
1184 spin_unlock(&br
->multicast_lock
);
1188 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
1189 static int br_ip6_multicast_query(struct net_bridge
*br
,
1190 struct net_bridge_port
*port
,
1191 struct sk_buff
*skb
)
1193 struct ipv6hdr
*ip6h
= ipv6_hdr(skb
);
1194 struct mld_msg
*mld
= (struct mld_msg
*) icmp6_hdr(skb
);
1195 struct net_bridge_mdb_entry
*mp
;
1196 struct mld2_query
*mld2q
;
1197 struct net_bridge_port_group
*p
;
1198 struct net_bridge_port_group __rcu
**pp
;
1199 unsigned long max_delay
;
1200 unsigned long now
= jiffies
;
1201 struct in6_addr
*group
= NULL
;
1204 spin_lock(&br
->multicast_lock
);
1205 if (!netif_running(br
->dev
) ||
1206 (port
&& port
->state
== BR_STATE_DISABLED
))
1209 br_multicast_query_received(br
, port
, !ipv6_addr_any(&ip6h
->saddr
));
1211 if (skb
->len
== sizeof(*mld
)) {
1212 if (!pskb_may_pull(skb
, sizeof(*mld
))) {
1216 mld
= (struct mld_msg
*) icmp6_hdr(skb
);
1217 max_delay
= msecs_to_jiffies(htons(mld
->mld_maxdelay
));
1219 group
= &mld
->mld_mca
;
1220 } else if (skb
->len
>= sizeof(*mld2q
)) {
1221 if (!pskb_may_pull(skb
, sizeof(*mld2q
))) {
1225 mld2q
= (struct mld2_query
*)icmp6_hdr(skb
);
1226 if (!mld2q
->mld2q_nsrcs
)
1227 group
= &mld2q
->mld2q_mca
;
1228 max_delay
= mld2q
->mld2q_mrc
? MLDV2_MRC(mld2q
->mld2q_mrc
) : 1;
1234 mp
= br_mdb_ip6_get(mlock_dereference(br
->mdb
, br
), group
);
1238 max_delay
*= br
->multicast_last_member_count
;
1239 if (!hlist_unhashed(&mp
->mglist
) &&
1240 (timer_pending(&mp
->timer
) ?
1241 time_after(mp
->timer
.expires
, now
+ max_delay
) :
1242 try_to_del_timer_sync(&mp
->timer
) >= 0))
1243 mod_timer(&mp
->timer
, now
+ max_delay
);
1245 for (pp
= &mp
->ports
;
1246 (p
= mlock_dereference(*pp
, br
)) != NULL
;
1248 if (timer_pending(&p
->timer
) ?
1249 time_after(p
->timer
.expires
, now
+ max_delay
) :
1250 try_to_del_timer_sync(&p
->timer
) >= 0)
1251 mod_timer(&mp
->timer
, now
+ max_delay
);
1255 spin_unlock(&br
->multicast_lock
);
1260 static void br_multicast_leave_group(struct net_bridge
*br
,
1261 struct net_bridge_port
*port
,
1262 struct br_ip
*group
)
1264 struct net_bridge_mdb_htable
*mdb
;
1265 struct net_bridge_mdb_entry
*mp
;
1266 struct net_bridge_port_group
*p
;
1270 spin_lock(&br
->multicast_lock
);
1271 if (!netif_running(br
->dev
) ||
1272 (port
&& port
->state
== BR_STATE_DISABLED
) ||
1273 timer_pending(&br
->multicast_querier_timer
))
1276 mdb
= mlock_dereference(br
->mdb
, br
);
1277 mp
= br_mdb_ip_get(mdb
, group
);
1282 time
= now
+ br
->multicast_last_member_count
*
1283 br
->multicast_last_member_interval
;
1286 if (!hlist_unhashed(&mp
->mglist
) &&
1287 (timer_pending(&mp
->timer
) ?
1288 time_after(mp
->timer
.expires
, time
) :
1289 try_to_del_timer_sync(&mp
->timer
) >= 0)) {
1290 mod_timer(&mp
->timer
, time
);
1292 mp
->queries_sent
= 0;
1293 mod_timer(&mp
->query_timer
, now
);
1299 for (p
= mlock_dereference(mp
->ports
, br
);
1301 p
= mlock_dereference(p
->next
, br
)) {
1302 if (p
->port
!= port
)
1305 if (!hlist_unhashed(&p
->mglist
) &&
1306 (timer_pending(&p
->timer
) ?
1307 time_after(p
->timer
.expires
, time
) :
1308 try_to_del_timer_sync(&p
->timer
) >= 0)) {
1309 mod_timer(&p
->timer
, time
);
1311 p
->queries_sent
= 0;
1312 mod_timer(&p
->query_timer
, now
);
1319 spin_unlock(&br
->multicast_lock
);
1322 static void br_ip4_multicast_leave_group(struct net_bridge
*br
,
1323 struct net_bridge_port
*port
,
1326 struct br_ip br_group
;
1328 if (ipv4_is_local_multicast(group
))
1331 br_group
.u
.ip4
= group
;
1332 br_group
.proto
= htons(ETH_P_IP
);
1334 br_multicast_leave_group(br
, port
, &br_group
);
1337 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
1338 static void br_ip6_multicast_leave_group(struct net_bridge
*br
,
1339 struct net_bridge_port
*port
,
1340 const struct in6_addr
*group
)
1342 struct br_ip br_group
;
1344 if (ipv6_is_local_multicast(group
))
1347 ipv6_addr_copy(&br_group
.u
.ip6
, group
);
1348 br_group
.proto
= htons(ETH_P_IPV6
);
1350 br_multicast_leave_group(br
, port
, &br_group
);
1354 static int br_multicast_ipv4_rcv(struct net_bridge
*br
,
1355 struct net_bridge_port
*port
,
1356 struct sk_buff
*skb
)
1358 struct sk_buff
*skb2
= skb
;
1365 /* We treat OOM as packet loss for now. */
1366 if (!pskb_may_pull(skb
, sizeof(*iph
)))
1371 if (iph
->ihl
< 5 || iph
->version
!= 4)
1374 if (!pskb_may_pull(skb
, ip_hdrlen(skb
)))
1379 if (unlikely(ip_fast_csum((u8
*)iph
, iph
->ihl
)))
1382 if (iph
->protocol
!= IPPROTO_IGMP
)
1385 len
= ntohs(iph
->tot_len
);
1386 if (skb
->len
< len
|| len
< ip_hdrlen(skb
))
1389 if (skb
->len
> len
) {
1390 skb2
= skb_clone(skb
, GFP_ATOMIC
);
1394 err
= pskb_trim_rcsum(skb2
, len
);
1399 len
-= ip_hdrlen(skb2
);
1400 offset
= skb_network_offset(skb2
) + ip_hdrlen(skb2
);
1401 __skb_pull(skb2
, offset
);
1402 skb_reset_transport_header(skb2
);
1405 if (!pskb_may_pull(skb2
, sizeof(*ih
)))
1408 switch (skb2
->ip_summed
) {
1409 case CHECKSUM_COMPLETE
:
1410 if (!csum_fold(skb2
->csum
))
1415 if (skb_checksum_complete(skb2
))
1421 BR_INPUT_SKB_CB(skb
)->igmp
= 1;
1422 ih
= igmp_hdr(skb2
);
1425 case IGMP_HOST_MEMBERSHIP_REPORT
:
1426 case IGMPV2_HOST_MEMBERSHIP_REPORT
:
1427 BR_INPUT_SKB_CB(skb2
)->mrouters_only
= 1;
1428 err
= br_ip4_multicast_add_group(br
, port
, ih
->group
);
1430 case IGMPV3_HOST_MEMBERSHIP_REPORT
:
1431 err
= br_ip4_multicast_igmp3_report(br
, port
, skb2
);
1433 case IGMP_HOST_MEMBERSHIP_QUERY
:
1434 err
= br_ip4_multicast_query(br
, port
, skb2
);
1436 case IGMP_HOST_LEAVE_MESSAGE
:
1437 br_ip4_multicast_leave_group(br
, port
, ih
->group
);
1442 __skb_push(skb2
, offset
);
1449 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
1450 static int br_multicast_ipv6_rcv(struct net_bridge
*br
,
1451 struct net_bridge_port
*port
,
1452 struct sk_buff
*skb
)
1454 struct sk_buff
*skb2
;
1455 struct ipv6hdr
*ip6h
;
1456 struct icmp6hdr
*icmp6h
;
1462 if (!pskb_may_pull(skb
, sizeof(*ip6h
)))
1465 ip6h
= ipv6_hdr(skb
);
1468 * We're interested in MLD messages only.
1470 * - MLD has always Router Alert hop-by-hop option
1471 * - But we do not support jumbrograms.
1473 if (ip6h
->version
!= 6 ||
1474 ip6h
->nexthdr
!= IPPROTO_HOPOPTS
||
1475 ip6h
->payload_len
== 0)
1478 len
= ntohs(ip6h
->payload_len
);
1482 nexthdr
= ip6h
->nexthdr
;
1483 offset
= ipv6_skip_exthdr(skb
, sizeof(*ip6h
), &nexthdr
);
1485 if (offset
< 0 || nexthdr
!= IPPROTO_ICMPV6
)
1488 /* Okay, we found ICMPv6 header */
1489 skb2
= skb_clone(skb
, GFP_ATOMIC
);
1494 if (!pskb_may_pull(skb2
, offset
+ sizeof(struct icmp6hdr
)))
1497 len
-= offset
- skb_network_offset(skb2
);
1499 __skb_pull(skb2
, offset
);
1500 skb_reset_transport_header(skb2
);
1502 icmp6h
= icmp6_hdr(skb2
);
1504 switch (icmp6h
->icmp6_type
) {
1505 case ICMPV6_MGM_QUERY
:
1506 case ICMPV6_MGM_REPORT
:
1507 case ICMPV6_MGM_REDUCTION
:
1508 case ICMPV6_MLD2_REPORT
:
1515 /* Okay, we found MLD message. Check further. */
1516 if (skb2
->len
> len
) {
1517 err
= pskb_trim_rcsum(skb2
, len
);
1522 switch (skb2
->ip_summed
) {
1523 case CHECKSUM_COMPLETE
:
1524 if (!csum_fold(skb2
->csum
))
1529 if (skb_checksum_complete(skb2
))
1535 BR_INPUT_SKB_CB(skb
)->igmp
= 1;
1537 switch (icmp6h
->icmp6_type
) {
1538 case ICMPV6_MGM_REPORT
:
1540 struct mld_msg
*mld
;
1541 if (!pskb_may_pull(skb2
, sizeof(*mld
))) {
1545 mld
= (struct mld_msg
*)skb_transport_header(skb2
);
1546 BR_INPUT_SKB_CB(skb2
)->mrouters_only
= 1;
1547 err
= br_ip6_multicast_add_group(br
, port
, &mld
->mld_mca
);
1550 case ICMPV6_MLD2_REPORT
:
1551 err
= br_ip6_multicast_mld2_report(br
, port
, skb2
);
1553 case ICMPV6_MGM_QUERY
:
1554 err
= br_ip6_multicast_query(br
, port
, skb2
);
1556 case ICMPV6_MGM_REDUCTION
:
1558 struct mld_msg
*mld
;
1559 if (!pskb_may_pull(skb2
, sizeof(*mld
))) {
1563 mld
= (struct mld_msg
*)skb_transport_header(skb2
);
1564 br_ip6_multicast_leave_group(br
, port
, &mld
->mld_mca
);
1574 int br_multicast_rcv(struct net_bridge
*br
, struct net_bridge_port
*port
,
1575 struct sk_buff
*skb
)
1577 BR_INPUT_SKB_CB(skb
)->igmp
= 0;
1578 BR_INPUT_SKB_CB(skb
)->mrouters_only
= 0;
1580 if (br
->multicast_disabled
)
1583 switch (skb
->protocol
) {
1584 case htons(ETH_P_IP
):
1585 return br_multicast_ipv4_rcv(br
, port
, skb
);
1586 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
1587 case htons(ETH_P_IPV6
):
1588 return br_multicast_ipv6_rcv(br
, port
, skb
);
1595 static void br_multicast_query_expired(unsigned long data
)
1597 struct net_bridge
*br
= (void *)data
;
1599 spin_lock(&br
->multicast_lock
);
1600 if (br
->multicast_startup_queries_sent
<
1601 br
->multicast_startup_query_count
)
1602 br
->multicast_startup_queries_sent
++;
1604 br_multicast_send_query(br
, NULL
, br
->multicast_startup_queries_sent
);
1606 spin_unlock(&br
->multicast_lock
);
1609 void br_multicast_init(struct net_bridge
*br
)
1611 br
->hash_elasticity
= 4;
1614 br
->multicast_router
= 1;
1615 br
->multicast_last_member_count
= 2;
1616 br
->multicast_startup_query_count
= 2;
1618 br
->multicast_last_member_interval
= HZ
;
1619 br
->multicast_query_response_interval
= 10 * HZ
;
1620 br
->multicast_startup_query_interval
= 125 * HZ
/ 4;
1621 br
->multicast_query_interval
= 125 * HZ
;
1622 br
->multicast_querier_interval
= 255 * HZ
;
1623 br
->multicast_membership_interval
= 260 * HZ
;
1625 spin_lock_init(&br
->multicast_lock
);
1626 setup_timer(&br
->multicast_router_timer
,
1627 br_multicast_local_router_expired
, 0);
1628 setup_timer(&br
->multicast_querier_timer
,
1629 br_multicast_local_router_expired
, 0);
1630 setup_timer(&br
->multicast_query_timer
, br_multicast_query_expired
,
1634 void br_multicast_open(struct net_bridge
*br
)
1636 br
->multicast_startup_queries_sent
= 0;
1638 if (br
->multicast_disabled
)
1641 mod_timer(&br
->multicast_query_timer
, jiffies
);
1644 void br_multicast_stop(struct net_bridge
*br
)
1646 struct net_bridge_mdb_htable
*mdb
;
1647 struct net_bridge_mdb_entry
*mp
;
1648 struct hlist_node
*p
, *n
;
1652 del_timer_sync(&br
->multicast_router_timer
);
1653 del_timer_sync(&br
->multicast_querier_timer
);
1654 del_timer_sync(&br
->multicast_query_timer
);
1656 spin_lock_bh(&br
->multicast_lock
);
1657 mdb
= mlock_dereference(br
->mdb
, br
);
1664 for (i
= 0; i
< mdb
->max
; i
++) {
1665 hlist_for_each_entry_safe(mp
, p
, n
, &mdb
->mhash
[i
],
1667 del_timer(&mp
->timer
);
1668 del_timer(&mp
->query_timer
);
1669 call_rcu_bh(&mp
->rcu
, br_multicast_free_group
);
1674 spin_unlock_bh(&br
->multicast_lock
);
1676 spin_lock_bh(&br
->multicast_lock
);
1681 call_rcu_bh(&mdb
->rcu
, br_mdb_free
);
1684 spin_unlock_bh(&br
->multicast_lock
);
1687 int br_multicast_set_router(struct net_bridge
*br
, unsigned long val
)
1691 spin_lock_bh(&br
->multicast_lock
);
1692 if (!netif_running(br
->dev
))
1698 del_timer(&br
->multicast_router_timer
);
1701 br
->multicast_router
= val
;
1711 spin_unlock_bh(&br
->multicast_lock
);
1716 int br_multicast_set_port_router(struct net_bridge_port
*p
, unsigned long val
)
1718 struct net_bridge
*br
= p
->br
;
1721 spin_lock(&br
->multicast_lock
);
1722 if (!netif_running(br
->dev
) || p
->state
== BR_STATE_DISABLED
)
1729 p
->multicast_router
= val
;
1732 if (val
< 2 && !hlist_unhashed(&p
->rlist
))
1733 hlist_del_init_rcu(&p
->rlist
);
1738 del_timer(&p
->multicast_router_timer
);
1743 br_multicast_add_router(br
, p
);
1752 spin_unlock(&br
->multicast_lock
);
1757 int br_multicast_toggle(struct net_bridge
*br
, unsigned long val
)
1759 struct net_bridge_port
*port
;
1761 struct net_bridge_mdb_htable
*mdb
;
1763 spin_lock(&br
->multicast_lock
);
1764 if (br
->multicast_disabled
== !val
)
1767 br
->multicast_disabled
= !val
;
1768 if (br
->multicast_disabled
)
1771 if (!netif_running(br
->dev
))
1774 mdb
= mlock_dereference(br
->mdb
, br
);
1779 br
->multicast_disabled
= !!val
;
1783 err
= br_mdb_rehash(&br
->mdb
, mdb
->max
,
1784 br
->hash_elasticity
);
1789 br_multicast_open(br
);
1790 list_for_each_entry(port
, &br
->port_list
, list
) {
1791 if (port
->state
== BR_STATE_DISABLED
||
1792 port
->state
== BR_STATE_BLOCKING
)
1795 __br_multicast_enable_port(port
);
1799 spin_unlock(&br
->multicast_lock
);
1804 int br_multicast_set_hash_max(struct net_bridge
*br
, unsigned long val
)
1808 struct net_bridge_mdb_htable
*mdb
;
1810 spin_lock(&br
->multicast_lock
);
1811 if (!netif_running(br
->dev
))
1815 if (!is_power_of_2(val
))
1818 mdb
= mlock_dereference(br
->mdb
, br
);
1819 if (mdb
&& val
< mdb
->size
)
1835 err
= br_mdb_rehash(&br
->mdb
, br
->hash_max
,
1836 br
->hash_elasticity
);
1842 spin_unlock(&br
->multicast_lock
);