From patchwork Wed Sep 23 10:24:16 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark McLoughlin X-Patchwork-Id: 34138 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 ozlabs.org (Postfix) with ESMTPS id EF0B4B7B7D for ; Wed, 23 Sep 2009 21:10:08 +1000 (EST) Received: from localhost ([127.0.0.1]:51327 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MqPjZ-0007Ar-7f for incoming@patchwork.ozlabs.org; Wed, 23 Sep 2009 07:10:05 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MqP2t-0003nq-M2 for qemu-devel@nongnu.org; Wed, 23 Sep 2009 06:25:59 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MqP2k-0003ie-AC for qemu-devel@nongnu.org; Wed, 23 Sep 2009 06:25:54 -0400 Received: from [199.232.76.173] (port=37818 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MqP2i-0003hP-Gj for qemu-devel@nongnu.org; Wed, 23 Sep 2009 06:25:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37939) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MqP2h-0001Vv-73 for qemu-devel@nongnu.org; Wed, 23 Sep 2009 06:25:47 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n8NAPkmH028207 for ; Wed, 23 Sep 2009 06:25:46 -0400 Received: from blaa.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n8NAPhbW011616; Wed, 23 Sep 2009 06:25:45 -0400 Received: by blaa.localdomain (Postfix, from userid 500) id 49F4647443; Wed, 23 Sep 2009 11:24:24 +0100 (IST) From: Mark McLoughlin To: qemu-devel@nongnu.org Date: Wed, 23 Sep 2009 11:24:16 +0100 Message-Id: <1253701463-3134-18-git-send-email-markmc@redhat.com> In-Reply-To: <1253701463-3134-1-git-send-email-markmc@redhat.com> References: <1253701463-3134-1-git-send-email-markmc@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Mark McLoughlin Subject: [Qemu-devel] [PATCH 17/24] 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 468d25c..f2bc9f8 100644 --- a/net.c +++ b/net.c @@ -2629,6 +2629,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", \ @@ -2791,6 +2874,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 */ } }; @@ -2834,7 +2941,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); @@ -2873,64 +2981,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[] = {