]> git.proxmox.com Git - qemu.git/commitdiff
net: Consistently use qemu_macaddr_default_if_unset
authorJan Kiszka <jan.kiszka@siemens.com>
Wed, 20 Jul 2011 10:20:22 +0000 (12:20 +0200)
committerAnthony Liguori <aliguori@us.ibm.com>
Sat, 23 Jul 2011 15:19:50 +0000 (10:19 -0500)
Drop the open-coded MAC assignment from net_init_nic and replace it with
standard qemu_macaddr_default_if_unset which is also used by qdev. That
avoid creating colliding MACs when instantiating NICs via different
mechanisms.

This change requires to store the MAC as MACAddr in NICInfo, and the
remaining nd_table users need to be updated.

Based on suggestion by Peter Maydell.

CC: Markus Armbruster <armbru@redhat.com>
CC: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
hw/dp8393x.c
hw/etraxfs_eth.c
hw/mcf_fec.c
hw/mipsnet.c
hw/qdev.c
hw/stellaris.c
hw/xen_devconfig.c
net.c
net.h

index c332dd59d285c2972ec6d47603835d311b272e16..1bcd8eeba9e650dd8c28efebccec7f4e3062076f 100644 (file)
@@ -898,7 +898,7 @@ void dp83932_init(NICInfo *nd, target_phys_addr_t base, int it_shift,
     s->watchdog = qemu_new_timer_ns(vm_clock, dp8393x_watchdog, s);
     s->regs[SONIC_SR] = 0x0004; /* only revision recognized by Linux */
 
-    memcpy(s->conf.macaddr.a, nd->macaddr, sizeof(s->conf.macaddr));
+    s->conf.macaddr = nd->macaddr;
     s->conf.vlan = nd->vlan;
     s->conf.peer = nd->netdev;
 
index 6aa4007203d1d3a0fbf072e648627e5f5919234d..dff5f55f3316ebf5df65707723f25dca8008bcdb 100644 (file)
@@ -602,7 +602,7 @@ void *etraxfs_eth_init(NICInfo *nd, target_phys_addr_t base, int phyaddr)
                                               DEVICE_NATIVE_ENDIAN);
        cpu_register_physical_memory (base, 0x5c, eth->ethregs);
 
-       memcpy(eth->conf.macaddr.a, nd->macaddr, sizeof(nd->macaddr));
+       eth->conf.macaddr = nd->macaddr;
        eth->conf.vlan = nd->vlan;
        eth->conf.peer = nd->netdev;
 
index 21035da3451eb485692a5d19ad74cf66a526b11e..5477e0e159db9ea04688d928a9617c9fc96c4084 100644 (file)
@@ -471,7 +471,7 @@ void mcf_fec_init(NICInfo *nd, target_phys_addr_t base, qemu_irq *irq)
                                            DEVICE_NATIVE_ENDIAN);
     cpu_register_physical_memory(base, 0x400, s->mmio_index);
 
-    memcpy(s->conf.macaddr.a, nd->macaddr, sizeof(nd->macaddr));
+    s->conf.macaddr = nd->macaddr;
     s->conf.vlan = nd->vlan;
     s->conf.peer = nd->netdev;
 
