interface: fix jail ifdown and jails without jail_ifname
authorDaniel Golle <daniel@makrotopia.org>
Mon, 13 Apr 2020 23:36:29 +0000 (00:36 +0100)
committerDaniel Golle <daniel@makrotopia.org>
Mon, 13 Apr 2020 23:42:10 +0000 (00:42 +0100)
Fixes: d93126d ("interface: allow renaming interface when moving to jail netns")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
interface.c

index 2c883d80dd538b9bb2e67af985f70d0224673652..24d90aa39613e741c9b81ac451bef3f4aeb2d6c0 100644 (file)
@@ -1200,7 +1200,9 @@ interface_start_jail(const char *jail, const pid_t netns_pid)
                 * We are inside a fork which got it's own copy of the interfaces
                 * list, so we can mess with it :)
                 */
-               iface->ifname = iface->jail_ifname;
+               if (iface->jail_ifname)
+                       iface->ifname = iface->jail_ifname;
+
                interface_do_reload(iface);
                interface_set_up(iface);
        }
@@ -1217,6 +1219,7 @@ interface_stop_jail(const char *jail, const pid_t netns_pid)
        int wstatus;
        pid_t parent_pid = getpid();
        pid_t pr = 0;
+       const char *orig_ifname;
 
        pr = fork();
        if (pr) {
@@ -1239,8 +1242,13 @@ interface_stop_jail(const char *jail, const pid_t netns_pid)
                if (!iface->jail || strcmp(iface->jail, jail))
                        continue;
 
+               orig_ifname = iface->ifname;
+               if (iface->jail_ifname)
+                       iface->ifname = iface->jail_ifname;
+
+               interface_do_reload(iface);
                interface_set_down(iface);
-               system_link_netns_move(iface->jail_ifname, root_netns, iface->ifname);
+               system_link_netns_move(iface->ifname, root_netns, orig_ifname);
        }
 
        close(root_netns);