]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
bhyve: extend serial devices validation
authorRoman Bogorodskiy <bogorodskiy@gmail.com>
Tue, 15 Jul 2025 18:20:12 +0000 (20:20 +0200)
committerRoman Bogorodskiy <bogorodskiy@gmail.com>
Thu, 17 Jul 2025 17:29:11 +0000 (19:29 +0200)
Extend bhyveDomainDeviceDefValidate() to check that:

 - only 'nmdm' or 'tcp' serial devices are used,
 - serial device count is not more than supported,
 - only listening raw TCP sockets are used.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
src/bhyve/bhyve_domain.c

index c9bbf27d83caf00c98b591085d0d816eb9da8370..9dec300a99d0aa460309084aaf1cdcdd677d1294 100644 (file)
@@ -263,6 +263,33 @@ bhyveDomainDeviceDefValidate(const virDomainDeviceDef *dev,
                            _("Only 'virio' RNG device model is supported"));
             return -1;
         }
+    } else if (dev->type == VIR_DOMAIN_DEVICE_CHR &&
+               dev->data.chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL) {
+        virDomainChrDef *chr = dev->data.chr;
+        if (chr->source->type != VIR_DOMAIN_CHR_TYPE_NMDM &&
+            chr->source->type != VIR_DOMAIN_CHR_TYPE_TCP) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("Only 'nmdm' and 'tcp' console types are supported"));
+            return -1;
+        }
+        if (chr->target.port > 3) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("Only four serial ports are supported"));
+            return -1;
+        }
+        if (chr->source->type == VIR_DOMAIN_CHR_TYPE_TCP) {
+            if (chr->source->data.tcp.listen == false) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                               _("Only listening TCP sockets are supported"));
+                return -1;
+            }
+
+            if (chr->source->data.tcp.protocol != VIR_DOMAIN_CHR_TCP_PROTOCOL_RAW) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                               _("Only 'raw' protocol is supported for TCP sockets"));
+                return -1;
+            }
+        }
     }
 
     return 0;