[CRIU] [PATCH 10/11] zdmt: add more checks into socket-closed-tcp

Andrei Vagin avagin at openvz.org
Thu Nov 10 23:10:10 PST 2016


From: Andrei Vagin <avagin at virtuozzo.com>

Check source and destination addresses for closed tcp sockets.

Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 test/zdtm/static/Makefile                |   4 +-
 test/zdtm/static/socket-closed-tcp.c     |  58 ---------------
 test/zdtm/static/socket-closed-tcp.desc  |   1 -
 test/zdtm/static/socket-tcp-closed.c     | 123 +++++++++++++++++++++++++++++++
 test/zdtm/static/socket-tcp-closed.desc  |   1 +
 test/zdtm/static/socket-tcp6-closed.c    |   1 +
 test/zdtm/static/socket-tcp6-closed.desc |   1 +
 7 files changed, 129 insertions(+), 60 deletions(-)
 delete mode 100644 test/zdtm/static/socket-closed-tcp.c
 delete mode 100644 test/zdtm/static/socket-closed-tcp.desc
 create mode 100644 test/zdtm/static/socket-tcp-closed.c
 create mode 100644 test/zdtm/static/socket-tcp-closed.desc
 create mode 120000 test/zdtm/static/socket-tcp6-closed.c
 create mode 120000 test/zdtm/static/socket-tcp6-closed.desc

diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index 3a0313b..55d6a8e 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -72,7 +72,6 @@ TST_NOFILE	:=				\
 		socket-tcpbuf-local		\
 		socket-tcpbuf6-local		\
 		socket-tcpbuf6			\
-		socket-closed-tcp		\
 		socket-tcp-fin-wait1		\
 		socket-tcp6-fin-wait1		\
 		socket-tcp-fin-wait2		\
@@ -83,6 +82,8 @@ TST_NOFILE	:=				\
 		socket-tcp6-last-ack		\
 		socket-tcp-closing		\
 		socket-tcp6-closing		\
+		socket-tcp-closed		\
+		socket-tcp6-closed		\
 		sock_opts00			\
 		sock_opts01			\
 		sk-unix-unconn			\
@@ -408,6 +409,7 @@ socket-tcp6-local: override CFLAGS += -D ZDTM_TCP_LOCAL -D ZDTM_IPV6
 socket-tcp-local: override CFLAGS += -D ZDTM_TCP_LOCAL
 socket-tcp-nfconntrack: override CFLAGS += -D ZDTM_TCP_LOCAL -DZDTM_CONNTRACK
 socket_listen6: override CFLAGS += -D ZDTM_IPV6
+socket-tcp6-closed: override CFLAGS += -D ZDTM_IPV6
 mnt_ext_manual: override CFLAGS += -D ZDTM_EXTMAP_MANUAL
 sigpending:		override LDLIBS += -lrt
 vdso01:			override LDLIBS += -lrt
