-/* $OpenBSD: config.c,v 1.73 2024/01/03 22:34:39 dv Exp $ */
+/* $OpenBSD: config.c,v 1.74 2024/01/18 14:49:59 claudio Exp $ */
/*
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
{
struct vmop_create_params vmc;
struct vmd_vm *vm = NULL;
+ int fd;
IMSG_SIZE_CHECK(imsg, &vmc);
memcpy(&vmc, imsg->data, sizeof(vmc));
- vmc.vmc_kernel = imsg->fd;
+ fd = imsg_get_fd(imsg);
+ vmc.vmc_kernel = fd;
errno = 0;
if (vm_register(ps, &vmc, &vm, imsg->hdr.peerid, 0) == -1)
vm->vm_state |= VM_STATE_RUNNING;
vm->vm_peerid = (uint32_t)-1;
- vm->vm_kernel = imsg->fd;
+ vm->vm_kernel = fd;
return (0);
fail:
- if (imsg->fd != -1) {
- close(imsg->fd);
- imsg->fd = -1;
- }
+ if (fd != -1)
+ close(fd);
vm_remove(vm, __func__);
if (errno == 0)
{
struct vmd_vm *vm;
unsigned int n, idx;
+ int fd;
errno = 0;
if ((vm = vm_getbyvmid(imsg->hdr.peerid)) == NULL) {
IMSG_SIZE_CHECK(imsg, &n);
memcpy(&n, imsg->data, sizeof(n));
+ fd = imsg_get_fd(imsg);
- if (n >= vm->vm_params.vmc_ndisks || imsg->fd == -1) {
+ if (n >= vm->vm_params.vmc_ndisks || fd == -1) {
log_warnx("invalid disk id");
errno = EINVAL;
return (-1);
errno = EINVAL;
return (-1);
}
- vm->vm_disks[n][idx] = imsg->fd;
+ vm->vm_disks[n][idx] = fd;
return (0);
}
{
struct vmd_vm *vm;
unsigned int n;
+ int fd;
errno = 0;
if ((vm = vm_getbyvmid(imsg->hdr.peerid)) == NULL) {
IMSG_SIZE_CHECK(imsg, &n);
memcpy(&n, imsg->data, sizeof(n));
+ fd = imsg_get_fd(imsg);
+
if (n >= vm->vm_params.vmc_nnics ||
- vm->vm_ifs[n].vif_fd != -1 || imsg->fd == -1) {
+ vm->vm_ifs[n].vif_fd != -1 || fd == -1) {
log_warnx("invalid interface id");
goto fail;
}
- vm->vm_ifs[n].vif_fd = imsg->fd;
+ vm->vm_ifs[n].vif_fd = fd;
return (0);
fail:
- if (imsg->fd != -1)
- close(imsg->fd);
+ if (fd != -1)
+ close(fd);
errno = EINVAL;
return (-1);
}
config_getcdrom(struct privsep *ps, struct imsg *imsg)
{
struct vmd_vm *vm;
+ int fd;
errno = 0;
if ((vm = vm_getbyvmid(imsg->hdr.peerid)) == NULL) {
return (-1);
}
- if (imsg->fd == -1) {
+ fd = imsg_get_fd(imsg);
+ if (fd == -1) {
log_warnx("invalid cdrom id");
goto fail;
}
- vm->vm_cdrom = imsg->fd;
+ vm->vm_cdrom = fd;
return (0);
fail:
- if (imsg->fd != -1)
- close(imsg->fd);
errno = EINVAL;
return (-1);
}
-/* $OpenBSD: control.c,v 1.41 2023/04/28 19:46:42 dv Exp $ */
+/* $OpenBSD: control.c,v 1.42 2024/01/18 14:49:59 claudio Exp $ */
/*
* Copyright (c) 2010-2015 Reyk Floeter <reyk@openbsd.org>
case IMSG_VMDOP_RELOAD:
case IMSG_CTL_RESET:
if (proc_compose_imsg(ps, PROC_PARENT, -1,
- imsg.hdr.type, fd, imsg.fd,
+ imsg.hdr.type, fd, imsg_get_fd(&imsg),
imsg.data, IMSG_DATA_SIZE(&imsg)) == -1)
goto fail;
break;
/* imsg.fd may contain kernel image fd. */
if (proc_compose_imsg(ps, PROC_PARENT, -1,
- imsg.hdr.type, fd, imsg.fd, &vmc,
+ imsg.hdr.type, fd, imsg_get_fd(&imsg), &vmc,
sizeof(vmc)) == -1) {
control_close(fd, cs);
return;
vid.vid_uid);
if (proc_compose_imsg(ps, PROC_PARENT, -1,
- imsg.hdr.type, fd, imsg.fd,
+ imsg.hdr.type, fd, imsg_get_fd(&imsg),
&vid, sizeof(vid)) == -1)
goto fail;
break;
-/* $OpenBSD: priv.c,v 1.23 2023/07/13 18:31:59 dv Exp $ */
+/* $OpenBSD: priv.c,v 1.24 2024/01/18 14:49:59 claudio Exp $ */
/*
* Copyright (c) 2016 Reyk Floeter <reyk@openbsd.org>
struct vmop_addr_req vareq;
struct vmop_addr_result varesult;
char type[IF_NAMESIZE];
+ int ifd;
switch (imsg->hdr.type) {
case IMSG_VMDOP_PRIV_IFDESCR:
varesult.var_vmid = vareq.var_vmid;
varesult.var_nic_idx = vareq.var_nic_idx;
+ ifd = imsg_get_fd(imsg);
/* resolve lladdr for the tap(4) and send back to parent */
- if (ioctl(imsg->fd, SIOCGIFADDR, &varesult.var_addr) != 0)
+ if (ioctl(ifd, SIOCGIFADDR, &varesult.var_addr) != 0)
log_warn("SIOCGIFADDR");
else
proc_compose_imsg(ps, PROC_PARENT, -1,
IMSG_VMDOP_PRIV_GET_ADDR_RESPONSE, imsg->hdr.peerid,
-1, &varesult, sizeof(varesult));
- close(imsg->fd);
+ close(ifd);
break;
case IMSG_VMDOP_CONFIG:
config_getconfig(env, imsg);
-/* $OpenBSD: proc.c,v 1.21 2023/09/26 01:53:54 dv Exp $ */
+/* $OpenBSD: proc.c,v 1.22 2024/01/18 14:49:59 claudio Exp $ */
/*
* Copyright (c) 2010 - 2016 Reyk Floeter <reyk@openbsd.org>
case IMSG_CTL_PROCFD:
IMSG_SIZE_CHECK(&imsg, &pf);
memcpy(&pf, imsg.data, sizeof(pf));
- proc_accept(ps, imsg.fd, pf.pf_procid,
+ proc_accept(ps, imsg_get_fd(&imsg), pf.pf_procid,
pf.pf_instance);
break;
default:
enum privsep_procid id, int n)
{
return (proc_compose_imsg(ps, id, n, imsg->hdr.type,
- imsg->hdr.peerid, imsg->fd, imsg->data, IMSG_DATA_SIZE(imsg)));
+ imsg->hdr.peerid, imsg_get_fd(imsg), imsg->data,
+ IMSG_DATA_SIZE(imsg)));
}
struct imsgbuf *
-/* $OpenBSD: vm.c,v 1.95 2024/01/10 04:13:59 dv Exp $ */
+/* $OpenBSD: vm.c,v 1.96 2024/01/18 14:49:59 claudio Exp $ */
/*
* Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
break;
case IMSG_VMDOP_SEND_VM_REQUEST:
vmr.vmr_id = vm->vm_vmid;
- vmr.vmr_result = send_vm(imsg.fd, vm);
+ vmr.vmr_result = send_vm(imsg_get_fd(&imsg), vm);
imsg_compose_event(&vm->vm_iev,
IMSG_VMDOP_SEND_VM_RESPONSE,
imsg.hdr.peerid, imsg.hdr.pid, -1, &vmr,
-/* $OpenBSD: vmd.c,v 1.152 2023/09/26 01:53:54 dv Exp $ */
+/* $OpenBSD: vmd.c,v 1.153 2024/01/18 14:49:59 claudio Exp $ */
/*
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
{
struct privsep *ps = p->p_ps;
int res = 0, ret = 0, cmd = 0, verbose;
+ int ifd;
unsigned int v = 0, flags;
struct vmop_create_params vmc;
struct vmop_id vid;
case IMSG_VMDOP_START_VM_REQUEST:
IMSG_SIZE_CHECK(imsg, &vmc);
memcpy(&vmc, imsg->data, sizeof(vmc));
- vmc.vmc_kernel = imsg->fd;
+ vmc.vmc_kernel = imsg_get_fd(imsg);
/* Try registering our VM in our list of known VMs. */
if (vm_register(ps, &vmc, &vm, 0, vmc.vmc_owner.uid)) {
IMSG_SIZE_CHECK(imsg, &vid);
memcpy(&vid, imsg->data, sizeof(vid));
id = vid.vid_id;
+ ifd = imsg_get_fd(imsg);
if (vid.vid_id == 0) {
if ((vm = vm_getbyname(vid.vid_name)) == NULL) {
res = ENOENT;
cmd = IMSG_VMDOP_SEND_VM_RESPONSE;
- close(imsg->fd);
+ close(ifd);
break;
} else {
vid.vid_id = vm->vm_vmid;
} else if ((vm = vm_getbyvmid(vid.vid_id)) == NULL) {
res = ENOENT;
cmd = IMSG_VMDOP_SEND_VM_RESPONSE;
- close(imsg->fd);
+ close(ifd);
break;
}
vmr.vmr_id = vid.vid_id;
log_debug("%s: sending fd to vmm", __func__);
proc_compose_imsg(ps, PROC_VMM, -1, imsg->hdr.type,
- imsg->hdr.peerid, imsg->fd, &vid, sizeof(vid));
+ imsg->hdr.peerid, ifd, &vid, sizeof(vid));
break;
case IMSG_VMDOP_RECEIVE_VM_REQUEST:
IMSG_SIZE_CHECK(imsg, &vid);
memcpy(&vid, imsg->data, sizeof(vid));
- if (imsg->fd == -1) {
+ ifd = imsg_get_fd(imsg);
+ if (ifd == -1) {
log_warnx("%s: invalid fd", __func__);
return (-1);
}
- if (atomicio(read, imsg->fd, &vmh, sizeof(vmh)) !=
- sizeof(vmh)) {
+ if (atomicio(read, ifd, &vmh, sizeof(vmh)) != sizeof(vmh)) {
log_warnx("%s: error reading vmh from received vm",
__func__);
res = EIO;
- close(imsg->fd);
+ close(ifd);
cmd = IMSG_VMDOP_START_VM_RESPONSE;
break;
}
if (vmd_check_vmh(&vmh)) {
res = ENOENT;
- close(imsg->fd);
+ close(ifd);
cmd = IMSG_VMDOP_START_VM_RESPONSE;
break;
}
- if (atomicio(read, imsg->fd, &vmc, sizeof(vmc)) !=
- sizeof(vmc)) {
+ if (atomicio(read, ifd, &vmc, sizeof(vmc)) != sizeof(vmc)) {
log_warnx("%s: error reading vmc from received vm",
__func__);
res = EIO;
- close(imsg->fd);
+ close(ifd);
cmd = IMSG_VMDOP_START_VM_RESPONSE;
break;
}
if (ret != 0) {
res = errno;
cmd = IMSG_VMDOP_START_VM_RESPONSE;
- close(imsg->fd);
+ close(ifd);
} else {
vm->vm_state |= VM_STATE_RECEIVED;
config_setvm(ps, vm, imsg->hdr.peerid,
vmc.vmc_owner.uid);
log_debug("%s: sending fd to vmm", __func__);
proc_compose_imsg(ps, PROC_VMM, -1,
- IMSG_VMDOP_RECEIVE_VM_END, vm->vm_vmid, imsg->fd,
+ IMSG_VMDOP_RECEIVE_VM_END, vm->vm_vmid, ifd,
NULL, 0);
}
break;
-/* $OpenBSD: vmm.c,v 1.116 2024/01/03 22:34:39 dv Exp $ */
+/* $OpenBSD: vmm.c,v 1.117 2024/01/18 14:49:59 claudio Exp $ */
/*
* Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
}
imsg_compose_event(&vm->vm_iev,
imsg->hdr.type, imsg->hdr.peerid, imsg->hdr.pid,
- imsg->fd, &vid, sizeof(vid));
+ imsg_get_fd(imsg), &vid, sizeof(vid));
break;
case IMSG_VMDOP_UNPAUSE_VM:
IMSG_SIZE_CHECK(imsg, &vid);
}
imsg_compose_event(&vm->vm_iev,
imsg->hdr.type, imsg->hdr.peerid, imsg->hdr.pid,
- imsg->fd, &vid, sizeof(vid));
+ imsg_get_fd(imsg), &vid, sizeof(vid));
break;
case IMSG_VMDOP_SEND_VM_REQUEST:
IMSG_SIZE_CHECK(imsg, &vid);
id = vid.vid_id;
if ((vm = vm_getbyvmid(id)) == NULL) {
res = ENOENT;
- close(imsg->fd);
+ close(imsg_get_fd(imsg)); /* XXX */
cmd = IMSG_VMDOP_START_VM_RESPONSE;
break;
}
imsg_compose_event(&vm->vm_iev,
imsg->hdr.type, imsg->hdr.peerid, imsg->hdr.pid,
- imsg->fd, &vid, sizeof(vid));
+ imsg_get_fd(imsg), &vid, sizeof(vid));
break;
case IMSG_VMDOP_RECEIVE_VM_REQUEST:
IMSG_SIZE_CHECK(imsg, &vmc);
cmd = IMSG_VMDOP_START_VM_RESPONSE;
break;
}
- vm->vm_tty = imsg->fd;
+ vm->vm_tty = imsg_get_fd(imsg);
vm->vm_state |= VM_STATE_RECEIVED;
vm->vm_state |= VM_STATE_PAUSED;
break;
case IMSG_VMDOP_RECEIVE_VM_END:
if ((vm = vm_getbyvmid(imsg->hdr.peerid)) == NULL) {
res = ENOENT;
- close(imsg->fd);
+ close(imsg_get_fd(imsg)); /* XXX */
cmd = IMSG_VMDOP_START_VM_RESPONSE;
break;
}
- vm->vm_receive_fd = imsg->fd;
+ vm->vm_receive_fd = imsg_get_fd(imsg);
res = vmm_start_vm(imsg, &id, &pid);
/* Check if the ID can be mapped correctly */
if ((id = vm_id2vmid(id, NULL)) == 0)
/* Forward hardware address details to the guest vm */
imsg_compose_event(&vm->vm_iev,
imsg->hdr.type, imsg->hdr.peerid, imsg->hdr.pid,
- imsg->fd, &var, sizeof(var));
+ imsg_get_fd(imsg), &var, sizeof(var));
break;
case IMSG_VMDOP_RECEIVE_VMM_FD:
if (env->vmd_fd > -1)
fatalx("already received vmm fd");
- env->vmd_fd = imsg->fd;
+ env->vmd_fd = imsg_get_fd(imsg);
/* Get and terminate all running VMs */
get_info_vm(ps, NULL, 1);
vcp = &vm->vm_params.vmc_params;
if (!(vm->vm_state & VM_STATE_RECEIVED)) {
- if ((vm->vm_tty = imsg->fd) == -1) {
+ if ((vm->vm_tty = imsg_get_fd(imsg)) == -1) {
log_warnx("%s: can't get tty", __func__);
goto err;
}