Use the virDomainXMLConf structure to hold this data and tweak the code
to avoid semantic change.
Without configuration the KVM mac prefix is used by default. I chose it
as it's in the privately administered segment so it should be usable for
any purposes.
---
Notes:
Version 4:
- new in series
src/conf/capabilities.c | 14 --------------
src/conf/capabilities.h | 9 ---------
src/conf/domain_conf.c | 26 ++++++++++++++++++++++----
src/conf/domain_conf.h | 3 +++
src/esx/esx_driver.c | 1 -
src/libvirt_private.syms | 3 +--
src/libxl/libxl_conf.c | 2 --
src/libxl/libxl_driver.c | 6 +++++-
src/lxc/lxc_conf.c | 3 ---
src/openvz/openvz_conf.c | 2 --
src/openvz/openvz_driver.c | 2 +-
src/parallels/parallels_driver.c | 12 ++++++++----
src/phyp/phyp_driver.c | 4 ----
src/qemu/qemu_capabilities.c | 3 ---
src/qemu/qemu_command.c | 6 +++---
src/vbox/vbox_tmpl.c | 10 +++++++---
src/vmware/vmware_conf.c | 2 --
src/vmx/vmx.c | 1 +
src/xen/xen_driver.c | 7 ++++++-
src/xen/xen_hypervisor.c | 2 --
tests/vmx2xmltest.c | 1 -
tests/xml2vmxtest.c | 1 -
22 files changed, 57 insertions(+), 63 deletions(-)
diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index 1d29ce6..c7ec92f 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -921,17 +921,3 @@ virCapabilitiesFormatXML(virCapsPtr caps)
return virBufferContentAndReset(&xml);
}
-
-extern void
-virCapabilitiesSetMacPrefix(virCapsPtr caps,
- const unsigned char prefix[VIR_MAC_PREFIX_BUFLEN])
-{
- memcpy(caps->macPrefix, prefix, sizeof(caps->macPrefix));
-}
-
-extern void
-virCapabilitiesGenerateMac(virCapsPtr caps,
- virMacAddrPtr mac)
-{
- virMacAddrGenerate(caps->macPrefix, mac);
-}
diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h
index f4cf8f3..6b65e6a 100644
--- a/src/conf/capabilities.h
+++ b/src/conf/capabilities.h
@@ -162,7 +162,6 @@ struct _virCaps {
virCapsGuestPtr *guests;
/* Move to virDomainXMLConf later */
- unsigned char macPrefix[VIR_MAC_PREFIX_BUFLEN];
int (*defaultConsoleTargetType)(const char *ostype, virArch guestarch);
};
@@ -175,14 +174,6 @@ virCapabilitiesNew(virArch hostarch,
extern void
virCapabilitiesFreeNUMAInfo(virCapsPtr caps);
-extern void
-virCapabilitiesSetMacPrefix(virCapsPtr caps,
- const unsigned char prefix[VIR_MAC_PREFIX_BUFLEN]);
-
-extern void
-virCapabilitiesGenerateMac(virCapsPtr caps,
- virMacAddrPtr mac);
-
extern int
virCapabilitiesAddHostFeature(virCapsPtr caps,
const char *name);
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index cad5387..a26bc7b 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -800,6 +800,16 @@ virDomainXMLConfNew(virDomainDefParserConfigPtr config,
if (xmlns)
xmlconf->ns = *xmlns;
+ /* Technically this forbids to use one of Xerox's MAC address prefixes in
+ * our hypervisor drivers. This shouldn't ever be a problem.
+ *
+ * Use the KVM prefix as default as it's in the privately administered
+ * range */
+ if (memcmp(xmlconf->config.macPrefix,
+ (unsigned char[]) {0x00, 0x00, 0x00}, 3))
+ memcpy(xmlconf->config.macPrefix,
+ (unsigned char[]) {0x54, 0x52, 0x00}, 3);
+
return xmlconf;
}
@@ -5077,6 +5087,14 @@ cleanup:
}
+void
+virDomainNetGenerateMAC(virDomainXMLConfPtr xmlconf,
+ virMacAddrPtr mac)
+{
+ virMacAddrGenerate(xmlconf->config.macPrefix, mac);
+}
+
+
/* Parse a value located at XPATH within CTXT, and store the
* result into val. If REQUIRED, then the value must exist;
* otherwise, the value is optional. The value is in bytes.
@@ -5445,7 +5463,7 @@ error:
* @return 0 on success, -1 on failure
*/
static virDomainNetDefPtr
-virDomainNetDefParseXML(virCapsPtr caps,
+virDomainNetDefParseXML(virDomainXMLConfPtr xmlconf,
xmlNodePtr node,
xmlXPathContextPtr ctxt,
virBitmapPtr bootMap,
@@ -5630,7 +5648,7 @@ virDomainNetDefParseXML(virCapsPtr caps,
goto error;
}
} else {
- virCapabilitiesGenerateMac(caps, &def->mac);
+ virDomainNetGenerateMAC(xmlconf, &def->mac);
}
if (devaddr) {
@@ -8553,7 +8571,7 @@ virDomainDeviceDefParse(virCapsPtr caps,
goto error;
} else if (xmlStrEqual(node->name, BAD_CAST "interface")) {
dev->type = VIR_DOMAIN_DEVICE_NET;
- if (!(dev->data.net = virDomainNetDefParseXML(caps, node, ctxt,
+ if (!(dev->data.net = virDomainNetDefParseXML(xmlconf, node, ctxt,
NULL, flags)))
goto error;
} else if (xmlStrEqual(node->name, BAD_CAST "input")) {
@@ -10493,7 +10511,7 @@ virDomainDefParseXML(virCapsPtr caps,
if (n && VIR_ALLOC_N(def->nets, n) < 0)
goto no_memory;
for (i = 0 ; i < n ; i++) {
- virDomainNetDefPtr net = virDomainNetDefParseXML(caps,
+ virDomainNetDefPtr net = virDomainNetDefParseXML(xmlconf,
nodes[i],
ctxt,
bootMap,
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index a253438..6f24528 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1975,6 +1975,7 @@ struct _virDomainDefParserConfig {
/* data */
bool hasWideScsiBus;
+ unsigned char macPrefix[VIR_MAC_PREFIX_BUFLEN];
};
typedef struct _virDomainXMLPrivateDataCallbacks virDomainXMLPrivateDataCallbacks;
@@ -1991,6 +1992,8 @@ virDomainXMLConfPtr virDomainXMLConfNew(virDomainDefParserConfigPtr
config,
virDomainXMLPrivateDataCallbacksPtr priv,
virDomainXMLNamespacePtr xmlns);
+void virDomainNetGenerateMAC(virDomainXMLConfPtr xmlconf, virMacAddrPtr mac);
+
virDomainXMLNamespacePtr
virDomainXMLConfGetNamespace(virDomainXMLConfPtr xmlconf)
ATTRIBUTE_NONNULL(1);
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index ff2a9b8..aa6f8c1 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -598,7 +598,6 @@ esxCapsInit(esxPrivate *priv)
return NULL;
}
- virCapabilitiesSetMacPrefix(caps, (unsigned char[]){ 0x00, 0x0c, 0x29 });
virCapabilitiesAddHostMigrateTransport(caps, "vpxmigr");
caps->defaultConsoleTargetType = esxDefaultConsoleType;
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index fb05d59..5326766 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -20,10 +20,8 @@ virCapabilitiesDefaultGuestMachine;
virCapabilitiesFormatXML;
virCapabilitiesFreeMachines;
virCapabilitiesFreeNUMAInfo;
-virCapabilitiesGenerateMac;
virCapabilitiesNew;
virCapabilitiesSetHostCPU;
-virCapabilitiesSetMacPrefix;
# conf/cpu_conf.h
@@ -238,6 +236,7 @@ virDomainMemDumpTypeToString;
virDomainNetDefFree;
virDomainNetFind;
virDomainNetFindIdx;
+virDomainNetGenerateMAC;
virDomainNetGetActualBandwidth;
virDomainNetGetActualBridgeName;
virDomainNetGetActualDirectDev;
diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index b208dd8..ed3e832 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -85,8 +85,6 @@ libxlBuildCapabilities(virArch hostarch,
if ((caps = virCapabilitiesNew(hostarch, 1, 1)) == NULL)
goto no_memory;
- virCapabilitiesSetMacPrefix(caps, (unsigned char[]){ 0x00, 0x16, 0x3e });
-
if (host_pae &&
virCapabilitiesAddHostFeature(caps, "pae") < 0)
goto no_memory;
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index fd69637..cfc2cfe 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -431,6 +431,10 @@ virDomainXMLPrivateDataCallbacks libxlDomainXMLPrivateDataCallbacks =
{
.free = libxlDomainObjPrivateFree,
};
+virDomainDefParserConfig libxlDomainDefParserConfig = {
+ .macPrefix = { 0x00, 0x16, 0x3e },
+};
+
/* driver must be locked before calling */
static void
libxlDomainEventQueue(libxlDriverPrivatePtr driver, virDomainEventPtr event)
@@ -1239,7 +1243,7 @@ libxlStartup(bool privileged,
goto error;
}
- if (!(libxl_driver->xmlconf = virDomainXMLConfNew(NULL,
+ if (!(libxl_driver->xmlconf =
virDomainXMLConfNew(&libxlDomainDefParserConfig,
&libxlDomainXMLPrivateDataCallbacks,
NULL)))
goto error;
diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c
index 71b8916..d835139 100644
--- a/src/lxc/lxc_conf.c
+++ b/src/lxc/lxc_conf.c
@@ -79,9 +79,6 @@ virCapsPtr lxcCapsInit(virLXCDriverPtr driver)
goto error;
}
- /* XXX shouldn't 'borrow' KVM's prefix */
- virCapabilitiesSetMacPrefix(caps, (unsigned char []){ 0x52, 0x54, 0x00 });
-
if ((guest = virCapabilitiesAddGuest(caps,
"exe",
caps->host.arch,
diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
index 05c6113..83d8d18 100644
--- a/src/openvz/openvz_conf.c
+++ b/src/openvz/openvz_conf.c
@@ -187,8 +187,6 @@ virCapsPtr openvzCapsInit(void)
if (nodeCapsInitNUMA(caps) < 0)
goto no_memory;
- virCapabilitiesSetMacPrefix(caps, (unsigned char[]){ 0x52, 0x54, 0x00 });
-
if ((guest = virCapabilitiesAddGuest(caps,
"exe",
caps->host.arch,
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index de6198c..350c8c7 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -832,7 +832,7 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid,
}
virMacAddrFormat(&net->mac, macaddr);
- virCapabilitiesGenerateMac(driver->caps, &host_mac);
+ virDomainNetGenerateMAC(driver->xmlconf, &host_mac);
virMacAddrFormat(&host_mac, host_macaddr);
if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE ||
diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c
index ffb86dc..b137b66 100644
--- a/src/parallels/parallels_driver.c
+++ b/src/parallels/parallels_driver.c
@@ -129,9 +129,6 @@ parallelsBuildCapabilities(void)
if (nodeCapsInitNUMA(caps) < 0)
goto no_memory;
- virCapabilitiesSetMacPrefix(caps, (unsigned char[]) {
- 0x42, 0x1C, 0x00});
-
if ((guest = virCapabilitiesAddGuest(caps, "hvm",
VIR_ARCH_X86_64,
"parallels",
@@ -911,6 +908,12 @@ parallelsLoadDomains(parallelsConnPtr privconn, const char
*domain_name)
return ret;
}
+
+virDomainDefParserConfig parallelsDomainDefParserConfig = {
+ .macPrefix = {0x42, 0x1C, 0x00},
+};
+
+
static int
parallelsOpenDefault(virConnectPtr conn)
{
@@ -929,7 +932,8 @@ parallelsOpenDefault(virConnectPtr conn)
if (!(privconn->caps = parallelsBuildCapabilities()))
goto error;
- if (!(privconn->xmlconf = virDomainXMLConfNew(NULL, NULL, NULL)))
+ if (!(privconn->xmlconf =
virDomainXMLConfNew(¶llelsDomainDefParserConfig,
+ NULL, NULL)))
goto error;
if (!(privconn->domains = virDomainObjListNew()))
diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index 6063256..8b3fdb6 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -327,10 +327,6 @@ phypCapsInit(void)
("Failed to query host NUMA topology, disabling NUMA
capabilities");
}
- /* XXX shouldn't 'borrow' KVM's prefix */
- virCapabilitiesSetMacPrefix(caps, (unsigned char[]) {
- 0x52, 0x54, 0x00});
-
if ((guest = virCapabilitiesAddGuest(caps,
"linux",
caps->host.arch,
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 4ef7092..f3517c1 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -871,9 +871,6 @@ virCapsPtr virQEMUCapsInit(virQEMUCapsCachePtr cache)
1, 1)) == NULL)
goto error;
- /* Using KVM's mac prefix for QEMU too */
- virCapabilitiesSetMacPrefix(caps, (unsigned char[]){ 0x52, 0x54, 0x00 });
-
/* Some machines have problematic NUMA toplogy causing
* unexpected failures. We don't want to break the QEMU
* driver in this scenario, so log errors & carry on
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index ea99d69..aba6eb1 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -8129,7 +8129,7 @@ qemuFindNICForVLAN(int nnics,
* match up against. Horribly complicated stuff
*/
static virDomainNetDefPtr
-qemuParseCommandLineNet(virCapsPtr qemuCaps,
+qemuParseCommandLineNet(virDomainXMLConfPtr xmlconf,
const char *val,
int nnics,
const char **nics)
@@ -8263,7 +8263,7 @@ qemuParseCommandLineNet(virCapsPtr qemuCaps,
}
if (genmac)
- virCapabilitiesGenerateMac(qemuCaps, &def->mac);
+ virDomainNetGenerateMAC(xmlconf, &def->mac);
cleanup:
for (i = 0 ; i < nkeywords ; i++) {
@@ -9359,7 +9359,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
WANT_VALUE();
if (!STRPREFIX(val, "nic") && STRNEQ(val,
"none")) {
virDomainNetDefPtr net;
- if (!(net = qemuParseCommandLineNet(qemuCaps, val, nnics, nics)))
+ if (!(net = qemuParseCommandLineNet(xmlconf, val, nnics, nics)))
goto error;
if (VIR_REALLOC_N(def->nets, def->nnets+1) < 0) {
virDomainNetDefFree(net);
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index dd96e7b..6f2dcf0 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -851,10 +851,16 @@ static int vboxDefaultConsoleType(const char *ostype
ATTRIBUTE_UNUSED,
}
+static virDomainDefParserConfig vboxDomainDefParserConfig = {
+ .macPrefix = { 0x08, 0x00, 0x27 },
+};
+
+
static virDomainXMLConfPtr
vboxXMLConfInit(void)
{
- return virDomainXMLConfNew(NULL, NULL, NULL);
+ return virDomainXMLConfNew(&vboxDomainDefParserConfig,
+ NULL, NULL);
}
@@ -870,8 +876,6 @@ static virCapsPtr vboxCapsInit(void)
if (nodeCapsInitNUMA(caps) < 0)
goto no_memory;
- virCapabilitiesSetMacPrefix(caps, (unsigned char[]){ 0x08, 0x00, 0x27 });
-
if ((guest = virCapabilitiesAddGuest(caps,
"hvm",
caps->host.arch,
diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c
index e5e8c40..ab06c66 100644
--- a/src/vmware/vmware_conf.c
+++ b/src/vmware/vmware_conf.c
@@ -72,8 +72,6 @@ vmwareCapsInit(void)
if (nodeCapsInitNUMA(caps) < 0)
goto error;
- virCapabilitiesSetMacPrefix(caps, (unsigned char[]) {0x52, 0x54, 0x00});
-
/* i686 guests are always supported */
if ((guest = virCapabilitiesAddGuest(caps,
"hvm",
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index 1761a80..a211eb6 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -521,6 +521,7 @@ VIR_ENUM_IMPL(virVMXControllerModelSCSI,
VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LAST,
virDomainDefParserConfig virVMXDomainDefParserConfig = {
.hasWideScsiBus = true,
+ .macPrefix = {0x00, 0x0c, 0x29},
};
diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index 2ef3609..b13dcec 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -265,6 +265,10 @@ xenUnifiedXendProbe(void)
#endif
+virDomainDefParserConfig xenDomainDefParserConfig = {
+ .macPrefix = { 0x00, 0x16, 0x3e },
+};
+
static virDrvOpenStatus
xenUnifiedOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags)
@@ -401,7 +405,8 @@ xenUnifiedOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned
int flags)
goto fail;
}
- if (!(priv->xmlconf = virDomainXMLConfNew(NULL, NULL, NULL)))
+ if (!(priv->xmlconf = virDomainXMLConfNew(&xenDomainDefParserConfig,
+ NULL, NULL)))
goto fail;
#if WITH_XEN_INOTIFY
diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c
index d803972..69bc6cd 100644
--- a/src/xen/xen_hypervisor.c
+++ b/src/xen/xen_hypervisor.c
@@ -2303,8 +2303,6 @@ xenHypervisorBuildCapabilities(virConnectPtr conn, virArch
hostarch,
if ((caps = virCapabilitiesNew(hostarch, 1, 1)) == NULL)
goto no_memory;
- virCapabilitiesSetMacPrefix(caps, (unsigned char[]){ 0x00, 0x16, 0x3e });
-
if (hvm_type && STRNEQ(hvm_type, "") &&
virCapabilitiesAddHostFeature(caps, hvm_type) < 0)
goto no_memory;
diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c
index d73c6d2..7f2c73b 100644
--- a/tests/vmx2xmltest.c
+++ b/tests/vmx2xmltest.c
@@ -35,7 +35,6 @@ testCapsInit(void)
caps->defaultConsoleTargetType = testDefaultConsoleType;
- virCapabilitiesSetMacPrefix(caps, (unsigned char[]){ 0x00, 0x0c, 0x29 });
virCapabilitiesAddHostMigrateTransport(caps, "esx");
/* i686 guest */
diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c
index 303cb22..b62d214 100644
--- a/tests/xml2vmxtest.c
+++ b/tests/xml2vmxtest.c
@@ -34,7 +34,6 @@ testCapsInit(void)
caps->defaultConsoleTargetType = testDefaultConsoleType;
- virCapabilitiesSetMacPrefix(caps, (unsigned char[]){ 0x00, 0x0c, 0x29 });
virCapabilitiesAddHostMigrateTransport(caps, "esx");
--
1.8.1.5