From patchwork Fri Oct 16 13:41:55 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 36220 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 046D6B7BB2 for ; Sat, 17 Oct 2009 01:25:36 +1100 (EST) Received: from localhost ([127.0.0.1]:36866 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MynkK-00025E-P5 for incoming@patchwork.ozlabs.org; Fri, 16 Oct 2009 10:25:32 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Myn4X-0001u6-Bf for qemu-devel@nongnu.org; Fri, 16 Oct 2009 09:42:21 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Myn4P-0001q5-Ja for qemu-devel@nongnu.org; Fri, 16 Oct 2009 09:42:17 -0400 Received: from [199.232.76.173] (port=40518 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Myn4M-0001pA-Go for qemu-devel@nongnu.org; Fri, 16 Oct 2009 09:42:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:5730) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Myn4M-0007n3-54 for qemu-devel@nongnu.org; Fri, 16 Oct 2009 09:42:10 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9GDg8MQ001952 for ; Fri, 16 Oct 2009 09:42:08 -0400 Received: from zweiblum.home.kraxel.org (vpn2-9-112.ams2.redhat.com [10.36.9.112]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id n9GDg5QV028715; Fri, 16 Oct 2009 09:42:06 -0400 Received: by zweiblum.home.kraxel.org (Postfix, from userid 500) id D88A0700E5; Fri, 16 Oct 2009 15:42:03 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 16 Oct 2009 15:41:55 +0200 Message-Id: <1255700523-15270-3-git-send-email-kraxel@redhat.com> In-Reply-To: <1255700523-15270-1-git-send-email-kraxel@redhat.com> References: <1255700523-15270-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [RfC PATCH v3 02/10] qdev: mac addr property fixups 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: Gerd Hoffmann --- hw/qdev-properties.c | 31 +++++++++++++++++++++---------- hw/qdev.h | 3 ++- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c index 5c627fa..1d68125 100644 --- a/hw/qdev-properties.c +++ b/hw/qdev-properties.c @@ -1,4 +1,5 @@ #include "sysemu.h" +#include "net.h" #include "qdev.h" void *qdev_get_prop_ptr(DeviceState *dev, Property *prop) @@ -274,7 +275,7 @@ PropertyInfo qdev_prop_ptr = { */ static int parse_mac(DeviceState *dev, Property *prop, const char *str) { - uint8_t *mac = qdev_get_prop_ptr(dev, prop); + MACAddr *mac = qdev_get_prop_ptr(dev, prop); int i, pos; char *p; @@ -283,26 +284,31 @@ static int parse_mac(DeviceState *dev, Property *prop, const char *str) return -1; if (!qemu_isxdigit(str[pos+1])) return -1; - if (i == 5 && str[pos+2] != '\0') - return -1; - if (str[pos+2] != ':' && str[pos+2] != '-') - return -1; - mac[i] = strtol(str+pos, &p, 16); + if (i == 5) { + if (str[pos+2] != '\0') + return -1; + } else { + if (str[pos+2] != ':' && str[pos+2] != '-') + return -1; + } + mac->a[i] = strtol(str+pos, &p, 16); } return 0; } static int print_mac(DeviceState *dev, Property *prop, char *dest, size_t len) { - uint8_t *mac = qdev_get_prop_ptr(dev, prop); + MACAddr *mac = qdev_get_prop_ptr(dev, prop); + return snprintf(dest, len, "%02x:%02x:%02x:%02x:%02x:%02x", - mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + mac->a[0], mac->a[1], mac->a[2], + mac->a[3], mac->a[4], mac->a[5]); } PropertyInfo qdev_prop_macaddr = { - .name = "mac-addr", + .name = "macaddr", .type = PROP_TYPE_MACADDR, - .size = 6, + .size = sizeof(MACAddr), .parse = parse_mac, .print = print_mac, }; @@ -454,6 +460,11 @@ void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *valu qdev_prop_set(dev, name, &value, PROP_TYPE_CHR); } +void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value) +{ + qdev_prop_set(dev, name, value, PROP_TYPE_MACADDR); +} + void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value) { qdev_prop_set(dev, name, &value, PROP_TYPE_PTR); diff --git a/hw/qdev.h b/hw/qdev.h index 8cd843e..118e886 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -230,7 +230,7 @@ extern PropertyInfo qdev_prop_pci_devfn; #define DEFINE_PROP_DRIVE(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_drive, DriveInfo*) #define DEFINE_PROP_MACADDR(_n, _s, _f) \ - DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, uint8_t[6]) + DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr) #define DEFINE_PROP_END_OF_LIST() \ {} @@ -246,6 +246,7 @@ void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value); void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value); void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value); void qdev_prop_set_drive(DeviceState *dev, const char *name, DriveInfo *value); +void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value); /* FIXME: Remove opaque pointer properties. */ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value); void qdev_prop_set_defaults(DeviceState *dev, Property *props);