diff mbox series

[ipsec-next,v1,5/7] bpf: selftests: test_tunnel: Use vmlinux.h declarations

Message ID c5f6a6686e1472e17014f5d015c8dacade9f053e.1700676682.git.dxu@dxuuu.xyz (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series Add bpf_xdp_get_xfrm_state() kfunc | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Validate matrix.py
bpf/vmtest-bpf-next-VM_Test-13 fail Logs for x86_64-llvm-16 / build / build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-4 success Logs for aarch64-gcc / test
bpf/vmtest-bpf-next-PR fail PR summary
bpf/vmtest-bpf-next-VM_Test-6 fail Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-3 fail Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-7 success Logs for s390x-gcc / test
bpf/vmtest-bpf-next-VM_Test-8 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-5 success Logs for aarch64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-10 fail Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-12 success Logs for x86_64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-11 success Logs for x86_64-gcc / test
bpf/vmtest-bpf-next-VM_Test-14 success Logs for x86_64-llvm-16 / test
bpf/vmtest-bpf-next-VM_Test-15 success Logs for x86_64-llvm-16 / veristat
netdev/series_format success Posting correctly formatted
netdev/codegen success Generated files up to date
netdev/tree_selection success Guessed tree name to be net-next, async
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/cc_maintainers warning 2 maintainers not CCed: cehrig@cloudflare.com eyal.birger@gmail.com
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch warning WARNING: Possible repeated word: 'Antony'
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Daniel Xu Nov. 22, 2023, 6:20 p.m. UTC
vmlinux.h declarations are more ergnomic, especially when working with
kfuncs. The uapi headers are often incomplete for kfunc definitions.

Co-developed-by: Antony Antony <antony.antony@secunet.com>
Signed-off-by: Antony Antony <antony.antony@secunet.com>
Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
---
 .../selftests/bpf/progs/bpf_tracing_net.h     |  1 +
 .../selftests/bpf/progs/test_tunnel_kern.c    | 48 ++++---------------
 2 files changed, 9 insertions(+), 40 deletions(-)

Comments

Yonghong Song Nov. 26, 2023, 12:34 a.m. UTC | #1
On 11/22/23 1:20 PM, Daniel Xu wrote:
> vmlinux.h declarations are more ergnomic, especially when working with
> kfuncs. The uapi headers are often incomplete for kfunc definitions.
>
> Co-developed-by: Antony Antony <antony.antony@secunet.com>
> Signed-off-by: Antony Antony <antony.antony@secunet.com>
> Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
> ---
>   .../selftests/bpf/progs/bpf_tracing_net.h     |  1 +
>   .../selftests/bpf/progs/test_tunnel_kern.c    | 48 ++++---------------
>   2 files changed, 9 insertions(+), 40 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/progs/bpf_tracing_net.h b/tools/testing/selftests/bpf/progs/bpf_tracing_net.h
> index 0b793a102791..1bdc680b0e0e 100644
> --- a/tools/testing/selftests/bpf/progs/bpf_tracing_net.h
> +++ b/tools/testing/selftests/bpf/progs/bpf_tracing_net.h
> @@ -26,6 +26,7 @@
>   #define IPV6_AUTOFLOWLABEL	70
>   
>   #define TC_ACT_UNSPEC		(-1)
> +#define TC_ACT_OK		0
>   #define TC_ACT_SHOT		2
>   
>   #define SOL_TCP			6
> diff --git a/tools/testing/selftests/bpf/progs/test_tunnel_kern.c b/tools/testing/selftests/bpf/progs/test_tunnel_kern.c
> index f66af753bbbb..3065a716544d 100644
> --- a/tools/testing/selftests/bpf/progs/test_tunnel_kern.c
> +++ b/tools/testing/selftests/bpf/progs/test_tunnel_kern.c
> @@ -6,62 +6,30 @@
>    * modify it under the terms of version 2 of the GNU General Public
>    * License as published by the Free Software Foundation.
>    */
> -#include <stddef.h>
> -#include <string.h>
> -#include <arpa/inet.h>
> -#include <linux/bpf.h>
> -#include <linux/if_ether.h>
> -#include <linux/if_packet.h>
> -#include <linux/if_tunnel.h>
> -#include <linux/ip.h>
> -#include <linux/ipv6.h>
> -#include <linux/icmp.h>
> -#include <linux/types.h>
> -#include <linux/socket.h>
> -#include <linux/pkt_cls.h>
> -#include <linux/erspan.h>
> -#include <linux/udp.h>
> +#include "vmlinux.h"
>   #include <bpf/bpf_helpers.h>
>   #include <bpf/bpf_endian.h>
> +#include "bpf_kfuncs.h"
> +#include "bpf_tracing_net.h"
>   
>   #define log_err(__ret) bpf_printk("ERROR line:%d ret:%d\n", __LINE__, __ret)
>   
> -#define VXLAN_UDP_PORT 4789
> +#define VXLAN_UDP_PORT		4789
> +#define ETH_P_IP		0x0800
> +#define PACKET_HOST		0
> +#define TUNNEL_CSUM		bpf_htons(0x01)
> +#define TUNNEL_KEY		bpf_htons(0x04)
>   
>   /* Only IPv4 address assigned to veth1.
>    * 172.16.1.200
>    */
>   #define ASSIGNED_ADDR_VETH1 0xac1001c8
>   
> -struct geneve_opt {
> -	__be16	opt_class;
> -	__u8	type;
> -	__u8	length:5;
> -	__u8	r3:1;
> -	__u8	r2:1;
> -	__u8	r1:1;
> -	__u8	opt_data[8]; /* hard-coded to 8 byte */
> -};
> -
>   struct vxlanhdr {
>   	__be32 vx_flags;
>   	__be32 vx_vni;
>   } __attribute__((packed));

In my particular setup, I have struct vxlanhdr defined in vmlinux.h so
I hit a compilation failure.

>   
> -struct vxlan_metadata {
> -	__u32     gbp;
> -};
> -
> -struct bpf_fou_encap {
> -	__be16 sport;
> -	__be16 dport;
> -};
> -
> -enum bpf_fou_encap_type {
> -	FOU_BPF_ENCAP_FOU,
> -	FOU_BPF_ENCAP_GUE,
> -};
> -
>   int bpf_skb_set_fou_encap(struct __sk_buff *skb_ctx,
>   			  struct bpf_fou_encap *encap, int type) __ksym;
>   int bpf_skb_get_fou_encap(struct __sk_buff *skb_ctx,
Daniel Xu Nov. 26, 2023, 4:34 a.m. UTC | #2
Hi Yonghong,

On Sat, Nov 25, 2023 at 04:34:36PM -0800, Yonghong Song wrote:
> 
> On 11/22/23 1:20 PM, Daniel Xu wrote:
> > vmlinux.h declarations are more ergnomic, especially when working with
> > kfuncs. The uapi headers are often incomplete for kfunc definitions.
> > 
> > Co-developed-by: Antony Antony <antony.antony@secunet.com>
> > Signed-off-by: Antony Antony <antony.antony@secunet.com>
> > Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
> > ---
> >   .../selftests/bpf/progs/bpf_tracing_net.h     |  1 +
> >   .../selftests/bpf/progs/test_tunnel_kern.c    | 48 ++++---------------
> >   2 files changed, 9 insertions(+), 40 deletions(-)
> > 
> > diff --git a/tools/testing/selftests/bpf/progs/bpf_tracing_net.h b/tools/testing/selftests/bpf/progs/bpf_tracing_net.h
> > index 0b793a102791..1bdc680b0e0e 100644
> > --- a/tools/testing/selftests/bpf/progs/bpf_tracing_net.h
> > +++ b/tools/testing/selftests/bpf/progs/bpf_tracing_net.h
> > @@ -26,6 +26,7 @@
> >   #define IPV6_AUTOFLOWLABEL	70
> >   #define TC_ACT_UNSPEC		(-1)
> > +#define TC_ACT_OK		0
> >   #define TC_ACT_SHOT		2
> >   #define SOL_TCP			6
> > diff --git a/tools/testing/selftests/bpf/progs/test_tunnel_kern.c b/tools/testing/selftests/bpf/progs/test_tunnel_kern.c
> > index f66af753bbbb..3065a716544d 100644
> > --- a/tools/testing/selftests/bpf/progs/test_tunnel_kern.c
> > +++ b/tools/testing/selftests/bpf/progs/test_tunnel_kern.c
> > @@ -6,62 +6,30 @@
> >    * modify it under the terms of version 2 of the GNU General Public
> >    * License as published by the Free Software Foundation.
> >    */
> > -#include <stddef.h>
> > -#include <string.h>
> > -#include <arpa/inet.h>
> > -#include <linux/bpf.h>
> > -#include <linux/if_ether.h>
> > -#include <linux/if_packet.h>
> > -#include <linux/if_tunnel.h>
> > -#include <linux/ip.h>
> > -#include <linux/ipv6.h>
> > -#include <linux/icmp.h>
> > -#include <linux/types.h>
> > -#include <linux/socket.h>
> > -#include <linux/pkt_cls.h>
> > -#include <linux/erspan.h>
> > -#include <linux/udp.h>
> > +#include "vmlinux.h"
> >   #include <bpf/bpf_helpers.h>
> >   #include <bpf/bpf_endian.h>
> > +#include "bpf_kfuncs.h"
> > +#include "bpf_tracing_net.h"
> >   #define log_err(__ret) bpf_printk("ERROR line:%d ret:%d\n", __LINE__, __ret)
> > -#define VXLAN_UDP_PORT 4789
> > +#define VXLAN_UDP_PORT		4789
> > +#define ETH_P_IP		0x0800
> > +#define PACKET_HOST		0
> > +#define TUNNEL_CSUM		bpf_htons(0x01)
> > +#define TUNNEL_KEY		bpf_htons(0x04)
> >   /* Only IPv4 address assigned to veth1.
> >    * 172.16.1.200
> >    */
> >   #define ASSIGNED_ADDR_VETH1 0xac1001c8
> > -struct geneve_opt {
> > -	__be16	opt_class;
> > -	__u8	type;
> > -	__u8	length:5;
> > -	__u8	r3:1;
> > -	__u8	r2:1;
> > -	__u8	r1:1;
> > -	__u8	opt_data[8]; /* hard-coded to 8 byte */
> > -};
> > -
> >   struct vxlanhdr {
> >   	__be32 vx_flags;
> >   	__be32 vx_vni;
> >   } __attribute__((packed));
> 
> In my particular setup, I have struct vxlanhdr defined in vmlinux.h so
> I hit a compilation failure.

Yeah, saw the same error in CI (the emails are nice btw). Looks like
vxlanhdr isn't even being used in this selftest. I've deleted it for v2.

Thanks,
Daniel
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/progs/bpf_tracing_net.h b/tools/testing/selftests/bpf/progs/bpf_tracing_net.h
index 0b793a102791..1bdc680b0e0e 100644
--- a/tools/testing/selftests/bpf/progs/bpf_tracing_net.h
+++ b/tools/testing/selftests/bpf/progs/bpf_tracing_net.h
@@ -26,6 +26,7 @@ 
 #define IPV6_AUTOFLOWLABEL	70
 
 #define TC_ACT_UNSPEC		(-1)
+#define TC_ACT_OK		0
 #define TC_ACT_SHOT		2
 
 #define SOL_TCP			6
diff --git a/tools/testing/selftests/bpf/progs/test_tunnel_kern.c b/tools/testing/selftests/bpf/progs/test_tunnel_kern.c
index f66af753bbbb..3065a716544d 100644
--- a/tools/testing/selftests/bpf/progs/test_tunnel_kern.c
+++ b/tools/testing/selftests/bpf/progs/test_tunnel_kern.c
@@ -6,62 +6,30 @@ 
  * modify it under the terms of version 2 of the GNU General Public
  * License as published by the Free Software Foundation.
  */
-#include <stddef.h>
-#include <string.h>
-#include <arpa/inet.h>
-#include <linux/bpf.h>
-#include <linux/if_ether.h>
-#include <linux/if_packet.h>
-#include <linux/if_tunnel.h>
-#include <linux/ip.h>
-#include <linux/ipv6.h>
-#include <linux/icmp.h>
-#include <linux/types.h>
-#include <linux/socket.h>
-#include <linux/pkt_cls.h>
-#include <linux/erspan.h>
-#include <linux/udp.h>
+#include "vmlinux.h"
 #include <bpf/bpf_helpers.h>
 #include <bpf/bpf_endian.h>
+#include "bpf_kfuncs.h"
+#include "bpf_tracing_net.h"
 
 #define log_err(__ret) bpf_printk("ERROR line:%d ret:%d\n", __LINE__, __ret)
 
-#define VXLAN_UDP_PORT 4789
+#define VXLAN_UDP_PORT		4789
+#define ETH_P_IP		0x0800
+#define PACKET_HOST		0
+#define TUNNEL_CSUM		bpf_htons(0x01)
+#define TUNNEL_KEY		bpf_htons(0x04)
 
 /* Only IPv4 address assigned to veth1.
  * 172.16.1.200
  */
 #define ASSIGNED_ADDR_VETH1 0xac1001c8
 
-struct geneve_opt {
-	__be16	opt_class;
-	__u8	type;
-	__u8	length:5;
-	__u8	r3:1;
-	__u8	r2:1;
-	__u8	r1:1;
-	__u8	opt_data[8]; /* hard-coded to 8 byte */
-};
-
 struct vxlanhdr {
 	__be32 vx_flags;
 	__be32 vx_vni;
 } __attribute__((packed));
 
-struct vxlan_metadata {
-	__u32     gbp;
-};
-
-struct bpf_fou_encap {
-	__be16 sport;
-	__be16 dport;
-};
-
-enum bpf_fou_encap_type {
-	FOU_BPF_ENCAP_FOU,
-	FOU_BPF_ENCAP_GUE,
-};
-
 int bpf_skb_set_fou_encap(struct __sk_buff *skb_ctx,
 			  struct bpf_fou_encap *encap, int type) __ksym;
 int bpf_skb_get_fou_encap(struct __sk_buff *skb_ctx,