[CRIU] [PATCH 3/3] zdtm: check that the IP_FREEBIND is restored correctly

Andrey Vagin avagin at openvz.org
Mon Nov 23 00:09:43 PST 2015


From: Andrew Vagin <avagin at virtuozzo.com>

Signed-off-by: Andrew Vagin <avagin at virtuozzo.com>
---
 test/zdtm/live/static/Makefile            |  3 ++
 test/zdtm/live/static/sk-freebind-false.c |  1 +
 test/zdtm/live/static/sk-freebind.c       | 72 +++++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+)
 create mode 120000 test/zdtm/live/static/sk-freebind-false.c
 create mode 100644 test/zdtm/live/static/sk-freebind.c

diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index 23ec5a1..66920ca 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -31,6 +31,8 @@ TST_NOFILE	=				\
 		socket_listen6			\
 		socket_udp			\
 		socket6_udp			\
+		sk-freebind			\
+		sk-freebind-false		\
 		socket_udplite			\
 		socket_aio			\
 		socket_close_data		\
@@ -354,6 +356,7 @@ maps02:		get_smaps_bits.o
 mlock_setuid:		get_smaps_bits.o
 inotify01:		override CFLAGS += -DINOTIFY01
 unlink_fstat01+:	override CFLAGS += -DUNLINK_OVER
+sk-freebind-false:	override CFLAGS += -DZDTM_FREEBIND_FALSE
 
 $(LIB):	force
 	$(Q) $(MAKE) -C $(LIBDIR)
diff --git a/test/zdtm/live/static/sk-freebind-false.c b/test/zdtm/live/static/sk-freebind-false.c
new file mode 120000
index 0000000..de243ce
--- /dev/null
+++ b/test/zdtm/live/static/sk-freebind-false.c
@@ -0,0 +1 @@
+sk-freebind.c
\ No newline at end of file
diff --git a/test/zdtm/live/static/sk-freebind.c b/test/zdtm/live/static/sk-freebind.c
new file mode 100644
index 0000000..488110a
--- /dev/null
+++ b/test/zdtm/live/static/sk-freebind.c
@@ -0,0 +1,72 @@
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>  /* for sockaddr_in and inet_ntoa() */
+
+#include "zdtmtst.h"
+
+const char *test_doc	= "Check that IP_FREEBIND is restored";
+const char *test_author	= "Andrew Vagin <avagin at virtuozzo.com>";
+
+union sockaddr_inet {
+	struct sockaddr_in v4;
+	struct sockaddr_in6 v6;
+};
+
+int main(int argc, char **argv)
+{
+	union sockaddr_inet addr;
+	socklen_t len;
+	int val, sock;
+
+	test_init(argc, argv);
+
+	addr.v6.sin6_family = AF_INET6;
+	inet_pton(AF_INET6, "2001:db8::ff00:42:8329", &(addr.v6.sin6_addr));
+	addr.v6.sin6_port = htons(56789);
+
+	sock = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
+	if (sock == -1) {
+		pr_perror("socket() failed");
+		return -1;
+	}
+	val = 1;
+	if (setsockopt(sock, SOL_IP, IP_FREEBIND, &val, sizeof(int)) == -1 ) {
+		pr_perror("setsockopt() error");
+		return -1;
+	}
+	if (bind(sock, (struct sockaddr *) &addr, sizeof(addr))) {
+		pr_perror("bind()");
+		return -1;
+	}
+#ifdef ZDTM_FREEBIND_FALSE
+	val = 0;
+	if (setsockopt(sock, SOL_IP, IP_FREEBIND, &val, sizeof(int)) == -1 ) {
+		pr_perror("setsockopt() error");
+		return -1;
+	}
+#endif
+
+	test_daemon();
+	test_waitsig();
+
+	len = sizeof(int);
+	if (getsockopt(sock, SOL_IP, IP_FREEBIND, &val, &len) == -1 ) {
+		pr_perror("setsockopt() error");
+		return -1;
+	}
+
+#ifdef ZDTM_FREEBIND_FALSE
+	if (val) {
+#else
+	if (val == 0) {
+#endif
+		fail("Unexpected value: %d", val);
+		return -1;
+	}
+
+	pass();
+
+	return 0;
+}
-- 
2.4.3



More information about the CRIU mailing list