0001
0002
0003 #include "bpf_iter.h"
0004 #include <bpf/bpf_helpers.h>
0005
0006 char _license[] SEC("license") = "GPL";
0007
0008 __u32 map1_id = 0, map2_id = 0;
0009 __u32 map1_accessed = 0, map2_accessed = 0;
0010 __u64 map1_seqnum = 0, map2_seqnum1 = 0, map2_seqnum2 = 0;
0011
0012 volatile const __u32 print_len;
0013 volatile const __u32 ret1;
0014
0015 SEC("iter/bpf_map")
0016 int dump_bpf_map(struct bpf_iter__bpf_map *ctx)
0017 {
0018 struct seq_file *seq = ctx->meta->seq;
0019 struct bpf_map *map = ctx->map;
0020 __u64 seq_num;
0021 int i, ret = 0;
0022
0023 if (map == (void *)0)
0024 return 0;
0025
0026
0027 if (map->id != map1_id && map->id != map2_id)
0028 return 0;
0029
0030 seq_num = ctx->meta->seq_num;
0031 if (map->id == map1_id) {
0032 map1_seqnum = seq_num;
0033 map1_accessed++;
0034 }
0035
0036 if (map->id == map2_id) {
0037 if (map2_accessed == 0) {
0038 map2_seqnum1 = seq_num;
0039 if (ret1)
0040 ret = 1;
0041 } else {
0042 map2_seqnum2 = seq_num;
0043 }
0044 map2_accessed++;
0045 }
0046
0047
0048 for (i = 0; i < print_len; i++)
0049 bpf_seq_write(seq, &seq_num, sizeof(seq_num));
0050
0051 return ret;
0052 }