bitkeeper revision 1.1159.269.5 (42386371nvHctvk3SHgDUG4w3o9URw)

Add support for specifying the interface name to be used by a netif
backend driver instead of the default vifD.N.

Signed-off-by: Mike Wray <mike.wray@hp.com>
This commit is contained in:
mjw@wray-m-3.hpl.hp.com committed 2005-03-16 16:48:49 +00:00
1 parent 421b18073a
commit afedb1e48f
5 files changed
+56 -9

No files matched your search

+26
View File
@@ -259,6 +259,7 @@ static PyTypeObject xu_notifier_type = {
*/
#define TYPE(_x,_y) (((_x)<<8)|(_y))
#define P2C(_struct, _field, _ctype) \
do { \
PyObject *obj; \
@@ -279,6 +280,29 @@ static PyTypeObject xu_notifier_type = {
} \
xum->msg.length = sizeof(_struct); \
} while ( 0 )
/** Set a char[] field in a struct from a Python string.
* Can't do this in P2C because of the typing.
*/
#define P2CSTRING(_struct, _field) \
do { \
PyObject *obj; \
if ( (obj = PyDict_GetItemString(payload, #_field)) != NULL ) \
{ \
if ( PyString_Check(obj) ) \
{ \
_struct * _cobj = (_struct *)&xum->msg.msg[0]; \
int _field_n = sizeof(_cobj->_field); \
memset(_cobj->_field, 0, _field_n); \
strncpy(_cobj->_field, \
PyString_AsString(obj), \
_field_n - 1); \
dict_items_parsed++; \
} \
} \
xum->msg.length = sizeof(_struct); \
} while ( 0 )
#define C2P(_struct, _field, _pytype, _ctype) \
do { \
PyObject *obj = Py ## _pytype ## _From ## _ctype \
@@ -456,6 +480,7 @@ static PyObject *xu_message_get_payload(PyObject *self, PyObject *args)
C2P(netif_be_create_t, domid, Int, Long);
C2P(netif_be_create_t, netif_handle, Int, Long);
C2P(netif_be_create_t, status, Int, Long);
C2P(netif_be_create_t, vifname, String, String);
return dict;
case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_DESTROY):
C2P(netif_be_destroy_t, domid, Int, Long);
@@ -623,6 +648,7 @@ 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);
P2CSTRING(netif_be_create_t, vifname);
break;
case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_DESTROY):
P2C(netif_be_destroy_t, domid, u32);
+13 -3
View File
@@ -130,7 +130,13 @@ class NetDev(controller.SplitDev):
self.bridge = None
self.script = None
self.ipaddr = []
self.vifname = None
self.vifname = sxp.child_value(config, 'vifname')
if self.vifname is None:
self.vifname = "vif%d.%d" % (self.controller.dom, self.vif)
if len(self.vifname) > 15:
raise XendError('invalid vifname: too long: ' + self.vifname)
mac = self._get_config_mac(config)
if mac is None:
raise XendError("invalid mac")
@@ -189,7 +195,9 @@ class NetDev(controller.SplitDev):
val = ['vif',
['idx', self.idx],
['vif', vif],
['mac', mac]]
['mac', mac],
['vifname', self.vifname],
]
if self.bridge:
val.append(['bridge', self.bridge])
if self.script:
@@ -207,7 +215,7 @@ class NetDev(controller.SplitDev):
def get_vifname(self):
"""Get the virtual interface device name.
"""
return "vif%d.%d" % (self.controller.dom, self.vif)
return self.vifname
def get_mac(self):
"""Get the MAC address as a string.
@@ -267,7 +275,9 @@ class NetDev(controller.SplitDev):
msg = packMsg('netif_be_create_t',
{ 'domid' : self.controller.dom,
'netif_handle' : self.vif,
'mac' : self.mac })
'mac' : self.mac,
'vifname' : self.vifname
})
self.getBackendInterface().writeRequest(msg, response=d)
return d
+8 -2
View File
@@ -151,7 +151,7 @@ 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,bridge=BRIDGE,script=SCRIPT,backend=DOM,vifname=NAME",
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.
@@ -159,6 +159,8 @@ gopts.var('vif', val="mac=MAC,bridge=BRIDGE,script=SCRIPT,backend=DOM",
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.
If vifname is not specified the backend virtual interface will have name vifD.N
where D is the domain id and N is the interface id.
This option may be repeated to add more than one vif.
Specifying vifs will increase the number of interfaces as needed.""")
@@ -289,14 +291,18 @@ def configure_vifs(config_devs, vals):
script = d.get('script')
backend = d.get('backend')
ip = d.get('ip')
vifname = d.get('vifname')
else:
mac = randomMAC()
bridge = None
script = None
backend = None
ip = None
vifname = None
config_vif = ['vif']
config_vif.append(['mac', mac])
if vifname:
config_vif.append(['vifname', vifname])
if bridge:
config_vif.append(['bridge', bridge])
if script:
@@ -383,7 +389,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', 'bridge', 'script', 'backend', 'ip', 'vifname']:
opts.err('Invalid vif specifier: ' + vif)
d[k] = v
vifs.append(d)
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.