diff mbox series

[v3,net-next,1/3] net: dsa: tag_dsa: Allow forwarding of redirected IGMP traffic

Message ID 20201114234558.31203-2-tobias@waldekranz.com (mailing list archive)
State Accepted
Delegated to: Netdev Maintainers
Headers show
Series net: dsa: tag_dsa: Unify regular and ethertype DSA taggers | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch warning WARNING: networking block comments don't use an empty /* line, use /* Comment...
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link
netdev/stable success Stable not CCed

Commit Message

Tobias Waldekranz Nov. 14, 2020, 11:45 p.m. UTC
When receiving an IGMP/MLD frame with a TO_CPU tag, the switch has not
performed any forwarding of it. This means that we should not set the
offload_fwd_mark on the skb, in case a software bridge wants it
forwarded.

This is a port of:

1ed9ec9b08ad ("dsa: Allow forwarding of redirected IGMP traffic")

Which corrected the issue for chips using EDSA tags, but not for those
using regular DSA tags.

Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com>
---
 net/dsa/tag_dsa.c | 32 +++++++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)

Comments

Andrew Lunn Nov. 17, 2020, 2:49 a.m. UTC | #1
On Sun, Nov 15, 2020 at 12:45:56AM +0100, Tobias Waldekranz wrote:
> When receiving an IGMP/MLD frame with a TO_CPU tag, the switch has not
> performed any forwarding of it. This means that we should not set the
> offload_fwd_mark on the skb, in case a software bridge wants it
> forwarded.
> 
> This is a port of:
> 
> 1ed9ec9b08ad ("dsa: Allow forwarding of redirected IGMP traffic")
> 
> Which corrected the issue for chips using EDSA tags, but not for those
> using regular DSA tags.
> 
> Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew
Florian Fainelli Nov. 17, 2020, 3:47 a.m. UTC | #2
On 11/14/2020 3:45 PM, Tobias Waldekranz wrote:
> When receiving an IGMP/MLD frame with a TO_CPU tag, the switch has not
> performed any forwarding of it. This means that we should not set the
> offload_fwd_mark on the skb, in case a software bridge wants it
> forwarded.
> 
> This is a port of:
> 
> 1ed9ec9b08ad ("dsa: Allow forwarding of redirected IGMP traffic")
> 
> Which corrected the issue for chips using EDSA tags, but not for those
> using regular DSA tags.
> 
> Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
diff mbox series

Patch

diff --git a/net/dsa/tag_dsa.c b/net/dsa/tag_dsa.c
index 63d690a0fca6..af340a4945dc 100644
--- a/net/dsa/tag_dsa.c
+++ b/net/dsa/tag_dsa.c
@@ -12,6 +12,11 @@ 
 
 #define DSA_HLEN	4
 
+#define FRAME_TYPE_TO_CPU	0x00
+#define FRAME_TYPE_FORWARD	0x03
+
+#define TO_CPU_CODE_IGMP_MLD_TRAP	0x02
+
 static struct sk_buff *dsa_xmit(struct sk_buff *skb, struct net_device *dev)
 {
 	struct dsa_port *dp = dsa_slave_to_port(dev);
@@ -61,6 +66,8 @@  static struct sk_buff *dsa_rcv(struct sk_buff *skb, struct net_device *dev,
 	u8 *dsa_header;
 	int source_device;
 	int source_port;
+	int frame_type;
+	int code;
 
 	if (unlikely(!pskb_may_pull(skb, DSA_HLEN)))
 		return NULL;
@@ -73,8 +80,29 @@  static struct sk_buff *dsa_rcv(struct sk_buff *skb, struct net_device *dev,
 	/*
 	 * Check that frame type is either TO_CPU or FORWARD.
 	 */
-	if ((dsa_header[0] & 0xc0) != 0x00 && (dsa_header[0] & 0xc0) != 0xc0)
+	frame_type = dsa_header[0] >> 6;
+
+	switch (frame_type) {
+	case FRAME_TYPE_TO_CPU:
+		code = (dsa_header[1] & 0x6) | ((dsa_header[2] >> 4) & 1);
+
+		/*
+		 * Mark the frame to never egress on any port of the same switch
+		 * unless it's a trapped IGMP/MLD packet, in which case the
+		 * bridge might want to forward it.
+		 */
+		if (code != TO_CPU_CODE_IGMP_MLD_TRAP)
+			skb->offload_fwd_mark = 1;
+
+		break;
+
+	case FRAME_TYPE_FORWARD:
+		skb->offload_fwd_mark = 1;
+		break;
+
+	default:
 		return NULL;
+	}
 
 	/*
 	 * Determine source device and port.
@@ -132,8 +160,6 @@  static struct sk_buff *dsa_rcv(struct sk_buff *skb, struct net_device *dev,
 			2 * ETH_ALEN);
 	}
 
-	skb->offload_fwd_mark = 1;
-
 	return skb;
 }