[PATCH net-next 4/5] net: dsa: microchip: ksz9477: refuse FDB/MDB entries for trapped groups

From
Oleksij Rempel <o.rempel@pengutronix.de>
Date
2026-11-26 08:08:03
Also in
bridge
Reply to
Oleksij Rempel, 2026-11-26
Refuse FDB and MDB entries for trapped link-local groups on user ports,
so that they cannot bypass the trap.

The KSZ9477 family looks up a destination address in the address
lookup table (learned and static FDB entries), the static address table
(MDB entries) and the reserved multicast table. The driver traps the
link-local groups with the reserved multicast table: it sends
01:80:C2:00:00:00 to :0F to the CPU only, except :01 (PAUSE frames),
which it drops. On a KSZ9893, an FDB or MDB entry for a trapped group
overrides that rule. The switch then forwards such frames by its own
lookup, while the bridge decides in software whether to forward these
groups:
- with an MDB entry for 01:80:C2:00:00:0E on lan2, the switch forwarded
  these frames from lan1 to lan2, although group_fwd_mask did not allow
  it.
- with a host FDB entry for 01:80:C2:00:00:00, a Blocking port stopped
  passing BPDUs to the CPU, so the bridge moved the port to Listening.

Record the trapped groups when the driver sets up the reserved multicast
table, and refuse to offload such entries on user ports with
-EOPNOTSUPP. bridge fdb add and bridge mdb add still succeed, and the
bridge keeps the entries without the offload flag. In software the
bridge uses only the MDB entries for these groups, so an FDB entry for
such a group has no effect. DSA logs an error for a refused FDB entry,
not for an MDB entry. Accept the entries on the CPU and DSA ports
without a write. Entries for :01 are accepted as before.

A later patch makes the tagger stop marking these frames as already
forwarded by the switch. This patch comes first, so that the switch and
the bridge never both forward such a frame. Until then, frames to a
group with a refused MDB entry are not forwarded between switch ports
at all.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/dsa/microchip/ksz9477.c    | 58 ++++++++++++++++++++++++++++++++++
 drivers/net/dsa/microchip/ksz_common.h |  2 ++
 2 files changed, 60 insertions(+)
diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index 8271bc742ddc5c92b925b01bedfcf876cfa14078..b972c9fab55c170758dac97bda026e1f29e487f2 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -768,6 +768,27 @@ int ksz9477_port_vlan_del(struct dsa_switch *ds, int port,
 	return 0;
 }
 
