Skip to content

Libbpf userspace function bpf_map_create

0.6.0

Low level wrapper around the BPF_MAP_CREATE syscall command.

Definition

int bpf_map_create(enum bpf_map_type map_type, const char *map_name, __u32 key_size, __u32 value_size, __u32 max_entries, const struct bpf_map_create_opts *opts);

Parameters

  • map_type: type of the map to create
  • map_name: name of the map
  • key_size: size of the key in bytes
  • value_size: size of the value in bytes
  • max_entries: maximum number of entries in the map
  • opts: options for the map creation

struct bpf_map_create_opts

struct bpf_map_create_opts {
    size_t sz; /* size of this struct for forward/backward compatibility */

    __u32 btf_fd;
    __u32 btf_key_type_id;
    __u32 btf_value_type_id;
    __u32 btf_vmlinux_value_type_id;

    __u32 inner_map_fd;
    __u32 map_flags;
    __u64 map_extra;

    __u32 numa_node;
    __u32 map_ifindex;
    __s32 value_type_btf_obj_fd;

    __u32 token_fd;
    size_t :0;
};

btf_fd

0.6.0

btf_key_type_id

0.6.0

btf_value_type_id

0.6.0

btf_vmlinux_value_type_id

0.6.0

inner_map_fd

0.6.0

map_flags

0.6.0

map_extra

0.6.0

numa_node

0.6.0

map_ifindex

0.6.0

value_type_btf_obj_fd

1.4.0

token_fd

1.5.0

Return

>=0, file descriptor of the created map; <0, on error.

Usage

This function should only be used if you need precise control over the map creation process. For most cases, map should be created via bpf_object__load or similar high level APIs instead.

Example

Docs could be improved

This part of the docs is incomplete, contributions are very welcome