[PATCH bpf-next 11/15] selftests/bpf: Add loopback_addr_str helper

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

 



From: Geliang Tang <tanggeliang@xxxxxxxxxx>

This patch adds a new helper loopback_addr_str() to get the loopback
address string according to the given different protocol family.

Also use this new helper in start_servers() in migrate_reuseport.c.

Signed-off-by: Geliang Tang <tanggeliang@xxxxxxxxxx>
---
 tools/testing/selftests/bpf/network_helpers.h     | 15 +++++++++++++++
 .../selftests/bpf/prog_tests/migrate_reuseport.c  |  2 +-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h
index 16f266c53b61..893f07c677da 100644
--- a/tools/testing/selftests/bpf/network_helpers.h
+++ b/tools/testing/selftests/bpf/network_helpers.h
@@ -55,6 +55,21 @@ struct ipv6_packet {
 } __packed;
 extern struct ipv6_packet pkt_v6;
 
+static inline char *loopback_addr_str(int family)
+{
+	switch (family) {
+	case AF_INET:
+		return "127.0.0.1";
+	case AF_INET6:
+		return "::1";
+	case AF_VSOCK:
+		return "1"; /* VMADDR_CID_LOCAL */
+	default:
+		fprintf(stderr, "unsupported address family %d", family);
+		return NULL;
+	}
+}
+
 int settimeo(int fd, int timeout_ms);
 int start_server_str(int family, int type, const char *addr_str, __u16 port,
 		     const struct network_helper_opts *opts);
diff --git a/tools/testing/selftests/bpf/prog_tests/migrate_reuseport.c b/tools/testing/selftests/bpf/prog_tests/migrate_reuseport.c
index 653b0a20fab9..7c31c7fdaecb 100644
--- a/tools/testing/selftests/bpf/prog_tests/migrate_reuseport.c
+++ b/tools/testing/selftests/bpf/prog_tests/migrate_reuseport.c
@@ -221,7 +221,7 @@ static int start_servers(struct migrate_reuseport_test_case *test_case,
 	prog_fd = bpf_program__fd(skel->progs.migrate_reuseport);
 
 	make_sockaddr(test_case->family,
-		      test_case->family == AF_INET ? "127.0.0.1" : "::1", 0,
+		      loopback_addr_str(test_case->family), 0,
 		      &test_case->addr, &test_case->addrlen);
 
 	for (i = 0; i < NR_SERVERS; i++) {
-- 
2.43.0





[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