On Thu, May 19, 2022 at 12:18:03AM +0000, Daniel Müller wrote: > This patch set introduces the means for querying a textual representation of > the following BPF related enum types: > - enum bpf_map_type > - enum bpf_prog_type > - enum bpf_attach_type > - enum bpf_link_type > > To make that possible, we introduce a new public function for each of the types: > libbpf_bpf_<type>_type_str. > > Having a way to query a textual representation has been asked for in the past > (by systemd, among others). Such representations can generally be useful in > tracing and logging contexts, among others. At this point, at least one client, > bpftool, maintains such a mapping manually, which is prone to get out of date as > new enum variants are introduced. libbpf is arguably best situated to keep this > list complete and up-to-date. This patch series adds BTF based tests to ensure > that exhaustiveness is upheld moving forward. > > The libbpf provided textual representation can be inferred from the > corresponding enum variant name by removing the prefix and lowercasing the > remainder. E.g., BPF_PROG_TYPE_SOCKET_FILTER -> socket_filter. Unfortunately, > bpftool does not use such a programmatic approach for some of the > bpf_attach_type variants. We decided changing its behavior to work with libbpf > representations. However, for user inputs, specifically, we do keep support for > the traditionally used names around (please see patch "bpftool: Use > libbpf_bpf_attach_type_str"). > > The patch series is structured as follows: > - for each enumeration type in {bpf_prog_type, bpf_map_type, bpf_attach_type, > bpf_link_type}: > - we first introduce the corresponding public libbpf API function > - we then add BTF based self-tests > - we lastly adjust bpftool to use the libbpf provided functionality > > Changelog: > v1 -> v2: > - adjusted bpftool to work with algorithmically determined attach types as > libbpf now uses (just removed prefix from enum name and lowercased the rest) > - adjusted tests, man page, and completion script to work with the new names > - renamed bpf_attach_type_str -> bpf_attach_type_input_str > - for input: added special cases that accept the traditionally used strings as > well > - changed 'char const *' -> 'const char *' I forgot to add the following: this patch set will need another revision in order to integrate with Andrii's https://patchwork.kernel.org/project/netdevbpf/patch/20220518185915.3529475-3-andrii@xxxxxxxxxx/ once merged. This revision is mostly send out to get more feedback for the changes to bpftool, which are rather significant. Thanks, Daniel