1 // SPDX-License-Identifier: GPL-2.0
3 #include <bpf/bpf_helpers.h>
6 __uint(type, BPF_MAP_TYPE_DEVMAP);
7 __uint(key_size, sizeof(__u32));
8 __uint(value_size, sizeof(struct bpf_devmap_val));
9 __uint(max_entries, 4);
10 } dm_ports SEC(".maps");
13 int xdp_redir_prog(struct xdp_md *ctx)
15 return bpf_redirect_map(&dm_ports, 1, 0);
18 /* invalid program on DEVMAP entry;
19 * SEC name means expected attach type not set
22 int xdp_dummy_prog(struct xdp_md *ctx)
27 /* valid program on DEVMAP entry via SEC name;
28 * has access to egress and ingress ifindex
31 int xdp_dummy_dm(struct xdp_md *ctx)
33 char fmt[] = "devmap redirect: dev %u -> dev %u len %u\n";
34 void *data_end = (void *)(long)ctx->data_end;
35 void *data = (void *)(long)ctx->data;
36 unsigned int len = data_end - data;
38 bpf_trace_printk(fmt, sizeof(fmt),
39 ctx->ingress_ifindex, ctx->egress_ifindex, len);
44 SEC("xdp.frags/devmap")
45 int xdp_dummy_dm_frags(struct xdp_md *ctx)
50 char _license[] SEC("license") = "GPL";