Skip to contentSkip to conversation

bridge: multicast snooping patches / exports

PATCH Superseded Linus Lüssing 4 participants 10 messages May 25, 2014 – Jun 27, 2014

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#2 lore raw

PATCH v2 2/4 bridge: adhere to querier election mechanism specified by RFCs

In reply to Linus Lüssing

MLDv1 (RFC2710 section 6), MLDv2 (RFC3810 section 7.6.2), IGMPv2 (RFC2236 section 3) and IGMPv3 (RFC3376 section 6.6.2) specify that the querier with lowest source address shall become the selected querier.

So far the bridge stopped its querier as soon as it heard another querier regardless of its source address. This results in the "wrong" querier potentially becoming the active querier or a potential, unnecessary querying delay.

With this patch the bridge memorizes the source address of the currently selected querier and ignores queries from queriers with a higher source address than the currently selected one. This slight optimization is supposed to make it more RFC compliant (but is rather uncritical and therefore probably not necessary to be queued for stable kernels).

---
 net/bridge/br_multicast.c |  101 +++++++++++++++++++++++++++++++++++++++------
 net/bridge/br_private.h   |    7 ++++
 2 files changed, 95 insertions(+), 13 deletions(-)
net/bridge/br_multicast.c +88 -13
index 5ccac62..b3f17c9 100644
@@ -789,6 +789,18 @@ static void br_ip6_multicast_querier_expired(unsigned long data)
 }
 #endif
 
+static void br_multicast_select_own_querier(struct net_bridge *br,
+					    struct br_ip *ip,
+					    struct sk_buff *skb)
+{
+	if (ip->proto == htons(ETH_P_IP))
+		br->ip4_querier.addr.u.ip4 = ip_hdr(skb)->saddr;
+#if IS_ENABLED(CONFIG_IPV6)
+	else
+		br->ip6_querier.addr.u.ip6 = ipv6_hdr(skb)->saddr;
+#endif
+}
+
 static void __br_multicast_send_query(struct net_bridge *br,
 				      struct net_bridge_port *port,
 				      struct br_ip *ip)
@@ -804,8 +816,10 @@ static void __br_multicast_send_query(struct net_bridge *br,
 		skb->dev = port->dev;
 		NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
 			dev_queue_xmit);
