Skip to content

Commit 5157454

Browse files
mmhalAlexei Starovoitov
authored andcommitted
selftest/bpf: Add test for vsock removal from sockmap on close()
Make sure the proto::close callback gets invoked on vsock release. Signed-off-by: Michal Luczaj <[email protected]> Acked-by: Stefano Garzarella <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: John Fastabend <[email protected]>
1 parent 135ffc7 commit 5157454

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tools/testing/selftests/bpf/prog_tests/sockmap_basic.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,35 @@ static void test_sockmap_create_update_free(enum bpf_map_type map_type)
108108
close(s);
109109
}
110110

111+
static void test_sockmap_vsock_delete_on_close(void)
112+
{
113+
int err, c, p, map;
114+
const int zero = 0;
115+
116+
err = create_pair(AF_VSOCK, SOCK_STREAM, &c, &p);
117+
if (!ASSERT_OK(err, "create_pair(AF_VSOCK)"))
118+
return;
119+
120+
map = bpf_map_create(BPF_MAP_TYPE_SOCKMAP, NULL, sizeof(int),
121+
sizeof(int), 1, NULL);
122+
if (!ASSERT_GE(map, 0, "bpf_map_create")) {
123+
close(c);
124+
goto out;
125+
}
126+
127+
err = bpf_map_update_elem(map, &zero, &c, BPF_NOEXIST);
128+
close(c);
129+
if (!ASSERT_OK(err, "bpf_map_update"))
130+
goto out;
131+
132+
err = bpf_map_update_elem(map, &zero, &p, BPF_NOEXIST);
133+
ASSERT_OK(err, "after close(), bpf_map_update");
134+
135+
out:
136+
close(p);
137+
close(map);
138+
}
139+
111140
static void test_skmsg_helpers(enum bpf_map_type map_type)
112141
{
113142
struct test_skmsg_load_helpers *skel;
@@ -987,6 +1016,8 @@ void test_sockmap_basic(void)
9871016
test_sockmap_create_update_free(BPF_MAP_TYPE_SOCKMAP);
9881017
if (test__start_subtest("sockhash create_update_free"))
9891018
test_sockmap_create_update_free(BPF_MAP_TYPE_SOCKHASH);
1019+
if (test__start_subtest("sockmap vsock delete on close"))
1020+
test_sockmap_vsock_delete_on_close();
9901021
if (test__start_subtest("sockmap sk_msg load helpers"))
9911022
test_skmsg_helpers(BPF_MAP_TYPE_SOCKMAP);
9921023
if (test__start_subtest("sockhash sk_msg load helpers"))

0 commit comments

Comments
 (0)