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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Geliang Tang <tanggeliang@xxxxxxxxxx>

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@xxxxxxxxxx>
---
 .../selftests/bpf/prog_tests/sk_assign.c      | 25 +------------------
 1 file changed, 1 insertion(+), 24 deletions(-)

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
-- 
2.40.1





[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux