]> www.infradead.org Git - users/hch/misc.git/commitdiff
selftest/bpf: Adapt vsock_delete_on_close to sockmap rejecting unconnected
authorMichal Luczaj <mhal@rbox.co>
Thu, 13 Feb 2025 11:58:51 +0000 (12:58 +0100)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 18 Feb 2025 11:00:01 +0000 (12:00 +0100)
Commit 515745445e92 ("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 <mhal@rbox.co>
Acked-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
tools/testing/selftests/bpf/prog_tests/sockmap_basic.c

index 884ad87783d59ef3d1ca84c3a542f3f8670cd463..21793d8c79e12b6e607f59ecebb26448c310044b 100644 (file)
@@ -111,31 +111,35 @@ out:
 
 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)