mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-07-25 19:14:04 +00:00
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: Andrei Vagin <avagin@virtuozzo.com>
This commit is contained in:
parent
7e355e7b12
commit
c90c7bd5e6
4 changed files with 12 additions and 4 deletions
|
|
@ -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,7 +762,14 @@ int set_netns(uint32_t ns_id)
|
|||
if (ns_id == last_ns_id)
|
||||
return 0;
|
||||
|
||||
ns = lookup_ns_by_id(ns_id, &net_ns_desc);
|
||||
/*
|
||||
* 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");
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue