53 lines · c
1// SPDX-License-Identifier: GPL-2.02/* Copyright (c) 2020 Facebook */3#include "bpf_iter.h"4#include <bpf/bpf_helpers.h>5 6char _license[] SEC("license") = "GPL";7 8__u32 map1_id = 0, map2_id = 0;9__u32 map1_accessed = 0, map2_accessed = 0;10__u64 map1_seqnum = 0, map2_seqnum1 = 0, map2_seqnum2 = 0;11 12volatile const __u32 print_len;13volatile const __u32 ret1;14 15SEC("iter/bpf_map")16int dump_bpf_map(struct bpf_iter__bpf_map *ctx)17{18 struct seq_file *seq = ctx->meta->seq;19 struct bpf_map *map = ctx->map;20 __u64 seq_num;21 int i, ret = 0;22 23 if (map == (void *)0)24 return 0;25 26 /* only dump map1_id and map2_id */27 if (map->id != map1_id && map->id != map2_id)28 return 0;29 30 seq_num = ctx->meta->seq_num;31 if (map->id == map1_id) {32 map1_seqnum = seq_num;33 map1_accessed++;34 }35 36 if (map->id == map2_id) {37 if (map2_accessed == 0) {38 map2_seqnum1 = seq_num;39 if (ret1)40 ret = 1;41 } else {42 map2_seqnum2 = seq_num;43 }44 map2_accessed++;45 }46 47 /* fill seq_file buffer */48 for (i = 0; i < (int)print_len; i++)49 bpf_seq_write(seq, &seq_num, sizeof(seq_num));50 51 return ret;52}53