]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
network: restore old behavior 3415/head
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 15 May 2020 19:14:15 +0000 (21:14 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 15 May 2020 19:17:48 +0000 (21:17 +0200)
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@ubuntu.com>
src/lxc/network.c

index eaab9eccfee2f644bd234b1d39f5a77f34913ddf..ef6707ff4cdef82303ddfccfe060b42880d72f6d 100644 (file)
@@ -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)