[lxc-devel] [lxc/master] network: restore old behavior
brauner on Github
lxc-bot at linuxcontainers.org
Fri May 15 19:18:16 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 724 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200515/328a2caa/attachment.bin>
-------------- next part --------------
From 717f77f2f32f7331606f2709dbca74e0d680b5ef Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Fri, 15 May 2020 21:14:15 +0200
Subject: [PATCH] network: restore old behavior
I introduced a regression: when users didn't specify a specific name via
lxc.net.<idx>.name then the device would retain the random name it received
when we created it. Before we would use the "eth%d" syntax to get the kernel to
assign a fixed name. Restore that behavior.
Closes: #3407.
Fixes: 8bf64b77ac8a ("network: rework network device creation")
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/network.c | 25 ++++++++++---------------
1 file changed, 10 insertions(+), 15 deletions(-)
diff --git a/src/lxc/network.c b/src/lxc/network.c
index eaab9eccfe..ef6707ff4c 100644
--- a/src/lxc/network.c
+++ b/src/lxc/network.c
@@ -482,10 +482,6 @@ static int instantiate_macvlan(struct lxc_handler *handler, struct lxc_netdev *n
goto on_error;
}
- strlcpy(netdev->created_name, peer, IFNAMSIZ);
- if (is_empty_string(netdev->name))
- (void)strlcpy(netdev->name, peer, IFNAMSIZ);
-
netdev->ifindex = if_nametoindex(peer);
if (!netdev->ifindex) {
ERROR("Failed to retrieve ifindex for \"%s\"", peer);
@@ -634,8 +630,6 @@ static int instantiate_ipvlan(struct lxc_handler *handler, struct lxc_netdev *ne
}
strlcpy(netdev->created_name, peer, IFNAMSIZ);
- if (is_empty_string(netdev->name))
- (void)strlcpy(netdev->name, peer, IFNAMSIZ);
netdev->ifindex = if_nametoindex(peer);
if (!netdev->ifindex) {
@@ -709,8 +703,6 @@ static int instantiate_vlan(struct lxc_handler *handler, struct lxc_netdev *netd
}
strlcpy(netdev->created_name, peer, IFNAMSIZ);
- if (is_empty_string(netdev->name))
- (void)strlcpy(netdev->name, peer, IFNAMSIZ);
netdev->ifindex = if_nametoindex(peer);
if (!netdev->ifindex) {
@@ -866,7 +858,7 @@ static instantiate_cb netdev_conf[LXC_NET_MAXCONFTYPE + 1] = {
[LXC_NET_NONE] = instantiate_none,
};
-static int instantiate_ns_veth(struct lxc_netdev *netdev)
+static int __instantiate_common(struct lxc_netdev *netdev)
{
char current_ifname[IFNAMSIZ];
@@ -908,13 +900,10 @@ static int instantiate_ns_veth(struct lxc_netdev *netdev)
return 0;
}
-static int __instantiate_common(struct lxc_netdev *netdev)
+static int instantiate_ns_veth(struct lxc_netdev *netdev)
{
- netdev->ifindex = if_nametoindex(netdev->name);
- if (!netdev->ifindex)
- return log_error_errno(-1, errno, "Failed to retrieve ifindex for network device with name %s", netdev->name);
- return 0;
+ return __instantiate_common(netdev);
}
static int instantiate_ns_macvlan(struct lxc_netdev *netdev)
@@ -934,7 +923,13 @@ static int instantiate_ns_vlan(struct lxc_netdev *netdev)
static int instantiate_ns_phys(struct lxc_netdev *netdev)
{
- return __instantiate_common(netdev);
+ netdev->ifindex = if_nametoindex(netdev->name);
+ if (!netdev->ifindex)
+ return log_error_errno(-1, errno,
+ "Failed to retrieve ifindex for network device with name %s",
+ netdev->name);
+
+ return 0;
}
static int instantiate_ns_empty(struct lxc_netdev *netdev)
More information about the lxc-devel
mailing list