[PATCH v2] conf: virDomainGraphicsDefValidate: validate attribute 'network' for listen type 'network'

Amneesh Singh posted 1 patch 2 years ago
Test syntax-check passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20220413163137.282909-1-natto@weirdnatto.in
src/conf/domain_validate.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
[PATCH v2] conf: virDomainGraphicsDefValidate: validate attribute 'network' for listen type 'network'
Posted by Amneesh Singh 2 years ago
Related: https://gitlab.com/libvirt/libvirt/-/issues/93
Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
---
v1 PATCH: https://listman.redhat.com/archives/libvir-list/2022-April/230021.html

 src/conf/domain_validate.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c
index 68190fc..e58b84e 100644
--- a/src/conf/domain_validate.c
+++ b/src/conf/domain_validate.c
@@ -2347,10 +2347,35 @@ virDomainAudioDefValidate(const virDomainDef *def,
     return 0;
 }
 
+static int
+virDomainGraphicsDefListensValidate(const virDomainGraphicsDef *def)
+{
+    size_t i;
+
+    for (i = 0; i < def->nListens; i++) {
+        if (def->listens[i].type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK &&
+            !def->listens[i].network) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("'network' attribute is required for "
+                             "listen type 'network'"));
+            return -1;
+        }
+    }
+
+    return 0;
+}
+
 static int
 virDomainGraphicsDefValidate(const virDomainDef *def,
                              const virDomainGraphicsDef *graphics)
 {
+    if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC ||
+        graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE ||
+        graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_RDP) {
+        if (virDomainGraphicsDefListensValidate(graphics) < 0)
+            return -1;
+    }
+
     if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC)
         return virDomainEnsureAudioID(def, graphics->data.vnc.audioId);
 
-- 
2.35.1
Re: [PATCH v2] conf: virDomainGraphicsDefValidate: validate attribute 'network' for listen type 'network'
Posted by Martin Kletzander 1 year, 11 months ago
On Wed, Apr 13, 2022 at 10:01:37PM +0530, Amneesh Singh wrote:
>Related: https://gitlab.com/libvirt/libvirt/-/issues/93
>Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
>---
>v1 PATCH: https://listman.redhat.com/archives/libvir-list/2022-April/230021.html
>
> src/conf/domain_validate.c | 25 +++++++++++++++++++++++++
> 1 file changed, 25 insertions(+)
>

Sorry for missing this patch.

Reviewed-by: Martin Kletzander <mkletzan@redhat.com>

and pushed.  I added a test case here as well to make it complete:

https://listman.redhat.com/archives/libvir-list/2022-May/230664.html