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:
1
Makefile
1
Makefile
@@ -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
|
||||||
|
@@ -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
6
include/net.h
Normal 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
|
@@ -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__ */
|
||||||
|
15
namespaces.c
15
namespaces.c
@@ -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)
|
||||||
|
Reference in New Issue
Block a user