]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
network: prefix veth interface name with uid info 2781/head
authorhn <hn@users.noreply.github.com>
Tue, 8 Jan 2019 20:23:41 +0000 (21:23 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Thu, 10 Jan 2019 22:22:52 +0000 (23:22 +0100)
Signed-off-by: Hajo Noerenberg <hajo-github@noerenberg.de>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/cmd/lxc_user_nic.c

index 0ff41849741adfcd2819de5ea21c3133ac19bfa0..12c3d83c71ad1b836f31e141bf1b97df3679d2d6 100644 (file)
@@ -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;