[PATCH bpf-next v4 14/14] selftests/bpf: Use make_sockaddr in ip_check_defrag

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

 



From: Geliang Tang <tanggeliang@xxxxxxxxxx>

This patch uses public helper make_sockaddr() exported in network_helpers.h
instead of open-coding in test_bpf_ip_check_defrag_ok() in
prog_tests/ip_check_defrag.c. This can avoid duplicate code.

Signed-off-by: Geliang Tang <tanggeliang@xxxxxxxxxx>
---
 .../selftests/bpf/prog_tests/ip_check_defrag.c | 18 +++---------------
 1 file changed, 3 insertions(+), 15 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c b/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c
index 284764e7179f..aafadb0ca666 100644
--- a/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c
+++ b/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c
@@ -220,21 +220,9 @@ void test_bpf_ip_check_defrag_ok(bool ipv6)
 	nstoken = open_netns(NS0);
 	if (!ASSERT_OK_PTR(nstoken, "setns ns0"))
 		goto out;
-	if (ipv6) {
-		struct sockaddr_in6 *c = (struct sockaddr_in6 *)&caddr;
-
-		c->sin6_family = AF_INET6;
-		inet_pton(AF_INET6, VETH0_ADDR6, &c->sin6_addr);
-		c->sin6_port = htons(CLIENT_PORT);
-		err = bind(client_rx_fd, (struct sockaddr *)c, sizeof(*c));
-	} else {
-		struct sockaddr_in *c = (struct sockaddr_in *)&caddr;
-
-		c->sin_family = AF_INET;
-		inet_pton(AF_INET, VETH0_ADDR, &c->sin_addr);
-		c->sin_port = htons(CLIENT_PORT);
-		err = bind(client_rx_fd, (struct sockaddr *)c, sizeof(*c));
-	}
+	make_sockaddr(ipv6 ? AF_INET6 : AF_INET, ipv6 ? VETH0_ADDR6 : VETH0_ADDR,
+		      CLIENT_PORT, &caddr, &caddr_len);
+	err = bind(client_rx_fd, (struct sockaddr *)&caddr, sizeof(caddr));
 	close_netns(nstoken);
 	if (!ASSERT_OK(err, "bind"))
 		goto out;
-- 
2.40.1





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux