[CRIU] [PATCH 3/3] zdtm: adapt all tcp tests for ipv6

Andrey Vagin avagin at openvz.org
Wed Nov 21 08:32:46 EST 2012


Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 test/zdtm.sh                           |  4 +++
 test/zdtm/lib/tcp.c                    | 46 +++++++++++++++++++++++++---------
 test/zdtm/lib/zdtmtst.h                |  4 +--
 test/zdtm/live/static/Makefile         |  6 +++++
 test/zdtm/live/static/socket-tcp.c     | 11 ++++++--
 test/zdtm/live/static/socket-tcp6.c    |  1 +
 test/zdtm/live/static/socket-tcpbuf.c  | 13 +++++++---
 test/zdtm/live/static/socket-tcpbuf6.c |  1 +
 test/zdtm/live/static/socket_aio.c     |  5 ++--
 test/zdtm/live/static/socket_listen.c  | 11 ++++++--
 test/zdtm/live/static/socket_listen6.c |  1 +
 test/zdtm/live/streaming/Makefile      |  2 ++
 test/zdtm/live/streaming/socket-tcp6.c |  1 +
 13 files changed, 83 insertions(+), 23 deletions(-)
 create mode 120000 test/zdtm/live/static/socket-tcp6.c
 create mode 120000 test/zdtm/live/static/socket-tcpbuf6.c
 create mode 120000 test/zdtm/live/static/socket_listen6.c
 create mode 120000 test/zdtm/live/streaming/socket-tcp6.c

diff --git a/test/zdtm.sh b/test/zdtm.sh
index 32a637c..d1fcfb8 100644
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -45,6 +45,7 @@ static/pid00
 static/pstree
 static/cmdlinenv00
 static/socket_listen
+static/socket_listen6
 static/packet_sock
 static/socket_udp
 static/sock_filter
@@ -79,8 +80,11 @@ TEST_LIST="$TEST_LIST
 static/file_fown
 static/socket-ext
 static/socket-tcp
+static/socket-tcp6
 streaming/socket-tcp
+streaming/socket-tcp6
 static/socket-tcpbuf
+static/socket-tcpbuf6
 static/pty03
 "
 
diff --git a/test/zdtm/lib/tcp.c b/test/zdtm/lib/tcp.c
index eb88de8..cbdc52a 100644
--- a/test/zdtm/lib/tcp.c
+++ b/test/zdtm/lib/tcp.c
@@ -4,16 +4,28 @@
 
 #include "zdtmtst.h"
 
