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;
77 int dump_bpf_map(struct bpf_iter__bpf_map *ctx)
79 struct seq_file *seq = ctx->meta->seq;
80 __u64 seq_num = ctx->meta->seq_num;
81 struct bpf_map *map = ctx->map;
87 BPF_SEQ_PRINTF(seq, " id name max_entries\n");
89 BPF_SEQ_PRINTF(seq, "%4u %-16s%6d\n", map->id, map->name, map->max_entries);
94 int dump_bpf_prog(struct bpf_iter__bpf_prog *ctx)
96 struct seq_file *seq = ctx->meta->seq;
97 __u64 seq_num = ctx->meta->seq_num;
98 struct bpf_prog *prog = ctx->prog;
99 struct bpf_prog_aux *aux;
106 BPF_SEQ_PRINTF(seq, " id name attached\n");
108 BPF_SEQ_PRINTF(seq, "%4u %-16s %s %s\n", aux->id,
109 get_name(aux->btf, aux->func_info[0].type_id, aux->name),
110 aux->attach_func_name, aux->dst_prog->aux->name);
113 char LICENSE[] SEC("license") = "GPL";