diff mbox series

[bpf-next,v2,14/14] selftests/bpf: Use connect_to_addr in test_tcp_check_syncookie

Message ID 993fe5771221a5307d566ff88fcbf3f41ecad48f.1712796967.git.tanggeliang@kylinos.cn (mailing list archive)
State New
Headers show
Series use start_server and connect_to helpers | expand

Commit Message

Geliang Tang April 11, 2024, 1:03 a.m. UTC
From: Geliang Tang <tanggeliang@kylinos.cn>

This patch uses public helper connect_to_addr() exported in
network_helpers.h instead of the local defined function connect_to_server()
in test_tcp_check_syncookie_user.c. This can avoid duplicate code.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 .../bpf/test_tcp_check_syncookie_user.c       | 26 +------------------
 1 file changed, 1 insertion(+), 25 deletions(-)
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c b/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c
index e6ad4895d2b3..e678228b915f 100644
--- a/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c
+++ b/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c
@@ -25,30 +25,6 @@  static int setsockopt_mode(int fd, int dual)
 	return setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&mode, sizeof(mode));
 }
 
-static int connect_to_server(const struct sockaddr *addr, socklen_t len)
-{
-	int fd = -1;
-
-	fd = socket(addr->sa_family, SOCK_STREAM, 0);
-	if (fd == -1) {
-		log_err("Failed to create client socket");
-		goto out;
-	}
-
-	if (connect(fd, (const struct sockaddr *)addr, len) == -1) {
-		log_err("Fail to connect to server");
-		goto close_out;
-	}
-
-	goto out;
-
-close_out:
-	close(fd);
-	fd = -1;
-out:
-	return fd;
-}
-
 static int get_map_fd_by_prog_id(int prog_id, bool *xdp)
 {
 	struct bpf_prog_info info = {};
@@ -114,7 +90,7 @@  static int run_test(int server_fd, int results_fd, bool xdp,
 		goto err;
 	}
 
-	client = connect_to_server(addr, len);
+	client = connect_to_addr((struct sockaddr_storage *)addr, len, SOCK_STREAM);
 	if (client == -1)
 		goto err;