Commit cd7dac19 authored by Andrew Vagin's avatar Andrew Vagin Committed by Andrei Vagin

net: Dump tun device net id in img

This adds new tunfile_entry::ns_id field and populates
it in standard socket way. Restore uses this ns_id
to choose correct namespace. Note, we could completelly
skip set_netns() on restore in case of !has_ns_id, but
using top_net_ns invents some definite behaviour.
Signed-off-by: 's avatarAndrew Vagin <avagin@virtuozzo.com>
ktkhai: comment written/code movings
Signed-off-by: 's avatarKirill Tkhai <ktkhai@virtuozzo.com>
parent 62d77801
......@@ -20,6 +20,7 @@
#include "namespaces.h"
#include "xmalloc.h"
#include "kerndat.h"
#include "sockets.h"
#include "images/tun.pb-c.h"
......@@ -304,6 +305,8 @@ static int dump_tunfile(int lfd, u32 id, const struct fd_parms *p)
pr_err("No net_ns for tun device\n");
return -1;
}
tfe.has_ns_id = true;
tfe.ns_id = ns->id;
}
if (dump_one_reg_file(lfd, id, p))
......@@ -356,7 +359,7 @@ struct tunfile_info {
static int tunfile_open(struct file_desc *d, int *new_fd)
{
int fd;
int fd, ns_id;
struct tunfile_info *ti;
struct ifreq ifr;
struct tun_link *tl;
......@@ -366,6 +369,10 @@ static int tunfile_open(struct file_desc *d, int *new_fd)
if (fd < 0)
return -1;
ns_id = ti->tfe->has_ns_id ? ti->tfe->ns_id : top_net_ns->id;
if (set_netns(ns_id))
return -1;
if (!ti->tfe->netdev)
/* just-opened tun file */
goto ok;;
......
......@@ -6,6 +6,7 @@ message tunfile_entry {
required uint32 id = 1;
optional string netdev = 2;
optional bool detached = 3;
optional uint32 ns_id = 4;
};
message tun_link_entry {
......
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