Commit a6ca7158 authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Alexei Starovoitov
Browse files

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: default avatarAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20211111051758.92283-2-andrii@kernel.org
parent 04f8cb6d
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -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,				    \
+3 −0
Original line number Diff line number Diff line
@@ -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);
+2 −0
Original line number Diff line number Diff line
@@ -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;