All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Linus Lüssing" <linus.luessing@c0d3.blue>
To: netdev@vger.kernel.org
Cc: "Roopa Prabhu" <roopa@nvidia.com>,
	"Nikolay Aleksandrov" <nikolay@nvidia.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"David S . Miller" <davem@davemloft.net>,
	bridge@lists.linux-foundation.org, linux-kernel@vger.kernel.org,
	"Linus Lüssing" <linus.luessing@c0d3.blue>
Subject: [net-next v3 11/11] net: bridge: mcast: export multicast router presence adjacent to a port
Date: Thu, 13 May 2021 01:19:41 +0200	[thread overview]
Message-ID: <20210512231941.19211-12-linus.luessing@c0d3.blue> (raw)
In-Reply-To: <20210512231941.19211-1-linus.luessing@c0d3.blue>

To properly support routable multicast addresses in batman-adv in a
group-aware way, a batman-adv node needs to know if it serves multicast
routers.

This adds a function to the bridge to export this so that batman-adv
can then make full use of the Multicast Router Discovery capability of
the bridge.

Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
---
 include/linux/if_bridge.h |  8 ++++++
 net/bridge/br_multicast.c | 55 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+)

diff --git a/include/linux/if_bridge.h b/include/linux/if_bridge.h
index 2cc3503..12e9a32 100644
--- a/include/linux/if_bridge.h
+++ b/include/linux/if_bridge.h
@@ -67,6 +67,7 @@ int br_multicast_list_adjacent(struct net_device *dev,
 			       struct list_head *br_ip_list);
 bool br_multicast_has_querier_anywhere(struct net_device *dev, int proto);
 bool br_multicast_has_querier_adjacent(struct net_device *dev, int proto);
