Skip to contentSkip to conversation

net: dsa: Implement flow dissection for tag_brcm.c

PATCH Applied Florian Fainelli 4 participants 4 messages Mar 22, 2020 – Mar 24, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: dsa: Implement flow dissection for tag_brcm.c

Provide a flow_dissect callback which returns the network offset and where to find the skb protocol, given the tags structure a common function works for both tagging formats that are supported.

---
 net/dsa/tag_brcm.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
net/dsa/tag_brcm.c +23 -0
index 9c3114179690..0d3f796d14a3 100644
@@ -142,6 +142,27 @@ static struct sk_buff *brcm_tag_rcv_ll(struct sk_buff *skb,
 
 	return skb;
 }
+
+static int brcm_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
+				 int *offset)
+{
+	/* We have been called on the DSA master network device after
+	 * eth_type_trans() which pulled the Ethernet header already.
+	 * Frames have one of these two layouts:
+	 * -----------------------------------
+	 * | MAC DA | MAC SA | 4b tag | Type | DSA_TAG_PROTO_BRCM
+	 * -----------------------------------
+	 * -----------------------------------
+	 * | 4b tag | MAC DA | MAC SA | Type | DSA_TAG_PROTO_BRCM_PREPEND
+	 * -----------------------------------
+	 * skb->data points 2 bytes before the actual Ethernet type field and
+	 * we have an offset of 4bytes between where skb->data and where the
+	 * payload starts.
+	 */
+	*offset = BRCM_TAG_LEN;
+	*proto = ((__be16 *)skb->data)[1];
+	return 0;
+}
 #endif
 
 #if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM)
@@ -177,6 +198,7 @@ static const struct dsa_device_ops brcm_netdev_ops = {
 	.xmit	= brcm_tag_xmit,
 	.rcv	= brcm_tag_rcv,
 	.overhead = BRCM_TAG_LEN,
+	.flow_dissect = brcm_tag_flow_dissect,
 };
 
 DSA_TAG_DRIVER(brcm_netdev_ops);
@@ -205,6 +227,7 @@ static const struct dsa_device_ops brcm_prepend_netdev_ops = {
 	.xmit	= brcm_tag_xmit_prepend,
 	.rcv	= brcm_tag_rcv_prepend,
 	.overhead = BRCM_TAG_LEN,
+	.flow_dissect = brcm_tag_flow_dissect,
 };
 
 DSA_TAG_DRIVER(brcm_prepend_netdev_ops);
Signature · 1 line
2.19.1
maintainer
#1 lore raw
Quoted 7 lines · Florian Fainelli

Provide a flow_dissect callback which returns the network offset and where to find the skb protocol, given the tags structure a common function works for both tagging formats that are supported.

---

Looks good to me.

Quoted 52 lines
 net/dsa/tag_brcm.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
net/dsa/tag_brcm.c +23 -1
index 9c3114179690..0d3f796d14a3 100644
@@ -142,6 +142,27 @@ static struct sk_buff *brcm_tag_rcv_ll(struct sk_buff *skb,
 
        return skb;
 }
+
+static int brcm_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
+                                int *offset)
+{
+       /* We have been called on the DSA master network device after
+        * eth_type_trans() which pulled the Ethernet header already.
+        * Frames have one of these two layouts:
+        * -----------------------------------
+        * | MAC DA | MAC SA | 4b tag | Type | DSA_TAG_PROTO_BRCM
+        * -----------------------------------
+        * -----------------------------------
+        * | 4b tag | MAC DA | MAC SA | Type | DSA_TAG_PROTO_BRCM_PREPEND
+        * -----------------------------------
+        * skb->data points 2 bytes before the actual Ethernet type field and
+        * we have an offset of 4bytes between where skb->data and where the
+        * payload starts.
+        */
+       *offset = BRCM_TAG_LEN;
+       *proto = ((__be16 *)skb->data)[1];
+       return 0;
+}
 #endif
 
 #if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM)
@@ -177,6 +198,7 @@ static const struct dsa_device_ops brcm_netdev_ops = {
        .xmit   = brcm_tag_xmit,
        .rcv    = brcm_tag_rcv,
        .overhead = BRCM_TAG_LEN,
+       .flow_dissect = brcm_tag_flow_dissect,
 };
 
 DSA_TAG_DRIVER(brcm_netdev_ops);
@@ -205,6 +227,7 @@ static const struct dsa_device_ops brcm_prepend_netdev_ops = {
        .xmit   = brcm_tag_xmit_prepend,
        .rcv    = brcm_tag_rcv_prepend,
        .overhead = BRCM_TAG_LEN,
+       .flow_dissect = brcm_tag_flow_dissect,
 };
 
 DSA_TAG_DRIVER(brcm_prepend_netdev_ops);
--
Quoted 2 lines

2.19.1

Regards,
-Vladimir