0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #include "vmlinux.h"
0014 #include "xdp_sample.bpf.h"
0015 #include "xdp_sample_shared.h"
0016
0017 const volatile int ifindex_out;
0018
0019 SEC("xdp")
0020 int xdp_redirect_prog(struct xdp_md *ctx)
0021 {
0022 void *data_end = (void *)(long)ctx->data_end;
0023 void *data = (void *)(long)ctx->data;
0024 u32 key = bpf_get_smp_processor_id();
0025 struct ethhdr *eth = data;
0026 struct datarec *rec;
0027 u64 nh_off;
0028
0029 nh_off = sizeof(*eth);
0030 if (data + nh_off > data_end)
0031 return XDP_DROP;
0032
0033 rec = bpf_map_lookup_elem(&rx_cnt, &key);
0034 if (!rec)
0035 return XDP_PASS;
0036 NO_TEAR_INC(rec->processed);
0037
0038 swap_src_dst_mac(data);
0039 return bpf_redirect(ifindex_out, 0);
0040 }
0041
0042
0043 SEC("xdp")
0044 int xdp_redirect_dummy_prog(struct xdp_md *ctx)
0045 {
0046 return XDP_PASS;
0047 }
0048
0049 char _license[] SEC("license") = "GPL";