Libbpf userspace function bpf_map__fd
Gets the file descriptor of the passed BPF map
Definition
int bpf_map__fd(const struct bpf_map *map);
Parameters
map: the BPF map instance
Return
The file descriptor; or -EINVAL in case of an error
Usage
The file descriptor is used to refer to a BPF map in other libbpf helper functions, such as bpf_map_update_elem. It is owned by the BPF object and closed with it.
Example
A hash map defined in the BPF program:
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__uint(max_entries, 1024);
__type(key, __u32);
__type(value, __u64);
} counters SEC(".maps");
In user space, this map can be accessed:
struct my_bpf *skel = my_bpf__open_and_load();
int map_fd = bpf_map__fd(skel->maps.counters);
__u32 key = 1;
__u64 value = 0;
bpf_map_update_elem(map_fd, &key, &value, BPF_ANY);