Bug 712046

Summary: Qemu allocates an existed macaddress to hotpluged nic
Product: Red Hat Enterprise Linux 6 Reporter: Amos Kong <akong>
Component: qemu-kvmAssignee: Marcelo Tosatti <mtosatti>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: medium    
Version: 6.2CC: ailan, gcosta, juzhang, mkenneth, tburke, virt-maint
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: qemu-kvm-0.12.1.2-2.176.el6 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-12-06 15:52:17 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 580954    

Description Amos Kong 2011-06-09 11:08:01 UTC
Description of problem:
Boot up guest with no network related parameters, then guest would have a default rtl8139 nic with default macaddress(52:54:00:12:34:56).
And try to hotplug a new nic to guest by monitor, but qemu also allocate (52:54:00:12:34:56) to the new nic.


Version-Release number of selected component (if applicable):
qemu-kvm-0.12.1.2-2.162.el6.x86_64

How reproducible:
100%

Steps to Reproduce:
1. boot up guest with no network related parameters
# qemu-kvm -boot n -monitor stdio
(qemu) info network
VLAN 0 devices:
  user.0: net=10.0.2.0, restricted=n
  rtl8139.0: model=rtl8139,macaddr=52:54:00:12:34:56
Devices not on any VLAN:
2. hotplug a new nic to guest
(qemu) netdev_add tap,id=h1
(qemu) device_add virtio-net-pci,netdev=h1
3. check the network info by monitor
(qemu) info network
VLAN 0 devices:
  user.0: net=10.0.2.0, restricted=n
  rtl8139.0: model=rtl8139,macaddr=52:54:00:12:34:56
Devices not on any VLAN:
  h1: ifname=tap0,script=/etc/qemu-ifup,downscript=/etc/qemu-ifdown peer=virtio-net-pci.0
  virtio-net-pci.0: model=virtio-net-pci,macaddr=52:54:00:12:34:56 peer=h1
4. login guest and check the nic info
guest)# ifconfig 

  
Actual results:
The second nic got a same macaddress as 1th nic.

Expected results:
The second nic got a different macaddress.

Additional info:

default nic has a default mac address:
net.c:
 798 static int net_init_nic(QemuOpts *opts,
 799                         Monitor *mon,
 800                         const char *name,
 801                         VLANState *vlan)
 802 {
.....
 837     nd->macaddr[0] = 0x52;
 838     nd->macaddr[1] = 0x54;
 839     nd->macaddr[2] = 0x00;
 840     nd->macaddr[3] = 0x12;
 841     nd->macaddr[4] = 0x34;
 842     nd->macaddr[5] = 0x56 + idx;
                                  ^ idx=0


hotpluged nic got mac from this function:
net.c:
 176 void qemu_macaddr_default_if_unset(MACAddr *macaddr)
 177 {
 178     static int index = 0;
 179     static const MACAddr zero = { .a = { 0,0,0,0,0,0 } };
 180 
 181     if (memcmp(macaddr, &zero, sizeof(zero)) != 0)
 182         return;
 183     macaddr->a[0] = 0x52;
 184     macaddr->a[1] = 0x54;
 185     macaddr->a[2] = 0x00;
 186     macaddr->a[3] = 0x12;
 187     macaddr->a[4] = 0x34;
 188     macaddr->a[5] = 0x56 + index++;
                                ^ index=0

Comment 1 Amos Kong 2011-06-09 11:08:45 UTC
This bug also exists in qemu-kvm upstream.

Comment 7 Amos Kong 2011-08-04 01:38:23 UTC
Bug exists in qemu-kvm-0.12.1.2-2.171.el6.x86_64, and it could not be reproduced with qemu-kvm-0.12.1.2-2.176.el6.x86_64
So moving to VERIFIED.

Comment 8 errata-xmlrpc 2011-12-06 15:52:17 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

http://rhn.redhat.com/errata/RHSA-2011-1531.html