index 26aad51eab7dd5fedde3f9120c3056f6ac2f929e..0db3ba7a89f619cc1b06c108699c0860f4e0e2a8 100644 (file)
@@ -258,7 +258,7 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd)
     s->irq = irq;
 
     if (nd) {
-        memcpy(s->conf.macaddr.a, nd->macaddr, sizeof(nd->macaddr));
+        s->conf.macaddr = nd->macaddr;
         s->conf.vlan = nd->vlan;
         s->conf.peer = nd->netdev;
 
index 292b52f8c542d3e7f2456cdeea9003f5c6284a52..a0fcd0609424ec468e843219cdac2c87e82aed06 100644 (file)
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -459,7 +459,7 @@ void qdev_connect_gpio_out(DeviceState * dev, int n, qemu_irq pin)
 
 void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd)
 {
-    qdev_prop_set_macaddr(dev, "mac", nd->macaddr);
+    qdev_prop_set_macaddr(dev, "mac", nd->macaddr.a);
     if (nd->vlan)
         qdev_prop_set_vlan(dev, "vlan", nd->vlan);
     if (nd->netdev)
index ac9fcc1f38d54ee83d6b45a6644ef49ec73d5946..b8a7cebd8cf8c01bad9773ccd78433dd5cf69316 100644 (file)
@@ -1230,7 +1230,7 @@ static void stellaris_init(const char *kernel_filename, const char *cpu_model,
         }
     }
 
-    stellaris_sys_init(0x400fe000, pic[28], board, nd_table[0].macaddr);
+    stellaris_sys_init(0x400fe000, pic[28], board, nd_table[0].macaddr.a);
 
     for (i = 0; i < 7; i++) {
         if (board->dc4 & (1 << i)) {
index 3a9215566d448f246c7415980e94497231c17645..6926c54f4f2bab118e84f49e4e729e4945af8810 100644 (file)
@@ -126,8 +126,8 @@ int xen_config_dev_nic(NICInfo *nic)
     char mac[20];
 
     snprintf(mac, sizeof(mac), "%02x:%02x:%02x:%02x:%02x:%02x",
-            nic->macaddr[0], nic->macaddr[1], nic->macaddr[2],
-            nic->macaddr[3], nic->macaddr[4], nic->macaddr[5]);
+             nic->macaddr.a[0], nic->macaddr.a[1], nic->macaddr.a[2],
+             nic->macaddr.a[3], nic->macaddr.a[4], nic->macaddr.a[5]);
     xen_be_printf(NULL, 1, "config nic %d: mac=\"%s\"\n", nic->vlan->id, mac);
     xen_config_dev_dirs("vif", "qnic", nic->vlan->id, fe, be, sizeof(fe));
 
diff --git a/net.c b/net.c
index 12701af253883737df8a7ea7421a3a97aec61690..31c23389c835f8e7fe2c31190c0063a06e16cbe4 100644 (file)
--- a/net.c
+++ b/net.c
@@ -776,18 +776,12 @@ static int net_init_nic(QemuOpts *opts,
         nd->devaddr = qemu_strdup(qemu_opt_get(opts, "addr"));
     }
 
-    nd->macaddr[0] = 0x52;
-    nd->macaddr[1] = 0x54;
-    nd->macaddr[2] = 0x00;
-    nd->macaddr[3] = 0x12;
-    nd->macaddr[4] = 0x34;
-    nd->macaddr[5] = 0x56 + idx;
-
     if (qemu_opt_get(opts, "macaddr") &&
-        net_parse_macaddr(nd->macaddr, qemu_opt_get(opts, "macaddr")) < 0) {
+        net_parse_macaddr(nd->macaddr.a, qemu_opt_get(opts, "macaddr")) < 0) {
         error_report("invalid syntax for ethernet address");
         return -1;
     }
+    qemu_macaddr_default_if_unset(&nd->macaddr);
 
     nd->nvectors = qemu_opt_get_number(opts, "vectors",
                                        DEV_NVECTORS_UNSPECIFIED);
diff --git a/net.h b/net.h
index 4fdd9420bcc6fd21b4aefa9c7e1f24d924a66eb5..5a7881cf671e231b18cb346566e20642a44c8553 100644 (file)
--- a/net.h
+++ b/net.h
@@ -129,7 +129,7 @@ int do_set_link(Monitor *mon, const QDict *qdict, QObject **ret_data);
 #define MAX_NICS 8
 
 struct NICInfo {
-    uint8_t macaddr[6];
+    MACAddr macaddr;
     char *model;
     char *name;
     char *devaddr;