+bool br_multicast_has_router_adjacent(struct net_device *dev, int proto);
 bool br_multicast_enabled(const struct net_device *dev);
 bool br_multicast_router(const struct net_device *dev);
 int br_mdb_replay(struct net_device *br_dev, struct net_device *dev,
@@ -87,6 +88,13 @@ static inline bool br_multicast_has_querier_adjacent(struct net_device *dev,
 {
 	return false;
 }
+
+static inline bool br_multicast_has_router_adjacent(struct net_device *dev,
+						    int proto)
+{
+	return true;
+}
+
 static inline bool br_multicast_enabled(const struct net_device *dev)
 {
 	return false;
diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
index 4448490..fe21f52 100644
--- a/net/bridge/br_multicast.c
+++ b/net/bridge/br_multicast.c
@@ -4061,6 +4061,61 @@ unlock:
 }
 EXPORT_SYMBOL_GPL(br_multicast_has_querier_adjacent);
 
+/**
+ * br_multicast_has_router_adjacent - Checks for a router behind a bridge port
+ * @dev: The bridge port adjacent to which to check for a multicast router
+ * @proto: The protocol family to check for: IGMP -> ETH_P_IP, MLD -> ETH_P_IPV6
+ *
+ * Checks whether the given interface has a bridge on top and if so returns
+ * true if a multicast router is behind one of the other ports of this
+ * bridge. Otherwise returns false.
+ */
+bool br_multicast_has_router_adjacent(struct net_device *dev, int proto)
+{
+	struct net_bridge_port *port, *p;
+	bool ret = false;
+
+	rcu_read_lock();
+	port = br_port_get_check_rcu(dev);
+	if (!port)
+		goto unlock;
+
+	switch (proto) {
+	case ETH_P_IP:
+		hlist_for_each_entry_rcu(p, &port->br->ip4_mc_router_list,
+					 ip4_rlist) {
+			if (p == port)
+				continue;
+
+			ret = true;
+			goto unlock;
+		}
+		break;
+#if IS_ENABLED(CONFIG_IPV6)
+	case ETH_P_IPV6:
+		hlist_for_each_entry_rcu(p, &port->br->ip6_mc_router_list,
+					 ip6_rlist) {
+			if (p == port)
+				continue;
+
+			ret = true;
+			goto unlock;
+		}
+		break;
+#endif
+	default:
+		/* when compiled without IPv6 support, be conservative and
+		 * always assume presence of an IPv6 multicast router
+		 */
+		ret = true;
+	}
+
+unlock:
+	rcu_read_unlock();
+	return ret;
+}
+EXPORT_SYMBOL_GPL(br_multicast_has_router_adjacent);
+
 static void br_mcast_stats_add(struct bridge_mcast_stats __percpu *stats,
 			       const struct sk_buff *skb, u8 type, u8 dir)
 {
-- 
2.31.0


WARNING: multiple messages have this Message-ID (diff)
From: "Linus Lüssing" <linus.luessing@c0d3.blue>
To: netdev@vger.kernel.org
Cc: bridge@lists.linux-foundation.org, linux-kernel@vger.kernel.org,
	Nikolay Aleksandrov <nikolay@nvidia.com>,
	Roopa Prabhu <roopa@nvidia.com>, Jakub Kicinski <kuba@kernel.org>,
	"David S . Miller" <davem@davemloft.net>
Subject: [Bridge] [net-next v3 11/11] net: bridge: mcast: export multicast router presence adjacent to a port
Date: Thu, 13 May 2021 01:19:41 +0200	[thread overview]
Message-ID: <20210512231941.19211-12-linus.luessing@c0d3.blue> (raw)
In-Reply-To: <20210512231941.19211-1-linus.luessing@c0d3.blue>

To properly support routable multicast addresses in batman-adv in a
group-aware way, a batman-adv node needs to know if it serves multicast
routers.

This adds a function to the bridge to export this so that batman-adv
can then make full use of the Multicast Router Discovery capability of
the bridge.

Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
---
 include/linux/if_bridge.h |  8 ++++++
 net/bridge/br_multicast.c | 55 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+)

diff --git a/include/linux/if_bridge.h b/include/linux/if_bridge.h
index 2cc3503..12e9a32 100644
--- a/include/linux/if_bridge.h
+++ b/include/linux/if_bridge.h
@@ -67,6 +67,7 @@ int br_multicast_list_adjacent(struct net_device *dev,
 			       struct list_head *br_ip_list);
 bool br_multicast_has_querier_anywhere(struct net_device *dev, int proto);
 bool br_multicast_has_querier_adjacent(struct net_device *dev, int proto);
+bool br_multicast_has_router_adjacent(struct net_device *dev, int proto);
 bool br_multicast_enabled(const struct net_device *dev);
 bool br_multicast_router(const struct net_device *dev);
 int br_mdb_replay(struct net_device *br_dev, struct net_device *dev,
@@ -87,6 +88,13 @@ static inline bool br_multicast_has_querier_adjacent(struct net_device *dev,
 {
 	return false;
 }
+
+static inline bool br_multicast_has_router_adjacent(struct net_device *dev,
+						    int proto)
+{
+	return true;
+}
+
 static inline bool br_multicast_enabled(const struct net_device *dev)
 {
 	return false;
diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
index 4448490..fe21f52 100644
--- a/net/bridge/br_multicast.c
+++ b/net/bridge/br_multicast.c
@@ -4061,6 +4061,61 @@ unlock:
 }
 EXPORT_SYMBOL_GPL(br_multicast_has_querier_adjacent);
 
+/**
+ * br_multicast_has_router_adjacent - Checks for a router behind a bridge port
+ * @dev: The bridge port adjacent to which to check for a multicast router
+ * @proto: The protocol family to check for: IGMP -> ETH_P_IP, MLD -> ETH_P_IPV6
+ *
+ * Checks whether the given interface has a bridge on top and if so returns
+ * true if a multicast router is behind one of the other ports of this
+ * bridge. Otherwise returns false.
+ */
+bool br_multicast_has_router_adjacent(struct net_device *dev, int proto)
+{
+	struct net_bridge_port *port, *p;
+	bool ret = false;
+
+	rcu_read_lock();
+	port = br_port_get_check_rcu(dev);
+	if (!port)
+		goto unlock;
+
+	switch (proto) {
+	case ETH_P_IP:
+		hlist_for_each_entry_rcu(p, &port->br->ip4_mc_router_list,
+					 ip4_rlist) {
+			if (p == port)
+				continue;
+
+			ret = true;
+			goto unlock;
+		}
+		break;
+#if IS_ENABLED(CONFIG_IPV6)
+	case ETH_P_IPV6:
+		hlist_for_each_entry_rcu(p, &port->br->ip6_mc_router_list,
+					 ip6_rlist) {
+			if (p == port)
+				continue;
+
+			ret = true;
+			goto unlock;
+		}
+		break;
+#endif
+	default:
+		/* when compiled without IPv6 support, be conservative and
+		 * always assume presence of an IPv6 multicast router
+		 */
+		ret = true;
+	}
+
+unlock:
+	rcu_read_unlock();
+	return ret;
+}
+EXPORT_SYMBOL_GPL(br_multicast_has_router_adjacent);
+
 static void br_mcast_stats_add(struct bridge_mcast_stats __percpu *stats,
 			       const struct sk_buff *skb, u8 type, u8 dir)
 {
-- 
2.31.0


  parent reply	other threads:[~2021-05-12 23:43 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-12 23:19 [PATCH net-next v3 00/11] net: bridge: split IPv4/v6 mc router state and export for batman-adv Linus Lüssing
2021-05-12 23:19 ` [Bridge] " Linus Lüssing
2021-05-12 23:19 ` [net-next v3 01/11] net: bridge: mcast: rename multicast router lists and timers Linus Lüssing
2021-05-12 23:19   ` [Bridge] " Linus Lüssing
2021-05-13 11:29   ` Nikolay Aleksandrov
2021-05-13 11:29     ` [Bridge] " Nikolay Aleksandrov
2021-05-12 23:19 ` [net-next v3 02/11] net: bridge: mcast: add wrappers for router node retrieval Linus Lüssing
2021-05-12 23:19   ` [Bridge] " Linus Lüssing
2021-05-13 11:29   ` Nikolay Aleksandrov
2021-05-13 11:29     ` [Bridge] " Nikolay Aleksandrov
2021-05-12 23:19 ` [net-next v3 03/11] net: bridge: mcast: prepare mdb netlink for mcast router split Linus Lüssing
2021-05-12 23:19   ` [Bridge] " Linus Lüssing
2021-05-13 11:30   ` Nikolay Aleksandrov
2021-05-13 11:30     ` [Bridge] " Nikolay Aleksandrov
2021-05-12 23:19 ` [net-next v3 04/11] net: bridge: mcast: prepare query reception " Linus Lüssing
2021-05-12 23:19   ` [Bridge] " Linus Lüssing
2021-05-13 11:30   ` Nikolay Aleksandrov
2021-05-13 11:30     ` [Bridge] " Nikolay Aleksandrov
2021-05-12 23:19 ` [net-next v3 05/11] net: bridge: mcast: prepare is-router function " Linus Lüssing
2021-05-12 23:19   ` [Bridge] " Linus Lüssing
2021-05-13 11:32   ` Nikolay Aleksandrov
2021-05-13 11:32     ` [Bridge] " Nikolay Aleksandrov
2021-05-12 23:19 ` [net-next v3 06/11] net: bridge: mcast: prepare expiry functions " Linus Lüssing
2021-05-12 23:19   ` [Bridge] " Linus Lüssing
2021-05-13 11:33   ` Nikolay Aleksandrov
2021-05-13 11:33     ` [Bridge] " Nikolay Aleksandrov
2021-05-12 23:19 ` [net-next v3 07/11] net: bridge: mcast: prepare add-router function " Linus Lüssing
2021-05-12 23:19   ` [Bridge] " Linus Lüssing
2021-05-13 11:35   ` Nikolay Aleksandrov
2021-05-13 11:35     ` [Bridge] " Nikolay Aleksandrov
2021-05-12 23:19 ` [net-next v3 08/11] net: bridge: mcast: split router port del+notify " Linus Lüssing
2021-05-12 23:19   ` [Bridge] " Linus Lüssing
2021-05-13 11:46   ` Nikolay Aleksandrov
2021-05-13 11:46     ` [Bridge] " Nikolay Aleksandrov
2021-05-12 23:19 ` [net-next v3 09/11] net: bridge: mcast: split multicast router state for IPv4 and IPv6 Linus Lüssing
2021-05-12 23:19   ` [Bridge] " Linus Lüssing
2021-05-13 11:59   ` Nikolay Aleksandrov
2021-05-13 11:59     ` [Bridge] " Nikolay Aleksandrov
2021-05-12 23:19 ` [net-next v3 10/11] net: bridge: mcast: add ip4+ip6 mcast router timers to mdb netlink Linus Lüssing
2021-05-12 23:19   ` [Bridge] " Linus Lüssing
2021-05-13 11:38   ` Nikolay Aleksandrov
2021-05-13 11:38     ` [Bridge] " Nikolay Aleksandrov
2021-05-12 23:19 ` Linus Lüssing [this message]
2021-05-12 23:19   ` [Bridge] [net-next v3 11/11] net: bridge: mcast: export multicast router presence adjacent to a port Linus Lüssing
2021-05-13 11:39   ` Nikolay Aleksandrov
2021-05-13 11:39     ` [Bridge] " Nikolay Aleksandrov
2021-05-13 12:02 ` [PATCH net-next v3 00/11] net: bridge: split IPv4/v6 mc router state and export for batman-adv Nikolay Aleksandrov
2021-05-13 12:02   ` [Bridge] " Nikolay Aleksandrov
2021-05-13 13:34   ` Linus Lüssing
2021-05-13 13:34     ` [Bridge] " Linus Lüssing
2021-05-13 13:36     ` Nikolay Aleksandrov
2021-05-13 13:36       ` [Bridge] " Nikolay Aleksandrov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210512231941.19211-12-linus.luessing@c0d3.blue \
    --to=linus.luessing@c0d3.blue \
    --cc=bridge@lists.linux-foundation.org \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nikolay@nvidia.com \
    --cc=roopa@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.