Commit aff66b4e authored by Tycho Andersen's avatar Tycho Andersen Committed by Pavel Emelyanov

net: open a netlink socket in criu's netns

We'll use this socket to restore macvlan interfaces.

travis-ci: success for series starting with [v10,01/11] net: pass the struct nlattrs to dump() functions
Signed-off-by: 's avatarTycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent 0a9f9e95
...@@ -1027,7 +1027,7 @@ static int changeflags(int s, char *name, short flags) ...@@ -1027,7 +1027,7 @@ static int changeflags(int s, char *name, short flags)
return 0; return 0;
} }
static int restore_link(NetDeviceEntry *nde, int nlsk) static int restore_link(NetDeviceEntry *nde, int nlsk, int criu_nlsk)
{ {
pr_info("Restoring link %s type %d\n", nde->name, nde->type); pr_info("Restoring link %s type %d\n", nde->name, nde->type);
...@@ -1053,7 +1053,7 @@ static int restore_link(NetDeviceEntry *nde, int nlsk) ...@@ -1053,7 +1053,7 @@ static int restore_link(NetDeviceEntry *nde, int nlsk)
static int restore_links(int pid, NetnsEntry **netns) static int restore_links(int pid, NetnsEntry **netns)
{ {
int nlsk, ret; int nlsk, criu_nlsk = -1, ret = -1, my_netns = -1, ns_fd = get_service_fd(NS_FD_OFF);
struct cr_img *img; struct cr_img *img;
NetDeviceEntry *nde; NetDeviceEntry *nde;
...@@ -1068,6 +1068,38 @@ static int restore_links(int pid, NetnsEntry **netns) ...@@ -1068,6 +1068,38 @@ static int restore_links(int pid, NetnsEntry **netns)
return -1; return -1;
} }
if (!(root_ns_mask & CLONE_NEWUSER)) {
/* FIXME: this whole dance is so we can have a netlink socket to criu's
* netns in case we need it. It should really live on the ns_id struct,
* but those aren't generated on restore yet.
*/
my_netns = open_proc(PROC_SELF, "ns/net");
if (my_netns < 0) {
pr_perror("couldn't open my netns");
goto out;
}
if (setns(ns_fd, CLONE_NEWNET) < 0) {
close(my_netns);
pr_perror("couldn't setns to parent ns");
goto out;
}
criu_nlsk = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
ret = setns(my_netns, CLONE_NEWNET);
close(my_netns);
if (ret < 0) {
pr_perror("Can't setns back my netns");
goto out;
}
if (criu_nlsk < 0) {
pr_perror("Can't create nlk socket");
goto out;
}
}
while (1) { while (1) {
NetnsEntry **def_netns = netns; NetnsEntry **def_netns = netns;
...@@ -1075,7 +1107,7 @@ static int restore_links(int pid, NetnsEntry **netns) ...@@ -1075,7 +1107,7 @@ static int restore_links(int pid, NetnsEntry **netns)
if (ret <= 0) if (ret <= 0)
break; break;
ret = restore_link(nde, nlsk); ret = restore_link(nde, nlsk, criu_nlsk);
if (ret) { if (ret) {
pr_err("Can't restore link\n"); pr_err("Can't restore link\n");
goto exit; goto exit;
...@@ -1104,6 +1136,9 @@ exit: ...@@ -1104,6 +1136,9 @@ exit:
break; break;
} }
out:
if (criu_nlsk >= 0)
close(criu_nlsk);
close(nlsk); close(nlsk);
close_image(img); close_image(img);
return ret; return ret;
......
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