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 v4 05/11] net: bridge: mcast: prepare is-router function for mcast router split
Date: Thu, 13 May 2021 15:20:47 +0200 [thread overview]
Message-ID: <20210513132053.23445-6-linus.luessing@c0d3.blue> (raw)
In-Reply-To: <20210513132053.23445-1-linus.luessing@c0d3.blue>
In preparation for the upcoming split of multicast router state into
their IPv4 and IPv6 variants make br_multicast_is_router() protocol
family aware.
Note that for now br_ip6_multicast_is_router() uses the currently still
common ip4_mc_router_timer for now. It will be renamed to
ip6_mc_router_timer later when the split is performed.
While at it also renames the "1" and "2" constants in
br_multicast_is_router() to the MDB_RTR_TYPE_TEMP_QUERY and
MDB_RTR_TYPE_PERM enums.
Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
---
net/bridge/br_input.c | 2 +-
net/bridge/br_multicast.c | 5 +++--
net/bridge/br_private.h | 37 +++++++++++++++++++++++++++++++++----
3 files changed, 37 insertions(+), 7 deletions(-)
diff --git a/net/bridge/br_input.c b/net/bridge/br_input.c
index 8875e95..1f50630 100644
--- a/net/bridge/br_input.c
+++ b/net/bridge/br_input.c
@@ -132,7 +132,7 @@ int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb
if ((mdst || BR_INPUT_SKB_CB_MROUTERS_ONLY(skb)) &&
br_multicast_querier_exists(br, eth_hdr(skb), mdst)) {
if ((mdst && mdst->host_joined) ||
- br_multicast_is_router(br)) {
+ br_multicast_is_router(br, skb)) {
local_rcv = true;
br->dev->stats.multicast++;
}
diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
index 7edbbc9..048b5b9 100644
--- a/net/bridge/br_multicast.c
+++ b/net/bridge/br_multicast.c
@@ -1391,7 +1391,8 @@ static void br_multicast_local_router_expired(struct timer_list *t)
spin_lock(&br->multicast_lock);
if (br->multicast_router == MDB_RTR_TYPE_DISABLED ||
br->multicast_router == MDB_RTR_TYPE_PERM ||
- timer_pending(&br->ip4_mc_router_timer))
+ br_ip4_multicast_is_router(br) ||
+ br_ip6_multicast_is_router(br))
goto out;
br_mc_router_state_change(br, false);
@@ -3622,7 +3623,7 @@ bool br_multicast_router(const struct net_device *dev)
bool is_router;
spin_lock_bh(&br->multicast_lock);
- is_router = br_multicast_is_router(br);
+ is_router = br_multicast_is_router(br, NULL);
spin_unlock_bh(&br->multicast_lock);
return is_router;
}
diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
index d970ef7..f9a381f 100644
--- a/net/bridge/br_private.h
+++ b/net/bridge/br_private.h
@@ -874,11 +874,40 @@ br_multicast_rport_from_node_skb(struct hlist_node *rp, struct sk_buff *skb) {
return hlist_entry_safe(rp, struct net_bridge_port, ip4_rlist);
}
-static inline bool br_multicast_is_router(struct net_bridge *br)
+static inline bool br_ip4_multicast_is_router(struct net_bridge *br)
{
- return br->multicast_router == 2 ||
- (br->multicast_router == 1 &&
- timer_pending(&br->ip4_mc_router_timer));
+ return timer_pending(&br->ip4_mc_router_timer);
+}
+
+static inline bool br_ip6_multicast_is_router(struct net_bridge *br)
+{
+#if IS_ENABLED(CONFIG_IPV6)
+ return timer_pending(&br->ip4_mc_router_timer);
+#else
+ return false;
+#endif
+}
+
+static inline bool
+br_multicast_is_router(struct net_bridge *br, struct sk_buff *skb)
+{
+ switch (br->multicast_router) {
+ case MDB_RTR_TYPE_PERM:
+ return true;
+ case MDB_RTR_TYPE_TEMP_QUERY:
+ if (skb) {
+ if (skb->protocol == htons(ETH_P_IP))
+ return br_ip4_multicast_is_router(br);
+ else if (skb->protocol == htons(ETH_P_IPV6))
+ return br_ip6_multicast_is_router(br);
+ } else {
+ return br_ip4_multicast_is_router(br) ||
+ br_ip6_multicast_is_router(br);
+ }
+ fallthrough;
+ default:
+ return false;
+ }
}
static inline bool
--
2.31.0
next prev parent reply other threads:[~2021-05-13 13:21 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-13 13:20 [PATCH net-next v4 00/11] net: bridge: split IPv4/v6 mc router state and export for batman-adv Linus Lüssing
2021-05-13 13:20 ` [net-next v4 01/11] net: bridge: mcast: rename multicast router lists and timers Linus Lüssing
2021-05-13 13:20 ` [net-next v4 02/11] net: bridge: mcast: add wrappers for router node retrieval Linus Lüssing
2021-05-13 13:20 ` [net-next v4 03/11] net: bridge: mcast: prepare mdb netlink for mcast router split Linus Lüssing
2021-05-13 13:20 ` [net-next v4 04/11] net: bridge: mcast: prepare query reception " Linus Lüssing
2021-05-13 13:20 ` Linus Lüssing [this message]
2021-05-15 16:44 ` [net-next v4 05/11] net: bridge: mcast: prepare is-router function " Guenter Roeck
2021-05-13 13:20 ` [net-next v4 06/11] net: bridge: mcast: prepare expiry functions " Linus Lüssing
2021-05-13 13:20 ` [net-next v4 07/11] net: bridge: mcast: prepare add-router function " Linus Lüssing
2021-05-13 13:20 ` [net-next v4 08/11] net: bridge: mcast: split router port del+notify " Linus Lüssing
2021-05-13 13:20 ` [net-next v4 09/11] net: bridge: mcast: split multicast router state for IPv4 and IPv6 Linus Lüssing
2021-05-13 13:20 ` [net-next v4 10/11] net: bridge: mcast: add ip4+ip6 mcast router timers to mdb netlink Linus Lüssing
2021-05-13 13:20 ` [net-next v4 11/11] net: bridge: mcast: export multicast router presence adjacent to a port Linus Lüssing
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=20210513132053.23445-6-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).