]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests/bpf: Add start_server_str helper
authorGeliang Tang <tanggeliang@kylinos.cn>
Sat, 25 May 2024 12:08:16 +0000 (20:08 +0800)
committerMartin KaFai Lau <martin.lau@kernel.org>
Wed, 29 May 2024 00:53:03 +0000 (17:53 -0700)
It's a tech debt that start_server() does not take the "opts" argument.
It's pretty handy to have start_server() as a helper that takes string
address.

So this patch creates a new helper start_server_str(). Then start_server()
can be a wrapper of it.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Link: https://lore.kernel.org/r/606e6cfd7e1aff8bc51ede49862eed0802e52170.1716638248.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

index 4d776b78929cb6af9d5de7108e22db33f758b9d1..0e8266f439e482744251c147c30ecf648cb2b023 100644 (file)
@@ -118,19 +118,29 @@ error_close:
        return -1;
 }
 
-int start_server(int family, int type, const char *addr_str, __u16 port,
-                int timeout_ms)
+int start_server_str(int family, int type, const char *addr_str, __u16 port,
+                    const struct network_helper_opts *opts)
 {
-       struct network_helper_opts opts = {
-               .timeout_ms     = timeout_ms,
-       };
        struct sockaddr_storage addr;
        socklen_t addrlen;
 
+       if (!opts)
+               opts = &default_opts;
+
        if (make_sockaddr(family, addr_str, port, &addr, &addrlen))
                return -1;
 
-       return __start_server(type, (struct sockaddr *)&addr, addrlen, &opts);
+       return __start_server(type, (struct sockaddr *)&addr, addrlen, opts);
+}
+
+int start_server(int family, int type, const char *addr_str, __u16 port,
+                int timeout_ms)
+{
+       struct network_helper_opts opts = {
+               .timeout_ms     = timeout_ms,
+       };
+
+       return start_server_str(family, type, addr_str, port, &opts);
 }
 
 static int reuseport_cb(int fd, void *opts)
index 40011e0f584b75c1aa684e3dca1ed4d47da3d7bd..4e3e6afe7d3a8a48dffb23d44ec038c025288356 100644 (file)
@@ -48,6 +48,8 @@ struct ipv6_packet {
 extern struct ipv6_packet pkt_v6;
 
 int settimeo(int fd, int timeout_ms);
+int start_server_str(int family, int type, const char *addr_str, __u16 port,
+                    const struct network_helper_opts *opts);
 int start_server(int family, int type, const char *addr, __u16 port,
                 int timeout_ms);
 int *start_reuseport_server(int family, int type, const char *addr_str,