Skip to content

Commit 4bfe3bd

Browse files
rgushchinborkmann
authored andcommitted
tools/bpftool: use version from the kernel source tree
Bpftool determines it's own version based on the kernel version, which is picked from the linux/version.h header. It's strange to use the version of the installed kernel headers, and makes much more sense to use the version of the actual source tree, where bpftool sources are. Fix this by building kernelversion target and use the resulting string as bpftool version. Example: before: $ bpftool version bpftool v4.14.6 after: $ bpftool version bpftool v4.15.0-rc3 $bpftool version --json {"version":"4.15.0-rc3"} Signed-off-by: Roman Gushchin <guro@fb.com> Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com> Cc: Alexei Starovoitov <ast@kernel.org> Cc: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent 6bb8824 commit 4bfe3bd

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

tools/bpf/bpftool/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ endif
2323

2424
LIBBPF = $(BPF_PATH)libbpf.a
2525

26+
BPFTOOL_VERSION=$(shell make --no-print-directory -sC ../../.. kernelversion)
27+
2628
$(LIBBPF): FORCE
2729
$(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) $(OUTPUT)libbpf.a FEATURES_DUMP=$(FEATURE_DUMP_EXPORT)
2830

@@ -38,6 +40,7 @@ CC = gcc
3840
CFLAGS += -O2
3941
CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wshadow
4042
CFLAGS += -D__EXPORTED_HEADERS__ -I$(srctree)/tools/include/uapi -I$(srctree)/tools/include -I$(srctree)/tools/lib/bpf -I$(srctree)/kernel/bpf/
43+
CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSION)"'
4144
LIBS = -lelf -lbfd -lopcodes $(LIBBPF)
4245

4346
INSTALL ?= install

tools/bpf/bpftool/main.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
#include <errno.h>
3939
#include <getopt.h>
4040
#include <linux/bpf.h>
41-
#include <linux/version.h>
4241
#include <stdio.h>
4342
#include <stdlib.h>
4443
#include <string.h>
@@ -95,21 +94,13 @@ static int do_help(int argc, char **argv)
9594

9695
static int do_version(int argc, char **argv)
9796
{
98-
unsigned int version[3];
99-
100-
version[0] = LINUX_VERSION_CODE >> 16;
101-
version[1] = LINUX_VERSION_CODE >> 8 & 0xf;
102-
version[2] = LINUX_VERSION_CODE & 0xf;
103-
10497
if (json_output) {
10598
jsonw_start_object(json_wtr);
10699
jsonw_name(json_wtr, "version");
107-
jsonw_printf(json_wtr, "\"%u.%u.%u\"",
108-
version[0], version[1], version[2]);
100+
jsonw_printf(json_wtr, "\"%s\"", BPFTOOL_VERSION);
109101
jsonw_end_object(json_wtr);
110102
} else {
111-
printf("%s v%u.%u.%u\n", bin_name,
112-
version[0], version[1], version[2]);
103+
printf("%s v%s\n", bin_name, BPFTOOL_VERSION);
113104
}
114105
return 0;
115106
}

0 commit comments

Comments
 (0)