[CRIU] [PATCH v2 8/8] restore netns ipv4 conf all/default

Pavel Tikhomirov ptikhomirov at parallels.com
Thu Sep 25 01:00:43 PDT 2014


Signed-off-by: Pavel Tikhomirov <ptikhomirov at parallels.com>
---
 net.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/net.c b/net.c
index 01b98ea..bf0a904 100644
--- a/net.c
+++ b/net.c
@@ -617,6 +617,38 @@ static inline int restore_iptables(int pid)
 	return ret;
 }
 
+static int restore_netns_conf(int pid)
+{
+	int ret;
+	int fd;
+	NetnsEntry *netns;
+
+	fd = open_image(CR_FD_NETNS, O_RSTR, pid);
+	if (fd < 0) {
+		pr_err("Can not open netns image\n");
+		return -1;
+	}
+
+	ret = pb_read_one(fd, &netns, PB_NETNS);
+	if (ret < 0) {
+		pr_err("Can not read netns object\n");
+		close(fd);
+		return -1;
+	}
+
+	ret = ipv4_conf_op("net/ipv4/conf/default", netns->def_conf, CTL_WRITE);
+	if (ret < 0)
+		goto err;
+	ret = ipv4_conf_op("net/ipv4/conf/all", netns->all_conf, CTL_WRITE);
+err:
+	netns_entry__free_unpacked(netns, NULL);
+	close(fd);
+	if (ret < 0)
+		return -1;
+
+	return 0;
+}
+
 static int mount_ns_sysfs(void)
 {
 	char sys_mount[] = "crtools-sys.XXXXXX";
@@ -698,6 +730,8 @@ int prepare_net_ns(int pid)
 		ret = restore_route(pid);
 	if (!ret)
 		ret = restore_iptables(pid);
+	if (!ret)
+		ret = restore_netns_conf(pid);
 
 	close(ns_fd);
 
-- 
1.9.3



More information about the CRIU mailing list