From: David Yang <mmyangfl@gmail.com>
To: netdev@vger.kernel.org
Cc: David Yang <mmyangfl@gmail.com>, Andrew Lunn <andrew@lunn.ch>,
Vladimir Oltean <olteanv@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Subject: [PATCH net-next v3 4/5] net: dsa: motorcomm: Reject bridge flags that break redirect rules
Date: Tue, 1 Dec 2026 16:14:55 +0800 [thread overview]
Message-ID: <20261201081459.2104904-5-mmyangfl@gmail.com> (raw)
In-Reply-To: <20261201081459.2104904-1-mmyangfl@gmail.com>
Bridge flag changes rewrite the isolation masks, so a reachable redirect
rule may be blocked by port isolation. The masks are rewritten only from
the deferred handler, so judge a rule and a flag change against the flags
as configured, not against what the switch was last programmed with.
Reject such changes based on bookkeeping counters:
.port_pre_bridge_flags() is atomic.
Fixes: 8eb9e7520b17 ("net: dsa: yt921x: Add ACL support")
Signed-off-by: David Yang <mmyangfl@gmail.com>
---
drivers/net/dsa/motorcomm/chip.c | 31 +++++++++++++++++++++++++++
drivers/net/dsa/motorcomm/chip.h | 1 +
drivers/net/dsa/motorcomm/tc.c | 36 +++++++++++++++++++++++++-------
3 files changed, 60 insertions(+), 8 deletions(-)
diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index 6c6a87207bd5..0bc5da2b80d7 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -1448,6 +1448,37 @@ yt921x_dsa_port_pre_bridge_flags(struct dsa_switch *ds, int port,
BR_MCAST_FLOOD | BR_ISOLATED))
return -EINVAL;
+ if ((flags.mask & BR_HAIRPIN_MODE) && !(flags.val & BR_HAIRPIN_MODE) &&
+ pp->acl_dst_cnts[port]) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Cannot disable hairpin mode while there are hairpin redirect rules installed");
+ return -EINVAL;
+ }
+
+ if ((flags.mask & BR_ISOLATED) && (flags.val & BR_ISOLATED)) {
+ struct dsa_port *dp = dsa_to_port(ds, port);
+ unsigned long ports_mask;
+ struct net_device *bdev;
+ unsigned int i;
+
+ bdev = dsa_port_bridge_dev_get(dp);
+ if (!bdev)
+ return 0;
+
+ ports_mask = dsa_bridge_ports(ds, bdev);
+ for_each_set_bit(i, &ports_mask, YT921X_PORT_NUM) {
+ if (i == port || !priv->ports[i].isolated)
+ continue;
+
+ if (pp->acl_dst_cnts[i] ||
+ priv->ports[i].acl_dst_cnts[port]) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Cannot isolate port while there are redirect rules installed");
+ return -EINVAL;
+ }
+ }
+ }
+
if ((flags.mask & BR_HAIRPIN_MODE) || (flags.mask & BR_ISOLATED)) {
struct dsa_port *dp = dsa_to_port(ds, port);
struct net_device *bdev;
diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h
index 203371888c45..b87329dac609 100644
--- a/drivers/net/dsa/motorcomm/chip.h
+++ b/drivers/net/dsa/motorcomm/chip.h
@@ -467,6 +467,7 @@ struct yt921x_port {
u16 isolation_mask;
unsigned short acl_cnt;
+ unsigned short acl_dst_cnts[YT921X_PORT_NUM];
#if IS_ENABLED(CONFIG_NET_DSA_YT921X_LEDS)
unsigned char led_duty;
diff --git a/drivers/net/dsa/motorcomm/tc.c b/drivers/net/dsa/motorcomm/tc.c
index b7fe867da088..9a19ee7d4358 100644
--- a/drivers/net/dsa/motorcomm/tc.c
+++ b/drivers/net/dsa/motorcomm/tc.c
@@ -1403,7 +1403,8 @@ yt921x_acl_del(struct yt921x_priv *priv, enum tc_setup_type type,
unsigned int binid;
unsigned int blkid;
unsigned int entid;
- unsigned long m;
+ unsigned long srcs;
+ unsigned long dsts;
unsigned int o;
u32 ctrl;
int res;
@@ -1422,9 +1423,17 @@ yt921x_acl_del(struct yt921x_priv *priv, enum tc_setup_type type,
ret = yt921x_acl_commit(priv, entid, aclrule->mask);
/* the kernel never rolls back on failure */
- m = FIELD_GET(YT921X_ACL_KEYb_SPORTS_M, aclrule->entries[0].key[1]);
- for_each_set_bit(o, &m, YT921X_PORT_NUM) {
+ srcs = FIELD_GET(YT921X_ACL_KEYb_SPORTS_M, aclrule->entries[0].key[1]);
+ dsts = FIELD_GET(YT921X_ACL_ACTc_FWD_REDIR_DPORTS_M,
+ aclrule->action[2]);
+ for_each_set_bit(o, &srcs, YT921X_PORT_NUM) {
struct yt921x_port *pp = &priv->ports[o];
+ unsigned int i;
+
+ if (!aclrule->sw_assisted)
+ for_each_set_bit(i, &dsts, YT921X_PORT_NUM)
+ if (!WARN_ON(!pp->acl_dst_cnts[i]))
+ pp->acl_dst_cnts[i]--;
if (!WARN_ON(!pp->acl_cnt)) {
pp->acl_cnt--;
@@ -1466,6 +1475,8 @@ yt921x_acl_add(struct yt921x_priv *priv,
unsigned int binid;
unsigned int blkid;
unsigned int entid;
+ unsigned long srcs;
+ unsigned long dsts;
unsigned long m;
unsigned int o;
u32 ctrl;
@@ -1539,8 +1550,8 @@ yt921x_acl_add(struct yt921x_priv *priv,
/* Activate ACL if needed */
ctrl = 0;
- m = FIELD_GET(YT921X_ACL_KEYb_SPORTS_M, ruleext->r.entries[0].key[1]);
- for_each_set_bit(o, &m, YT921X_PORT_NUM)
+ srcs = FIELD_GET(YT921X_ACL_KEYb_SPORTS_M, aclrule->entries[0].key[1]);
+ for_each_set_bit(o, &srcs, YT921X_PORT_NUM)
if (!priv->ports[o].acl_cnt)
ctrl |= YT921X_ACL_PORT_PORTn(o);
if (ctrl) {
@@ -1559,9 +1570,18 @@ yt921x_acl_add(struct yt921x_priv *priv,
}
/* Bookkeeping */
- m = FIELD_GET(YT921X_ACL_KEYb_SPORTS_M, ruleext->r.entries[0].key[1]);
- for_each_set_bit(o, &m, YT921X_PORT_NUM)
- priv->ports[o].acl_cnt++;
+ dsts = FIELD_GET(YT921X_ACL_ACTc_FWD_REDIR_DPORTS_M,
+ aclrule->action[2]);
+ for_each_set_bit(o, &srcs, YT921X_PORT_NUM) {
+ struct yt921x_port *pp = &priv->ports[o];
+ unsigned int i;
+
+ pp->acl_cnt++;
+
+ if (!aclrule->sw_assisted)
+ for_each_set_bit(i, &dsts, YT921X_PORT_NUM)
+ pp->acl_dst_cnts[i]++;
+ }
if (meterid < YT921X_METER_NUM)
set_bit(meterid, priv->meters_map);
--
2.53.0
next prev parent reply other threads:[~2026-12-01 8:16 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 8:14 [PATCH net-next v3 0/5] net: dsa: motorcomm: Reject isolated redirect targets David Yang
2026-12-01 8:14 ` [PATCH net-next v3 1/5] net: dsa: motorcomm: Remove local cpu_ports_mask David Yang
2026-12-01 8:14 ` [PATCH net-next v3 2/5] net: dsa: motorcomm: Cache port isolation masks David Yang
2026-12-01 8:14 ` [PATCH net-next v3 3/5] net: dsa: motorcomm: Reject isolated redirect targets David Yang
2026-12-01 8:14 ` David Yang [this message]
2026-12-01 8:14 ` [PATCH net-next v3 5/5] net: dsa: motorcomm: Recompute redirect rules on bridge changes David Yang
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=20261201081459.2104904-5-mmyangfl@gmail.com \
--to=mmyangfl@gmail.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.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