Add a helper that marks a received frame like
dsa_default_offload_fwd_mark(), except for link-local frames that the
switch traps to the CPU.
Some switches trap all link-local groups (01:80:C2:00:00:00 to :0F),
others only some of them. The tagger must not mark a trapped frame, so
that the bridge decides whether to forward it. tag_mxl862xx.c
open-codes this check for all groups; tag_ksz.c needs it for a set of
groups that depends on the switch.
Suggested-by: Andrew Lunn <andr…@lunn.ch>
Signed-off-by: Oleksij Rempel <o.re…@pengutronix.de>
---
Changes in v2:
- New in v2 (Andrew).
---
net/dsa/tag.h | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/net/dsa/tag.h b/net/dsa/tag.h
index cf52283fe9df47685a2c8b605f42727691439830..d3a55438fc7a78b689f1a68c6dd9a7c22a3cbea4 100644
--- a/net/dsa/tag.h
+++ b/net/dsa/tag.h
@@ -241,6 +241,31 @@ static inline void dsa_default_offload_fwd_mark(struct sk_buff *skb)
skb->offload_fwd_mark = !!(dp->bridge);
}
+/* All link-local groups, 01:80:C2:00:00:00 to :0F */
+#define DSA_LINK_LOCAL_ALL GENMASK(15, 0)
+
+/**
+ * dsa_link_local_offload_fwd_mark - mark a frame unless the switch trapped it
+ * @skb: received frame
+ * @trapped: link-local groups that the switch traps to the CPU, bit N for
+ * 01:80:C2:00:00:0N
+ *
+ * Like dsa_default_offload_fwd_mark(), but leave frames to the groups in
+ * @trapped unmarked. The switch did not forward them, so the bridge decides.
+ */
+static inline void dsa_link_local_offload_fwd_mark(struct sk_buff *skb,
+ u16 trapped)
+{
+ const u8 *addr = eth_hdr(skb)->h_dest;
+
+ /* is_link_local_ether_addr() limits addr[5] to 0x00..0x0f */
+ if (unlikely(is_link_local_ether_addr(addr)) &&
+ (trapped & BIT(addr[5])))
+ return;
+
+ dsa_default_offload_fwd_mark(skb);
+}
+
/* Helper for removing DSA header tags from packets in the RX path.
* Must not be called before skb_pull(len).
* skb->data
--
2.47.3