]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
network: introduce lxc_ifname_alnum_case_sensitive()
authorChristian Brauner <christian.brauner@ubuntu.com>
Sat, 21 Mar 2020 10:50:59 +0000 (11:50 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Sat, 21 Mar 2020 10:50:59 +0000 (11:50 +0100)
Right now we have 36^n unique network device names. Let's make it 62^n.

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

index 5038d16e0ae81d09b149ca81f63bcd9983428d89..cd9c1ef2f4850089c606815ac3d44d0250ac6c6d 100644 (file)
@@ -735,7 +735,7 @@ static char *get_nic_if_avail(int fd, struct alloted_s *names, int pid,
        if (ret < 0 || (size_t)ret >= sizeof(nicname))
                return NULL;
 
-       if (!lxc_mkifname(nicname))
+       if (!lxc_ifname_alnum_case_sensitive(nicname))
                return NULL;
 
        ret = create_nic(nicname, br, pid, cnic);
index e74bd4ddca5c90f4caf00f3e0a2fe5e74a325314..421da89416319aabfe6cf30361bfaa111b07749c 100644 (file)
@@ -903,7 +903,7 @@ static bool restore_net_info(struct lxc_container *c)
 
                if (netdev->priv.veth_attr.pair[0] == '\0' &&
                    netdev->priv.veth_attr.veth1[0] == '\0') {
-                       if (!lxc_mkifname(template))
+                       if (!lxc_ifname_alnum_case_sensitive(template))
                                goto out_unlock;
 
                        (void)strlcpy(netdev->priv.veth_attr.veth1, template, IFNAMSIZ);
index 469f9bdcafc594394e48b0be21a0f99442336db0..b442ed5752691e5a928e7618d56f1b3ba59c642b 100644 (file)
@@ -261,7 +261,7 @@ static int instantiate_veth(struct lxc_handler *handler, struct lxc_netdev *netd
                if (err < 0 || (size_t)err >= sizeof(veth1buf))
                        return -1;
 
-               veth1 = lxc_mkifname(veth1buf);
+               veth1 = lxc_ifname_alnum_case_sensitive(veth1buf);
                if (!veth1)
                        return -1;
 
@@ -273,7 +273,7 @@ static int instantiate_veth(struct lxc_handler *handler, struct lxc_netdev *netd
        if (err < 0 || (size_t)err >= sizeof(veth2buf))
                return -1;
 
-       veth2 = lxc_mkifname(veth2buf);
+       veth2 = lxc_ifname_alnum_case_sensitive(veth2buf);
        if (!veth2)
                return -1;
 
@@ -470,7 +470,7 @@ static int instantiate_macvlan(struct lxc_handler *handler, struct lxc_netdev *n
        if (err < 0 || (size_t)err >= sizeof(peer))
                return -1;
 
-       if (!lxc_mkifname(peer))
+       if (!lxc_ifname_alnum_case_sensitive(peer))
                return -1;
 
        err = lxc_macvlan_create(netdev->link, peer,
@@ -625,7 +625,7 @@ static int instantiate_ipvlan(struct lxc_handler *handler, struct lxc_netdev *ne
        if (err < 0 || (size_t)err >= sizeof(peer))
                return -1;
 
-       if (!lxc_mkifname(peer))
+       if (!lxc_ifname_alnum_case_sensitive(peer))
                return -1;
 
        err = lxc_ipvlan_create(netdev->link, peer, netdev->priv.ipvlan_attr.mode,
@@ -2446,9 +2446,9 @@ const char *lxc_net_type_to_str(int type)
        return lxc_network_types[type];
 }
 
-static const char padchar[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+static const char padchar[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
 
-char *lxc_mkifname(char *template)
+char *lxc_ifname_alnum_case_sensitive(char *template)
 {
        int ret;
        struct netns_ifaddrs *ifa, *ifaddr;
index 2cf1cbb0d0b43627470da932fcb6f9a779b5abd4..696380c9009a018cc23db2a2dc2d36ffa09c79f8 100644 (file)
@@ -251,10 +251,12 @@ extern int lxc_ip_forwarding_on(const char *name, int family);
 /* Disable IP forwarding. */
 extern int lxc_ip_forwarding_off(const char *name, int family);
 
-/* Generate a new unique network interface name.
- * Allocated memory must be freed by caller.
+/*
+ * Generate a new unique network interface name.
+ *
+ * Allows for 62^n unique combinations.
  */
-extern char *lxc_mkifname(char *template);
+extern char *lxc_ifname_alnum_case_sensitive(char *template);
 
 extern const char *lxc_net_type_to_str(int type);
 extern int setup_private_host_hw_addr(char *veth1);