diff --git a/test/zdtm/static/socket-closed-tcp.c b/test/zdtm/static/socket-closed-tcp.c
deleted file mode 100644
index 58fc7d7..0000000
--- a/test/zdtm/static/socket-closed-tcp.c
+++ /dev/null
@@ -1,58 +0,0 @@
-#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 socket in the TCP_CLOSE state can be restored\n";
-const char *test_author = "Andrey Vagin <avagin at openvz.org";
-
-#include <stdio.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <netinet/tcp.h>
-
-static int port = 8880;
-
-int main(int argc, char **argv)
-{
-	int fd, fd_s, clt;
-
-	test_init(argc, argv);
-
-	if ((fd_s = tcp_init_server(ZDTM_FAMILY, &port)) < 0) {
-		pr_err("initializing server failed\n");
-		return 1;
-	}
-
-	clt = tcp_init_client(ZDTM_FAMILY, "localhost", port);
-	if (clt < 0)
-		return 1;
-
-	/*
-	 * parent is server of TCP connection
-	 */
-	fd = tcp_accept_server(fd_s);
-	if (fd < 0) {
-		pr_err("can't accept client connection\n");
-		return 1;
-	}
-	close(fd_s);
-
-	shutdown(fd, SHUT_WR);
-	shutdown(clt, SHUT_WR);
-	close(fd);
-
-	test_daemon();
-	test_waitsig();
-
-
-	pass();
-	return 0;
-}
diff --git a/test/zdtm/static/socket-closed-tcp.desc b/test/zdtm/static/socket-closed-tcp.desc
deleted file mode 100644
index ded8987..0000000
--- a/test/zdtm/static/socket-closed-tcp.desc
+++ /dev/null
@@ -1 +0,0 @@
-{'flags': 'crfail'}
diff --git a/test/zdtm/static/socket-tcp-closed.c b/test/zdtm/static/socket-tcp-closed.c
new file mode 100644
index 0000000..4da3ac3
--- /dev/null
+++ b/test/zdtm/static/socket-tcp-closed.c
@@ -0,0 +1,123 @@
+#include "zdtmtst.h"
+
+#ifdef ZDTM_IPV6
+#define ZDTM_FAMILY AF_INET6
+#else
+#define ZDTM_FAMILY AF_INET
+#endif
+
+const char *test_doc = "Check closed tcp sockets\n";
+const char *test_author = "Andrey Vagin <avagin at openvz.org";
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <netinet/tcp.h>
+#include <arpa/inet.h>
+
+static int port = 8880;
+
+union sockaddr_inet {
+	struct sockaddr addr;
+	struct sockaddr_in v4;
+	struct sockaddr_in6 v6;
+};
+
+int main(int argc, char **argv)
+{
+	int fd, fd_s, clt, sk;
+	union sockaddr_inet src_addr, dst_addr, addr;
+	socklen_t aux;
+	char c = 5;
+
+	test_init(argc, argv);
+
+	sk = socket(ZDTM_FAMILY, SOCK_STREAM, 0);
+	if (sk < 0) {
+		pr_perror("socket");
+		return 1;
+	}
+
+	if ((fd_s = tcp_init_server(ZDTM_FAMILY, &port)) < 0) {
+		pr_err("initializing server failed\n");
+		return 1;
+	}
+
+	clt = tcp_init_client(ZDTM_FAMILY, "localhost", port);
+	if (clt < 0)
+		return 1;
+
+	/*
+	 * parent is server of TCP connection
+	 */
+	fd = tcp_accept_server(fd_s);
+	if (fd < 0) {
+		pr_err("can't accept client connection\n");
+		return 1;
+	}
+	close(fd_s);
+
+	shutdown(fd, SHUT_WR);
+	shutdown(clt, SHUT_WR);
+
+	if (ZDTM_FAMILY == AF_INET)
+		aux = sizeof(struct sockaddr_in);
+	else if (ZDTM_FAMILY == AF_INET6)
+		aux = sizeof(struct sockaddr_in6);
+	else
+		return 1;
+
+	if (getsockopt(clt, SOL_SOCKET, SO_PEERNAME, &dst_addr, &aux)) {
+		pr_perror("SO_PEERNAME");
+		return 1;
+	}
+	if (getsockname(clt, &src_addr.addr, &aux)) {
+		pr_perror("getsockname");
+		return 1;
+	}
+
+	test_daemon();
+	test_waitsig();
+
+	if (read(fd, &c, 1) != 0) {
+		fail("read");
+		return 1;
+	}
+	if (read(clt, &c, 1) != 0) {
+		fail("read");
+		return 1;
+	}
+	if (write(clt, &c, 1) != -1) {
+		fail("write");
+		return 1;
+	}
+	if (write(fd, &c, 1) != -1) {
+		fail("write");
+		return 1;
+	}
+
+	if (getsockopt(clt, SOL_SOCKET, SO_PEERNAME, &addr, &aux)) {
+		pr_perror("SO_PEERNAME");
+		return 1;
+	}
+	if (memcmp(&addr, &dst_addr, aux)) {
+		pr_err("A destination address mismatch");
+		return 1;
+	}
+
+	if (getsockname(clt, &addr.addr, &aux)) {
+		pr_perror("getsockname");
+		return 1;
+	}
+	if (memcmp(&addr, &src_addr, aux)) {
+		pr_err("A source address mismatch");
+		return 1;
+	}
+
+	pass();
+	return 0;
+}
diff --git a/test/zdtm/static/socket-tcp-closed.desc b/test/zdtm/static/socket-tcp-closed.desc
new file mode 100644
index 0000000..155e103
--- /dev/null
+++ b/test/zdtm/static/socket-tcp-closed.desc
@@ -0,0 +1 @@
+{'opts': '--tcp-established', 'flags': 'nouser samens', 'feature' : 'tcp_half_closed'}
diff --git a/test/zdtm/static/socket-tcp6-closed.c b/test/zdtm/static/socket-tcp6-closed.c
new file mode 120000
index 0000000..b0c363c
--- /dev/null
+++ b/test/zdtm/static/socket-tcp6-closed.c
@@ -0,0 +1 @@
+socket-tcp-closed.c
\ No newline at end of file
diff --git a/test/zdtm/static/socket-tcp6-closed.desc b/test/zdtm/static/socket-tcp6-closed.desc
new file mode 120000
index 0000000..a365149
--- /dev/null
+++ b/test/zdtm/static/socket-tcp6-closed.desc
@@ -0,0 +1 @@
+socket-tcp-closed.desc
\ No newline at end of file
-- 
2.7.4



More information about the CRIU mailing list