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

Kirill Tkhai ktkhai at virtuozzo.com
Fri Mar 2 15:46:28 MSK 2018


Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/cr-check.c        |    8 ++++++++
 criu/include/kerndat.h |    1 +
 criu/include/tun.h     |    1 +
 criu/kerndat.c         |    9 +++++++++
 criu/tun.c             |   20 ++++++++++++++++++++
 5 files changed, 39 insertions(+)

diff --git a/criu/cr-check.c b/criu/cr-check.c
index a256d670f..793ec6486 100644
--- a/criu/cr-check.c
+++ b/criu/cr-check.c
@@ -1242,6 +1242,13 @@ static int check_tun(void)
 	return check_tun_cr(-1);
 }
 
+static int check_tun_netns(void)
+{
+	bool has = false;
+	check_tun_netns_cr(&has);
+	return has ? 0 : -1;
+}
+
 static int check_nsid(void)
 {
 	if (!kdat.has_nsid) {
@@ -1273,6 +1280,7 @@ static struct feature_list feature_list[] = {
 	{ "aio_remap", check_aio_remap },
 	{ "timerfd", check_timerfd },
 	{ "tun", check_tun },
+	{ "tun_ns", check_tun_netns },
 	{ "userns", check_userns },
 	{ "fdinfo_lock", check_fdinfo_lock },
 	{ "seccomp_suspend", check_ptrace_suspend_seccomp },
diff --git a/criu/include/kerndat.h b/criu/include/kerndat.h
index d26d7630b..0919d382a 100644
--- a/criu/include/kerndat.h
+++ b/criu/include/kerndat.h
@@ -48,6 +48,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..2ccd007c2 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 check_tun_netns_cr(bool *result);
 
 #endif /* __CR_TUN_H__ */
diff --git a/criu/kerndat.c b/criu/kerndat.c
index cf76862d9..52d8b093a 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"
@@ -1014,6 +1015,12 @@ int kerndat_has_nspid(void)
 	bclose(&f);
 	return ret;
 }
+
+static int kerndat_tun_netns(void)
+{
+	return check_tun_netns_cr(&kdat.tun_ns);
+}
+
 int kerndat_init(void)
 {
 	int ret;
@@ -1050,6 +1057,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..117d30aa3 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,25 @@ int check_tun_cr(int no_tun_err)
 	return ret;
 }
 
+int check_tun_netns_cr(bool *result)
+{
+	bool val;
+	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, &val, "tun");
+	close(tun);
+
+	if (result)
+		*result = val;
+
+	return 0;
+}
+
 static LIST_HEAD(tun_links);
 
 struct tun_link {



More information about the CRIU mailing list