]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
setup_netdev: re-read ifindex in LXC_NET_PHYS case
authorBogdan Purcareata <bogdan.purcareata@freescale.com>
Thu, 14 Nov 2013 10:58:06 +0000 (12:58 +0200)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Thu, 14 Nov 2013 15:25:09 +0000 (09:25 -0600)
When moving an interface from the host netns to a container's,
the ifindex might not remain the same. This happens when the
index of the host interface is already assigned to another interface
in the new netns.

For veth/vlan/macvlan, virtual interfaces are first created on the host,
and then moved in the container. Since they are created after all other
interfaces are discovered, there is no chance for its assigned ifindex
to be already present in a freshly created netns, because it's a greater
number.

However, when moving a physical interface, there is a chance that its
ifindex in the host netns is not free in the new netns. The patch
forces ifindex re-read for the LXC_NET_PHYS case to update the
lxc_netdev structure.

Signed-off-by: Bogdan Purcareata <bogdan.purcareata@freescale.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
src/lxc/conf.c

index a75673126f55ccf413436934ffb345fa42ada5b7..dec1c054d8d449cbe24fc84afca67df203bfcbba 100644 (file)
@@ -2144,6 +2144,14 @@ static int setup_netdev(struct lxc_netdev *netdev)
                return 0;
        }
 
+       /* get the new ifindex in case of physical netdev */
+       if (netdev->type == LXC_NET_PHYS)
+               if (!(netdev->ifindex = if_nametoindex(netdev->link))) {
+                       ERROR("failed to get ifindex for %s",
+                               netdev->link);
+                       return -1;
+               }
+
        /* retrieve the name of the interface */
        if (!if_indextoname(netdev->ifindex, current_ifname)) {
                ERROR("no interface corresponding to index '%d'",