Commit c3be3676 authored by Daniel Borkmann's avatar Daniel Borkmann

Merge branch 'bpf-libbpf-deprecated-cleanup'

Andrii Nakryiko says:

====================
Clean up remaining missed uses of deprecated libbpf APIs across samples/bpf,
selftests/bpf, libbpf, and bpftool.

Also fix uninit variable warning in bpftool.
====================
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parents 707ee8ac 1e4edb6d
...@@ -79,13 +79,11 @@ static void usage(const char *prog) ...@@ -79,13 +79,11 @@ static void usage(const char *prog)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
struct bpf_prog_load_attr prog_load_attr = {
.prog_type = BPF_PROG_TYPE_XDP,
};
struct bpf_prog_info info = {}; struct bpf_prog_info info = {};
__u32 info_len = sizeof(info); __u32 info_len = sizeof(info);
const char *optstr = "FSN"; const char *optstr = "FSN";
int prog_fd, map_fd, opt; int prog_fd, map_fd, opt;
struct bpf_program *prog;
struct bpf_object *obj; struct bpf_object *obj;
struct bpf_map *map; struct bpf_map *map;
char filename[256]; char filename[256];
...@@ -123,11 +121,19 @@ int main(int argc, char **argv) ...@@ -123,11 +121,19 @@ int main(int argc, char **argv)
} }
snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
prog_load_attr.file = filename; obj = bpf_object__open_file(filename, NULL);
if (libbpf_get_error(obj))
return 1;
prog = bpf_object__next_program(obj, NULL);
bpf_program__set_type(prog, BPF_PROG_TYPE_XDP);
if (bpf_prog_load_xattr(&prog_load_attr, &obj, &prog_fd)) err = bpf_object__load(obj);
if (err)
return 1; return 1;
prog_fd = bpf_program__fd(prog);
map = bpf_object__next_map(obj, NULL); map = bpf_object__next_map(obj, NULL);
if (!map) { if (!map) {
printf("finding a map in obj file failed\n"); printf("finding a map in obj file failed\n");
......
...@@ -82,15 +82,13 @@ static void usage(const char *cmd) ...@@ -82,15 +82,13 @@ static void usage(const char *cmd)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
struct bpf_prog_load_attr prog_load_attr = {
.prog_type = BPF_PROG_TYPE_XDP,
};
unsigned char opt_flags[256] = {}; unsigned char opt_flags[256] = {};
const char *optstr = "i:T:P:SNFh"; const char *optstr = "i:T:P:SNFh";
struct bpf_prog_info info = {}; struct bpf_prog_info info = {};
__u32 info_len = sizeof(info); __u32 info_len = sizeof(info);
unsigned int kill_after_s = 0; unsigned int kill_after_s = 0;
int i, prog_fd, map_fd, opt; int i, prog_fd, map_fd, opt;
struct bpf_program *prog;
struct bpf_object *obj; struct bpf_object *obj;
__u32 max_pckt_size = 0; __u32 max_pckt_size = 0;
__u32 key = 0; __u32 key = 0;
...@@ -148,11 +146,20 @@ int main(int argc, char **argv) ...@@ -148,11 +146,20 @@ int main(int argc, char **argv)
} }
snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
prog_load_attr.file = filename;
if (bpf_prog_load_xattr(&prog_load_attr, &obj, &prog_fd)) obj = bpf_object__open_file(filename, NULL);
if (libbpf_get_error(obj))
return 1; return 1;
prog = bpf_object__next_program(obj, NULL);
bpf_program__set_type(prog, BPF_PROG_TYPE_XDP);
err = bpf_object__load(obj);
if (err)
return 1;
prog_fd = bpf_program__fd(prog);
/* static global var 'max_pcktsz' is accessible from .data section */ /* static global var 'max_pcktsz' is accessible from .data section */
if (max_pckt_size) { if (max_pckt_size) {
map_fd = bpf_object__find_map_fd_by_name(obj, "xdp_adju.data"); map_fd = bpf_object__find_map_fd_by_name(obj, "xdp_adju.data");
......
...@@ -75,14 +75,11 @@ static void usage(const char *prog) ...@@ -75,14 +75,11 @@ static void usage(const char *prog)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
struct bpf_prog_load_attr prog_load_attr = {
.prog_type = BPF_PROG_TYPE_XDP,
};
const char *prog_name = "xdp_fwd"; const char *prog_name = "xdp_fwd";
struct bpf_program *prog = NULL; struct bpf_program *prog = NULL;
struct bpf_program *pos; struct bpf_program *pos;
const char *sec_name; const char *sec_name;
int prog_fd, map_fd = -1; int prog_fd = -1, map_fd = -1;
char filename[PATH_MAX]; char filename[PATH_MAX];
struct bpf_object *obj; struct bpf_object *obj;
int opt, i, idx, err; int opt, i, idx, err;
...@@ -119,7 +116,6 @@ int main(int argc, char **argv) ...@@ -119,7 +116,6 @@ int main(int argc, char **argv)
if (attach) { if (attach) {
snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
prog_load_attr.file = filename;
if (access(filename, O_RDONLY) < 0) { if (access(filename, O_RDONLY) < 0) {
printf("error accessing file %s: %s\n", printf("error accessing file %s: %s\n",
...@@ -127,7 +123,14 @@ int main(int argc, char **argv) ...@@ -127,7 +123,14 @@ int main(int argc, char **argv)
return 1; return 1;
} }
err = bpf_prog_load_xattr(&prog_load_attr, &obj, &prog_fd); obj = bpf_object__open_file(filename, NULL);
if (libbpf_get_error(obj))
return 1;
prog = bpf_object__next_program(obj, NULL);
bpf_program__set_type(prog, BPF_PROG_TYPE_XDP);
err = bpf_object__load(obj);
if (err) { if (err) {
printf("Does kernel support devmap lookup?\n"); printf("Does kernel support devmap lookup?\n");
/* If not, the error message will be: /* If not, the error message will be:
......
...@@ -640,12 +640,10 @@ static void usage(const char *prog) ...@@ -640,12 +640,10 @@ static void usage(const char *prog)
int main(int ac, char **argv) int main(int ac, char **argv)
{ {
struct bpf_prog_load_attr prog_load_attr = {
.prog_type = BPF_PROG_TYPE_XDP,
};
struct bpf_prog_info info = {}; struct bpf_prog_info info = {};
__u32 info_len = sizeof(info); __u32 info_len = sizeof(info);
const char *optstr = "SF"; const char *optstr = "SF";
struct bpf_program *prog;
struct bpf_object *obj; struct bpf_object *obj;
char filename[256]; char filename[256];
char **ifname_list; char **ifname_list;
...@@ -653,7 +651,6 @@ int main(int ac, char **argv) ...@@ -653,7 +651,6 @@ int main(int ac, char **argv)
int err, i = 1; int err, i = 1;
snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
prog_load_attr.file = filename;
total_ifindex = ac - 1; total_ifindex = ac - 1;
ifname_list = (argv + 1); ifname_list = (argv + 1);
...@@ -684,14 +681,20 @@ int main(int ac, char **argv) ...@@ -684,14 +681,20 @@ int main(int ac, char **argv)
return 1; return 1;
} }
if (bpf_prog_load_xattr(&prog_load_attr, &obj, &prog_fd)) obj = bpf_object__open_file(filename, NULL);
if (libbpf_get_error(obj))
return 1; return 1;
prog = bpf_object__next_program(obj, NULL);
bpf_program__set_type(prog, BPF_PROG_TYPE_XDP);
printf("\n******************loading bpf file*********************\n"); printf("\n******************loading bpf file*********************\n");
if (!prog_fd) { err = bpf_object__load(obj);
printf("bpf_prog_load_xattr: %s\n", strerror(errno)); if (err) {
printf("bpf_object__load(): %s\n", strerror(errno));
return 1; return 1;
} }
prog_fd = bpf_program__fd(prog);
lpm_map_fd = bpf_object__find_map_fd_by_name(obj, "lpm_map"); lpm_map_fd = bpf_object__find_map_fd_by_name(obj, "lpm_map");
rxcnt_map_fd = bpf_object__find_map_fd_by_name(obj, "rxcnt"); rxcnt_map_fd = bpf_object__find_map_fd_by_name(obj, "rxcnt");
......
...@@ -450,14 +450,12 @@ static void stats_poll(int interval, int action, __u32 cfg_opt) ...@@ -450,14 +450,12 @@ static void stats_poll(int interval, int action, __u32 cfg_opt)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
__u32 cfg_options= NO_TOUCH ; /* Default: Don't touch packet memory */ __u32 cfg_options= NO_TOUCH ; /* Default: Don't touch packet memory */
struct bpf_prog_load_attr prog_load_attr = {
.prog_type = BPF_PROG_TYPE_XDP,
};
struct bpf_prog_info info = {}; struct bpf_prog_info info = {};
__u32 info_len = sizeof(info); __u32 info_len = sizeof(info);
int prog_fd, map_fd, opt, err; int prog_fd, map_fd, opt, err;
bool use_separators = true; bool use_separators = true;
struct config cfg = { 0 }; struct config cfg = { 0 };
struct bpf_program *prog;
struct bpf_object *obj; struct bpf_object *obj;
struct bpf_map *map; struct bpf_map *map;
char filename[256]; char filename[256];
...@@ -471,11 +469,19 @@ int main(int argc, char **argv) ...@@ -471,11 +469,19 @@ int main(int argc, char **argv)
char *action_str = NULL; char *action_str = NULL;
snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
prog_load_attr.file = filename;
if (bpf_prog_load_xattr(&prog_load_attr, &obj, &prog_fd)) obj = bpf_object__open_file(filename, NULL);
if (libbpf_get_error(obj))
return EXIT_FAIL; return EXIT_FAIL;
prog = bpf_object__next_program(obj, NULL);
bpf_program__set_type(prog, BPF_PROG_TYPE_XDP);
err = bpf_object__load(obj);
if (err)
return EXIT_FAIL;
prog_fd = bpf_program__fd(prog);
map = bpf_object__find_map_by_name(obj, "config_map"); map = bpf_object__find_map_by_name(obj, "config_map");
stats_global_map = bpf_object__find_map_by_name(obj, "stats_global_map"); stats_global_map = bpf_object__find_map_by_name(obj, "stats_global_map");
rx_queue_index_map = bpf_object__find_map_by_name(obj, "rx_queue_index_map"); rx_queue_index_map = bpf_object__find_map_by_name(obj, "rx_queue_index_map");
......
...@@ -152,9 +152,6 @@ static int parse_ports(const char *port_str, int *min_port, int *max_port) ...@@ -152,9 +152,6 @@ static int parse_ports(const char *port_str, int *min_port, int *max_port)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
struct bpf_prog_load_attr prog_load_attr = {
.prog_type = BPF_PROG_TYPE_XDP,
};
int min_port = 0, max_port = 0, vip2tnl_map_fd; int min_port = 0, max_port = 0, vip2tnl_map_fd;
const char *optstr = "i:a:p:s:d:m:T:P:FSNh"; const char *optstr = "i:a:p:s:d:m:T:P:FSNh";
unsigned char opt_flags[256] = {}; unsigned char opt_flags[256] = {};
...@@ -162,6 +159,7 @@ int main(int argc, char **argv) ...@@ -162,6 +159,7 @@ int main(int argc, char **argv)
__u32 info_len = sizeof(info); __u32 info_len = sizeof(info);
unsigned int kill_after_s = 0; unsigned int kill_after_s = 0;
struct iptnl_info tnl = {}; struct iptnl_info tnl = {};
struct bpf_program *prog;
struct bpf_object *obj; struct bpf_object *obj;
struct vip vip = {}; struct vip vip = {};
char filename[256]; char filename[256];
...@@ -259,15 +257,20 @@ int main(int argc, char **argv) ...@@ -259,15 +257,20 @@ int main(int argc, char **argv)
} }
snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
prog_load_attr.file = filename;
if (bpf_prog_load_xattr(&prog_load_attr, &obj, &prog_fd)) obj = bpf_object__open_file(filename, NULL);
if (libbpf_get_error(obj))
return 1; return 1;
if (!prog_fd) { prog = bpf_object__next_program(obj, NULL);
printf("bpf_prog_load_xattr: %s\n", strerror(errno)); bpf_program__set_type(prog, BPF_PROG_TYPE_XDP);
err = bpf_object__load(obj);
if (err) {
printf("bpf_object__load(): %s\n", strerror(errno));
return 1; return 1;
} }
prog_fd = bpf_program__fd(prog);
rxcnt_map_fd = bpf_object__find_map_fd_by_name(obj, "rxcnt"); rxcnt_map_fd = bpf_object__find_map_fd_by_name(obj, "rxcnt");
vip2tnl_map_fd = bpf_object__find_map_fd_by_name(obj, "vip2tnl"); vip2tnl_map_fd = bpf_object__find_map_fd_by_name(obj, "vip2tnl");
......
...@@ -310,7 +310,7 @@ void get_prog_full_name(const struct bpf_prog_info *prog_info, int prog_fd, ...@@ -310,7 +310,7 @@ void get_prog_full_name(const struct bpf_prog_info *prog_info, int prog_fd,
{ {
const char *prog_name = prog_info->name; const char *prog_name = prog_info->name;
const struct btf_type *func_type; const struct btf_type *func_type;
const struct bpf_func_info finfo; const struct bpf_func_info finfo = {};
struct bpf_prog_info info = {}; struct bpf_prog_info info = {};
__u32 info_len = sizeof(info); __u32 info_len = sizeof(info);
struct btf *prog_btf = NULL; struct btf *prog_btf = NULL;
......
...@@ -487,17 +487,12 @@ probe_prog_type(enum bpf_prog_type prog_type, bool *supported_types, ...@@ -487,17 +487,12 @@ probe_prog_type(enum bpf_prog_type prog_type, bool *supported_types,
size_t maxlen; size_t maxlen;
bool res; bool res;
if (ifindex) if (ifindex) {
/* Only test offload-able program types */ p_info("BPF offload feature probing is not supported");
switch (prog_type) { return;
case BPF_PROG_TYPE_SCHED_CLS: }
case BPF_PROG_TYPE_XDP:
break;
default:
return;
}
res = bpf_probe_prog_type(prog_type, ifindex); res = libbpf_probe_bpf_prog_type(prog_type, NULL);
#ifdef USE_LIBCAP #ifdef USE_LIBCAP
/* Probe may succeed even if program load fails, for unprivileged users /* Probe may succeed even if program load fails, for unprivileged users
* check that we did not fail because of insufficient permissions * check that we did not fail because of insufficient permissions
...@@ -535,7 +530,12 @@ probe_map_type(enum bpf_map_type map_type, const char *define_prefix, ...@@ -535,7 +530,12 @@ probe_map_type(enum bpf_map_type map_type, const char *define_prefix,
size_t maxlen; size_t maxlen;
bool res; bool res;
res = bpf_probe_map_type(map_type, ifindex); if (ifindex) {
p_info("BPF offload feature probing is not supported");
return;
}
res = libbpf_probe_bpf_map_type(map_type, NULL);
/* Probe result depends on the success of map creation, no additional /* Probe result depends on the success of map creation, no additional
* check required for unprivileged users * check required for unprivileged users
...@@ -567,7 +567,12 @@ probe_helper_for_progtype(enum bpf_prog_type prog_type, bool supported_type, ...@@ -567,7 +567,12 @@ probe_helper_for_progtype(enum bpf_prog_type prog_type, bool supported_type,
bool res = false; bool res = false;
if (supported_type) { if (supported_type) {
res = bpf_probe_helper(id, prog_type, ifindex); if (ifindex) {
p_info("BPF offload feature probing is not supported");
return;
}
res = libbpf_probe_bpf_helper(prog_type, id, NULL);
#ifdef USE_LIBCAP #ifdef USE_LIBCAP
/* Probe may succeed even if program load fails, for /* Probe may succeed even if program load fails, for
* unprivileged users check that we did not fail because of * unprivileged users check that we did not fail because of
......
...@@ -9505,7 +9505,7 @@ static int bpf_prog_load_xattr2(const struct bpf_prog_load_attr *attr, ...@@ -9505,7 +9505,7 @@ static int bpf_prog_load_xattr2(const struct bpf_prog_load_attr *attr,
} }
bpf_object__for_each_map(map, obj) { bpf_object__for_each_map(map, obj) {
if (!bpf_map__is_offload_neutral(map)) if (map->def.type != BPF_MAP_TYPE_PERF_EVENT_ARRAY)
map->map_ifindex = attr->ifindex; map->map_ifindex = attr->ifindex;
} }
......
...@@ -11,8 +11,7 @@ void serial_test_xdp_attach(void) ...@@ -11,8 +11,7 @@ void serial_test_xdp_attach(void)
const char *file = "./test_xdp.o"; const char *file = "./test_xdp.o";
struct bpf_prog_info info = {}; struct bpf_prog_info info = {};
int err, fd1, fd2, fd3; int err, fd1, fd2, fd3;
DECLARE_LIBBPF_OPTS(bpf_xdp_set_link_opts, opts, LIBBPF_OPTS(bpf_xdp_attach_opts, opts);
.old_fd = -1);
len = sizeof(info); len = sizeof(info);
...@@ -38,49 +37,47 @@ void serial_test_xdp_attach(void) ...@@ -38,49 +37,47 @@ void serial_test_xdp_attach(void)
if (CHECK_FAIL(err)) if (CHECK_FAIL(err))
goto out_2; goto out_2;
err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, fd1, XDP_FLAGS_REPLACE, err = bpf_xdp_attach(IFINDEX_LO, fd1, XDP_FLAGS_REPLACE, &opts);
&opts);
if (CHECK(err, "load_ok", "initial load failed")) if (CHECK(err, "load_ok", "initial load failed"))
goto out_close; goto out_close;
err = bpf_get_link_xdp_id(IFINDEX_LO, &id0, 0); err = bpf_xdp_query_id(IFINDEX_LO, 0, &id0);
if (CHECK(err || id0 != id1, "id1_check", if (CHECK(err || id0 != id1, "id1_check",
"loaded prog id %u != id1 %u, err %d", id0, id1, err)) "loaded prog id %u != id1 %u, err %d", id0, id1, err))
goto out_close; goto out_close;
err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, fd2, XDP_FLAGS_REPLACE, err = bpf_xdp_attach(IFINDEX_LO, fd2, XDP_FLAGS_REPLACE, &opts);
&opts);
if (CHECK(!err, "load_fail", "load with expected id didn't fail")) if (CHECK(!err, "load_fail", "load with expected id didn't fail"))
goto out; goto out;
opts.old_fd = fd1; opts.old_prog_fd = fd1;
err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, fd2, 0, &opts); err = bpf_xdp_attach(IFINDEX_LO, fd2, 0, &opts);
if (CHECK(err, "replace_ok", "replace valid old_fd failed")) if (CHECK(err, "replace_ok", "replace valid old_fd failed"))
goto out; goto out;
err = bpf_get_link_xdp_id(IFINDEX_LO, &id0, 0); err = bpf_xdp_query_id(IFINDEX_LO, 0, &id0);
if (CHECK(err || id0 != id2, "id2_check", if (CHECK(err || id0 != id2, "id2_check",
"loaded prog id %u != id2 %u, err %d", id0, id2, err)) "loaded prog id %u != id2 %u, err %d", id0, id2, err))
goto out_close; goto out_close;
err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, fd3, 0, &opts); err = bpf_xdp_attach(IFINDEX_LO, fd3, 0, &opts);
if (CHECK(!err, "replace_fail", "replace invalid old_fd didn't fail")) if (CHECK(!err, "replace_fail", "replace invalid old_fd didn't fail"))
goto out; goto out;
err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, -1, 0, &opts); err = bpf_xdp_detach(IFINDEX_LO, 0, &opts);
if (CHECK(!err, "remove_fail", "remove invalid old_fd didn't fail")) if (CHECK(!err, "remove_fail", "remove invalid old_fd didn't fail"))
goto out; goto out;
opts.old_fd = fd2; opts.old_prog_fd = fd2;
err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, -1, 0, &opts); err = bpf_xdp_detach(IFINDEX_LO, 0, &opts);
if (CHECK(err, "remove_ok", "remove valid old_fd failed")) if (CHECK(err, "remove_ok", "remove valid old_fd failed"))
goto out; goto out;
err = bpf_get_link_xdp_id(IFINDEX_LO, &id0, 0); err = bpf_xdp_query_id(IFINDEX_LO, 0, &id0);
if (CHECK(err || id0 != 0, "unload_check", if (CHECK(err || id0 != 0, "unload_check",
"loaded prog id %u != 0, err %d", id0, err)) "loaded prog id %u != 0, err %d", id0, err))
goto out_close; goto out_close;
out: out:
bpf_set_link_xdp_fd(IFINDEX_LO, -1, 0); bpf_xdp_detach(IFINDEX_LO, 0, NULL);
out_close: out_close:
bpf_object__close(obj3); bpf_object__close(obj3);
out_2: out_2:
......
...@@ -24,11 +24,11 @@ void test_xdp_with_cpumap_helpers(void) ...@@ -24,11 +24,11 @@ void test_xdp_with_cpumap_helpers(void)
return; return;
prog_fd = bpf_program__fd(skel->progs.xdp_redir_prog); prog_fd = bpf_program__fd(skel->progs.xdp_redir_prog);
err = bpf_set_link_xdp_fd(IFINDEX_LO, prog_fd, XDP_FLAGS_SKB_MODE); err = bpf_xdp_attach(IFINDEX_LO, prog_fd, XDP_FLAGS_SKB_MODE, NULL);
if (!ASSERT_OK(err, "Generic attach of program with 8-byte CPUMAP")) if (!ASSERT_OK(err, "Generic attach of program with 8-byte CPUMAP"))
goto out_close; goto out_close;
err = bpf_set_link_xdp_fd(IFINDEX_LO, -1, XDP_FLAGS_SKB_MODE); err = bpf_xdp_detach(IFINDEX_LO, XDP_FLAGS_SKB_MODE, NULL);
ASSERT_OK(err, "XDP program detach"); ASSERT_OK(err, "XDP program detach");
prog_fd = bpf_program__fd(skel->progs.xdp_dummy_cm); prog_fd = bpf_program__fd(skel->progs.xdp_dummy_cm);
...@@ -46,9 +46,9 @@ void test_xdp_with_cpumap_helpers(void) ...@@ -46,9 +46,9 @@ void test_xdp_with_cpumap_helpers(void)
ASSERT_EQ(info.id, val.bpf_prog.id, "Match program id to cpumap entry prog_id"); ASSERT_EQ(info.id, val.bpf_prog.id, "Match program id to cpumap entry prog_id");
/* can not attach BPF_XDP_CPUMAP program to a device */ /* can not attach BPF_XDP_CPUMAP program to a device */
err = bpf_set_link_xdp_fd(IFINDEX_LO, prog_fd, XDP_FLAGS_SKB_MODE); err = bpf_xdp_attach(IFINDEX_LO, prog_fd, XDP_FLAGS_SKB_MODE, NULL);
if (!ASSERT_NEQ(err, 0, "Attach of BPF_XDP_CPUMAP program")) if (!ASSERT_NEQ(err, 0, "Attach of BPF_XDP_CPUMAP program"))
bpf_set_link_xdp_fd(IFINDEX_LO, -1, XDP_FLAGS_SKB_MODE); bpf_xdp_detach(IFINDEX_LO, XDP_FLAGS_SKB_MODE, NULL);
val.qsize = 192; val.qsize = 192;
val.bpf_prog.fd = bpf_program__fd(skel->progs.xdp_dummy_prog); val.bpf_prog.fd = bpf_program__fd(skel->progs.xdp_dummy_prog);
......
...@@ -26,11 +26,11 @@ static void test_xdp_with_devmap_helpers(void) ...@@ -26,11 +26,11 @@ static void test_xdp_with_devmap_helpers(void)
return; return;
dm_fd = bpf_program__fd(skel->progs.xdp_redir_prog); dm_fd = bpf_program__fd(skel->progs.xdp_redir_prog);
err = bpf_set_link_xdp_fd(IFINDEX_LO, dm_fd, XDP_FLAGS_SKB_MODE); err = bpf_xdp_attach(IFINDEX_LO, dm_fd, XDP_FLAGS_SKB_MODE, NULL);
if (!ASSERT_OK(err, "Generic attach of program with 8-byte devmap")) if (!ASSERT_OK(err, "Generic attach of program with 8-byte devmap"))
goto out_close; goto out_close;
err = bpf_set_link_xdp_fd(IFINDEX_LO, -1, XDP_FLAGS_SKB_MODE); err = bpf_xdp_detach(IFINDEX_LO, XDP_FLAGS_SKB_MODE, NULL);
ASSERT_OK(err, "XDP program detach"); ASSERT_OK(err, "XDP program detach");
dm_fd = bpf_program__fd(skel->progs.xdp_dummy_dm); dm_fd = bpf_program__fd(skel->progs.xdp_dummy_dm);
...@@ -48,9 +48,9 @@ static void test_xdp_with_devmap_helpers(void) ...@@ -48,9 +48,9 @@ static void test_xdp_with_devmap_helpers(void)
ASSERT_EQ(info.id, val.bpf_prog.id, "Match program id to devmap entry prog_id"); ASSERT_EQ(info.id, val.bpf_prog.id, "Match program id to devmap entry prog_id");
/* can not attach BPF_XDP_DEVMAP program to a device */ /* can not attach BPF_XDP_DEVMAP program to a device */
err = bpf_set_link_xdp_fd(IFINDEX_LO, dm_fd, XDP_FLAGS_SKB_MODE); err = bpf_xdp_attach(IFINDEX_LO, dm_fd, XDP_FLAGS_SKB_MODE, NULL);
if (!ASSERT_NEQ(err, 0, "Attach of BPF_XDP_DEVMAP program")) if (!ASSERT_NEQ(err, 0, "Attach of BPF_XDP_DEVMAP program"))
bpf_set_link_xdp_fd(IFINDEX_LO, -1, XDP_FLAGS_SKB_MODE); bpf_xdp_detach(IFINDEX_LO, XDP_FLAGS_SKB_MODE, NULL);
val.ifindex = 1; val.ifindex = 1;
val.bpf_prog.fd = bpf_program__fd(skel->progs.xdp_dummy_prog); val.bpf_prog.fd = bpf_program__fd(skel->progs.xdp_dummy_prog);
......
...@@ -14,13 +14,13 @@ void serial_test_xdp_info(void) ...@@ -14,13 +14,13 @@ void serial_test_xdp_info(void)
/* Get prog_id for XDP_ATTACHED_NONE mode */ /* Get prog_id for XDP_ATTACHED_NONE mode */
err = bpf_get_link_xdp_id(IFINDEX_LO, &prog_id, 0); err = bpf_xdp_query_id(IFINDEX_LO, 0, &prog_id);
if (CHECK(err, "get_xdp_none", "errno=%d\n", errno)) if (CHECK(err, "get_xdp_none", "errno=%d\n", errno))
return; return;
if (CHECK(prog_id, "prog_id_none", "unexpected prog_id=%u\n", prog_id)) if (CHECK(prog_id, "prog_id_none", "unexpected prog_id=%u\n", prog_id))
return; return;
err = bpf_get_link_xdp_id(IFINDEX_LO, &prog_id, XDP_FLAGS_SKB_MODE); err = bpf_xdp_query_id(IFINDEX_LO, XDP_FLAGS_SKB_MODE, &prog_id);
if (CHECK(err, "get_xdp_none_skb", "errno=%d\n", errno)) if (CHECK(err, "get_xdp_none_skb", "errno=%d\n", errno))
return; return;
if (CHECK(prog_id, "prog_id_none_skb", "unexpected prog_id=%u\n", if (CHECK(prog_id, "prog_id_none_skb", "unexpected prog_id=%u\n",
...@@ -37,32 +37,32 @@ void serial_test_xdp_info(void) ...@@ -37,32 +37,32 @@ void serial_test_xdp_info(void)
if (CHECK(err, "get_prog_info", "errno=%d\n", errno)) if (CHECK(err, "get_prog_info", "errno=%d\n", errno))
goto out_close; goto out_close;
err = bpf_set_link_xdp_fd(IFINDEX_LO, prog_fd, XDP_FLAGS_SKB_MODE); err = bpf_xdp_attach(IFINDEX_LO, prog_fd, XDP_FLAGS_SKB_MODE, NULL);
if (CHECK(err, "set_xdp_skb", "errno=%d\n", errno)) if (CHECK(err, "set_xdp_skb", "errno=%d\n", errno))
goto out_close; goto out_close;
/* Get prog_id for single prog mode */ /* Get prog_id for single prog mode */
err = bpf_get_link_xdp_id(IFINDEX_LO, &prog_id, 0); err = bpf_xdp_query_id(IFINDEX_LO, 0, &prog_id);
if (CHECK(err, "get_xdp", "errno=%d\n", errno)) if (CHECK(err, "get_xdp", "errno=%d\n", errno))
goto out; goto out;
if (CHECK(prog_id != info.id, "prog_id", "prog_id not available\n")) if (CHECK(prog_id != info.id, "prog_id", "prog_id not available\n"))
goto out; goto out;
err = bpf_get_link_xdp_id(IFINDEX_LO, &prog_id, XDP_FLAGS_SKB_MODE); err = bpf_xdp_query_id(IFINDEX_LO, XDP_FLAGS_SKB_MODE, &prog_id);
if (CHECK(err, "get_xdp_skb", "errno=%d\n", errno)) if (CHECK(err, "get_xdp_skb", "errno=%d\n", errno))
goto out; goto out;
if (CHECK(prog_id != info.id, "prog_id_skb", "prog_id not available\n")) if (CHECK(prog_id != info.id, "prog_id_skb", "prog_id not available\n"))
goto out; goto out;
err = bpf_get_link_xdp_id(IFINDEX_LO, &prog_id, XDP_FLAGS_DRV_MODE); err = bpf_xdp_query_id(IFINDEX_LO, XDP_FLAGS_DRV_MODE, &prog_id);
if (CHECK(err, "get_xdp_drv", "errno=%d\n", errno)) if (CHECK(err, "get_xdp_drv", "errno=%d\n", errno))
goto out; goto out;
if (CHECK(prog_id, "prog_id_drv", "unexpected prog_id=%u\n", prog_id)) if (CHECK(prog_id, "prog_id_drv", "unexpected prog_id=%u\n", prog_id))
goto out; goto out;
out: out:
bpf_set_link_xdp_fd(IFINDEX_LO, -1, 0); bpf_xdp_detach(IFINDEX_LO, 0, NULL);
out_close: out_close:
bpf_object__close(obj); bpf_object__close(obj);
} }
...@@ -8,9 +8,9 @@ ...@@ -8,9 +8,9 @@
void serial_test_xdp_link(void) void serial_test_xdp_link(void)
{ {
DECLARE_LIBBPF_OPTS(bpf_xdp_set_link_opts, opts, .old_fd = -1);
struct test_xdp_link *skel1 = NULL, *skel2 = NULL; struct test_xdp_link *skel1 = NULL, *skel2 = NULL;
__u32 id1, id2, id0 = 0, prog_fd1, prog_fd2; __u32 id1, id2, id0 = 0, prog_fd1, prog_fd2;
LIBBPF_OPTS(bpf_xdp_attach_opts, opts);
struct bpf_link_info link_info; struct bpf_link_info link_info;
struct bpf_prog_info prog_info; struct bpf_prog_info prog_info;
struct bpf_link *link; struct bpf_link *link;
...@@ -41,12 +41,12 @@ void serial_test_xdp_link(void) ...@@ -41,12 +41,12 @@ void serial_test_xdp_link(void)
id2 = prog_info.id; id2 = prog_info.id;
/* set initial prog attachment */ /* set initial prog attachment */
err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, prog_fd1, XDP_FLAGS_REPLACE, &opts); err = bpf_xdp_attach(IFINDEX_LO, prog_fd1, XDP_FLAGS_REPLACE, &opts);
if (!ASSERT_OK(err, "fd_attach")) if (!ASSERT_OK(err, "fd_attach"))
goto cleanup; goto cleanup;
/* validate prog ID */ /* validate prog ID */
err = bpf_get_link_xdp_id(IFINDEX_LO, &id0, 0); err = bpf_xdp_query_id(IFINDEX_LO, 0, &id0);
if (!ASSERT_OK(err, "id1_check_err") || !ASSERT_EQ(id0, id1, "id1_check_val")) if (!ASSERT_OK(err, "id1_check_err") || !ASSERT_EQ(id0, id1, "id1_check_val"))
goto cleanup; goto cleanup;
...@@ -55,14 +55,14 @@ void serial_test_xdp_link(void) ...@@ -55,14 +55,14 @@ void serial_test_xdp_link(void)
if (!ASSERT_ERR_PTR(link, "link_attach_should_fail")) { if (!ASSERT_ERR_PTR(link, "link_attach_should_fail")) {
bpf_link__destroy(link); bpf_link__destroy(link);
/* best-effort detach prog */ /* best-effort detach prog */
opts.old_fd = prog_fd1; opts.old_prog_fd = prog_fd1;
bpf_set_link_xdp_fd_opts(IFINDEX_LO, -1, XDP_FLAGS_REPLACE, &opts); bpf_xdp_detach(IFINDEX_LO, XDP_FLAGS_REPLACE, &opts);
goto cleanup; goto cleanup;
} }
/* detach BPF program */ /* detach BPF program */
opts.old_fd = prog_fd1; opts.old_prog_fd = prog_fd1;
err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, -1, XDP_FLAGS_REPLACE, &opts); err = bpf_xdp_detach(IFINDEX_LO, XDP_FLAGS_REPLACE, &opts);
if (!ASSERT_OK(err, "prog_detach")) if (!ASSERT_OK(err, "prog_detach"))
goto cleanup; goto cleanup;
...@@ -73,23 +73,23 @@ void serial_test_xdp_link(void) ...@@ -73,23 +73,23 @@ void serial_test_xdp_link(void)
skel1->links.xdp_handler = link; skel1->links.xdp_handler = link;
/* validate prog ID */ /* validate prog ID */
err = bpf_get_link_xdp_id(IFINDEX_LO, &id0, 0); err = bpf_xdp_query_id(IFINDEX_LO, 0, &id0);
if (!ASSERT_OK(err, "id1_check_err") || !ASSERT_EQ(id0, id1, "id1_check_val")) if (!ASSERT_OK(err, "id1_check_err") || !ASSERT_EQ(id0, id1, "id1_check_val"))
goto cleanup; goto cleanup;
/* BPF prog attach is not allowed to replace BPF link */ /* BPF prog attach is not allowed to replace BPF link */
opts.old_fd = prog_fd1; opts.old_prog_fd = prog_fd1;
err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, prog_fd2, XDP_FLAGS_REPLACE, &opts); err = bpf_xdp_attach(IFINDEX_LO, prog_fd2, XDP_FLAGS_REPLACE, &opts);
if (!ASSERT_ERR(err, "prog_attach_fail")) if (!ASSERT_ERR(err, "prog_attach_fail"))
goto cleanup; goto cleanup;
/* Can't force-update when BPF link is active */ /* Can't force-update when BPF link is active */
err = bpf_set_link_xdp_fd(IFINDEX_LO, prog_fd2, 0); err = bpf_xdp_attach(IFINDEX_LO, prog_fd2, 0, NULL);
if (!ASSERT_ERR(err, "prog_update_fail")) if (!ASSERT_ERR(err, "prog_update_fail"))
goto cleanup; goto cleanup;
/* Can't force-detach when BPF link is active */ /* Can't force-detach when BPF link is active */
err = bpf_set_link_xdp_fd(IFINDEX_LO, -1, 0); err = bpf_xdp_detach(IFINDEX_LO, 0, NULL);
if (!ASSERT_ERR(err, "prog_detach_fail")) if (!ASSERT_ERR(err, "prog_detach_fail"))
goto cleanup; goto cleanup;
...@@ -109,7 +109,7 @@ void serial_test_xdp_link(void) ...@@ -109,7 +109,7 @@ void serial_test_xdp_link(void)
goto cleanup; goto cleanup;
skel2->links.xdp_handler = link; skel2->links.xdp_handler = link;
err = bpf_get_link_xdp_id(IFINDEX_LO, &id0, 0); err = bpf_xdp_query_id(IFINDEX_LO, 0, &id0);
if (!ASSERT_OK(err, "id2_check_err") || !ASSERT_EQ(id0, id2, "id2_check_val")) if (!ASSERT_OK(err, "id2_check_err") || !ASSERT_EQ(id0, id2, "id2_check_val"))
goto cleanup; goto cleanup;
......
...@@ -738,7 +738,7 @@ static void test_sockmap(unsigned int tasks, void *data) ...@@ -738,7 +738,7 @@ static void test_sockmap(unsigned int tasks, void *data)
sizeof(key), sizeof(value), sizeof(key), sizeof(value),
6, NULL); 6, NULL);
if (fd < 0) { if (fd < 0) {
if (!bpf_probe_map_type(BPF_MAP_TYPE_SOCKMAP, 0)) { if (!libbpf_probe_bpf_map_type(BPF_MAP_TYPE_SOCKMAP, NULL)) {
printf("%s SKIP (unsupported map type BPF_MAP_TYPE_SOCKMAP)\n", printf("%s SKIP (unsupported map type BPF_MAP_TYPE_SOCKMAP)\n",
__func__); __func__);
skips++; skips++;
......
...@@ -456,7 +456,7 @@ static int probe_filter_length(const struct bpf_insn *fp) ...@@ -456,7 +456,7 @@ static int probe_filter_length(const struct bpf_insn *fp)
static bool skip_unsupported_map(enum bpf_map_type map_type) static bool skip_unsupported_map(enum bpf_map_type map_type)
{ {
if (!bpf_probe_map_type(map_type, 0)) { if (!libbpf_probe_bpf_map_type(map_type, NULL)) {
printf("SKIP (unsupported map type %d)\n", map_type); printf("SKIP (unsupported map type %d)\n", map_type);
skips++; skips++;
return true; return true;
...@@ -1180,7 +1180,7 @@ static void do_test_single(struct bpf_test *test, bool unpriv, ...@@ -1180,7 +1180,7 @@ static void do_test_single(struct bpf_test *test, bool unpriv,
* bpf_probe_prog_type won't give correct answer * bpf_probe_prog_type won't give correct answer
*/ */
if (fd_prog < 0 && prog_type != BPF_PROG_TYPE_TRACING && if (fd_prog < 0 && prog_type != BPF_PROG_TYPE_TRACING &&
!bpf_probe_prog_type(prog_type, 0)) { !libbpf_probe_bpf_prog_type(prog_type, NULL)) {
printf("SKIP (unsupported program type %d)\n", prog_type); printf("SKIP (unsupported program type %d)\n", prog_type);
skips++; skips++;
goto close_fds; goto close_fds;
......
...@@ -32,12 +32,12 @@ static void int_exit(int sig) ...@@ -32,12 +32,12 @@ static void int_exit(int sig)
int i; int i;
for (i = 0; ifaces[i] > 0; i++) { for (i = 0; ifaces[i] > 0; i++) {
if (bpf_get_link_xdp_id(ifaces[i], &prog_id, xdp_flags)) { if (bpf_xdp_query_id(ifaces[i], xdp_flags, &prog_id)) {
printf("bpf_get_link_xdp_id failed\n"); printf("bpf_xdp_query_id failed\n");
exit(1); exit(1);
} }
if (prog_id) if (prog_id)
bpf_set_link_xdp_fd(ifaces[i], -1, xdp_flags); bpf_xdp_detach(ifaces[i], xdp_flags, NULL);
} }
exit(0); exit(0);
...@@ -210,7 +210,7 @@ int main(int argc, char **argv) ...@@ -210,7 +210,7 @@ int main(int argc, char **argv)
} }
/* bind prog_fd to each interface */ /* bind prog_fd to each interface */
ret = bpf_set_link_xdp_fd(ifindex, prog_fd, xdp_flags); ret = bpf_xdp_attach(ifindex, prog_fd, xdp_flags, NULL);
if (ret) { if (ret) {
printf("Set xdp fd failed on %d\n", ifindex); printf("Set xdp fd failed on %d\n", ifindex);
goto err_out; goto err_out;
......
...@@ -29,7 +29,7 @@ static __u32 xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST; ...@@ -29,7 +29,7 @@ static __u32 xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST;
static void cleanup(int sig) static void cleanup(int sig)
{ {
bpf_set_link_xdp_fd(ifindex, -1, xdp_flags); bpf_xdp_detach(ifindex, xdp_flags, NULL);
if (sig) if (sig)
exit(1); exit(1);
} }
...@@ -203,7 +203,7 @@ int main(int argc, char **argv) ...@@ -203,7 +203,7 @@ int main(int argc, char **argv)
printf("XDP setup disrupts network connectivity, hit Ctrl+C to quit\n"); printf("XDP setup disrupts network connectivity, hit Ctrl+C to quit\n");
if (bpf_set_link_xdp_fd(ifindex, prog_fd, xdp_flags) < 0) { if (bpf_xdp_attach(ifindex, prog_fd, xdp_flags, NULL) < 0) {
fprintf(stderr, "Link set xdp fd failed for %s\n", ifname); fprintf(stderr, "Link set xdp fd failed for %s\n", ifname);
goto done; goto done;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment