netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vladimir Oltean <vladimir.oltean@nxp.com>
To: netdev@vger.kernel.org, davem@davemloft.net
Cc: andrew@lunn.ch, f.fainelli@gmail.com, vivien.didelot@gmail.com,
	kuba@kernel.org
Subject: [PATCH v3 net-next 06/15] net: dsa: add a generic procedure for the flow dissector
Date: Sat, 26 Sep 2020 22:32:06 +0300	[thread overview]
Message-ID: <20200926193215.1405730-7-vladimir.oltean@nxp.com> (raw)
In-Reply-To: <20200926193215.1405730-1-vladimir.oltean@nxp.com>

For all DSA formats that don't use tail tags, it looks like behind the
obscure number crunching they're all doing the same thing: locating the
real EtherType behind the DSA tag. Nonetheless, this is not immediately
obvious, so create a generic helper for those DSA taggers that put the
header before the EtherType.

Another assumption for the generic function is that the DSA tags are of
equal length on RX and on TX. Prior to the previous patch, this was not
true for ocelot and for gswip. The problem was resolved for ocelot, but
for gswip it still remains, so that can't use this helper yet.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
Changes in v3:
Made this a static inline function callable from the outside world.

 include/net/dsa.h | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/include/net/dsa.h b/include/net/dsa.h
index 98d339311898..817fab5e2c21 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -711,6 +711,32 @@ static inline bool dsa_can_decode(const struct sk_buff *skb,
 	return false;
 }
 
+/* All DSA tags that push the EtherType to the right (basically all except tail
+ * tags, which don't break dissection) can be treated the same from the
+ * perspective of the flow dissector.
+ *
+ * We need to return:
+ *  - offset: the (B - A) difference between:
+ *    A. the position of the real EtherType and
+ *    B. the current skb->data (aka ETH_HLEN bytes into the frame, aka 2 bytes
+ *       after the normal EtherType was supposed to be)
+ *    The offset in bytes is exactly equal to the tagger overhead (and half of
+ *    that, in __be16 shorts).
+ *
+ *  - proto: the value of the real EtherType.
+ */
+static inline void dsa_tag_generic_flow_dissect(const struct sk_buff *skb,
+						__be16 *proto, int *offset)
+{
+#if IS_ENABLED(CONFIG_NET_DSA)
+	const struct dsa_device_ops *ops = skb->dev->dsa_ptr->tag_ops;
+	int tag_len = ops->overhead;
+
+	*offset = tag_len;
+	*proto = ((__be16 *)skb->data)[(tag_len / 2) - 1];
+#endif
+}
+
 #if IS_ENABLED(CONFIG_NET_DSA)
 static inline int __dsa_netdevice_ops_check(struct net_device *dev)
 {
-- 
2.25.1


  parent reply	other threads:[~2020-09-26 19:33 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-26 19:32 [PATCH v3 net-next 00/15] Generic adjustment for flow dissector in DSA Vladimir Oltean
2020-09-26 19:32 ` [PATCH v3 net-next 01/15] net: mscc: ocelot: move NPI port configuration to DSA Vladimir Oltean
2020-09-26 19:32 ` [PATCH v3 net-next 02/15] net: dsa: allow drivers to request promiscuous mode on master Vladimir Oltean
2020-09-26 20:22   ` Andrew Lunn
2020-09-26 19:32 ` [PATCH v3 net-next 03/15] net: dsa: tag_sja1105: request promiscuous mode for master Vladimir Oltean
2020-09-26 20:22   ` Andrew Lunn
2020-09-26 19:32 ` [PATCH v3 net-next 04/15] net: dsa: tag_ocelot: use a short prefix on both ingress and egress Vladimir Oltean
2020-09-26 19:32 ` [PATCH v3 net-next 05/15] net: dsa: make the .flow_dissect tagger callback return void Vladimir Oltean
2020-09-26 19:32 ` Vladimir Oltean [this message]
2020-09-26 20:25   ` [PATCH v3 net-next 06/15] net: dsa: add a generic procedure for the flow dissector Andrew Lunn
2020-09-26 20:33   ` Andrew Lunn
2020-09-26 20:49     ` Vladimir Oltean
2020-09-26 19:32 ` [PATCH v3 net-next 07/15] net: dsa: point out the tail taggers Vladimir Oltean
2020-09-26 20:27   ` Andrew Lunn
2020-09-26 19:32 ` [PATCH v3 net-next 08/15] net: flow_dissector: avoid indirect call to DSA .flow_dissect for generic case Vladimir Oltean
2020-09-26 19:32 ` [PATCH v3 net-next 09/15] net: dsa: tag_brcm: use generic flow dissector procedure Vladimir Oltean
2020-09-26 19:32 ` [PATCH v3 net-next 10/15] net: dsa: tag_dsa: use the " Vladimir Oltean
2020-09-26 21:08   ` Andrew Lunn
2020-09-26 19:32 ` [PATCH v3 net-next 11/15] net: dsa: tag_edsa: " Vladimir Oltean
2020-09-26 21:08   ` Andrew Lunn
2020-09-26 19:32 ` [PATCH v3 net-next 12/15] net: dsa: tag_mtk: " Vladimir Oltean
2020-09-26 19:32 ` [PATCH v3 net-next 13/15] net: dsa: tag_qca: " Vladimir Oltean
2020-09-26 19:32 ` [PATCH v3 net-next 14/15] net: dsa: tag_sja1105: use a custom " Vladimir Oltean
2020-09-26 19:32 ` [PATCH v3 net-next 15/15] net: dsa: tag_rtl4_a: use the generic " Vladimir Oltean
2020-09-30  8:36   ` Linus Walleij
2020-09-26 21:18 ` [PATCH v3 net-next 00/15] Generic adjustment for flow dissector in DSA David Miller

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=20200926193215.1405730-7-vladimir.oltean@nxp.com \
    --to=vladimir.oltean@nxp.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=vivien.didelot@gmail.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;
as well as URLs for NNTP newsgroup(s).