]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxccontainer: only attach netns on netdev detach
authorChristian Brauner <christian.brauner@ubuntu.com>
Sun, 10 Dec 2017 01:41:14 +0000 (02:41 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 15 Dec 2017 12:35:09 +0000 (13:35 +0100)
Detaching network namespaces as an unprivileged user is currently not possible
and attaching to the user namespace will mean we are not allowed to move the
network device into an ancestor network namespace.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/lxccontainer.c

index f8b0f67d361b1c3251d34f6187b2bc9262d88a1e..b0fcec53a6ba1b0847e53363befbb231d979fcd1 100644 (file)
@@ -4320,10 +4320,12 @@ static bool do_lxcapi_detach_interface(struct lxc_container *c, const char *ifna
        }
 
        if (pid == 0) { /* child */
-               int ret = 0;
-               if (!enter_net_ns(c)) {
-                       ERROR("failed to enter namespace");
-                       exit(-1);
+               pid_t init_pid;
+
+               init_pid = do_lxcapi_init_pid(c);
+               if (!switch_to_ns(init_pid, "net")) {
+                       ERROR("Failed to enter network namespace");
+                       exit(EXIT_FAILURE);
                }
 
                ret = lxc_netdev_isup(ifname);