If mgmt apps on top of libvirt want to make a decision on the
backend type for <interface type='user'/> (e.g. whether past is
supported) we currently offer them no way to learn this fact.
Domain capabilities were invented exactly for this reason. Report
supported net backend types there.

Now, because of backwards compatibility, specifying no backend
type (which translates to VIR_DOMAIN_NET_BACKEND_DEFAULT) means
"use hyperviosr's builtin SLIRP". That behaviour can not be
changed. But it may happen that the hypervisor has no support for
SLIRP. So we have to report it.

Signed-off-by: Michal Privoznik <mpriv...@redhat.com>
---
 docs/formatdomaincaps.rst       | 25 +++++++++++++++++++++++++
 src/conf/domain_capabilities.c  | 13 +++++++++++++
 src/conf/domain_capabilities.h  |  8 ++++++++
 src/conf/schemas/domaincaps.rng | 10 ++++++++++
 4 files changed, 56 insertions(+)

diff --git a/docs/formatdomaincaps.rst b/docs/formatdomaincaps.rst
index a2ad0acc3d..be45de8996 100644
--- a/docs/formatdomaincaps.rst
+++ b/docs/formatdomaincaps.rst
@@ -629,6 +629,31 @@ Crypto device capabilities are exposed under the 
``crypto`` element. For instanc
 ``backendModel``
    Options for the ``backendModel`` attribute of the ``<crypto><backend/>`` 
element.
 
+Interface device
+^^^^^^^^^^^^^^^^
+
+Interface device corresponds to `network interface
+<formatdomain.html#network-interfaces>`__ (``<interface/>``) in domain XML.
+
+::
+
+  <domainCapabilities>
+    ...
+    <devices>
+      <interface supported='yes'>
+        <enum name='backendType'>
+          <value>default</value>
+          <value>passt</value>
+        </enum>
+      </interface>
+      ...
+    </devices>
+  </domainCapabilities>
+
+``backendType``
+   Options for the ``type`` attribute of the ``<backend/>`` element
+
+
 Features
 ~~~~~~~~
 
diff --git a/src/conf/domain_capabilities.c b/src/conf/domain_capabilities.c
index 3f2d231d1c..199bac006b 100644
--- a/src/conf/domain_capabilities.c
+++ b/src/conf/domain_capabilities.c
@@ -607,6 +607,18 @@ virDomainCapsDeviceCryptoFormat(virBuffer *buf,
 }
 
 
+static void
+virDomainCapsDeviceNetFormat(virBuffer *buf,
+                             const virDomainCapsDeviceNet *interface)
+{
+    FORMAT_PROLOGUE(interface);
+
+    ENUM_PROCESS(interface, backendType, virDomainNetBackendTypeToString);
+
+    FORMAT_EPILOGUE(interface);
+}
+
+
 /**
  * virDomainCapsFeatureGICFormat:
  * @buf: target buffer
@@ -787,6 +799,7 @@ virDomainCapsFormat(const virDomainCaps *caps)
     virDomainCapsDeviceRedirdevFormat(&buf, &caps->redirdev);
     virDomainCapsDeviceChannelFormat(&buf, &caps->channel);
     virDomainCapsDeviceCryptoFormat(&buf, &caps->crypto);
+    virDomainCapsDeviceNetFormat(&buf, &caps->net);
 
     virBufferAdjustIndent(&buf, -2);
     virBufferAddLit(&buf, "</devices>\n");
diff --git a/src/conf/domain_capabilities.h b/src/conf/domain_capabilities.h
index 986f3cb394..3fe62ce211 100644
--- a/src/conf/domain_capabilities.h
+++ b/src/conf/domain_capabilities.h
@@ -250,6 +250,13 @@ struct _virDomainCapsDeviceCrypto {
     virDomainCapsEnum backendModel;   /* virDomainCryptoBackend */
 };
 
+STATIC_ASSERT_ENUM(VIR_DOMAIN_NET_BACKEND_LAST);
+typedef struct _virDomainCapsDeviceNet virDomainCapsDeviceNet;
+struct _virDomainCapsDeviceNet {
+    virTristateBool supported;
+    virDomainCapsEnum backendType; /* virDomainNetBackendType */
+};
+
 typedef enum {
     VIR_DOMAIN_CAPS_FEATURE_IOTHREADS = 0,
     VIR_DOMAIN_CAPS_FEATURE_VMCOREINFO,
@@ -286,6 +293,7 @@ struct _virDomainCaps {
     virDomainCapsDeviceRedirdev redirdev;
     virDomainCapsDeviceChannel channel;
     virDomainCapsDeviceCrypto crypto;
+    virDomainCapsDeviceNet net;
     /* add new domain devices here */
 
     virDomainCapsFeatureGIC gic;
diff --git a/src/conf/schemas/domaincaps.rng b/src/conf/schemas/domaincaps.rng
index b8115fe028..f17a4e681d 100644
--- a/src/conf/schemas/domaincaps.rng
+++ b/src/conf/schemas/domaincaps.rng
@@ -212,6 +212,9 @@
       <optional>
         <ref name="crypto"/>
       </optional>
+      <optional>
+        <ref name="interface"/>
+      </optional>
     </element>
   </define>
 
@@ -285,6 +288,13 @@
     </element>
   </define>
 
+  <define name="interface">
+    <element name="interface">
+      <ref name="supported"/>
+      <ref name="enum"/>
+    </element>
+  </define>
+
   <define name="launchSecurity">
     <element name="launchSecurity">
       <ref name="supported"/>
-- 
2.44.2

Reply via email to