[CRIU] [PATCH 17/21] zdmt: add more checks into socket-closed-tcp

Andrei Vagin avagin at openvz.org
Thu Dec 1 00:32:35 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                        |   6 +-
 test/zdtm/static/socket-closed-tcp.c             |  58 ----------
 test/zdtm/static/socket-closed-tcp.desc          |   1 -
 test/zdtm/static/socket-tcp-closed-last-ack.c    |   1 +
 test/zdtm/static/socket-tcp-closed-last-ack.desc |  10 ++
 test/zdtm/static/socket-tcp-closed-last-ack.hook |   1 +
 test/zdtm/static/socket-tcp-closed.c             | 139 +++++++++++++++++++++++
 test/zdtm/static/socket-tcp-closed.desc          |   1 +
 test/zdtm/static/socket-tcp6-closed.c            |   1 +
 test/zdtm/static/socket-tcp6-closed.desc         |   1 +
 10 files changed, 159 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 120000 test/zdtm/static/socket-tcp-closed-last-ack.c
 create mode 100644 test/zdtm/static/socket-tcp-closed-last-ack.desc
 create mode 120000 test/zdtm/static/socket-tcp-closed-last-ack.hook
 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 06ce754..a04df8d 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,9 @@ TST_NOFILE	:=				\
 		socket-tcp6-last-ack		\
 		socket-tcp-closing		\
 		socket-tcp6-closing		\
+		socket-tcp-closed		\
+		socket-tcp-closed-last-ack	\
+		socket-tcp6-closed		\
 		sock_opts00			\
 		sock_opts01			\
 		sk-unix-unconn			\
@@ -410,6 +412,8 @@ 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
+socket-tcp-closed-last-ack: override CFLAGS += -D ZDTM_TCP_LAST_ACK
 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-last-ack.c b/test/zdtm/static/socket-tcp-closed-last-ack.c
new file mode 120000
index 0000000..b0c363c
--- /dev/null
+++ b/test/zdtm/static/socket-tcp-closed-last-ack.c
@@ -0,0 +1 @@
+socket-tcp-closed.c
\ No newline at end of file
diff --git a/test/zdtm/static/socket-tcp-closed-last-ack.desc b/test/zdtm/static/socket-tcp-closed-last-ack.desc
new file mode 100644
index 0000000..bc56073
--- /dev/null
+++ b/test/zdtm/static/socket-tcp-closed-last-ack.desc
@@ -0,0 +1,10 @@
+{   'deps': [   '/bin/sh',
+                '/sbin/iptables',
+                '/usr/lib64/xtables/libxt_tcp.so|/lib/xtables/libxt_tcp.so|/usr/lib/powerpc64le-linux-gnu/xtables/libxt_tcp.so|/usr/lib/x86_64-linux-gnu/xtables/libxt_tcp.so',
+                '/usr/lib64/xtables/libxt_standard.so|/lib/xtables/libxt_standard.so|/usr/lib/powerpc64le-linux-gnu/xtables/libxt_standard.so|/usr/lib/x86_64-linux-gnu/xtables/libxt_standard.so',
+	],
+	'opts': '--tcp-established',
+	'flags': 'suid nouser samens',
+	'feature' : 'tcp_half_closed',
+	'flavor': 'ns uns',
+}
diff --git a/test/zdtm/static/socket-tcp-closed-last-ack.hook b/test/zdtm/static/socket-tcp-closed-last-ack.hook
new file mode 120000
index 0000000..73d7da1
--- /dev/null
+++ b/test/zdtm/static/socket-tcp-closed-last-ack.hook
@@ -0,0 +1 @@
+socket-tcp-fin-wait1.hook
\ No newline at end of file
diff --git a/test/zdtm/static/socket-tcp-closed.c b/test/zdtm/static/socket-tcp-closed.c
new file mode 100644
index 0000000..2125b00
--- /dev/null
+++ b/test/zdtm/static/socket-tcp-closed.c
@@ -0,0 +1,139 @@
+#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;
+#ifdef ZDTM_TCP_LAST_ACK
+	char cmd[4096];
+#endif
+
+	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(clt, SHUT_WR);
+
+#ifdef ZDTM_TCP_LAST_ACK
+	snprintf(cmd, sizeof(cmd), "iptables -w -t filter --protocol tcp -A INPUT --dport %d -j DROP", port);
+	if (system(cmd))
+		return -1;
+#endif
+
+	shutdown(fd, 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();
+
+#ifdef ZDTM_TCP_LAST_ACK
+	snprintf(cmd, sizeof(cmd), "iptables -w -t filter --protocol tcp -D INPUT --dport %d -j DROP", port);
+	if (system(cmd))
+		return -1;
+#endif
+
+	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..21cbeff
--- /dev/null
+++ b/test/zdtm/static/socket-tcp-closed.desc
@@ -0,0 +1 @@
+{'opts': '--tcp-established', 'flags': 'nouser samens', 'feature' : 'tcp_half_closed', 'flavor' : 'ns uns'}
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