Commit c90c7bd5 authored by Andrei Vagin's avatar Andrei Vagin

net: set_netns should set a root net ns if ns_id is zero

We need this to save backward compatibility with old images.
It is zero only if it is absent in an image file.
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 7e355e7b
......@@ -47,6 +47,7 @@ extern int move_veth_to_bridge(void);
extern int kerndat_link_nsid(void);
extern int net_get_nsid(int rtsk, int fd, int *nsid);
extern struct ns_id *net_get_root_ns();
extern int kerndat_nsid(void);
extern void check_has_netns_ioc(int fd, bool *kdat_val, const char *name);
......
......@@ -2664,7 +2664,7 @@ int collect_net_namespaces(bool for_dump)
struct ns_desc net_ns_desc = NS_DESC_ENTRY(CLONE_NEWNET, "net");
static struct ns_id *get_root_netns()
struct ns_id *net_get_root_ns()
{
static struct ns_id *root_netns = NULL;
......@@ -2693,7 +2693,7 @@ struct ns_id *get_socket_ns(int lfd)
if (ns_fd < 0) {
/* backward compatiblity with old kernels */
if (netns_nr == 1)
return get_root_netns();
return net_get_root_ns();
pr_perror("Unable to get a socket net namespace");
return NULL;
......
......@@ -762,6 +762,13 @@ int set_netns(uint32_t ns_id)
if (ns_id == last_ns_id)
return 0;
/*
* The 0 ns_id means that it was not set. We need
* this to be compatible with old images.
*/
if (ns_id == 0)
ns = net_get_root_ns();
else
ns = lookup_ns_by_id(ns_id, &net_ns_desc);
if (ns == NULL) {
pr_err("Unable to find a network namespace\n");
......
......@@ -369,7 +369,7 @@ 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;
ns_id = ti->tfe->ns_id;
if (set_netns(ns_id))
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