Commit 6ebb85c8 authored by Jakub Sitnicki's avatar Jakub Sitnicki Committed by Alexei Starovoitov

selftests/bpf: Test updating flow_dissector link with same program

This case, while not particularly useful, is worth covering because we
expect the operation to succeed as opposed when re-attaching the same
program directly with PROG_ATTACH.

While at it, update the tests summary that fell out of sync when tests
extended to cover links.
Signed-off-by: default avatarJakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Acked-by: default avatarMartin KaFai Lau <kafai@fb.com>
Link: https://lore.kernel.org/bpf/20200625141357.910330-5-jakub@cloudflare.com
parent ab53cad9
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
/* /*
* Test that the flow_dissector program can be updated with a single * Tests for attaching, detaching, and replacing flow_dissector BPF program.
* syscall by attaching a new program that replaces the existing one.
*
* Corner case - the same program cannot be attached twice.
*/ */
#define _GNU_SOURCE #define _GNU_SOURCE
...@@ -308,6 +305,31 @@ static void test_link_update_replace_old_prog(int netns, int prog1, int prog2) ...@@ -308,6 +305,31 @@ static void test_link_update_replace_old_prog(int netns, int prog1, int prog2)
CHECK_FAIL(prog_is_attached(netns)); CHECK_FAIL(prog_is_attached(netns));
} }
static void test_link_update_same_prog(int netns, int prog1, int prog2)
{
DECLARE_LIBBPF_OPTS(bpf_link_create_opts, create_opts);
DECLARE_LIBBPF_OPTS(bpf_link_update_opts, update_opts);
int err, link;
link = bpf_link_create(prog1, netns, BPF_FLOW_DISSECTOR, &create_opts);
if (CHECK_FAIL(link < 0)) {
perror("bpf_link_create(prog1)");
return;
}
CHECK_FAIL(query_attached_prog_id(netns) != query_prog_id(prog1));
/* Expect success updating the prog with the same one */
update_opts.flags = 0;
update_opts.old_prog_fd = 0;
err = bpf_link_update(link, prog1, &update_opts);
if (CHECK_FAIL(err))
perror("bpf_link_update");
CHECK_FAIL(query_attached_prog_id(netns) != query_prog_id(prog1));
close(link);
CHECK_FAIL(prog_is_attached(netns));
}
static void test_link_update_invalid_opts(int netns, int prog1, int prog2) static void test_link_update_invalid_opts(int netns, int prog1, int prog2)
{ {
DECLARE_LIBBPF_OPTS(bpf_link_create_opts, create_opts); DECLARE_LIBBPF_OPTS(bpf_link_create_opts, create_opts);
...@@ -571,6 +593,8 @@ static void run_tests(int netns) ...@@ -571,6 +593,8 @@ static void run_tests(int netns)
test_link_update_no_old_prog }, test_link_update_no_old_prog },
{ "link update with replace old prog", { "link update with replace old prog",
test_link_update_replace_old_prog }, test_link_update_replace_old_prog },
{ "link update with same prog",
test_link_update_same_prog },
{ "link update invalid opts", { "link update invalid opts",
test_link_update_invalid_opts }, test_link_update_invalid_opts },
{ "link update invalid prog", { "link update invalid prog",
......
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