mirror of
https://github.com/netdata/libbpf.git
synced 2026-04-05 16:19:06 +08:00
libbpf: Remove internal use of deprecated bpf_prog_load() variants
Remove all the internal uses of bpf_load_program_xattr(), which is slated for deprecation in v0.7. Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20211103220845.2676888-5-andrii@kernel.org
This commit is contained in:
committed by
Andrii Nakryiko
parent
65cdd0c73d
commit
9b422137af
34
src/xsk.c
34
src/xsk.c
@@ -364,7 +364,6 @@ int xsk_umem__create_v0_0_2(struct xsk_umem **umem_ptr, void *umem_area,
|
||||
static enum xsk_prog get_xsk_prog(void)
|
||||
{
|
||||
enum xsk_prog detected = XSK_PROG_FALLBACK;
|
||||
struct bpf_load_program_attr prog_attr;
|
||||
struct bpf_create_map_attr map_attr;
|
||||
__u32 size_out, retval, duration;
|
||||
char data_in = 0, data_out;
|
||||
@@ -375,7 +374,7 @@ static enum xsk_prog get_xsk_prog(void)
|
||||
BPF_EMIT_CALL(BPF_FUNC_redirect_map),
|
||||
BPF_EXIT_INSN(),
|
||||
};
|
||||
int prog_fd, map_fd, ret;
|
||||
int prog_fd, map_fd, ret, insn_cnt = ARRAY_SIZE(insns);
|
||||
|
||||
memset(&map_attr, 0, sizeof(map_attr));
|
||||
map_attr.map_type = BPF_MAP_TYPE_XSKMAP;
|
||||
@@ -389,13 +388,7 @@ static enum xsk_prog get_xsk_prog(void)
|
||||
|
||||
insns[0].imm = map_fd;
|
||||
|
||||
memset(&prog_attr, 0, sizeof(prog_attr));
|
||||
prog_attr.prog_type = BPF_PROG_TYPE_XDP;
|
||||
prog_attr.insns = insns;
|
||||
prog_attr.insns_cnt = ARRAY_SIZE(insns);
|
||||
prog_attr.license = "GPL";
|
||||
|
||||
prog_fd = bpf_load_program_xattr(&prog_attr, NULL, 0);
|
||||
prog_fd = bpf_prog_load(BPF_PROG_TYPE_XDP, NULL, "GPL", insns, insn_cnt, NULL);
|
||||
if (prog_fd < 0) {
|
||||
close(map_fd);
|
||||
return detected;
|
||||
@@ -495,10 +488,13 @@ static int xsk_load_xdp_prog(struct xsk_socket *xsk)
|
||||
};
|
||||
struct bpf_insn *progs[] = {prog, prog_redirect_flags};
|
||||
enum xsk_prog option = get_xsk_prog();
|
||||
LIBBPF_OPTS(bpf_prog_load_opts, opts,
|
||||
.log_buf = log_buf,
|
||||
.log_size = log_buf_size,
|
||||
);
|
||||
|
||||
prog_fd = bpf_load_program(BPF_PROG_TYPE_XDP, progs[option], insns_cnt[option],
|
||||
"LGPL-2.1 or BSD-2-Clause", 0, log_buf,
|
||||
log_buf_size);
|
||||
prog_fd = bpf_prog_load(BPF_PROG_TYPE_XDP, NULL, "LGPL-2.1 or BSD-2-Clause",
|
||||
progs[option], insns_cnt[option], &opts);
|
||||
if (prog_fd < 0) {
|
||||
pr_warn("BPF log buffer:\n%s", log_buf);
|
||||
return prog_fd;
|
||||
@@ -725,14 +721,12 @@ static int xsk_link_lookup(int ifindex, __u32 *prog_id, int *link_fd)
|
||||
|
||||
static bool xsk_probe_bpf_link(void)
|
||||
{
|
||||
DECLARE_LIBBPF_OPTS(bpf_link_create_opts, opts,
|
||||
.flags = XDP_FLAGS_SKB_MODE);
|
||||
struct bpf_load_program_attr prog_attr;
|
||||
LIBBPF_OPTS(bpf_link_create_opts, opts, .flags = XDP_FLAGS_SKB_MODE);
|
||||
struct bpf_insn insns[2] = {
|
||||
BPF_MOV64_IMM(BPF_REG_0, XDP_PASS),
|
||||
BPF_EXIT_INSN()
|
||||
};
|
||||
int prog_fd, link_fd = -1;
|
||||
int prog_fd, link_fd = -1, insn_cnt = ARRAY_SIZE(insns);
|
||||
int ifindex_lo = 1;
|
||||
bool ret = false;
|
||||
int err;
|
||||
@@ -744,13 +738,7 @@ static bool xsk_probe_bpf_link(void)
|
||||
if (link_fd >= 0)
|
||||
return true;
|
||||
|
||||
memset(&prog_attr, 0, sizeof(prog_attr));
|
||||
prog_attr.prog_type = BPF_PROG_TYPE_XDP;
|
||||
prog_attr.insns = insns;
|
||||
prog_attr.insns_cnt = ARRAY_SIZE(insns);
|
||||
prog_attr.license = "GPL";
|
||||
|
||||
prog_fd = bpf_load_program_xattr(&prog_attr, NULL, 0);
|
||||
prog_fd = bpf_prog_load(BPF_PROG_TYPE_XDP, NULL, "GPL", insns, insn_cnt, NULL);
|
||||
if (prog_fd < 0)
|
||||
return ret;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user