1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2016 John Fastabend <john.r.fastabend@intel.com>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of version 2 of the GNU General Public
6 * License as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
14 #include "xdp_sample.bpf.h"
15 #include "xdp_sample_shared.h"
17 const volatile int ifindex_out;
20 int xdp_redirect_prog(struct xdp_md *ctx)
22 void *data_end = (void *)(long)ctx->data_end;
23 void *data = (void *)(long)ctx->data;
24 u32 key = bpf_get_smp_processor_id();
25 struct ethhdr *eth = data;
29 nh_off = sizeof(*eth);
30 if (data + nh_off > data_end)
33 rec = bpf_map_lookup_elem(&rx_cnt, &key);
36 NO_TEAR_INC(rec->processed);
38 swap_src_dst_mac(data);
39 return bpf_redirect(ifindex_out, 0);
42 /* Redirect require an XDP bpf_prog loaded on the TX device */
44 int xdp_redirect_dummy_prog(struct xdp_md *ctx)
49 char _license[] SEC("license") = "GPL";