xref: /linux/tools/testing/selftests/bpf/progs/freplace_progmap.c (revision fd7d598270724cc787982ea48bbe17ad383a8b7f)
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/bpf.h>
3 #include <bpf/bpf_helpers.h>
4 
5 struct {
6 	__uint(type, BPF_MAP_TYPE_CPUMAP);
7 	__type(key, __u32);
8 	__type(value, struct bpf_cpumap_val);
9 	__uint(max_entries, 1);
10 } cpu_map SEC(".maps");
11 
12 SEC("xdp/cpumap")
13 int xdp_drop_prog(struct xdp_md *ctx)
14 {
15 	return XDP_DROP;
16 }
17 
18 SEC("freplace")
19 int xdp_cpumap_prog(struct xdp_md *ctx)
20 {
21 	return bpf_redirect_map(&cpu_map, 0, XDP_PASS);
22 }
23 
24 char _license[] SEC("license") = "GPL";
25