Bug 907779

Summary: virsh net-update can add multiple dhcp sections to ipv4 in network
Product: Red Hat Enterprise Linux 7 Reporter: hongming <honzhang>
Component: libvirtAssignee: Jiri Denemark <jdenemar>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: high    
Version: 7.0CC: cwei, dyuan, lcheng, mzhan, rbalakri
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libvirt-1.2.13-1.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-11-19 05:42:06 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description hongming 2013-02-05 09:18:46 UTC
Description of problem:
virsh net-update can add multiple dhcp sections to ipv4 in network. 

Version-Release number of selected component (if applicable):
libvirt-1.0.2-1.el7.x86_64

How reproducible:
100%

Steps to Reproduce:
# virsh net-start mynetwork
Network mynetwork started

# virsh net-dumpxml mynetwork
<network>
  <name>mynetwork</name>
  <uuid>fe8ffe14-8478-060d-ece1-2c97f96e1c59</uuid>
  <forward mode='nat'/>
  <bridge name='virbr1' stp='on' delay='0' />
  <mac address='52:54:00:E5:B6:95'/>
  <ip address='192.168.121.1' netmask='255.255.255.0'>
  </ip>
  <ip address='192.168.10.1' netmask='255.255.255.0'>
  </ip>
</network>

# virsh net-update mynetwork add ip-dhcp-host "<host mac='00:11:22:33:44:57' ip='192.168.122.47'/>" --live --config --parent-index 0
Updated network mynetwork persistent config and live state

# virsh net-update mynetwork add ip-dhcp-host "<host mac='00:11:22:33:44:58' ip='192.168.122.48'/>" --live --config --parent-index 1
Updated network mynetwork persistent config and live state


# virsh net-list --all
 Name                 State      Autostart     Persistent
----------------------------------------------------------
 default              active     yes           yes
 mynetwork            active     no            yes

# virsh net-dumpxml mynetwork<network>
  <name>mynetwork</name>
  <uuid>fe8ffe14-8478-060d-ece1-2c97f96e1c59</uuid>
  <forward mode='nat'/>
  <bridge name='virbr1' stp='on' delay='0' />
  <mac address='52:54:00:E5:B6:95'/>
  <ip address='192.168.121.1' netmask='255.255.255.0'>
    <dhcp>
      <host mac='00:11:22:33:44:57' ip='192.168.122.47' />
    </dhcp>
  </ip>
  <ip address='192.168.10.1' netmask='255.255.255.0'>
    <dhcp>
      <host mac='00:11:22:33:44:58' ip='192.168.122.48' />
    </dhcp>
  </ip>
</network>  

Actual results:
virsh net-update can add multiple dhcp sections to ipv4 in network.

Expected results:
Check for multiple DHCP sections in network 

Additional info:

Comment 2 hongming 2013-05-27 03:07:56 UTC
Clone of 
(rhel6) Bug 907769 - virsh net-update can add multiple dhcp sections to ipv4 in network

Comment 3 Jiri Denemark 2014-04-11 08:19:39 UTC
*** Bug 907769 has been marked as a duplicate of this bug. ***

Comment 5 Jiri Denemark 2014-12-09 12:42:19 UTC
Fixed upstream by v1.2.10-300-g5adc603:

commit 5adc6031fa60379719d4856001a7e32a6f0221aa
Author: Kyle DeFrancia <kdef.ibm.com>
Date:   Thu Dec 4 13:07:36 2014 -0800

    network: don't allow multiple dhcp sections
    
    This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=907779
    
    A <dhcp> element can exist in only one IPv4 address and one IPv6
    address per network.  This patch enforces that in virNetworkUpdate.

Comment 7 lcheng 2015-04-13 06:30:22 UTC
Reproduced this issue with libvirt-1.2.8-16.el7.x86_64.

[root@localhost ~]# cat net.xml 
<network>
  <name>net</name>
  <uuid>fe8ffe14-8478-060d-ece1-2c97f96e1c59</uuid>
  <forward mode='nat'/>
  <bridge name='virbr1' stp='on' delay='0' />
  <mac address='52:54:00:E5:B6:95'/>
  <ip address='192.168.121.1' netmask='255.255.255.0'>
  </ip>
  <ip address='192.168.10.1' netmask='255.255.255.0'>
  </ip>
</network>


[root@localhost ~]# virsh net-define net.xml 
Network net defined from net.xml

[root@localhost ~]# virsh net-start net
Network net started

[root@localhost ~]# virsh net-dumpxml net
<network>
  <name>net</name>
  <uuid>fe8ffe14-8478-060d-ece1-2c97f96e1c59</uuid>
  <forward mode='nat'>
    <nat>
      <port start='1024' end='65535'/>
    </nat>
  </forward>
  <bridge name='virbr1' stp='on' delay='0'/>
  <mac address='52:54:00:e5:b6:95'/>
  <ip address='192.168.121.1' netmask='255.255.255.0'>
  </ip>
  <ip address='192.168.10.1' netmask='255.255.255.0'>
  </ip>
