2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-09-02 07:15:31 +00:00

net: add ability to set names for outside links of veth devices

When restoring a container crtools create veth pair inside it and then
pushed one end to the namespaces crtools live in (outside). To facilitate
the subsequent management of the otter end of the veth pair this option
is added -- one can specifu a name by which the respective end would be
visible. E.g.: --veth-pair eth0=veth101.0

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
Andrey Vagin
2012-09-02 01:07:32 +04:00
committed by Pavel Emelyanov
parent bf94ff3a26
commit ae70bc0ad6
4 changed files with 41 additions and 2 deletions

View File

@@ -20,6 +20,7 @@
#include "syscall.h" #include "syscall.h"
#include "files.h" #include "files.h"
#include "sk-inet.h" #include "sk-inet.h"
#include "net.h"
struct cr_options opts; struct cr_options opts;
@@ -70,6 +71,7 @@ int main(int argc, char *argv[])
/* Default options */ /* Default options */
opts.final_state = TASK_DEAD; opts.final_state = TASK_DEAD;
INIT_LIST_HEAD(&opts.veth_pairs);
while (1) { while (1) {
static struct option long_opts[] = { static struct option long_opts[] = {
@@ -90,6 +92,7 @@ int main(int argc, char *argv[])
{ "version", no_argument, 0, 'V'}, { "version", no_argument, 0, 'V'},
{ "evasive-devices", no_argument, 0, 45}, { "evasive-devices", no_argument, 0, 45},
{ "pidfile", required_argument, 0, 46}, { "pidfile", required_argument, 0, 46},
{ "veth-pair", required_argument, 0, 47},
{ }, { },
}; };
@@ -173,6 +176,25 @@ int main(int argc, char *argv[])
case 46: case 46:
opts.pidfile = optarg; opts.pidfile = optarg;
break; break;
case 47:
{
struct veth_pair *n;
n = xmalloc(sizeof(*n));
if (n == NULL)
return -1;
n->outside = strchr(optarg, '=');
if (n->outside == NULL) {
xfree(n);
pr_err("Invalid agument for --veth-pair\n");
goto usage;
}
*n->outside++ = '\0';
n->inside = optarg;
list_add(&n->node, &opts.veth_pairs);
}
break;
case 'V': case 'V':
pr_msg("Version: %d.%d\n", CRIU_VERSION_MAJOR, CRIU_VERSION_MINOR); pr_msg("Version: %d.%d\n", CRIU_VERSION_MAJOR, CRIU_VERSION_MINOR);
return 0; return 0;
@@ -262,6 +284,7 @@ usage:
pr_msg(" --%s checkpoint/restore established TCP connections\n", SK_EST_PARAM); pr_msg(" --%s checkpoint/restore established TCP connections\n", SK_EST_PARAM);
pr_msg(" -r|--root [PATH] change the root filesystem (when run in mount namespace)\n"); pr_msg(" -r|--root [PATH] change the root filesystem (when run in mount namespace)\n");
pr_msg(" --evasive-devices use any path to a device file if the original one is inaccessible\n"); pr_msg(" --evasive-devices use any path to a device file if the original one is inaccessible\n");
pr_msg(" --veth-pair [IN=OUT] correspondence between outside and inside names of veth devices\n");
pr_msg("\n* Logging:\n"); pr_msg("\n* Logging:\n");
pr_msg(" -o|--log-file [NAME] log file name (relative path is relative to --images-dir)\n"); pr_msg(" -o|--log-file [NAME] log file name (relative path is relative to --images-dir)\n");

View File

@@ -93,6 +93,7 @@ struct cr_options {
char *output; char *output;
char *root; char *root;
char *pidfile; char *pidfile;
struct list_head veth_pairs;
}; };
extern struct cr_options opts; extern struct cr_options opts;

View File

@@ -1,5 +1,8 @@
#ifndef __CR_NET_H__ #ifndef __CR_NET_H__
#define __CR_NET_H__ #define __CR_NET_H__
#include "list.h"
struct cr_options; struct cr_options;
void show_netdevices(int fd, struct cr_options *); void show_netdevices(int fd, struct cr_options *);
@@ -7,4 +10,10 @@ struct cr_fdset;
int dump_net_ns(int pid, struct cr_fdset *); int dump_net_ns(int pid, struct cr_fdset *);
int prepare_net_ns(int pid); int prepare_net_ns(int pid);
int netns_pre_create(void); int netns_pre_create(void);
struct veth_pair {
struct list_head node;
char *inside;
char *outside;
};
#endif #endif

10
net.c
View File

@@ -10,6 +10,7 @@
#include "namespaces.h" #include "namespaces.h"
#include "net.h" #include "net.h"
#include "libnetlink.h" #include "libnetlink.h"
#include "crtools.h"
#include "protobuf.h" #include "protobuf.h"
#include "protobuf/netdev.pb-c.h" #include "protobuf/netdev.pb-c.h"
@@ -203,7 +204,7 @@ static int veth_link_info(NetDeviceEntry *nde, struct newlink_req *req)
{ {
struct rtattr *veth_data, *peer_data; struct rtattr *veth_data, *peer_data;
struct ifinfomsg ifm; struct ifinfomsg ifm;
char veth_host_name[] = "veth_host"; struct veth_pair *n;
BUG_ON(ns_fd < 0); BUG_ON(ns_fd < 0);
@@ -214,7 +215,12 @@ static int veth_link_info(NetDeviceEntry *nde, struct newlink_req *req)
peer_data = NLMSG_TAIL(&req->h); peer_data = NLMSG_TAIL(&req->h);
memset(&ifm, 0, sizeof(ifm)); memset(&ifm, 0, sizeof(ifm));
addattr_l(&req->h, sizeof(*req), VETH_INFO_PEER, &ifm, sizeof(ifm)); addattr_l(&req->h, sizeof(*req), VETH_INFO_PEER, &ifm, sizeof(ifm));
addattr_l(&req->h, sizeof(*req), IFLA_IFNAME, veth_host_name, sizeof(veth_host_name)); list_for_each_entry(n, &opts.veth_pairs, node) {
if (!strcmp(nde->name, n->inside))
break;
}
if (&n->node != &opts.veth_pairs)
addattr_l(&req->h, sizeof(*req), IFLA_IFNAME, n->outside, strlen(n->outside));
addattr_l(&req->h, sizeof(*req), IFLA_NET_NS_FD, &ns_fd, sizeof(ns_fd)); addattr_l(&req->h, sizeof(*req), IFLA_NET_NS_FD, &ns_fd, sizeof(ns_fd));
peer_data->rta_len = (void *)NLMSG_TAIL(&req->h) - (void *)peer_data; peer_data->rta_len = (void *)NLMSG_TAIL(&req->h) - (void *)peer_data;
veth_data->rta_len = (void *)NLMSG_TAIL(&req->h) - (void *)veth_data; veth_data->rta_len = (void *)NLMSG_TAIL(&req->h) - (void *)veth_data;