Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Bridge multicast support. |
| 3 | * |
| 4 | * Copyright (c) 2010 Herbert Xu <herbert@gondor.apana.org.au> |
| 5 | * |
| 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) |
| 9 | * any later version. |
| 10 | * |
| 11 | */ |
| 12 | |
| 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> |
Herbert Xu | b195167 | 2010-02-27 19:41:51 +0000 | [diff] [blame] | 18 | #include <linux/log2.h> |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 19 | #include <linux/netdevice.h> |
| 20 | #include <linux/netfilter_bridge.h> |
| 21 | #include <linux/random.h> |
| 22 | #include <linux/rculist.h> |
| 23 | #include <linux/skbuff.h> |
| 24 | #include <linux/slab.h> |
| 25 | #include <linux/timer.h> |
| 26 | #include <net/ip.h> |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 27 | #if IS_ENABLED(CONFIG_IPV6) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 28 | #include <net/ipv6.h> |
| 29 | #include <net/mld.h> |
| 30 | #include <net/addrconf.h> |
David S. Miller | d4c4f07 | 2010-04-27 10:16:54 -0700 | [diff] [blame] | 31 | #include <net/ip6_checksum.h> |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 32 | #endif |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 33 | |
| 34 | #include "br_private.h" |
| 35 | |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 36 | #define mlock_dereference(X, br) \ |
| 37 | rcu_dereference_protected(X, lockdep_is_held(&br->multicast_lock)) |
| 38 | |
Herbert Xu | c83b8fa | 2012-04-13 02:37:42 +0000 | [diff] [blame] | 39 | static void br_multicast_start_querier(struct net_bridge *br); |
| 40 | |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 41 | #if IS_ENABLED(CONFIG_IPV6) |
Linus Lüssing | e4de9f9 | 2011-02-15 13:19:21 +0000 | [diff] [blame] | 42 | static inline int ipv6_is_transient_multicast(const struct in6_addr *addr) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 43 | { |
Linus Lüssing | e4de9f9 | 2011-02-15 13:19:21 +0000 | [diff] [blame] | 44 | if (ipv6_addr_is_multicast(addr) && IPV6_ADDR_MC_FLAG_TRANSIENT(addr)) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 45 | return 1; |
| 46 | return 0; |
| 47 | } |
| 48 | #endif |
| 49 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 50 | static inline int br_ip_equal(const struct br_ip *a, const struct br_ip *b) |
| 51 | { |
| 52 | if (a->proto != b->proto) |
| 53 | return 0; |
| 54 | switch (a->proto) { |
| 55 | case htons(ETH_P_IP): |
| 56 | return a->u.ip4 == b->u.ip4; |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 57 | #if IS_ENABLED(CONFIG_IPV6) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 58 | case htons(ETH_P_IPV6): |
| 59 | return ipv6_addr_equal(&a->u.ip6, &b->u.ip6); |
| 60 | #endif |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 61 | } |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | static inline int __br_ip4_hash(struct net_bridge_mdb_htable *mdb, __be32 ip) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 66 | { |
Eric Dumazet | 0eae88f | 2010-04-20 19:06:52 -0700 | [diff] [blame] | 67 | return jhash_1word(mdb->secret, (__force u32)ip) & (mdb->max - 1); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 70 | #if IS_ENABLED(CONFIG_IPV6) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 71 | static inline int __br_ip6_hash(struct net_bridge_mdb_htable *mdb, |
| 72 | const struct in6_addr *ip) |
| 73 | { |
| 74 | return jhash2((__force u32 *)ip->s6_addr32, 4, mdb->secret) & (mdb->max - 1); |
| 75 | } |
| 76 | #endif |
| 77 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 78 | static inline int br_ip_hash(struct net_bridge_mdb_htable *mdb, |
| 79 | struct br_ip *ip) |
| 80 | { |
| 81 | switch (ip->proto) { |
| 82 | case htons(ETH_P_IP): |
| 83 | return __br_ip4_hash(mdb, ip->u.ip4); |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 84 | #if IS_ENABLED(CONFIG_IPV6) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 85 | case htons(ETH_P_IPV6): |
| 86 | return __br_ip6_hash(mdb, &ip->u.ip6); |
| 87 | #endif |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 88 | } |
| 89 | return 0; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | static struct net_bridge_mdb_entry *__br_mdb_ip_get( |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 93 | struct net_bridge_mdb_htable *mdb, struct br_ip *dst, int hash) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 94 | { |
| 95 | struct net_bridge_mdb_entry *mp; |
| 96 | struct hlist_node *p; |
| 97 | |
Herbert Xu | 49f5fcf | 2010-03-05 21:07:39 +0000 | [diff] [blame] | 98 | hlist_for_each_entry_rcu(mp, p, &mdb->mhash[hash], hlist[mdb->ver]) { |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 99 | if (br_ip_equal(&mp->addr, dst)) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 100 | return mp; |
| 101 | } |
| 102 | |
| 103 | return NULL; |
| 104 | } |
| 105 | |
Herbert Xu | 7f285fa | 2010-07-05 14:50:08 +0000 | [diff] [blame] | 106 | static struct net_bridge_mdb_entry *br_mdb_ip_get( |
| 107 | struct net_bridge_mdb_htable *mdb, struct br_ip *dst) |
| 108 | { |
| 109 | if (!mdb) |
| 110 | return NULL; |
| 111 | |
| 112 | return __br_mdb_ip_get(mdb, dst, br_ip_hash(mdb, dst)); |
| 113 | } |
| 114 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 115 | static struct net_bridge_mdb_entry *br_mdb_ip4_get( |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 116 | struct net_bridge_mdb_htable *mdb, __be32 dst) |
| 117 | { |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 118 | struct br_ip br_dst; |
Herbert Xu | 0821ec5 | 2010-03-15 20:38:25 -0700 | [diff] [blame] | 119 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 120 | br_dst.u.ip4 = dst; |
| 121 | br_dst.proto = htons(ETH_P_IP); |
| 122 | |
Herbert Xu | 7f285fa | 2010-07-05 14:50:08 +0000 | [diff] [blame] | 123 | return br_mdb_ip_get(mdb, &br_dst); |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 124 | } |
| 125 | |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 126 | #if IS_ENABLED(CONFIG_IPV6) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 127 | static struct net_bridge_mdb_entry *br_mdb_ip6_get( |
| 128 | struct net_bridge_mdb_htable *mdb, const struct in6_addr *dst) |
| 129 | { |
| 130 | struct br_ip br_dst; |
| 131 | |
Alexey Dobriyan | 4e3fd7a | 2011-11-21 03:39:03 +0000 | [diff] [blame] | 132 | br_dst.u.ip6 = *dst; |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 133 | br_dst.proto = htons(ETH_P_IPV6); |
| 134 | |
Herbert Xu | 7f285fa | 2010-07-05 14:50:08 +0000 | [diff] [blame] | 135 | return br_mdb_ip_get(mdb, &br_dst); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 136 | } |
| 137 | #endif |
| 138 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 139 | struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br, |
| 140 | struct sk_buff *skb) |
| 141 | { |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 142 | struct net_bridge_mdb_htable *mdb = rcu_dereference(br->mdb); |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 143 | struct br_ip ip; |
| 144 | |
Herbert Xu | 7f285fa | 2010-07-05 14:50:08 +0000 | [diff] [blame] | 145 | if (br->multicast_disabled) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 146 | return NULL; |
| 147 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 148 | if (BR_INPUT_SKB_CB(skb)->igmp) |
| 149 | return NULL; |
| 150 | |
| 151 | ip.proto = skb->protocol; |
| 152 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 153 | switch (skb->protocol) { |
| 154 | case htons(ETH_P_IP): |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 155 | ip.u.ip4 = ip_hdr(skb)->daddr; |
| 156 | break; |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 157 | #if IS_ENABLED(CONFIG_IPV6) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 158 | case htons(ETH_P_IPV6): |
Alexey Dobriyan | 4e3fd7a | 2011-11-21 03:39:03 +0000 | [diff] [blame] | 159 | ip.u.ip6 = ipv6_hdr(skb)->daddr; |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 160 | break; |
| 161 | #endif |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 162 | default: |
| 163 | return NULL; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 164 | } |
| 165 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 166 | return br_mdb_ip_get(mdb, &ip); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | static void br_mdb_free(struct rcu_head *head) |
| 170 | { |
| 171 | struct net_bridge_mdb_htable *mdb = |
| 172 | container_of(head, struct net_bridge_mdb_htable, rcu); |
| 173 | struct net_bridge_mdb_htable *old = mdb->old; |
| 174 | |
| 175 | mdb->old = NULL; |
| 176 | kfree(old->mhash); |
| 177 | kfree(old); |
| 178 | } |
| 179 | |
| 180 | static int br_mdb_copy(struct net_bridge_mdb_htable *new, |
| 181 | struct net_bridge_mdb_htable *old, |
| 182 | int elasticity) |
| 183 | { |
| 184 | struct net_bridge_mdb_entry *mp; |
| 185 | struct hlist_node *p; |
| 186 | int maxlen; |
| 187 | int len; |
| 188 | int i; |
| 189 | |
| 190 | for (i = 0; i < old->max; i++) |
| 191 | hlist_for_each_entry(mp, p, &old->mhash[i], hlist[old->ver]) |
| 192 | hlist_add_head(&mp->hlist[new->ver], |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 193 | &new->mhash[br_ip_hash(new, &mp->addr)]); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 194 | |
| 195 | if (!elasticity) |
| 196 | return 0; |
| 197 | |
| 198 | maxlen = 0; |
| 199 | for (i = 0; i < new->max; i++) { |
| 200 | len = 0; |
| 201 | hlist_for_each_entry(mp, p, &new->mhash[i], hlist[new->ver]) |
| 202 | len++; |
| 203 | if (len > maxlen) |
| 204 | maxlen = len; |
| 205 | } |
| 206 | |
| 207 | return maxlen > elasticity ? -EINVAL : 0; |
| 208 | } |
| 209 | |
| 210 | static void br_multicast_free_pg(struct rcu_head *head) |
| 211 | { |
| 212 | struct net_bridge_port_group *p = |
| 213 | container_of(head, struct net_bridge_port_group, rcu); |
| 214 | |
| 215 | kfree(p); |
| 216 | } |
| 217 | |
| 218 | static void br_multicast_free_group(struct rcu_head *head) |
| 219 | { |
| 220 | struct net_bridge_mdb_entry *mp = |
| 221 | container_of(head, struct net_bridge_mdb_entry, rcu); |
| 222 | |
| 223 | kfree(mp); |
| 224 | } |
| 225 | |
| 226 | static void br_multicast_group_expired(unsigned long data) |
| 227 | { |
| 228 | struct net_bridge_mdb_entry *mp = (void *)data; |
| 229 | struct net_bridge *br = mp->br; |
| 230 | struct net_bridge_mdb_htable *mdb; |
| 231 | |
| 232 | spin_lock(&br->multicast_lock); |
| 233 | if (!netif_running(br->dev) || timer_pending(&mp->timer)) |
| 234 | goto out; |
| 235 | |
Herbert Xu | 8a87017 | 2011-02-12 01:05:42 -0800 | [diff] [blame] | 236 | mp->mglist = false; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 237 | |
| 238 | if (mp->ports) |
| 239 | goto out; |
| 240 | |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 241 | mdb = mlock_dereference(br->mdb, br); |
| 242 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 243 | hlist_del_rcu(&mp->hlist[mdb->ver]); |
| 244 | mdb->size--; |
| 245 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 246 | call_rcu_bh(&mp->rcu, br_multicast_free_group); |
| 247 | |
| 248 | out: |
| 249 | spin_unlock(&br->multicast_lock); |
| 250 | } |
| 251 | |
| 252 | static void br_multicast_del_pg(struct net_bridge *br, |
| 253 | struct net_bridge_port_group *pg) |
| 254 | { |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 255 | struct net_bridge_mdb_htable *mdb; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 256 | struct net_bridge_mdb_entry *mp; |
| 257 | struct net_bridge_port_group *p; |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 258 | struct net_bridge_port_group __rcu **pp; |
| 259 | |
| 260 | mdb = mlock_dereference(br->mdb, br); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 261 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 262 | mp = br_mdb_ip_get(mdb, &pg->addr); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 263 | if (WARN_ON(!mp)) |
| 264 | return; |
| 265 | |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 266 | for (pp = &mp->ports; |
| 267 | (p = mlock_dereference(*pp, br)) != NULL; |
| 268 | pp = &p->next) { |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 269 | if (p != pg) |
| 270 | continue; |
| 271 | |
stephen hemminger | 83f6a74 | 2010-04-27 15:01:06 +0000 | [diff] [blame] | 272 | rcu_assign_pointer(*pp, p->next); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 273 | hlist_del_init(&p->mglist); |
| 274 | del_timer(&p->timer); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 275 | call_rcu_bh(&p->rcu, br_multicast_free_pg); |
| 276 | |
Herbert Xu | 8a87017 | 2011-02-12 01:05:42 -0800 | [diff] [blame] | 277 | if (!mp->ports && !mp->mglist && |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 278 | netif_running(br->dev)) |
| 279 | mod_timer(&mp->timer, jiffies); |
| 280 | |
| 281 | return; |
| 282 | } |
| 283 | |
| 284 | WARN_ON(1); |
| 285 | } |
| 286 | |
| 287 | static void br_multicast_port_group_expired(unsigned long data) |
| 288 | { |
| 289 | struct net_bridge_port_group *pg = (void *)data; |
| 290 | struct net_bridge *br = pg->port->br; |
| 291 | |
| 292 | spin_lock(&br->multicast_lock); |
| 293 | if (!netif_running(br->dev) || timer_pending(&pg->timer) || |
| 294 | hlist_unhashed(&pg->mglist)) |
| 295 | goto out; |
| 296 | |
| 297 | br_multicast_del_pg(br, pg); |
| 298 | |
| 299 | out: |
| 300 | spin_unlock(&br->multicast_lock); |
| 301 | } |
| 302 | |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 303 | static int br_mdb_rehash(struct net_bridge_mdb_htable __rcu **mdbp, int max, |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 304 | int elasticity) |
| 305 | { |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 306 | struct net_bridge_mdb_htable *old = rcu_dereference_protected(*mdbp, 1); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 307 | struct net_bridge_mdb_htable *mdb; |
| 308 | int err; |
| 309 | |
| 310 | mdb = kmalloc(sizeof(*mdb), GFP_ATOMIC); |
| 311 | if (!mdb) |
| 312 | return -ENOMEM; |
| 313 | |
| 314 | mdb->max = max; |
| 315 | mdb->old = old; |
| 316 | |
| 317 | mdb->mhash = kzalloc(max * sizeof(*mdb->mhash), GFP_ATOMIC); |
| 318 | if (!mdb->mhash) { |
| 319 | kfree(mdb); |
| 320 | return -ENOMEM; |
| 321 | } |
| 322 | |
| 323 | mdb->size = old ? old->size : 0; |
| 324 | mdb->ver = old ? old->ver ^ 1 : 0; |
| 325 | |
| 326 | if (!old || elasticity) |
| 327 | get_random_bytes(&mdb->secret, sizeof(mdb->secret)); |
| 328 | else |
| 329 | mdb->secret = old->secret; |
| 330 | |
| 331 | if (!old) |
| 332 | goto out; |
| 333 | |
| 334 | err = br_mdb_copy(mdb, old, elasticity); |
| 335 | if (err) { |
| 336 | kfree(mdb->mhash); |
| 337 | kfree(mdb); |
| 338 | return err; |
| 339 | } |
| 340 | |
| 341 | call_rcu_bh(&mdb->rcu, br_mdb_free); |
| 342 | |
| 343 | out: |
| 344 | rcu_assign_pointer(*mdbp, mdb); |
| 345 | |
| 346 | return 0; |
| 347 | } |
| 348 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 349 | static struct sk_buff *br_ip4_multicast_alloc_query(struct net_bridge *br, |
| 350 | __be32 group) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 351 | { |
| 352 | struct sk_buff *skb; |
| 353 | struct igmphdr *ih; |
| 354 | struct ethhdr *eth; |
| 355 | struct iphdr *iph; |
| 356 | |
| 357 | skb = netdev_alloc_skb_ip_align(br->dev, sizeof(*eth) + sizeof(*iph) + |
| 358 | sizeof(*ih) + 4); |
| 359 | if (!skb) |
| 360 | goto out; |
| 361 | |
| 362 | skb->protocol = htons(ETH_P_IP); |
| 363 | |
| 364 | skb_reset_mac_header(skb); |
| 365 | eth = eth_hdr(skb); |
| 366 | |
| 367 | memcpy(eth->h_source, br->dev->dev_addr, 6); |
| 368 | eth->h_dest[0] = 1; |
| 369 | eth->h_dest[1] = 0; |
| 370 | eth->h_dest[2] = 0x5e; |
| 371 | eth->h_dest[3] = 0; |
| 372 | eth->h_dest[4] = 0; |
| 373 | eth->h_dest[5] = 1; |
| 374 | eth->h_proto = htons(ETH_P_IP); |
| 375 | skb_put(skb, sizeof(*eth)); |
| 376 | |
| 377 | skb_set_network_header(skb, skb->len); |
| 378 | iph = ip_hdr(skb); |
| 379 | |
| 380 | iph->version = 4; |
| 381 | iph->ihl = 6; |
| 382 | iph->tos = 0xc0; |
| 383 | iph->tot_len = htons(sizeof(*iph) + sizeof(*ih) + 4); |
| 384 | iph->id = 0; |
| 385 | iph->frag_off = htons(IP_DF); |
| 386 | iph->ttl = 1; |
| 387 | iph->protocol = IPPROTO_IGMP; |
| 388 | iph->saddr = 0; |
| 389 | iph->daddr = htonl(INADDR_ALLHOSTS_GROUP); |
| 390 | ((u8 *)&iph[1])[0] = IPOPT_RA; |
| 391 | ((u8 *)&iph[1])[1] = 4; |
| 392 | ((u8 *)&iph[1])[2] = 0; |
| 393 | ((u8 *)&iph[1])[3] = 0; |
| 394 | ip_send_check(iph); |
| 395 | skb_put(skb, 24); |
| 396 | |
| 397 | skb_set_transport_header(skb, skb->len); |
| 398 | ih = igmp_hdr(skb); |
| 399 | ih->type = IGMP_HOST_MEMBERSHIP_QUERY; |
| 400 | ih->code = (group ? br->multicast_last_member_interval : |
| 401 | br->multicast_query_response_interval) / |
| 402 | (HZ / IGMP_TIMER_SCALE); |
| 403 | ih->group = group; |
| 404 | ih->csum = 0; |
| 405 | ih->csum = ip_compute_csum((void *)ih, sizeof(struct igmphdr)); |
| 406 | skb_put(skb, sizeof(*ih)); |
| 407 | |
| 408 | __skb_pull(skb, sizeof(*eth)); |
| 409 | |
| 410 | out: |
| 411 | return skb; |
| 412 | } |
| 413 | |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 414 | #if IS_ENABLED(CONFIG_IPV6) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 415 | static struct sk_buff *br_ip6_multicast_alloc_query(struct net_bridge *br, |
Eric Dumazet | b71d1d4 | 2011-04-22 04:53:02 +0000 | [diff] [blame] | 416 | const struct in6_addr *group) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 417 | { |
| 418 | struct sk_buff *skb; |
| 419 | struct ipv6hdr *ip6h; |
| 420 | struct mld_msg *mldq; |
| 421 | struct ethhdr *eth; |
| 422 | u8 *hopopt; |
| 423 | unsigned long interval; |
| 424 | |
| 425 | skb = netdev_alloc_skb_ip_align(br->dev, sizeof(*eth) + sizeof(*ip6h) + |
| 426 | 8 + sizeof(*mldq)); |
| 427 | if (!skb) |
| 428 | goto out; |
| 429 | |
| 430 | skb->protocol = htons(ETH_P_IPV6); |
| 431 | |
| 432 | /* Ethernet header */ |
| 433 | skb_reset_mac_header(skb); |
| 434 | eth = eth_hdr(skb); |
| 435 | |
| 436 | memcpy(eth->h_source, br->dev->dev_addr, 6); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 437 | eth->h_proto = htons(ETH_P_IPV6); |
| 438 | skb_put(skb, sizeof(*eth)); |
| 439 | |
| 440 | /* IPv6 header + HbH option */ |
| 441 | skb_set_network_header(skb, skb->len); |
| 442 | ip6h = ipv6_hdr(skb); |
| 443 | |
| 444 | *(__force __be32 *)ip6h = htonl(0x60000000); |
David Stevens | 76d6615 | 2010-12-14 08:42:16 +0000 | [diff] [blame] | 445 | ip6h->payload_len = htons(8 + sizeof(*mldq)); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 446 | ip6h->nexthdr = IPPROTO_HOPOPTS; |
| 447 | ip6h->hop_limit = 1; |
Linus Lüssing | a7bff75 | 2011-03-22 11:40:32 +0000 | [diff] [blame] | 448 | ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1)); |
Ulrich Weber | d1d81d4 | 2012-03-05 04:52:44 +0000 | [diff] [blame] | 449 | if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0, |
| 450 | &ip6h->saddr)) { |
| 451 | kfree_skb(skb); |
| 452 | return NULL; |
| 453 | } |
Linus Lüssing | 36cff5a | 2011-02-17 08:17:51 +0000 | [diff] [blame] | 454 | ipv6_eth_mc_map(&ip6h->daddr, eth->h_dest); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 455 | |
| 456 | hopopt = (u8 *)(ip6h + 1); |
| 457 | hopopt[0] = IPPROTO_ICMPV6; /* next hdr */ |
| 458 | hopopt[1] = 0; /* length of HbH */ |
| 459 | hopopt[2] = IPV6_TLV_ROUTERALERT; /* Router Alert */ |
| 460 | hopopt[3] = 2; /* Length of RA Option */ |
| 461 | hopopt[4] = 0; /* Type = 0x0000 (MLD) */ |
| 462 | hopopt[5] = 0; |
Eldad Zack | 1de5a71 | 2012-05-17 06:00:25 +0000 | [diff] [blame] | 463 | hopopt[6] = IPV6_TLV_PAD1; /* Pad1 */ |
| 464 | hopopt[7] = IPV6_TLV_PAD1; /* Pad1 */ |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 465 | |
| 466 | skb_put(skb, sizeof(*ip6h) + 8); |
| 467 | |
| 468 | /* ICMPv6 */ |
| 469 | skb_set_transport_header(skb, skb->len); |
| 470 | mldq = (struct mld_msg *) icmp6_hdr(skb); |
| 471 | |
| 472 | interval = ipv6_addr_any(group) ? br->multicast_last_member_interval : |
| 473 | br->multicast_query_response_interval; |
| 474 | |
| 475 | mldq->mld_type = ICMPV6_MGM_QUERY; |
| 476 | mldq->mld_code = 0; |
| 477 | mldq->mld_cksum = 0; |
| 478 | mldq->mld_maxdelay = htons((u16)jiffies_to_msecs(interval)); |
| 479 | mldq->mld_reserved = 0; |
Alexey Dobriyan | 4e3fd7a | 2011-11-21 03:39:03 +0000 | [diff] [blame] | 480 | mldq->mld_mca = *group; |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 481 | |
| 482 | /* checksum */ |
| 483 | mldq->mld_cksum = csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr, |
| 484 | sizeof(*mldq), IPPROTO_ICMPV6, |
| 485 | csum_partial(mldq, |
| 486 | sizeof(*mldq), 0)); |
| 487 | skb_put(skb, sizeof(*mldq)); |
| 488 | |
| 489 | __skb_pull(skb, sizeof(*eth)); |
| 490 | |
| 491 | out: |
| 492 | return skb; |
| 493 | } |
| 494 | #endif |
| 495 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 496 | static struct sk_buff *br_multicast_alloc_query(struct net_bridge *br, |
| 497 | struct br_ip *addr) |
| 498 | { |
| 499 | switch (addr->proto) { |
| 500 | case htons(ETH_P_IP): |
| 501 | return br_ip4_multicast_alloc_query(br, addr->u.ip4); |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 502 | #if IS_ENABLED(CONFIG_IPV6) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 503 | case htons(ETH_P_IPV6): |
| 504 | return br_ip6_multicast_alloc_query(br, &addr->u.ip6); |
| 505 | #endif |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 506 | } |
| 507 | return NULL; |
| 508 | } |
| 509 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 510 | static struct net_bridge_mdb_entry *br_multicast_get_group( |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 511 | struct net_bridge *br, struct net_bridge_port *port, |
| 512 | struct br_ip *group, int hash) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 513 | { |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 514 | struct net_bridge_mdb_htable *mdb; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 515 | struct net_bridge_mdb_entry *mp; |
| 516 | struct hlist_node *p; |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 517 | unsigned int count = 0; |
| 518 | unsigned int max; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 519 | int elasticity; |
| 520 | int err; |
| 521 | |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 522 | mdb = rcu_dereference_protected(br->mdb, 1); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 523 | hlist_for_each_entry(mp, p, &mdb->mhash[hash], hlist[mdb->ver]) { |
| 524 | count++; |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 525 | if (unlikely(br_ip_equal(group, &mp->addr))) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 526 | return mp; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | elasticity = 0; |
| 530 | max = mdb->max; |
| 531 | |
| 532 | if (unlikely(count > br->hash_elasticity && count)) { |
| 533 | if (net_ratelimit()) |
stephen hemminger | 28a16c9 | 2010-05-10 09:31:09 +0000 | [diff] [blame] | 534 | br_info(br, "Multicast hash table " |
| 535 | "chain limit reached: %s\n", |
| 536 | port ? port->dev->name : br->dev->name); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 537 | |
| 538 | elasticity = br->hash_elasticity; |
| 539 | } |
| 540 | |
| 541 | if (mdb->size >= max) { |
| 542 | max *= 2; |
Thomas Graf | 036be6d | 2012-07-10 22:29:19 +0000 | [diff] [blame] | 543 | if (unlikely(max > br->hash_max)) { |
| 544 | br_warn(br, "Multicast hash table maximum of %d " |
| 545 | "reached, disabling snooping: %s\n", |
| 546 | br->hash_max, |
| 547 | port ? port->dev->name : br->dev->name); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 548 | err = -E2BIG; |
| 549 | disable: |
| 550 | br->multicast_disabled = 1; |
| 551 | goto err; |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | if (max > mdb->max || elasticity) { |
| 556 | if (mdb->old) { |
| 557 | if (net_ratelimit()) |
stephen hemminger | 28a16c9 | 2010-05-10 09:31:09 +0000 | [diff] [blame] | 558 | br_info(br, "Multicast hash table " |
| 559 | "on fire: %s\n", |
| 560 | port ? port->dev->name : br->dev->name); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 561 | err = -EEXIST; |
| 562 | goto err; |
| 563 | } |
| 564 | |
| 565 | err = br_mdb_rehash(&br->mdb, max, elasticity); |
| 566 | if (err) { |
stephen hemminger | 28a16c9 | 2010-05-10 09:31:09 +0000 | [diff] [blame] | 567 | br_warn(br, "Cannot rehash multicast " |
| 568 | "hash table, disabling snooping: %s, %d, %d\n", |
| 569 | port ? port->dev->name : br->dev->name, |
| 570 | mdb->size, err); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 571 | goto disable; |
| 572 | } |
| 573 | |
| 574 | err = -EAGAIN; |
| 575 | goto err; |
| 576 | } |
| 577 | |
| 578 | return NULL; |
| 579 | |
| 580 | err: |
| 581 | mp = ERR_PTR(err); |
| 582 | return mp; |
| 583 | } |
| 584 | |
| 585 | static struct net_bridge_mdb_entry *br_multicast_new_group( |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 586 | struct net_bridge *br, struct net_bridge_port *port, |
| 587 | struct br_ip *group) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 588 | { |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 589 | struct net_bridge_mdb_htable *mdb; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 590 | struct net_bridge_mdb_entry *mp; |
| 591 | int hash; |
Tobias Klauser | 4c0833b | 2010-12-10 03:18:04 +0000 | [diff] [blame] | 592 | int err; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 593 | |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 594 | mdb = rcu_dereference_protected(br->mdb, 1); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 595 | if (!mdb) { |
Tobias Klauser | 4c0833b | 2010-12-10 03:18:04 +0000 | [diff] [blame] | 596 | err = br_mdb_rehash(&br->mdb, BR_HASH_SIZE, 0); |
| 597 | if (err) |
| 598 | return ERR_PTR(err); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 599 | goto rehash; |
| 600 | } |
| 601 | |
| 602 | hash = br_ip_hash(mdb, group); |
| 603 | mp = br_multicast_get_group(br, port, group, hash); |
| 604 | switch (PTR_ERR(mp)) { |
| 605 | case 0: |
| 606 | break; |
| 607 | |
| 608 | case -EAGAIN: |
| 609 | rehash: |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 610 | mdb = rcu_dereference_protected(br->mdb, 1); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 611 | hash = br_ip_hash(mdb, group); |
| 612 | break; |
| 613 | |
| 614 | default: |
| 615 | goto out; |
| 616 | } |
| 617 | |
| 618 | mp = kzalloc(sizeof(*mp), GFP_ATOMIC); |
| 619 | if (unlikely(!mp)) |
Tobias Klauser | 4c0833b | 2010-12-10 03:18:04 +0000 | [diff] [blame] | 620 | return ERR_PTR(-ENOMEM); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 621 | |
| 622 | mp->br = br; |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 623 | mp->addr = *group; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 624 | setup_timer(&mp->timer, br_multicast_group_expired, |
| 625 | (unsigned long)mp); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 626 | |
| 627 | hlist_add_head_rcu(&mp->hlist[mdb->ver], &mdb->mhash[hash]); |
| 628 | mdb->size++; |
| 629 | |
| 630 | out: |
| 631 | return mp; |
| 632 | } |
| 633 | |
| 634 | static int br_multicast_add_group(struct net_bridge *br, |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 635 | struct net_bridge_port *port, |
| 636 | struct br_ip *group) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 637 | { |
| 638 | struct net_bridge_mdb_entry *mp; |
| 639 | struct net_bridge_port_group *p; |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 640 | struct net_bridge_port_group __rcu **pp; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 641 | unsigned long now = jiffies; |
| 642 | int err; |
| 643 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 644 | spin_lock(&br->multicast_lock); |
| 645 | if (!netif_running(br->dev) || |
| 646 | (port && port->state == BR_STATE_DISABLED)) |
| 647 | goto out; |
| 648 | |
| 649 | mp = br_multicast_new_group(br, port, group); |
| 650 | err = PTR_ERR(mp); |
Tobias Klauser | 4c0833b | 2010-12-10 03:18:04 +0000 | [diff] [blame] | 651 | if (IS_ERR(mp)) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 652 | goto err; |
| 653 | |
| 654 | if (!port) { |
Herbert Xu | 8a87017 | 2011-02-12 01:05:42 -0800 | [diff] [blame] | 655 | mp->mglist = true; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 656 | mod_timer(&mp->timer, now + br->multicast_membership_interval); |
| 657 | goto out; |
| 658 | } |
| 659 | |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 660 | for (pp = &mp->ports; |
| 661 | (p = mlock_dereference(*pp, br)) != NULL; |
| 662 | pp = &p->next) { |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 663 | if (p->port == port) |
| 664 | goto found; |
| 665 | if ((unsigned long)p->port < (unsigned long)port) |
| 666 | break; |
| 667 | } |
| 668 | |
| 669 | p = kzalloc(sizeof(*p), GFP_ATOMIC); |
| 670 | err = -ENOMEM; |
| 671 | if (unlikely(!p)) |
| 672 | goto err; |
| 673 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 674 | p->addr = *group; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 675 | p->port = port; |
| 676 | p->next = *pp; |
| 677 | hlist_add_head(&p->mglist, &port->mglist); |
| 678 | setup_timer(&p->timer, br_multicast_port_group_expired, |
| 679 | (unsigned long)p); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 680 | |
| 681 | rcu_assign_pointer(*pp, p); |
| 682 | |
| 683 | found: |
| 684 | mod_timer(&p->timer, now + br->multicast_membership_interval); |
| 685 | out: |
| 686 | err = 0; |
| 687 | |
| 688 | err: |
| 689 | spin_unlock(&br->multicast_lock); |
| 690 | return err; |
| 691 | } |
| 692 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 693 | static int br_ip4_multicast_add_group(struct net_bridge *br, |
| 694 | struct net_bridge_port *port, |
| 695 | __be32 group) |
| 696 | { |
| 697 | struct br_ip br_group; |
| 698 | |
| 699 | if (ipv4_is_local_multicast(group)) |
| 700 | return 0; |
| 701 | |
| 702 | br_group.u.ip4 = group; |
| 703 | br_group.proto = htons(ETH_P_IP); |
| 704 | |
| 705 | return br_multicast_add_group(br, port, &br_group); |
| 706 | } |
| 707 | |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 708 | #if IS_ENABLED(CONFIG_IPV6) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 709 | static int br_ip6_multicast_add_group(struct net_bridge *br, |
| 710 | struct net_bridge_port *port, |
| 711 | const struct in6_addr *group) |
| 712 | { |
| 713 | struct br_ip br_group; |
| 714 | |
Linus Lüssing | e4de9f9 | 2011-02-15 13:19:21 +0000 | [diff] [blame] | 715 | if (!ipv6_is_transient_multicast(group)) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 716 | return 0; |
| 717 | |
Alexey Dobriyan | 4e3fd7a | 2011-11-21 03:39:03 +0000 | [diff] [blame] | 718 | br_group.u.ip6 = *group; |
Linus Lüssing | 9cc6e0c | 2011-02-15 13:19:17 +0000 | [diff] [blame] | 719 | br_group.proto = htons(ETH_P_IPV6); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 720 | |
| 721 | return br_multicast_add_group(br, port, &br_group); |
| 722 | } |
| 723 | #endif |
| 724 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 725 | static void br_multicast_router_expired(unsigned long data) |
| 726 | { |
| 727 | struct net_bridge_port *port = (void *)data; |
| 728 | struct net_bridge *br = port->br; |
| 729 | |
| 730 | spin_lock(&br->multicast_lock); |
| 731 | if (port->multicast_router != 1 || |
| 732 | timer_pending(&port->multicast_router_timer) || |
| 733 | hlist_unhashed(&port->rlist)) |
| 734 | goto out; |
| 735 | |
| 736 | hlist_del_init_rcu(&port->rlist); |
| 737 | |
| 738 | out: |
| 739 | spin_unlock(&br->multicast_lock); |
| 740 | } |
| 741 | |
| 742 | static void br_multicast_local_router_expired(unsigned long data) |
| 743 | { |
| 744 | } |
| 745 | |
Herbert Xu | c83b8fa | 2012-04-13 02:37:42 +0000 | [diff] [blame] | 746 | static void br_multicast_querier_expired(unsigned long data) |
| 747 | { |
Herbert Xu | bb63f1f | 2012-04-30 00:22:56 +0000 | [diff] [blame] | 748 | struct net_bridge *br = (void *)data; |
Herbert Xu | c83b8fa | 2012-04-13 02:37:42 +0000 | [diff] [blame] | 749 | |
| 750 | spin_lock(&br->multicast_lock); |
| 751 | if (!netif_running(br->dev) || br->multicast_disabled) |
| 752 | goto out; |
| 753 | |
| 754 | br_multicast_start_querier(br); |
| 755 | |
| 756 | out: |
| 757 | spin_unlock(&br->multicast_lock); |
| 758 | } |
| 759 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 760 | static void __br_multicast_send_query(struct net_bridge *br, |
| 761 | struct net_bridge_port *port, |
| 762 | struct br_ip *ip) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 763 | { |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 764 | struct sk_buff *skb; |
| 765 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 766 | skb = br_multicast_alloc_query(br, ip); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 767 | if (!skb) |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 768 | return; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 769 | |
| 770 | if (port) { |
| 771 | __skb_push(skb, sizeof(struct ethhdr)); |
| 772 | skb->dev = port->dev; |
Jan Engelhardt | 713aefa | 2010-03-23 04:07:21 +0100 | [diff] [blame] | 773 | NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev, |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 774 | dev_queue_xmit); |
| 775 | } else |
| 776 | netif_rx(skb); |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 777 | } |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 778 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 779 | static void br_multicast_send_query(struct net_bridge *br, |
| 780 | struct net_bridge_port *port, u32 sent) |
| 781 | { |
| 782 | unsigned long time; |
| 783 | struct br_ip br_group; |
| 784 | |
| 785 | if (!netif_running(br->dev) || br->multicast_disabled || |
Herbert Xu | c5c2326 | 2012-04-13 02:37:42 +0000 | [diff] [blame] | 786 | !br->multicast_querier || |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 787 | timer_pending(&br->multicast_querier_timer)) |
| 788 | return; |
| 789 | |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 790 | memset(&br_group.u, 0, sizeof(br_group.u)); |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 791 | |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 792 | br_group.proto = htons(ETH_P_IP); |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 793 | __br_multicast_send_query(br, port, &br_group); |
| 794 | |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 795 | #if IS_ENABLED(CONFIG_IPV6) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 796 | br_group.proto = htons(ETH_P_IPV6); |
| 797 | __br_multicast_send_query(br, port, &br_group); |
| 798 | #endif |
| 799 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 800 | time = jiffies; |
| 801 | time += sent < br->multicast_startup_query_count ? |
| 802 | br->multicast_startup_query_interval : |
| 803 | br->multicast_query_interval; |
| 804 | mod_timer(port ? &port->multicast_query_timer : |
| 805 | &br->multicast_query_timer, time); |
| 806 | } |
| 807 | |
| 808 | static void br_multicast_port_query_expired(unsigned long data) |
| 809 | { |
| 810 | struct net_bridge_port *port = (void *)data; |
| 811 | struct net_bridge *br = port->br; |
| 812 | |
| 813 | spin_lock(&br->multicast_lock); |
Dan Carpenter | 02a780c | 2010-03-06 01:14:09 +0000 | [diff] [blame] | 814 | if (port->state == BR_STATE_DISABLED || |
| 815 | port->state == BR_STATE_BLOCKING) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 816 | goto out; |
| 817 | |
| 818 | if (port->multicast_startup_queries_sent < |
| 819 | br->multicast_startup_query_count) |
| 820 | port->multicast_startup_queries_sent++; |
| 821 | |
| 822 | br_multicast_send_query(port->br, port, |
| 823 | port->multicast_startup_queries_sent); |
| 824 | |
| 825 | out: |
| 826 | spin_unlock(&br->multicast_lock); |
| 827 | } |
| 828 | |
| 829 | void br_multicast_add_port(struct net_bridge_port *port) |
| 830 | { |
| 831 | port->multicast_router = 1; |
| 832 | |
| 833 | setup_timer(&port->multicast_router_timer, br_multicast_router_expired, |
| 834 | (unsigned long)port); |
| 835 | setup_timer(&port->multicast_query_timer, |
| 836 | br_multicast_port_query_expired, (unsigned long)port); |
| 837 | } |
| 838 | |
| 839 | void br_multicast_del_port(struct net_bridge_port *port) |
| 840 | { |
| 841 | del_timer_sync(&port->multicast_router_timer); |
| 842 | } |
| 843 | |
Herbert Xu | 561f110 | 2010-02-27 19:41:50 +0000 | [diff] [blame] | 844 | static void __br_multicast_enable_port(struct net_bridge_port *port) |
| 845 | { |
| 846 | port->multicast_startup_queries_sent = 0; |
| 847 | |
| 848 | if (try_to_del_timer_sync(&port->multicast_query_timer) >= 0 || |
| 849 | del_timer(&port->multicast_query_timer)) |
| 850 | mod_timer(&port->multicast_query_timer, jiffies); |
| 851 | } |
| 852 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 853 | void br_multicast_enable_port(struct net_bridge_port *port) |
| 854 | { |
| 855 | struct net_bridge *br = port->br; |
| 856 | |
| 857 | spin_lock(&br->multicast_lock); |
| 858 | if (br->multicast_disabled || !netif_running(br->dev)) |
| 859 | goto out; |
| 860 | |
Herbert Xu | 561f110 | 2010-02-27 19:41:50 +0000 | [diff] [blame] | 861 | __br_multicast_enable_port(port); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 862 | |
| 863 | out: |
| 864 | spin_unlock(&br->multicast_lock); |
| 865 | } |
| 866 | |
| 867 | void br_multicast_disable_port(struct net_bridge_port *port) |
| 868 | { |
| 869 | struct net_bridge *br = port->br; |
| 870 | struct net_bridge_port_group *pg; |
| 871 | struct hlist_node *p, *n; |
| 872 | |
| 873 | spin_lock(&br->multicast_lock); |
| 874 | hlist_for_each_entry_safe(pg, p, n, &port->mglist, mglist) |
| 875 | br_multicast_del_pg(br, pg); |
| 876 | |
| 877 | if (!hlist_unhashed(&port->rlist)) |
| 878 | hlist_del_init_rcu(&port->rlist); |
| 879 | del_timer(&port->multicast_router_timer); |
| 880 | del_timer(&port->multicast_query_timer); |
| 881 | spin_unlock(&br->multicast_lock); |
| 882 | } |
| 883 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 884 | static int br_ip4_multicast_igmp3_report(struct net_bridge *br, |
| 885 | struct net_bridge_port *port, |
| 886 | struct sk_buff *skb) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 887 | { |
| 888 | struct igmpv3_report *ih; |
| 889 | struct igmpv3_grec *grec; |
| 890 | int i; |
| 891 | int len; |
| 892 | int num; |
| 893 | int type; |
| 894 | int err = 0; |
| 895 | __be32 group; |
| 896 | |
| 897 | if (!pskb_may_pull(skb, sizeof(*ih))) |
| 898 | return -EINVAL; |
| 899 | |
| 900 | ih = igmpv3_report_hdr(skb); |
| 901 | num = ntohs(ih->ngrec); |
| 902 | len = sizeof(*ih); |
| 903 | |
| 904 | for (i = 0; i < num; i++) { |
| 905 | len += sizeof(*grec); |
| 906 | if (!pskb_may_pull(skb, len)) |
| 907 | return -EINVAL; |
| 908 | |
Herbert Xu | fd218cf | 2010-04-07 21:20:47 -0700 | [diff] [blame] | 909 | grec = (void *)(skb->data + len - sizeof(*grec)); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 910 | group = grec->grec_mca; |
| 911 | type = grec->grec_type; |
| 912 | |
Eric Dumazet | 8eabf95 | 2010-04-20 03:20:05 +0000 | [diff] [blame] | 913 | len += ntohs(grec->grec_nsrcs) * 4; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 914 | if (!pskb_may_pull(skb, len)) |
| 915 | return -EINVAL; |
| 916 | |
| 917 | /* We treat this as an IGMPv2 report for now. */ |
| 918 | switch (type) { |
| 919 | case IGMPV3_MODE_IS_INCLUDE: |
| 920 | case IGMPV3_MODE_IS_EXCLUDE: |
| 921 | case IGMPV3_CHANGE_TO_INCLUDE: |
| 922 | case IGMPV3_CHANGE_TO_EXCLUDE: |
| 923 | case IGMPV3_ALLOW_NEW_SOURCES: |
| 924 | case IGMPV3_BLOCK_OLD_SOURCES: |
| 925 | break; |
| 926 | |
| 927 | default: |
| 928 | continue; |
| 929 | } |
| 930 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 931 | err = br_ip4_multicast_add_group(br, port, group); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 932 | if (err) |
| 933 | break; |
| 934 | } |
| 935 | |
| 936 | return err; |
| 937 | } |
| 938 | |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 939 | #if IS_ENABLED(CONFIG_IPV6) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 940 | static int br_ip6_multicast_mld2_report(struct net_bridge *br, |
| 941 | struct net_bridge_port *port, |
| 942 | struct sk_buff *skb) |
| 943 | { |
| 944 | struct icmp6hdr *icmp6h; |
| 945 | struct mld2_grec *grec; |
| 946 | int i; |
| 947 | int len; |
| 948 | int num; |
| 949 | int err = 0; |
| 950 | |
| 951 | if (!pskb_may_pull(skb, sizeof(*icmp6h))) |
| 952 | return -EINVAL; |
| 953 | |
| 954 | icmp6h = icmp6_hdr(skb); |
| 955 | num = ntohs(icmp6h->icmp6_dataun.un_data16[1]); |
| 956 | len = sizeof(*icmp6h); |
| 957 | |
| 958 | for (i = 0; i < num; i++) { |
| 959 | __be16 *nsrcs, _nsrcs; |
| 960 | |
| 961 | nsrcs = skb_header_pointer(skb, |
| 962 | len + offsetof(struct mld2_grec, |
Linus Lüssing | 649e984 | 2011-02-15 13:19:18 +0000 | [diff] [blame] | 963 | grec_nsrcs), |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 964 | sizeof(_nsrcs), &_nsrcs); |
| 965 | if (!nsrcs) |
| 966 | return -EINVAL; |
| 967 | |
| 968 | if (!pskb_may_pull(skb, |
| 969 | len + sizeof(*grec) + |
Linus Lüssing | d41db9f | 2011-02-15 13:19:19 +0000 | [diff] [blame] | 970 | sizeof(struct in6_addr) * ntohs(*nsrcs))) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 971 | return -EINVAL; |
| 972 | |
| 973 | grec = (struct mld2_grec *)(skb->data + len); |
Linus Lüssing | d41db9f | 2011-02-15 13:19:19 +0000 | [diff] [blame] | 974 | len += sizeof(*grec) + |
| 975 | sizeof(struct in6_addr) * ntohs(*nsrcs); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 976 | |
| 977 | /* We treat these as MLDv1 reports for now. */ |
| 978 | switch (grec->grec_type) { |
| 979 | case MLD2_MODE_IS_INCLUDE: |
| 980 | case MLD2_MODE_IS_EXCLUDE: |
| 981 | case MLD2_CHANGE_TO_INCLUDE: |
| 982 | case MLD2_CHANGE_TO_EXCLUDE: |
| 983 | case MLD2_ALLOW_NEW_SOURCES: |
| 984 | case MLD2_BLOCK_OLD_SOURCES: |
| 985 | break; |
| 986 | |
| 987 | default: |
| 988 | continue; |
| 989 | } |
| 990 | |
| 991 | err = br_ip6_multicast_add_group(br, port, &grec->grec_mca); |
| 992 | if (!err) |
| 993 | break; |
| 994 | } |
| 995 | |
| 996 | return err; |
| 997 | } |
| 998 | #endif |
| 999 | |
stephen hemminger | 7e80c12 | 2010-04-27 15:01:04 +0000 | [diff] [blame] | 1000 | /* |
| 1001 | * Add port to rotuer_list |
| 1002 | * list is maintained ordered by pointer value |
| 1003 | * and locked by br->multicast_lock and RCU |
| 1004 | */ |
Herbert Xu | 0909e11 | 2010-02-27 19:41:49 +0000 | [diff] [blame] | 1005 | static void br_multicast_add_router(struct net_bridge *br, |
| 1006 | struct net_bridge_port *port) |
| 1007 | { |
stephen hemminger | dcdca2c | 2010-04-27 07:13:11 +0000 | [diff] [blame] | 1008 | struct net_bridge_port *p; |
stephen hemminger | 7e80c12 | 2010-04-27 15:01:04 +0000 | [diff] [blame] | 1009 | struct hlist_node *n, *slot = NULL; |
Herbert Xu | 0909e11 | 2010-02-27 19:41:49 +0000 | [diff] [blame] | 1010 | |
David S. Miller | 709b932 | 2010-04-27 16:49:58 -0700 | [diff] [blame] | 1011 | hlist_for_each_entry(p, n, &br->router_list, rlist) { |
stephen hemminger | 7e80c12 | 2010-04-27 15:01:04 +0000 | [diff] [blame] | 1012 | if ((unsigned long) port >= (unsigned long) p) |
| 1013 | break; |
| 1014 | slot = n; |
stephen hemminger | dcdca2c | 2010-04-27 07:13:11 +0000 | [diff] [blame] | 1015 | } |
Herbert Xu | 0909e11 | 2010-02-27 19:41:49 +0000 | [diff] [blame] | 1016 | |
stephen hemminger | 7e80c12 | 2010-04-27 15:01:04 +0000 | [diff] [blame] | 1017 | if (slot) |
| 1018 | hlist_add_after_rcu(slot, &port->rlist); |
stephen hemminger | dcdca2c | 2010-04-27 07:13:11 +0000 | [diff] [blame] | 1019 | else |
| 1020 | hlist_add_head_rcu(&port->rlist, &br->router_list); |
Herbert Xu | 0909e11 | 2010-02-27 19:41:49 +0000 | [diff] [blame] | 1021 | } |
| 1022 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1023 | static void br_multicast_mark_router(struct net_bridge *br, |
| 1024 | struct net_bridge_port *port) |
| 1025 | { |
| 1026 | unsigned long now = jiffies; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1027 | |
| 1028 | if (!port) { |
| 1029 | if (br->multicast_router == 1) |
| 1030 | mod_timer(&br->multicast_router_timer, |
| 1031 | now + br->multicast_querier_interval); |
| 1032 | return; |
| 1033 | } |
| 1034 | |
| 1035 | if (port->multicast_router != 1) |
| 1036 | return; |
| 1037 | |
| 1038 | if (!hlist_unhashed(&port->rlist)) |
| 1039 | goto timer; |
| 1040 | |
Herbert Xu | 0909e11 | 2010-02-27 19:41:49 +0000 | [diff] [blame] | 1041 | br_multicast_add_router(br, port); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1042 | |
| 1043 | timer: |
| 1044 | mod_timer(&port->multicast_router_timer, |
| 1045 | now + br->multicast_querier_interval); |
| 1046 | } |
| 1047 | |
| 1048 | static void br_multicast_query_received(struct net_bridge *br, |
| 1049 | struct net_bridge_port *port, |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 1050 | int saddr) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1051 | { |
| 1052 | if (saddr) |
| 1053 | mod_timer(&br->multicast_querier_timer, |
| 1054 | jiffies + br->multicast_querier_interval); |
| 1055 | else if (timer_pending(&br->multicast_querier_timer)) |
| 1056 | return; |
| 1057 | |
| 1058 | br_multicast_mark_router(br, port); |
| 1059 | } |
| 1060 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 1061 | static int br_ip4_multicast_query(struct net_bridge *br, |
| 1062 | struct net_bridge_port *port, |
| 1063 | struct sk_buff *skb) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1064 | { |
Eric Dumazet | b71d1d4 | 2011-04-22 04:53:02 +0000 | [diff] [blame] | 1065 | const struct iphdr *iph = ip_hdr(skb); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1066 | struct igmphdr *ih = igmp_hdr(skb); |
| 1067 | struct net_bridge_mdb_entry *mp; |
| 1068 | struct igmpv3_query *ih3; |
| 1069 | struct net_bridge_port_group *p; |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 1070 | struct net_bridge_port_group __rcu **pp; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1071 | unsigned long max_delay; |
| 1072 | unsigned long now = jiffies; |
| 1073 | __be32 group; |
YOSHIFUJI Hideaki | bec68ff | 2010-03-13 12:27:21 -0800 | [diff] [blame] | 1074 | int err = 0; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1075 | |
| 1076 | spin_lock(&br->multicast_lock); |
| 1077 | if (!netif_running(br->dev) || |
| 1078 | (port && port->state == BR_STATE_DISABLED)) |
| 1079 | goto out; |
| 1080 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 1081 | br_multicast_query_received(br, port, !!iph->saddr); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1082 | |
| 1083 | group = ih->group; |
| 1084 | |
| 1085 | if (skb->len == sizeof(*ih)) { |
| 1086 | max_delay = ih->code * (HZ / IGMP_TIMER_SCALE); |
| 1087 | |
| 1088 | if (!max_delay) { |
| 1089 | max_delay = 10 * HZ; |
| 1090 | group = 0; |
| 1091 | } |
| 1092 | } else { |
YOSHIFUJI Hideaki | bec68ff | 2010-03-13 12:27:21 -0800 | [diff] [blame] | 1093 | if (!pskb_may_pull(skb, sizeof(struct igmpv3_query))) { |
| 1094 | err = -EINVAL; |
| 1095 | goto out; |
| 1096 | } |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1097 | |
| 1098 | ih3 = igmpv3_query_hdr(skb); |
| 1099 | if (ih3->nsrcs) |
YOSHIFUJI Hideaki | bec68ff | 2010-03-13 12:27:21 -0800 | [diff] [blame] | 1100 | goto out; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1101 | |
YOSHIFUJI Hideaki / 吉藤英明 | 0ba8c9e | 2010-03-15 19:27:00 +0000 | [diff] [blame] | 1102 | max_delay = ih3->code ? |
| 1103 | IGMPV3_MRC(ih3->code) * (HZ / IGMP_TIMER_SCALE) : 1; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | if (!group) |
| 1107 | goto out; |
| 1108 | |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 1109 | mp = br_mdb_ip4_get(mlock_dereference(br->mdb, br), group); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1110 | if (!mp) |
| 1111 | goto out; |
| 1112 | |
| 1113 | max_delay *= br->multicast_last_member_count; |
| 1114 | |
Herbert Xu | 8a87017 | 2011-02-12 01:05:42 -0800 | [diff] [blame] | 1115 | if (mp->mglist && |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1116 | (timer_pending(&mp->timer) ? |
| 1117 | time_after(mp->timer.expires, now + max_delay) : |
| 1118 | try_to_del_timer_sync(&mp->timer) >= 0)) |
| 1119 | mod_timer(&mp->timer, now + max_delay); |
| 1120 | |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 1121 | for (pp = &mp->ports; |
| 1122 | (p = mlock_dereference(*pp, br)) != NULL; |
| 1123 | pp = &p->next) { |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1124 | if (timer_pending(&p->timer) ? |
| 1125 | time_after(p->timer.expires, now + max_delay) : |
| 1126 | try_to_del_timer_sync(&p->timer) >= 0) |
Herbert Xu | 24f9cdc | 2011-02-11 12:42:07 +0000 | [diff] [blame] | 1127 | mod_timer(&p->timer, now + max_delay); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | out: |
| 1131 | spin_unlock(&br->multicast_lock); |
YOSHIFUJI Hideaki | bec68ff | 2010-03-13 12:27:21 -0800 | [diff] [blame] | 1132 | return err; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1133 | } |
| 1134 | |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 1135 | #if IS_ENABLED(CONFIG_IPV6) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1136 | static int br_ip6_multicast_query(struct net_bridge *br, |
| 1137 | struct net_bridge_port *port, |
| 1138 | struct sk_buff *skb) |
| 1139 | { |
Eric Dumazet | b71d1d4 | 2011-04-22 04:53:02 +0000 | [diff] [blame] | 1140 | const struct ipv6hdr *ip6h = ipv6_hdr(skb); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1141 | struct mld_msg *mld = (struct mld_msg *) icmp6_hdr(skb); |
| 1142 | struct net_bridge_mdb_entry *mp; |
| 1143 | struct mld2_query *mld2q; |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 1144 | struct net_bridge_port_group *p; |
| 1145 | struct net_bridge_port_group __rcu **pp; |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1146 | unsigned long max_delay; |
| 1147 | unsigned long now = jiffies; |
Eric Dumazet | b71d1d4 | 2011-04-22 04:53:02 +0000 | [diff] [blame] | 1148 | const struct in6_addr *group = NULL; |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1149 | int err = 0; |
| 1150 | |
| 1151 | spin_lock(&br->multicast_lock); |
| 1152 | if (!netif_running(br->dev) || |
| 1153 | (port && port->state == BR_STATE_DISABLED)) |
| 1154 | goto out; |
| 1155 | |
| 1156 | br_multicast_query_received(br, port, !ipv6_addr_any(&ip6h->saddr)); |
| 1157 | |
| 1158 | if (skb->len == sizeof(*mld)) { |
| 1159 | if (!pskb_may_pull(skb, sizeof(*mld))) { |
| 1160 | err = -EINVAL; |
| 1161 | goto out; |
| 1162 | } |
| 1163 | mld = (struct mld_msg *) icmp6_hdr(skb); |
Li RongQing | 4715213 | 2012-07-09 23:56:12 +0000 | [diff] [blame] | 1164 | max_delay = msecs_to_jiffies(ntohs(mld->mld_maxdelay)); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1165 | if (max_delay) |
| 1166 | group = &mld->mld_mca; |
| 1167 | } else if (skb->len >= sizeof(*mld2q)) { |
| 1168 | if (!pskb_may_pull(skb, sizeof(*mld2q))) { |
| 1169 | err = -EINVAL; |
| 1170 | goto out; |
| 1171 | } |
| 1172 | mld2q = (struct mld2_query *)icmp6_hdr(skb); |
| 1173 | if (!mld2q->mld2q_nsrcs) |
| 1174 | group = &mld2q->mld2q_mca; |
| 1175 | max_delay = mld2q->mld2q_mrc ? MLDV2_MRC(mld2q->mld2q_mrc) : 1; |
| 1176 | } |
| 1177 | |
| 1178 | if (!group) |
| 1179 | goto out; |
| 1180 | |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 1181 | mp = br_mdb_ip6_get(mlock_dereference(br->mdb, br), group); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1182 | if (!mp) |
| 1183 | goto out; |
| 1184 | |
| 1185 | max_delay *= br->multicast_last_member_count; |
Herbert Xu | 8a87017 | 2011-02-12 01:05:42 -0800 | [diff] [blame] | 1186 | if (mp->mglist && |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1187 | (timer_pending(&mp->timer) ? |
| 1188 | time_after(mp->timer.expires, now + max_delay) : |
| 1189 | try_to_del_timer_sync(&mp->timer) >= 0)) |
| 1190 | mod_timer(&mp->timer, now + max_delay); |
| 1191 | |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 1192 | for (pp = &mp->ports; |
| 1193 | (p = mlock_dereference(*pp, br)) != NULL; |
| 1194 | pp = &p->next) { |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1195 | if (timer_pending(&p->timer) ? |
| 1196 | time_after(p->timer.expires, now + max_delay) : |
| 1197 | try_to_del_timer_sync(&p->timer) >= 0) |
Herbert Xu | 24f9cdc | 2011-02-11 12:42:07 +0000 | [diff] [blame] | 1198 | mod_timer(&p->timer, now + max_delay); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | out: |
| 1202 | spin_unlock(&br->multicast_lock); |
| 1203 | return err; |
| 1204 | } |
| 1205 | #endif |
| 1206 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1207 | static void br_multicast_leave_group(struct net_bridge *br, |
| 1208 | struct net_bridge_port *port, |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 1209 | struct br_ip *group) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1210 | { |
| 1211 | struct net_bridge_mdb_htable *mdb; |
| 1212 | struct net_bridge_mdb_entry *mp; |
| 1213 | struct net_bridge_port_group *p; |
| 1214 | unsigned long now; |
| 1215 | unsigned long time; |
| 1216 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1217 | spin_lock(&br->multicast_lock); |
| 1218 | if (!netif_running(br->dev) || |
| 1219 | (port && port->state == BR_STATE_DISABLED) || |
| 1220 | timer_pending(&br->multicast_querier_timer)) |
| 1221 | goto out; |
| 1222 | |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 1223 | mdb = mlock_dereference(br->mdb, br); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1224 | mp = br_mdb_ip_get(mdb, group); |
| 1225 | if (!mp) |
| 1226 | goto out; |
| 1227 | |
David S. Miller | c2d3bab | 2012-12-05 16:24:45 -0500 | [diff] [blame^] | 1228 | if (port && (port->flags & BR_MULTICAST_FAST_LEAVE)) { |
Amerigo Wang | 50426b5 | 2012-12-03 23:56:40 +0000 | [diff] [blame] | 1229 | struct net_bridge_port_group __rcu **pp; |
| 1230 | |
| 1231 | for (pp = &mp->ports; |
| 1232 | (p = mlock_dereference(*pp, br)) != NULL; |
| 1233 | pp = &p->next) { |
| 1234 | if (p->port != port) |
| 1235 | continue; |
| 1236 | |
| 1237 | rcu_assign_pointer(*pp, p->next); |
| 1238 | hlist_del_init(&p->mglist); |
| 1239 | del_timer(&p->timer); |
| 1240 | call_rcu_bh(&p->rcu, br_multicast_free_pg); |
| 1241 | |
| 1242 | if (!mp->ports && !mp->mglist && |
| 1243 | netif_running(br->dev)) |
| 1244 | mod_timer(&mp->timer, jiffies); |
| 1245 | } |
| 1246 | goto out; |
| 1247 | } |
| 1248 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1249 | now = jiffies; |
| 1250 | time = now + br->multicast_last_member_count * |
| 1251 | br->multicast_last_member_interval; |
| 1252 | |
| 1253 | if (!port) { |
Herbert Xu | 8a87017 | 2011-02-12 01:05:42 -0800 | [diff] [blame] | 1254 | if (mp->mglist && |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1255 | (timer_pending(&mp->timer) ? |
| 1256 | time_after(mp->timer.expires, time) : |
| 1257 | try_to_del_timer_sync(&mp->timer) >= 0)) { |
| 1258 | mod_timer(&mp->timer, time); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | goto out; |
| 1262 | } |
| 1263 | |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 1264 | for (p = mlock_dereference(mp->ports, br); |
| 1265 | p != NULL; |
| 1266 | p = mlock_dereference(p->next, br)) { |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1267 | if (p->port != port) |
| 1268 | continue; |
| 1269 | |
| 1270 | if (!hlist_unhashed(&p->mglist) && |
| 1271 | (timer_pending(&p->timer) ? |
| 1272 | time_after(p->timer.expires, time) : |
| 1273 | try_to_del_timer_sync(&p->timer) >= 0)) { |
| 1274 | mod_timer(&p->timer, time); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1275 | } |
| 1276 | |
| 1277 | break; |
| 1278 | } |
| 1279 | |
| 1280 | out: |
| 1281 | spin_unlock(&br->multicast_lock); |
| 1282 | } |
| 1283 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 1284 | static void br_ip4_multicast_leave_group(struct net_bridge *br, |
| 1285 | struct net_bridge_port *port, |
| 1286 | __be32 group) |
| 1287 | { |
| 1288 | struct br_ip br_group; |
| 1289 | |
| 1290 | if (ipv4_is_local_multicast(group)) |
| 1291 | return; |
| 1292 | |
| 1293 | br_group.u.ip4 = group; |
| 1294 | br_group.proto = htons(ETH_P_IP); |
| 1295 | |
| 1296 | br_multicast_leave_group(br, port, &br_group); |
| 1297 | } |
| 1298 | |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 1299 | #if IS_ENABLED(CONFIG_IPV6) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1300 | static void br_ip6_multicast_leave_group(struct net_bridge *br, |
| 1301 | struct net_bridge_port *port, |
| 1302 | const struct in6_addr *group) |
| 1303 | { |
| 1304 | struct br_ip br_group; |
| 1305 | |
Linus Lüssing | e4de9f9 | 2011-02-15 13:19:21 +0000 | [diff] [blame] | 1306 | if (!ipv6_is_transient_multicast(group)) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1307 | return; |
| 1308 | |
Alexey Dobriyan | 4e3fd7a | 2011-11-21 03:39:03 +0000 | [diff] [blame] | 1309 | br_group.u.ip6 = *group; |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1310 | br_group.proto = htons(ETH_P_IPV6); |
| 1311 | |
| 1312 | br_multicast_leave_group(br, port, &br_group); |
| 1313 | } |
| 1314 | #endif |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 1315 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1316 | static int br_multicast_ipv4_rcv(struct net_bridge *br, |
| 1317 | struct net_bridge_port *port, |
| 1318 | struct sk_buff *skb) |
| 1319 | { |
| 1320 | struct sk_buff *skb2 = skb; |
Eric Dumazet | b71d1d4 | 2011-04-22 04:53:02 +0000 | [diff] [blame] | 1321 | const struct iphdr *iph; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1322 | struct igmphdr *ih; |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 1323 | unsigned int len; |
| 1324 | unsigned int offset; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1325 | int err; |
| 1326 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1327 | /* We treat OOM as packet loss for now. */ |
| 1328 | if (!pskb_may_pull(skb, sizeof(*iph))) |
| 1329 | return -EINVAL; |
| 1330 | |
| 1331 | iph = ip_hdr(skb); |
| 1332 | |
| 1333 | if (iph->ihl < 5 || iph->version != 4) |
| 1334 | return -EINVAL; |
| 1335 | |
| 1336 | if (!pskb_may_pull(skb, ip_hdrlen(skb))) |
| 1337 | return -EINVAL; |
| 1338 | |
| 1339 | iph = ip_hdr(skb); |
| 1340 | |
| 1341 | if (unlikely(ip_fast_csum((u8 *)iph, iph->ihl))) |
| 1342 | return -EINVAL; |
| 1343 | |
Herbert Xu | bd4265f | 2011-06-23 02:39:12 +0000 | [diff] [blame] | 1344 | if (iph->protocol != IPPROTO_IGMP) { |
| 1345 | if ((iph->daddr & IGMP_LOCAL_GROUP_MASK) != IGMP_LOCAL_GROUP) |
| 1346 | BR_INPUT_SKB_CB(skb)->mrouters_only = 1; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1347 | return 0; |
Herbert Xu | bd4265f | 2011-06-23 02:39:12 +0000 | [diff] [blame] | 1348 | } |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1349 | |
| 1350 | len = ntohs(iph->tot_len); |
| 1351 | if (skb->len < len || len < ip_hdrlen(skb)) |
| 1352 | return -EINVAL; |
| 1353 | |
| 1354 | if (skb->len > len) { |
| 1355 | skb2 = skb_clone(skb, GFP_ATOMIC); |
| 1356 | if (!skb2) |
| 1357 | return -ENOMEM; |
| 1358 | |
| 1359 | err = pskb_trim_rcsum(skb2, len); |
| 1360 | if (err) |
YOSHIFUJI Hideaki / 吉藤英明 | 8440853 | 2010-03-15 19:26:56 +0000 | [diff] [blame] | 1361 | goto err_out; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | len -= ip_hdrlen(skb2); |
| 1365 | offset = skb_network_offset(skb2) + ip_hdrlen(skb2); |
| 1366 | __skb_pull(skb2, offset); |
| 1367 | skb_reset_transport_header(skb2); |
| 1368 | |
| 1369 | err = -EINVAL; |
| 1370 | if (!pskb_may_pull(skb2, sizeof(*ih))) |
| 1371 | goto out; |
| 1372 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1373 | switch (skb2->ip_summed) { |
| 1374 | case CHECKSUM_COMPLETE: |
| 1375 | if (!csum_fold(skb2->csum)) |
| 1376 | break; |
| 1377 | /* fall through */ |
| 1378 | case CHECKSUM_NONE: |
| 1379 | skb2->csum = 0; |
| 1380 | if (skb_checksum_complete(skb2)) |
YOSHIFUJI Hideaki / 吉藤英明 | 8440853 | 2010-03-15 19:26:56 +0000 | [diff] [blame] | 1381 | goto out; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1382 | } |
| 1383 | |
| 1384 | err = 0; |
| 1385 | |
| 1386 | BR_INPUT_SKB_CB(skb)->igmp = 1; |
| 1387 | ih = igmp_hdr(skb2); |
| 1388 | |
| 1389 | switch (ih->type) { |
| 1390 | case IGMP_HOST_MEMBERSHIP_REPORT: |
| 1391 | case IGMPV2_HOST_MEMBERSHIP_REPORT: |
Fernando Luis Vázquez Cao | 62b2bcb | 2011-06-13 15:04:43 +0000 | [diff] [blame] | 1392 | BR_INPUT_SKB_CB(skb)->mrouters_only = 1; |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 1393 | err = br_ip4_multicast_add_group(br, port, ih->group); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1394 | break; |
| 1395 | case IGMPV3_HOST_MEMBERSHIP_REPORT: |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 1396 | err = br_ip4_multicast_igmp3_report(br, port, skb2); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1397 | break; |
| 1398 | case IGMP_HOST_MEMBERSHIP_QUERY: |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 1399 | err = br_ip4_multicast_query(br, port, skb2); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1400 | break; |
| 1401 | case IGMP_HOST_LEAVE_MESSAGE: |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 1402 | br_ip4_multicast_leave_group(br, port, ih->group); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1403 | break; |
| 1404 | } |
| 1405 | |
| 1406 | out: |
| 1407 | __skb_push(skb2, offset); |
YOSHIFUJI Hideaki / 吉藤英明 | 8440853 | 2010-03-15 19:26:56 +0000 | [diff] [blame] | 1408 | err_out: |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1409 | if (skb2 != skb) |
| 1410 | kfree_skb(skb2); |
| 1411 | return err; |
| 1412 | } |
| 1413 | |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 1414 | #if IS_ENABLED(CONFIG_IPV6) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1415 | static int br_multicast_ipv6_rcv(struct net_bridge *br, |
| 1416 | struct net_bridge_port *port, |
| 1417 | struct sk_buff *skb) |
| 1418 | { |
Tomas Winkler | 9d89081 | 2011-01-03 11:26:08 -0800 | [diff] [blame] | 1419 | struct sk_buff *skb2; |
Eric Dumazet | b71d1d4 | 2011-04-22 04:53:02 +0000 | [diff] [blame] | 1420 | const struct ipv6hdr *ip6h; |
Eric Dumazet | 22df133 | 2011-08-23 19:57:05 +0000 | [diff] [blame] | 1421 | u8 icmp6_type; |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1422 | u8 nexthdr; |
Jesse Gross | 75f2811 | 2011-11-30 17:05:51 -0800 | [diff] [blame] | 1423 | __be16 frag_off; |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 1424 | unsigned int len; |
Kulikov Vasiliy | bb7a0bd | 2010-07-15 08:47:33 +0000 | [diff] [blame] | 1425 | int offset; |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1426 | int err; |
| 1427 | |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1428 | if (!pskb_may_pull(skb, sizeof(*ip6h))) |
| 1429 | return -EINVAL; |
| 1430 | |
| 1431 | ip6h = ipv6_hdr(skb); |
| 1432 | |
| 1433 | /* |
| 1434 | * We're interested in MLD messages only. |
| 1435 | * - Version is 6 |
| 1436 | * - MLD has always Router Alert hop-by-hop option |
| 1437 | * - But we do not support jumbrograms. |
| 1438 | */ |
| 1439 | if (ip6h->version != 6 || |
| 1440 | ip6h->nexthdr != IPPROTO_HOPOPTS || |
| 1441 | ip6h->payload_len == 0) |
| 1442 | return 0; |
| 1443 | |
Linus Lüssing | ff9a57a | 2011-03-26 20:27:24 +0000 | [diff] [blame] | 1444 | len = ntohs(ip6h->payload_len) + sizeof(*ip6h); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1445 | if (skb->len < len) |
| 1446 | return -EINVAL; |
| 1447 | |
| 1448 | nexthdr = ip6h->nexthdr; |
Jesse Gross | 75f2811 | 2011-11-30 17:05:51 -0800 | [diff] [blame] | 1449 | offset = ipv6_skip_exthdr(skb, sizeof(*ip6h), &nexthdr, &frag_off); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1450 | |
| 1451 | if (offset < 0 || nexthdr != IPPROTO_ICMPV6) |
| 1452 | return 0; |
| 1453 | |
| 1454 | /* Okay, we found ICMPv6 header */ |
| 1455 | skb2 = skb_clone(skb, GFP_ATOMIC); |
| 1456 | if (!skb2) |
| 1457 | return -ENOMEM; |
| 1458 | |
Tomas Winkler | 9d89081 | 2011-01-03 11:26:08 -0800 | [diff] [blame] | 1459 | err = -EINVAL; |
| 1460 | if (!pskb_may_pull(skb2, offset + sizeof(struct icmp6hdr))) |
| 1461 | goto out; |
| 1462 | |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1463 | len -= offset - skb_network_offset(skb2); |
| 1464 | |
| 1465 | __skb_pull(skb2, offset); |
| 1466 | skb_reset_transport_header(skb2); |
stephen hemminger | fa2da8c | 2011-11-15 08:09:14 +0000 | [diff] [blame] | 1467 | skb_postpull_rcsum(skb2, skb_network_header(skb2), |
| 1468 | skb_network_header_len(skb2)); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1469 | |
Eric Dumazet | 22df133 | 2011-08-23 19:57:05 +0000 | [diff] [blame] | 1470 | icmp6_type = icmp6_hdr(skb2)->icmp6_type; |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1471 | |
Eric Dumazet | 22df133 | 2011-08-23 19:57:05 +0000 | [diff] [blame] | 1472 | switch (icmp6_type) { |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1473 | case ICMPV6_MGM_QUERY: |
| 1474 | case ICMPV6_MGM_REPORT: |
| 1475 | case ICMPV6_MGM_REDUCTION: |
| 1476 | case ICMPV6_MLD2_REPORT: |
| 1477 | break; |
| 1478 | default: |
| 1479 | err = 0; |
| 1480 | goto out; |
| 1481 | } |
| 1482 | |
| 1483 | /* Okay, we found MLD message. Check further. */ |
| 1484 | if (skb2->len > len) { |
| 1485 | err = pskb_trim_rcsum(skb2, len); |
| 1486 | if (err) |
| 1487 | goto out; |
Yan, Zheng | 4b275d7 | 2011-08-23 22:54:33 +0000 | [diff] [blame] | 1488 | err = -EINVAL; |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1489 | } |
| 1490 | |
Yan, Zheng | 4b275d7 | 2011-08-23 22:54:33 +0000 | [diff] [blame] | 1491 | ip6h = ipv6_hdr(skb2); |
| 1492 | |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1493 | switch (skb2->ip_summed) { |
| 1494 | case CHECKSUM_COMPLETE: |
Yan, Zheng | 4b275d7 | 2011-08-23 22:54:33 +0000 | [diff] [blame] | 1495 | if (!csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr, skb2->len, |
| 1496 | IPPROTO_ICMPV6, skb2->csum)) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1497 | break; |
| 1498 | /*FALLTHROUGH*/ |
| 1499 | case CHECKSUM_NONE: |
Yan, Zheng | 4b275d7 | 2011-08-23 22:54:33 +0000 | [diff] [blame] | 1500 | skb2->csum = ~csum_unfold(csum_ipv6_magic(&ip6h->saddr, |
| 1501 | &ip6h->daddr, |
| 1502 | skb2->len, |
| 1503 | IPPROTO_ICMPV6, 0)); |
| 1504 | if (__skb_checksum_complete(skb2)) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1505 | goto out; |
| 1506 | } |
| 1507 | |
| 1508 | err = 0; |
| 1509 | |
| 1510 | BR_INPUT_SKB_CB(skb)->igmp = 1; |
| 1511 | |
Eric Dumazet | 22df133 | 2011-08-23 19:57:05 +0000 | [diff] [blame] | 1512 | switch (icmp6_type) { |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1513 | case ICMPV6_MGM_REPORT: |
| 1514 | { |
Tomas Winkler | 9d89081 | 2011-01-03 11:26:08 -0800 | [diff] [blame] | 1515 | struct mld_msg *mld; |
| 1516 | if (!pskb_may_pull(skb2, sizeof(*mld))) { |
| 1517 | err = -EINVAL; |
| 1518 | goto out; |
| 1519 | } |
| 1520 | mld = (struct mld_msg *)skb_transport_header(skb2); |
Fernando Luis Vázquez Cao | fc2af6c | 2011-06-13 15:06:58 +0000 | [diff] [blame] | 1521 | BR_INPUT_SKB_CB(skb)->mrouters_only = 1; |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1522 | err = br_ip6_multicast_add_group(br, port, &mld->mld_mca); |
| 1523 | break; |
| 1524 | } |
| 1525 | case ICMPV6_MLD2_REPORT: |
| 1526 | err = br_ip6_multicast_mld2_report(br, port, skb2); |
| 1527 | break; |
| 1528 | case ICMPV6_MGM_QUERY: |
| 1529 | err = br_ip6_multicast_query(br, port, skb2); |
| 1530 | break; |
| 1531 | case ICMPV6_MGM_REDUCTION: |
| 1532 | { |
Tomas Winkler | 9d89081 | 2011-01-03 11:26:08 -0800 | [diff] [blame] | 1533 | struct mld_msg *mld; |
| 1534 | if (!pskb_may_pull(skb2, sizeof(*mld))) { |
| 1535 | err = -EINVAL; |
| 1536 | goto out; |
| 1537 | } |
| 1538 | mld = (struct mld_msg *)skb_transport_header(skb2); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1539 | br_ip6_multicast_leave_group(br, port, &mld->mld_mca); |
| 1540 | } |
| 1541 | } |
| 1542 | |
| 1543 | out: |
Tomas Winkler | 9d89081 | 2011-01-03 11:26:08 -0800 | [diff] [blame] | 1544 | kfree_skb(skb2); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1545 | return err; |
| 1546 | } |
| 1547 | #endif |
| 1548 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1549 | int br_multicast_rcv(struct net_bridge *br, struct net_bridge_port *port, |
| 1550 | struct sk_buff *skb) |
| 1551 | { |
YOSHIFUJI Hideaki / 吉藤英明 | 1fafc7a | 2010-04-25 08:06:40 +0000 | [diff] [blame] | 1552 | BR_INPUT_SKB_CB(skb)->igmp = 0; |
| 1553 | BR_INPUT_SKB_CB(skb)->mrouters_only = 0; |
| 1554 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1555 | if (br->multicast_disabled) |
| 1556 | return 0; |
| 1557 | |
| 1558 | switch (skb->protocol) { |
| 1559 | case htons(ETH_P_IP): |
| 1560 | return br_multicast_ipv4_rcv(br, port, skb); |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 1561 | #if IS_ENABLED(CONFIG_IPV6) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1562 | case htons(ETH_P_IPV6): |
| 1563 | return br_multicast_ipv6_rcv(br, port, skb); |
| 1564 | #endif |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1565 | } |
| 1566 | |
| 1567 | return 0; |
| 1568 | } |
| 1569 | |
| 1570 | static void br_multicast_query_expired(unsigned long data) |
| 1571 | { |
| 1572 | struct net_bridge *br = (void *)data; |
| 1573 | |
| 1574 | spin_lock(&br->multicast_lock); |
| 1575 | if (br->multicast_startup_queries_sent < |
| 1576 | br->multicast_startup_query_count) |
| 1577 | br->multicast_startup_queries_sent++; |
| 1578 | |
| 1579 | br_multicast_send_query(br, NULL, br->multicast_startup_queries_sent); |
| 1580 | |
| 1581 | spin_unlock(&br->multicast_lock); |
| 1582 | } |
| 1583 | |
| 1584 | void br_multicast_init(struct net_bridge *br) |
| 1585 | { |
| 1586 | br->hash_elasticity = 4; |
| 1587 | br->hash_max = 512; |
| 1588 | |
| 1589 | br->multicast_router = 1; |
Herbert Xu | c5c2326 | 2012-04-13 02:37:42 +0000 | [diff] [blame] | 1590 | br->multicast_querier = 0; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1591 | br->multicast_last_member_count = 2; |
| 1592 | br->multicast_startup_query_count = 2; |
| 1593 | |
| 1594 | br->multicast_last_member_interval = HZ; |
| 1595 | br->multicast_query_response_interval = 10 * HZ; |
| 1596 | br->multicast_startup_query_interval = 125 * HZ / 4; |
| 1597 | br->multicast_query_interval = 125 * HZ; |
| 1598 | br->multicast_querier_interval = 255 * HZ; |
| 1599 | br->multicast_membership_interval = 260 * HZ; |
| 1600 | |
| 1601 | spin_lock_init(&br->multicast_lock); |
| 1602 | setup_timer(&br->multicast_router_timer, |
| 1603 | br_multicast_local_router_expired, 0); |
| 1604 | setup_timer(&br->multicast_querier_timer, |
Herbert Xu | bb63f1f | 2012-04-30 00:22:56 +0000 | [diff] [blame] | 1605 | br_multicast_querier_expired, (unsigned long)br); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1606 | setup_timer(&br->multicast_query_timer, br_multicast_query_expired, |
| 1607 | (unsigned long)br); |
| 1608 | } |
| 1609 | |
| 1610 | void br_multicast_open(struct net_bridge *br) |
| 1611 | { |
| 1612 | br->multicast_startup_queries_sent = 0; |
| 1613 | |
| 1614 | if (br->multicast_disabled) |
| 1615 | return; |
| 1616 | |
| 1617 | mod_timer(&br->multicast_query_timer, jiffies); |
| 1618 | } |
| 1619 | |
| 1620 | void br_multicast_stop(struct net_bridge *br) |
| 1621 | { |
| 1622 | struct net_bridge_mdb_htable *mdb; |
| 1623 | struct net_bridge_mdb_entry *mp; |
| 1624 | struct hlist_node *p, *n; |
| 1625 | u32 ver; |
| 1626 | int i; |
| 1627 | |
| 1628 | del_timer_sync(&br->multicast_router_timer); |
| 1629 | del_timer_sync(&br->multicast_querier_timer); |
| 1630 | del_timer_sync(&br->multicast_query_timer); |
| 1631 | |
| 1632 | spin_lock_bh(&br->multicast_lock); |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 1633 | mdb = mlock_dereference(br->mdb, br); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1634 | if (!mdb) |
| 1635 | goto out; |
| 1636 | |
| 1637 | br->mdb = NULL; |
| 1638 | |
| 1639 | ver = mdb->ver; |
| 1640 | for (i = 0; i < mdb->max; i++) { |
| 1641 | hlist_for_each_entry_safe(mp, p, n, &mdb->mhash[i], |
| 1642 | hlist[ver]) { |
| 1643 | del_timer(&mp->timer); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1644 | call_rcu_bh(&mp->rcu, br_multicast_free_group); |
| 1645 | } |
| 1646 | } |
| 1647 | |
| 1648 | if (mdb->old) { |
| 1649 | spin_unlock_bh(&br->multicast_lock); |
Herbert Xu | 10cc2b5 | 2010-03-05 21:03:35 +0000 | [diff] [blame] | 1650 | rcu_barrier_bh(); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1651 | spin_lock_bh(&br->multicast_lock); |
| 1652 | WARN_ON(mdb->old); |
| 1653 | } |
| 1654 | |
| 1655 | mdb->old = mdb; |
| 1656 | call_rcu_bh(&mdb->rcu, br_mdb_free); |
| 1657 | |
| 1658 | out: |
| 1659 | spin_unlock_bh(&br->multicast_lock); |
| 1660 | } |
Herbert Xu | 0909e11 | 2010-02-27 19:41:49 +0000 | [diff] [blame] | 1661 | |
| 1662 | int br_multicast_set_router(struct net_bridge *br, unsigned long val) |
| 1663 | { |
| 1664 | int err = -ENOENT; |
| 1665 | |
| 1666 | spin_lock_bh(&br->multicast_lock); |
| 1667 | if (!netif_running(br->dev)) |
| 1668 | goto unlock; |
| 1669 | |
| 1670 | switch (val) { |
| 1671 | case 0: |
| 1672 | case 2: |
| 1673 | del_timer(&br->multicast_router_timer); |
| 1674 | /* fall through */ |
| 1675 | case 1: |
| 1676 | br->multicast_router = val; |
| 1677 | err = 0; |
| 1678 | break; |
| 1679 | |
| 1680 | default: |
| 1681 | err = -EINVAL; |
| 1682 | break; |
| 1683 | } |
| 1684 | |
| 1685 | unlock: |
| 1686 | spin_unlock_bh(&br->multicast_lock); |
| 1687 | |
| 1688 | return err; |
| 1689 | } |
| 1690 | |
| 1691 | int br_multicast_set_port_router(struct net_bridge_port *p, unsigned long val) |
| 1692 | { |
| 1693 | struct net_bridge *br = p->br; |
| 1694 | int err = -ENOENT; |
| 1695 | |
| 1696 | spin_lock(&br->multicast_lock); |
| 1697 | if (!netif_running(br->dev) || p->state == BR_STATE_DISABLED) |
| 1698 | goto unlock; |
| 1699 | |
| 1700 | switch (val) { |
| 1701 | case 0: |
| 1702 | case 1: |
| 1703 | case 2: |
| 1704 | p->multicast_router = val; |
| 1705 | err = 0; |
| 1706 | |
| 1707 | if (val < 2 && !hlist_unhashed(&p->rlist)) |
| 1708 | hlist_del_init_rcu(&p->rlist); |
| 1709 | |
| 1710 | if (val == 1) |
| 1711 | break; |
| 1712 | |
| 1713 | del_timer(&p->multicast_router_timer); |
| 1714 | |
| 1715 | if (val == 0) |
| 1716 | break; |
| 1717 | |
| 1718 | br_multicast_add_router(br, p); |
| 1719 | break; |
| 1720 | |
| 1721 | default: |
| 1722 | err = -EINVAL; |
| 1723 | break; |
| 1724 | } |
| 1725 | |
| 1726 | unlock: |
| 1727 | spin_unlock(&br->multicast_lock); |
| 1728 | |
| 1729 | return err; |
| 1730 | } |
Herbert Xu | 561f110 | 2010-02-27 19:41:50 +0000 | [diff] [blame] | 1731 | |
Herbert Xu | 7485721 | 2012-04-13 02:37:42 +0000 | [diff] [blame] | 1732 | static void br_multicast_start_querier(struct net_bridge *br) |
Herbert Xu | 561f110 | 2010-02-27 19:41:50 +0000 | [diff] [blame] | 1733 | { |
| 1734 | struct net_bridge_port *port; |
Herbert Xu | 7485721 | 2012-04-13 02:37:42 +0000 | [diff] [blame] | 1735 | |
| 1736 | br_multicast_open(br); |
| 1737 | |
| 1738 | list_for_each_entry(port, &br->port_list, list) { |
| 1739 | if (port->state == BR_STATE_DISABLED || |
| 1740 | port->state == BR_STATE_BLOCKING) |
| 1741 | continue; |
| 1742 | |
| 1743 | __br_multicast_enable_port(port); |
| 1744 | } |
| 1745 | } |
| 1746 | |
| 1747 | int br_multicast_toggle(struct net_bridge *br, unsigned long val) |
| 1748 | { |
Herbert Xu | 3a7fda0 | 2010-07-29 00:45:30 +0000 | [diff] [blame] | 1749 | int err = 0; |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 1750 | struct net_bridge_mdb_htable *mdb; |
Herbert Xu | 561f110 | 2010-02-27 19:41:50 +0000 | [diff] [blame] | 1751 | |
Andrey Vagin | ef5e0d8 | 2011-11-10 05:48:03 +0000 | [diff] [blame] | 1752 | spin_lock_bh(&br->multicast_lock); |
Herbert Xu | 561f110 | 2010-02-27 19:41:50 +0000 | [diff] [blame] | 1753 | if (br->multicast_disabled == !val) |
| 1754 | goto unlock; |
| 1755 | |
| 1756 | br->multicast_disabled = !val; |
| 1757 | if (br->multicast_disabled) |
| 1758 | goto unlock; |
| 1759 | |
Herbert Xu | 3a7fda0 | 2010-07-29 00:45:30 +0000 | [diff] [blame] | 1760 | if (!netif_running(br->dev)) |
| 1761 | goto unlock; |
| 1762 | |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 1763 | mdb = mlock_dereference(br->mdb, br); |
| 1764 | if (mdb) { |
| 1765 | if (mdb->old) { |
Herbert Xu | 561f110 | 2010-02-27 19:41:50 +0000 | [diff] [blame] | 1766 | err = -EEXIST; |
| 1767 | rollback: |
| 1768 | br->multicast_disabled = !!val; |
| 1769 | goto unlock; |
| 1770 | } |
| 1771 | |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 1772 | err = br_mdb_rehash(&br->mdb, mdb->max, |
Herbert Xu | 561f110 | 2010-02-27 19:41:50 +0000 | [diff] [blame] | 1773 | br->hash_elasticity); |
| 1774 | if (err) |
| 1775 | goto rollback; |
| 1776 | } |
| 1777 | |
Herbert Xu | 7485721 | 2012-04-13 02:37:42 +0000 | [diff] [blame] | 1778 | br_multicast_start_querier(br); |
Herbert Xu | 561f110 | 2010-02-27 19:41:50 +0000 | [diff] [blame] | 1779 | |
| 1780 | unlock: |
Andrey Vagin | ef5e0d8 | 2011-11-10 05:48:03 +0000 | [diff] [blame] | 1781 | spin_unlock_bh(&br->multicast_lock); |
Herbert Xu | 561f110 | 2010-02-27 19:41:50 +0000 | [diff] [blame] | 1782 | |
| 1783 | return err; |
| 1784 | } |
Herbert Xu | b195167 | 2010-02-27 19:41:51 +0000 | [diff] [blame] | 1785 | |
Herbert Xu | c5c2326 | 2012-04-13 02:37:42 +0000 | [diff] [blame] | 1786 | int br_multicast_set_querier(struct net_bridge *br, unsigned long val) |
| 1787 | { |
| 1788 | val = !!val; |
| 1789 | |
| 1790 | spin_lock_bh(&br->multicast_lock); |
| 1791 | if (br->multicast_querier == val) |
| 1792 | goto unlock; |
| 1793 | |
| 1794 | br->multicast_querier = val; |
| 1795 | if (val) |
| 1796 | br_multicast_start_querier(br); |
| 1797 | |
| 1798 | unlock: |
| 1799 | spin_unlock_bh(&br->multicast_lock); |
| 1800 | |
| 1801 | return 0; |
| 1802 | } |
| 1803 | |
Herbert Xu | b195167 | 2010-02-27 19:41:51 +0000 | [diff] [blame] | 1804 | int br_multicast_set_hash_max(struct net_bridge *br, unsigned long val) |
| 1805 | { |
| 1806 | int err = -ENOENT; |
| 1807 | u32 old; |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 1808 | struct net_bridge_mdb_htable *mdb; |
Herbert Xu | b195167 | 2010-02-27 19:41:51 +0000 | [diff] [blame] | 1809 | |
| 1810 | spin_lock(&br->multicast_lock); |
| 1811 | if (!netif_running(br->dev)) |
| 1812 | goto unlock; |
| 1813 | |
| 1814 | err = -EINVAL; |
| 1815 | if (!is_power_of_2(val)) |
| 1816 | goto unlock; |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 1817 | |
| 1818 | mdb = mlock_dereference(br->mdb, br); |
| 1819 | if (mdb && val < mdb->size) |
Herbert Xu | b195167 | 2010-02-27 19:41:51 +0000 | [diff] [blame] | 1820 | goto unlock; |
| 1821 | |
| 1822 | err = 0; |
| 1823 | |
| 1824 | old = br->hash_max; |
| 1825 | br->hash_max = val; |
| 1826 | |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 1827 | if (mdb) { |
| 1828 | if (mdb->old) { |
Herbert Xu | b195167 | 2010-02-27 19:41:51 +0000 | [diff] [blame] | 1829 | err = -EEXIST; |
| 1830 | rollback: |
| 1831 | br->hash_max = old; |
| 1832 | goto unlock; |
| 1833 | } |
| 1834 | |
| 1835 | err = br_mdb_rehash(&br->mdb, br->hash_max, |
| 1836 | br->hash_elasticity); |
| 1837 | if (err) |
| 1838 | goto rollback; |
| 1839 | } |
| 1840 | |
| 1841 | unlock: |
| 1842 | spin_unlock(&br->multicast_lock); |
| 1843 | |
| 1844 | return err; |
| 1845 | } |