From patchwork Tue May 18 17:07:41 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Di Ciurcio Filho X-Patchwork-Id: 52901 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 BC055B7D6A for ; Wed, 19 May 2010 03:33:55 +1000 (EST) Received: from localhost ([127.0.0.1]:36379 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OEQfu-0006Sc-Pd for incoming@patchwork.ozlabs.org; Tue, 18 May 2010 13:33:50 -0400 Received: from [140.186.70.92] (port=32823 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OEQRc-0006Pi-M5 for qemu-devel@nongnu.org; Tue, 18 May 2010 13:19:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OEQH8-0005RV-47 for qemu-devel@nongnu.org; Tue, 18 May 2010 13:08:22 -0400 Received: from mail-yw0-f184.google.com ([209.85.211.184]:51679) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OEQH7-0005QE-LY for qemu-devel@nongnu.org; Tue, 18 May 2010 13:08:13 -0400 Received: by mail-yw0-f184.google.com with SMTP id 14so3433770ywh.25 for ; Tue, 18 May 2010 10:08:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer:in-reply-to:references; bh=7bcuFXc4ZfHQ98u/405vqtv/d/sOSNxsuQRLMNcxBrA=; b=EdAknSTjwUKd4Yt7R20MfwAzY9pitsTiREqqz6FoDzxfUdwpKvNz6tWw2+jXgqC20w Vv0kNZXFT42HU/BsB+ve4OTz2IvZcL+uPtqVdbO+rp6wjKYE//6h4rjXMB4t8IOqhrTe pbpcrBiVogUKk9s0pUibyQCiR2qV62IbK9cEY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=IJteL4ntx9dc999LUicoaOlbDnhCjlPflMprm019y9fZH8+WB+MmyrHcZAoOZk1Pol dkdnoLHqj/7Bm5JmGOjop4n0R4PzLHWmEtI54SwTxryoX6FiEyyeKXYOcQfw6izAeZOy V4H538VroUrMoYPlUINSivbq6G2C/Jug0kiuc= Received: by 10.150.179.21 with SMTP id b21mr7670951ybf.217.1274202492803; Tue, 18 May 2010 10:08:12 -0700 (PDT) Received: from localhost.localdomain (quake.ic.unicamp.br [143.106.7.51]) by mx.google.com with ESMTPS id k30sm58427272ybb.19.2010.05.18.10.08.10 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 18 May 2010 10:08:12 -0700 (PDT) From: Miguel Di Ciurcio Filho To: qemu-devel@nongnu.org Date: Tue, 18 May 2010 14:07:41 -0300 Message-Id: <1274202469-9332-3-git-send-email-miguel.filho@gmail.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1274202469-9332-1-git-send-email-miguel.filho@gmail.com> References: <1274202469-9332-1-git-send-email-miguel.filho@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: armbru@redhat.com, lcapitulino@redhat.com Subject: [Qemu-devel] [PATCH v4 02/10] net: introduce qemu_nic_format_info_dict and VLANClientState->info_dict 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 There is no standard format when formatting VLANClientState.info_str, so it is difficult to extract information and transmit it over QMP. This patch adds info_dict, a QDict to better handle the information of a NIC. Signed-off-by: Miguel Di Ciurcio Filho --- net.c | 17 +++++++++++++++++ net.h | 2 ++ 2 files changed, 19 insertions(+), 0 deletions(-) diff --git a/net.c b/net.c index efa8b3d..9e8a8ab 100644 --- a/net.c +++ b/net.c @@ -173,6 +173,22 @@ void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]) macaddr[3], macaddr[4], macaddr[5]); } +void qemu_format_nic_info_dict(VLANClientState *vc, uint8_t macaddr[6]) +{ + char mac[18]; + + if (vc->info_dict == NULL) { + vc->info_dict = qdict_new(); + } + + snprintf(mac, sizeof(mac), "%02x:%02x:%02x:%02x:%02x:%02x", + macaddr[0], macaddr[1], macaddr[2], + macaddr[3], macaddr[4], macaddr[5]); + + qdict_put(vc->info_dict, "macaddr", qstring_from_str(mac)); + qdict_put(vc->info_dict, "model", qstring_from_str(vc->model)); +} + void qemu_macaddr_default_if_unset(MACAddr *macaddr) { static int index = 0; @@ -301,6 +317,7 @@ void qemu_del_vlan_client(VLANClientState *vc) qemu_free(vc->name); qemu_free(vc->model); + QDECREF(vc->info_dict); qemu_free(vc); } diff --git a/net.h b/net.h index b83f615..4566f7d 100644 --- a/net.h +++ b/net.h @@ -66,6 +66,7 @@ struct VLANClientState { char *model; char *name; char info_str[256]; + QDict *info_dict; unsigned receive_disabled : 1; }; @@ -111,6 +112,7 @@ ssize_t qemu_send_packet_async(VLANClientState *vc, const uint8_t *buf, void qemu_purge_queued_packets(VLANClientState *vc); void qemu_flush_queued_packets(VLANClientState *vc); void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]); +void qemu_format_nic_info_dict(VLANClientState *vc, uint8_t macaddr[6]); void qemu_macaddr_default_if_unset(MACAddr *macaddr); int qemu_show_nic_models(const char *arg, const char *const *models); void qemu_check_nic_model(NICInfo *nd, const char *model);