[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 3/3] Add support for fd=msgfd for tap and socket net
From: |
Mark McLoughlin |
Subject: |
[Qemu-devel] [PATCH 3/3] Add support for fd=msgfd for tap and socket networking |
Date: |
Mon, 06 Jul 2009 18:32:13 +0100 |
This allows a program to initialize a host networking device using a
file descriptor passed over a unix monitor socket.
If the programs does e.g. "host_net_add tap fd=msgfd" it must pass
a file descriptor as part of that same message via SCM_RIGHTS ancillary
data.
Signed-off-by: Mark McLoughlin <address@hidden>
---
net.c | 39 ++++++++++++++++++++++++++++++++++-----
1 files changed, 34 insertions(+), 5 deletions(-)
diff --git a/net.c b/net.c
index 001ebcb..0bb8b52 100644
--- a/net.c
+++ b/net.c
@@ -2388,6 +2388,30 @@ void qemu_check_nic_model_list(NICInfo *nd, const char *
const *models,
exit(exit_status);
}
+static int net_handle_fd_param(Monitor *mon, const char *param)
+{
+ if (!strcmp(param, "msgfd")) {
+ int fd;
+
+ fd = monitor_get_msgfd(mon);
+ if (fd == -1) {
+ config_error(mon, "No file descriptor found in ancillary data\n");
+ return -1;
+ }
+
+ fd = dup(fd);
+ if (fd == -1) {
+ config_error(mon, "Failed to dup() file descriptor: %s\n",
+ strerror(errno));
+ return -1;
+ }
+
+ return fd;
+ } else {
+ return strtol(param, NULL, 0);
+ }
+}
+
int net_client_init(Monitor *mon, const char *device, const char *p)
{
char buf[1024];
@@ -2625,12 +2649,15 @@ int net_client_init(Monitor *mon, const char *device,
const char *p)
static const char * const fd_params[] = {
"vlan", "name", "fd", "sndbuf", NULL
};
+ ret = -1;
if (check_params(chkbuf, sizeof(chkbuf), fd_params, p) < 0) {
config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf,
p);
- ret = -1;
goto out;
}
- fd = strtol(buf, NULL, 0);
+ fd = net_handle_fd_param(mon, buf);
+ if (fd == -1) {
+ goto out;
+ }
fcntl(fd, F_SETFL, O_NONBLOCK);
s = net_tap_fd_init(vlan, device, name, fd);
} else {
@@ -2670,13 +2697,15 @@ int net_client_init(Monitor *mon, const char *device,
const char *p)
"vlan", "name", "fd", NULL
};
int fd;
+ ret = -1;
if (check_params(chkbuf, sizeof(chkbuf), fd_params, p) < 0) {
config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf,
p);
- ret = -1;
goto out;
}
- fd = strtol(buf, NULL, 0);
- ret = -1;
+ fd = net_handle_fd_param(mon, buf);
+ if (fd == -1) {
+ goto out;
+ }
if (net_socket_fd_init(vlan, device, name, fd, 1))
ret = 0;
} else if (get_param_value(buf, sizeof(buf), "listen", p) > 0) {
--
1.6.2.5
- [Qemu-devel] [PATCH 0/3] Allow host_net_add monitor command accept file descriptors, Mark McLoughlin, 2009/07/06
- [Qemu-devel] [PATCH 1/3] Make tcp_chr_read() use recvmsg(), Mark McLoughlin, 2009/07/06
- Re: [Qemu-devel] [PATCH 0/3] Allow host_net_add monitor command accept file descriptors, Avi Kivity, 2009/07/07
- Re: [Qemu-devel] [PATCH 0/3] Allow host_net_add monitor command accept file descriptors, Mark McLoughlin, 2009/07/07
- Re: [Qemu-devel] [PATCH 0/3] Allow host_net_add monitor command accept file descriptors, Avi Kivity, 2009/07/07
- Re: [Qemu-devel] [PATCH 0/3] Allow host_net_add monitor command accept file descriptors, Mark McLoughlin, 2009/07/07
- Re: [Qemu-devel] [PATCH 0/3] Allow host_net_add monitor command accept file descriptors, Avi Kivity, 2009/07/07
- Re: [Qemu-devel] [PATCH 0/3] Allow host_net_add monitor command accept file descriptors, Daniel P. Berrange, 2009/07/07
- Re: [Qemu-devel] [PATCH 0/3] Allow host_net_add monitor command accept file descriptors, Mark McLoughlin, 2009/07/08
- [Qemu-devel] [PATCH 1/5] Make tcp_chr_read() use recvmsg(), Mark McLoughlin, 2009/07/08
- [Qemu-devel] [PATCH 2/5] Add SCM_RIGHTS support to unix socket character devices, Mark McLoughlin, 2009/07/08
- [Qemu-devel] [PATCH 3/5] Add getfd and closefd monitor commands, Mark McLoughlin, 2009/07/08