1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2021 Facebook */
4 #include <bpf/bpf_helpers.h>
6 char _license[] SEC("license") = "GPL";
9 __uint(type, BPF_MAP_TYPE_ARRAY);
10 __uint(max_entries, 3);
13 } arraymap SEC(".maps");
16 __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
17 __uint(max_entries, 1);
20 } percpu_map SEC(".maps");
26 const volatile int bypass_unused = 1;
29 unused_subprog(struct bpf_map *map, __u32 *key, __u64 *val,
30 struct callback_ctx *data)
37 check_array_elem(struct bpf_map *map, __u32 *key, __u64 *val,
38 struct callback_ctx *data)
42 return 1; /* stop the iteration */
50 check_percpu_elem(struct bpf_map *map, __u32 *key, __u64 *val,
51 struct callback_ctx *data)
53 cpu = bpf_get_smp_processor_id();
58 u32 arraymap_output = 0;
61 int test_pkt_access(struct __sk_buff *skb)
63 struct callback_ctx data;
66 bpf_for_each_map_elem(&arraymap, check_array_elem, &data, 0);
68 bpf_for_each_map_elem(&arraymap, unused_subprog, &data, 0);
69 arraymap_output = data.output;
71 bpf_for_each_map_elem(&percpu_map, check_percpu_elem, (void *)0, 0);