[CRIU] [PATCH 2/2] zdtm: check a reseted tcp connect

Andrei Vagin avagin at openvz.org
Sat Oct 7 00:31:55 MSK 2017


From: Andrei Vagin <avagin at virtuozzo.com>

This test create a closed socket with a non-empty sent queue.

Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 test/zdtm/static/Makefile                |  1 +
 test/zdtm/static/socket-tcp-reseted.c    | 90 ++++++++++++++++++++++++++++++++
 test/zdtm/static/socket-tcp-reseted.desc | 10 ++++
 test/zdtm/static/socket-tcp-reseted.hook |  1 +
 4 files changed, 102 insertions(+)
 create mode 100644 test/zdtm/static/socket-tcp-reseted.c
 create mode 100644 test/zdtm/static/socket-tcp-reseted.desc
 create mode 120000 test/zdtm/static/socket-tcp-reseted.hook

diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index 373c6c507..a9ee927d0 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -63,6 +63,7 @@ TST_NOFILE	:=				\
 		sockets_spair			\
 		socket_queues			\
 		socket-tcp			\
+		socket-tcp-reseted		\
 		socket-tcp6			\
 		socket-tcp-local		\
 		socket-tcp-nfconntrack		\
diff --git a/test/zdtm/static/socket-tcp-reseted.c b/test/zdtm/static/socket-tcp-reseted.c
new file mode 100644
index 000000000..f5d1bfb92
--- /dev/null
+++ b/test/zdtm/static/socket-tcp-reseted.c
@@ -0,0 +1,90 @@
+
+#include "zdtmtst.h"
+#include <string.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>  /* for sockaddr_in and inet_ntoa() */
+#include <stdlib.h>
+#include <sys/wait.h>
+
+
+#ifdef ZDTM_IPV6
+#define ZDTM_FAMILY AF_INET6
+#else
+#define ZDTM_FAMILY AF_INET
+#endif
+
+const char *test_doc = "Check, that a reseted TCP connection can be restored\n";
+const char *test_author = "Andrey Vagin <avagin at parallels.com";
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <sched.h>
+#include <netinet/tcp.h>
+
+static int port = 8880;
+
+int main(int argc, char **argv)
+{
+	int fd, fd_s, clt;
+	char cmd[4096], buf[10];
+
+	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) {
+		pr_perror("Unable to create a client socket");
+	        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;
+	}
+	if (write(clt, "asd", 3) != 3) {
+		pr_perror("Unable to write into a socket");
+		return 1;
+	}
+	snprintf(cmd, sizeof(cmd), "iptables -w -t filter --protocol tcp -A INPUT --dport %d -j REJECT --reject-with tcp-reset", port);
+	if (system(cmd))
+		return 1;
+
+	if (write(fd, "asdas", 5) == -1) {
+		pr_perror("Unable to write into a socket");
+		return 1;
+	}
+
+	snprintf(cmd, sizeof(cmd), "iptables -w -t filter --protocol tcp -D INPUT --dport %d -j REJECT --reject-with tcp-reset", port);
+	if (system(cmd))
+		return 1;
+
+	test_daemon();
+	test_waitsig();
+
+	if (read(fd, buf, sizeof(buf)) != 3) {
+		fail("Unable to read data from a socket");
+		return 1;
+	}
+
+	if (write(fd, buf, 3) != -1) {
+		fail("Can write into a closed socket");
+		return 1;
+	}
+
+	pass();
+	return 0;
+}
diff --git a/test/zdtm/static/socket-tcp-reseted.desc b/test/zdtm/static/socket-tcp-reseted.desc
new file mode 100644
index 000000000..c026d9d61
--- /dev/null
+++ b/test/zdtm/static/socket-tcp-reseted.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',
+		'/usr/lib64/xtables/libipt_REJECT.so|/lib/xtables/libipt_REJECT.so|/usr/lib/powerpc64le-linux-gnu/xtables/libipt_REJECT.so|/usr/lib/x86_64-linux-gnu/xtables/libipt_REJECT.so',
+       ],
+       'opts': '--tcp-established',
+       'flags': 'suid nouser samens',
+       'feature' : 'tcp_half_closed'
+}
diff --git a/test/zdtm/static/socket-tcp-reseted.hook b/test/zdtm/static/socket-tcp-reseted.hook
new file mode 120000
index 000000000..73d7da1c4
--- /dev/null
+++ b/test/zdtm/static/socket-tcp-reseted.hook
@@ -0,0 +1 @@
+socket-tcp-fin-wait1.hook
\ No newline at end of file
-- 
2.13.3



More information about the CRIU mailing list