[lxc-devel] [lxc/master] network: prefix veth interface name with uid info

brauner on Github lxc-bot at linuxcontainers.org
Thu Jan 10 22:17:40 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 424 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190110/048a836c/attachment.bin>
-------------- next part --------------
From 0693faf6ad2bd2c17504c5b43c9a1185e371801c Mon Sep 17 00:00:00 2001
From: hn <hn at users.noreply.github.com>
Date: Tue, 8 Jan 2019 21:23:41 +0100
Subject: [PATCH] network: prefix veth interface name with uid info

Signed-off-by: Hajo Noerenberg <hajo-github at noerenberg.de>
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/cmd/lxc_user_nic.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/lxc/cmd/lxc_user_nic.c b/src/lxc/cmd/lxc_user_nic.c
index 0ff418497..0eb88f683 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,13 @@ 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;
 


More information about the lxc-devel mailing list