diff mbox series

[bpf-next,v3,2/9] selftests/bpf: Add start_server_addr* helpers

Message ID b91517285bb6c53225d4b92f543b3e819d109113.1713161975.git.tanggeliang@kylinos.cn (mailing list archive)
State New
Headers show
Series use start_server_addr/connect_to_addr helpers | expand

Commit Message

Geliang Tang April 15, 2024, 6:31 a.m. UTC
From: Geliang Tang <tanggeliang@kylinos.cn>

In order to pair up with connect_to_addr(), this patch adds a new helper
start_server_addr(), and another one start_server_addr_opts(), which is
a wrapper of __start_server(), only added a network_helper_opts arg at
the end.

They all accept an argument 'addr' of 'struct sockaddr_storage' type
instead of a string type argument like start_server().

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 tools/testing/selftests/bpf/network_helpers.c | 16 ++++++++++++++++
 tools/testing/selftests/bpf/network_helpers.h |  3 +++
 2 files changed, 19 insertions(+)
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c
index 3759948439a7..92c980b18afd 100644
--- a/tools/testing/selftests/bpf/network_helpers.c
+++ b/tools/testing/selftests/bpf/network_helpers.c
@@ -185,6 +185,22 @@  int *start_reuseport_server(int family, int type, const char *addr_str,
 	return NULL;
 }
 
+int start_server_addr_opts(int type, const struct sockaddr_storage *addr, socklen_t len,
+			   const struct network_helper_opts *opts)
+{
+	return __start_server(type, 0, (struct sockaddr *)addr, len,
+			      opts->timeout_ms, 0);
+}
+
+int start_server_addr(int type, const struct sockaddr_storage *addr, socklen_t len)
+{
+	struct network_helper_opts opts = {
+		.timeout_ms = 0,
+	};
+
+	return start_server_addr_opts(type, addr, len, &opts);
+}
+
 void free_fds(int *fds, unsigned int nr_close_fds)
 {
 	if (fds) {
diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h
index ac4da5fdcc95..9e6fcc89a8d0 100644
--- a/tools/testing/selftests/bpf/network_helpers.h
+++ b/tools/testing/selftests/bpf/network_helpers.h
@@ -53,6 +53,9 @@  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_opts(int type, const struct sockaddr_storage *addr, socklen_t len,
+			   const struct network_helper_opts *opts);
+int start_server_addr(int type, const struct sockaddr_storage *addr, socklen_t len);
 void free_fds(int *fds, unsigned int nr_close_fds);
 int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t len);
 int connect_to_fd(int server_fd, int timeout_ms);