0001
0002
0003 #include <linux/bpf.h>
0004 #include <bpf/bpf_helpers.h>
0005
0006 #define IFINDEX_LO 1
0007
0008 struct {
0009 __uint(type, BPF_MAP_TYPE_CPUMAP);
0010 __uint(key_size, sizeof(__u32));
0011 __uint(value_size, sizeof(struct bpf_cpumap_val));
0012 __uint(max_entries, 4);
0013 } cpu_map SEC(".maps");
0014
0015 SEC("xdp")
0016 int xdp_redir_prog(struct xdp_md *ctx)
0017 {
0018 return bpf_redirect_map(&cpu_map, 1, 0);
0019 }
0020
0021 SEC("xdp")
0022 int xdp_dummy_prog(struct xdp_md *ctx)
0023 {
0024 return XDP_PASS;
0025 }
0026
0027 SEC("xdp/cpumap")
0028 int xdp_dummy_cm(struct xdp_md *ctx)
0029 {
0030 if (ctx->ingress_ifindex == IFINDEX_LO)
0031 return XDP_DROP;
0032
0033 return XDP_PASS;
0034 }
0035
0036 SEC("xdp.frags/cpumap")
0037 int xdp_dummy_cm_frags(struct xdp_md *ctx)
0038 {
0039 return XDP_PASS;
0040 }
0041
0042 char _license[] SEC("license") = "GPL";