From 71854255820d1a479654bd2e98483129c588c118 Mon Sep 17 00:00:00 2001 From: Eran Ben Elisha Date: Tue, 12 Jan 2021 21:07:12 +0200 Subject: [PATCH 1/2] net: vlan: Add parse protocol header ops Add parse protocol header ops for vlan device. Before this patch, vlan tagged packet transmitted by af_packet had skb->protocol unset. Some kernel methods (like __skb_flow_dissect()) rely on this missing information for its packet processing. Signed-off-by: Eran Ben Elisha Reviewed-by: Tariq Toukan Signed-off-by: Jakub Kicinski --- net/8021q/vlan_dev.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c index ec8408d1638f..dc1a197792e6 100644 --- a/net/8021q/vlan_dev.c +++ b/net/8021q/vlan_dev.c @@ -510,9 +510,17 @@ static void vlan_dev_set_lockdep_class(struct net_device *dev) netdev_for_each_tx_queue(dev, vlan_dev_set_lockdep_one, NULL); } +static __be16 vlan_parse_protocol(const struct sk_buff *skb) +{ + struct vlan_ethhdr *veth = (struct vlan_ethhdr *)(skb->data); + + return __vlan_get_protocol(skb, veth->h_vlan_proto, NULL); +} + static const struct header_ops vlan_header_ops = { .create = vlan_dev_hard_header, .parse = eth_header_parse, + .parse_protocol = vlan_parse_protocol, }; static int vlan_passthru_hard_header(struct sk_buff *skb, struct net_device *dev, @@ -532,6 +540,7 @@ static int vlan_passthru_hard_header(struct sk_buff *skb, struct net_device *dev static const struct header_ops vlan_passthru_header_ops = { .create = vlan_passthru_hard_header, .parse = eth_header_parse, + .parse_protocol = vlan_parse_protocol, }; static struct device_type vlan_type = { From 4f1cc51f34886d645cd3e8fc2915cc9b7a55c3b6 Mon Sep 17 00:00:00 2001 From: Eran Ben Elisha Date: Tue, 12 Jan 2021 21:07:13 +0200 Subject: [PATCH 2/2] net: flow_dissector: Parse PTP L2 packet header Add support for parsing PTP L2 packet header. Such packet consists of an L2 header (with ethertype of ETH_P_1588), PTP header, body and an optional suffix. Signed-off-by: Eran Ben Elisha Reviewed-by: Tariq Toukan Signed-off-by: Jakub Kicinski --- net/core/flow_dissector.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c index 6f1adba6695f..2d70ded389ae 100644 --- a/net/core/flow_dissector.c +++ b/net/core/flow_dissector.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -1251,6 +1252,21 @@ proto_again: &proto, &nhoff, hlen, flags); break; + case htons(ETH_P_1588): { + struct ptp_header *hdr, _hdr; + + hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data, + hlen, &_hdr); + if (!hdr) { + fdret = FLOW_DISSECT_RET_OUT_BAD; + break; + } + + nhoff += ntohs(hdr->message_length); + fdret = FLOW_DISSECT_RET_OUT_GOOD; + break; + } + default: fdret = FLOW_DISSECT_RET_OUT_BAD; break;