]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: Restrict use of <portForward> to the passt backend
authorAndrea Bolognani <abologna@redhat.com>
Tue, 18 Apr 2023 09:08:03 +0000 (11:08 +0200)
committerAndrea Bolognani <abologna@redhat.com>
Tue, 18 Apr 2023 13:52:30 +0000 (15:52 +0200)
That's already the case in practice, but it's a better
experience for the user if we reject this configuration
outright instead of silently ignoring part of it.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/domain_validate.c
tests/qemuxml2argvdata/net-user-slirp-portforward.x86_64-latest.err [new file with mode: 0644]
tests/qemuxml2argvdata/net-user-slirp-portforward.xml [new file with mode: 0644]
tests/qemuxml2argvtest.c

index ce6b8bf5a06252bd48655ffcd3aa402707f4747f..e04b85fee4b4645beff7ac2b4e411ed4d393cd9d 100644 (file)
@@ -2097,6 +2097,15 @@ virDomainNetDefValidate(const virDomainNetDef *net)
         }
     }
 
+    if (net->nPortForwards > 0 &&
+        (net->type != VIR_DOMAIN_NET_TYPE_USER ||
+         (net->type == VIR_DOMAIN_NET_TYPE_USER &&
+          net->backend.type != VIR_DOMAIN_NET_BACKEND_PASST))) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("The <portForward> element can only be used with <interface type='user'> and its 'passt' backend"));
+        return -1;
+    }
+
     switch (net->type) {
     case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
         if (!virDomainNetIsVirtioModel(net)) {
diff --git a/tests/qemuxml2argvdata/net-user-slirp-portforward.x86_64-latest.err b/tests/qemuxml2argvdata/net-user-slirp-portforward.x86_64-latest.err
new file mode 100644 (file)
index 0000000..eaa9347
--- /dev/null
@@ -0,0 +1 @@
+unsupported configuration: The <portForward> element can only be used with <interface type='user'> and its 'passt' backend
diff --git a/tests/qemuxml2argvdata/net-user-slirp-portforward.xml b/tests/qemuxml2argvdata/net-user-slirp-portforward.xml
new file mode 100644 (file)
index 0000000..721f04c
--- /dev/null
@@ -0,0 +1,20 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <devices>
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
+    <interface type='user'>
+      <mac address='00:11:22:33:44:55'/>
+      <portForward proto='tcp'>
+        <range start='443' to='344'/>
+      </portForward>
+      <model type='virtio'/>
+    </interface>
+  </devices>
+</domain>
index 1808d9fc02adfbea7ad6847191ae12f4451eeece..23e0c4054c1ef959a210a97bb0e215641d7656b4 100644 (file)
@@ -1413,6 +1413,7 @@ mymain(void)
     DO_TEST_NOCAPS("net-user-addr");
     DO_TEST_CAPS_LATEST("net-user-passt");
     DO_TEST_CAPS_VER("net-user-passt", "7.2.0");
+    DO_TEST_CAPS_LATEST_PARSE_ERROR("net-user-slirp-portforward");
     DO_TEST_NOCAPS("net-virtio");
     DO_TEST_NOCAPS("net-virtio-device");
     DO_TEST_NOCAPS("net-virtio-disable-offloads");