[CRIU] [PATCH 2/2] test: Add simple socket-raw test

Cyrill Gorcunov gorcunov at openvz.org
Wed Nov 16 02:59:46 PST 2016


Trivial test for sockets dump support and restore.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 test/zdtm/static/Makefile        |  1 +
 test/zdtm/static/socket-raw.c    | 86 ++++++++++++++++++++++++++++++++++++++++
 test/zdtm/static/socket-raw.desc |  1 +
 3 files changed, 88 insertions(+)
 create mode 100644 test/zdtm/static/socket-raw.c
 create mode 100644 test/zdtm/static/socket-raw.desc

diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index f8a922b10025..f9ee5c4d449e 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -63,6 +63,7 @@ TST_NOFILE	:=				\
 		sockets_spair			\
 		socket_queues			\
 		socket_queues02			\
+		socket-raw			\
 		socket-tcp			\
 		socket-tcp6			\
 		socket-tcp-local		\
diff --git a/test/zdtm/static/socket-raw.c b/test/zdtm/static/socket-raw.c
new file mode 100644
index 000000000000..598c565d4d80
--- /dev/null
+++ b/test/zdtm/static/socket-raw.c
@@ -0,0 +1,86 @@
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/wait.h>
+#include <sys/un.h>
+#include <sys/stat.h>
+
+#include <netinet/ip.h>
+#include <arpa/inet.h>
+
+#include <limits.h>
+#include <fcntl.h>
+
+#include "zdtmtst.h"
+
+const char *test_doc		= "Test RAW sockets (IPv4,6)\n";
+const char *test_author		= "Cyrill Gorcunov <gorcunov at openvz.org";
+
+#ifndef SO_IP_SET
+# define SO_IP_SET		83
+#endif
+
+#ifndef IP_SET_OP_VERSION
+# define IP_SET_OP_VERSION	0x00000100	/* Ask kernel version */
+#endif
+
+struct ip_set_req_version {
+	unsigned int	op;
+	unsigned int	version;
+};
+
+int main(int argc, char *argv[])
+{
+	struct ip_set_req_version req_version;
+	socklen_t size = sizeof(req_version);
+
+	int sk_raw, sk6_raw, res;
+	int sk_tcp, sk_udp;
+
+	test_init(argc, argv);
+
+	sk_raw = socket(PF_INET, SOCK_RAW | SOCK_NONBLOCK, IPPROTO_RAW);
+	if (sk_raw < 0) {
+		pr_perror("Can't create IPv4 raw socket");
+		exit(1);
+	}
+
+	/* Simply to make sure it can be recreated on restore */
+	sk6_raw = socket(PF_INET6, SOCK_RAW | SOCK_NONBLOCK, IPPROTO_RAW);
+	if (sk6_raw < 0) {
+		pr_perror("Can't create IPv6 raw socket");
+		exit(1);
+	}
+
+	sk_tcp = socket(PF_INET, SOCK_RAW | SOCK_NONBLOCK, IPPROTO_TCP);
+	if (sk_tcp < 0) {
+		pr_perror("Can't create IPv4 raw-tcp socket");
+		exit(1);
+	}
+
+	sk_udp = socket(PF_INET, SOCK_RAW | SOCK_NONBLOCK, IPPROTO_UDP);
+	if (sk_udp < 0) {
+		pr_perror("Can't create IPv4 raw-udp socket");
+		exit(1);
+	}
+
+	test_daemon();
+	test_waitsig();
+
+	req_version.op = IP_SET_OP_VERSION;
+	res = getsockopt(sk_raw, SOL_IP, SO_IP_SET, &req_version, &size);
+	if (res) {
+		pr_perror("xt_set getsockopt");
+	} else
+		test_msg("SO_IP_SET version = %d\n", req_version.version);
+
+	pass();
+	return 0;
+}
diff --git a/test/zdtm/static/socket-raw.desc b/test/zdtm/static/socket-raw.desc
new file mode 100644
index 000000000000..2eac7e654bf2
--- /dev/null
+++ b/test/zdtm/static/socket-raw.desc
@@ -0,0 +1 @@
+{'flags': 'suid'}
-- 
2.7.4



More information about the CRIU mailing list