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>,
Willem de Bruijn <willemb@google.com>,
Simon Horman <horms@kernel.org>
Subject: [PATCH net-next v5 4/7] net: dsa: motorcomm: Reject isolated redirect targets
Date: Sun, 6 Dec 2026 10:20:35 +0800 [thread overview]
Message-ID: <20261206022040.4020726-5-mmyangfl@gmail.com> (raw)
In-Reply-To: <20261206022040.4020726-1-mmyangfl@gmail.com>
Port isolation takes after REDIR judgment, but software delivers such
frames. Either route such rules to the software, or reject offloading.
Fixes: 8eb9e7520b17 ("net: dsa: yt921x: Add ACL support")
Signed-off-by: David Yang <mmyangfl@gmail.com>
---
drivers/net/dsa/motorcomm/chip.c | 9 +++++++++
drivers/net/dsa/motorcomm/chip.h | 2 ++
drivers/net/dsa/motorcomm/tc.c | 34 ++++++++++++++++++++++++++++++--
drivers/net/dsa/motorcomm/tc.h | 6 +++++-
4 files changed, 48 insertions(+), 3 deletions(-)
diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index b15c1b821087..0fdef7d2c11d 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -1420,6 +1420,15 @@ yt921x_isolation_calc(struct yt921x_priv *priv, u16 *ports_maskp,
*ports_maskp = ports_mask;
}
+u16 yt921x_isolation_calc_port(struct yt921x_priv *priv, int port)
+{
+ u16 isolation_masks[YT921X_PORT_NUM];
+ u16 ports_mask = BIT(port);
+
+ yt921x_isolation_calc(priv, &ports_mask, isolation_masks);
+ return isolation_masks[port];
+}
+
static int
yt921x_isolation_commit(struct yt921x_priv *priv, u16 ports_mask,
const u16 *isolation_masks)
diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h
index 22381009db51..749fe12fa852 100644
--- a/drivers/net/dsa/motorcomm/chip.h
+++ b/drivers/net/dsa/motorcomm/chip.h
@@ -559,4 +559,6 @@ static inline u32 ethaddr_lo2_to_u32(const unsigned char *addr)
return (addr[4] << 8) | addr[5];
}
+u16 yt921x_isolation_calc_port(struct yt921x_priv *priv, int port);
+
#endif
diff --git a/drivers/net/dsa/motorcomm/tc.c b/drivers/net/dsa/motorcomm/tc.c
index e3f057ed580f..597a986026d5 100644
--- a/drivers/net/dsa/motorcomm/tc.c
+++ b/drivers/net/dsa/motorcomm/tc.c
@@ -1041,6 +1041,8 @@ yt921x_acl_rule_ext_parse_flow_action(struct yt921x_acl_rule_ext *ruleext,
int res;
memset(action, 0, 3 * sizeof(*action));
+ ruleext->r.sw_assisting = false;
+
flow_action_for_each(i, act, flow_action) {
/* The flow action entry carries no mirred control, so there
* is no way to tell whether software would continue past a
@@ -1072,6 +1074,21 @@ yt921x_acl_rule_ext_parse_flow_action(struct yt921x_acl_rule_ext *ruleext,
goto fallback;
}
+ /* Port isolation takes after REDIR judgment, but
+ * software delivers such frames.
+ */
+ if (yt921x_isolation_calc_port(priv, port) &
+ BIT(to_dp->index)) {
+ if (cls->common.skip_sw) {
+ if (to_dp->index == port)
+ reason = "Redirect to self, which is not hairpinning";
+ else
+ reason = "Redirect target isolated, or not in the same bridge";
+ goto fallback;
+ }
+ ruleext->r.sw_assisting = true;
+ }
+
action[2] |= YT921X_ACL_ACTc_FWD_EN |
YT921X_ACL_ACTc_FWD_REDIR |
YT921X_ACL_ACTc_FWD_REDIR_DPORTn(to_dp->index);
@@ -1135,6 +1152,7 @@ yt921x_acl_rule_ext_parse_flow_action(struct yt921x_acl_rule_ext *ruleext,
~YT921X_ACL_ACTc_FWD_M;
action[2] |= YT921X_ACL_ACTc_FWD_EN |
YT921X_ACL_ACTc_FWD_TRAP;
+ ruleext->r.sw_assisting = false;
terminal = true;
break;
}
@@ -1301,8 +1319,19 @@ yt921x_acl_commit(struct yt921x_priv *priv, unsigned int entid, u8 entsmask)
aclrule = aclblk->rules[binid];
/* Write actions */
- res = yt921x_reg96_write(priv, YT921X_ACLn_ACT(entid),
- aclrule ? aclrule->action : zeros);
+ if (!aclrule || !aclrule->sw_assisting) {
+ res = yt921x_reg96_write(priv, YT921X_ACLn_ACT(entid),
+ aclrule ? aclrule->action : zeros);
+ } else {
+ u32 action[3];
+
+ memcpy(action, aclrule->action, sizeof(action));
+ action[2] &= ~YT921X_ACL_ACTc_FWD_REDIR_DPORTS_M &
+ ~YT921X_ACL_ACTc_FWD_M;
+ action[2] |= YT921X_ACL_ACTc_FWD_EN | YT921X_ACL_ACTc_FWD_TRAP;
+
+ res = yt921x_reg96_write(priv, YT921X_ACLn_ACT(entid), action);
+ }
if (res)
return res;
@@ -1502,6 +1531,7 @@ yt921x_acl_add(struct yt921x_priv *priv,
~YT921X_ACL_ACTc_FWD_M;
aclrule->action[2] |= YT921X_ACL_ACTc_FWD_EN |
YT921X_ACL_ACTc_FWD_TRAP;
+ aclrule->sw_assisting = false;
}
if (meterid < YT921X_METER_NUM)
aclrule->action[0] |= YT921X_ACL_ACTa_METER_ID(meterid);
diff --git a/drivers/net/dsa/motorcomm/tc.h b/drivers/net/dsa/motorcomm/tc.h
index cc53f148d690..81c29a8eec5a 100644
--- a/drivers/net/dsa/motorcomm/tc.h
+++ b/drivers/net/dsa/motorcomm/tc.h
@@ -349,7 +349,11 @@ struct yt921x_acl_rule {
enum tc_setup_type type;
u32 action[3];
- bool sw_assisted;
+ bool sw_assisted:1;
+ /* not a TRAP rule, but installed as trapped as some conditions are not
+ * met
+ */
+ bool sw_assisting:1;
u8 mask;
struct yt921x_acl_entry entries[YT921X_ACL_ENT_PER_BLK];
--
2.53.0
next prev parent reply other threads:[~2026-12-06 2:21 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-06 2:20 [PATCH net-next v5 0/7] net: dsa: motorcomm: Reject isolated redirect targets David Yang
2026-12-06 2:20 ` [PATCH net-next v5 1/7] net: dsa: motorcomm: Remove local cpu_ports_mask David Yang
2026-12-06 2:20 ` [PATCH net-next v5 2/7] net: dsa: motorcomm: Do not block hairpins on standalone ports David Yang
2026-12-06 2:20 ` [PATCH net-next v5 3/7] net: dsa: motorcomm: Derive port isolation masks on the fly David Yang
2026-12-06 2:20 ` David Yang [this message]
2026-12-06 2:20 ` [PATCH net-next v5 5/7] net: dsa: motorcomm: Reject bridge changes that break redirect rules David Yang
2026-12-06 2:20 ` [PATCH net-next v5 6/7] net: dsa: destroy the bridge port before the leave on join rollback David Yang
2026-12-06 2:20 ` [PATCH net-next v5 7/7] 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=20261206022040.4020726-5-mmyangfl@gmail.com \
--to=mmyangfl@gmail.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=willemb@google.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