OSDN Git Service

net: dsa: add a generic procedure for the flow dissector
authorVladimir Oltean <vladimir.oltean@nxp.com>
Sat, 26 Sep 2020 19:32:06 +0000 (22:32 +0300)
committerDavid S. Miller <davem@davemloft.net>
Sat, 26 Sep 2020 21:17:59 +0000 (14:17 -0700)
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>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/dsa.h

index 98d3393..817fab5 100644 (file)
@@ -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)
 {