@@ -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");
@@ -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,
@@ -139,7 +139,7 @@ networkDnsmasqCapsRefresh(virNetworkDriverStatePtr driver)
static virNetworkXMLOptionPtr
networkDnsmasqCreateXMLConf(void)
{
- return virNetworkXMLOptionNew();
+ return virNetworkXMLOptionNew(NULL);
}
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