Commit 8350695b authored by Michal Luczaj's avatar Michal Luczaj Committed by Paolo Abeni
Browse files

selftest/bpf: Adapt vsock_delete_on_close to sockmap rejecting unconnected



Commit 51574544 ("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: default avatarMichal Luczaj <mhal@rbox.co>
Acked-by: default avatarStefano Garzarella <sgarzare@redhat.com>
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent 857ae055
Loading
Loading
Loading
Loading
+22 −18
Original line number Diff line number Diff line
@@ -111,31 +111,35 @@ static void test_sockmap_create_update_free(enum bpf_map_type map_type)

static void test_sockmap_vsock_delete_on_close(void)
{
	int err, c, p, map;
	const int zero = 0;

	err = create_pair(AF_VSOCK, SOCK_STREAM, &c, &p);
	if (!ASSERT_OK(err, "create_pair(AF_VSOCK)"))
		return;
	int map, c, p, err, zero = 0;

	map = bpf_map_create(BPF_MAP_TYPE_SOCKMAP, NULL, sizeof(int),
			     sizeof(int), 1, NULL);
	if (!ASSERT_GE(map, 0, "bpf_map_create")) {
		close(c);
		goto out;
	}
	if (!ASSERT_OK_FD(map, "bpf_map_create"))
		return;

	err = bpf_map_update_elem(map, &zero, &c, BPF_NOEXIST);
	close(c);
	if (!ASSERT_OK(err, "bpf_map_update"))
		goto out;
	err = create_pair(AF_VSOCK, SOCK_STREAM, &c, &p);
	if (!ASSERT_OK(err, "create_pair"))
		goto close_map;

	err = bpf_map_update_elem(map, &zero, &p, BPF_NOEXIST);
	if (xbpf_map_update_elem(map, &zero, &c, BPF_NOEXIST))
		goto close_socks;

	xclose(c);
	xclose(p);

	err = create_pair(AF_VSOCK, SOCK_STREAM, &c, &p);
	if (!ASSERT_OK(err, "create_pair"))
		goto close_map;

	err = bpf_map_update_elem(map, &zero, &c, BPF_NOEXIST);
	ASSERT_OK(err, "after close(), bpf_map_update");

out:
	close(p);
	close(map);
close_socks:
	xclose(c);
	xclose(p);
close_map:
	xclose(map);
}

static void test_skmsg_helpers(enum bpf_map_type map_type)