[RFC bpf-next 21/23] selftests/bpf: check checksum state in xdp_metadata

Larysa Zaremba
2023-08-24T19:34:41Z

Verify, whether kfunc in xdp_metadata test correctly represent veth
metadata state.

Signed-off-by: Larysa Zaremba <larysa.zaremba@intel.com>
---
tools/testing/selftests/bpf/prog_tests/xdp_metadata.c | 3 +++
tools/testing/selftests/bpf/progs/xdp_metadata.c | 11 +++++++++++
2 files changed, 14 insertions(+)

diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c b/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
index 61e1b073a4b2..aeb2701efba5 100644
--- a/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
@@ -228,6 +228,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_EQ(meta->rx_csum_status, XDP_CHECKSUM_MAGIC, "rx_csum_status"))
+ 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 f3db5cef4726..766477e0a31d 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,
+ __wsum *csum) __ksym;

SEC("xdp")
int rx(struct xdp_md *ctx)
@@ -63,6 +66,14 @@ int rx(struct xdp_md *ctx)
bpf_xdp_metadata_rx_vlan_tag(ctx, &meta->rx_vlan_tci,
&meta->rx_vlan_proto);

+ /* This is supposed to fail on veth, so tell userspace
+ * everything is OK by passing a magic status.
+ */
+ ret = bpf_xdp_metadata_rx_csum(ctx, &meta->rx_csum_status,
+ &meta->rx_csum);
+ if (ret)
+ meta->rx_csum_status = XDP_CHECKSUM_MAGIC;
+
return bpf_redirect_map(&xsk, ctx->rx_queue_index, XDP_PASS);
}

--
2.41.0