On 13/03/2026 23.27, Chris J Arges wrote:
diff --git a/tools/testing/selftests/net/lib/xdp_metadata.bpf.c
b/tools/testing/selftests/net/lib/xdp_metadata.bpf.c
new file mode 100644
index 000000000000..f71f59215239
--- /dev/null
+++ b/tools/testing/selftests/net/lib/xdp_metadata.bpf.c
@@ -0,0 +1,163 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <stddef.h>
+#include <linux/bpf.h>
+#include <linux/in.h>
+#include <linux/if_ether.h>
+#include <linux/ip.h>
+#include <linux/ipv6.h>
+#include <linux/udp.h>
+#include <linux/tcp.h>
+#include <bpf/bpf_endian.h>
+#include <bpf/bpf_helpers.h>
+
+enum {
+ XDP_PORT = 1,
+ XDP_PROTO = 4,
+} xdp_map_setup_keys;
+
+struct {
+ __uint(type, BPF_MAP_TYPE_ARRAY);
+ __uint(max_entries, 5);
+ __type(key, __u32);
+ __type(value, __s32);
+} map_xdp_setup SEC(".maps");
+
+/* RSS hash results: key 0 = hash, key 1 = hash type,
+ * key 2 = packet count, key 3 = error count.
+ */
+enum {
+ RSS_KEY_HASH = 0,
+ RSS_KEY_TYPE = 1,
+ RSS_KEY_PKT_CNT = 2,
+ RSS_KEY_ERR_CNT = 3,
+};
+
+struct {
+ __uint(type, BPF_MAP_TYPE_ARRAY);
+ __type(key, __u32);
+ __type(value, __u32);
+ __uint(max_entries, 4);
+} map_rss SEC(".maps");
+
+/* Mirror of enum xdp_rss_hash_type from include/net/xdp.h.
+ * Needed because the enum is not part of UAPI headers.
It is on purpose that enum is not part of UAPI headers, because BPF
progs (like this) are suppose to handle this via CO-RE.
Asking CO-RE experts (e.g. Cc Andrii), will below enum xdp_rss_hash_type
usage automatically get relocated by libbpf, based on running kernel?
(or do we need some explicit bpf_core_ calls?)
+ */
+enum xdp_rss_hash_type {
+ XDP_RSS_L3_IPV4 = 1U << 0,
+ XDP_RSS_L3_IPV6 = 1U << 1,
+ XDP_RSS_L3_DYNHDR = 1U << 2,
+ XDP_RSS_L4 = 1U << 3,
+ XDP_RSS_L4_TCP = 1U << 4,
+ XDP_RSS_L4_UDP = 1U << 5,
+ XDP_RSS_L4_SCTP = 1U << 6,
+ XDP_RSS_L4_IPSEC = 1U << 7,
+ XDP_RSS_L4_ICMP = 1U << 8,
+};
--Jesper