2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-31 22:35:33 +00:00

net: Basic netns dump/restore skeleton

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
Pavel Emelyanov
2012-08-02 08:06:29 +04:00
parent 2d56d1b056
commit 0a827aa96c
6 changed files with 46 additions and 0 deletions

View File

@@ -27,6 +27,7 @@ OBJS += parasite-syscall.o
OBJS += cr-restore.o OBJS += cr-restore.o
OBJS += crtools.o OBJS += crtools.o
OBJS += image.o OBJS += image.o
OBJS += net.o
OBJS += proc_parse.o OBJS += proc_parse.o
OBJS += cr-dump.o OBJS += cr-dump.o
OBJS += cr-show.o OBJS += cr-show.o

View File

@@ -38,6 +38,8 @@ static int parse_ns_string(const char *ptr)
opts.namespaces_flags |= CLONE_NEWNS; opts.namespaces_flags |= CLONE_NEWNS;
else if (!strncmp(ptr, "pid", 3)) else if (!strncmp(ptr, "pid", 3))
opts.namespaces_flags |= CLONE_NEWPID; opts.namespaces_flags |= CLONE_NEWPID;
else if (!strncmp(ptr, "net", 3))
opts.namespaces_flags |= CLONE_NEWNET;
else else
goto bad_ns; goto bad_ns;
ptr += 4; ptr += 4;

6
include/net.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef __CR_NET_H__
#define __CR_NET_H__
struct cr_fdset;
int dump_net_ns(int pid, struct cr_fdset *);
int prepare_net_ns(int pid);
#endif

View File

@@ -53,6 +53,10 @@ struct file_handle;
#define CLONE_NEWIPC 0x08000000 #define CLONE_NEWIPC 0x08000000
#endif #endif
#ifndef CLONE_NEWNET
#define CLONE_NEWNET 0x40000000
#endif
#define setns sys_setns #define setns sys_setns
#endif /* SYSCALL_TYPES_H__ */ #endif /* SYSCALL_TYPES_H__ */

View File

@@ -8,6 +8,7 @@
#include "ipc_ns.h" #include "ipc_ns.h"
#include "mount.h" #include "mount.h"
#include "namespaces.h" #include "namespaces.h"
#include "net.h"
int switch_ns(int pid, int type, char *ns, int *rst) int switch_ns(int pid, int type, char *ns, int *rst)
{ {
@@ -87,6 +88,12 @@ static int do_dump_namespaces(struct pid *ns_pid, unsigned int ns_flags)
if (ret < 0) if (ret < 0)
goto err; goto err;
} }
if (ns_flags & CLONE_NEWNET) {
pr_info("Dump NET namespace info\n");
ret = dump_net_ns(ns_pid->real, fdset);
if (ret < 0)
goto err;
}
err: err:
close_cr_fdset(&fdset); close_cr_fdset(&fdset);
return ret; return ret;
@@ -149,6 +156,14 @@ int prepare_namespace(int pid, unsigned long clone_flags)
pr_info("Restoring namespaces %d flags 0x%lx\n", pr_info("Restoring namespaces %d flags 0x%lx\n",
pid, clone_flags); pid, clone_flags);
/*
* On netns restore we launch an IP tool, thus we
* have to restore it _before_ altering the mount
* tree (i.e. -- mnt_ns restoring)
*/
if (clone_flags & CLONE_NEWNET)
ret = prepare_net_ns(pid);
if (clone_flags & CLONE_NEWUTS) if (clone_flags & CLONE_NEWUTS)
ret = prepare_utsns(pid); ret = prepare_utsns(pid);
if (clone_flags & CLONE_NEWIPC) if (clone_flags & CLONE_NEWIPC)

18
net.c Normal file
View File

@@ -0,0 +1,18 @@
#include <unistd.h>
#include "syscall-types.h"
#include "namespaces.h"
#include "net.h"
int dump_net_ns(int pid, struct cr_fdset *fds)
{
int ret;
ret = switch_ns(pid, CLONE_NEWNET, "net", NULL);
return ret;
}
int prepare_net_ns(int pid)
{
return -1;
}