[CRIU] [PATCH 2/3] tun: Check tun has ioctl() cmd SIOCGSKNS

Kirill Tkhai ktkhai at virtuozzo.com
Mon Feb 19 15:16:11 MSK 2018


Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/include/kerndat.h |    1 +
 criu/include/tun.h     |    1 +
 criu/kerndat.c         |    3 +++
 criu/tun.c             |   16 ++++++++++++++++
 4 files changed, 21 insertions(+)

diff --git a/criu/include/kerndat.h b/criu/include/kerndat.h
index 9e7af14a3..70ae521d0 100644
--- a/criu/include/kerndat.h
+++ b/criu/include/kerndat.h
@@ -47,6 +47,7 @@ struct kerndat_s {
 	enum loginuid_func luid;
 	bool compat_cr;
 	bool sk_ns;
+	bool tun_ns;
 	enum pagemap_func pmap;
 	unsigned int has_xtlocks;
 	unsigned long mmap_min_addr;
diff --git a/criu/include/tun.h b/criu/include/tun.h
index 2d0aa8e08..e7f644065 100644
--- a/criu/include/tun.h
+++ b/criu/include/tun.h
@@ -15,5 +15,6 @@ struct net_link;
 extern int restore_one_tun(struct net_link *link, int nlsk);
 extern struct collect_image_info tunfile_cinfo;
 extern int check_tun_cr(int no_tun_err);
+extern int kerndat_tun_netns(void);
 
 #endif /* __CR_TUN_H__ */
diff --git a/criu/kerndat.c b/criu/kerndat.c
index cea2e3348..3abca2ff4 100644
--- a/criu/kerndat.c
+++ b/criu/kerndat.c
@@ -29,6 +29,7 @@
 #include "sk-inet.h"
 #include "sockets.h"
 #include "net.h"
+#include "tun.h"
 #include <compel/plugins/std/syscall-codes.h>
 #include <compel/compel.h>
 #include "netfilter.h"
@@ -1049,6 +1050,8 @@ int kerndat_init(void)
 		ret = kerndat_compat_restore();
 	if (!ret)
 		ret = kerndat_socket_netns();
+	if (!ret)
+		ret = kerndat_tun_netns();
 	if (!ret)
 		ret = kerndat_nsid();
 	if (!ret)
diff --git a/criu/tun.c b/criu/tun.c
index dfca4b125..e1d247409 100644
--- a/criu/tun.c
+++ b/criu/tun.c
@@ -19,6 +19,7 @@
 #include "net.h"
 #include "namespaces.h"
 #include "xmalloc.h"
+#include "kerndat.h"
 
 #include "images/tun.pb-c.h"
 
@@ -70,6 +71,21 @@ int check_tun_cr(int no_tun_err)
 	return ret;
 }
 
+int kerndat_tun_netns(void)
+{
+	int tun;
+
+	tun = open(TUN_DEV_GEN_PATH, O_RDONLY);
+	if (tun < 0) {
+		pr_perror("Unable to create tun");
+		return -1;
+	}
+	check_has_netns_ioc(tun, &kdat.tun_ns, "tun");
+	close(tun);
+
+	return 0;
+}
+
 static LIST_HEAD(tun_links);
 
 struct tun_link {



More information about the CRIU mailing list