diff mbox series

[3/5] conf: Add virNetworkXMLNamespace

Message ID c7a30e9fb4b6a30342dd3e4688843c206c6e6259.1563148979.git.crobinso@redhat.com
State Accepted
Commit 2dde2dbba12834e0117cd2a6d0d836910b64769e
Headers show
Series network: xmlns dnsmasq option passthrough | expand

Commit Message

Cole Robinson July 15, 2019, 12:03 a.m. UTC
Just the plumbing, no real implementation yet

Signed-off-by: Cole Robinson <crobinso@redhat.com>

---
 src/conf/network_conf.c     | 22 ++++++++++++++++++++--
 src/conf/network_conf.h     | 21 ++++++++++++++++++++-
 src/network/bridge_driver.c |  2 +-
 3 files changed, 41 insertions(+), 4 deletions(-)

-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Comments

Ján Tomko July 18, 2019, 1:06 p.m. UTC | #1
On Sun, Jul 14, 2019 at 08:03:59PM -0400, Cole Robinson wrote:
>Just the plumbing, no real implementation yet

>

>Signed-off-by: Cole Robinson <crobinso@redhat.com>

>---

> src/conf/network_conf.c     | 22 ++++++++++++++++++++--

> src/conf/network_conf.h     | 21 ++++++++++++++++++++-

> src/network/bridge_driver.c |  2 +-

> 3 files changed, 41 insertions(+), 4 deletions(-)

>

>diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h

>index b7ce569d4a..b167b57e85 100644

>--- a/src/conf/network_conf.h

>+++ b/src/conf/network_conf.h

>@@ -41,9 +41,24 @@

> #include "virmacmap.h"

> #include "virenum.h"

>

>+typedef int (*virNetworkDefNamespaceParse)(xmlXPathContextPtr, void **);

>+typedef void (*virNetworkDefNamespaceFree)(void *);

>+typedef int (*virNetworkDefNamespaceXMLFormat)(virBufferPtr, void *);

>+typedef const char *(*virNetworkDefNamespaceHref)(void);

>+

>+typedef struct _virNetworkXMLNamespace virNetworkXMLNamespace;

>+typedef virNetworkXMLNamespace *virNetworkXMLNamespacePtr;

>+struct _virNetworkXMLNamespace {

>+    virNetworkDefNamespaceParse parse;

>+    virNetworkDefNamespaceFree free;

>+    virNetworkDefNamespaceXMLFormat format;

>+    virNetworkDefNamespaceHref href;

>+};

>


These declarations are identical to virDomainXMLNamespace

Jano
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
diff mbox series

Patch

diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 067adf7936..c5a243684a 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -93,7 +93,7 @@  virNetworkXMLOnceInit(void)
 VIR_ONCE_GLOBAL_INIT(virNetworkXML);
 
 virNetworkXMLOptionPtr
-virNetworkXMLOptionNew(void)
+virNetworkXMLOptionNew(virNetworkXMLNamespacePtr xmlns)
 {
     virNetworkXMLOptionPtr xmlopt;
 
@@ -103,6 +103,9 @@  virNetworkXMLOptionNew(void)
     if (!(xmlopt = virObjectNew(virNetworkXMLOptionClass)))
         return NULL;
 
+    if (xmlns)
+        xmlopt->ns = *xmlns;
+
     return xmlopt;
 }
 
@@ -268,6 +271,8 @@  virNetworkDefFree(virNetworkDefPtr def)
 
     xmlFreeNode(def->metadata);
 
+    if (def->namespaceData && def->ns.free)
+        (def->ns.free)(def->namespaceData);
     VIR_FREE(def);
 }
 
@@ -1622,7 +1627,7 @@  virNetworkForwardDefParseXML(const char *networkName,
 
 virNetworkDefPtr
 virNetworkDefParseXML(xmlXPathContextPtr ctxt,
-                      virNetworkXMLOptionPtr xmlopt ATTRIBUTE_UNUSED)
+                      virNetworkXMLOptionPtr xmlopt)
 {
     virNetworkDefPtr def;
     char *tmp = NULL;
@@ -2043,6 +2048,12 @@  virNetworkDefParseXML(xmlXPathContextPtr ctxt,
         virXMLNodeSanitizeNamespaces(def->metadata);
     }
 
+    if (xmlopt)
+        def->ns = xmlopt->ns;
+    if (def->ns.parse &&
+        (def->ns.parse)(ctxt, &def->namespaceData) < 0)
+        goto error;
+
     ctxt->node = save;
     return def;
 
@@ -2422,6 +2433,8 @@  virNetworkDefFormatBuf(virBufferPtr buf,
     bool hasbridge = false;
 
     virBufferAddLit(buf, "<network");
+    if (def->namespaceData && def->ns.href)
+        virBufferAsprintf(buf, " %s", (def->ns.href)());
     if (!(flags & VIR_NETWORK_XML_INACTIVE) && (def->connections > 0))
         virBufferAsprintf(buf, " connections='%d'", def->connections);
     if (def->ipv6nogw)
@@ -2627,6 +2640,11 @@  virNetworkDefFormatBuf(virBufferPtr buf,
         if (virPortGroupDefFormat(buf, &def->portGroups[i]) < 0)
             goto error;
 
+    if (def->namespaceData && def->ns.format) {
+        if ((def->ns.format)(buf, def->namespaceData) < 0)
+            return -1;
+    }
+
     virBufferAdjustIndent(buf, -2);
     virBufferAddLit(buf, "</network>\n");
 
diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
index b7ce569d4a..b167b57e85 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -41,9 +41,24 @@ 
 #include "virmacmap.h"
 #include "virenum.h"
 
+typedef int (*virNetworkDefNamespaceParse)(xmlXPathContextPtr, void **);
+typedef void (*virNetworkDefNamespaceFree)(void *);
+typedef int (*virNetworkDefNamespaceXMLFormat)(virBufferPtr, void *);
+typedef const char *(*virNetworkDefNamespaceHref)(void);
+
+typedef struct _virNetworkXMLNamespace virNetworkXMLNamespace;
+typedef virNetworkXMLNamespace *virNetworkXMLNamespacePtr;
+struct _virNetworkXMLNamespace {
+    virNetworkDefNamespaceParse parse;
+    virNetworkDefNamespaceFree free;
+    virNetworkDefNamespaceXMLFormat format;
+    virNetworkDefNamespaceHref href;
+};
 
 struct _virNetworkXMLOption {
     virObject parent;
+
+    virNetworkXMLNamespace ns;
 };
 typedef struct _virNetworkXMLOption virNetworkXMLOption;
 typedef virNetworkXMLOption *virNetworkXMLOptionPtr;
@@ -277,6 +292,10 @@  struct _virNetworkDef {
 
     /* Application-specific custom metadata */
     xmlNodePtr metadata;
+
+    /* Network specific XML namespace data */
+    void *namespaceData;
+    virNetworkXMLNamespace ns;
 };
 
 typedef enum {
@@ -298,7 +317,7 @@  enum {
 };
 
 virNetworkXMLOptionPtr
-virNetworkXMLOptionNew(void);
+virNetworkXMLOptionNew(virNetworkXMLNamespacePtr xmlns);
 
 virNetworkDefPtr
 virNetworkDefCopy(virNetworkDefPtr def,
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 3353754eb5..1a4d6e7f7b 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -139,7 +139,7 @@  networkDnsmasqCapsRefresh(virNetworkDriverStatePtr driver)
 static virNetworkXMLOptionPtr
 networkDnsmasqCreateXMLConf(void)
 {
-    return virNetworkXMLOptionNew();
+    return virNetworkXMLOptionNew(NULL);
 }