Skip to content

Commit 9f40de5

Browse files
qmonnetkernel-patches-bot
authored andcommitted
Bpftool has a number of features that can be included or left aside
during compilation. This includes: - Support for libbfd, providing the disassembler for JIT-compiled programs. - Support for BPF skeletons, used for profiling programs or iterating on the PIDs of processes associated with BPF objects. In order to make it easy for users to understand what features were compiled for a given bpftool binary, print the status of the two features above when showing the version number for bpftool ("bpftool -V" or "bpftool version"). Document this in the main manual page. Example invocations: $ bpftool version ./bpftool v5.9.0-rc1 features: libbfd, skeletons $ bpftool -p version { "version": "5.9.0-rc1", "features": { "libbfd": true, "skeletons": true } } Some other parameters are optional at compilation ("DISASM_FOUR_ARGS_SIGNATURE", LIBCAP support) but they do not impact significantly bpftool's behaviour from a user's point of view, so their status is not reported. Available commands and supported program types depend on the version number, and are therefore not reported either. Note that they are already available, albeit without JSON, via bpftool's help messages. v3: - Use a simple list instead of boolean values for plain output. v2: - Fix JSON (object instead or array for the features). Signed-off-by: Quentin Monnet <quentin@isovalent.com> --- tools/bpf/bpftool/Documentation/bpftool.rst | 8 ++++- tools/bpf/bpftool/main.c | 33 +++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-)
1 parent 1ee29b5 commit 9f40de5

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

tools/bpf/bpftool/Documentation/bpftool.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,13 @@ OPTIONS
5050
Print short help message (similar to **bpftool help**).
5151

5252
-V, --version
53-
Print version number (similar to **bpftool version**).
53+
Print version number (similar to **bpftool version**), and
54+
optional features that were included when bpftool was
55+
compiled. Optional features include linking against libbfd to
56+
provide the disassembler for JIT-ted programs (**bpftool prog
57+
dump jited**) and usage of BPF skeletons (some features like
58+
**bpftool prog profile** or showing pids associated to BPF
59+
objects may rely on it).
5460

5561
-j, --json
5662
Generate JSON output. For commands that cannot produce JSON, this

tools/bpf/bpftool/main.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,42 @@ static int do_help(int argc, char **argv)
7070

7171
static int do_version(int argc, char **argv)
7272
{
73+
#ifdef HAVE_LIBBFD_SUPPORT
74+
const bool has_libbfd = true;
75+
#else
76+
const bool has_libbfd = false;
77+
#endif
78+
#ifdef BPFTOOL_WITHOUT_SKELETONS
79+
const bool has_skeletons = false;
80+
#else
81+
const bool has_skeletons = true;
82+
#endif
83+
7384
if (json_output) {
74-
jsonw_start_object(json_wtr);
85+
jsonw_start_object(json_wtr);/* root object */
86+
7587
jsonw_name(json_wtr, "version");
7688
jsonw_printf(json_wtr, "\"%s\"", BPFTOOL_VERSION);
77-
jsonw_end_object(json_wtr);
89+
90+
jsonw_name(json_wtr, "features");
91+
jsonw_start_object(json_wtr);/* features */
92+
jsonw_bool_field(json_wtr, "libbfd", has_libbfd);
93+
jsonw_bool_field(json_wtr, "skeletons", has_skeletons);
94+
jsonw_end_object(json_wtr);/* features */
95+
96+
jsonw_end_object(json_wtr);/* root object */
7897
} else {
98+
unsigned int nb_features = 0;
99+
79100
printf("%s v%s\n", bin_name, BPFTOOL_VERSION);
101+
printf("features:");
102+
if (has_libbfd) {
103+
printf(" libbfd");
104+
nb_features++;
105+
}
106+
if (has_skeletons)
107+
printf("%s skeletons", nb_features++ ? "," : "");
108+
printf("\n");
80109
}
81110
return 0;
82111
}

0 commit comments

Comments
 (0)