diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index d3dcba91e696..afb7bd516640 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -189,9 +189,9 @@ int *start_reuseport_server(int family, int type, const char *addr_str, return NULL; } -int start_server_addr(const struct sockaddr *addr, socklen_t addrlen, int type) +int start_server_addr(int type, const struct sockaddr_storage *addr, socklen_t addrlen) { - return __start_server(type, 0, addr, addrlen, 0, NULL, 0); + return __start_server(type, 0, (struct sockaddr *)addr, addrlen, 0, NULL, 0); } int start_server_setsockopt(const struct sockaddr *addr, socklen_t addrlen, int type, @@ -273,7 +273,7 @@ static int connect_fd_to_addr(int fd, return 0; } -int connect_to_addr(const struct sockaddr_storage *addr, socklen_t addrlen, int type) +int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t addrlen) { int fd; diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index 543295230062..2ce5ffe8c578 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -54,11 +54,11 @@ int start_mptcp_server(int family, const char *addr, __u16 port, int *start_reuseport_server(int family, int type, const char *addr_str, __u16 port, int timeout_ms, unsigned int nr_listens); -int start_server_addr(const struct sockaddr *addr, socklen_t addrlen, int type); +int start_server_addr(int type, const struct sockaddr_storage *addr, socklen_t addrlen); int start_server_setsockopt(const struct sockaddr *addr, socklen_t addrlen, int type, int *(*setsockopt)(int fd, int val), int val); void free_fds(int *fds, unsigned int nr_close_fds); -int connect_to_addr(const struct sockaddr_storage *addr, socklen_t len, int type); +int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t len); int connect_to_fd(int server_fd, int timeout_ms); int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts); int connect_fd_to_fd(int client_fd, int server_fd, int timeout_ms); diff --git a/tools/testing/selftests/bpf/prog_tests/cls_redirect.c b/tools/testing/selftests/bpf/prog_tests/cls_redirect.c index 4b185b608fae..9aa2f3b12884 100644 --- a/tools/testing/selftests/bpf/prog_tests/cls_redirect.c +++ b/tools/testing/selftests/bpf/prog_tests/cls_redirect.c @@ -66,14 +66,14 @@ static bool set_up_conn(const struct sockaddr *addr, socklen_t len, int type, socklen_t slen = sizeof(ss); struct sockaddr *sa = (struct sockaddr *)&ss; - *server = start_server_addr(addr, len, type); + *server = start_server_addr(type, (struct sockaddr_storage *)addr, len); if (*server < 0) return false; if (CHECK_FAIL(getsockname(*server, sa, &slen))) goto close_server; - *conn = connect_to_addr((struct sockaddr_storage *)sa, slen, type); + *conn = connect_to_addr(type, (struct sockaddr_storage *)sa, slen); if (*conn < 0) goto close_server; diff --git a/tools/testing/selftests/bpf/prog_tests/sk_assign.c b/tools/testing/selftests/bpf/prog_tests/sk_assign.c index b574e162ce6e..5598a845f6db 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_assign.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_assign.c @@ -114,7 +114,7 @@ run_test(int server_fd, const struct sockaddr *addr, socklen_t len, int type) in_port_t port; int ret = 1; - client = connect_to_addr((struct sockaddr_storage *)addr, len, type); + client = connect_to_addr(type, (struct sockaddr_storage *)addr, len); if (client == -1) { perror("Cannot connect to server"); goto out; @@ -255,15 +255,15 @@ void test_sk_assign(void) for (i = 0; i < ARRAY_SIZE(tests) && !READ_ONCE(stop); i++) { struct test_sk_cfg *test = &tests[i]; - const struct sockaddr *addr; + const struct sockaddr_storage *addr; const int zero = 0; int err; if (!test__start_subtest(test->name)) continue; prepare_addr(test->addr, test->family, BIND_PORT, false); - addr = (const struct sockaddr *)test->addr; - server = start_server_addr(addr, test->len, test->type); + addr = (struct sockaddr_storage *)test->addr; + server = start_server_addr(test->type, addr, test->len); if (server == -1) goto close; @@ -276,7 +276,7 @@ void test_sk_assign(void) /* connect to unbound ports */ prepare_addr(test->addr, test->family, CONNECT_PORT, test->rewrite_addr); - if (run_test(server, addr, test->len, test->type)) + if (run_test(server, test->addr, test->len, test->type)) goto close; close(server); diff --git a/tools/testing/selftests/bpf/prog_tests/sock_addr.c b/tools/testing/selftests/bpf/prog_tests/sock_addr.c index 5fd617718991..b182667e78c9 100644 --- a/tools/testing/selftests/bpf/prog_tests/sock_addr.c +++ b/tools/testing/selftests/bpf/prog_tests/sock_addr.c @@ -328,7 +328,7 @@ static void test_bind(struct sock_addr_test *test) goto cleanup; /* Try to connect to server just in case */ - client = connect_to_addr(&expected_addr, expected_addr_len, test->socket_type); + client = connect_to_addr(test->socket_type, &expected_addr, expected_addr_len); if (!ASSERT_GE(client, 0, "connect_to_addr")) goto cleanup; @@ -357,7 +357,7 @@ static void test_connect(struct sock_addr_test *test) if (!ASSERT_EQ(err, 0, "make_sockaddr")) goto cleanup; - client = connect_to_addr(&addr, addr_len, test->socket_type); + client = connect_to_addr(test->socket_type, &addr, addr_len); if (!ASSERT_GE(client, 0, "connect_to_addr")) goto cleanup; @@ -538,7 +538,7 @@ static void test_getpeername(struct sock_addr_test *test) if (!ASSERT_EQ(err, 0, "make_sockaddr")) goto cleanup; - client = connect_to_addr(&addr, addr_len, test->socket_type); + client = connect_to_addr(test->socket_type, &addr, addr_len); if (!ASSERT_GE(client, 0, "connect_to_addr")) goto cleanup; diff --git a/tools/testing/selftests/bpf/test_sock_addr.c b/tools/testing/selftests/bpf/test_sock_addr.c index 743ff05e7755..422255c8575e 100644 --- a/tools/testing/selftests/bpf/test_sock_addr.c +++ b/tools/testing/selftests/bpf/test_sock_addr.c @@ -1116,7 +1116,7 @@ static int run_bind_test_case(const struct sock_addr_test *test) if (init_addrs(test, &requested_addr, &expected_addr, NULL)) goto err; - servfd = start_server_addr((struct sockaddr *)&requested_addr, addr_len, test->type); + servfd = start_server_addr(test->type, &requested_addr, addr_len); if (servfd == -1) goto err; @@ -1124,7 +1124,7 @@ static int run_bind_test_case(const struct sock_addr_test *test) goto err; /* Try to connect to server just in case */ - clientfd = connect_to_addr(&expected_addr, addr_len, test->type); + clientfd = connect_to_addr(test->type, &expected_addr, addr_len); if (clientfd == -1) goto err; @@ -1152,11 +1152,11 @@ static int run_connect_test_case(const struct sock_addr_test *test) goto err; /* Prepare server to connect to */ - servfd = start_server_addr((struct sockaddr *)&expected_addr, addr_len, test->type); + servfd = start_server_addr(test->type, &expected_addr, addr_len); if (servfd == -1) goto err; - clientfd = connect_to_addr(&requested_addr, addr_len, test->type); + clientfd = connect_to_addr(test->type, &requested_addr, addr_len); if (clientfd == -1) goto err; @@ -1209,7 +1209,7 @@ static int run_xmsg_test_case(const struct sock_addr_test *test, int max_cmsg) goto err; /* Prepare server to sendmsg to */ - servfd = start_server_addr((struct sockaddr *)&server_addr, addr_len, test->type); + servfd = start_server_addr(test->type, &server_addr, addr_len); if (servfd == -1) goto err; diff --git a/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c b/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c index e678228b915f..51acd591fa64 100644 --- a/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c +++ b/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c @@ -90,7 +90,7 @@ static int run_test(int server_fd, int results_fd, bool xdp, goto err; } - client = connect_to_addr((struct sockaddr_storage *)addr, len, SOCK_STREAM); + client = connect_to_addr(SOCK_STREAM, (struct sockaddr_storage *)addr, len); if (client == -1) goto err; @@ -205,8 +205,8 @@ int main(int argc, char **argv) addr6dual.sin6_addr = in6addr_any; addr6dual.sin6_port = 0; - server = start_server_addr((const struct sockaddr *)&addr4, - sizeof(addr4), SOCK_STREAM); + server = start_server_addr(SOCK_STREAM, (const struct sockaddr_storage *)&addr4, + sizeof(addr4)); if (server == -1 || !get_port(server, &addr4.sin_port)) goto err;