Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Geliang Tang <[email protected]>
  • Loading branch information
Geliang Tang committed Apr 15, 2024
1 parent 904d3e0 commit b331104
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
6 changes: 3 additions & 3 deletions tools/testing/selftests/bpf/network_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions tools/testing/selftests/bpf/network_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tools/testing/selftests/bpf/prog_tests/cls_redirect.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 5 additions & 5 deletions tools/testing/selftests/bpf/prog_tests/sk_assign.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions tools/testing/selftests/bpf/prog_tests/sock_addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
10 changes: 5 additions & 5 deletions tools/testing/selftests/bpf/test_sock_addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1116,15 +1116,15 @@ 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;

if (cmp_local_addr(servfd, &expected_addr))
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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit b331104

Please sign in to comment.