ia64/xen-unstable

changeset 11598:6d7bba6443ef

Update vnet kernel module to handle architectures without
socketcall(), for example Itanium, and some small changes
to be compatible with changed kernel interfaces.

Signed-off-by: Mike Wray <mike.wray@hp.com>
author kfraser@localhost.localdomain
date Sat Sep 23 14:01:53 2006 +0100 (2006-09-23)
parents d913017a5c66
children decde35c6abf
files .hgignore tools/vnet/doc/man/vn.pod.1 tools/vnet/libxutil/Makefile tools/vnet/libxutil/hash_table.c tools/vnet/libxutil/hash_table.h tools/vnet/vnet-module/Makefile.ver tools/vnet/vnet-module/esp.c tools/vnet/vnet-module/etherip.c tools/vnet/vnet-module/tunnel.c tools/vnet/vnet-module/tunnel.h tools/vnet/vnet-module/varp.c tools/vnet/vnet-module/varp_socket.c tools/vnet/vnet-module/vif.c tools/vnet/vnet-module/vnet.c tools/vnet/vnet-module/vnet_dev.c tools/vnet/vnet-module/vnet_eval.c tools/vnet/vnet-module/vnet_forward.c tools/vnet/vnetd/Makefile tools/vnet/vnetd/vnetd.c
line diff
     1.1 --- a/.hgignore	Sat Sep 23 14:00:38 2006 +0100
     1.2 +++ b/.hgignore	Sat Sep 23 14:01:53 2006 +0100
     1.3 @@ -139,12 +139,15 @@
     1.4  ^tools/security/secpol_tool$
     1.5  ^tools/security/xen/.*$
     1.6  ^tools/tests/test_x86_emulator$
     1.7 +^tools/vnet/Make.local$
     1.8 +^tools/vnet/build/.*$
     1.9  ^tools/vnet/gc$
    1.10  ^tools/vnet/gc.*/.*$
    1.11  ^tools/vnet/vnet-module/.*\.ko$
    1.12  ^tools/vnet/vnet-module/\..*\.cmd$
    1.13  ^tools/vnet/vnet-module/\.tmp_versions/.*$
    1.14  ^tools/vnet/vnet-module/vnet_module\.mod\..*$
    1.15 +^tools/vnet/vnetd/vnetd$
    1.16  ^tools/vtpm/tpm_emulator-.*\.tar\.gz$
    1.17  ^tools/vtpm/tpm_emulator/.*$
    1.18  ^tools/vtpm/vtpm/.*$
     2.1 --- a/tools/vnet/doc/man/vn.pod.1	Sat Sep 23 14:00:38 2006 +0100
     2.2 +++ b/tools/vnet/doc/man/vn.pod.1	Sat Sep 23 14:01:53 2006 +0100
     2.3 @@ -105,7 +105,7 @@ the vnet device to it.
     2.4  =item B<-v | --vnetif> I<vnetifname>
     2.5  
     2.6  Use I<vnetifname> as the name for the vnet device. If this option
     2.7 -is not specified the default isto  name the device vnifN where N
     2.8 +is not specified the default is to name the device vnifN where N
     2.9  is the last field of the vnet id as 4 hex characters.
    2.10  For example vnif0004. Network device names can be at
    2.11  most 14 characters.
    2.12 @@ -173,4 +173,4 @@ Copyright (C) 2006 Mike Wray <mike.wray@
    2.13  This library is free software; you can redistribute it and/or modify
    2.14  it under the terms of the GNU Lesser General Public License as published by
    2.15  the Free Software Foundation; either version 2.1 of the License, or
    2.16 -(at your option) any later version.
    2.17 \ No newline at end of file
    2.18 +(at your option) any later version.
     3.1 --- a/tools/vnet/libxutil/Makefile	Sat Sep 23 14:00:38 2006 +0100
     3.2 +++ b/tools/vnet/libxutil/Makefile	Sat Sep 23 14:01:53 2006 +0100
     3.3 @@ -30,6 +30,8 @@ LIB_OBJS := $(LIB_SRCS:.c=.o)
     3.4  PIC_OBJS := $(LIB_SRCS:.c=.opic)
     3.5  
     3.6  CFLAGS   += -Werror -fno-strict-aliasing
     3.7 +CFLAGS   += -O3
     3.8 +#CFLAGS   += -g
     3.9  
    3.10  # Get gcc to generate the dependencies for us.
    3.11  CFLAGS   += -Wp,-MD,.$(@F).d
     4.1 --- a/tools/vnet/libxutil/hash_table.c	Sat Sep 23 14:00:38 2006 +0100
     4.2 +++ b/tools/vnet/libxutil/hash_table.c	Sat Sep 23 14:01:53 2006 +0100
     4.3 @@ -116,7 +116,7 @@ acceptable.  Do NOT use for cryptographi
     4.4  --------------------------------------------------------------------
     4.5  */
     4.6  
     4.7 -ub4 hash(const ub1 *k, ub4 length, ub4 initval)
     4.8 +static inline ub4 _hash(const ub1 *k, ub4 length, ub4 initval)
     4.9  //register ub1 *k;        /* the key */
    4.10  //register ub4  length;   /* the length of the key */
    4.11  //register ub4  initval;    /* the previous hash, or an arbitrary value */
    4.12 @@ -160,6 +160,11 @@ ub4 hash(const ub1 *k, ub4 length, ub4 i
    4.13     /*-------------------------------------------- report the result */
    4.14     return c;
    4.15  }
    4.16 +
    4.17 +ub4 hash(const ub1 *k, ub4 length, ub4 initval){
    4.18 +    return _hash(k, length, initval);
    4.19 +}
    4.20 +
    4.21  /*============================================================================*/
    4.22  
    4.23  /** Get the bucket for a hashcode in a hash table.
    4.24 @@ -381,6 +386,9 @@ inline HTEntry * HashTable_find_entry(Ha
    4.25   * @return 1 if equal, 0 otherwise
    4.26   */
    4.27  inline int HashTable_key_equal(HashTable *table, void *key1, void *key2){
    4.28 +    if(table->key_size){
    4.29 +        return memcmp(key1, key2, table->key_size) == 0;
    4.30 +    }
    4.31      return (table->key_equal_fn ? table->key_equal_fn(key1, key2) : key1 == key2);
    4.32  }
    4.33  
    4.34 @@ -393,6 +401,9 @@ inline int HashTable_key_equal(HashTable
    4.35   * @return hashcode
    4.36   */
    4.37  inline Hashcode HashTable_key_hash(HashTable *table, void *key){
    4.38 +    if(table->key_size){
    4.39 +        return _hash(key, table->key_size, 0);
    4.40 +    }
    4.41      return (table->key_hash_fn 
    4.42              ? table->key_hash_fn(key)
    4.43              : hash_hvoid(0, &key, sizeof(key)));
     5.1 --- a/tools/vnet/libxutil/hash_table.h	Sat Sep 23 14:00:38 2006 +0100
     5.2 +++ b/tools/vnet/libxutil/hash_table.h	Sat Sep 23 14:01:53 2006 +0100
     5.3 @@ -96,6 +96,7 @@ struct HashTable {
     5.4      int buckets_n;
     5.5      /** Number of entries in the table. */
     5.6      int entry_count;
     5.7 +    unsigned long key_size;
     5.8      /** Function to free keys and values in entries. */
     5.9      TableFreeFn *entry_free_fn;
    5.10      /** Function to hash keys. */
     6.1 --- a/tools/vnet/vnet-module/Makefile.ver	Sat Sep 23 14:00:38 2006 +0100
     6.2 +++ b/tools/vnet/vnet-module/Makefile.ver	Sat Sep 23 14:01:53 2006 +0100
     6.3 @@ -18,27 +18,32 @@
     6.4  # 59 Temple Place, suite 330, Boston, MA 02111-1307 USA
     6.5  #============================================================================
     6.6  
     6.7 -LINUX_SERIES ?=2.6
     6.8 -KERNEL_MINOR ?=-xen0
     6.9 +LINUX_SERIES?=2.6
    6.10 +KERNEL_MINOR=-xen
    6.11  
    6.12 -LINUX_VERSION ?= $(shell (/bin/ls -ld $(XEN_ROOT)/pristine-linux-$(LINUX_SERIES).* 2>/dev/null) | \
    6.13 +LINUX_VERSION?=$(shell (/bin/ls -d $(XEN_ROOT)/pristine-linux-$(LINUX_SERIES).* 2>/dev/null) | \
    6.14                        sed -e 's!^.*linux-\(.\+\)!\1!' )
    6.15  
    6.16  ifeq ($(LINUX_VERSION),)
    6.17  $(error Kernel source for linux $(LINUX_SERIES) not found)
    6.18  endif
    6.19  
    6.20 -KERNEL_VERSION =$(LINUX_VERSION)$(KERNEL_MINOR)
    6.21 +KERNEL_VERSION=$(LINUX_VERSION)$(KERNEL_MINOR)
    6.22  
    6.23 -KERNEL_SRC ?= $(XEN_ROOT)/linux-$(KERNEL_VERSION)
    6.24 +KERNEL_SRC?=$(shell cd $(XEN_ROOT)/linux-$(KERNEL_VERSION) && pwd)
    6.25 +
    6.26 +ifeq ($(KERNEL_SRC),)
    6.27 +$(error Kernel source for kernel $(KERNEL_VERSION) not found)
    6.28 +endif
    6.29  
    6.30  # Get the full kernel release version from its makefile, as the source path
    6.31  # may not have the extraversion, e.g. linux-2.6.12-xen0 may contain release 2.6.12.6-xen0.
    6.32 -KERNEL_RELEASE = $(shell make -s -C $(KERNEL_SRC) kernelrelease || \
    6.33 -	make -f $(shell pwd)/Makefile.kver -s -C $(KERNEL_SRC) kernelrelease )
    6.34 +KERNEL_RELEASE=$(shell make -s -C $(KERNEL_SRC) kernelrelease)
    6.35  
    6.36 -KERNEL_MODULE_DIR = /lib/modules/$(KERNEL_RELEASE)/kernel
    6.37 +KERNEL_MODULE_DIR=/lib/modules/$$(KERNEL_RELEASE)/kernel
    6.38  
    6.39 -$(warning KERNEL_SRC     $(KERNEL_SRC))
    6.40 -#$(warning KERNEL_VERSION $(KERNEL_VERSION))
    6.41 -$(warning KERNEL_RELEASE $(KERNEL_RELEASE))
    6.42 +$(warning KERNEL_SRC		$(KERNEL_SRC))
    6.43 +$(warning LINUX_VERSION		$(LINUX_VERSION))
    6.44 +$(warning KERNEL_VERSION	$(KERNEL_VERSION))
    6.45 +$(warning KERNEL_RELEASE	$(KERNEL_RELEASE))
    6.46 +$(warning KERNEL_ MODULE_DIR	$(KERNEL_MODULE_DIR))
     7.1 --- a/tools/vnet/vnet-module/esp.c	Sat Sep 23 14:00:38 2006 +0100
     7.2 +++ b/tools/vnet/vnet-module/esp.c	Sat Sep 23 14:01:53 2006 +0100
     7.3 @@ -104,7 +104,7 @@ void __exit esp_module_exit(void){
     7.4   * @param block size to round to a multiple of
     7.5   * @return rounded value
     7.6   */
     7.7 -static inline int roundup(int n, int block){
     7.8 +static inline int roundupto(int n, int block){
     7.9      if(block <= 1) return n;
    7.10      block--;
    7.11      return (n + block) & ~block;
    7.12 @@ -312,9 +312,9 @@ static int esp_sa_send(SAState *sa, stru
    7.13      // header and IP header.
    7.14      plaintext_n = skb->len - ETH_HLEN - ip_n;
    7.15      // Add size of padding fields.
    7.16 -    ciphertext_n = roundup(plaintext_n + ESP_PAD_N, esp->cipher.block_n);
    7.17 +    ciphertext_n = roundupto(plaintext_n + ESP_PAD_N, esp->cipher.block_n);
    7.18      if(esp->cipher.pad_n > 0){
    7.19 -        ciphertext_n = roundup(ciphertext_n, esp->cipher.pad_n);
    7.20 +        ciphertext_n = roundupto(ciphertext_n, esp->cipher.pad_n);
    7.21      }
    7.22      extra_n = ciphertext_n - plaintext_n;
    7.23      iv_n = esp->cipher.iv_n;
    7.24 @@ -502,9 +502,9 @@ static u32 esp_sa_size(SAState *sa, int 
    7.25      // Have to add some padding for alignment even if pad_n is zero.
    7.26      ESPState *esp = sa->data;
    7.27      
    7.28 -    data_n = roundup(data_n + ESP_PAD_N, esp->cipher.block_n);
    7.29 +    data_n = roundupto(data_n + ESP_PAD_N, esp->cipher.block_n);
    7.30      if(esp->cipher.pad_n > 0){
    7.31 -        data_n = roundup(data_n, esp->cipher.pad_n);
    7.32 +        data_n = roundupto(data_n, esp->cipher.pad_n);
    7.33      }
    7.34      data_n += esp->digest.icv_n;
    7.35      //data_n += esp->cipher.iv_n;
    7.36 @@ -607,7 +607,7 @@ static int esp_cipher_init(SAState *sa, 
    7.37          err = -EINVAL;
    7.38          goto exit;
    7.39      }
    7.40 -    esp->cipher.key_n = roundup(sa->cipher.bits, 8);
    7.41 +    esp->cipher.key_n = roundupto(sa->cipher.bits, 8);
    7.42      // If cipher is null must use ECB because CBC algo does not support blocksize 1.
    7.43      if(strcmp(sa->cipher.name, "cipher_null")){
    7.44          cipher_mode = CRYPTO_TFM_MODE_ECB;
    7.45 @@ -617,7 +617,7 @@ static int esp_cipher_init(SAState *sa, 
    7.46          err = -ENOMEM;
    7.47          goto exit;
    7.48      }
    7.49 -    esp->cipher.block_n = roundup(crypto_tfm_alg_blocksize(esp->cipher.tfm), 4);
    7.50 +    esp->cipher.block_n = roundupto(crypto_tfm_alg_blocksize(esp->cipher.tfm), 4);
    7.51      esp->cipher.iv_n = crypto_tfm_alg_ivsize(esp->cipher.tfm);
    7.52      esp->cipher.pad_n = 0;
    7.53      if(esp->cipher.iv_n){
    7.54 @@ -643,7 +643,7 @@ static int esp_digest_init(SAState *sa, 
    7.55      
    7.56      dprintf(">\n");
    7.57      esp->digest.key = sa->digest.key;
    7.58 -    esp->digest.key_n = bits_to_bytes(roundup(sa->digest.bits, 8));
    7.59 +    esp->digest.key_n = bits_to_bytes(roundupto(sa->digest.bits, 8));
    7.60      esp->digest.tfm = crypto_alloc_tfm(sa->digest.name, 0);
    7.61      if(!esp->digest.tfm){
    7.62          err = -ENOMEM;
     8.1 --- a/tools/vnet/vnet-module/etherip.c	Sat Sep 23 14:00:38 2006 +0100
     8.2 +++ b/tools/vnet/vnet-module/etherip.c	Sat Sep 23 14:01:53 2006 +0100
     8.3 @@ -128,9 +128,27 @@ static void etherip_tunnel_close(Tunnel 
     8.4  }
     8.5  
     8.6  
     8.7 +static inline int skb_make_headroom(struct sk_buff **pskb, struct sk_buff *skb, int head_n){
     8.8 +    int err = 0;
     8.9 +    dprintf("> skb=%p headroom=%d head_n=%d\n", skb, skb_headroom(skb), head_n);
    8.10 +    if(head_n > skb_headroom(skb) || skb_cloned(skb) || skb_shared(skb)){
    8.11 +        // Expand header the way GRE does.
    8.12 +        struct sk_buff *new_skb = skb_realloc_headroom(skb, head_n + 16);
    8.13 +        if(!new_skb){
    8.14 +            err = -ENOMEM;
    8.15 +            goto exit;
    8.16 +        }
    8.17 +        kfree_skb(skb);
    8.18 +        *pskb = new_skb;
    8.19 +    } else {
    8.20 +        *pskb = skb;
    8.21 +    }
    8.22 +  exit:
    8.23 +    return err;
    8.24 +}
    8.25 +    
    8.26  /** Send a packet via an etherip tunnel.
    8.27 - * Adds etherip header, new ip header, new ethernet header around
    8.28 - * ethernet frame.
    8.29 + * Adds etherip header and new ip header around ethernet frame.
    8.30   *
    8.31   * @param tunnel tunnel
    8.32   * @param skb packet
    8.33 @@ -150,7 +168,7 @@ static int etherip_tunnel_send(Tunnel *t
    8.34      if(etherip_in_udp){
    8.35          head_n += vnet_n + udp_n;
    8.36      }
    8.37 -    err = skb_make_room(&skb, skb, head_n, 0);
    8.38 +    err = skb_make_headroom(&skb, skb, head_n);
    8.39      if(err) goto exit;
    8.40  
    8.41      // Null the pointer as we are pushing a new IP header.
    8.42 @@ -219,6 +237,20 @@ int etherip_tunnel_create(VnetId *vnet, 
    8.43      return Tunnel_create(etherip_tunnel_type, vnet, addr, base, tunnel);
    8.44  }
    8.45  
    8.46 +#if defined(__KERNEL__) && defined(CONFIG_BRIDGE_NETFILTER)
    8.47 +/** We need our own copy of this as it is no longer exported from the bridge module.
    8.48 + */
    8.49 +static inline void _nf_bridge_save_header(struct sk_buff *skb){
    8.50 +    int header_size = 16;
    8.51 +    
    8.52 +    // Were using this modified to use h_proto instead of skb->protocol.
    8.53 +    if(skb->protocol == htons(ETH_P_8021Q)){
    8.54 +        header_size = 18;
    8.55 +    }
    8.56 +    memcpy(skb->nf_bridge->data, skb->data - header_size, header_size);
    8.57 +}
    8.58 +#endif
    8.59 +
    8.60  /** Do etherip receive processing.
    8.61   * Strips the etherip header to extract the ethernet frame, sets
    8.62   * the vnet from the header and re-receives the frame.
    8.63 @@ -320,10 +352,9 @@ int etherip_protocol_recv(struct sk_buff
    8.64      skb->dst = NULL;
    8.65      nf_reset(skb);
    8.66  #ifdef CONFIG_BRIDGE_NETFILTER
    8.67 -    // Stop the eth header being clobbered by nf_bridge_maybe_copy_header().
    8.68 -    // Were using this modified to use h_proto instead of skb->protocol.
    8.69      if(skb->nf_bridge){
    8.70 -        nf_bridge_save_header(skb);
    8.71 +        // Stop the eth header being clobbered by nf_bridge_maybe_copy_header().
    8.72 +        _nf_bridge_save_header(skb);
    8.73      }
    8.74  #endif
    8.75  #endif // __KERNEL__
     9.1 --- a/tools/vnet/vnet-module/tunnel.c	Sat Sep 23 14:00:38 2006 +0100
     9.2 +++ b/tools/vnet/vnet-module/tunnel.c	Sat Sep 23 14:01:53 2006 +0100
     9.3 @@ -51,6 +51,12 @@ rwlock_t tunnel_table_lock = RW_LOCK_UNL
     9.4  #define tunnel_write_lock(flags)   write_lock_irqsave(&tunnel_table_lock, (flags))
     9.5  #define tunnel_write_unlock(flags) write_unlock_irqrestore(&tunnel_table_lock, (flags))
     9.6  
     9.7 +void Tunnel_free(Tunnel *tunnel){
     9.8 +    tunnel->type->close(tunnel);
     9.9 +    Tunnel_decref(tunnel->base);
    9.10 +    kfree(tunnel);
    9.11 +}
    9.12 +
    9.13  void Tunnel_print(Tunnel *tunnel){
    9.14      if(tunnel){
    9.15          iprintf("Tunnel<%p base=%p ref=%02d type=%s>\n",
    9.16 @@ -136,6 +142,7 @@ int Tunnel_init(void){
    9.17          goto exit;
    9.18      }
    9.19      tunnel_table->entry_free_fn = tunnel_table_entry_free_fn;
    9.20 +    tunnel_table->key_size = sizeof(TunnelKey);
    9.21      tunnel_table->key_hash_fn = tunnel_table_key_hash_fn;
    9.22      tunnel_table->key_equal_fn = tunnel_table_key_equal_fn;
    9.23    exit:
    10.1 --- a/tools/vnet/vnet-module/tunnel.h	Sat Sep 23 14:00:38 2006 +0100
    10.2 +++ b/tools/vnet/vnet-module/tunnel.h	Sat Sep 23 14:01:53 2006 +0100
    10.3 @@ -70,6 +70,8 @@ typedef struct Tunnel {
    10.4      struct Tunnel *base;
    10.5  } Tunnel;
    10.6  
    10.7 +extern void Tunnel_free(struct Tunnel *tunnel);
    10.8 +
    10.9  /** Decrement the reference count, freeing if zero.
   10.10   *
   10.11   * @param tunnel tunnel (may be null)
   10.12 @@ -77,9 +79,7 @@ typedef struct Tunnel {
   10.13  static inline void Tunnel_decref(struct Tunnel *tunnel){
   10.14      if(!tunnel) return;
   10.15      if(atomic_dec_and_test(&tunnel->refcount)){
   10.16 -        tunnel->type->close(tunnel);
   10.17 -        Tunnel_decref(tunnel->base);
   10.18 -        kfree(tunnel);
   10.19 +        Tunnel_free(tunnel);
   10.20      }
   10.21  }
   10.22  
   10.23 @@ -87,7 +87,7 @@ static inline void Tunnel_decref(struct 
   10.24   *
   10.25   * @param tunnel tunnel (may be null)
   10.26   */
   10.27 -static inline void Tunnel_incref(Tunnel *tunnel){
   10.28 +static inline void Tunnel_incref(struct Tunnel *tunnel){
   10.29      if(!tunnel) return;
   10.30      atomic_inc(&tunnel->refcount);
   10.31  }
    11.1 --- a/tools/vnet/vnet-module/varp.c	Sat Sep 23 14:00:38 2006 +0100
    11.2 +++ b/tools/vnet/vnet-module/varp.c	Sat Sep 23 14:01:53 2006 +0100
    11.3 @@ -849,6 +849,7 @@ VarpTable * VarpTable_new(void){
    11.4      if(!vtable) goto exit;
    11.5      vtable->table = HashTable_new(VARP_TABLE_BUCKETS);
    11.6      if(!vtable->table) goto exit;
    11.7 +    vtable->table->key_size = sizeof(VarpKey);
    11.8      vtable->table->key_equal_fn = varp_key_equal_fn;
    11.9      vtable->table->key_hash_fn = varp_key_hash_fn;
   11.10      vtable->table->entry_free_fn = varp_entry_free_fn;
   11.11 @@ -1529,8 +1530,12 @@ void varp_exit(void){
   11.12      dprintf("<\n");
   11.13  }
   11.14  
   11.15 +#ifdef MODULE_PARM
   11.16  MODULE_PARM(varp_mcaddr, "s");
   11.17 +MODULE_PARM(varp_device, "s");
   11.18 +#else
   11.19 +module_param(varp_mcaddr, charp, 0644);
   11.20 +module_param(varp_device, charp, 0644);
   11.21 +#endif
   11.22  MODULE_PARM_DESC(varp_mcaddr, "VARP multicast address");
   11.23 -
   11.24 -MODULE_PARM(varp_device, "s");
   11.25  MODULE_PARM_DESC(varp_device, "VARP network device");
    12.1 --- a/tools/vnet/vnet-module/varp_socket.c	Sat Sep 23 14:00:38 2006 +0100
    12.2 +++ b/tools/vnet/vnet-module/varp_socket.c	Sat Sep 23 14:01:53 2006 +0100
    12.3 @@ -1,5 +1,5 @@
    12.4  /*
    12.5 - * Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
    12.6 + * Copyright (C) 2004, 2005, 2006 Mike Wray <mike.wray@hp.com>
    12.7   *
    12.8   * This program is free software; you can redistribute it and/or modify
    12.9   * it under the terms of the GNU General Public License as published by the 
   12.10 @@ -36,7 +36,7 @@
   12.11  
   12.12  /* Get macros needed to define system calls as functions in the kernel. */
   12.13  #define __KERNEL_SYSCALLS__
   12.14 -static int errno;
   12.15 +int errno=0;
   12.16  #include <linux/unistd.h>
   12.17  
   12.18  #define MODULE_NAME "VARP"
   12.19 @@ -73,8 +73,14 @@ static inline _syscall3(int, fcntl,
   12.20  
   12.21  /* Replicate the user-space socket API.
   12.22   * The parts we need anyway.
   12.23 + *
   12.24 + * Some architectures use socketcall() to multiplex the socket-related calls,
   12.25 + * but others define individual syscalls instead.
   12.26 + * Architectures using socketcall() define __ARCH_WANT_SYS_SOCKETCALL.
   12.27   */
   12.28  
   12.29 +#ifdef __ARCH_WANT_SYS_SOCKETCALL
   12.30 +
   12.31  /* Define the socketcall() syscall.
   12.32   * Multiplexes all the socket-related calls.
   12.33   *
   12.34 @@ -180,6 +186,66 @@ int getsockname(int fd, struct sockaddr 
   12.35      return socketcall(SYS_GETSOCKNAME, args);
   12.36  }
   12.37  
   12.38 +#else /* !__ARCH_WANT_SYS_SOCKETCALL */
   12.39 +
   12.40 +/* No socketcall - define the individual syscalls. */
   12.41 +
   12.42 +static inline _syscall3(int, socket,
   12.43 +                        int, family,
   12.44 +                        int, type,
   12.45 +                        int, protocol);
   12.46 +
   12.47 +static inline _syscall3(int, bind,
   12.48 +                        int, fd,
   12.49 +                        struct sockaddr *, umyaddr,
   12.50 +                        int, addrlen);
   12.51 +
   12.52 +static inline _syscall3(int, connect,
   12.53 +                        int, fd,
   12.54 +                        struct sockaddr *, uservaddr,
   12.55 +                        int, addrlen);
   12.56 +
   12.57 +static inline _syscall6(int, sendto,
   12.58 +                        int, fd,
   12.59 +                        void *, buff,
   12.60 +                        size_t, len,
   12.61 +                        unsigned, flags,
   12.62 +                        struct sockaddr *, addr,
   12.63 +                        int, addr_len);
   12.64 +
   12.65 +static inline _syscall6(int, recvfrom,
   12.66 +                        int, fd,
   12.67 +                        void *, ubuf,
   12.68 +                        size_t, size,
   12.69 +                        unsigned, flags,
   12.70 +                        struct sockaddr *, addr,
   12.71 +                        int *, addr_len);
   12.72 +
   12.73 +static inline _syscall5(int, setsockopt,
   12.74 +                        int, fd,
   12.75 +                        int, level,
   12.76 +                        int, optname,
   12.77 +                        void *, optval,
   12.78 +                        int, optlen);
   12.79 +
   12.80 +static inline _syscall5(int, getsockopt,
   12.81 +                        int, fd,
   12.82 +                        int, level,
   12.83 +                        int, optname,
   12.84 +                        void *, optval,
   12.85 +                        int *, optlen);
   12.86 +
   12.87 +static inline _syscall2(int, shutdown,
   12.88 +                        int, fd,
   12.89 +                        int, how);
   12.90 +
   12.91 +static inline _syscall3(int, getsockname,
   12.92 +                        int, fd,
   12.93 +                        struct sockaddr *, usockaddr,
   12.94 +                        int *, usockaddr_len);
   12.95 +
   12.96 +#endif /* __ARCH_WANT_SYS_SOCKETCALL */
   12.97 +
   12.98  /*============================================================================*/
   12.99  /** Socket flags. */
  12.100  enum VsockFlag {
  12.101 @@ -418,9 +484,7 @@ int varp_ucast_open(uint32_t addr, u16 p
  12.102   * an error.
  12.103   */
  12.104  static int handle_varp_skb(struct sk_buff *skb){
  12.105 -    static int count = 0;
  12.106      int err = 0;
  12.107 -    count++;
  12.108      switch(skb->pkt_type){
  12.109      case PACKET_BROADCAST:
  12.110      case PACKET_MULTICAST:
    13.1 --- a/tools/vnet/vnet-module/vif.c	Sat Sep 23 14:00:38 2006 +0100
    13.2 +++ b/tools/vnet/vnet-module/vif.c	Sat Sep 23 14:01:53 2006 +0100
    13.3 @@ -366,6 +366,7 @@ int vif_init(void){
    13.4          goto exit;
    13.5      }
    13.6      vif_table->entry_free_fn = vif_entry_free_fn;
    13.7 +    vif_table->key_size = sizeof(VifKey);
    13.8      vif_table->key_hash_fn   = vif_key_hash_fn;
    13.9      vif_table->key_equal_fn  = vif_key_equal_fn;
   13.10  
    14.1 --- a/tools/vnet/vnet-module/vnet.c	Sat Sep 23 14:00:38 2006 +0100
    14.2 +++ b/tools/vnet/vnet-module/vnet.c	Sat Sep 23 14:01:53 2006 +0100
    14.3 @@ -318,6 +318,7 @@ int vnet_table_init(void){
    14.4          err = -ENOMEM;
    14.5          goto exit;
    14.6      }
    14.7 +    vnet_table->key_size = sizeof(VnetId);
    14.8      vnet_table->key_equal_fn = vnet_key_equal_fn;
    14.9      vnet_table->key_hash_fn = vnet_key_hash_fn;
   14.10      vnet_table->entry_free_fn = vnet_entry_free_fn;
   14.11 @@ -431,14 +432,14 @@ inline int _skb_xmit(struct sk_buff *skb
   14.12  
   14.13      ip_send_check(skb->nh.iph);
   14.14  
   14.15 -    if(1){
   14.16 +#if 1
   14.17          // Output to skb destination. Will use ip_output(), which fragments.
   14.18          // Slightly slower than neigh_compat_output() (marginal - 1%).
   14.19          err = dst_output(skb); 
   14.20 -    } else {
   14.21 +#else
   14.22          // Sends direct to device via dev_queue_xmit(). No fragmentation?
   14.23          err = neigh_compat_output(skb);
   14.24 -    }
   14.25 +#endif
   14.26  
   14.27  #if 0
   14.28      if(needs_frags){
   14.29 @@ -447,6 +448,7 @@ inline int _skb_xmit(struct sk_buff *skb
   14.30          err = ip_finish_output(skb);
   14.31      }
   14.32  #endif
   14.33 +
   14.34    exit:
   14.35      dprintf("< err=%d\n", err);
   14.36      return err;
   14.37 @@ -691,7 +693,12 @@ module_init(vnet_module_init);
   14.38  module_exit(vnet_module_exit);
   14.39  MODULE_LICENSE("GPL");
   14.40  
   14.41 +#ifdef MODULE_PARM
   14.42  MODULE_PARM(vnet_encaps, "s");
   14.43 +#else
   14.44 +module_param(vnet_encaps, charp, 0644);
   14.45 +#endif
   14.46 +
   14.47  MODULE_PARM_DESC(vnet_encaps, "Vnet encapsulation: etherip or udp.");
   14.48  
   14.49  #endif
    15.1 --- a/tools/vnet/vnet-module/vnet_dev.c	Sat Sep 23 14:00:38 2006 +0100
    15.2 +++ b/tools/vnet/vnet-module/vnet_dev.c	Sat Sep 23 14:01:53 2006 +0100
    15.3 @@ -49,8 +49,12 @@
    15.4  #undef DEBUG
    15.5  #include "debug.h"
    15.6  
    15.7 -#ifndef CONFIG_BRIDGE
    15.8 -#warning Should configure ethernet bridging in kernel Network Options
    15.9 +#if !defined(CONFIG_BRIDGE) && !defined(CONFIG_BRIDGE_MODULE)
   15.10 +#warning Should configure Ethernet Bridging in kernel Network Options
   15.11 +#endif
   15.12 +
   15.13 +#ifndef CONFIG_BRIDGE_NETFILTER
   15.14 +#warning Should configure CONFIG_BRIDGE_NETFILTER in kernel
   15.15  #endif
   15.16  
   15.17  static void vnet_dev_destructor(struct net_device *dev){
   15.18 @@ -254,7 +258,7 @@ static int vnet_dev_setup(Vnet *vnet, st
   15.19      return err;
   15.20  }
   15.21  
   15.22 -static inline int roundup(int n, int k){
   15.23 +static inline int roundupto(int n, int k){
   15.24      return k * ((n + k - 1) / k);
   15.25  }
   15.26  
   15.27 @@ -275,7 +279,7 @@ int vnet_dev_add(Vnet *vnet){
   15.28          vnet->header_n += sizeof(struct VnetMsgHdr);
   15.29          vnet->header_n += sizeof(struct udphdr);
   15.30      }
   15.31 -    vnet->header_n = roundup(vnet->header_n, 4);
   15.32 +    vnet->header_n = roundupto(vnet->header_n, 4);
   15.33      dev = alloc_netdev(0, vnet->device, vnet_dev_init);
   15.34      if(!dev){
   15.35          err = -ENOMEM;
    16.1 --- a/tools/vnet/vnet-module/vnet_eval.c	Sat Sep 23 14:00:38 2006 +0100
    16.2 +++ b/tools/vnet/vnet-module/vnet_eval.c	Sat Sep 23 14:01:53 2006 +0100
    16.3 @@ -188,7 +188,7 @@ int eval_vnet_add(Sxpr exp, IOStream *ou
    16.4      if(err) goto exit;
    16.5      child_string(exp, ovnetif, &device);
    16.6      if(!device){
    16.7 -        snprintf(dev, IFNAMSIZ-1, "vnif%04x", ntohs(vnet.u.vnet16[7]));
    16.8 +        snprintf(dev, IFNAMSIZ-1, "vnif%04x", ntohs(vnet.u.vnet16[VNETID_SIZE16 - 1]));
    16.9          device = dev;
   16.10      }
   16.11      csecurity = sxpr_child_value(exp, osecurity, intern("none"));
    17.1 --- a/tools/vnet/vnet-module/vnet_forward.c	Sat Sep 23 14:00:38 2006 +0100
    17.2 +++ b/tools/vnet/vnet-module/vnet_forward.c	Sat Sep 23 14:01:53 2006 +0100
    17.3 @@ -370,6 +370,7 @@ int vnet_forward_init(void){
    17.4          err = -ENOMEM;
    17.5          goto exit;
    17.6      }
    17.7 +    vnet_peer_table->key_size = sizeof(struct VarpAddr);
    17.8      vnet_peer_table->key_equal_fn = peer_key_equal_fn;
    17.9      vnet_peer_table->key_hash_fn = peer_key_hash_fn;
   17.10      vnet_peer_table->entry_free_fn = peer_entry_free_fn;
    18.1 --- a/tools/vnet/vnetd/Makefile	Sat Sep 23 14:00:38 2006 +0100
    18.2 +++ b/tools/vnet/vnetd/Makefile	Sat Sep 23 14:01:53 2006 +0100
    18.3 @@ -24,7 +24,8 @@ all: vnetd
    18.4  
    18.5  #----------------------------------------------------------------------------
    18.6  
    18.7 -include $(XEN_ROOT)/tools/Rules.mk
    18.8 +# Comment out when outside xen.
    18.9 +#include $(XEN_ROOT)/tools/Rules.mk
   18.10  
   18.11  VNETD_INSTALL_DIR = /usr/sbin
   18.12  
   18.13 @@ -43,6 +44,7 @@ CPPFLAGS += -D USE_GC
   18.14  CPPFLAGS += -D __ARCH_I386_ATOMIC__
   18.15  
   18.16  #----------------------------------------------------------------------------
   18.17 +CFLAGS += -O3
   18.18  CFLAGS += $(INCLUDES) $(LIBS)
   18.19  
   18.20  LDFLAGS += $(LIBS)
    19.1 --- a/tools/vnet/vnetd/vnetd.c	Sat Sep 23 14:00:38 2006 +0100
    19.2 +++ b/tools/vnet/vnetd/vnetd.c	Sat Sep 23 14:01:53 2006 +0100
    19.3 @@ -196,7 +196,7 @@ int vnet_dev_add(struct Vnet *vnet){
    19.4      if(err){
    19.5          wprintf("> Unable to open tap device.\n"
    19.6                  "The tun module must be loaded and\n"
    19.7 -                "the vnet kernel module must not be loaded.");
    19.8 +                "the vnet kernel module must not be loaded.\n");
    19.9          deallocate(dev);
   19.10          goto exit;
   19.11      }
   19.12 @@ -764,7 +764,7 @@ static int vnetd_getopts(Vnetd *vnetd, i
   19.13   *
   19.14   * @param vnetd vnetd
   19.15   */
   19.16 -int vnetd_init(Vnetd *vnetd, int argc, char *argv[]){
   19.17 +static int vnetd_init(Vnetd *vnetd, int argc, char *argv[]){
   19.18      int err = 0;
   19.19  
   19.20      // Use etherip-in-udp encapsulation.
   19.21 @@ -791,7 +791,7 @@ int vnetd_init(Vnetd *vnetd, int argc, c
   19.22      return err;
   19.23  }
   19.24  
   19.25 -void vnet_select(Vnetd *vnetd, SelectSet *set){
   19.26 +static void vnet_select(Vnetd *vnetd, SelectSet *set){
   19.27      HashTable_for_decl(entry);
   19.28  
   19.29      HashTable_for_each(entry, vnetd->vnet_table){
   19.30 @@ -803,7 +803,7 @@ void vnet_select(Vnetd *vnetd, SelectSet
   19.31      }
   19.32  }
   19.33  
   19.34 -void vnet_handle(Vnetd *vnetd, SelectSet *set){
   19.35 +static void vnet_handle(Vnetd *vnetd, SelectSet *set){
   19.36      HashTable_for_decl(entry);
   19.37  
   19.38      HashTable_for_each(entry, vnetd->vnet_table){
   19.39 @@ -820,7 +820,7 @@ void vnet_handle(Vnetd *vnetd, SelectSet
   19.40      }
   19.41  }
   19.42  
   19.43 -int vnetd_handle_udp(Vnetd *vnetd, struct sockaddr_in *addr, int sock){
   19.44 +static int vnetd_handle_udp(Vnetd *vnetd, struct sockaddr_in *addr, int sock){
   19.45      int err = 0, n = 0;
   19.46      struct sockaddr_in peer, dest;
   19.47      socklen_t peer_n = sizeof(peer), dest_n = sizeof(dest);
   19.48 @@ -851,7 +851,7 @@ int vnetd_handle_udp(Vnetd *vnetd, struc
   19.49      return err;
   19.50  }
   19.51  
   19.52 -int vnetd_handle_etherip(Vnetd *vnetd, struct sockaddr_in *addr, int sock){
   19.53 +static int vnetd_handle_etherip(Vnetd *vnetd, struct sockaddr_in *addr, int sock){
   19.54      int err = 0, n = 0;
   19.55      struct sockaddr_in peer, dest;
   19.56      socklen_t peer_n = sizeof(peer), dest_n = sizeof(dest);
   19.57 @@ -883,7 +883,7 @@ typedef struct ConnClient {
   19.58      Parser *parser;
   19.59  } ConnClient;
   19.60  
   19.61 -int conn_handle_fn(Conn *conn, int mode){
   19.62 +static int conn_handle_fn(Conn *conn, int mode){
   19.63      int err;
   19.64      ConnClient *client = conn->data;
   19.65      char data[1024] = {};
   19.66 @@ -923,12 +923,12 @@ int conn_handle_fn(Conn *conn, int mode)
   19.67      return (err < 0 ? err : 0);
   19.68  }
   19.69  
   19.70 -int vnetd_handle_unix(Vnetd *vnetd, int sock){
   19.71 +static int vnetd_handle_unix(Vnetd *vnetd, int sock){
   19.72      int err;
   19.73      ConnClient *client = NULL;
   19.74      Conn *conn = NULL;
   19.75      struct sockaddr_un peer = {};
   19.76 -    int peer_n = sizeof(peer);
   19.77 +    socklen_t peer_n = sizeof(peer);
   19.78      int peersock;
   19.79  
   19.80      peersock = accept(sock, (struct sockaddr *)&peer, &peer_n);
   19.81 @@ -956,7 +956,7 @@ int vnetd_handle_unix(Vnetd *vnetd, int 
   19.82      return err;
   19.83  }
   19.84  
   19.85 -void vnetd_select(Vnetd *vnetd, SelectSet *set){
   19.86 +static void vnetd_select(Vnetd *vnetd, SelectSet *set){
   19.87      SelectSet_add(set, vnetd->unix_sock, SELECT_READ);
   19.88      SelectSet_add(set, vnetd->udp_sock, SELECT_READ);
   19.89      SelectSet_add(set, vnetd->mcast_sock, SELECT_READ);
   19.90 @@ -967,7 +967,7 @@ void vnetd_select(Vnetd *vnetd, SelectSe
   19.91      ConnList_select(vnetd->conns, set);
   19.92  }
   19.93  
   19.94 -void vnetd_handle(Vnetd *vnetd, SelectSet *set){
   19.95 +static void vnetd_handle(Vnetd *vnetd, SelectSet *set){
   19.96      if(SelectSet_in_read(set, vnetd->unix_sock)){
   19.97          vnetd_handle_unix(vnetd, vnetd->unix_sock);
   19.98      }
   19.99 @@ -995,7 +995,7 @@ void vnetd_handle(Vnetd *vnetd, SelectSe
  19.100   */
  19.101  static unsigned timer_alarms = 0;
  19.102  
  19.103 -int vnetd_main(Vnetd *vnetd){
  19.104 +static int vnetd_main(Vnetd *vnetd){
  19.105      int err = 0;
  19.106      SelectSet _set = {}, *set = &_set;
  19.107      struct timeval _timeout = {}, *timeout = &_timeout;
  19.108 @@ -1030,12 +1030,12 @@ int vnetd_main(Vnetd *vnetd){
  19.109      return err;
  19.110  }
  19.111  
  19.112 -int getsockaddr(int sock, struct sockaddr_in *addr){
  19.113 +static int getsockaddr(int sock, struct sockaddr_in *addr){
  19.114      socklen_t addr_n = sizeof(struct sockaddr_in);
  19.115      return getsockname(sock, (struct sockaddr*)addr, &addr_n);
  19.116  }
  19.117  
  19.118 -int vnetd_etherip_sock(Vnetd *vnetd){
  19.119 +static int vnetd_etherip_sock(Vnetd *vnetd){
  19.120      int err = 0;
  19.121  
  19.122      if(!vnetd->etherip) goto exit;
  19.123 @@ -1051,7 +1051,7 @@ int vnetd_etherip_sock(Vnetd *vnetd){
  19.124      return err;
  19.125  }
  19.126  
  19.127 -int vnetd_udp_sock(Vnetd *vnetd){
  19.128 +static int vnetd_udp_sock(Vnetd *vnetd){
  19.129      int err;
  19.130      uint32_t mcaddr = vnetd_mcast_addr(vnetd);
  19.131  
  19.132 @@ -1087,7 +1087,7 @@ int vnetd_udp_sock(Vnetd *vnetd){
  19.133      return err;
  19.134  }
  19.135  
  19.136 -int vnetd_raw_sock(Vnetd *vnetd){
  19.137 +static int vnetd_raw_sock(Vnetd *vnetd){
  19.138      int err;
  19.139  
  19.140      err = vnetd_raw_socket(vnetd, IPPROTO_RAW,
  19.141 @@ -1101,7 +1101,7 @@ int vnetd_raw_sock(Vnetd *vnetd){
  19.142      return err;
  19.143  }
  19.144  
  19.145 -int vnetd_unix_sock(Vnetd *vnetd){
  19.146 +static int vnetd_unix_sock(Vnetd *vnetd){
  19.147      int err = 0;
  19.148      struct sockaddr_un addr = { .sun_family = AF_UNIX };
  19.149      socklen_t addr_n;