libbpf: Add ability to get/set per-program load flags

Add bpf_program__flags() API to retrieve prog_flags that will be (or
were) supplied to BPF_PROG_LOAD command.

Also add bpf_program__set_extra_flags() API to allow to set *extra*
flags, in addition to those determined by program's SEC() definition.
Such flags are logically OR'ed with libbpf-derived flags.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20211111051758.92283-2-andrii@kernel.org
This commit is contained in:
Andrii Nakryiko 2021-11-10 21:17:57 -08:00 committed by Alexei Starovoitov
parent 04f8cb6d6b
commit a6ca715831
3 changed files with 19 additions and 0 deletions

View file

@ -8262,6 +8262,20 @@ void bpf_program__set_expected_attach_type(struct bpf_program *prog,
prog->expected_attach_type = type;
}
__u32 bpf_program__flags(const struct bpf_program *prog)
{
return prog->prog_flags;
}
int bpf_program__set_extra_flags(struct bpf_program *prog, __u32 extra_flags)
{
if (prog->obj->loaded)
return libbpf_err(-EBUSY);
prog->prog_flags |= extra_flags;
return 0;
}
#define SEC_DEF(sec_pfx, ptype, atype, flags, ...) { \
.sec = sec_pfx, \
.prog_type = BPF_PROG_TYPE_##ptype, \

View file

@ -493,6 +493,9 @@ LIBBPF_API void
bpf_program__set_expected_attach_type(struct bpf_program *prog,
enum bpf_attach_type type);
LIBBPF_API __u32 bpf_program__flags(const struct bpf_program *prog);
LIBBPF_API int bpf_program__set_extra_flags(struct bpf_program *prog, __u32 extra_flags);
LIBBPF_API int
bpf_program__set_attach_target(struct bpf_program *prog, int attach_prog_fd,
const char *attach_func_name);

View file

@ -397,8 +397,10 @@ LIBBPF_0.6.0 {
bpf_object__prev_program;
bpf_prog_load_deprecated;
bpf_prog_load;
bpf_program__flags;
bpf_program__insn_cnt;
bpf_program__insns;
bpf_program__set_extra_flags;
btf__add_btf;
btf__add_decl_tag;
btf__raw_data;