mirror of
https://github.com/netdata/libbpf.git
synced 2026-04-02 22:59:07 +08:00
libbpf: Introduce libbpf_bpf_map_type_str
This change introduces a new function, libbpf_bpf_map_type_str, to the public libbpf API. The function allows users to get a string representation for a bpf_map_type enum variant. Signed-off-by: Daniel Müller <deso@posteo.net> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Acked-by: Quentin Monnet <quentin@isovalent.com> Acked-by: Yonghong Song <yhs@fb.com> Link: https://lore.kernel.org/bpf/20220523230428.3077108-5-deso@posteo.net
This commit is contained in:
committed by
Andrii Nakryiko
parent
4d9cd51e7e
commit
242c116f04
42
src/libbpf.c
42
src/libbpf.c
@@ -72,6 +72,40 @@
|
||||
static struct bpf_map *bpf_object__add_map(struct bpf_object *obj);
|
||||
static bool prog_is_subprog(const struct bpf_object *obj, const struct bpf_program *prog);
|
||||
|
||||
static const char * const map_type_name[] = {
|
||||
[BPF_MAP_TYPE_UNSPEC] = "unspec",
|
||||
[BPF_MAP_TYPE_HASH] = "hash",
|
||||
[BPF_MAP_TYPE_ARRAY] = "array",
|
||||
[BPF_MAP_TYPE_PROG_ARRAY] = "prog_array",
|
||||
[BPF_MAP_TYPE_PERF_EVENT_ARRAY] = "perf_event_array",
|
||||
[BPF_MAP_TYPE_PERCPU_HASH] = "percpu_hash",
|
||||
[BPF_MAP_TYPE_PERCPU_ARRAY] = "percpu_array",
|
||||
[BPF_MAP_TYPE_STACK_TRACE] = "stack_trace",
|
||||
[BPF_MAP_TYPE_CGROUP_ARRAY] = "cgroup_array",
|
||||
[BPF_MAP_TYPE_LRU_HASH] = "lru_hash",
|
||||
[BPF_MAP_TYPE_LRU_PERCPU_HASH] = "lru_percpu_hash",
|
||||
[BPF_MAP_TYPE_LPM_TRIE] = "lpm_trie",
|
||||
[BPF_MAP_TYPE_ARRAY_OF_MAPS] = "array_of_maps",
|
||||
[BPF_MAP_TYPE_HASH_OF_MAPS] = "hash_of_maps",
|
||||
[BPF_MAP_TYPE_DEVMAP] = "devmap",
|
||||
[BPF_MAP_TYPE_DEVMAP_HASH] = "devmap_hash",
|
||||
[BPF_MAP_TYPE_SOCKMAP] = "sockmap",
|
||||
[BPF_MAP_TYPE_CPUMAP] = "cpumap",
|
||||
[BPF_MAP_TYPE_XSKMAP] = "xskmap",
|
||||
[BPF_MAP_TYPE_SOCKHASH] = "sockhash",
|
||||
[BPF_MAP_TYPE_CGROUP_STORAGE] = "cgroup_storage",
|
||||
[BPF_MAP_TYPE_REUSEPORT_SOCKARRAY] = "reuseport_sockarray",
|
||||
[BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE] = "percpu_cgroup_storage",
|
||||
[BPF_MAP_TYPE_QUEUE] = "queue",
|
||||
[BPF_MAP_TYPE_STACK] = "stack",
|
||||
[BPF_MAP_TYPE_SK_STORAGE] = "sk_storage",
|
||||
[BPF_MAP_TYPE_STRUCT_OPS] = "struct_ops",
|
||||
[BPF_MAP_TYPE_RINGBUF] = "ringbuf",
|
||||
[BPF_MAP_TYPE_INODE_STORAGE] = "inode_storage",
|
||||
[BPF_MAP_TYPE_TASK_STORAGE] = "task_storage",
|
||||
[BPF_MAP_TYPE_BLOOM_FILTER] = "bloom_filter",
|
||||
};
|
||||
|
||||
static const char * const prog_type_name[] = {
|
||||
[BPF_PROG_TYPE_UNSPEC] = "unspec",
|
||||
[BPF_PROG_TYPE_SOCKET_FILTER] = "socket_filter",
|
||||
@@ -9335,6 +9369,14 @@ int libbpf_prog_type_by_name(const char *name, enum bpf_prog_type *prog_type,
|
||||
return libbpf_err(-ESRCH);
|
||||
}
|
||||
|
||||
const char *libbpf_bpf_map_type_str(enum bpf_map_type t)
|
||||
{
|
||||
if (t < 0 || t >= ARRAY_SIZE(map_type_name))
|
||||
return NULL;
|
||||
|
||||
return map_type_name[t];
|
||||
}
|
||||
|
||||
const char *libbpf_bpf_prog_type_str(enum bpf_prog_type t)
|
||||
{
|
||||
if (t < 0 || t >= ARRAY_SIZE(prog_type_name))
|
||||
|
||||
Reference in New Issue
Block a user