Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <mhal@rbox.co>
Acked-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Michal Luczaj and committed by
Paolo Abeni
85928e9c 8350695b

+30
+30
tools/testing/selftests/bpf/prog_tests/sockmap_basic.c
··· 1065 1065 test_sockmap_pass_prog__destroy(skel); 1066 1066 } 1067 1067 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 + 1068 1096 void test_sockmap_basic(void) 1069 1097 { 1070 1098 if (test__start_subtest("sockmap create_update_free")) ··· 1159 1131 test_skmsg_helpers_with_link(BPF_MAP_TYPE_SOCKHASH); 1160 1132 if (test__start_subtest("sockmap skb_verdict vsock poll")) 1161 1133 test_sockmap_skb_verdict_vsock_poll(); 1134 + if (test__start_subtest("sockmap vsock unconnected")) 1135 + test_sockmap_vsock_unconnected(); 1162 1136 }