Commit 0bfb95f5 authored by Daniel Borkmann's avatar Daniel Borkmann

selftests, bpf: Do not yet switch to new libbpf XDP APIs

Revert commit 54435652 ("selftests/bpf: switch to new libbpf XDP APIs")
for now given this will heavily conflict with 4b27480d ("bpf/selftests:
convert xdp_link test to ASSERT_* macros") upon merge. Andrii agreed to redo
the conversion cleanly after trees merged.
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarAlexei Starovoitov <ast@kernel.org>
Acked-by: default avatarAndrii Nakryiko <andrii@kernel.org>
parent b4ec6a19
...@@ -11,7 +11,8 @@ void serial_test_xdp_attach(void) ...@@ -11,7 +11,8 @@ 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;
LIBBPF_OPTS(bpf_xdp_attach_opts, opts); DECLARE_LIBBPF_OPTS(bpf_xdp_set_link_opts, opts,
.old_fd = -1);
len = sizeof(info); len = sizeof(info);
...@@ -37,47 +38,49 @@ void serial_test_xdp_attach(void) ...@@ -37,47 +38,49 @@ void serial_test_xdp_attach(void)
if (CHECK_FAIL(err)) if (CHECK_FAIL(err))
goto out_2; goto out_2;
err = bpf_xdp_attach(IFINDEX_LO, fd1, XDP_FLAGS_REPLACE, &opts); err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, fd1, XDP_FLAGS_REPLACE,
&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_xdp_query_id(IFINDEX_LO, 0, &id0); err = bpf_get_link_xdp_id(IFINDEX_LO, &id0, 0);
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_xdp_attach(IFINDEX_LO, fd2, XDP_FLAGS_REPLACE, &opts); err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, fd2, XDP_FLAGS_REPLACE,
&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_prog_fd = fd1; opts.old_fd = fd1;
err = bpf_xdp_attach(IFINDEX_LO, fd2, 0, &opts); err = bpf_set_link_xdp_fd_opts(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_xdp_query_id(IFINDEX_LO, 0, &id0); err = bpf_get_link_xdp_id(IFINDEX_LO, &id0, 0);
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_xdp_attach(IFINDEX_LO, fd3, 0, &opts); err = bpf_set_link_xdp_fd_opts(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_xdp_detach(IFINDEX_LO, 0, &opts); err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, -1, 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_prog_fd = fd2; opts.old_fd = fd2;
err = bpf_xdp_detach(IFINDEX_LO, 0, &opts); err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, -1, 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_xdp_query_id(IFINDEX_LO, 0, &id0); err = bpf_get_link_xdp_id(IFINDEX_LO, &id0, 0);
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_xdp_detach(IFINDEX_LO, 0, NULL); bpf_set_link_xdp_fd(IFINDEX_LO, -1, 0);
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_xdp_attach(IFINDEX_LO, prog_fd, XDP_FLAGS_SKB_MODE, NULL); err = bpf_set_link_xdp_fd(IFINDEX_LO, prog_fd, XDP_FLAGS_SKB_MODE);
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_xdp_detach(IFINDEX_LO, XDP_FLAGS_SKB_MODE, NULL); err = bpf_set_link_xdp_fd(IFINDEX_LO, -1, XDP_FLAGS_SKB_MODE);
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_xdp_attach(IFINDEX_LO, prog_fd, XDP_FLAGS_SKB_MODE, NULL); err = bpf_set_link_xdp_fd(IFINDEX_LO, prog_fd, XDP_FLAGS_SKB_MODE);
if (!ASSERT_NEQ(err, 0, "Attach of BPF_XDP_CPUMAP program")) if (!ASSERT_NEQ(err, 0, "Attach of BPF_XDP_CPUMAP program"))
bpf_xdp_detach(IFINDEX_LO, XDP_FLAGS_SKB_MODE, NULL); bpf_set_link_xdp_fd(IFINDEX_LO, -1, XDP_FLAGS_SKB_MODE);
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_xdp_attach(IFINDEX_LO, dm_fd, XDP_FLAGS_SKB_MODE, NULL); err = bpf_set_link_xdp_fd(IFINDEX_LO, dm_fd, XDP_FLAGS_SKB_MODE);
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_xdp_detach(IFINDEX_LO, XDP_FLAGS_SKB_MODE, NULL); err = bpf_set_link_xdp_fd(IFINDEX_LO, -1, XDP_FLAGS_SKB_MODE);
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_xdp_attach(IFINDEX_LO, dm_fd, XDP_FLAGS_SKB_MODE, NULL); err = bpf_set_link_xdp_fd(IFINDEX_LO, dm_fd, XDP_FLAGS_SKB_MODE);
if (!ASSERT_NEQ(err, 0, "Attach of BPF_XDP_DEVMAP program")) if (!ASSERT_NEQ(err, 0, "Attach of BPF_XDP_DEVMAP program"))
bpf_xdp_detach(IFINDEX_LO, XDP_FLAGS_SKB_MODE, NULL); bpf_set_link_xdp_fd(IFINDEX_LO, -1, XDP_FLAGS_SKB_MODE);
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_xdp_query_id(IFINDEX_LO, 0, &prog_id); err = bpf_get_link_xdp_id(IFINDEX_LO, &prog_id, 0);
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_xdp_query_id(IFINDEX_LO, XDP_FLAGS_SKB_MODE, &prog_id); err = bpf_get_link_xdp_id(IFINDEX_LO, &prog_id, XDP_FLAGS_SKB_MODE);
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_xdp_attach(IFINDEX_LO, prog_fd, XDP_FLAGS_SKB_MODE, NULL); err = bpf_set_link_xdp_fd(IFINDEX_LO, prog_fd, XDP_FLAGS_SKB_MODE);
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_xdp_query_id(IFINDEX_LO, 0, &prog_id); err = bpf_get_link_xdp_id(IFINDEX_LO, &prog_id, 0);
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_xdp_query_id(IFINDEX_LO, XDP_FLAGS_SKB_MODE, &prog_id); err = bpf_get_link_xdp_id(IFINDEX_LO, &prog_id, XDP_FLAGS_SKB_MODE);
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_xdp_query_id(IFINDEX_LO, XDP_FLAGS_DRV_MODE, &prog_id); err = bpf_get_link_xdp_id(IFINDEX_LO, &prog_id, XDP_FLAGS_DRV_MODE);
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_xdp_detach(IFINDEX_LO, 0, NULL); bpf_set_link_xdp_fd(IFINDEX_LO, -1, 0);
out_close: out_close:
bpf_object__close(obj); bpf_object__close(obj);
} }
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
void serial_test_xdp_link(void) void serial_test_xdp_link(void)
{ {
__u32 duration = 0, id1, id2, id0 = 0, prog_fd1, prog_fd2, err; __u32 duration = 0, id1, id2, id0 = 0, prog_fd1, prog_fd2, err;
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;
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;
...@@ -40,12 +40,12 @@ void serial_test_xdp_link(void) ...@@ -40,12 +40,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_xdp_attach(IFINDEX_LO, prog_fd1, XDP_FLAGS_REPLACE, &opts); err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, prog_fd1, XDP_FLAGS_REPLACE, &opts);
if (CHECK(err, "fd_attach", "initial prog attach failed: %d\n", err)) if (CHECK(err, "fd_attach", "initial prog attach failed: %d\n", err))
goto cleanup; goto cleanup;
/* validate prog ID */ /* validate prog ID */
err = bpf_xdp_query_id(IFINDEX_LO, 0, &id0); err = bpf_get_link_xdp_id(IFINDEX_LO, &id0, 0);
CHECK(err || id0 != id1, "id1_check", 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);
...@@ -54,14 +54,14 @@ void serial_test_xdp_link(void) ...@@ -54,14 +54,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_prog_fd = prog_fd1; opts.old_fd = prog_fd1;
bpf_xdp_detach(IFINDEX_LO, XDP_FLAGS_REPLACE, &opts); bpf_set_link_xdp_fd_opts(IFINDEX_LO, -1, XDP_FLAGS_REPLACE, &opts);
goto cleanup; goto cleanup;
} }
/* detach BPF program */ /* detach BPF program */
opts.old_prog_fd = prog_fd1; opts.old_fd = prog_fd1;
err = bpf_xdp_detach(IFINDEX_LO, XDP_FLAGS_REPLACE, &opts); err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, -1, XDP_FLAGS_REPLACE, &opts);
if (CHECK(err, "prog_detach", "failed %d\n", err)) if (CHECK(err, "prog_detach", "failed %d\n", err))
goto cleanup; goto cleanup;
...@@ -72,24 +72,24 @@ void serial_test_xdp_link(void) ...@@ -72,24 +72,24 @@ void serial_test_xdp_link(void)
skel1->links.xdp_handler = link; skel1->links.xdp_handler = link;
/* validate prog ID */ /* validate prog ID */
err = bpf_xdp_query_id(IFINDEX_LO, 0, &id0); err = bpf_get_link_xdp_id(IFINDEX_LO, &id0, 0);
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 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_prog_fd = prog_fd1; opts.old_fd = prog_fd1;
err = bpf_xdp_attach(IFINDEX_LO, prog_fd2, XDP_FLAGS_REPLACE, &opts); err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, prog_fd2, XDP_FLAGS_REPLACE, &opts);
if (CHECK(!err, "prog_attach_fail", "unexpected success\n")) if (CHECK(!err, "prog_attach_fail", "unexpected success\n"))
goto cleanup; goto cleanup;
/* Can't force-update when BPF link is active */ /* Can't force-update when BPF link is active */
err = bpf_xdp_attach(IFINDEX_LO, prog_fd2, 0, NULL); err = bpf_set_link_xdp_fd(IFINDEX_LO, prog_fd2, 0);
if (CHECK(!err, "prog_update_fail", "unexpected success\n")) if (CHECK(!err, "prog_update_fail", "unexpected success\n"))
goto cleanup; goto cleanup;
/* Can't force-detach when BPF link is active */ /* Can't force-detach when BPF link is active */
err = bpf_xdp_detach(IFINDEX_LO, 0, NULL); err = bpf_set_link_xdp_fd(IFINDEX_LO, -1, 0);
if (CHECK(!err, "prog_detach_fail", "unexpected success\n")) if (CHECK(!err, "prog_detach_fail", "unexpected success\n"))
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_xdp_query_id(IFINDEX_LO, 0, &id0); err = bpf_get_link_xdp_id(IFINDEX_LO, &id0, 0);
if (CHECK(err || id0 != id2, "id2_check", if (CHECK(err || id0 != id2, "id2_check",
"loaded prog id %u != id2 %u, err %d", id0, id1, err)) "loaded prog id %u != id2 %u, err %d", id0, id1, err))
goto cleanup; goto cleanup;
......
...@@ -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_xdp_query_id(ifaces[i], xdp_flags, &prog_id)) { if (bpf_get_link_xdp_id(ifaces[i], &prog_id, xdp_flags)) {
printf("bpf_xdp_query_id failed\n"); printf("bpf_get_link_xdp_id failed\n");
exit(1); exit(1);
} }
if (prog_id) if (prog_id)
bpf_xdp_detach(ifaces[i], xdp_flags, NULL); bpf_set_link_xdp_fd(ifaces[i], -1, xdp_flags);
} }
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_xdp_attach(ifindex, prog_fd, xdp_flags, NULL); ret = bpf_set_link_xdp_fd(ifindex, prog_fd, xdp_flags);
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_xdp_detach(ifindex, xdp_flags, NULL); bpf_set_link_xdp_fd(ifindex, -1, xdp_flags);
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_xdp_attach(ifindex, prog_fd, xdp_flags, NULL) < 0) { if (bpf_set_link_xdp_fd(ifindex, prog_fd, xdp_flags) < 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