|
|
c1c534 |
From 1747bfd95ad80d2453de11e99a7bf9fa53c9aa55 Mon Sep 17 00:00:00 2001
|
|
|
c1c534 |
Message-Id: <1747bfd95ad80d2453de11e99a7bf9fa53c9aa55@dist-git>
|
|
|
c1c534 |
From: Peter Krempa <pkrempa@redhat.com>
|
|
|
c1c534 |
Date: Thu, 23 Nov 2017 19:02:14 +0100
|
|
|
c1c534 |
Subject: [PATCH] qemu: domain: Despaghettify qemuDomainDeviceDefValidate
|
|
|
c1c534 |
|
|
|
c1c534 |
Move network device validation into a separate function.
|
|
|
c1c534 |
|
|
|
c1c534 |
(cherry picked from commit 577ccd07c35a8e9b9d682778cc7d6c1d34d891f9)
|
|
|
c1c534 |
|
|
|
c1c534 |
https://bugzilla.redhat.com/show_bug.cgi?id=1511480
|
|
|
c1c534 |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
c1c534 |
---
|
|
|
c1c534 |
src/qemu/qemu_domain.c | 184 ++++++++++++++++++++++++++-----------------------
|
|
|
c1c534 |
1 file changed, 97 insertions(+), 87 deletions(-)
|
|
|
c1c534 |
|
|
|
c1c534 |
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
|
|
|
c1c534 |
index 72d67adfe3..30a602a1e9 100644
|
|
|
c1c534 |
--- a/src/qemu/qemu_domain.c
|
|
|
c1c534 |
+++ b/src/qemu/qemu_domain.c
|
|
|
c1c534 |
@@ -3553,102 +3553,112 @@ qemuDomainWatchdogDefValidate(const virDomainWatchdogDef *dev,
|
|
|
c1c534 |
}
|
|
|
c1c534 |
|
|
|
c1c534 |
|
|
|
c1c534 |
+static int
|
|
|
c1c534 |
+qemuDomainDeviceDefValidateNetwork(const virDomainNetDef *net)
|
|
|
c1c534 |
+{
|
|
|
c1c534 |
+ bool hasIPv4 = false;
|
|
|
c1c534 |
+ bool hasIPv6 = false;
|
|
|
c1c534 |
+ size_t i;
|
|
|
c1c534 |
+
|
|
|
c1c534 |
+ if (net->type == VIR_DOMAIN_NET_TYPE_USER) {
|
|
|
c1c534 |
+ if (net->guestIP.nroutes) {
|
|
|
c1c534 |
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
c1c534 |
+ _("Invalid attempt to set network interface "
|
|
|
c1c534 |
+ "guest-side IP route, not supported by QEMU"));
|
|
|
c1c534 |
+ return -1;
|
|
|
c1c534 |
+ }
|
|
|
c1c534 |
+
|
|
|
c1c534 |
+ for (i = 0; i < net->guestIP.nips; i++) {
|
|
|
c1c534 |
+ const virNetDevIPAddr *ip = net->guestIP.ips[i];
|
|
|
c1c534 |
+
|
|
|
c1c534 |
+ if (VIR_SOCKET_ADDR_VALID(&net->guestIP.ips[i]->peer)) {
|
|
|
c1c534 |
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
c1c534 |
+ _("Invalid attempt to set peer IP for guest"));
|
|
|
c1c534 |
+ return -1;
|
|
|
c1c534 |
+ }
|
|
|
c1c534 |
+
|
|
|
c1c534 |
+ if (VIR_SOCKET_ADDR_IS_FAMILY(&ip->address, AF_INET)) {
|
|
|
c1c534 |
+ if (hasIPv4) {
|
|
|
c1c534 |
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
c1c534 |
+ _("Only one IPv4 address per "
|
|
|
c1c534 |
+ "interface is allowed"));
|
|
|
c1c534 |
+ return -1;
|
|
|
c1c534 |
+ }
|
|
|
c1c534 |
+ hasIPv4 = true;
|
|
|
c1c534 |
+
|
|
|
c1c534 |
+ if (ip->prefix > 27) {
|
|
|
c1c534 |
+ virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
c1c534 |
+ _("prefix too long"));
|
|
|
c1c534 |
+ return -1;
|
|
|
c1c534 |
+ }
|
|
|
c1c534 |
+ }
|
|
|
c1c534 |
+
|
|
|
c1c534 |
+ if (VIR_SOCKET_ADDR_IS_FAMILY(&ip->address, AF_INET6)) {
|
|
|
c1c534 |
+ if (hasIPv6) {
|
|
|
c1c534 |
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
c1c534 |
+ _("Only one IPv6 address per "
|
|
|
c1c534 |
+ "interface is allowed"));
|
|
|
c1c534 |
+ return -1;
|
|
|
c1c534 |
+ }
|
|
|
c1c534 |
+ hasIPv6 = true;
|
|
|
c1c534 |
+
|
|
|
c1c534 |
+ if (ip->prefix > 120) {
|
|
|
c1c534 |
+ virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
c1c534 |
+ _("prefix too long"));
|
|
|
c1c534 |
+ return -1;
|
|
|
c1c534 |
+ }
|
|
|
c1c534 |
+ }
|
|
|
c1c534 |
+ }
|
|
|
c1c534 |
+ } else if (net->guestIP.nroutes || net->guestIP.nips) {
|
|
|
c1c534 |
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
c1c534 |
+ _("Invalid attempt to set network interface "
|
|
|
c1c534 |
+ "guest-side IP route and/or address info, "
|
|
|
c1c534 |
+ "not supported by QEMU"));
|
|
|
c1c534 |
+ return -1;
|
|
|
c1c534 |
+ }
|
|
|
c1c534 |
+
|
|
|
c1c534 |
+ if (STREQ_NULLABLE(net->model, "virtio")) {
|
|
|
c1c534 |
+ if (net->driver.virtio.rx_queue_size & (net->driver.virtio.rx_queue_size - 1)) {
|
|
|
c1c534 |
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
c1c534 |
+ _("rx_queue_size has to be a power of two"));
|
|
|
c1c534 |
+ return -1;
|
|
|
c1c534 |
+ }
|
|
|
c1c534 |
+ if (net->driver.virtio.tx_queue_size & (net->driver.virtio.tx_queue_size - 1)) {
|
|
|
c1c534 |
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
c1c534 |
+ _("tx_queue_size has to be a power of two"));
|
|
|
c1c534 |
+ return -1;
|
|
|
c1c534 |
+ }
|
|
|
c1c534 |
+ }
|
|
|
c1c534 |
+
|
|
|
c1c534 |
+ if (net->mtu &&
|
|
|
c1c534 |
+ !qemuDomainNetSupportsMTU(net->type)) {
|
|
|
c1c534 |
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
c1c534 |
+ _("setting MTU on interface type %s is not supported yet"),
|
|
|
c1c534 |
+ virDomainNetTypeToString(net->type));
|
|
|
c1c534 |
+ return -1;
|
|
|
c1c534 |
+ }
|
|
|
c1c534 |
+
|
|
|
c1c534 |
+ if (net->coalesce && !qemuDomainNetSupportsCoalesce(net->type)) {
|
|
|
c1c534 |
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
c1c534 |
+ _("coalesce settings on interface type %s are not supported"),
|
|
|
c1c534 |
+ virDomainNetTypeToString(net->type));
|
|
|
c1c534 |
+ return -1;
|
|
|
c1c534 |
+ }
|
|
|
c1c534 |
+
|
|
|
c1c534 |
+ return 0;
|
|
|
c1c534 |
+}
|
|
|
c1c534 |
+
|
|
|
c1c534 |
+
|
|
|
c1c534 |
static int
|
|
|
c1c534 |
qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
|
|
|
c1c534 |
const virDomainDef *def,
|
|
|
c1c534 |
void *opaque ATTRIBUTE_UNUSED)
|
|
|
c1c534 |
{
|
|
|
c1c534 |
int ret = -1;
|
|
|
c1c534 |
- size_t i;
|
|
|
c1c534 |
|
|
|
c1c534 |
if (dev->type == VIR_DOMAIN_DEVICE_NET) {
|
|
|
c1c534 |
- const virDomainNetDef *net = dev->data.net;
|
|
|
c1c534 |
- bool hasIPv4 = false, hasIPv6 = false;
|
|
|
c1c534 |
-
|
|
|
c1c534 |
- if (net->type == VIR_DOMAIN_NET_TYPE_USER) {
|
|
|
c1c534 |
- if (net->guestIP.nroutes) {
|
|
|
c1c534 |
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
c1c534 |
- _("Invalid attempt to set network interface "
|
|
|
c1c534 |
- "guest-side IP route, not supported by QEMU"));
|
|
|
c1c534 |
- goto cleanup;
|
|
|
c1c534 |
- }
|
|
|
c1c534 |
-
|
|
|
c1c534 |
- for (i = 0; i < net->guestIP.nips; i++) {
|
|
|
c1c534 |
- const virNetDevIPAddr *ip = net->guestIP.ips[i];
|
|
|
c1c534 |
-
|
|
|
c1c534 |
- if (VIR_SOCKET_ADDR_VALID(&net->guestIP.ips[i]->peer)) {
|
|
|
c1c534 |
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
c1c534 |
- _("Invalid attempt to set peer IP for guest"));
|
|
|
c1c534 |
- goto cleanup;
|
|
|
c1c534 |
- }
|
|
|
c1c534 |
-
|
|
|
c1c534 |
- if (VIR_SOCKET_ADDR_IS_FAMILY(&ip->address, AF_INET)) {
|
|
|
c1c534 |
- if (hasIPv4) {
|
|
|
c1c534 |
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
c1c534 |
- _("Only one IPv4 address per "
|
|
|
c1c534 |
- "interface is allowed"));
|
|
|
c1c534 |
- goto cleanup;
|
|
|
c1c534 |
- }
|
|
|
c1c534 |
- hasIPv4 = true;
|
|
|
c1c534 |
-
|
|
|
c1c534 |
- if (ip->prefix > 27) {
|
|
|
c1c534 |
- virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
c1c534 |
- _("prefix too long"));
|
|
|
c1c534 |
- goto cleanup;
|
|
|
c1c534 |
- }
|
|
|
c1c534 |
- }
|
|
|
c1c534 |
-
|
|
|
c1c534 |
- if (VIR_SOCKET_ADDR_IS_FAMILY(&ip->address, AF_INET6)) {
|
|
|
c1c534 |
- if (hasIPv6) {
|
|
|
c1c534 |
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
c1c534 |
- _("Only one IPv6 address per "
|
|
|
c1c534 |
- "interface is allowed"));
|
|
|
c1c534 |
- goto cleanup;
|
|
|
c1c534 |
- }
|
|
|
c1c534 |
- hasIPv6 = true;
|
|
|
c1c534 |
-
|
|
|
c1c534 |
- if (ip->prefix > 120) {
|
|
|
c1c534 |
- virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
c1c534 |
- _("prefix too long"));
|
|
|
c1c534 |
- goto cleanup;
|
|
|
c1c534 |
- }
|
|
|
c1c534 |
- }
|
|
|
c1c534 |
- }
|
|
|
c1c534 |
- } else if (net->guestIP.nroutes || net->guestIP.nips) {
|
|
|
c1c534 |
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
c1c534 |
- _("Invalid attempt to set network interface "
|
|
|
c1c534 |
- "guest-side IP route and/or address info, "
|
|
|
c1c534 |
- "not supported by QEMU"));
|
|
|
c1c534 |
+ if (qemuDomainDeviceDefValidateNetwork(dev->data.net) < 0)
|
|
|
c1c534 |
goto cleanup;
|
|
|
c1c534 |
- }
|
|
|
c1c534 |
-
|
|
|
c1c534 |
- if (STREQ_NULLABLE(net->model, "virtio")) {
|
|
|
c1c534 |
- if (net->driver.virtio.rx_queue_size & (net->driver.virtio.rx_queue_size - 1)) {
|
|
|
c1c534 |
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
c1c534 |
- _("rx_queue_size has to be a power of two"));
|
|
|
c1c534 |
- goto cleanup;
|
|
|
c1c534 |
- }
|
|
|
c1c534 |
- if (net->driver.virtio.tx_queue_size & (net->driver.virtio.tx_queue_size - 1)) {
|
|
|
c1c534 |
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
c1c534 |
- _("tx_queue_size has to be a power of two"));
|
|
|
c1c534 |
- goto cleanup;
|
|
|
c1c534 |
- }
|
|
|
c1c534 |
- }
|
|
|
c1c534 |
-
|
|
|
c1c534 |
- if (net->mtu &&
|
|
|
c1c534 |
- !qemuDomainNetSupportsMTU(net->type)) {
|
|
|
c1c534 |
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
c1c534 |
- _("setting MTU on interface type %s is not supported yet"),
|
|
|
c1c534 |
- virDomainNetTypeToString(net->type));
|
|
|
c1c534 |
- goto cleanup;
|
|
|
c1c534 |
- }
|
|
|
c1c534 |
-
|
|
|
c1c534 |
- if (net->coalesce && !qemuDomainNetSupportsCoalesce(net->type)) {
|
|
|
c1c534 |
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
c1c534 |
- _("coalesce settings on interface type %s are not supported"),
|
|
|
c1c534 |
- virDomainNetTypeToString(net->type));
|
|
|
c1c534 |
- goto cleanup;
|
|
|
c1c534 |
- }
|
|
|
c1c534 |
} else if (dev->type == VIR_DOMAIN_DEVICE_CHR) {
|
|
|
c1c534 |
if (qemuDomainChrDefValidate(dev->data.chr, def) < 0)
|
|
|
c1c534 |
goto cleanup;
|
|
|
c1c534 |
--
|
|
|
c1c534 |
2.15.0
|
|
|
c1c534 |
|