summaryrefslogtreecommitdiffstats
path: root/lib/libxdp/xsk_def_xdp_prog_5.3.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 07:10:00 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 07:10:00 +0000
commit4ba2b326284765e942044db13a7f0dae702bec93 (patch)
treecbdfaec33eed4f3a970c54cd10e8ddfe3003b3b1 /lib/libxdp/xsk_def_xdp_prog_5.3.c
parentInitial commit. (diff)
downloadxdp-tools-upstream.tar.xz
xdp-tools-upstream.zip
Adding upstream version 1.3.1.upstream/1.3.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/libxdp/xsk_def_xdp_prog_5.3.c')
-rw-r--r--lib/libxdp/xsk_def_xdp_prog_5.3.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/libxdp/xsk_def_xdp_prog_5.3.c b/lib/libxdp/xsk_def_xdp_prog_5.3.c
new file mode 100644
index 0000000..7973477
--- /dev/null
+++ b/lib/libxdp/xsk_def_xdp_prog_5.3.c
@@ -0,0 +1,49 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#include <linux/bpf.h>
+#include <bpf/bpf_helpers.h>
+#include <xdp/xdp_helpers.h>
+
+#include "xsk_def_xdp_prog.h"
+
+#define DEFAULT_QUEUE_IDS 64
+
+struct {
+ __uint(type, BPF_MAP_TYPE_XSKMAP);
+ __uint(key_size, sizeof(int));
+ __uint(value_size, sizeof(int));
+ __uint(max_entries, DEFAULT_QUEUE_IDS);
+} xsks_map SEC(".maps");
+
+struct {
+ __uint(priority, 20);
+ __uint(XDP_PASS, 1);
+} XDP_RUN_CONFIG(xsk_def_prog);
+
+/* Program refcount, in order to work properly,
+ * must be declared before any other global variables
+ * and initialized with '1'.
+ */
+volatile int refcnt = 1;
+
+/* This is the program for 5.3 kernels and older. */
+SEC("xdp")
+int xsk_def_prog(struct xdp_md *ctx)
+{
+ int index = ctx->rx_queue_index;
+
+ /* Make sure refcount is referenced by the program */
+ if (!refcnt)
+ return XDP_PASS;
+
+ /* A set entry here means that the corresponding queue_id
+ * has an active AF_XDP socket bound to it.
+ */
+ if (bpf_map_lookup_elem(&xsks_map, &index))
+ return bpf_redirect_map(&xsks_map, index, 0);
+ return XDP_PASS;
+
+}
+
+char _license[] SEC("license") = "GPL";
+__uint(xsk_prog_version, XSK_PROG_VERSION) SEC(XDP_METADATA_SECTION);