1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2020 Facebook */
4 #include <bpf/bpf_helpers.h>
5 #include <bpf/bpf_core_read.h>
7 #pragma clang attribute push (__attribute__((preserve_access_index)), apply_to = record)
21 struct bpf_iter__bpf_map {
22 struct bpf_iter_meta *meta;
36 struct btf_type **types;
37 struct btf_header hdr;
43 const char *attach_func_name;
44 struct bpf_prog *dst_prog;
45 struct bpf_func_info *func_info;
50 struct bpf_prog_aux *aux;
53 struct bpf_iter__bpf_prog {
54 struct bpf_iter_meta *meta;
55 struct bpf_prog *prog;
57 #pragma clang attribute pop
59 static const char *get_name(struct btf *btf, long btf_id, const char *fallback)
61 struct btf_type **types, *t;
62 unsigned int name_off;
69 bpf_probe_read_kernel(&t, sizeof(t), types + btf_id);
70 name_off = BPF_CORE_READ(t, name_off);
71 if (name_off >= btf->hdr.str_len)
73 return str + name_off;
76 __s64 bpf_map_sum_elem_count(struct bpf_map *map) __ksym;
79 int dump_bpf_map(struct bpf_iter__bpf_map *ctx)
81 struct seq_file *seq = ctx->meta->seq;
82 __u64 seq_num = ctx->meta->seq_num;
83 struct bpf_map *map = ctx->map;
89 BPF_SEQ_PRINTF(seq, " id name max_entries cur_entries\n");
91 BPF_SEQ_PRINTF(seq, "%4u %-16s %10d %10lld\n",
92 map->id, map->name, map->max_entries,
93 bpf_map_sum_elem_count(map));
99 int dump_bpf_prog(struct bpf_iter__bpf_prog *ctx)
101 struct seq_file *seq = ctx->meta->seq;
102 __u64 seq_num = ctx->meta->seq_num;
103 struct bpf_prog *prog = ctx->prog;
104 struct bpf_prog_aux *aux;
111 BPF_SEQ_PRINTF(seq, " id name attached\n");
113 BPF_SEQ_PRINTF(seq, "%4u %-16s %s %s\n", aux->id,
114 get_name(aux->btf, aux->func_info[0].type_id, aux->name),
115 aux->attach_func_name, aux->dst_prog->aux->name);
118 char LICENSE[] SEC("license") = "GPL";