1eb1d1641SHerbert Xu /* 2eb1d1641SHerbert Xu * Bridge multicast support. 3eb1d1641SHerbert Xu * 4eb1d1641SHerbert Xu * Copyright (c) 2010 Herbert Xu <herbert@gondor.apana.org.au> 5eb1d1641SHerbert Xu * 6eb1d1641SHerbert Xu * This program is free software; you can redistribute it and/or modify it 7eb1d1641SHerbert Xu * under the terms of the GNU General Public License as published by the Free 8eb1d1641SHerbert Xu * Software Foundation; either version 2 of the License, or (at your option) 9eb1d1641SHerbert Xu * any later version. 10eb1d1641SHerbert Xu * 11eb1d1641SHerbert Xu */ 12eb1d1641SHerbert Xu 13eb1d1641SHerbert Xu #include <linux/err.h> 1407f8ac4aSLinus Lüssing #include <linux/export.h> 15eb1d1641SHerbert Xu #include <linux/if_ether.h> 16eb1d1641SHerbert Xu #include <linux/igmp.h> 17eb1d1641SHerbert Xu #include <linux/jhash.h> 18eb1d1641SHerbert Xu #include <linux/kernel.h> 19b195167fSHerbert Xu #include <linux/log2.h> 20eb1d1641SHerbert Xu #include <linux/netdevice.h> 21eb1d1641SHerbert Xu #include <linux/netfilter_bridge.h> 22eb1d1641SHerbert Xu #include <linux/random.h> 23eb1d1641SHerbert Xu #include <linux/rculist.h> 24eb1d1641SHerbert Xu #include <linux/skbuff.h> 25eb1d1641SHerbert Xu #include <linux/slab.h> 26eb1d1641SHerbert Xu #include <linux/timer.h> 271c8ad5bfSCong Wang #include <linux/inetdevice.h> 28eb1d1641SHerbert Xu #include <net/ip.h> 29dfd56b8bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6) 3008b202b6SYOSHIFUJI Hideaki #include <net/ipv6.h> 3108b202b6SYOSHIFUJI Hideaki #include <net/mld.h> 32d4c4f07dSDavid S. Miller #include <net/ip6_checksum.h> 333c3769e6SLinus Lüssing #include <net/addrconf.h> 3408b202b6SYOSHIFUJI Hideaki #endif 35eb1d1641SHerbert Xu 36eb1d1641SHerbert Xu #include "br_private.h" 37eb1d1641SHerbert Xu 38cc0fdd80SLinus Lüssing static void br_multicast_start_querier(struct net_bridge *br, 3990010b36SLinus Lüssing struct bridge_mcast_own_query *query); 40754bc547SSatish Ashok static void br_multicast_add_router(struct net_bridge *br, 41754bc547SSatish Ashok struct net_bridge_port *port); 42bc8c20acSSatish Ashok static void br_ip4_multicast_leave_group(struct net_bridge *br, 43bc8c20acSSatish Ashok struct net_bridge_port *port, 44bc8c20acSSatish Ashok __be32 group, 45bc8c20acSSatish Ashok __u16 vid); 46bc8c20acSSatish Ashok #if IS_ENABLED(CONFIG_IPV6) 47bc8c20acSSatish Ashok static void br_ip6_multicast_leave_group(struct net_bridge *br, 48bc8c20acSSatish Ashok struct net_bridge_port *port, 49bc8c20acSSatish Ashok const struct in6_addr *group, 50bc8c20acSSatish Ashok __u16 vid); 51bc8c20acSSatish Ashok #endif 522ce297fcSCong Wang unsigned int br_mdb_rehash_seq; 53c83b8fabSHerbert Xu 548ef2a9a5SYOSHIFUJI Hideaki static inline int br_ip_equal(const struct br_ip *a, const struct br_ip *b) 558ef2a9a5SYOSHIFUJI Hideaki { 568ef2a9a5SYOSHIFUJI Hideaki if (a->proto != b->proto) 578ef2a9a5SYOSHIFUJI Hideaki return 0; 58b0e9a30dSVlad Yasevich if (a->vid != b->vid) 59b0e9a30dSVlad Yasevich return 0; 608ef2a9a5SYOSHIFUJI Hideaki switch (a->proto) { 618ef2a9a5SYOSHIFUJI Hideaki case htons(ETH_P_IP): 628ef2a9a5SYOSHIFUJI Hideaki return a->u.ip4 == b->u.ip4; 63dfd56b8bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6) 6408b202b6SYOSHIFUJI Hideaki case htons(ETH_P_IPV6): 6508b202b6SYOSHIFUJI Hideaki return ipv6_addr_equal(&a->u.ip6, &b->u.ip6); 6608b202b6SYOSHIFUJI Hideaki #endif 678ef2a9a5SYOSHIFUJI Hideaki } 688ef2a9a5SYOSHIFUJI Hideaki return 0; 698ef2a9a5SYOSHIFUJI Hideaki } 708ef2a9a5SYOSHIFUJI Hideaki 71b0e9a30dSVlad Yasevich static inline int __br_ip4_hash(struct net_bridge_mdb_htable *mdb, __be32 ip, 72b0e9a30dSVlad Yasevich __u16 vid) 73eb1d1641SHerbert Xu { 74b0e9a30dSVlad Yasevich return jhash_2words((__force u32)ip, vid, mdb->secret) & (mdb->max - 1); 75eb1d1641SHerbert Xu } 76eb1d1641SHerbert Xu 77dfd56b8bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6) 7808b202b6SYOSHIFUJI Hideaki static inline int __br_ip6_hash(struct net_bridge_mdb_htable *mdb, 79b0e9a30dSVlad Yasevich const struct in6_addr *ip, 80b0e9a30dSVlad Yasevich __u16 vid) 8108b202b6SYOSHIFUJI Hideaki { 82b0e9a30dSVlad Yasevich return jhash_2words(ipv6_addr_hash(ip), vid, 83b0e9a30dSVlad Yasevich mdb->secret) & (mdb->max - 1); 8408b202b6SYOSHIFUJI Hideaki } 8508b202b6SYOSHIFUJI Hideaki #endif 8608b202b6SYOSHIFUJI Hideaki 878ef2a9a5SYOSHIFUJI Hideaki static inline int br_ip_hash(struct net_bridge_mdb_htable *mdb, 888ef2a9a5SYOSHIFUJI Hideaki struct br_ip *ip) 898ef2a9a5SYOSHIFUJI Hideaki { 908ef2a9a5SYOSHIFUJI Hideaki switch (ip->proto) { 918ef2a9a5SYOSHIFUJI Hideaki case htons(ETH_P_IP): 92b0e9a30dSVlad Yasevich return __br_ip4_hash(mdb, ip->u.ip4, ip->vid); 93dfd56b8bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6) 9408b202b6SYOSHIFUJI Hideaki case htons(ETH_P_IPV6): 95b0e9a30dSVlad Yasevich return __br_ip6_hash(mdb, &ip->u.ip6, ip->vid); 9608b202b6SYOSHIFUJI Hideaki #endif 978ef2a9a5SYOSHIFUJI Hideaki } 988ef2a9a5SYOSHIFUJI Hideaki return 0; 99eb1d1641SHerbert Xu } 100eb1d1641SHerbert Xu 101eb1d1641SHerbert Xu static struct net_bridge_mdb_entry *__br_mdb_ip_get( 1028ef2a9a5SYOSHIFUJI Hideaki struct net_bridge_mdb_htable *mdb, struct br_ip *dst, int hash) 103eb1d1641SHerbert Xu { 104eb1d1641SHerbert Xu struct net_bridge_mdb_entry *mp; 105eb1d1641SHerbert Xu 106b67bfe0dSSasha Levin hlist_for_each_entry_rcu(mp, &mdb->mhash[hash], hlist[mdb->ver]) { 1078ef2a9a5SYOSHIFUJI Hideaki if (br_ip_equal(&mp->addr, dst)) 108eb1d1641SHerbert Xu return mp; 109eb1d1641SHerbert Xu } 110eb1d1641SHerbert Xu 111eb1d1641SHerbert Xu return NULL; 112eb1d1641SHerbert Xu } 113eb1d1641SHerbert Xu 114cfd56754SCong Wang struct net_bridge_mdb_entry *br_mdb_ip_get(struct net_bridge_mdb_htable *mdb, 115cfd56754SCong Wang struct br_ip *dst) 1167f285fa7SHerbert Xu { 1177f285fa7SHerbert Xu if (!mdb) 1187f285fa7SHerbert Xu return NULL; 1197f285fa7SHerbert Xu 1207f285fa7SHerbert Xu return __br_mdb_ip_get(mdb, dst, br_ip_hash(mdb, dst)); 1217f285fa7SHerbert Xu } 1227f285fa7SHerbert Xu 1238ef2a9a5SYOSHIFUJI Hideaki static struct net_bridge_mdb_entry *br_mdb_ip4_get( 124b0e9a30dSVlad Yasevich struct net_bridge_mdb_htable *mdb, __be32 dst, __u16 vid) 125eb1d1641SHerbert Xu { 1268ef2a9a5SYOSHIFUJI Hideaki struct br_ip br_dst; 1270821ec55SHerbert Xu 1288ef2a9a5SYOSHIFUJI Hideaki br_dst.u.ip4 = dst; 1298ef2a9a5SYOSHIFUJI Hideaki br_dst.proto = htons(ETH_P_IP); 130b0e9a30dSVlad Yasevich br_dst.vid = vid; 1318ef2a9a5SYOSHIFUJI Hideaki 1327f285fa7SHerbert Xu return br_mdb_ip_get(mdb, &br_dst); 1338ef2a9a5SYOSHIFUJI Hideaki } 1348ef2a9a5SYOSHIFUJI Hideaki 135dfd56b8bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6) 13608b202b6SYOSHIFUJI Hideaki static struct net_bridge_mdb_entry *br_mdb_ip6_get( 137b0e9a30dSVlad Yasevich struct net_bridge_mdb_htable *mdb, const struct in6_addr *dst, 138b0e9a30dSVlad Yasevich __u16 vid) 13908b202b6SYOSHIFUJI Hideaki { 14008b202b6SYOSHIFUJI Hideaki struct br_ip br_dst; 14108b202b6SYOSHIFUJI Hideaki 1424e3fd7a0SAlexey Dobriyan br_dst.u.ip6 = *dst; 14308b202b6SYOSHIFUJI Hideaki br_dst.proto = htons(ETH_P_IPV6); 144b0e9a30dSVlad Yasevich br_dst.vid = vid; 14508b202b6SYOSHIFUJI Hideaki 1467f285fa7SHerbert Xu return br_mdb_ip_get(mdb, &br_dst); 14708b202b6SYOSHIFUJI Hideaki } 14808b202b6SYOSHIFUJI Hideaki #endif 14908b202b6SYOSHIFUJI Hideaki 150eb1d1641SHerbert Xu struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br, 151fbca58a2SCong Wang struct sk_buff *skb, u16 vid) 152eb1d1641SHerbert Xu { 153e8051688SEric Dumazet struct net_bridge_mdb_htable *mdb = rcu_dereference(br->mdb); 1548ef2a9a5SYOSHIFUJI Hideaki struct br_ip ip; 1558ef2a9a5SYOSHIFUJI Hideaki 1567f285fa7SHerbert Xu if (br->multicast_disabled) 157eb1d1641SHerbert Xu return NULL; 158eb1d1641SHerbert Xu 1598ef2a9a5SYOSHIFUJI Hideaki if (BR_INPUT_SKB_CB(skb)->igmp) 1608ef2a9a5SYOSHIFUJI Hideaki return NULL; 1618ef2a9a5SYOSHIFUJI Hideaki 1628ef2a9a5SYOSHIFUJI Hideaki ip.proto = skb->protocol; 163fbca58a2SCong Wang ip.vid = vid; 1648ef2a9a5SYOSHIFUJI Hideaki 165eb1d1641SHerbert Xu switch (skb->protocol) { 166eb1d1641SHerbert Xu case htons(ETH_P_IP): 1678ef2a9a5SYOSHIFUJI Hideaki ip.u.ip4 = ip_hdr(skb)->daddr; 168eb1d1641SHerbert Xu break; 169dfd56b8bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6) 17008b202b6SYOSHIFUJI Hideaki case htons(ETH_P_IPV6): 1714e3fd7a0SAlexey Dobriyan ip.u.ip6 = ipv6_hdr(skb)->daddr; 17208b202b6SYOSHIFUJI Hideaki break; 17308b202b6SYOSHIFUJI Hideaki #endif 1748ef2a9a5SYOSHIFUJI Hideaki default: 1758ef2a9a5SYOSHIFUJI Hideaki return NULL; 176eb1d1641SHerbert Xu } 177eb1d1641SHerbert Xu 1788ef2a9a5SYOSHIFUJI Hideaki return br_mdb_ip_get(mdb, &ip); 179eb1d1641SHerbert Xu } 180eb1d1641SHerbert Xu 181eb1d1641SHerbert Xu static void br_mdb_free(struct rcu_head *head) 182eb1d1641SHerbert Xu { 183eb1d1641SHerbert Xu struct net_bridge_mdb_htable *mdb = 184eb1d1641SHerbert Xu container_of(head, struct net_bridge_mdb_htable, rcu); 185eb1d1641SHerbert Xu struct net_bridge_mdb_htable *old = mdb->old; 186eb1d1641SHerbert Xu 187eb1d1641SHerbert Xu mdb->old = NULL; 188eb1d1641SHerbert Xu kfree(old->mhash); 189eb1d1641SHerbert Xu kfree(old); 190eb1d1641SHerbert Xu } 191eb1d1641SHerbert Xu 192eb1d1641SHerbert Xu static int br_mdb_copy(struct net_bridge_mdb_htable *new, 193eb1d1641SHerbert Xu struct net_bridge_mdb_htable *old, 194eb1d1641SHerbert Xu int elasticity) 195eb1d1641SHerbert Xu { 196eb1d1641SHerbert Xu struct net_bridge_mdb_entry *mp; 197eb1d1641SHerbert Xu int maxlen; 198eb1d1641SHerbert Xu int len; 199eb1d1641SHerbert Xu int i; 200eb1d1641SHerbert Xu 201eb1d1641SHerbert Xu for (i = 0; i < old->max; i++) 202b67bfe0dSSasha Levin hlist_for_each_entry(mp, &old->mhash[i], hlist[old->ver]) 203eb1d1641SHerbert Xu hlist_add_head(&mp->hlist[new->ver], 2048ef2a9a5SYOSHIFUJI Hideaki &new->mhash[br_ip_hash(new, &mp->addr)]); 205eb1d1641SHerbert Xu 206eb1d1641SHerbert Xu if (!elasticity) 207eb1d1641SHerbert Xu return 0; 208eb1d1641SHerbert Xu 209eb1d1641SHerbert Xu maxlen = 0; 210eb1d1641SHerbert Xu for (i = 0; i < new->max; i++) { 211eb1d1641SHerbert Xu len = 0; 212b67bfe0dSSasha Levin hlist_for_each_entry(mp, &new->mhash[i], hlist[new->ver]) 213eb1d1641SHerbert Xu len++; 214eb1d1641SHerbert Xu if (len > maxlen) 215eb1d1641SHerbert Xu maxlen = len; 216eb1d1641SHerbert Xu } 217eb1d1641SHerbert Xu 218eb1d1641SHerbert Xu return maxlen > elasticity ? -EINVAL : 0; 219eb1d1641SHerbert Xu } 220eb1d1641SHerbert Xu 221cfd56754SCong Wang void br_multicast_free_pg(struct rcu_head *head) 222eb1d1641SHerbert Xu { 223eb1d1641SHerbert Xu struct net_bridge_port_group *p = 224eb1d1641SHerbert Xu container_of(head, struct net_bridge_port_group, rcu); 225eb1d1641SHerbert Xu 226eb1d1641SHerbert Xu kfree(p); 227eb1d1641SHerbert Xu } 228eb1d1641SHerbert Xu 229eb1d1641SHerbert Xu static void br_multicast_free_group(struct rcu_head *head) 230eb1d1641SHerbert Xu { 231eb1d1641SHerbert Xu struct net_bridge_mdb_entry *mp = 232eb1d1641SHerbert Xu container_of(head, struct net_bridge_mdb_entry, rcu); 233eb1d1641SHerbert Xu 234eb1d1641SHerbert Xu kfree(mp); 235eb1d1641SHerbert Xu } 236eb1d1641SHerbert Xu 237eb1d1641SHerbert Xu static void br_multicast_group_expired(unsigned long data) 238eb1d1641SHerbert Xu { 239eb1d1641SHerbert Xu struct net_bridge_mdb_entry *mp = (void *)data; 240eb1d1641SHerbert Xu struct net_bridge *br = mp->br; 241eb1d1641SHerbert Xu struct net_bridge_mdb_htable *mdb; 242eb1d1641SHerbert Xu 243eb1d1641SHerbert Xu spin_lock(&br->multicast_lock); 244eb1d1641SHerbert Xu if (!netif_running(br->dev) || timer_pending(&mp->timer)) 245eb1d1641SHerbert Xu goto out; 246eb1d1641SHerbert Xu 2478a870178SHerbert Xu mp->mglist = false; 248eb1d1641SHerbert Xu 249eb1d1641SHerbert Xu if (mp->ports) 250eb1d1641SHerbert Xu goto out; 251eb1d1641SHerbert Xu 252e8051688SEric Dumazet mdb = mlock_dereference(br->mdb, br); 253e8051688SEric Dumazet 254eb1d1641SHerbert Xu hlist_del_rcu(&mp->hlist[mdb->ver]); 255eb1d1641SHerbert Xu mdb->size--; 256eb1d1641SHerbert Xu 257eb1d1641SHerbert Xu call_rcu_bh(&mp->rcu, br_multicast_free_group); 258eb1d1641SHerbert Xu 259eb1d1641SHerbert Xu out: 260eb1d1641SHerbert Xu spin_unlock(&br->multicast_lock); 261eb1d1641SHerbert Xu } 262eb1d1641SHerbert Xu 263eb1d1641SHerbert Xu static void br_multicast_del_pg(struct net_bridge *br, 264eb1d1641SHerbert Xu struct net_bridge_port_group *pg) 265eb1d1641SHerbert Xu { 266e8051688SEric Dumazet struct net_bridge_mdb_htable *mdb; 267eb1d1641SHerbert Xu struct net_bridge_mdb_entry *mp; 268eb1d1641SHerbert Xu struct net_bridge_port_group *p; 269e8051688SEric Dumazet struct net_bridge_port_group __rcu **pp; 270e8051688SEric Dumazet 271e8051688SEric Dumazet mdb = mlock_dereference(br->mdb, br); 272eb1d1641SHerbert Xu 2738ef2a9a5SYOSHIFUJI Hideaki mp = br_mdb_ip_get(mdb, &pg->addr); 274eb1d1641SHerbert Xu if (WARN_ON(!mp)) 275eb1d1641SHerbert Xu return; 276eb1d1641SHerbert Xu 277e8051688SEric Dumazet for (pp = &mp->ports; 278e8051688SEric Dumazet (p = mlock_dereference(*pp, br)) != NULL; 279e8051688SEric Dumazet pp = &p->next) { 280eb1d1641SHerbert Xu if (p != pg) 281eb1d1641SHerbert Xu continue; 282eb1d1641SHerbert Xu 28383f6a740Sstephen hemminger rcu_assign_pointer(*pp, p->next); 284eb1d1641SHerbert Xu hlist_del_init(&p->mglist); 285eb1d1641SHerbert Xu del_timer(&p->timer); 2869e8430f8SElad Raz br_mdb_notify(br->dev, p, RTM_DELMDB); 287eb1d1641SHerbert Xu call_rcu_bh(&p->rcu, br_multicast_free_pg); 288eb1d1641SHerbert Xu 289454594f3SLinus Lüssing if (!mp->ports && !mp->mglist && 290eb1d1641SHerbert Xu netif_running(br->dev)) 291eb1d1641SHerbert Xu mod_timer(&mp->timer, jiffies); 292eb1d1641SHerbert Xu 293eb1d1641SHerbert Xu return; 294eb1d1641SHerbert Xu } 295eb1d1641SHerbert Xu 296eb1d1641SHerbert Xu WARN_ON(1); 297eb1d1641SHerbert Xu } 298eb1d1641SHerbert Xu 299eb1d1641SHerbert Xu static void br_multicast_port_group_expired(unsigned long data) 300eb1d1641SHerbert Xu { 301eb1d1641SHerbert Xu struct net_bridge_port_group *pg = (void *)data; 302eb1d1641SHerbert Xu struct net_bridge *br = pg->port->br; 303eb1d1641SHerbert Xu 304eb1d1641SHerbert Xu spin_lock(&br->multicast_lock); 305eb1d1641SHerbert Xu if (!netif_running(br->dev) || timer_pending(&pg->timer) || 3069d06b6d8SElad Raz hlist_unhashed(&pg->mglist) || pg->flags & MDB_PG_FLAGS_PERMANENT) 307eb1d1641SHerbert Xu goto out; 308eb1d1641SHerbert Xu 309eb1d1641SHerbert Xu br_multicast_del_pg(br, pg); 310eb1d1641SHerbert Xu 311eb1d1641SHerbert Xu out: 312eb1d1641SHerbert Xu spin_unlock(&br->multicast_lock); 313eb1d1641SHerbert Xu } 314eb1d1641SHerbert Xu 315e8051688SEric Dumazet static int br_mdb_rehash(struct net_bridge_mdb_htable __rcu **mdbp, int max, 316eb1d1641SHerbert Xu int elasticity) 317eb1d1641SHerbert Xu { 318e8051688SEric Dumazet struct net_bridge_mdb_htable *old = rcu_dereference_protected(*mdbp, 1); 319eb1d1641SHerbert Xu struct net_bridge_mdb_htable *mdb; 320eb1d1641SHerbert Xu int err; 321eb1d1641SHerbert Xu 322eb1d1641SHerbert Xu mdb = kmalloc(sizeof(*mdb), GFP_ATOMIC); 323eb1d1641SHerbert Xu if (!mdb) 324eb1d1641SHerbert Xu return -ENOMEM; 325eb1d1641SHerbert Xu 326eb1d1641SHerbert Xu mdb->max = max; 327eb1d1641SHerbert Xu mdb->old = old; 328eb1d1641SHerbert Xu 329eb1d1641SHerbert Xu mdb->mhash = kzalloc(max * sizeof(*mdb->mhash), GFP_ATOMIC); 330eb1d1641SHerbert Xu if (!mdb->mhash) { 331eb1d1641SHerbert Xu kfree(mdb); 332eb1d1641SHerbert Xu return -ENOMEM; 333eb1d1641SHerbert Xu } 334eb1d1641SHerbert Xu 335eb1d1641SHerbert Xu mdb->size = old ? old->size : 0; 336eb1d1641SHerbert Xu mdb->ver = old ? old->ver ^ 1 : 0; 337eb1d1641SHerbert Xu 338eb1d1641SHerbert Xu if (!old || elasticity) 339eb1d1641SHerbert Xu get_random_bytes(&mdb->secret, sizeof(mdb->secret)); 340eb1d1641SHerbert Xu else 341eb1d1641SHerbert Xu mdb->secret = old->secret; 342eb1d1641SHerbert Xu 343eb1d1641SHerbert Xu if (!old) 344eb1d1641SHerbert Xu goto out; 345eb1d1641SHerbert Xu 346eb1d1641SHerbert Xu err = br_mdb_copy(mdb, old, elasticity); 347eb1d1641SHerbert Xu if (err) { 348eb1d1641SHerbert Xu kfree(mdb->mhash); 349eb1d1641SHerbert Xu kfree(mdb); 350eb1d1641SHerbert Xu return err; 351eb1d1641SHerbert Xu } 352eb1d1641SHerbert Xu 3532ce297fcSCong Wang br_mdb_rehash_seq++; 354eb1d1641SHerbert Xu call_rcu_bh(&mdb->rcu, br_mdb_free); 355eb1d1641SHerbert Xu 356eb1d1641SHerbert Xu out: 357eb1d1641SHerbert Xu rcu_assign_pointer(*mdbp, mdb); 358eb1d1641SHerbert Xu 359eb1d1641SHerbert Xu return 0; 360eb1d1641SHerbert Xu } 361eb1d1641SHerbert Xu 3628ef2a9a5SYOSHIFUJI Hideaki static struct sk_buff *br_ip4_multicast_alloc_query(struct net_bridge *br, 363eb1d1641SHerbert Xu __be32 group) 364eb1d1641SHerbert Xu { 365eb1d1641SHerbert Xu struct sk_buff *skb; 366eb1d1641SHerbert Xu struct igmphdr *ih; 367eb1d1641SHerbert Xu struct ethhdr *eth; 368eb1d1641SHerbert Xu struct iphdr *iph; 369eb1d1641SHerbert Xu 370eb1d1641SHerbert Xu skb = netdev_alloc_skb_ip_align(br->dev, sizeof(*eth) + sizeof(*iph) + 371eb1d1641SHerbert Xu sizeof(*ih) + 4); 372eb1d1641SHerbert Xu if (!skb) 373eb1d1641SHerbert Xu goto out; 374eb1d1641SHerbert Xu 375eb1d1641SHerbert Xu skb->protocol = htons(ETH_P_IP); 376eb1d1641SHerbert Xu 377eb1d1641SHerbert Xu skb_reset_mac_header(skb); 378eb1d1641SHerbert Xu eth = eth_hdr(skb); 379eb1d1641SHerbert Xu 380e5a727f6SJoe Perches ether_addr_copy(eth->h_source, br->dev->dev_addr); 381eb1d1641SHerbert Xu eth->h_dest[0] = 1; 382eb1d1641SHerbert Xu eth->h_dest[1] = 0; 383eb1d1641SHerbert Xu eth->h_dest[2] = 0x5e; 384eb1d1641SHerbert Xu eth->h_dest[3] = 0; 385eb1d1641SHerbert Xu eth->h_dest[4] = 0; 386eb1d1641SHerbert Xu eth->h_dest[5] = 1; 387eb1d1641SHerbert Xu eth->h_proto = htons(ETH_P_IP); 388eb1d1641SHerbert Xu skb_put(skb, sizeof(*eth)); 389eb1d1641SHerbert Xu 390eb1d1641SHerbert Xu skb_set_network_header(skb, skb->len); 391eb1d1641SHerbert Xu iph = ip_hdr(skb); 392eb1d1641SHerbert Xu 393eb1d1641SHerbert Xu iph->version = 4; 394eb1d1641SHerbert Xu iph->ihl = 6; 395eb1d1641SHerbert Xu iph->tos = 0xc0; 396eb1d1641SHerbert Xu iph->tot_len = htons(sizeof(*iph) + sizeof(*ih) + 4); 397eb1d1641SHerbert Xu iph->id = 0; 398eb1d1641SHerbert Xu iph->frag_off = htons(IP_DF); 399eb1d1641SHerbert Xu iph->ttl = 1; 400eb1d1641SHerbert Xu iph->protocol = IPPROTO_IGMP; 4011c8ad5bfSCong Wang iph->saddr = br->multicast_query_use_ifaddr ? 4021c8ad5bfSCong Wang inet_select_addr(br->dev, 0, RT_SCOPE_LINK) : 0; 403eb1d1641SHerbert Xu iph->daddr = htonl(INADDR_ALLHOSTS_GROUP); 404eb1d1641SHerbert Xu ((u8 *)&iph[1])[0] = IPOPT_RA; 405eb1d1641SHerbert Xu ((u8 *)&iph[1])[1] = 4; 406eb1d1641SHerbert Xu ((u8 *)&iph[1])[2] = 0; 407eb1d1641SHerbert Xu ((u8 *)&iph[1])[3] = 0; 408eb1d1641SHerbert Xu ip_send_check(iph); 409eb1d1641SHerbert Xu skb_put(skb, 24); 410eb1d1641SHerbert Xu 411eb1d1641SHerbert Xu skb_set_transport_header(skb, skb->len); 412eb1d1641SHerbert Xu ih = igmp_hdr(skb); 413eb1d1641SHerbert Xu ih->type = IGMP_HOST_MEMBERSHIP_QUERY; 414eb1d1641SHerbert Xu ih->code = (group ? br->multicast_last_member_interval : 415eb1d1641SHerbert Xu br->multicast_query_response_interval) / 416eb1d1641SHerbert Xu (HZ / IGMP_TIMER_SCALE); 417eb1d1641SHerbert Xu ih->group = group; 418eb1d1641SHerbert Xu ih->csum = 0; 419eb1d1641SHerbert Xu ih->csum = ip_compute_csum((void *)ih, sizeof(struct igmphdr)); 420eb1d1641SHerbert Xu skb_put(skb, sizeof(*ih)); 421eb1d1641SHerbert Xu 422eb1d1641SHerbert Xu __skb_pull(skb, sizeof(*eth)); 423eb1d1641SHerbert Xu 424eb1d1641SHerbert Xu out: 425eb1d1641SHerbert Xu return skb; 426eb1d1641SHerbert Xu } 427eb1d1641SHerbert Xu 428dfd56b8bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6) 42908b202b6SYOSHIFUJI Hideaki static struct sk_buff *br_ip6_multicast_alloc_query(struct net_bridge *br, 430b71d1d42SEric Dumazet const struct in6_addr *group) 43108b202b6SYOSHIFUJI Hideaki { 43208b202b6SYOSHIFUJI Hideaki struct sk_buff *skb; 43308b202b6SYOSHIFUJI Hideaki struct ipv6hdr *ip6h; 43408b202b6SYOSHIFUJI Hideaki struct mld_msg *mldq; 43508b202b6SYOSHIFUJI Hideaki struct ethhdr *eth; 43608b202b6SYOSHIFUJI Hideaki u8 *hopopt; 43708b202b6SYOSHIFUJI Hideaki unsigned long interval; 43808b202b6SYOSHIFUJI Hideaki 43908b202b6SYOSHIFUJI Hideaki skb = netdev_alloc_skb_ip_align(br->dev, sizeof(*eth) + sizeof(*ip6h) + 44008b202b6SYOSHIFUJI Hideaki 8 + sizeof(*mldq)); 44108b202b6SYOSHIFUJI Hideaki if (!skb) 44208b202b6SYOSHIFUJI Hideaki goto out; 44308b202b6SYOSHIFUJI Hideaki 44408b202b6SYOSHIFUJI Hideaki skb->protocol = htons(ETH_P_IPV6); 44508b202b6SYOSHIFUJI Hideaki 44608b202b6SYOSHIFUJI Hideaki /* Ethernet header */ 44708b202b6SYOSHIFUJI Hideaki skb_reset_mac_header(skb); 44808b202b6SYOSHIFUJI Hideaki eth = eth_hdr(skb); 44908b202b6SYOSHIFUJI Hideaki 450e5a727f6SJoe Perches ether_addr_copy(eth->h_source, br->dev->dev_addr); 45108b202b6SYOSHIFUJI Hideaki eth->h_proto = htons(ETH_P_IPV6); 45208b202b6SYOSHIFUJI Hideaki skb_put(skb, sizeof(*eth)); 45308b202b6SYOSHIFUJI Hideaki 45408b202b6SYOSHIFUJI Hideaki /* IPv6 header + HbH option */ 45508b202b6SYOSHIFUJI Hideaki skb_set_network_header(skb, skb->len); 45608b202b6SYOSHIFUJI Hideaki ip6h = ipv6_hdr(skb); 45708b202b6SYOSHIFUJI Hideaki 45808b202b6SYOSHIFUJI Hideaki *(__force __be32 *)ip6h = htonl(0x60000000); 45976d66158SDavid Stevens ip6h->payload_len = htons(8 + sizeof(*mldq)); 46008b202b6SYOSHIFUJI Hideaki ip6h->nexthdr = IPPROTO_HOPOPTS; 46108b202b6SYOSHIFUJI Hideaki ip6h->hop_limit = 1; 462a7bff75bSLinus Lüssing ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1)); 463d1d81d4cSUlrich Weber if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0, 464d1d81d4cSUlrich Weber &ip6h->saddr)) { 465d1d81d4cSUlrich Weber kfree_skb(skb); 466d1d81d4cSUlrich Weber return NULL; 467d1d81d4cSUlrich Weber } 46836cff5a1SLinus Lüssing ipv6_eth_mc_map(&ip6h->daddr, eth->h_dest); 46908b202b6SYOSHIFUJI Hideaki 47008b202b6SYOSHIFUJI Hideaki hopopt = (u8 *)(ip6h + 1); 47108b202b6SYOSHIFUJI Hideaki hopopt[0] = IPPROTO_ICMPV6; /* next hdr */ 47208b202b6SYOSHIFUJI Hideaki hopopt[1] = 0; /* length of HbH */ 47308b202b6SYOSHIFUJI Hideaki hopopt[2] = IPV6_TLV_ROUTERALERT; /* Router Alert */ 47408b202b6SYOSHIFUJI Hideaki hopopt[3] = 2; /* Length of RA Option */ 47508b202b6SYOSHIFUJI Hideaki hopopt[4] = 0; /* Type = 0x0000 (MLD) */ 47608b202b6SYOSHIFUJI Hideaki hopopt[5] = 0; 4771de5a71cSEldad Zack hopopt[6] = IPV6_TLV_PAD1; /* Pad1 */ 4781de5a71cSEldad Zack hopopt[7] = IPV6_TLV_PAD1; /* Pad1 */ 47908b202b6SYOSHIFUJI Hideaki 48008b202b6SYOSHIFUJI Hideaki skb_put(skb, sizeof(*ip6h) + 8); 48108b202b6SYOSHIFUJI Hideaki 48208b202b6SYOSHIFUJI Hideaki /* ICMPv6 */ 48308b202b6SYOSHIFUJI Hideaki skb_set_transport_header(skb, skb->len); 48408b202b6SYOSHIFUJI Hideaki mldq = (struct mld_msg *) icmp6_hdr(skb); 48508b202b6SYOSHIFUJI Hideaki 48632de868cSLinus Lüssing interval = ipv6_addr_any(group) ? 48732de868cSLinus Lüssing br->multicast_query_response_interval : 48832de868cSLinus Lüssing br->multicast_last_member_interval; 48908b202b6SYOSHIFUJI Hideaki 49008b202b6SYOSHIFUJI Hideaki mldq->mld_type = ICMPV6_MGM_QUERY; 49108b202b6SYOSHIFUJI Hideaki mldq->mld_code = 0; 49208b202b6SYOSHIFUJI Hideaki mldq->mld_cksum = 0; 49308b202b6SYOSHIFUJI Hideaki mldq->mld_maxdelay = htons((u16)jiffies_to_msecs(interval)); 49408b202b6SYOSHIFUJI Hideaki mldq->mld_reserved = 0; 4954e3fd7a0SAlexey Dobriyan mldq->mld_mca = *group; 49608b202b6SYOSHIFUJI Hideaki 49708b202b6SYOSHIFUJI Hideaki /* checksum */ 49808b202b6SYOSHIFUJI Hideaki mldq->mld_cksum = csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr, 49908b202b6SYOSHIFUJI Hideaki sizeof(*mldq), IPPROTO_ICMPV6, 50008b202b6SYOSHIFUJI Hideaki csum_partial(mldq, 50108b202b6SYOSHIFUJI Hideaki sizeof(*mldq), 0)); 50208b202b6SYOSHIFUJI Hideaki skb_put(skb, sizeof(*mldq)); 50308b202b6SYOSHIFUJI Hideaki 50408b202b6SYOSHIFUJI Hideaki __skb_pull(skb, sizeof(*eth)); 50508b202b6SYOSHIFUJI Hideaki 50608b202b6SYOSHIFUJI Hideaki out: 50708b202b6SYOSHIFUJI Hideaki return skb; 50808b202b6SYOSHIFUJI Hideaki } 50908b202b6SYOSHIFUJI Hideaki #endif 51008b202b6SYOSHIFUJI Hideaki 5118ef2a9a5SYOSHIFUJI Hideaki static struct sk_buff *br_multicast_alloc_query(struct net_bridge *br, 5128ef2a9a5SYOSHIFUJI Hideaki struct br_ip *addr) 5138ef2a9a5SYOSHIFUJI Hideaki { 5148ef2a9a5SYOSHIFUJI Hideaki switch (addr->proto) { 5158ef2a9a5SYOSHIFUJI Hideaki case htons(ETH_P_IP): 5168ef2a9a5SYOSHIFUJI Hideaki return br_ip4_multicast_alloc_query(br, addr->u.ip4); 517dfd56b8bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6) 51808b202b6SYOSHIFUJI Hideaki case htons(ETH_P_IPV6): 51908b202b6SYOSHIFUJI Hideaki return br_ip6_multicast_alloc_query(br, &addr->u.ip6); 52008b202b6SYOSHIFUJI Hideaki #endif 5218ef2a9a5SYOSHIFUJI Hideaki } 5228ef2a9a5SYOSHIFUJI Hideaki return NULL; 5238ef2a9a5SYOSHIFUJI Hideaki } 5248ef2a9a5SYOSHIFUJI Hideaki 525eb1d1641SHerbert Xu static struct net_bridge_mdb_entry *br_multicast_get_group( 5268ef2a9a5SYOSHIFUJI Hideaki struct net_bridge *br, struct net_bridge_port *port, 5278ef2a9a5SYOSHIFUJI Hideaki struct br_ip *group, int hash) 528eb1d1641SHerbert Xu { 529e8051688SEric Dumazet struct net_bridge_mdb_htable *mdb; 530eb1d1641SHerbert Xu struct net_bridge_mdb_entry *mp; 53195c96174SEric Dumazet unsigned int count = 0; 53295c96174SEric Dumazet unsigned int max; 533eb1d1641SHerbert Xu int elasticity; 534eb1d1641SHerbert Xu int err; 535eb1d1641SHerbert Xu 536e8051688SEric Dumazet mdb = rcu_dereference_protected(br->mdb, 1); 537b67bfe0dSSasha Levin hlist_for_each_entry(mp, &mdb->mhash[hash], hlist[mdb->ver]) { 538eb1d1641SHerbert Xu count++; 5398ef2a9a5SYOSHIFUJI Hideaki if (unlikely(br_ip_equal(group, &mp->addr))) 540eb1d1641SHerbert Xu return mp; 541eb1d1641SHerbert Xu } 542eb1d1641SHerbert Xu 543eb1d1641SHerbert Xu elasticity = 0; 544eb1d1641SHerbert Xu max = mdb->max; 545eb1d1641SHerbert Xu 546eb1d1641SHerbert Xu if (unlikely(count > br->hash_elasticity && count)) { 547eb1d1641SHerbert Xu if (net_ratelimit()) 54828a16c97Sstephen hemminger br_info(br, "Multicast hash table " 549eb1d1641SHerbert Xu "chain limit reached: %s\n", 55028a16c97Sstephen hemminger port ? port->dev->name : br->dev->name); 551eb1d1641SHerbert Xu 552eb1d1641SHerbert Xu elasticity = br->hash_elasticity; 553eb1d1641SHerbert Xu } 554eb1d1641SHerbert Xu 555eb1d1641SHerbert Xu if (mdb->size >= max) { 556eb1d1641SHerbert Xu max *= 2; 557036be6dbSThomas Graf if (unlikely(max > br->hash_max)) { 558036be6dbSThomas Graf br_warn(br, "Multicast hash table maximum of %d " 559036be6dbSThomas Graf "reached, disabling snooping: %s\n", 560036be6dbSThomas Graf br->hash_max, 561036be6dbSThomas Graf port ? port->dev->name : br->dev->name); 562eb1d1641SHerbert Xu err = -E2BIG; 563eb1d1641SHerbert Xu disable: 564eb1d1641SHerbert Xu br->multicast_disabled = 1; 565eb1d1641SHerbert Xu goto err; 566eb1d1641SHerbert Xu } 567eb1d1641SHerbert Xu } 568eb1d1641SHerbert Xu 569eb1d1641SHerbert Xu if (max > mdb->max || elasticity) { 570eb1d1641SHerbert Xu if (mdb->old) { 571eb1d1641SHerbert Xu if (net_ratelimit()) 57228a16c97Sstephen hemminger br_info(br, "Multicast hash table " 573eb1d1641SHerbert Xu "on fire: %s\n", 57428a16c97Sstephen hemminger port ? port->dev->name : br->dev->name); 575eb1d1641SHerbert Xu err = -EEXIST; 576eb1d1641SHerbert Xu goto err; 577eb1d1641SHerbert Xu } 578eb1d1641SHerbert Xu 579eb1d1641SHerbert Xu err = br_mdb_rehash(&br->mdb, max, elasticity); 580eb1d1641SHerbert Xu if (err) { 58128a16c97Sstephen hemminger br_warn(br, "Cannot rehash multicast " 58228a16c97Sstephen hemminger "hash table, disabling snooping: %s, %d, %d\n", 58328a16c97Sstephen hemminger port ? port->dev->name : br->dev->name, 584eb1d1641SHerbert Xu mdb->size, err); 585eb1d1641SHerbert Xu goto disable; 586eb1d1641SHerbert Xu } 587eb1d1641SHerbert Xu 588eb1d1641SHerbert Xu err = -EAGAIN; 589eb1d1641SHerbert Xu goto err; 590eb1d1641SHerbert Xu } 591eb1d1641SHerbert Xu 592eb1d1641SHerbert Xu return NULL; 593eb1d1641SHerbert Xu 594eb1d1641SHerbert Xu err: 595eb1d1641SHerbert Xu mp = ERR_PTR(err); 596eb1d1641SHerbert Xu return mp; 597eb1d1641SHerbert Xu } 598eb1d1641SHerbert Xu 599cfd56754SCong Wang struct net_bridge_mdb_entry *br_multicast_new_group(struct net_bridge *br, 600cfd56754SCong Wang struct net_bridge_port *port, struct br_ip *group) 601eb1d1641SHerbert Xu { 602e8051688SEric Dumazet struct net_bridge_mdb_htable *mdb; 603eb1d1641SHerbert Xu struct net_bridge_mdb_entry *mp; 604eb1d1641SHerbert Xu int hash; 6054c0833bcSTobias Klauser int err; 606eb1d1641SHerbert Xu 607e8051688SEric Dumazet mdb = rcu_dereference_protected(br->mdb, 1); 608eb1d1641SHerbert Xu if (!mdb) { 6094c0833bcSTobias Klauser err = br_mdb_rehash(&br->mdb, BR_HASH_SIZE, 0); 6104c0833bcSTobias Klauser if (err) 6114c0833bcSTobias Klauser return ERR_PTR(err); 612eb1d1641SHerbert Xu goto rehash; 613eb1d1641SHerbert Xu } 614eb1d1641SHerbert Xu 615eb1d1641SHerbert Xu hash = br_ip_hash(mdb, group); 616eb1d1641SHerbert Xu mp = br_multicast_get_group(br, port, group, hash); 617eb1d1641SHerbert Xu switch (PTR_ERR(mp)) { 618eb1d1641SHerbert Xu case 0: 619eb1d1641SHerbert Xu break; 620eb1d1641SHerbert Xu 621eb1d1641SHerbert Xu case -EAGAIN: 622eb1d1641SHerbert Xu rehash: 623e8051688SEric Dumazet mdb = rcu_dereference_protected(br->mdb, 1); 624eb1d1641SHerbert Xu hash = br_ip_hash(mdb, group); 625eb1d1641SHerbert Xu break; 626eb1d1641SHerbert Xu 627eb1d1641SHerbert Xu default: 628eb1d1641SHerbert Xu goto out; 629eb1d1641SHerbert Xu } 630eb1d1641SHerbert Xu 631eb1d1641SHerbert Xu mp = kzalloc(sizeof(*mp), GFP_ATOMIC); 632eb1d1641SHerbert Xu if (unlikely(!mp)) 6334c0833bcSTobias Klauser return ERR_PTR(-ENOMEM); 634eb1d1641SHerbert Xu 635eb1d1641SHerbert Xu mp->br = br; 6368ef2a9a5SYOSHIFUJI Hideaki mp->addr = *group; 6371faabf2aSEric Dumazet setup_timer(&mp->timer, br_multicast_group_expired, 6381faabf2aSEric Dumazet (unsigned long)mp); 6391faabf2aSEric Dumazet 640eb1d1641SHerbert Xu hlist_add_head_rcu(&mp->hlist[mdb->ver], &mdb->mhash[hash]); 641eb1d1641SHerbert Xu mdb->size++; 642eb1d1641SHerbert Xu 643eb1d1641SHerbert Xu out: 644eb1d1641SHerbert Xu return mp; 645eb1d1641SHerbert Xu } 646eb1d1641SHerbert Xu 647cfd56754SCong Wang struct net_bridge_port_group *br_multicast_new_port_group( 648cfd56754SCong Wang struct net_bridge_port *port, 649cfd56754SCong Wang struct br_ip *group, 650ccb1c31aSAmerigo Wang struct net_bridge_port_group __rcu *next, 6519d06b6d8SElad Raz unsigned char flags) 652cfd56754SCong Wang { 653cfd56754SCong Wang struct net_bridge_port_group *p; 654cfd56754SCong Wang 655cfd56754SCong Wang p = kzalloc(sizeof(*p), GFP_ATOMIC); 656cfd56754SCong Wang if (unlikely(!p)) 657cfd56754SCong Wang return NULL; 658cfd56754SCong Wang 659cfd56754SCong Wang p->addr = *group; 660cfd56754SCong Wang p->port = port; 6619d06b6d8SElad Raz p->flags = flags; 662eca2a43bSstephen hemminger rcu_assign_pointer(p->next, next); 663cfd56754SCong Wang hlist_add_head(&p->mglist, &port->mglist); 664cfd56754SCong Wang setup_timer(&p->timer, br_multicast_port_group_expired, 665cfd56754SCong Wang (unsigned long)p); 666cfd56754SCong Wang return p; 667cfd56754SCong Wang } 668cfd56754SCong Wang 669eb1d1641SHerbert Xu static int br_multicast_add_group(struct net_bridge *br, 6708ef2a9a5SYOSHIFUJI Hideaki struct net_bridge_port *port, 6718ef2a9a5SYOSHIFUJI Hideaki struct br_ip *group) 672eb1d1641SHerbert Xu { 673eb1d1641SHerbert Xu struct net_bridge_mdb_entry *mp; 674eb1d1641SHerbert Xu struct net_bridge_port_group *p; 675e8051688SEric Dumazet struct net_bridge_port_group __rcu **pp; 676454594f3SLinus Lüssing unsigned long now = jiffies; 677eb1d1641SHerbert Xu int err; 678eb1d1641SHerbert Xu 679eb1d1641SHerbert Xu spin_lock(&br->multicast_lock); 680eb1d1641SHerbert Xu if (!netif_running(br->dev) || 681eb1d1641SHerbert Xu (port && port->state == BR_STATE_DISABLED)) 682eb1d1641SHerbert Xu goto out; 683eb1d1641SHerbert Xu 684eb1d1641SHerbert Xu mp = br_multicast_new_group(br, port, group); 685eb1d1641SHerbert Xu err = PTR_ERR(mp); 6864c0833bcSTobias Klauser if (IS_ERR(mp)) 687eb1d1641SHerbert Xu goto err; 688eb1d1641SHerbert Xu 689eb1d1641SHerbert Xu if (!port) { 6908a870178SHerbert Xu mp->mglist = true; 691454594f3SLinus Lüssing mod_timer(&mp->timer, now + br->multicast_membership_interval); 692eb1d1641SHerbert Xu goto out; 693eb1d1641SHerbert Xu } 694eb1d1641SHerbert Xu 695e8051688SEric Dumazet for (pp = &mp->ports; 696e8051688SEric Dumazet (p = mlock_dereference(*pp, br)) != NULL; 697e8051688SEric Dumazet pp = &p->next) { 698eb1d1641SHerbert Xu if (p->port == port) 699454594f3SLinus Lüssing goto found; 700eb1d1641SHerbert Xu if ((unsigned long)p->port < (unsigned long)port) 701eb1d1641SHerbert Xu break; 702eb1d1641SHerbert Xu } 703eb1d1641SHerbert Xu 7049d06b6d8SElad Raz p = br_multicast_new_port_group(port, group, *pp, 0); 705eb1d1641SHerbert Xu if (unlikely(!p)) 706eb1d1641SHerbert Xu goto err; 707eb1d1641SHerbert Xu rcu_assign_pointer(*pp, p); 7089e8430f8SElad Raz br_mdb_notify(br->dev, p, RTM_NEWMDB); 709eb1d1641SHerbert Xu 710454594f3SLinus Lüssing found: 711454594f3SLinus Lüssing mod_timer(&p->timer, now + br->multicast_membership_interval); 712eb1d1641SHerbert Xu out: 713eb1d1641SHerbert Xu err = 0; 714eb1d1641SHerbert Xu 715eb1d1641SHerbert Xu err: 716eb1d1641SHerbert Xu spin_unlock(&br->multicast_lock); 717eb1d1641SHerbert Xu return err; 718eb1d1641SHerbert Xu } 719eb1d1641SHerbert Xu 7208ef2a9a5SYOSHIFUJI Hideaki static int br_ip4_multicast_add_group(struct net_bridge *br, 7218ef2a9a5SYOSHIFUJI Hideaki struct net_bridge_port *port, 722b0e9a30dSVlad Yasevich __be32 group, 723b0e9a30dSVlad Yasevich __u16 vid) 7248ef2a9a5SYOSHIFUJI Hideaki { 7258ef2a9a5SYOSHIFUJI Hideaki struct br_ip br_group; 7268ef2a9a5SYOSHIFUJI Hideaki 7278ef2a9a5SYOSHIFUJI Hideaki if (ipv4_is_local_multicast(group)) 7288ef2a9a5SYOSHIFUJI Hideaki return 0; 7298ef2a9a5SYOSHIFUJI Hideaki 7308ef2a9a5SYOSHIFUJI Hideaki br_group.u.ip4 = group; 7318ef2a9a5SYOSHIFUJI Hideaki br_group.proto = htons(ETH_P_IP); 732b0e9a30dSVlad Yasevich br_group.vid = vid; 7338ef2a9a5SYOSHIFUJI Hideaki 7348ef2a9a5SYOSHIFUJI Hideaki return br_multicast_add_group(br, port, &br_group); 7358ef2a9a5SYOSHIFUJI Hideaki } 7368ef2a9a5SYOSHIFUJI Hideaki 737dfd56b8bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6) 73808b202b6SYOSHIFUJI Hideaki static int br_ip6_multicast_add_group(struct net_bridge *br, 73908b202b6SYOSHIFUJI Hideaki struct net_bridge_port *port, 740b0e9a30dSVlad Yasevich const struct in6_addr *group, 741b0e9a30dSVlad Yasevich __u16 vid) 74208b202b6SYOSHIFUJI Hideaki { 74308b202b6SYOSHIFUJI Hideaki struct br_ip br_group; 74408b202b6SYOSHIFUJI Hideaki 7453c3769e6SLinus Lüssing if (ipv6_addr_is_ll_all_nodes(group)) 74608b202b6SYOSHIFUJI Hideaki return 0; 74708b202b6SYOSHIFUJI Hideaki 7484e3fd7a0SAlexey Dobriyan br_group.u.ip6 = *group; 7499cc6e0c4SLinus Lüssing br_group.proto = htons(ETH_P_IPV6); 750b0e9a30dSVlad Yasevich br_group.vid = vid; 75108b202b6SYOSHIFUJI Hideaki 75208b202b6SYOSHIFUJI Hideaki return br_multicast_add_group(br, port, &br_group); 75308b202b6SYOSHIFUJI Hideaki } 75408b202b6SYOSHIFUJI Hideaki #endif 75508b202b6SYOSHIFUJI Hideaki 756eb1d1641SHerbert Xu static void br_multicast_router_expired(unsigned long data) 757eb1d1641SHerbert Xu { 758eb1d1641SHerbert Xu struct net_bridge_port *port = (void *)data; 759eb1d1641SHerbert Xu struct net_bridge *br = port->br; 760eb1d1641SHerbert Xu 761eb1d1641SHerbert Xu spin_lock(&br->multicast_lock); 7627f0aec7aSNikolay Aleksandrov if (port->multicast_router != MDB_RTR_TYPE_TEMP_QUERY || 763eb1d1641SHerbert Xu timer_pending(&port->multicast_router_timer) || 764eb1d1641SHerbert Xu hlist_unhashed(&port->rlist)) 765eb1d1641SHerbert Xu goto out; 766eb1d1641SHerbert Xu 767eb1d1641SHerbert Xu hlist_del_init_rcu(&port->rlist); 768949f1e39SSatish Ashok br_rtr_notify(br->dev, port, RTM_DELMDB); 769eb1d1641SHerbert Xu 770eb1d1641SHerbert Xu out: 771eb1d1641SHerbert Xu spin_unlock(&br->multicast_lock); 772eb1d1641SHerbert Xu } 773eb1d1641SHerbert Xu 774eb1d1641SHerbert Xu static void br_multicast_local_router_expired(unsigned long data) 775eb1d1641SHerbert Xu { 776eb1d1641SHerbert Xu } 777eb1d1641SHerbert Xu 778cc0fdd80SLinus Lüssing static void br_multicast_querier_expired(struct net_bridge *br, 77990010b36SLinus Lüssing struct bridge_mcast_own_query *query) 780c83b8fabSHerbert Xu { 781c83b8fabSHerbert Xu spin_lock(&br->multicast_lock); 782c83b8fabSHerbert Xu if (!netif_running(br->dev) || br->multicast_disabled) 783c83b8fabSHerbert Xu goto out; 784c83b8fabSHerbert Xu 785cc0fdd80SLinus Lüssing br_multicast_start_querier(br, query); 786c83b8fabSHerbert Xu 787c83b8fabSHerbert Xu out: 788c83b8fabSHerbert Xu spin_unlock(&br->multicast_lock); 789c83b8fabSHerbert Xu } 790c83b8fabSHerbert Xu 791cc0fdd80SLinus Lüssing static void br_ip4_multicast_querier_expired(unsigned long data) 792cc0fdd80SLinus Lüssing { 793cc0fdd80SLinus Lüssing struct net_bridge *br = (void *)data; 794cc0fdd80SLinus Lüssing 79590010b36SLinus Lüssing br_multicast_querier_expired(br, &br->ip4_own_query); 796cc0fdd80SLinus Lüssing } 797cc0fdd80SLinus Lüssing 798cc0fdd80SLinus Lüssing #if IS_ENABLED(CONFIG_IPV6) 799cc0fdd80SLinus Lüssing static void br_ip6_multicast_querier_expired(unsigned long data) 800cc0fdd80SLinus Lüssing { 801cc0fdd80SLinus Lüssing struct net_bridge *br = (void *)data; 802cc0fdd80SLinus Lüssing 80390010b36SLinus Lüssing br_multicast_querier_expired(br, &br->ip6_own_query); 804cc0fdd80SLinus Lüssing } 805cc0fdd80SLinus Lüssing #endif 806cc0fdd80SLinus Lüssing 807dc4eb53aSLinus Lüssing static void br_multicast_select_own_querier(struct net_bridge *br, 808dc4eb53aSLinus Lüssing struct br_ip *ip, 809dc4eb53aSLinus Lüssing struct sk_buff *skb) 810dc4eb53aSLinus Lüssing { 811dc4eb53aSLinus Lüssing if (ip->proto == htons(ETH_P_IP)) 812dc4eb53aSLinus Lüssing br->ip4_querier.addr.u.ip4 = ip_hdr(skb)->saddr; 813dc4eb53aSLinus Lüssing #if IS_ENABLED(CONFIG_IPV6) 814dc4eb53aSLinus Lüssing else 815dc4eb53aSLinus Lüssing br->ip6_querier.addr.u.ip6 = ipv6_hdr(skb)->saddr; 816dc4eb53aSLinus Lüssing #endif 817dc4eb53aSLinus Lüssing } 818dc4eb53aSLinus Lüssing 8198ef2a9a5SYOSHIFUJI Hideaki static void __br_multicast_send_query(struct net_bridge *br, 8208ef2a9a5SYOSHIFUJI Hideaki struct net_bridge_port *port, 8218ef2a9a5SYOSHIFUJI Hideaki struct br_ip *ip) 822eb1d1641SHerbert Xu { 823eb1d1641SHerbert Xu struct sk_buff *skb; 824eb1d1641SHerbert Xu 8258ef2a9a5SYOSHIFUJI Hideaki skb = br_multicast_alloc_query(br, ip); 826eb1d1641SHerbert Xu if (!skb) 8278ef2a9a5SYOSHIFUJI Hideaki return; 828eb1d1641SHerbert Xu 829eb1d1641SHerbert Xu if (port) { 830eb1d1641SHerbert Xu skb->dev = port->dev; 83129a26a56SEric W. Biederman NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_OUT, 83229a26a56SEric W. Biederman dev_net(port->dev), NULL, skb, NULL, skb->dev, 833f0b4eeceSLinus Lüssing br_dev_queue_push_xmit); 834dc4eb53aSLinus Lüssing } else { 835dc4eb53aSLinus Lüssing br_multicast_select_own_querier(br, ip, skb); 836eb1d1641SHerbert Xu netif_rx(skb); 8378ef2a9a5SYOSHIFUJI Hideaki } 838dc4eb53aSLinus Lüssing } 839eb1d1641SHerbert Xu 8408ef2a9a5SYOSHIFUJI Hideaki static void br_multicast_send_query(struct net_bridge *br, 841cc0fdd80SLinus Lüssing struct net_bridge_port *port, 84290010b36SLinus Lüssing struct bridge_mcast_own_query *own_query) 8438ef2a9a5SYOSHIFUJI Hideaki { 8448ef2a9a5SYOSHIFUJI Hideaki unsigned long time; 8458ef2a9a5SYOSHIFUJI Hideaki struct br_ip br_group; 84690010b36SLinus Lüssing struct bridge_mcast_other_query *other_query = NULL; 8478ef2a9a5SYOSHIFUJI Hideaki 8488ef2a9a5SYOSHIFUJI Hideaki if (!netif_running(br->dev) || br->multicast_disabled || 849cc0fdd80SLinus Lüssing !br->multicast_querier) 8508ef2a9a5SYOSHIFUJI Hideaki return; 8518ef2a9a5SYOSHIFUJI Hideaki 85208b202b6SYOSHIFUJI Hideaki memset(&br_group.u, 0, sizeof(br_group.u)); 8538ef2a9a5SYOSHIFUJI Hideaki 85490010b36SLinus Lüssing if (port ? (own_query == &port->ip4_own_query) : 85590010b36SLinus Lüssing (own_query == &br->ip4_own_query)) { 85690010b36SLinus Lüssing other_query = &br->ip4_other_query; 85708b202b6SYOSHIFUJI Hideaki br_group.proto = htons(ETH_P_IP); 858dfd56b8bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6) 859cc0fdd80SLinus Lüssing } else { 86090010b36SLinus Lüssing other_query = &br->ip6_other_query; 86108b202b6SYOSHIFUJI Hideaki br_group.proto = htons(ETH_P_IPV6); 86208b202b6SYOSHIFUJI Hideaki #endif 863eb1d1641SHerbert Xu } 864eb1d1641SHerbert Xu 86590010b36SLinus Lüssing if (!other_query || timer_pending(&other_query->timer)) 866cc0fdd80SLinus Lüssing return; 867cc0fdd80SLinus Lüssing 868cc0fdd80SLinus Lüssing __br_multicast_send_query(br, port, &br_group); 869cc0fdd80SLinus Lüssing 870cc0fdd80SLinus Lüssing time = jiffies; 87190010b36SLinus Lüssing time += own_query->startup_sent < br->multicast_startup_query_count ? 872cc0fdd80SLinus Lüssing br->multicast_startup_query_interval : 873cc0fdd80SLinus Lüssing br->multicast_query_interval; 87490010b36SLinus Lüssing mod_timer(&own_query->timer, time); 875cc0fdd80SLinus Lüssing } 876cc0fdd80SLinus Lüssing 87790010b36SLinus Lüssing static void 87890010b36SLinus Lüssing br_multicast_port_query_expired(struct net_bridge_port *port, 87990010b36SLinus Lüssing struct bridge_mcast_own_query *query) 880eb1d1641SHerbert Xu { 881eb1d1641SHerbert Xu struct net_bridge *br = port->br; 882eb1d1641SHerbert Xu 883eb1d1641SHerbert Xu spin_lock(&br->multicast_lock); 88402a780c0SDan Carpenter if (port->state == BR_STATE_DISABLED || 88502a780c0SDan Carpenter port->state == BR_STATE_BLOCKING) 886eb1d1641SHerbert Xu goto out; 887eb1d1641SHerbert Xu 888cc0fdd80SLinus Lüssing if (query->startup_sent < br->multicast_startup_query_count) 889cc0fdd80SLinus Lüssing query->startup_sent++; 890eb1d1641SHerbert Xu 891cc0fdd80SLinus Lüssing br_multicast_send_query(port->br, port, query); 892eb1d1641SHerbert Xu 893eb1d1641SHerbert Xu out: 894eb1d1641SHerbert Xu spin_unlock(&br->multicast_lock); 895eb1d1641SHerbert Xu } 896eb1d1641SHerbert Xu 897cc0fdd80SLinus Lüssing static void br_ip4_multicast_port_query_expired(unsigned long data) 898cc0fdd80SLinus Lüssing { 899cc0fdd80SLinus Lüssing struct net_bridge_port *port = (void *)data; 900cc0fdd80SLinus Lüssing 90190010b36SLinus Lüssing br_multicast_port_query_expired(port, &port->ip4_own_query); 902cc0fdd80SLinus Lüssing } 903cc0fdd80SLinus Lüssing 904cc0fdd80SLinus Lüssing #if IS_ENABLED(CONFIG_IPV6) 905cc0fdd80SLinus Lüssing static void br_ip6_multicast_port_query_expired(unsigned long data) 906cc0fdd80SLinus Lüssing { 907cc0fdd80SLinus Lüssing struct net_bridge_port *port = (void *)data; 908cc0fdd80SLinus Lüssing 90990010b36SLinus Lüssing br_multicast_port_query_expired(port, &port->ip6_own_query); 910cc0fdd80SLinus Lüssing } 911cc0fdd80SLinus Lüssing #endif 912cc0fdd80SLinus Lüssing 913eb1d1641SHerbert Xu void br_multicast_add_port(struct net_bridge_port *port) 914eb1d1641SHerbert Xu { 9157f0aec7aSNikolay Aleksandrov port->multicast_router = MDB_RTR_TYPE_TEMP_QUERY; 916eb1d1641SHerbert Xu 917eb1d1641SHerbert Xu setup_timer(&port->multicast_router_timer, br_multicast_router_expired, 918eb1d1641SHerbert Xu (unsigned long)port); 91990010b36SLinus Lüssing setup_timer(&port->ip4_own_query.timer, 92090010b36SLinus Lüssing br_ip4_multicast_port_query_expired, (unsigned long)port); 921cc0fdd80SLinus Lüssing #if IS_ENABLED(CONFIG_IPV6) 92290010b36SLinus Lüssing setup_timer(&port->ip6_own_query.timer, 92390010b36SLinus Lüssing br_ip6_multicast_port_query_expired, (unsigned long)port); 924cc0fdd80SLinus Lüssing #endif 925eb1d1641SHerbert Xu } 926eb1d1641SHerbert Xu 927eb1d1641SHerbert Xu void br_multicast_del_port(struct net_bridge_port *port) 928eb1d1641SHerbert Xu { 929e10177abSSatish Ashok struct net_bridge *br = port->br; 930e10177abSSatish Ashok struct net_bridge_port_group *pg; 931e10177abSSatish Ashok struct hlist_node *n; 932e10177abSSatish Ashok 933e10177abSSatish Ashok /* Take care of the remaining groups, only perm ones should be left */ 934e10177abSSatish Ashok spin_lock_bh(&br->multicast_lock); 935e10177abSSatish Ashok hlist_for_each_entry_safe(pg, n, &port->mglist, mglist) 936e10177abSSatish Ashok br_multicast_del_pg(br, pg); 937e10177abSSatish Ashok spin_unlock_bh(&br->multicast_lock); 938eb1d1641SHerbert Xu del_timer_sync(&port->multicast_router_timer); 939eb1d1641SHerbert Xu } 940eb1d1641SHerbert Xu 94190010b36SLinus Lüssing static void br_multicast_enable(struct bridge_mcast_own_query *query) 942561f1103SHerbert Xu { 943cc0fdd80SLinus Lüssing query->startup_sent = 0; 944561f1103SHerbert Xu 945cc0fdd80SLinus Lüssing if (try_to_del_timer_sync(&query->timer) >= 0 || 946cc0fdd80SLinus Lüssing del_timer(&query->timer)) 947cc0fdd80SLinus Lüssing mod_timer(&query->timer, jiffies); 948561f1103SHerbert Xu } 949561f1103SHerbert Xu 950eb1d1641SHerbert Xu void br_multicast_enable_port(struct net_bridge_port *port) 951eb1d1641SHerbert Xu { 952eb1d1641SHerbert Xu struct net_bridge *br = port->br; 953eb1d1641SHerbert Xu 954eb1d1641SHerbert Xu spin_lock(&br->multicast_lock); 955eb1d1641SHerbert Xu if (br->multicast_disabled || !netif_running(br->dev)) 956eb1d1641SHerbert Xu goto out; 957eb1d1641SHerbert Xu 95890010b36SLinus Lüssing br_multicast_enable(&port->ip4_own_query); 959cc0fdd80SLinus Lüssing #if IS_ENABLED(CONFIG_IPV6) 96090010b36SLinus Lüssing br_multicast_enable(&port->ip6_own_query); 961cc0fdd80SLinus Lüssing #endif 9627f0aec7aSNikolay Aleksandrov if (port->multicast_router == MDB_RTR_TYPE_PERM && 9637f0aec7aSNikolay Aleksandrov hlist_unhashed(&port->rlist)) 964754bc547SSatish Ashok br_multicast_add_router(br, port); 965eb1d1641SHerbert Xu 966eb1d1641SHerbert Xu out: 967eb1d1641SHerbert Xu spin_unlock(&br->multicast_lock); 968eb1d1641SHerbert Xu } 969eb1d1641SHerbert Xu 970eb1d1641SHerbert Xu void br_multicast_disable_port(struct net_bridge_port *port) 971eb1d1641SHerbert Xu { 972eb1d1641SHerbert Xu struct net_bridge *br = port->br; 973eb1d1641SHerbert Xu struct net_bridge_port_group *pg; 974b67bfe0dSSasha Levin struct hlist_node *n; 975eb1d1641SHerbert Xu 976eb1d1641SHerbert Xu spin_lock(&br->multicast_lock); 977b67bfe0dSSasha Levin hlist_for_each_entry_safe(pg, n, &port->mglist, mglist) 9789d06b6d8SElad Raz if (!(pg->flags & MDB_PG_FLAGS_PERMANENT)) 979eb1d1641SHerbert Xu br_multicast_del_pg(br, pg); 980eb1d1641SHerbert Xu 981949f1e39SSatish Ashok if (!hlist_unhashed(&port->rlist)) { 982eb1d1641SHerbert Xu hlist_del_init_rcu(&port->rlist); 983949f1e39SSatish Ashok br_rtr_notify(br->dev, port, RTM_DELMDB); 984949f1e39SSatish Ashok } 985eb1d1641SHerbert Xu del_timer(&port->multicast_router_timer); 98690010b36SLinus Lüssing del_timer(&port->ip4_own_query.timer); 987cc0fdd80SLinus Lüssing #if IS_ENABLED(CONFIG_IPV6) 98890010b36SLinus Lüssing del_timer(&port->ip6_own_query.timer); 989cc0fdd80SLinus Lüssing #endif 990eb1d1641SHerbert Xu spin_unlock(&br->multicast_lock); 991eb1d1641SHerbert Xu } 992eb1d1641SHerbert Xu 9938ef2a9a5SYOSHIFUJI Hideaki static int br_ip4_multicast_igmp3_report(struct net_bridge *br, 994eb1d1641SHerbert Xu struct net_bridge_port *port, 99506499098SVlad Yasevich struct sk_buff *skb, 99606499098SVlad Yasevich u16 vid) 997eb1d1641SHerbert Xu { 998eb1d1641SHerbert Xu struct igmpv3_report *ih; 999eb1d1641SHerbert Xu struct igmpv3_grec *grec; 1000eb1d1641SHerbert Xu int i; 1001eb1d1641SHerbert Xu int len; 1002eb1d1641SHerbert Xu int num; 1003eb1d1641SHerbert Xu int type; 1004eb1d1641SHerbert Xu int err = 0; 1005eb1d1641SHerbert Xu __be32 group; 1006eb1d1641SHerbert Xu 1007eb1d1641SHerbert Xu ih = igmpv3_report_hdr(skb); 1008eb1d1641SHerbert Xu num = ntohs(ih->ngrec); 1009c2d4fbd2SLinus Lüssing len = skb_transport_offset(skb) + sizeof(*ih); 1010eb1d1641SHerbert Xu 1011eb1d1641SHerbert Xu for (i = 0; i < num; i++) { 1012eb1d1641SHerbert Xu len += sizeof(*grec); 1013eb1d1641SHerbert Xu if (!pskb_may_pull(skb, len)) 1014eb1d1641SHerbert Xu return -EINVAL; 1015eb1d1641SHerbert Xu 1016fd218cf9SHerbert Xu grec = (void *)(skb->data + len - sizeof(*grec)); 1017eb1d1641SHerbert Xu group = grec->grec_mca; 1018eb1d1641SHerbert Xu type = grec->grec_type; 1019eb1d1641SHerbert Xu 10208eabf95cSEric Dumazet len += ntohs(grec->grec_nsrcs) * 4; 1021eb1d1641SHerbert Xu if (!pskb_may_pull(skb, len)) 1022eb1d1641SHerbert Xu return -EINVAL; 1023eb1d1641SHerbert Xu 1024eb1d1641SHerbert Xu /* We treat this as an IGMPv2 report for now. */ 1025eb1d1641SHerbert Xu switch (type) { 1026eb1d1641SHerbert Xu case IGMPV3_MODE_IS_INCLUDE: 1027eb1d1641SHerbert Xu case IGMPV3_MODE_IS_EXCLUDE: 1028eb1d1641SHerbert Xu case IGMPV3_CHANGE_TO_INCLUDE: 1029eb1d1641SHerbert Xu case IGMPV3_CHANGE_TO_EXCLUDE: 1030eb1d1641SHerbert Xu case IGMPV3_ALLOW_NEW_SOURCES: 1031eb1d1641SHerbert Xu case IGMPV3_BLOCK_OLD_SOURCES: 1032eb1d1641SHerbert Xu break; 1033eb1d1641SHerbert Xu 1034eb1d1641SHerbert Xu default: 1035eb1d1641SHerbert Xu continue; 1036eb1d1641SHerbert Xu } 1037eb1d1641SHerbert Xu 1038bc8c20acSSatish Ashok if ((type == IGMPV3_CHANGE_TO_INCLUDE || 1039bc8c20acSSatish Ashok type == IGMPV3_MODE_IS_INCLUDE) && 1040bc8c20acSSatish Ashok ntohs(grec->grec_nsrcs) == 0) { 1041bc8c20acSSatish Ashok br_ip4_multicast_leave_group(br, port, group, vid); 1042bc8c20acSSatish Ashok } else { 1043b0e9a30dSVlad Yasevich err = br_ip4_multicast_add_group(br, port, group, vid); 1044eb1d1641SHerbert Xu if (err) 1045eb1d1641SHerbert Xu break; 1046eb1d1641SHerbert Xu } 1047bc8c20acSSatish Ashok } 1048eb1d1641SHerbert Xu 1049eb1d1641SHerbert Xu return err; 1050eb1d1641SHerbert Xu } 1051eb1d1641SHerbert Xu 1052dfd56b8bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6) 105308b202b6SYOSHIFUJI Hideaki static int br_ip6_multicast_mld2_report(struct net_bridge *br, 105408b202b6SYOSHIFUJI Hideaki struct net_bridge_port *port, 105506499098SVlad Yasevich struct sk_buff *skb, 105606499098SVlad Yasevich u16 vid) 105708b202b6SYOSHIFUJI Hideaki { 105808b202b6SYOSHIFUJI Hideaki struct icmp6hdr *icmp6h; 105908b202b6SYOSHIFUJI Hideaki struct mld2_grec *grec; 106008b202b6SYOSHIFUJI Hideaki int i; 106108b202b6SYOSHIFUJI Hideaki int len; 106208b202b6SYOSHIFUJI Hideaki int num; 106308b202b6SYOSHIFUJI Hideaki int err = 0; 106408b202b6SYOSHIFUJI Hideaki 106508b202b6SYOSHIFUJI Hideaki if (!pskb_may_pull(skb, sizeof(*icmp6h))) 106608b202b6SYOSHIFUJI Hideaki return -EINVAL; 106708b202b6SYOSHIFUJI Hideaki 106808b202b6SYOSHIFUJI Hideaki icmp6h = icmp6_hdr(skb); 106908b202b6SYOSHIFUJI Hideaki num = ntohs(icmp6h->icmp6_dataun.un_data16[1]); 1070c2d4fbd2SLinus Lüssing len = skb_transport_offset(skb) + sizeof(*icmp6h); 107108b202b6SYOSHIFUJI Hideaki 107208b202b6SYOSHIFUJI Hideaki for (i = 0; i < num; i++) { 107308b202b6SYOSHIFUJI Hideaki __be16 *nsrcs, _nsrcs; 107408b202b6SYOSHIFUJI Hideaki 107508b202b6SYOSHIFUJI Hideaki nsrcs = skb_header_pointer(skb, 107608b202b6SYOSHIFUJI Hideaki len + offsetof(struct mld2_grec, 1077649e984dSLinus Lüssing grec_nsrcs), 107808b202b6SYOSHIFUJI Hideaki sizeof(_nsrcs), &_nsrcs); 107908b202b6SYOSHIFUJI Hideaki if (!nsrcs) 108008b202b6SYOSHIFUJI Hideaki return -EINVAL; 108108b202b6SYOSHIFUJI Hideaki 108208b202b6SYOSHIFUJI Hideaki if (!pskb_may_pull(skb, 108308b202b6SYOSHIFUJI Hideaki len + sizeof(*grec) + 1084d41db9f3SLinus Lüssing sizeof(struct in6_addr) * ntohs(*nsrcs))) 108508b202b6SYOSHIFUJI Hideaki return -EINVAL; 108608b202b6SYOSHIFUJI Hideaki 108708b202b6SYOSHIFUJI Hideaki grec = (struct mld2_grec *)(skb->data + len); 1088d41db9f3SLinus Lüssing len += sizeof(*grec) + 1089d41db9f3SLinus Lüssing sizeof(struct in6_addr) * ntohs(*nsrcs); 109008b202b6SYOSHIFUJI Hideaki 109108b202b6SYOSHIFUJI Hideaki /* We treat these as MLDv1 reports for now. */ 109208b202b6SYOSHIFUJI Hideaki switch (grec->grec_type) { 109308b202b6SYOSHIFUJI Hideaki case MLD2_MODE_IS_INCLUDE: 109408b202b6SYOSHIFUJI Hideaki case MLD2_MODE_IS_EXCLUDE: 109508b202b6SYOSHIFUJI Hideaki case MLD2_CHANGE_TO_INCLUDE: 109608b202b6SYOSHIFUJI Hideaki case MLD2_CHANGE_TO_EXCLUDE: 109708b202b6SYOSHIFUJI Hideaki case MLD2_ALLOW_NEW_SOURCES: 109808b202b6SYOSHIFUJI Hideaki case MLD2_BLOCK_OLD_SOURCES: 109908b202b6SYOSHIFUJI Hideaki break; 110008b202b6SYOSHIFUJI Hideaki 110108b202b6SYOSHIFUJI Hideaki default: 110208b202b6SYOSHIFUJI Hideaki continue; 110308b202b6SYOSHIFUJI Hideaki } 110408b202b6SYOSHIFUJI Hideaki 1105bc8c20acSSatish Ashok if ((grec->grec_type == MLD2_CHANGE_TO_INCLUDE || 1106bc8c20acSSatish Ashok grec->grec_type == MLD2_MODE_IS_INCLUDE) && 1107bc8c20acSSatish Ashok ntohs(*nsrcs) == 0) { 1108bc8c20acSSatish Ashok br_ip6_multicast_leave_group(br, port, &grec->grec_mca, 1109b0e9a30dSVlad Yasevich vid); 1110bc8c20acSSatish Ashok } else { 1111bc8c20acSSatish Ashok err = br_ip6_multicast_add_group(br, port, 1112bc8c20acSSatish Ashok &grec->grec_mca, vid); 1113bc8c20acSSatish Ashok if (!err) 111408b202b6SYOSHIFUJI Hideaki break; 111508b202b6SYOSHIFUJI Hideaki } 1116bc8c20acSSatish Ashok } 111708b202b6SYOSHIFUJI Hideaki 111808b202b6SYOSHIFUJI Hideaki return err; 111908b202b6SYOSHIFUJI Hideaki } 112008b202b6SYOSHIFUJI Hideaki #endif 112108b202b6SYOSHIFUJI Hideaki 1122dc4eb53aSLinus Lüssing static bool br_ip4_multicast_select_querier(struct net_bridge *br, 11232cd41431SLinus Lüssing struct net_bridge_port *port, 1124dc4eb53aSLinus Lüssing __be32 saddr) 1125dc4eb53aSLinus Lüssing { 1126dc4eb53aSLinus Lüssing if (!timer_pending(&br->ip4_own_query.timer) && 1127dc4eb53aSLinus Lüssing !timer_pending(&br->ip4_other_query.timer)) 1128dc4eb53aSLinus Lüssing goto update; 1129dc4eb53aSLinus Lüssing 1130dc4eb53aSLinus Lüssing if (!br->ip4_querier.addr.u.ip4) 1131dc4eb53aSLinus Lüssing goto update; 1132dc4eb53aSLinus Lüssing 1133dc4eb53aSLinus Lüssing if (ntohl(saddr) <= ntohl(br->ip4_querier.addr.u.ip4)) 1134dc4eb53aSLinus Lüssing goto update; 1135dc4eb53aSLinus Lüssing 1136dc4eb53aSLinus Lüssing return false; 1137dc4eb53aSLinus Lüssing 1138dc4eb53aSLinus Lüssing update: 1139dc4eb53aSLinus Lüssing br->ip4_querier.addr.u.ip4 = saddr; 1140dc4eb53aSLinus Lüssing 11412cd41431SLinus Lüssing /* update protected by general multicast_lock by caller */ 11422cd41431SLinus Lüssing rcu_assign_pointer(br->ip4_querier.port, port); 11432cd41431SLinus Lüssing 1144dc4eb53aSLinus Lüssing return true; 1145dc4eb53aSLinus Lüssing } 1146dc4eb53aSLinus Lüssing 1147dc4eb53aSLinus Lüssing #if IS_ENABLED(CONFIG_IPV6) 1148dc4eb53aSLinus Lüssing static bool br_ip6_multicast_select_querier(struct net_bridge *br, 11492cd41431SLinus Lüssing struct net_bridge_port *port, 1150dc4eb53aSLinus Lüssing struct in6_addr *saddr) 1151dc4eb53aSLinus Lüssing { 1152dc4eb53aSLinus Lüssing if (!timer_pending(&br->ip6_own_query.timer) && 1153dc4eb53aSLinus Lüssing !timer_pending(&br->ip6_other_query.timer)) 1154dc4eb53aSLinus Lüssing goto update; 1155dc4eb53aSLinus Lüssing 1156dc4eb53aSLinus Lüssing if (ipv6_addr_cmp(saddr, &br->ip6_querier.addr.u.ip6) <= 0) 1157dc4eb53aSLinus Lüssing goto update; 1158dc4eb53aSLinus Lüssing 1159dc4eb53aSLinus Lüssing return false; 1160dc4eb53aSLinus Lüssing 1161dc4eb53aSLinus Lüssing update: 1162dc4eb53aSLinus Lüssing br->ip6_querier.addr.u.ip6 = *saddr; 1163dc4eb53aSLinus Lüssing 11642cd41431SLinus Lüssing /* update protected by general multicast_lock by caller */ 11652cd41431SLinus Lüssing rcu_assign_pointer(br->ip6_querier.port, port); 11662cd41431SLinus Lüssing 1167dc4eb53aSLinus Lüssing return true; 1168dc4eb53aSLinus Lüssing } 1169dc4eb53aSLinus Lüssing #endif 1170dc4eb53aSLinus Lüssing 1171dc4eb53aSLinus Lüssing static bool br_multicast_select_querier(struct net_bridge *br, 11722cd41431SLinus Lüssing struct net_bridge_port *port, 1173dc4eb53aSLinus Lüssing struct br_ip *saddr) 1174dc4eb53aSLinus Lüssing { 1175dc4eb53aSLinus Lüssing switch (saddr->proto) { 1176dc4eb53aSLinus Lüssing case htons(ETH_P_IP): 11772cd41431SLinus Lüssing return br_ip4_multicast_select_querier(br, port, saddr->u.ip4); 1178dc4eb53aSLinus Lüssing #if IS_ENABLED(CONFIG_IPV6) 1179dc4eb53aSLinus Lüssing case htons(ETH_P_IPV6): 11802cd41431SLinus Lüssing return br_ip6_multicast_select_querier(br, port, &saddr->u.ip6); 1181dc4eb53aSLinus Lüssing #endif 1182dc4eb53aSLinus Lüssing } 1183dc4eb53aSLinus Lüssing 1184dc4eb53aSLinus Lüssing return false; 1185dc4eb53aSLinus Lüssing } 1186dc4eb53aSLinus Lüssing 1187cc0fdd80SLinus Lüssing static void 118890010b36SLinus Lüssing br_multicast_update_query_timer(struct net_bridge *br, 118990010b36SLinus Lüssing struct bridge_mcast_other_query *query, 1190b00589afSLinus Lüssing unsigned long max_delay) 1191b00589afSLinus Lüssing { 119290010b36SLinus Lüssing if (!timer_pending(&query->timer)) 119390010b36SLinus Lüssing query->delay_time = jiffies + max_delay; 1194b00589afSLinus Lüssing 119590010b36SLinus Lüssing mod_timer(&query->timer, jiffies + br->multicast_querier_interval); 1196b00589afSLinus Lüssing } 1197b00589afSLinus Lüssing 11987e80c124Sstephen hemminger /* 11997c77602fSCong Wang * Add port to router_list 12007e80c124Sstephen hemminger * list is maintained ordered by pointer value 12017e80c124Sstephen hemminger * and locked by br->multicast_lock and RCU 12027e80c124Sstephen hemminger */ 12030909e117SHerbert Xu static void br_multicast_add_router(struct net_bridge *br, 12040909e117SHerbert Xu struct net_bridge_port *port) 12050909e117SHerbert Xu { 1206dcdca2c4Sstephen hemminger struct net_bridge_port *p; 1207b67bfe0dSSasha Levin struct hlist_node *slot = NULL; 12080909e117SHerbert Xu 12091a040eacSNikolay Aleksandrov if (!hlist_unhashed(&port->rlist)) 12101a040eacSNikolay Aleksandrov return; 12111a040eacSNikolay Aleksandrov 1212b67bfe0dSSasha Levin hlist_for_each_entry(p, &br->router_list, rlist) { 12137e80c124Sstephen hemminger if ((unsigned long) port >= (unsigned long) p) 12147e80c124Sstephen hemminger break; 1215b67bfe0dSSasha Levin slot = &p->rlist; 1216dcdca2c4Sstephen hemminger } 12170909e117SHerbert Xu 12187e80c124Sstephen hemminger if (slot) 12191d023284SKen Helias hlist_add_behind_rcu(&port->rlist, slot); 1220dcdca2c4Sstephen hemminger else 1221dcdca2c4Sstephen hemminger hlist_add_head_rcu(&port->rlist, &br->router_list); 1222949f1e39SSatish Ashok br_rtr_notify(br->dev, port, RTM_NEWMDB); 12230909e117SHerbert Xu } 12240909e117SHerbert Xu 1225eb1d1641SHerbert Xu static void br_multicast_mark_router(struct net_bridge *br, 1226eb1d1641SHerbert Xu struct net_bridge_port *port) 1227eb1d1641SHerbert Xu { 1228eb1d1641SHerbert Xu unsigned long now = jiffies; 1229eb1d1641SHerbert Xu 1230eb1d1641SHerbert Xu if (!port) { 12317f0aec7aSNikolay Aleksandrov if (br->multicast_router == MDB_RTR_TYPE_TEMP_QUERY) 1232eb1d1641SHerbert Xu mod_timer(&br->multicast_router_timer, 1233eb1d1641SHerbert Xu now + br->multicast_querier_interval); 1234eb1d1641SHerbert Xu return; 1235eb1d1641SHerbert Xu } 1236eb1d1641SHerbert Xu 12377f0aec7aSNikolay Aleksandrov if (port->multicast_router != MDB_RTR_TYPE_TEMP_QUERY) 1238eb1d1641SHerbert Xu return; 1239eb1d1641SHerbert Xu 12400909e117SHerbert Xu br_multicast_add_router(br, port); 1241eb1d1641SHerbert Xu 1242eb1d1641SHerbert Xu mod_timer(&port->multicast_router_timer, 1243eb1d1641SHerbert Xu now + br->multicast_querier_interval); 1244eb1d1641SHerbert Xu } 1245eb1d1641SHerbert Xu 1246eb1d1641SHerbert Xu static void br_multicast_query_received(struct net_bridge *br, 1247eb1d1641SHerbert Xu struct net_bridge_port *port, 124890010b36SLinus Lüssing struct bridge_mcast_other_query *query, 1249dc4eb53aSLinus Lüssing struct br_ip *saddr, 1250b00589afSLinus Lüssing unsigned long max_delay) 1251eb1d1641SHerbert Xu { 12522cd41431SLinus Lüssing if (!br_multicast_select_querier(br, port, saddr)) 1253eb1d1641SHerbert Xu return; 1254eb1d1641SHerbert Xu 1255dc4eb53aSLinus Lüssing br_multicast_update_query_timer(br, query, max_delay); 1256eb1d1641SHerbert Xu br_multicast_mark_router(br, port); 1257eb1d1641SHerbert Xu } 1258eb1d1641SHerbert Xu 12598ef2a9a5SYOSHIFUJI Hideaki static int br_ip4_multicast_query(struct net_bridge *br, 1260eb1d1641SHerbert Xu struct net_bridge_port *port, 126106499098SVlad Yasevich struct sk_buff *skb, 126206499098SVlad Yasevich u16 vid) 1263eb1d1641SHerbert Xu { 1264b71d1d42SEric Dumazet const struct iphdr *iph = ip_hdr(skb); 1265eb1d1641SHerbert Xu struct igmphdr *ih = igmp_hdr(skb); 1266eb1d1641SHerbert Xu struct net_bridge_mdb_entry *mp; 1267eb1d1641SHerbert Xu struct igmpv3_query *ih3; 1268eb1d1641SHerbert Xu struct net_bridge_port_group *p; 1269e8051688SEric Dumazet struct net_bridge_port_group __rcu **pp; 1270dc4eb53aSLinus Lüssing struct br_ip saddr; 1271eb1d1641SHerbert Xu unsigned long max_delay; 1272eb1d1641SHerbert Xu unsigned long now = jiffies; 1273eb1d1641SHerbert Xu __be32 group; 1274bec68ff1SYOSHIFUJI Hideaki int err = 0; 1275eb1d1641SHerbert Xu 1276eb1d1641SHerbert Xu spin_lock(&br->multicast_lock); 1277eb1d1641SHerbert Xu if (!netif_running(br->dev) || 1278eb1d1641SHerbert Xu (port && port->state == BR_STATE_DISABLED)) 1279eb1d1641SHerbert Xu goto out; 1280eb1d1641SHerbert Xu 1281eb1d1641SHerbert Xu group = ih->group; 1282eb1d1641SHerbert Xu 1283eb1d1641SHerbert Xu if (skb->len == sizeof(*ih)) { 1284eb1d1641SHerbert Xu max_delay = ih->code * (HZ / IGMP_TIMER_SCALE); 1285eb1d1641SHerbert Xu 1286eb1d1641SHerbert Xu if (!max_delay) { 1287eb1d1641SHerbert Xu max_delay = 10 * HZ; 1288eb1d1641SHerbert Xu group = 0; 1289eb1d1641SHerbert Xu } 12909afd85c9SLinus Lüssing } else if (skb->len >= sizeof(*ih3)) { 1291eb1d1641SHerbert Xu ih3 = igmpv3_query_hdr(skb); 1292eb1d1641SHerbert Xu if (ih3->nsrcs) 1293bec68ff1SYOSHIFUJI Hideaki goto out; 1294eb1d1641SHerbert Xu 12950ba8c9ecSYOSHIFUJI Hideaki / 吉藤英明 max_delay = ih3->code ? 12960ba8c9ecSYOSHIFUJI Hideaki / 吉藤英明 IGMPV3_MRC(ih3->code) * (HZ / IGMP_TIMER_SCALE) : 1; 12979afd85c9SLinus Lüssing } else { 12989ed973ccSLinus Lüssing goto out; 12999ed973ccSLinus Lüssing } 13009ed973ccSLinus Lüssing 1301dc4eb53aSLinus Lüssing if (!group) { 1302dc4eb53aSLinus Lüssing saddr.proto = htons(ETH_P_IP); 1303dc4eb53aSLinus Lüssing saddr.u.ip4 = iph->saddr; 1304b00589afSLinus Lüssing 1305dc4eb53aSLinus Lüssing br_multicast_query_received(br, port, &br->ip4_other_query, 1306dc4eb53aSLinus Lüssing &saddr, max_delay); 1307eb1d1641SHerbert Xu goto out; 1308dc4eb53aSLinus Lüssing } 1309eb1d1641SHerbert Xu 1310b0e9a30dSVlad Yasevich mp = br_mdb_ip4_get(mlock_dereference(br->mdb, br), group, vid); 1311eb1d1641SHerbert Xu if (!mp) 1312eb1d1641SHerbert Xu goto out; 1313eb1d1641SHerbert Xu 1314eb1d1641SHerbert Xu max_delay *= br->multicast_last_member_count; 1315eb1d1641SHerbert Xu 13168a870178SHerbert Xu if (mp->mglist && 1317eb1d1641SHerbert Xu (timer_pending(&mp->timer) ? 1318eb1d1641SHerbert Xu time_after(mp->timer.expires, now + max_delay) : 1319eb1d1641SHerbert Xu try_to_del_timer_sync(&mp->timer) >= 0)) 1320eb1d1641SHerbert Xu mod_timer(&mp->timer, now + max_delay); 1321eb1d1641SHerbert Xu 1322e8051688SEric Dumazet for (pp = &mp->ports; 1323e8051688SEric Dumazet (p = mlock_dereference(*pp, br)) != NULL; 1324e8051688SEric Dumazet pp = &p->next) { 1325eb1d1641SHerbert Xu if (timer_pending(&p->timer) ? 1326eb1d1641SHerbert Xu time_after(p->timer.expires, now + max_delay) : 1327eb1d1641SHerbert Xu try_to_del_timer_sync(&p->timer) >= 0) 132824f9cdcbSHerbert Xu mod_timer(&p->timer, now + max_delay); 1329eb1d1641SHerbert Xu } 1330eb1d1641SHerbert Xu 1331eb1d1641SHerbert Xu out: 1332eb1d1641SHerbert Xu spin_unlock(&br->multicast_lock); 1333bec68ff1SYOSHIFUJI Hideaki return err; 1334eb1d1641SHerbert Xu } 1335eb1d1641SHerbert Xu 1336dfd56b8bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6) 133708b202b6SYOSHIFUJI Hideaki static int br_ip6_multicast_query(struct net_bridge *br, 133808b202b6SYOSHIFUJI Hideaki struct net_bridge_port *port, 133906499098SVlad Yasevich struct sk_buff *skb, 134006499098SVlad Yasevich u16 vid) 134108b202b6SYOSHIFUJI Hideaki { 1342b71d1d42SEric Dumazet const struct ipv6hdr *ip6h = ipv6_hdr(skb); 1343eca2a43bSstephen hemminger struct mld_msg *mld; 134408b202b6SYOSHIFUJI Hideaki struct net_bridge_mdb_entry *mp; 134508b202b6SYOSHIFUJI Hideaki struct mld2_query *mld2q; 1346e8051688SEric Dumazet struct net_bridge_port_group *p; 1347e8051688SEric Dumazet struct net_bridge_port_group __rcu **pp; 1348dc4eb53aSLinus Lüssing struct br_ip saddr; 134908b202b6SYOSHIFUJI Hideaki unsigned long max_delay; 135008b202b6SYOSHIFUJI Hideaki unsigned long now = jiffies; 1351b71d1d42SEric Dumazet const struct in6_addr *group = NULL; 13529ed973ccSLinus Lüssing bool is_general_query; 135308b202b6SYOSHIFUJI Hideaki int err = 0; 135408b202b6SYOSHIFUJI Hideaki 135508b202b6SYOSHIFUJI Hideaki spin_lock(&br->multicast_lock); 135608b202b6SYOSHIFUJI Hideaki if (!netif_running(br->dev) || 135708b202b6SYOSHIFUJI Hideaki (port && port->state == BR_STATE_DISABLED)) 135808b202b6SYOSHIFUJI Hideaki goto out; 135908b202b6SYOSHIFUJI Hideaki 136008b202b6SYOSHIFUJI Hideaki if (skb->len == sizeof(*mld)) { 136108b202b6SYOSHIFUJI Hideaki if (!pskb_may_pull(skb, sizeof(*mld))) { 136208b202b6SYOSHIFUJI Hideaki err = -EINVAL; 136308b202b6SYOSHIFUJI Hideaki goto out; 136408b202b6SYOSHIFUJI Hideaki } 136508b202b6SYOSHIFUJI Hideaki mld = (struct mld_msg *) icmp6_hdr(skb); 13664715213dSLi RongQing max_delay = msecs_to_jiffies(ntohs(mld->mld_maxdelay)); 136708b202b6SYOSHIFUJI Hideaki if (max_delay) 136808b202b6SYOSHIFUJI Hideaki group = &mld->mld_mca; 1369248ba8ecSLinus Lüssing } else { 137008b202b6SYOSHIFUJI Hideaki if (!pskb_may_pull(skb, sizeof(*mld2q))) { 137108b202b6SYOSHIFUJI Hideaki err = -EINVAL; 137208b202b6SYOSHIFUJI Hideaki goto out; 137308b202b6SYOSHIFUJI Hideaki } 137408b202b6SYOSHIFUJI Hideaki mld2q = (struct mld2_query *)icmp6_hdr(skb); 137508b202b6SYOSHIFUJI Hideaki if (!mld2q->mld2q_nsrcs) 137608b202b6SYOSHIFUJI Hideaki group = &mld2q->mld2q_mca; 1377e3f5b170SDaniel Borkmann 1378e3f5b170SDaniel Borkmann max_delay = max(msecs_to_jiffies(mldv2_mrc(mld2q)), 1UL); 137908b202b6SYOSHIFUJI Hideaki } 138008b202b6SYOSHIFUJI Hideaki 13819ed973ccSLinus Lüssing is_general_query = group && ipv6_addr_any(group); 13829ed973ccSLinus Lüssing 1383dc4eb53aSLinus Lüssing if (is_general_query) { 1384dc4eb53aSLinus Lüssing saddr.proto = htons(ETH_P_IPV6); 1385dc4eb53aSLinus Lüssing saddr.u.ip6 = ip6h->saddr; 1386b00589afSLinus Lüssing 1387dc4eb53aSLinus Lüssing br_multicast_query_received(br, port, &br->ip6_other_query, 1388dc4eb53aSLinus Lüssing &saddr, max_delay); 138908b202b6SYOSHIFUJI Hideaki goto out; 13906c03ee8bSLinus Lüssing } else if (!group) { 13916c03ee8bSLinus Lüssing goto out; 1392dc4eb53aSLinus Lüssing } 139308b202b6SYOSHIFUJI Hideaki 1394b0e9a30dSVlad Yasevich mp = br_mdb_ip6_get(mlock_dereference(br->mdb, br), group, vid); 139508b202b6SYOSHIFUJI Hideaki if (!mp) 139608b202b6SYOSHIFUJI Hideaki goto out; 139708b202b6SYOSHIFUJI Hideaki 139808b202b6SYOSHIFUJI Hideaki max_delay *= br->multicast_last_member_count; 13998a870178SHerbert Xu if (mp->mglist && 140008b202b6SYOSHIFUJI Hideaki (timer_pending(&mp->timer) ? 140108b202b6SYOSHIFUJI Hideaki time_after(mp->timer.expires, now + max_delay) : 140208b202b6SYOSHIFUJI Hideaki try_to_del_timer_sync(&mp->timer) >= 0)) 140308b202b6SYOSHIFUJI Hideaki mod_timer(&mp->timer, now + max_delay); 140408b202b6SYOSHIFUJI Hideaki 1405e8051688SEric Dumazet for (pp = &mp->ports; 1406e8051688SEric Dumazet (p = mlock_dereference(*pp, br)) != NULL; 1407e8051688SEric Dumazet pp = &p->next) { 140808b202b6SYOSHIFUJI Hideaki if (timer_pending(&p->timer) ? 140908b202b6SYOSHIFUJI Hideaki time_after(p->timer.expires, now + max_delay) : 141008b202b6SYOSHIFUJI Hideaki try_to_del_timer_sync(&p->timer) >= 0) 141124f9cdcbSHerbert Xu mod_timer(&p->timer, now + max_delay); 141208b202b6SYOSHIFUJI Hideaki } 141308b202b6SYOSHIFUJI Hideaki 141408b202b6SYOSHIFUJI Hideaki out: 141508b202b6SYOSHIFUJI Hideaki spin_unlock(&br->multicast_lock); 141608b202b6SYOSHIFUJI Hideaki return err; 141708b202b6SYOSHIFUJI Hideaki } 141808b202b6SYOSHIFUJI Hideaki #endif 141908b202b6SYOSHIFUJI Hideaki 142090010b36SLinus Lüssing static void 142190010b36SLinus Lüssing br_multicast_leave_group(struct net_bridge *br, 1422eb1d1641SHerbert Xu struct net_bridge_port *port, 1423cc0fdd80SLinus Lüssing struct br_ip *group, 142490010b36SLinus Lüssing struct bridge_mcast_other_query *other_query, 142590010b36SLinus Lüssing struct bridge_mcast_own_query *own_query) 1426eb1d1641SHerbert Xu { 1427eb1d1641SHerbert Xu struct net_bridge_mdb_htable *mdb; 1428eb1d1641SHerbert Xu struct net_bridge_mdb_entry *mp; 1429eb1d1641SHerbert Xu struct net_bridge_port_group *p; 1430eb1d1641SHerbert Xu unsigned long now; 1431eb1d1641SHerbert Xu unsigned long time; 1432eb1d1641SHerbert Xu 1433eb1d1641SHerbert Xu spin_lock(&br->multicast_lock); 1434eb1d1641SHerbert Xu if (!netif_running(br->dev) || 1435544586f7SSatish Ashok (port && port->state == BR_STATE_DISABLED)) 1436eb1d1641SHerbert Xu goto out; 1437eb1d1641SHerbert Xu 1438e8051688SEric Dumazet mdb = mlock_dereference(br->mdb, br); 1439eb1d1641SHerbert Xu mp = br_mdb_ip_get(mdb, group); 1440eb1d1641SHerbert Xu if (!mp) 1441eb1d1641SHerbert Xu goto out; 1442eb1d1641SHerbert Xu 1443544586f7SSatish Ashok if (port && (port->flags & BR_MULTICAST_FAST_LEAVE)) { 1444544586f7SSatish Ashok struct net_bridge_port_group __rcu **pp; 1445544586f7SSatish Ashok 1446544586f7SSatish Ashok for (pp = &mp->ports; 1447544586f7SSatish Ashok (p = mlock_dereference(*pp, br)) != NULL; 1448544586f7SSatish Ashok pp = &p->next) { 1449544586f7SSatish Ashok if (p->port != port) 1450544586f7SSatish Ashok continue; 1451544586f7SSatish Ashok 1452544586f7SSatish Ashok rcu_assign_pointer(*pp, p->next); 1453544586f7SSatish Ashok hlist_del_init(&p->mglist); 1454544586f7SSatish Ashok del_timer(&p->timer); 1455544586f7SSatish Ashok call_rcu_bh(&p->rcu, br_multicast_free_pg); 14569e8430f8SElad Raz br_mdb_notify(br->dev, p, RTM_DELMDB); 1457544586f7SSatish Ashok 1458544586f7SSatish Ashok if (!mp->ports && !mp->mglist && 1459544586f7SSatish Ashok netif_running(br->dev)) 1460544586f7SSatish Ashok mod_timer(&mp->timer, jiffies); 1461544586f7SSatish Ashok } 1462544586f7SSatish Ashok goto out; 1463544586f7SSatish Ashok } 1464544586f7SSatish Ashok 1465544586f7SSatish Ashok if (timer_pending(&other_query->timer)) 1466544586f7SSatish Ashok goto out; 1467544586f7SSatish Ashok 1468cc0fdd80SLinus Lüssing if (br->multicast_querier) { 14696b7df111SCong Wang __br_multicast_send_query(br, port, &mp->addr); 14706b7df111SCong Wang 14716b7df111SCong Wang time = jiffies + br->multicast_last_member_count * 14726b7df111SCong Wang br->multicast_last_member_interval; 1473cc0fdd80SLinus Lüssing 147490010b36SLinus Lüssing mod_timer(&own_query->timer, time); 14756b7df111SCong Wang 14766b7df111SCong Wang for (p = mlock_dereference(mp->ports, br); 14776b7df111SCong Wang p != NULL; 14786b7df111SCong Wang p = mlock_dereference(p->next, br)) { 14796b7df111SCong Wang if (p->port != port) 14806b7df111SCong Wang continue; 14816b7df111SCong Wang 14826b7df111SCong Wang if (!hlist_unhashed(&p->mglist) && 14836b7df111SCong Wang (timer_pending(&p->timer) ? 14846b7df111SCong Wang time_after(p->timer.expires, time) : 14856b7df111SCong Wang try_to_del_timer_sync(&p->timer) >= 0)) { 14866b7df111SCong Wang mod_timer(&p->timer, time); 14876b7df111SCong Wang } 14886b7df111SCong Wang 14896b7df111SCong Wang break; 14906b7df111SCong Wang } 14916b7df111SCong Wang } 14926b7df111SCong Wang 1493eb1d1641SHerbert Xu now = jiffies; 1494eb1d1641SHerbert Xu time = now + br->multicast_last_member_count * 1495eb1d1641SHerbert Xu br->multicast_last_member_interval; 1496eb1d1641SHerbert Xu 1497eb1d1641SHerbert Xu if (!port) { 1498454594f3SLinus Lüssing if (mp->mglist && 1499eb1d1641SHerbert Xu (timer_pending(&mp->timer) ? 1500eb1d1641SHerbert Xu time_after(mp->timer.expires, time) : 1501eb1d1641SHerbert Xu try_to_del_timer_sync(&mp->timer) >= 0)) { 1502eb1d1641SHerbert Xu mod_timer(&mp->timer, time); 1503eb1d1641SHerbert Xu } 1504454594f3SLinus Lüssing 1505454594f3SLinus Lüssing goto out; 1506454594f3SLinus Lüssing } 1507454594f3SLinus Lüssing 1508454594f3SLinus Lüssing for (p = mlock_dereference(mp->ports, br); 1509454594f3SLinus Lüssing p != NULL; 1510454594f3SLinus Lüssing p = mlock_dereference(p->next, br)) { 1511454594f3SLinus Lüssing if (p->port != port) 1512454594f3SLinus Lüssing continue; 1513454594f3SLinus Lüssing 1514454594f3SLinus Lüssing if (!hlist_unhashed(&p->mglist) && 1515454594f3SLinus Lüssing (timer_pending(&p->timer) ? 1516454594f3SLinus Lüssing time_after(p->timer.expires, time) : 1517454594f3SLinus Lüssing try_to_del_timer_sync(&p->timer) >= 0)) { 1518454594f3SLinus Lüssing mod_timer(&p->timer, time); 1519454594f3SLinus Lüssing } 1520454594f3SLinus Lüssing 1521454594f3SLinus Lüssing break; 1522eb1d1641SHerbert Xu } 1523eb1d1641SHerbert Xu out: 1524eb1d1641SHerbert Xu spin_unlock(&br->multicast_lock); 1525eb1d1641SHerbert Xu } 1526eb1d1641SHerbert Xu 15278ef2a9a5SYOSHIFUJI Hideaki static void br_ip4_multicast_leave_group(struct net_bridge *br, 15288ef2a9a5SYOSHIFUJI Hideaki struct net_bridge_port *port, 1529b0e9a30dSVlad Yasevich __be32 group, 1530b0e9a30dSVlad Yasevich __u16 vid) 15318ef2a9a5SYOSHIFUJI Hideaki { 15328ef2a9a5SYOSHIFUJI Hideaki struct br_ip br_group; 153390010b36SLinus Lüssing struct bridge_mcast_own_query *own_query; 15348ef2a9a5SYOSHIFUJI Hideaki 15358ef2a9a5SYOSHIFUJI Hideaki if (ipv4_is_local_multicast(group)) 15368ef2a9a5SYOSHIFUJI Hideaki return; 15378ef2a9a5SYOSHIFUJI Hideaki 153890010b36SLinus Lüssing own_query = port ? &port->ip4_own_query : &br->ip4_own_query; 153990010b36SLinus Lüssing 15408ef2a9a5SYOSHIFUJI Hideaki br_group.u.ip4 = group; 15418ef2a9a5SYOSHIFUJI Hideaki br_group.proto = htons(ETH_P_IP); 1542b0e9a30dSVlad Yasevich br_group.vid = vid; 15438ef2a9a5SYOSHIFUJI Hideaki 154490010b36SLinus Lüssing br_multicast_leave_group(br, port, &br_group, &br->ip4_other_query, 154590010b36SLinus Lüssing own_query); 15468ef2a9a5SYOSHIFUJI Hideaki } 15478ef2a9a5SYOSHIFUJI Hideaki 1548dfd56b8bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6) 154908b202b6SYOSHIFUJI Hideaki static void br_ip6_multicast_leave_group(struct net_bridge *br, 155008b202b6SYOSHIFUJI Hideaki struct net_bridge_port *port, 1551b0e9a30dSVlad Yasevich const struct in6_addr *group, 1552b0e9a30dSVlad Yasevich __u16 vid) 155308b202b6SYOSHIFUJI Hideaki { 155408b202b6SYOSHIFUJI Hideaki struct br_ip br_group; 155590010b36SLinus Lüssing struct bridge_mcast_own_query *own_query; 155608b202b6SYOSHIFUJI Hideaki 15573c3769e6SLinus Lüssing if (ipv6_addr_is_ll_all_nodes(group)) 155808b202b6SYOSHIFUJI Hideaki return; 155908b202b6SYOSHIFUJI Hideaki 156090010b36SLinus Lüssing own_query = port ? &port->ip6_own_query : &br->ip6_own_query; 156190010b36SLinus Lüssing 15624e3fd7a0SAlexey Dobriyan br_group.u.ip6 = *group; 156308b202b6SYOSHIFUJI Hideaki br_group.proto = htons(ETH_P_IPV6); 1564b0e9a30dSVlad Yasevich br_group.vid = vid; 156508b202b6SYOSHIFUJI Hideaki 156690010b36SLinus Lüssing br_multicast_leave_group(br, port, &br_group, &br->ip6_other_query, 156790010b36SLinus Lüssing own_query); 156808b202b6SYOSHIFUJI Hideaki } 156908b202b6SYOSHIFUJI Hideaki #endif 15708ef2a9a5SYOSHIFUJI Hideaki 1571eb1d1641SHerbert Xu static int br_multicast_ipv4_rcv(struct net_bridge *br, 1572eb1d1641SHerbert Xu struct net_bridge_port *port, 157306499098SVlad Yasevich struct sk_buff *skb, 157406499098SVlad Yasevich u16 vid) 1575eb1d1641SHerbert Xu { 15769afd85c9SLinus Lüssing struct sk_buff *skb_trimmed = NULL; 1577eb1d1641SHerbert Xu struct igmphdr *ih; 1578eb1d1641SHerbert Xu int err; 1579eb1d1641SHerbert Xu 15809afd85c9SLinus Lüssing err = ip_mc_check_igmp(skb, &skb_trimmed); 1581eb1d1641SHerbert Xu 15829afd85c9SLinus Lüssing if (err == -ENOMSG) { 15839afd85c9SLinus Lüssing if (!ipv4_is_local_multicast(ip_hdr(skb)->daddr)) 1584bd4265feSHerbert Xu BR_INPUT_SKB_CB(skb)->mrouters_only = 1; 1585eb1d1641SHerbert Xu return 0; 15869afd85c9SLinus Lüssing } else if (err < 0) { 15879afd85c9SLinus Lüssing return err; 1588bd4265feSHerbert Xu } 1589eb1d1641SHerbert Xu 1590eb1d1641SHerbert Xu BR_INPUT_SKB_CB(skb)->igmp = 1; 15919afd85c9SLinus Lüssing ih = igmp_hdr(skb); 1592eb1d1641SHerbert Xu 1593eb1d1641SHerbert Xu switch (ih->type) { 1594eb1d1641SHerbert Xu case IGMP_HOST_MEMBERSHIP_REPORT: 1595eb1d1641SHerbert Xu case IGMPV2_HOST_MEMBERSHIP_REPORT: 159662b2bcb4SFernando Luis Vázquez Cao BR_INPUT_SKB_CB(skb)->mrouters_only = 1; 1597b0e9a30dSVlad Yasevich err = br_ip4_multicast_add_group(br, port, ih->group, vid); 1598eb1d1641SHerbert Xu break; 1599eb1d1641SHerbert Xu case IGMPV3_HOST_MEMBERSHIP_REPORT: 16009afd85c9SLinus Lüssing err = br_ip4_multicast_igmp3_report(br, port, skb_trimmed, vid); 1601eb1d1641SHerbert Xu break; 1602eb1d1641SHerbert Xu case IGMP_HOST_MEMBERSHIP_QUERY: 16039afd85c9SLinus Lüssing err = br_ip4_multicast_query(br, port, skb_trimmed, vid); 1604eb1d1641SHerbert Xu break; 1605eb1d1641SHerbert Xu case IGMP_HOST_LEAVE_MESSAGE: 1606b0e9a30dSVlad Yasevich br_ip4_multicast_leave_group(br, port, ih->group, vid); 1607eb1d1641SHerbert Xu break; 1608eb1d1641SHerbert Xu } 1609eb1d1641SHerbert Xu 1610a516993fSLinus Lüssing if (skb_trimmed && skb_trimmed != skb) 16119afd85c9SLinus Lüssing kfree_skb(skb_trimmed); 16129afd85c9SLinus Lüssing 1613eb1d1641SHerbert Xu return err; 1614eb1d1641SHerbert Xu } 1615eb1d1641SHerbert Xu 1616dfd56b8bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6) 161708b202b6SYOSHIFUJI Hideaki static int br_multicast_ipv6_rcv(struct net_bridge *br, 161808b202b6SYOSHIFUJI Hideaki struct net_bridge_port *port, 161906499098SVlad Yasevich struct sk_buff *skb, 162006499098SVlad Yasevich u16 vid) 162108b202b6SYOSHIFUJI Hideaki { 16229afd85c9SLinus Lüssing struct sk_buff *skb_trimmed = NULL; 16239afd85c9SLinus Lüssing struct mld_msg *mld; 162408b202b6SYOSHIFUJI Hideaki int err; 162508b202b6SYOSHIFUJI Hideaki 16269afd85c9SLinus Lüssing err = ipv6_mc_check_mld(skb, &skb_trimmed); 162708b202b6SYOSHIFUJI Hideaki 16289afd85c9SLinus Lüssing if (err == -ENOMSG) { 16299afd85c9SLinus Lüssing if (!ipv6_addr_is_ll_all_nodes(&ipv6_hdr(skb)->daddr)) 16308fad9c39SLinus Lüssing BR_INPUT_SKB_CB(skb)->mrouters_only = 1; 163108b202b6SYOSHIFUJI Hideaki return 0; 16329afd85c9SLinus Lüssing } else if (err < 0) { 16339afd85c9SLinus Lüssing return err; 163408b202b6SYOSHIFUJI Hideaki } 163508b202b6SYOSHIFUJI Hideaki 163608b202b6SYOSHIFUJI Hideaki BR_INPUT_SKB_CB(skb)->igmp = 1; 16379afd85c9SLinus Lüssing mld = (struct mld_msg *)skb_transport_header(skb); 163808b202b6SYOSHIFUJI Hideaki 16399afd85c9SLinus Lüssing switch (mld->mld_type) { 164008b202b6SYOSHIFUJI Hideaki case ICMPV6_MGM_REPORT: 1641fc2af6c7SFernando Luis Vázquez Cao BR_INPUT_SKB_CB(skb)->mrouters_only = 1; 1642b0e9a30dSVlad Yasevich err = br_ip6_multicast_add_group(br, port, &mld->mld_mca, vid); 164308b202b6SYOSHIFUJI Hideaki break; 164408b202b6SYOSHIFUJI Hideaki case ICMPV6_MLD2_REPORT: 16459afd85c9SLinus Lüssing err = br_ip6_multicast_mld2_report(br, port, skb_trimmed, vid); 164608b202b6SYOSHIFUJI Hideaki break; 164708b202b6SYOSHIFUJI Hideaki case ICMPV6_MGM_QUERY: 16489afd85c9SLinus Lüssing err = br_ip6_multicast_query(br, port, skb_trimmed, vid); 164908b202b6SYOSHIFUJI Hideaki break; 165008b202b6SYOSHIFUJI Hideaki case ICMPV6_MGM_REDUCTION: 1651b0e9a30dSVlad Yasevich br_ip6_multicast_leave_group(br, port, &mld->mld_mca, vid); 16529afd85c9SLinus Lüssing break; 165308b202b6SYOSHIFUJI Hideaki } 165408b202b6SYOSHIFUJI Hideaki 1655a516993fSLinus Lüssing if (skb_trimmed && skb_trimmed != skb) 16569afd85c9SLinus Lüssing kfree_skb(skb_trimmed); 16579afd85c9SLinus Lüssing 165808b202b6SYOSHIFUJI Hideaki return err; 165908b202b6SYOSHIFUJI Hideaki } 166008b202b6SYOSHIFUJI Hideaki #endif 166108b202b6SYOSHIFUJI Hideaki 1662eb1d1641SHerbert Xu int br_multicast_rcv(struct net_bridge *br, struct net_bridge_port *port, 166306499098SVlad Yasevich struct sk_buff *skb, u16 vid) 1664eb1d1641SHerbert Xu { 16651fafc7a9SYOSHIFUJI Hideaki / 吉藤英明 BR_INPUT_SKB_CB(skb)->igmp = 0; 16661fafc7a9SYOSHIFUJI Hideaki / 吉藤英明 BR_INPUT_SKB_CB(skb)->mrouters_only = 0; 16671fafc7a9SYOSHIFUJI Hideaki / 吉藤英明 1668eb1d1641SHerbert Xu if (br->multicast_disabled) 1669eb1d1641SHerbert Xu return 0; 1670eb1d1641SHerbert Xu 1671eb1d1641SHerbert Xu switch (skb->protocol) { 1672eb1d1641SHerbert Xu case htons(ETH_P_IP): 167306499098SVlad Yasevich return br_multicast_ipv4_rcv(br, port, skb, vid); 1674dfd56b8bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6) 167508b202b6SYOSHIFUJI Hideaki case htons(ETH_P_IPV6): 167606499098SVlad Yasevich return br_multicast_ipv6_rcv(br, port, skb, vid); 167708b202b6SYOSHIFUJI Hideaki #endif 1678eb1d1641SHerbert Xu } 1679eb1d1641SHerbert Xu 1680eb1d1641SHerbert Xu return 0; 1681eb1d1641SHerbert Xu } 1682eb1d1641SHerbert Xu 1683cc0fdd80SLinus Lüssing static void br_multicast_query_expired(struct net_bridge *br, 16842cd41431SLinus Lüssing struct bridge_mcast_own_query *query, 16852cd41431SLinus Lüssing struct bridge_mcast_querier *querier) 1686cc0fdd80SLinus Lüssing { 1687cc0fdd80SLinus Lüssing spin_lock(&br->multicast_lock); 1688cc0fdd80SLinus Lüssing if (query->startup_sent < br->multicast_startup_query_count) 1689cc0fdd80SLinus Lüssing query->startup_sent++; 1690cc0fdd80SLinus Lüssing 169171d9f614SEric Dumazet RCU_INIT_POINTER(querier->port, NULL); 1692cc0fdd80SLinus Lüssing br_multicast_send_query(br, NULL, query); 1693cc0fdd80SLinus Lüssing spin_unlock(&br->multicast_lock); 1694cc0fdd80SLinus Lüssing } 1695cc0fdd80SLinus Lüssing 1696cc0fdd80SLinus Lüssing static void br_ip4_multicast_query_expired(unsigned long data) 1697eb1d1641SHerbert Xu { 1698eb1d1641SHerbert Xu struct net_bridge *br = (void *)data; 1699eb1d1641SHerbert Xu 17002cd41431SLinus Lüssing br_multicast_query_expired(br, &br->ip4_own_query, &br->ip4_querier); 1701eb1d1641SHerbert Xu } 1702eb1d1641SHerbert Xu 1703cc0fdd80SLinus Lüssing #if IS_ENABLED(CONFIG_IPV6) 1704cc0fdd80SLinus Lüssing static void br_ip6_multicast_query_expired(unsigned long data) 1705cc0fdd80SLinus Lüssing { 1706cc0fdd80SLinus Lüssing struct net_bridge *br = (void *)data; 1707cc0fdd80SLinus Lüssing 17082cd41431SLinus Lüssing br_multicast_query_expired(br, &br->ip6_own_query, &br->ip6_querier); 1709cc0fdd80SLinus Lüssing } 1710cc0fdd80SLinus Lüssing #endif 1711cc0fdd80SLinus Lüssing 1712eb1d1641SHerbert Xu void br_multicast_init(struct net_bridge *br) 1713eb1d1641SHerbert Xu { 1714eb1d1641SHerbert Xu br->hash_elasticity = 4; 1715eb1d1641SHerbert Xu br->hash_max = 512; 1716eb1d1641SHerbert Xu 17177f0aec7aSNikolay Aleksandrov br->multicast_router = MDB_RTR_TYPE_TEMP_QUERY; 1718c5c23260SHerbert Xu br->multicast_querier = 0; 17191c8ad5bfSCong Wang br->multicast_query_use_ifaddr = 0; 1720eb1d1641SHerbert Xu br->multicast_last_member_count = 2; 1721eb1d1641SHerbert Xu br->multicast_startup_query_count = 2; 1722eb1d1641SHerbert Xu 1723eb1d1641SHerbert Xu br->multicast_last_member_interval = HZ; 1724eb1d1641SHerbert Xu br->multicast_query_response_interval = 10 * HZ; 1725eb1d1641SHerbert Xu br->multicast_startup_query_interval = 125 * HZ / 4; 1726eb1d1641SHerbert Xu br->multicast_query_interval = 125 * HZ; 1727eb1d1641SHerbert Xu br->multicast_querier_interval = 255 * HZ; 1728eb1d1641SHerbert Xu br->multicast_membership_interval = 260 * HZ; 1729eb1d1641SHerbert Xu 173090010b36SLinus Lüssing br->ip4_other_query.delay_time = 0; 17312cd41431SLinus Lüssing br->ip4_querier.port = NULL; 1732cc0fdd80SLinus Lüssing #if IS_ENABLED(CONFIG_IPV6) 173390010b36SLinus Lüssing br->ip6_other_query.delay_time = 0; 17342cd41431SLinus Lüssing br->ip6_querier.port = NULL; 1735cc0fdd80SLinus Lüssing #endif 1736b00589afSLinus Lüssing 1737eb1d1641SHerbert Xu spin_lock_init(&br->multicast_lock); 1738eb1d1641SHerbert Xu setup_timer(&br->multicast_router_timer, 1739eb1d1641SHerbert Xu br_multicast_local_router_expired, 0); 174090010b36SLinus Lüssing setup_timer(&br->ip4_other_query.timer, 174190010b36SLinus Lüssing br_ip4_multicast_querier_expired, (unsigned long)br); 174290010b36SLinus Lüssing setup_timer(&br->ip4_own_query.timer, br_ip4_multicast_query_expired, 1743cc0fdd80SLinus Lüssing (unsigned long)br); 1744cc0fdd80SLinus Lüssing #if IS_ENABLED(CONFIG_IPV6) 174590010b36SLinus Lüssing setup_timer(&br->ip6_other_query.timer, 174690010b36SLinus Lüssing br_ip6_multicast_querier_expired, (unsigned long)br); 174790010b36SLinus Lüssing setup_timer(&br->ip6_own_query.timer, br_ip6_multicast_query_expired, 1748cc0fdd80SLinus Lüssing (unsigned long)br); 1749cc0fdd80SLinus Lüssing #endif 1750eb1d1641SHerbert Xu } 1751eb1d1641SHerbert Xu 1752cc0fdd80SLinus Lüssing static void __br_multicast_open(struct net_bridge *br, 175390010b36SLinus Lüssing struct bridge_mcast_own_query *query) 1754eb1d1641SHerbert Xu { 1755cc0fdd80SLinus Lüssing query->startup_sent = 0; 1756eb1d1641SHerbert Xu 1757eb1d1641SHerbert Xu if (br->multicast_disabled) 1758eb1d1641SHerbert Xu return; 1759eb1d1641SHerbert Xu 1760cc0fdd80SLinus Lüssing mod_timer(&query->timer, jiffies); 1761cc0fdd80SLinus Lüssing } 1762cc0fdd80SLinus Lüssing 1763cc0fdd80SLinus Lüssing void br_multicast_open(struct net_bridge *br) 1764cc0fdd80SLinus Lüssing { 176590010b36SLinus Lüssing __br_multicast_open(br, &br->ip4_own_query); 1766cc0fdd80SLinus Lüssing #if IS_ENABLED(CONFIG_IPV6) 176790010b36SLinus Lüssing __br_multicast_open(br, &br->ip6_own_query); 1768cc0fdd80SLinus Lüssing #endif 1769eb1d1641SHerbert Xu } 1770eb1d1641SHerbert Xu 1771eb1d1641SHerbert Xu void br_multicast_stop(struct net_bridge *br) 1772eb1d1641SHerbert Xu { 1773eb1d1641SHerbert Xu del_timer_sync(&br->multicast_router_timer); 177490010b36SLinus Lüssing del_timer_sync(&br->ip4_other_query.timer); 177590010b36SLinus Lüssing del_timer_sync(&br->ip4_own_query.timer); 1776cc0fdd80SLinus Lüssing #if IS_ENABLED(CONFIG_IPV6) 177790010b36SLinus Lüssing del_timer_sync(&br->ip6_other_query.timer); 177890010b36SLinus Lüssing del_timer_sync(&br->ip6_own_query.timer); 1779cc0fdd80SLinus Lüssing #endif 1780e10177abSSatish Ashok } 1781e10177abSSatish Ashok 1782e10177abSSatish Ashok void br_multicast_dev_del(struct net_bridge *br) 1783e10177abSSatish Ashok { 1784e10177abSSatish Ashok struct net_bridge_mdb_htable *mdb; 1785e10177abSSatish Ashok struct net_bridge_mdb_entry *mp; 1786e10177abSSatish Ashok struct hlist_node *n; 1787e10177abSSatish Ashok u32 ver; 1788e10177abSSatish Ashok int i; 1789eb1d1641SHerbert Xu 1790eb1d1641SHerbert Xu spin_lock_bh(&br->multicast_lock); 1791e8051688SEric Dumazet mdb = mlock_dereference(br->mdb, br); 1792eb1d1641SHerbert Xu if (!mdb) 1793eb1d1641SHerbert Xu goto out; 1794eb1d1641SHerbert Xu 1795eb1d1641SHerbert Xu br->mdb = NULL; 1796eb1d1641SHerbert Xu 1797eb1d1641SHerbert Xu ver = mdb->ver; 1798eb1d1641SHerbert Xu for (i = 0; i < mdb->max; i++) { 1799b67bfe0dSSasha Levin hlist_for_each_entry_safe(mp, n, &mdb->mhash[i], 1800eb1d1641SHerbert Xu hlist[ver]) { 1801eb1d1641SHerbert Xu del_timer(&mp->timer); 1802eb1d1641SHerbert Xu call_rcu_bh(&mp->rcu, br_multicast_free_group); 1803eb1d1641SHerbert Xu } 1804eb1d1641SHerbert Xu } 1805eb1d1641SHerbert Xu 1806eb1d1641SHerbert Xu if (mdb->old) { 1807eb1d1641SHerbert Xu spin_unlock_bh(&br->multicast_lock); 180810cc2b50SHerbert Xu rcu_barrier_bh(); 1809eb1d1641SHerbert Xu spin_lock_bh(&br->multicast_lock); 1810eb1d1641SHerbert Xu WARN_ON(mdb->old); 1811eb1d1641SHerbert Xu } 1812eb1d1641SHerbert Xu 1813eb1d1641SHerbert Xu mdb->old = mdb; 1814eb1d1641SHerbert Xu call_rcu_bh(&mdb->rcu, br_mdb_free); 1815eb1d1641SHerbert Xu 1816eb1d1641SHerbert Xu out: 1817eb1d1641SHerbert Xu spin_unlock_bh(&br->multicast_lock); 1818eb1d1641SHerbert Xu } 18190909e117SHerbert Xu 18200909e117SHerbert Xu int br_multicast_set_router(struct net_bridge *br, unsigned long val) 18210909e117SHerbert Xu { 18226ae4ae8eSLinus Lüssing int err = -EINVAL; 18230909e117SHerbert Xu 18240909e117SHerbert Xu spin_lock_bh(&br->multicast_lock); 18250909e117SHerbert Xu 18260909e117SHerbert Xu switch (val) { 18277f0aec7aSNikolay Aleksandrov case MDB_RTR_TYPE_DISABLED: 18287f0aec7aSNikolay Aleksandrov case MDB_RTR_TYPE_PERM: 18290909e117SHerbert Xu del_timer(&br->multicast_router_timer); 18300909e117SHerbert Xu /* fall through */ 18317f0aec7aSNikolay Aleksandrov case MDB_RTR_TYPE_TEMP_QUERY: 18320909e117SHerbert Xu br->multicast_router = val; 18330909e117SHerbert Xu err = 0; 18340909e117SHerbert Xu break; 18350909e117SHerbert Xu } 18360909e117SHerbert Xu 18370909e117SHerbert Xu spin_unlock_bh(&br->multicast_lock); 18380909e117SHerbert Xu 18390909e117SHerbert Xu return err; 18400909e117SHerbert Xu } 18410909e117SHerbert Xu 18427f0aec7aSNikolay Aleksandrov static void __del_port_router(struct net_bridge_port *p) 18437f0aec7aSNikolay Aleksandrov { 18447f0aec7aSNikolay Aleksandrov if (hlist_unhashed(&p->rlist)) 18457f0aec7aSNikolay Aleksandrov return; 18467f0aec7aSNikolay Aleksandrov hlist_del_init_rcu(&p->rlist); 18477f0aec7aSNikolay Aleksandrov br_rtr_notify(p->br->dev, p, RTM_DELMDB); 18487f0aec7aSNikolay Aleksandrov } 18497f0aec7aSNikolay Aleksandrov 18500909e117SHerbert Xu int br_multicast_set_port_router(struct net_bridge_port *p, unsigned long val) 18510909e117SHerbert Xu { 18520909e117SHerbert Xu struct net_bridge *br = p->br; 18536ae4ae8eSLinus Lüssing int err = -EINVAL; 18540909e117SHerbert Xu 18550909e117SHerbert Xu spin_lock(&br->multicast_lock); 1856*4950cfd1SNikolay Aleksandrov if (p->multicast_router == val) { 1857*4950cfd1SNikolay Aleksandrov err = 0; 1858*4950cfd1SNikolay Aleksandrov goto unlock; 1859*4950cfd1SNikolay Aleksandrov } 18600909e117SHerbert Xu switch (val) { 18617f0aec7aSNikolay Aleksandrov case MDB_RTR_TYPE_DISABLED: 18627f0aec7aSNikolay Aleksandrov p->multicast_router = MDB_RTR_TYPE_DISABLED; 18637f0aec7aSNikolay Aleksandrov __del_port_router(p); 18640909e117SHerbert Xu del_timer(&p->multicast_router_timer); 18650909e117SHerbert Xu break; 18667f0aec7aSNikolay Aleksandrov case MDB_RTR_TYPE_TEMP_QUERY: 18677f0aec7aSNikolay Aleksandrov p->multicast_router = MDB_RTR_TYPE_TEMP_QUERY; 18687f0aec7aSNikolay Aleksandrov __del_port_router(p); 18697f0aec7aSNikolay Aleksandrov break; 18707f0aec7aSNikolay Aleksandrov case MDB_RTR_TYPE_PERM: 18717f0aec7aSNikolay Aleksandrov p->multicast_router = MDB_RTR_TYPE_PERM; 18727f0aec7aSNikolay Aleksandrov del_timer(&p->multicast_router_timer); 18730909e117SHerbert Xu br_multicast_add_router(br, p); 18740909e117SHerbert Xu break; 18757f0aec7aSNikolay Aleksandrov default: 18767f0aec7aSNikolay Aleksandrov goto unlock; 18770909e117SHerbert Xu } 18787f0aec7aSNikolay Aleksandrov err = 0; 18797f0aec7aSNikolay Aleksandrov unlock: 18800909e117SHerbert Xu spin_unlock(&br->multicast_lock); 18810909e117SHerbert Xu 18820909e117SHerbert Xu return err; 18830909e117SHerbert Xu } 1884561f1103SHerbert Xu 1885cc0fdd80SLinus Lüssing static void br_multicast_start_querier(struct net_bridge *br, 188690010b36SLinus Lüssing struct bridge_mcast_own_query *query) 1887561f1103SHerbert Xu { 1888561f1103SHerbert Xu struct net_bridge_port *port; 188974857216SHerbert Xu 1890cc0fdd80SLinus Lüssing __br_multicast_open(br, query); 189174857216SHerbert Xu 189274857216SHerbert Xu list_for_each_entry(port, &br->port_list, list) { 189374857216SHerbert Xu if (port->state == BR_STATE_DISABLED || 189474857216SHerbert Xu port->state == BR_STATE_BLOCKING) 189574857216SHerbert Xu continue; 189674857216SHerbert Xu 189790010b36SLinus Lüssing if (query == &br->ip4_own_query) 189890010b36SLinus Lüssing br_multicast_enable(&port->ip4_own_query); 1899cc0fdd80SLinus Lüssing #if IS_ENABLED(CONFIG_IPV6) 1900cc0fdd80SLinus Lüssing else 190190010b36SLinus Lüssing br_multicast_enable(&port->ip6_own_query); 1902cc0fdd80SLinus Lüssing #endif 190374857216SHerbert Xu } 190474857216SHerbert Xu } 190574857216SHerbert Xu 190674857216SHerbert Xu int br_multicast_toggle(struct net_bridge *br, unsigned long val) 190774857216SHerbert Xu { 19083a7fda06SHerbert Xu int err = 0; 1909e8051688SEric Dumazet struct net_bridge_mdb_htable *mdb; 1910561f1103SHerbert Xu 1911ef5e0d82SAndrey Vagin spin_lock_bh(&br->multicast_lock); 1912561f1103SHerbert Xu if (br->multicast_disabled == !val) 1913561f1103SHerbert Xu goto unlock; 1914561f1103SHerbert Xu 1915561f1103SHerbert Xu br->multicast_disabled = !val; 1916561f1103SHerbert Xu if (br->multicast_disabled) 1917561f1103SHerbert Xu goto unlock; 1918561f1103SHerbert Xu 19193a7fda06SHerbert Xu if (!netif_running(br->dev)) 19203a7fda06SHerbert Xu goto unlock; 19213a7fda06SHerbert Xu 1922e8051688SEric Dumazet mdb = mlock_dereference(br->mdb, br); 1923e8051688SEric Dumazet if (mdb) { 1924e8051688SEric Dumazet if (mdb->old) { 1925561f1103SHerbert Xu err = -EEXIST; 1926561f1103SHerbert Xu rollback: 1927561f1103SHerbert Xu br->multicast_disabled = !!val; 1928561f1103SHerbert Xu goto unlock; 1929561f1103SHerbert Xu } 1930561f1103SHerbert Xu 1931e8051688SEric Dumazet err = br_mdb_rehash(&br->mdb, mdb->max, 1932561f1103SHerbert Xu br->hash_elasticity); 1933561f1103SHerbert Xu if (err) 1934561f1103SHerbert Xu goto rollback; 1935561f1103SHerbert Xu } 1936561f1103SHerbert Xu 193790010b36SLinus Lüssing br_multicast_start_querier(br, &br->ip4_own_query); 1938cc0fdd80SLinus Lüssing #if IS_ENABLED(CONFIG_IPV6) 193990010b36SLinus Lüssing br_multicast_start_querier(br, &br->ip6_own_query); 1940cc0fdd80SLinus Lüssing #endif 1941561f1103SHerbert Xu 1942561f1103SHerbert Xu unlock: 1943ef5e0d82SAndrey Vagin spin_unlock_bh(&br->multicast_lock); 1944561f1103SHerbert Xu 1945561f1103SHerbert Xu return err; 1946561f1103SHerbert Xu } 1947b195167fSHerbert Xu 1948c5c23260SHerbert Xu int br_multicast_set_querier(struct net_bridge *br, unsigned long val) 1949c5c23260SHerbert Xu { 1950b00589afSLinus Lüssing unsigned long max_delay; 1951b00589afSLinus Lüssing 1952c5c23260SHerbert Xu val = !!val; 1953c5c23260SHerbert Xu 1954c5c23260SHerbert Xu spin_lock_bh(&br->multicast_lock); 1955c5c23260SHerbert Xu if (br->multicast_querier == val) 1956c5c23260SHerbert Xu goto unlock; 1957c5c23260SHerbert Xu 1958c5c23260SHerbert Xu br->multicast_querier = val; 1959b00589afSLinus Lüssing if (!val) 1960b00589afSLinus Lüssing goto unlock; 1961b00589afSLinus Lüssing 1962b00589afSLinus Lüssing max_delay = br->multicast_query_response_interval; 1963b00589afSLinus Lüssing 196490010b36SLinus Lüssing if (!timer_pending(&br->ip4_other_query.timer)) 196590010b36SLinus Lüssing br->ip4_other_query.delay_time = jiffies + max_delay; 1966cc0fdd80SLinus Lüssing 196790010b36SLinus Lüssing br_multicast_start_querier(br, &br->ip4_own_query); 1968cc0fdd80SLinus Lüssing 1969cc0fdd80SLinus Lüssing #if IS_ENABLED(CONFIG_IPV6) 197090010b36SLinus Lüssing if (!timer_pending(&br->ip6_other_query.timer)) 197190010b36SLinus Lüssing br->ip6_other_query.delay_time = jiffies + max_delay; 1972cc0fdd80SLinus Lüssing 197390010b36SLinus Lüssing br_multicast_start_querier(br, &br->ip6_own_query); 1974cc0fdd80SLinus Lüssing #endif 1975c5c23260SHerbert Xu 1976c5c23260SHerbert Xu unlock: 1977c5c23260SHerbert Xu spin_unlock_bh(&br->multicast_lock); 1978c5c23260SHerbert Xu 1979c5c23260SHerbert Xu return 0; 1980c5c23260SHerbert Xu } 1981c5c23260SHerbert Xu 1982b195167fSHerbert Xu int br_multicast_set_hash_max(struct net_bridge *br, unsigned long val) 1983b195167fSHerbert Xu { 19846ae4ae8eSLinus Lüssing int err = -EINVAL; 1985b195167fSHerbert Xu u32 old; 1986e8051688SEric Dumazet struct net_bridge_mdb_htable *mdb; 1987b195167fSHerbert Xu 1988fe0d692bSCurt Brune spin_lock_bh(&br->multicast_lock); 1989b195167fSHerbert Xu if (!is_power_of_2(val)) 1990b195167fSHerbert Xu goto unlock; 1991e8051688SEric Dumazet 1992e8051688SEric Dumazet mdb = mlock_dereference(br->mdb, br); 1993e8051688SEric Dumazet if (mdb && val < mdb->size) 1994b195167fSHerbert Xu goto unlock; 1995b195167fSHerbert Xu 1996b195167fSHerbert Xu err = 0; 1997b195167fSHerbert Xu 1998b195167fSHerbert Xu old = br->hash_max; 1999b195167fSHerbert Xu br->hash_max = val; 2000b195167fSHerbert Xu 2001e8051688SEric Dumazet if (mdb) { 2002e8051688SEric Dumazet if (mdb->old) { 2003b195167fSHerbert Xu err = -EEXIST; 2004b195167fSHerbert Xu rollback: 2005b195167fSHerbert Xu br->hash_max = old; 2006b195167fSHerbert Xu goto unlock; 2007b195167fSHerbert Xu } 2008b195167fSHerbert Xu 2009b195167fSHerbert Xu err = br_mdb_rehash(&br->mdb, br->hash_max, 2010b195167fSHerbert Xu br->hash_elasticity); 2011b195167fSHerbert Xu if (err) 2012b195167fSHerbert Xu goto rollback; 2013b195167fSHerbert Xu } 2014b195167fSHerbert Xu 2015b195167fSHerbert Xu unlock: 2016fe0d692bSCurt Brune spin_unlock_bh(&br->multicast_lock); 2017b195167fSHerbert Xu 2018b195167fSHerbert Xu return err; 2019b195167fSHerbert Xu } 202007f8ac4aSLinus Lüssing 202107f8ac4aSLinus Lüssing /** 202207f8ac4aSLinus Lüssing * br_multicast_list_adjacent - Returns snooped multicast addresses 202307f8ac4aSLinus Lüssing * @dev: The bridge port adjacent to which to retrieve addresses 202407f8ac4aSLinus Lüssing * @br_ip_list: The list to store found, snooped multicast IP addresses in 202507f8ac4aSLinus Lüssing * 202607f8ac4aSLinus Lüssing * Creates a list of IP addresses (struct br_ip_list) sensed by the multicast 202707f8ac4aSLinus Lüssing * snooping feature on all bridge ports of dev's bridge device, excluding 202807f8ac4aSLinus Lüssing * the addresses from dev itself. 202907f8ac4aSLinus Lüssing * 203007f8ac4aSLinus Lüssing * Returns the number of items added to br_ip_list. 203107f8ac4aSLinus Lüssing * 203207f8ac4aSLinus Lüssing * Notes: 203307f8ac4aSLinus Lüssing * - br_ip_list needs to be initialized by caller 203407f8ac4aSLinus Lüssing * - br_ip_list might contain duplicates in the end 203507f8ac4aSLinus Lüssing * (needs to be taken care of by caller) 203607f8ac4aSLinus Lüssing * - br_ip_list needs to be freed by caller 203707f8ac4aSLinus Lüssing */ 203807f8ac4aSLinus Lüssing int br_multicast_list_adjacent(struct net_device *dev, 203907f8ac4aSLinus Lüssing struct list_head *br_ip_list) 204007f8ac4aSLinus Lüssing { 204107f8ac4aSLinus Lüssing struct net_bridge *br; 204207f8ac4aSLinus Lüssing struct net_bridge_port *port; 204307f8ac4aSLinus Lüssing struct net_bridge_port_group *group; 204407f8ac4aSLinus Lüssing struct br_ip_list *entry; 204507f8ac4aSLinus Lüssing int count = 0; 204607f8ac4aSLinus Lüssing 204707f8ac4aSLinus Lüssing rcu_read_lock(); 204807f8ac4aSLinus Lüssing if (!br_ip_list || !br_port_exists(dev)) 204907f8ac4aSLinus Lüssing goto unlock; 205007f8ac4aSLinus Lüssing 205107f8ac4aSLinus Lüssing port = br_port_get_rcu(dev); 205207f8ac4aSLinus Lüssing if (!port || !port->br) 205307f8ac4aSLinus Lüssing goto unlock; 205407f8ac4aSLinus Lüssing 205507f8ac4aSLinus Lüssing br = port->br; 205607f8ac4aSLinus Lüssing 205707f8ac4aSLinus Lüssing list_for_each_entry_rcu(port, &br->port_list, list) { 205807f8ac4aSLinus Lüssing if (!port->dev || port->dev == dev) 205907f8ac4aSLinus Lüssing continue; 206007f8ac4aSLinus Lüssing 206107f8ac4aSLinus Lüssing hlist_for_each_entry_rcu(group, &port->mglist, mglist) { 206207f8ac4aSLinus Lüssing entry = kmalloc(sizeof(*entry), GFP_ATOMIC); 206307f8ac4aSLinus Lüssing if (!entry) 206407f8ac4aSLinus Lüssing goto unlock; 206507f8ac4aSLinus Lüssing 206607f8ac4aSLinus Lüssing entry->addr = group->addr; 206707f8ac4aSLinus Lüssing list_add(&entry->list, br_ip_list); 206807f8ac4aSLinus Lüssing count++; 206907f8ac4aSLinus Lüssing } 207007f8ac4aSLinus Lüssing } 207107f8ac4aSLinus Lüssing 207207f8ac4aSLinus Lüssing unlock: 207307f8ac4aSLinus Lüssing rcu_read_unlock(); 207407f8ac4aSLinus Lüssing return count; 207507f8ac4aSLinus Lüssing } 207607f8ac4aSLinus Lüssing EXPORT_SYMBOL_GPL(br_multicast_list_adjacent); 20772cd41431SLinus Lüssing 20782cd41431SLinus Lüssing /** 2079c34963e2SLinus Lüssing * br_multicast_has_querier_anywhere - Checks for a querier on a bridge 2080c34963e2SLinus Lüssing * @dev: The bridge port providing the bridge on which to check for a querier 2081c34963e2SLinus Lüssing * @proto: The protocol family to check for: IGMP -> ETH_P_IP, MLD -> ETH_P_IPV6 2082c34963e2SLinus Lüssing * 2083c34963e2SLinus Lüssing * Checks whether the given interface has a bridge on top and if so returns 2084c34963e2SLinus Lüssing * true if a valid querier exists anywhere on the bridged link layer. 2085c34963e2SLinus Lüssing * Otherwise returns false. 2086c34963e2SLinus Lüssing */ 2087c34963e2SLinus Lüssing bool br_multicast_has_querier_anywhere(struct net_device *dev, int proto) 2088c34963e2SLinus Lüssing { 2089c34963e2SLinus Lüssing struct net_bridge *br; 2090c34963e2SLinus Lüssing struct net_bridge_port *port; 2091c34963e2SLinus Lüssing struct ethhdr eth; 2092c34963e2SLinus Lüssing bool ret = false; 2093c34963e2SLinus Lüssing 2094c34963e2SLinus Lüssing rcu_read_lock(); 2095c34963e2SLinus Lüssing if (!br_port_exists(dev)) 2096c34963e2SLinus Lüssing goto unlock; 2097c34963e2SLinus Lüssing 2098c34963e2SLinus Lüssing port = br_port_get_rcu(dev); 2099c34963e2SLinus Lüssing if (!port || !port->br) 2100c34963e2SLinus Lüssing goto unlock; 2101c34963e2SLinus Lüssing 2102c34963e2SLinus Lüssing br = port->br; 2103c34963e2SLinus Lüssing 2104c34963e2SLinus Lüssing memset(ð, 0, sizeof(eth)); 2105c34963e2SLinus Lüssing eth.h_proto = htons(proto); 2106c34963e2SLinus Lüssing 2107c34963e2SLinus Lüssing ret = br_multicast_querier_exists(br, ð); 2108c34963e2SLinus Lüssing 2109c34963e2SLinus Lüssing unlock: 2110c34963e2SLinus Lüssing rcu_read_unlock(); 2111c34963e2SLinus Lüssing return ret; 2112c34963e2SLinus Lüssing } 2113c34963e2SLinus Lüssing EXPORT_SYMBOL_GPL(br_multicast_has_querier_anywhere); 2114c34963e2SLinus Lüssing 2115c34963e2SLinus Lüssing /** 21162cd41431SLinus Lüssing * br_multicast_has_querier_adjacent - Checks for a querier behind a bridge port 21172cd41431SLinus Lüssing * @dev: The bridge port adjacent to which to check for a querier 21182cd41431SLinus Lüssing * @proto: The protocol family to check for: IGMP -> ETH_P_IP, MLD -> ETH_P_IPV6 21192cd41431SLinus Lüssing * 21202cd41431SLinus Lüssing * Checks whether the given interface has a bridge on top and if so returns 21212cd41431SLinus Lüssing * true if a selected querier is behind one of the other ports of this 21222cd41431SLinus Lüssing * bridge. Otherwise returns false. 21232cd41431SLinus Lüssing */ 21242cd41431SLinus Lüssing bool br_multicast_has_querier_adjacent(struct net_device *dev, int proto) 21252cd41431SLinus Lüssing { 21262cd41431SLinus Lüssing struct net_bridge *br; 21272cd41431SLinus Lüssing struct net_bridge_port *port; 21282cd41431SLinus Lüssing bool ret = false; 21292cd41431SLinus Lüssing 21302cd41431SLinus Lüssing rcu_read_lock(); 21312cd41431SLinus Lüssing if (!br_port_exists(dev)) 21322cd41431SLinus Lüssing goto unlock; 21332cd41431SLinus Lüssing 21342cd41431SLinus Lüssing port = br_port_get_rcu(dev); 21352cd41431SLinus Lüssing if (!port || !port->br) 21362cd41431SLinus Lüssing goto unlock; 21372cd41431SLinus Lüssing 21382cd41431SLinus Lüssing br = port->br; 21392cd41431SLinus Lüssing 21402cd41431SLinus Lüssing switch (proto) { 21412cd41431SLinus Lüssing case ETH_P_IP: 21422cd41431SLinus Lüssing if (!timer_pending(&br->ip4_other_query.timer) || 21432cd41431SLinus Lüssing rcu_dereference(br->ip4_querier.port) == port) 21442cd41431SLinus Lüssing goto unlock; 21452cd41431SLinus Lüssing break; 21463993c4e1SLinus Lüssing #if IS_ENABLED(CONFIG_IPV6) 21472cd41431SLinus Lüssing case ETH_P_IPV6: 21482cd41431SLinus Lüssing if (!timer_pending(&br->ip6_other_query.timer) || 21492cd41431SLinus Lüssing rcu_dereference(br->ip6_querier.port) == port) 21502cd41431SLinus Lüssing goto unlock; 21512cd41431SLinus Lüssing break; 21523993c4e1SLinus Lüssing #endif 21532cd41431SLinus Lüssing default: 21542cd41431SLinus Lüssing goto unlock; 21552cd41431SLinus Lüssing } 21562cd41431SLinus Lüssing 21572cd41431SLinus Lüssing ret = true; 21582cd41431SLinus Lüssing unlock: 21592cd41431SLinus Lüssing rcu_read_unlock(); 21602cd41431SLinus Lüssing return ret; 21612cd41431SLinus Lüssing } 21622cd41431SLinus Lüssing EXPORT_SYMBOL_GPL(br_multicast_has_querier_adjacent); 2163