1 // SPDX-License-Identifier: GPL-2.0
4 #include "xdp_metadata.h"
5 #include <bpf/bpf_helpers.h>
6 #include <bpf/bpf_endian.h>
9 __uint(type, BPF_MAP_TYPE_XSKMAP);
10 __uint(max_entries, 4);
16 __uint(type, BPF_MAP_TYPE_PROG_ARRAY);
17 __uint(max_entries, 1);
20 } prog_arr SEC(".maps");
22 extern int bpf_xdp_metadata_rx_timestamp(const struct xdp_md *ctx,
23 __u64 *timestamp) __ksym;
24 extern int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, __u32 *hash,
25 enum xdp_rss_hash_type *rss_type) __ksym;
28 int rx(struct xdp_md *ctx)
30 void *data, *data_meta;
31 struct xdp_meta *meta;
35 /* Reserve enough for all custom metadata. */
37 ret = bpf_xdp_adjust_meta(ctx, -(int)sizeof(struct xdp_meta));
41 data = (void *)(long)ctx->data;
42 data_meta = (void *)(long)ctx->data_meta;
44 if (data_meta + sizeof(struct xdp_meta) > data)
49 /* Export metadata. */
51 /* We expect veth bpf_xdp_metadata_rx_timestamp to return 0 HW
52 * timestamp, so put some non-zero value into AF_XDP frame for
55 bpf_xdp_metadata_rx_timestamp(ctx, ×tamp);
57 meta->rx_timestamp = 1;
59 bpf_xdp_metadata_rx_hash(ctx, &meta->rx_hash, &meta->rx_hash_type);
61 return bpf_redirect_map(&xsk, ctx->rx_queue_index, XDP_PASS);
64 char _license[] SEC("license") = "GPL";