mirror of
https://github.com/checkpoint-restore/criu
synced 2025-09-01 14:55:39 +00:00
check: add a feature test for netns id manipulation
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>
This commit is contained in:
committed by
Pavel Emelyanov
parent
0d2f3a409f
commit
612fb65ff7
@@ -1,5 +1,6 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <linux/netlink.h>
|
#include <linux/netlink.h>
|
||||||
|
#include <linux/rtnetlink.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/eventfd.h>
|
#include <sys/eventfd.h>
|
||||||
@@ -43,6 +44,8 @@
|
|||||||
#include "namespaces.h"
|
#include "namespaces.h"
|
||||||
#include "pstree.h"
|
#include "pstree.h"
|
||||||
#include "cr_options.h"
|
#include "cr_options.h"
|
||||||
|
#include "libnetlink.h"
|
||||||
|
#include "net.h"
|
||||||
|
|
||||||
static char *feature_name(int (*func)());
|
static char *feature_name(int (*func)());
|
||||||
|
|
||||||
@@ -935,6 +938,58 @@ static int check_tcp_window(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int nsid_manip_cb(struct nlmsghdr *hdr, void *arg)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int check_nsid_manip(void)
|
||||||
|
{
|
||||||
|
int parent = -1, ret = -1, nlsk = -1;
|
||||||
|
struct {
|
||||||
|
struct nlmsghdr n;
|
||||||
|
struct rtgenmsg g;
|
||||||
|
char buf[1024];
|
||||||
|
} req;
|
||||||
|
|
||||||
|
parent = open("/proc/self/ns/net", O_RDONLY);
|
||||||
|
if (parent < 0) {
|
||||||
|
pr_perror("open");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unshare(CLONE_NEWNET) < 0) {
|
||||||
|
pr_perror("unshare");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
nlsk = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
|
||||||
|
if (nlsk < 0) {
|
||||||
|
pr_perror("socket");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(&req, 0, sizeof(req));
|
||||||
|
|
||||||
|
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.g));
|
||||||
|
req.n.nlmsg_flags = NLM_F_REQUEST|NLM_F_ACK;
|
||||||
|
req.n.nlmsg_type = RTM_GETNSID;
|
||||||
|
req.n.nlmsg_seq = CR_NLMSG_SEQ;
|
||||||
|
|
||||||
|
addattr_l(&req.n, sizeof(req), NETNSA_FD, &parent, sizeof(parent));
|
||||||
|
ret = do_rtnl_req(nlsk, &req, req.n.nlmsg_len, nsid_manip_cb, NULL, NULL);
|
||||||
|
if (ret < 0)
|
||||||
|
pr_err("can't manipulate netns ids\n");
|
||||||
|
out:
|
||||||
|
if (nlsk > 0)
|
||||||
|
close(nlsk);
|
||||||
|
if (setns(parent, CLONE_NEWNET) < 0)
|
||||||
|
pr_warn("couldn't setns back to parent");
|
||||||
|
if (parent > 0)
|
||||||
|
close(parent);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static int (*chk_feature)(void);
|
static int (*chk_feature)(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1035,6 +1090,7 @@ int cr_check(void)
|
|||||||
ret |= check_clone_parent_vs_pid();
|
ret |= check_clone_parent_vs_pid();
|
||||||
ret |= check_cgroupns();
|
ret |= check_cgroupns();
|
||||||
ret |= check_tcp_window();
|
ret |= check_tcp_window();
|
||||||
|
ret |= check_nsid_manip();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1114,6 +1170,7 @@ static struct feature_list feature_list[] = {
|
|||||||
{ "loginuid", check_loginuid },
|
{ "loginuid", check_loginuid },
|
||||||
{ "cgroupns", check_cgroupns },
|
{ "cgroupns", check_cgroupns },
|
||||||
{ "autofs", check_autofs },
|
{ "autofs", check_autofs },
|
||||||
|
{ "nsid_manip", check_nsid_manip },
|
||||||
{ NULL, NULL },
|
{ NULL, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -6,6 +6,17 @@
|
|||||||
#include "common/list.h"
|
#include "common/list.h"
|
||||||
#include "external.h"
|
#include "external.h"
|
||||||
|
|
||||||
|
#ifdef CONFIG_HAS_NET_NAMESPACE_H
|
||||||
|
#include <linux/net_namespace.h>
|
||||||
|
#else
|
||||||
|
#define NETNSA_NSID 1
|
||||||
|
#define NETNSA_FD 3
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef RTM_GETNSID
|
||||||
|
#define RTM_GETNSID 90
|
||||||
|
#endif
|
||||||
|
|
||||||
struct cr_imgset;
|
struct cr_imgset;
|
||||||
extern int dump_net_ns(int ns_id);
|
extern int dump_net_ns(int ns_id);
|
||||||
extern int prepare_net_ns(int pid);
|
extern int prepare_net_ns(int pid);
|
||||||
|
11
criu/net.c
11
criu/net.c
@@ -36,13 +36,6 @@
|
|||||||
#include "protobuf.h"
|
#include "protobuf.h"
|
||||||
#include "images/netdev.pb-c.h"
|
#include "images/netdev.pb-c.h"
|
||||||
|
|
||||||
#ifdef CONFIG_HAS_NET_NAMESPACE_H
|
|
||||||
#include <linux/net_namespace.h>
|
|
||||||
#else
|
|
||||||
#define NETNSA_NSID 1
|
|
||||||
#define NETNSA_FD 3
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef IFLA_LINK_NETNSID
|
#ifndef IFLA_LINK_NETNSID
|
||||||
#define IFLA_LINK_NETNSID 37
|
#define IFLA_LINK_NETNSID 37
|
||||||
#endif
|
#endif
|
||||||
@@ -51,10 +44,6 @@
|
|||||||
#define RTM_NEWNSID 88
|
#define RTM_NEWNSID 88
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef RTM_GETNSID
|
|
||||||
#define RTM_GETNSID 90
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef IFLA_MACVLAN_FLAGS
|
#ifndef IFLA_MACVLAN_FLAGS
|
||||||
#define IFLA_MACVLAN_FLAGS 2
|
#define IFLA_MACVLAN_FLAGS 2
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user