diff mbox series

[bpf-next,v3,21/21] selftests/bpf: check checksum state in xdp_metadata

Message ID 20230719183734.21681-22-larysa.zaremba@intel.com (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series XDP metadata via kfuncs for ice | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for bpf-next, async
netdev/apply fail Patch does not apply to bpf-next
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-2 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-3 success Logs for build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-4 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-5 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-6 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-7 success Logs for test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-8 success Logs for test_maps on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-10 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-11 success Logs for test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-12 success Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-13 success Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-14 success Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-15 success Logs for test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-16 success Logs for test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-17 success Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-18 success Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-19 success Logs for test_progs_no_alu32_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-21 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-22 success Logs for test_progs_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for test_progs_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-25 success Logs for test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-27 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-28 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-29 success Logs for veristat

Commit Message

Larysa Zaremba July 19, 2023, 6:37 p.m. UTC
Verify, whether kfunc in xdp_metadata test correctly returns partial
checksum status and offsets.

Signed-off-by: Larysa Zaremba <larysa.zaremba@intel.com>
---
 .../selftests/bpf/prog_tests/xdp_metadata.c   | 30 +++++++++++++++++++
 .../selftests/bpf/progs/xdp_metadata.c        |  6 ++++
 2 files changed, 36 insertions(+)

Comments

Stanislav Fomichev July 20, 2023, 10:14 p.m. UTC | #1
On 07/19, Larysa Zaremba wrote:
> Verify, whether kfunc in xdp_metadata test correctly returns partial
> checksum status and offsets.
> 
> Signed-off-by: Larysa Zaremba <larysa.zaremba@intel.com>

Acked-by: Stanislav Fomichev <sdf@google.com>

> ---
>  .../selftests/bpf/prog_tests/xdp_metadata.c   | 30 +++++++++++++++++++
>  .../selftests/bpf/progs/xdp_metadata.c        |  6 ++++
>  2 files changed, 36 insertions(+)
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c b/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
> index 6665cf0c59cc..c0ce66703696 100644
> --- a/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
> +++ b/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
> @@ -47,6 +47,7 @@
>  
>  #define XDP_RSS_TYPE_L4 BIT(3)
>  #define VLAN_VID_MASK 0xfff
> +#define XDP_CHECKSUM_PARTIAL BIT(3)
>  
>  struct xsk {
>  	void *umem_area;
> @@ -168,6 +169,32 @@ static void refill_rx(struct xsk *xsk, __u64 addr)
>  	}
>  }
>  
> +struct partial_csum_info {
> +	__u16 csum_start;
> +	__u16 csum_offset;
> +};
> +
> +static bool assert_checksum_ok(struct xdp_meta *meta)
> +{
> +	struct partial_csum_info *info;
> +	u32 csum_start, csum_offset;
> +
> +	if (!ASSERT_EQ(meta->rx_csum_status, XDP_CHECKSUM_PARTIAL,
> +		       "rx_csum_status"))
> +		return false;
> +
> +	csum_start = sizeof(struct ethhdr) + sizeof(struct iphdr);
> +	csum_offset = offsetof(struct udphdr, check);
> +	info = (void *)&meta->rx_csum_info;
> +
> +	if (!ASSERT_EQ(info->csum_start, csum_start, "rx csum_start"))
> +		return false;
> +	if (!ASSERT_EQ(info->csum_offset, csum_offset, "rx csum_offset"))
> +		return false;
> +
> +	return true;
> +}
> +
>  static int verify_xsk_metadata(struct xsk *xsk)
>  {
>  	const struct xdp_desc *rx_desc;
> @@ -229,6 +256,9 @@ static int verify_xsk_metadata(struct xsk *xsk)
>  	if (!ASSERT_EQ(meta->rx_vlan_proto, VLAN_PID, "rx_vlan_proto"))
>  		return -1;
>  
> +	if (!assert_checksum_ok(meta))
> +		return -1;
> +
>  	xsk_ring_cons__release(&xsk->rx, 1);
>  	refill_rx(xsk, comp_addr);
>  
> diff --git a/tools/testing/selftests/bpf/progs/xdp_metadata.c b/tools/testing/selftests/bpf/progs/xdp_metadata.c
> index d3111649170e..e79667a0726e 100644
> --- a/tools/testing/selftests/bpf/progs/xdp_metadata.c
> +++ b/tools/testing/selftests/bpf/progs/xdp_metadata.c
> @@ -26,6 +26,9 @@ extern int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, __u32 *hash,
>  extern int bpf_xdp_metadata_rx_vlan_tag(const struct xdp_md *ctx,
>  					__u16 *vlan_tci,
>  					__be16 *vlan_proto) __ksym;
> +extern int bpf_xdp_metadata_rx_csum(const struct xdp_md *ctx,
> +				    enum xdp_csum_status *csum_status,
> +				    union xdp_csum_info *csum_info) __ksym;
>  
>  SEC("xdp")
>  int rx(struct xdp_md *ctx)
> @@ -62,6 +65,9 @@ int rx(struct xdp_md *ctx)
>  	bpf_xdp_metadata_rx_hash(ctx, &meta->rx_hash, &meta->rx_hash_type);
>  	bpf_xdp_metadata_rx_vlan_tag(ctx, &meta->rx_vlan_tci, &meta->rx_vlan_proto);
>  
> +	bpf_xdp_metadata_rx_csum(ctx, &meta->rx_csum_status,
> +				 (void *)&meta->rx_csum_info);
> +
>  	return bpf_redirect_map(&xsk, ctx->rx_queue_index, XDP_PASS);
>  }
>  
> -- 
> 2.41.0
>
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c b/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
index 6665cf0c59cc..c0ce66703696 100644
--- a/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
@@ -47,6 +47,7 @@ 
 
 #define XDP_RSS_TYPE_L4 BIT(3)
 #define VLAN_VID_MASK 0xfff
