From patchwork Wed Nov 25 18:49:06 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark McLoughlin X-Patchwork-Id: 39432 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 46F791007D1 for ; Thu, 26 Nov 2009 06:27:22 +1100 (EST) Received: from localhost ([127.0.0.1]:52935 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDNWJ-00019F-Il for incoming@patchwork.ozlabs.org; Wed, 25 Nov 2009 14:27:19 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NDMym-0007Rp-6v for qemu-devel@nongnu.org; Wed, 25 Nov 2009 13:52:40 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NDMyZ-0007Hc-KT for qemu-devel@nongnu.org; Wed, 25 Nov 2009 13:52:33 -0500 Received: from [199.232.76.173] (port=48997 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDMyY-0007H4-2B for qemu-devel@nongnu.org; Wed, 25 Nov 2009 13:52:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:5987) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NDMyX-0000EJ-CE for qemu-devel@nongnu.org; Wed, 25 Nov 2009 13:52:25 -0500 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nAPIqOC4030549 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 25 Nov 2009 13:52:24 -0500 Received: from blaa.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nAPIqNOV031167; Wed, 25 Nov 2009 13:52:23 -0500 Received: by blaa.localdomain (Postfix, from userid 500) id D38C3B07D; Wed, 25 Nov 2009 18:49:40 +0000 (GMT) From: Mark McLoughlin To: qemu-devel@nongnu.org Date: Wed, 25 Nov 2009 18:49:06 +0000 Message-Id: <1259174977-26212-14-git-send-email-markmc@redhat.com> In-Reply-To: <1259174977-26212-1-git-send-email-markmc@redhat.com> References: <1259174977-26212-1-git-send-email-markmc@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Mark McLoughlin Subject: [Qemu-devel] [PATCH 13/44] net: convert slirp to NetClientInfo 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/slirp.c | 61 +++++++++++++++++++++++++++++++++++----------------------- 1 files changed, 37 insertions(+), 24 deletions(-) diff --git a/net/slirp.c b/net/slirp.c index d6d5772..3f91c4b 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -64,8 +64,8 @@ struct slirp_config_str { }; typedef struct SlirpState { + VLANClientState nc; QTAILQ_ENTRY(SlirpState) entry; - VLANClientState *vc; Slirp *slirp; #ifndef _WIN32 char smb_dir[128]; @@ -97,35 +97,41 @@ int slirp_can_output(void *opaque) { SlirpState *s = opaque; - return qemu_can_send_packet(s->vc); + return qemu_can_send_packet(&s->nc); } void slirp_output(void *opaque, const uint8_t *pkt, int pkt_len) { SlirpState *s = opaque; - qemu_send_packet(s->vc, pkt, pkt_len); + qemu_send_packet(&s->nc, pkt, pkt_len); } -static ssize_t slirp_receive(VLANClientState *vc, const uint8_t *buf, size_t size) +static ssize_t net_slirp_receive(VLANClientState *nc, const uint8_t *buf, size_t size) { - SlirpState *s = vc->opaque; + SlirpState *s = DO_UPCAST(SlirpState, nc, nc); slirp_input(s->slirp, buf, size); return size; } -static void net_slirp_cleanup(VLANClientState *vc) +static void net_slirp_cleanup(VLANClientState *nc) { - SlirpState *s = vc->opaque; + SlirpState *s = DO_UPCAST(SlirpState, nc, nc); slirp_cleanup(s->slirp); slirp_smb_cleanup(s); QTAILQ_REMOVE(&slirp_stacks, s, entry); - qemu_free(s); } +static NetClientInfo net_slirp_info = { + .type = NET_CLIENT_TYPE_SLIRP, + .size = sizeof(SlirpState), + .receive = net_slirp_receive, + .cleanup = net_slirp_cleanup, +}; + static int net_slirp_init(VLANState *vlan, const char *model, const char *name, int restricted, const char *vnetwork, const char *vhost, @@ -143,6 +149,7 @@ static int net_slirp_init(VLANState *vlan, const char *model, #ifndef _WIN32 struct in_addr smbsrv = { .s_addr = 0 }; #endif + VLANClientState *nc; SlirpState *s; char buf[20]; uint32_t addr; @@ -228,7 +235,13 @@ static int net_slirp_init(VLANState *vlan, const char *model, } #endif - s = qemu_mallocz(sizeof(SlirpState)); + nc = qemu_new_net_client(&net_slirp_info, vlan, NULL, model, name); + + snprintf(nc->info_str, sizeof(nc->info_str), + "net=%s, restricted=%c", inet_ntoa(net), restricted ? 'y' : 'n'); + + s = DO_UPCAST(SlirpState, nc, nc); + s->slirp = slirp_init(restricted, net, mask, host, vhostname, tftp_export, bootfile, dhcp, dns, s); QTAILQ_INSERT_TAIL(&slirp_stacks, s, entry); @@ -237,11 +250,11 @@ static int net_slirp_init(VLANState *vlan, const char *model, if (config->flags & SLIRP_CFG_HOSTFWD) { if (slirp_hostfwd(s, config->str, config->flags & SLIRP_CFG_LEGACY) < 0) - return -1; + goto error; } else { if (slirp_guestfwd(s, config->str, config->flags & SLIRP_CFG_LEGACY) < 0) - return -1; + goto error; } } #ifndef _WIN32 @@ -250,34 +263,32 @@ static int net_slirp_init(VLANState *vlan, const char *model, } if (smb_export) { if (slirp_smb(s, smb_export, smbsrv) < 0) - return -1; + goto error; } #endif - s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_SLIRP, - vlan, NULL, model, name, NULL, - slirp_receive, NULL, NULL, - net_slirp_cleanup, s); - snprintf(s->vc->info_str, sizeof(s->vc->info_str), - "net=%s, restricted=%c", inet_ntoa(net), restricted ? 'y' : 'n'); return 0; + +error: + qemu_del_vlan_client(nc); + return -1; } static SlirpState *slirp_lookup(Monitor *mon, const char *vlan, const char *stack) { - VLANClientState *vc; if (vlan) { - vc = qemu_find_vlan_client_by_name(mon, strtol(vlan, NULL, 0), stack); - if (!vc) { + VLANClientState *nc; + nc = qemu_find_vlan_client_by_name(mon, strtol(vlan, NULL, 0), stack); + if (!nc) { return NULL; } - if (strcmp(vc->model, "user")) { + if (strcmp(nc->model, "user")) { monitor_printf(mon, "invalid device specified\n"); return NULL; } - return vc->opaque; + return DO_UPCAST(SlirpState, nc, nc); } else { if (QTAILQ_EMPTY(&slirp_stacks)) { monitor_printf(mon, "user mode network stack not in use\n"); @@ -626,7 +637,9 @@ void do_info_usernet(Monitor *mon) SlirpState *s; QTAILQ_FOREACH(s, &slirp_stacks, entry) { - monitor_printf(mon, "VLAN %d (%s):\n", s->vc->vlan->id, s->vc->name); + monitor_printf(mon, "VLAN %d (%s):\n", + s->nc.vlan ? s->nc.vlan->id : -1, + s->nc.name); slirp_connection_info(s->slirp, mon); } }