From patchwork Wed Jun 13 08:22:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laszlo Ersek X-Patchwork-Id: 164585 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BE0F5B7001 for ; Wed, 13 Jun 2012 19:32:33 +1000 (EST) Received: from localhost ([::1]:58631 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SeirJ-0003BI-Tc for incoming@patchwork.ozlabs.org; Wed, 13 Jun 2012 04:23:21 -0400 Received: from eggs.gnu.org ([208.118.235.92]:35843) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SeiqU-0001dP-DZ for qemu-devel@nongnu.org; Wed, 13 Jun 2012 04:22:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Seipz-0003h1-TB for qemu-devel@nongnu.org; Wed, 13 Jun 2012 04:22:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58360) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Seipz-0003gE-Kr for qemu-devel@nongnu.org; Wed, 13 Jun 2012 04:21:59 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q5D8LwN3005134 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 13 Jun 2012 04:21:58 -0400 Received: from lacos-laptop.usersys.redhat.com (vpn1-5-237.ams2.redhat.com [10.36.5.237]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q5D8Lfmq031699; Wed, 13 Jun 2012 04:21:57 -0400 From: Laszlo Ersek To: qemu-devel@nongnu.org, lersek@redhat.com Date: Wed, 13 Jun 2012 10:22:43 +0200 Message-Id: <1339575768-2557-13-git-send-email-lersek@redhat.com> In-Reply-To: <1339575768-2557-1-git-send-email-lersek@redhat.com> References: <1339575768-2557-1-git-send-email-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 12/17] convert net_init_slirp() to NetClientOptions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Laszlo Ersek --- net/slirp.c | 93 ++++++++++++++++------------------------------------------- 1 files changed, 25 insertions(+), 68 deletions(-) diff --git a/net/slirp.c b/net/slirp.c index 9b925b7..166304c 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -654,89 +654,46 @@ void do_info_usernet(Monitor *mon) } } -static int net_init_slirp_configs(const char *name, const char *value, void *opaque) +static void +net_init_slirp_configs(const StringList *fwd, int flags) { - struct slirp_config_str *config; - - if (strcmp(name, "hostfwd") != 0 && strcmp(name, "guestfwd") != 0) { - return 0; - } - - config = g_malloc0(sizeof(*config)); + while (fwd) { + struct slirp_config_str *config; - pstrcpy(config->str, sizeof(config->str), value); + config = g_malloc0(sizeof(*config)); + pstrcpy(config->str, sizeof(config->str), fwd->value->str); + config->flags = flags; + config->next = slirp_configs; + slirp_configs = config; - if (!strcmp(name, "hostfwd")) { - config->flags = SLIRP_CFG_HOSTFWD; + fwd = fwd->next; } - - config->next = slirp_configs; - slirp_configs = config; - - return 0; } -int net_init_slirp(QemuOpts *opts, const NetClientOptions *new_opts, +int net_init_slirp(QemuOpts *old_opts, const NetClientOptions *opts, const char *name, VLANState *vlan) { struct slirp_config_str *config; - const char *vhost; - const char *vhostname; - const char *vdhcp_start; - const char *vnamesrv; - const char *tftp_export; - const char *bootfile; - const char *smb_export; - const char *vsmbsrv; - const char *restrict_opt; - char *vnet = NULL; - int restricted = 0; + char *vnet; int ret; + const NetdevUserOptions *user; - vhost = qemu_opt_get(opts, "host"); - vhostname = qemu_opt_get(opts, "hostname"); - vdhcp_start = qemu_opt_get(opts, "dhcpstart"); - vnamesrv = qemu_opt_get(opts, "dns"); - tftp_export = qemu_opt_get(opts, "tftp"); - bootfile = qemu_opt_get(opts, "bootfile"); - smb_export = qemu_opt_get(opts, "smb"); - vsmbsrv = qemu_opt_get(opts, "smbserver"); - - restrict_opt = qemu_opt_get(opts, "restrict"); - if (restrict_opt) { - if (!strcmp(restrict_opt, "on") || - !strcmp(restrict_opt, "yes") || !strcmp(restrict_opt, "y")) { - restricted = 1; - } else if (strcmp(restrict_opt, "off") && - strcmp(restrict_opt, "no") && strcmp(restrict_opt, "n")) { - error_report("invalid option: 'restrict=%s'", restrict_opt); - return -1; - } - } - - if (qemu_opt_get(opts, "ip")) { - const char *ip = qemu_opt_get(opts, "ip"); - int l = strlen(ip) + strlen("/24") + 1; + assert(opts->kind == NET_CLIENT_OPTIONS_KIND_USER); + user = opts->user; - vnet = g_malloc(l); + vnet = user->has_net ? g_strdup(user->net) : + user->has_ip ? g_strdup_printf("%s/24", user->ip) : + NULL; - /* emulate legacy ip= parameter */ - pstrcpy(vnet, l, ip); - pstrcat(vnet, l, "/24"); - } - - if (qemu_opt_get(opts, "net")) { - if (vnet) { - g_free(vnet); - } - vnet = g_strdup(qemu_opt_get(opts, "net")); - } + /* all optional fields are initialized to "all bits zero" */ - qemu_opt_foreach(opts, net_init_slirp_configs, NULL, 0); + net_init_slirp_configs(user->hostfwd, SLIRP_CFG_HOSTFWD); + net_init_slirp_configs(user->guestfwd, 0); - ret = net_slirp_init(vlan, "user", name, restricted, vnet, vhost, - vhostname, tftp_export, bootfile, vdhcp_start, - vnamesrv, smb_export, vsmbsrv); + ret = net_slirp_init(vlan, "user", name, user->restrict, vnet, user->host, + user->hostname, user->tftp, user->bootfile, + user->dhcpstart, user->dns, user->smb, + user->smbserver); while (slirp_configs) { config = slirp_configs;