mirror of
https://github.com/torvalds/linux.git
synced 2024-12-04 01:51:34 +00:00
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>
This commit is contained in:
parent
a2e4979536
commit
db9994d022
@ -270,17 +270,24 @@ 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,
|
||||
const struct network_helper_opts *opts)
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = socket(addr->ss_family, type, 0);
|
||||
if (!opts)
|
||||
opts = &default_opts;
|
||||
|
||||
fd = socket(addr->ss_family, type, opts->proto);
|
||||
if (fd < 0) {
|
||||
log_err("Failed to create client socket");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (connect_fd_to_addr(fd, addr, addrlen, false))
|
||||
if (settimeo(fd, opts->timeout_ms))
|
||||
goto error_close;
|
||||
|
||||
if (connect_fd_to_addr(fd, addr, addrlen, opts->must_fail))
|
||||
goto error_close;
|
||||
|
||||
return fd;
|
||||
|
@ -56,7 +56,8 @@ int *start_reuseport_server(int family, int type, const char *addr_str,
|
||||
int start_server_addr(int type, const struct sockaddr_storage *addr, socklen_t len,
|
||||
const struct network_helper_opts *opts);
|
||||
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,
|
||||
const struct network_helper_opts *opts);
|
||||
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);
|
||||
|
@ -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, NULL);
|
||||
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, NULL);
|
||||
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, NULL);
|
||||
if (!ASSERT_GE(client, 0, "connect_to_addr"))
|
||||
goto cleanup;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user