[PATCH 2/4] conf: introduce new family attribute in graphics listen for chose IP family

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

 



If a interface or network have both ipv6 and ipv4 address which can be used,
we do not know use which be a listen address. So introduce a new attribute
to help us chose this.

graphics XML will like this after this commit:

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

and this ip family can be set 3 type:

default: check if the interface or network have a can be used ipv4 address,
if yes use this address, if not will try to get a ipv6 address.

ipv4: check if the interface or network have a can be used ipv4 address
ipv6: check if the interface or network have a can be used ipv6 address

fix some test which will be break by this commit.

Signed-off-by: Luyao Huang <lhuang@xxxxxxxxxx>
---
 docs/formatdomain.html.in                           | 10 +++++++++-
 docs/schemas/domaincommon.rng                       |  9 +++++++++
 src/conf/domain_conf.c                              | 21 +++++++++++++++++++++
 src/conf/domain_conf.h                              | 10 ++++++++++
 .../qemuxml2argv-graphics-listen-network.xml        |  2 +-
 .../qemuxml2argv-graphics-listen-network2.xml       |  2 +-
 .../qemuxml2xmlout-graphics-listen-network2.xml     |  2 +-
 7 files changed, 52 insertions(+), 4 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index fcf5984..7a07ca0 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -4512,7 +4512,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='default'/&gt;
     &lt;/graphics&gt;
   &lt;/devices&gt;
   ...</pre>
@@ -4752,6 +4752,14 @@ 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 will contain an IP family. This tells which IP address
+        will be got for the network. IP family can be set to default, ipv4
+        or ipv6.
+      </dd>
+    </dl>
 
     <h4><a name="elementsVideo">Video devices</a></h4>
     <p>
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 7a1d299..fb8d084 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2888,6 +2888,15 @@
                 <ref name="addrIPorName"/>
               </attribute>
             </optional>
+            <optional>
+              <attribute name="family">
+                <choice>
+                  <value>default</value>
+                  <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 fd36063..307801d 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,
+              "default",
+              "ipv4",
+              "ipv6")
+
 VIR_ENUM_IMPL(virDomainGraphicsAuthConnected,
               VIR_DOMAIN_GRAPHICS_AUTH_CONNECTED_LAST,
               "default",
@@ -9396,6 +9402,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) {
@@ -9433,6 +9440,16 @@ virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDefPtr def,
         network = NULL;
     }
 
+    if (def->type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK) {
+        if (!family) {
+            def->family = VIR_DOMAIN_GRAPHICS_LISTEN_FAMILY_DEFAULT;
+        } else 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) {
@@ -9452,6 +9469,7 @@ virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDefPtr def,
     VIR_FREE(address);
     VIR_FREE(network);
     VIR_FREE(fromConfig);
+    VIR_FREE(family);
     return ret;
 }
 
@@ -19044,6 +19062,9 @@ virDomainGraphicsListenDefFormat(virBufferPtr buf,
     if (def->network &&
         (def->type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK)) {
         virBufferEscapeString(buf, " network='%s'", def->network);
+
+        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 da21bce..7806bc6 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1438,6 +1438,14 @@ typedef enum {
 } virDomainGraphicsListenType;
 
 typedef enum {
+    VIR_DOMAIN_GRAPHICS_LISTEN_FAMILY_DEFAULT = 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
@@ -1450,6 +1458,7 @@ struct _virDomainGraphicsListenDef {
     char *address;
     char *network;
     bool fromConfig;    /* true if the @address is config file originated */
+    int family;   /*enum virDomainGraphicsListenFamily*/
 };
 
 struct _virDomainGraphicsDef {
@@ -2862,6 +2871,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.xml b/tests/qemuxml2argvdata/qemuxml2argv-graphics-listen-network.xml
index bf78ca8..1962474 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-graphics-listen-network.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-listen-network.xml
@@ -25,7 +25,7 @@
     <input type='mouse' bus='ps2'/>
     <input type='keyboard' bus='ps2'/>
     <graphics type='vnc' port='5903' autoport='no'>
-      <listen type='network' network='Bobsnetwork'/>
+      <listen type='network' network='Bobsnetwork' family='default'/>
     </graphics>
     <video>
       <model type='cirrus' vram='16384' heads='1'/>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-graphics-listen-network2.xml b/tests/qemuxml2argvdata/qemuxml2argv-graphics-listen-network2.xml
index 62353e9..d11eead 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-graphics-listen-network2.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-listen-network2.xml
@@ -25,7 +25,7 @@
     <input type='keyboard' bus='ps2'/>
     <graphics type='vnc' listen='1.2.3.4' autoport='yes'>
       <listen type='address' address='1.2.3.4'/>
-      <listen type='network' network='Bobsnetwork'/>
+      <listen type='network' network='Bobsnetwork' family='default'/>
     </graphics>
     <video>
       <model type='cirrus' vram='16384' heads='1'/>
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-graphics-listen-network2.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-graphics-listen-network2.xml
index abee7b6..e69c29a 100644
--- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-graphics-listen-network2.xml
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-graphics-listen-network2.xml
@@ -26,7 +26,7 @@
     <input type='keyboard' bus='ps2'/>
     <graphics type='vnc' port='-1' autoport='yes' listen='1.2.3.4'>
       <listen type='address' address='1.2.3.4'/>
-      <listen type='network' network='Bobsnetwork'/>
+      <listen type='network' network='Bobsnetwork' family='default'/>
     </graphics>
     <video>
       <model type='cirrus' vram='16384' heads='1'/>
-- 
1.8.3.1

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