Skip to content

Commit 8350695

Browse files
mmhalPaolo Abeni
authored andcommitted
selftest/bpf: Adapt vsock_delete_on_close to sockmap rejecting unconnected
Commit 5157454 ("selftest/bpf: Add test for vsock removal from sockmap on close()") added test that checked if proto::close() callback was invoked on AF_VSOCK socket release. I.e. it verified that a close()d vsock does indeed get removed from the sockmap. It was done simply by creating a socket pair and attempting to replace a close()d one with its peer. Since, due to a recent change, sockmap does not allow updating index with a non-established connectible vsock, redo it with a freshly established one. Signed-off-by: Michal Luczaj <[email protected]> Acked-by: Stefano Garzarella <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 857ae05 commit 8350695

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

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

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -111,31 +111,35 @@ static void test_sockmap_create_update_free(enum bpf_map_type map_type)
111111

112112
static void test_sockmap_vsock_delete_on_close(void)
113113
{
114-
int err, c, p, map;
115-
const int zero = 0;
116-
117-
err = create_pair(AF_VSOCK, SOCK_STREAM, &c, &p);
118-
if (!ASSERT_OK(err, "create_pair(AF_VSOCK)"))
119-
return;
114+
int map, c, p, err, zero = 0;
120115

121116
map = bpf_map_create(BPF_MAP_TYPE_SOCKMAP, NULL, sizeof(int),
122117
sizeof(int), 1, NULL);
123-
if (!ASSERT_GE(map, 0, "bpf_map_create")) {
124-
close(c);
125-
goto out;
126-
}
118+
if (!ASSERT_OK_FD(map, "bpf_map_create"))
119+
return;
127120

128-
err = bpf_map_update_elem(map, &zero, &c, BPF_NOEXIST);
129-
close(c);
130-
if (!ASSERT_OK(err, "bpf_map_update"))
131-
goto out;
121+
err = create_pair(AF_VSOCK, SOCK_STREAM, &c, &p);
122+
if (!ASSERT_OK(err, "create_pair"))
123+
goto close_map;
132124

133-
err = bpf_map_update_elem(map, &zero, &p, BPF_NOEXIST);
125+
if (xbpf_map_update_elem(map, &zero, &c, BPF_NOEXIST))
126+
goto close_socks;
127+
128+
xclose(c);
129+
xclose(p);
130+
131+
err = create_pair(AF_VSOCK, SOCK_STREAM, &c, &p);
132+
if (!ASSERT_OK(err, "create_pair"))
133+
goto close_map;
134+
135+
err = bpf_map_update_elem(map, &zero, &c, BPF_NOEXIST);
134136
ASSERT_OK(err, "after close(), bpf_map_update");
135137

136-
out:
137-
close(p);
138-
close(map);
138+
close_socks:
139+
xclose(c);
140+
xclose(p);
141+
close_map:
142+
xclose(map);
139143
}
140144

141145
static void test_skmsg_helpers(enum bpf_map_type map_type)

0 commit comments

Comments
 (0)