Skip to content

Commit

Permalink
net: dsa: add a generic procedure for the flow dissector
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Vladimir Oltean authored and David S. Miller committed Sep 26, 2020
1 parent 2e8cb1b commit 9790cf2
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions include/net/dsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 9790cf2

Please sign in to comment.