]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
libbpf: Add runtime APIs to query libbpf version
authorAndrii Nakryiko <andrii@kernel.org>
Thu, 18 Nov 2021 17:40:54 +0000 (09:40 -0800)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 19 Nov 2021 15:25:57 +0000 (16:25 +0100)
Libbpf provided LIBBPF_MAJOR_VERSION and LIBBPF_MINOR_VERSION macros to
check libbpf version at compilation time. This doesn't cover all the
needs, though, because version of libbpf that application is compiled
against doesn't necessarily match the version of libbpf at runtime,
especially if libbpf is used as a shared library.

Add libbpf_major_version() and libbpf_minor_version() returning major
and minor versions, respectively, as integers. Also add a convenience
libbpf_version_string() for various tooling using libbpf to print out
libbpf version in a human-readable form. Currently it will return
"v0.6", but in the future it can contains some extra information, so the
format itself is not part of a stable API and shouldn't be relied upon.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Acked-by: Toke Høiland-Jørgensen <toke@redhat.com>
Link: https://lore.kernel.org/bpf/20211118174054.2699477-1-andrii@kernel.org
tools/lib/bpf/libbpf.c
tools/lib/bpf/libbpf.h
tools/lib/bpf/libbpf.map

index de7e09a6b5eca1823970452274fdaad49b626265..78de238f975a8adfd7e7a200835fa33d3d649c3f 100644 (file)
@@ -168,6 +168,25 @@ int libbpf_set_strict_mode(enum libbpf_strict_mode mode)
        return 0;
 }
 
+__u32 libbpf_major_version(void)
+{
+       return LIBBPF_MAJOR_VERSION;
+}
+
+__u32 libbpf_minor_version(void)
+{
+       return LIBBPF_MINOR_VERSION;
+}
+
+const char *libbpf_version_string(void)
+{
+#define __S(X) #X
+#define _S(X) __S(X)
+       return  "v" _S(LIBBPF_MAJOR_VERSION) "." _S(LIBBPF_MINOR_VERSION);
+#undef _S
+#undef __S
+}
+
 enum kern_feature_id {
        /* v4.14: kernel support for program & map names. */
        FEAT_PROG_NAME,
index 4ec69f22434260ce03a3989221ff59aa3643a7a1..003fdc5cf3a8d2ab93071e4f5a9d78f237bcce4e 100644 (file)
 extern "C" {
 #endif
 
+LIBBPF_API __u32 libbpf_major_version(void);
+LIBBPF_API __u32 libbpf_minor_version(void);
+LIBBPF_API const char *libbpf_version_string(void);
+
 enum libbpf_errno {
        __LIBBPF_ERRNO__START = 4000,
 
index 6a59514a48cfe97fc684aeb92521979a150a9e91..bea6791272e567070c3f4bfdb327d1e3f75f0cb5 100644 (file)
@@ -410,6 +410,9 @@ LIBBPF_0.6.0 {
                btf__type_cnt;
                btf_dump__new;
                btf_dump__new_deprecated;
+               libbpf_major_version;
+               libbpf_minor_version;
+               libbpf_version_string;
                perf_buffer__new;
                perf_buffer__new_deprecated;
                perf_buffer__new_raw;