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 v4 4/6] net: dsa: motorcomm: Reject isolated redirect targets
Date: Fri, 4 Dec 2026 18:12:55 +0800 [thread overview]
Message-ID: <20261204101300.3680838-5-mmyangfl@gmail.com> (raw)
In-Reply-To: <20261204101300.3680838-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 | 33 ++++++++++++++++++++++++++++++--
drivers/net/dsa/motorcomm/tc.h | 6 +++++-
4 files changed, 47 insertions(+), 3 deletions(-)
diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index 567ce8716acd..a71a8dd5dc63 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -1412,6 +1412,15 @@ yt921x_isolation_calc_ports(struct yt921x_priv *priv, u16 *ports_maskp,
}
}
+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_ports(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..e65baccda99e 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);
@@ -1301,8 +1318,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 +1530,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-04 10:13 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 10:12 [PATCH net-next v4 0/6] net: dsa: motorcomm: Reject isolated redirect targets David Yang
2026-12-04 10:12 ` [PATCH net-next v4 1/6] net: dsa: motorcomm: Remove local cpu_ports_mask David Yang
2026-12-04 10:12 ` [PATCH net-next v4 2/6] net: dsa: motorcomm: Do not block hairpins on standalone ports David Yang
2026-12-04 10:12 ` [PATCH net-next v4 3/6] net: dsa: motorcomm: Derive port isolation masks on the fly David Yang
2026-12-04 10:12 ` David Yang [this message]
2026-12-04 10:12 ` [PATCH net-next v4 5/6] net: dsa: motorcomm: Reject bridge flags that break redirect rules David Yang
2026-12-04 10:12 ` [PATCH net-next v4 6/6] 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=20261204101300.3680838-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