]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
network: retrieve the host's veth device ifindex
authorChristian Brauner <christian.brauner@ubuntu.com>
Thu, 31 Aug 2017 20:58:30 +0000 (22:58 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 4 Sep 2017 11:19:16 +0000 (13:19 +0200)
- Retrieve the host's veth device ifindex in the host's network namespace.
- Add a note why we retrieve the container's veth device ifindex in the host's
  network namespace.

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

index 8d565ed531dc9865a482366e45b2e76d8cab9796..6a3c36dcc80285a2a8dfc06a11516fc687dcc403 100644 (file)
@@ -140,6 +140,18 @@ static int instantiate_veth(struct lxc_handler *handler, struct lxc_netdev *netd
                goto out_delete;
        }
 
+       /* Retrieve ifindex of the host's veth device. */
+       netdev->priv.veth_attr.ifindex = if_nametoindex(veth1);
+       if (!netdev->priv.veth_attr.ifindex) {
+               ERROR("Failed to retrieve ifindex for \"%s\"", veth1);
+               goto out_delete;
+       }
+
+       /* Note that we're retrieving the container's ifindex in the host's
+        * network namespace because we need it to move the device from the
+        * host's network namespace to the container's network namespace later
+        * on.
+        */
        netdev->ifindex = if_nametoindex(veth2);
        if (!netdev->ifindex) {
                ERROR("Failed to retrieve ifindex for \"%s\"", veth2);