[CRIU] [PATCH CRIU 07/14] dump/net/ipv6: net device and def/all configuration

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Wed Mar 30 03:42:25 PDT 2016


* old MAX_CONF_OPT_PATH should be enough for ipv6 path array as
len('net/ipv6/conf//mldv2_unsolicited_report_interval') is 48
but len and size are almost back to back, so increase it a bit,
to don't worry about it.

https://jira.sw.ru/browse/PSBM-30942
Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
 criu/net.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 62 insertions(+), 4 deletions(-)

diff --git a/criu/net.c b/criu/net.c
index b1d42ff..a55cfba 100644
--- a/criu/net.c
+++ b/criu/net.c
@@ -145,7 +145,7 @@ char *devconfs6[] = {
 };
 
 #define CONF_OPT_PATH "net/%s/conf/%s/%s"
-#define MAX_CONF_OPT_PATH IFNAMSIZ+50
+#define MAX_CONF_OPT_PATH IFNAMSIZ+60
 
 static int net_conf_op(char *tgt, int *conf, int n, int op, char *proto,
 		struct sysctl_req *req, char (*path)[MAX_CONF_OPT_PATH], int size,
@@ -215,6 +215,17 @@ static int ipv4_conf_op(char *tgt, int *conf, int n,
 			devconfs4, mask_unused, netns ? (*netns)->def_conf4 : NULL);
 }
 
+static int ipv6_conf_op(char *tgt, int *conf, int n,
+		int op, int *mask_unused, NetnsEntry **netns)
+{
+	struct sysctl_req req[ARRAY_SIZE(devconfs6)];
+	char path[ARRAY_SIZE(devconfs6)][MAX_CONF_OPT_PATH];
+
+	return net_conf_op(tgt, conf, n, op, "ipv6",
+			req, path, ARRAY_SIZE(devconfs6),
+			devconfs6, mask_unused, netns ? (*netns)->def_conf6 : NULL);
+}
+
 int write_netdev_img(NetDeviceEntry *nde, struct cr_imgset *fds)
 {
 	return pb_write_one(img_from_set(fds, CR_FD_NETDEV), nde, PB_NETDEV);
@@ -227,7 +238,7 @@ static int dump_one_netdev(int type, struct ifinfomsg *ifi,
 		int (*dump)(NetDeviceEntry *, struct cr_imgset *))
 {
 	int ret;
-	int mask_unused4[CONF_MASK_SIZE] = { 0 };
+	int mask_unused4[CONF_MASK_SIZE] = { 0 }, mask_unused6[CONF_MASK_SIZE] = { 0 };
 	NetDeviceEntry netdev = NET_DEVICE_ENTRY__INIT;
 
 	if (!tb[IFLA_IFNAME]) {
@@ -251,22 +262,38 @@ static int dump_one_netdev(int type, struct ifinfomsg *ifi,
 	}
 
 	netdev.n_mask_unused4 = CONF_MASK_SIZE;
+	netdev.n_mask_unused6 = CONF_MASK_SIZE;
 	netdev.mask_unused4 = mask_unused4;
+	netdev.mask_unused6 = mask_unused6;
+
 	netdev.n_conf4 = ARRAY_SIZE(devconfs4);
 	netdev.conf4 = xmalloc(sizeof(int) * netdev.n_conf4);
 	if (!netdev.conf4)
 		return -1;
 
+	netdev.n_conf6 = ARRAY_SIZE(devconfs6);
+	netdev.conf6 = xmalloc(sizeof(int) * netdev.n_conf6);
+	if (!netdev.conf6) {
+		ret = -1;
+		goto err_free;
+	}
+
 	ret = ipv4_conf_op(netdev.name, netdev.conf4, netdev.n_conf4,
 			CTL_READ, netdev.mask_unused4, NULL);
 	if (ret < 0)
 		goto err_free;
 
+	ret = ipv6_conf_op(netdev.name, netdev.conf6, netdev.n_conf6,
+			CTL_READ, netdev.mask_unused6, NULL);
+	if (ret < 0)
+		goto err_free;
+
 	if (!dump)
 		dump = write_netdev_img;
 
 	ret = dump(&netdev, fds);
 err_free:
+	xfree(netdev.conf6);
 	xfree(netdev.conf4);
 	return ret;
 }
@@ -943,11 +970,14 @@ static inline int dump_iptables(struct cr_imgset *fds)
 static int dump_netns_conf(struct cr_imgset *fds)
 {
 	int ret, n;
-	int mask_unused4[CONF_MASK_SIZE] = { 0 };
+	int mask_unused4[CONF_MASK_SIZE] = { 0 }, mask_unused6[CONF_MASK_SIZE] = { 0 };
 	NetnsEntry netns = NETNS_ENTRY__INIT;
 
 	netns.n_mask_unused4 = CONF_MASK_SIZE;
+	netns.n_mask_unused6 = CONF_MASK_SIZE;
 	netns.mask_unused4 = mask_unused4;
+	netns.mask_unused6 = mask_unused6;
+
 	netns.n_def_conf4 = ARRAY_SIZE(devconfs4);
 	netns.n_all_conf4 = ARRAY_SIZE(devconfs4);
 	netns.def_conf4 = xmalloc(sizeof(int) * netns.n_def_conf4);
@@ -959,6 +989,22 @@ static int dump_netns_conf(struct cr_imgset *fds)
 		return -1;
 	}
 
+	netns.n_def_conf6 = ARRAY_SIZE(devconfs6);
+	netns.n_all_conf6 = ARRAY_SIZE(devconfs6);
+	netns.def_conf6 = xmalloc(sizeof(int) * netns.n_def_conf6);
+	if (!netns.def_conf6) {
+		xfree(netns.all_conf4);
+		xfree(netns.def_conf4);
+		return -1;
+	}
+	netns.all_conf6 = xmalloc(sizeof(int) * netns.n_all_conf6);
+	if (!netns.all_conf6) {
+		xfree(netns.def_conf6);
+		xfree(netns.all_conf4);
+		xfree(netns.def_conf4);
+		return -1;
+	}
+
 	n = netns.n_def_conf4;
 	ret = ipv4_conf_op("default", netns.def_conf4, n,
 			CTL_READ, netns.mask_unused4, NULL);
@@ -969,10 +1015,22 @@ static int dump_netns_conf(struct cr_imgset *fds)
 	if (ret < 0)
 		goto err_free;
 
+	n = netns.n_def_conf6;
+	ret = ipv6_conf_op("default", netns.def_conf6, n,
+			CTL_READ, netns.mask_unused6, NULL);
+	if (ret < 0)
+		goto err_free;
+	ret = ipv6_conf_op("all", netns.all_conf6, n,
+			CTL_READ, netns.mask_unused6, NULL);
+	if (ret < 0)
+		goto err_free;
+
 	ret = pb_write_one(img_from_set(fds, CR_FD_NETNS), &netns, PB_NETNS);
 err_free:
-	xfree(netns.def_conf4);
+	xfree(netns.all_conf6);
+	xfree(netns.def_conf6);
 	xfree(netns.all_conf4);
+	xfree(netns.def_conf4);
 	return ret;
 }
 
-- 
1.9.3



More information about the CRIU mailing list