2019-01-21 22:06 UTC+0900 ~ Taeung Song <treeze.tae...@gmail.com> > We need to let users check their wrong ELF section name > with proper ELF section names when failed to get a prog/attach type from it. > Because users can't realize libbpf guess prog/attach types from > given ELF section names. > For example, when a 'cgroup' section name of a BPF program is used, > show available ELF section names(types). > > Before: > > $ bpftool prog load bpf-prog.o /sys/fs/bpf/prog1 > Error: failed to guess program type based on ELF section name cgroup > > After: > > libbpf: failed to guess program type based on ELF section name 'cgroup' > libbpf: supported section(type) names are: socket kprobe/ kretprobe/ > classifier action tracepoint/ raw_tracepoint/ xdp perf_event lwt_in lwt_out > lwt_xmit lwt_seg6local cgroup_skb/ingress cgroup_skb/egress cgroup/skb > cgroup/sock cgroup/post_bind4 cgroup/post_bind6 cgroup/dev sockops > sk_skb/stream_parser sk_skb/stream_verdict sk_skb sk_msg lirc_mode2 > flow_dissector cgroup/bind4 cgroup/bind6 cgroup/connect4 cgroup/connect6 > cgroup/sendmsg4 cgroup/sendmsg6 > > Cc: Quentin Monnet <quentin.mon...@netronome.com> > Cc: Jakub Kicinski <jakub.kicin...@netronome.com> > Cc: Andrey Ignatov <r...@fb.com> > Signed-off-by: Taeung Song <treeze.tae...@gmail.com>
Thanks for the modifications! This version looks good to me. Reviewed-by: Quentin Monnet <quentin.mon...@netronome.com> > --- > tools/bpf/bpftool/prog.c | 10 ++-- > tools/lib/bpf/libbpf.c | 46 ++++++++++++++++++- > .../selftests/bpf/test_socket_cookie.c | 4 +- > 3 files changed, 48 insertions(+), 12 deletions(-) > > diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c > index 2d1bb7d6ff51..0640e9bc0ada 100644 > --- a/tools/bpf/bpftool/prog.c > +++ b/tools/bpf/bpftool/prog.c > @@ -2682,12 +2711,20 @@ int libbpf_prog_type_by_name(const char *name, enum > bpf_prog_type *prog_type, > *expected_attach_type = section_names[i].expected_attach_type; > return 0; > } > + pr_warning("failed to guess program type based on ELF section name > '%s'\n", name); > + type_names = libbpf_get_type_names(false); > + if (type_names != NULL) { For next time: No need for the "!= NULL" part here (just checking on "if (type_names)" is enough). But don't respin your series just for that :). > + pr_info("supported section(type) names are:%s\n", type_names); > + free(type_names); > + } > + > return -EINVAL; > } > > int libbpf_attach_type_by_name(const char *name, > enum bpf_attach_type *attach_type) > { > + char *type_names; > int i; > > if (!name)