xref: /linux/tools/testing/selftests/bpf/progs/bpf_iter_map_elem.c (revision d9104cec3e8fe4b458b74709853231385779001f)
1 // SPDX-License-Identifier: GPL-2.0-only
2 
3 #include "vmlinux.h"
4 #include <bpf/bpf_tracing.h>
5 #include <bpf/bpf_helpers.h>
6 
7 char _license[] SEC("license") = "GPL";
8 
9 __u32 value_sum = 0;
10 
11 SEC("iter/bpf_map_elem")
dump_bpf_map_values(struct bpf_iter__bpf_map_elem * ctx)12 int dump_bpf_map_values(struct bpf_iter__bpf_map_elem *ctx)
13 {
14 	__u32 value = 0;
15 
16 	if (ctx->value == (void *)0)
17 		return 0;
18 
19 	bpf_probe_read_kernel(&value, sizeof(value), ctx->value);
20 	value_sum += value;
21 	return 0;
22 }
23