qdev: mac addr property fixups
Make the mac property use the newly added type for the mac address. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
		
							parent
							
								
									76d32cba7e
								
							
						
					
					
						commit
						1503fff343
					
				@ -1,4 +1,5 @@
 | 
				
			|||||||
#include "sysemu.h"
 | 
					#include "sysemu.h"
 | 
				
			||||||
 | 
					#include "net.h"
 | 
				
			||||||
#include "qdev.h"
 | 
					#include "qdev.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void *qdev_get_prop_ptr(DeviceState *dev, Property *prop)
 | 
					void *qdev_get_prop_ptr(DeviceState *dev, Property *prop)
 | 
				
			||||||
@ -302,7 +303,7 @@ PropertyInfo qdev_prop_ptr = {
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
static int parse_mac(DeviceState *dev, Property *prop, const char *str)
 | 
					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;
 | 
					    int i, pos;
 | 
				
			||||||
    char *p;
 | 
					    char *p;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -311,26 +312,31 @@ static int parse_mac(DeviceState *dev, Property *prop, const char *str)
 | 
				
			|||||||
            return -1;
 | 
					            return -1;
 | 
				
			||||||
        if (!qemu_isxdigit(str[pos+1]))
 | 
					        if (!qemu_isxdigit(str[pos+1]))
 | 
				
			||||||
            return -1;
 | 
					            return -1;
 | 
				
			||||||
        if (i == 5 && str[pos+2] != '\0')
 | 
					        if (i == 5) {
 | 
				
			||||||
 | 
					            if (str[pos+2] != '\0')
 | 
				
			||||||
                return -1;
 | 
					                return -1;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
            if (str[pos+2] != ':' && str[pos+2] != '-')
 | 
					            if (str[pos+2] != ':' && str[pos+2] != '-')
 | 
				
			||||||
                return -1;
 | 
					                return -1;
 | 
				
			||||||
        mac[i] = strtol(str+pos, &p, 16);
 | 
					        }
 | 
				
			||||||
 | 
					        mac->a[i] = strtol(str+pos, &p, 16);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int print_mac(DeviceState *dev, Property *prop, char *dest, size_t len)
 | 
					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",
 | 
					    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 = {
 | 
					PropertyInfo qdev_prop_macaddr = {
 | 
				
			||||||
    .name  = "mac-addr",
 | 
					    .name  = "macaddr",
 | 
				
			||||||
    .type  = PROP_TYPE_MACADDR,
 | 
					    .type  = PROP_TYPE_MACADDR,
 | 
				
			||||||
    .size  = 6,
 | 
					    .size  = sizeof(MACAddr),
 | 
				
			||||||
    .parse = parse_mac,
 | 
					    .parse = parse_mac,
 | 
				
			||||||
    .print = print_mac,
 | 
					    .print = print_mac,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
@ -482,6 +488,11 @@ void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *valu
 | 
				
			|||||||
    qdev_prop_set(dev, name, &value, PROP_TYPE_CHR);
 | 
					    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)
 | 
					void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    qdev_prop_set(dev, name, &value, PROP_TYPE_PTR);
 | 
					    qdev_prop_set(dev, name, &value, PROP_TYPE_PTR);
 | 
				
			||||||
 | 
				
			|||||||
@ -234,7 +234,7 @@ extern PropertyInfo qdev_prop_pci_devfn;
 | 
				
			|||||||
#define DEFINE_PROP_DRIVE(_n, _s, _f)             \
 | 
					#define DEFINE_PROP_DRIVE(_n, _s, _f)             \
 | 
				
			||||||
    DEFINE_PROP(_n, _s, _f, qdev_prop_drive, DriveInfo*)
 | 
					    DEFINE_PROP(_n, _s, _f, qdev_prop_drive, DriveInfo*)
 | 
				
			||||||
#define DEFINE_PROP_MACADDR(_n, _s, _f)         \
 | 
					#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()               \
 | 
					#define DEFINE_PROP_END_OF_LIST()               \
 | 
				
			||||||
    {}
 | 
					    {}
 | 
				
			||||||
@ -250,6 +250,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_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_chr(DeviceState *dev, const char *name, CharDriverState *value);
 | 
				
			||||||
void qdev_prop_set_drive(DeviceState *dev, const char *name, DriveInfo *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.  */
 | 
					/* FIXME: Remove opaque pointer properties.  */
 | 
				
			||||||
void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
 | 
					void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
 | 
				
			||||||
void qdev_prop_set_defaults(DeviceState *dev, Property *props);
 | 
					void qdev_prop_set_defaults(DeviceState *dev, Property *props);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user