Commit 72b42d48 authored by Pavel Tikhomirov's avatar Pavel Tikhomirov Committed by Pavel Emelyanov

save net device confs bunched with criu sysctl API

Signed-off-by: 's avatarPavel Tikhomirov <ptikhomirov@parallels.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent e700fe93
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "action-scripts.h" #include "action-scripts.h"
#include "sockets.h" #include "sockets.h"
#include "pstree.h" #include "pstree.h"
#include "sysctl.h"
#include "protobuf.h" #include "protobuf.h"
#include "protobuf/netdev.pb-c.h" #include "protobuf/netdev.pb-c.h"
...@@ -81,6 +82,32 @@ char *devconfs[] = { ...@@ -81,6 +82,32 @@ char *devconfs[] = {
NULL, NULL,
}; };
#define NET_CONF_PATH "net/ipv4/conf"
#define MAX_CONF_OPT_PATH IFNAMSIZ+50
static int ipv4_conf_op(char *tgt, int *conf, int op)
{
int i;
int ret;
struct sysctl_req req[ARRAY_SIZE(devconfs) + 1];
char path[ARRAY_SIZE(devconfs)][MAX_CONF_OPT_PATH];
for (i = 0; devconfs[i]; i++) {
sprintf(path[i], "%s/%s/%s", NET_CONF_PATH, tgt, devconfs[i]);
req[i].name = path[i];
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 %s %s/<confs>\n", (op == CTL_READ)?"read":"write", tgt);
return -1;
}
return 0;
}
int write_netdev_img(NetDeviceEntry *nde, struct cr_imgset *fds) int write_netdev_img(NetDeviceEntry *nde, struct cr_imgset *fds)
{ {
return pb_write_one(img_from_set(fds, CR_FD_NETDEV), nde, PB_NETDEV); return pb_write_one(img_from_set(fds, CR_FD_NETDEV), nde, PB_NETDEV);
...@@ -90,6 +117,7 @@ static int dump_one_netdev(int type, struct ifinfomsg *ifi, ...@@ -90,6 +117,7 @@ static int dump_one_netdev(int type, struct ifinfomsg *ifi,
struct rtattr **tb, struct cr_imgset *fds, struct rtattr **tb, struct cr_imgset *fds,
int (*dump)(NetDeviceEntry *, struct cr_imgset *)) int (*dump)(NetDeviceEntry *, struct cr_imgset *))
{ {
int ret;
NetDeviceEntry netdev = NET_DEVICE_ENTRY__INIT; NetDeviceEntry netdev = NET_DEVICE_ENTRY__INIT;
if (!tb[IFLA_IFNAME]) { if (!tb[IFLA_IFNAME]) {
...@@ -112,10 +140,22 @@ static int dump_one_netdev(int type, struct ifinfomsg *ifi, ...@@ -112,10 +140,22 @@ static int dump_one_netdev(int type, struct ifinfomsg *ifi,
(int)netdev.address.len, netdev.name); (int)netdev.address.len, netdev.name);
} }
netdev.n_conf = ARRAY_SIZE(devconfs);
netdev.conf = xmalloc(sizeof(int) * netdev.n_conf);
if (!netdev.conf)
return -1;
ret = ipv4_conf_op(netdev.name, netdev.conf, CTL_READ);
if (ret < 0)
goto err_free;
if (!dump) if (!dump)
dump = write_netdev_img; 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) static char *link_kind(struct ifinfomsg *ifi, struct rtattr **tb)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment