3edc2cab5ec5c6426d809bd788b100381aacd79c
[openwrt.git] / target / linux / generic / patches-3.10 / 070-net_bridge_backports.patch
1 --- a/net/bridge/br_device.c
2 +++ b/net/bridge/br_device.c
3 @@ -67,7 +67,8 @@ netdev_tx_t br_dev_xmit(struct sk_buff *
4                 }
5  
6                 mdst = br_mdb_get(br, skb, vid);
7 -               if (mdst || BR_INPUT_SKB_CB_MROUTERS_ONLY(skb))
8 +               if ((mdst || BR_INPUT_SKB_CB_MROUTERS_ONLY(skb)) &&
9 +                   br_multicast_querier_exists(br, eth_hdr(skb)))
10                         br_multicast_deliver(mdst, skb);
11                 else
12                         br_flood_deliver(br, skb);
13 --- a/net/bridge/br_input.c
14 +++ b/net/bridge/br_input.c
15 @@ -98,7 +98,8 @@ int br_handle_frame_finish(struct sk_buf
16                 skb2 = skb;
17         else if (is_multicast_ether_addr(dest)) {
18                 mdst = br_mdb_get(br, skb, vid);
19 -               if (mdst || BR_INPUT_SKB_CB_MROUTERS_ONLY(skb)) {
20 +               if ((mdst || BR_INPUT_SKB_CB_MROUTERS_ONLY(skb)) &&
21 +                   br_multicast_querier_exists(br, eth_hdr(skb))) {
22                         if ((mdst && mdst->mglist) ||
23                             br_multicast_is_router(br))
24                                 skb2 = skb;
25 --- a/net/bridge/br_multicast.c
26 +++ b/net/bridge/br_multicast.c
27 @@ -23,16 +23,19 @@
28  #include <linux/skbuff.h>
29  #include <linux/slab.h>
30  #include <linux/timer.h>
31 +#include <linux/inetdevice.h>
32  #include <net/ip.h>
33  #if IS_ENABLED(CONFIG_IPV6)
34  #include <net/ipv6.h>
35  #include <net/mld.h>
36  #include <net/ip6_checksum.h>
37 +#include <net/addrconf.h>
38  #endif
39  
40  #include "br_private.h"
41  
42 -static void br_multicast_start_querier(struct net_bridge *br);
43 +static void br_multicast_start_querier(struct net_bridge *br,
44 +                                      struct bridge_mcast_query *query);
45  unsigned int br_mdb_rehash_seq;
46  
47  static inline int br_ip_equal(const struct br_ip *a, const struct br_ip *b)
48 @@ -381,7 +384,8 @@ static struct sk_buff *br_ip4_multicast_
49         iph->frag_off = htons(IP_DF);
50         iph->ttl = 1;
51         iph->protocol = IPPROTO_IGMP;
52 -       iph->saddr = 0;
53 +       iph->saddr = br->multicast_query_use_ifaddr ?
54 +                    inet_select_addr(br->dev, 0, RT_SCOPE_LINK) : 0;
55         iph->daddr = htonl(INADDR_ALLHOSTS_GROUP);
56         ((u8 *)&iph[1])[0] = IPOPT_RA;
57         ((u8 *)&iph[1])[1] = 4;
58 @@ -724,7 +728,7 @@ static int br_ip6_multicast_add_group(st
59  {
60         struct br_ip br_group;
61  
62 -       if (!ipv6_is_transient_multicast(group))
63 +       if (ipv6_addr_is_ll_all_nodes(group))
64                 return 0;
65  
66         br_group.u.ip6 = *group;
67 @@ -756,20 +760,35 @@ static void br_multicast_local_router_ex
68  {
69  }
70  
71 -static void br_multicast_querier_expired(unsigned long data)
72 +static void br_multicast_querier_expired(struct net_bridge *br,
73 +                                        struct bridge_mcast_query *query)
74  {
75 -       struct net_bridge *br = (void *)data;
76 -
77         spin_lock(&br->multicast_lock);
78         if (!netif_running(br->dev) || br->multicast_disabled)
79                 goto out;
80  
81 -       br_multicast_start_querier(br);
82 +       br_multicast_start_querier(br, query);
83  
84  out:
85         spin_unlock(&br->multicast_lock);
86  }
87  
88 +static void br_ip4_multicast_querier_expired(unsigned long data)
89 +{
90 +       struct net_bridge *br = (void *)data;
91 +
92 +       br_multicast_querier_expired(br, &br->ip4_query);
93 +}
94 +
95 +#if IS_ENABLED(CONFIG_IPV6)
96 +static void br_ip6_multicast_querier_expired(unsigned long data)
97 +{
98 +       struct net_bridge *br = (void *)data;
99 +
100 +       br_multicast_querier_expired(br, &br->ip6_query);
101 +}
102 +#endif
103 +
104  static void __br_multicast_send_query(struct net_bridge *br,
105                                       struct net_bridge_port *port,
106                                       struct br_ip *ip)
107 @@ -790,37 +809,45 @@ static void __br_multicast_send_query(st
108  }
109  
110  static void br_multicast_send_query(struct net_bridge *br,
111 -                                   struct net_bridge_port *port, u32 sent)
112 +                                   struct net_bridge_port *port,
113 +                                   struct bridge_mcast_query *query)
114  {
115         unsigned long time;
116         struct br_ip br_group;
117 +       struct bridge_mcast_querier *querier = NULL;
118  
119         if (!netif_running(br->dev) || br->multicast_disabled ||
120 -           !br->multicast_querier ||
121 -           timer_pending(&br->multicast_querier_timer))
122 +           !br->multicast_querier)
123                 return;
124  
125         memset(&br_group.u, 0, sizeof(br_group.u));
126  
127 -       br_group.proto = htons(ETH_P_IP);
128 -       __br_multicast_send_query(br, port, &br_group);
129 -
130 +       if (port ? (query == &port->ip4_query) :
131 +                  (query == &br->ip4_query)) {
132 +               querier = &br->ip4_querier;
133 +               br_group.proto = htons(ETH_P_IP);
134  #if IS_ENABLED(CONFIG_IPV6)
135 -       br_group.proto = htons(ETH_P_IPV6);
136 -       __br_multicast_send_query(br, port, &br_group);
137 +       } else {
138 +               querier = &br->ip6_querier;
139 +               br_group.proto = htons(ETH_P_IPV6);
140  #endif
141 +       }
142 +
143 +       if (!querier || timer_pending(&querier->timer))
144 +               return;
145 +
146 +       __br_multicast_send_query(br, port, &br_group);
147  
148         time = jiffies;
149 -       time += sent < br->multicast_startup_query_count ?
150 +       time += query->startup_sent < br->multicast_startup_query_count ?
151                 br->multicast_startup_query_interval :
152                 br->multicast_query_interval;
153 -       mod_timer(port ? &port->multicast_query_timer :
154 -                        &br->multicast_query_timer, time);
155 +       mod_timer(&query->timer, time);
156  }
157  
158 -static void br_multicast_port_query_expired(unsigned long data)
159 +static void br_multicast_port_query_expired(struct net_bridge_port *port,
160 +                                           struct bridge_mcast_query *query)
161  {
162 -       struct net_bridge_port *port = (void *)data;
163         struct net_bridge *br = port->br;
164  
165         spin_lock(&br->multicast_lock);
166 @@ -828,25 +855,43 @@ static void br_multicast_port_query_expi
167             port->state == BR_STATE_BLOCKING)
168                 goto out;
169  
170 -       if (port->multicast_startup_queries_sent <
171 -           br->multicast_startup_query_count)
172 -               port->multicast_startup_queries_sent++;
173 +       if (query->startup_sent < br->multicast_startup_query_count)
174 +               query->startup_sent++;
175  
176 -       br_multicast_send_query(port->br, port,
177 -                               port->multicast_startup_queries_sent);
178 +       br_multicast_send_query(port->br, port, query);
179  
180  out:
181         spin_unlock(&br->multicast_lock);
182  }
183  
184 +static void br_ip4_multicast_port_query_expired(unsigned long data)
185 +{
186 +       struct net_bridge_port *port = (void *)data;
187 +
188 +       br_multicast_port_query_expired(port, &port->ip4_query);
189 +}
190 +
191 +#if IS_ENABLED(CONFIG_IPV6)
192 +static void br_ip6_multicast_port_query_expired(unsigned long data)
193 +{
194 +       struct net_bridge_port *port = (void *)data;
195 +
196 +       br_multicast_port_query_expired(port, &port->ip6_query);
197 +}
198 +#endif
199 +
200  void br_multicast_add_port(struct net_bridge_port *port)
201  {
202         port->multicast_router = 1;
203  
204         setup_timer(&port->multicast_router_timer, br_multicast_router_expired,
205                     (unsigned long)port);
206 -       setup_timer(&port->multicast_query_timer,
207 -                   br_multicast_port_query_expired, (unsigned long)port);
208 +       setup_timer(&port->ip4_query.timer, br_ip4_multicast_port_query_expired,
209 +                   (unsigned long)port);
210 +#if IS_ENABLED(CONFIG_IPV6)
211 +       setup_timer(&port->ip6_query.timer, br_ip6_multicast_port_query_expired,
212 +                   (unsigned long)port);
213 +#endif
214  }
215  
216  void br_multicast_del_port(struct net_bridge_port *port)
217 @@ -854,13 +899,13 @@ void br_multicast_del_port(struct net_br
218         del_timer_sync(&port->multicast_router_timer);
219  }
220  
221 -static void __br_multicast_enable_port(struct net_bridge_port *port)
222 +static void br_multicast_enable(struct bridge_mcast_query *query)
223  {
224 -       port->multicast_startup_queries_sent = 0;
225 +       query->startup_sent = 0;
226  
227 -       if (try_to_del_timer_sync(&port->multicast_query_timer) >= 0 ||
228 -           del_timer(&port->multicast_query_timer))
229 -               mod_timer(&port->multicast_query_timer, jiffies);
230 +       if (try_to_del_timer_sync(&query->timer) >= 0 ||
231 +           del_timer(&query->timer))
232 +               mod_timer(&query->timer, jiffies);
233  }
234  
235  void br_multicast_enable_port(struct net_bridge_port *port)
236 @@ -871,7 +916,10 @@ void br_multicast_enable_port(struct net
237         if (br->multicast_disabled || !netif_running(br->dev))
238                 goto out;
239  
240 -       __br_multicast_enable_port(port);
241 +       br_multicast_enable(&port->ip4_query);
242 +#if IS_ENABLED(CONFIG_IPV6)
243 +       br_multicast_enable(&port->ip6_query);
244 +#endif
245  
246  out:
247         spin_unlock(&br->multicast_lock);
248 @@ -890,7 +938,10 @@ void br_multicast_disable_port(struct ne
249         if (!hlist_unhashed(&port->rlist))
250                 hlist_del_init_rcu(&port->rlist);
251         del_timer(&port->multicast_router_timer);
252 -       del_timer(&port->multicast_query_timer);
253 +       del_timer(&port->ip4_query.timer);
254 +#if IS_ENABLED(CONFIG_IPV6)
255 +       del_timer(&port->ip6_query.timer);
256 +#endif
257         spin_unlock(&br->multicast_lock);
258  }
259  
260 @@ -1015,6 +1066,17 @@ static int br_ip6_multicast_mld2_report(
261  }
262  #endif
263  
264 +static void
265 +br_multicast_update_querier_timer(struct net_bridge *br,
266 +                                 struct bridge_mcast_querier *querier,
267 +                                 unsigned long max_delay)
268 +{
269 +       if (!timer_pending(&querier->timer))
270 +               querier->delay_time = jiffies + max_delay;
271 +
272 +       mod_timer(&querier->timer, jiffies + br->multicast_querier_interval);
273 +}
274 +
275  /*
276   * Add port to rotuer_list
277   *  list is maintained ordered by pointer value
278 @@ -1065,12 +1127,13 @@ timer:
279  
280  static void br_multicast_query_received(struct net_bridge *br,
281                                         struct net_bridge_port *port,
282 -                                       int saddr)
283 +                                       struct bridge_mcast_querier *querier,
284 +                                       int saddr,
285 +                                       unsigned long max_delay)
286  {
287         if (saddr)
288 -               mod_timer(&br->multicast_querier_timer,
289 -                         jiffies + br->multicast_querier_interval);
290 -       else if (timer_pending(&br->multicast_querier_timer))
291 +               br_multicast_update_querier_timer(br, querier, max_delay);
292 +       else if (timer_pending(&querier->timer))
293                 return;
294  
295         br_multicast_mark_router(br, port);
296 @@ -1097,8 +1160,6 @@ static int br_ip4_multicast_query(struct
297             (port && port->state == BR_STATE_DISABLED))
298                 goto out;
299  
300 -       br_multicast_query_received(br, port, !!iph->saddr);
301 -
302         group = ih->group;
303  
304         if (skb->len == sizeof(*ih)) {
305 @@ -1122,6 +1183,9 @@ static int br_ip4_multicast_query(struct
306                             IGMPV3_MRC(ih3->code) * (HZ / IGMP_TIMER_SCALE) : 1;
307         }
308  
309 +       br_multicast_query_received(br, port, &br->ip4_querier, !!iph->saddr,
310 +                                   max_delay);
311 +
312         if (!group)
313                 goto out;
314  
315 @@ -1174,8 +1238,6 @@ static int br_ip6_multicast_query(struct
316             (port && port->state == BR_STATE_DISABLED))
317                 goto out;
318  
319 -       br_multicast_query_received(br, port, !ipv6_addr_any(&ip6h->saddr));
320 -
321         /* RFC2710+RFC3810 (MLDv1+MLDv2) require link-local source addresses */
322         if (!(ipv6_addr_type(&ip6h->saddr) & IPV6_ADDR_LINKLOCAL)) {
323                 err = -EINVAL;
324 @@ -1203,6 +1265,9 @@ static int br_ip6_multicast_query(struct
325                 max_delay = max(msecs_to_jiffies(MLDV2_MRC(ntohs(mld2q->mld2q_mrc))), 1UL);
326         }
327  
328 +       br_multicast_query_received(br, port, &br->ip6_querier,
329 +                                   !ipv6_addr_any(&ip6h->saddr), max_delay);
330 +
331         if (!group)
332                 goto out;
333  
334 @@ -1235,7 +1300,9 @@ out:
335  
336  static void br_multicast_leave_group(struct net_bridge *br,
337                                      struct net_bridge_port *port,
338 -                                    struct br_ip *group)
339 +                                    struct br_ip *group,
340 +                                    struct bridge_mcast_querier *querier,
341 +                                    struct bridge_mcast_query *query)
342  {
343         struct net_bridge_mdb_htable *mdb;
344         struct net_bridge_mdb_entry *mp;
345 @@ -1246,7 +1313,7 @@ static void br_multicast_leave_group(str
346         spin_lock(&br->multicast_lock);
347         if (!netif_running(br->dev) ||
348             (port && port->state == BR_STATE_DISABLED) ||
349 -           timer_pending(&br->multicast_querier_timer))
350 +           timer_pending(&querier->timer))
351                 goto out;
352  
353         mdb = mlock_dereference(br->mdb, br);
354 @@ -1254,6 +1321,31 @@ static void br_multicast_leave_group(str
355         if (!mp)
356                 goto out;
357  
358 +       if (br->multicast_querier) {
359 +               __br_multicast_send_query(br, port, &mp->addr);
360 +
361 +               time = jiffies + br->multicast_last_member_count *
362 +                                br->multicast_last_member_interval;
363 +
364 +               mod_timer(&query->timer, time);
365 +
366 +               for (p = mlock_dereference(mp->ports, br);
367 +                    p != NULL;
368 +                    p = mlock_dereference(p->next, br)) {
369 +                       if (p->port != port)
370 +                               continue;
371 +
372 +                       if (!hlist_unhashed(&p->mglist) &&
373 +                           (timer_pending(&p->timer) ?
374 +                            time_after(p->timer.expires, time) :
375 +                            try_to_del_timer_sync(&p->timer) >= 0)) {
376 +                               mod_timer(&p->timer, time);
377 +                       }
378 +
379 +                       break;
380 +               }
381 +       }
382 +
383         if (port && (port->flags & BR_MULTICAST_FAST_LEAVE)) {
384                 struct net_bridge_port_group __rcu **pp;
385  
386 @@ -1306,7 +1398,6 @@ static void br_multicast_leave_group(str
387  
388                 break;
389         }
390 -
391  out:
392         spin_unlock(&br->multicast_lock);
393  }
394 @@ -1317,6 +1408,8 @@ static void br_ip4_multicast_leave_group
395                                          __u16 vid)
396  {
397         struct br_ip br_group;
398 +       struct bridge_mcast_query *query = port ? &port->ip4_query :
399 +                                                 &br->ip4_query;
400  
401         if (ipv4_is_local_multicast(group))
402                 return;
403 @@ -1325,7 +1418,7 @@ static void br_ip4_multicast_leave_group
404         br_group.proto = htons(ETH_P_IP);
405         br_group.vid = vid;
406  
407 -       br_multicast_leave_group(br, port, &br_group);
408 +       br_multicast_leave_group(br, port, &br_group, &br->ip4_querier, query);
409  }
410  
411  #if IS_ENABLED(CONFIG_IPV6)
412 @@ -1335,15 +1428,18 @@ static void br_ip6_multicast_leave_group
413                                          __u16 vid)
414  {
415         struct br_ip br_group;
416 +       struct bridge_mcast_query *query = port ? &port->ip6_query :
417 +                                                 &br->ip6_query;
418  
419 -       if (!ipv6_is_transient_multicast(group))
420 +
421 +       if (ipv6_addr_is_ll_all_nodes(group))
422                 return;
423  
424         br_group.u.ip6 = *group;
425         br_group.proto = htons(ETH_P_IPV6);
426         br_group.vid = vid;
427  
428 -       br_multicast_leave_group(br, port, &br_group);
429 +       br_multicast_leave_group(br, port, &br_group, &br->ip6_querier, query);
430  }
431  #endif
432  
433 @@ -1473,8 +1569,14 @@ static int br_multicast_ipv6_rcv(struct 
434          *  - MLD has always Router Alert hop-by-hop option
435          *  - But we do not support jumbrograms.
436          */
437 -       if (ip6h->version != 6 ||
438 -           ip6h->nexthdr != IPPROTO_HOPOPTS ||
439 +       if (ip6h->version != 6)
440 +               return 0;
441 +
442 +       /* Prevent flooding this packet if there is no listener present */
443 +       if (!ipv6_addr_is_ll_all_nodes(&ip6h->daddr))
444 +               BR_INPUT_SKB_CB(skb)->mrouters_only = 1;
445 +
446 +       if (ip6h->nexthdr != IPPROTO_HOPOPTS ||
447             ip6h->payload_len == 0)
448                 return 0;
449  
450 @@ -1605,19 +1707,32 @@ int br_multicast_rcv(struct net_bridge *
451         return 0;
452  }
453  
454 -static void br_multicast_query_expired(unsigned long data)
455 +static void br_multicast_query_expired(struct net_bridge *br,
456 +                                      struct bridge_mcast_query *query)
457 +{
458 +       spin_lock(&br->multicast_lock);
459 +       if (query->startup_sent < br->multicast_startup_query_count)
460 +               query->startup_sent++;
461 +
462 +       br_multicast_send_query(br, NULL, query);
463 +       spin_unlock(&br->multicast_lock);
464 +}
465 +
466 +static void br_ip4_multicast_query_expired(unsigned long data)
467  {
468         struct net_bridge *br = (void *)data;
469  
470 -       spin_lock(&br->multicast_lock);
471 -       if (br->multicast_startup_queries_sent <
472 -           br->multicast_startup_query_count)
473 -               br->multicast_startup_queries_sent++;
474 +       br_multicast_query_expired(br, &br->ip4_query);
475 +}
476  
477 -       br_multicast_send_query(br, NULL, br->multicast_startup_queries_sent);
478 +#if IS_ENABLED(CONFIG_IPV6)
479 +static void br_ip6_multicast_query_expired(unsigned long data)
480 +{
481 +       struct net_bridge *br = (void *)data;
482  
483 -       spin_unlock(&br->multicast_lock);
484 +       br_multicast_query_expired(br, &br->ip6_query);
485  }
486 +#endif
487  
488  void br_multicast_init(struct net_bridge *br)
489  {
490 @@ -1626,6 +1741,7 @@ void br_multicast_init(struct net_bridge
491  
492         br->multicast_router = 1;
493         br->multicast_querier = 0;
494 +       br->multicast_query_use_ifaddr = 0;
495         br->multicast_last_member_count = 2;
496         br->multicast_startup_query_count = 2;
497  
498 @@ -1636,23 +1752,43 @@ void br_multicast_init(struct net_bridge
499         br->multicast_querier_interval = 255 * HZ;
500         br->multicast_membership_interval = 260 * HZ;
501  
502 +       br->ip4_querier.delay_time = 0;
503 +#if IS_ENABLED(CONFIG_IPV6)
504 +       br->ip6_querier.delay_time = 0;
505 +#endif
506 +
507         spin_lock_init(&br->multicast_lock);
508         setup_timer(&br->multicast_router_timer,
509                     br_multicast_local_router_expired, 0);
510 -       setup_timer(&br->multicast_querier_timer,
511 -                   br_multicast_querier_expired, (unsigned long)br);
512 -       setup_timer(&br->multicast_query_timer, br_multicast_query_expired,
513 +       setup_timer(&br->ip4_querier.timer, br_ip4_multicast_querier_expired,
514                     (unsigned long)br);
515 +       setup_timer(&br->ip4_query.timer, br_ip4_multicast_query_expired,
516 +                   (unsigned long)br);
517 +#if IS_ENABLED(CONFIG_IPV6)
518 +       setup_timer(&br->ip6_querier.timer, br_ip6_multicast_querier_expired,
519 +                   (unsigned long)br);
520 +       setup_timer(&br->ip6_query.timer, br_ip6_multicast_query_expired,
521 +                   (unsigned long)br);
522 +#endif
523  }
524  
525 -void br_multicast_open(struct net_bridge *br)
526 +static void __br_multicast_open(struct net_bridge *br,
527 +                               struct bridge_mcast_query *query)
528  {
529 -       br->multicast_startup_queries_sent = 0;
530 +       query->startup_sent = 0;
531  
532         if (br->multicast_disabled)
533                 return;
534  
535 -       mod_timer(&br->multicast_query_timer, jiffies);
536 +       mod_timer(&query->timer, jiffies);
537 +}
538 +
539 +void br_multicast_open(struct net_bridge *br)
540 +{
541 +       __br_multicast_open(br, &br->ip4_query);
542 +#if IS_ENABLED(CONFIG_IPV6)
543 +       __br_multicast_open(br, &br->ip6_query);
544 +#endif
545  }
546  
547  void br_multicast_stop(struct net_bridge *br)
548 @@ -1664,8 +1800,12 @@ void br_multicast_stop(struct net_bridge
549         int i;
550  
551         del_timer_sync(&br->multicast_router_timer);
552 -       del_timer_sync(&br->multicast_querier_timer);
553 -       del_timer_sync(&br->multicast_query_timer);
554 +       del_timer_sync(&br->ip4_querier.timer);
555 +       del_timer_sync(&br->ip4_query.timer);
556 +#if IS_ENABLED(CONFIG_IPV6)
557 +       del_timer_sync(&br->ip6_querier.timer);
558 +       del_timer_sync(&br->ip6_query.timer);
559 +#endif
560  
561         spin_lock_bh(&br->multicast_lock);
562         mdb = mlock_dereference(br->mdb, br);
563 @@ -1767,18 +1907,24 @@ unlock:
564         return err;
565  }
566  
567 -static void br_multicast_start_querier(struct net_bridge *br)
568 +static void br_multicast_start_querier(struct net_bridge *br,
569 +                                      struct bridge_mcast_query *query)
570  {
571         struct net_bridge_port *port;
572  
573 -       br_multicast_open(br);
574 +       __br_multicast_open(br, query);
575  
576         list_for_each_entry(port, &br->port_list, list) {
577                 if (port->state == BR_STATE_DISABLED ||
578                     port->state == BR_STATE_BLOCKING)
579                         continue;
580  
581 -               __br_multicast_enable_port(port);
582 +               if (query == &br->ip4_query)
583 +                       br_multicast_enable(&port->ip4_query);
584 +#if IS_ENABLED(CONFIG_IPV6)
585 +               else
586 +                       br_multicast_enable(&port->ip6_query);
587 +#endif
588         }
589  }
590  
591 @@ -1813,7 +1959,10 @@ rollback:
592                         goto rollback;
593         }
594  
595 -       br_multicast_start_querier(br);
596 +       br_multicast_start_querier(br, &br->ip4_query);
597 +#if IS_ENABLED(CONFIG_IPV6)
598 +       br_multicast_start_querier(br, &br->ip6_query);
599 +#endif
600  
601  unlock:
602         spin_unlock_bh(&br->multicast_lock);
603 @@ -1823,6 +1972,8 @@ unlock:
604  
605  int br_multicast_set_querier(struct net_bridge *br, unsigned long val)
606  {
607 +       unsigned long max_delay;
608 +
609         val = !!val;
610  
611         spin_lock_bh(&br->multicast_lock);
612 @@ -1830,8 +1981,22 @@ int br_multicast_set_querier(struct net_
613                 goto unlock;
614  
615         br->multicast_querier = val;
616 -       if (val)
617 -               br_multicast_start_querier(br);
618 +       if (!val)
619 +               goto unlock;
620 +
621 +       max_delay = br->multicast_query_response_interval;
622 +
623 +       if (!timer_pending(&br->ip4_querier.timer))
624 +               br->ip4_querier.delay_time = jiffies + max_delay;
625 +
626 +       br_multicast_start_querier(br, &br->ip4_query);
627 +
628 +#if IS_ENABLED(CONFIG_IPV6)
629 +       if (!timer_pending(&br->ip6_querier.timer))
630 +               br->ip6_querier.delay_time = jiffies + max_delay;
631 +
632 +       br_multicast_start_querier(br, &br->ip6_query);
633 +#endif
634  
635  unlock:
636         spin_unlock_bh(&br->multicast_lock);
637 --- a/net/bridge/br_private.h
638 +++ b/net/bridge/br_private.h
639 @@ -66,6 +66,20 @@ struct br_ip
640         __u16           vid;
641  };
642  
643 +#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
644 +/* our own querier */
645 +struct bridge_mcast_query {
646 +       struct timer_list       timer;
647 +       u32                     startup_sent;
648 +};
649 +
650 +/* other querier */
651 +struct bridge_mcast_querier {
652 +       struct timer_list               timer;
653 +       unsigned long                   delay_time;
654 +};
655 +#endif
656 +
657  struct net_port_vlans {
658         u16                             port_idx;
659         u16                             pvid;
660 @@ -159,10 +173,12 @@ struct net_bridge_port
661  #define BR_ADMIN_COST          0x00000010
662  
663  #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
664 -       u32                             multicast_startup_queries_sent;
665 +       struct bridge_mcast_query       ip4_query;
666 +#if IS_ENABLED(CONFIG_IPV6)
667 +       struct bridge_mcast_query       ip6_query;
668 +#endif /* IS_ENABLED(CONFIG_IPV6) */
669         unsigned char                   multicast_router;
670         struct timer_list               multicast_router_timer;
671 -       struct timer_list               multicast_query_timer;
672         struct hlist_head               mglist;
673         struct hlist_node               rlist;
674  #endif
675 @@ -246,12 +262,12 @@ struct net_bridge
676  
677         u8                              multicast_disabled:1;
678         u8                              multicast_querier:1;
679 +       u8                              multicast_query_use_ifaddr:1;
680  
681         u32                             hash_elasticity;
682         u32                             hash_max;
683  
684         u32                             multicast_last_member_count;
685 -       u32                             multicast_startup_queries_sent;
686         u32                             multicast_startup_query_count;
687  
688         unsigned long                   multicast_last_member_interval;
689 @@ -266,8 +282,12 @@ struct net_bridge
690         struct hlist_head               router_list;
691  
692         struct timer_list               multicast_router_timer;
693 -       struct timer_list               multicast_querier_timer;
694 -       struct timer_list               multicast_query_timer;
695 +       struct bridge_mcast_querier     ip4_querier;
696 +       struct bridge_mcast_query       ip4_query;
697 +#if IS_ENABLED(CONFIG_IPV6)
698 +       struct bridge_mcast_querier     ip6_querier;
699 +       struct bridge_mcast_query       ip6_query;
700 +#endif /* IS_ENABLED(CONFIG_IPV6) */
701  #endif
702  
703         struct timer_list               hello_timer;
704 @@ -477,22 +497,35 @@ extern void br_mdb_notify(struct net_dev
705  #define mlock_dereference(X, br) \
706         rcu_dereference_protected(X, lockdep_is_held(&br->multicast_lock))
707  
708 -#if IS_ENABLED(CONFIG_IPV6)
709 -#include <net/addrconf.h>
710 -static inline int ipv6_is_transient_multicast(const struct in6_addr *addr)
711 -{
712 -       if (ipv6_addr_is_multicast(addr) && IPV6_ADDR_MC_FLAG_TRANSIENT(addr))
713 -               return 1;
714 -       return 0;
715 -}
716 -#endif
717 -
718  static inline bool br_multicast_is_router(struct net_bridge *br)
719  {
720         return br->multicast_router == 2 ||
721                (br->multicast_router == 1 &&
722                 timer_pending(&br->multicast_router_timer));
723  }
724 +
725 +static inline bool
726 +__br_multicast_querier_exists(struct net_bridge *br,
727 +                             struct bridge_mcast_querier *querier)
728 +{
729 +       return time_is_before_jiffies(querier->delay_time) &&
730 +              (br->multicast_querier || timer_pending(&querier->timer));
731 +}
732 +
733 +static inline bool br_multicast_querier_exists(struct net_bridge *br,
734 +                                              struct ethhdr *eth)
735 +{
736 +       switch (eth->h_proto) {
737 +       case (htons(ETH_P_IP)):
738 +               return __br_multicast_querier_exists(br, &br->ip4_querier);
739 +#if IS_ENABLED(CONFIG_IPV6)
740 +       case (htons(ETH_P_IPV6)):
741 +               return __br_multicast_querier_exists(br, &br->ip6_querier);
742 +#endif
743 +       default:
744 +               return false;
745 +       }
746 +}
747  #else
748  static inline int br_multicast_rcv(struct net_bridge *br,
749                                    struct net_bridge_port *port,
750 @@ -549,6 +582,11 @@ static inline bool br_multicast_is_route
751  {
752         return 0;
753  }
754 +static inline bool br_multicast_querier_exists(struct net_bridge *br,
755 +                                              struct ethhdr *eth)
756 +{
757 +       return false;
758 +}
759  static inline void br_mdb_init(void)
760  {
761  }
762 --- a/net/bridge/br_sysfs_br.c
763 +++ b/net/bridge/br_sysfs_br.c
764 @@ -375,6 +375,31 @@ static ssize_t store_multicast_snooping(
765  static DEVICE_ATTR(multicast_snooping, S_IRUGO | S_IWUSR,
766                    show_multicast_snooping, store_multicast_snooping);
767  
768 +static ssize_t show_multicast_query_use_ifaddr(struct device *d,
769 +                                     struct device_attribute *attr,
770 +                                     char *buf)
771 +{
772 +       struct net_bridge *br = to_bridge(d);
773 +       return sprintf(buf, "%d\n", br->multicast_query_use_ifaddr);
774 +}
775 +
776 +static int set_query_use_ifaddr(struct net_bridge *br, unsigned long val)
777 +{
778 +       br->multicast_query_use_ifaddr = !!val;
779 +       return 0;
780 +}
781 +
782 +static ssize_t
783 +store_multicast_query_use_ifaddr(struct device *d,
784 +                                struct device_attribute *attr,
785 +                                const char *buf, size_t len)
786 +{
787 +       return store_bridge_parm(d, buf, len, set_query_use_ifaddr);
788 +}
789 +static DEVICE_ATTR(multicast_query_use_ifaddr, S_IRUGO | S_IWUSR,
790 +                  show_multicast_query_use_ifaddr,
791 +                  store_multicast_query_use_ifaddr);
792 +
793  static ssize_t show_multicast_querier(struct device *d,
794                                       struct device_attribute *attr,
795                                       char *buf)
796 @@ -734,6 +759,7 @@ static struct attribute *bridge_attrs[] 
797         &dev_attr_multicast_router.attr,
798         &dev_attr_multicast_snooping.attr,
799         &dev_attr_multicast_querier.attr,
800 +       &dev_attr_multicast_query_use_ifaddr.attr,
801         &dev_attr_hash_elasticity.attr,
802         &dev_attr_hash_max.attr,
803         &dev_attr_multicast_last_member_count.attr,
804 --- a/net/bridge/br_mdb.c
805 +++ b/net/bridge/br_mdb.c
806 @@ -9,6 +9,7 @@
807  #include <net/netlink.h>
808  #if IS_ENABLED(CONFIG_IPV6)
809  #include <net/ipv6.h>
810 +#include <net/addrconf.h>
811  #endif
812  
813  #include "br_private.h"
814 @@ -253,7 +254,7 @@ static bool is_valid_mdb_entry(struct br
815                         return false;
816  #if IS_ENABLED(CONFIG_IPV6)
817         } else if (entry->addr.proto == htons(ETH_P_IPV6)) {
818 -               if (!ipv6_is_transient_multicast(&entry->addr.u.ip6))
819 +               if (ipv6_addr_is_ll_all_nodes(&entry->addr.u.ip6))
820                         return false;
821  #endif
822         } else
823 @@ -414,16 +415,20 @@ static int __br_mdb_del(struct net_bridg
824         if (!netif_running(br->dev) || br->multicast_disabled)
825                 return -EINVAL;
826  
827 -       if (timer_pending(&br->multicast_querier_timer))
828 -               return -EBUSY;
829 -
830         ip.proto = entry->addr.proto;
831 -       if (ip.proto == htons(ETH_P_IP))
832 +       if (ip.proto == htons(ETH_P_IP)) {
833 +               if (timer_pending(&br->ip4_querier.timer))
834 +                       return -EBUSY;
835 +
836                 ip.u.ip4 = entry->addr.u.ip4;
837  #if IS_ENABLED(CONFIG_IPV6)
838 -       else
839 +       } else {
840 +               if (timer_pending(&br->ip6_querier.timer))
841 +                       return -EBUSY;
842 +
843                 ip.u.ip6 = entry->addr.u.ip6;
844  #endif
845 +       }
846  
847         spin_lock_bh(&br->multicast_lock);
848         mdb = mlock_dereference(br->mdb, br);