[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] Add support for specifying the interface name to be used by a netif
ChangeSet 1.1775.1.5, 2005/03/16 16:48:49+00:00, mjw@xxxxxxxxxxxxxxxxxxx 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@xxxxxx> linux-2.6.10-xen-sparse/drivers/xen/netback/interface.c | 8 +++- tools/python/xen/lowlevel/xu/xu.c | 26 ++++++++++++++++ tools/python/xen/xend/server/netif.py | 16 ++++++++- tools/python/xen/xm/create.py | 10 ++++-- xen/include/public/io/domain_controller.h | 5 +-- 5 files changed, 56 insertions(+), 9 deletions(-) diff -Nru a/linux-2.6.10-xen-sparse/drivers/xen/netback/interface.c b/linux-2.6.10-xen-sparse/drivers/xen/netback/interface.c --- a/linux-2.6.10-xen-sparse/drivers/xen/netback/interface.c 2005-03-25 07:08:38 -05:00 +++ b/linux-2.6.10-xen-sparse/drivers/xen/netback/interface.c 2005-03-25 07:08:38 -05:00 @@ -119,9 +119,13 @@ unsigned int handle = create->netif_handle; struct net_device *dev; netif_t **pnetif, *netif; - char name[IFNAMSIZ]; + char name[IFNAMSIZ] = {}; - snprintf(name, IFNAMSIZ - 1, "vif%u.%u", domid, handle); + if(create->vifname[0] == '\0'){ + snprintf(name, IFNAMSIZ - 1, "vif%u.%u", domid, handle); + } else { + snprintf(name, IFNAMSIZ - 1, "%s", create->vifname); + } dev = alloc_netdev(sizeof(netif_t), name, ether_setup); if ( dev == NULL ) { diff -Nru a/tools/python/xen/lowlevel/xu/xu.c b/tools/python/xen/lowlevel/xu/xu.c --- a/tools/python/xen/lowlevel/xu/xu.c 2005-03-25 07:08:38 -05:00 +++ b/tools/python/xen/lowlevel/xu/xu.c 2005-03-25 07:08:38 -05:00 @@ -259,6 +259,7 @@ */ #define TYPE(_x,_y) (((_x)<<8)|(_y)) + #define P2C(_struct, _field, _ctype) \ do { \ PyObject *obj; \ @@ -279,6 +280,29 @@ } \ 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 @@ 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 @@ 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); diff -Nru a/tools/python/xen/xend/server/netif.py b/tools/python/xen/xend/server/netif.py --- a/tools/python/xen/xend/server/netif.py 2005-03-25 07:08:38 -05:00 +++ b/tools/python/xen/xend/server/netif.py 2005-03-25 07:08:38 -05:00 @@ -130,7 +130,13 @@ 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 @@ 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 @@ 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 @@ 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 diff -Nru a/tools/python/xen/xm/create.py b/tools/python/xen/xm/create.py --- a/tools/python/xen/xm/create.py 2005-03-25 07:08:38 -05:00 +++ b/tools/python/xen/xm/create.py 2005-03-25 07:08:38 -05:00 @@ -151,7 +151,7 @@ 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 @@ 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 @@ 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 @@ (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) diff -Nru a/xen/include/public/io/domain_controller.h b/xen/include/public/io/domain_controller.h --- a/xen/include/public/io/domain_controller.h 2005-03-25 07:08:38 -05:00 +++ b/xen/include/public/io/domain_controller.h 2005-03-25 07:08:39 -05:00 @@ -477,9 +477,10 @@ u32 netif_handle; /* 4: Domain-specific interface handle. */ u8 mac[6]; /* 8 */ u16 __pad1; /* 14 */ + char vifname[16]; /* 16 */ /* OUT */ - u32 status; /* 16 */ -} PACKED netif_be_create_t; /* 20 bytes */ + u32 status; /* 32 */ +} PACKED netif_be_create_t; /* 36 bytes */ /* * CMSG_NETIF_BE_DESTROY: ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxxxx https://lists.sourceforge.net/lists/listinfo/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |