mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 10:40:03 +01:00
bitkeeper revision 1.1159.212.64 (42000361XrdUoEK_vD6RMga2eLmwZg)
Allow specification of backend vif MAC addresses. If a backend MAC is not provided, generate one as before Signed-off-by: Jody Belka <knew-xen@pimb.org> Signed-off-by: ian.pratt@cl.cam.ac.uk
This commit is contained in:
1 parent
d4aa4577a8
commit
12814f99e4
7 files changed
+61
-14
No files matched your search
@@ -917,6 +917,12 @@ static PyObject *xu_message_new(PyObject *self, PyObject *args)
|
||||
P2C(netif_be_create_t, mac[3], u8);
|
||||
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):
|
||||
P2C(netif_be_destroy_t, domid, u32);
|
||||
|
||||
@@ -330,9 +330,9 @@ def packMsg(ty, params):
|
||||
(major, minor) = msg_formats[ty]
|
||||
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
|
||||
msg = xu.message(major, minor, msgid, args)
|
||||
|
||||
@@ -109,7 +109,14 @@ class NetDev(controller.SplitDev):
|
||||
vmac = sxp.child_value(config, 'mac')
|
||||
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
|
||||
|
||||
def _get_config_ipaddr(self, config):
|
||||
@@ -127,6 +134,7 @@ class NetDev(controller.SplitDev):
|
||||
return self.reconfigure(config)
|
||||
self.config = config
|
||||
self.mac = None
|
||||
self.be_mac = None
|
||||
self.bridge = None
|
||||
self.script = None
|
||||
self.ipaddr = []
|
||||
@@ -135,6 +143,7 @@ class NetDev(controller.SplitDev):
|
||||
if mac is None:
|
||||
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')
|
||||
self.ipaddr = self._get_config_ipaddr(config) or []
|
||||
@@ -159,6 +168,7 @@ class NetDev(controller.SplitDev):
|
||||
"""
|
||||
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')
|
||||
ipaddr = self._get_config_ipaddr(config)
|
||||
@@ -166,6 +176,8 @@ class NetDev(controller.SplitDev):
|
||||
backendDomain = str(xd.domain_lookup(sxp.child_value(config, 'backend', '0')).id)
|
||||
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")
|
||||
if (bridge is not None) and (bridge != self.bridge):
|
||||
@@ -190,6 +202,8 @@ class NetDev(controller.SplitDev):
|
||||
['idx', self.idx],
|
||||
['vif', vif],
|
||||
['mac', mac]]
|
||||
if self.be_mac:
|
||||
val.append(['be_mac', self.get_be_mac()])
|
||||
if self.bridge:
|
||||
val.append(['bridge', self.bridge])
|
||||
if self.script:
|
||||
@@ -214,6 +228,11 @@ class NetDev(controller.SplitDev):
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
@@ -267,6 +286,7 @@ class NetDev(controller.SplitDev):
|
||||
msg = packMsg('netif_be_create_t',
|
||||
{ '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)
|
||||
return d
|
||||
|
||||
@@ -160,11 +160,13 @@ gopts.var('ipaddr', val="IPADDR",
|
||||
fn=append_value, default=[],
|
||||
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.
|
||||
If backend is not specified the default backend driver domain is used.
|
||||
@@ -314,18 +316,22 @@ def configure_vifs(config_devs, vals):
|
||||
mac = d.get('mac')
|
||||
if not mac:
|
||||
mac = randomMAC()
|
||||
be_mac = d.get('be_mac')
|
||||
bridge = d.get('bridge')
|
||||
script = d.get('script')
|
||||
backend = d.get('backend')
|
||||
ip = d.get('ip')
|
||||
else:
|
||||
mac = randomMAC()
|
||||
be_mac = None
|
||||
bridge = None
|
||||
script = None
|
||||
backend = None
|
||||
ip = None
|
||||
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])
|
||||
if script:
|
||||
@@ -423,7 +429,7 @@ def preprocess_vifs(opts, vals):
|
||||
(k, v) = b.strip().split('=', 1)
|
||||
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
|
||||
vifs.append(d)
|
||||
|
||||