[PATCH v3 3/5] conf: Add 'family' attribute to <graphics> 'listen' element

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

 



From: Luyao Huang <lhuang@xxxxxxxxxx>

If an interface or network has both ipv6 and ipv4 addresses which can
be used, we do not know which to use as a listen address. This patch
introduces the 'family' attribute to allow the XML to determine whether
the desire is to use IPv6 instead of IPv4 as the listen family to use.
The default will remain IPv4.

The graphics XML may look like this after this commit:

    <graphics type='spice' port='5900' autoport='yes'>
      <listen type='network' address='192.168.0.1' network='vepa-net' family='ipv4'/>
    </graphics>

The address used to listen will be the first address of the family type
found for the network.

Added two new tests with the new attribute in place.

Signed-off-by: Luyao Huang <lhuang@xxxxxxxxxx>
Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 docs/formatdomain.html.in                          | 14 ++++++++-
 docs/schemas/domaincommon.rng                      |  8 +++++
 src/conf/domain_conf.c                             | 21 +++++++++++++
 src/conf/domain_conf.h                             | 10 +++++++
 .../qemuxml2argv-graphics-listen-network-ipv4.xml  | 35 ++++++++++++++++++++++
 .../qemuxml2argv-graphics-listen-network-ipv6.xml  | 35 ++++++++++++++++++++++
 tests/qemuxml2xmltest.c                            |  2 ++
 7 files changed, 124 insertions(+), 1 deletion(-)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-graphics-listen-network-ipv4.xml
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-graphics-listen-network-ipv6.xml

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 335763f..262c576 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -4553,7 +4553,7 @@ qemu-kvm -net nic,model=? /dev/null
     &lt;graphics type='rdp' autoport='yes' multiUser='yes' /&gt;
     &lt;graphics type='desktop' fullscreen='yes'/&gt;
     &lt;graphics type='spice'&gt;
-      &lt;listen type='network' network='rednet'/&gt;
+      &lt;listen type='network' network='rednet' family='ipv4'/&gt;
     &lt;/graphics&gt;
   &lt;/devices&gt;
   ...</pre>
@@ -4793,6 +4793,18 @@ qemu-kvm -net nic,model=? /dev/null
         the first forward dev will be used.
       </dd>
     </dl>
+    <dl>
+      <dt><code>family</code></dt>
+      <dd>if <code>type='network'</code>, the <code>family</code>
+        attribute may contain the IP family. The <code>family</code>
+        can be set to either <code>ipv4</code> or <code>ipv6</code>.
+        This advises the graphics device which IP address family
+        to use as listen address for the network. The listen address
+        used will be the first found address of the <code>family</code>
+        type defined for the host.
+        <span class="since">Since 1.2.14</span>
+      </dd>
+    </dl>
 
     <h4><a name="elementsVideo">Video devices</a></h4>
     <p>
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 56ea6a4..87582cc 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2926,6 +2926,14 @@
                 <ref name="addrIPorName"/>
               </attribute>
             </optional>
+            <optional>
+              <attribute name="family">
+                <choice>
+                  <value>ipv4</value>
+                  <value>ipv6</value>
+                </choice>
+              </attribute>
+            </optional>
           </group>
         </choice>
       </element>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index cc8616b..70a3525 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -522,6 +522,12 @@ VIR_ENUM_IMPL(virDomainGraphicsListen, VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST,
               "address",
               "network")
 
