aya-rs / aya

Aya is an eBPF library for the Rust programming language, built with a focus on developer experience and operability.
https://aya-rs.dev/book/
Apache License 2.0
3.2k stars 286 forks source link

Export LINUX_KERNEL_VERSION extern variable #246

Open MatteoNardi opened 2 years ago

MatteoNardi commented 2 years ago

In order to take full advantage of BTF/CORE and support a large variety of systems with the same static build, it is useful for the eBPF program to know the kernel version.

libbpf exports this information alongside the host system Kconfig variables. https://nakryiko.com/posts/bpf-core-reference-guide/#linux-kernel-version

It would be useful to have the same feature in aya.

For context, we're currently using aya only for the userspace and sticking to C for the eBPF program.

qjerome commented 7 months ago

One can use a workaround using loader's set_global function such as:

BpfLoader::new().set_global("LINUX_KERNEL_VERSION", version).load(...)