[CRIU] [PATCH v2 4/8] save net device confs one by one

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


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

diff --git a/net.c b/net.c
index c4c1c84..abf9f50 100644
--- a/net.c
+++ b/net.c
@@ -18,6 +18,7 @@
 #include "tun.h"
 #include "util-pie.h"
 #include "plugin.h"
+#include "sysctl.h"
 
 #include "protobuf.h"
 #include "protobuf/netdev.pb-c.h"
@@ -80,6 +81,32 @@ char *devconfs[] = {
 
 #define NET_DEV_CONF_SIZE 28
 
+static int ipv4_conf_op(char *dir, int *conf, int op)
+{
+	int ret;
+	int i;
+
+	for (i = 0; devconfs[i]; i++) {
+		char path[PATH_MAX];
+		struct sysctl_req req[2];
+
+		snprintf(path, sizeof(path), "%s/%s", dir, devconfs[i]);
+
+		req[0].name = path;
+		req[0].arg = &conf[i];
+		req[0].type = CTL_32;
+		req[1].name = NULL;
+
+		ret = sysctl_op(req, op);
+		if (ret < 0) {
+			pr_err("Failed to read %s/%s\n", dir, devconfs[i]);
+			return -1;
+		}
+	}
+
+	return 0;
+}
+
 int write_netdev_img(NetDeviceEntry *nde, struct cr_fdset *fds)
 {
 	return pb_write_one(fdset_fd(fds, CR_FD_NETDEV), nde, PB_NETDEV);
@@ -89,6 +116,8 @@ static int dump_one_netdev(int type, struct ifinfomsg *ifi,
 		struct rtattr **tb, struct cr_fdset *fds,
 		int (*dump)(NetDeviceEntry *, struct cr_fdset *))
 {
+	int ret;
+	char path[PATH_MAX];
 	NetDeviceEntry netdev = NET_DEVICE_ENTRY__INIT;
 
 	if (!tb[IFLA_IFNAME]) {
@@ -111,10 +140,23 @@ static int dump_one_netdev(int type, struct ifinfomsg *ifi,
 				(int)netdev.address.len, netdev.name);
 	}
 
+	netdev.n_conf = NET_DEV_CONF_SIZE;
+	netdev.conf = xmalloc(sizeof(int) * NET_DEV_CONF_SIZE);
+
+	snprintf(path, sizeof(path), "net/ipv4/conf/%s", netdev.name);
+	ret = ipv4_conf_op(path, netdev.conf, CTL_READ);
+	if (ret < 0) {
+		pr_err("failed to get net device ipv4 conf");
+		goto err_free;
+	}
+
 	if (!dump)
 		dump = write_netdev_img;
 
-	return dump(&netdev, fds);
+	ret = dump(&netdev, fds);
+err_free:
+	xfree(netdev.conf);
+	return ret;
 }
 
 static char *link_kind(struct ifinfomsg *ifi, struct rtattr **tb)
-- 
1.9.3



More information about the CRIU mailing list