-	} else
+	} else {
+		br_multicast_select_own_querier(br, ip, skb);
 		netif_rx(skb);
+	}
 }
 
 static void br_multicast_send_query(struct net_bridge *br,
@@ -1065,6 +1079,62 @@ static int br_ip6_multicast_mld2_report(struct net_bridge *br,
 }
 #endif
 
+static bool br_ip4_multicast_select_querier(struct net_bridge *br,
+					    __be32 saddr)
+{
+	if (!timer_pending(&br->ip4_own_query.timer) &&
+	    !timer_pending(&br->ip4_other_query.timer))
+		goto update;
+
+	if (!br->ip4_querier.addr.u.ip4)
+		goto update;
+
+	if (ntohl(saddr) <= ntohl(br->ip4_querier.addr.u.ip4))
+		goto update;
+
+	return false;
+
+update:
+	br->ip4_querier.addr.u.ip4 = saddr;
+
+	return true;
+}
+
+#if IS_ENABLED(CONFIG_IPV6)
+static bool br_ip6_multicast_select_querier(struct net_bridge *br,
+					    struct in6_addr *saddr)
+{
+	if (!timer_pending(&br->ip6_own_query.timer) &&
+	    !timer_pending(&br->ip6_other_query.timer))
+		goto update;
+
+	if (ipv6_addr_cmp(saddr, &br->ip6_querier.addr.u.ip6) <= 0)
+		goto update;
+
+	return false;
+
+update:
+	br->ip6_querier.addr.u.ip6 = *saddr;
+
+	return true;
+}
+#endif
+
+static bool br_multicast_select_querier(struct net_bridge *br,
+					struct br_ip *saddr)
+{
+	switch (saddr->proto) {
+	case htons(ETH_P_IP):
+		return br_ip4_multicast_select_querier(br, saddr->u.ip4);
+#if IS_ENABLED(CONFIG_IPV6)
+	case htons(ETH_P_IPV6):
+		return br_ip6_multicast_select_querier(br, &saddr->u.ip6);
+#endif
+	}
+
+	return false;
+}
+
 static void
 br_multicast_update_query_timer(struct net_bridge *br,
 				struct bridge_mcast_other_query *query,
@@ -1127,15 +1197,13 @@ timer:
 static void br_multicast_query_received(struct net_bridge *br,
 					struct net_bridge_port *port,
 					struct bridge_mcast_other_query *query,
-					int saddr,
-					bool is_general_query,
+					struct br_ip *saddr,
 					unsigned long max_delay)
 {
-	if (saddr && is_general_query)
-		br_multicast_update_query_timer(br, query, max_delay);
-	else if (timer_pending(&query->timer))
+	if (!br_multicast_select_querier(br, saddr))
 		return;
 
+	br_multicast_update_query_timer(br, query, max_delay);
 	br_multicast_mark_router(br, port);
 }
 
@@ -1150,6 +1218,7 @@ static int br_ip4_multicast_query(struct net_bridge *br,
 	struct igmpv3_query *ih3;
 	struct net_bridge_port_group *p;
 	struct net_bridge_port_group __rcu **pp;
+	struct br_ip saddr;
 	unsigned long max_delay;
 	unsigned long now = jiffies;
 	__be32 group;
@@ -1191,11 +1260,14 @@ static int br_ip4_multicast_query(struct net_bridge *br,
 		goto out;
 	}
 
-	br_multicast_query_received(br, port, &br->ip4_other_query,
-				    !!iph->saddr, !group, max_delay);
+	if (!group) {
+		saddr.proto = htons(ETH_P_IP);
+		saddr.u.ip4 = iph->saddr;
 
-	if (!group)
+		br_multicast_query_received(br, port, &br->ip4_other_query,
+					    &saddr, max_delay);
 		goto out;
+	}
 
 	mp = br_mdb_ip4_get(mlock_dereference(br->mdb, br), group, vid);
 	if (!mp)
@@ -1235,6 +1307,7 @@ static int br_ip6_multicast_query(struct net_bridge *br,
 	struct mld2_query *mld2q;
 	struct net_bridge_port_group *p;
 	struct net_bridge_port_group __rcu **pp;
+	struct br_ip saddr;
 	unsigned long max_delay;
 	unsigned long now = jiffies;
 	const struct in6_addr *group = NULL;
@@ -1283,12 +1356,14 @@ static int br_ip6_multicast_query(struct net_bridge *br,
 		goto out;
 	}
 
-	br_multicast_query_received(br, port, &br->ip6_other_query,
-				    !ipv6_addr_any(&ip6h->saddr),
-				    is_general_query, max_delay);
+	if (is_general_query) {
+		saddr.proto = htons(ETH_P_IPV6);
+		saddr.u.ip6 = ip6h->saddr;
 
-	if (!group)
+		br_multicast_query_received(br, port, &br->ip6_other_query,
+					    &saddr, max_delay);
 		goto out;
+	}
 
 	mp = br_mdb_ip6_get(mlock_dereference(br->mdb, br), group, vid);
 	if (!mp)
net/bridge/br_private.h +7 -0
index f186ce8..bc1803b 100644
@@ -78,6 +78,11 @@ struct bridge_mcast_other_query {
 	struct timer_list		timer;
 	unsigned long			delay_time;
 };
+
+/* selected querier */
+struct bridge_mcast_querier {
+	struct br_ip addr;
+};
 #endif
 
 struct net_port_vlans {
@@ -284,9 +289,11 @@ struct net_bridge
 	struct timer_list		multicast_router_timer;
 	struct bridge_mcast_other_query	ip4_other_query;
 	struct bridge_mcast_own_query	ip4_own_query;
+	struct bridge_mcast_querier	ip4_querier;
 #if IS_ENABLED(CONFIG_IPV6)
 	struct bridge_mcast_other_query	ip6_other_query;
 	struct bridge_mcast_own_query	ip6_own_query;
+	struct bridge_mcast_querier	ip6_querier;
 #endif /* IS_ENABLED(CONFIG_IPV6) */
 #endif
 
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH v2 1/4 bridge: rename struct bridge_mcast_query/querier

In reply to Linus Lüssing

The current naming of these two structs is very random, in that reversing their naming would not make any semantical difference.

This patch tries to make the naming less confusing by giving them a more specific, distinguishable naming.

This is also useful for the upcoming patches reintroducing the "struct bridge_mcast_querier" but for storing information about the selected querier (no matter if our own or a foreign querier).

---
 net/bridge/br_mdb.c       |    4 +-
 net/bridge/br_multicast.c |  169 +++++++++++++++++++++++----------------------
 net/bridge/br_private.h   |   22 +++---
 3 files changed, 100 insertions(+), 95 deletions(-)
net/bridge/br_mdb.c +2 -2
index b7b1914..5df0526 100644
@@ -418,13 +418,13 @@ static int __br_mdb_del(struct net_bridge *br, struct br_mdb_entry *entry)
 
 	ip.proto = entry->addr.proto;
 	if (ip.proto == htons(ETH_P_IP)) {
-		if (timer_pending(&br->ip4_querier.timer))
+		if (timer_pending(&br->ip4_other_query.timer))
 			return -EBUSY;
 
 		ip.u.ip4 = entry->addr.u.ip4;
 #if IS_ENABLED(CONFIG_IPV6)
 	} else {
-		if (timer_pending(&br->ip6_querier.timer))
+		if (timer_pending(&br->ip6_other_query.timer))
 			return -EBUSY;
 
 		ip.u.ip6 = entry->addr.u.ip6;
net/bridge/br_multicast.c +87 -82

422 lines not on this page · raw message

net/bridge/br_private.h +11 -11
index af067711..f186ce8 100644
@@ -68,13 +68,13 @@ struct br_ip
 
 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
 /* our own querier */
-struct bridge_mcast_query {
+struct bridge_mcast_own_query {
 	struct timer_list	timer;
 	u32			startup_sent;
 };
 
 /* other querier */
-struct bridge_mcast_querier {
+struct bridge_mcast_other_query {
 	struct timer_list		timer;
 	unsigned long			delay_time;
 };
@@ -178,9 +178,9 @@ struct net_bridge_port
 #define BR_PROMISC		0x00000080
 
 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
-	struct bridge_mcast_query	ip4_query;
+	struct bridge_mcast_own_query	ip4_own_query;
 #if IS_ENABLED(CONFIG_IPV6)
-	struct bridge_mcast_query	ip6_query;
+	struct bridge_mcast_own_query	ip6_own_query;
 #endif /* IS_ENABLED(CONFIG_IPV6) */
 	unsigned char			multicast_router;
 	struct timer_list		multicast_router_timer;
@@ -282,11 +282,11 @@ struct net_bridge
 	struct hlist_head		router_list;
 
 	struct timer_list		multicast_router_timer;
-	struct bridge_mcast_querier	ip4_querier;
-	struct bridge_mcast_query	ip4_query;
+	struct bridge_mcast_other_query	ip4_other_query;
+	struct bridge_mcast_own_query	ip4_own_query;
 #if IS_ENABLED(CONFIG_IPV6)
-	struct bridge_mcast_querier	ip6_querier;
-	struct bridge_mcast_query	ip6_query;
+	struct bridge_mcast_other_query	ip6_other_query;
+	struct bridge_mcast_own_query	ip6_own_query;
 #endif /* IS_ENABLED(CONFIG_IPV6) */
 #endif
 
@@ -495,7 +495,7 @@ static inline bool br_multicast_is_router(struct net_bridge *br)
 
 static inline bool
 __br_multicast_querier_exists(struct net_bridge *br,
-			      struct bridge_mcast_querier *querier)
+			      struct bridge_mcast_other_query *querier)
 {
 	return time_is_before_jiffies(querier->delay_time) &&
 	       (br->multicast_querier || timer_pending(&querier->timer));
@@ -506,10 +506,10 @@ static inline bool br_multicast_querier_exists(struct net_bridge *br,
 {
 	switch (eth->h_proto) {
 	case (htons(ETH_P_IP)):
-		return __br_multicast_querier_exists(br, &br->ip4_querier);
+		return __br_multicast_querier_exists(br, &br->ip4_other_query);
 #if IS_ENABLED(CONFIG_IPV6)
 	case (htons(ETH_P_IPV6)):
-		return __br_multicast_querier_exists(br, &br->ip6_querier);
+		return __br_multicast_querier_exists(br, &br->ip6_other_query);
 #endif
 	default:
 		return false;
Signature · 1 line
1.7.10.4
#7 lore raw

PATCH v2 4/4 bridge: memorize and export selected IGMP/MLD querier port

In reply to Linus Lüssing

Adding bridge support to the batman-adv multicast optimization requires batman-adv knowing about the existence of bridged-in IGMP/MLD queriers to be able to reliably serve any multicast listener behind this same bridge.

---
 include/linux/if_bridge.h |    1 +
 net/bridge/br_multicast.c |   72 +++++++++++++++++++++++++++++++++++++++++----
 net/bridge/br_private.h   |    1 +
 3 files changed, 68 insertions(+), 6 deletions(-)
include/linux/if_bridge.h +1 -0
index 44d6eb0..fd22789 100644
@@ -38,5 +38,6 @@ typedef int br_should_route_hook_t(struct sk_buff *skb);
 extern br_should_route_hook_t __rcu *br_should_route_hook;
 int br_multicast_list_adjacent(struct net_device *dev,
 			       struct list_head *br_ip_list);
+bool br_multicast_has_querier_adjacent(struct net_device *dev, int proto);
 
 #endif
net/bridge/br_multicast.c +66 -6

146 lines not on this page · raw message

net/bridge/br_private.h +1 -0
index cb704a6..625d1bf 100644
@@ -70,6 +70,7 @@ struct bridge_mcast_other_query {
 /* selected querier */
 struct bridge_mcast_querier {
 	struct br_ip addr;
+	struct net_bridge_port __rcu	*port;
 };
 #endif
 
Signature · 1 line
1.7.10.4
#5 lore raw

PATCH v2 3/4 bridge: add export of multicast database adjacent to net_dev

In reply to Linus Lüssing

With this new, exported function br_multicast_list_adjacent(net_dev) a list of IPv4/6 addresses is returned. This list contains all multicast addresses sensed by the bridge multicast snooping feature on all bridge ports of the bridge interface of net_dev, excluding addresses from the specified net_device itself.

Adding bridge support to the batman-adv multicast optimization requires batman-adv knowing about the existence of bridged-in multicast listeners to be able to reliably serve them with multicast packets.

---
 include/linux/if_bridge.h |   18 ++++++++++++++
 net/bridge/br_multicast.c |   58 +++++++++++++++++++++++++++++++++++++++++++++
 net/bridge/br_private.h   |   12 ----------
 3 files changed, 76 insertions(+), 12 deletions(-)
include/linux/if_bridge.h +18 -0
index 1085ffe..44d6eb0 100644
@@ -16,9 +16,27 @@
 #include <linux/netdevice.h>
 #include <uapi/linux/if_bridge.h>
 
+struct br_ip {
+	union {
+		__be32	ip4;
+#if IS_ENABLED(CONFIG_IPV6)
+		struct in6_addr ip6;
+#endif
+	} u;
+	__be16		proto;
+	__u16           vid;
+};
+
+struct br_ip_list {
+	struct list_head list;
+	struct br_ip addr;
+};
+
 extern void brioctl_set(int (*ioctl_hook)(struct net *, unsigned int, void __user *));
 
 typedef int br_should_route_hook_t(struct sk_buff *skb);
 extern br_should_route_hook_t __rcu *br_should_route_hook;
+int br_multicast_list_adjacent(struct net_device *dev,
+			       struct list_head *br_ip_list);
 
 #endif
net/bridge/br_multicast.c +58 -0

67 lines not on this page · raw message

net/bridge/br_private.h +0 -12
index bc1803b..cb704a6 100644
@@ -54,18 +54,6 @@ struct mac_addr
 	unsigned char	addr[ETH_ALEN];
 };
 
-struct br_ip
-{
-	union {
-		__be32	ip4;
-#if IS_ENABLED(CONFIG_IPV6)
-		struct in6_addr ip6;
-#endif
-	} u;
-	__be16		proto;
-	__u16		vid;
-};
-
 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
 /* our own querier */
 struct bridge_mcast_own_query {
Signature · 1 line
1.7.10.4
#0 lore raw

v2 cover bridge: multicast snooping patches / exports

Changes in v2:

* fix a nasty typo in PATCH 1/4, br_multicast_update_query_timer():
"br->multicast_query_interval" vs. "br->multicast_querier_interval" => this accidentally reduced the other querier present timer

     from 255 to 125 seconds

* fix a typo in PATCH 2/4, br_ip{4,6}_multicast_query():
ntohs(ETH_P_{IP,IPV6}) vs. htons(ETH_P_{IP,IPV6})
* add missing ntohl()s before address comparison in PATCH 2/4, br_ip4_multicast_select_querier() (thanks David!)

Cheers, Linus

maintainer
#8 lore raw

From: Linus Lüssing <[email protected]>
Date: Sun, 25 May 2014 07:03:21 +0200

Quoted 1 line

Changes in v2:

I really need a bridging expert to review this series, thank you.

#9 lore raw
Quoted 6 lines · On Thu, 29 May 2014 15:36:22 -0700 (PDT) David Miller <[email protected]>…

From: Linus Lüssing <[email protected]>
Date: Sun, 25 May 2014 07:03:21 +0200

Quoted 1 line

Changes in v2:

I really need a bridging expert to review this series, thank you.

I am fine with these, but would like original author of IGMP snooping to weigh in.

#6 lore raw

Re: [PATCHv2 net-next 3/4] bridge: add export of multicast database adjacent to net_dev

In reply to Linus Lüssing
Quoted 11 lines · On Sun, 25 May 2014 07:03:24 +0200 Linus Lüssing <[email protected]> wrote:

With this new, exported function br_multicast_list_adjacent(net_dev) a list of IPv4/6 addresses is returned. This list contains all multicast addresses sensed by the bridge multicast snooping feature on all bridge ports of the bridge interface of net_dev, excluding addresses from the specified net_device itself.

Adding bridge support to the batman-adv multicast optimization requires batman-adv knowing about the existence of bridged-in multicast listeners to be able to reliably serve them with multicast packets.

Please use EXPORT_SYMBOL_GPL

#3 lore raw

Re: [PATCHv2 net-next 2/4] bridge: adhere to querier election mechanism specified by RFCs

In reply to Linus Lüssing

Hi Luessing,

As per RFC 4541, snooping switches send query with source address as 0.0.0.0 since port in a L2 switch doesn't have ip-address configured.

With current changes linux bridge will always select a querier who sends a query message with 0.0.0.0. Right ?

+ if (ntohl(saddr) <= ntohl(br->ip4_querier.addr.u.ip4))
+ goto update;

Currently linux bridge sends a query message with source address as 0.0.0.0. Right ?

What should be the expected behaviour ?

Regards,
Ajith
--------------------------------------------
codingfreak.blogspot.com

Quoted 238 lines · Linus Lüssing

MLDv1 (RFC2710 section 6), MLDv2 (RFC3810 section 7.6.2), IGMPv2 (RFC2236 section 3) and IGMPv3 (RFC3376 section 6.6.2) specify that the querier with lowest source address shall become the selected querier.

So far the bridge stopped its querier as soon as it heard another querier regardless of its source address. This results in the "wrong" querier potentially becoming the active querier or a potential, unnecessary querying delay.

With this patch the bridge memorizes the source address of the currently selected querier and ignores queries from queriers with a higher source address than the currently selected one. This slight optimization is supposed to make it more RFC compliant (but is rather uncritical and therefore probably not necessary to be queued for stable kernels).

---
 net/bridge/br_multicast.c |  101
+++++++++++++++++++++++++++++++++++++++------
 net/bridge/br_private.h   |    7 ++++
 2 files changed, 95 insertions(+), 13 deletions(-)
net/bridge/br_multicast.c +12 -0
index 5ccac62..b3f17c9 100644
@@ -789,6 +789,18 @@ static void br_ip6_multicast_querier_expired(unsigned
 long data)
 }
 #endif
 
+static void br_multicast_select_own_querier(struct net_bridge *br,
+                                           struct br_ip *ip,
+                                           struct sk_buff *skb)
+{
+       if (ip->proto == htons(ETH_P_IP))
+               br->ip4_querier.addr.u.ip4 = ip_hdr(skb)->saddr;
+#if IS_ENABLED(CONFIG_IPV6)
+       else
+               br->ip6_querier.addr.u.ip6 = ipv6_hdr(skb)->saddr;
+#endif
+}
+
 static void __br_multicast_send_query(struct net_bridge *br,
                                      struct net_bridge_port *port,

struct br_ip *ip)

net/bridge/br_multicast.c +3 -1
@@ -804,8 +816,10 @@ static void __br_multicast_send_query(struct
 net_bridge *br,
                skb->dev = port->dev;
                NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL,
 skb->dev,
                        dev_queue_xmit);
-       } else
+       } else {
+               br_multicast_select_own_querier(br, ip, skb);
                netif_rx(skb);
+       }
 }

static void br_multicast_send_query(struct net_bridge *br,

net/bridge/br_multicast.c +56 -0
@@ -1065,6 +1079,62 @@ static int br_ip6_multicast_mld2_report(struct
 net_bridge *br,
 }
 #endif
 
+static bool br_ip4_multicast_select_querier(struct net_bridge *br,
+                                           __be32 saddr)
+{
+       if (!timer_pending(&br->ip4_own_query.timer) &&
+           !timer_pending(&br->ip4_other_query.timer))
+               goto update;
+
+       if (!br->ip4_querier.addr.u.ip4)
+               goto update;
+
+       if (ntohl(saddr) <= ntohl(br->ip4_querier.addr.u.ip4))
+               goto update;
+
+       return false;
+
+update:
+       br->ip4_querier.addr.u.ip4 = saddr;
+
+       return true;
+}
+
+#if IS_ENABLED(CONFIG_IPV6)
+static bool br_ip6_multicast_select_querier(struct net_bridge *br,
+                                           struct in6_addr *saddr)
+{
+       if (!timer_pending(&br->ip6_own_query.timer) &&
+           !timer_pending(&br->ip6_other_query.timer))
+               goto update;
+
+       if (ipv6_addr_cmp(saddr, &br->ip6_querier.addr.u.ip6) <= 0)
+               goto update;
+
+       return false;
+
+update:
+       br->ip6_querier.addr.u.ip6 = *saddr;
+
+       return true;
+}
+#endif
+
+static bool br_multicast_select_querier(struct net_bridge *br,
+                                       struct br_ip *saddr)
+{
+       switch (saddr->proto) {
+       case htons(ETH_P_IP):
+               return br_ip4_multicast_select_querier(br, saddr->u.ip4);
+#if IS_ENABLED(CONFIG_IPV6)
+       case htons(ETH_P_IPV6):
+               return br_ip6_multicast_select_querier(br, &saddr->u.ip6);
+#endif
+       }
+
+       return false;
+}
+
 static void
 br_multicast_update_query_timer(struct net_bridge *br,

struct bridge_mcast_other_query *query,

net/bridge/br_multicast.c +4 -5
@@ -1127,15 +1197,13 @@ timer:
 static void br_multicast_query_received(struct net_bridge *br,
                                        struct net_bridge_port *port,
                                        struct bridge_mcast_other_query
 *query,
-                                       int saddr,
-                                       bool is_general_query,
+                                       struct br_ip *saddr,
                                        unsigned long max_delay)
 {
-       if (saddr && is_general_query)
-               br_multicast_update_query_timer(br, query, max_delay);
-       else if (timer_pending(&query->timer))
+       if (!br_multicast_select_querier(br, saddr))
                return;
 
+       br_multicast_update_query_timer(br, query, max_delay);
        br_multicast_mark_router(br, port);
 }
@@ -1150,6 +1218,7 @@ static int br_ip4_multicast_query(struct net_bridge
 *br,
        struct igmpv3_query *ih3;
        struct net_bridge_port_group *p;
        struct net_bridge_port_group __rcu **pp;
+       struct br_ip saddr;
        unsigned long max_delay;
        unsigned long now = jiffies;
        __be32 group;
net/bridge/br_multicast.c +6 -3
@@ -1191,11 +1260,14 @@ static int br_ip4_multicast_query(struct
 net_bridge *br,
                goto out;
        }
 
-       br_multicast_query_received(br, port, &br->ip4_other_query,
-                                   !!iph->saddr, !group, max_delay);
+       if (!group) {
+               saddr.proto = htons(ETH_P_IP);
+               saddr.u.ip4 = iph->saddr;
 
-       if (!group)
+               br_multicast_query_received(br, port, &br->ip4_other_query,
+                                           &saddr, max_delay);
                goto out;
+       }
 
        mp = br_mdb_ip4_get(mlock_dereference(br->mdb, br), group, vid);
        if (!mp)
net/bridge/br_multicast.c +1 -0
@@ -1235,6 +1307,7 @@ static int br_ip6_multicast_query(struct net_bridge
 *br,
        struct mld2_query *mld2q;
        struct net_bridge_port_group *p;
        struct net_bridge_port_group __rcu **pp;
+       struct br_ip saddr;
        unsigned long max_delay;
        unsigned long now = jiffies;
        const struct in6_addr *group = NULL;
net/bridge/br_multicast.c +6 -4
@@ -1283,12 +1356,14 @@ static int br_ip6_multicast_query(struct
 net_bridge *br,
                goto out;
        }
 
-       br_multicast_query_received(br, port, &br->ip6_other_query,
-                                   !ipv6_addr_any(&ip6h->saddr),
-                                   is_general_query, max_delay);
+       if (is_general_query) {
+               saddr.proto = htons(ETH_P_IPV6);
+               saddr.u.ip6 = ip6h->saddr;
 
-       if (!group)
+               br_multicast_query_received(br, port, &br->ip6_other_query,
+                                           &saddr, max_delay);
                goto out;
+       }
 
        mp = br_mdb_ip6_get(mlock_dereference(br->mdb, br), group, vid);
        if (!mp)
net/bridge/br_private.h +7 -1
index f186ce8..bc1803b 100644
@@ -78,6 +78,11 @@ struct bridge_mcast_other_query {
        struct timer_list               timer;
        unsigned long                   delay_time;
 };
+
+/* selected querier */
+struct bridge_mcast_querier {
+       struct br_ip addr;
+};
 #endif
 
 struct net_port_vlans {
@@ -284,9 +289,11 @@ struct net_bridge
        struct timer_list               multicast_router_timer;
        struct bridge_mcast_other_query ip4_other_query;
        struct bridge_mcast_own_query   ip4_own_query;
+       struct bridge_mcast_querier     ip4_querier;
 #if IS_ENABLED(CONFIG_IPV6)
        struct bridge_mcast_other_query ip6_other_query;
        struct bridge_mcast_own_query   ip6_own_query;
+       struct bridge_mcast_querier     ip6_querier;
 #endif /* IS_ENABLED(CONFIG_IPV6) */
 #endif
 
--

1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw

Re: [PATCHv2 net-next 2/4] bridge: adhere to querier election mechanism specified by RFCs

Hi Ajith,

Quoted 4 lines · Ajith Adapa

Hi Luessing,

As per RFC 4541, snooping switches send query with source address as 0.0.0.0 since port in a L2 switch doesn't have ip-address configured.

Hm, I'm not quite sure whether this is true. Do you have a section/paragraph in RFC4541 which says that?

To me, it seems that 0.0.0.0/:: should only be used when the topology changes, on links becoming active (the RFC uses the example of STP). As a performance optimization but not as the source address for General Queries.

In section 2.1.1 1) b) says:

"The 0.0.0.0 address represents a special case where the switch
is proxying IGMP Queries for faster network convergence, but is not itself the Querier."

In section 2.1.1 4) it says:

"If the switch is not the Querier, it should use the 'all-zeros' IP
Source Address in these proxy queries (even though some hosts may elect to not process queries with a 0.0.0.0 IP Source Address)."

(which seems to imply that if a switch is the selected Querier, that it should use something other than the 'all-zeros' IP Source Address?)

Also, section 2.1.1 4) says:

"[...] even though some hosts may elect to not process queries with a
0.0.0.0 IP Source Address"

Which seems to indicate that 0.0.0.0 might be a bad choice to get reliable IGMP Reports and might only make sense for performance optimizations (at least for IPv4 - for IPv6 it doesn't make sense to me to send General Queries with '::' source address at all since '::' is ignored by hosts per RFC).

(*)

Review

Quoted 6 lines

With current changes linux bridge will always select a querier who sends a query message with 0.0.0.0. Right ?

(quoted diff) +2 -0
+       if (ntohl(saddr) <= ntohl(br->ip4_querier.addr.u.ip4))
+               goto update;

Yes. Which is what the querier election mechanism in the RFCs for IGMPv2/IGMPv3 (RFC2236/RFC3376) specifies, I think. (**)

Quoted 3 lines

Currently linux bridge sends a query message with source address as 0.0.0.0. Right ?

For IPv4, this is currently the default, yes. (there's a sysfs switch to change that, if desired) (***)

Quoted 2 lines

What should be the expected behaviour ?

Hm, good question.

Regarding (***): After rereading RFC4541 a few more times, I think (*) would be the right choice: The bridge code should probably be changed to always use an available, non-zero IPv4 source address for General Queries. If none is available it, doesn't make sense to me to become the selected Querier at all (should be changed for IPv6, too: Currently it refrains from sending Query messages then, but thinks a valid querier were in the network, enabling the multicast snooping of the bridge).

Regarding (**): Now that you're mentioning that, you're right, my change isn't quite straightforward in that regard, a few lines earlier there is:

Review

Quoted 2 lines
(quoted diff) +2 -0
+       if (!br->ip4_querier.addr.u.ip4)
+               goto update;

So it would select the all-zeros Querier if it receives such messages. But would happily switch to a non-all-zeros Querier as well if receiving such messages...

And now, this baffles me, section 2.1.1 4) again:

"When such proxy queries are received, they must not be included in
the Querier election process."

If we were following that, a snooping switch and a true multicast router could potentially have an argument about which becomes the selected IGMP querier? (for IPv6/MLD this dilemma should not exist, I think)

I'm currently unsure, whether we should follow RFC2236(IGMPv2)+RFC3376(IGMPv3) or the informational (!) RFC4541.

Or am I overlooking something? What do others think?

Cheers, Linus