From patchwork Thu Sep 10 15:18:54 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark McLoughlin X-Patchwork-Id: 33329 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bilbo.ozlabs.org (Postfix) with ESMTPS id D306DB70BA for ; Fri, 11 Sep 2009 01:41:15 +1000 (EST) Received: from localhost ([127.0.0.1]:48362 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mllln-0004Gr-Qk for incoming@patchwork.ozlabs.org; Thu, 10 Sep 2009 11:41:11 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MllXz-0006HU-Tz for qemu-devel@nongnu.org; Thu, 10 Sep 2009 11:26:56 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MllXu-0006Dx-MF for qemu-devel@nongnu.org; Thu, 10 Sep 2009 11:26:54 -0400 Received: from [199.232.76.173] (port=40187 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MllXt-0006DD-CE for qemu-devel@nongnu.org; Thu, 10 Sep 2009 11:26:49 -0400 Received: from mail06.svc.cra.dublin.eircom.net ([159.134.118.22]:34302) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1MllXs-00007z-GK for qemu-devel@nongnu.org; Thu, 10 Sep 2009 11:26:48 -0400 Received: (qmail 7647 messnum 12831263 invoked from network[83.71.108.236/83-71-108-236-dynamic.b-ras1.srl.dublin.eircom.net]); 10 Sep 2009 15:20:05 -0000 Received: from 83-71-108-236-dynamic.b-ras1.srl.dublin.eircom.net (HELO blaa.localdomain) (83.71.108.236) by mail06.svc.cra.dublin.eircom.net (qp 7647) with SMTP; 10 Sep 2009 15:20:05 -0000 Received: by blaa.localdomain (Postfix, from userid 500) id BEA0441AC2; Thu, 10 Sep 2009 16:19:01 +0100 (IST) From: Mark McLoughlin To: qemu-devel@nongnu.org Date: Thu, 10 Sep 2009 16:18:54 +0100 Message-Id: <1252595941-15196-13-git-send-email-markmc@redhat.com> X-Mailer: git-send-email 1.6.2.5 In-Reply-To: <1252595941-15196-1-git-send-email-markmc@redhat.com> References: <1252595941-15196-1-git-send-email-markmc@redhat.com> X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Mark McLoughlin Subject: [Qemu-devel] [PATCH 12/19] Port -net socket to QemuOpts X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Mark McLoughlin --- net.c | 168 ++++++++++++++++++++++++++++++++++++++++++----------------------- 1 files changed, 109 insertions(+), 59 deletions(-) diff --git a/net.c b/net.c index 55792a5..c3414eb 100644 --- a/net.c +++ b/net.c @@ -2611,6 +2611,89 @@ static int net_init_tap(QemuOpts *opts, Monitor *mon) } #endif +static int net_init_socket(QemuOpts *opts, Monitor *mon) +{ + VLANState *vlan; + const char *name; + + vlan = qemu_find_vlan(qemu_opt_get_number(opts, "vlan", 0), 1); + + name = qemu_opt_get(opts, "name"); + + if (qemu_opt_get(opts, "fd")) { + int fd; + + if (qemu_opt_get(opts, "listen") || + qemu_opt_get(opts, "connect") || + qemu_opt_get(opts, "mcast")) { + qemu_error("listen=, connect= and mcast= is invalid with fd=\n"); + return -1; + } + + fd = net_handle_fd_param(mon, qemu_opt_get(opts, "fd")); + if (fd == -1) { + return -1; + } + + if (!net_socket_fd_init(vlan, "socket", name, fd, 1)) { + close(fd); + return -1; + } + } else if (qemu_opt_get(opts, "listen")) { + const char *listen; + + if (qemu_opt_get(opts, "fd") || + qemu_opt_get(opts, "connect") || + qemu_opt_get(opts, "mcast")) { + qemu_error("fd=, connect= and mcast= is invalid with listen=\n"); + return -1; + } + + listen = qemu_opt_get(opts, "listen"); + + if (net_socket_listen_init(vlan, "socket", name, listen) == -1) { + return -1; + } + } else if (qemu_opt_get(opts, "connect")) { + const char *connect; + + if (qemu_opt_get(opts, "fd") || + qemu_opt_get(opts, "listen") || + qemu_opt_get(opts, "mcast")) { + qemu_error("fd=, listen= and mcast= is invalid with connect=\n"); + return -1; + } + + connect = qemu_opt_get(opts, "connect"); + + if (net_socket_connect_init(vlan, "socket", name, connect) == -1) { + return -1; + } + } else if (qemu_opt_get(opts, "mcast")) { + const char *mcast; + + if (qemu_opt_get(opts, "fd") || + qemu_opt_get(opts, "connect") || + qemu_opt_get(opts, "listen")) { + qemu_error("fd=, connect= and listen= is invalid with mcast=\n"); + return -1; + } + + mcast = qemu_opt_get(opts, "mcast"); + + if (net_socket_mcast_init(vlan, "socket", name, mcast) == -1) { + return -1; + } + } else { + qemu_error("-socket requires fd=, listen=, connect= or mcast=\n"); + return -1; + } + + vlan->nb_host_devs++; + + return 0; +} + #define NET_COMMON_PARAMS_DESC \ { \ .name = "type", \ @@ -2773,6 +2856,30 @@ static struct { { /* end of list */ } }, #endif + }, { + .type = "socket", + .init = net_init_socket, + .desc = { + NET_COMMON_PARAMS_DESC, + { + .name = "fd", + .type = QEMU_OPT_STRING, + .help = "file descriptor of an already opened socket", + }, { + .name = "listen", + .type = QEMU_OPT_STRING, + .help = "port number, and optional hostname, to listen on", + }, { + .name = "connect", + .type = QEMU_OPT_STRING, + .help = "port number, and optional hostname, to connect to", + }, { + .name = "mcast", + .type = QEMU_OPT_STRING, + .help = "UDP multicast address and port number", + }, + { /* end of list */ } + }, }, { /* end of list */ } }; @@ -2814,7 +2921,8 @@ int net_client_init(Monitor *mon, const char *device, const char *p) if (!strcmp(device, "none") || !strcmp(device, "nic") || !strcmp(device, "user") || - !strcmp(device, "tap")) { + !strcmp(device, "tap") || + !strcmp(device, "socket")) { QemuOpts *opts; opts = qemu_opts_parse(&qemu_net_opts, p, NULL); @@ -2852,64 +2960,6 @@ int net_client_init(Monitor *mon, const char *device, const char *p) ret = 0; } else #endif - if (!strcmp(device, "socket")) { - char chkbuf[64]; - if (get_param_value(buf, sizeof(buf), "fd", p) > 0) { - static const char * const fd_params[] = { - "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); - goto out; - } - 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 - }; - if (check_params(chkbuf, sizeof(chkbuf), listen_params, p) < 0) { - config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p); - ret = -1; - goto out; - } - ret = net_socket_listen_init(vlan, device, name, buf); - } else if (get_param_value(buf, sizeof(buf), "connect", p) > 0) { - static const char * const connect_params[] = { - "vlan", "name", "connect", NULL - }; - if (check_params(chkbuf, sizeof(chkbuf), connect_params, p) < 0) { - config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p); - ret = -1; - goto out; - } - ret = net_socket_connect_init(vlan, device, name, buf); - } else if (get_param_value(buf, sizeof(buf), "mcast", p) > 0) { - static const char * const mcast_params[] = { - "vlan", "name", "mcast", NULL - }; - if (check_params(chkbuf, sizeof(chkbuf), mcast_params, p) < 0) { - config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p); - ret = -1; - goto out; - } - ret = net_socket_mcast_init(vlan, device, name, buf); - } else { - config_error(mon, "Unknown socket options: %s\n", p); - ret = -1; - goto out; - } - vlan->nb_host_devs++; - } else #ifdef CONFIG_VDE if (!strcmp(device, "vde")) { static const char * const vde_params[] = {