summaryrefslogtreecommitdiffstats
path: root/xdp-bench/xdp_basic.bpf.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 /xdp-bench/xdp_basic.bpf.c
parentInitial commit. (diff)
downloadxdp-tools-4ba2b326284765e942044db13a7f0dae702bec93.tar.xz
xdp-tools-4ba2b326284765e942044db13a7f0dae702bec93.zip
Adding upstream version 1.3.1.upstream/1.3.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xdp-bench/xdp_basic.bpf.c')
-rw-r--r--xdp-bench/xdp_basic.bpf.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/xdp-bench/xdp_basic.bpf.c b/xdp-bench/xdp_basic.bpf.c
new file mode 100644
index 0000000..a803a4b
--- /dev/null
+++ b/xdp-bench/xdp_basic.bpf.c
@@ -0,0 +1,68 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2016 John Fastabend <john.r.fastabend@intel.com>
+*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ */
+#include <bpf/vmlinux.h>
+#include <xdp/xdp_sample_shared.h>
+#include <xdp/xdp_sample.bpf.h>
+#include <xdp/xdp_sample_common.bpf.h>
+#include <xdp/parsing_helpers.h>
+
+const volatile bool read_data = 0;
+const volatile bool swap_macs = 0;
+const volatile bool rxq_stats = 0;
+const volatile enum xdp_action action = XDP_DROP;
+
+SEC("xdp")
+int xdp_basic_prog(struct xdp_md *ctx)
+{
+ void *data_end = (void *)(long)ctx->data_end;
+ void *data = (void *)(long)ctx->data;
+ __u32 key = bpf_get_smp_processor_id();
+ struct datarec *rec, *rxq_rec;
+ struct ethhdr *eth = data;
+ __u64 nh_off;
+
+ nh_off = sizeof(*eth);
+ if (data + nh_off > data_end)
+ return XDP_DROP;
+
+ rec = bpf_map_lookup_elem(&rx_cnt, &key);
+ if (!rec)
+ return XDP_PASS;
+ NO_TEAR_INC(rec->processed);
+
+ if (rxq_stats) {
+ key = ctx->rx_queue_index;
+ rxq_rec = bpf_map_lookup_elem(&rxq_cnt, &key);
+ if (!rxq_rec)
+ return XDP_PASS;
+ NO_TEAR_INC(rxq_rec->processed);
+ }
+
+ if (read_data) {
+ if (bpf_ntohs(eth->h_proto) < ETH_P_802_3_MIN)
+ return XDP_ABORTED;
+
+ if (swap_macs)
+ swap_src_dst_mac(data);
+ }
+
+ if (action == XDP_DROP) {
+ NO_TEAR_INC(rec->dropped);
+ if (rxq_stats)
+ NO_TEAR_INC(rxq_rec->dropped);
+ }
+
+ return action;
+}
+
+char _license[] SEC("license") = "GPL";