+/* True if @addr is a link-local group that the switch sends to the CPU only.
+ * An FDB or MDB entry for such a group would override the trap.
+ */
+static bool ksz9477_link_local_is_trapped(struct ksz_device *dev,
+					  const unsigned char *addr)
+{
+	/* is_link_local_ether_addr() limits addr[5] to 0x00..0x0f */
+	return is_link_local_ether_addr(addr) &&
+	       dev->link_local_to_cpu & BIT(addr[5]);
+}
+
+/* Return -EOPNOTSUPP on a user port, so that the bridge keeps the entry in
+ * software and does not mark it offloaded. Return 0 on the CPU and DSA ports
+ * and write nothing: the bridge adds its host entries there, and they must
+ * not fail.
+ */
+static int ksz9477_link_local_entry_err(struct dsa_switch *ds, int port)
+{
+	return dsa_is_user_port(ds, port) ? -EOPNOTSUPP : 0;
+}
+
 int ksz9477_fdb_add(struct dsa_switch *ds, int port,
 		    const unsigned char *addr, u16 vid, struct dsa_db db)
 {
@@ -776,6 +797,9 @@ int ksz9477_fdb_add(struct dsa_switch *ds, int port,
 	u32 data;
 	int ret = 0;
 
+	if (ksz9477_link_local_is_trapped(dev, addr))
+		return ksz9477_link_local_entry_err(ds, port);
+
 	mutex_lock(&dev->alu_mutex);
 
 	/* find any entry with mac & vid */
@@ -840,6 +864,10 @@ int ksz9477_fdb_del(struct dsa_switch *ds, int port,
 	u32 data;
 	int ret = 0;
 
+	/* never written, see ksz9477_link_local_entry_err() */
+	if (ksz9477_link_local_is_trapped(dev, addr))
+		return 0;
+
 	mutex_lock(&dev->alu_mutex);
 
 	/* read any entry with mac & vid */
@@ -989,6 +1017,9 @@ int ksz9477_mdb_add(struct dsa_switch *ds, int port,
 	u32 mac_hi, mac_lo;
 	int err = 0;
 
+	if (ksz9477_link_local_is_trapped(dev, mdb->addr))
+		return ksz9477_link_local_entry_err(ds, port);
+
 	shifts = dev->info->shifts;
 	masks = dev->info->masks;
 
@@ -1069,6 +1100,10 @@ int ksz9477_mdb_del(struct dsa_switch *ds, int port,
 	int index;
 	u32 data;
 
+	/* never written, see ksz9477_link_local_entry_err() */
+	if (ksz9477_link_local_is_trapped(dev, mdb->addr))
+		return 0;
+
 	shifts = dev->info->shifts;
 	masks = dev->info->masks;
 
@@ -1554,8 +1589,21 @@ static void ksz9477_config_cpu_port(struct dsa_switch *ds)
 
 static u8 reserved_mcast_map[RESV_MCAST_CNT] = { 0, 1, 3, 16, 32, 33, 2, 17 };
 
+/* Index: group number in the datasheet's Reserved Multicast Address Table,
+ * the same index as reserved_mcast_map. Value: the link-local addresses the
+ * group covers, bit X for 01:80:C2:00:00:0X. The other groups cover
+ * addresses above :0F.
+ */
+static const u16 ksz9477_resv_mcast_link_local[RESV_MCAST_CNT] = {
+	[0] = BIT(0),			/* STP BPDUs */
+	[1] = BIT(1),			/* MAC control (e.g. PAUSE), dropped */
+	[2] = BIT(3),			/* 802.1X (EAPOL) */
+	[6] = BIT(2) | GENMASK(15, 4),	/* LACP, LLDP and others */
+};
+
 int ksz9477_enable_stp_addr(struct ksz_device *dev)
 {
+	u16 link_local_to_cpu = 0;
 	u8 i, ports, update;
 	const u32 *masks;
 	bool override;
@@ -1621,6 +1669,14 @@ int ksz9477_enable_stp_addr(struct ksz_device *dev)
 			update = ports;
 			break;
 		}
+
+		/* Record the link-local addresses of group i if the switch
+		 * sends it to the CPU only. Group 1 keeps its drop default and
+		 * does not match.
+		 */
+		if (update == BIT(dev->cpu_port))
+			link_local_to_cpu |= ksz9477_resv_mcast_link_local[i];
+
 		if (update != ports || override) {
 			data &= ~dev->port_mask;
 			data |= update;
@@ -1650,6 +1706,8 @@ int ksz9477_enable_stp_addr(struct ksz_device *dev)
 		}
 	}
 
+	dev->link_local_to_cpu = link_local_to_cpu;
+
 	return 0;
 }
 
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index 8819670cbb053eeb73ea4a7685303d9849bd6efb..7b96d110b1f64f4226ee7a371da38cd7e5b3767a 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -243,6 +243,8 @@ struct ksz_device {
 	u16 mirror_rx;
 	u16 mirror_tx;
 	u16 port_mask;
+	/* link-local groups sent to the CPU only, bit X: 01:80:C2:00:00:0X */
+	u16 link_local_to_cpu;
 	struct mutex lock_irq;		/* IRQ Access */
 	struct ksz_irq girq;
 	struct ksz_ptp_data ptp_data;
-- 
2.47.3
Thread (14 messages) 14 messages, 4 authors, last reply 5d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help