ia64/xen-unstable

changeset 4940:f849286c8a79

bitkeeper revision 1.1421 (4288ce4e6ck3yeSz45ZczyyRR_QzUw)

Merge firebug.cl.cam.ac.uk:/local/scratch/kaf24/xen-2.0-testing.bk
into firebug.cl.cam.ac.uk:/local/scratch/kaf24/xen-unstable.bk
author kaf24@firebug.cl.cam.ac.uk
date Mon May 16 16:46:06 2005 +0000 (2005-05-16)
parents b233317fe94b 328fbee2128c
children e8ad55c3b8fb 6556b9a0ffa4 1f62b00cdcad
files .rootkeys linux-2.6.11-xen-sparse/drivers/xen/netback/Makefile linux-2.6.11-xen-sparse/drivers/xen/netback/loopback.c tools/examples/network
line diff
     1.1 --- a/.rootkeys	Mon May 16 16:16:02 2005 +0000
     1.2 +++ b/.rootkeys	Mon May 16 16:46:06 2005 +0000
     1.3 @@ -333,6 +333,7 @@ 410a9817HEVJvred5Oy_uKH3HFJC5Q linux-2.6
     1.4  4097ba831lpGeLlPg-bfV8XarVVuoQ linux-2.6.11-xen-sparse/drivers/xen/netback/common.h
     1.5  4097ba83wvv8yi5P5xugCUBAdb6O-A linux-2.6.11-xen-sparse/drivers/xen/netback/control.c
     1.6  4097ba83byY5bTSugJGZ1exTxIcMKw linux-2.6.11-xen-sparse/drivers/xen/netback/interface.c
     1.7 +4288ce19CHtBLg600EZ8TNuSPLs5Ng linux-2.6.11-xen-sparse/drivers/xen/netback/loopback.c
     1.8  4087cf0dGmSbFhFZyIZBJzvqxY-qBw linux-2.6.11-xen-sparse/drivers/xen/netback/netback.c
     1.9  40f56239lrg_Ob0BJ8WBFS1zeg2CYw linux-2.6.11-xen-sparse/drivers/xen/netfront/Kconfig
    1.10  40f56239Wd4k_ycG_mFsSO1r5xKdtQ linux-2.6.11-xen-sparse/drivers/xen/netfront/Makefile
     2.1 --- a/linux-2.6.11-xen-sparse/drivers/xen/netback/Makefile	Mon May 16 16:16:02 2005 +0000
     2.2 +++ b/linux-2.6.11-xen-sparse/drivers/xen/netback/Makefile	Mon May 16 16:46:06 2005 +0000
     2.3 @@ -1,2 +1,2 @@
     2.4  
     2.5 -obj-y	:= netback.o control.o interface.o
     2.6 +obj-y	:= netback.o control.o interface.o loopback.o
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/linux-2.6.11-xen-sparse/drivers/xen/netback/loopback.c	Mon May 16 16:46:06 2005 +0000
     3.3 @@ -0,0 +1,140 @@
     3.4 +/******************************************************************************
     3.5 + * netback/loopback.c
     3.6 + * 
     3.7 + * A two-interface loopback device to emulate a local netfront-netback
     3.8 + * connection. This ensures that local packet delivery looks identical
     3.9 + * to inter-domain delivery. Most importantly, packets delivered locally
    3.10 + * originating from other domains will get *copied* when they traverse this
    3.11 + * driver. This prevents unbounded delays in socket-buffer queues from
    3.12 + * causing the netback driver to "seize up".
    3.13 + * 
    3.14 + * This driver creates a symmetric pair of loopback interfaces with names
    3.15 + * vif0.0 and veth0. The intention is that 'vif0.0' is bound to an Ethernet
    3.16 + * bridge, just like a proper netback interface, while a local IP interface
    3.17 + * is configured on 'veth0'.
    3.18 + * 
    3.19 + * As with a real netback interface, vif0.0 is configured with a suitable
    3.20 + * dummy MAC address. No default is provided for veth0: a reasonable strategy
    3.21 + * is to transfer eth0's MAC address to veth0, and give eth0 a dummy address
    3.22 + * (to avoid confusing the Etherbridge).
    3.23 + * 
    3.24 + * Copyright (c) 2005 K A Fraser
    3.25 + */
    3.26 +
    3.27 +#include <linux/config.h>
    3.28 +#include <linux/module.h>
    3.29 +#include <linux/netdevice.h>
    3.30 +#include <linux/inetdevice.h>
    3.31 +#include <linux/etherdevice.h>
    3.32 +#include <linux/skbuff.h>
    3.33 +#include <net/dst.h>
    3.34 +
    3.35 +struct net_private {
    3.36 +    struct net_device *loopback_dev;
    3.37 +    struct net_device_stats stats;
    3.38 +};
    3.39 +
    3.40 +static int loopback_open(struct net_device *dev)
    3.41 +{
    3.42 +    struct net_private *np = netdev_priv(dev);
    3.43 +    memset(&np->stats, 0, sizeof(np->stats));
    3.44 +    netif_start_queue(dev);
    3.45 +    return 0;
    3.46 +}
    3.47 +
    3.48 +static int loopback_close(struct net_device *dev)
    3.49 +{
    3.50 +    netif_stop_queue(dev);
    3.51 +    return 0;
    3.52 +}
    3.53 +
    3.54 +static int loopback_start_xmit(struct sk_buff *skb, struct net_device *dev)
    3.55 +{
    3.56 +    struct net_private *np = netdev_priv(dev);
    3.57 +
    3.58 +    dst_release(skb->dst);
    3.59 +    skb->dst = NULL;
    3.60 +
    3.61 +    skb_orphan(skb);
    3.62 +
    3.63 +    np->stats.tx_bytes += skb->len;
    3.64 +    np->stats.tx_packets++;
    3.65 +
    3.66 +    /* Switch to loopback context. */
    3.67 +    dev = np->loopback_dev;
    3.68 +    np  = netdev_priv(dev);
    3.69 +
    3.70 +    np->stats.rx_bytes += skb->len;
    3.71 +    np->stats.rx_packets++;
    3.72 +
    3.73 +    skb->pkt_type = PACKET_HOST; /* overridden by eth_type_trans() */
    3.74 +    skb->protocol = eth_type_trans(skb, dev);
    3.75 +    skb->dev      = dev;
    3.76 +    dev->last_rx  = jiffies;
    3.77 +    netif_rx(skb);
    3.78 +
    3.79 +    return 0;
    3.80 +}
    3.81 +
    3.82 +static struct net_device_stats *loopback_get_stats(struct net_device *dev)
    3.83 +{
    3.84 +    struct net_private *np = netdev_priv(dev);
    3.85 +    return &np->stats;
    3.86 +}
    3.87 +
    3.88 +static void loopback_construct(struct net_device *dev, struct net_device *lo)
    3.89 +{
    3.90 +    struct net_private *np = netdev_priv(dev);
    3.91 +
    3.92 +    np->loopback_dev     = lo;
    3.93 +
    3.94 +    dev->open            = loopback_open;
    3.95 +    dev->stop            = loopback_close;
    3.96 +    dev->hard_start_xmit = loopback_start_xmit;
    3.97 +    dev->get_stats       = loopback_get_stats;
    3.98 +
    3.99 +    dev->tx_queue_len    = 0;
   3.100 +    dev->mtu             = 16*1024;
   3.101 +}
   3.102 +
   3.103 +static int __init loopback_init(void)
   3.104 +{
   3.105 +    struct net_device *dev1, *dev2;
   3.106 +    int err = -ENOMEM;
   3.107 +
   3.108 +    dev1 = alloc_netdev(sizeof(struct net_private), "vif0.0", ether_setup);
   3.109 +    dev2 = alloc_netdev(sizeof(struct net_private), "veth0", ether_setup);
   3.110 +    if ( (dev1 == NULL) || (dev2 == NULL) )
   3.111 +        goto fail;
   3.112 +
   3.113 +    loopback_construct(dev1, dev2);
   3.114 +    loopback_construct(dev2, dev1);
   3.115 +
   3.116 +    /*
   3.117 +     * Initialise a dummy MAC address for the 'dummy backend' interface. We
   3.118 +     * choose the numerically largest non-broadcast address to prevent the
   3.119 +     * address getting stolen by an Ethernet bridge for STP purposes.
   3.120 +     */
   3.121 +    memset(dev1->dev_addr, 0xFF, ETH_ALEN);
   3.122 +    dev1->dev_addr[0] &= ~0x01;
   3.123 +
   3.124 +    if ( (err = register_netdev(dev1)) != 0 )
   3.125 +        goto fail;
   3.126 +
   3.127 +    if ( (err = register_netdev(dev2)) != 0 )
   3.128 +    {
   3.129 +        unregister_netdev(dev1);
   3.130 +        goto fail;
   3.131 +    }
   3.132 +
   3.133 +    return 0;
   3.134 +
   3.135 + fail:
   3.136 +    if ( dev1 != NULL )
   3.137 +        kfree(dev1);
   3.138 +    if ( dev2 != NULL )
   3.139 +        kfree(dev2);
   3.140 +    return err;
   3.141 +}
   3.142 +
   3.143 +module_init(loopback_init);
     4.1 --- a/tools/examples/network	Mon May 16 16:16:02 2005 +0000
     4.2 +++ b/tools/examples/network	Mon May 16 16:46:06 2005 +0000
     4.3 @@ -74,6 +74,16 @@ s/${src}/dev ${dst}/
     4.4  " | sh -e
     4.5  }
     4.6  
     4.7 +# Usage: del_addrs src
     4.8 +del_addrs () {
     4.9 +    local src=$1
    4.10 +    ip addr show dev ${src} | egrep '^ *inet ' | sed -e "
    4.11 +s/inet/ip addr del/
    4.12 +s@\([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\)/[0-9]\+@\1@
    4.13 +s/${src}/dev ${src}/
    4.14 +" | sh -e
    4.15 +}
    4.16 +
    4.17  # Usage: transfer_routes src dst
    4.18  # Get all IP routes to device $src, delete them, and
    4.19  # add the same routes to device $dst.
    4.20 @@ -97,11 +107,9 @@ d
    4.21  " | sh -e
    4.22  }
    4.23  
    4.24 -# Usage: create_bridge dev bridge
    4.25 -# Create bridge $bridge and add device $dev to it.
    4.26 +# Usage: create_bridge bridge
    4.27  create_bridge () {
    4.28 -    local dev=$1
    4.29 -    local bridge=$2
    4.30 +    local bridge=$1
    4.31  
    4.32      # Don't create the bridge if it already exists.
    4.33      if ! brctl show | grep -q ${bridge} ; then
    4.34 @@ -112,6 +120,16 @@ create_bridge () {
    4.35      ifconfig ${bridge} up
    4.36  }
    4.37  
    4.38 +# Usage: add_to_bridge bridge dev
    4.39 +add_to_bridge () {
    4.40 +    local bridge=$1
    4.41 +    local dev=$2
    4.42 +    # Don't add $dev to $bridge if it's already on a bridge.
    4.43 +    if ! brctl show | grep -q ${dev} ; then
    4.44 +        brctl addif ${bridge} ${dev}
    4.45 +    fi
    4.46 +}
    4.47 +
    4.48  # Usage: antispoofing dev bridge
    4.49  # Set the default forwarding policy for $dev to drop.
    4.50  # Allow forwarding to the bridge.
    4.51 @@ -143,15 +161,31 @@ op_start () {
    4.52      if [ "${bridge}" == "null" ] ; then
    4.53          return
    4.54      fi
    4.55 -    # Create the bridge and give it the interface IP addresses.
    4.56 -    # Move the interface routes onto the bridge.
    4.57 -    create_bridge ${netdev} ${bridge}
    4.58 -    transfer_addrs ${netdev} ${bridge}
    4.59 -    transfer_routes ${netdev} ${bridge}
    4.60 -    # Don't add $dev to $bridge if it's already on a bridge.
    4.61 -    if ! brctl show | grep -q ${netdev} ; then
    4.62 -        brctl addif ${bridge} ${netdev}
    4.63 +
    4.64 +    create_bridge ${bridge}
    4.65 +
    4.66 +    if ifconfig veth0 2>/dev/null | grep -q veth0 ; then
    4.67 +        # Propagate MAC address and ARP responsibilities to virtual interface.
    4.68 +        mac=`ifconfig ${netdev} | grep HWadd | sed -e 's/.*\(..:..:..:..:..:..\).*/\1/'`
    4.69 +        ifconfig veth0 down
    4.70 +        ifconfig veth0 hw ether ${mac}
    4.71 +        ifconfig veth0 arp up
    4.72 +        transfer_addrs ${netdev} veth0
    4.73 +        transfer_routes ${netdev} veth0
    4.74 +        del_addrs ${netdev}
    4.75 +        ifconfig ${netdev} -arp down
    4.76 +        ifconfig ${netdev} hw ether fe:ff:ff:ff:ff:ff up
    4.77 +        # Bring up second half of virtual device and attach it to the bridge.
    4.78 +        ifconfig vif0.0 up
    4.79 +        add_to_bridge ${bridge} vif0.0
    4.80 +    else
    4.81 +        transfer_addrs ${netdev} ${bridge}
    4.82 +        transfer_routes ${netdev} ${bridge}
    4.83 +        del_addrs ${netdev}
    4.84      fi
    4.85 +
    4.86 +    # Attach the real interface to the bridge.
    4.87 +    add_to_bridge ${bridge} ${netdev}
    4.88      
    4.89      if [ ${antispoof} == 'yes' ] ; then
    4.90          antispoofing ${netdev} ${bridge}
    4.91 @@ -162,16 +196,30 @@ op_stop () {
    4.92      if [ "${bridge}" == "null" ] ; then
    4.93          return
    4.94      fi
    4.95 -    # Remove the interface from the bridge.
    4.96 -    # Move the routes back to the interface.
    4.97 +
    4.98      brctl delif ${bridge} ${netdev}
    4.99 -    transfer_routes ${bridge} ${netdev}
   4.100  
   4.101 -    # It's not our place to be enabling forwarding...
   4.102 +    if ifconfig veth0 2>/dev/null | grep -q veth0 ; then
   4.103 +        brctl delif ${bridge} vif0.0
   4.104 +        ifconfig vif0.0 down
   4.105 +        mac=`ifconfig veth0 | grep HWadd | sed -e 's/.*\(..:..:..:..:..:..\).*/\1/'`
   4.106 +        ifconfig ${netdev} down
   4.107 +        ifconfig ${netdev} hw ether ${mac}
   4.108 +        ifconfig ${netdev} arp up
   4.109 +        transfer_addrs veth0 ${netdev}
   4.110 +        transfer_routes veth0 ${netdev}
   4.111 +        del_addrs veth0
   4.112 +        ifconfig veth0 -arp down
   4.113 +        ifconfig veth0 hw ether 00:00:00:00:00:00
   4.114 +    else
   4.115 +        transfer_addrs ${bridge} ${netdev}
   4.116 +        transfer_routes ${bridge} ${netdev}
   4.117 +        del_addrs ${bridge}
   4.118 +    fi
   4.119  }
   4.120  
   4.121  case ${OP} in
   4.122 -    start)
   4.123 +  start)
   4.124          op_start
   4.125          ;;
   4.126