From 4ba2b326284765e942044db13a7f0dae702bec93 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 09:10:00 +0200 Subject: Adding upstream version 1.3.1. Signed-off-by: Daniel Baumann --- xdp-bench/xdp_basic.bpf.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 xdp-bench/xdp_basic.bpf.c (limited to 'xdp-bench/xdp_basic.bpf.c') 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 +* + * 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 +#include +#include +#include +#include + +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"; -- cgit v1.2.3