Accessing BPF maps from kernel space
Solution 1:
To lookup map elements from userspace, you should use the bpf(2)
syscall, with command BPF_MAP_LOOKUP_ELEM
. The main userspace library for BPF does expose this syscall command as bpf_map_lookup_elem()
.
To lookup map elements from BPF programs, you indeed need to use the bpf_map_lookup_elem
BPF helper. In a nutshell, BPF helpers are kernel functions you can call from the BPF bytecode with instruction call
.
Despite having the same name, they are however different things: the first is a library function, while the second is a BPF helper.