From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MNs3T-0005JU-85 for qemu-devel@nongnu.org; Mon, 06 Jul 2009 13:32:39 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MNs3O-0005GV-AO for qemu-devel@nongnu.org; Mon, 06 Jul 2009 13:32:38 -0400 Received: from [199.232.76.173] (port=57369 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MNs3N-0005GP-S9 for qemu-devel@nongnu.org; Mon, 06 Jul 2009 13:32:34 -0400 Received: from mx2.redhat.com ([66.187.237.31]:60273) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MNs3M-0000UB-NX for qemu-devel@nongnu.org; Mon, 06 Jul 2009 13:32:33 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n66HWUo8001850 for ; Mon, 6 Jul 2009 13:32:30 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n66HWUY2022996 for ; Mon, 6 Jul 2009 13:32:30 -0400 Received: from [IPv6:::1] (sebastian-int.corp.redhat.com [172.16.52.221]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n66HWThi003195 for ; Mon, 6 Jul 2009 13:32:29 -0400 From: Mark McLoughlin In-Reply-To: <1246901495.12086.22.camel@blaa> References: <1246901401.12086.20.camel@blaa> <1246901456.12086.21.camel@blaa> <1246901495.12086.22.camel@blaa> Content-Type: text/plain Date: Mon, 06 Jul 2009 18:32:13 +0100 Message-Id: <1246901533.12086.23.camel@blaa> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH 3/3] Add support for fd=msgfd for tap and socket networking Reply-To: Mark McLoughlin List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel 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 --- 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