[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240821212212.1795357-11-tom@herbertland.com>
Date: Wed, 21 Aug 2024 14:22:09 -0700
From: Tom Herbert <tom@...bertland.com>
To: davem@...emloft.net,
kuba@...nel.org,
edumazet@...gle.com,
netdev@...r.kernel.org,
felipe@...anda.io,
willemdebruijn.kernel@...il.com,
pablo@...filter.org,
laforge@...monks.org,
xeb@...l.ru
Cc: Tom Herbert <tom@...bertland.com>
Subject: [PATCH net-next v3 10/13] flow_dissector: Parse GUE in UDP
Parse both version 0 and 1 of GUE encapsulated in UDP. Add helper
function __skb_direct_ip_dissect to convert an IP header to
IPPROTO_IPIP or IPPROTO_IPV6 (by looking just at the version
number)
Signed-off-by: Tom Herbert <tom@...bertland.com>
---
net/core/flow_dissector.c | 60 +++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
index 307d4bb20e99..0a8398068756 100644
--- a/net/core/flow_dissector.c
+++ b/net/core/flow_dissector.c
@@ -821,6 +821,61 @@ __skb_flow_dissect_geneve(const struct sk_buff *skb,
return FLOW_DISSECT_RET_PROTO_AGAIN;
}
+static __u8
+__skb_direct_ip_dissect(void *hdr)
+{
+ /* Direct encapsulation of IPv4 or IPv6 */
+
+ switch (((struct iphdr *)hdr)->version) {
+ case 4:
+ return IPPROTO_IPIP;
+ case 6:
+ return IPPROTO_IPV6;
+ default:
+ return 0;
+ }
+}
+
+static enum flow_dissect_ret
+__skb_flow_dissect_gue(const struct sk_buff *skb,
+ struct flow_dissector *flow_dissector,
+ void *target_container, const void *data,
+ __u8 *p_ip_proto, int *p_nhoff,
+ int hlen, unsigned int flags)
+{
+ struct guehdr *hdr, _hdr;
+ __u8 proto;
+
+ hdr = __skb_header_pointer(skb, *p_nhoff, sizeof(_hdr), data, hlen,
+ &_hdr);
+ if (!hdr)
+ return FLOW_DISSECT_RET_OUT_BAD;
+
+ switch (hdr->version) {
+ case 0:
+ if (unlikely(hdr->control))
+ return FLOW_DISSECT_RET_OUT_GOOD;
+
+ *p_nhoff += sizeof(struct guehdr) + (hdr->hlen << 2);
+ *p_ip_proto = hdr->proto_ctype;
+
+ break;
+ case 1:
+ /* Direct encapsulation of IPv4 or IPv6 */
+
+ proto = __skb_direct_ip_dissect(hdr);
+ if (proto) {
+ *p_ip_proto = proto;
+ break;
+ }
+ fallthrough;
+ default:
+ return FLOW_DISSECT_RET_OUT_GOOD;
+ }
+
+ return FLOW_DISSECT_RET_IPPROTO_AGAIN;
+}
+
/**
* __skb_flow_dissect_batadv() - dissect batman-adv header
* @skb: sk_buff to with the batman-adv header
@@ -1000,6 +1055,11 @@ __skb_flow_dissect_udp(const struct sk_buff *skb, const struct net *net,
*p_ip_proto = fou_protocol;
ret = FLOW_DISSECT_RET_IPPROTO_AGAIN;
break;
+ case UDP_ENCAP_GUE:
+ ret = __skb_flow_dissect_gue(skb, flow_dissector,
+ target_container, data,
+ p_ip_proto, p_nhoff, hlen, flags);
+ break;
case UDP_ENCAP_SCTP:
*p_ip_proto = IPPROTO_SCTP;
ret = FLOW_DISSECT_RET_IPPROTO_AGAIN;
--
2.34.1
Powered by blists - more mailing lists