Commit 0a827aa9 authored by Pavel Emelyanov's avatar Pavel Emelyanov

net: Basic netns dump/restore skeleton

Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 2d56d1b0
...@@ -27,6 +27,7 @@ OBJS += parasite-syscall.o ...@@ -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) ...@@ -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;
......
#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; ...@@ -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__ */
...@@ -8,6 +8,7 @@ ...@@ -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) ...@@ -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) ...@@ -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)
......
#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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment