From d1dbb3078245b44186f6b3f09b6e66fe98b4bede Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Wed, 13 Sep 2017 10:47:52 +0200 Subject: [PATCH] conf: Allow usernet to have an address 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 Reviewed-by: laine@laine.org --- docs/formatdomain.html.in | 12 +++++- src/qemu/qemu_domain.c | 9 +++- .../qemuxml2argv-net-user-addr.xml | 41 +++++++++++++++++++ .../qemuxml2xmlout-net-user-addr.xml | 1 + tests/qemuxml2xmltest.c | 1 + 5 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-net-user-addr.xml create mode 120000 tests/qemuxml2xmloutdata/qemuxml2xmlout-net-user-addr.xml diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 3b78bbeb84..57ec2ff34c 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -4695,7 +4695,15 @@ starting from 10.0.2.15. The default router will be 10.0.2.2 and the DNS server will be 10.0.2.3. This networking is the only option for unprivileged users who need their - VMs to have outgoing access. + VMs to have outgoing access. Since 3.8.0 + it is possible to override the default network address by + including an ip element specifying an IPv4 + address in its one mandatory attribute, address. + Optionally, a second ip element with a + family attribute set to "ipv6" can be + specified to add an IPv6 address to the interface. + address. Optionally, address + prefix can be specified.

@@ -4705,6 +4713,8 @@
   ...
   <interface type='user'>
     <mac address="00:11:22:33:44:55"/>
+    <ip family='ipv4' address='172.17.2.0' prefix='24'/>
+    <ip family='ipv6' address='2001:db8:ac10:fd01::' prefix='64'/>
   </interface>
 </devices>
 ...
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 05f8e9488e..305019b66c 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -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 index 0000000000..0b5f151989 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-net-user-addr.xml @@ -0,0 +1,41 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i686 + + + + +
+ + +
+ + +
+ + + + + + + +
+ + + + + + diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-net-user-addr.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-net-user-addr.xml new file mode 120000 index 0000000000..fd909ec242 --- /dev/null +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-net-user-addr.xml @@ -0,0 +1 @@ +../qemuxml2argvdata/qemuxml2argv-net-user-addr.xml \ No newline at end of file diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 0a87cedf22..efac9e8286 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -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);