mirror of
https://git.proxmox.com/git/mirror_iproute2
synced 2025-11-05 02:38:54 +00:00
bpf: dump id/jited info for cls/act programs
Make use of TCA_BPF_ID/TCA_ACT_BPF_ID that we exposed and print the ID of the programs loaded and use the new BPF_OBJ_GET_INFO_BY_FD command for dumping further information about the program, currently whether the attached program is jited. Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
This commit is contained in:
parent
612ff099a1
commit
779525cd77
@ -261,6 +261,8 @@ int bpf_prog_load(enum bpf_prog_type type, const struct bpf_insn *insns,
|
||||
int bpf_prog_attach_fd(int prog_fd, int target_fd, enum bpf_attach_type type);
|
||||
int bpf_prog_detach_fd(int target_fd, enum bpf_attach_type type);
|
||||
|
||||
void bpf_dump_prog_info(FILE *f, uint32_t id);
|
||||
|
||||
#ifdef HAVE_ELF
|
||||
int bpf_send_map_fds(const char *path, const char *obj);
|
||||
int bpf_recv_map_fds(const char *path, int *fds, struct bpf_map_aux *aux,
|
||||
|
||||
48
lib/bpf.c
48
lib/bpf.c
@ -152,6 +152,54 @@ static int bpf_map_update(int fd, const void *key, const void *value,
|
||||
return bpf(BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr));
|
||||
}
|
||||
|
||||
static int bpf_prog_fd_by_id(uint32_t id)
|
||||
{
|
||||
union bpf_attr attr = {};
|
||||
|
||||
attr.prog_id = id;
|
||||
|
||||
return bpf(BPF_PROG_GET_FD_BY_ID, &attr, sizeof(attr));
|
||||
}
|
||||
|
||||
static int bpf_prog_info_by_fd(int fd, struct bpf_prog_info *info,
|
||||
uint32_t *info_len)
|
||||
{
|
||||
union bpf_attr attr = {};
|
||||
int ret;
|
||||
|
||||
attr.info.bpf_fd = fd;
|
||||
attr.info.info = bpf_ptr_to_u64(info);
|
||||
attr.info.info_len = *info_len;
|
||||
|
||||
*info_len = 0;
|
||||
ret = bpf(BPF_OBJ_GET_INFO_BY_FD, &attr, sizeof(attr));
|
||||
if (!ret)
|
||||
*info_len = attr.info.info_len;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void bpf_dump_prog_info(FILE *f, uint32_t id)
|
||||
{
|
||||
struct bpf_prog_info info = {};
|
||||
uint32_t len = sizeof(info);
|
||||
int fd, ret;
|
||||
|
||||
fprintf(f, "id %u ", id);
|
||||
|
||||
fd = bpf_prog_fd_by_id(id);
|
||||
if (fd < 0)
|
||||
return;
|
||||
|
||||
ret = bpf_prog_info_by_fd(fd, &info, &len);
|
||||
if (!ret && len) {
|
||||
if (info.jited_prog_len)
|
||||
fprintf(f, "jited ");
|
||||
}
|
||||
|
||||
close(fd);
|
||||
}
|
||||
|
||||
static int bpf_parse_string(char *arg, bool from_file, __u16 *bpf_len,
|
||||
char **bpf_string, bool *need_release,
|
||||
const char separator)
|
||||
|
||||
@ -230,6 +230,9 @@ static int bpf_print_opt(struct filter_util *qu, FILE *f,
|
||||
b, sizeof(b)));
|
||||
}
|
||||
|
||||
if (tb[TCA_BPF_ID])
|
||||
bpf_dump_prog_info(f, rta_getattr_u32(tb[TCA_BPF_ID]));
|
||||
|
||||
if (tb[TCA_BPF_POLICE]) {
|
||||
fprintf(f, "\n");
|
||||
tc_print_police(f, tb[TCA_BPF_POLICE]);
|
||||
|
||||
@ -186,6 +186,9 @@ static int bpf_print_opt(struct action_util *au, FILE *f, struct rtattr *arg)
|
||||
b, sizeof(b)));
|
||||
}
|
||||
|
||||
if (tb[TCA_ACT_BPF_ID])
|
||||
bpf_dump_prog_info(f, rta_getattr_u32(tb[TCA_ACT_BPF_ID]));
|
||||
|
||||
print_action_control(f, "default-action ", parm->action, "\n");
|
||||
fprintf(f, "\tindex %u ref %d bind %d", parm->index, parm->refcnt,
|
||||
parm->bindcnt);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user