Skip to content

Commit 85928e9

Browse files
mmhalPaolo Abeni
authored andcommitted
selftest/bpf: Add vsock test for sockmap rejecting unconnected
Verify that for a connectible AF_VSOCK socket, merely having a transport assigned is insufficient; socket must be connected for the sockmap to accept. This does not test datagram vsocks. Even though it hardly matters. VMCI is the only transport that features VSOCK_TRANSPORT_F_DGRAM, but it has an unimplemented vsock_transport::readskb() callback, making it unsupported by BPF/sockmap. Signed-off-by: Michal Luczaj <[email protected]> Acked-by: Stefano Garzarella <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 8350695 commit 85928e9

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,34 @@ static void test_sockmap_skb_verdict_vsock_poll(void)
10651065
test_sockmap_pass_prog__destroy(skel);
10661066
}
10671067

1068+
static void test_sockmap_vsock_unconnected(void)
1069+
{
1070+
struct sockaddr_storage addr;
1071+
int map, s, zero = 0;
1072+
socklen_t alen;
1073+
1074+
map = bpf_map_create(BPF_MAP_TYPE_SOCKMAP, NULL, sizeof(int),
1075+
sizeof(int), 1, NULL);
1076+
if (!ASSERT_OK_FD(map, "bpf_map_create"))
1077+
return;
1078+
1079+
s = xsocket(AF_VSOCK, SOCK_STREAM, 0);
1080+
if (s < 0)
1081+
goto close_map;
1082+
1083+
/* Fail connect(), but trigger transport assignment. */
1084+
init_addr_loopback(AF_VSOCK, &addr, &alen);
1085+
if (!ASSERT_ERR(connect(s, sockaddr(&addr), alen), "connect"))
1086+
goto close_sock;
1087+
1088+
ASSERT_ERR(bpf_map_update_elem(map, &zero, &s, BPF_ANY), "map_update");
1089+
1090+
close_sock:
1091+
xclose(s);
1092+
close_map:
1093+
xclose(map);
1094+
}
1095+
10681096
void test_sockmap_basic(void)
10691097
{
10701098
if (test__start_subtest("sockmap create_update_free"))
@@ -1131,4 +1159,6 @@ void test_sockmap_basic(void)
11311159
test_skmsg_helpers_with_link(BPF_MAP_TYPE_SOCKHASH);
11321160
if (test__start_subtest("sockmap skb_verdict vsock poll"))
11331161
test_sockmap_skb_verdict_vsock_poll();
1162+
if (test__start_subtest("sockmap vsock unconnected"))
1163+
test_sockmap_vsock_unconnected();
11341164
}

0 commit comments

Comments
 (0)