ia64/xen-unstable

changeset 3601:ef59b38283a5

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
author iap10@labyrinth.cl.cam.ac.uk
date Tue Feb 01 22:32:01 2005 +0000 (2005-02-01)
parents 11b95fad5f5d
children d03ad25af1a8
files linux-2.6.10-xen-sparse/drivers/xen/netback/common.h linux-2.6.10-xen-sparse/drivers/xen/netback/interface.c tools/python/xen/lowlevel/xu/xu.c tools/python/xen/xend/server/messages.py tools/python/xen/xend/server/netif.py tools/python/xen/xm/create.py xen/include/public/io/domain_controller.h
line diff
     1.1 --- a/linux-2.6.10-xen-sparse/drivers/xen/netback/common.h	Tue Feb 01 22:05:38 2005 +0000
     1.2 +++ b/linux-2.6.10-xen-sparse/drivers/xen/netback/common.h	Tue Feb 01 22:32:01 2005 +0000
     1.3 @@ -35,6 +35,8 @@ typedef struct netif_st {
     1.4      domid_t          domid;
     1.5      unsigned int     handle;
     1.6  
     1.7 +    u8               fe_dev_addr[6];
     1.8 +
     1.9      /* Physical parameters of the comms window. */
    1.10      unsigned long    tx_shmem_frame;
    1.11      unsigned long    rx_shmem_frame;
     2.1 --- a/linux-2.6.10-xen-sparse/drivers/xen/netback/interface.c	Tue Feb 01 22:05:38 2005 +0000
     2.2 +++ b/linux-2.6.10-xen-sparse/drivers/xen/netback/interface.c	Tue Feb 01 22:32:01 2005 +0000
     2.3 @@ -163,13 +163,24 @@ void netif_create(netif_be_create_t *cre
     2.4      /* Disable queuing. */
     2.5      dev->tx_queue_len = 0;
     2.6  
     2.7 -    /*
     2.8 -     * Initialise a dummy MAC address. We choose the numerically largest
     2.9 -     * non-broadcast address to prevent the address getting stolen by an 
    2.10 -     * Ethernet bridge for STP purposes. (FE:FF:FF:FF:FF:FF)
    2.11 -     */
    2.12 -    memset(dev->dev_addr, 0xFF, ETH_ALEN);
    2.13 -    dev->dev_addr[0] &= ~0x01;
    2.14 +    if ( (create->be_mac[0] == 0) && (create->be_mac[1] == 0) &&
    2.15 +         (create->be_mac[2] == 0) && (create->be_mac[3] == 0) &&
    2.16 +         (create->be_mac[4] == 0) && (create->be_mac[5] == 0) )
    2.17 +    {
    2.18 +        /*
    2.19 +         * Initialise a dummy MAC address. We choose the numerically largest
    2.20 +         * non-broadcast address to prevent the address getting stolen by an
    2.21 +         * Ethernet bridge for STP purposes. (FE:FF:FF:FF:FF:FF)
    2.22 +         */ 
    2.23 +        memset(dev->dev_addr, 0xFF, ETH_ALEN);
    2.24 +        dev->dev_addr[0] &= ~0x01;
    2.25 +    }
    2.26 +    else
    2.27 +    {
    2.28 +        memcpy(dev->dev_addr, create->be_mac, ETH_ALEN);
    2.29 +    }
    2.30 +
    2.31 +    memcpy(netif->fe_dev_addr, create->mac, ETH_ALEN);
    2.32  
    2.33      rtnl_lock();
    2.34      err = register_netdevice(dev);
     3.1 --- a/tools/python/xen/lowlevel/xu/xu.c	Tue Feb 01 22:05:38 2005 +0000
     3.2 +++ b/tools/python/xen/lowlevel/xu/xu.c	Tue Feb 01 22:32:01 2005 +0000
     3.3 @@ -917,6 +917,12 @@ static PyObject *xu_message_new(PyObject
     3.4          P2C(netif_be_create_t, mac[3],       u8);
     3.5          P2C(netif_be_create_t, mac[4],       u8);
     3.6          P2C(netif_be_create_t, mac[5],       u8);
     3.7 +        P2C(netif_be_create_t, be_mac[0],    u8);
     3.8 +        P2C(netif_be_create_t, be_mac[1],    u8);
     3.9 +        P2C(netif_be_create_t, be_mac[2],    u8);
    3.10 +        P2C(netif_be_create_t, be_mac[3],    u8);
    3.11 +        P2C(netif_be_create_t, be_mac[4],    u8);
    3.12 +        P2C(netif_be_create_t, be_mac[5],    u8);
    3.13          break;
    3.14      case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_DESTROY):
    3.15          P2C(netif_be_destroy_t, domid,        u32);
     4.1 --- a/tools/python/xen/xend/server/messages.py	Tue Feb 01 22:05:38 2005 +0000
     4.2 +++ b/tools/python/xen/xend/server/messages.py	Tue Feb 01 22:32:01 2005 +0000
     4.3 @@ -330,9 +330,9 @@ def packMsg(ty, params):
     4.4      (major, minor) = msg_formats[ty]
     4.5      args = {}
     4.6      for (k, v) in params.items():
     4.7 -        if k == 'mac':
     4.8 +        if k in ['mac', 'be_mac']:
     4.9              for i in range(0, 6):
    4.10 -                args['mac[%d]' % i] = v[i]
    4.11 +                args['%s[%d]' % (k, i)] = v[i]
    4.12          else:
    4.13              args[k] = v
    4.14      msg = xu.message(major, minor, msgid, args)
     5.1 --- a/tools/python/xen/xend/server/netif.py	Tue Feb 01 22:05:38 2005 +0000
     5.2 +++ b/tools/python/xen/xend/server/netif.py	Tue Feb 01 22:32:01 2005 +0000
     5.3 @@ -109,7 +109,14 @@ class NetDev(controller.SplitDev):
     5.4          vmac = sxp.child_value(config, 'mac')
     5.5          if not vmac: return None
     5.6          mac = [ int(x, 16) for x in vmac.split(':') ]
     5.7 -        if len(mac) != 6: raise XendError("invalid mac")
     5.8 +        if len(mac) != 6: raise XendError("invalid mac: %s" % vmac)
     5.9 +        return mac
    5.10 +
    5.11 +    def _get_config_be_mac(self, config):
    5.12 +        vmac = sxp.child_value(config, 'be_mac')
    5.13 +        if not vmac: return None
    5.14 +        mac = [ int(x, 16) for x in vmac.split(':') ]
    5.15 +        if len(mac) != 6: raise XendError("invalid backend mac: %s" % vmac)
    5.16          return mac
    5.17  
    5.18      def _get_config_ipaddr(self, config):
    5.19 @@ -127,6 +134,7 @@ class NetDev(controller.SplitDev):
    5.20              return self.reconfigure(config)
    5.21          self.config = config
    5.22          self.mac = None
    5.23 +        self.be_mac = None
    5.24          self.bridge = None
    5.25          self.script = None
    5.26          self.ipaddr = []
    5.27 @@ -135,6 +143,7 @@ class NetDev(controller.SplitDev):
    5.28          if mac is None:
    5.29              raise XendError("invalid mac")
    5.30          self.mac = mac
    5.31 +        self.be_mac = self._get_config_be_mac(config)
    5.32          self.bridge = sxp.child_value(config, 'bridge')
    5.33          self.script = sxp.child_value(config, 'script')
    5.34          self.ipaddr = self._get_config_ipaddr(config) or []
    5.35 @@ -159,6 +168,7 @@ class NetDev(controller.SplitDev):
    5.36          """
    5.37          changes = {}
    5.38          mac = self._get_config_mac(config)
    5.39 +        be_mac = self._get_config_be_mac(config)
    5.40          bridge = sxp.child_value(config, 'bridge')
    5.41          script = sxp.child_value(config, 'script')
    5.42          ipaddr = self._get_config_ipaddr(config)
    5.43 @@ -166,6 +176,8 @@ class NetDev(controller.SplitDev):
    5.44          backendDomain = str(xd.domain_lookup(sxp.child_value(config, 'backend', '0')).id)
    5.45          if (mac is not None) and (mac != self.mac):
    5.46              raise XendError("cannot change mac")
    5.47 +        if (be_mac is not None) and (be_mac != self.be_mac):
    5.48 +            raise XendError("cannot change backend mac")
    5.49          if (backendDomain is not None) and (backendDomain != str(self.backendDomain)):
    5.50              raise XendError("cannot change backend")
    5.51          if (bridge is not None) and (bridge != self.bridge):
    5.52 @@ -190,6 +202,8 @@ class NetDev(controller.SplitDev):
    5.53                 ['idx', self.idx],
    5.54                 ['vif', vif],
    5.55                 ['mac', mac]]
    5.56 +        if self.be_mac:
    5.57 +            val.append(['be_mac', self.get_be_mac()])
    5.58          if self.bridge:
    5.59              val.append(['bridge', self.bridge])
    5.60          if self.script:
    5.61 @@ -214,6 +228,11 @@ class NetDev(controller.SplitDev):
    5.62          """
    5.63          return ':'.join(map(lambda x: "%02x" % x, self.mac))
    5.64  
    5.65 +    def get_be_mac(self):
    5.66 +        """Get the backend MAC address as a string.
    5.67 +        """
    5.68 +        return ':'.join(map(lambda x: "%02x" % x, self.be_mac))
    5.69 +
    5.70      def vifctl_params(self, vmname=None):
    5.71          """Get the parameters to pass to vifctl.
    5.72          """
    5.73 @@ -267,6 +286,7 @@ class NetDev(controller.SplitDev):
    5.74          msg = packMsg('netif_be_create_t',
    5.75                        { 'domid'        : self.controller.dom,
    5.76                          'netif_handle' : self.vif,
    5.77 +                        'be_mac'       : self.be_mac or [0, 0, 0, 0, 0, 0],
    5.78                          'mac'          : self.mac })
    5.79          self.getBackendInterface().writeRequest(msg, response=d)
    5.80          return d
     6.1 --- a/tools/python/xen/xm/create.py	Tue Feb 01 22:05:38 2005 +0000
     6.2 +++ b/tools/python/xen/xm/create.py	Tue Feb 01 22:32:01 2005 +0000
     6.3 @@ -160,11 +160,13 @@ gopts.var('ipaddr', val="IPADDR",
     6.4            fn=append_value, default=[],
     6.5            use="Add an IP address to the domain.")
     6.6  
     6.7 -gopts.var('vif', val="mac=MAC,bridge=BRIDGE,script=SCRIPT,backend=DOM",
     6.8 +gopts.var('vif', val="mac=MAC,be_mac=MAC,bridge=BRIDGE,script=SCRIPT,backend=DOM",
     6.9            fn=append_value, default=[],
    6.10            use="""Add a network interface with the given MAC address and bridge.
    6.11            The vif is configured by calling the given configuration script.
    6.12            If mac is not specified a random MAC address is used.
    6.13 +          The MAC address of the backend interface can be selected with be_mac.
    6.14 +          If not specified then the network backend chooses it's own MAC address.
    6.15            If bridge is not specified the default bridge is used.
    6.16            If script is not specified the default script is used.
    6.17            If backend is not specified the default backend driver domain is used.
    6.18 @@ -314,18 +316,22 @@ def configure_vifs(config_devs, vals):
    6.19              mac = d.get('mac')
    6.20              if not mac:
    6.21                  mac = randomMAC()
    6.22 +            be_mac = d.get('be_mac')
    6.23              bridge = d.get('bridge')
    6.24              script = d.get('script')
    6.25              backend = d.get('backend')
    6.26              ip = d.get('ip')
    6.27          else:
    6.28              mac = randomMAC()
    6.29 +            be_mac = None
    6.30              bridge = None
    6.31              script = None
    6.32              backend = None
    6.33              ip = None
    6.34          config_vif = ['vif']
    6.35          config_vif.append(['mac', mac])
    6.36 +        if be_mac:
    6.37 +            config_vif.append(['be_mac', be_mac])
    6.38          if bridge:
    6.39              config_vif.append(['bridge', bridge])
    6.40          if script:
    6.41 @@ -423,7 +429,7 @@ def preprocess_vifs(opts, vals):
    6.42              (k, v) = b.strip().split('=', 1)
    6.43              k = k.strip()
    6.44              v = v.strip()
    6.45 -            if k not in ['mac', 'bridge', 'script', 'backend', 'ip']:
    6.46 +            if k not in ['mac', 'be_mac', 'bridge', 'script', 'backend', 'ip']:
    6.47                  opts.err('Invalid vif specifier: ' + vif)
    6.48              d[k] = v
    6.49          vifs.append(d)
     7.1 --- a/xen/include/public/io/domain_controller.h	Tue Feb 01 22:05:38 2005 +0000
     7.2 +++ b/xen/include/public/io/domain_controller.h	Tue Feb 01 22:32:01 2005 +0000
     7.3 @@ -489,9 +489,11 @@ typedef struct {
     7.4      u32        netif_handle;  /*  4: Domain-specific interface handle.   */
     7.5      u8         mac[6];        /*  8 */
     7.6      u16        __pad1;        /* 14 */
     7.7 +    u8         be_mac[6];     /* 16 */
     7.8 +    u16        __pad2;        /* 22 */
     7.9      /* OUT */
    7.10 -    u32        status;        /* 16 */
    7.11 -} PACKED netif_be_create_t; /* 20 bytes */
    7.12 +    u32        status;        /* 24 */
    7.13 +} PACKED netif_be_create_t; /* 28 bytes */
    7.14  
    7.15  /*
    7.16   * CMSG_NETIF_BE_DESTROY: