bpftool: Translate prog_id to its bpf prog_name
authorMartin KaFai Lau <kafai@fb.com>
Wed, 18 Mar 2020 17:16:50 +0000 (10:16 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 20 Mar 2020 14:51:35 +0000 (15:51 +0100)
commitd5ae04da34a213cc518558ecd25af0f609428560
tree7f9647bbdcef022552275ecb575a2e8b86004447
parent30255d317579e93ca3ecf7f4ab953094123e4a8c
bpftool: Translate prog_id to its bpf prog_name

The kernel struct_ops obj has kernel's func ptrs implemented by bpf_progs.
The bpf prog_id is stored as the value of the func ptr for introspection
purpose.  In the latter patch, a struct_ops dump subcmd will be added
to introspect these func ptrs.  It is desired to print the actual bpf
prog_name instead of only printing the prog_id.

Since struct_ops is the only usecase storing prog_id in the func ptr,
this patch adds a prog_id_as_func_ptr bool (default is false) to
"struct btf_dumper" in order not to mis-interpret the ptr value
for the other existing use-cases.

While printing a func_ptr as a bpf prog_name,
this patch also prefix the bpf prog_name with the ptr's func_proto.
[ Note that it is the ptr's func_proto instead of the bpf prog's
  func_proto ]
It reuses the current btf_dump_func() to obtain the ptr's func_proto
string.

Here is an example from the bpf_cubic.c:
"void (struct sock *, u32, u32) bictcp_cong_avoid/prog_id:140"

Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Quentin Monnet <quentin@isovalent.com>
Link: https://lore.kernel.org/bpf/20200318171650.129252-1-kafai@fb.com
tools/bpf/bpftool/btf_dumper.c
tools/bpf/bpftool/main.h