From patchwork Thu Aug 15 21:45:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Herbert X-Patchwork-Id: 13765218 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B66B14885C for ; Thu, 15 Aug 2024 21:46:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723758375; cv=none; b=qdTyKHkcypO7nA2gZM/BIHAcQrHaTE3IJa9PvoOaSuSpPduNhcepLjQLRKnIMny+2AkIC0lf/sGG9QlPzqeSl0G/VttRcqnT4IKe61wm1x8HbZrR0vZaIrj0wfSrs2S1h311NzSYNrPdw0ZWi1rbp5KU1uXlV0QjHOXDD/gCkZU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723758375; c=relaxed/simple; bh=pMxSFLHW8OQQ9MzLo9nOIyQKK3+TRUxatAegI+kLcMw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LOIHg9j37OJ1x6R/IMW7dZ1WOhhc7oRaBvUkFT3EppW5cjwUViMxxAc8Y2CLVuR0lYKwa+KlwMwaqM6xUKIvXpuhTaN64Hf0hGiF2q3vHINsg7eTeVoNeHOUoIKD1sZKeLLCB9WNjOofzuBDtBaW+EBXX0UMenHLstZAhx7RuBI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=herbertland.com; spf=pass smtp.mailfrom=herbertland.com; dkim=pass (2048-bit key) header.d=herbertland.com header.i=@herbertland.com header.b=GsFg44uR; arc=none smtp.client-ip=209.85.216.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=herbertland.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=herbertland.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=herbertland.com header.i=@herbertland.com header.b="GsFg44uR" Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-2d1ecfe88d7so1057249a91.3 for ; Thu, 15 Aug 2024 14:46:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=herbertland.com; s=google; t=1723758374; x=1724363174; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bhsTJBR9FLQP0AcbJ+2oEI3J4Md6+zJ2qyQOiOouhL0=; b=GsFg44uR7VeRF3tHa0TXvuNe1C+9tWpH8KQgkQGSxHkFLy0Q8mj3fdkuYC0umC/fTA TuYmQlm5Wd0bZRxZua81cGJOLnbOF9BtTiJy7Ik9qwosFY/JAPTsl/1NIdJWyrroNFUk 7zrBdKQMllUlQpY3q2RHbn3z5x4LKD3e+MrYUynSvL+FVE8DH3y3IIvq4NvYCxN4wPRX WI5zLpaTJhKke5iMnMEHqZWHe4XiUfbC8+Md1icbgfjS1G/0dwW2PbayHWe/JC94H75o p66EGHsT8tuK9Rx1RqkrpI2DYFBxcCxjdrBS4DBhKLFFBBtU4qJXcg7BeOAzG9WmutYg t2YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723758374; x=1724363174; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bhsTJBR9FLQP0AcbJ+2oEI3J4Md6+zJ2qyQOiOouhL0=; b=m37JAUVNDoEz5CKplbdoKphtdgeouAfYdjSbYYOhlWsZZBjeiC2K4nm744gqB6yn3+ JrGylsQ4aTp1oMummFsNnHJ/ZGLGhW7s7gS9XdlqfrEJIXDN2HifGbSuHEEMwBASm87J FcsrmcN234zBcYEg3SV0EbjyGY/lCbvykJyi72UwAjhE6fOvuVZ/SeMdjJTW0Tm44aye tcGFsDsl2Q2ItY1q0kYDDRVMbzp8iaZCg5lWbHKlVuWZjSXBxD6URZBNEJWGlpUv7Lmx PlmFJC4iUBK3ZD7uOFFlFvfcT14PFTy3EX60jfrEX1Zwqq6eIWUxn/W3//WOzchzRPoA Q2MQ== X-Forwarded-Encrypted: i=1; AJvYcCVpm0/rcap4D8Gi5v34ctb11v6scJGPcBCJRJpqnsWB1em/9OD+JgMUibY69E5dEPHHrW2gIVRr02iyJmnkqqB9WJqKyhPt X-Gm-Message-State: AOJu0YwkynSeCWmvHqBur6Tv9e043qa4gJ+HBqaTmSs8f+hunEBKfSsd GmXWOtXbU0eP011WzmXWBP/aYhBzQPUyfVIJN9Mqs4YOTp8zk1qZNEMixCw1ZQ== X-Google-Smtp-Source: AGHT+IHVk6B7DKjFnjD+eeR8kPpbfJTfgmjA1RYXRjNxMDhE0aWTPtZDO6q7zSqtzun6tIMYz58tLQ== X-Received: by 2002:a17:90b:234f:b0:2c9:649c:5e10 with SMTP id 98e67ed59e1d1-2d3dfc48a3bmr1266936a91.10.1723758373425; Thu, 15 Aug 2024 14:46:13 -0700 (PDT) Received: from TomsPC.home ([2601:646:8300:55f0:99b4:e046:411:1b72]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d3e2c652ffsm303288a91.10.2024.08.15.14.46.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2024 14:46:13 -0700 (PDT) From: Tom Herbert To: davem@davemloft.net, kuba@kernel.org, edumazet@google.com, netdev@vger.kernel.org, felipe@sipanda.io, willemdebruijn.kernel@gmail.com Cc: Tom Herbert Subject: [PATCH net-next v2 01/12] flow_dissector: Parse ETH_P_TEB and move out of GRE Date: Thu, 15 Aug 2024 14:45:16 -0700 Message-Id: <20240815214527.2100137-2-tom@herbertland.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240815214527.2100137-1-tom@herbertland.com> References: <20240815214527.2100137-1-tom@herbertland.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org ETH_P_TEB (Trans Ether Bridging) is the EtherType to carry a plain Etherent frame. Add case in skb_flow_dissect to parse packets of this type If the GRE protocol is ETH_P_TEB then just process that as any another EtherType since it's now supported in the main loop Signed-off-by: Tom Herbert Reviewed-by: Willem de Bruijn --- net/core/flow_dissector.c | 57 +++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c index 0e638a37aa09..4b116119086a 100644 --- a/net/core/flow_dissector.c +++ b/net/core/flow_dissector.c @@ -654,7 +654,7 @@ __skb_flow_dissect_gre(const struct sk_buff *skb, struct flow_dissector_key_control *key_control, struct flow_dissector *flow_dissector, void *target_container, const void *data, - __be16 *p_proto, int *p_nhoff, int *p_hlen, + __be16 *p_proto, int *p_nhoff, int hlen, unsigned int flags) { struct flow_dissector_key_keyid *key_keyid; @@ -663,7 +663,7 @@ __skb_flow_dissect_gre(const struct sk_buff *skb, u16 gre_ver; hdr = __skb_header_pointer(skb, *p_nhoff, sizeof(_hdr), - data, *p_hlen, &_hdr); + data, hlen, &_hdr); if (!hdr) return FLOW_DISSECT_RET_OUT_BAD; @@ -695,7 +695,7 @@ __skb_flow_dissect_gre(const struct sk_buff *skb, keyid = __skb_header_pointer(skb, *p_nhoff + offset, sizeof(_keyid), - data, *p_hlen, &_keyid); + data, hlen, &_keyid); if (!keyid) return FLOW_DISSECT_RET_OUT_BAD; @@ -715,27 +715,11 @@ __skb_flow_dissect_gre(const struct sk_buff *skb, if (hdr->flags & GRE_SEQ) offset += sizeof_field(struct pptp_gre_header, seq); - if (gre_ver == 0) { - if (*p_proto == htons(ETH_P_TEB)) { - const struct ethhdr *eth; - struct ethhdr _eth; - - eth = __skb_header_pointer(skb, *p_nhoff + offset, - sizeof(_eth), - data, *p_hlen, &_eth); - if (!eth) - return FLOW_DISSECT_RET_OUT_BAD; - *p_proto = eth->h_proto; - offset += sizeof(*eth); - - /* Cap headers that we access via pointers at the - * end of the Ethernet header as our maximum alignment - * at that point is only 2 bytes. - */ - if (NET_IP_ALIGN) - *p_hlen = *p_nhoff + offset; - } - } else { /* version 1, must be PPTP */ + /* For GRE version 0 p_proto is already correctly set (including if + * it is ETH_P_TEB) + */ + + if (gre_ver == 1) { /* Version 1 is PPP */ u8 _ppp_hdr[PPP_HDRLEN]; u8 *ppp_hdr; @@ -744,7 +728,7 @@ __skb_flow_dissect_gre(const struct sk_buff *skb, ppp_hdr = __skb_header_pointer(skb, *p_nhoff + offset, sizeof(_ppp_hdr), - data, *p_hlen, _ppp_hdr); + data, hlen, _ppp_hdr); if (!ppp_hdr) return FLOW_DISSECT_RET_OUT_BAD; @@ -1284,6 +1268,27 @@ bool __skb_flow_dissect(const struct net *net, break; } + case htons(ETH_P_TEB): { + const struct ethhdr *eth; + struct ethhdr _eth; + + eth = __skb_header_pointer(skb, nhoff, sizeof(_eth), + data, hlen, &_eth); + if (!eth) + goto out_bad; + + proto = eth->h_proto; + nhoff += sizeof(*eth); + + /* Cap headers that we access via pointers at the + * end of the Ethernet header as our maximum alignment + * at that point is only 2 bytes. + */ + if (NET_IP_ALIGN) + hlen = nhoff; + + goto proto_again; + } case htons(ETH_P_8021AD): case htons(ETH_P_8021Q): { const struct vlan_hdr *vlan = NULL; @@ -1531,7 +1536,7 @@ bool __skb_flow_dissect(const struct net *net, fdret = __skb_flow_dissect_gre(skb, key_control, flow_dissector, target_container, data, - &proto, &nhoff, &hlen, flags); + &proto, &nhoff, hlen, flags); break; case NEXTHDR_HOP: From patchwork Thu Aug 15 21:45:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Herbert X-Patchwork-Id: 13765219 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0C3315381A for ; Thu, 15 Aug 2024 21:46:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723758377; cv=none; b=Vh5QQV1lw0La1jnm4QZsVvLRGeIjQqv4TkudhMpB2YCMiLTUhe2P2bx3Zp0Jnb+j5QQWqG/i3kwd/a93lXkw9DM9LpneXfRrUrDHhUv2YbwOMvWQ4InkKFyu65MQsIEQJ95lSLR7DmxiK5v/xzFxTdVYSZ/dUOcwtj993MqFZOU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723758377; c=relaxed/simple; bh=UBnlbylDQiGGFqb824hJ8LOfBeF2it/cgHiViI1JVBU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KWp9DYvko/3i29euAo5mFWb8rOFXhz8qFFP98lX0HgfYFBlTUDXmngX4+Cpwe2fegrx3r8zszZL/rNGnodmZP5rLcpsnzGvCv3DF5OKHZyPN/IhR/JU3oMaD13LcFaZInIdG5aXeNTFTqjFGDX1rnhkoPc76BGJmlxtm5l3kDPo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=herbertland.com; spf=pass smtp.mailfrom=herbertland.com; dkim=pass (2048-bit key) header.d=herbertland.com header.i=@herbertland.com header.b=RTANqz+8; arc=none smtp.client-ip=209.85.216.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=herbertland.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=herbertland.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=herbertland.com header.i=@herbertland.com header.b="RTANqz+8" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-2d3d662631aso566504a91.1 for ; Thu, 15 Aug 2024 14:46:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=herbertland.com; s=google; t=1723758375; x=1724363175; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8f2VEr48rqS/xVUGYX/zdpL28CXVAGtsS1olIt5KoRY=; b=RTANqz+8mSqAebiXiE57zKg/4jxXcdRtzkeLGiHzrye8VN1LiauEsp9kWaFoAM08ER UwRQrURLrkqpxg38ViBhKkheFUsF4cND1vz4GqUhJ3CMr43bPflumPIo5YR8CMDCxnHa +YEdthpqMI2V4B7zs5uQ4FImaUTc2/NA9M0YwDlGNtRgI5u0KLmo+y1TgsX3SNKwB3zS 0+uGduep0U6OBkc6XrVUfDIhTbLiFR4+IeESRO0w994FijiL4WMoFRoXOV33ppnGFwwM jj95yG8avDHHrGBFQf2OMZvQUeC8GZjh4g/lWEiGkLPz9Uvskmtg7SREeN3uIdJpnRMB YEig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723758375; x=1724363175; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8f2VEr48rqS/xVUGYX/zdpL28CXVAGtsS1olIt5KoRY=; b=ZGWr1nniOZFdawAgVpmEZxIDXBYjZfLLmdZLR1oxjBLinE7cTZ+tUkj12aNeXE/Us6 N3PllBsk+u5b4MbJ7bQ/qKSa5/stT00CElJgdHKVy5sgpEyqO2vDDF8B4gVEAaHnPXhh SodX7H4MSpbuyVEO3HyfVlPH+AdgPlLfqweiE+9XMVU87ok5A3Mo1IqBaejTEc2jhLd9 3y372rsPjlcmEv1wl94GSqPgGfuhvg9REfjvK8V5NsiqVESrSBUFwgVD6RHPQyD+z+/r yohrxzoADiJcUJVtv+S42+McR4U43H0jLYE4rBhyeFabrJVpDYGg6XQ7XuHusdDMElXA xPhQ== X-Forwarded-Encrypted: i=1; AJvYcCW+8XgjBP8nMwMldeAvVVyd0X53rGEfiTCbMiRrnoAJoOpeojz26tbjaoHvREpnkJst7nH/sAux1k/aZoz5u7NK37oI6nba X-Gm-Message-State: AOJu0Yx8jSxvSuQ10jrMIG8InuRm4Ji0BqU0ExB2EjqjOy/SCuSwq7yq 09mFslxPBrsjIPdEXgx4OMu3F0+i1JvVv/rmihI9zOBQph89dvuxkuj/O1ZWkA== X-Google-Smtp-Source: AGHT+IH38zZyVOwq3xvlSO8GAw6H4f9Q7vdPuONKGe+qQAIILL+/EILHrLuKfnyzg+isGH+UU+2Hlg== X-Received: by 2002:a17:90a:6d89:b0:2cb:e429:f525 with SMTP id 98e67ed59e1d1-2d3e055f018mr1088797a91.33.1723758374702; Thu, 15 Aug 2024 14:46:14 -0700 (PDT) Received: from TomsPC.home ([2601:646:8300:55f0:99b4:e046:411:1b72]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d3e2c652ffsm303288a91.10.2024.08.15.14.46.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2024 14:46:14 -0700 (PDT) From: Tom Herbert To: davem@davemloft.net, kuba@kernel.org, edumazet@google.com, netdev@vger.kernel.org, felipe@sipanda.io, willemdebruijn.kernel@gmail.com Cc: Tom Herbert Subject: [PATCH net-next v2 02/12] udp_encaps: Add new UDP_ENCAP constants Date: Thu, 15 Aug 2024 14:45:17 -0700 Message-Id: <20240815214527.2100137-3-tom@herbertland.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240815214527.2100137-1-tom@herbertland.com> References: <20240815214527.2100137-1-tom@herbertland.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Add constants for various UDP encapsulations that are supported Signed-off-by: Tom Herbert Reviewed-by: Willem de Bruijn --- include/uapi/linux/udp.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/uapi/linux/udp.h b/include/uapi/linux/udp.h index 1a0fe8b151fb..0432a9a6536d 100644 --- a/include/uapi/linux/udp.h +++ b/include/uapi/linux/udp.h @@ -36,6 +36,7 @@ struct udphdr { #define UDP_GRO 104 /* This socket can receive UDP GRO packets */ /* UDP encapsulation types */ +#define UDP_ENCAP_NONE 0 #define UDP_ENCAP_ESPINUDP_NON_IKE 1 /* unused draft-ietf-ipsec-nat-t-ike-00/01 */ #define UDP_ENCAP_ESPINUDP 2 /* draft-ietf-ipsec-udp-encaps-06 */ #define UDP_ENCAP_L2TPINUDP 3 /* rfc2661 */ @@ -43,5 +44,17 @@ struct udphdr { #define UDP_ENCAP_GTP1U 5 /* 3GPP TS 29.060 */ #define UDP_ENCAP_RXRPC 6 #define TCP_ENCAP_ESPINTCP 7 /* Yikes, this is really xfrm encap types. */ +#define UDP_ENCAP_TIPC 8 +#define UDP_ENCAP_FOU 9 +#define UDP_ENCAP_GUE 10 +#define UDP_ENCAP_SCTP 11 +#define UDP_ENCAP_RXE 12 +#define UDP_ENCAP_PFCP 13 +#define UDP_ENCAP_WIREGUARD 14 +#define UDP_ENCAP_BAREUDP 15 +#define UDP_ENCAP_VXLAN 16 +#define UDP_ENCAP_VXLAN_GPE 17 +#define UDP_ENCAP_GENEVE 18 +#define UDP_ENCAP_AMT 19 #endif /* _UAPI_LINUX_UDP_H */ From patchwork Thu Aug 15 21:45:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Herbert X-Patchwork-Id: 13765220 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4DE7914885C for ; Thu, 15 Aug 2024 21:46:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723758378; cv=none; b=SNpKmlMZmrgkPmhCkHibO9jsrXV5pl8E0eH2j93UuNQbWPeFuWXfLQYJZ+7XSnkT45xfETUT8oByRAHO6Hp1oJzIjFryDtP4p2ezU8B8cdHQ8LtkAU/mr60I8HDnTw5YunEAIAa4vQTJKETpYDgz00+NQ5+poTQye9Y0Ti5nZU8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723758378; c=relaxed/simple; bh=nYu8yZ/VN1Dg7+BXBxyOnOybgHomc2LXxWLVKv9ctjk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SZNFJHMJJbvMTT1ZSUlQiFGmxkuKWtaXYj8/jOASpJnKaSD9r+Z+eie8dSHZbh82icgdWfX8sXxeUPi1r45O72Y+kbrzqYaWB2LF3nE1pYUFgTfHWY7Wh1yHHuA1p3+wZMu3OR031PpvfRUNUWmGsFwHCcAgcJm10q+ieBREcHw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=herbertland.com; spf=pass smtp.mailfrom=herbertland.com; dkim=pass (2048-bit key) header.d=herbertland.com header.i=@herbertland.com header.b=c3lLawlE; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=herbertland.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=herbertland.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=herbertland.com header.i=@herbertland.com header.b="c3lLawlE" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1fc587361b6so14039055ad.2 for ; Thu, 15 Aug 2024 14:46:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=herbertland.com; s=google; t=1723758377; x=1724363177; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=e1sb8cWs53jZLxOrCKQjc0PrlsqOnPbedcs+Sjt1xik=; b=c3lLawlEnX+EEDRxNo58ISkHBQQM+7O2thFwlclc60iVh/2X92DbBbe6FcPoMv2lXT hEozUVZFBe0Dn13utzXBuPs+//UzuKAXl5376MG7exQk7pU6Gm/lRCUg+JzlrziXV7y0 CSh/ad/sn2m4mfkFKwBnjPkDp+uI2VX2t58f3cEwFP2JLNuNNZQTFSjG9YP70wWi3kNR hFmEYPQA/7aqIMtdqLYmCWKobx7GjeTmEFSXY31/kwI6UopRYdmCegV6MwYFpy9x5mFb Jh7xAUMjyW6sZoOPgd/7fT6L8lK8Zrf/wQgMYzw22/kNnoPlzDN6jhuGyJrx/QLQ73DR cWjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723758377; x=1724363177; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=e1sb8cWs53jZLxOrCKQjc0PrlsqOnPbedcs+Sjt1xik=; b=GOrQf7DnPRiMCn6SLYgovG5WnZhqKTWnps8EdSS5Ye3nzSFmW187TquEvC89RZs92H paroMhaD5vSSdbedcsYrcxqIO+aYuovijgrR81VAehrRXrSjxqxaBsSmu6SP0mfoJRRp UV++tZTqP6m5yxUpuJnsZ3PUFZKyIx79IrPjtthGarWt/w56foiQxJvu68yZmVF7DBpH HUuKSbD5FALMTDu37degfR4JPez+Z2N9b0YL0W1fjU3L73FeyQ6gJqxwaK+ExlEC3qxN vie8qYjGxXzt5DTF4nq+cIGJpa5k7ne3XIK2PEC4ugIF8+5FjRFyqb7GQWbmkM2BvR0L P4bA== X-Forwarded-Encrypted: i=1; AJvYcCWpBIKecl1v70lo2fdY6NDnCeb6AUuKEhbSYIlKR7tvAyFbQ9AURbjAacZMtopD2fqgRWFSbrs7Ka7za8/4U+1FbUQGxCEu X-Gm-Message-State: AOJu0YxhwPvCqtlncTzg6PsatEOAunDbW0jgYtIVra+JzHL5vLDqWT4O z0r0V7gPa2G6B65MXnb6O8iujM6uI2SgzqAmg31bJIQqc2OXbb452BmVAZzsSw== X-Google-Smtp-Source: AGHT+IEM5SdRRa598+GChnK2n9oQgquKZjibx3jqsy3lY3xgqIpDIen3vrWOragr5tTZOiLqI0AQaw== X-Received: by 2002:a17:90a:de8f:b0:2d3:d654:54f5 with SMTP id 98e67ed59e1d1-2d3dfc378bdmr1215638a91.3.1723758376391; Thu, 15 Aug 2024 14:46:16 -0700 (PDT) Received: from TomsPC.home ([2601:646:8300:55f0:99b4:e046:411:1b72]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d3e2c652ffsm303288a91.10.2024.08.15.14.46.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2024 14:46:15 -0700 (PDT) From: Tom Herbert To: davem@davemloft.net, kuba@kernel.org, edumazet@google.com, netdev@vger.kernel.org, felipe@sipanda.io, willemdebruijn.kernel@gmail.com Cc: Tom Herbert , Willem de Bruijn Subject: [PATCH net-next v2 03/12] udp_encaps: Set proper UDP_ENCAP types in tunnel setup Date: Thu, 15 Aug 2024 14:45:18 -0700 Message-Id: <20240815214527.2100137-4-tom@herbertland.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240815214527.2100137-1-tom@herbertland.com> References: <20240815214527.2100137-1-tom@herbertland.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Instead of just setting UDP tunnel config encap_type to 1, use the appropriate constat for the tunnel type. This value can be used to determine the encapsulated protocol in UDP by looking at the socket Reviewed-by: Willem de Bruijn Signed-off-by: Tom Herbert --- drivers/infiniband/sw/rxe/rxe_net.c | 2 +- drivers/net/amt.c | 2 +- drivers/net/bareudp.c | 2 +- drivers/net/geneve.c | 2 +- drivers/net/pfcp.c | 2 +- drivers/net/vxlan/vxlan_core.c | 3 ++- drivers/net/wireguard/socket.c | 2 +- net/ipv4/fou_core.c | 3 ++- net/sctp/protocol.c | 2 +- net/tipc/udp_media.c | 2 +- 10 files changed, 12 insertions(+), 10 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_net.c b/drivers/infiniband/sw/rxe/rxe_net.c index 75d1407db52d..1c2bb88132c5 100644 --- a/drivers/infiniband/sw/rxe/rxe_net.c +++ b/drivers/infiniband/sw/rxe/rxe_net.c @@ -193,7 +193,7 @@ static struct socket *rxe_setup_udp_tunnel(struct net *net, __be16 port, if (err < 0) return ERR_PTR(err); - tnl_cfg.encap_type = 1; + tnl_cfg.encap_type = UDP_ENCAP_RXE; tnl_cfg.encap_rcv = rxe_udp_encap_recv; /* Setup UDP tunnel */ diff --git a/drivers/net/amt.c b/drivers/net/amt.c index 6d15ab3bfbbc..fc421cf2c032 100644 --- a/drivers/net/amt.c +++ b/drivers/net/amt.c @@ -2970,7 +2970,7 @@ static int amt_socket_create(struct amt_dev *amt) /* Mark socket as an encapsulation socket */ memset(&tunnel_cfg, 0, sizeof(tunnel_cfg)); tunnel_cfg.sk_user_data = amt; - tunnel_cfg.encap_type = 1; + tunnel_cfg.encap_type = UDP_ENCAP_AMT; tunnel_cfg.encap_rcv = amt_rcv; tunnel_cfg.encap_err_lookup = amt_err_lookup; tunnel_cfg.encap_destroy = NULL; diff --git a/drivers/net/bareudp.c b/drivers/net/bareudp.c index d5c56ca91b77..007fb8c5168b 100644 --- a/drivers/net/bareudp.c +++ b/drivers/net/bareudp.c @@ -248,7 +248,7 @@ static int bareudp_socket_create(struct bareudp_dev *bareudp, __be16 port) /* Mark socket as an encapsulation socket */ memset(&tunnel_cfg, 0, sizeof(tunnel_cfg)); tunnel_cfg.sk_user_data = bareudp; - tunnel_cfg.encap_type = 1; + tunnel_cfg.encap_type = UDP_ENCAP_BAREUDP; tunnel_cfg.encap_rcv = bareudp_udp_encap_recv; tunnel_cfg.encap_err_lookup = bareudp_err_lookup; tunnel_cfg.encap_destroy = NULL; diff --git a/drivers/net/geneve.c b/drivers/net/geneve.c index 838e85ddec67..923c573b6e5c 100644 --- a/drivers/net/geneve.c +++ b/drivers/net/geneve.c @@ -611,7 +611,7 @@ static struct geneve_sock *geneve_socket_create(struct net *net, __be16 port, /* Mark socket as an encapsulation socket */ memset(&tunnel_cfg, 0, sizeof(tunnel_cfg)); tunnel_cfg.sk_user_data = gs; - tunnel_cfg.encap_type = 1; + tunnel_cfg.encap_type = UDP_ENCAP_GENEVE; tunnel_cfg.gro_receive = geneve_gro_receive; tunnel_cfg.gro_complete = geneve_gro_complete; tunnel_cfg.encap_rcv = geneve_udp_encap_recv; diff --git a/drivers/net/pfcp.c b/drivers/net/pfcp.c index 69434fd13f96..c7e4fa606b16 100644 --- a/drivers/net/pfcp.c +++ b/drivers/net/pfcp.c @@ -170,7 +170,7 @@ static struct socket *pfcp_create_sock(struct pfcp_dev *pfcp) tuncfg.sk_user_data = pfcp; tuncfg.encap_rcv = pfcp_encap_recv; - tuncfg.encap_type = 1; + tuncfg.encap_type = UDP_ENCAP_PFCP; setup_udp_tunnel_sock(net, sock, &tuncfg); diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index 8983e75e9881..e02cbc018b8c 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -3572,7 +3572,8 @@ static struct vxlan_sock *vxlan_socket_create(struct net *net, bool ipv6, /* Mark socket as an encapsulation socket. */ memset(&tunnel_cfg, 0, sizeof(tunnel_cfg)); tunnel_cfg.sk_user_data = vs; - tunnel_cfg.encap_type = 1; + tunnel_cfg.encap_type = vs->flags & VXLAN_F_GPE ? + UDP_ENCAP_VXLAN_GPE : UDP_ENCAP_VXLAN; tunnel_cfg.encap_rcv = vxlan_rcv; tunnel_cfg.encap_err_lookup = vxlan_err_lookup; tunnel_cfg.encap_destroy = NULL; diff --git a/drivers/net/wireguard/socket.c b/drivers/net/wireguard/socket.c index 0414d7a6ce74..f4b5bd14fd56 100644 --- a/drivers/net/wireguard/socket.c +++ b/drivers/net/wireguard/socket.c @@ -352,7 +352,7 @@ int wg_socket_init(struct wg_device *wg, u16 port) int ret; struct udp_tunnel_sock_cfg cfg = { .sk_user_data = wg, - .encap_type = 1, + .encap_type = UDP_ENCAP_WIREGUARD, .encap_rcv = wg_receive }; struct socket *new4 = NULL, *new6 = NULL; diff --git a/net/ipv4/fou_core.c b/net/ipv4/fou_core.c index 0abbc413e0fe..8241f762e45b 100644 --- a/net/ipv4/fou_core.c +++ b/net/ipv4/fou_core.c @@ -578,19 +578,20 @@ static int fou_create(struct net *net, struct fou_cfg *cfg, fou->sock = sock; memset(&tunnel_cfg, 0, sizeof(tunnel_cfg)); - tunnel_cfg.encap_type = 1; tunnel_cfg.sk_user_data = fou; tunnel_cfg.encap_destroy = NULL; /* Initial for fou type */ switch (cfg->type) { case FOU_ENCAP_DIRECT: + tunnel_cfg.encap_type = UDP_ENCAP_FOU; tunnel_cfg.encap_rcv = fou_udp_recv; tunnel_cfg.gro_receive = fou_gro_receive; tunnel_cfg.gro_complete = fou_gro_complete; fou->protocol = cfg->protocol; break; case FOU_ENCAP_GUE: + tunnel_cfg.encap_type = UDP_ENCAP_GUE; tunnel_cfg.encap_rcv = gue_udp_recv; tunnel_cfg.gro_receive = gue_gro_receive; tunnel_cfg.gro_complete = gue_gro_complete; diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c index 5a7436a13b74..290ebcf17a48 100644 --- a/net/sctp/protocol.c +++ b/net/sctp/protocol.c @@ -876,7 +876,7 @@ int sctp_udp_sock_start(struct net *net) return err; } - tuncfg.encap_type = 1; + tuncfg.encap_type = UDP_ENCAP_SCTP; tuncfg.encap_rcv = sctp_udp_rcv; tuncfg.encap_err_lookup = sctp_udp_v4_err; setup_udp_tunnel_sock(net, sock, &tuncfg); diff --git a/net/tipc/udp_media.c b/net/tipc/udp_media.c index 439f75539977..3c081b7b9d67 100644 --- a/net/tipc/udp_media.c +++ b/net/tipc/udp_media.c @@ -771,7 +771,7 @@ static int tipc_udp_enable(struct net *net, struct tipc_bearer *b, if (err) goto err; tuncfg.sk_user_data = ub; - tuncfg.encap_type = 1; + tuncfg.encap_type = UDP_ENCAP_TIPC; tuncfg.encap_rcv = tipc_udp_recv; tuncfg.encap_destroy = NULL; setup_udp_tunnel_sock(net, ub->ubsock, &tuncfg); From patchwork Thu Aug 15 21:45:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Herbert X-Patchwork-Id: 13765221 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA54B15381A for ; Thu, 15 Aug 2024 21:46:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723758380; cv=none; b=g9XqjOUuSHvX9XeOKbDh2mEdPPX95i4EgRXLevjRMwzGeCu/vtBjskM5119j9U54woWqbu9PMx3RYVDb/4ajnOYbn4wB59X5hblV5J//Eo/SiqzktSAgX1OafzMiCyhgT5+ve5AMp1IHeJna5EAissKruiudXo1/uJD+z7r8h+g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723758380; c=relaxed/simple; bh=IE8vtXqONENH4COQ0PuVZvYVtcuAddeFlS3FJx3SoOQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LosLCelArB0+o1L+HwT2ahlXHxTCEaMtkAVeqA7oMIuXab7Iwm9LbTU/C2nMIRRCg50IIzGoBRKzHaUdgIGZFP6MmPspQ3DxeAHas+1uf//8uz88HnVZn8U4kIEnlvSxSFs3URnmTjCDrsirEwCnqsFGpNLy/Anbh6oC1oAA0N8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=herbertland.com; spf=pass smtp.mailfrom=herbertland.com; dkim=pass (2048-bit key) header.d=herbertland.com header.i=@herbertland.com header.b=NL3kCpUp; arc=none smtp.client-ip=209.85.216.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=herbertland.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=herbertland.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=herbertland.com header.i=@herbertland.com header.b="NL3kCpUp" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-2d3c071d276so1020441a91.1 for ; Thu, 15 Aug 2024 14:46:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=herbertland.com; s=google; t=1723758378; x=1724363178; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LLZrJlXskda2l3oFJRKH6Sq0IZmFsCGWA7iCElqA/4c=; b=NL3kCpUpvUmSPhc38ShnmkpVd6jnU/qlTh5VBbDiIYt3Ygip8x4bi0CtuBYFe0VYY/ D1/tdE5ss4kfJqaBS64psP1R690PZq9J9kbt476vtW8ET3EtDpuOl4eFIq9/xatMcmWE K/NUPu1nEFOyaK7I9DfX4qvtFk5qtt0y89aDnd8PUugxJnz85Q+ruWJBZoglS3SYXFGG /3kGBZI8fJ71QKcSNOu5wGdB0ORncISA9EzsXcykf9wcyGXnJTwLAtOk6E4EpfvyYQGG nyVR9BXoXCLEvx/ND38QqeNnOpzM8PO+ANwhzsE7lG8m2FPfG8zoOpSRsTE4KMFWCD2J 0sMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723758378; x=1724363178; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LLZrJlXskda2l3oFJRKH6Sq0IZmFsCGWA7iCElqA/4c=; b=OwPFFaGi6KK9diKqKhFK6Uw/VCrhSECRjrWnbtv9CVz0jzJYMysaKi5j0nH74KilJq 6DY0Tzq44n8ydCzcZRluLfnBBWCkans/R3iWS9I1xZiRYlhz8P9viO7htl6WiH1eGgNO l/1sUuxtQ3EHn6TIvUjPAh6NrXJ6m6puYbvtm5x1tZ206MkLKtmxRRhkAt8N6iy4Dpu1 kMUEzJhyRb4I8sc02r0cRqMd2qHbNNTEZOUUCvF+7IU13NK+ImnNEdJ3S5J6rBGiFB4z rM1fJSaRPeWX3OxPqMCxHIVRvmDFoXyta6xKKv6XxsuAP9OOsxyi1+kcjRQwrM+Ysk+x oqcw== X-Forwarded-Encrypted: i=1; AJvYcCVYKSYP0Xr0dRyh7MfHKO7fNFcbV2IrYt02yMvdzTCE/J5i7/qJpcAbqHNRUREoXdY/77+4TpMb7AIuBg+8JgXgPqF+IMoB X-Gm-Message-State: AOJu0Yzd0MAODT0Xw6bo56J4TrVYRscCnRh/J9BOF+BKWv3UCp1c1chY MkPXEjwxiHxeBZTFnB8lq1AivKFloTTCdx0NxEnentg3wl0IOOEGB5t/QJOO+g== X-Google-Smtp-Source: AGHT+IFfZHPay4UM2Zgjj7fMaG+8wE7bnXu8gpOS1I2C23NeY2lN/sp8+hFaqIJysCficanria9aag== X-Received: by 2002:a17:90a:d50a:b0:2c9:69cc:3a6f with SMTP id 98e67ed59e1d1-2d3e00ebf73mr1116758a91.31.1723758377765; Thu, 15 Aug 2024 14:46:17 -0700 (PDT) Received: from TomsPC.home ([2601:646:8300:55f0:99b4:e046:411:1b72]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d3e2c652ffsm303288a91.10.2024.08.15.14.46.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2024 14:46:17 -0700 (PDT) From: Tom Herbert To: davem@davemloft.net, kuba@kernel.org, edumazet@google.com, netdev@vger.kernel.org, felipe@sipanda.io, willemdebruijn.kernel@gmail.com Cc: Tom Herbert Subject: [PATCH net-next v2 04/12] flow_dissector: UDP encap infrastructure Date: Thu, 15 Aug 2024 14:45:19 -0700 Message-Id: <20240815214527.2100137-5-tom@herbertland.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240815214527.2100137-1-tom@herbertland.com> References: <20240815214527.2100137-1-tom@herbertland.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Add infrastructure for parsing into UDP encapsulations Add function __skb_flow_dissect_udp that is called for IPPROTO_UDP. The flag FLOW_DISSECTOR_F_PARSE_UDP_ENCAPS enables parsing of UDP encapsulations. If the flag is set when parsing a UDP packet then a socket lookup is performed. The offset of the base network header, either an IPv4 or IPv6 header, is tracked and passed to __skb_flow_dissect_udp so that it can perform the socket lookup If a socket is found and it's for a UDP encapsulation (encap_type is set in the UDP socket) then a switch is performed on the encap_type value (cases are UDP_ENCAP_* values) An encapsulated packet in UDP can either be indicated by an EtherType or IP protocol. The processing for dissecting a UDP encap protocol returns a flow dissector return code. If FLOW_DISSECT_RET_PROTO_AGAIN or FLOW_DISSECT_RET_IPPROTO_AGAIN is returned then the corresponding encapsulated protocol is dissected. The nhoff is set to point to the header to process. In the case FLOW_DISSECT_RET_PROTO_AGAIN the EtherType protocol is returned and the IP protocol is set to zero. In the case of FLOW_DISSECT_RET_IPPROTO_AGAIN, the IP protocol is returned and the EtherType protocol is returned unchanged Signed-off-by: Tom Herbert --- include/net/flow_dissector.h | 1 + net/core/flow_dissector.c | 121 +++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) diff --git a/include/net/flow_dissector.h b/include/net/flow_dissector.h index ced79dc8e856..8a868a88a6f1 100644 --- a/include/net/flow_dissector.h +++ b/include/net/flow_dissector.h @@ -384,6 +384,7 @@ enum flow_dissector_key_id { #define FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL BIT(1) #define FLOW_DISSECTOR_F_STOP_AT_ENCAP BIT(2) #define FLOW_DISSECTOR_F_STOP_BEFORE_ENCAP BIT(3) +#define FLOW_DISSECTOR_F_PARSE_UDP_ENCAPS BIT(4) struct flow_dissector_key { enum flow_dissector_key_id key_id; diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c index 4b116119086a..160801b83d54 100644 --- a/net/core/flow_dissector.c +++ b/net/core/flow_dissector.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -806,6 +807,117 @@ __skb_flow_dissect_batadv(const struct sk_buff *skb, return FLOW_DISSECT_RET_PROTO_AGAIN; } +static enum flow_dissect_ret +__skb_flow_dissect_udp(const struct sk_buff *skb, const struct net *net, + struct flow_dissector *flow_dissector, + void *target_container, const void *data, + int *p_nhoff, int hlen, __be16 *p_proto, + u8 *p_ip_proto, int base_nhoff, unsigned int flags) +{ + enum flow_dissect_ret ret; + const struct udphdr *udph; + struct udphdr _udph; + struct sock *sk; + __u8 encap_type; + int nhoff; + + if (!(flags & FLOW_DISSECTOR_F_PARSE_UDP_ENCAPS)) + return FLOW_DISSECT_RET_OUT_GOOD; + + switch (*p_proto) { + case htons(ETH_P_IP): { + const struct iphdr *iph; + struct iphdr _iph; + + iph = __skb_header_pointer(skb, base_nhoff, sizeof(_iph), data, + hlen, &_iph); + if (!iph) + return FLOW_DISSECT_RET_OUT_BAD; + + udph = __skb_header_pointer(skb, *p_nhoff, sizeof(_udph), data, + hlen, &_udph); + if (!udph) + return FLOW_DISSECT_RET_OUT_BAD; + + rcu_read_lock(); + /* Look up the UDPv4 socket and get the encap_type */ + sk = __udp4_lib_lookup(net, iph->saddr, udph->source, + iph->daddr, udph->dest, + inet_iif(skb), inet_sdif(skb), + net->ipv4.udp_table, NULL); + if (!sk || !udp_sk(sk)->encap_type) { + rcu_read_unlock(); + return FLOW_DISSECT_RET_OUT_GOOD; + } + + encap_type = udp_sk(sk)->encap_type; + rcu_read_unlock(); + + break; + } +#if IS_ENABLED(CONFIG_IPV6) + case htons(ETH_P_IPV6): { + const struct ipv6hdr *iph; + struct ipv6hdr _iph; + + if (!likely(ipv6_bpf_stub)) + return FLOW_DISSECT_RET_OUT_GOOD; + + iph = __skb_header_pointer(skb, base_nhoff, sizeof(_iph), data, + hlen, &_iph); + if (!iph) + return FLOW_DISSECT_RET_OUT_BAD; + + udph = __skb_header_pointer(skb, *p_nhoff, sizeof(_udph), data, + hlen, &_udph); + if (!udph) + return FLOW_DISSECT_RET_OUT_BAD; + + rcu_read_lock(); + /* Look up the UDPv6 socket and get the encap_type */ + sk = ipv6_bpf_stub->udp6_lib_lookup(net, + &iph->saddr, udph->source, + &iph->daddr, udph->dest, + inet_iif(skb), inet_sdif(skb), + net->ipv4.udp_table, NULL); + + if (!sk || !udp_sk(sk)->encap_type) { + rcu_read_unlock(); + return FLOW_DISSECT_RET_OUT_GOOD; + } + + encap_type = udp_sk(sk)->encap_type; + rcu_read_unlock(); + + break; + } +#endif /* CONFIG_IPV6 */ + default: + return FLOW_DISSECT_RET_OUT_GOOD; + } + + nhoff = *p_nhoff + sizeof(struct udphdr); + ret = FLOW_DISSECT_RET_OUT_GOOD; + + switch (encap_type) { + default: + break; + } + + switch (ret) { + case FLOW_DISSECT_RET_PROTO_AGAIN: + *p_ip_proto = 0; + fallthrough; + case FLOW_DISSECT_RET_IPPROTO_AGAIN: + *p_nhoff = nhoff; + break; + default: + break; + } + + return ret; +} + static void __skb_flow_dissect_tcp(const struct sk_buff *skb, struct flow_dissector *flow_dissector, @@ -1046,6 +1158,7 @@ bool __skb_flow_dissect(const struct net *net, int mpls_lse = 0; int num_hdrs = 0; u8 ip_proto = 0; + int base_nhoff; bool ret; if (!data) { @@ -1168,6 +1281,7 @@ bool __skb_flow_dissect(const struct net *net, proto_again: fdret = FLOW_DISSECT_RET_CONTINUE; + base_nhoff = nhoff; switch (proto) { case htons(ETH_P_IP): { @@ -1635,6 +1749,13 @@ bool __skb_flow_dissect(const struct net *net, data, nhoff, hlen); break; + case IPPROTO_UDP: + fdret = __skb_flow_dissect_udp(skb, net, flow_dissector, + target_container, data, &nhoff, + hlen, &proto, &ip_proto, + base_nhoff, flags); + break; + case IPPROTO_ICMP: case IPPROTO_ICMPV6: __skb_flow_dissect_icmp(skb, flow_dissector, target_container, From patchwork Thu Aug 15 21:45:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Herbert X-Patchwork-Id: 13765222 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 09EBE1547FB for ; Thu, 15 Aug 2024 21:46:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723758381; cv=none; b=P0rD1I82hDLdoso79mXG5JpeqvtTKuUAESyG+LUf04xpudI+mIlgQXUjOcrm9aQj2WDw5o5FKR5adfiyob/3cfkCOPnj74EhuLgguk8JIEL+PzKFO3kKZ64hPgRKIlrX86okteIcQ//A4uByrXsJ2nYQPUOmD2qJeMVbjAVhuDk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723758381; c=relaxed/simple; bh=Eu0gvtwEP5vc+i4ivHb7XKBq1Gpt/bUuqZGjd4JylG8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VT1nss6DGX6vPTW8jRIo+mfRhkAS2emEuvmtw+Z1rO7KkGbeBWLahJoRvcNvCHO6g4NijgR1+NAf/9iePjML8D3u+CSK/vjF+Zsl5xqMRVoZAoEmUWAt9JWqu83oieSqh7R5SyNwq7jrE5FxYsf29oDu31/qInDGriWBF+5lcFo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=herbertland.com; spf=pass smtp.mailfrom=herbertland.com; dkim=pass (2048-bit key) header.d=herbertland.com header.i=@herbertland.com header.b=U8IXWGmV; arc=none smtp.client-ip=209.85.215.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=herbertland.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=herbertland.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=herbertland.com header.i=@herbertland.com header.b="U8IXWGmV" Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-7163489149eso1074711a12.1 for ; Thu, 15 Aug 2024 14:46:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=herbertland.com; s=google; t=1723758379; x=1724363179; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9Qw9rlCyrxF1posPx7i5iOLRFflQN5d/XkK6SF1LsBY=; b=U8IXWGmVWyeJ02b0P613dEHDFZdx5b5kKjOWkMSSecrC1yULSR3tL+ulRmJF/TkrQK CEf/v8dUbAjVQnrn0i9uqhY5TYEdRUvqZJmFdn3YXqFVkWuy4ofcN11/eyueQ7uxNjCg CVxIGw1Y/LZqdxbFPPiWM0Jctjuj895V7eRy35p8502/c5LOMQwEU2C8GHLEBWPq/4ze 3AUQAT2VeQeKxtGjst5JGcUnNVeBMjvs1C5T7s6dZotlkT6SQQ86RrhQLa1e8OPgstY/ tb/tQlieB+nUSm71VGbJRwoRPSA8okLVsNFnnEr3950+C3Ht0qLbJopUHrkB2OfIcNmy siPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723758379; x=1724363179; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9Qw9rlCyrxF1posPx7i5iOLRFflQN5d/XkK6SF1LsBY=; b=vYQMTv/tXbF2ZUnwBbqC/wSoYOHO0Xd5wwYG9qioBBQdy+S/T6jlLApDFENzLYJwOF AXxStZxfzCazUoKRzAKb75m21qo3BJW4O7slHPKrIDEOMxM9TiGMPVr70oaylOGar36G OFUtGwXPfGDPkJdKZDlvUG1P4zSiP/vSpE+hszFgdJdoKUwJCVFhYSuwGLkKeG0Xy4qq y9OLO8wpf8CC9KFWWd3SL3V5BbItXegU+DS18qk0R+Ph49OffxMh1lvhtRxmMEzBMUDZ Nr5IMGYBGU18yRDfGCGZ5hHy2RixPcSDtN8a79CUE2NRmh6N3cDhJ71Ia7FCPfmGpDaI vvRA== X-Forwarded-Encrypted: i=1; AJvYcCVUQNQMl93+0uhKvWa0NgjLHL3GD2k47MqXhwxG2PcN/EFwx+HsXZ9VBLLBqPz3WSKJcRAk6llrs6zacxGuAo+eA1SliqLq X-Gm-Message-State: AOJu0YyA+hXhc/mLHjCh2D2bajNMiUPImazuemaZoIDC8n6DVS8Jm5cq WHJCjP7z/xQZtvkv+NZWddanuXuIz+V4pUtSBv8GVDyUFky51fTY8yIel+nOmQ== X-Google-Smtp-Source: AGHT+IEhl2ouPCjcHl2h3n0KAgpV1jLfMjVxSxI+xtMi8Wucp0Z1O0PNZejOr4EF+S2YGLFEUxo3xw== X-Received: by 2002:a17:90b:950:b0:2c8:6308:ad78 with SMTP id 98e67ed59e1d1-2d3e00ef914mr1173296a91.34.1723758379099; Thu, 15 Aug 2024 14:46:19 -0700 (PDT) Received: from TomsPC.home ([2601:646:8300:55f0:99b4:e046:411:1b72]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d3e2c652ffsm303288a91.10.2024.08.15.14.46.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2024 14:46:18 -0700 (PDT) From: Tom Herbert To: davem@davemloft.net, kuba@kernel.org, edumazet@google.com, netdev@vger.kernel.org, felipe@sipanda.io, willemdebruijn.kernel@gmail.com Cc: Tom Herbert Subject: [PATCH net-next v2 05/12] flow_dissector: Parse vxlan in UDP Date: Thu, 15 Aug 2024 14:45:20 -0700 Message-Id: <20240815214527.2100137-6-tom@herbertland.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240815214527.2100137-1-tom@herbertland.com> References: <20240815214527.2100137-1-tom@herbertland.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Parse vxlan in a UDP encapsulation Signed-off-by: Tom Herbert Reviewed-by: Willem de Bruijn --- net/core/flow_dissector.c | 57 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c index 160801b83d54..57cfae4b5d2f 100644 --- a/net/core/flow_dissector.c +++ b/net/core/flow_dissector.c @@ -13,7 +13,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -756,6 +758,55 @@ __skb_flow_dissect_gre(const struct sk_buff *skb, return FLOW_DISSECT_RET_PROTO_AGAIN; } +static enum flow_dissect_ret +__skb_flow_dissect_vxlan(const struct sk_buff *skb, + struct flow_dissector *flow_dissector, + void *target_container, const void *data, + __be16 *p_proto, int *p_nhoff, int hlen, + unsigned int flags) +{ + struct vxlanhdr *hdr, _hdr; + __be16 protocol; + + hdr = __skb_header_pointer(skb, *p_nhoff, sizeof(_hdr), data, hlen, + &_hdr); + if (!hdr) + return FLOW_DISSECT_RET_OUT_BAD; + + /* VNI flag always required to be set */ + if (!(hdr->vx_flags & VXLAN_HF_VNI)) + return FLOW_DISSECT_RET_OUT_BAD; + + if (hdr->vx_flags & VXLAN_F_GPE) { + struct vxlanhdr_gpe *gpe = (struct vxlanhdr_gpe *)hdr; + + /* Need to have Next Protocol set for interfaces in GPE mode. */ + if (!gpe->np_applied) + return FLOW_DISSECT_RET_OUT_BAD; + + /* The initial version is 0 */ + if (gpe->version != 0) + return FLOW_DISSECT_RET_OUT_GOOD; + + /* "When the O bit is set to 1, the packet is an OAM packet and + * OAM so ignore + */ + if (gpe->oam_flag) + return FLOW_DISSECT_RET_OUT_GOOD; + + protocol = tun_p_to_eth_p(gpe->next_protocol); + if (!protocol) + return FLOW_DISSECT_RET_OUT_GOOD; + } else { + protocol = htons(ETH_P_TEB); + } + + *p_nhoff += sizeof(struct vxlanhdr); + *p_proto = protocol; + + return FLOW_DISSECT_RET_PROTO_AGAIN; +} + /** * __skb_flow_dissect_batadv() - dissect batman-adv header * @skb: sk_buff to with the batman-adv header @@ -900,6 +951,12 @@ __skb_flow_dissect_udp(const struct sk_buff *skb, const struct net *net, ret = FLOW_DISSECT_RET_OUT_GOOD; switch (encap_type) { + case UDP_ENCAP_VXLAN: + case UDP_ENCAP_VXLAN_GPE: + ret = __skb_flow_dissect_vxlan(skb, flow_dissector, + target_container, data, + p_proto, &nhoff, hlen, flags); + break; default: break; } From patchwork Thu Aug 15 21:45:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Herbert X-Patchwork-Id: 13765223 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E6BC154BFE for ; Thu, 15 Aug 2024 21:46:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723758382; cv=none; b=EBa5J43sXPt51SDDvn3+0y5lqSKpSBbBrdpn8IbMOYMkBw3R8WHu8liFC+CgnPfiDCiVw57NMnyVggRZOdYJM0T2nRoZeYsarwtTk+cevFOVmeAZyxcWZhsgc6Q55jt2PR9abLqhZ/ZCbiGIa8W5mckr0ZZPbfZj3seCGTudBY0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723758382; c=relaxed/simple; bh=oalgP9O9gpcKlYJBcSNPBq0Wmbsxw0YVzP2gX8IN3c0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=isIxo6Hj3sHLn6+OQBGa2W4n68o2QCeGwTDw6mMqcamri39AO7ZN6Wr+I0p7BE+EjUZ7sLh1c2VXeDDLIknvugXNKdshcubOCA6KzRs/D8AJzMCiEgRk5zHRDt/lx5BStXFiT0jr35Elo9v7ofV9sVC7HO0mFGgw/rdjSAfa+X4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=herbertland.com; spf=pass smtp.mailfrom=herbertland.com; dkim=pass (2048-bit key) header.d=herbertland.com header.i=@herbertland.com header.b=BxszTmEl; arc=none smtp.client-ip=209.85.215.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=herbertland.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=herbertland.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=herbertland.com header.i=@herbertland.com header.b="BxszTmEl" Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-6c5bcb8e8edso1102802a12.2 for ; Thu, 15 Aug 2024 14:46:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=herbertland.com; s=google; t=1723758380; x=1724363180; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Fl4aAKLOqzFhxiacmKbEmhmC238Jn9ZCDBpZAd6LT98=; b=BxszTmElL7Uadld+n9iCUxyVnfnmNRQlm8I9pZhPcbIBrHIwLTBvCEf1PYQNt2S7nf wVdCQ3jbtTY9WnH7FHooa9ObHZ98P+IYyxSU+g2kf5/5KJhSEEx0f0Fz/FJ20nw/SQ+z IZxJR7zvIVb9vOl3WLjxcugKiWKmhboaOIDr3XXiNrQv+f7Kh+nKheuL2lZqe2QsgjGz 0eiec7pJdzZGGOEVh5RyJaq8BnhCK3nR0V8LsFzsWzMMEfVrUO/2FGIw60sgUD616CKE B6j1sMUVXgxbD2kywZDkXjgBV7bREcNID+kepiPggIQlQ1J43qrQ/Oxgxo432rg7GihA 55Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723758380; x=1724363180; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Fl4aAKLOqzFhxiacmKbEmhmC238Jn9ZCDBpZAd6LT98=; b=wmEbEAw3rQ4gFa+yo//LBsCq7EjetKDQTocSqxsdnmkqUAXP5PSGOdjojkgaveCP/1 nKxWqhf/RMXleC5ufUNol6ugcytVQxRm/jH0tpGHr+5E3yD4kUE6u3FNygwJi8vlSk6l AtCR5y7Jot6S5oV4bC4Grv7RrDQLKRYD5z0g6b6ZAwCU7V4s0bO1SJV3d90hHCRct8Dp GM3qhovHihcDhV/rxyjs9TjLhPZo7GFzlenPKYj5WIQQH3eXG+7SOZXIn/hPFvNgeE+m dO1HkrRJPHTb+DsduZEh3dRr+A13+gqHw84TzDDyRzBmQSsMph3vEI+zuMBpZ1KK2WcR Rjww== X-Forwarded-Encrypted: i=1; AJvYcCUZOHqxwFiWC/jCsvNW8NVyjqll9Lbelovm/yoKgv9qwgwAcJKl0m7YrWbGHd6jO1O4kt5Pi//+gkJ4TUhw/3cN22zmsyP1 X-Gm-Message-State: AOJu0YzkZBL6RHHiGDkuv6U+XIyuKv6myYsXI/uGqn7q6AYJWKgyyBFU ji6TfA3JoE9+tDcfjCw/Ce5LnWigJtQQEeqDhG88KnxK6igj0qTtPW9UBGOmYw== X-Google-Smtp-Source: AGHT+IHSdyyb6Yx9BAUbTphNur0zx8hkm9pMcynVfm2tE7Tg7dhCrQYQFFcDT4ngYP2ljfLZmTkM+A== X-Received: by 2002:a17:90b:224e:b0:2c8:716f:b46e with SMTP id 98e67ed59e1d1-2d3dfc61a62mr1173056a91.16.1723758380431; Thu, 15 Aug 2024 14:46:20 -0700 (PDT) Received: from TomsPC.home ([2601:646:8300:55f0:99b4:e046:411:1b72]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d3e2c652ffsm303288a91.10.2024.08.15.14.46.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2024 14:46:20 -0700 (PDT) From: Tom Herbert To: davem@davemloft.net, kuba@kernel.org, edumazet@google.com, netdev@vger.kernel.org, felipe@sipanda.io, willemdebruijn.kernel@gmail.com Cc: Tom Herbert , Willem de Bruijn Subject: [PATCH net-next v2 06/12] flow_dissector: Parse foo-over-udp (FOU) Date: Thu, 15 Aug 2024 14:45:21 -0700 Message-Id: <20240815214527.2100137-7-tom@herbertland.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240815214527.2100137-1-tom@herbertland.com> References: <20240815214527.2100137-1-tom@herbertland.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Parse FOU by getting the FOU protocol from the matching socket. This includes moving "struct fou" and "fou_from_sock" to fou.h Reviewed-by: Willem de Bruijn Signed-off-by: Tom Herbert --- include/net/fou.h | 16 ++++++++++++++++ net/core/flow_dissector.c | 13 ++++++++++++- net/ipv4/fou_core.c | 16 ---------------- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/include/net/fou.h b/include/net/fou.h index 824eb4b231fd..8574767b91b6 100644 --- a/include/net/fou.h +++ b/include/net/fou.h @@ -17,6 +17,22 @@ int __fou_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e, int __gue_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e, u8 *protocol, __be16 *sport, int type); +struct fou { + struct socket *sock; + u8 protocol; + u8 flags; + __be16 port; + u8 family; + u16 type; + struct list_head list; + struct rcu_head rcu; +}; + +static inline struct fou *fou_from_sock(struct sock *sk) +{ + return sk->sk_user_data; +} + int register_fou_bpf(void); #endif diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c index 57cfae4b5d2f..ce7119dbf1ab 100644 --- a/net/core/flow_dissector.c +++ b/net/core/flow_dissector.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -865,11 +866,11 @@ __skb_flow_dissect_udp(const struct sk_buff *skb, const struct net *net, int *p_nhoff, int hlen, __be16 *p_proto, u8 *p_ip_proto, int base_nhoff, unsigned int flags) { + __u8 encap_type, fou_protocol; enum flow_dissect_ret ret; const struct udphdr *udph; struct udphdr _udph; struct sock *sk; - __u8 encap_type; int nhoff; if (!(flags & FLOW_DISSECTOR_F_PARSE_UDP_ENCAPS)) @@ -902,6 +903,9 @@ __skb_flow_dissect_udp(const struct sk_buff *skb, const struct net *net, } encap_type = udp_sk(sk)->encap_type; + if (encap_type == UDP_ENCAP_FOU) + fou_protocol = fou_from_sock(sk)->protocol; + rcu_read_unlock(); break; @@ -938,6 +942,9 @@ __skb_flow_dissect_udp(const struct sk_buff *skb, const struct net *net, } encap_type = udp_sk(sk)->encap_type; + if (encap_type == UDP_ENCAP_FOU) + fou_protocol = fou_from_sock(sk)->protocol; + rcu_read_unlock(); break; @@ -951,6 +958,10 @@ __skb_flow_dissect_udp(const struct sk_buff *skb, const struct net *net, ret = FLOW_DISSECT_RET_OUT_GOOD; switch (encap_type) { + case UDP_ENCAP_FOU: + *p_ip_proto = fou_protocol; + ret = FLOW_DISSECT_RET_IPPROTO_AGAIN; + break; case UDP_ENCAP_VXLAN: case UDP_ENCAP_VXLAN_GPE: ret = __skb_flow_dissect_vxlan(skb, flow_dissector, diff --git a/net/ipv4/fou_core.c b/net/ipv4/fou_core.c index 8241f762e45b..137eb80c56a2 100644 --- a/net/ipv4/fou_core.c +++ b/net/ipv4/fou_core.c @@ -21,17 +21,6 @@ #include "fou_nl.h" -struct fou { - struct socket *sock; - u8 protocol; - u8 flags; - __be16 port; - u8 family; - u16 type; - struct list_head list; - struct rcu_head rcu; -}; - #define FOU_F_REMCSUM_NOPARTIAL BIT(0) struct fou_cfg { @@ -48,11 +37,6 @@ struct fou_net { struct mutex fou_lock; }; -static inline struct fou *fou_from_sock(struct sock *sk) -{ - return sk->sk_user_data; -} - static int fou_recv_pull(struct sk_buff *skb, struct fou *fou, size_t len) { /* Remove 'len' bytes from the packet (UDP header and From patchwork Thu Aug 15 21:45:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Herbert X-Patchwork-Id: 13765224 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8EEF3154C0F for ; Thu, 15 Aug 2024 21:46:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723758383; cv=none; b=iX07T5YaaqkLbI8Y76A/ZFO38YRTTcrFV2DKLdjgidiGGtBKBDuBvs6yQvRitWjpJqWF6DOXOUk4htk6QymmJ4L44UhDt9OhYUWyGaW2SB1kIY686cSE9VYmRhkrXxr9eQYUBOx7Liqz/SCKylvXQ3CHOi3vggXm2pacG9LNhq4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723758383; c=relaxed/simple; bh=PXBP4otjfoI2KnZ03tyygL+2esXXiEIeV344gWDQjo4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nx2MyooSaAxC026c2XaxkrhWF/72lAoTiIb469kfV2CVDyzHG/GQn8zaZNNskCA1UXliKmCI6dTiY4MTVrOgTNpNXOg6iejsVArmXrrwShS/2J+dSOCL+3W9nd+OIz6GCpdGa18L17hUjYJZ1Y52jSe0tcfmwClz8bXun754NoI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=herbertland.com; spf=pass smtp.mailfrom=herbertland.com; dkim=pass (2048-bit key) header.d=herbertland.com header.i=@herbertland.com header.b=LaHYUiIY; arc=none smtp.client-ip=209.85.215.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=herbertland.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=herbertland.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=herbertland.com header.i=@herbertland.com header.b="LaHYUiIY" Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-7b594936e9bso958155a12.1 for ; Thu, 15 Aug 2024 14:46:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=herbertland.com; s=google; t=1723758382; x=1724363182; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=M5PeGhSnOFENfQ9oa4tF+z+r4plsYTo0K+Sh8hUO/8s=; b=LaHYUiIYXFqWo7ycTCYwGRaXMWe7hzFkERx2upkoyCMqX69hHiZT3ABpLOWzqliXVZ xr1+jBWj1jIwujNr+aWxSZASfq/O9NN+FBrkc7SAA6vzv5iY49tosgpDtcEYSMFVmlGh KZfQn92m3JcKIVMrPbV0Ce85ZdBXo8AhafCz/ZEawpXlF3kozHJma3fMFNwSZSL5kaZH plm3qIvORHlmvmQRsViXPwZDwuFblXfEFlxf9shbFYQhY4yxAp0jEqK7rzo73z8dnP2b k/Q+4X2xzgHzCpADtSINcFmp/MQWO/MD7gJgRePO6bYH7La6xHMTeidM4m4Iknc7kVbC mLTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723758382; x=1724363182; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=M5PeGhSnOFENfQ9oa4tF+z+r4plsYTo0K+Sh8hUO/8s=; b=tBePfZ1VQ9AAYQtf3zLQ6aKIkRv/VMwiwmDCAjOjPzCpGqQx9MIF+CCfvUa1xJGHiz aQ0IAjmP84ha253lRS+OWsbwgD848GsL51RWAWzRVvafUbmO+s42q/1l1Kts34O4n9ZQ denO9aUv6641m1jSB45LlgdsnelSPO4mwvPM6e6ayBKRx6QfoCBbwllJ3zKdvdtL5DLg 1e0ZAxsjXDuzk8Y45lqsFNAFLzcD1nOfxrDbQvgFjSXj3TzGqLv0sOXNs9EZ/BI+ce4M kC67SwPiBDDSSJG3Z2Flh/wfNPN4Xe4aQyYsnBVhEzDvVGhBjCWGqcnTRnvUKuni73h7 Cvvw== X-Forwarded-Encrypted: i=1; AJvYcCUOwkLDHCqDrJSCaeqI5wyhyuFBRLYEcvrNrTartxkHVxgYgXRal6G+ruMM0PMDz+HGGaoLc9ryiqvZZab7wEaOEzjJd9x6 X-Gm-Message-State: AOJu0YzmOD/iNm9792mTO3yZazA3YBoM+XUGTq+EYYb8ImHt9P//Ikza p3ERH8XHyvzZEdg7aMFkbDcT81aIbHESMkXwgSrkktGpRuP+67qGEa8iPSLK2g== X-Google-Smtp-Source: AGHT+IG0wa4EQ5Fhf/JTVtyv7FH2IGq96L3od5XrN8nGqanM2BKXTsrFgmMGejz1lKiKo17lQm0/9w== X-Received: by 2002:a17:90b:1d91:b0:2d3:dca0:89b7 with SMTP id 98e67ed59e1d1-2d3dfc240a7mr1252370a91.3.1723758381635; Thu, 15 Aug 2024 14:46:21 -0700 (PDT) Received: from TomsPC.home ([2601:646:8300:55f0:99b4:e046:411:1b72]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d3e2c652ffsm303288a91.10.2024.08.15.14.46.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2024 14:46:21 -0700 (PDT) From: Tom Herbert To: davem@davemloft.net, kuba@kernel.org, edumazet@google.com, netdev@vger.kernel.org, felipe@sipanda.io, willemdebruijn.kernel@gmail.com Cc: Tom Herbert Subject: [PATCH net-next v2 07/12] flow_dissector: Parse ESP, L2TP, and SCTP in UDP Date: Thu, 15 Aug 2024 14:45:22 -0700 Message-Id: <20240815214527.2100137-8-tom@herbertland.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240815214527.2100137-1-tom@herbertland.com> References: <20240815214527.2100137-1-tom@herbertland.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org These don't have an encapsulation header so it's fairly easy to support them Signed-off-by: Tom Herbert Reviewed-by: Willem de Bruijn --- net/core/flow_dissector.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c index ce7119dbf1ab..5878955c01a5 100644 --- a/net/core/flow_dissector.c +++ b/net/core/flow_dissector.c @@ -958,10 +958,23 @@ __skb_flow_dissect_udp(const struct sk_buff *skb, const struct net *net, ret = FLOW_DISSECT_RET_OUT_GOOD; switch (encap_type) { + case UDP_ENCAP_ESPINUDP_NON_IKE: + case UDP_ENCAP_ESPINUDP: + *p_ip_proto = IPPROTO_ESP; + ret = FLOW_DISSECT_RET_IPPROTO_AGAIN; + break; + case UDP_ENCAP_L2TPINUDP: + *p_ip_proto = IPPROTO_L2TP; + ret = FLOW_DISSECT_RET_IPPROTO_AGAIN; + break; case UDP_ENCAP_FOU: *p_ip_proto = fou_protocol; ret = FLOW_DISSECT_RET_IPPROTO_AGAIN; break; + case UDP_ENCAP_SCTP: + *p_ip_proto = IPPROTO_SCTP; + ret = FLOW_DISSECT_RET_IPPROTO_AGAIN; + break; case UDP_ENCAP_VXLAN: case UDP_ENCAP_VXLAN_GPE: ret = __skb_flow_dissect_vxlan(skb, flow_dissector, From patchwork Thu Aug 15 21:45:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Herbert X-Patchwork-Id: 13765225 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E366315531A for ; Thu, 15 Aug 2024 21:46:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723758385; cv=none; b=CtSqta1hxBZRkvX84uaTXAqPUPH7aYu8rDDAIBtlLiZJvnlkMsQDEVIxwrJ7eMr0KQnNKcgVR5Dy8obpuQ2F2VP2lOOqV1gMfAQNar0ZhBvw3muyzYrGDDuyQFKgLMTq+cm+fvQDyBmQcERO3sAKLiwQdqDqEaOkAm5CNsY1ptQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723758385; c=relaxed/simple; bh=+L3PxYRN4rxWkDczdXPPa9GErwl/3ywUvrtMJG7ANdU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uWIZYM6JpCc43CWC1cNA1YSCSzZoGRKaYx8D7RDRUeDifbNFTcUZgQ4zyLNcHMKlpxEGbrVUmdzI9DwZ2+19kgFCWYg+I26uKTxiSRb64IsLMoIGJvmpjIll32U545s8cqjzin0YnRJNUjvP2GA0dppCfDzkg/ewhdFMSSqQzKw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=herbertland.com; spf=pass smtp.mailfrom=herbertland.com; dkim=pass (2048-bit key) header.d=herbertland.com header.i=@herbertland.com header.b=Fkp6Qkxd; arc=none smtp.client-ip=209.85.216.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=herbertland.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=herbertland.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=herbertland.com header.i=@herbertland.com header.b="Fkp6Qkxd" Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-2cb53da06a9so949016a91.0 for ; Thu, 15 Aug 2024 14:46:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=herbertland.com; s=google; t=1723758383; x=1724363183; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RzF9x4/T4xaT7sQe5OBeO8JW+tCEl/mAvMEK7IpsLHU=; b=Fkp6QkxdGgu/aSSMaSONVThH7+GFWPRwxWQN8dD5u/FsGoho5btGpoOcJzUluu9F89 KWifFR+UA0mHfNI72+HQIwOIiMdCVHZFr++ig9oeoxjBYhs3DiuRzPblO75uef6dCbaR 68QsF0BcByI8qT1//mzVddx8YV2PDRQYsw0vWGTLWpHKt02CUJCOvts2MGYxzI0NIQpH 9l5Q+pjg4S4VRf+mKLhP79KLe2wEz2lZeyoQHS3xCk2RO5jS6UsoCKWEOBTW/PiWZD3p ONU2DqrNj0Wma8LHnxMag6E1cLM5xJELvyozKxpaWMF9Os/QFuPB+UCdknYmtWyhBP1t 9cyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723758383; x=1724363183; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RzF9x4/T4xaT7sQe5OBeO8JW+tCEl/mAvMEK7IpsLHU=; b=MW6VlUrsEdvqkKb4qzsutiMrXbsYSGjjwAiCTXOvhi8t4U+dLYYwOsIZ9SnLlqyQhb u91oIHvcGRuP4J4ewzXmFqNouLFdBbDRLOL6bpIyaiP7Lj1UjvBSPnEeipyJqEqX5jWc y6h95xEwfKjnZ3mWztv7Uto7DG6gO/axd63ptuGLSyhWCKqSgjLlqt9e8mbVX+pgZMlt tCF3XLVGjW1W8syJoQo0oZ7Sf+WxEui3lBu+P9m1tXaphv/GoJruh+4OZJE5uKC+0ssp LKtDrnXmQ+dDrkes7A/nJSTZ+oVV0gkPHfVNdfyvWbVf1O7MrG2wZJ6i8LFRBFAefMin CLHw== X-Forwarded-Encrypted: i=1; AJvYcCVByN7XT3b1idKxVzruhvI2BS0a41vOnW4QziZnsFR18RwGByoQ/LGT+myp+rdUE9GIM7b1wcKyZxXboXKMCHG0czM6gIew X-Gm-Message-State: AOJu0Yy/U47YYyxFoRiDTH5Ef6+3LceSRcK11gIpT38Cb/TO/U/iyrzW DOI/xnaVUNOztP35iaPluwvcaAEHnx7U6QBwPpeh4jtMJaXTMcEwfnKcL9FtKQ== X-Google-Smtp-Source: AGHT+IGWVozJbXq0RuQenJyd3tBKDVWG5VGoxzO0uh2q1sKPeo51rkAVwbJys4gLuRwJlciixfEhGg== X-Received: by 2002:a17:90a:9e2:b0:2d3:b1ac:4bd3 with SMTP id 98e67ed59e1d1-2d3c3984d1dmr6665333a91.11.1723758382990; Thu, 15 Aug 2024 14:46:22 -0700 (PDT) Received: from TomsPC.home ([2601:646:8300:55f0:99b4:e046:411:1b72]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d3e2c652ffsm303288a91.10.2024.08.15.14.46.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2024 14:46:22 -0700 (PDT) From: Tom Herbert To: davem@davemloft.net, kuba@kernel.org, edumazet@google.com, netdev@vger.kernel.org, felipe@sipanda.io, willemdebruijn.kernel@gmail.com Cc: Tom Herbert Subject: [PATCH net-next v2 08/12] flow_dissector: Parse Geneve in UDP Date: Thu, 15 Aug 2024 14:45:23 -0700 Message-Id: <20240815214527.2100137-9-tom@herbertland.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240815214527.2100137-1-tom@herbertland.com> References: <20240815214527.2100137-1-tom@herbertland.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Parse Geneve in a UDP encapsulation Signed-off-by: Tom Herbert Reviewed-by: Willem de Bruijn --- net/core/flow_dissector.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c index 5878955c01a5..e2a0d67b2753 100644 --- a/net/core/flow_dissector.c +++ b/net/core/flow_dissector.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -808,6 +809,29 @@ __skb_flow_dissect_vxlan(const struct sk_buff *skb, return FLOW_DISSECT_RET_PROTO_AGAIN; } +static enum flow_dissect_ret +__skb_flow_dissect_geneve(const struct sk_buff *skb, + struct flow_dissector *flow_dissector, + void *target_container, const void *data, + __be16 *p_proto, int *p_nhoff, int hlen, + unsigned int flags) +{ + struct genevehdr *hdr, _hdr; + + hdr = __skb_header_pointer(skb, *p_nhoff, sizeof(_hdr), data, hlen, + &_hdr); + if (!hdr) + return FLOW_DISSECT_RET_OUT_BAD; + + if (hdr->ver != 0) + return FLOW_DISSECT_RET_OUT_GOOD; + + *p_proto = hdr->proto_type; + *p_nhoff += sizeof(struct genevehdr) + (hdr->opt_len * 4); + + return FLOW_DISSECT_RET_PROTO_AGAIN; +} + /** * __skb_flow_dissect_batadv() - dissect batman-adv header * @skb: sk_buff to with the batman-adv header @@ -981,6 +1005,11 @@ __skb_flow_dissect_udp(const struct sk_buff *skb, const struct net *net, target_container, data, p_proto, &nhoff, hlen, flags); break; + case UDP_ENCAP_GENEVE: + ret = __skb_flow_dissect_geneve(skb, flow_dissector, + target_container, data, + p_proto, &nhoff, hlen, flags); + break; default: break; } From patchwork Thu Aug 15 21:45:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Herbert X-Patchwork-Id: 13765226 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 39870155353 for ; Thu, 15 Aug 2024 21:46:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723758386; cv=none; b=Eb4Cm40vhU9R8C17iq6LSiFCqHW0HNAUHAsmHOv3PdjEyKECX7TlAnvYiFJfR2bGD4ULAP4eASTLseGY0R04Vl4C3Bmr1PJRPK5JhE7x7BZfC0rratKYDXMZrnWfdg2/eFy5l8HAonnemoJcasfYccJ490ECjg6532OqPdOwBoU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723758386; c=relaxed/simple; bh=AKZTwTOl/6402WHfcJqVRq+TsbkjKlN8zLi+0jDoEds=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=P8quDLFOaFf0RzkPGMZQZKG1fsL0YKdyvtmWo0luhCJXXIRKeEZtr74BUk70npz+LgPibdnkVzIY/ERFdeAqnr2B3SHaqf1kyCUivWqdKjThAlqpYGsZCbJxDWJ6SlhtCNbvY+0llnU2iGPvKXjROh07o7VfTVaupKbX2Gfnrhg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=herbertland.com; spf=pass smtp.mailfrom=herbertland.com; dkim=pass (2048-bit key) header.d=herbertland.com header.i=@herbertland.com header.b=GdqGHA1i; arc=none smtp.client-ip=209.85.216.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=herbertland.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=herbertland.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=herbertland.com header.i=@herbertland.com header.b="GdqGHA1i" Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-2d3e44b4613so174014a91.3 for ; Thu, 15 Aug 2024 14:46:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=herbertland.com; s=google; t=1723758384; x=1724363184; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6KLZ8lvNd3VBHtbxfeJSmBIFPoMINjfQPWX7ldcRSDA=; b=GdqGHA1ilIHDP7eP4BSQuYahjkX4HbmZy0UU0lVKEVanpzQDpCXwzrDfx32819UrQz 7+Ix7CATCEg6bXCnkYh2oJh5mx73ExkyWOi+drIjRfTgZ5FPCMY7XpLa47/d287sMEa4 l0fOZECERvtzL/lK+DlVsWv9ZB8zC/NEnwntX2uU/E3scEJ41xC7dD86jU01AS1wir/X 1mb25GauGFxHIhvxl0a68CtoCCCayMA7ek248Psc/V0tlHe++adXLGqH+l28Syr6AG7u k9pEJFiuU5u7MkN7c/gNmnbxsJzmoL/bUM7XjcW3tigyowiV6zBAl706b1ZAs4wvHMCx Q9oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723758384; x=1724363184; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6KLZ8lvNd3VBHtbxfeJSmBIFPoMINjfQPWX7ldcRSDA=; b=PCSHK1QT2IxU+ewbk0Umx+qnj71uzSgSlhvuRo9YBkfWgIjOkWXTbpGf4JcoWHWBDp uTqt943cbS6AAFabZpcM5SH/AjjolLKVsMN1Rb5NtcDgUjYP4o1I9Wow1VcYUJETBjxO Ur7Wzw90db25cnORk3S3SOq33EAvD2qc2sLyjhPJuhLAUjAMHXQOPXY1XPYpbnQb2MoU AFYAtZWbUFMVh0eajzvdhAaRkMg+gHvbbiZ8pzb/CYO7ptm7dBmdqR4TWu1S08+UaqB5 u0T+8fjm/Saq9yoxFs4hCS6BSeeIoCaovH97TB1//77fzUf5W2nnUWUO4+WyCVxjvofn +/zw== X-Forwarded-Encrypted: i=1; AJvYcCVhZAZpqWpn1WDMKbrJJ1SI7A1Oa5LIBSlulhc5FjpSQ1cn50NmWAR1SMp4HxBDyhnFowVmLJFmKy+Y1CzmE4iRGdO2voIl X-Gm-Message-State: AOJu0Yz2pnfi4LyBIZCeOKB/Lc5dl6Ej2O+Ud3O1n4wJK2E+P7lkTJRB fSjKYjv5LpJ4pzfljnCqqzB+9HjrLC2eUNFRoavBK37PB8ez8tX7+GtunSq+OQ== X-Google-Smtp-Source: AGHT+IF48AOdOPZrsNIWrKiHI9u535TaG3hKjZUbJlHm3BNsZaYMcA8pCXkUNogGa39/TnFW5mXH6w== X-Received: by 2002:a17:90a:e548:b0:2c9:8b33:3197 with SMTP id 98e67ed59e1d1-2d3dfc6862bmr1223257a91.10.1723758384405; Thu, 15 Aug 2024 14:46:24 -0700 (PDT) Received: from TomsPC.home ([2601:646:8300:55f0:99b4:e046:411:1b72]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d3e2c652ffsm303288a91.10.2024.08.15.14.46.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2024 14:46:24 -0700 (PDT) From: Tom Herbert To: davem@davemloft.net, kuba@kernel.org, edumazet@google.com, netdev@vger.kernel.org, felipe@sipanda.io, willemdebruijn.kernel@gmail.com Cc: Tom Herbert Subject: [PATCH net-next v2 09/12] flow_dissector: Parse GUE in UDP Date: Thu, 15 Aug 2024 14:45:24 -0700 Message-Id: <20240815214527.2100137-10-tom@herbertland.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240815214527.2100137-1-tom@herbertland.com> References: <20240815214527.2100137-1-tom@herbertland.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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 Reviewed-by: Willem de Bruijn --- 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 e2a0d67b2753..fb8c0d97384e 100644 --- a/net/core/flow_dissector.c +++ b/net/core/flow_dissector.c @@ -832,6 +832,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 @@ -995,6 +1050,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; From patchwork Thu Aug 15 21:45:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Herbert X-Patchwork-Id: 13765227 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93930155730 for ; Thu, 15 Aug 2024 21:46:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723758388; cv=none; b=BX2UkBYh3aYkB9BRifClXenMFmyuagstksLR2CQLpiG55R8V+LO+9cKDZovh49yglaZpS7E2bFP40JKrvtTOkJngnJFAQL01k/IOW1evfdj4agzBjOEvRaVsdq+A7YAuR8MRM7WHFQHjEuL4V9NGfuaj7PQ8Z3SnKikZOUcsDNc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723758388; c=relaxed/simple; bh=VSaUriivj9kHl2ATci4Yrkr8UVaJCANZPPFfenBzm7A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=G/wtPMwpTMPRwjqKA3i9a3UGexEBogZpw7ItYxHm61209seZen62KJM9dIeAj1UD6D6GSbpN9wcvuaVrh8LEEiNc28FbGON7rnyFp9RfPhjzZwXk1S11vIdzMRV+WhmoljATAhlU07i0OZYmCPPMROLI6MLjBt56LWjQewd50yE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=herbertland.com; spf=pass smtp.mailfrom=herbertland.com; dkim=pass (2048-bit key) header.d=herbertland.com header.i=@herbertland.com header.b=Hq3RQMeC; arc=none smtp.client-ip=209.85.215.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=herbertland.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=herbertland.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=herbertland.com header.i=@herbertland.com header.b="Hq3RQMeC" Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-7ae3d7222d4so1040982a12.3 for ; Thu, 15 Aug 2024 14:46:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=herbertland.com; s=google; t=1723758386; x=1724363186; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Kr0BLhj/kH1I2bfmAdGzcmYGGYBiHhQ0koclENsRg7Y=; b=Hq3RQMeCTZPX47j5jXZ3OGhgKoxv/hpwOLqyzoGCxWVHQj853M1W/g5qBKC/AUxmg9 /g2/5RRkXOkruzdzZm0TlZ12FHCO+7mbQPV2L9sSbGigdXRnK9vI5697ABkKtUJw24l4 eX9LqUHGJVDVc8Iw7VpHbBZeaTGxcWrPYxbwYYmWSLXc+Q3k6/Uhp1Dosiq6blbzOFHZ ruZtFlkzF+SINx77kJMaC9oRcWq4tIAEQPaIVyS0cc4dNxUWtoldZh/k+bV4GVw9wtQr pRwPuDlpfZtcK1qUByGMpenEqylBrhd99xmJQWK2+g9Iu6U8i1gyjHONKVFAdTkXhkT8 pnmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723758386; x=1724363186; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Kr0BLhj/kH1I2bfmAdGzcmYGGYBiHhQ0koclENsRg7Y=; b=cBmtYQXhmtVaLdG/ZT1U5za4rLbM+FVKsolYt9QPM8qhpkeuONB9/stqDMBr19J22M xiwMghds8SPrf9ZorP96jZKzYdXEhA8Dj7B2qCfGzFapGELYfYm4uHm0cdS+HxazWzvP fucqB4ieIJKz8GlQGWfVdOf2N6bsuQ2VDWigHl2b2tT56Iwc+Mr7k2BkUrboiooiN3ch h3yYDzAmTRBwG0xYgLlb+TYWb2rvjZWMA3Uk3diqbrVPtjZDPjcF3KyUIIY899OSko3w HKx1VmoZoKmKRbj7vC2p/hVwPdWX5z5Hwj8ll4WkROvOgRkZv1/ilDXIiWD7fDUaltpo mxug== X-Forwarded-Encrypted: i=1; AJvYcCVVYlYrjJboKKVfbcq8MZgE++Ie+vbCWQtMmLHN4BWPCjp7KfsJyHUyuVhSRmeYnCT+69XQMENDJOSWEuWzxKoJT6QNPNBQ X-Gm-Message-State: AOJu0YwEyRjanHcfg3DydW6MoiT8RSON5XIf6/ORbhotsuB50B3DV8uo IHosUZZHu/GkXu+wypiq+dgn4g2FR7/RDA3wr9fj2fOb39ckUiSl5gmjfoicZH3prgQpCgIdJ0s = X-Google-Smtp-Source: AGHT+IH9Hy+zG2DIdFJJ9oxk9WYqurorb9EmdCBBY9VuUOe4fuE174MFR1SM3InslTaXlnyoRTdDCQ== X-Received: by 2002:a17:90a:c718:b0:2d3:b357:7859 with SMTP id 98e67ed59e1d1-2d3dffc5ccbmr1255483a91.13.1723758385667; Thu, 15 Aug 2024 14:46:25 -0700 (PDT) Received: from TomsPC.home ([2601:646:8300:55f0:99b4:e046:411:1b72]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d3e2c652ffsm303288a91.10.2024.08.15.14.46.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2024 14:46:25 -0700 (PDT) From: Tom Herbert To: davem@davemloft.net, kuba@kernel.org, edumazet@google.com, netdev@vger.kernel.org, felipe@sipanda.io, willemdebruijn.kernel@gmail.com Cc: Tom Herbert Subject: [PATCH net-next v2 10/12] gtp: Move gtp_parse_exthdrs into net/gtp.h Date: Thu, 15 Aug 2024 14:45:25 -0700 Message-Id: <20240815214527.2100137-11-tom@herbertland.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240815214527.2100137-1-tom@herbertland.com> References: <20240815214527.2100137-1-tom@herbertland.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org gtp_parse_exthdrs is a generic function, move into a header file so we can call it outside of the GTP driver (specifically, we can call it from flow dissector) Signed-off-by: Tom Herbert Reviewed-by: Willem de Bruijn --- drivers/net/gtp.c | 37 ------------------------------------- include/net/gtp.h | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 37 deletions(-) diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c index 427b91aca50d..61d5dfd48c88 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -742,43 +742,6 @@ static int gtp1u_handle_echo_resp(struct gtp_dev *gtp, struct sk_buff *skb) msg, 0, GTP_GENL_MCGRP, GFP_ATOMIC); } -static int gtp_parse_exthdrs(struct sk_buff *skb, unsigned int *hdrlen) -{ - struct gtp_ext_hdr *gtp_exthdr, _gtp_exthdr; - unsigned int offset = *hdrlen; - __u8 *next_type, _next_type; - - /* From 29.060: "The Extension Header Length field specifies the length - * of the particular Extension header in 4 octets units." - * - * This length field includes length field size itself (1 byte), - * payload (variable length) and next type (1 byte). The extension - * header is aligned to to 4 bytes. - */ - - do { - gtp_exthdr = skb_header_pointer(skb, offset, sizeof(*gtp_exthdr), - &_gtp_exthdr); - if (!gtp_exthdr || !gtp_exthdr->len) - return -1; - - offset += gtp_exthdr->len * 4; - - /* From 29.060: "If no such Header follows, then the value of - * the Next Extension Header Type shall be 0." - */ - next_type = skb_header_pointer(skb, offset - 1, - sizeof(_next_type), &_next_type); - if (!next_type) - return -1; - - } while (*next_type != 0); - - *hdrlen = offset; - - return 0; -} - static int gtp1u_udp_encap_recv(struct gtp_dev *gtp, struct sk_buff *skb) { unsigned int hdrlen = sizeof(struct udphdr) + diff --git a/include/net/gtp.h b/include/net/gtp.h index c0253c8702d0..a513aa1c7394 100644 --- a/include/net/gtp.h +++ b/include/net/gtp.h @@ -83,4 +83,42 @@ struct gtp_ext_hdr { __u8 data[]; }; +static inline int gtp_parse_exthdrs(const struct sk_buff *skb, + unsigned int *hdrlen) +{ + struct gtp_ext_hdr *gtp_exthdr, _gtp_exthdr; + unsigned int offset = *hdrlen; + __u8 *next_type, _next_type; + + /* From 29.060: "The Extension Header Length field specifies the length + * of the particular Extension header in 4 octets units." + * + * This length field includes length field size itself (1 byte), + * payload (variable length) and next type (1 byte). The extension + * header is aligned to 4 bytes. + */ + + do { + gtp_exthdr = skb_header_pointer(skb, offset, sizeof(*gtp_exthdr), + &_gtp_exthdr); + if (!gtp_exthdr || !gtp_exthdr->len) + return -1; + + offset += gtp_exthdr->len * 4; + + /* From 29.060: "If no such Header follows, then the value of + * the Next Extension Header Type shall be 0." + */ + next_type = skb_header_pointer(skb, offset - 1, + sizeof(_next_type), &_next_type); + if (!next_type) + return -1; + + } while (*next_type != 0); + + *hdrlen = offset; + + return 0; +} + #endif From patchwork Thu Aug 15 21:45:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Herbert X-Patchwork-Id: 13765228 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 52724155CB2 for ; Thu, 15 Aug 2024 21:46:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723758390; cv=none; b=ZPSF++GYBCY9BWXIjGCprNGtjEg44+T5qDt4FDZp8khZQdC8e41j58OFYIodvfymrWsBG8rsRmJ2v6t1lSbhplNk19zevaEw++kCunMEo+JzZhcSdciCh+OBvamWJJHJ01b3UvnDD1sq5keqgrfkFwQ/I/aii1lPtuo2MesCuMQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723758390; c=relaxed/simple; bh=gAPJdokW9OyPh5V23AKwk+6cbUxGPq6x1pSC5j+Kow0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=N6QcaIGsP/pcuq/gwn3rsfS1YVakMDmbw5DnzzoAQWNOJTmlQ9/6m7FVQ+pLvaybYcLJ9FdJN4lIV/oOE1Heuw/D3t39e3DGW+c2LYBmMJI5wSdv2yMiKE7OpcLFOc0AkxwQosoYFbWrI92K5pCjFX/1xoqM8OBfUxgGqfsBW1Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=herbertland.com; spf=pass smtp.mailfrom=herbertland.com; dkim=pass (2048-bit key) header.d=herbertland.com header.i=@herbertland.com header.b=P3amZS7i; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=herbertland.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=herbertland.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=herbertland.com header.i=@herbertland.com header.b="P3amZS7i" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1fc587361b6so14041055ad.2 for ; Thu, 15 Aug 2024 14:46:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=herbertland.com; s=google; t=1723758388; x=1724363188; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=h8MFOXRjdH8fksJJ/YKbkpwMOZGHQVEaj1LKadg7RDU=; b=P3amZS7ieSvBD5cloYpZZ5lmDzrhiiU0hTNiwuzETEMGrbf06XaiW6b3Hqgg6GgCzI t0ZiVzlCrfAH3OS3zbN6LkZn9pOu3Xp5T5v7Z/8RF89V3iPmtHCFWekqeEjL0AjRco5M +GaM/Sad/w/n+vfOpTxVG4Hn7pxTRDmwOSqz7adl7z6mu/fpzTJ5qH7MU98CVXaW1jVc xT6xJbTeAK7mihVP6lc1/buNM1dCcFpu6W2ubafHNLK+NmscrtaRttL+BrjtDBlCCE2k ckIYtSwBtaapt7i8IKQvkmLinoTkXsETKI+lr+VdIWAteZhD9PI/L2LxSUyTPnSX36uZ A1qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723758388; x=1724363188; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=h8MFOXRjdH8fksJJ/YKbkpwMOZGHQVEaj1LKadg7RDU=; b=R2jSUWqJuZcsQUuLeHavF4HL+8xrxlxdNLgL8CzkU/nS5ldJy3HjbmiJpCxqSkDOT+ aiqVFvXiD1WMKpgnlZbtvcKr543zlO/CncNjjeyBc3fK3FUIleyAf3yWm1Ynbu4Aj0GA 33+xaVYsdQVPfl806R0s9//qPcZcdVBhRu2bdE0l2x3JVMwBYoe5uX50rSc+dKAVHz9h 0mmO+sQBFqHYFlPizzWUQ5GiUpbFA7pk2bVO73IP1TLpOWUhxhkqMJdqKJJ6CICpOzQv ChVLhcyKlC+qbrWUjvmk6FS9QmJYhAYdTsU7JGv9Q9LX5S8dP7XKhmGeM1kSPV9bcoeq qMjw== X-Forwarded-Encrypted: i=1; AJvYcCV5XG8oN0EHr24MKMVDUDVl47YPu4ac3uDzvakQStSz6axP7FM3MTsGXKzH2CEMkNKrpEJRDLVu/9wXvs99TQveFX/AyX4s X-Gm-Message-State: AOJu0YyC4pHlM6wb8D7LoLIGbTIy9HxL7rLN1FSUdcjb77OdrEqNr3UR aRX0IWn6xsxpsgzpKmK8B77kQ1H1VlVZtz0ZeFUpuXq4/lRxTdB7IWNRr3OhoQ== X-Google-Smtp-Source: AGHT+IHon11uMMueAdIsyFmm238Pt2RRMnNEsnHc83Qm8BFK6LOlmMax447H5tUxesit/kOZprXTSA== X-Received: by 2002:a17:90a:bc97:b0:2d3:c863:cf16 with SMTP id 98e67ed59e1d1-2d3dfff5d4bmr1083016a91.33.1723758388345; Thu, 15 Aug 2024 14:46:28 -0700 (PDT) Received: from TomsPC.home ([2601:646:8300:55f0:99b4:e046:411:1b72]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d3e2c652ffsm303288a91.10.2024.08.15.14.46.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2024 14:46:26 -0700 (PDT) From: Tom Herbert To: davem@davemloft.net, kuba@kernel.org, edumazet@google.com, netdev@vger.kernel.org, felipe@sipanda.io, willemdebruijn.kernel@gmail.com Cc: Tom Herbert Subject: [PATCH net-next v2 11/12] flow_dissector: Parse gtp in UDP Date: Thu, 15 Aug 2024 14:45:26 -0700 Message-Id: <20240815214527.2100137-12-tom@herbertland.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240815214527.2100137-1-tom@herbertland.com> References: <20240815214527.2100137-1-tom@herbertland.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Parse both version 0 and 1. Call __skb_direct_ip_dissect to determine IP version of the encapsulated packet Signed-off-by: Tom Herbert --- net/core/flow_dissector.c | 97 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c index fb8c0d97384e..b2abccf8aac2 100644 --- a/net/core/flow_dissector.c +++ b/net/core/flow_dissector.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -35,6 +36,7 @@ #include #include #include +#include #include #if IS_ENABLED(CONFIG_NF_CONNTRACK) #include @@ -887,6 +889,91 @@ __skb_flow_dissect_gue(const struct sk_buff *skb, return FLOW_DISSECT_RET_IPPROTO_AGAIN; } +static enum flow_dissect_ret +__skb_flow_dissect_gtp0(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) +{ + __u8 *ip_version, _ip_version, proto; + struct gtp0_header *hdr, _hdr; + + hdr = __skb_header_pointer(skb, *p_nhoff, sizeof(_hdr), data, hlen, + &_hdr); + if (!hdr) + return FLOW_DISSECT_RET_OUT_BAD; + + if ((hdr->flags >> 5) != GTP_V0) + return FLOW_DISSECT_RET_OUT_GOOD; + + ip_version = skb_header_pointer(skb, *p_nhoff + sizeof(_hdr), + sizeof(*ip_version), + &_ip_version); + if (!ip_version) + return FLOW_DISSECT_RET_OUT_BAD; + + proto = __skb_direct_ip_dissect(ip_version); + if (!proto) + return FLOW_DISSECT_RET_OUT_GOOD; + + *p_ip_proto = proto; + *p_nhoff += sizeof(struct gtp0_header); + + return FLOW_DISSECT_RET_IPPROTO_AGAIN; +} + +static enum flow_dissect_ret +__skb_flow_dissect_gtp1u(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) +{ + __u8 *ip_version, _ip_version, proto; + struct gtp1_header *hdr, _hdr; + int hdrlen = sizeof(_hdr); + + hdr = __skb_header_pointer(skb, *p_nhoff, sizeof(_hdr), data, hlen, + &_hdr); + if (!hdr) + return FLOW_DISSECT_RET_OUT_BAD; + + if ((hdr->flags >> 5) != GTP_V1) + return FLOW_DISSECT_RET_OUT_GOOD; + + if (hdr->type != GTP_TPDU) + return FLOW_DISSECT_RET_OUT_GOOD; + + if (hdr->flags & GTP1_F_MASK) + hdrlen += 4; + + /* Skip over GTP extension headers if they are present */ + if (hdr->flags & GTP1_F_EXTHDR && + gtp_parse_exthdrs(skb, &hdrlen) < 0) + return FLOW_DISSECT_RET_OUT_BAD; + + /* Exit if either NPDU or SEQ glags are set */ + if (hdr->flags & GTP1_F_NPDU || + hdr->flags & GTP1_F_SEQ) + return FLOW_DISSECT_RET_OUT_GOOD; + + ip_version = skb_header_pointer(skb, *p_nhoff + hdrlen, + sizeof(*ip_version), + &_ip_version); + if (!ip_version) + return FLOW_DISSECT_RET_OUT_GOOD; + + proto = __skb_direct_ip_dissect(ip_version); + if (!proto) + return FLOW_DISSECT_RET_OUT_GOOD; + + *p_ip_proto = proto; + *p_nhoff += hdrlen; + + return FLOW_DISSECT_RET_IPPROTO_AGAIN; +} + /** * __skb_flow_dissect_batadv() - dissect batman-adv header * @skb: sk_buff to with the batman-adv header @@ -1046,6 +1133,16 @@ __skb_flow_dissect_udp(const struct sk_buff *skb, const struct net *net, *p_ip_proto = IPPROTO_L2TP; ret = FLOW_DISSECT_RET_IPPROTO_AGAIN; break; + case UDP_ENCAP_GTP0: + ret = __skb_flow_dissect_gtp0(skb, flow_dissector, + target_container, data, + p_ip_proto, &nhoff, hlen, flags); + break; + case UDP_ENCAP_GTP1U: + ret = __skb_flow_dissect_gtp1u(skb, flow_dissector, + target_container, data, + p_ip_proto, &nhoff, hlen, flags); + break; case UDP_ENCAP_FOU: *p_ip_proto = fou_protocol; ret = FLOW_DISSECT_RET_IPPROTO_AGAIN; From patchwork Thu Aug 15 21:45:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Herbert X-Patchwork-Id: 13765229 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85EA315688C for ; Thu, 15 Aug 2024 21:46:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723758392; cv=none; b=rnayLNKurdkYXpBQl+IbrDO9BB85VLOMhLtGF4q2FPr1/tIvIlzuwOlAO1UHpn8RDHfuxQMJh9JptWOtpEKBj4Gbu5URcp8vrYWU9TC6uoboo/Y60vM2UL7uKmSbQhPuzTJ5TYLXPNFWtiAAB8t+aMCCyuX/KFM+7ExJg5pncvo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723758392; c=relaxed/simple; bh=9cBs1VmwGUDwtfaUGPwFGHwA6yK6LQNIgBe9lhPxBbQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=aq8F6A0XEKQpNiERNEhG+XfANpMzwmTihh6DpHUV7BpzXnTYp4Cey/taIgYD0pIxcP1gBqaXZWcsIPDkM2hfcaInWvFto0B5gj9u3xlItmTdgeNQg3lpmR7sE+nDzDVh9/rsbhgHWZsfwxgPWSTrk0mcobNHXiqnkHq9b+v0Nq8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=herbertland.com; spf=pass smtp.mailfrom=herbertland.com; dkim=pass (2048-bit key) header.d=herbertland.com header.i=@herbertland.com header.b=QMJ4qcFN; arc=none smtp.client-ip=209.85.216.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=herbertland.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=herbertland.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=herbertland.com header.i=@herbertland.com header.b="QMJ4qcFN" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-2d3e44b4613so174070a91.3 for ; Thu, 15 Aug 2024 14:46:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=herbertland.com; s=google; t=1723758391; x=1724363191; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qibwpDkMHgImrmFYGovT/+p+MzHHRNwi0Z9FJ0eqf3g=; b=QMJ4qcFNyVP07IVnBA8t4feEFpg/cgLvIUE/xFQDCcxyrvN5Ww4az8Wb6QUebV8P1K MdhSgrpWArPlc3IgKRwzqrR9CoZ37j2Izy8ntheMaPaXdUIae0HsvUx5zPoIRM67mEAV VjUSlZ8aIKgWd0/SP3bzX3CfrT0j4cuNNkfTF8gDzVPs1q0QRnm4bLsb2tUofG0DHKF8 XozBvwi+QQVhpgiDSkwqV95ldHZs1t9Lo54Jenj5QzhrmR3XP+BD5ULrRUl/8wlGRV7A uoJnerrO0fSJOwYEmPJ2Vbo9eEFaomT0F3KMeR0uw9MolYYApVowaDl92iF4kjVaTREH rkLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723758391; x=1724363191; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qibwpDkMHgImrmFYGovT/+p+MzHHRNwi0Z9FJ0eqf3g=; b=i2H9z9/F54oZ3/muZdzdltRFvoJLXOqEr2xvpzeUWfL9Q7iwEJ9itIh+Cgj0lrojaP nWmVGo38YvSMS5V/tkDfjLvLc4hRmAOQsU1ZWS/OEG2MbXNeIsUc1P9/2OanRIijc0Wi Ho6UVECwXPIwsMPxJwyY4rnfUBi5slicmDyP+8taJKADFa3zyOHx1/RR4fUCdooBp7jQ +ys7dZIS8KPhhPdcxUZjhBwe98QJwW1PGLqmkOlnaFuvRHIZonmSwT5qEGMRDXQpPa8w zxdzJk0Z/WG7FXMA0hyfxyY8GMA0Dy9TmOWpsqzGB40lQF3Eyh3vlqpmsMIfk7J9qDXR 39Sw== X-Forwarded-Encrypted: i=1; AJvYcCVil/TLfVa/IkxpJVXhQ7oYs1ap2Xd+gmjgRBMYzbi+O4JnELfRK0EIyveg30tByuXGqg1141T1lHQh4ndZeydpqDR901vc X-Gm-Message-State: AOJu0YzWuSWEsJtBx9OVHPXyBTILRcgz+w7xQSwmdisK/GXS4m4jkaLM dDI/lP2ki5Ul3jGVbVmVknG30IXlh4Q5NUiQCiXwxNmXcvOxzBym2AG9EsCr6A== X-Google-Smtp-Source: AGHT+IHGFv0nA4sjqzXh4be1nvGKutFXONxschvn0iv3eDmWqI3MlkJhKmjEpzVw99xKD3KIcd9zaw== X-Received: by 2002:a17:90b:88e:b0:2d3:de40:d767 with SMTP id 98e67ed59e1d1-2d3dfd8c698mr1207372a91.24.1723758390591; Thu, 15 Aug 2024 14:46:30 -0700 (PDT) Received: from TomsPC.home ([2601:646:8300:55f0:99b4:e046:411:1b72]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d3e2c652ffsm303288a91.10.2024.08.15.14.46.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2024 14:46:29 -0700 (PDT) From: Tom Herbert To: davem@davemloft.net, kuba@kernel.org, edumazet@google.com, netdev@vger.kernel.org, felipe@sipanda.io, willemdebruijn.kernel@gmail.com Cc: Tom Herbert Subject: [PATCH net-next v2 12/12] flow_dissector: Add case in ipproto switch for NEXTHDR_NONE Date: Thu, 15 Aug 2024 14:45:27 -0700 Message-Id: <20240815214527.2100137-13-tom@herbertland.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240815214527.2100137-1-tom@herbertland.com> References: <20240815214527.2100137-1-tom@herbertland.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Protocol number 59 (no-next-header) means nothing follows the IP header, break out of the flow dissector loop on FLOW_DISSECT_RET_OUT_GOOD when encountered in a packet Signed-off-by: Tom Herbert Reviewed-by: Willem de Bruijn --- net/core/flow_dissector.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c index b2abccf8aac2..fb1ca7d024de 100644 --- a/net/core/flow_dissector.c +++ b/net/core/flow_dissector.c @@ -1971,6 +1971,9 @@ bool __skb_flow_dissect(const struct net *net, fdret = FLOW_DISSECT_RET_OUT_GOOD; break; } + case NEXTHDR_NONE: + fdret = FLOW_DISSECT_RET_OUT_GOOD; + break; case IPPROTO_IPIP: if (flags & FLOW_DISSECTOR_F_STOP_BEFORE_ENCAP) { fdret = FLOW_DISSECT_RET_OUT_GOOD;