+#define XDP_CHECKSUM_PARTIAL BIT(3)
 
 struct xsk {
 	void *umem_area;
@@ -168,6 +169,32 @@  static void refill_rx(struct xsk *xsk, __u64 addr)
 	}
 }
 
+struct partial_csum_info {
+	__u16 csum_start;
+	__u16 csum_offset;
+};
+
+static bool assert_checksum_ok(struct xdp_meta *meta)
+{
+	struct partial_csum_info *info;
+	u32 csum_start, csum_offset;
+
+	if (!ASSERT_EQ(meta->rx_csum_status, XDP_CHECKSUM_PARTIAL,
+		       "rx_csum_status"))
+		return false;
+
+	csum_start = sizeof(struct ethhdr) + sizeof(struct iphdr);
+	csum_offset = offsetof(struct udphdr, check);
+	info = (void *)&meta->rx_csum_info;
+
+	if (!ASSERT_EQ(info->csum_start, csum_start, "rx csum_start"))
+		return false;
+	if (!ASSERT_EQ(info->csum_offset, csum_offset, "rx csum_offset"))
+		return false;
+
+	return true;
+}
+
 static int verify_xsk_metadata(struct xsk *xsk)
 {
 	const struct xdp_desc *rx_desc;
@@ -229,6 +256,9 @@  static int verify_xsk_metadata(struct xsk *xsk)
 	if (!ASSERT_EQ(meta->rx_vlan_proto, VLAN_PID, "rx_vlan_proto"))
 		return -1;
 
+	if (!assert_checksum_ok(meta))
+		return -1;
+
 	xsk_ring_cons__release(&xsk->rx, 1);
 	refill_rx(xsk, comp_addr);
 
diff --git a/tools/testing/selftests/bpf/progs/xdp_metadata.c b/tools/testing/selftests/bpf/progs/xdp_metadata.c
index d3111649170e..e79667a0726e 100644
--- a/tools/testing/selftests/bpf/progs/xdp_metadata.c
+++ b/tools/testing/selftests/bpf/progs/xdp_metadata.c
@@ -26,6 +26,9 @@  extern int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, __u32 *hash,
 extern int bpf_xdp_metadata_rx_vlan_tag(const struct xdp_md *ctx,
 					__u16 *vlan_tci,
 					__be16 *vlan_proto) __ksym;
+extern int bpf_xdp_metadata_rx_csum(const struct xdp_md *ctx,
+				    enum xdp_csum_status *csum_status,
+				    union xdp_csum_info *csum_info) __ksym;
 
 SEC("xdp")
 int rx(struct xdp_md *ctx)
@@ -62,6 +65,9 @@  int rx(struct xdp_md *ctx)
 	bpf_xdp_metadata_rx_hash(ctx, &meta->rx_hash, &meta->rx_hash_type);
 	bpf_xdp_metadata_rx_vlan_tag(ctx, &meta->rx_vlan_tci, &meta->rx_vlan_proto);
 
+	bpf_xdp_metadata_rx_csum(ctx, &meta->rx_csum_status,
+				 (void *)&meta->rx_csum_info);
+
 	return bpf_redirect_map(&xsk, ctx->rx_queue_index, XDP_PASS);
 }