]> Git Repo - linux.git/blob - tools/testing/selftests/bpf/progs/test_xdp_with_cpumap_helpers.c
Linux 6.14-rc3
[linux.git] / tools / testing / selftests / bpf / progs / test_xdp_with_cpumap_helpers.c
1 // SPDX-License-Identifier: GPL-2.0
2
3 #include <linux/bpf.h>
4 #include <bpf/bpf_helpers.h>
5
6 #define IFINDEX_LO      1
7
8 struct {
9         __uint(type, BPF_MAP_TYPE_CPUMAP);
10         __uint(key_size, sizeof(__u32));
11         __uint(value_size, sizeof(struct bpf_cpumap_val));
12         __uint(max_entries, 4);
13 } cpu_map SEC(".maps");
14
15 __u32 redirect_count = 0;
16
17 SEC("xdp")
18 int xdp_redir_prog(struct xdp_md *ctx)
19 {
20         return bpf_redirect_map(&cpu_map, 0, 0);
21 }
22
23 SEC("xdp")
24 int xdp_dummy_prog(struct xdp_md *ctx)
25 {
26         return XDP_PASS;
27 }
28
29 SEC("xdp/cpumap")
30 int xdp_dummy_cm(struct xdp_md *ctx)
31 {
32         if (bpf_get_smp_processor_id() == 0)
33                 redirect_count++;
34
35         if (ctx->ingress_ifindex == IFINDEX_LO)
36                 return XDP_DROP;
37
38         return XDP_PASS;
39 }
40
41 SEC("xdp.frags/cpumap")
42 int xdp_dummy_cm_frags(struct xdp_md *ctx)
43 {
44         return XDP_PASS;
45 }
46
47 char _license[] SEC("license") = "GPL";
This page took 0.03382 seconds and 4 git commands to generate.