From: hn Date: Tue, 8 Jan 2019 20:23:41 +0000 (+0100) Subject: network: prefix veth interface name with uid info X-Git-Tag: lxc-3.2.0~191^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aa2fdfd362586bdbedf0a5f7751d9237bf91afa9;p=thirdparty%2Flxc.git network: prefix veth interface name with uid info Signed-off-by: Hajo Noerenberg Signed-off-by: Christian Brauner --- diff --git a/src/lxc/cmd/lxc_user_nic.c b/src/lxc/cmd/lxc_user_nic.c index 0ff418497..12c3d83c7 100644 --- a/src/lxc/cmd/lxc_user_nic.c +++ b/src/lxc/cmd/lxc_user_nic.c @@ -711,6 +711,7 @@ static char *get_nic_if_avail(int fd, struct alloted_s *names, int pid, struct stat sb; struct alloted_s *n; char *buf = NULL; + uid_t uid; for (n = names; n != NULL; n = n->next) cull_entries(fd, n->name, intype, br, NULL, NULL); @@ -753,7 +754,12 @@ static char *get_nic_if_avail(int fd, struct alloted_s *names, int pid, if (!owner) return NULL; - ret = snprintf(nicname, sizeof(nicname), "vethXXXXXX"); + uid = getuid(); + /* for POSIX integer uids the network device name schema is vethUID_XXXXX */ + if (uid > 0 && uid <= 65536) + ret = snprintf(nicname, sizeof(nicname), "veth%d_XXXXX", uid); + else + ret = snprintf(nicname, sizeof(nicname), "vethXXXXXX"); if (ret < 0 || (size_t)ret >= sizeof(nicname)) return NULL;