From fa2e1cea8de4f3e9bbb4ceccdcfd78bb64e87f58 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Sat, 21 Mar 2020 11:52:15 +0100 Subject: [PATCH] lxc-user-nic: enable uid-marked veth devices for uids with 5 digits With the newly extended lxc_ifname_alnum_case_sensitive() we'll have 62^4 unique network device names per user. Closes #3176. Signed-off-by: Christian Brauner --- src/lxc/cmd/lxc_user_nic.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lxc/cmd/lxc_user_nic.c b/src/lxc/cmd/lxc_user_nic.c index cd9c1ef2f..fd3455903 100644 --- a/src/lxc/cmd/lxc_user_nic.c +++ b/src/lxc/cmd/lxc_user_nic.c @@ -727,9 +727,15 @@ static char *get_nic_if_avail(int fd, struct alloted_s *names, int pid, return NULL; uid = getuid(); - /* for POSIX integer uids the network device name schema is vethUID_XXXXX */ + /* + * For POSIX integer uids the network device name schema is + * vethUID_XXXX. + * With four random characters passed to + * lxc_ifname_alnum_case_sensitive() we get 62^4 = 14776336 + * combinations per uid. That's plenty of network devices for now. + */ if (uid > 0 && uid <= 65536) - ret = snprintf(nicname, sizeof(nicname), "veth%d_XXXXX", uid); + ret = snprintf(nicname, sizeof(nicname), "veth%d_XXXX", uid); else ret = snprintf(nicname, sizeof(nicname), "vethXXXXXX"); if (ret < 0 || (size_t)ret >= sizeof(nicname)) -- 2.47.2