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

selftests/bpf: Update arguments of connect_to_addr

Move the third argument "int type" of connect_to_addr() to the first one
which is closer to how the socket syscall is doing it. And add a
network_helper_opts argument as the fourth one. Then change its usages in
sock_addr.c too.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Link: https://lore.kernel.org/r/088ea8a95055f93409c5f57d12f0e58d43059ac4.1713427236.git.tanggeliang@kylinos.cn
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>

authored by

Geliang Tang and committed by
Martin KaFai Lau
db9994d0 a2e49795

+15 -7
+10 -3
tools/testing/selftests/bpf/network_helpers.c
··· 270 270 return 0; 271 271 } 272 272 273 - int connect_to_addr(const struct sockaddr_storage *addr, socklen_t addrlen, int type) 273 + int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t addrlen, 274 + const struct network_helper_opts *opts) 274 275 { 275 276 int fd; 276 277 277 - fd = socket(addr->ss_family, type, 0); 278 + if (!opts) 279 + opts = &default_opts; 280 + 281 + fd = socket(addr->ss_family, type, opts->proto); 278 282 if (fd < 0) { 279 283 log_err("Failed to create client socket"); 280 284 return -1; 281 285 } 282 286 283 - if (connect_fd_to_addr(fd, addr, addrlen, false)) 287 + if (settimeo(fd, opts->timeout_ms)) 288 + goto error_close; 289 + 290 + if (connect_fd_to_addr(fd, addr, addrlen, opts->must_fail)) 284 291 goto error_close; 285 292 286 293 return fd;
+2 -1
tools/testing/selftests/bpf/network_helpers.h
··· 56 56 int start_server_addr(int type, const struct sockaddr_storage *addr, socklen_t len, 57 57 const struct network_helper_opts *opts); 58 58 void free_fds(int *fds, unsigned int nr_close_fds); 59 - int connect_to_addr(const struct sockaddr_storage *addr, socklen_t len, int type); 59 + int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t len, 60 + const struct network_helper_opts *opts); 60 61 int connect_to_fd(int server_fd, int timeout_ms); 61 62 int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts); 62 63 int connect_fd_to_fd(int client_fd, int server_fd, int timeout_ms);
+3 -3
tools/testing/selftests/bpf/prog_tests/sock_addr.c
··· 328 328 goto cleanup; 329 329 330 330 /* Try to connect to server just in case */ 331 - client = connect_to_addr(&expected_addr, expected_addr_len, test->socket_type); 331 + client = connect_to_addr(test->socket_type, &expected_addr, expected_addr_len, NULL); 332 332 if (!ASSERT_GE(client, 0, "connect_to_addr")) 333 333 goto cleanup; 334 334 ··· 357 357 if (!ASSERT_EQ(err, 0, "make_sockaddr")) 358 358 goto cleanup; 359 359 360 - client = connect_to_addr(&addr, addr_len, test->socket_type); 360 + client = connect_to_addr(test->socket_type, &addr, addr_len, NULL); 361 361 if (!ASSERT_GE(client, 0, "connect_to_addr")) 362 362 goto cleanup; 363 363 ··· 538 538 if (!ASSERT_EQ(err, 0, "make_sockaddr")) 539 539 goto cleanup; 540 540 541 - client = connect_to_addr(&addr, addr_len, test->socket_type); 541 + client = connect_to_addr(test->socket_type, &addr, addr_len, NULL); 542 542 if (!ASSERT_GE(client, 0, "connect_to_addr")) 543 543 goto cleanup; 544 544