Commit 3c24ad96 authored by Martin KaFai Lau's avatar Martin KaFai Lau

Add a few introspection helpers

This patch adds the following helpers to libbpf:
int bpf_prog_get_next_id(uint32_t start_id, uint32_t *next_id);
int bpf_prog_get_fd_by_id(uint32_t id);
int bpf_map_get_fd_by_id(uint32_t id);

It also changes the info_len arg of the existing bpf_obj_get_info()
from int to uint32_t.
Signed-off-by: default avatarMartin KaFai Lau <kafai@fb.com>
parent df36816a
......@@ -232,7 +232,7 @@ static void bpf_print_hints(char *log)
}
#define ROUND_UP(x, n) (((x) + (n) - 1u) & ~((n) - 1u))
int bpf_obj_get_info(int prog_map_fd, void *info, int *info_len)
int bpf_obj_get_info(int prog_map_fd, void *info, uint32_t *info_len)
{
union bpf_attr attr;
int err;
......@@ -1046,3 +1046,38 @@ int bpf_obj_get(const char *pathname)
return syscall(__NR_bpf, BPF_OBJ_GET, &attr, sizeof(attr));
}
int bpf_prog_get_next_id(uint32_t start_id, uint32_t *next_id)
{
union bpf_attr attr;
int err;
memset(&attr, 0, sizeof(attr));
attr.start_id = start_id;
err = syscall(__NR_bpf, BPF_PROG_GET_NEXT_ID, &attr, sizeof(attr));
if (!err)
*next_id = attr.next_id;
return err;
}
int bpf_prog_get_fd_by_id(uint32_t id)
{
union bpf_attr attr;
memset(&attr, 0, sizeof(attr));
attr.prog_id = id;
return syscall(__NR_bpf, BPF_PROG_GET_FD_BY_ID, &attr, sizeof(attr));
}
int bpf_map_get_fd_by_id(uint32_t id)
{
union bpf_attr attr;
memset(&attr, 0, sizeof(attr));
attr.map_id = id;
return syscall(__NR_bpf, BPF_MAP_GET_FD_BY_ID, &attr, sizeof(attr));
}
......@@ -90,10 +90,13 @@ int bpf_close_perf_event_fd(int fd);
int bpf_obj_pin(int fd, const char *pathname);
int bpf_obj_get(const char *pathname);
int bpf_obj_get_info(int prog_map_fd, void *info, int *info_len);
int bpf_obj_get_info(int prog_map_fd, void *info, uint32_t *info_len);
int bpf_prog_compute_tag(const struct bpf_insn *insns, int prog_len,
unsigned long long *tag);
int bpf_prog_get_tag(int fd, unsigned long long *tag);
int bpf_prog_get_next_id(uint32_t start_id, uint32_t *next_id);
int bpf_prog_get_fd_by_id(uint32_t id);
int bpf_map_get_fd_by_id(uint32_t id);
#define LOG_BUF_SIZE 65536
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment