diff mbox series

[bpf-next,v4,07/14] selftests/bpf: Use get_socket_local_port in sk_assign

Message ID 68cea931420c8c26d34487979c245976531ac191.1713262052.git.tanggeliang@kylinos.cn (mailing list archive)
State New
Headers show
Series use network helpers, part 1 | expand

Commit Message

Geliang Tang April 16, 2024, 10:13 a.m. UTC
From: Geliang Tang <tanggeliang@kylinos.cn>

This patch uses public helper get_socket_local_port() exported in
network_helpers.h instead of the local defined function get_port()
in prog_tests/sk_assign.c. This can avoid duplicate code.

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

Patch

diff --git a/tools/testing/selftests/bpf/prog_tests/sk_assign.c b/tools/testing/selftests/bpf/prog_tests/sk_assign.c
index 766fc56f5fc7..c0ef210f7622 100644
--- a/tools/testing/selftests/bpf/prog_tests/sk_assign.c
+++ b/tools/testing/selftests/bpf/prog_tests/sk_assign.c
@@ -72,29 +72,6 @@  configure_stack(void)
 	return true;
 }
 
-static in_port_t
-get_port(int fd)
-{
-	struct sockaddr_storage ss;
-	socklen_t slen = sizeof(ss);
-	in_port_t port = 0;
-
-	if (CHECK_FAIL(getsockname(fd, (struct sockaddr *)&ss, &slen)))
-		return port;
-
-	switch (ss.ss_family) {
-	case AF_INET:
-		port = ((struct sockaddr_in *)&ss)->sin_port;
-		break;
-	case AF_INET6:
-		port = ((struct sockaddr_in6 *)&ss)->sin6_port;
-		break;
-	default:
-		CHECK(1, "Invalid address family", "%d\n", ss.ss_family);
-	}
-	return port;
-}
-
 static ssize_t
 rcv_msg(int srv_client, int type)
 {
@@ -138,7 +115,7 @@  run_test(int server_fd, const struct sockaddr *addr, socklen_t len, int type)
 		goto out;
 	}
 
-	port = get_port(srv_client);
+	port = get_socket_local_port(srv_client);
 	if (CHECK_FAIL(!port))
 		goto out;
 	/* SOCK_STREAM is connected via accept(), so the server's local address