aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuentin Monnet <quentin.monnet@netronome.com>2017-10-19 18:46:26 -0400
committerDavid S. Miller <davem@davemloft.net>2017-10-21 21:11:32 -0400
commit821cfbb0dcfbb24506dc6958361ca2b80b928049 (patch)
tree3c15e3ad7cc63f5a05994983138b36e1ad4a3c1e
parent8dfbc6d1d213df340e5dcfdcdc76ad9407a29273 (diff)
tools: bpftool: add a command to display bpftool version
This command can be used to print the version of the tool, which is in fact the version from Linux taken from usr/include/linux/version.h. Example usage: $ bpftool version bpftool v4.14.0 Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com> Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> Acked-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--tools/bpf/bpftool/Documentation/bpftool.rst2
-rw-r--r--tools/bpf/bpftool/main.c14
2 files changed, 15 insertions, 1 deletions
diff --git a/tools/bpf/bpftool/Documentation/bpftool.rst b/tools/bpf/bpftool/Documentation/bpftool.rst
index f1df1893fb54..45ad8baf1915 100644
--- a/tools/bpf/bpftool/Documentation/bpftool.rst
+++ b/tools/bpf/bpftool/Documentation/bpftool.rst
@@ -14,6 +14,8 @@ SYNOPSIS
14 14
15 **bpftool** batch file *FILE* 15 **bpftool** batch file *FILE*
16 16
17 **bpftool** version
18
17 *OBJECT* := { **map** | **program** } 19 *OBJECT* := { **map** | **program** }
18 20
19 *MAP-COMMANDS* := 21 *MAP-COMMANDS* :=
diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c
index 8662199ee050..814d19e1b53f 100644
--- a/tools/bpf/bpftool/main.c
+++ b/tools/bpf/bpftool/main.c
@@ -37,6 +37,7 @@
37#include <ctype.h> 37#include <ctype.h>
38#include <errno.h> 38#include <errno.h>
39#include <linux/bpf.h> 39#include <linux/bpf.h>
40#include <linux/version.h>
40#include <stdio.h> 41#include <stdio.h>
41#include <stdlib.h> 42#include <stdlib.h>
42#include <string.h> 43#include <string.h>
@@ -62,13 +63,23 @@ static int do_help(int argc, char **argv)
62 fprintf(stderr, 63 fprintf(stderr,
63 "Usage: %s OBJECT { COMMAND | help }\n" 64 "Usage: %s OBJECT { COMMAND | help }\n"
64 " %s batch file FILE\n" 65 " %s batch file FILE\n"
66 " %s version\n"
65 "\n" 67 "\n"
66 " OBJECT := { prog | map }\n", 68 " OBJECT := { prog | map }\n",
67 bin_name, bin_name); 69 bin_name, bin_name, bin_name);
68 70
69 return 0; 71 return 0;
70} 72}
71 73
74static int do_version(int argc, char **argv)
75{
76 printf("%s v%d.%d.%d\n", bin_name,
77 LINUX_VERSION_CODE >> 16,
78 LINUX_VERSION_CODE >> 8 & 0xf,
79 LINUX_VERSION_CODE & 0xf);
80 return 0;
81}
82
72int cmd_select(const struct cmd *cmds, int argc, char **argv, 83int cmd_select(const struct cmd *cmds, int argc, char **argv,
73 int (*help)(int argc, char **argv)) 84 int (*help)(int argc, char **argv))
74{ 85{
@@ -128,6 +139,7 @@ static const struct cmd cmds[] = {
128 { "batch", do_batch }, 139 { "batch", do_batch },
129 { "prog", do_prog }, 140 { "prog", do_prog },
130 { "map", do_map }, 141 { "map", do_map },
142 { "version", do_version },
131 { 0 } 143 { 0 }
132}; 144};
133 145