diff --git a/criu/tun.c b/criu/tun.c index a6cd372d3..742816afc 100644 --- a/criu/tun.c +++ b/criu/tun.c @@ -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;; diff --git a/images/tun.proto b/images/tun.proto index 796e1f5d9..b70c9ed67 100644 --- a/images/tun.proto +++ b/images/tun.proto @@ -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 {