]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
selftests/bpf: Drop type of connect_to_fd_opts
authorGeliang Tang <tanggeliang@kylinos.cn>
Thu, 18 Jul 2024 06:22:29 +0000 (14:22 +0800)
committerAndrii Nakryiko <andrii@kernel.org>
Mon, 29 Jul 2024 19:52:24 +0000 (12:52 -0700)
The "type" parameter of connect_to_fd_opts() is redundant of "server_fd".
Since the "type" can be obtained inside by invoking getsockopt(SO_TYPE),
without passing it in as a parameter.

This patch drops the "type" parameter of connect_to_fd_opts() and updates
its callers.

Suggested-by: Martin KaFai Lau <martin.lau@kernel.org>
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Link: https://lore.kernel.org/r/50d8ce7ab7ab0c0f4d211fc7cc4ebe3d3f63424c.1721282219.git.tanggeliang@kylinos.cn
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
tools/testing/selftests/bpf/network_helpers.c
tools/testing/selftests/bpf/network_helpers.h
tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
tools/testing/selftests/bpf/prog_tests/cgroup_v1v2.c

index e0cba4178e41d3325ce4d5bd84eff9b002abf8fc..15e0e0bb75536c627f06372763e3b599de2c01ec 100644 (file)
@@ -328,14 +328,21 @@ error_close:
        return -1;
 }
 
-int connect_to_fd_opts(int server_fd, int type, const struct network_helper_opts *opts)
+int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts)
 {
        struct sockaddr_storage addr;
-       socklen_t addrlen;
+       socklen_t addrlen, optlen;
+       int type;
 
        if (!opts)
                opts = &default_opts;
 
+       optlen = sizeof(type);
+       if (getsockopt(server_fd, SOL_SOCKET, SO_TYPE, &type, &optlen)) {
+               log_err("getsockopt(SOL_TYPE)");
+               return -1;
+       }
+
        addrlen = sizeof(addr);
        if (getsockname(server_fd, (struct sockaddr *)&addr, &addrlen)) {
                log_err("Failed to get server addr");
@@ -350,14 +357,8 @@ int connect_to_fd(int server_fd, int timeout_ms)
        struct network_helper_opts opts = {
                .timeout_ms = timeout_ms,
        };
-       int type, protocol;
        socklen_t optlen;
-
-       optlen = sizeof(type);
-       if (getsockopt(server_fd, SOL_SOCKET, SO_TYPE, &type, &optlen)) {
-               log_err("getsockopt(SOL_TYPE)");
-               return -1;
-       }
+       int protocol;
 
        optlen = sizeof(protocol);
        if (getsockopt(server_fd, SOL_SOCKET, SO_PROTOCOL, &protocol, &optlen)) {
@@ -366,7 +367,7 @@ int connect_to_fd(int server_fd, int timeout_ms)
        }
        opts.proto = protocol;
 
-       return connect_to_fd_opts(server_fd, type, &opts);
+       return connect_to_fd_opts(server_fd, &opts);
 }
 
 int connect_fd_to_fd(int client_fd, int server_fd, int timeout_ms)
index aac5b94d6379916d63a9e9192b69af720e06c706..5b548c0c60dea31449d0c2ea35df1bd1b676aaba 100644 (file)
@@ -71,7 +71,7 @@ int client_socket(int family, 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, int type, const struct network_helper_opts *opts);
+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);
 int fastopen_connect(int server_fd, const char *data, unsigned int data_len,
                     int timeout_ms);
index 63422f4f389675b77564de9361d45a9d4a62001b..1d494b4453f42ff5044ea9276b135aaba3a4d061 100644 (file)
@@ -49,7 +49,7 @@ static bool start_test(char *addr_str,
                goto err;
 
        /* connect to server */
-       *cli_fd = connect_to_fd_opts(*srv_fd, SOCK_STREAM, cli_opts);
+       *cli_fd = connect_to_fd_opts(*srv_fd, cli_opts);
        if (!ASSERT_NEQ(*cli_fd, -1, "connect_to_fd_opts"))
                goto err;
 
index 9709c8db727512fba4a4614c849b6195717dbbbb..addf720428f7d5ca5ca91345552f72e02caac45a 100644 (file)
@@ -32,7 +32,7 @@ static int run_test(int cgroup_fd, int server_fd, bool classid)
                goto out;
        }
 
-       fd = connect_to_fd_opts(server_fd, SOCK_STREAM, &opts);
+       fd = connect_to_fd_opts(server_fd, &opts);
        if (fd < 0)
                err = -1;
        else
@@ -52,7 +52,7 @@ void test_cgroup_v1v2(void)
        server_fd = start_server(AF_INET, SOCK_STREAM, NULL, port, 0);
        if (!ASSERT_GE(server_fd, 0, "server_fd"))
                return;
-       client_fd = connect_to_fd_opts(server_fd, SOCK_STREAM, &opts);
+       client_fd = connect_to_fd_opts(server_fd, &opts);
        if (!ASSERT_GE(client_fd, 0, "client_fd")) {
                close(server_fd);
                return;