network: introduce lxc_ifname_alnum_case_sensitive()

Right now we have 36^n unique network device names. Let's make it 62^n. Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent 0c241537
...@@ -735,7 +735,7 @@ static char *get_nic_if_avail(int fd, struct alloted_s *names, int pid, ...@@ -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)) if (ret < 0 || (size_t)ret >= sizeof(nicname))
return NULL; return NULL;
if (!lxc_mkifname(nicname)) if (!lxc_ifname_alnum_case_sensitive(nicname))
return NULL; return NULL;
ret = create_nic(nicname, br, pid, cnic); ret = create_nic(nicname, br, pid, cnic);
......
...@@ -903,7 +903,7 @@ static bool restore_net_info(struct lxc_container *c) ...@@ -903,7 +903,7 @@ static bool restore_net_info(struct lxc_container *c)
if (netdev->priv.veth_attr.pair[0] == '\0' && if (netdev->priv.veth_attr.pair[0] == '\0' &&
netdev->priv.veth_attr.veth1[0] == '\0') { netdev->priv.veth_attr.veth1[0] == '\0') {
if (!lxc_mkifname(template)) if (!lxc_ifname_alnum_case_sensitive(template))
goto out_unlock; goto out_unlock;
(void)strlcpy(netdev->priv.veth_attr.veth1, template, IFNAMSIZ); (void)strlcpy(netdev->priv.veth_attr.veth1, template, IFNAMSIZ);
......
...@@ -261,7 +261,7 @@ static int instantiate_veth(struct lxc_handler *handler, struct lxc_netdev *netd ...@@ -261,7 +261,7 @@ static int instantiate_veth(struct lxc_handler *handler, struct lxc_netdev *netd
if (err < 0 || (size_t)err >= sizeof(veth1buf)) if (err < 0 || (size_t)err >= sizeof(veth1buf))
return -1; return -1;
veth1 = lxc_mkifname(veth1buf); veth1 = lxc_ifname_alnum_case_sensitive(veth1buf);
if (!veth1) if (!veth1)
return -1; return -1;
...@@ -273,7 +273,7 @@ static int instantiate_veth(struct lxc_handler *handler, struct lxc_netdev *netd ...@@ -273,7 +273,7 @@ static int instantiate_veth(struct lxc_handler *handler, struct lxc_netdev *netd
if (err < 0 || (size_t)err >= sizeof(veth2buf)) if (err < 0 || (size_t)err >= sizeof(veth2buf))
return -1; return -1;
veth2 = lxc_mkifname(veth2buf); veth2 = lxc_ifname_alnum_case_sensitive(veth2buf);
if (!veth2) if (!veth2)
return -1; return -1;
...@@ -470,7 +470,7 @@ static int instantiate_macvlan(struct lxc_handler *handler, struct lxc_netdev *n ...@@ -470,7 +470,7 @@ static int instantiate_macvlan(struct lxc_handler *handler, struct lxc_netdev *n
if (err < 0 || (size_t)err >= sizeof(peer)) if (err < 0 || (size_t)err >= sizeof(peer))
return -1; return -1;
if (!lxc_mkifname(peer)) if (!lxc_ifname_alnum_case_sensitive(peer))
return -1; return -1;
err = lxc_macvlan_create(netdev->link, peer, err = lxc_macvlan_create(netdev->link, peer,
...@@ -625,7 +625,7 @@ static int instantiate_ipvlan(struct lxc_handler *handler, struct lxc_netdev *ne ...@@ -625,7 +625,7 @@ static int instantiate_ipvlan(struct lxc_handler *handler, struct lxc_netdev *ne
if (err < 0 || (size_t)err >= sizeof(peer)) if (err < 0 || (size_t)err >= sizeof(peer))
return -1; return -1;
if (!lxc_mkifname(peer)) if (!lxc_ifname_alnum_case_sensitive(peer))
return -1; return -1;
err = lxc_ipvlan_create(netdev->link, peer, netdev->priv.ipvlan_attr.mode, 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) ...@@ -2446,9 +2446,9 @@ const char *lxc_net_type_to_str(int type)
return lxc_network_types[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; int ret;
struct netns_ifaddrs *ifa, *ifaddr; struct netns_ifaddrs *ifa, *ifaddr;
......
...@@ -251,10 +251,12 @@ extern int lxc_ip_forwarding_on(const char *name, int family); ...@@ -251,10 +251,12 @@ extern int lxc_ip_forwarding_on(const char *name, int family);
/* Disable IP forwarding. */ /* Disable IP forwarding. */
extern int lxc_ip_forwarding_off(const char *name, int family); 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 const char *lxc_net_type_to_str(int type);
extern int setup_private_host_hw_addr(char *veth1); extern int setup_private_host_hw_addr(char *veth1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment