ia64/xen-unstable

changeset 383:90eb994a96e2

bitkeeper revision 1.184 (3ea3068dWnCzvBRYV1RTpoVK29FlDg)

Many files:
Removed the system-wide VIF list -- we now find VIFs via the task hashtable. Fixed a few synchronisation problems.
author kaf24@scramble.cl.cam.ac.uk
date Sun Apr 20 20:43:57 2003 +0000 (2003-04-20)
parents a2d825bf9f08
children ab8fc04f7f0b 49c0cdb50376
files tools/domain_builder/newdom tools/domain_builder/vifinit xen/arch/i386/apic.c xen/arch/i386/ioremap.c xen/arch/i386/smpboot.c xen/arch/i386/traps.c xen/common/dom0_ops.c xen/common/dom_mem_ops.c xen/common/domain.c xen/common/kernel.c xen/common/network.c xen/common/schedule.c xen/drivers/block/xen_block.c xen/drivers/scsi/scsi.h xen/include/hypervisor-ifs/network.h xen/include/xeno/blkdev.h xen/include/xeno/ide.h xen/include/xeno/sched.h xen/include/xeno/skbuff.h xen/include/xeno/vif.h xen/net/dev.c xen/net/skbuff.c xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/dom0/dom0_core.c xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/dom0/vfr.c
line diff
     1.1 --- a/tools/domain_builder/newdom	Sun Apr 20 13:47:19 2003 +0000
     1.2 +++ b/tools/domain_builder/newdom	Sun Apr 20 20:43:57 2003 +0000
     1.3 @@ -21,10 +21,6 @@ DOM=$?
     1.4  
     1.5  echo DOM= $DOM
     1.6  
     1.7 -VIF=`cat /proc/xeno/dom$DOM/vif`
     1.8 -
     1.9 -echo VIF= $VIF
    1.10 -
    1.11 -$VIFINIT $VIF $IP
    1.12 +$VIFINIT $DOM 0 $IP
    1.13  
    1.14  
     2.1 --- a/tools/domain_builder/vifinit	Sun Apr 20 13:47:19 2003 +0000
     2.2 +++ b/tools/domain_builder/vifinit	Sun Apr 20 20:43:57 2003 +0000
     2.3 @@ -7,19 +7,19 @@
     2.4  # 
     2.5  # Usage is:
     2.6  #
     2.7 -#   vifinit [vif id] [dotted decimal ip address]
     2.8 +#   vifinit [vif dom] [vif idx] [dotted decimal ip address]
     2.9  #
    2.10 -if [ $# -ne 2 ] ; 
    2.11 +if [ $# -ne 3 ] ; 
    2.12  then
    2.13 -        echo "usage: vifinit [vif id] [dotted decimal ip address]"
    2.14 +        echo "usage: vifinit [vif dom] [vif idx] [dotted decimal ip address]"
    2.15          exit
    2.16  fi
    2.17  
    2.18  #outbound rule:
    2.19 -echo "ADD ACCEPT srcaddr=$2 srcaddrmask=255.255.255.255 srcint=$1 dstint=-1 proto=any" > /proc/vfr
    2.20 +echo "ADD ACCEPT srcaddr=$3 srcaddrmask=255.255.255.255 srcdom=$1 srcidx=$2 dst=PHYS proto=any" > /proc/vfr
    2.21  
    2.22  #inbound rule:
    2.23 -echo "ADD ACCEPT dstaddr=$2 dstaddrmask=255.255.255.255 srcint=-4 dstint=$1 proto=any" > /proc/vfr
    2.24 +echo "ADD ACCEPT dstaddr=$3 dstaddrmask=255.255.255.255 src=ANY dstdom=$1 dstidx=$2 proto=any" > /proc/vfr
    2.25  
    2.26  #----] done.
    2.27  
     3.1 --- a/xen/arch/i386/apic.c	Sun Apr 20 13:47:19 2003 +0000
     3.2 +++ b/xen/arch/i386/apic.c	Sun Apr 20 20:43:57 2003 +0000
     3.3 @@ -46,6 +46,7 @@
     3.4  #include <asm/pgalloc.h>
     3.5  #include <asm/hardirq.h>
     3.6  #include <asm/apic.h>
     3.7 +#include <xeno/mm.h>
     3.8  
     3.9  #include <asm/timex.h>
    3.10  #include <xeno/ac_timer.h>
     4.1 --- a/xen/arch/i386/ioremap.c	Sun Apr 20 13:47:19 2003 +0000
     4.2 +++ b/xen/arch/i386/ioremap.c	Sun Apr 20 20:43:57 2003 +0000
     4.3 @@ -8,7 +8,9 @@
     4.4   * (C) Copyright 1995 1996 Linus Torvalds
     4.5   */
     4.6  
     4.7 -//#include <linux/vmalloc.h>
     4.8 +#include <xeno/config.h>
     4.9 +#include <xeno/lib.h>
    4.10 +#include <xeno/mm.h>
    4.11  #include <asm/io.h>
    4.12  #include <asm/pgalloc.h>
    4.13  #include <asm/page.h>
     5.1 --- a/xen/arch/i386/smpboot.c	Sun Apr 20 13:47:19 2003 +0000
     5.2 +++ b/xen/arch/i386/smpboot.c	Sun Apr 20 20:43:57 2003 +0000
     5.3 @@ -36,6 +36,8 @@
     5.4  #include <xeno/init.h>
     5.5  #include <xeno/interrupt.h>
     5.6  #include <xeno/irq.h>
     5.7 +#include <xeno/mm.h>
     5.8 +#include <xeno/slab.h>
     5.9  #include <asm/pgalloc.h>
    5.10  #include <asm/mc146818rtc.h>
    5.11  #include <asm/smpboot.h>
     6.1 --- a/xen/arch/i386/traps.c	Sun Apr 20 13:47:19 2003 +0000
     6.2 +++ b/xen/arch/i386/traps.c	Sun Apr 20 20:43:57 2003 +0000
     6.3 @@ -13,6 +13,7 @@
     6.4  #include <xeno/sched.h>
     6.5  #include <xeno/lib.h>
     6.6  #include <xeno/errno.h>
     6.7 +#include <xeno/mm.h>
     6.8  #include <asm/ptrace.h>
     6.9  #include <xeno/delay.h>
    6.10  #include <xeno/spinlock.h>
     7.1 --- a/xen/common/dom0_ops.c	Sun Apr 20 13:47:19 2003 +0000
     7.2 +++ b/xen/common/dom0_ops.c	Sun Apr 20 20:43:57 2003 +0000
     7.3 @@ -9,6 +9,7 @@
     7.4  #include <xeno/config.h>
     7.5  #include <xeno/types.h>
     7.6  #include <xeno/lib.h>
     7.7 +#include <xeno/mm.h>
     7.8  #include <xeno/dom0_ops.h>
     7.9  #include <xeno/sched.h>
    7.10  #include <xeno/event.h>
     8.1 --- a/xen/common/dom_mem_ops.c	Sun Apr 20 13:47:19 2003 +0000
     8.2 +++ b/xen/common/dom_mem_ops.c	Sun Apr 20 20:43:57 2003 +0000
     8.3 @@ -9,6 +9,7 @@
     8.4  #include <xeno/config.h>
     8.5  #include <xeno/types.h>
     8.6  #include <xeno/lib.h>
     8.7 +#include <xeno/mm.h>
     8.8  #include <xeno/dom_mem_ops.h>
     8.9  #include <xeno/sched.h>
    8.10  #include <xeno/event.h>
     9.1 --- a/xen/common/domain.c	Sun Apr 20 13:47:19 2003 +0000
     9.2 +++ b/xen/common/domain.c	Sun Apr 20 20:43:57 2003 +0000
     9.3 @@ -24,11 +24,9 @@
     9.4  #define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED)
     9.5  #define L2_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
     9.6  
     9.7 +/* Both these structures are protected by the tasklist_lock. */
     9.8  rwlock_t tasklist_lock __cacheline_aligned = RW_LOCK_UNLOCKED;
     9.9 -
    9.10 -#define TASK_HASH_SIZE 256
    9.11 -#define TASK_HASH(_id) ((_id)&(TASK_HASH_SIZE-1))
    9.12 -static struct task_struct *task_hash[TASK_HASH_SIZE];
    9.13 +struct task_struct *task_hash[TASK_HASH_SIZE];
    9.14  
    9.15  /*
    9.16   * create a new domain
    10.1 --- a/xen/common/kernel.c	Sun Apr 20 13:47:19 2003 +0000
    10.2 +++ b/xen/common/kernel.c	Sun Apr 20 20:43:57 2003 +0000
    10.3 @@ -527,10 +527,6 @@ int console_export(char *str, int len)
    10.4      ethh->h_proto = htons(ETH_P_IP);
    10.5      skb->mac.ethernet= (struct ethhdr *)ethh;
    10.6  
    10.7 -    /* Keep the net rule tables happy. */
    10.8 -    skb->src_vif = VIF_PHYSICAL_INTERFACE;
    10.9 -    skb->dst_vif = 0;
   10.10 -    
   10.11      unmap_domain_mem(skb_data);
   10.12      
   10.13      (void)netif_rx(skb);
    11.1 --- a/xen/common/network.c	Sun Apr 20 13:47:19 2003 +0000
    11.2 +++ b/xen/common/network.c	Sun Apr 20 20:43:57 2003 +0000
    11.3 @@ -21,25 +21,41 @@
    11.4  #include <asm/domain_page.h>
    11.5  #include <asm/io.h>
    11.6  
    11.7 -/* vif globals 
    11.8 - * sys_vif_list is a lookup table for vifs, used in packet forwarding.
    11.9 - * it will be replaced later by something a little more flexible.
   11.10 - */
   11.11 -
   11.12 -int sys_vif_count;                                  /* global vif count */
   11.13 -net_vif_t *sys_vif_list[MAX_SYSTEM_VIFS];           /* global vif array */
   11.14  net_rule_ent_t *net_rule_list;                      /* global list of rules */
   11.15  kmem_cache_t *net_vif_cache;                        
   11.16  kmem_cache_t *net_rule_cache;
   11.17  static rwlock_t net_rule_lock = RW_LOCK_UNLOCKED;   /* rule mutex */
   11.18  
   11.19 -rwlock_t sys_vif_lock = RW_LOCK_UNLOCKED;    /* vif mutex */
   11.20 -
   11.21  void print_net_rule_list();
   11.22  
   11.23  
   11.24  /* ----[ VIF Functions ]----------------------------------------------------*/
   11.25  
   11.26 +
   11.27 +net_vif_t *find_vif_by_id(unsigned long id)
   11.28 +{
   11.29 +    struct task_struct *p;
   11.30 +    net_vif_t *vif = NULL;
   11.31 +    unsigned long flags, dom = id>>VIF_DOMAIN_SHIFT;
   11.32 +
   11.33 +    read_lock_irqsave(&tasklist_lock, flags);
   11.34 +    p = task_hash[TASK_HASH(dom)];
   11.35 +    while ( p != NULL )
   11.36 +    {
   11.37 +        if ( p->domain == dom )
   11.38 +        {
   11.39 +            vif = p->net_vif_list[id&VIF_INDEX_MASK];
   11.40 +            if ( vif != NULL ) get_vif(vif);
   11.41 +            break;
   11.42 +        }
   11.43 +        p = p->next_hash;
   11.44 +    }
   11.45 +    read_unlock_irqrestore(&tasklist_lock, flags);
   11.46 +
   11.47 +    return vif;
   11.48 +}
   11.49 +
   11.50 +
   11.51  /* create_net_vif - Create a new vif and append it to the specified domain.
   11.52   * 
   11.53   * the domain is examined to determine how many vifs currently are allocated
   11.54 @@ -47,7 +63,6 @@ void print_net_rule_list();
   11.55   * global list.
   11.56   * 
   11.57   */
   11.58 -
   11.59  net_vif_t *create_net_vif(int domain)
   11.60  {
   11.61      int dom_vif_idx;
   11.62 @@ -59,6 +74,8 @@ net_vif_t *create_net_vif(int domain)
   11.63      if ( !(p = find_domain_by_id(domain)) )
   11.64          return NULL;
   11.65      
   11.66 +    write_lock_irqsave(&tasklist_lock, flags);
   11.67 +
   11.68      for ( dom_vif_idx = 0; dom_vif_idx < MAX_DOMAIN_VIFS; dom_vif_idx++ )
   11.69          if ( p->net_vif_list[dom_vif_idx] == NULL ) break;
   11.70      if ( dom_vif_idx == MAX_DOMAIN_VIFS )
   11.71 @@ -82,20 +99,18 @@ net_vif_t *create_net_vif(int domain)
   11.72      new_vif->shared_rings = new_ring;
   11.73      new_vif->shared_idxs  = &p->shared_info->net_idx[dom_vif_idx];
   11.74      new_vif->domain       = p;
   11.75 +    new_vif->idx          = dom_vif_idx;
   11.76      new_vif->list.next    = NULL;
   11.77      spin_lock_init(&new_vif->rx_lock);
   11.78      spin_lock_init(&new_vif->tx_lock);
   11.79  
   11.80      p->net_vif_list[dom_vif_idx] = new_vif;
   11.81 -
   11.82 -    write_lock_irqsave(&sys_vif_lock, flags);
   11.83 -    new_vif->id = sys_vif_count;
   11.84 -    sys_vif_list[sys_vif_count++] = new_vif;
   11.85 -    write_unlock_irqrestore(&sys_vif_lock, flags);
   11.86      
   11.87 +    write_unlock_irqrestore(&tasklist_lock, flags);
   11.88      return new_vif;
   11.89      
   11.90   fail:
   11.91 +    write_unlock_irqrestore(&tasklist_lock, flags);
   11.92      if ( new_vif != NULL )
   11.93          kmem_cache_free(net_vif_cache, new_vif);
   11.94      if ( p != NULL )
   11.95 @@ -146,32 +161,25 @@ void destroy_net_vif(net_vif_t *vif)
   11.96  void unlink_net_vif(net_vif_t *vif)
   11.97  {
   11.98      unsigned long flags;
   11.99 -    int i;
  11.100  
  11.101      if ( vif == NULL )
  11.102          return;
  11.103  
  11.104 -    for ( i = 0; i < MAX_DOMAIN_VIFS; i++ )
  11.105 -        if ( vif->domain->net_vif_list[i] == vif )
  11.106 -            vif->domain->net_vif_list[i] = NULL;
  11.107 -    
  11.108 -    write_lock_irqsave(&sys_vif_lock, flags);
  11.109 -    sys_vif_list[vif->id] = NULL;
  11.110 -    write_unlock_irqrestore(&sys_vif_lock, flags);
  11.111 -    
  11.112 +    write_lock_irqsave(&tasklist_lock, flags);
  11.113 +    vif->domain->net_vif_list[vif->idx] = NULL;
  11.114 +    write_unlock_irqrestore(&tasklist_lock, flags);
  11.115 +
  11.116      put_vif(vif);
  11.117  }
  11.118  
  11.119  
  11.120 -/* vif_query - Call from the proc file system to get a list of vifs 
  11.121 - * assigned to a particular domain.
  11.122 +/* vif_query - Call from the proc file system to get a list of indexes
  11.123 + * in use by a particular domain.
  11.124   */
  11.125 -
  11.126  void vif_query(vif_query_t *vq)
  11.127  {
  11.128      net_vif_t *vif;
  11.129      struct task_struct *p;
  11.130 -    unsigned long flags;
  11.131      char buf[128];
  11.132      int i;
  11.133  
  11.134 @@ -180,14 +188,12 @@ void vif_query(vif_query_t *vq)
  11.135  
  11.136      *buf = '\0';
  11.137  
  11.138 -    read_lock_irqsave(&sys_vif_lock, flags);
  11.139 -    for ( i = 0; i < MAX_SYSTEM_VIFS; i++ )
  11.140 +    for ( i = 0; i < MAX_DOMAIN_VIFS; i++ )
  11.141      {
  11.142 -        vif = sys_vif_list[i];
  11.143 -        if ( (vif == NULL) || (vif->domain != p) ) continue;
  11.144 -        sprintf(buf + strlen(buf), "%d\n", vif->id);
  11.145 +        vif = p->net_vif_list[i];
  11.146 +        if ( vif == NULL ) continue;
  11.147 +        sprintf(buf + strlen(buf), "%d\n", i);
  11.148      }
  11.149 -    read_unlock_irqrestore(&sys_vif_lock, flags);
  11.150  
  11.151      copy_to_user(vq->buf, buf, strlen(buf) + 1);
  11.152      
  11.153 @@ -204,9 +210,7 @@ int add_net_rule(net_rule_t *rule)
  11.154      net_rule_ent_t *new_ent;
  11.155      
  11.156      if ( (new_ent = kmem_cache_alloc(net_rule_cache, GFP_KERNEL)) == NULL )
  11.157 -    {
  11.158          return -ENOMEM;
  11.159 -    }
  11.160  
  11.161      memcpy(&new_ent->r, rule, sizeof(net_rule_t));
  11.162  
  11.163 @@ -253,7 +257,7 @@ int delete_net_rule(net_rule_t *rule)
  11.164   * ip address to the specified vif.  It's used to set up domain zero.
  11.165   */
  11.166  
  11.167 -void add_default_net_rule(int vif_id, u32 ipaddr)
  11.168 +void add_default_net_rule(unsigned long vif_id, u32 ipaddr)
  11.169  {
  11.170      net_rule_t new_rule;
  11.171  
  11.172 @@ -261,8 +265,8 @@ void add_default_net_rule(int vif_id, u3
  11.173      memset(&new_rule, 0, sizeof(net_rule_t));
  11.174      new_rule.src_addr = ipaddr;
  11.175      new_rule.src_addr_mask = 0xffffffff;
  11.176 -    new_rule.src_interface = vif_id;
  11.177 -    new_rule.dst_interface = VIF_PHYSICAL_INTERFACE;
  11.178 +    new_rule.src_vif = vif_id;
  11.179 +    new_rule.dst_vif = VIF_PHYSICAL_INTERFACE;
  11.180      new_rule.action = NETWORK_ACTION_ACCEPT;
  11.181      new_rule.proto = NETWORK_PROTO_ANY;
  11.182      add_net_rule(&new_rule);
  11.183 @@ -271,8 +275,8 @@ void add_default_net_rule(int vif_id, u3
  11.184      memset(&new_rule, 0, sizeof(net_rule_t));
  11.185      new_rule.dst_addr = ipaddr;
  11.186      new_rule.dst_addr_mask = 0xffffffff;
  11.187 -    new_rule.src_interface = VIF_ANY_INTERFACE;
  11.188 -    new_rule.dst_interface = vif_id;
  11.189 +    new_rule.src_vif = VIF_ANY_INTERFACE;
  11.190 +    new_rule.dst_vif = vif_id;
  11.191      new_rule.action = NETWORK_ACTION_ACCEPT;
  11.192      new_rule.proto = NETWORK_PROTO_ANY;
  11.193      add_net_rule(&new_rule);
  11.194 @@ -294,8 +298,32 @@ void print_net_rule(net_rule_t *r)
  11.195      printk("=] dst_port         : %u\n", r->dst_port);
  11.196      printk("=] dst_port_mask    : %u\n", r->dst_port_mask);
  11.197      printk("=] dst_proto        : %u\n", r->proto);
  11.198 -    printk("=] src_interface    : %d\n", r->src_interface);
  11.199 -    printk("=] dst_interface    : %d\n", r->dst_interface);
  11.200 +    switch ( r->src_vif )
  11.201 +    {
  11.202 +    case VIF_PHYSICAL_INTERFACE:
  11.203 +        printk("=] src_dom/idx      : PHYSICAL\n"); 
  11.204 +        break;
  11.205 +    case VIF_ANY_INTERFACE:
  11.206 +        printk("=] src_dom/idx      : ANY\n"); 
  11.207 +        break;
  11.208 +    default:
  11.209 +        printk("=] src_dom/idx      : %lu/%lu\n", 
  11.210 +               r->src_vif>>VIF_DOMAIN_SHIFT, r->src_vif&VIF_INDEX_MASK);
  11.211 +        break;
  11.212 +    }
  11.213 +    switch ( r->dst_vif )
  11.214 +    {
  11.215 +    case VIF_PHYSICAL_INTERFACE:
  11.216 +        printk("=] dst_dom/idx      : PHYSICAL\n"); 
  11.217 +        break;
  11.218 +    case VIF_ANY_INTERFACE:
  11.219 +        printk("=] dst_dom/idx      : ANY\n"); 
  11.220 +        break;
  11.221 +    default:
  11.222 +        printk("=] dst_dom/idx      : %lu/%lu\n", 
  11.223 +               r->dst_vif>>VIF_DOMAIN_SHIFT, r->dst_vif&VIF_INDEX_MASK);
  11.224 +        break;
  11.225 +    }
  11.226      printk("=] action           : %u\n", r->action);
  11.227  }
  11.228  
  11.229 @@ -327,20 +355,21 @@ void print_net_rule_list()
  11.230   * Apply the rules to this skbuff and return the vif id that it is bound for.
  11.231   * If there is no match, VIF_DROP is returned.
  11.232   */
  11.233 -int net_find_rule(u8 nproto, u8 tproto, u32 src_addr, u32 dst_addr, 
  11.234 -                  u16 src_port, u16 dst_port, int src_vif)
  11.235 +static net_vif_t *net_find_rule(u8 nproto, u8 tproto, u32 src_addr, 
  11.236 +                                u32 dst_addr, u16 src_port, 
  11.237 +                                u16 dst_port, unsigned long src_vif)
  11.238  {
  11.239      net_rule_ent_t *ent;
  11.240 -    int dest = VIF_DROP;
  11.241 -    
  11.242 +    unsigned long dest = VIF_UNKNOWN_INTERFACE;
  11.243 +
  11.244      read_lock(&net_rule_lock);
  11.245      
  11.246      ent = net_rule_list;
  11.247      
  11.248      while ( ent != NULL )
  11.249      {
  11.250 -        if ( ((ent->r.src_interface == src_vif)
  11.251 -              || (ent->r.src_interface == VIF_ANY_INTERFACE)) &&
  11.252 +        if ( ((ent->r.src_vif == src_vif)
  11.253 +              || (ent->r.src_vif == VIF_ANY_INTERFACE)) &&
  11.254  
  11.255               (!((ent->r.src_addr ^ src_addr) & ent->r.src_addr_mask )) &&
  11.256               (!((ent->r.dst_addr ^ dst_addr) & ent->r.dst_addr_mask )) &&
  11.257 @@ -361,18 +390,24 @@ int net_find_rule(u8 nproto, u8 tproto, 
  11.258              /*
  11.259               * XXX FFS! We keep going to find the "best" rule. Where best 
  11.260               * corresponds to vaguely sane routing of a packet. We need a less 
  11.261 -             * shafted model for aour "virtual firewall/router" methinks!
  11.262 +             * shafted model for our "virtual firewall/router" methinks!
  11.263               */
  11.264 -            if ( dest < 0 )
  11.265 -                dest = ent->r.dst_interface;
  11.266 -            if ( dest >= 0 )
  11.267 +            if ( (dest & VIF_DOMAIN_MASK) == VIF_SPECIAL )
  11.268 +                dest = ent->r.dst_vif;
  11.269 +            if ( (dest & VIF_DOMAIN_MASK) != VIF_SPECIAL )
  11.270                  break;
  11.271          }
  11.272          ent = ent->next;
  11.273      }
  11.274  
  11.275      read_unlock(&net_rule_lock);
  11.276 -    return dest;
  11.277 +
  11.278 +    if ( dest == VIF_PHYSICAL_INTERFACE )
  11.279 +        return VIF_PHYS;
  11.280 +    else if ( (dest & VIF_DOMAIN_MASK) == VIF_SPECIAL )
  11.281 +        return VIF_DROP;
  11.282 +    else
  11.283 +        return find_vif_by_id(dest);
  11.284  }
  11.285  
  11.286  /* net_get_target_vif - Find the vif that the given sk_buff is bound for.
  11.287 @@ -393,14 +428,16 @@ int net_find_rule(u8 nproto, u8 tproto, 
  11.288   * based on the packet type.  it then calls net_find_rule to scan the rule 
  11.289   * list.
  11.290   */
  11.291 -
  11.292 -#define net_get_target_vif(skb) __net_get_target_vif(skb->data, skb->len, skb->src_vif)
  11.293 +net_vif_t *net_get_target_vif(u8 *data, unsigned int len, net_vif_t *src_vif)
  11.294 +{
  11.295 +    net_vif_t *target = VIF_DROP;
  11.296 +    u8 *h_raw, *nh_raw;
  11.297 +    unsigned long src_vif_val = VIF_PHYSICAL_INTERFACE;
  11.298  
  11.299 -int __net_get_target_vif(u8 *data, unsigned int len, int src_vif)
  11.300 -{
  11.301 -    int target = VIF_DROP;
  11.302 -    u8 *h_raw, *nh_raw;
  11.303 -    
  11.304 +    if ( src_vif != VIF_PHYS )
  11.305 +        src_vif_val = (src_vif->domain->domain<<VIF_DOMAIN_SHIFT) | 
  11.306 +            src_vif->idx;
  11.307 +
  11.308      if ( len < ETH_HLEN ) goto drop;
  11.309  
  11.310      nh_raw = data + ETH_HLEN;
  11.311 @@ -410,34 +447,26 @@ int __net_get_target_vif(u8 *data, unsig
  11.312          if ( len < (ETH_HLEN + 28) ) goto drop;
  11.313          target = net_find_rule((u8)ETH_P_ARP, 0, ntohl(*(u32 *)(nh_raw + 14)),
  11.314                                 ntohl(*(u32 *)(nh_raw + 24)), 0, 0, 
  11.315 -                               src_vif);
  11.316 +                               src_vif_val);
  11.317          break;
  11.318  
  11.319      case ETH_P_IP:
  11.320          if ( len < (ETH_HLEN + 20) ) goto drop;
  11.321          h_raw =  data + ((*(unsigned char *)(nh_raw)) & 0x0f) * 4;
  11.322 -        
  11.323 -        /* XXX For now, we ignore ports. */
  11.324 -#if 0
  11.325 -        target = net_find_rule((u8)ETH_P_IP,  *(u8 *)(nh_raw + 9),
  11.326 -                               ntohl(*(u32 *)(nh_raw + 12)),
  11.327 -                               ntohl(*(u32 *)(nh_raw + 16)),
  11.328 -                               ntohs(*(u16 *)(h_raw)),
  11.329 -                               ntohs(*(u16 *)(h_raw + 2)), 
  11.330 -                               src_vif);
  11.331 -#else
  11.332 +        /* NB. For now we ignore ports. */
  11.333          target = net_find_rule((u8)ETH_P_IP,  *(u8 *)(data + 9),
  11.334                                 ntohl(*(u32 *)(nh_raw + 12)),
  11.335                                 ntohl(*(u32 *)(nh_raw + 16)),
  11.336                                 0,
  11.337                                 0, 
  11.338 -                               src_vif);
  11.339 -#endif
  11.340 +                               src_vif_val);
  11.341 +        break;
  11.342      }
  11.343      return target;
  11.344      
  11.345   drop:
  11.346 -    printk("VIF%d: pkt to drop!\n", src_vif);
  11.347 +    printk("VIF%lu/%lu: pkt to drop!\n", 
  11.348 +           src_vif_val>>VIF_DOMAIN_SHIFT, src_vif_val&VIF_INDEX_MASK);
  11.349      return VIF_DROP;
  11.350  }
  11.351  
  11.352 @@ -496,8 +525,6 @@ long do_network_op(network_op_t *u_netwo
  11.353  
  11.354  void __init net_init (void)
  11.355  {
  11.356 -    sys_vif_count = 0;
  11.357 -    memset(sys_vif_list, 0, sizeof(sys_vif_list));
  11.358      net_rule_list = NULL;
  11.359      net_vif_cache = kmem_cache_create("net_vif_cache", sizeof(net_vif_t),
  11.360                                      0, SLAB_HWCACHE_ALIGN, NULL, NULL);
    12.1 --- a/xen/common/schedule.c	Sun Apr 20 13:47:19 2003 +0000
    12.2 +++ b/xen/common/schedule.c	Sun Apr 20 20:43:57 2003 +0000
    12.3 @@ -28,7 +28,7 @@
    12.4  #include <xeno/time.h>
    12.5  #include <xeno/ac_timer.h>
    12.6  #include <xeno/interrupt.h>
    12.7 -
    12.8 +#include <xeno/timer.h>
    12.9  #include <xeno/perfc.h>
   12.10  
   12.11  
    13.1 --- a/xen/drivers/block/xen_block.c	Sun Apr 20 13:47:19 2003 +0000
    13.2 +++ b/xen/drivers/block/xen_block.c	Sun Apr 20 20:43:57 2003 +0000
    13.3 @@ -17,6 +17,7 @@
    13.4  #include <xeno/keyhandler.h>
    13.5  #include <xeno/interrupt.h>
    13.6  #include <xeno/segment.h>
    13.7 +#include <xeno/slab.h>
    13.8  
    13.9  #if 0
   13.10  #define DPRINTK(_f, _a...) printk( _f , ## _a )
    14.1 --- a/xen/drivers/scsi/scsi.h	Sun Apr 20 13:47:19 2003 +0000
    14.2 +++ b/xen/drivers/scsi/scsi.h	Sun Apr 20 20:43:57 2003 +0000
    14.3 @@ -16,7 +16,7 @@
    14.4  #define _SCSI_H
    14.5  
    14.6  #include <xeno/config.h>	/* for CONFIG_SCSI_LOGGING */
    14.7 -/*#include <xeno/devfs_fs_kernel.h>*/
    14.8 +#include <xeno/timer.h>
    14.9  /*#include <xeno/proc_fs.h>*/
   14.10  
   14.11  /*
    15.1 --- a/xen/include/hypervisor-ifs/network.h	Sun Apr 20 13:47:19 2003 +0000
    15.2 +++ b/xen/include/hypervisor-ifs/network.h	Sun Apr 20 20:43:57 2003 +0000
    15.3 @@ -104,12 +104,22 @@ typedef struct net_rule_st
    15.4      u16  src_port_mask;
    15.5      u16  dst_port_mask;
    15.6      u16  proto;
    15.7 -    
    15.8 -    int  src_interface;
    15.9 -    int  dst_interface;
   15.10 +    unsigned long src_vif;
   15.11 +    unsigned long dst_vif;
   15.12      u16  action;
   15.13  } net_rule_t;
   15.14  
   15.15 +#define VIF_DOMAIN_MASK  0xfffff000UL
   15.16 +#define VIF_DOMAIN_SHIFT 12
   15.17 +#define VIF_INDEX_MASK   0x00000fffUL
   15.18 +#define VIF_INDEX_SHIFT  0
   15.19 +
   15.20 +/* These are specified in the index if the dom is SPECIAL. */
   15.21 +#define VIF_SPECIAL      0xfffff000UL
   15.22 +#define VIF_UNKNOWN_INTERFACE   (VIF_SPECIAL | 0)
   15.23 +#define VIF_PHYSICAL_INTERFACE  (VIF_SPECIAL | 1)
   15.24 +#define VIF_ANY_INTERFACE       (VIF_SPECIAL | 2)
   15.25 +
   15.26  typedef struct vif_query_st
   15.27  {
   15.28      unsigned int    domain;
    16.1 --- a/xen/include/xeno/blkdev.h	Sun Apr 20 13:47:19 2003 +0000
    16.2 +++ b/xen/include/xeno/blkdev.h	Sun Apr 20 20:43:57 2003 +0000
    16.3 @@ -7,6 +7,7 @@
    16.4  #include <xeno/list.h>
    16.5  #include <xeno/kdev_t.h>
    16.6  #include <xeno/sched.h>
    16.7 +#include <xeno/mm.h>
    16.8  
    16.9  /* Some defines from fs.h that may actually be useful to the blkdev layer. */
   16.10  #define READ 0
    17.1 --- a/xen/include/xeno/ide.h	Sun Apr 20 13:47:19 2003 +0000
    17.2 +++ b/xen/include/xeno/ide.h	Sun Apr 20 20:43:57 2003 +0000
    17.3 @@ -13,7 +13,7 @@
    17.4  #include <xeno/hdsmart.h>
    17.5  #include <xeno/major.h>
    17.6  #include <xeno/blkdev.h>
    17.7 -/*#include <xeno/proc_fs.h>*/
    17.8 +#include <xeno/timer.h>
    17.9  /*#include <xeno/devfs_fs_kernel.h>*/
   17.10  #include <asm/hdreg.h>
   17.11  
    18.1 --- a/xen/include/xeno/sched.h	Sun Apr 20 13:47:19 2003 +0000
    18.2 +++ b/xen/include/xeno/sched.h	Sun Apr 20 20:43:57 2003 +0000
    18.3 @@ -267,6 +267,11 @@ void domain_init(void);
    18.4  int idle_cpu(int cpu); /* Is CPU 'cpu' idle right now? */
    18.5  void cpu_idle(void);   /* Idle loop. */
    18.6  
    18.7 +/* This hash table is protected by the tasklist_lock. */
    18.8 +#define TASK_HASH_SIZE 256
    18.9 +#define TASK_HASH(_id) ((_id)&(TASK_HASH_SIZE-1))
   18.10 +struct task_struct *task_hash[TASK_HASH_SIZE];
   18.11 +
   18.12  #define REMOVE_LINKS(p) do { \
   18.13          (p)->next_task->prev_task = (p)->prev_task; \
   18.14          (p)->prev_task->next_task = (p)->next_task; \
    19.1 --- a/xen/include/xeno/skbuff.h	Sun Apr 20 13:47:19 2003 +0000
    19.2 +++ b/xen/include/xeno/skbuff.h	Sun Apr 20 20:43:57 2003 +0000
    19.3 @@ -25,12 +25,7 @@
    19.4  #include <asm/types.h>
    19.5  #include <linux/spinlock.h>
    19.6  #include <linux/mm.h>
    19.7 -
    19.8 -/* vif special values */
    19.9 -#define VIF_PHYSICAL_INTERFACE  -1
   19.10 -#define VIF_UNKNOWN_INTERFACE   -2
   19.11 -#define VIF_DROP                -3
   19.12 -#define VIF_ANY_INTERFACE       -4
   19.13 +#include <xeno/vif.h>
   19.14  
   19.15  /* skb_type values */
   19.16  #define SKB_NORMAL               0 /* A Linux-style skbuff: no strangeness */
   19.17 @@ -162,8 +157,8 @@ struct sk_buff {
   19.18  
   19.19      void 		(*destructor)(struct sk_buff *);	/* Destruct function		*/
   19.20      struct pfn_info *pf;                    /* record of physical pf address for freeing    */
   19.21 -    int src_vif;                            /* vif we came from                             */
   19.22 -    int dst_vif;                            /* vif we are bound for                         */
   19.23 +    net_vif_t *src_vif;                     /* vif we came from                             */
   19.24 +    net_vif_t *dst_vif;                     /* vif we are bound for                         */
   19.25      struct skb_shared_info shinfo;          /* shared info is no longer shared in Xen.      */
   19.26  };
   19.27  
    20.1 --- a/xen/include/xeno/vif.h	Sun Apr 20 13:47:19 2003 +0000
    20.2 +++ b/xen/include/xeno/vif.h	Sun Apr 20 20:43:57 2003 +0000
    20.3 @@ -6,6 +6,9 @@
    20.4   * Copyright (c) 2002-2003, A K Warfield and K A Fraser
    20.5   */
    20.6  
    20.7 +#ifndef __XENO_VIF_H__
    20.8 +#define __XENO_VIF_H__
    20.9 +
   20.10  /* virtual network interface struct and associated defines. */
   20.11  /* net_vif_st is the larger struct that describes a virtual network interface
   20.12   * it contains a pointer to the net_ring_t structure that needs to be on a 
   20.13 @@ -16,7 +19,6 @@
   20.14   */
   20.15  
   20.16  #include <hypervisor-ifs/network.h>
   20.17 -#include <xeno/skbuff.h>
   20.18  
   20.19  /* 
   20.20   * shadow ring structures are used to protect the descriptors from
   20.21 @@ -62,8 +64,8 @@ typedef struct net_vif_st {
   20.22      unsigned int tx_resp_prod; /* private version of shared variable */
   20.23  
   20.24      /* Miscellaneous private stuff. */
   20.25 -    int                 id;
   20.26      struct task_struct *domain;
   20.27 +    unsigned int idx; /* index within domain */
   20.28      struct list_head    list;     /* scheduling list */
   20.29      atomic_t            refcnt;
   20.30      spinlock_t          rx_lock, tx_lock;
   20.31 @@ -75,24 +77,22 @@ do {                                    
   20.32      if ( atomic_dec_and_test(&(_v)->refcnt) ) destroy_net_vif(_v); \
   20.33  } while (0)                                                        \
   20.34  
   20.35 -/* VIF-related defines. */
   20.36 -#define MAX_SYSTEM_VIFS 256  
   20.37 -
   20.38 -/* vif globals */
   20.39 -extern int sys_vif_count;
   20.40 -extern net_vif_t *sys_vif_list[];
   20.41 -extern rwlock_t sys_vif_lock; /* protects the sys_vif_list */
   20.42 -
   20.43  /* vif prototypes */
   20.44  net_vif_t *create_net_vif(int domain);
   20.45  void destroy_net_vif(net_vif_t *vif);
   20.46  void unlink_net_vif(net_vif_t *vif);
   20.47 -void add_default_net_rule(int vif_id, u32 ipaddr);
   20.48 -int __net_get_target_vif(u8 *data, unsigned int len, int src_vif);
   20.49 -void add_default_net_rule(int vif_id, u32 ipaddr);
   20.50 +void add_default_net_rule(unsigned long vif_id, u32 ipaddr);
   20.51 +net_vif_t *net_get_target_vif(u8 *data, unsigned int len, net_vif_t *src_vif);
   20.52 +net_vif_t *find_vif_by_id(unsigned long id);
   20.53  
   20.54 -#define net_get_target_vif(skb) __net_get_target_vif(skb->data, skb->len, skb->src_vif)
   20.55 -/* status fields per-descriptor:
   20.56 +/*
   20.57 + * Return values from net_get_target_vif:
   20.58 + *  VIF_PHYS -- Send to physical NIC
   20.59 + *  VIF_DROP -- Drop this packet
   20.60 + *  others   -- Send to specified VIF (reference held on return)
   20.61   */
   20.62 +#define VIF_PHYS ((net_vif_t *)0)
   20.63 +#define VIF_DROP ((net_vif_t *)1)
   20.64  
   20.65 +#endif /* __XENO_VIF_H__ */
   20.66  
    21.1 --- a/xen/net/dev.c	Sun Apr 20 13:47:19 2003 +0000
    21.2 +++ b/xen/net/dev.c	Sun Apr 20 20:43:57 2003 +0000
    21.3 @@ -586,7 +586,6 @@ int netif_rx(struct sk_buff *skb)
    21.4  {
    21.5      int offset, this_cpu = smp_processor_id();
    21.6      unsigned long flags;
    21.7 -    net_vif_t *vif;
    21.8  
    21.9      local_irq_save(flags);
   21.10  
   21.11 @@ -605,17 +604,11 @@ int netif_rx(struct sk_buff *skb)
   21.12  
   21.13      netdev_rx_stat[this_cpu].total++;
   21.14  
   21.15 -    if ( skb->src_vif == VIF_UNKNOWN_INTERFACE )
   21.16 -        skb->src_vif = VIF_PHYSICAL_INTERFACE;
   21.17 -                
   21.18 -    if ( skb->dst_vif == VIF_UNKNOWN_INTERFACE )
   21.19 -        skb->dst_vif = __net_get_target_vif(skb->data, skb->len, skb->src_vif);
   21.20 +    if ( skb->dst_vif == NULL )
   21.21 +        skb->dst_vif = net_get_target_vif(skb->data, skb->len, skb->src_vif);
   21.22          
   21.23 -    read_lock(&sys_vif_lock);
   21.24 -    if ( (skb->dst_vif <= VIF_PHYSICAL_INTERFACE) ||
   21.25 -         ((vif = sys_vif_list[skb->dst_vif]) == NULL) )
   21.26 +    if ( (skb->dst_vif == VIF_PHYS) || (skb->dst_vif == VIF_DROP) )
   21.27      {
   21.28 -        read_unlock(&sys_vif_lock);
   21.29          netdev_rx_stat[this_cpu].dropped++;
   21.30          unmap_domain_mem(skb->head);
   21.31          kfree_skb(skb);
   21.32 @@ -623,10 +616,8 @@ int netif_rx(struct sk_buff *skb)
   21.33          return NET_RX_DROP;
   21.34      }
   21.35  
   21.36 -    get_vif(vif);
   21.37 -    read_unlock(&sys_vif_lock);
   21.38 -    deliver_packet(skb, vif);
   21.39 -    put_vif(vif);
   21.40 +    deliver_packet(skb, skb->dst_vif);
   21.41 +    put_vif(skb->dst_vif);
   21.42  
   21.43      unmap_domain_mem(skb->head);
   21.44      kfree_skb(skb);
   21.45 @@ -690,7 +681,7 @@ static void add_to_net_schedule_list_tai
   21.46  static void tx_skb_release(struct sk_buff *skb)
   21.47  {
   21.48      int i;
   21.49 -    net_vif_t *vif = sys_vif_list[skb->src_vif];
   21.50 +    net_vif_t *vif = skb->src_vif;
   21.51      tx_shadow_entry_t *tx;
   21.52      unsigned long flags;
   21.53      
   21.54 @@ -755,8 +746,8 @@ static void net_tx_action(unsigned long 
   21.55          skb->end  = skb->tail = skb->head + PKT_PROT_LEN;
   21.56          
   21.57          skb->dev      = the_dev;
   21.58 -        skb->src_vif  = vif->id;
   21.59 -        skb->dst_vif  = VIF_PHYSICAL_INTERFACE;
   21.60 +        skb->src_vif  = vif;
   21.61 +        skb->dst_vif  = NULL;
   21.62          skb->mac.raw  = skb->data; 
   21.63          
   21.64          skb_shinfo(skb)->frags[0].page        = frame_table +
   21.65 @@ -1765,7 +1756,7 @@ long do_net_update(void)
   21.66      unsigned long pte_pfn, buf_pfn;
   21.67      struct pfn_info *pte_page, *buf_page;
   21.68      unsigned long *ptep;    
   21.69 -    int target;
   21.70 +    net_vif_t *target;
   21.71      u8 *g_data;
   21.72      unsigned short protocol;
   21.73  
   21.74 @@ -1792,7 +1783,8 @@ long do_net_update(void)
   21.75                    (((vif->tx_resp_prod-i) & (TX_RING_SIZE-1)) != 1); 
   21.76                i = TX_RING_INC(i) )
   21.77          {
   21.78 -            tx = shared_rings->tx_ring[i].req;
   21.79 +            tx     = shared_rings->tx_ring[i].req;
   21.80 +            target = VIF_DROP;
   21.81  
   21.82              if ( (tx.size < PKT_PROT_LEN) || (tx.size > ETH_FRAME_LEN) )
   21.83              {
   21.84 @@ -1832,18 +1824,36 @@ long do_net_update(void)
   21.85                  goto tx_unmap_and_continue;
   21.86              }
   21.87  
   21.88 -            target = __net_get_target_vif(g_data, tx.size, vif->id);
   21.89 +            target = net_get_target_vif(g_data, tx.size, vif);
   21.90  
   21.91 -            if ( target > VIF_PHYSICAL_INTERFACE )
   21.92 +            if ( target == VIF_PHYS )
   21.93 +            {
   21.94 +                vif->tx_shadow_ring[j].id     = tx.id;
   21.95 +                vif->tx_shadow_ring[j].size   = tx.size;
   21.96 +                vif->tx_shadow_ring[j].header = 
   21.97 +                    kmem_cache_alloc(net_header_cachep, GFP_KERNEL);
   21.98 +                if ( vif->tx_shadow_ring[j].header == NULL )
   21.99 +                { 
  21.100 +                    make_tx_response(vif, tx.id, RING_STATUS_OK);
  21.101 +                    goto tx_unmap_and_continue;
  21.102 +                }
  21.103 +
  21.104 +                memcpy(vif->tx_shadow_ring[j].header, g_data, PKT_PROT_LEN);
  21.105 +                vif->tx_shadow_ring[j].payload = tx.addr + PKT_PROT_LEN;
  21.106 +                get_page_tot(buf_page);
  21.107 +                j = TX_RING_INC(j);
  21.108 +            }
  21.109 +            else if ( target != VIF_DROP )
  21.110              {
  21.111                  /* Local delivery */
  21.112                  if ( (skb = dev_alloc_skb(ETH_FRAME_LEN + 32)) == NULL )
  21.113                  {
  21.114                      make_tx_response(vif, tx.id, RING_STATUS_BAD_PAGE);
  21.115 +                    put_vif(target);
  21.116                      goto tx_unmap_and_continue;
  21.117                  }
  21.118  
  21.119 -                skb->src_vif = vif->id;
  21.120 +                skb->src_vif = vif;
  21.121                  skb->dst_vif = target;
  21.122                  skb->protocol = protocol;                
  21.123  
  21.124 @@ -1865,23 +1875,6 @@ long do_net_update(void)
  21.125  
  21.126                  make_tx_response(vif, tx.id, RING_STATUS_OK);
  21.127              }
  21.128 -            else if ( target == VIF_PHYSICAL_INTERFACE )
  21.129 -            {
  21.130 -                vif->tx_shadow_ring[j].id     = tx.id;
  21.131 -                vif->tx_shadow_ring[j].size   = tx.size;
  21.132 -                vif->tx_shadow_ring[j].header = 
  21.133 -                    kmem_cache_alloc(net_header_cachep, GFP_KERNEL);
  21.134 -                if ( vif->tx_shadow_ring[j].header == NULL )
  21.135 -                { 
  21.136 -                    make_tx_response(vif, tx.id, RING_STATUS_OK);
  21.137 -                    goto tx_unmap_and_continue;
  21.138 -                }
  21.139 -
  21.140 -                memcpy(vif->tx_shadow_ring[j].header, g_data, PKT_PROT_LEN);
  21.141 -                vif->tx_shadow_ring[j].payload = tx.addr + PKT_PROT_LEN;
  21.142 -                get_page_tot(buf_page);
  21.143 -                j = TX_RING_INC(j);
  21.144 -            }
  21.145  
  21.146          tx_unmap_and_continue:
  21.147              unmap_domain_mem(g_data);
    22.1 --- a/xen/net/skbuff.c	Sun Apr 20 13:47:19 2003 +0000
    22.2 +++ b/xen/net/skbuff.c	Sun Apr 20 20:43:57 2003 +0000
    22.3 @@ -222,8 +222,6 @@ struct sk_buff *alloc_skb(unsigned int s
    22.4      /* Set up other state */
    22.5      skb->len = 0;
    22.6      skb->data_len = 0;
    22.7 -    skb->src_vif = VIF_UNKNOWN_INTERFACE;
    22.8 -    skb->dst_vif = VIF_UNKNOWN_INTERFACE;
    22.9      skb->skb_type = SKB_NORMAL;
   22.10  
   22.11      skb_shinfo(skb)->nr_frags = 0;
   22.12 @@ -270,8 +268,6 @@ struct sk_buff *alloc_zc_skb(unsigned in
   22.13      /* Set up other state */
   22.14      skb->len = 0;
   22.15      skb->data_len = 0;
   22.16 -    skb->src_vif = VIF_UNKNOWN_INTERFACE;
   22.17 -    skb->dst_vif = VIF_UNKNOWN_INTERFACE;
   22.18      skb->skb_type = SKB_ZERO_COPY;
   22.19  
   22.20      skb_shinfo(skb)->nr_frags = 0;
   22.21 @@ -312,6 +308,8 @@ static inline void skb_headerinit(void *
   22.22  {
   22.23      struct sk_buff *skb = p;
   22.24  
   22.25 +    skb->src_vif = NULL;
   22.26 +    skb->dst_vif = NULL;
   22.27      skb->next = NULL;
   22.28      skb->prev = NULL;
   22.29      skb->list = NULL;
    23.1 --- a/xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/dom0/dom0_core.c	Sun Apr 20 13:47:19 2003 +0000
    23.2 +++ b/xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/dom0/dom0_core.c	Sun Apr 20 20:43:57 2003 +0000
    23.3 @@ -75,15 +75,11 @@ static int cmd_read_proc(char *page, cha
    23.4  
    23.5  static ssize_t dom_vif_read(struct file * file, char * buff, size_t size, loff_t * off)
    23.6  {
    23.7 -    char hyp_buf[128]; // Hypervisor is going to write its reply here.
    23.8 +    char hyp_buf[128];
    23.9      network_op_t op;
   23.10      static int finished = 0;
   23.11  
   23.12 -    // This seems to be the only way to make the OS stop making read requests
   23.13 -    // to the file.  When we use the fileoperations version of read, offset 
   23.14 -    // seems to be ignored altogether.
   23.15 -    
   23.16 -    if (finished) 
   23.17 +    if ( finished ) 
   23.18      {
   23.19          finished = 0;
   23.20          return 0;
    24.1 --- a/xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/dom0/vfr.c	Sun Apr 20 13:47:19 2003 +0000
    24.2 +++ b/xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/dom0/vfr.c	Sun Apr 20 20:43:57 2003 +0000
    24.3 @@ -26,7 +26,7 @@ u16 antous(const char *buff, int len);
    24.4  int anton(const char *buff, int len);
    24.5  
    24.6  static int vfr_read_proc(char *page, char **start, off_t off,
    24.7 -                                          int count, int *eof, void *data)
    24.8 +                         int count, int *eof, void *data)
    24.9  {   
   24.10      strcpy(page, readbuf);
   24.11      *readbuf = '\0';
   24.12 @@ -60,147 +60,163 @@ static int vfr_read_proc(char *page, cha
   24.13  		      ((_x)=='\f') || ((_x)=='\r') || ((_x)=='\n') )
   24.14  
   24.15  static int vfr_write_proc(struct file *file, const char *buffer,
   24.16 -                                           u_long count, void *data)
   24.17 +                          u_long count, void *data)
   24.18  {
   24.19 -  network_op_t op;
   24.20 -  int ret, len;
   24.21 -  int ts, te, tl; // token start, end, and length
   24.22 -  int fs, fe, fl; // field.
   24.23 +    network_op_t op;
   24.24 +    int ret, len;
   24.25 +    int ts, te, tl; // token start, end, and length
   24.26 +    int fs, fe, fl; // field.
   24.27  
   24.28 -  len = count;
   24.29 -  ts = te = 0;
   24.30 +    len = count;
   24.31 +    ts = te = 0;
   24.32  
   24.33 -  memset(&op, 0, sizeof(network_op_t));
   24.34 +    memset(&op, 0, sizeof(network_op_t));
   24.35  
   24.36 -  // get the command:
   24.37 -  while ( count && isspace(buffer[ts]) ) { ts++; count--; } // skip spaces.
   24.38 -  te = ts;
   24.39 -  while ( count && !isspace(buffer[te]) ) { te++; count--; } // command end
   24.40 -  if ( te <= ts ) goto bad;
   24.41 -  tl = te - ts;
   24.42 +    // get the command:
   24.43 +    while ( count && isspace(buffer[ts]) ) { ts++; count--; } // skip spaces.
   24.44 +    te = ts;
   24.45 +    while ( count && !isspace(buffer[te]) ) { te++; count--; } // command end
   24.46 +    if ( te <= ts ) goto bad;
   24.47 +    tl = te - ts;
   24.48    
   24.49 -  if ( strncmp(&buffer[ts], "ADD", tl) == 0 )
   24.50 -  {
   24.51 -     op.cmd = NETWORK_OP_ADDRULE;
   24.52 -  }
   24.53 -  else if ( strncmp(&buffer[ts], "DELETE", tl) == 0 )
   24.54 -  {
   24.55 -     op.cmd = NETWORK_OP_DELETERULE;
   24.56 -  }
   24.57 -  else if ( strncmp(&buffer[ts], "PRINT", tl) == 0 )
   24.58 -  {
   24.59 -     op.cmd = NETWORK_OP_GETRULELIST;
   24.60 -     goto doneparsing;
   24.61 -  }
   24.62 +    if ( strncmp(&buffer[ts], "ADD", tl) == 0 )
   24.63 +    {
   24.64 +        op.cmd = NETWORK_OP_ADDRULE;
   24.65 +    }
   24.66 +    else if ( strncmp(&buffer[ts], "DELETE", tl) == 0 )
   24.67 +    {
   24.68 +        op.cmd = NETWORK_OP_DELETERULE;
   24.69 +    }
   24.70 +    else if ( strncmp(&buffer[ts], "PRINT", tl) == 0 )
   24.71 +    {
   24.72 +        op.cmd = NETWORK_OP_GETRULELIST;
   24.73 +        goto doneparsing;
   24.74 +    }
   24.75          
   24.76 -  ts = te;
   24.77 +    ts = te;
   24.78    
   24.79 -  // get the action
   24.80 -  while ( count && (buffer[ts] == ' ') ) { ts++; count--; } // skip spaces.
   24.81 -  te = ts;
   24.82 -  while ( count && (buffer[te] != ' ') ) { te++; count--; } // command end
   24.83 -  if ( te <= ts ) goto bad;
   24.84 -  tl = te - ts;
   24.85 +    // get the action
   24.86 +    while ( count && (buffer[ts] == ' ') ) { ts++; count--; } // skip spaces.
   24.87 +    te = ts;
   24.88 +    while ( count && (buffer[te] != ' ') ) { te++; count--; } // command end
   24.89 +    if ( te <= ts ) goto bad;
   24.90 +    tl = te - ts;
   24.91  
   24.92 -  if ( strncmp(&buffer[ts], "ACCEPT", tl) == 0 ) 
   24.93 -  {
   24.94 -    op.u.net_rule.action = NETWORK_ACTION_ACCEPT;
   24.95 -    goto keyval;
   24.96 -  }
   24.97 -  if ( strncmp(&buffer[ts], "COUNT", tl) == 0 ) 
   24.98 -  {
   24.99 -    op.u.net_rule.action = NETWORK_ACTION_COUNT;
  24.100 -    goto keyval;
  24.101 -  }
  24.102 +    if ( strncmp(&buffer[ts], "ACCEPT", tl) == 0 ) 
  24.103 +    {
  24.104 +        op.u.net_rule.action = NETWORK_ACTION_ACCEPT;
  24.105 +        goto keyval;
  24.106 +    }
  24.107 +    if ( strncmp(&buffer[ts], "COUNT", tl) == 0 ) 
  24.108 +    {
  24.109 +        op.u.net_rule.action = NETWORK_ACTION_COUNT;
  24.110 +        goto keyval;
  24.111 +    }
  24.112     
  24.113 -  // default case;
  24.114 -  return (len);
  24.115 +    // default case;
  24.116 +    return (len);
  24.117    
  24.118  
  24.119 -  // get the key=val pairs.
  24.120 +    // get the key=val pairs.
  24.121   keyval:
  24.122 -  while (count)
  24.123 -  {
  24.124 -    //get field
  24.125 -    ts = te; while ( count && isspace(buffer[ts]) ) { ts++; count--; }
  24.126 -    te = ts;
  24.127 -    while ( count && !isspace(buffer[te]) && (buffer[te] != '=') ) 
  24.128 -      { te++; count--; }
  24.129 -    if ( te <= ts )
  24.130 -	goto doneparsing;
  24.131 -    tl = te - ts;
  24.132 -    fs = ts; fe = te; fl = tl; // save the field markers.
  24.133 -    // skip "   =   " (ignores extra equals.)
  24.134 -    while ( count && (isspace(buffer[te]) || (buffer[te] == '=')) ) 
  24.135 -      { te++; count--; }
  24.136 -    ts = te;
  24.137 -    while ( count && !isspace(buffer[te]) ) { te++; count--; }
  24.138 -    tl = te - ts;
  24.139 +    while (count)
  24.140 +    {
  24.141 +        //get field
  24.142 +        ts = te; while ( count && isspace(buffer[ts]) ) { ts++; count--; }
  24.143 +        te = ts;
  24.144 +        while ( count && !isspace(buffer[te]) && (buffer[te] != '=') ) 
  24.145 +        { te++; count--; }
  24.146 +        if ( te <= ts )
  24.147 +            goto doneparsing;
  24.148 +        tl = te - ts;
  24.149 +        fs = ts; fe = te; fl = tl; // save the field markers.
  24.150 +        // skip "   =   " (ignores extra equals.)
  24.151 +        while ( count && (isspace(buffer[te]) || (buffer[te] == '=')) ) 
  24.152 +        { te++; count--; }
  24.153 +        ts = te;
  24.154 +        while ( count && !isspace(buffer[te]) ) { te++; count--; }
  24.155 +        tl = te - ts;
  24.156 +
  24.157 +        if ( (fl <= 0) || (tl <= 0) ) goto bad;
  24.158  
  24.159 -    if ( (fl <= 0) || (tl <= 0) ) goto bad;
  24.160 -
  24.161 -    if (strncmp(&buffer[fs], "srcaddr", fl) == 0) 
  24.162 -    {  
  24.163 -      op.u.net_rule.src_addr = getipaddr(&buffer[ts], tl);
  24.164 -    }
  24.165 -    else if (strncmp(&buffer[fs], "dstaddr", fl) == 0)
  24.166 -    {    
  24.167 -      op.u.net_rule.dst_addr = getipaddr(&buffer[ts], tl);
  24.168 -    }
  24.169 -    else if (strncmp(&buffer[fs], "srcaddrmask", fl) == 0) 
  24.170 -    {
  24.171 -      op.u.net_rule.src_addr_mask = getipaddr(&buffer[ts], tl);
  24.172 -    }
  24.173 -    else if (strncmp(&buffer[fs], "dstaddrmask", fl) == 0)
  24.174 -    {
  24.175 -      op.u.net_rule.dst_addr_mask = getipaddr(&buffer[ts], tl);
  24.176 +        /* NB. Prefix matches must go first! */
  24.177 +        if (strncmp(&buffer[fs], "src", fl) == 0)
  24.178 +        {
  24.179 +            op.u.net_rule.src_vif = VIF_ANY_INTERFACE;
  24.180 +        }
  24.181 +        else if (strncmp(&buffer[fs], "dst", fl) == 0)
  24.182 +        {
  24.183 +            op.u.net_rule.dst_vif = VIF_PHYSICAL_INTERFACE;
  24.184 +        }
  24.185 +        else if (strncmp(&buffer[fs], "srcaddr", fl) == 0) 
  24.186 +        {  
  24.187 +            op.u.net_rule.src_addr = getipaddr(&buffer[ts], tl);
  24.188 +        }
  24.189 +        else if (strncmp(&buffer[fs], "dstaddr", fl) == 0)
  24.190 +        {    
  24.191 +            op.u.net_rule.dst_addr = getipaddr(&buffer[ts], tl);
  24.192 +        }
  24.193 +        else if (strncmp(&buffer[fs], "srcaddrmask", fl) == 0) 
  24.194 +        {
  24.195 +            op.u.net_rule.src_addr_mask = getipaddr(&buffer[ts], tl);
  24.196 +        }
  24.197 +        else if (strncmp(&buffer[fs], "dstaddrmask", fl) == 0)
  24.198 +        {
  24.199 +            op.u.net_rule.dst_addr_mask = getipaddr(&buffer[ts], tl);
  24.200 +        }
  24.201 +        else if (strncmp(&buffer[fs], "srcport", fl) == 0)
  24.202 +        {
  24.203 +            op.u.net_rule.src_port = antous(&buffer[ts], tl);
  24.204 +        }
  24.205 +        else if (strncmp(&buffer[fs], "dstport", fl) == 0)
  24.206 +        {
  24.207 +            op.u.net_rule.dst_port = antous(&buffer[ts], tl);
  24.208 +        }
  24.209 +        else if (strncmp(&buffer[fs], "srcportmask", fl) == 0)
  24.210 +        {
  24.211 +            op.u.net_rule.src_port_mask = antous(&buffer[ts], tl);
  24.212 +        }
  24.213 +        else if (strncmp(&buffer[fs], "dstportmask", fl) == 0)
  24.214 +        {
  24.215 +            op.u.net_rule.dst_port_mask = antous(&buffer[ts], tl);
  24.216 +        }
  24.217 +        else if (strncmp(&buffer[fs], "srcdom", fl) == 0)
  24.218 +        {
  24.219 +            op.u.net_rule.src_vif |= anton(&buffer[ts], tl)<<VIF_DOMAIN_SHIFT;
  24.220 +        }
  24.221 +        else if (strncmp(&buffer[fs], "srcidx", fl) == 0)
  24.222 +        {
  24.223 +            op.u.net_rule.src_vif |= anton(&buffer[ts], tl);
  24.224 +        }
  24.225 +        else if (strncmp(&buffer[fs], "dstdom", fl) == 0)
  24.226 +        {
  24.227 +            op.u.net_rule.dst_vif |= anton(&buffer[ts], tl)<<VIF_DOMAIN_SHIFT;
  24.228 +        }
  24.229 +        else if (strncmp(&buffer[fs], "dstidx", fl) == 0)
  24.230 +        {
  24.231 +            op.u.net_rule.dst_vif |= anton(&buffer[ts], tl);
  24.232 +        }
  24.233 +        else if ( (strncmp(&buffer[fs], "proto", fl) == 0))
  24.234 +        {	
  24.235 +            if (strncmp(&buffer[ts], "any", tl) == 0) 
  24.236 +                op.u.net_rule.proto = NETWORK_PROTO_ANY; 
  24.237 +            if (strncmp(&buffer[ts], "ip", tl) == 0)
  24.238 +                op.u.net_rule.proto = NETWORK_PROTO_IP;
  24.239 +            if (strncmp(&buffer[ts], "tcp", tl) == 0) 
  24.240 +                op.u.net_rule.proto = NETWORK_PROTO_TCP;
  24.241 +            if (strncmp(&buffer[ts], "udp", tl) == 0)
  24.242 +                op.u.net_rule.proto = NETWORK_PROTO_UDP;
  24.243 +            if (strncmp(&buffer[ts], "arp", tl) == 0)
  24.244 +                op.u.net_rule.proto = NETWORK_PROTO_ARP;
  24.245 +        }
  24.246      }
  24.247 -    else if (strncmp(&buffer[fs], "srcport", fl) == 0)
  24.248 -    {
  24.249 -      op.u.net_rule.src_port = antous(&buffer[ts], tl);
  24.250 -    }
  24.251 -    else if (strncmp(&buffer[fs], "dstport", fl) == 0)
  24.252 -    {
  24.253 -      op.u.net_rule.dst_port = antous(&buffer[ts], tl);
  24.254 -    }
  24.255 -    else if (strncmp(&buffer[fs], "srcportmask", fl) == 0)
  24.256 -    {
  24.257 -      op.u.net_rule.src_port_mask = antous(&buffer[ts], tl);
  24.258 -    }
  24.259 -    else if (strncmp(&buffer[fs], "dstportmask", fl) == 0)
  24.260 -    {
  24.261 -      op.u.net_rule.dst_port_mask = antous(&buffer[ts], tl);
  24.262 -    }
  24.263 -    else if (strncmp(&buffer[fs], "srcint", fl) == 0)
  24.264 -    {
  24.265 -      op.u.net_rule.src_interface = anton(&buffer[ts], tl);
  24.266 -    }
  24.267 -    else if (strncmp(&buffer[fs], "dstint", fl) == 0)
  24.268 -    {
  24.269 -      op.u.net_rule.dst_interface = anton(&buffer[ts], tl);
  24.270 -    }
  24.271 -    else if ( (strncmp(&buffer[fs], "proto", fl) == 0))
  24.272 -    {	
  24.273 -      if (strncmp(&buffer[ts], "any", tl) == 0) 
  24.274 -	  op.u.net_rule.proto = NETWORK_PROTO_ANY; 
  24.275 -      if (strncmp(&buffer[ts], "ip", tl) == 0)
  24.276 -	  op.u.net_rule.proto = NETWORK_PROTO_IP;
  24.277 -      if (strncmp(&buffer[ts], "tcp", tl) == 0) 
  24.278 -	  op.u.net_rule.proto = NETWORK_PROTO_TCP;
  24.279 -      if (strncmp(&buffer[ts], "udp", tl) == 0)
  24.280 -	  op.u.net_rule.proto = NETWORK_PROTO_UDP;
  24.281 -      if (strncmp(&buffer[ts], "arp", tl) == 0)
  24.282 -	  op.u.net_rule.proto = NETWORK_PROTO_ARP;
  24.283 -      
  24.284 -    }
  24.285 -  }
  24.286  
  24.287   doneparsing:  
  24.288 -  ret = HYPERVISOR_network_op(&op);
  24.289 -  return(len);
  24.290 +    ret = HYPERVISOR_network_op(&op);
  24.291 +    return(len);
  24.292  
  24.293   bad:
  24.294 -  return(len);
  24.295 +    return(len);
  24.296      
  24.297      
  24.298  }
  24.299 @@ -256,51 +272,50 @@ int anton(const char *buff, int len)
  24.300      
  24.301  u16 antous(const char *buff, int len)
  24.302  {
  24.303 -  u16 ret;
  24.304 -  char c;
  24.305 +    u16 ret;
  24.306 +    char c;
  24.307  
  24.308 -  ret = 0;
  24.309 +    ret = 0;
  24.310  
  24.311 -  while ( (len) && ((c = *buff) >= '0') && (c <= '9') )
  24.312 -  {
  24.313 -    ret *= 10;
  24.314 -    ret += c - '0';
  24.315 -    buff++; len--;
  24.316 -  }
  24.317 +    while ( (len) && ((c = *buff) >= '0') && (c <= '9') )
  24.318 +    {
  24.319 +        ret *= 10;
  24.320 +        ret += c - '0';
  24.321 +        buff++; len--;
  24.322 +    }
  24.323  
  24.324 -  return ret;
  24.325 +    return ret;
  24.326  }
  24.327  
  24.328  u32 getipaddr(const char *buff, unsigned int len)
  24.329  {
  24.330 -  int i; 
  24.331 -  char c;
  24.332 -  u32 ret, val;
  24.333 +    char c;
  24.334 +    u32 ret, val;
  24.335  
  24.336 -  ret = 0; val = 0;
  24.337 +    ret = 0; val = 0;
  24.338  
  24.339 -  while ( len )
  24.340 -  {
  24.341 -    if (!((((c = *buff) >= '0') && ( c <= '9')) || ( c == '.' ) ) ) 
  24.342 +    while ( len )
  24.343      {
  24.344 -      return(0); // malformed.
  24.345 -    }
  24.346 +        if (!((((c = *buff) >= '0') && ( c <= '9')) || ( c == '.' ) ) ) 
  24.347 +        {
  24.348 +            return(0); // malformed.
  24.349 +        }
  24.350  
  24.351 -    if ( c == '.' ) {
  24.352 -      if (val > 255) return (0); //malformed.
  24.353 -      ret = ret << 8; 
  24.354 -      ret += val;
  24.355 -      val = 0;
  24.356 -      len--; buff++;
  24.357 -      continue;
  24.358 +        if ( c == '.' ) {
  24.359 +            if (val > 255) return (0); //malformed.
  24.360 +            ret = ret << 8; 
  24.361 +            ret += val;
  24.362 +            val = 0;
  24.363 +            len--; buff++;
  24.364 +            continue;
  24.365 +        }
  24.366 +        val *= 10;
  24.367 +        val += c - '0';
  24.368 +        buff++; len--;
  24.369      }
  24.370 -    val *= 10;
  24.371 -    val += c - '0';
  24.372 -    buff++; len--;
  24.373 -  }
  24.374 -  ret = ret << 8;
  24.375 -  ret += val;
  24.376 +    ret = ret << 8;
  24.377 +    ret += val;
  24.378  
  24.379 -  return (ret);
  24.380 +    return (ret);
  24.381  }
  24.382