diff --git a/Makefile b/Makefile index 3cb51a045..0ac83ead7 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,7 @@ OBJS += parasite-syscall.o OBJS += cr-restore.o OBJS += crtools.o OBJS += image.o +OBJS += net.o OBJS += proc_parse.o OBJS += cr-dump.o OBJS += cr-show.o diff --git a/crtools.c b/crtools.c index 23ec4550b..7a9f9281e 100644 --- a/crtools.c +++ b/crtools.c @@ -38,6 +38,8 @@ static int parse_ns_string(const char *ptr) opts.namespaces_flags |= CLONE_NEWNS; else if (!strncmp(ptr, "pid", 3)) opts.namespaces_flags |= CLONE_NEWPID; + else if (!strncmp(ptr, "net", 3)) + opts.namespaces_flags |= CLONE_NEWNET; else goto bad_ns; ptr += 4; diff --git a/include/net.h b/include/net.h new file mode 100644 index 000000000..2f271030f --- /dev/null +++ b/include/net.h @@ -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 diff --git a/include/syscall-types.h b/include/syscall-types.h index a4f0a008d..1501e3bac 100644 --- a/include/syscall-types.h +++ b/include/syscall-types.h @@ -53,6 +53,10 @@ struct file_handle; #define CLONE_NEWIPC 0x08000000 #endif +#ifndef CLONE_NEWNET +#define CLONE_NEWNET 0x40000000 +#endif + #define setns sys_setns #endif /* SYSCALL_TYPES_H__ */ diff --git a/namespaces.c b/namespaces.c index ee6c59a10..fe2ebabe5 100644 --- a/namespaces.c +++ b/namespaces.c @@ -8,6 +8,7 @@ #include "ipc_ns.h" #include "mount.h" #include "namespaces.h" +#include "net.h" 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) 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: close_cr_fdset(&fdset); return ret; @@ -149,6 +156,14 @@ int prepare_namespace(int pid, unsigned long clone_flags) pr_info("Restoring namespaces %d flags 0x%lx\n", 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) ret = prepare_utsns(pid); if (clone_flags & CLONE_NEWIPC) diff --git a/net.c b/net.c new file mode 100644 index 000000000..7c2325ea5 --- /dev/null +++ b/net.c @@ -0,0 +1,18 @@ +#include +#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; +}