[PATCH 8/8] qemu: require "peer" if ip address is supplied for an interface

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Since "peer" is really the address of the tap interface, while
"address" is actually the peer address of the tap interface, and since
you can't set the peer address of a POINTOPOINT tap device without
setting the local address, we need to require "peer" in the config.
---
 src/qemu/qemu_domain.c | 44 +++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 39 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index f2488ad..03baa5a 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1788,15 +1788,49 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
     virQEMUCapsPtr qemuCaps = NULL;
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
     int ret = -1;
+    size_t i;
 
     qemuCaps = virQEMUCapsCacheLookup(driver->qemuCapsCache, def->emulator);
 
-    if (dev->type == VIR_DOMAIN_DEVICE_NET &&
-        dev->data.net->type != VIR_DOMAIN_NET_TYPE_HOSTDEV &&
-        !dev->data.net->model) {
-        if (VIR_STRDUP(dev->data.net->model,
-                       qemuDomainDefaultNetModel(def, qemuCaps)) < 0)
+    if (dev->type == VIR_DOMAIN_DEVICE_NET) {
+        virDomainNetDefPtr net = dev->data.net;
+
+        if (net->type != VIR_DOMAIN_NET_TYPE_HOSTDEV && !net->model &&
+            VIR_STRDUP(net->model,
+                       qemuDomainDefaultNetModel(def, qemuCaps)) < 0) {
             goto cleanup;
+        }
+
+        if (net->nips) {
+            /* we currently only support setting an IP address
+             * for <interface type='ethernet'>
+             */
+            if (net->type != VIR_DOMAIN_NET_TYPE_ETHERNET) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                               _("ip addresses cannot be set in config "
+                                 "for interfaces of type '%s'"),
+                               virDomainNetTypeToString(net->type));
+                goto cleanup;
+            }
+            /* verify that every ip has a peer address set,
+             * since the "peer" attribute in the config becomes
+             * the tap device's local IP address, which is required
+             */
+            for (i = 0; i < net->nips; i++) {
+                virDomainNetIpDefPtr ip = net->ips[i];
+
+                if (!VIR_SOCKET_ADDR_VALID(&ip->peer)) {
+                    char *ipStr = virSocketAddrFormat(&ip->address);
+
+                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                                   _("interface ip address '%s' must "
+                                     "have a peer address set in config"),
+                                   ipStr ? ipStr : "(unknown)");
+                    VIR_FREE(ipStr);
+                    goto cleanup;
+                }
+            }
+        }
     }
 
     /* set default disk types and drivers */
-- 
2.5.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]