From: Andrea Bolognani Date: Tue, 18 Apr 2023 09:08:03 +0000 (+0200) Subject: conf: Restrict use of to the passt backend X-Git-Tag: v9.3.0-rc1~67 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=985f78e804d80357bce0a4b70034a37ad0611181;p=thirdparty%2Flibvirt.git conf: Restrict use of to the passt backend 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 Reviewed-by: Ján Tomko --- diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index ce6b8bf5a0..e04b85fee4 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -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 element can only be used with 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 index 0000000000..eaa934742e --- /dev/null +++ b/tests/qemuxml2argvdata/net-user-slirp-portforward.x86_64-latest.err @@ -0,0 +1 @@ +unsupported configuration: The element can only be used with 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 index 0000000000..721f04c878 --- /dev/null +++ b/tests/qemuxml2argvdata/net-user-slirp-portforward.xml @@ -0,0 +1,20 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 1 + + hvm + + + + /usr/bin/qemu-system-x86_64 + + + + + + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 1808d9fc02..23e0c4054c 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -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");