]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
network: handle name collisions when returning physical interfaces to host 3731/head
authorSam Boyles <sam.boyles@alliedtelesis.co.nz>
Fri, 26 Mar 2021 02:00:18 +0000 (15:00 +1300)
committerSam Boyles <sam.boyles@alliedtelesis.co.nz>
Fri, 26 Mar 2021 02:27:07 +0000 (15:27 +1300)
Reviewed-by: Blair Steven <blair.steven@alliedtelesis.co.nz>
Signed-off-by: Sam Boyles <sam.boyles@alliedtelesis.co.nz>
src/lxc/network.c
src/lxc/network.h

index ed4b8ff331ac7ae339adb9cd86a92f253bdf3d55..52d8e91336c6b18e1ed9f189a9e4bb6775f637ea 100644 (file)
@@ -3612,6 +3612,10 @@ static bool lxc_delete_network_priv(struct lxc_handler *handler)
                }
 
                if (netdev->type == LXC_NET_PHYS) {
+                       /* Physical interfaces are initially returned to the parent namespace
+                        * with their transient name to avoid collisions
+                        */
+                       netdev->ifindex = if_nametoindex(netdev->transient_name);
                        ret = lxc_netdev_rename_by_index(netdev->ifindex, netdev->link);
                        if (ret < 0)
                                WARN("Failed to rename interface with index %d "
@@ -3684,6 +3688,12 @@ clear_ifindices:
                        netdev->priv.veth_attr.veth1[0] = '\0';
                        netdev->priv.veth_attr.ifindex = 0;
                }
+
+               /* Clear transient name */
+               if (!is_empty_string (netdev->transient_name))
+               {
+                       netdev->transient_name[0] = '\0';
+               }
        }
 
        return true;
@@ -3761,7 +3771,10 @@ int lxc_restore_phys_nics_to_netns(struct lxc_handler *handler)
                        continue;
                }
 
-               ret = lxc_netdev_move_by_index_fd(netdev->ifindex, oldfd, netdev->link);
+               /* Restore physical interfaces to host's network namespace with its transient name
+                * to avoid collisions with the host's other interfaces.
+                */
+               ret = lxc_netdev_move_by_index_fd(netdev->ifindex, oldfd, netdev->transient_name);
                if (ret < 0)
                        WARN("Error moving network device \"%s\" back to network namespace", ifname);
                else
index 88523586eb7de99a8fbf728b864df15ec8936670..3526f106fa4b610ae489b35ba6b2bfa3d3a63618 100644 (file)
@@ -136,6 +136,7 @@ union netdev_p {
  * @created_name      : the name with which this interface got created before
  *                     being renamed to final_name.
  *                     Currenly only used for veth devices.
+ * @transient_name    : temporary name to avoid namespace collisions
  * @hwaddr            : mac address
  * @mtu               : maximum transmission unit
  * @priv              : information specific to the specificed network type