Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /* Copyright (c) 2016 John Fastabend <john.r.fastabend@intel.com>
0003  *
0004  * This program is free software; you can redistribute it and/or
0005  * modify it under the terms of version 2 of the GNU General Public
0006  * License as published by the Free Software Foundation.
0007  *
0008  * This program is distributed in the hope that it will be useful, but
0009  * WITHOUT ANY WARRANTY; without even the implied warranty of
0010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0011  * General Public License for more details.
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 /* Redirect require an XDP bpf_prog loaded on the TX device */
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";