From: Christian Brauner Date: Thu, 31 Aug 2017 20:58:30 +0000 (+0200) Subject: network: retrieve the host's veth device ifindex X-Git-Tag: lxc-2.0.9~48^2~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=59574a77e34c5646cc0fe74f4996a3e11a3d1f94;p=thirdparty%2Flxc.git network: retrieve the host's veth device ifindex - 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 --- diff --git a/src/lxc/network.c b/src/lxc/network.c index 8d565ed53..6a3c36dcc 100644 --- a/src/lxc/network.c +++ b/src/lxc/network.c @@ -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);