1 #include "vmlinux.h"
2 
3 #include <bpf/bpf_core_read.h>
4 #include <bpf/bpf_helpers.h>
5 
6 SEC("iter/bpf_map_elem")
map_iter(struct bpf_iter__bpf_map_elem * ctx)7 int map_iter(struct bpf_iter__bpf_map_elem *ctx) {
8   struct seq_file *seq = ctx->meta->seq;
9   __u32 seq_num = ctx->meta->seq_num;
10   struct bpf_map *map = ctx->map;
11   __u32 *key = ctx->key;
12   __u64 *value = ctx->value;
13   __u32 tmp_key = 0;
14   __u64 tmp_val = 0;
15 
16   if (seq_num == 0) {
17     bpf_printk("map dump starts");
18   }
19 
20   if (key == (void *)0 || value == (void *)0) {
21     bpf_printk("map dump end");
22     return 0;
23   }
24 
25   bpf_printk("test map iter, target map: %s, key: %d", map->name, (*key));
26   bpf_seq_write(seq, key, sizeof(__u32));
27   return 0;
28 }
29 
30 char _license[] SEC("license") = "GPL";
31