From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MOYam-00039O-Lm for qemu-devel@nongnu.org; Wed, 08 Jul 2009 10:57:52 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MOYah-00031d-MV for qemu-devel@nongnu.org; Wed, 08 Jul 2009 10:57:51 -0400 Received: from [199.232.76.173] (port=56154 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MOYah-00031P-Hv for qemu-devel@nongnu.org; Wed, 08 Jul 2009 10:57:47 -0400 Received: from mail11.svc.cra.dublin.eircom.net ([159.134.118.27]:38577) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1MOYah-0000Y7-1e for qemu-devel@nongnu.org; Wed, 08 Jul 2009 10:57:47 -0400 From: Mark McLoughlin Date: Wed, 8 Jul 2009 15:57:28 +0100 Message-Id: <1247065048-15706-5-git-send-email-markmc@redhat.com> In-Reply-To: <1247065048-15706-4-git-send-email-markmc@redhat.com> References: <1247064963.3270.63.camel@blaa> <1247065048-15706-1-git-send-email-markmc@redhat.com> <1247065048-15706-2-git-send-email-markmc@redhat.com> <1247065048-15706-3-git-send-email-markmc@redhat.com> <1247065048-15706-4-git-send-email-markmc@redhat.com> Subject: [Qemu-devel] [PATCH 5/5] Add support for fd=name to tap and socket networking List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Mark McLoughlin This allows a program to initialize a host networking device using a file descriptor passed over a unix monitor socket. The program must first pass the file descriptor using SCM_RIGHTS ancillary data with the getfd monitor command. It then may do "host_net_add tap fd=name" to use the named file descriptor. Signed-off-by: Mark McLoughlin --- net.c | 42 +++++++++++++++++++++++++++++++++++------- 1 files changed, 35 insertions(+), 7 deletions(-) diff --git a/net.c b/net.c index 001ebcb..a97abb4 100644 --- a/net.c +++ b/net.c @@ -2388,6 +2388,23 @@ 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 (!qemu_isdigit(param[0])) { + int fd; + + fd = monitor_get_fd(mon, param); + if (fd == -1) { + config_error(mon, "No file descriptor named %s found", param); + 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,14 +2642,20 @@ 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); + if (!s) { + close(fd); + } } else { static const char * const tap_params[] = { "vlan", "name", "ifname", "script", "downscript", "sndbuf", NULL @@ -2670,15 +2693,20 @@ 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; - if (net_socket_fd_init(vlan, device, name, fd, 1)) - ret = 0; + fd = net_handle_fd_param(mon, buf); + if (fd == -1) { + goto out; + } + if (!net_socket_fd_init(vlan, device, name, fd, 1)) { + close(fd); + goto out; + } + ret = 0; } else if (get_param_value(buf, sizeof(buf), "listen", p) > 0) { static const char * const listen_params[] = { "vlan", "name", "listen", NULL -- 1.6.2.5