aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Lüssing <linus.luessing@web.de>2013-08-30 11:28:17 -0400
committerDavid S. Miller <davem@davemloft.net>2013-08-30 15:24:37 -0400
commitcc0fdd802859eaeb00e1c87dbb655594bed2844c (patch)
treeeb5643ad4e5c783b28a6d936a1a91bb40e905447
parent79f9ab7e0a8ec452e58b5a5267b9eb019ff493d0 (diff)
bridge: separate querier and query timer into IGMP/IPv4 and MLD/IPv6 ones
Currently we would still potentially suffer multicast packet loss if there is just either an IGMP or an MLD querier: For the former case, we would possibly drop IPv6 multicast packets, for the latter IPv4 ones. This is because we are currently assuming that if either an IGMP or MLD querier is present that the other one is present, too. This patch makes the behaviour and fix added in "bridge: disable snooping if there is no querier" (b00589af3b04) to also work if there is either just an IGMP or an MLD querier on the link: It refines the deactivation of the snooping to be protocol specific by using separate timers for the snooped IGMP and MLD queries as well as separate timers for our internal IGMP and MLD queriers. Signed-off-by: Linus Lüssing <linus.luessing@web.de> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/bridge/br_device.c2
-rw-r--r--net/bridge/br_input.c2
-rw-r--r--net/bridge/br_mdb.c14
-rw-r--r--net/bridge/br_multicast.c258
-rw-r--r--net/bridge/br_private.h57
5 files changed, 240 insertions, 93 deletions
diff --git a/net/bridge/br_device.c b/net/bridge/br_device.c
index 69363bd37f64..89659d4ed1f9 100644
--- a/net/bridge/br_device.c
+++ b/net/bridge/br_device.c
@@ -71,7 +71,7 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev)
71 71
72 mdst = br_mdb_get(br, skb, vid); 72 mdst = br_mdb_get(br, skb, vid);
73 if ((mdst || BR_INPUT_SKB_CB_MROUTERS_ONLY(skb)) && 73 if ((mdst || BR_INPUT_SKB_CB_MROUTERS_ONLY(skb)) &&
74 br_multicast_querier_exists(br)) 74 br_multicast_querier_exists(br, eth_hdr(skb)))
75 br_multicast_deliver(mdst, skb); 75 br_multicast_deliver(mdst, skb);
76 else 76 else
77 br_flood_deliver(br, skb, false); 77 br_flood_deliver(br, skb, false);
diff --git a/net/bridge/br_input.c b/net/bridge/br_input.c
index 8c561c0aa636..a2fd37ec35f7 100644
--- a/net/bridge/br_input.c
+++ b/net/bridge/br_input.c
@@ -102,7 +102,7 @@ int br_handle_frame_finish(struct sk_buff *skb)
102 } else if (is_multicast_ether_addr(dest)) { 102 } else if (is_multicast_ether_addr(dest)) {
103 mdst = br_mdb_get(br, skb, vid); 103 mdst = br_mdb_get(br, skb, vid);
104 if ((mdst || BR_INPUT_SKB_CB_MROUTERS_ONLY(skb)) && 104 if ((mdst || BR_INPUT_SKB_CB_MROUTERS_ONLY(skb)) &&
105 br_multicast_querier_exists(br)) { 105 br_multicast_querier_exists(br, eth_hdr(skb))) {
106 if ((mdst && mdst->mglist) || 106 if ((mdst && mdst->mglist) ||
107 br_multicast_is_router(br)) 107 br_multicast_is_router(br))
108 skb2 = skb; 108 skb2 = skb;
diff --git a/net/bridge/br_mdb.c b/net/bridge/br_mdb.c
index 0daae3ec2355..6319c4333c39 100644
--- a/net/bridge/br_mdb.c
+++ b/net/bridge/br_mdb.c
@@ -414,16 +414,20 @@ static int __br_mdb_del(struct net_bridge *br, struct br_mdb_entry *entry)
414 if (!netif_running(br->dev) || br->multicast_disabled) 414 if (!netif_running(br->dev) || br->multicast_disabled)
415 return -EINVAL; 415 return -EINVAL;
416 416
417 if (timer_pending(&br->multicast_querier_timer))
418 return -EBUSY;
419
420 ip.proto = entry->addr.proto; 417 ip.proto = entry->addr.proto;
421 if (ip.proto == htons(ETH_P_IP)) 418 if (ip.proto == htons(ETH_P_IP)) {
419 if (timer_pending(&br->ip4_querier.timer))
420 return -EBUSY;
421
422 ip.u.ip4 = entry->addr.u.ip4; 422 ip.u.ip4 = entry->addr.u.ip4;
423#if IS_ENABLED(CONFIG_IPV6) 423#if IS_ENABLED(CONFIG_IPV6)
424 else 424 } else {
425 if (timer_pending(&br->ip6_querier.timer))
426 return -EBUSY;
427
425 ip.u.ip6 = entry->addr.u.ip6; 428 ip.u.ip6 = entry->addr.u.ip6;
426#endif 429#endif
430 }
427 431
428 spin_lock_bh(&br->multicast_lock); 432 spin_lock_bh(&br->multicast_lock);
429 mdb = mlock_dereference(br->mdb, br); 433 mdb = mlock_dereference(br->mdb, br);
diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
index 08e576ada0b2..9d1d0e66c357 100644
--- a/net/bridge/br_multicast.c
+++ b/net/bridge/br_multicast.c
@@ -33,7 +33,8 @@
33 33
34#include "br_private.h" 34#include "br_private.h"
35 35
36static void br_multicast_start_querier(struct net_bridge *br); 36static void br_multicast_start_querier(struct net_bridge *br,
37 struct bridge_mcast_query *query);
37unsigned int br_mdb_rehash_seq; 38unsigned int br_mdb_rehash_seq;
38 39
39static inline int br_ip_equal(const struct br_ip *a, const struct br_ip *b) 40static inline int br_ip_equal(const struct br_ip *a, const struct br_ip *b)
@@ -755,20 +756,35 @@ static void br_multicast_local_router_expired(unsigned long data)
755{ 756{
756} 757}
757 758
758static void br_multicast_querier_expired(unsigned long data) 759static void br_multicast_querier_expired(struct net_bridge *br,
760 struct bridge_mcast_query *query)
759{ 761{
760 struct net_bridge *br = (void *)data;
761
762 spin_lock(&br->multicast_lock); 762 spin_lock(&br->multicast_lock);
763 if (!netif_running(br->dev) || br->multicast_disabled) 763 if (!netif_running(br->dev) || br->multicast_disabled)
764 goto out; 764 goto out;
765 765
766 br_multicast_start_querier(br); 766 br_multicast_start_querier(br, query);
767 767
768out: 768out:
769 spin_unlock(&br->multicast_lock); 769 spin_unlock(&br->multicast_lock);
770} 770}
771 771
772static void br_ip4_multicast_querier_expired(unsigned long data)
773{
774 struct net_bridge *br = (void *)data;
775
776 br_multicast_querier_expired(br, &br->ip4_query);
777}
778
779#if IS_ENABLED(CONFIG_IPV6)
780static void br_ip6_multicast_querier_expired(unsigned long data)
781{
782 struct net_bridge *br = (void *)data;
783
784 br_multicast_querier_expired(br, &br->ip6_query);
785}
786#endif
787
772static void __br_multicast_send_query(struct net_bridge *br, 788static void __br_multicast_send_query(struct net_bridge *br,
773 struct net_bridge_port *port, 789 struct net_bridge_port *port,
774 struct br_ip *ip) 790 struct br_ip *ip)
@@ -789,37 +805,45 @@ static void __br_multicast_send_query(struct net_bridge *br,
789} 805}
790 806
791static void br_multicast_send_query(struct net_bridge *br, 807static void br_multicast_send_query(struct net_bridge *br,
792 struct net_bridge_port *port, u32 sent) 808 struct net_bridge_port *port,
809 struct bridge_mcast_query *query)
793{ 810{
794 unsigned long time; 811 unsigned long time;
795 struct br_ip br_group; 812 struct br_ip br_group;
813 struct bridge_mcast_querier *querier = NULL;
796 814
797 if (!netif_running(br->dev) || br->multicast_disabled || 815 if (!netif_running(br->dev) || br->multicast_disabled ||
798 !br->multicast_querier || 816 !br->multicast_querier)
799 timer_pending(&br->multicast_querier_timer))
800 return; 817 return;
801 818
802 memset(&br_group.u, 0, sizeof(br_group.u)); 819 memset(&br_group.u, 0, sizeof(br_group.u));
803 820
804 br_group.proto = htons(ETH_P_IP); 821 if (port ? (query == &port->ip4_query) :
805 __br_multicast_send_query(br, port, &br_group); 822 (query == &br->ip4_query)) {
806 823 querier = &br->ip4_querier;
824 br_group.proto = htons(ETH_P_IP);
807#if IS_ENABLED(CONFIG_IPV6) 825#if IS_ENABLED(CONFIG_IPV6)
808 br_group.proto = htons(ETH_P_IPV6); 826 } else {
809 __br_multicast_send_query(br, port, &br_group); 827 querier = &br->ip6_querier;
828 br_group.proto = htons(ETH_P_IPV6);
810#endif 829#endif
830 }
831
832 if (!querier || timer_pending(&querier->timer))
833 return;
834
835 __br_multicast_send_query(br, port, &br_group);
811 836
812 time = jiffies; 837 time = jiffies;
813 time += sent < br->multicast_startup_query_count ? 838 time += query->startup_sent < br->multicast_startup_query_count ?
814 br->multicast_startup_query_interval : 839 br->multicast_startup_query_interval :
815 br->multicast_query_interval; 840 br->multicast_query_interval;
816 mod_timer(port ? &port->multicast_query_timer : 841 mod_timer(&query->timer, time);
817 &br->multicast_query_timer, time);
818} 842}
819 843
820static void br_multicast_port_query_expired(unsigned long data) 844static void br_multicast_port_query_expired(struct net_bridge_port *port,
845 struct bridge_mcast_query *query)
821{ 846{
822 struct net_bridge_port *port = (void *)data;
823 struct net_bridge *br = port->br; 847 struct net_bridge *br = port->br;
824 848
825 spin_lock(&br->multicast_lock); 849 spin_lock(&br->multicast_lock);
@@ -827,25 +851,43 @@ static void br_multicast_port_query_expired(unsigned long data)
827 port->state == BR_STATE_BLOCKING) 851 port->state == BR_STATE_BLOCKING)
828 goto out; 852 goto out;
829 853
830 if (port->multicast_startup_queries_sent < 854 if (query->startup_sent < br->multicast_startup_query_count)
831 br->multicast_startup_query_count) 855 query->startup_sent++;
832 port->multicast_startup_queries_sent++;
833 856
834 br_multicast_send_query(port->br, port, 857 br_multicast_send_query(port->br, port, query);
835 port->multicast_startup_queries_sent);
836 858
837out: 859out:
838 spin_unlock(&br->multicast_lock); 860 spin_unlock(&br->multicast_lock);
839} 861}
840 862
863static void br_ip4_multicast_port_query_expired(unsigned long data)
864{
865 struct net_bridge_port *port = (void *)data;
866
867 br_multicast_port_query_expired(port, &port->ip4_query);
868}
869
870#if IS_ENABLED(CONFIG_IPV6)
871static void br_ip6_multicast_port_query_expired(unsigned long data)
872{
873 struct net_bridge_port *port = (void *)data;
874
875 br_multicast_port_query_expired(port, &port->ip6_query);
876}
877#endif
878
841void br_multicast_add_port(struct net_bridge_port *port) 879void br_multicast_add_port(struct net_bridge_port *port)
842{ 880{
843 port->multicast_router = 1; 881 port->multicast_router = 1;
844 882
845 setup_timer(&port->multicast_router_timer, br_multicast_router_expired, 883 setup_timer(&port->multicast_router_timer, br_multicast_router_expired,
846 (unsigned long)port); 884 (unsigned long)port);
847 setup_timer(&port->multicast_query_timer, 885 setup_timer(&port->ip4_query.timer, br_ip4_multicast_port_query_expired,
848 br_multicast_port_query_expired, (unsigned long)port); 886 (unsigned long)port);
887#if IS_ENABLED(CONFIG_IPV6)
888 setup_timer(&port->ip6_query.timer, br_ip6_multicast_port_query_expired,
889 (unsigned long)port);
890#endif
849} 891}
850 892
851void br_multicast_del_port(struct net_bridge_port *port) 893void br_multicast_del_port(struct net_bridge_port *port)
@@ -853,13 +895,13 @@ void br_multicast_del_port(struct net_bridge_port *port)
853 del_timer_sync(&port->multicast_router_timer); 895 del_timer_sync(&port->multicast_router_timer);
854} 896}
855 897
856static void __br_multicast_enable_port(struct net_bridge_port *port) 898static void br_multicast_enable(struct bridge_mcast_query *query)
857{ 899{
858 port->multicast_startup_queries_sent = 0; 900 query->startup_sent = 0;
859 901
860 if (try_to_del_timer_sync(&port->multicast_query_timer) >= 0 || 902 if (try_to_del_timer_sync(&query->timer) >= 0 ||
861 del_timer(&port->multicast_query_timer)) 903 del_timer(&query->timer))
862 mod_timer(&port->multicast_query_timer, jiffies); 904 mod_timer(&query->timer, jiffies);
863} 905}
864 906
865void br_multicast_enable_port(struct net_bridge_port *port) 907void br_multicast_enable_port(struct net_bridge_port *port)
@@ -870,7 +912,10 @@ void br_multicast_enable_port(struct net_bridge_port *port)
870 if (br->multicast_disabled || !netif_running(br->dev)) 912 if (br->multicast_disabled || !netif_running(br->dev))
871 goto out; 913 goto out;
872 914
873 __br_multicast_enable_port(port); 915 br_multicast_enable(&port->ip4_query);
916#if IS_ENABLED(CONFIG_IPV6)
917 br_multicast_enable(&port->ip6_query);
918#endif
874 919
875out: 920out:
876 spin_unlock(&br->multicast_lock); 921 spin_unlock(&br->multicast_lock);
@@ -889,7 +934,10 @@ void br_multicast_disable_port(struct net_bridge_port *port)
889 if (!hlist_unhashed(&port->rlist)) 934 if (!hlist_unhashed(&port->rlist))
890 hlist_del_init_rcu(&port->rlist); 935 hlist_del_init_rcu(&port->rlist);
891 del_timer(&port->multicast_router_timer); 936 del_timer(&port->multicast_router_timer);
892 del_timer(&port->multicast_query_timer); 937 del_timer(&port->ip4_query.timer);
938#if IS_ENABLED(CONFIG_IPV6)
939 del_timer(&port->ip6_query.timer);
940#endif
893 spin_unlock(&br->multicast_lock); 941 spin_unlock(&br->multicast_lock);
894} 942}
895 943
@@ -1014,14 +1062,15 @@ static int br_ip6_multicast_mld2_report(struct net_bridge *br,
1014} 1062}
1015#endif 1063#endif
1016 1064
1017static void br_multicast_update_querier_timer(struct net_bridge *br, 1065static void
1018 unsigned long max_delay) 1066br_multicast_update_querier_timer(struct net_bridge *br,
1067 struct bridge_mcast_querier *querier,
1068 unsigned long max_delay)
1019{ 1069{
1020 if (!timer_pending(&br->multicast_querier_timer)) 1070 if (!timer_pending(&querier->timer))
1021 br->multicast_querier_delay_time = jiffies + max_delay; 1071 querier->delay_time = jiffies + max_delay;
1022 1072
1023 mod_timer(&br->multicast_querier_timer, 1073 mod_timer(&querier->timer, jiffies + br->multicast_querier_interval);
1024 jiffies + br->multicast_querier_interval);
1025} 1074}
1026 1075
1027/* 1076/*
@@ -1074,12 +1123,13 @@ timer:
1074 1123
1075static void br_multicast_query_received(struct net_bridge *br, 1124static void br_multicast_query_received(struct net_bridge *br,
1076 struct net_bridge_port *port, 1125 struct net_bridge_port *port,
1126 struct bridge_mcast_querier *querier,
1077 int saddr, 1127 int saddr,
1078 unsigned long max_delay) 1128 unsigned long max_delay)
1079{ 1129{
1080 if (saddr) 1130 if (saddr)
1081 br_multicast_update_querier_timer(br, max_delay); 1131 br_multicast_update_querier_timer(br, querier, max_delay);
1082 else if (timer_pending(&br->multicast_querier_timer)) 1132 else if (timer_pending(&querier->timer))
1083 return; 1133 return;
1084 1134
1085 br_multicast_mark_router(br, port); 1135 br_multicast_mark_router(br, port);
@@ -1129,7 +1179,8 @@ static int br_ip4_multicast_query(struct net_bridge *br,
1129 IGMPV3_MRC(ih3->code) * (HZ / IGMP_TIMER_SCALE) : 1; 1179 IGMPV3_MRC(ih3->code) * (HZ / IGMP_TIMER_SCALE) : 1;
1130 } 1180 }
1131 1181
1132 br_multicast_query_received(br, port, !!iph->saddr, max_delay); 1182 br_multicast_query_received(br, port, &br->ip4_querier, !!iph->saddr,
1183 max_delay);
1133 1184
1134 if (!group) 1185 if (!group)
1135 goto out; 1186 goto out;
@@ -1206,8 +1257,8 @@ static int br_ip6_multicast_query(struct net_bridge *br,
1206 max_delay = mld2q->mld2q_mrc ? MLDV2_MRC(ntohs(mld2q->mld2q_mrc)) : 1; 1257 max_delay = mld2q->mld2q_mrc ? MLDV2_MRC(ntohs(mld2q->mld2q_mrc)) : 1;
1207 } 1258 }
1208 1259
1209 br_multicast_query_received(br, port, !ipv6_addr_any(&ip6h->saddr), 1260 br_multicast_query_received(br, port, &br->ip6_querier,
1210 max_delay); 1261 !ipv6_addr_any(&ip6h->saddr), max_delay);
1211 1262
1212 if (!group) 1263 if (!group)
1213 goto out; 1264 goto out;
@@ -1244,7 +1295,9 @@ out:
1244 1295
1245static void br_multicast_leave_group(struct net_bridge *br, 1296static void br_multicast_leave_group(struct net_bridge *br,
1246 struct net_bridge_port *port, 1297 struct net_bridge_port *port,
1247 struct br_ip *group) 1298 struct br_ip *group,
1299 struct bridge_mcast_querier *querier,
1300 struct bridge_mcast_query *query)
1248{ 1301{
1249 struct net_bridge_mdb_htable *mdb; 1302 struct net_bridge_mdb_htable *mdb;
1250 struct net_bridge_mdb_entry *mp; 1303 struct net_bridge_mdb_entry *mp;
@@ -1255,7 +1308,7 @@ static void br_multicast_leave_group(struct net_bridge *br,
1255 spin_lock(&br->multicast_lock); 1308 spin_lock(&br->multicast_lock);
1256 if (!netif_running(br->dev) || 1309 if (!netif_running(br->dev) ||
1257 (port && port->state == BR_STATE_DISABLED) || 1310 (port && port->state == BR_STATE_DISABLED) ||
1258 timer_pending(&br->multicast_querier_timer)) 1311 timer_pending(&querier->timer))
1259 goto out; 1312 goto out;
1260 1313
1261 mdb = mlock_dereference(br->mdb, br); 1314 mdb = mlock_dereference(br->mdb, br);
@@ -1263,14 +1316,13 @@ static void br_multicast_leave_group(struct net_bridge *br,
1263 if (!mp) 1316 if (!mp)
1264 goto out; 1317 goto out;
1265 1318
1266 if (br->multicast_querier && 1319 if (br->multicast_querier) {
1267 !timer_pending(&br->multicast_querier_timer)) {
1268 __br_multicast_send_query(br, port, &mp->addr); 1320 __br_multicast_send_query(br, port, &mp->addr);
1269 1321
1270 time = jiffies + br->multicast_last_member_count * 1322 time = jiffies + br->multicast_last_member_count *
1271 br->multicast_last_member_interval; 1323 br->multicast_last_member_interval;
1272 mod_timer(port ? &port->multicast_query_timer : 1324
1273 &br->multicast_query_timer, time); 1325 mod_timer(&query->timer, time);
1274 1326
1275 for (p = mlock_dereference(mp->ports, br); 1327 for (p = mlock_dereference(mp->ports, br);
1276 p != NULL; 1328 p != NULL;
@@ -1323,7 +1375,6 @@ static void br_multicast_leave_group(struct net_bridge *br,
1323 mod_timer(&mp->timer, time); 1375 mod_timer(&mp->timer, time);
1324 } 1376 }
1325 } 1377 }
1326
1327out: 1378out:
1328 spin_unlock(&br->multicast_lock); 1379 spin_unlock(&br->multicast_lock);
1329} 1380}
@@ -1334,6 +1385,8 @@ static void br_ip4_multicast_leave_group(struct net_bridge *br,
1334 __u16 vid) 1385 __u16 vid)
1335{ 1386{
1336 struct br_ip br_group; 1387 struct br_ip br_group;
1388 struct bridge_mcast_query *query = port ? &port->ip4_query :
1389 &br->ip4_query;
1337 1390
1338 if (ipv4_is_local_multicast(group)) 1391 if (ipv4_is_local_multicast(group))
1339 return; 1392 return;
@@ -1342,7 +1395,7 @@ static void br_ip4_multicast_leave_group(struct net_bridge *br,
1342 br_group.proto = htons(ETH_P_IP); 1395 br_group.proto = htons(ETH_P_IP);
1343 br_group.vid = vid; 1396 br_group.vid = vid;
1344 1397
1345 br_multicast_leave_group(br, port, &br_group); 1398 br_multicast_leave_group(br, port, &br_group, &br->ip4_querier, query);
1346} 1399}
1347 1400
1348#if IS_ENABLED(CONFIG_IPV6) 1401#if IS_ENABLED(CONFIG_IPV6)
@@ -1352,6 +1405,9 @@ static void br_ip6_multicast_leave_group(struct net_bridge *br,
1352 __u16 vid) 1405 __u16 vid)
1353{ 1406{
1354 struct br_ip br_group; 1407 struct br_ip br_group;
1408 struct bridge_mcast_query *query = port ? &port->ip6_query :
1409 &br->ip6_query;
1410
1355 1411
1356 if (!ipv6_is_transient_multicast(group)) 1412 if (!ipv6_is_transient_multicast(group))
1357 return; 1413 return;
@@ -1360,7 +1416,7 @@ static void br_ip6_multicast_leave_group(struct net_bridge *br,
1360 br_group.proto = htons(ETH_P_IPV6); 1416 br_group.proto = htons(ETH_P_IPV6);
1361 br_group.vid = vid; 1417 br_group.vid = vid;
1362 1418
1363 br_multicast_leave_group(br, port, &br_group); 1419 br_multicast_leave_group(br, port, &br_group, &br->ip6_querier, query);
1364} 1420}
1365#endif 1421#endif
1366 1422
@@ -1622,19 +1678,32 @@ int br_multicast_rcv(struct net_bridge *br, struct net_bridge_port *port,
1622 return 0; 1678 return 0;
1623} 1679}
1624 1680
1625static void br_multicast_query_expired(unsigned long data) 1681static void br_multicast_query_expired(struct net_bridge *br,
1682 struct bridge_mcast_query *query)
1683{
1684 spin_lock(&br->multicast_lock);
1685 if (query->startup_sent < br->multicast_startup_query_count)
1686 query->startup_sent++;
1687
1688 br_multicast_send_query(br, NULL, query);
1689 spin_unlock(&br->multicast_lock);
1690}
1691
1692static void br_ip4_multicast_query_expired(unsigned long data)
1626{ 1693{
1627 struct net_bridge *br = (void *)data; 1694 struct net_bridge *br = (void *)data;
1628 1695
1629 spin_lock(&br->multicast_lock); 1696 br_multicast_query_expired(br, &br->ip4_query);
1630 if (br->multicast_startup_queries_sent < 1697}
1631 br->multicast_startup_query_count)
1632 br->multicast_startup_queries_sent++;
1633 1698
1634 br_multicast_send_query(br, NULL, br->multicast_startup_queries_sent); 1699#if IS_ENABLED(CONFIG_IPV6)
1700static void br_ip6_multicast_query_expired(unsigned long data)
1701{
1702 struct net_bridge *br = (void *)data;
1635 1703
1636 spin_unlock(&br->multicast_lock); 1704 br_multicast_query_expired(br, &br->ip6_query);
1637} 1705}
1706#endif
1638 1707
1639void br_multicast_init(struct net_bridge *br) 1708void br_multicast_init(struct net_bridge *br)
1640{ 1709{
@@ -1654,25 +1723,43 @@ void br_multicast_init(struct net_bridge *br)
1654 br->multicast_querier_interval = 255 * HZ; 1723 br->multicast_querier_interval = 255 * HZ;
1655 br->multicast_membership_interval = 260 * HZ; 1724 br->multicast_membership_interval = 260 * HZ;
1656 1725
1657 br->multicast_querier_delay_time = 0; 1726 br->ip4_querier.delay_time = 0;
1727#if IS_ENABLED(CONFIG_IPV6)
1728 br->ip6_querier.delay_time = 0;
1729#endif
1658 1730
1659 spin_lock_init(&br->multicast_lock); 1731 spin_lock_init(&br->multicast_lock);
1660 setup_timer(&br->multicast_router_timer, 1732 setup_timer(&br->multicast_router_timer,
1661 br_multicast_local_router_expired, 0); 1733 br_multicast_local_router_expired, 0);
1662 setup_timer(&br->multicast_querier_timer, 1734 setup_timer(&br->ip4_querier.timer, br_ip4_multicast_querier_expired,
1663 br_multicast_querier_expired, (unsigned long)br); 1735 (unsigned long)br);
1664 setup_timer(&br->multicast_query_timer, br_multicast_query_expired, 1736 setup_timer(&br->ip4_query.timer, br_ip4_multicast_query_expired,
1665 (unsigned long)br); 1737 (unsigned long)br);
1738#if IS_ENABLED(CONFIG_IPV6)
1739 setup_timer(&br->ip6_querier.timer, br_ip6_multicast_querier_expired,
1740 (unsigned long)br);
1741 setup_timer(&br->ip6_query.timer, br_ip6_multicast_query_expired,
1742 (unsigned long)br);
1743#endif
1666} 1744}
1667 1745
1668void br_multicast_open(struct net_bridge *br) 1746static void __br_multicast_open(struct net_bridge *br,
1747 struct bridge_mcast_query *query)
1669{ 1748{
1670 br->multicast_startup_queries_sent = 0; 1749 query->startup_sent = 0;
1671 1750
1672 if (br->multicast_disabled) 1751 if (br->multicast_disabled)
1673 return; 1752 return;
1674 1753
1675 mod_timer(&br->multicast_query_timer, jiffies); 1754 mod_timer(&query->timer, jiffies);
1755}
1756
1757void br_multicast_open(struct net_bridge *br)
1758{
1759 __br_multicast_open(br, &br->ip4_query);
1760#if IS_ENABLED(CONFIG_IPV6)
1761 __br_multicast_open(br, &br->ip6_query);
1762#endif
1676} 1763}
1677 1764
1678void br_multicast_stop(struct net_bridge *br) 1765void br_multicast_stop(struct net_bridge *br)
@@ -1684,8 +1771,12 @@ void br_multicast_stop(struct net_bridge *br)
1684 int i; 1771 int i;
1685 1772
1686 del_timer_sync(&br->multicast_router_timer); 1773 del_timer_sync(&br->multicast_router_timer);
1687 del_timer_sync(&br->multicast_querier_timer); 1774 del_timer_sync(&br->ip4_querier.timer);
1688 del_timer_sync(&br->multicast_query_timer); 1775 del_timer_sync(&br->ip4_query.timer);
1776#if IS_ENABLED(CONFIG_IPV6)
1777 del_timer_sync(&br->ip6_querier.timer);
1778 del_timer_sync(&br->ip6_query.timer);
1779#endif
1689 1780
1690 spin_lock_bh(&br->multicast_lock); 1781 spin_lock_bh(&br->multicast_lock);
1691 mdb = mlock_dereference(br->mdb, br); 1782 mdb = mlock_dereference(br->mdb, br);
@@ -1788,18 +1879,24 @@ unlock:
1788 return err; 1879 return err;
1789} 1880}
1790 1881
1791static void br_multicast_start_querier(struct net_bridge *br) 1882static void br_multicast_start_querier(struct net_bridge *br,
1883 struct bridge_mcast_query *query)
1792{ 1884{
1793 struct net_bridge_port *port; 1885 struct net_bridge_port *port;
1794 1886
1795 br_multicast_open(br); 1887 __br_multicast_open(br, query);
1796 1888
1797 list_for_each_entry(port, &br->port_list, list) { 1889 list_for_each_entry(port, &br->port_list, list) {
1798 if (port->state == BR_STATE_DISABLED || 1890 if (port->state == BR_STATE_DISABLED ||
1799 port->state == BR_STATE_BLOCKING) 1891 port->state == BR_STATE_BLOCKING)
1800 continue; 1892 continue;
1801 1893
1802 __br_multicast_enable_port(port); 1894 if (query == &br->ip4_query)
1895 br_multicast_enable(&port->ip4_query);
1896#if IS_ENABLED(CONFIG_IPV6)
1897 else
1898 br_multicast_enable(&port->ip6_query);
1899#endif
1803 } 1900 }
1804} 1901}
1805 1902
@@ -1834,7 +1931,10 @@ rollback:
1834 goto rollback; 1931 goto rollback;
1835 } 1932 }
1836 1933
1837 br_multicast_start_querier(br); 1934 br_multicast_start_querier(br, &br->ip4_query);
1935#if IS_ENABLED(CONFIG_IPV6)
1936 br_multicast_start_querier(br, &br->ip6_query);
1937#endif
1838 1938
1839unlock: 1939unlock:
1840 spin_unlock_bh(&br->multicast_lock); 1940 spin_unlock_bh(&br->multicast_lock);
@@ -1857,10 +1957,18 @@ int br_multicast_set_querier(struct net_bridge *br, unsigned long val)
1857 goto unlock; 1957 goto unlock;
1858 1958
1859 max_delay = br->multicast_query_response_interval; 1959 max_delay = br->multicast_query_response_interval;
1860 if (!timer_pending(&br->multicast_querier_timer))
1861 br->multicast_querier_delay_time = jiffies + max_delay;
1862 1960
1863 br_multicast_start_querier(br); 1961 if (!timer_pending(&br->ip4_querier.timer))
1962 br->ip4_querier.delay_time = jiffies + max_delay;
1963
1964 br_multicast_start_querier(br, &br->ip4_query);
1965
1966#if IS_ENABLED(CONFIG_IPV6)
1967 if (!timer_pending(&br->ip6_querier.timer))
1968 br->ip6_querier.delay_time = jiffies + max_delay;
1969
1970 br_multicast_start_querier(br, &br->ip6_query);
1971#endif
1864 1972
1865unlock: 1973unlock:
1866 spin_unlock_bh(&br->multicast_lock); 1974 spin_unlock_bh(&br->multicast_lock);
diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
index 2f7da41851bf..263ba9034468 100644
--- a/net/bridge/br_private.h
+++ b/net/bridge/br_private.h
@@ -66,6 +66,20 @@ struct br_ip
66 __u16 vid; 66 __u16 vid;
67}; 67};
68 68
69#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
70/* our own querier */
71struct bridge_mcast_query {
72 struct timer_list timer;
73 u32 startup_sent;
74};
75
76/* other querier */
77struct bridge_mcast_querier {
78 struct timer_list timer;
79 unsigned long delay_time;
80};
81#endif
82
69struct net_port_vlans { 83struct net_port_vlans {
70 u16 port_idx; 84 u16 port_idx;
71 u16 pvid; 85 u16 pvid;
@@ -162,10 +176,12 @@ struct net_bridge_port
162#define BR_FLOOD 0x00000040 176#define BR_FLOOD 0x00000040
163 177
164#ifdef CONFIG_BRIDGE_IGMP_SNOOPING 178#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
165 u32 multicast_startup_queries_sent; 179 struct bridge_mcast_query ip4_query;
180#if IS_ENABLED(CONFIG_IPV6)
181 struct bridge_mcast_query ip6_query;
182#endif /* IS_ENABLED(CONFIG_IPV6) */
166 unsigned char multicast_router; 183 unsigned char multicast_router;
167 struct timer_list multicast_router_timer; 184 struct timer_list multicast_router_timer;
168 struct timer_list multicast_query_timer;
169 struct hlist_head mglist; 185 struct hlist_head mglist;
170 struct hlist_node rlist; 186 struct hlist_node rlist;
171#endif 187#endif
@@ -258,7 +274,6 @@ struct net_bridge
258 u32 hash_max; 274 u32 hash_max;
259 275
260 u32 multicast_last_member_count; 276 u32 multicast_last_member_count;
261 u32 multicast_startup_queries_sent;
262 u32 multicast_startup_query_count; 277 u32 multicast_startup_query_count;
263 278
264 unsigned long multicast_last_member_interval; 279 unsigned long multicast_last_member_interval;
@@ -267,15 +282,18 @@ struct net_bridge
267 unsigned long multicast_query_interval; 282 unsigned long multicast_query_interval;
268 unsigned long multicast_query_response_interval; 283 unsigned long multicast_query_response_interval;
269 unsigned long multicast_startup_query_interval; 284 unsigned long multicast_startup_query_interval;
270 unsigned long multicast_querier_delay_time;
271 285
272 spinlock_t multicast_lock; 286 spinlock_t multicast_lock;
273 struct net_bridge_mdb_htable __rcu *mdb; 287 struct net_bridge_mdb_htable __rcu *mdb;
274 struct hlist_head router_list; 288 struct hlist_head router_list;
275 289
276 struct timer_list multicast_router_timer; 290 struct timer_list multicast_router_timer;
277 struct timer_list multicast_querier_timer; 291 struct bridge_mcast_querier ip4_querier;
278 struct timer_list multicast_query_timer; 292 struct bridge_mcast_query ip4_query;
293#if IS_ENABLED(CONFIG_IPV6)
294 struct bridge_mcast_querier ip6_querier;
295 struct bridge_mcast_query ip6_query;
296#endif /* IS_ENABLED(CONFIG_IPV6) */
279#endif 297#endif
280 298
281 struct timer_list hello_timer; 299 struct timer_list hello_timer;
@@ -503,11 +521,27 @@ static inline bool br_multicast_is_router(struct net_bridge *br)
503 timer_pending(&br->multicast_router_timer)); 521 timer_pending(&br->multicast_router_timer));
504} 522}
505 523
506static inline bool br_multicast_querier_exists(struct net_bridge *br) 524static inline bool
525__br_multicast_querier_exists(struct net_bridge *br,
526 struct bridge_mcast_querier *querier)
527{
528 return time_is_before_jiffies(querier->delay_time) &&
529 (br->multicast_querier || timer_pending(&querier->timer));
530}
531
532static inline bool br_multicast_querier_exists(struct net_bridge *br,
533 struct ethhdr *eth)
507{ 534{
508 return time_is_before_jiffies(br->multicast_querier_delay_time) && 535 switch (eth->h_proto) {
509 (br->multicast_querier || 536 case (htons(ETH_P_IP)):
510 timer_pending(&br->multicast_querier_timer)); 537 return __br_multicast_querier_exists(br, &br->ip4_querier);
538#if IS_ENABLED(CONFIG_IPV6)
539 case (htons(ETH_P_IPV6)):
540 return __br_multicast_querier_exists(br, &br->ip6_querier);
541#endif
542 default:
543 return false;
544 }
511} 545}
512#else 546#else
513static inline int br_multicast_rcv(struct net_bridge *br, 547static inline int br_multicast_rcv(struct net_bridge *br,
@@ -565,7 +599,8 @@ static inline bool br_multicast_is_router(struct net_bridge *br)
565{ 599{
566 return 0; 600 return 0;
567} 601}
568static inline bool br_multicast_querier_exists(struct net_bridge *br) 602static inline bool br_multicast_querier_exists(struct net_bridge *br,
603 struct ethhdr *eth)
569{ 604{
570 return false; 605 return false;
571} 606}