-int tcp_init_server(int *port)
+union sockaddr_inet {
+	struct sockaddr_in v4;
+	struct sockaddr_in6 v6;
+};
+
+int tcp_init_server(int family, int *port)
 {
-	struct sockaddr_in addr;
+	union sockaddr_inet addr;
 	int sock;
 	int yes = 1, ret;
 
 	memset(&addr,0,sizeof(addr));
-	addr.sin_family = AF_INET;
-	addr.sin_addr.s_addr = inet_addr("0.0.0.0");
-	sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
+	if (family == AF_INET) {
+		addr.v4.sin_family = family;
+		inet_pton(family, "0.0.0.0", &(addr.v4.sin_addr));
+	} else if (family == AF_INET6){
+		addr.v6.sin6_family = family;
+		inet_pton(family, "::0", &(addr.v6.sin6_addr));
+	} else
+		return -1;
+
+	sock = socket(family, SOCK_STREAM, IPPROTO_TCP);
 	if (sock == -1) {
 		err ("socket() failed %m");
 		return -1;
@@ -25,7 +37,11 @@ int tcp_init_server(int *port)
 	}
 
 	while (1) {
-		addr.sin_port = htons(*port);
+		if (family == AF_INET)
+			addr.v4.sin_port = htons(*port);
+		else if (family == AF_INET6)
+			addr.v6.sin6_port = htons(*port);
+
 		ret = bind(sock, (struct sockaddr *) &addr, sizeof(addr));
 
 		/* crtools doesn't restore sock opts, so we need this hack */
@@ -71,20 +87,26 @@ int tcp_accept_server(int sock)
 	return sock2;
 }
 
-int tcp_init_client(char *servIP, unsigned short servPort)
+int tcp_init_client(int family, char *servIP, unsigned short servPort)
 {
 	int sock;
-	struct sockaddr_in servAddr;
+	union sockaddr_inet servAddr;
 
-	if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
+	if ((sock = socket(family, SOCK_STREAM, IPPROTO_TCP)) < 0) {
 		err("can't create socket %m");
 		return -1;
 	}
 	/* Construct the server address structure */
 	memset(&servAddr, 0, sizeof(servAddr));
-	servAddr.sin_family      = AF_INET;
-	servAddr.sin_addr.s_addr = inet_addr(servIP);
-	servAddr.sin_port        = htons(servPort);
+	if (family == AF_INET) {
+		servAddr.v4.sin_family      = AF_INET;
+		servAddr.v4.sin_port        = htons(servPort);
+		inet_pton(AF_INET, servIP, &servAddr.v4.sin_addr);
+	} else {
+		servAddr.v6.sin6_family      = AF_INET6;
+		servAddr.v6.sin6_port        = htons(servPort);
+		inet_pton(AF_INET6, servIP, &servAddr.v6.sin6_addr);
+	}
 	if (connect(sock, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0) {
 		err("can't connect to server %m");
 		return -1;
diff --git a/test/zdtm/lib/zdtmtst.h b/test/zdtm/lib/zdtmtst.h
index 6a21569..323b70e 100644
--- a/test/zdtm/lib/zdtmtst.h
+++ b/test/zdtm/lib/zdtmtst.h
@@ -111,8 +111,8 @@ extern void task_waiter_fini(task_waiter_t *t);
 extern void task_waiter_wait4(task_waiter_t *t, unsigned int lockid);
 extern void task_waiter_complete(task_waiter_t *t, unsigned int lockid);
 extern void task_waiter_complete_current(task_waiter_t *t);
-extern int tcp_init_server(int *port);
+extern int tcp_init_server(int family, int *port);
 extern int tcp_accept_server(int sock);
-extern int tcp_init_client(char *servIP, unsigned short servPort);
+extern int tcp_init_client(int family, char *servIP, unsigned short servPort);
 
 #endif /* _VIMITESU_H_ */
diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index 6715ceb..3944fee 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -23,6 +23,7 @@ TST_NOFILE	=				\
 		sched_prio00			\
 		sched_policy00			\
 		socket_listen			\
+		socket_listen6			\
 		socket_udp			\
 		socket6_udp			\
 		socket_udplite			\
@@ -48,7 +49,9 @@ TST_NOFILE	=				\
 		socket_queues			\
 		socket_queues02			\
 		socket-tcp			\
+		socket-tcp6			\
 		socket-tcpbuf			\
+		socket-tcpbuf6			\
 		sock_opts00			\
 		sock_opts01			\
 		sk-unix-unconn			\
@@ -210,6 +213,9 @@ shm:			override CFLAGS += -DNEW_IPC_NS
 msgque:			override CFLAGS += -DNEW_IPC_NS
 sem:			override CFLAGS += -DNEW_IPC_NS
 posix_timers:		override LDLIBS += -lrt
+socket-tcp6: override CFLAGS += -D ZDTM_IPV6
+socket-tcpbuf6: override CFLAGS += -D ZDTM_IPV6
+socket_listen6: override CFLAGS += -D ZDTM_IPV6
 
 $(LIB):	force
 	$(MAKE) -C $(LIBDIR)
diff --git a/test/zdtm/live/static/socket-tcp.c b/test/zdtm/live/static/socket-tcp.c
index 747e9f0..b37f012 100644
--- a/test/zdtm/live/static/socket-tcp.c
+++ b/test/zdtm/live/static/socket-tcp.c
@@ -1,5 +1,11 @@
 #include "zdtmtst.h"
 
+#ifdef ZDTM_IPV6
+#define ZDTM_FAMILY AF_INET6
+#else
+#define ZDTM_FAMILY AF_INET
+#endif
+
 const char *test_doc = "Check, that a TCP connection can be restored\n";
 const char *test_author = "Andrey Vagin <avagin at parallels.com";
 
@@ -10,6 +16,7 @@ const char *test_author = "Andrey Vagin <avagin at parallels.com";
 #include <errno.h>
 #include <stdlib.h>
 #include <signal.h>
+#include <netinet/tcp.h>
 
 static int port = 8880;
 
@@ -70,7 +77,7 @@ int main(int argc, char **argv)
 			return 1;
 		}
 
-		fd = tcp_init_client("127.0.0.1", port);
+		fd = tcp_init_client(ZDTM_FAMILY, "localhost", port);
 		if (fd < 0)
 			return 1;
 
@@ -108,7 +115,7 @@ int main(int argc, char **argv)
 
 	test_init(argc, argv);
 
-	if ((fd_s = tcp_init_server(&port)) < 0) {
+	if ((fd_s = tcp_init_server(ZDTM_FAMILY, &port)) < 0) {
 		err("initializing server failed");
 		return 1;
 	}
diff --git a/test/zdtm/live/static/socket-tcp6.c b/test/zdtm/live/static/socket-tcp6.c
new file mode 120000
index 0000000..8cb60dd
--- /dev/null
+++ b/test/zdtm/live/static/socket-tcp6.c
@@ -0,0 +1 @@
+socket-tcp.c
\ No newline at end of file
diff --git a/test/zdtm/live/static/socket-tcpbuf.c b/test/zdtm/live/static/socket-tcpbuf.c
index 4618974..57a17a1 100644
--- a/test/zdtm/live/static/socket-tcpbuf.c
+++ b/test/zdtm/live/static/socket-tcpbuf.c
@@ -1,5 +1,11 @@
 #include "zdtmtst.h"
 
+#ifdef ZDTM_IPV6
+#define ZDTM_FAMILY AF_INET6
+#else
+#define ZDTM_FAMILY AF_INET
+#endif
+
 const char *test_doc = "Check full tcp buffers with custom sizes\n";
 const char *test_author = "Andrey Vagin <avagin at parallels.com";
 
@@ -12,6 +18,7 @@ const char *test_author = "Andrey Vagin <avagin at parallels.com";
 #include <signal.h>
 #include <fcntl.h>
 #include <sys/socket.h>
+#include <netinet/tcp.h>
 
 static int port = 8880;
 
@@ -110,11 +117,11 @@ int main(int argc, char **argv)
 			return 1;
 		}
 
-		fd = tcp_init_client("127.0.0.1", port);
+		fd = tcp_init_client(ZDTM_FAMILY, "127.0.0.1", port);
 		if (fd < 0)
 			return 1;
 
-		ctl_fd = tcp_init_client("127.0.0.1", port);
+		ctl_fd = tcp_init_client(ZDTM_FAMILY, "127.0.0.1", port);
 		if (fd < 0)
 			return 1;
 
@@ -149,7 +156,7 @@ int main(int argc, char **argv)
 
 	test_init(argc, argv);
 
-	if ((fd_s = tcp_init_server(&port)) < 0) {
+	if ((fd_s = tcp_init_server(ZDTM_FAMILY, &port)) < 0) {
 		err("initializing server failed");
 		return 1;
 	}
diff --git a/test/zdtm/live/static/socket-tcpbuf6.c b/test/zdtm/live/static/socket-tcpbuf6.c
new file mode 120000
index 0000000..58c46c7
--- /dev/null
+++ b/test/zdtm/live/static/socket-tcpbuf6.c
@@ -0,0 +1 @@
+socket-tcpbuf.c
\ No newline at end of file
diff --git a/test/zdtm/live/static/socket_aio.c b/test/zdtm/live/static/socket_aio.c
index 8779e8f..b7925f2 100644
--- a/test/zdtm/live/static/socket_aio.c
+++ b/test/zdtm/live/static/socket_aio.c
@@ -17,6 +17,7 @@ const char *test_author = "Andrew Vagin <avagin at parallels.com>";
 #include <stdlib.h>
 #include <aio.h>
 #include <wait.h>
+#include <netinet/tcp.h>
 
 static int port = 8880;
 
@@ -34,7 +35,7 @@ int main(int argc, char **argv)
 
 	test_init(argc, argv);
 
-	if ((fd_s = tcp_init_server(&port)) < 0) {
+	if ((fd_s = tcp_init_server(AF_INET, &port)) < 0) {
 		err("initializing server failed");
 		return 1;
 	}
@@ -50,7 +51,7 @@ int main(int argc, char **argv)
 		 * Chiled is client of TCP connection
 		 */
 		close(fd_s);
-		fd = tcp_init_client("127.0.0.1", port);
+		fd = tcp_init_client(AF_INET, "127.0.0.1", port);
 		if (fd < 0)
 			return 1;
 
diff --git a/test/zdtm/live/static/socket_listen.c b/test/zdtm/live/static/socket_listen.c
index def309f..6aef4a6 100644
--- a/test/zdtm/live/static/socket_listen.c
+++ b/test/zdtm/live/static/socket_listen.c
@@ -1,5 +1,11 @@
 #include "zdtmtst.h"
 
+#ifdef ZDTM_IPV6
+#define ZDTM_FAMILY AF_INET6
+#else
+#define ZDTM_FAMILY AF_INET
+#endif
+
 const char *test_doc = "static test for listening socket\n";
 const char *test_author = "Stanislav Kinsbursky <skinsbursky at openvz.org>";
 
@@ -14,6 +20,7 @@ const char *test_author = "Stanislav Kinsbursky <skinsbursky at openvz.org>";
 #include <errno.h>
 #include <stdlib.h>
 #include <wait.h>
+#include <netinet/tcp.h>
 
 static int port = 8880;
 
@@ -36,7 +43,7 @@ int main(int argc, char **argv)
 
 	test_init(argc, argv);
 
-	if ((fd_s = tcp_init_server(&port)) < 0) {
+	if ((fd_s = tcp_init_server(ZDTM_FAMILY, &port)) < 0) {
 		err("initializing server failed");
 		return 1;
 	}
@@ -59,7 +66,7 @@ int main(int argc, char **argv)
 		 * Chiled is client of TCP connection
 		 */
 		close(fd_s);
-		fd = tcp_init_client("127.0.0.1", port);
+		fd = tcp_init_client(ZDTM_FAMILY, "localhost", port);
 		if (fd < 0)
 			return 1;
 
diff --git a/test/zdtm/live/static/socket_listen6.c b/test/zdtm/live/static/socket_listen6.c
new file mode 120000
index 0000000..d026b3b
--- /dev/null
+++ b/test/zdtm/live/static/socket_listen6.c
@@ -0,0 +1 @@
+socket_listen.c
\ No newline at end of file
diff --git a/test/zdtm/live/streaming/Makefile b/test/zdtm/live/streaming/Makefile
index b9a9f84..24b96a2 100644
--- a/test/zdtm/live/streaming/Makefile
+++ b/test/zdtm/live/streaming/Makefile
@@ -10,6 +10,7 @@ TST_NOFILE	=	\
 		netlink00	\
 		file_aio	\
 		socket-tcp	\
+		socket-tcp6	\
 
 TST_FILE	=	\
 		unix_sock	\
@@ -60,6 +61,7 @@ $(TST):	$(LIB)
 
 file_aio: override LDLIBS += -lrt -pthread
 socket-tcp: override CFLAGS += -D STREAM
+socket-tcp6: override CFLAGS += -D ZDTM_IPV6 -D STREAM
 
 $(LIB):	force
 	$(MAKE) -C $(LIBDIR)
diff --git a/test/zdtm/live/streaming/socket-tcp6.c b/test/zdtm/live/streaming/socket-tcp6.c
new file mode 120000
index 0000000..772a5dd
--- /dev/null
+++ b/test/zdtm/live/streaming/socket-tcp6.c
@@ -0,0 +1 @@
+../static/socket-tcp.c
\ No newline at end of file
-- 
1.7.11.7



More information about the CRIU mailing list