From d3aa28925f8c914187996542b20ffc69cb627cb9 Mon Sep 17 00:00:00 2001 From: Bastien Orivel Date: Mon, 13 Jul 2020 11:44:13 +0200 Subject: [PATCH] Add a check attribute on the mac address element MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 VMX conversion parts rewritten to apply on top of previously merged support for type='generated|static' Reviewed-by: Michal Privoznik Signed-off-by: Daniel P. Berrangé --- 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 @@ + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 8d328819af..386b04b5b8 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11925,6 +11925,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; @@ -12006,6 +12007,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")) { @@ -12206,6 +12208,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 @@ -26555,6 +26567,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 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + + + + + + + + + + + + + + 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 @@ destroy - + -- 2.47.2