提交 96ceb124 编写于 作者: M Matthias Bolte

esx: Fix 'vpx' MAC address range and allow arbitrary MAC addresses

The MAC addresses with 00:50:56 prefix are split into several ranges:

  00:50:56:00:00:00 - 00:50:56:3f:ff:ff  'static' range (manually assigned)
  00:50:56:80:00:00 - 00:50:56:bf:ff:ff  'vpx' range (assigned by a VI Client)

Erroneously the 'vpx' range was assumed to be larger and to occupy the
remaining addresses of the 00:50:56 prefix that are not part of the 'static'
range.

00:50:56 was used as prefix for generated MAC addresses, this is not possible
anymore, because there are gaps in the allowed ranges. Therefore, change the
prefix to 00:0c:29 which is the prefix for auto generated MAC addresses anyway.

Allow arbitrary MAC addresses to be used and set the checkMACAddress VMX option
to false in case the MAC address doesn't fall into any predefined range.

* docs/drvesx.html.in: update website accordingly
* src/esx/esx_driver.c: set the auto generation prefix to 00:0c:29
* src/esx/esx_vmx.c: fix MAC address range handling and allow arbitrary MAC
  addresses
* tests/vmx2xml*, tests/xml2vmx*: add some basic MAC address range tests
上级 79f94196
......@@ -16,8 +16,8 @@
SOAP based
<a href="http://www.vmware.com/support/developer/vc-sdk/visdk25pubs/ReferenceGuide/">
VMware Virtual Infrastructure API</a> (VI API) to communicate with the
ESX server, like the VMware Virtual Infrastructure Client does. Since
version 4.0 this API is called
ESX server, like the VMware Virtual Infrastructure Client (VI client)
does. Since version 4.0 this API is called
<a href="http://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/">
VMware vSphere API</a>.
</p>
......@@ -159,7 +159,7 @@ type://[username@]hostname[:port]/[?extraparameters]
There are several specialties in the domain XML config for ESX domains.
</p>
<h3>Restrictions</h3>
<h3><a name="restrictions">Restrictions</h3>
<p>
There are some restrictions for some values of the domain XML config.
The driver will complain if this restrictions are violated.
......@@ -173,12 +173,13 @@ type://[username@]hostname[:port]/[?extraparameters]
</li>
<li>
Valid MAC address prefixes are <code>00:0c:29</code> and
<code>00:50:56</code>
<code>00:50:56</code>. <span class="since">Since 0.7.6</span>
arbitrary <a href="#macaddresses">MAC addresses</a> are supported.
</li>
</ul>
<h3>Datastore references</h3>
<h3><a name="datastore">Datastore references</h3>
<p>
Storage is managed in datastores. VMware uses a special path format to
reference files in a datastore. Basically, the datastore name is put
......@@ -197,7 +198,68 @@ type://[username@]hostname[:port]/[?extraparameters]
</p>
<h3>Available hardware</h3>
<h3><a name="macaddresses">MAC addresses</h3>
<p>
VMware has registered two MAC address prefixes for domains:
<code>00:0c:29</code> and <code>00:50:56</code>. These prefixes are
split into ranges for different purposes.
</p>
<table class="top_table">
<tr>
<th>Range</th>
<th>Purpose</th>
</tr>
<tr>
<td>
<code>00:0c:29:00:00:00</code> - <code>00:0c:29:ff:ff:ff</code>
</td>
<td>
An ESX server autogenerates MAC addresses from this range if
the VMX file doesn't contain a MAC address when trying to start
a domain.
</td>
</tr>
<tr>
<td>
<code>00:50:56:00:00:00</code> - <code>00:50:56:3f:ff:ff</code>
</td>
<td>
MAC addresses from this range can by manually assigned by the
user in the VI client.
</td>
</tr>
<tr>
<td>
<code>00:50:56:80:00:00</code> - <code>00:50:56:bf:ff:ff</code>
</td>
<td>
A VI client autogenerates MAC addresses from this range for
newly defined domains.
</td>
</tr>
</table>
<p>
The VMX files generated by the ESX driver always contain a MAC address,
because libvirt generates a random one if an interface element in the
domain XML file lacks a MAC address.
<span class="since">Since 0.7.6</span> the ESX driver sets the prefix
for generated MAC addresses to <code>00:0c:29</code>. Before 0.7.6
the <code>00:50:56</code> prefix was used. Sometimes this resulted in
the generation of out-of-range MAC address that were rejected by the
ESX server.
</p>
<p>
Also <span class="since">since 0.7.6</span> every MAC address outside
this ranges can be used. For such MAC addresses the ESX server-side
check is disabled in the VMX file to stop the ESX server from rejecting
out-of-predefined-range MAC addresses.
</p>
<pre>
ethernet0.checkMACAddress = "false"
</pre>
<h3><a name="hardware">Available hardware</h3>
<p>
VMware ESX supports different models of SCSI controllers and network
cards.
......
......@@ -184,7 +184,7 @@ esxCapsInit(virConnectPtr conn)
return NULL;
}
virCapabilitiesSetMacPrefix(caps, (unsigned char[]){ 0x00, 0x50, 0x56 });
virCapabilitiesSetMacPrefix(caps, (unsigned char[]){ 0x00, 0x0c, 0x29 });
virCapabilitiesAddHostMigrateTransport(caps, "esx");
/* i686 */
......
......@@ -266,8 +266,8 @@ def->nets[0]...
ethernet0.addressType = "generated" # default to "generated"
ethernet0.generatedAddressOffset = "0" # ?
->mac = <value> <=> ethernet0.generatedAddress = "<value>"
ethernet0.generatedAddressOffset = "0" # ?
ethernet0.addressType = "static" # default to "generated"
......@@ -277,10 +277,15 @@ def->nets[0]...
ethernet0.addressType = "vpx" # default to "generated"
->mac = <value> <=> ethernet0.generatedAddress = "<value>"
ethernet0.addressType = "static" # default to "generated"
->mac = <value> <=> ethernet0.address = "<value>"
ethernet0.checkMACAddress = "false" # mac address outside the VMware prefixes
# 00:0c:29 prefix for autogenerated mac's -> ethernet0.addressType = "generated"
# 00:50:56 prefix for manual configured mac's
# 00:50:56:00:00:00 - 00:50:56:3f:ff:ff -> ethernet0.addressType = "static"
# 00:50:56:40:00:00 - 00:50:56:ff:ff:ff -> ethernet0.addressType = "vpx"
# 00:50:56:80:00:00 - 00:50:56:bf:ff:ff -> ethernet0.addressType = "vpx"
# 00:05:69 old prefix from esx 1.5
......@@ -2602,6 +2607,7 @@ esxVMX_FormatEthernet(virConnectPtr conn, virDomainNetDefPtr def,
int controller, virBufferPtr buffer)
{
char mac_string[VIR_MAC_STRING_BUFLEN];
unsigned int prefix, suffix;
if (controller < 0 || controller > 3) {
ESX_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
......@@ -2654,33 +2660,36 @@ esxVMX_FormatEthernet(virConnectPtr conn, virDomainNetDefPtr def,
return -1;
}
/* def:mac -> vmx:addressType, vmx:(generated)Address, vmx:checkMACAddress */
virFormatMacAddr(def->mac, mac_string);
if (def->mac[0] == 0x00 && def->mac[1] == 0x0c && def->mac[2] == 0x29) {
prefix = (def->mac[0] << 16) | (def->mac[1] << 8) | def->mac[2];
suffix = (def->mac[3] << 16) | (def->mac[4] << 8) | def->mac[5];
if (prefix == 0x000c29) {
virBufferVSprintf(buffer, "ethernet%d.addressType = \"generated\"\n",
controller);
virBufferVSprintf(buffer, "ethernet%d.generatedAddress = \"%s\"\n",
controller, mac_string);
virBufferVSprintf(buffer, "ethernet%d.generatedAddressOffset = \"0\"\n",
controller);
} else if (def->mac[0] == 0x00 && def->mac[1] == 0x50 && def->mac[2] == 0x56) {
if (def->mac[3] <= 0x3f) {
} else if (prefix == 0x005056 && suffix <= 0x3fffff) {
virBufferVSprintf(buffer, "ethernet%d.addressType = \"static\"\n",
controller);
virBufferVSprintf(buffer, "ethernet%d.address = \"%s\"\n",
controller, mac_string);
} else {
} else if (prefix == 0x005056 && suffix >= 0x800000 && suffix <= 0xbfffff) {
virBufferVSprintf(buffer, "ethernet%d.addressType = \"vpx\"\n",
controller);
virBufferVSprintf(buffer, "ethernet%d.generatedAddress = \"%s\"\n",
controller, mac_string);
}
} else {
ESX_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
"Unsupported MAC address prefix '%02X:%02X:%02X', expecting "
"'00:0c:29' or '00:50:56'",
def->mac[0], def->mac[1], def->mac[2]);
return -1;
virBufferVSprintf(buffer, "ethernet%d.addressType = \"static\"\n",
controller);
virBufferVSprintf(buffer, "ethernet%d.address = \"%s\"\n",
controller, mac_string);
virBufferVSprintf(buffer, "ethernet%d.checkMACAddress = \"false\"\n",
controller);
}
return 0;
......
config.version = "8"
virtualHW.version = "4"
ethernet0.present = "true"
ethernet0.networkName = "VM Network"
ethernet0.connectionType = "bridged"
ethernet0.addressType = "generated"
ethernet0.generatedAddress = "00:0C:29:11:22:33"
ethernet0.generatedAddressOffset = "0"
<domain type='vmware'>
<uuid>00000000-0000-0000-0000-000000000000</uuid>
<memory>32768</memory>
<currentMemory>32768</currentMemory>
<vcpu>1</vcpu>
<os>
<type arch='i686'>hvm</type>
</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='00:0c:29:11:22:33'/>
<source bridge='VM Network'/>
</interface>
</devices>
</domain>
config.version = "8"
virtualHW.version = "4"
ethernet0.present = "true"
ethernet0.networkName = "VM Network"
ethernet0.connectionType = "bridged"
ethernet0.checkMACAddress = "false"
ethernet0.addressType = "static"
ethernet0.address = "00:12:34:56:78:90"
<domain type='vmware'>
<uuid>00000000-0000-0000-0000-000000000000</uuid>
<memory>32768</memory>
<currentMemory>32768</currentMemory>
<vcpu>1</vcpu>
<os>
<type arch='i686'>hvm</type>
</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='00:12:34:56:78:90'/>
<source bridge='VM Network'/>
</interface>
</devices>
</domain>
config.version = "8"
virtualHW.version = "4"
ethernet0.present = "true"
ethernet0.networkName = "VM Network"
ethernet0.connectionType = "bridged"
ethernet0.addressType = "static"
ethernet0.address = "00:50:56:11:22:33"
<domain type='vmware'>
<uuid>00000000-0000-0000-0000-000000000000</uuid>
<memory>32768</memory>
<currentMemory>32768</currentMemory>
<vcpu>1</vcpu>
<os>
<type arch='i686'>hvm</type>
</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='00:50:56:11:22:33'/>
<source bridge='VM Network'/>
</interface>
</devices>
</domain>
config.version = "8"
virtualHW.version = "4"
ethernet0.present = "true"
ethernet0.networkName = "VM Network"
ethernet0.connectionType = "bridged"
ethernet0.addressType = "vpx"
ethernet0.generatedAddress = "00:50:56:87:65:43"
<domain type='vmware'>
<uuid>00000000-0000-0000-0000-000000000000</uuid>
<memory>32768</memory>
<currentMemory>32768</currentMemory>
<vcpu>1</vcpu>
<os>
<type arch='i686'>hvm</type>
</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='00:50:56:87:65:43'/>
<source bridge='VM Network'/>
</interface>
</devices>
</domain>
......@@ -139,6 +139,11 @@ mymain(int argc, char **argv)
DO_TEST("ethernet-custom", "ethernet-custom", esxVI_APIVersion_25);
DO_TEST("ethernet-bridged", "ethernet-bridged", esxVI_APIVersion_25);
DO_TEST("ethernet-generated", "ethernet-generated", esxVI_APIVersion_25);
DO_TEST("ethernet-static", "ethernet-static", esxVI_APIVersion_25);
DO_TEST("ethernet-vpx", "ethernet-vpx", esxVI_APIVersion_25);
DO_TEST("ethernet-other", "ethernet-other", esxVI_APIVersion_25);
DO_TEST("serial-file", "serial-file", esxVI_APIVersion_25);
DO_TEST("serial-device", "serial-device", esxVI_APIVersion_25);
DO_TEST("serial-pipe-client-app", "serial-pipe", esxVI_APIVersion_25);
......
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
uuid.bios = "56 4d 9b ef ac d9 b4 e0-c8 f0 ae a8 b9 10 35 15"
displayName = "ethernet-generated"
memsize = "4"
numvcpus = "1"
ethernet0.present = "true"
ethernet0.networkName = "VM Network"
ethernet0.connectionType = "bridged"
ethernet0.addressType = "generated"
ethernet0.generatedAddress = "00:0C:29:11:22:33"
ethernet0.generatedAddressOffset = "0"
<domain type='vmware'>
<name>ethernet-generated</name>
<uuid>564d9bef-acd9-b4e0-c8f0-aea8b9103515</uuid>
<memory>4096</memory>
<os>
<type>hvm</type>
</os>
<devices>
<interface type='bridge'>
<mac address='00:0c:29:11:22:33'/>
<source bridge='VM Network'/>
</interface>
</devices>
</domain>
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
uuid.bios = "56 4d 9b ef ac d9 b4 e0-c8 f0 ae a8 b9 10 35 15"
displayName = "ethernet-static"
memsize = "4"
numvcpus = "1"
ethernet0.present = "true"
ethernet0.networkName = "VM Network"
ethernet0.connectionType = "bridged"
ethernet0.addressType = "static"
ethernet0.address = "00:12:34:56:78:90"
ethernet0.checkMACAddress = "false"
<domain type='vmware'>
<name>ethernet-static</name>
<uuid>564d9bef-acd9-b4e0-c8f0-aea8b9103515</uuid>
<memory>4096</memory>
<os>
<type>hvm</type>
</os>
<devices>
<interface type='bridge'>
<mac address='00:12:34:56:78:90'/>
<source bridge='VM Network'/>
</interface>
</devices>
</domain>
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
uuid.bios = "56 4d 9b ef ac d9 b4 e0-c8 f0 ae a8 b9 10 35 15"
displayName = "ethernet-static"
memsize = "4"
numvcpus = "1"
ethernet0.present = "true"
ethernet0.networkName = "VM Network"
ethernet0.connectionType = "bridged"
ethernet0.addressType = "static"
ethernet0.address = "00:50:56:11:22:33"
<domain type='vmware'>
<name>ethernet-static</name>
<uuid>564d9bef-acd9-b4e0-c8f0-aea8b9103515</uuid>
<memory>4096</memory>
<os>
<type>hvm</type>
</os>
<devices>
<interface type='bridge'>
<mac address='00:50:56:11:22:33'/>
<source bridge='VM Network'/>
</interface>
</devices>
</domain>
config.version = "8"
virtualHW.version = "4"
guestOS = "other"
uuid.bios = "56 4d 9b ef ac d9 b4 e0-c8 f0 ae a8 b9 10 35 15"
displayName = "ethernet-vpx"
memsize = "4"
numvcpus = "1"
ethernet0.present = "true"
ethernet0.networkName = "VM Network"
ethernet0.connectionType = "bridged"
ethernet0.addressType = "vpx"
ethernet0.generatedAddress = "00:50:56:87:65:43"
<domain type='vmware'>
<name>ethernet-vpx</name>
<uuid>564d9bef-acd9-b4e0-c8f0-aea8b9103515</uuid>
<memory>4096</memory>
<os>
<type>hvm</type>
</os>
<devices>
<interface type='bridge'>
<mac address='00:50:56:87:65:43'/>
<source bridge='VM Network'/>
</interface>
</devices>
</domain>
......@@ -192,6 +192,11 @@ mymain(int argc, char **argv)
DO_TEST("ethernet-custom", "ethernet-custom", esxVI_APIVersion_25);
DO_TEST("ethernet-bridged", "ethernet-bridged", esxVI_APIVersion_25);
DO_TEST("ethernet-generated", "ethernet-generated", esxVI_APIVersion_25);
DO_TEST("ethernet-static", "ethernet-static", esxVI_APIVersion_25);
DO_TEST("ethernet-vpx", "ethernet-vpx", esxVI_APIVersion_25);
DO_TEST("ethernet-other", "ethernet-other", esxVI_APIVersion_25);
DO_TEST("serial-file", "serial-file", esxVI_APIVersion_25);
DO_TEST("serial-device", "serial-device", esxVI_APIVersion_25);
DO_TEST("serial-pipe", "serial-pipe", esxVI_APIVersion_25);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册