]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: Allow usernet to have an address
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 13 Sep 2017 08:47:52 +0000 (10:47 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 18 Sep 2017 11:54:27 +0000 (13:54 +0200)
https://bugzilla.redhat.com/show_bug.cgi?id=1075520

Currently, all that users can specify for an interface type of
'user' is the common attributes: PCI address, NIC model (and
that's basically it). However, some need to configure other
address range than the default one.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: laine@laine.org
docs/formatdomain.html.in
src/qemu/qemu_domain.c
tests/qemuxml2argvdata/qemuxml2argv-net-user-addr.xml [new file with mode: 0644]
tests/qemuxml2xmloutdata/qemuxml2xmlout-net-user-addr.xml [new symlink]
tests/qemuxml2xmltest.c

index 3b78bbeb84da977d3ad5ad9454d29c195eae8625..57ec2ff34cdcb3ace4d3fca14eddb40bc50efab5 100644 (file)
       starting from <code>10.0.2.15</code>. The default router will be
       <code>10.0.2.2</code> and the DNS server will be <code>10.0.2.3</code>.
       This networking is the only option for unprivileged users who need their
-      VMs to have outgoing access.
+      VMs to have outgoing access. <span class="since">Since 3.8.0</span>
+      it is possible to override the default network address by
+      including an <code>ip</code> element specifying an IPv4
+      address in its one mandatory attribute, <code>address</code>.
+      Optionally, a second <code>ip</code> element with a
+      <code>family</code> attribute set to "ipv6" can be
+      specified to add an IPv6 address to the interface.
+      <code>address</code>. Optionally, address
+      <code>prefix</code> can be specified.
     </p>
 
 <pre>
   ...
   &lt;interface type='user'&gt;
     &lt;mac address="00:11:22:33:44:55"/&gt;
+    &lt;ip family='ipv4' address='172.17.2.0' prefix='24'/&gt;
+    &lt;ip family='ipv6' address='2001:db8:ac10:fd01::' prefix='64'/&gt;
   &lt;/interface&gt;
 &lt;/devices&gt;
 ...</pre>
index 05f8e9488ed4ac0f8260dfaf212932db4aa191d9..305019b66cf6216ab2c6869a413c01f331e685f3 100644 (file)
@@ -3342,7 +3342,14 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
     if (dev->type == VIR_DOMAIN_DEVICE_NET) {
         const virDomainNetDef *net = dev->data.net;
 
-        if (net->guestIP.nroutes || net->guestIP.nips) {
+        if (net->type == VIR_DOMAIN_NET_TYPE_USER) {
+            if (net->guestIP.nroutes) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                               _("Invalid attempt to set network interface "
+                                 "guest-side IP route, not supported by QEMU"));
+                goto cleanup;
+            }
+        } else if (net->guestIP.nroutes || net->guestIP.nips) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                            _("Invalid attempt to set network interface "
                              "guest-side IP route and/or address info, "
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-user-addr.xml b/tests/qemuxml2argvdata/qemuxml2argv-net-user-addr.xml
new file mode 100644 (file)
index 0000000..0b5f151
--- /dev/null
@@ -0,0 +1,41 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='i686' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu-system-i686</emulator>
+    <disk type='block' device='disk'>
+      <driver name='qemu' type='raw'/>
+      <source dev='/dev/HostVG/QEMUGuest1'/>
+      <target dev='hda' bus='ide'/>
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+    </disk>
+    <controller type='usb' index='0'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
+    </controller>
+    <controller type='ide' index='0'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
+    </controller>
+    <controller type='pci' index='0' model='pci-root'/>
+    <interface type='user'>
+      <mac address='00:11:22:33:44:55'/>
+      <ip address='172.17.2.0' family='ipv4' prefix='24'/>
+      <ip address='2001:db8:ac10:fd01::' family='ipv6' prefix='64'/>
+      <model type='rtl8139'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+    </interface>
+    <input type='mouse' bus='ps2'/>
+    <input type='keyboard' bus='ps2'/>
+    <memballoon model='none'/>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-net-user-addr.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-net-user-addr.xml
new file mode 120000 (symlink)
index 0000000..fd909ec
--- /dev/null
@@ -0,0 +1 @@
+../qemuxml2argvdata/qemuxml2argv-net-user-addr.xml
\ No newline at end of file
index 0a87cedf2200c30d5905e8f9570e4e4ddac06c13..efac9e8286e29183d2107e5ece0484f4a429f2b2 100644 (file)
@@ -531,6 +531,7 @@ mymain(void)
     DO_TEST("misc-uuid", NONE);
     DO_TEST("net-vhostuser", NONE);
     DO_TEST("net-user", NONE);
+    DO_TEST("net-user-addr", QEMU_CAPS_NETDEV);
     DO_TEST("net-virtio", NONE);
     DO_TEST("net-virtio-device", NONE);
     DO_TEST("net-virtio-disable-offloads", NONE);