diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c index 490381688c..7d460e9824 100644 --- a/src/bhyve/bhyve_parse_command.c +++ b/src/bhyve/bhyve_parse_command.c @@ -501,7 +501,7 @@ bhyveParsePCINet(virDomainDefPtr def, const char *separator = NULL; const char *mac = NULL; - if (VIR_ALLOC(net) < 0) + if (!(net = virDomainNetDefNew(xmlopt))) goto cleanup; /* As we only support interface type='bridge' and cannot diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 210deeee7e..e051d4b67a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2455,6 +2455,7 @@ virDomainNetDefFree(virDomainNetDefPtr def) if (!def) return; virDomainNetDefClear(def); + virObjectUnref(def->privateData); VIR_FREE(def); } @@ -11449,7 +11450,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt, VIR_AUTOFREE(char *) trustGuestRxFilters = NULL; VIR_AUTOFREE(char *) vhost_path = NULL; - if (VIR_ALLOC(def) < 0) + if (!(def = virDomainNetDefNew(xmlopt))) return NULL; ctxt->node = node; @@ -14345,6 +14346,24 @@ virDomainGraphicsDefNew(virDomainXMLOptionPtr xmlopt) } +virDomainNetDefPtr +virDomainNetDefNew(virDomainXMLOptionPtr xmlopt) +{ + virDomainNetDefPtr def = NULL; + + if (VIR_ALLOC(def) < 0) + return NULL; + + if (xmlopt && xmlopt->privateData.networkNew && + !(def->privateData = xmlopt->privateData.networkNew())) { + virDomainNetDefFree(def); + def = NULL; + } + + return def; +} + + /* Parse the XML definition for a graphics device */ static virDomainGraphicsDefPtr virDomainGraphicsDefParseXML(virDomainXMLOptionPtr xmlopt, diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 33cef5b75c..c00d2b4953 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1018,6 +1018,7 @@ struct _virDomainNetDef { unsigned int mtu; virNetDevCoalescePtr coalesce; virDomainVirtioOptionsPtr virtio; + virObjectPtr privateData; }; typedef enum { @@ -2713,6 +2714,7 @@ struct _virDomainXMLPrivateDataCallbacks { virDomainXMLPrivateDataNewFunc chrSourceNew; virDomainXMLPrivateDataNewFunc vsockNew; virDomainXMLPrivateDataNewFunc graphicsNew; + virDomainXMLPrivateDataNewFunc networkNew; virDomainXMLPrivateDataFormatFunc format; virDomainXMLPrivateDataParseFunc parse; /* following function shall return a pointer which will be used as the @@ -2897,6 +2899,10 @@ virDomainChrDefPtr virDomainChrDefNew(virDomainXMLOptionPtr xmlopt); virDomainGraphicsDefPtr virDomainGraphicsDefNew(virDomainXMLOptionPtr xmlopt); + +virDomainNetDefPtr +virDomainNetDefNew(virDomainXMLOptionPtr xmlopt); + virDomainDefPtr virDomainDefNew(void); void virDomainObjAssignDef(virDomainObjPtr domain, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a34d92f5ef..f1fe7259f9 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -478,6 +478,7 @@ virDomainNetDefActualToNetworkPort; virDomainNetDefClear; virDomainNetDefFormat; virDomainNetDefFree; +virDomainNetDefNew; virDomainNetDefToNetworkPort; virDomainNetFind; virDomainNetFindByName; diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c index 7eb52c8c84..d327f03d73 100644 --- a/src/libxl/xen_common.c +++ b/src/libxl/xen_common.c @@ -1234,7 +1234,7 @@ xenParseVif(char *entry, const char *vif_typename) key = nextkey; } - if (VIR_ALLOC(net) < 0) + if (!(net = virDomainNetDefNew(NULL))) goto cleanup; if (mac[0]) { diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index b4c6e790d8..018eec6977 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -359,7 +359,7 @@ lxcCreateNetDef(const char *type, virDomainNetDefPtr net = NULL; virMacAddr macAddr; - if (VIR_ALLOC(net) < 0) + if (!(net = virDomainNetDefNew(NULL))) goto error; if (STREQ_NULLABLE(flag, "up")) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 49e657cdb7..ddabcb80ca 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -3692,7 +3692,7 @@ vboxDumpNetwork(vboxDriverPtr data, INetworkAdapter *adapter) char *utf8 = NULL; virDomainNetDefPtr net = NULL; - if (VIR_ALLOC(net) < 0) + if (!(net = virDomainNetDefNew(data->xmlopt))) return NULL; gVBoxAPI.UINetworkAdapter.GetAttachmentType(adapter, &attachmentType);