0001
0002 #include <linux/bpf.h>
0003 #include <bpf/bpf_helpers.h>
0004
0005 struct {
0006 __uint(type, BPF_MAP_TYPE_DEVMAP);
0007 __uint(key_size, sizeof(__u32));
0008 __uint(value_size, sizeof(struct bpf_devmap_val));
0009 __uint(max_entries, 4);
0010 } dm_ports SEC(".maps");
0011
0012 SEC("xdp")
0013 int xdp_redir_prog(struct xdp_md *ctx)
0014 {
0015 return bpf_redirect_map(&dm_ports, 1, 0);
0016 }
0017
0018
0019
0020
0021 SEC("xdp")
0022 int xdp_dummy_prog(struct xdp_md *ctx)
0023 {
0024 return XDP_PASS;
0025 }
0026
0027
0028
0029
0030 SEC("xdp/devmap")
0031 int xdp_dummy_dm(struct xdp_md *ctx)
0032 {
0033 char fmt[] = "devmap redirect: dev %u -> dev %u len %u\n";
0034 void *data_end = (void *)(long)ctx->data_end;
0035 void *data = (void *)(long)ctx->data;
0036 unsigned int len = data_end - data;
0037
0038 bpf_trace_printk(fmt, sizeof(fmt),
0039 ctx->ingress_ifindex, ctx->egress_ifindex, len);
0040
0041 return XDP_PASS;
0042 }
0043
0044 SEC("xdp.frags/devmap")
0045 int xdp_dummy_dm_frags(struct xdp_md *ctx)
0046 {
0047 return XDP_PASS;
0048 }
0049
0050 char _license[] SEC("license") = "GPL";