]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
selftests/bpf: Update arguments of connect_to_addr
authorGeliang Tang <tanggeliang@kylinos.cn>
Thu, 18 Apr 2024 08:09:10 +0000 (16:09 +0800)
committerMartin KaFai Lau <martin.lau@kernel.org>
Sat, 20 Apr 2024 00:13:28 +0000 (17:13 -0700)
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>
tools/testing/selftests/bpf/network_helpers.c
tools/testing/selftests/bpf/network_helpers.h
tools/testing/selftests/bpf/prog_tests/sock_addr.c

index 28fe8367451b00a6c514d9e08416a44c12c5107f..9d63d2ac13d8d3f17170b3c29e74736c446d70ff 100644 (file)
@@ -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;
index 414ea50bb3fcd972fce0648823585c56c54b379c..aef297dfa6cafacc28c10445c13f84365932403f 100644 (file)
@@ -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);
index 5fd6177189915b6a3a09f532d0536220de78dfb7..61668e0f11b0608bafaf91177aa7f6b1c0d4e309 100644 (file)
@@ -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;