From: Christian Brauner Date: Sun, 27 Aug 2017 02:59:57 +0000 (+0200) Subject: network: send ifindex for unpriv networks X-Git-Tag: lxc-2.0.9~49^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=07bb83244b563a5205230864cbdd71ae75b890bd;p=thirdparty%2Flxc.git network: send ifindex for unpriv networks We use the ifindex as an indicator that liblxc created the network so let's record it for the unprivileged case as well. Signed-off-by: Christian Brauner --- diff --git a/src/lxc/conf.c b/src/lxc/conf.c index c8a05b43c..7fe3297ee 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -3167,6 +3167,7 @@ bool lxc_delete_network(struct lxc_handler *handler) static int unpriv_assign_nic(const char *lxcpath, char *lxcname, struct lxc_netdev *netdev, pid_t pid) { + int ret; pid_t child; int bytes, pipefd[2]; char *token, *saveptr = NULL; @@ -3280,6 +3281,17 @@ static int unpriv_assign_nic(const char *lxcpath, char *lxcname, return -1; } + /* fill netdev->veth_attr.pair field */ + token = strtok_r(NULL, ":", &saveptr); + if (!token) + return -1; + + ret = lxc_safe_int(token, &netdev->ifindex); + if (ret < 0) { + ERROR("Failed to parse ifindex for network device \"%s\"", netdev->name); + return -1; + } + return 0; } diff --git a/src/lxc/lxc_user_nic.c b/src/lxc/lxc_user_nic.c index a9b37c8e0..70dcd8975 100644 --- a/src/lxc/lxc_user_nic.c +++ b/src/lxc/lxc_user_nic.c @@ -767,7 +767,8 @@ again: goto again; } -static char *lxc_secure_rename_in_ns(int pid, char *oldname, char *newname) +static char *lxc_secure_rename_in_ns(int pid, char *oldname, char *newname, + int *ifidx) { int ret; uid_t ruid, suid, euid; @@ -849,6 +850,7 @@ static char *lxc_secure_rename_in_ns(int pid, char *oldname, char *newname) /* Allocation failure for strdup() is checked below. */ name = strdup(ifname); string_ret = name; + *ifidx = ifindex; do_full_cleanup: ret = setresuid(ruid, euid, suid); @@ -944,7 +946,7 @@ struct user_nic_args { int main(int argc, char *argv[]) { - int fd, n, pid, ret; + int fd, ifindex, n, pid, ret; char *me, *newname; char *cnic = NULL, *nicname = NULL; struct alloted_s *alloted = NULL; @@ -1019,7 +1021,7 @@ int main(int argc, char *argv[]) } /* Now rename the link. */ - newname = lxc_secure_rename_in_ns(pid, cnic, args.veth_name); + newname = lxc_secure_rename_in_ns(pid, cnic, args.veth_name, &ifindex); if (!newname) { usernic_error("%s", "Failed to rename the link\n"); ret = lxc_netdev_delete_by_name(cnic); @@ -1030,7 +1032,7 @@ int main(int argc, char *argv[]) } /* Write the name of the interface pair to the stdout: eth0:veth9MT2L4 */ - fprintf(stdout, "%s:%s\n", newname, nicname); + fprintf(stdout, "%s:%s:%d\n", newname, nicname, ifindex); free(newname); free(nicname); exit(EXIT_SUCCESS);