[CRIU] [PATCH v3 4/7] save net device confs bunched with criu sysctl API
Pavel Tikhomirov
ptikhomirov at parallels.com
Wed Oct 1 03:42:39 PDT 2014
Signed-off-by: Pavel Tikhomirov <ptikhomirov at parallels.com>
---
net.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 54 insertions(+), 1 deletion(-)
diff --git a/net.c b/net.c
index def4fdc..05616cf 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"
@@ -79,6 +80,41 @@ char *devconfs[] = {
#define NET_DEV_CONF_SIZE 27
+static int ipv4_conf_op(char *dir, int *conf, int op)
+{
+ int ret;
+ int i, j;
+ struct sysctl_req req[NET_DEV_CONF_SIZE + 1];
+ int sdir = strlen(dir);
+
+ for (i = 0; devconfs[i]; i++) {
+ char *path;
+ int size = sdir + strlen(devconfs[i]) + 2;
+
+ path = xmalloc(size);
+ if (!path) {
+ ret = -1;
+ goto free;
+ }
+ snprintf(path, size, "%s/%s", dir, devconfs[i]);
+
+ req[i].name = path;
+ req[i].arg = &conf[i];
+ req[i].type = CTL_32;
+ }
+ req[i].name = NULL;
+
+ ret = sysctl_op(req, op);
+ if (ret < 0)
+ pr_err("Failed to read %s/<confs>\n", dir);
+free:
+ for (j = 0; j < i; j++)
+ xfree(req[j].name);
+ if (ret < 0)
+ 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);
@@ -88,6 +124,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]) {
@@ -110,10 +148,25 @@ 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);
+ if (!netdev.conf)
+ return -1;
+
+ 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