[CRIU] [PATCH CRIU 03/14] net: add net_conf_op to reuse for ipv6

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


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

diff --git a/criu/net.c b/criu/net.c
index cddbf98..096cd25 100644
--- a/criu/net.c
+++ b/criu/net.c
@@ -101,29 +101,29 @@ static char *devconfs4[] = {
  */
 #define DEVCONFS_UNUSED        (-1u)
 
-#define NET_CONF_PATH "net/ipv4/conf"
+#define CONF_OPT_PATH "net/%s/conf/%s/%s"
 #define MAX_CONF_OPT_PATH IFNAMSIZ+50
 
-static int ipv4_conf_op(char *tgt, int *conf, int n, int op, NetnsEntry **netns)
+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,
+		char **devconfs, int32_t *def_conf)
 {
 	int i, ri;
 	int ret, flags = op == CTL_READ ? CTL_FLAGS_OPTIONAL : 0;
-	struct sysctl_req req[ARRAY_SIZE(devconfs4)];
-	char path[ARRAY_SIZE(devconfs4)][MAX_CONF_OPT_PATH];
 
-	if (n > ARRAY_SIZE(devconfs4))
+	if (n > size)
 		pr_warn("The image contains unknown sysctl-s\n");
 
-	for (i = 0, ri = 0; i < ARRAY_SIZE(devconfs4); i++) {
+	for (i = 0, ri = 0; i < size; i++) {
 		if (i >= n) {
-			pr_warn("Skip %s/%s\n", tgt, devconfs4[i]);
+			pr_warn("Skip %s/%s\n", tgt, devconfs[i]);
 			continue;
 		}
 		/*
 		 * If dev conf value is the same as default skip restoring it
 		 */
-		if (netns && conf[i] == (*netns)->def_conf4[i]) {
-			pr_debug("DEBUG Skip %s/%s, val =%d\n", tgt, devconfs4[i], conf[i]);
+		if (def_conf && conf[i] == def_conf[i]) {
+			pr_debug("DEBUG Skip %s/%s, val =%d\n", tgt, devconfs[i], conf[i]);
 			continue;
 		}
 
@@ -132,7 +132,7 @@ static int ipv4_conf_op(char *tgt, int *conf, int n, int op, NetnsEntry **netns)
 		else if (op == CTL_READ)
 			conf[i] = DEVCONFS_UNUSED;
 
-		snprintf(path[i], MAX_CONF_OPT_PATH, "%s/%s/%s", NET_CONF_PATH, tgt, devconfs4[i]);
+		snprintf(path[i], MAX_CONF_OPT_PATH, CONF_OPT_PATH, proto, tgt, devconfs[i]);
 		req[ri].name = path[i];
 		req[ri].arg = &conf[i];
 		req[ri].type = CTL_32;
@@ -148,6 +148,16 @@ static int ipv4_conf_op(char *tgt, int *conf, int n, int op, NetnsEntry **netns)
 	return 0;
 }
 
+static int ipv4_conf_op(char *tgt, int *conf, int n, int op, NetnsEntry **netns)
+{
+	struct sysctl_req req[ARRAY_SIZE(devconfs4)];
+	char path[ARRAY_SIZE(devconfs4)][MAX_CONF_OPT_PATH];
+
+	return net_conf_op(tgt, conf, n, op, "ipv4",
+			req, path, ARRAY_SIZE(devconfs4),
+			devconfs4, netns ? (*netns)->def_conf4 : 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);
-- 
1.9.3



More information about the CRIU mailing list