Skip to content

Commit

Permalink
net: pass the struct nlattrs to dump() functions
Browse files Browse the repository at this point in the history
We'll use this later in the series to get specific information that macvlan
links need.

v2: pass the IFLA_LINKINFO instead of the whole attribute buffer, since
    that's al all we expect the info functions to need, and all we allow
    them to populate on restore

travis-ci: success for series starting with [v10,01/11] net: pass the struct nlattrs to dump() functions
Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
  • Loading branch information
Tycho Andersen authored and xemul committed Nov 3, 2016
1 parent 05ac45b commit b705dcc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
4 changes: 3 additions & 1 deletion criu/include/net.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef __CR_NET_H__
#define __CR_NET_H__

#include <linux/netlink.h>

#include "common/list.h"

struct cr_imgset;
Expand All @@ -23,7 +25,7 @@ extern void network_unlock(void);
extern struct ns_desc net_ns_desc;

#include "images/netdev.pb-c.h"
extern int write_netdev_img(NetDeviceEntry *nde, struct cr_imgset *fds);
extern int write_netdev_img(NetDeviceEntry *nde, struct cr_imgset *fds, struct nlattr **info);
extern int read_ns_sys_file(char *path, char *buf, int len);
extern int restore_link_parms(NetDeviceEntry *nde, int nlsk);

Expand Down
4 changes: 3 additions & 1 deletion criu/include/tun.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
#define TUN_MINOR 200
#endif

#include <linux/netlink.h>

#include "images/netdev.pb-c.h"

extern const struct fdtype_ops tunfile_dump_ops;
extern int dump_tun_link(NetDeviceEntry *nde, struct cr_imgset *fds);
extern int dump_tun_link(NetDeviceEntry *nde, struct cr_imgset *fds, struct nlattr **info);
extern int restore_one_tun(NetDeviceEntry *nde, int nlsk);
extern struct collect_image_info tunfile_cinfo;
extern int check_tun_cr(int no_tun_err);
Expand Down
20 changes: 15 additions & 5 deletions criu/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,14 @@ static int ipv4_conf_op_old(char *tgt, int *conf, int n, int op, int *def_conf)
return 0;
}

int write_netdev_img(NetDeviceEntry *nde, struct cr_imgset *fds)
int write_netdev_img(NetDeviceEntry *nde, struct cr_imgset *fds, struct nlattr **info)
{
return pb_write_one(img_from_set(fds, CR_FD_NETDEV), nde, PB_NETDEV);
}

static int dump_one_netdev(int type, struct ifinfomsg *ifi,
struct nlattr **tb, struct cr_imgset *fds,
int (*dump)(NetDeviceEntry *, struct cr_imgset *))
int (*dump)(NetDeviceEntry *, struct cr_imgset *, struct nlattr **info))
{
int ret = -1;
int i;
Expand All @@ -355,6 +355,7 @@ static int dump_one_netdev(int type, struct ifinfomsg *ifi,
SysctlEntry *confs6 = NULL;
int size6 = ARRAY_SIZE(devconfs6);
char stable_secret[MAX_STR_CONF_LEN + 1] = {};
struct nlattr *info[IFLA_INFO_MAX], **arg = NULL;

if (!tb[IFLA_IFNAME]) {
pr_err("No name for link %d\n", ifi->ifi_index);
Expand Down Expand Up @@ -422,7 +423,16 @@ static int dump_one_netdev(int type, struct ifinfomsg *ifi,
if (!dump)
dump = write_netdev_img;

ret = dump(&netdev, fds);
if (tb[IFLA_LINKINFO]) {
ret = nla_parse_nested(info, IFLA_INFO_MAX, tb[IFLA_LINKINFO], NULL);
if (ret < 0) {
pr_err("failed to parse nested linkinfo\n");
return -1;
}
arg = info;
}

ret = dump(&netdev, fds, arg);
err_free:
xfree(netdev.conf4);
xfree(confs4);
Expand Down Expand Up @@ -464,7 +474,7 @@ static int dump_unknown_device(struct ifinfomsg *ifi, char *kind,
return -1;
}

static int dump_bridge(NetDeviceEntry *nde, struct cr_imgset *imgset)
static int dump_bridge(NetDeviceEntry *nde, struct cr_imgset *imgset, struct nlattr **info)
{
char spath[IFNAMSIZ + 16]; /* len("class/net//brif") + 1 for null */
int ret, fd;
Expand Down Expand Up @@ -496,7 +506,7 @@ static int dump_bridge(NetDeviceEntry *nde, struct cr_imgset *imgset)
return -1;
}

return write_netdev_img(nde, imgset);
return write_netdev_img(nde, imgset, info);
}

static int dump_one_ethernet(struct ifinfomsg *ifi, char *kind,
Expand Down
4 changes: 2 additions & 2 deletions criu/tun.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ struct collect_image_info tunfile_cinfo = {
.collect = collect_one_tunfile,
};

int dump_tun_link(NetDeviceEntry *nde, struct cr_imgset *fds)
int dump_tun_link(NetDeviceEntry *nde, struct cr_imgset *fds, struct nlattr **info)
{
TunLinkEntry tle = TUN_LINK_ENTRY__INIT;
char spath[64];
Expand Down Expand Up @@ -430,7 +430,7 @@ int dump_tun_link(NetDeviceEntry *nde, struct cr_imgset *fds)
tle.sndbuf = tl->dmp.sndbuf;

nde->tun = &tle;
return write_netdev_img(nde, fds);
return write_netdev_img(nde, fds, info);
}

int restore_one_tun(NetDeviceEntry *nde, int nlsk)
Expand Down

0 comments on commit b705dcc

Please sign in to comment.