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> |
Linus Lüssing | 07f8ac4 | 2014-06-07 18:26:28 +0200 | [diff] [blame] | 14 | #include <linux/export.h> |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 15 | #include <linux/if_ether.h> |
| 16 | #include <linux/igmp.h> |
| 17 | #include <linux/jhash.h> |
| 18 | #include <linux/kernel.h> |
Herbert Xu | b195167 | 2010-02-27 19:41:51 +0000 | [diff] [blame] | 19 | #include <linux/log2.h> |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 20 | #include <linux/netdevice.h> |
| 21 | #include <linux/netfilter_bridge.h> |
| 22 | #include <linux/random.h> |
| 23 | #include <linux/rculist.h> |
| 24 | #include <linux/skbuff.h> |
| 25 | #include <linux/slab.h> |
| 26 | #include <linux/timer.h> |
Cong Wang | 1c8ad5b | 2013-05-21 21:52:54 +0000 | [diff] [blame] | 27 | #include <linux/inetdevice.h> |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 28 | #include <net/ip.h> |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 29 | #if IS_ENABLED(CONFIG_IPV6) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 30 | #include <net/ipv6.h> |
| 31 | #include <net/mld.h> |
David S. Miller | d4c4f07 | 2010-04-27 10:16:54 -0700 | [diff] [blame] | 32 | #include <net/ip6_checksum.h> |
Linus Lüssing | 3c3769e | 2013-09-04 02:13:39 +0200 | [diff] [blame] | 33 | #include <net/addrconf.h> |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 34 | #endif |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 35 | |
| 36 | #include "br_private.h" |
| 37 | |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 38 | static void br_multicast_start_querier(struct net_bridge *br, |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 39 | struct bridge_mcast_own_query *query); |
Satish Ashok | 754bc54 | 2015-06-19 01:22:57 -0700 | [diff] [blame] | 40 | static void br_multicast_add_router(struct net_bridge *br, |
| 41 | struct net_bridge_port *port); |
Satish Ashok | bc8c20a | 2015-07-13 05:28:37 -0700 | [diff] [blame] | 42 | static void br_ip4_multicast_leave_group(struct net_bridge *br, |
| 43 | struct net_bridge_port *port, |
| 44 | __be32 group, |
| 45 | __u16 vid); |
| 46 | #if IS_ENABLED(CONFIG_IPV6) |
| 47 | static void br_ip6_multicast_leave_group(struct net_bridge *br, |
| 48 | struct net_bridge_port *port, |
| 49 | const struct in6_addr *group, |
| 50 | __u16 vid); |
| 51 | #endif |
Cong Wang | 2ce297f | 2012-12-10 02:15:35 +0000 | [diff] [blame] | 52 | unsigned int br_mdb_rehash_seq; |
Herbert Xu | c83b8fa | 2012-04-13 02:37:42 +0000 | [diff] [blame] | 53 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 54 | static inline int br_ip_equal(const struct br_ip *a, const struct br_ip *b) |
| 55 | { |
| 56 | if (a->proto != b->proto) |
| 57 | return 0; |
Vlad Yasevich | b0e9a30 | 2013-02-13 12:00:17 +0000 | [diff] [blame] | 58 | if (a->vid != b->vid) |
| 59 | return 0; |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 60 | switch (a->proto) { |
| 61 | case htons(ETH_P_IP): |
| 62 | return a->u.ip4 == b->u.ip4; |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 63 | #if IS_ENABLED(CONFIG_IPV6) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 64 | case htons(ETH_P_IPV6): |
| 65 | return ipv6_addr_equal(&a->u.ip6, &b->u.ip6); |
| 66 | #endif |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 67 | } |
| 68 | return 0; |
| 69 | } |
| 70 | |
Vlad Yasevich | b0e9a30 | 2013-02-13 12:00:17 +0000 | [diff] [blame] | 71 | static inline int __br_ip4_hash(struct net_bridge_mdb_htable *mdb, __be32 ip, |
| 72 | __u16 vid) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 73 | { |
Vlad Yasevich | b0e9a30 | 2013-02-13 12:00:17 +0000 | [diff] [blame] | 74 | return jhash_2words((__force u32)ip, vid, mdb->secret) & (mdb->max - 1); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 77 | #if IS_ENABLED(CONFIG_IPV6) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 78 | static inline int __br_ip6_hash(struct net_bridge_mdb_htable *mdb, |
Vlad Yasevich | b0e9a30 | 2013-02-13 12:00:17 +0000 | [diff] [blame] | 79 | const struct in6_addr *ip, |
| 80 | __u16 vid) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 81 | { |
Vlad Yasevich | b0e9a30 | 2013-02-13 12:00:17 +0000 | [diff] [blame] | 82 | return jhash_2words(ipv6_addr_hash(ip), vid, |
| 83 | mdb->secret) & (mdb->max - 1); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 84 | } |
| 85 | #endif |
| 86 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 87 | static inline int br_ip_hash(struct net_bridge_mdb_htable *mdb, |
| 88 | struct br_ip *ip) |
| 89 | { |
| 90 | switch (ip->proto) { |
| 91 | case htons(ETH_P_IP): |
Vlad Yasevich | b0e9a30 | 2013-02-13 12:00:17 +0000 | [diff] [blame] | 92 | return __br_ip4_hash(mdb, ip->u.ip4, ip->vid); |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 93 | #if IS_ENABLED(CONFIG_IPV6) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 94 | case htons(ETH_P_IPV6): |
Vlad Yasevich | b0e9a30 | 2013-02-13 12:00:17 +0000 | [diff] [blame] | 95 | return __br_ip6_hash(mdb, &ip->u.ip6, ip->vid); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 96 | #endif |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 97 | } |
| 98 | return 0; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | static struct net_bridge_mdb_entry *__br_mdb_ip_get( |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 102 | struct net_bridge_mdb_htable *mdb, struct br_ip *dst, int hash) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 103 | { |
| 104 | struct net_bridge_mdb_entry *mp; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 105 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 106 | hlist_for_each_entry_rcu(mp, &mdb->mhash[hash], hlist[mdb->ver]) { |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 107 | if (br_ip_equal(&mp->addr, dst)) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 108 | return mp; |
| 109 | } |
| 110 | |
| 111 | return NULL; |
| 112 | } |
| 113 | |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 114 | struct net_bridge_mdb_entry *br_mdb_ip_get(struct net_bridge_mdb_htable *mdb, |
| 115 | struct br_ip *dst) |
Herbert Xu | 7f285fa | 2010-07-05 14:50:08 +0000 | [diff] [blame] | 116 | { |
| 117 | if (!mdb) |
| 118 | return NULL; |
| 119 | |
| 120 | return __br_mdb_ip_get(mdb, dst, br_ip_hash(mdb, dst)); |
| 121 | } |
| 122 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 123 | static struct net_bridge_mdb_entry *br_mdb_ip4_get( |
Vlad Yasevich | b0e9a30 | 2013-02-13 12:00:17 +0000 | [diff] [blame] | 124 | struct net_bridge_mdb_htable *mdb, __be32 dst, __u16 vid) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 125 | { |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 126 | struct br_ip br_dst; |
Herbert Xu | 0821ec5 | 2010-03-15 20:38:25 -0700 | [diff] [blame] | 127 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 128 | br_dst.u.ip4 = dst; |
| 129 | br_dst.proto = htons(ETH_P_IP); |
Vlad Yasevich | b0e9a30 | 2013-02-13 12:00:17 +0000 | [diff] [blame] | 130 | br_dst.vid = vid; |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 131 | |
Herbert Xu | 7f285fa | 2010-07-05 14:50:08 +0000 | [diff] [blame] | 132 | return br_mdb_ip_get(mdb, &br_dst); |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 133 | } |
| 134 | |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 135 | #if IS_ENABLED(CONFIG_IPV6) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 136 | static struct net_bridge_mdb_entry *br_mdb_ip6_get( |
Vlad Yasevich | b0e9a30 | 2013-02-13 12:00:17 +0000 | [diff] [blame] | 137 | struct net_bridge_mdb_htable *mdb, const struct in6_addr *dst, |
| 138 | __u16 vid) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 139 | { |
| 140 | struct br_ip br_dst; |
| 141 | |
Alexey Dobriyan | 4e3fd7a | 2011-11-21 03:39:03 +0000 | [diff] [blame] | 142 | br_dst.u.ip6 = *dst; |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 143 | br_dst.proto = htons(ETH_P_IPV6); |
Vlad Yasevich | b0e9a30 | 2013-02-13 12:00:17 +0000 | [diff] [blame] | 144 | br_dst.vid = vid; |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 145 | |
Herbert Xu | 7f285fa | 2010-07-05 14:50:08 +0000 | [diff] [blame] | 146 | return br_mdb_ip_get(mdb, &br_dst); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 147 | } |
| 148 | #endif |
| 149 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 150 | struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br, |
Cong Wang | fbca58a | 2013-03-07 03:05:33 +0000 | [diff] [blame] | 151 | struct sk_buff *skb, u16 vid) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 152 | { |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 153 | struct net_bridge_mdb_htable *mdb = rcu_dereference(br->mdb); |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 154 | struct br_ip ip; |
| 155 | |
Herbert Xu | 7f285fa | 2010-07-05 14:50:08 +0000 | [diff] [blame] | 156 | if (br->multicast_disabled) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 157 | return NULL; |
| 158 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 159 | if (BR_INPUT_SKB_CB(skb)->igmp) |
| 160 | return NULL; |
| 161 | |
| 162 | ip.proto = skb->protocol; |
Cong Wang | fbca58a | 2013-03-07 03:05:33 +0000 | [diff] [blame] | 163 | ip.vid = vid; |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 164 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 165 | switch (skb->protocol) { |
| 166 | case htons(ETH_P_IP): |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 167 | ip.u.ip4 = ip_hdr(skb)->daddr; |
| 168 | break; |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 169 | #if IS_ENABLED(CONFIG_IPV6) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 170 | case htons(ETH_P_IPV6): |
Alexey Dobriyan | 4e3fd7a | 2011-11-21 03:39:03 +0000 | [diff] [blame] | 171 | ip.u.ip6 = ipv6_hdr(skb)->daddr; |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 172 | break; |
| 173 | #endif |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 174 | default: |
| 175 | return NULL; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 176 | } |
| 177 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 178 | return br_mdb_ip_get(mdb, &ip); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | static void br_mdb_free(struct rcu_head *head) |
| 182 | { |
| 183 | struct net_bridge_mdb_htable *mdb = |
| 184 | container_of(head, struct net_bridge_mdb_htable, rcu); |
| 185 | struct net_bridge_mdb_htable *old = mdb->old; |
| 186 | |
| 187 | mdb->old = NULL; |
| 188 | kfree(old->mhash); |
| 189 | kfree(old); |
| 190 | } |
| 191 | |
| 192 | static int br_mdb_copy(struct net_bridge_mdb_htable *new, |
| 193 | struct net_bridge_mdb_htable *old, |
| 194 | int elasticity) |
| 195 | { |
| 196 | struct net_bridge_mdb_entry *mp; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 197 | int maxlen; |
| 198 | int len; |
| 199 | int i; |
| 200 | |
| 201 | for (i = 0; i < old->max; i++) |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 202 | hlist_for_each_entry(mp, &old->mhash[i], hlist[old->ver]) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 203 | hlist_add_head(&mp->hlist[new->ver], |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 204 | &new->mhash[br_ip_hash(new, &mp->addr)]); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 205 | |
| 206 | if (!elasticity) |
| 207 | return 0; |
| 208 | |
| 209 | maxlen = 0; |
| 210 | for (i = 0; i < new->max; i++) { |
| 211 | len = 0; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 212 | hlist_for_each_entry(mp, &new->mhash[i], hlist[new->ver]) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 213 | len++; |
| 214 | if (len > maxlen) |
| 215 | maxlen = len; |
| 216 | } |
| 217 | |
| 218 | return maxlen > elasticity ? -EINVAL : 0; |
| 219 | } |
| 220 | |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 221 | void br_multicast_free_pg(struct rcu_head *head) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 222 | { |
| 223 | struct net_bridge_port_group *p = |
| 224 | container_of(head, struct net_bridge_port_group, rcu); |
| 225 | |
| 226 | kfree(p); |
| 227 | } |
| 228 | |
| 229 | static void br_multicast_free_group(struct rcu_head *head) |
| 230 | { |
| 231 | struct net_bridge_mdb_entry *mp = |
| 232 | container_of(head, struct net_bridge_mdb_entry, rcu); |
| 233 | |
| 234 | kfree(mp); |
| 235 | } |
| 236 | |
| 237 | static void br_multicast_group_expired(unsigned long data) |
| 238 | { |
| 239 | struct net_bridge_mdb_entry *mp = (void *)data; |
| 240 | struct net_bridge *br = mp->br; |
| 241 | struct net_bridge_mdb_htable *mdb; |
| 242 | |
| 243 | spin_lock(&br->multicast_lock); |
| 244 | if (!netif_running(br->dev) || timer_pending(&mp->timer)) |
| 245 | goto out; |
| 246 | |
Herbert Xu | 8a87017 | 2011-02-12 01:05:42 -0800 | [diff] [blame] | 247 | mp->mglist = false; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 248 | |
| 249 | if (mp->ports) |
| 250 | goto out; |
| 251 | |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 252 | mdb = mlock_dereference(br->mdb, br); |
| 253 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 254 | hlist_del_rcu(&mp->hlist[mdb->ver]); |
| 255 | mdb->size--; |
| 256 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 257 | call_rcu_bh(&mp->rcu, br_multicast_free_group); |
| 258 | |
| 259 | out: |
| 260 | spin_unlock(&br->multicast_lock); |
| 261 | } |
| 262 | |
| 263 | static void br_multicast_del_pg(struct net_bridge *br, |
| 264 | struct net_bridge_port_group *pg) |
| 265 | { |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 266 | struct net_bridge_mdb_htable *mdb; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 267 | struct net_bridge_mdb_entry *mp; |
| 268 | struct net_bridge_port_group *p; |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 269 | struct net_bridge_port_group __rcu **pp; |
| 270 | |
| 271 | mdb = mlock_dereference(br->mdb, br); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 272 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 273 | mp = br_mdb_ip_get(mdb, &pg->addr); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 274 | if (WARN_ON(!mp)) |
| 275 | return; |
| 276 | |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 277 | for (pp = &mp->ports; |
| 278 | (p = mlock_dereference(*pp, br)) != NULL; |
| 279 | pp = &p->next) { |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 280 | if (p != pg) |
| 281 | continue; |
| 282 | |
stephen hemminger | 83f6a74 | 2010-04-27 15:01:06 +0000 | [diff] [blame] | 283 | rcu_assign_pointer(*pp, p->next); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 284 | hlist_del_init(&p->mglist); |
| 285 | del_timer(&p->timer); |
Nikolay Aleksandrov | ef8299de | 2015-07-15 07:16:50 -0700 | [diff] [blame] | 286 | br_mdb_notify(br->dev, p->port, &pg->addr, RTM_DELMDB, |
| 287 | p->state); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 288 | call_rcu_bh(&p->rcu, br_multicast_free_pg); |
| 289 | |
Linus Lüssing | 454594f | 2013-10-20 00:58:57 +0200 | [diff] [blame] | 290 | if (!mp->ports && !mp->mglist && |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 291 | netif_running(br->dev)) |
| 292 | mod_timer(&mp->timer, jiffies); |
| 293 | |
| 294 | return; |
| 295 | } |
| 296 | |
| 297 | WARN_ON(1); |
| 298 | } |
| 299 | |
| 300 | static void br_multicast_port_group_expired(unsigned long data) |
| 301 | { |
| 302 | struct net_bridge_port_group *pg = (void *)data; |
| 303 | struct net_bridge *br = pg->port->br; |
| 304 | |
| 305 | spin_lock(&br->multicast_lock); |
| 306 | if (!netif_running(br->dev) || timer_pending(&pg->timer) || |
Amerigo Wang | ccb1c31 | 2012-12-14 22:09:51 +0000 | [diff] [blame] | 307 | hlist_unhashed(&pg->mglist) || pg->state & MDB_PERMANENT) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 308 | goto out; |
| 309 | |
| 310 | br_multicast_del_pg(br, pg); |
| 311 | |
| 312 | out: |
| 313 | spin_unlock(&br->multicast_lock); |
| 314 | } |
| 315 | |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 316 | 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] | 317 | int elasticity) |
| 318 | { |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 319 | struct net_bridge_mdb_htable *old = rcu_dereference_protected(*mdbp, 1); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 320 | struct net_bridge_mdb_htable *mdb; |
| 321 | int err; |
| 322 | |
| 323 | mdb = kmalloc(sizeof(*mdb), GFP_ATOMIC); |
| 324 | if (!mdb) |
| 325 | return -ENOMEM; |
| 326 | |
| 327 | mdb->max = max; |
| 328 | mdb->old = old; |
| 329 | |
| 330 | mdb->mhash = kzalloc(max * sizeof(*mdb->mhash), GFP_ATOMIC); |
| 331 | if (!mdb->mhash) { |
| 332 | kfree(mdb); |
| 333 | return -ENOMEM; |
| 334 | } |
| 335 | |
| 336 | mdb->size = old ? old->size : 0; |
| 337 | mdb->ver = old ? old->ver ^ 1 : 0; |
| 338 | |
| 339 | if (!old || elasticity) |
| 340 | get_random_bytes(&mdb->secret, sizeof(mdb->secret)); |
| 341 | else |
| 342 | mdb->secret = old->secret; |
| 343 | |
| 344 | if (!old) |
| 345 | goto out; |
| 346 | |
| 347 | err = br_mdb_copy(mdb, old, elasticity); |
| 348 | if (err) { |
| 349 | kfree(mdb->mhash); |
| 350 | kfree(mdb); |
| 351 | return err; |
| 352 | } |
| 353 | |
Cong Wang | 2ce297f | 2012-12-10 02:15:35 +0000 | [diff] [blame] | 354 | br_mdb_rehash_seq++; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 355 | call_rcu_bh(&mdb->rcu, br_mdb_free); |
| 356 | |
| 357 | out: |
| 358 | rcu_assign_pointer(*mdbp, mdb); |
| 359 | |
| 360 | return 0; |
| 361 | } |
| 362 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 363 | static struct sk_buff *br_ip4_multicast_alloc_query(struct net_bridge *br, |
| 364 | __be32 group) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 365 | { |
| 366 | struct sk_buff *skb; |
| 367 | struct igmphdr *ih; |
| 368 | struct ethhdr *eth; |
| 369 | struct iphdr *iph; |
| 370 | |
| 371 | skb = netdev_alloc_skb_ip_align(br->dev, sizeof(*eth) + sizeof(*iph) + |
| 372 | sizeof(*ih) + 4); |
| 373 | if (!skb) |
| 374 | goto out; |
| 375 | |
| 376 | skb->protocol = htons(ETH_P_IP); |
| 377 | |
| 378 | skb_reset_mac_header(skb); |
| 379 | eth = eth_hdr(skb); |
| 380 | |
Joe Perches | e5a727f | 2014-02-23 00:05:25 -0800 | [diff] [blame] | 381 | ether_addr_copy(eth->h_source, br->dev->dev_addr); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 382 | eth->h_dest[0] = 1; |
| 383 | eth->h_dest[1] = 0; |
| 384 | eth->h_dest[2] = 0x5e; |
| 385 | eth->h_dest[3] = 0; |
| 386 | eth->h_dest[4] = 0; |
| 387 | eth->h_dest[5] = 1; |
| 388 | eth->h_proto = htons(ETH_P_IP); |
| 389 | skb_put(skb, sizeof(*eth)); |
| 390 | |
| 391 | skb_set_network_header(skb, skb->len); |
| 392 | iph = ip_hdr(skb); |
| 393 | |
| 394 | iph->version = 4; |
| 395 | iph->ihl = 6; |
| 396 | iph->tos = 0xc0; |
| 397 | iph->tot_len = htons(sizeof(*iph) + sizeof(*ih) + 4); |
| 398 | iph->id = 0; |
| 399 | iph->frag_off = htons(IP_DF); |
| 400 | iph->ttl = 1; |
| 401 | iph->protocol = IPPROTO_IGMP; |
Cong Wang | 1c8ad5b | 2013-05-21 21:52:54 +0000 | [diff] [blame] | 402 | iph->saddr = br->multicast_query_use_ifaddr ? |
| 403 | inet_select_addr(br->dev, 0, RT_SCOPE_LINK) : 0; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 404 | iph->daddr = htonl(INADDR_ALLHOSTS_GROUP); |
| 405 | ((u8 *)&iph[1])[0] = IPOPT_RA; |
| 406 | ((u8 *)&iph[1])[1] = 4; |
| 407 | ((u8 *)&iph[1])[2] = 0; |
| 408 | ((u8 *)&iph[1])[3] = 0; |
| 409 | ip_send_check(iph); |
| 410 | skb_put(skb, 24); |
| 411 | |
| 412 | skb_set_transport_header(skb, skb->len); |
| 413 | ih = igmp_hdr(skb); |
| 414 | ih->type = IGMP_HOST_MEMBERSHIP_QUERY; |
| 415 | ih->code = (group ? br->multicast_last_member_interval : |
| 416 | br->multicast_query_response_interval) / |
| 417 | (HZ / IGMP_TIMER_SCALE); |
| 418 | ih->group = group; |
| 419 | ih->csum = 0; |
| 420 | ih->csum = ip_compute_csum((void *)ih, sizeof(struct igmphdr)); |
| 421 | skb_put(skb, sizeof(*ih)); |
| 422 | |
| 423 | __skb_pull(skb, sizeof(*eth)); |
| 424 | |
| 425 | out: |
| 426 | return skb; |
| 427 | } |
| 428 | |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 429 | #if IS_ENABLED(CONFIG_IPV6) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 430 | 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] | 431 | const struct in6_addr *group) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 432 | { |
| 433 | struct sk_buff *skb; |
| 434 | struct ipv6hdr *ip6h; |
| 435 | struct mld_msg *mldq; |
| 436 | struct ethhdr *eth; |
| 437 | u8 *hopopt; |
| 438 | unsigned long interval; |
| 439 | |
| 440 | skb = netdev_alloc_skb_ip_align(br->dev, sizeof(*eth) + sizeof(*ip6h) + |
| 441 | 8 + sizeof(*mldq)); |
| 442 | if (!skb) |
| 443 | goto out; |
| 444 | |
| 445 | skb->protocol = htons(ETH_P_IPV6); |
| 446 | |
| 447 | /* Ethernet header */ |
| 448 | skb_reset_mac_header(skb); |
| 449 | eth = eth_hdr(skb); |
| 450 | |
Joe Perches | e5a727f | 2014-02-23 00:05:25 -0800 | [diff] [blame] | 451 | ether_addr_copy(eth->h_source, br->dev->dev_addr); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 452 | eth->h_proto = htons(ETH_P_IPV6); |
| 453 | skb_put(skb, sizeof(*eth)); |
| 454 | |
| 455 | /* IPv6 header + HbH option */ |
| 456 | skb_set_network_header(skb, skb->len); |
| 457 | ip6h = ipv6_hdr(skb); |
| 458 | |
| 459 | *(__force __be32 *)ip6h = htonl(0x60000000); |
David Stevens | 76d6615 | 2010-12-14 08:42:16 +0000 | [diff] [blame] | 460 | ip6h->payload_len = htons(8 + sizeof(*mldq)); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 461 | ip6h->nexthdr = IPPROTO_HOPOPTS; |
| 462 | ip6h->hop_limit = 1; |
Linus Lüssing | a7bff75 | 2011-03-22 11:40:32 +0000 | [diff] [blame] | 463 | ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1)); |
Ulrich Weber | d1d81d4 | 2012-03-05 04:52:44 +0000 | [diff] [blame] | 464 | if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0, |
| 465 | &ip6h->saddr)) { |
| 466 | kfree_skb(skb); |
| 467 | return NULL; |
| 468 | } |
Linus Lüssing | 36cff5a | 2011-02-17 08:17:51 +0000 | [diff] [blame] | 469 | ipv6_eth_mc_map(&ip6h->daddr, eth->h_dest); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 470 | |
| 471 | hopopt = (u8 *)(ip6h + 1); |
| 472 | hopopt[0] = IPPROTO_ICMPV6; /* next hdr */ |
| 473 | hopopt[1] = 0; /* length of HbH */ |
| 474 | hopopt[2] = IPV6_TLV_ROUTERALERT; /* Router Alert */ |
| 475 | hopopt[3] = 2; /* Length of RA Option */ |
| 476 | hopopt[4] = 0; /* Type = 0x0000 (MLD) */ |
| 477 | hopopt[5] = 0; |
Eldad Zack | 1de5a71 | 2012-05-17 06:00:25 +0000 | [diff] [blame] | 478 | hopopt[6] = IPV6_TLV_PAD1; /* Pad1 */ |
| 479 | hopopt[7] = IPV6_TLV_PAD1; /* Pad1 */ |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 480 | |
| 481 | skb_put(skb, sizeof(*ip6h) + 8); |
| 482 | |
| 483 | /* ICMPv6 */ |
| 484 | skb_set_transport_header(skb, skb->len); |
| 485 | mldq = (struct mld_msg *) icmp6_hdr(skb); |
| 486 | |
Linus Lüssing | 32de868 | 2013-06-16 23:20:34 +0200 | [diff] [blame] | 487 | interval = ipv6_addr_any(group) ? |
| 488 | br->multicast_query_response_interval : |
| 489 | br->multicast_last_member_interval; |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 490 | |
| 491 | mldq->mld_type = ICMPV6_MGM_QUERY; |
| 492 | mldq->mld_code = 0; |
| 493 | mldq->mld_cksum = 0; |
| 494 | mldq->mld_maxdelay = htons((u16)jiffies_to_msecs(interval)); |
| 495 | mldq->mld_reserved = 0; |
Alexey Dobriyan | 4e3fd7a | 2011-11-21 03:39:03 +0000 | [diff] [blame] | 496 | mldq->mld_mca = *group; |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 497 | |
| 498 | /* checksum */ |
| 499 | mldq->mld_cksum = csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr, |
| 500 | sizeof(*mldq), IPPROTO_ICMPV6, |
| 501 | csum_partial(mldq, |
| 502 | sizeof(*mldq), 0)); |
| 503 | skb_put(skb, sizeof(*mldq)); |
| 504 | |
| 505 | __skb_pull(skb, sizeof(*eth)); |
| 506 | |
| 507 | out: |
| 508 | return skb; |
| 509 | } |
| 510 | #endif |
| 511 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 512 | static struct sk_buff *br_multicast_alloc_query(struct net_bridge *br, |
| 513 | struct br_ip *addr) |
| 514 | { |
| 515 | switch (addr->proto) { |
| 516 | case htons(ETH_P_IP): |
| 517 | return br_ip4_multicast_alloc_query(br, addr->u.ip4); |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 518 | #if IS_ENABLED(CONFIG_IPV6) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 519 | case htons(ETH_P_IPV6): |
| 520 | return br_ip6_multicast_alloc_query(br, &addr->u.ip6); |
| 521 | #endif |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 522 | } |
| 523 | return NULL; |
| 524 | } |
| 525 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 526 | static struct net_bridge_mdb_entry *br_multicast_get_group( |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 527 | struct net_bridge *br, struct net_bridge_port *port, |
| 528 | struct br_ip *group, int hash) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 529 | { |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 530 | struct net_bridge_mdb_htable *mdb; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 531 | struct net_bridge_mdb_entry *mp; |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 532 | unsigned int count = 0; |
| 533 | unsigned int max; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 534 | int elasticity; |
| 535 | int err; |
| 536 | |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 537 | mdb = rcu_dereference_protected(br->mdb, 1); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 538 | hlist_for_each_entry(mp, &mdb->mhash[hash], hlist[mdb->ver]) { |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 539 | count++; |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 540 | if (unlikely(br_ip_equal(group, &mp->addr))) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 541 | return mp; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | elasticity = 0; |
| 545 | max = mdb->max; |
| 546 | |
| 547 | if (unlikely(count > br->hash_elasticity && count)) { |
| 548 | if (net_ratelimit()) |
stephen hemminger | 28a16c9 | 2010-05-10 09:31:09 +0000 | [diff] [blame] | 549 | br_info(br, "Multicast hash table " |
| 550 | "chain limit reached: %s\n", |
| 551 | port ? port->dev->name : br->dev->name); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 552 | |
| 553 | elasticity = br->hash_elasticity; |
| 554 | } |
| 555 | |
| 556 | if (mdb->size >= max) { |
| 557 | max *= 2; |
Thomas Graf | 036be6d | 2012-07-10 22:29:19 +0000 | [diff] [blame] | 558 | if (unlikely(max > br->hash_max)) { |
| 559 | br_warn(br, "Multicast hash table maximum of %d " |
| 560 | "reached, disabling snooping: %s\n", |
| 561 | br->hash_max, |
| 562 | port ? port->dev->name : br->dev->name); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 563 | err = -E2BIG; |
| 564 | disable: |
| 565 | br->multicast_disabled = 1; |
| 566 | goto err; |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | if (max > mdb->max || elasticity) { |
| 571 | if (mdb->old) { |
| 572 | if (net_ratelimit()) |
stephen hemminger | 28a16c9 | 2010-05-10 09:31:09 +0000 | [diff] [blame] | 573 | br_info(br, "Multicast hash table " |
| 574 | "on fire: %s\n", |
| 575 | port ? port->dev->name : br->dev->name); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 576 | err = -EEXIST; |
| 577 | goto err; |
| 578 | } |
| 579 | |
| 580 | err = br_mdb_rehash(&br->mdb, max, elasticity); |
| 581 | if (err) { |
stephen hemminger | 28a16c9 | 2010-05-10 09:31:09 +0000 | [diff] [blame] | 582 | br_warn(br, "Cannot rehash multicast " |
| 583 | "hash table, disabling snooping: %s, %d, %d\n", |
| 584 | port ? port->dev->name : br->dev->name, |
| 585 | mdb->size, err); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 586 | goto disable; |
| 587 | } |
| 588 | |
| 589 | err = -EAGAIN; |
| 590 | goto err; |
| 591 | } |
| 592 | |
| 593 | return NULL; |
| 594 | |
| 595 | err: |
| 596 | mp = ERR_PTR(err); |
| 597 | return mp; |
| 598 | } |
| 599 | |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 600 | struct net_bridge_mdb_entry *br_multicast_new_group(struct net_bridge *br, |
| 601 | struct net_bridge_port *port, struct br_ip *group) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 602 | { |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 603 | struct net_bridge_mdb_htable *mdb; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 604 | struct net_bridge_mdb_entry *mp; |
| 605 | int hash; |
Tobias Klauser | 4c0833b | 2010-12-10 03:18:04 +0000 | [diff] [blame] | 606 | int err; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 607 | |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 608 | mdb = rcu_dereference_protected(br->mdb, 1); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 609 | if (!mdb) { |
Tobias Klauser | 4c0833b | 2010-12-10 03:18:04 +0000 | [diff] [blame] | 610 | err = br_mdb_rehash(&br->mdb, BR_HASH_SIZE, 0); |
| 611 | if (err) |
| 612 | return ERR_PTR(err); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 613 | goto rehash; |
| 614 | } |
| 615 | |
| 616 | hash = br_ip_hash(mdb, group); |
| 617 | mp = br_multicast_get_group(br, port, group, hash); |
| 618 | switch (PTR_ERR(mp)) { |
| 619 | case 0: |
| 620 | break; |
| 621 | |
| 622 | case -EAGAIN: |
| 623 | rehash: |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 624 | mdb = rcu_dereference_protected(br->mdb, 1); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 625 | hash = br_ip_hash(mdb, group); |
| 626 | break; |
| 627 | |
| 628 | default: |
| 629 | goto out; |
| 630 | } |
| 631 | |
| 632 | mp = kzalloc(sizeof(*mp), GFP_ATOMIC); |
| 633 | if (unlikely(!mp)) |
Tobias Klauser | 4c0833b | 2010-12-10 03:18:04 +0000 | [diff] [blame] | 634 | return ERR_PTR(-ENOMEM); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 635 | |
| 636 | mp->br = br; |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 637 | mp->addr = *group; |
Eric Dumazet | 1faabf2 | 2013-07-19 20:07:16 -0700 | [diff] [blame] | 638 | setup_timer(&mp->timer, br_multicast_group_expired, |
| 639 | (unsigned long)mp); |
| 640 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 641 | hlist_add_head_rcu(&mp->hlist[mdb->ver], &mdb->mhash[hash]); |
| 642 | mdb->size++; |
| 643 | |
| 644 | out: |
| 645 | return mp; |
| 646 | } |
| 647 | |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 648 | struct net_bridge_port_group *br_multicast_new_port_group( |
| 649 | struct net_bridge_port *port, |
| 650 | struct br_ip *group, |
Amerigo Wang | ccb1c31 | 2012-12-14 22:09:51 +0000 | [diff] [blame] | 651 | struct net_bridge_port_group __rcu *next, |
| 652 | unsigned char state) |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 653 | { |
| 654 | struct net_bridge_port_group *p; |
| 655 | |
| 656 | p = kzalloc(sizeof(*p), GFP_ATOMIC); |
| 657 | if (unlikely(!p)) |
| 658 | return NULL; |
| 659 | |
| 660 | p->addr = *group; |
| 661 | p->port = port; |
Amerigo Wang | ccb1c31 | 2012-12-14 22:09:51 +0000 | [diff] [blame] | 662 | p->state = state; |
stephen hemminger | eca2a43 | 2012-12-13 06:51:28 +0000 | [diff] [blame] | 663 | rcu_assign_pointer(p->next, next); |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 664 | hlist_add_head(&p->mglist, &port->mglist); |
| 665 | setup_timer(&p->timer, br_multicast_port_group_expired, |
| 666 | (unsigned long)p); |
| 667 | return p; |
| 668 | } |
| 669 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 670 | static int br_multicast_add_group(struct net_bridge *br, |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 671 | struct net_bridge_port *port, |
| 672 | struct br_ip *group) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 673 | { |
| 674 | struct net_bridge_mdb_entry *mp; |
| 675 | struct net_bridge_port_group *p; |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 676 | struct net_bridge_port_group __rcu **pp; |
Linus Lüssing | 454594f | 2013-10-20 00:58:57 +0200 | [diff] [blame] | 677 | unsigned long now = jiffies; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 678 | int err; |
| 679 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 680 | spin_lock(&br->multicast_lock); |
| 681 | if (!netif_running(br->dev) || |
| 682 | (port && port->state == BR_STATE_DISABLED)) |
| 683 | goto out; |
| 684 | |
| 685 | mp = br_multicast_new_group(br, port, group); |
| 686 | err = PTR_ERR(mp); |
Tobias Klauser | 4c0833b | 2010-12-10 03:18:04 +0000 | [diff] [blame] | 687 | if (IS_ERR(mp)) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 688 | goto err; |
| 689 | |
| 690 | if (!port) { |
Herbert Xu | 8a87017 | 2011-02-12 01:05:42 -0800 | [diff] [blame] | 691 | mp->mglist = true; |
Linus Lüssing | 454594f | 2013-10-20 00:58:57 +0200 | [diff] [blame] | 692 | mod_timer(&mp->timer, now + br->multicast_membership_interval); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 693 | goto out; |
| 694 | } |
| 695 | |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 696 | for (pp = &mp->ports; |
| 697 | (p = mlock_dereference(*pp, br)) != NULL; |
| 698 | pp = &p->next) { |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 699 | if (p->port == port) |
Linus Lüssing | 454594f | 2013-10-20 00:58:57 +0200 | [diff] [blame] | 700 | goto found; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 701 | if ((unsigned long)p->port < (unsigned long)port) |
| 702 | break; |
| 703 | } |
| 704 | |
Amerigo Wang | ccb1c31 | 2012-12-14 22:09:51 +0000 | [diff] [blame] | 705 | p = br_multicast_new_port_group(port, group, *pp, MDB_TEMPORARY); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 706 | if (unlikely(!p)) |
| 707 | goto err; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 708 | rcu_assign_pointer(*pp, p); |
Nikolay Aleksandrov | 09cf021 | 2015-07-09 03:11:10 -0700 | [diff] [blame] | 709 | br_mdb_notify(br->dev, port, group, RTM_NEWMDB, MDB_TEMPORARY); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 710 | |
Linus Lüssing | 454594f | 2013-10-20 00:58:57 +0200 | [diff] [blame] | 711 | found: |
| 712 | mod_timer(&p->timer, now + br->multicast_membership_interval); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 713 | out: |
| 714 | err = 0; |
| 715 | |
| 716 | err: |
| 717 | spin_unlock(&br->multicast_lock); |
| 718 | return err; |
| 719 | } |
| 720 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 721 | static int br_ip4_multicast_add_group(struct net_bridge *br, |
| 722 | struct net_bridge_port *port, |
Vlad Yasevich | b0e9a30 | 2013-02-13 12:00:17 +0000 | [diff] [blame] | 723 | __be32 group, |
| 724 | __u16 vid) |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 725 | { |
| 726 | struct br_ip br_group; |
| 727 | |
| 728 | if (ipv4_is_local_multicast(group)) |
| 729 | return 0; |
| 730 | |
| 731 | br_group.u.ip4 = group; |
| 732 | br_group.proto = htons(ETH_P_IP); |
Vlad Yasevich | b0e9a30 | 2013-02-13 12:00:17 +0000 | [diff] [blame] | 733 | br_group.vid = vid; |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 734 | |
| 735 | return br_multicast_add_group(br, port, &br_group); |
| 736 | } |
| 737 | |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 738 | #if IS_ENABLED(CONFIG_IPV6) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 739 | static int br_ip6_multicast_add_group(struct net_bridge *br, |
| 740 | struct net_bridge_port *port, |
Vlad Yasevich | b0e9a30 | 2013-02-13 12:00:17 +0000 | [diff] [blame] | 741 | const struct in6_addr *group, |
| 742 | __u16 vid) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 743 | { |
| 744 | struct br_ip br_group; |
| 745 | |
Linus Lüssing | 3c3769e | 2013-09-04 02:13:39 +0200 | [diff] [blame] | 746 | if (ipv6_addr_is_ll_all_nodes(group)) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 747 | return 0; |
| 748 | |
Alexey Dobriyan | 4e3fd7a | 2011-11-21 03:39:03 +0000 | [diff] [blame] | 749 | br_group.u.ip6 = *group; |
Linus Lüssing | 9cc6e0c | 2011-02-15 13:19:17 +0000 | [diff] [blame] | 750 | br_group.proto = htons(ETH_P_IPV6); |
Vlad Yasevich | b0e9a30 | 2013-02-13 12:00:17 +0000 | [diff] [blame] | 751 | br_group.vid = vid; |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 752 | |
| 753 | return br_multicast_add_group(br, port, &br_group); |
| 754 | } |
| 755 | #endif |
| 756 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 757 | static void br_multicast_router_expired(unsigned long data) |
| 758 | { |
| 759 | struct net_bridge_port *port = (void *)data; |
| 760 | struct net_bridge *br = port->br; |
| 761 | |
| 762 | spin_lock(&br->multicast_lock); |
| 763 | if (port->multicast_router != 1 || |
| 764 | timer_pending(&port->multicast_router_timer) || |
| 765 | hlist_unhashed(&port->rlist)) |
| 766 | goto out; |
| 767 | |
| 768 | hlist_del_init_rcu(&port->rlist); |
Satish Ashok | 949f1e3 | 2015-07-23 05:00:53 -0700 | [diff] [blame] | 769 | br_rtr_notify(br->dev, port, RTM_DELMDB); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 770 | |
| 771 | out: |
| 772 | spin_unlock(&br->multicast_lock); |
| 773 | } |
| 774 | |
| 775 | static void br_multicast_local_router_expired(unsigned long data) |
| 776 | { |
| 777 | } |
| 778 | |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 779 | static void br_multicast_querier_expired(struct net_bridge *br, |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 780 | struct bridge_mcast_own_query *query) |
Herbert Xu | c83b8fa | 2012-04-13 02:37:42 +0000 | [diff] [blame] | 781 | { |
Herbert Xu | c83b8fa | 2012-04-13 02:37:42 +0000 | [diff] [blame] | 782 | spin_lock(&br->multicast_lock); |
| 783 | if (!netif_running(br->dev) || br->multicast_disabled) |
| 784 | goto out; |
| 785 | |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 786 | br_multicast_start_querier(br, query); |
Herbert Xu | c83b8fa | 2012-04-13 02:37:42 +0000 | [diff] [blame] | 787 | |
| 788 | out: |
| 789 | spin_unlock(&br->multicast_lock); |
| 790 | } |
| 791 | |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 792 | static void br_ip4_multicast_querier_expired(unsigned long data) |
| 793 | { |
| 794 | struct net_bridge *br = (void *)data; |
| 795 | |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 796 | br_multicast_querier_expired(br, &br->ip4_own_query); |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | #if IS_ENABLED(CONFIG_IPV6) |
| 800 | static void br_ip6_multicast_querier_expired(unsigned long data) |
| 801 | { |
| 802 | struct net_bridge *br = (void *)data; |
| 803 | |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 804 | br_multicast_querier_expired(br, &br->ip6_own_query); |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 805 | } |
| 806 | #endif |
| 807 | |
Linus Lüssing | dc4eb53 | 2014-06-07 18:26:27 +0200 | [diff] [blame] | 808 | static void br_multicast_select_own_querier(struct net_bridge *br, |
| 809 | struct br_ip *ip, |
| 810 | struct sk_buff *skb) |
| 811 | { |
| 812 | if (ip->proto == htons(ETH_P_IP)) |
| 813 | br->ip4_querier.addr.u.ip4 = ip_hdr(skb)->saddr; |
| 814 | #if IS_ENABLED(CONFIG_IPV6) |
| 815 | else |
| 816 | br->ip6_querier.addr.u.ip6 = ipv6_hdr(skb)->saddr; |
| 817 | #endif |
| 818 | } |
| 819 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 820 | static void __br_multicast_send_query(struct net_bridge *br, |
| 821 | struct net_bridge_port *port, |
| 822 | struct br_ip *ip) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 823 | { |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 824 | struct sk_buff *skb; |
| 825 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 826 | skb = br_multicast_alloc_query(br, ip); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 827 | if (!skb) |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 828 | return; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 829 | |
| 830 | if (port) { |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 831 | skb->dev = port->dev; |
David Miller | 7026b1d | 2015-04-05 22:19:04 -0400 | [diff] [blame] | 832 | NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_OUT, NULL, skb, |
| 833 | NULL, skb->dev, |
Linus Lüssing | f0b4eec | 2014-11-17 12:20:28 +0100 | [diff] [blame] | 834 | br_dev_queue_push_xmit); |
Linus Lüssing | dc4eb53 | 2014-06-07 18:26:27 +0200 | [diff] [blame] | 835 | } else { |
| 836 | br_multicast_select_own_querier(br, ip, skb); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 837 | netif_rx(skb); |
Linus Lüssing | dc4eb53 | 2014-06-07 18:26:27 +0200 | [diff] [blame] | 838 | } |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 839 | } |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 840 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 841 | static void br_multicast_send_query(struct net_bridge *br, |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 842 | struct net_bridge_port *port, |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 843 | struct bridge_mcast_own_query *own_query) |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 844 | { |
| 845 | unsigned long time; |
| 846 | struct br_ip br_group; |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 847 | struct bridge_mcast_other_query *other_query = NULL; |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 848 | |
| 849 | if (!netif_running(br->dev) || br->multicast_disabled || |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 850 | !br->multicast_querier) |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 851 | return; |
| 852 | |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 853 | memset(&br_group.u, 0, sizeof(br_group.u)); |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 854 | |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 855 | if (port ? (own_query == &port->ip4_own_query) : |
| 856 | (own_query == &br->ip4_own_query)) { |
| 857 | other_query = &br->ip4_other_query; |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 858 | br_group.proto = htons(ETH_P_IP); |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 859 | #if IS_ENABLED(CONFIG_IPV6) |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 860 | } else { |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 861 | other_query = &br->ip6_other_query; |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 862 | br_group.proto = htons(ETH_P_IPV6); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 863 | #endif |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 864 | } |
| 865 | |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 866 | if (!other_query || timer_pending(&other_query->timer)) |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 867 | return; |
| 868 | |
| 869 | __br_multicast_send_query(br, port, &br_group); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 870 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 871 | time = jiffies; |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 872 | time += own_query->startup_sent < br->multicast_startup_query_count ? |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 873 | br->multicast_startup_query_interval : |
| 874 | br->multicast_query_interval; |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 875 | mod_timer(&own_query->timer, time); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 876 | } |
| 877 | |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 878 | static void |
| 879 | br_multicast_port_query_expired(struct net_bridge_port *port, |
| 880 | struct bridge_mcast_own_query *query) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 881 | { |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 882 | struct net_bridge *br = port->br; |
| 883 | |
| 884 | spin_lock(&br->multicast_lock); |
Dan Carpenter | 02a780c | 2010-03-06 01:14:09 +0000 | [diff] [blame] | 885 | if (port->state == BR_STATE_DISABLED || |
| 886 | port->state == BR_STATE_BLOCKING) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 887 | goto out; |
| 888 | |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 889 | if (query->startup_sent < br->multicast_startup_query_count) |
| 890 | query->startup_sent++; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 891 | |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 892 | br_multicast_send_query(port->br, port, query); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 893 | |
| 894 | out: |
| 895 | spin_unlock(&br->multicast_lock); |
| 896 | } |
| 897 | |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 898 | static void br_ip4_multicast_port_query_expired(unsigned long data) |
| 899 | { |
| 900 | struct net_bridge_port *port = (void *)data; |
| 901 | |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 902 | br_multicast_port_query_expired(port, &port->ip4_own_query); |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | #if IS_ENABLED(CONFIG_IPV6) |
| 906 | static void br_ip6_multicast_port_query_expired(unsigned long data) |
| 907 | { |
| 908 | struct net_bridge_port *port = (void *)data; |
| 909 | |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 910 | br_multicast_port_query_expired(port, &port->ip6_own_query); |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 911 | } |
| 912 | #endif |
| 913 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 914 | void br_multicast_add_port(struct net_bridge_port *port) |
| 915 | { |
| 916 | port->multicast_router = 1; |
| 917 | |
| 918 | setup_timer(&port->multicast_router_timer, br_multicast_router_expired, |
| 919 | (unsigned long)port); |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 920 | setup_timer(&port->ip4_own_query.timer, |
| 921 | br_ip4_multicast_port_query_expired, (unsigned long)port); |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 922 | #if IS_ENABLED(CONFIG_IPV6) |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 923 | setup_timer(&port->ip6_own_query.timer, |
| 924 | br_ip6_multicast_port_query_expired, (unsigned long)port); |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 925 | #endif |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | void br_multicast_del_port(struct net_bridge_port *port) |
| 929 | { |
Satish Ashok | e10177a | 2015-07-15 07:16:51 -0700 | [diff] [blame] | 930 | struct net_bridge *br = port->br; |
| 931 | struct net_bridge_port_group *pg; |
| 932 | struct hlist_node *n; |
| 933 | |
| 934 | /* Take care of the remaining groups, only perm ones should be left */ |
| 935 | spin_lock_bh(&br->multicast_lock); |
| 936 | hlist_for_each_entry_safe(pg, n, &port->mglist, mglist) |
| 937 | br_multicast_del_pg(br, pg); |
| 938 | spin_unlock_bh(&br->multicast_lock); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 939 | del_timer_sync(&port->multicast_router_timer); |
| 940 | } |
| 941 | |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 942 | static void br_multicast_enable(struct bridge_mcast_own_query *query) |
Herbert Xu | 561f110 | 2010-02-27 19:41:50 +0000 | [diff] [blame] | 943 | { |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 944 | query->startup_sent = 0; |
Herbert Xu | 561f110 | 2010-02-27 19:41:50 +0000 | [diff] [blame] | 945 | |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 946 | if (try_to_del_timer_sync(&query->timer) >= 0 || |
| 947 | del_timer(&query->timer)) |
| 948 | mod_timer(&query->timer, jiffies); |
Herbert Xu | 561f110 | 2010-02-27 19:41:50 +0000 | [diff] [blame] | 949 | } |
| 950 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 951 | void br_multicast_enable_port(struct net_bridge_port *port) |
| 952 | { |
| 953 | struct net_bridge *br = port->br; |
| 954 | |
| 955 | spin_lock(&br->multicast_lock); |
| 956 | if (br->multicast_disabled || !netif_running(br->dev)) |
| 957 | goto out; |
| 958 | |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 959 | br_multicast_enable(&port->ip4_own_query); |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 960 | #if IS_ENABLED(CONFIG_IPV6) |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 961 | br_multicast_enable(&port->ip6_own_query); |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 962 | #endif |
Satish Ashok | 754bc54 | 2015-06-19 01:22:57 -0700 | [diff] [blame] | 963 | if (port->multicast_router == 2 && hlist_unhashed(&port->rlist)) |
| 964 | br_multicast_add_router(br, port); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 965 | |
| 966 | out: |
| 967 | spin_unlock(&br->multicast_lock); |
| 968 | } |
| 969 | |
| 970 | void br_multicast_disable_port(struct net_bridge_port *port) |
| 971 | { |
| 972 | struct net_bridge *br = port->br; |
| 973 | struct net_bridge_port_group *pg; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 974 | struct hlist_node *n; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 975 | |
| 976 | spin_lock(&br->multicast_lock); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 977 | hlist_for_each_entry_safe(pg, n, &port->mglist, mglist) |
Satish Ashok | e10177a | 2015-07-15 07:16:51 -0700 | [diff] [blame] | 978 | if (pg->state == MDB_TEMPORARY) |
| 979 | br_multicast_del_pg(br, pg); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 980 | |
Satish Ashok | 949f1e3 | 2015-07-23 05:00:53 -0700 | [diff] [blame] | 981 | if (!hlist_unhashed(&port->rlist)) { |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 982 | hlist_del_init_rcu(&port->rlist); |
Satish Ashok | 949f1e3 | 2015-07-23 05:00:53 -0700 | [diff] [blame] | 983 | br_rtr_notify(br->dev, port, RTM_DELMDB); |
| 984 | } |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 985 | del_timer(&port->multicast_router_timer); |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 986 | del_timer(&port->ip4_own_query.timer); |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 987 | #if IS_ENABLED(CONFIG_IPV6) |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 988 | del_timer(&port->ip6_own_query.timer); |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 989 | #endif |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 990 | spin_unlock(&br->multicast_lock); |
| 991 | } |
| 992 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 993 | static int br_ip4_multicast_igmp3_report(struct net_bridge *br, |
| 994 | struct net_bridge_port *port, |
Vlad Yasevich | 0649909 | 2013-10-28 15:45:07 -0400 | [diff] [blame] | 995 | struct sk_buff *skb, |
| 996 | u16 vid) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 997 | { |
| 998 | struct igmpv3_report *ih; |
| 999 | struct igmpv3_grec *grec; |
| 1000 | int i; |
| 1001 | int len; |
| 1002 | int num; |
| 1003 | int type; |
| 1004 | int err = 0; |
| 1005 | __be32 group; |
| 1006 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1007 | ih = igmpv3_report_hdr(skb); |
| 1008 | num = ntohs(ih->ngrec); |
| 1009 | len = sizeof(*ih); |
| 1010 | |
| 1011 | for (i = 0; i < num; i++) { |
| 1012 | len += sizeof(*grec); |
| 1013 | if (!pskb_may_pull(skb, len)) |
| 1014 | return -EINVAL; |
| 1015 | |
Herbert Xu | fd218cf | 2010-04-07 21:20:47 -0700 | [diff] [blame] | 1016 | grec = (void *)(skb->data + len - sizeof(*grec)); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1017 | group = grec->grec_mca; |
| 1018 | type = grec->grec_type; |
| 1019 | |
Eric Dumazet | 8eabf95 | 2010-04-20 03:20:05 +0000 | [diff] [blame] | 1020 | len += ntohs(grec->grec_nsrcs) * 4; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1021 | if (!pskb_may_pull(skb, len)) |
| 1022 | return -EINVAL; |
| 1023 | |
| 1024 | /* We treat this as an IGMPv2 report for now. */ |
| 1025 | switch (type) { |
| 1026 | case IGMPV3_MODE_IS_INCLUDE: |
| 1027 | case IGMPV3_MODE_IS_EXCLUDE: |
| 1028 | case IGMPV3_CHANGE_TO_INCLUDE: |
| 1029 | case IGMPV3_CHANGE_TO_EXCLUDE: |
| 1030 | case IGMPV3_ALLOW_NEW_SOURCES: |
| 1031 | case IGMPV3_BLOCK_OLD_SOURCES: |
| 1032 | break; |
| 1033 | |
| 1034 | default: |
| 1035 | continue; |
| 1036 | } |
| 1037 | |
Satish Ashok | bc8c20a | 2015-07-13 05:28:37 -0700 | [diff] [blame] | 1038 | if ((type == IGMPV3_CHANGE_TO_INCLUDE || |
| 1039 | type == IGMPV3_MODE_IS_INCLUDE) && |
| 1040 | ntohs(grec->grec_nsrcs) == 0) { |
| 1041 | br_ip4_multicast_leave_group(br, port, group, vid); |
| 1042 | } else { |
| 1043 | err = br_ip4_multicast_add_group(br, port, group, vid); |
| 1044 | if (err) |
| 1045 | break; |
| 1046 | } |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | return err; |
| 1050 | } |
| 1051 | |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 1052 | #if IS_ENABLED(CONFIG_IPV6) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1053 | static int br_ip6_multicast_mld2_report(struct net_bridge *br, |
| 1054 | struct net_bridge_port *port, |
Vlad Yasevich | 0649909 | 2013-10-28 15:45:07 -0400 | [diff] [blame] | 1055 | struct sk_buff *skb, |
| 1056 | u16 vid) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1057 | { |
| 1058 | struct icmp6hdr *icmp6h; |
| 1059 | struct mld2_grec *grec; |
| 1060 | int i; |
| 1061 | int len; |
| 1062 | int num; |
| 1063 | int err = 0; |
| 1064 | |
| 1065 | if (!pskb_may_pull(skb, sizeof(*icmp6h))) |
| 1066 | return -EINVAL; |
| 1067 | |
| 1068 | icmp6h = icmp6_hdr(skb); |
| 1069 | num = ntohs(icmp6h->icmp6_dataun.un_data16[1]); |
| 1070 | len = sizeof(*icmp6h); |
| 1071 | |
| 1072 | for (i = 0; i < num; i++) { |
| 1073 | __be16 *nsrcs, _nsrcs; |
| 1074 | |
| 1075 | nsrcs = skb_header_pointer(skb, |
| 1076 | len + offsetof(struct mld2_grec, |
Linus Lüssing | 649e984 | 2011-02-15 13:19:18 +0000 | [diff] [blame] | 1077 | grec_nsrcs), |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1078 | sizeof(_nsrcs), &_nsrcs); |
| 1079 | if (!nsrcs) |
| 1080 | return -EINVAL; |
| 1081 | |
| 1082 | if (!pskb_may_pull(skb, |
| 1083 | len + sizeof(*grec) + |
Linus Lüssing | d41db9f | 2011-02-15 13:19:19 +0000 | [diff] [blame] | 1084 | sizeof(struct in6_addr) * ntohs(*nsrcs))) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1085 | return -EINVAL; |
| 1086 | |
| 1087 | grec = (struct mld2_grec *)(skb->data + len); |
Linus Lüssing | d41db9f | 2011-02-15 13:19:19 +0000 | [diff] [blame] | 1088 | len += sizeof(*grec) + |
| 1089 | sizeof(struct in6_addr) * ntohs(*nsrcs); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1090 | |
| 1091 | /* We treat these as MLDv1 reports for now. */ |
| 1092 | switch (grec->grec_type) { |
| 1093 | case MLD2_MODE_IS_INCLUDE: |
| 1094 | case MLD2_MODE_IS_EXCLUDE: |
| 1095 | case MLD2_CHANGE_TO_INCLUDE: |
| 1096 | case MLD2_CHANGE_TO_EXCLUDE: |
| 1097 | case MLD2_ALLOW_NEW_SOURCES: |
| 1098 | case MLD2_BLOCK_OLD_SOURCES: |
| 1099 | break; |
| 1100 | |
| 1101 | default: |
| 1102 | continue; |
| 1103 | } |
| 1104 | |
Satish Ashok | bc8c20a | 2015-07-13 05:28:37 -0700 | [diff] [blame] | 1105 | if ((grec->grec_type == MLD2_CHANGE_TO_INCLUDE || |
| 1106 | grec->grec_type == MLD2_MODE_IS_INCLUDE) && |
| 1107 | ntohs(*nsrcs) == 0) { |
| 1108 | br_ip6_multicast_leave_group(br, port, &grec->grec_mca, |
| 1109 | vid); |
| 1110 | } else { |
| 1111 | err = br_ip6_multicast_add_group(br, port, |
| 1112 | &grec->grec_mca, vid); |
| 1113 | if (!err) |
| 1114 | break; |
| 1115 | } |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | return err; |
| 1119 | } |
| 1120 | #endif |
| 1121 | |
Linus Lüssing | dc4eb53 | 2014-06-07 18:26:27 +0200 | [diff] [blame] | 1122 | static bool br_ip4_multicast_select_querier(struct net_bridge *br, |
Linus Lüssing | 2cd4143 | 2014-06-07 18:26:29 +0200 | [diff] [blame] | 1123 | struct net_bridge_port *port, |
Linus Lüssing | dc4eb53 | 2014-06-07 18:26:27 +0200 | [diff] [blame] | 1124 | __be32 saddr) |
| 1125 | { |
| 1126 | if (!timer_pending(&br->ip4_own_query.timer) && |
| 1127 | !timer_pending(&br->ip4_other_query.timer)) |
| 1128 | goto update; |
| 1129 | |
| 1130 | if (!br->ip4_querier.addr.u.ip4) |
| 1131 | goto update; |
| 1132 | |
| 1133 | if (ntohl(saddr) <= ntohl(br->ip4_querier.addr.u.ip4)) |
| 1134 | goto update; |
| 1135 | |
| 1136 | return false; |
| 1137 | |
| 1138 | update: |
| 1139 | br->ip4_querier.addr.u.ip4 = saddr; |
| 1140 | |
Linus Lüssing | 2cd4143 | 2014-06-07 18:26:29 +0200 | [diff] [blame] | 1141 | /* update protected by general multicast_lock by caller */ |
| 1142 | rcu_assign_pointer(br->ip4_querier.port, port); |
| 1143 | |
Linus Lüssing | dc4eb53 | 2014-06-07 18:26:27 +0200 | [diff] [blame] | 1144 | return true; |
| 1145 | } |
| 1146 | |
| 1147 | #if IS_ENABLED(CONFIG_IPV6) |
| 1148 | static bool br_ip6_multicast_select_querier(struct net_bridge *br, |
Linus Lüssing | 2cd4143 | 2014-06-07 18:26:29 +0200 | [diff] [blame] | 1149 | struct net_bridge_port *port, |
Linus Lüssing | dc4eb53 | 2014-06-07 18:26:27 +0200 | [diff] [blame] | 1150 | struct in6_addr *saddr) |
| 1151 | { |
| 1152 | if (!timer_pending(&br->ip6_own_query.timer) && |
| 1153 | !timer_pending(&br->ip6_other_query.timer)) |
| 1154 | goto update; |
| 1155 | |
| 1156 | if (ipv6_addr_cmp(saddr, &br->ip6_querier.addr.u.ip6) <= 0) |
| 1157 | goto update; |
| 1158 | |
| 1159 | return false; |
| 1160 | |
| 1161 | update: |
| 1162 | br->ip6_querier.addr.u.ip6 = *saddr; |
| 1163 | |
Linus Lüssing | 2cd4143 | 2014-06-07 18:26:29 +0200 | [diff] [blame] | 1164 | /* update protected by general multicast_lock by caller */ |
| 1165 | rcu_assign_pointer(br->ip6_querier.port, port); |
| 1166 | |
Linus Lüssing | dc4eb53 | 2014-06-07 18:26:27 +0200 | [diff] [blame] | 1167 | return true; |
| 1168 | } |
| 1169 | #endif |
| 1170 | |
| 1171 | static bool br_multicast_select_querier(struct net_bridge *br, |
Linus Lüssing | 2cd4143 | 2014-06-07 18:26:29 +0200 | [diff] [blame] | 1172 | struct net_bridge_port *port, |
Linus Lüssing | dc4eb53 | 2014-06-07 18:26:27 +0200 | [diff] [blame] | 1173 | struct br_ip *saddr) |
| 1174 | { |
| 1175 | switch (saddr->proto) { |
| 1176 | case htons(ETH_P_IP): |
Linus Lüssing | 2cd4143 | 2014-06-07 18:26:29 +0200 | [diff] [blame] | 1177 | return br_ip4_multicast_select_querier(br, port, saddr->u.ip4); |
Linus Lüssing | dc4eb53 | 2014-06-07 18:26:27 +0200 | [diff] [blame] | 1178 | #if IS_ENABLED(CONFIG_IPV6) |
| 1179 | case htons(ETH_P_IPV6): |
Linus Lüssing | 2cd4143 | 2014-06-07 18:26:29 +0200 | [diff] [blame] | 1180 | return br_ip6_multicast_select_querier(br, port, &saddr->u.ip6); |
Linus Lüssing | dc4eb53 | 2014-06-07 18:26:27 +0200 | [diff] [blame] | 1181 | #endif |
| 1182 | } |
| 1183 | |
| 1184 | return false; |
| 1185 | } |
| 1186 | |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1187 | static void |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 1188 | br_multicast_update_query_timer(struct net_bridge *br, |
| 1189 | struct bridge_mcast_other_query *query, |
| 1190 | unsigned long max_delay) |
Linus Lüssing | b00589a | 2013-08-01 01:06:20 +0200 | [diff] [blame] | 1191 | { |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 1192 | if (!timer_pending(&query->timer)) |
| 1193 | query->delay_time = jiffies + max_delay; |
Linus Lüssing | b00589a | 2013-08-01 01:06:20 +0200 | [diff] [blame] | 1194 | |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 1195 | mod_timer(&query->timer, jiffies + br->multicast_querier_interval); |
Linus Lüssing | b00589a | 2013-08-01 01:06:20 +0200 | [diff] [blame] | 1196 | } |
| 1197 | |
stephen hemminger | 7e80c12 | 2010-04-27 15:01:04 +0000 | [diff] [blame] | 1198 | /* |
Cong Wang | 7c77602 | 2013-06-21 15:37:25 +0800 | [diff] [blame] | 1199 | * Add port to router_list |
stephen hemminger | 7e80c12 | 2010-04-27 15:01:04 +0000 | [diff] [blame] | 1200 | * list is maintained ordered by pointer value |
| 1201 | * and locked by br->multicast_lock and RCU |
| 1202 | */ |
Herbert Xu | 0909e11 | 2010-02-27 19:41:49 +0000 | [diff] [blame] | 1203 | static void br_multicast_add_router(struct net_bridge *br, |
| 1204 | struct net_bridge_port *port) |
| 1205 | { |
stephen hemminger | dcdca2c | 2010-04-27 07:13:11 +0000 | [diff] [blame] | 1206 | struct net_bridge_port *p; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1207 | struct hlist_node *slot = NULL; |
Herbert Xu | 0909e11 | 2010-02-27 19:41:49 +0000 | [diff] [blame] | 1208 | |
Nikolay Aleksandrov | 1a040ea | 2015-06-09 10:23:57 -0700 | [diff] [blame] | 1209 | if (!hlist_unhashed(&port->rlist)) |
| 1210 | return; |
| 1211 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1212 | hlist_for_each_entry(p, &br->router_list, rlist) { |
stephen hemminger | 7e80c12 | 2010-04-27 15:01:04 +0000 | [diff] [blame] | 1213 | if ((unsigned long) port >= (unsigned long) p) |
| 1214 | break; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1215 | slot = &p->rlist; |
stephen hemminger | dcdca2c | 2010-04-27 07:13:11 +0000 | [diff] [blame] | 1216 | } |
Herbert Xu | 0909e11 | 2010-02-27 19:41:49 +0000 | [diff] [blame] | 1217 | |
stephen hemminger | 7e80c12 | 2010-04-27 15:01:04 +0000 | [diff] [blame] | 1218 | if (slot) |
Ken Helias | 1d02328 | 2014-08-06 16:09:16 -0700 | [diff] [blame] | 1219 | hlist_add_behind_rcu(&port->rlist, slot); |
stephen hemminger | dcdca2c | 2010-04-27 07:13:11 +0000 | [diff] [blame] | 1220 | else |
| 1221 | hlist_add_head_rcu(&port->rlist, &br->router_list); |
Satish Ashok | 949f1e3 | 2015-07-23 05:00:53 -0700 | [diff] [blame] | 1222 | br_rtr_notify(br->dev, port, RTM_NEWMDB); |
Herbert Xu | 0909e11 | 2010-02-27 19:41:49 +0000 | [diff] [blame] | 1223 | } |
| 1224 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1225 | static void br_multicast_mark_router(struct net_bridge *br, |
| 1226 | struct net_bridge_port *port) |
| 1227 | { |
| 1228 | unsigned long now = jiffies; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1229 | |
| 1230 | if (!port) { |
| 1231 | if (br->multicast_router == 1) |
| 1232 | mod_timer(&br->multicast_router_timer, |
| 1233 | now + br->multicast_querier_interval); |
| 1234 | return; |
| 1235 | } |
| 1236 | |
| 1237 | if (port->multicast_router != 1) |
| 1238 | return; |
| 1239 | |
Herbert Xu | 0909e11 | 2010-02-27 19:41:49 +0000 | [diff] [blame] | 1240 | br_multicast_add_router(br, port); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1241 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1242 | mod_timer(&port->multicast_router_timer, |
| 1243 | now + br->multicast_querier_interval); |
| 1244 | } |
| 1245 | |
| 1246 | static void br_multicast_query_received(struct net_bridge *br, |
| 1247 | struct net_bridge_port *port, |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 1248 | struct bridge_mcast_other_query *query, |
Linus Lüssing | dc4eb53 | 2014-06-07 18:26:27 +0200 | [diff] [blame] | 1249 | struct br_ip *saddr, |
Linus Lüssing | b00589a | 2013-08-01 01:06:20 +0200 | [diff] [blame] | 1250 | unsigned long max_delay) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1251 | { |
Linus Lüssing | 2cd4143 | 2014-06-07 18:26:29 +0200 | [diff] [blame] | 1252 | if (!br_multicast_select_querier(br, port, saddr)) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1253 | return; |
| 1254 | |
Linus Lüssing | dc4eb53 | 2014-06-07 18:26:27 +0200 | [diff] [blame] | 1255 | br_multicast_update_query_timer(br, query, max_delay); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1256 | br_multicast_mark_router(br, port); |
| 1257 | } |
| 1258 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 1259 | static int br_ip4_multicast_query(struct net_bridge *br, |
| 1260 | struct net_bridge_port *port, |
Vlad Yasevich | 0649909 | 2013-10-28 15:45:07 -0400 | [diff] [blame] | 1261 | struct sk_buff *skb, |
| 1262 | u16 vid) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1263 | { |
Eric Dumazet | b71d1d4 | 2011-04-22 04:53:02 +0000 | [diff] [blame] | 1264 | const struct iphdr *iph = ip_hdr(skb); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1265 | struct igmphdr *ih = igmp_hdr(skb); |
| 1266 | struct net_bridge_mdb_entry *mp; |
| 1267 | struct igmpv3_query *ih3; |
| 1268 | struct net_bridge_port_group *p; |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 1269 | struct net_bridge_port_group __rcu **pp; |
Linus Lüssing | dc4eb53 | 2014-06-07 18:26:27 +0200 | [diff] [blame] | 1270 | struct br_ip saddr; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1271 | unsigned long max_delay; |
| 1272 | unsigned long now = jiffies; |
| 1273 | __be32 group; |
YOSHIFUJI Hideaki | bec68ff | 2010-03-13 12:27:21 -0800 | [diff] [blame] | 1274 | int err = 0; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1275 | |
| 1276 | spin_lock(&br->multicast_lock); |
| 1277 | if (!netif_running(br->dev) || |
| 1278 | (port && port->state == BR_STATE_DISABLED)) |
| 1279 | goto out; |
| 1280 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1281 | group = ih->group; |
| 1282 | |
| 1283 | if (skb->len == sizeof(*ih)) { |
| 1284 | max_delay = ih->code * (HZ / IGMP_TIMER_SCALE); |
| 1285 | |
| 1286 | if (!max_delay) { |
| 1287 | max_delay = 10 * HZ; |
| 1288 | group = 0; |
| 1289 | } |
Linus Lüssing | 9afd85c | 2015-05-02 14:01:07 +0200 | [diff] [blame] | 1290 | } else if (skb->len >= sizeof(*ih3)) { |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1291 | ih3 = igmpv3_query_hdr(skb); |
| 1292 | if (ih3->nsrcs) |
YOSHIFUJI Hideaki | bec68ff | 2010-03-13 12:27:21 -0800 | [diff] [blame] | 1293 | goto out; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1294 | |
YOSHIFUJI Hideaki / 吉藤英明 | 0ba8c9e | 2010-03-15 19:27:00 +0000 | [diff] [blame] | 1295 | max_delay = ih3->code ? |
| 1296 | IGMPV3_MRC(ih3->code) * (HZ / IGMP_TIMER_SCALE) : 1; |
Linus Lüssing | 9afd85c | 2015-05-02 14:01:07 +0200 | [diff] [blame] | 1297 | } else { |
Linus Lüssing | 9ed973c | 2014-03-10 22:25:24 +0100 | [diff] [blame] | 1298 | goto out; |
| 1299 | } |
| 1300 | |
Linus Lüssing | dc4eb53 | 2014-06-07 18:26:27 +0200 | [diff] [blame] | 1301 | if (!group) { |
| 1302 | saddr.proto = htons(ETH_P_IP); |
| 1303 | saddr.u.ip4 = iph->saddr; |
Linus Lüssing | b00589a | 2013-08-01 01:06:20 +0200 | [diff] [blame] | 1304 | |
Linus Lüssing | dc4eb53 | 2014-06-07 18:26:27 +0200 | [diff] [blame] | 1305 | br_multicast_query_received(br, port, &br->ip4_other_query, |
| 1306 | &saddr, max_delay); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1307 | goto out; |
Linus Lüssing | dc4eb53 | 2014-06-07 18:26:27 +0200 | [diff] [blame] | 1308 | } |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1309 | |
Vlad Yasevich | b0e9a30 | 2013-02-13 12:00:17 +0000 | [diff] [blame] | 1310 | mp = br_mdb_ip4_get(mlock_dereference(br->mdb, br), group, vid); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1311 | if (!mp) |
| 1312 | goto out; |
| 1313 | |
| 1314 | max_delay *= br->multicast_last_member_count; |
| 1315 | |
Herbert Xu | 8a87017 | 2011-02-12 01:05:42 -0800 | [diff] [blame] | 1316 | if (mp->mglist && |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1317 | (timer_pending(&mp->timer) ? |
| 1318 | time_after(mp->timer.expires, now + max_delay) : |
| 1319 | try_to_del_timer_sync(&mp->timer) >= 0)) |
| 1320 | mod_timer(&mp->timer, now + max_delay); |
| 1321 | |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 1322 | for (pp = &mp->ports; |
| 1323 | (p = mlock_dereference(*pp, br)) != NULL; |
| 1324 | pp = &p->next) { |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1325 | if (timer_pending(&p->timer) ? |
| 1326 | time_after(p->timer.expires, now + max_delay) : |
| 1327 | try_to_del_timer_sync(&p->timer) >= 0) |
Herbert Xu | 24f9cdc | 2011-02-11 12:42:07 +0000 | [diff] [blame] | 1328 | mod_timer(&p->timer, now + max_delay); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | out: |
| 1332 | spin_unlock(&br->multicast_lock); |
YOSHIFUJI Hideaki | bec68ff | 2010-03-13 12:27:21 -0800 | [diff] [blame] | 1333 | return err; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1334 | } |
| 1335 | |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 1336 | #if IS_ENABLED(CONFIG_IPV6) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1337 | static int br_ip6_multicast_query(struct net_bridge *br, |
| 1338 | struct net_bridge_port *port, |
Vlad Yasevich | 0649909 | 2013-10-28 15:45:07 -0400 | [diff] [blame] | 1339 | struct sk_buff *skb, |
| 1340 | u16 vid) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1341 | { |
Eric Dumazet | b71d1d4 | 2011-04-22 04:53:02 +0000 | [diff] [blame] | 1342 | const struct ipv6hdr *ip6h = ipv6_hdr(skb); |
stephen hemminger | eca2a43 | 2012-12-13 06:51:28 +0000 | [diff] [blame] | 1343 | struct mld_msg *mld; |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1344 | struct net_bridge_mdb_entry *mp; |
| 1345 | struct mld2_query *mld2q; |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 1346 | struct net_bridge_port_group *p; |
| 1347 | struct net_bridge_port_group __rcu **pp; |
Linus Lüssing | dc4eb53 | 2014-06-07 18:26:27 +0200 | [diff] [blame] | 1348 | struct br_ip saddr; |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1349 | unsigned long max_delay; |
| 1350 | unsigned long now = jiffies; |
Eric Dumazet | b71d1d4 | 2011-04-22 04:53:02 +0000 | [diff] [blame] | 1351 | const struct in6_addr *group = NULL; |
Linus Lüssing | 9ed973c | 2014-03-10 22:25:24 +0100 | [diff] [blame] | 1352 | bool is_general_query; |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1353 | int err = 0; |
| 1354 | |
| 1355 | spin_lock(&br->multicast_lock); |
| 1356 | if (!netif_running(br->dev) || |
| 1357 | (port && port->state == BR_STATE_DISABLED)) |
| 1358 | goto out; |
| 1359 | |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1360 | if (skb->len == sizeof(*mld)) { |
| 1361 | if (!pskb_may_pull(skb, sizeof(*mld))) { |
| 1362 | err = -EINVAL; |
| 1363 | goto out; |
| 1364 | } |
| 1365 | mld = (struct mld_msg *) icmp6_hdr(skb); |
Li RongQing | 4715213 | 2012-07-09 23:56:12 +0000 | [diff] [blame] | 1366 | max_delay = msecs_to_jiffies(ntohs(mld->mld_maxdelay)); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1367 | if (max_delay) |
| 1368 | group = &mld->mld_mca; |
Linus Lüssing | 248ba8e | 2013-08-06 00:32:05 +0200 | [diff] [blame] | 1369 | } else { |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1370 | if (!pskb_may_pull(skb, sizeof(*mld2q))) { |
| 1371 | err = -EINVAL; |
| 1372 | goto out; |
| 1373 | } |
| 1374 | mld2q = (struct mld2_query *)icmp6_hdr(skb); |
| 1375 | if (!mld2q->mld2q_nsrcs) |
| 1376 | group = &mld2q->mld2q_mca; |
Daniel Borkmann | e3f5b17 | 2013-09-04 00:19:39 +0200 | [diff] [blame] | 1377 | |
| 1378 | max_delay = max(msecs_to_jiffies(mldv2_mrc(mld2q)), 1UL); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1379 | } |
| 1380 | |
Linus Lüssing | 9ed973c | 2014-03-10 22:25:24 +0100 | [diff] [blame] | 1381 | is_general_query = group && ipv6_addr_any(group); |
| 1382 | |
Linus Lüssing | dc4eb53 | 2014-06-07 18:26:27 +0200 | [diff] [blame] | 1383 | if (is_general_query) { |
| 1384 | saddr.proto = htons(ETH_P_IPV6); |
| 1385 | saddr.u.ip6 = ip6h->saddr; |
Linus Lüssing | b00589a | 2013-08-01 01:06:20 +0200 | [diff] [blame] | 1386 | |
Linus Lüssing | dc4eb53 | 2014-06-07 18:26:27 +0200 | [diff] [blame] | 1387 | br_multicast_query_received(br, port, &br->ip6_other_query, |
| 1388 | &saddr, max_delay); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1389 | goto out; |
Linus Lüssing | 6c03ee8 | 2014-06-12 01:41:23 +0200 | [diff] [blame] | 1390 | } else if (!group) { |
| 1391 | goto out; |
Linus Lüssing | dc4eb53 | 2014-06-07 18:26:27 +0200 | [diff] [blame] | 1392 | } |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1393 | |
Vlad Yasevich | b0e9a30 | 2013-02-13 12:00:17 +0000 | [diff] [blame] | 1394 | mp = br_mdb_ip6_get(mlock_dereference(br->mdb, br), group, vid); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1395 | if (!mp) |
| 1396 | goto out; |
| 1397 | |
| 1398 | max_delay *= br->multicast_last_member_count; |
Herbert Xu | 8a87017 | 2011-02-12 01:05:42 -0800 | [diff] [blame] | 1399 | if (mp->mglist && |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1400 | (timer_pending(&mp->timer) ? |
| 1401 | time_after(mp->timer.expires, now + max_delay) : |
| 1402 | try_to_del_timer_sync(&mp->timer) >= 0)) |
| 1403 | mod_timer(&mp->timer, now + max_delay); |
| 1404 | |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 1405 | for (pp = &mp->ports; |
| 1406 | (p = mlock_dereference(*pp, br)) != NULL; |
| 1407 | pp = &p->next) { |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1408 | if (timer_pending(&p->timer) ? |
| 1409 | time_after(p->timer.expires, now + max_delay) : |
| 1410 | try_to_del_timer_sync(&p->timer) >= 0) |
Herbert Xu | 24f9cdc | 2011-02-11 12:42:07 +0000 | [diff] [blame] | 1411 | mod_timer(&p->timer, now + max_delay); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1412 | } |
| 1413 | |
| 1414 | out: |
| 1415 | spin_unlock(&br->multicast_lock); |
| 1416 | return err; |
| 1417 | } |
| 1418 | #endif |
| 1419 | |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 1420 | static void |
| 1421 | br_multicast_leave_group(struct net_bridge *br, |
| 1422 | struct net_bridge_port *port, |
| 1423 | struct br_ip *group, |
| 1424 | struct bridge_mcast_other_query *other_query, |
| 1425 | struct bridge_mcast_own_query *own_query) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1426 | { |
| 1427 | struct net_bridge_mdb_htable *mdb; |
| 1428 | struct net_bridge_mdb_entry *mp; |
| 1429 | struct net_bridge_port_group *p; |
| 1430 | unsigned long now; |
| 1431 | unsigned long time; |
| 1432 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1433 | spin_lock(&br->multicast_lock); |
| 1434 | if (!netif_running(br->dev) || |
Satish Ashok | 544586f | 2015-07-28 03:28:27 -0700 | [diff] [blame] | 1435 | (port && port->state == BR_STATE_DISABLED)) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1436 | goto out; |
| 1437 | |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 1438 | mdb = mlock_dereference(br->mdb, br); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1439 | mp = br_mdb_ip_get(mdb, group); |
| 1440 | if (!mp) |
| 1441 | goto out; |
| 1442 | |
Satish Ashok | 544586f | 2015-07-28 03:28:27 -0700 | [diff] [blame] | 1443 | if (port && (port->flags & BR_MULTICAST_FAST_LEAVE)) { |
| 1444 | struct net_bridge_port_group __rcu **pp; |
| 1445 | |
| 1446 | for (pp = &mp->ports; |
| 1447 | (p = mlock_dereference(*pp, br)) != NULL; |
| 1448 | pp = &p->next) { |
| 1449 | if (p->port != port) |
| 1450 | continue; |
| 1451 | |
| 1452 | rcu_assign_pointer(*pp, p->next); |
| 1453 | hlist_del_init(&p->mglist); |
| 1454 | del_timer(&p->timer); |
| 1455 | call_rcu_bh(&p->rcu, br_multicast_free_pg); |
David S. Miller | 5510b3c | 2015-07-31 23:52:20 -0700 | [diff] [blame] | 1456 | br_mdb_notify(br->dev, port, group, RTM_DELMDB, |
| 1457 | p->state); |
Satish Ashok | 544586f | 2015-07-28 03:28:27 -0700 | [diff] [blame] | 1458 | |
| 1459 | if (!mp->ports && !mp->mglist && |
| 1460 | netif_running(br->dev)) |
| 1461 | mod_timer(&mp->timer, jiffies); |
| 1462 | } |
| 1463 | goto out; |
| 1464 | } |
| 1465 | |
| 1466 | if (timer_pending(&other_query->timer)) |
| 1467 | goto out; |
| 1468 | |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1469 | if (br->multicast_querier) { |
Cong Wang | 6b7df11 | 2013-05-21 21:52:56 +0000 | [diff] [blame] | 1470 | __br_multicast_send_query(br, port, &mp->addr); |
| 1471 | |
| 1472 | time = jiffies + br->multicast_last_member_count * |
| 1473 | br->multicast_last_member_interval; |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1474 | |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 1475 | mod_timer(&own_query->timer, time); |
Cong Wang | 6b7df11 | 2013-05-21 21:52:56 +0000 | [diff] [blame] | 1476 | |
| 1477 | for (p = mlock_dereference(mp->ports, br); |
| 1478 | p != NULL; |
| 1479 | p = mlock_dereference(p->next, br)) { |
| 1480 | if (p->port != port) |
| 1481 | continue; |
| 1482 | |
| 1483 | if (!hlist_unhashed(&p->mglist) && |
| 1484 | (timer_pending(&p->timer) ? |
| 1485 | time_after(p->timer.expires, time) : |
| 1486 | try_to_del_timer_sync(&p->timer) >= 0)) { |
| 1487 | mod_timer(&p->timer, time); |
| 1488 | } |
| 1489 | |
| 1490 | break; |
| 1491 | } |
| 1492 | } |
| 1493 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1494 | now = jiffies; |
| 1495 | time = now + br->multicast_last_member_count * |
| 1496 | br->multicast_last_member_interval; |
| 1497 | |
| 1498 | if (!port) { |
Linus Lüssing | 454594f | 2013-10-20 00:58:57 +0200 | [diff] [blame] | 1499 | if (mp->mglist && |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1500 | (timer_pending(&mp->timer) ? |
| 1501 | time_after(mp->timer.expires, time) : |
| 1502 | try_to_del_timer_sync(&mp->timer) >= 0)) { |
| 1503 | mod_timer(&mp->timer, time); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1504 | } |
Linus Lüssing | 454594f | 2013-10-20 00:58:57 +0200 | [diff] [blame] | 1505 | |
| 1506 | goto out; |
| 1507 | } |
| 1508 | |
| 1509 | for (p = mlock_dereference(mp->ports, br); |
| 1510 | p != NULL; |
| 1511 | p = mlock_dereference(p->next, br)) { |
| 1512 | if (p->port != port) |
| 1513 | continue; |
| 1514 | |
| 1515 | if (!hlist_unhashed(&p->mglist) && |
| 1516 | (timer_pending(&p->timer) ? |
| 1517 | time_after(p->timer.expires, time) : |
| 1518 | try_to_del_timer_sync(&p->timer) >= 0)) { |
| 1519 | mod_timer(&p->timer, time); |
| 1520 | } |
| 1521 | |
| 1522 | break; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1523 | } |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1524 | out: |
| 1525 | spin_unlock(&br->multicast_lock); |
| 1526 | } |
| 1527 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 1528 | static void br_ip4_multicast_leave_group(struct net_bridge *br, |
| 1529 | struct net_bridge_port *port, |
Vlad Yasevich | b0e9a30 | 2013-02-13 12:00:17 +0000 | [diff] [blame] | 1530 | __be32 group, |
| 1531 | __u16 vid) |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 1532 | { |
| 1533 | struct br_ip br_group; |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 1534 | struct bridge_mcast_own_query *own_query; |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 1535 | |
| 1536 | if (ipv4_is_local_multicast(group)) |
| 1537 | return; |
| 1538 | |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 1539 | own_query = port ? &port->ip4_own_query : &br->ip4_own_query; |
| 1540 | |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 1541 | br_group.u.ip4 = group; |
| 1542 | br_group.proto = htons(ETH_P_IP); |
Vlad Yasevich | b0e9a30 | 2013-02-13 12:00:17 +0000 | [diff] [blame] | 1543 | br_group.vid = vid; |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 1544 | |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 1545 | br_multicast_leave_group(br, port, &br_group, &br->ip4_other_query, |
| 1546 | own_query); |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 1547 | } |
| 1548 | |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 1549 | #if IS_ENABLED(CONFIG_IPV6) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1550 | static void br_ip6_multicast_leave_group(struct net_bridge *br, |
| 1551 | struct net_bridge_port *port, |
Vlad Yasevich | b0e9a30 | 2013-02-13 12:00:17 +0000 | [diff] [blame] | 1552 | const struct in6_addr *group, |
| 1553 | __u16 vid) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1554 | { |
| 1555 | struct br_ip br_group; |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 1556 | struct bridge_mcast_own_query *own_query; |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1557 | |
Linus Lüssing | 3c3769e | 2013-09-04 02:13:39 +0200 | [diff] [blame] | 1558 | if (ipv6_addr_is_ll_all_nodes(group)) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1559 | return; |
| 1560 | |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 1561 | own_query = port ? &port->ip6_own_query : &br->ip6_own_query; |
| 1562 | |
Alexey Dobriyan | 4e3fd7a | 2011-11-21 03:39:03 +0000 | [diff] [blame] | 1563 | br_group.u.ip6 = *group; |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1564 | br_group.proto = htons(ETH_P_IPV6); |
Vlad Yasevich | b0e9a30 | 2013-02-13 12:00:17 +0000 | [diff] [blame] | 1565 | br_group.vid = vid; |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1566 | |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 1567 | br_multicast_leave_group(br, port, &br_group, &br->ip6_other_query, |
| 1568 | own_query); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1569 | } |
| 1570 | #endif |
YOSHIFUJI Hideaki | 8ef2a9a | 2010-04-18 12:42:07 +0900 | [diff] [blame] | 1571 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1572 | static int br_multicast_ipv4_rcv(struct net_bridge *br, |
| 1573 | struct net_bridge_port *port, |
Vlad Yasevich | 0649909 | 2013-10-28 15:45:07 -0400 | [diff] [blame] | 1574 | struct sk_buff *skb, |
| 1575 | u16 vid) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1576 | { |
Linus Lüssing | 9afd85c | 2015-05-02 14:01:07 +0200 | [diff] [blame] | 1577 | struct sk_buff *skb_trimmed = NULL; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1578 | struct igmphdr *ih; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1579 | int err; |
| 1580 | |
Linus Lüssing | 9afd85c | 2015-05-02 14:01:07 +0200 | [diff] [blame] | 1581 | err = ip_mc_check_igmp(skb, &skb_trimmed); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1582 | |
Linus Lüssing | 9afd85c | 2015-05-02 14:01:07 +0200 | [diff] [blame] | 1583 | if (err == -ENOMSG) { |
| 1584 | if (!ipv4_is_local_multicast(ip_hdr(skb)->daddr)) |
Herbert Xu | bd4265f | 2011-06-23 02:39:12 +0000 | [diff] [blame] | 1585 | BR_INPUT_SKB_CB(skb)->mrouters_only = 1; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1586 | return 0; |
Linus Lüssing | 9afd85c | 2015-05-02 14:01:07 +0200 | [diff] [blame] | 1587 | } else if (err < 0) { |
| 1588 | return err; |
Herbert Xu | bd4265f | 2011-06-23 02:39:12 +0000 | [diff] [blame] | 1589 | } |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1590 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1591 | BR_INPUT_SKB_CB(skb)->igmp = 1; |
Linus Lüssing | 9afd85c | 2015-05-02 14:01:07 +0200 | [diff] [blame] | 1592 | ih = igmp_hdr(skb); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1593 | |
| 1594 | switch (ih->type) { |
| 1595 | case IGMP_HOST_MEMBERSHIP_REPORT: |
| 1596 | case IGMPV2_HOST_MEMBERSHIP_REPORT: |
Fernando Luis Vázquez Cao | 62b2bcb | 2011-06-13 15:04:43 +0000 | [diff] [blame] | 1597 | BR_INPUT_SKB_CB(skb)->mrouters_only = 1; |
Vlad Yasevich | b0e9a30 | 2013-02-13 12:00:17 +0000 | [diff] [blame] | 1598 | err = br_ip4_multicast_add_group(br, port, ih->group, vid); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1599 | break; |
| 1600 | case IGMPV3_HOST_MEMBERSHIP_REPORT: |
Linus Lüssing | 9afd85c | 2015-05-02 14:01:07 +0200 | [diff] [blame] | 1601 | err = br_ip4_multicast_igmp3_report(br, port, skb_trimmed, vid); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1602 | break; |
| 1603 | case IGMP_HOST_MEMBERSHIP_QUERY: |
Linus Lüssing | 9afd85c | 2015-05-02 14:01:07 +0200 | [diff] [blame] | 1604 | err = br_ip4_multicast_query(br, port, skb_trimmed, vid); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1605 | break; |
| 1606 | case IGMP_HOST_LEAVE_MESSAGE: |
Vlad Yasevich | b0e9a30 | 2013-02-13 12:00:17 +0000 | [diff] [blame] | 1607 | br_ip4_multicast_leave_group(br, port, ih->group, vid); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1608 | break; |
| 1609 | } |
| 1610 | |
Linus Lüssing | a516993 | 2015-08-13 05:54:07 +0200 | [diff] [blame] | 1611 | if (skb_trimmed && skb_trimmed != skb) |
Linus Lüssing | 9afd85c | 2015-05-02 14:01:07 +0200 | [diff] [blame] | 1612 | kfree_skb(skb_trimmed); |
| 1613 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1614 | return err; |
| 1615 | } |
| 1616 | |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 1617 | #if IS_ENABLED(CONFIG_IPV6) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1618 | static int br_multicast_ipv6_rcv(struct net_bridge *br, |
| 1619 | struct net_bridge_port *port, |
Vlad Yasevich | 0649909 | 2013-10-28 15:45:07 -0400 | [diff] [blame] | 1620 | struct sk_buff *skb, |
| 1621 | u16 vid) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1622 | { |
Linus Lüssing | 9afd85c | 2015-05-02 14:01:07 +0200 | [diff] [blame] | 1623 | struct sk_buff *skb_trimmed = NULL; |
| 1624 | struct mld_msg *mld; |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1625 | int err; |
| 1626 | |
Linus Lüssing | 9afd85c | 2015-05-02 14:01:07 +0200 | [diff] [blame] | 1627 | err = ipv6_mc_check_mld(skb, &skb_trimmed); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1628 | |
Linus Lüssing | 9afd85c | 2015-05-02 14:01:07 +0200 | [diff] [blame] | 1629 | if (err == -ENOMSG) { |
| 1630 | if (!ipv6_addr_is_ll_all_nodes(&ipv6_hdr(skb)->daddr)) |
| 1631 | BR_INPUT_SKB_CB(skb)->mrouters_only = 1; |
Linus Lüssing | 8fad9c39 | 2013-09-04 02:13:38 +0200 | [diff] [blame] | 1632 | return 0; |
Linus Lüssing | 9afd85c | 2015-05-02 14:01:07 +0200 | [diff] [blame] | 1633 | } else if (err < 0) { |
| 1634 | return err; |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1635 | } |
| 1636 | |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1637 | BR_INPUT_SKB_CB(skb)->igmp = 1; |
Linus Lüssing | 9afd85c | 2015-05-02 14:01:07 +0200 | [diff] [blame] | 1638 | mld = (struct mld_msg *)skb_transport_header(skb); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1639 | |
Linus Lüssing | 9afd85c | 2015-05-02 14:01:07 +0200 | [diff] [blame] | 1640 | switch (mld->mld_type) { |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1641 | case ICMPV6_MGM_REPORT: |
Fernando Luis Vázquez Cao | fc2af6c | 2011-06-13 15:06:58 +0000 | [diff] [blame] | 1642 | BR_INPUT_SKB_CB(skb)->mrouters_only = 1; |
Vlad Yasevich | b0e9a30 | 2013-02-13 12:00:17 +0000 | [diff] [blame] | 1643 | err = br_ip6_multicast_add_group(br, port, &mld->mld_mca, vid); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1644 | break; |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1645 | case ICMPV6_MLD2_REPORT: |
Linus Lüssing | 9afd85c | 2015-05-02 14:01:07 +0200 | [diff] [blame] | 1646 | err = br_ip6_multicast_mld2_report(br, port, skb_trimmed, vid); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1647 | break; |
| 1648 | case ICMPV6_MGM_QUERY: |
Linus Lüssing | 9afd85c | 2015-05-02 14:01:07 +0200 | [diff] [blame] | 1649 | err = br_ip6_multicast_query(br, port, skb_trimmed, vid); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1650 | break; |
| 1651 | case ICMPV6_MGM_REDUCTION: |
Vlad Yasevich | b0e9a30 | 2013-02-13 12:00:17 +0000 | [diff] [blame] | 1652 | br_ip6_multicast_leave_group(br, port, &mld->mld_mca, vid); |
Linus Lüssing | 9afd85c | 2015-05-02 14:01:07 +0200 | [diff] [blame] | 1653 | break; |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1654 | } |
| 1655 | |
Linus Lüssing | a516993 | 2015-08-13 05:54:07 +0200 | [diff] [blame] | 1656 | if (skb_trimmed && skb_trimmed != skb) |
Linus Lüssing | 9afd85c | 2015-05-02 14:01:07 +0200 | [diff] [blame] | 1657 | kfree_skb(skb_trimmed); |
| 1658 | |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1659 | return err; |
| 1660 | } |
| 1661 | #endif |
| 1662 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1663 | int br_multicast_rcv(struct net_bridge *br, struct net_bridge_port *port, |
Vlad Yasevich | 0649909 | 2013-10-28 15:45:07 -0400 | [diff] [blame] | 1664 | struct sk_buff *skb, u16 vid) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1665 | { |
YOSHIFUJI Hideaki / 吉藤英明 | 1fafc7a | 2010-04-25 08:06:40 +0000 | [diff] [blame] | 1666 | BR_INPUT_SKB_CB(skb)->igmp = 0; |
| 1667 | BR_INPUT_SKB_CB(skb)->mrouters_only = 0; |
| 1668 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1669 | if (br->multicast_disabled) |
| 1670 | return 0; |
| 1671 | |
| 1672 | switch (skb->protocol) { |
| 1673 | case htons(ETH_P_IP): |
Vlad Yasevich | 0649909 | 2013-10-28 15:45:07 -0400 | [diff] [blame] | 1674 | return br_multicast_ipv4_rcv(br, port, skb, vid); |
Eric Dumazet | dfd56b8 | 2011-12-10 09:48:31 +0000 | [diff] [blame] | 1675 | #if IS_ENABLED(CONFIG_IPV6) |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1676 | case htons(ETH_P_IPV6): |
Vlad Yasevich | 0649909 | 2013-10-28 15:45:07 -0400 | [diff] [blame] | 1677 | return br_multicast_ipv6_rcv(br, port, skb, vid); |
YOSHIFUJI Hideaki | 08b202b | 2010-04-23 01:54:22 +0900 | [diff] [blame] | 1678 | #endif |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1679 | } |
| 1680 | |
| 1681 | return 0; |
| 1682 | } |
| 1683 | |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1684 | static void br_multicast_query_expired(struct net_bridge *br, |
Linus Lüssing | 2cd4143 | 2014-06-07 18:26:29 +0200 | [diff] [blame] | 1685 | struct bridge_mcast_own_query *query, |
| 1686 | struct bridge_mcast_querier *querier) |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1687 | { |
| 1688 | spin_lock(&br->multicast_lock); |
| 1689 | if (query->startup_sent < br->multicast_startup_query_count) |
| 1690 | query->startup_sent++; |
| 1691 | |
Eric Dumazet | 71d9f61 | 2015-05-28 04:42:54 -0700 | [diff] [blame] | 1692 | RCU_INIT_POINTER(querier->port, NULL); |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1693 | br_multicast_send_query(br, NULL, query); |
| 1694 | spin_unlock(&br->multicast_lock); |
| 1695 | } |
| 1696 | |
| 1697 | static void br_ip4_multicast_query_expired(unsigned long data) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1698 | { |
| 1699 | struct net_bridge *br = (void *)data; |
| 1700 | |
Linus Lüssing | 2cd4143 | 2014-06-07 18:26:29 +0200 | [diff] [blame] | 1701 | br_multicast_query_expired(br, &br->ip4_own_query, &br->ip4_querier); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1702 | } |
| 1703 | |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1704 | #if IS_ENABLED(CONFIG_IPV6) |
| 1705 | static void br_ip6_multicast_query_expired(unsigned long data) |
| 1706 | { |
| 1707 | struct net_bridge *br = (void *)data; |
| 1708 | |
Linus Lüssing | 2cd4143 | 2014-06-07 18:26:29 +0200 | [diff] [blame] | 1709 | br_multicast_query_expired(br, &br->ip6_own_query, &br->ip6_querier); |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1710 | } |
| 1711 | #endif |
| 1712 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1713 | void br_multicast_init(struct net_bridge *br) |
| 1714 | { |
| 1715 | br->hash_elasticity = 4; |
| 1716 | br->hash_max = 512; |
| 1717 | |
| 1718 | br->multicast_router = 1; |
Herbert Xu | c5c2326 | 2012-04-13 02:37:42 +0000 | [diff] [blame] | 1719 | br->multicast_querier = 0; |
Cong Wang | 1c8ad5b | 2013-05-21 21:52:54 +0000 | [diff] [blame] | 1720 | br->multicast_query_use_ifaddr = 0; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1721 | br->multicast_last_member_count = 2; |
| 1722 | br->multicast_startup_query_count = 2; |
| 1723 | |
| 1724 | br->multicast_last_member_interval = HZ; |
| 1725 | br->multicast_query_response_interval = 10 * HZ; |
| 1726 | br->multicast_startup_query_interval = 125 * HZ / 4; |
| 1727 | br->multicast_query_interval = 125 * HZ; |
| 1728 | br->multicast_querier_interval = 255 * HZ; |
| 1729 | br->multicast_membership_interval = 260 * HZ; |
| 1730 | |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 1731 | br->ip4_other_query.delay_time = 0; |
Linus Lüssing | 2cd4143 | 2014-06-07 18:26:29 +0200 | [diff] [blame] | 1732 | br->ip4_querier.port = NULL; |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1733 | #if IS_ENABLED(CONFIG_IPV6) |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 1734 | br->ip6_other_query.delay_time = 0; |
Linus Lüssing | 2cd4143 | 2014-06-07 18:26:29 +0200 | [diff] [blame] | 1735 | br->ip6_querier.port = NULL; |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1736 | #endif |
Linus Lüssing | b00589a | 2013-08-01 01:06:20 +0200 | [diff] [blame] | 1737 | |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1738 | spin_lock_init(&br->multicast_lock); |
| 1739 | setup_timer(&br->multicast_router_timer, |
| 1740 | br_multicast_local_router_expired, 0); |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 1741 | setup_timer(&br->ip4_other_query.timer, |
| 1742 | br_ip4_multicast_querier_expired, (unsigned long)br); |
| 1743 | setup_timer(&br->ip4_own_query.timer, br_ip4_multicast_query_expired, |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1744 | (unsigned long)br); |
| 1745 | #if IS_ENABLED(CONFIG_IPV6) |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 1746 | setup_timer(&br->ip6_other_query.timer, |
| 1747 | br_ip6_multicast_querier_expired, (unsigned long)br); |
| 1748 | setup_timer(&br->ip6_own_query.timer, br_ip6_multicast_query_expired, |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1749 | (unsigned long)br); |
| 1750 | #endif |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1751 | } |
| 1752 | |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1753 | static void __br_multicast_open(struct net_bridge *br, |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 1754 | struct bridge_mcast_own_query *query) |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1755 | { |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1756 | query->startup_sent = 0; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1757 | |
| 1758 | if (br->multicast_disabled) |
| 1759 | return; |
| 1760 | |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1761 | mod_timer(&query->timer, jiffies); |
| 1762 | } |
| 1763 | |
| 1764 | void br_multicast_open(struct net_bridge *br) |
| 1765 | { |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 1766 | __br_multicast_open(br, &br->ip4_own_query); |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1767 | #if IS_ENABLED(CONFIG_IPV6) |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 1768 | __br_multicast_open(br, &br->ip6_own_query); |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1769 | #endif |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1770 | } |
| 1771 | |
| 1772 | void br_multicast_stop(struct net_bridge *br) |
| 1773 | { |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1774 | del_timer_sync(&br->multicast_router_timer); |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 1775 | del_timer_sync(&br->ip4_other_query.timer); |
| 1776 | del_timer_sync(&br->ip4_own_query.timer); |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1777 | #if IS_ENABLED(CONFIG_IPV6) |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 1778 | del_timer_sync(&br->ip6_other_query.timer); |
| 1779 | del_timer_sync(&br->ip6_own_query.timer); |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1780 | #endif |
Satish Ashok | e10177a | 2015-07-15 07:16:51 -0700 | [diff] [blame] | 1781 | } |
| 1782 | |
| 1783 | void br_multicast_dev_del(struct net_bridge *br) |
| 1784 | { |
| 1785 | struct net_bridge_mdb_htable *mdb; |
| 1786 | struct net_bridge_mdb_entry *mp; |
| 1787 | struct hlist_node *n; |
| 1788 | u32 ver; |
| 1789 | int i; |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1790 | |
| 1791 | spin_lock_bh(&br->multicast_lock); |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 1792 | mdb = mlock_dereference(br->mdb, br); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1793 | if (!mdb) |
| 1794 | goto out; |
| 1795 | |
| 1796 | br->mdb = NULL; |
| 1797 | |
| 1798 | ver = mdb->ver; |
| 1799 | for (i = 0; i < mdb->max; i++) { |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1800 | hlist_for_each_entry_safe(mp, n, &mdb->mhash[i], |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1801 | hlist[ver]) { |
| 1802 | del_timer(&mp->timer); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1803 | call_rcu_bh(&mp->rcu, br_multicast_free_group); |
| 1804 | } |
| 1805 | } |
| 1806 | |
| 1807 | if (mdb->old) { |
| 1808 | spin_unlock_bh(&br->multicast_lock); |
Herbert Xu | 10cc2b5 | 2010-03-05 21:03:35 +0000 | [diff] [blame] | 1809 | rcu_barrier_bh(); |
Herbert Xu | eb1d164 | 2010-02-27 19:41:45 +0000 | [diff] [blame] | 1810 | spin_lock_bh(&br->multicast_lock); |
| 1811 | WARN_ON(mdb->old); |
| 1812 | } |
| 1813 | |
| 1814 | mdb->old = mdb; |
| 1815 | call_rcu_bh(&mdb->rcu, br_mdb_free); |
| 1816 | |
| 1817 | out: |
| 1818 | spin_unlock_bh(&br->multicast_lock); |
| 1819 | } |
Herbert Xu | 0909e11 | 2010-02-27 19:41:49 +0000 | [diff] [blame] | 1820 | |
| 1821 | int br_multicast_set_router(struct net_bridge *br, unsigned long val) |
| 1822 | { |
Linus Lüssing | 6ae4ae8 | 2015-05-23 03:12:34 +0200 | [diff] [blame] | 1823 | int err = -EINVAL; |
Herbert Xu | 0909e11 | 2010-02-27 19:41:49 +0000 | [diff] [blame] | 1824 | |
| 1825 | spin_lock_bh(&br->multicast_lock); |
Herbert Xu | 0909e11 | 2010-02-27 19:41:49 +0000 | [diff] [blame] | 1826 | |
| 1827 | switch (val) { |
| 1828 | case 0: |
| 1829 | case 2: |
| 1830 | del_timer(&br->multicast_router_timer); |
| 1831 | /* fall through */ |
| 1832 | case 1: |
| 1833 | br->multicast_router = val; |
| 1834 | err = 0; |
| 1835 | break; |
Herbert Xu | 0909e11 | 2010-02-27 19:41:49 +0000 | [diff] [blame] | 1836 | } |
| 1837 | |
Herbert Xu | 0909e11 | 2010-02-27 19:41:49 +0000 | [diff] [blame] | 1838 | spin_unlock_bh(&br->multicast_lock); |
| 1839 | |
| 1840 | return err; |
| 1841 | } |
| 1842 | |
| 1843 | int br_multicast_set_port_router(struct net_bridge_port *p, unsigned long val) |
| 1844 | { |
| 1845 | struct net_bridge *br = p->br; |
Linus Lüssing | 6ae4ae8 | 2015-05-23 03:12:34 +0200 | [diff] [blame] | 1846 | int err = -EINVAL; |
Herbert Xu | 0909e11 | 2010-02-27 19:41:49 +0000 | [diff] [blame] | 1847 | |
| 1848 | spin_lock(&br->multicast_lock); |
Herbert Xu | 0909e11 | 2010-02-27 19:41:49 +0000 | [diff] [blame] | 1849 | |
| 1850 | switch (val) { |
| 1851 | case 0: |
| 1852 | case 1: |
| 1853 | case 2: |
| 1854 | p->multicast_router = val; |
| 1855 | err = 0; |
| 1856 | |
Satish Ashok | 949f1e3 | 2015-07-23 05:00:53 -0700 | [diff] [blame] | 1857 | if (val < 2 && !hlist_unhashed(&p->rlist)) { |
Herbert Xu | 0909e11 | 2010-02-27 19:41:49 +0000 | [diff] [blame] | 1858 | hlist_del_init_rcu(&p->rlist); |
Satish Ashok | 949f1e3 | 2015-07-23 05:00:53 -0700 | [diff] [blame] | 1859 | br_rtr_notify(br->dev, p, RTM_DELMDB); |
| 1860 | } |
Herbert Xu | 0909e11 | 2010-02-27 19:41:49 +0000 | [diff] [blame] | 1861 | |
| 1862 | if (val == 1) |
| 1863 | break; |
| 1864 | |
| 1865 | del_timer(&p->multicast_router_timer); |
| 1866 | |
| 1867 | if (val == 0) |
| 1868 | break; |
| 1869 | |
| 1870 | br_multicast_add_router(br, p); |
| 1871 | break; |
Herbert Xu | 0909e11 | 2010-02-27 19:41:49 +0000 | [diff] [blame] | 1872 | } |
| 1873 | |
Herbert Xu | 0909e11 | 2010-02-27 19:41:49 +0000 | [diff] [blame] | 1874 | spin_unlock(&br->multicast_lock); |
| 1875 | |
| 1876 | return err; |
| 1877 | } |
Herbert Xu | 561f110 | 2010-02-27 19:41:50 +0000 | [diff] [blame] | 1878 | |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1879 | static void br_multicast_start_querier(struct net_bridge *br, |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 1880 | struct bridge_mcast_own_query *query) |
Herbert Xu | 561f110 | 2010-02-27 19:41:50 +0000 | [diff] [blame] | 1881 | { |
| 1882 | struct net_bridge_port *port; |
Herbert Xu | 7485721 | 2012-04-13 02:37:42 +0000 | [diff] [blame] | 1883 | |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1884 | __br_multicast_open(br, query); |
Herbert Xu | 7485721 | 2012-04-13 02:37:42 +0000 | [diff] [blame] | 1885 | |
| 1886 | list_for_each_entry(port, &br->port_list, list) { |
| 1887 | if (port->state == BR_STATE_DISABLED || |
| 1888 | port->state == BR_STATE_BLOCKING) |
| 1889 | continue; |
| 1890 | |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 1891 | if (query == &br->ip4_own_query) |
| 1892 | br_multicast_enable(&port->ip4_own_query); |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1893 | #if IS_ENABLED(CONFIG_IPV6) |
| 1894 | else |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 1895 | br_multicast_enable(&port->ip6_own_query); |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1896 | #endif |
Herbert Xu | 7485721 | 2012-04-13 02:37:42 +0000 | [diff] [blame] | 1897 | } |
| 1898 | } |
| 1899 | |
| 1900 | int br_multicast_toggle(struct net_bridge *br, unsigned long val) |
| 1901 | { |
Herbert Xu | 3a7fda0 | 2010-07-29 00:45:30 +0000 | [diff] [blame] | 1902 | int err = 0; |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 1903 | struct net_bridge_mdb_htable *mdb; |
Herbert Xu | 561f110 | 2010-02-27 19:41:50 +0000 | [diff] [blame] | 1904 | |
Andrey Vagin | ef5e0d8 | 2011-11-10 05:48:03 +0000 | [diff] [blame] | 1905 | spin_lock_bh(&br->multicast_lock); |
Herbert Xu | 561f110 | 2010-02-27 19:41:50 +0000 | [diff] [blame] | 1906 | if (br->multicast_disabled == !val) |
| 1907 | goto unlock; |
| 1908 | |
| 1909 | br->multicast_disabled = !val; |
| 1910 | if (br->multicast_disabled) |
| 1911 | goto unlock; |
| 1912 | |
Herbert Xu | 3a7fda0 | 2010-07-29 00:45:30 +0000 | [diff] [blame] | 1913 | if (!netif_running(br->dev)) |
| 1914 | goto unlock; |
| 1915 | |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 1916 | mdb = mlock_dereference(br->mdb, br); |
| 1917 | if (mdb) { |
| 1918 | if (mdb->old) { |
Herbert Xu | 561f110 | 2010-02-27 19:41:50 +0000 | [diff] [blame] | 1919 | err = -EEXIST; |
| 1920 | rollback: |
| 1921 | br->multicast_disabled = !!val; |
| 1922 | goto unlock; |
| 1923 | } |
| 1924 | |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 1925 | err = br_mdb_rehash(&br->mdb, mdb->max, |
Herbert Xu | 561f110 | 2010-02-27 19:41:50 +0000 | [diff] [blame] | 1926 | br->hash_elasticity); |
| 1927 | if (err) |
| 1928 | goto rollback; |
| 1929 | } |
| 1930 | |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 1931 | br_multicast_start_querier(br, &br->ip4_own_query); |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1932 | #if IS_ENABLED(CONFIG_IPV6) |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 1933 | br_multicast_start_querier(br, &br->ip6_own_query); |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1934 | #endif |
Herbert Xu | 561f110 | 2010-02-27 19:41:50 +0000 | [diff] [blame] | 1935 | |
| 1936 | unlock: |
Andrey Vagin | ef5e0d8 | 2011-11-10 05:48:03 +0000 | [diff] [blame] | 1937 | spin_unlock_bh(&br->multicast_lock); |
Herbert Xu | 561f110 | 2010-02-27 19:41:50 +0000 | [diff] [blame] | 1938 | |
| 1939 | return err; |
| 1940 | } |
Herbert Xu | b195167 | 2010-02-27 19:41:51 +0000 | [diff] [blame] | 1941 | |
Herbert Xu | c5c2326 | 2012-04-13 02:37:42 +0000 | [diff] [blame] | 1942 | int br_multicast_set_querier(struct net_bridge *br, unsigned long val) |
| 1943 | { |
Linus Lüssing | b00589a | 2013-08-01 01:06:20 +0200 | [diff] [blame] | 1944 | unsigned long max_delay; |
| 1945 | |
Herbert Xu | c5c2326 | 2012-04-13 02:37:42 +0000 | [diff] [blame] | 1946 | val = !!val; |
| 1947 | |
| 1948 | spin_lock_bh(&br->multicast_lock); |
| 1949 | if (br->multicast_querier == val) |
| 1950 | goto unlock; |
| 1951 | |
| 1952 | br->multicast_querier = val; |
Linus Lüssing | b00589a | 2013-08-01 01:06:20 +0200 | [diff] [blame] | 1953 | if (!val) |
| 1954 | goto unlock; |
| 1955 | |
| 1956 | max_delay = br->multicast_query_response_interval; |
Linus Lüssing | b00589a | 2013-08-01 01:06:20 +0200 | [diff] [blame] | 1957 | |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 1958 | if (!timer_pending(&br->ip4_other_query.timer)) |
| 1959 | br->ip4_other_query.delay_time = jiffies + max_delay; |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1960 | |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 1961 | br_multicast_start_querier(br, &br->ip4_own_query); |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1962 | |
| 1963 | #if IS_ENABLED(CONFIG_IPV6) |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 1964 | if (!timer_pending(&br->ip6_other_query.timer)) |
| 1965 | br->ip6_other_query.delay_time = jiffies + max_delay; |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1966 | |
Linus Lüssing | 90010b3 | 2014-06-07 18:26:26 +0200 | [diff] [blame] | 1967 | br_multicast_start_querier(br, &br->ip6_own_query); |
Linus Lüssing | cc0fdd8 | 2013-08-30 17:28:17 +0200 | [diff] [blame] | 1968 | #endif |
Herbert Xu | c5c2326 | 2012-04-13 02:37:42 +0000 | [diff] [blame] | 1969 | |
| 1970 | unlock: |
| 1971 | spin_unlock_bh(&br->multicast_lock); |
| 1972 | |
| 1973 | return 0; |
| 1974 | } |
| 1975 | |
Herbert Xu | b195167 | 2010-02-27 19:41:51 +0000 | [diff] [blame] | 1976 | int br_multicast_set_hash_max(struct net_bridge *br, unsigned long val) |
| 1977 | { |
Linus Lüssing | 6ae4ae8 | 2015-05-23 03:12:34 +0200 | [diff] [blame] | 1978 | int err = -EINVAL; |
Herbert Xu | b195167 | 2010-02-27 19:41:51 +0000 | [diff] [blame] | 1979 | u32 old; |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 1980 | struct net_bridge_mdb_htable *mdb; |
Herbert Xu | b195167 | 2010-02-27 19:41:51 +0000 | [diff] [blame] | 1981 | |
Curt Brune | fe0d692 | 2014-01-06 11:00:32 -0800 | [diff] [blame] | 1982 | spin_lock_bh(&br->multicast_lock); |
Herbert Xu | b195167 | 2010-02-27 19:41:51 +0000 | [diff] [blame] | 1983 | if (!is_power_of_2(val)) |
| 1984 | goto unlock; |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 1985 | |
| 1986 | mdb = mlock_dereference(br->mdb, br); |
| 1987 | if (mdb && val < mdb->size) |
Herbert Xu | b195167 | 2010-02-27 19:41:51 +0000 | [diff] [blame] | 1988 | goto unlock; |
| 1989 | |
| 1990 | err = 0; |
| 1991 | |
| 1992 | old = br->hash_max; |
| 1993 | br->hash_max = val; |
| 1994 | |
Eric Dumazet | e805168 | 2010-11-15 06:38:10 +0000 | [diff] [blame] | 1995 | if (mdb) { |
| 1996 | if (mdb->old) { |
Herbert Xu | b195167 | 2010-02-27 19:41:51 +0000 | [diff] [blame] | 1997 | err = -EEXIST; |
| 1998 | rollback: |
| 1999 | br->hash_max = old; |
| 2000 | goto unlock; |
| 2001 | } |
| 2002 | |
| 2003 | err = br_mdb_rehash(&br->mdb, br->hash_max, |
| 2004 | br->hash_elasticity); |
| 2005 | if (err) |
| 2006 | goto rollback; |
| 2007 | } |
| 2008 | |
| 2009 | unlock: |
Curt Brune | fe0d692 | 2014-01-06 11:00:32 -0800 | [diff] [blame] | 2010 | spin_unlock_bh(&br->multicast_lock); |
Herbert Xu | b195167 | 2010-02-27 19:41:51 +0000 | [diff] [blame] | 2011 | |
| 2012 | return err; |
| 2013 | } |
Linus Lüssing | 07f8ac4 | 2014-06-07 18:26:28 +0200 | [diff] [blame] | 2014 | |
| 2015 | /** |
| 2016 | * br_multicast_list_adjacent - Returns snooped multicast addresses |
| 2017 | * @dev: The bridge port adjacent to which to retrieve addresses |
| 2018 | * @br_ip_list: The list to store found, snooped multicast IP addresses in |
| 2019 | * |
| 2020 | * Creates a list of IP addresses (struct br_ip_list) sensed by the multicast |
| 2021 | * snooping feature on all bridge ports of dev's bridge device, excluding |
| 2022 | * the addresses from dev itself. |
| 2023 | * |
| 2024 | * Returns the number of items added to br_ip_list. |
| 2025 | * |
| 2026 | * Notes: |
| 2027 | * - br_ip_list needs to be initialized by caller |
| 2028 | * - br_ip_list might contain duplicates in the end |
| 2029 | * (needs to be taken care of by caller) |
| 2030 | * - br_ip_list needs to be freed by caller |
| 2031 | */ |
| 2032 | int br_multicast_list_adjacent(struct net_device *dev, |
| 2033 | struct list_head *br_ip_list) |
| 2034 | { |
| 2035 | struct net_bridge *br; |
| 2036 | struct net_bridge_port *port; |
| 2037 | struct net_bridge_port_group *group; |
| 2038 | struct br_ip_list *entry; |
| 2039 | int count = 0; |
| 2040 | |
| 2041 | rcu_read_lock(); |
| 2042 | if (!br_ip_list || !br_port_exists(dev)) |
| 2043 | goto unlock; |
| 2044 | |
| 2045 | port = br_port_get_rcu(dev); |
| 2046 | if (!port || !port->br) |
| 2047 | goto unlock; |
| 2048 | |
| 2049 | br = port->br; |
| 2050 | |
| 2051 | list_for_each_entry_rcu(port, &br->port_list, list) { |
| 2052 | if (!port->dev || port->dev == dev) |
| 2053 | continue; |
| 2054 | |
| 2055 | hlist_for_each_entry_rcu(group, &port->mglist, mglist) { |
| 2056 | entry = kmalloc(sizeof(*entry), GFP_ATOMIC); |
| 2057 | if (!entry) |
| 2058 | goto unlock; |
| 2059 | |
| 2060 | entry->addr = group->addr; |
| 2061 | list_add(&entry->list, br_ip_list); |
| 2062 | count++; |
| 2063 | } |
| 2064 | } |
| 2065 | |
| 2066 | unlock: |
| 2067 | rcu_read_unlock(); |
| 2068 | return count; |
| 2069 | } |
| 2070 | EXPORT_SYMBOL_GPL(br_multicast_list_adjacent); |
Linus Lüssing | 2cd4143 | 2014-06-07 18:26:29 +0200 | [diff] [blame] | 2071 | |
| 2072 | /** |
Linus Lüssing | c34963e | 2014-07-07 05:41:17 +0200 | [diff] [blame] | 2073 | * br_multicast_has_querier_anywhere - Checks for a querier on a bridge |
| 2074 | * @dev: The bridge port providing the bridge on which to check for a querier |
| 2075 | * @proto: The protocol family to check for: IGMP -> ETH_P_IP, MLD -> ETH_P_IPV6 |
| 2076 | * |
| 2077 | * Checks whether the given interface has a bridge on top and if so returns |
| 2078 | * true if a valid querier exists anywhere on the bridged link layer. |
| 2079 | * Otherwise returns false. |
| 2080 | */ |
| 2081 | bool br_multicast_has_querier_anywhere(struct net_device *dev, int proto) |
| 2082 | { |
| 2083 | struct net_bridge *br; |
| 2084 | struct net_bridge_port *port; |
| 2085 | struct ethhdr eth; |
| 2086 | bool ret = false; |
| 2087 | |
| 2088 | rcu_read_lock(); |
| 2089 | if (!br_port_exists(dev)) |
| 2090 | goto unlock; |
| 2091 | |
| 2092 | port = br_port_get_rcu(dev); |
| 2093 | if (!port || !port->br) |
| 2094 | goto unlock; |
| 2095 | |
| 2096 | br = port->br; |
| 2097 | |
| 2098 | memset(ð, 0, sizeof(eth)); |
| 2099 | eth.h_proto = htons(proto); |
| 2100 | |
| 2101 | ret = br_multicast_querier_exists(br, ð); |
| 2102 | |
| 2103 | unlock: |
| 2104 | rcu_read_unlock(); |
| 2105 | return ret; |
| 2106 | } |
| 2107 | EXPORT_SYMBOL_GPL(br_multicast_has_querier_anywhere); |
| 2108 | |
| 2109 | /** |
Linus Lüssing | 2cd4143 | 2014-06-07 18:26:29 +0200 | [diff] [blame] | 2110 | * br_multicast_has_querier_adjacent - Checks for a querier behind a bridge port |
| 2111 | * @dev: The bridge port adjacent to which to check for a querier |
| 2112 | * @proto: The protocol family to check for: IGMP -> ETH_P_IP, MLD -> ETH_P_IPV6 |
| 2113 | * |
| 2114 | * Checks whether the given interface has a bridge on top and if so returns |
| 2115 | * true if a selected querier is behind one of the other ports of this |
| 2116 | * bridge. Otherwise returns false. |
| 2117 | */ |
| 2118 | bool br_multicast_has_querier_adjacent(struct net_device *dev, int proto) |
| 2119 | { |
| 2120 | struct net_bridge *br; |
| 2121 | struct net_bridge_port *port; |
| 2122 | bool ret = false; |
| 2123 | |
| 2124 | rcu_read_lock(); |
| 2125 | if (!br_port_exists(dev)) |
| 2126 | goto unlock; |
| 2127 | |
| 2128 | port = br_port_get_rcu(dev); |
| 2129 | if (!port || !port->br) |
| 2130 | goto unlock; |
| 2131 | |
| 2132 | br = port->br; |
| 2133 | |
| 2134 | switch (proto) { |
| 2135 | case ETH_P_IP: |
| 2136 | if (!timer_pending(&br->ip4_other_query.timer) || |
| 2137 | rcu_dereference(br->ip4_querier.port) == port) |
| 2138 | goto unlock; |
| 2139 | break; |
Linus Lüssing | 3993c4e | 2014-06-12 01:41:24 +0200 | [diff] [blame] | 2140 | #if IS_ENABLED(CONFIG_IPV6) |
Linus Lüssing | 2cd4143 | 2014-06-07 18:26:29 +0200 | [diff] [blame] | 2141 | case ETH_P_IPV6: |
| 2142 | if (!timer_pending(&br->ip6_other_query.timer) || |
| 2143 | rcu_dereference(br->ip6_querier.port) == port) |
| 2144 | goto unlock; |
| 2145 | break; |
Linus Lüssing | 3993c4e | 2014-06-12 01:41:24 +0200 | [diff] [blame] | 2146 | #endif |
Linus Lüssing | 2cd4143 | 2014-06-07 18:26:29 +0200 | [diff] [blame] | 2147 | default: |
| 2148 | goto unlock; |
| 2149 | } |
| 2150 | |
| 2151 | ret = true; |
| 2152 | unlock: |
| 2153 | rcu_read_unlock(); |
| 2154 | return ret; |
| 2155 | } |
| 2156 | EXPORT_SYMBOL_GPL(br_multicast_has_querier_adjacent); |