</network>

[root@localhost ~]# virsh net-update net add ip-dhcp-host "<host mac='00:11:22:33:44:57' ip='192.168.122.47'/>" --live --config --parent-index 0
Updated network net persistent config and live state

[root@localhost ~]# virsh net-update net add ip-dhcp-host "<host mac='00:11:22:33:44:58' ip='192.168.122.48'/>" --live --config --parent-index 1
Updated network net persistent config and live state

[root@localhost ~]# virsh net-list --all
 Name                 State      Autostart     Persistent
----------------------------------------------------------
 default              active     yes           yes
 net                  active     no            yes

[root@localhost ~]# virsh net-dumpxml net
<network>
  <name>net</name>
  <uuid>fe8ffe14-8478-060d-ece1-2c97f96e1c59</uuid>
  <forward mode='nat'>
    <nat>
      <port start='1024' end='65535'/>
    </nat>
  </forward>
  <bridge name='virbr1' stp='on' delay='0'/>
  <mac address='52:54:00:e5:b6:95'/>
  <ip address='192.168.121.1' netmask='255.255.255.0'>
    <dhcp>
      <host mac='00:11:22:33:44:57' ip='192.168.122.47'/>
    </dhcp>
  </ip>
  <ip address='192.168.10.1' netmask='255.255.255.0'>
    <dhcp>
      <host mac='00:11:22:33:44:58' ip='192.168.122.48'/>
    </dhcp>
  </ip>
</network>



Verify it as follows. The result is expected. Change the state to VERIFIED

[root@localhost ~]# rpm -q libvirt
libvirt-1.2.14-1.el7.x86_64

[root@localhost ~]# cat net.xml 
<network>
  <name>net</name>
  <uuid>fe8ffe14-8478-060d-ece1-2c97f96e1c59</uuid>
  <forward mode='nat'/>
  <bridge name='virbr1' stp='on' delay='0' />
  <mac address='52:54:00:E5:B6:95'/>
  <ip address='192.168.121.1' netmask='255.255.255.0'>
  </ip>
  <ip address='192.168.10.1' netmask='255.255.255.0'>
  </ip>
</network>


[root@localhost ~]# virsh net-define net.xml 
Network net defined from net.xml

[root@localhost ~]# virsh net-start net
Network net started

[root@localhost ~]# virsh net-dumpxml net
<network>
  <name>net</name>
  <uuid>fe8ffe14-8478-060d-ece1-2c97f96e1c59</uuid>
  <forward mode='nat'>
    <nat>
      <port start='1024' end='65535'/>
    </nat>
  </forward>
  <bridge name='virbr1' stp='on' delay='0'/>
  <mac address='52:54:00:e5:b6:95'/>
  <ip address='192.168.121.1' netmask='255.255.255.0'>
  </ip>
  <ip address='192.168.10.1' netmask='255.255.255.0'>
  </ip>
</network>

[root@localhost ~]# virsh net-update net add ip-dhcp-host "<host mac='00:11:22:33:44:57' ip='192.168.122.47'/>" --live --config --parent-index 0
Updated network net persistent config and live state

[root@localhost ~]# virsh net-update net add ip-dhcp-host "<host mac='00:11:22:33:44:58' ip='192.168.122.48'/>" --live --config --parent-index 1
error: Failed to update network net
error: Requested operation is not valid: dhcp is supported only for a single IPv4 address on each network


[root@localhost ~]# virsh net-update net add ip-dhcp-range "<range start='192.168.200.130' end='192.168.200.140'/>" --live --config --parent-index 0
Updated network net persistent config and live state

[root@localhost ~]# virsh net-update net add ip-dhcp-range "<range start='192.168.200.130' end='192.168.200.140'/>" --live --config --parent-index 1
error: Failed to update network net
error: Requested operation is not valid: dhcp is supported only for a single IPv4 address on each network

[root@localhost ~]# virsh net-dumpxml net
<network>
  <name>net</name>
  <uuid>fe8ffe14-8478-060d-ece1-2c97f96e1c59</uuid>
  <forward mode='nat'>
    <nat>
      <port start='1024' end='65535'/>
    </nat>
  </forward>
  <bridge name='virbr1' stp='on' delay='0'/>
  <mac address='52:54:00:e5:b6:95'/>
  <ip address='192.168.121.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.200.130' end='192.168.200.140'/>
      <host mac='00:11:22:33:44:57' ip='192.168.122.47'/>
    </dhcp>
  </ip>
  <ip address='192.168.10.1' netmask='255.255.255.0'>
  </ip>
</network>

Comment 9 errata-xmlrpc 2015-11-19 05:42:06 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.

https://rhn.redhat.com/errata/RHBA-2015-2202.html