From patchwork Fri Sep 25 19:43:02 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 34302 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 839D1B7BA4 for ; Sat, 26 Sep 2009 06:26:20 +1000 (EST) Received: from localhost ([127.0.0.1]:50020 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MrHMv-0000Fd-Ss for incoming@patchwork.ozlabs.org; Fri, 25 Sep 2009 16:26:17 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MrGhL-0006aH-Je for qemu-devel@nongnu.org; Fri, 25 Sep 2009 15:43:19 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MrGhH-0006VG-B8 for qemu-devel@nongnu.org; Fri, 25 Sep 2009 15:43:18 -0400 Received: from [199.232.76.173] (port=56064 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MrGhG-0006Uv-Bf for qemu-devel@nongnu.org; Fri, 25 Sep 2009 15:43:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15105) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MrGhF-0004gK-R3 for qemu-devel@nongnu.org; Fri, 25 Sep 2009 15:43:14 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n8PJhD44018884 for ; Fri, 25 Sep 2009 15:43:13 -0400 Received: from zweiblum.home.kraxel.org (vpn2-8-108.ams2.redhat.com [10.36.8.108]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id n8PJgusW028042; Fri, 25 Sep 2009 15:43:06 -0400 Received: by zweiblum.home.kraxel.org (Postfix, from userid 500) id F1E6B700E6; Fri, 25 Sep 2009 21:43:03 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 25 Sep 2009 21:43:02 +0200 Message-Id: <1253907783-1231-3-git-send-email-kraxel@redhat.com> In-Reply-To: <1253907783-1231-1-git-send-email-kraxel@redhat.com> References: <1253907783-1231-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [RfC PATCH 2/3] 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 --- 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 2ecb58d..89e45e1 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) @@ -246,7 +247,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_t *mac = qdev_get_prop_ptr(dev, prop); int i, pos; char *p; @@ -255,26 +256,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)[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_t *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)[0], (*mac)[1], (*mac)[2], + (*mac)[3], (*mac)[4], (*mac)[5]); } PropertyInfo qdev_prop_macaddr = { - .name = "mac-addr", + .name = "macaddr", .type = PROP_TYPE_MACADDR, - .size = 6, + .size = sizeof(macaddr_t), .parse = parse_mac, .print = print_mac, }; @@ -421,6 +427,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, macaddr_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 623ded5..7a081f8 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -203,7 +203,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_t) #define DEFINE_PROP_END_OF_LIST() \ {} @@ -218,6 +218,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);