libbpf: add runtime APIs to query libbpf version
Andrii Nakryiko
maintainerPATCH v2 1/1 libbpf: add runtime APIs to query libbpf version
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.
---v1->v2:
- libbpf.map wasn't alphabetically sorted, fixed that.
tools/lib/bpf/libbpf.c | 19 +++++++++++++++++++ tools/lib/bpf/libbpf.h | 4 ++++ tools/lib/bpf/libbpf.map | 3 +++ 3 files changed, 26 insertions(+)
tools/lib/bpf/libbpf.c +19 -0
@@ -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 ,
tools/lib/bpf/libbpf.h +4 -0
@@ -24,6 +24,10 @@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 ,
tools/lib/bpf/libbpf.map +3 -0
@@ -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;
Signature · 1 line
2.30.2
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Quoted 6 lines · On Thu, 18 Nov 2021 09:40:54 -0800 you wrote:
Libbpf provided
LIBBPF_MAJOR_VERSIONandLIBBPF_MINOR_VERSIONmacros 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.
Quoted 8 lines
Add
libbpf_major_version()andlibbpf_minor_version()returning major and minor versions, respectively, as integers. Also add a conveniencelibbpf_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.[...]
Here is the summary with links:
- [v2,bpf-next] libbpf: add runtime APIs to query libbpf version
https://git.kernel.org/bpf/bpf-next/c/7615209f42a1
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html