mirror of
git://github.com/lxc/lxc
synced 2025-08-31 16:57:57 +00:00
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 <christian.brauner@ubuntu.com>
This commit is contained in:
@@ -3274,6 +3274,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;
|
||||
@@ -3387,6 +3388,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;
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
@@ -850,6 +851,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);
|
||||
@@ -943,7 +945,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;
|
||||
@@ -1018,7 +1020,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);
|
||||
@@ -1029,7 +1031,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);
|
||||
|
Reference in New Issue
Block a user