xen: netback mac selection
PATCH 4/5 xen: netback mac selection
Allow specification of backend vif MAC addresses. If a backend MAC is not provided, generate one as before
diffstat:
linux-2.6.10-xen-sparse/drivers/xen/netback/common.h | 2 + linux-2.6.10-xen-sparse/drivers/xen/netback/interface.c | 25 +++++++++++----- tools/python/xen/lowlevel/xu/xu.c | 6 +++ tools/python/xen/xend/server/messages.py | 4 +- tools/python/xen/xend/server/netif.py | 22 +++++++++++++- tools/python/xen/xm/create.py | 10 +++++- xen/include/public/io/domain_controller.h | 6 ++- 7 files changed, 61 insertions(+), 14 deletions(-)
linux-2.6.10-xen-sparse/drivers/xen/netback/common.h +2 -0
@@ -36,4 +36,6 @@unsigned int handle; +u8 fe_dev_addr[6 ]; +/* Physical parameters of the comms window. */ unsigned long tx_shmem_frame;
linux-2.6.10-xen-sparse/drivers/xen/netback/interface.c +18 -7
@@ -164,11 +164,22 @@ dev->tx_queue_len =0 ; -/* -* Initialise a dummy MAC address. We choose the numerically largest -* non-broadcast address to prevent the address getting stolen by an -* Ethernet bridge for STP purposes. (FE:FF:FF:FF:FF:FF) -*/ -memset (dev->dev_addr,0xFF ,ETH_ALEN ); - dev->dev_addr[0 ] &= ~0x01 ; +if ( (create->be_mac[0 ] ==0 ) && (create->be_mac[1 ] ==0 ) && + (create->be_mac[2 ] ==0 ) && (create->be_mac[3 ] ==0 ) && + (create->be_mac[4 ] ==0 ) && (create->be_mac[5 ] ==0 ) ) + { +/* +* Initialise a dummy MAC address. We choose the numerically largest +* non-broadcast address to prevent the address getting stolen by an +* Ethernet bridge for STP purposes. (FE:FF:FF:FF:FF:FF) +*/ +memset (dev->dev_addr,0xFF ,ETH_ALEN ); + dev->dev_addr[0 ] &= ~0x01 ; + } +else + { +memcpy (dev->dev_addr, create->be_mac,ETH_ALEN ); + } + +memcpy (netif->fe_dev_addr, create->mac,ETH_ALEN );rtnl_lock ();
tools/python/xen/lowlevel/xu/xu.c +6 -0
@@ -624,4 +624,10 @@P2C (netif_be_create_t, mac[4 ], u8);P2C (netif_be_create_t, mac[5 ], u8); +P2C (netif_be_create_t, be_mac[0 ], u8); +P2C (netif_be_create_t, be_mac[1 ], u8); +P2C (netif_be_create_t, be_mac[2 ], u8); +P2C (netif_be_create_t, be_mac[3 ], u8); +P2C (netif_be_create_t, be_mac[4 ], u8); +P2C (netif_be_create_t, be_mac[5 ], u8);break ;case TYPE (CMSG_NETIF_BE ,CMSG_NETIF_BE_DESTROY ):
tools/python/xen/xend/server/messages.py +2 -2
@@ -267,7 +267,7 @@ args = {} for (k, v) in params.items(): - if k == 'mac': + if k in ['mac', 'be_mac']: for i in range(0, 6): - args['mac[%d]' % i] = v[i] + args['%s[%d]' % (k, i)] = v[i] else: args[k] = v
tools/python/xen/xend/server/netif.py +21 -1
@@ -110,5 +110,12 @@ if not vmac: return None mac = [ int(x, 16) for x in vmac.split(':') ] - if len(mac) != 6: raise XendError("invalid mac") + if len(mac) != 6: raise XendError("invalid mac: %s" % vmac) + return mac + + def _get_config_be_mac(self, config): + vmac = sxp.child_value(config, 'be_mac') + if not vmac: return None + mac = [ int(x, 16) for x in vmac.split(':') ] + if len(mac) != 6: raise XendError("invalid backend mac: %s" % vmac) return mac
@@ -128,4 +135,5 @@ self.config = config self.mac = None + self.be_mac = None self.bridge = None self.script = None
@@ -136,4 +144,5 @@ raise XendError("invalid mac") self.mac = mac + self.be_mac = self._get_config_be_mac(config) self.bridge = sxp.child_value(config, 'bridge') self.script = sxp.child_value(config, 'script')
@@ -160,4 +169,5 @@ changes = {} mac = self._get_config_mac(config) + be_mac = self._get_config_be_mac(config) bridge = sxp.child_value(config, 'bridge') script = sxp.child_value(config, 'script')
@@ -167,4 +177,6 @@ if (mac is not None) and (mac != self.mac): raise XendError("cannot change mac") + if (be_mac is not None) and (be_mac != self.be_mac): + raise XendError("cannot change backend mac") if (backendDomain is not None) and (backendDomain != str(self.backendDomain)): raise XendError("cannot change backend")
@@ -191,4 +203,6 @@ ['vif', vif], ['mac', mac]] + if self.be_mac: + val.append(['be_mac', self.get_be_mac()]) if self.bridge: val.append(['bridge', self.bridge])
@@ -215,4 +229,9 @@ return ':'.join(map(lambda x: "%02x" % x, self.mac)) + def get_be_mac(self): + """Get the backend MAC address as a string. + """ + return ':'.join(map(lambda x: "%02x" % x, self.be_mac)) + def vifctl_params(self, vmname=None): """Get the parameters to pass to vifctl.
@@ -268,4 +287,5 @@ { 'domid' : self.controller.dom, 'netif_handle' : self.vif, + 'be_mac' : self.be_mac or [0, 0, 0, 0, 0, 0], 'mac' : self.mac }) self.getBackendInterface().writeRequest(msg, response=d)
tools/python/xen/xm/create.py +8 -2
@@ -152,9 +152,11 @@ use="Add an IP address to the domain.") -gopts.var('vif', val="mac=MAC,bridge=BRIDGE,script=SCRIPT,backend=DOM", +gopts.var('vif', val="mac=MAC,be_mac=MAC,bridge=BRIDGE,script=SCRIPT,backend=DOM", fn=append_value, default=[], use="""Add a network interface with the given MAC address and bridge. The vif is configured by calling the given configuration script. If mac is not specified a random MAC address is used. + The MAC address of the backend interface can be selected with be_mac. + If not specified then the network backend chooses it's own MAC address. If bridge is not specified the default bridge is used. If script is not specified the default script is used.
@@ -286,4 +288,5 @@ if not mac: mac = randomMAC() + be_mac = d.get('be_mac') bridge = d.get('bridge') script = d.get('script')
@@ -292,4 +295,5 @@ else: mac = randomMAC() + be_mac = None bridge = None script = None
@@ -298,4 +302,6 @@ config_vif = ['vif'] config_vif.append(['mac', mac]) + if be_mac: + config_vif.append(['be_mac', be_mac]) if bridge: config_vif.append(['bridge', bridge])
@@ -384,5 +390,5 @@ k = k.strip() v = v.strip() - if k not in ['mac', 'bridge', 'script', 'backend', 'ip']: + if k not in ['mac', 'be_mac', 'bridge', 'script', 'backend', 'ip']: opts.err('Invalid vif specifier: ' + vif) d[k] = v
xen/include/public/io/domain_controller.h +4 -2
@@ -479,7 +479,9 @@u8 mac[6 ];/* 8 */ u16 __pad1;/* 14 */ +u8 be_mac[6 ];/* 16 */ +u16 __pad2;/* 22 */ /* OUT */ -u32 status;/* 16 */ -}PACKED netif_be_create_t;/* 20 bytes */ +u32 status;/* 24 */ +}PACKED netif_be_create_t;/* 28 bytes */ /*
-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting Tool for open source databases. Create drag-&-drop reports. Save time by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc. Download a FREE copy at http://www.intelliview.com/go/osdn_nl
Quoted 3 lines
Allow specification of backend vif MAC addresses. If a backend MAC is not provided, generate one as before
Jody, since this patch (4) changes one of the message formats I'm applying it to just 'unstable' rather than 2.0-testing.
I've applied 1 and 2, and I think we came to mutual agreement on dropping 5. The 'sysfs' parts of 5 may still be worthwhile, or are they superseded by the proposed new 'xen bus' sysfs stuff?
Patch 3 is definitely worthwhile, though I'd appreciate it if you could rework it as discussed. At the very least, we should seed the random number generator off something better than system time in seconds! It would be ideal if it was seeded from a string containing the config file and all the variables passed to it.
Ian
01-blkfront-vbd-bugfix.patch
Fix incorrect result-check in xlvbd_init_device
02-xm-blkif-ide-dev-numbers.patch
Fix the device number calculation for /dev/hd* device names; ide device numbering works differently to scsi
03-xm-create-mac-selection.patch
Check for duplicate supplied vif MACs, and make sure that randomly generated MACs for a domain are all different
04-netback-mac-selection.patch
Allow specification of backend vif MAC addresses. If a backend MAC is not provided, generate one as before
05-net-features.patch
Allow (1) the making of both frontend and backend vif MACs read-only (independently), (2) the addition of some xen-specific sysfs attributes on front/back vifs, (3) an option to set several vif defaults in a domain config file, for ease of use when creating multiple vifs.
-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting Tool for open source databases. Create drag-&-drop reports. Save time by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc. Download a FREE copy at http://www.intelliview.com/go/osdn_nl