netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tom Herbert <tom@herbertland.com>
To: davem@davemloft.net, kuba@kernel.org, edumazet@google.com,
	netdev@vger.kernel.org, felipe@sipanda.io,
	willemdebruijn.kernel@gmail.com, pablo@netfilter.org,
	laforge@gnumonks.org, xeb@mail.ru
Cc: Tom Herbert <tom@herbertland.com>, Willem de Bruijn <willemb@google.com>
Subject: [PATCH net-next v4 07/13] flow_dissector: Parse foo-over-udp (FOU)
Date: Fri, 23 Aug 2024 13:15:51 -0700	[thread overview]
Message-ID: <20240823201557.1794985-8-tom@herbertland.com> (raw)
In-Reply-To: <20240823201557.1794985-1-tom@herbertland.com>

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 <willemb@google.com>
Signed-off-by: Tom Herbert <tom@herbertland.com>
---
 include/net/fou.h         | 16 ++++++++++++++++
 net/core/flow_dissector.c | 12 ++++++++++++
 net/ipv4/fou_core.c       | 16 ----------------
 3 files changed, 28 insertions(+), 16 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 49feea3fec56..e8760c1182b1 100644
--- a/net/core/flow_dissector.c
+++ b/net/core/flow_dissector.c
@@ -8,6 +8,7 @@
 #include <linux/filter.h>
 #include <net/dsa.h>
 #include <net/dst_metadata.h>
+#include <net/fou.h>
 #include <net/ip.h>
 #include <net/ipv6.h>
 #include <net/gre.h>
@@ -855,6 +856,7 @@ __skb_flow_dissect_udp(const struct sk_buff *skb, const struct net *net,
 		       u8 *p_ip_proto, int base_nhoff, unsigned int flags,
 		       unsigned int num_hdrs)
 {
+	__u8 encap_type, fou_protocol;
 	enum flow_dissect_ret ret;
 	struct udphdr _udph;
 	int nhoff;
@@ -905,6 +907,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;
@@ -943,6 +948,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;
@@ -957,6 +965,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
-- 
2.34.1


  parent reply	other threads:[~2024-08-23 20:16 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-23 20:15 [PATCH net-next v4 00/13] flow_dissector: Dissect UDP encapsulation protocols Tom Herbert
2024-08-23 20:15 ` [PATCH net-next v4 01/13] ipv6: Add udp6_lib_lookup to IPv6 stubs Tom Herbert
2024-08-23 20:15 ` [PATCH net-next v4 02/13] flow_dissector: Parse ETH_P_TEB and move out of GRE Tom Herbert
2024-08-23 20:15 ` [PATCH net-next v4 03/13] udp_encaps: Add new UDP_ENCAP constants Tom Herbert
2024-08-23 20:15 ` [PATCH net-next v4 04/13] udp_encaps: Set proper UDP_ENCAP types in tunnel setup Tom Herbert
2024-08-23 20:15 ` [PATCH net-next v4 05/13] flow_dissector: UDP encap infrastructure Tom Herbert
2024-08-24 19:18   ` Simon Horman
2024-08-23 20:15 ` [PATCH net-next v4 06/13] flow_dissector: Parse vxlan in UDP Tom Herbert
2024-08-23 20:15 ` Tom Herbert [this message]
2024-08-23 20:15 ` [PATCH net-next v4 08/13] flow_dissector: Parse ESP, L2TP, and SCTP " Tom Herbert
2024-08-23 20:15 ` [PATCH net-next v4 09/13] flow_dissector: Parse Geneve " Tom Herbert
2024-08-23 20:15 ` [PATCH net-next v4 10/13] flow_dissector: Parse GUE " Tom Herbert
2024-08-23 20:15 ` [PATCH net-next v4 11/13] gtp: Move gtp_parse_exthdrs into net/gtp.h Tom Herbert
2024-08-23 20:15 ` [PATCH net-next v4 12/13] flow_dissector: Parse gtp in UDP Tom Herbert
2024-08-23 20:15 ` [PATCH net-next v4 13/13] flow_dissector: Add case in ipproto switch for NEXTHDR_NONE Tom Herbert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240823201557.1794985-8-tom@herbertland.com \
    --to=tom@herbertland.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=felipe@sipanda.io \
    --cc=kuba@kernel.org \
    --cc=laforge@gnumonks.org \
    --cc=netdev@vger.kernel.org \
    --cc=pablo@netfilter.org \
    --cc=willemb@google.com \
    --cc=willemdebruijn.kernel@gmail.com \
    --cc=xeb@mail.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).