Skip to content

Commit

Permalink
tools/lib/bpf: bpf_program__insns allow to retrieve insns in libbpf
Browse files Browse the repository at this point in the history
This allows consumers of libbpf to iterate trough the insns
of a program without loading it first directly after the ELF parsing.

Being able to do that is useful to create tooling that can show
the structure of a BPF program using libbpf without having to
parse the ELF separately.

Usage:
  struct bpf_insn *insn;
  insn = bpf_program__insns(prog);

Signed-off-by: Lorenzo Fontana <fontanalorenz@gmail.com>
  • Loading branch information
fntlnz authored and intel-lab-lkp committed Jul 13, 2021
1 parent 97eb313 commit 999d992
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tools/lib/bpf/libbpf.c
Expand Up @@ -8908,6 +8908,11 @@ void *bpf_program__priv(const struct bpf_program *prog)
return prog ? prog->priv : libbpf_err_ptr(-EINVAL);
}

struct bpf_insn *bpf_program__insns(const struct bpf_program *prog)
{
return prog ? prog->insns : libbpf_err_ptr(-EINVAL);
}

void bpf_program__set_ifindex(struct bpf_program *prog, __u32 ifindex)
{
prog->prog_ifindex = ifindex;
Expand Down
1 change: 1 addition & 0 deletions tools/lib/bpf/libbpf.h
Expand Up @@ -195,6 +195,7 @@ typedef void (*bpf_program_clear_priv_t)(struct bpf_program *, void *);
LIBBPF_API int bpf_program__set_priv(struct bpf_program *prog, void *priv,
bpf_program_clear_priv_t clear_priv);

LIBBPF_API struct bpf_insn *bpf_program__insns(const struct bpf_program *prog);
LIBBPF_API void *bpf_program__priv(const struct bpf_program *prog);
LIBBPF_API void bpf_program__set_ifindex(struct bpf_program *prog,
__u32 ifindex);
Expand Down

0 comments on commit 999d992

Please sign in to comment.