From: Bastien Orivel <bastien.orivel(a)diateam.net>
This is only used in the ESX driver where, when set to "no", it will
ignore all the checks libvirt does about the origin of the MAC address
(whether or not it's in a VMWare OUI) and forward the original one to
the ESX server telling it not to check it either.
This allows keeping a deterministic MAC address which can be useful for
licensed software which might dislike changes.
Signed-off-by: Bastien Orivel <bastien.orivel(a)diateam.net>
VMX conversion parts rewritten to apply on top of previously merged
support for type='generated|static'
Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
docs/schemas/domaincommon.rng | 5 ++++
src/conf/domain_conf.c | 14 +++++++++
src/conf/domain_conf.h | 1 +
src/vmx/vmx.c | 11 +++++++
.../network-interface-mac-check.xml | 29 +++++++++++++++++++
tests/genericxml2xmltest.c | 2 ++
tests/vmx2xmldata/vmx2xml-ethernet-other.xml | 2 +-
.../xml2vmxdata/xml2vmx-ethernet-mac-type.vmx | 2 ++
.../xml2vmxdata/xml2vmx-ethernet-mac-type.xml | 4 +--
9 files changed, 67 insertions(+), 3 deletions(-)
create mode 100644 tests/genericxml2xmlindata/network-interface-mac-check.xml
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index a810f569c6..8cbbd7e6e9 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -3187,6 +3187,11 @@
</choice>
</attribute>
</optional>
+ <optional>
+ <attribute name="check">
+ <ref name="virYesNo"/>
+ </attribute>
+ </optional>
<empty/>
</element>
</optional>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 7ecd2818b9..6c05244c6e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -11928,6 +11928,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
int rv, val;
g_autofree char *macaddr = NULL;
g_autofree char *macaddr_type = NULL;
+ g_autofree char *macaddr_check = NULL;
g_autofree char *type = NULL;
g_autofree char *network = NULL;
g_autofree char *portgroup = NULL;
@@ -12009,6 +12010,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
if (!macaddr && virXMLNodeNameEqual(cur, "mac")) {
macaddr = virXMLPropString(cur, "address");
macaddr_type = virXMLPropString(cur, "type");
+ macaddr_check = virXMLPropString(cur, "check");
} else if (!network &&
def->type == VIR_DOMAIN_NET_TYPE_NETWORK &&
virXMLNodeNameEqual(cur, "source")) {
@@ -12209,6 +12211,16 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
}
def->mac_type = tmp;
}
+ if (macaddr_check) {
+ int tmpCheck;
+ if ((tmpCheck = virTristateBoolTypeFromString(macaddr_check)) < 0) {
+ virReportError(VIR_ERR_XML_ERROR,
+ _("invalid mac address check value: '%s'"),
+ macaddr_check);
+ goto error;
+ }
+ def->mac_check = tmpCheck;
+ }
if (virDomainDeviceInfoParseXML(xmlopt, node, &def->info,
flags | VIR_DOMAIN_DEF_PARSE_ALLOW_BOOT
@@ -26561,6 +26573,8 @@ virDomainNetDefFormat(virBufferPtr buf,
virMacAddrFormat(&def->mac, macstr));
if (def->mac_type)
virBufferAsprintf(buf, " type='%s'",
virDomainNetMacTypeTypeToString(def->mac_type));
+ if (def->mac_check != VIR_TRISTATE_BOOL_ABSENT)
+ virBufferAsprintf(buf, " check='%s'",
virTristateBoolTypeToString(def->mac_check));
virBufferAddLit(buf, "/>\n");
if (publicActual) {
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 241149af24..6e9da298b4 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -982,6 +982,7 @@ struct _virDomainNetDef {
virMacAddr mac;
bool mac_generated; /* true if mac was *just now* auto-generated by libvirt */
virDomainNetMacType mac_type;
+ virTristateBool mac_check;
int model; /* virDomainNetModelType */
char *modelstr;
union {
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index 72f6a7d8dd..a123a8807c 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -2638,6 +2638,14 @@ virVMXParseEthernet(virConfPtr conf, int controller,
virDomainNetDefPtr *def)
goto cleanup;
}
+ if (checkMACAddress) {
+ if (STREQ(checkMACAddress, "true")) {
+ (*def)->mac_check = VIR_TRISTATE_BOOL_YES;
+ } else {
+ (*def)->mac_check = VIR_TRISTATE_BOOL_NO;
+ }
+ }
+
/* vmx:virtualDev, vmx:features -> def:model */
if (virVMXGetConfigString(conf, virtualDev_name, &virtualDev, true) < 0 ||
virVMXGetConfigLong(conf, features_name, &features, 0, true) < 0) {
@@ -3865,6 +3873,9 @@ virVMXFormatEthernet(virDomainNetDefPtr def, int controller,
mac_check = VIR_TRISTATE_BOOL_ABSENT;
}
+ if (def->mac_check != VIR_TRISTATE_BOOL_ABSENT)
+ mac_check = def->mac_check;
+
if (mac_type == VIR_DOMAIN_NET_MAC_TYPE_GENERATED) {
virBufferAsprintf(buffer, "ethernet%d.addressType =
\"%s\"\n",
controller, mac_vpx ? "vpx" :
"generated");
diff --git a/tests/genericxml2xmlindata/network-interface-mac-check.xml
b/tests/genericxml2xmlindata/network-interface-mac-check.xml
new file mode 100644
index 0000000000..a84452fbaf
--- /dev/null
+++ b/tests/genericxml2xmlindata/network-interface-mac-check.xml
@@ -0,0 +1,29 @@
+<domain type='qemu'>
+ <name>QEMUGuest1</name>
+ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+ <memory unit='KiB'>219136</memory>
+ <currentMemory unit='KiB'>219136</currentMemory>
+ <vcpu placement='static'>1</vcpu>
+ <os>
+ <type arch='i686' machine='pc'>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <interface type='bridge'>
+ <mac address='aa:bb:cc:dd:ee:ff'/>
+ <source bridge='br0'/>
+ </interface>
+ <interface type='bridge'>
+ <mac address='aa:bb:cc:dd:ee:fe' type='static'
check='yes'/>
+ <source bridge='br1'/>
+ </interface>
+ <interface type='bridge'>
+ <mac address='aa:bb:cc:dd:ee:fd' type='generated'
check='no'/>
+ <source bridge='br2'/>
+ </interface>
+ </devices>
+</domain>
diff --git a/tests/genericxml2xmltest.c b/tests/genericxml2xmltest.c
index 8b9b0bafb6..102abfdec2 100644
--- a/tests/genericxml2xmltest.c
+++ b/tests/genericxml2xmltest.c
@@ -183,6 +183,8 @@ mymain(void)
DO_TEST("cpu-cache-passthrough");
DO_TEST("cpu-cache-disable");
+ DO_TEST("network-interface-mac-check");
+
DO_TEST_DIFFERENT("chardev-tcp");
DO_TEST_FULL("chardev-tcp-missing-host", 0, false,
TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE);
diff --git a/tests/vmx2xmldata/vmx2xml-ethernet-other.xml
b/tests/vmx2xmldata/vmx2xml-ethernet-other.xml
index b90dfe5d9b..ef324405d7 100644
--- a/tests/vmx2xmldata/vmx2xml-ethernet-other.xml
+++ b/tests/vmx2xmldata/vmx2xml-ethernet-other.xml
@@ -12,7 +12,7 @@
<on_crash>destroy</on_crash>
<devices>
<interface type='bridge'>
- <mac address='00:12:34:56:78:90' type='static'/>
+ <mac address='00:12:34:56:78:90' type='static'
check='no'/>
<source bridge='VM Network'/>
</interface>
<video>
diff --git a/tests/xml2vmxdata/xml2vmx-ethernet-mac-type.vmx
b/tests/xml2vmxdata/xml2vmx-ethernet-mac-type.vmx
index 061aed3010..8d7a067188 100644
--- a/tests/xml2vmxdata/xml2vmx-ethernet-mac-type.vmx
+++ b/tests/xml2vmxdata/xml2vmx-ethernet-mac-type.vmx
@@ -20,9 +20,11 @@ ethernet1.networkName = "br1"
ethernet1.connectionType = "bridged"
ethernet1.addressType = "static"
ethernet1.address = "00:0c:29:dd:ee:fe"
+ethernet1.checkMACAddress = "true"
ethernet2.present = "true"
ethernet2.networkName = "br2"
ethernet2.connectionType = "bridged"
ethernet2.addressType = "generated"
ethernet2.generatedAddress = "aa:bb:cc:dd:ee:fd"
ethernet2.generatedAddressOffset = "0"
+ethernet2.checkMACAddress = "false"
diff --git a/tests/xml2vmxdata/xml2vmx-ethernet-mac-type.xml
b/tests/xml2vmxdata/xml2vmx-ethernet-mac-type.xml
index ee85a1a56a..850fc4d80a 100644
--- a/tests/xml2vmxdata/xml2vmx-ethernet-mac-type.xml
+++ b/tests/xml2vmxdata/xml2vmx-ethernet-mac-type.xml
@@ -18,11 +18,11 @@
<source bridge='br0'/>
</interface>
<interface type='bridge'>
- <mac address='00:0c:29:dd:ee:fe' type='static'/>
+ <mac address='00:0c:29:dd:ee:fe' type='static'
check='yes'/>
<source bridge='br1'/>
</interface>
<interface type='bridge'>
- <mac address='aa:bb:cc:dd:ee:fd' type='generated'/>
+ <mac address='aa:bb:cc:dd:ee:fd' type='generated'
check='no'/>
<source bridge='br2'/>
</interface>
</devices>
--
2.24.1