[lxc-devel] [lxc/master] network: simplify lxc_network_move_created_netdev_priv()

brauner on Github lxc-bot at linuxcontainers.org
Wed Jul 3 21:57:20 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 364 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190703/40346d53/attachment.bin>
-------------- next part --------------
From 24190194c109767a30e974826b58fb557a70bd1f Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 3 Jul 2019 23:55:57 +0200
Subject: [PATCH] network: simplify lxc_network_move_created_netdev_priv()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/network.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/src/lxc/network.c b/src/lxc/network.c
index ca74b1e62d..dcedc01507 100644
--- a/src/lxc/network.c
+++ b/src/lxc/network.c
@@ -217,6 +217,8 @@ static int instantiate_veth(struct lxc_handler *handler, struct lxc_netdev *netd
 		goto out_delete;
 	}
 
+	strlcpy(netdev->created_name, veth2, IFNAMSIZ);
+
 	/* changing the high byte of the mac address to 0xfe, the bridge interface
 	 * will always keep the host's mac address and not take the mac address
 	 * of a container */
@@ -3144,31 +3146,21 @@ int lxc_network_move_created_netdev_priv(struct lxc_handler *handler)
 
 	lxc_list_for_each(iterator, network) {
 		int ret;
-		char ifname[IFNAMSIZ];
 		struct lxc_netdev *netdev = iterator->elem;
 
 		if (!netdev->ifindex)
 			continue;
 
-		/* retrieve the name of the interface */
-		if (!if_indextoname(netdev->ifindex, ifname)) {
-			ERROR("No interface corresponding to ifindex \"%d\"",
-			      netdev->ifindex);
-			return -1;
-		}
-
-		ret = lxc_netdev_move_by_name(ifname, pid, NULL);
+		ret = lxc_netdev_move_by_index(netdev->ifindex, pid, NULL);
 		if (ret) {
 			errno = -ret;
-			SYSERROR("Failed to move network device \"%s\" to network namespace %d",
-				 ifname, pid);
+			SYSERROR("Failed to move network device \"%s\" with ifindex %d to network namespace %d",
+				 netdev->created_name, netdev->ifindex, pid);
 			return -1;
 		}
 
-		strlcpy(netdev->created_name, ifname, IFNAMSIZ);
-
-		DEBUG("Moved network device \"%s\" to network namespace of %d",
-		      netdev->created_name, pid);
+		DEBUG("Moved network device \"%s\" with ifindex %d to network namespace of %d",
+		      netdev->created_name, netdev->ifindex, pid);
 	}
 
 	return 0;


More information about the lxc-devel mailing list