+VIR_ENUM_IMPL(virDomainGraphicsListenFamily,
+              VIR_DOMAIN_GRAPHICS_LISTEN_FAMILY_LAST,
+              "none",
+              "ipv4",
+              "ipv6")
+
 VIR_ENUM_IMPL(virDomainGraphicsAuthConnected,
               VIR_DOMAIN_GRAPHICS_AUTH_CONNECTED_LAST,
               "default",
@@ -9547,6 +9553,7 @@ virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDefPtr def,
     char *address  = virXMLPropString(node, "address");
     char *network  = virXMLPropString(node, "network");
     char *fromConfig = virXMLPropString(node, "fromConfig");
+    char *family   = virXMLPropString(node, "family");
     int tmp;
 
     if (!type) {
@@ -9584,6 +9591,15 @@ virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDefPtr def,
         network = NULL;
     }
 
+    if (def->type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK && family) {
+        if ((def->family =
+             virDomainGraphicsListenFamilyTypeFromString(family)) < 0) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("unknown graphics listen IP family '%s'"), family);
+            goto error;
+        }
+    }
+
     if (fromConfig &&
         flags & VIR_DOMAIN_DEF_PARSE_STATUS) {
         if (virStrToLong_i(fromConfig, NULL, 10, &tmp) < 0) {
@@ -9603,6 +9619,7 @@ virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDefPtr def,
     VIR_FREE(address);
     VIR_FREE(network);
     VIR_FREE(fromConfig);
+    VIR_FREE(family);
     return ret;
 }
 
@@ -19203,6 +19220,10 @@ virDomainGraphicsListenDefFormat(virBufferPtr buf,
     if (def->network &&
         (def->type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK)) {
         virBufferEscapeString(buf, " network='%s'", def->network);
+
+        if (def->family != VIR_DOMAIN_GRAPHICS_LISTEN_FAMILY_NONE)
+            virBufferAsprintf(buf, " family='%s'",
+                              virDomainGraphicsListenFamilyTypeToString(def->family));
     }
 
     if (flags & VIR_DOMAIN_DEF_FORMAT_STATUS)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 36bb418..8a6df7c 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1442,6 +1442,14 @@ typedef enum {
 } virDomainGraphicsListenType;
 
 typedef enum {
+    VIR_DOMAIN_GRAPHICS_LISTEN_FAMILY_NONE = 0,
+    VIR_DOMAIN_GRAPHICS_LISTEN_FAMILY_IPV4,
+    VIR_DOMAIN_GRAPHICS_LISTEN_FAMILY_IPV6,
+
+    VIR_DOMAIN_GRAPHICS_LISTEN_FAMILY_LAST
+} virDomainGraphicsListenFamily;
+
+typedef enum {
     VIR_DOMAIN_HUB_TYPE_USB,
 
     VIR_DOMAIN_HUB_TYPE_LAST
@@ -1454,6 +1462,7 @@ struct _virDomainGraphicsListenDef {
     char *address;
     char *network;
     bool fromConfig;    /* true if the @address is config file originated */
+    int family;   /*enum virDomainGraphicsListenFamily*/
 };
 
 struct _virDomainGraphicsDef {
@@ -2858,6 +2867,7 @@ VIR_ENUM_DECL(virDomainInput)
 VIR_ENUM_DECL(virDomainInputBus)
 VIR_ENUM_DECL(virDomainGraphics)
 VIR_ENUM_DECL(virDomainGraphicsListen)
+VIR_ENUM_DECL(virDomainGraphicsListenFamily)
 VIR_ENUM_DECL(virDomainGraphicsAuthConnected)
 VIR_ENUM_DECL(virDomainGraphicsSpiceChannelName)
 VIR_ENUM_DECL(virDomainGraphicsSpiceChannelMode)
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-graphics-listen-network-ipv4.xml b/tests/qemuxml2argvdata/qemuxml2argv-graphics-listen-network-ipv4.xml
new file mode 100644
index 0000000..3b5c2de
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-listen-network-ipv4.xml
@@ -0,0 +1,35 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219100</memory>
+  <currentMemory unit='KiB'>219100</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='i686' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu</emulator>
+    <disk type='block' device='disk'>
+      <source dev='/dev/HostVG/QEMUGuest1'/>
+      <target dev='hda' bus='ide'/>
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+    </disk>
+    <controller type='usb' index='0'/>
+    <controller type='ide' index='0'/>
+    <controller type='pci' index='0' model='pci-root'/>
+    <input type='mouse' bus='ps2'/>
+    <input type='keyboard' bus='ps2'/>
+    <graphics type='vnc' port='5903' autoport='no'>
+      <listen type='network' network='Bobsnetwork' family='ipv4'/>
+    </graphics>
+    <video>
+      <model type='cirrus' vram='16384' heads='1'/>
+    </video>
+    <memballoon model='virtio'/>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-graphics-listen-network-ipv6.xml b/tests/qemuxml2argvdata/qemuxml2argv-graphics-listen-network-ipv6.xml
new file mode 100644
index 0000000..6cce7a8
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-listen-network-ipv6.xml
@@ -0,0 +1,35 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219100</memory>
+  <currentMemory unit='KiB'>219100</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='i686' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu</emulator>
+    <disk type='block' device='disk'>
+      <source dev='/dev/HostVG/QEMUGuest1'/>
+      <target dev='hda' bus='ide'/>
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+    </disk>
+    <controller type='usb' index='0'/>
+    <controller type='ide' index='0'/>
+    <controller type='pci' index='0' model='pci-root'/>
+    <input type='mouse' bus='ps2'/>
+    <input type='keyboard' bus='ps2'/>
+    <graphics type='vnc' port='5903' autoport='no'>
+      <listen type='network' network='Bobsnetwork' family='ipv6'/>
+    </graphics>
+    <video>
+      <model type='cirrus' vram='16384' heads='1'/>
+    </video>
+    <memballoon model='virtio'/>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 8e12e84..e49510c 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -247,6 +247,8 @@ mymain(void)
     DO_TEST_FULL("disk-mirror", true, WHEN_INACTIVE);
     DO_TEST_FULL("disk-active-commit", false, WHEN_ACTIVE);
     DO_TEST("graphics-listen-network");
+    DO_TEST("graphics-listen-network-ipv4");
+    DO_TEST("graphics-listen-network-ipv6");
     DO_TEST("graphics-vnc");
     DO_TEST("graphics-vnc-websocket");
     DO_TEST("graphics-vnc-sasl");
-- 
2.1.0

--
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]