diff mbox series

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

Message ID cf2b340582b17a4337ef0910bb14e5adbdc48fa3.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:14 a.m. UTC
From: Geliang Tang <tanggeliang@kylinos.cn>

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@kylinos.cn>
---
 .../selftests/bpf/prog_tests/ip_check_defrag.c | 18 +++---------------
 1 file changed, 3 insertions(+), 15 deletions(-)
diff mbox series

Patch

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;