[CRIU] [PATCH] net: dump ipv6 routes

Andrey Vagin avagin at openvz.org
Wed Sep 30 04:10:48 PDT 2015


From: Andrew Vagin <avagin at openvz.org>

"ip route dump" dumps only ipv4 routes.

Reported-by: Ross Boucher <boucher at gmail.com>
Signed-off-by: Andrew Vagin <avagin at openvz.org>
---
 image-desc.c         |  1 +
 include/image-desc.h |  1 +
 include/magic.h      |  1 +
 net.c                | 37 ++++++++++++++++++++++++++++++-------
 4 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/image-desc.c b/image-desc.c
index 6140ed6..48e3f78 100644
--- a/image-desc.c
+++ b/image-desc.c
@@ -73,6 +73,7 @@ struct cr_fd_desc_tmpl imgset_template[CR_FD_MAX] = {
 	FD_ENTRY(NETNS,		"netns-%d"),
 	FD_ENTRY_F(IFADDR,	"ifaddr-%d", O_NOBUF),
 	FD_ENTRY_F(ROUTE,	"route-%d", O_NOBUF),
+	FD_ENTRY_F(ROUTE6,	"route6-%d", O_NOBUF),
 	FD_ENTRY_F(IPTABLES,	"iptables-%d", O_NOBUF),
 	FD_ENTRY_F(IP6TABLES,	"ip6tables-%d", O_NOBUF),
 	FD_ENTRY_F(TMPFS_IMG,	"tmpfs-%d.tar.gz", O_NOBUF),
diff --git a/include/image-desc.h b/include/image-desc.h
index 709b595..7edfb8f 100644
--- a/include/image-desc.h
+++ b/include/image-desc.h
@@ -39,6 +39,7 @@ enum {
 	CR_FD_NETDEV,
 	CR_FD_IFADDR,
 	CR_FD_ROUTE,
+	CR_FD_ROUTE6,
 	CR_FD_IPTABLES,
 	CR_FD_IP6TABLES,
 	CR_FD_NETNS,
diff --git a/include/magic.h b/include/magic.h
index c497329..085c0e8 100644
--- a/include/magic.h
+++ b/include/magic.h
@@ -92,6 +92,7 @@
 
 #define IFADDR_MAGIC		RAW_IMAGE_MAGIC
 #define ROUTE_MAGIC		RAW_IMAGE_MAGIC
+#define ROUTE6_MAGIC		RAW_IMAGE_MAGIC
 #define TMPFS_IMG_MAGIC		RAW_IMAGE_MAGIC
 #define TMPFS_DEV_MAGIC		RAW_IMAGE_MAGIC
 #define IPTABLES_MAGIC		RAW_IMAGE_MAGIC
diff --git a/net.c b/net.c
index 1903ae9..2a6352b 100644
--- a/net.c
+++ b/net.c
@@ -518,7 +518,7 @@ exit:
 	return ret;
 }
 
-static int run_ip_tool(char *arg1, char *arg2, int fdin, int fdout)
+static int run_ip_tool(char *arg1, char *arg2, char *arg3, int fdin, int fdout)
 {
 	char *ip_tool_cmd;
 	int ret;
@@ -530,7 +530,7 @@ static int run_ip_tool(char *arg1, char *arg2, int fdin, int fdout)
 		ip_tool_cmd = "ip";
 
 	ret = cr_system(fdin, fdout, -1, ip_tool_cmd,
-				(char *[]) { "ip", arg1, arg2, NULL });
+				(char *[]) { "ip", arg1, arg2, arg3, NULL });
 	if (ret) {
 		pr_err("IP tool failed on %s %s\n", arg1, arg2);
 		return -1;
@@ -558,13 +558,28 @@ static int run_iptables_tool(char *def_cmd, int fdin, int fdout)
 static inline int dump_ifaddr(struct cr_imgset *fds)
 {
 	struct cr_img *img = img_from_set(fds, CR_FD_IFADDR);
-	return run_ip_tool("addr", "save", -1, img_raw_fd(img));
+	return run_ip_tool("addr", "save", NULL, -1, img_raw_fd(img));
 }
 
 static inline int dump_route(struct cr_imgset *fds)
 {
-	struct cr_img *img = img_from_set(fds, CR_FD_ROUTE);
-	return run_ip_tool("route", "save", -1, img_raw_fd(img));
+	struct cr_img *img;
+
+	img = img_from_set(fds, CR_FD_ROUTE);
+	if (run_ip_tool("route", "save", NULL, -1, img_raw_fd(img)))
+		return -1;
+
+	/* If ipv6 is disabled, "ip -6 route dump" dumps all routes */
+	if (access("/proc/sys/net/ipv6/", F_OK)) {
+		pr_debug("ipv6 is disabled\n");
+		return 0;
+	}
+
+	img = img_from_set(fds, CR_FD_ROUTE6);
+	if (run_ip_tool("-6", "route", "save", -1, img_raw_fd(img)))
+		return -1;
+
+	return 0;
 }
 
 static inline int dump_iptables(struct cr_imgset *fds)
@@ -619,8 +634,10 @@ static int restore_ip_dump(int type, int pid, char *cmd)
 	struct cr_img *img;
 
 	img = open_image(type, O_RSTR, pid);
+	if (empty_image(img))
+		return 0;
 	if (img) {
-		ret = run_ip_tool(cmd, "restore", img_raw_fd(img), -1);
+		ret = run_ip_tool(cmd, "restore", NULL, img_raw_fd(img), -1);
 		close_image(img);
 	}
 
@@ -634,7 +651,13 @@ static inline int restore_ifaddr(int pid)
 
 static inline int restore_route(int pid)
 {
-	return restore_ip_dump(CR_FD_ROUTE, pid, "route");
+	if (restore_ip_dump(CR_FD_ROUTE, pid, "route"))
+		return -1;
+
+	if (restore_ip_dump(CR_FD_ROUTE6, pid, "route"))
+		return -1;
+
+	return 0;
 }
 
 static inline int restore_iptables(int pid)
-- 
2.4.3



More information about the CRIU mailing list