ia64/xen-unstable

changeset 404:3ac10ab82d37

bitkeeper revision 1.192 (3eae50ddRBIeCAm0nByE2rOPgLLz3A)

network.c, vif.h, kernel.c:
Removed 'dom0_ip' option from Xen. Console packets are now sent to 169.254.0.1 (DOM0's hardwired link-local address).
author kaf24@scramble.cl.cam.ac.uk
date Tue Apr 29 10:15:57 2003 +0000 (2003-04-29)
parents b695c18bad2d
children e82d0032ab3f 3ad4b311771f
files xen/common/kernel.c xen/common/network.c xen/include/xeno/vif.h xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/network/network.c
line diff
     1.1 --- a/xen/common/kernel.c	Mon Apr 28 15:11:10 2003 +0000
     1.2 +++ b/xen/common/kernel.c	Tue Apr 29 10:15:57 2003 +0000
     1.3 @@ -32,7 +32,6 @@ void init_serial(void);
     1.4  void start_of_day(void);
     1.5  
     1.6  /* Command line options and variables. */
     1.7 -unsigned long opt_dom0_ip = 0;
     1.8  unsigned int opt_ser_baud = 9600;  /* default baud for COM1 */
     1.9  unsigned int opt_dom0_mem = 16000; /* default kbytes for DOM0 */
    1.10  unsigned int opt_ne_base = 0; /* NE2k NICs cannot be probed */
    1.11 @@ -45,7 +44,6 @@ static struct {
    1.12      void *var;
    1.13  } opts[] = {
    1.14      { "ser_baud", OPT_UINT, &opt_ser_baud },
    1.15 -    { "dom0_ip",  OPT_IP,   &opt_dom0_ip },
    1.16      { "dom0_mem", OPT_UINT, &opt_dom0_mem }, 
    1.17      { "ne_base",  OPT_UINT, &opt_ne_base },
    1.18      { "ifname",   OPT_STR,  &opt_ifname },
    1.19 @@ -183,11 +181,6 @@ void cmain (unsigned long magic, multibo
    1.20      dom0_params.num_vifs  = 1;
    1.21      dom0_params.memory_kb = opt_dom0_mem;
    1.22  
    1.23 -    if ( opt_dom0_ip == 0 )
    1.24 -        panic("Must specify an IP address for domain 0!\n");
    1.25 -
    1.26 -    add_default_net_rule(0, opt_dom0_ip); // add vfr info for dom0
    1.27 -
    1.28      new_dom = do_newdomain(0, 0);
    1.29      if ( new_dom == NULL ) panic("Error creating domain 0\n");
    1.30  
    1.31 @@ -506,8 +499,8 @@ int console_export(char *str, int len)
    1.32      iph->id      = 0xdead;
    1.33      iph->ttl     = 255;
    1.34      iph->protocol= 17;
    1.35 -    iph->daddr   = htonl(opt_dom0_ip);
    1.36 -    iph->saddr   = htonl(0xa9fe0001); 
    1.37 +    iph->daddr   = htonl(0xa9fe0001);  /* 169.254.0.1 */
    1.38 +    iph->saddr   = htonl(0xa9fe0001);  /* 169.254.0.1 */
    1.39      iph->tot_len = htons(hdr_size + len); 
    1.40      iph->check	 = 0;
    1.41      iph->check   = compute_cksum((__u16 *)iph, sizeof(struct my_iphdr)/2); 
     2.1 --- a/xen/common/network.c	Mon Apr 28 15:11:10 2003 +0000
     2.2 +++ b/xen/common/network.c	Tue Apr 29 10:15:57 2003 +0000
     2.3 @@ -251,38 +251,6 @@ int delete_net_rule(net_rule_t *rule)
     2.4      return 0;
     2.5  }
     2.6   
     2.7 -/* add_default_net_rule - Set up default network path (ie for dom0).
     2.8 - * 
     2.9 - * this is a utility function to route all traffic with the specified
    2.10 - * ip address to the specified vif.  It's used to set up domain zero.
    2.11 - */
    2.12 -
    2.13 -void add_default_net_rule(unsigned long vif_id, u32 ipaddr)
    2.14 -{
    2.15 -    net_rule_t new_rule;
    2.16 -
    2.17 -    //outbound rule.
    2.18 -    memset(&new_rule, 0, sizeof(net_rule_t));
    2.19 -    new_rule.src_addr = ipaddr;
    2.20 -    new_rule.src_addr_mask = 0xffffffff;
    2.21 -    new_rule.src_vif = vif_id;
    2.22 -    new_rule.dst_vif = VIF_PHYSICAL_INTERFACE;
    2.23 -    new_rule.action = NETWORK_ACTION_ACCEPT;
    2.24 -    new_rule.proto = NETWORK_PROTO_ANY;
    2.25 -    add_net_rule(&new_rule);
    2.26 -
    2.27 -    //inbound rule;
    2.28 -    memset(&new_rule, 0, sizeof(net_rule_t));
    2.29 -    new_rule.dst_addr = ipaddr;
    2.30 -    new_rule.dst_addr_mask = 0xffffffff;
    2.31 -    new_rule.src_vif = VIF_ANY_INTERFACE;
    2.32 -    new_rule.dst_vif = vif_id;
    2.33 -    new_rule.action = NETWORK_ACTION_ACCEPT;
    2.34 -    new_rule.proto = NETWORK_PROTO_ANY;
    2.35 -    add_net_rule(&new_rule);
    2.36 -
    2.37 -}
    2.38 -
    2.39  /* print_net_rule - Print a single net rule.
    2.40   */
    2.41  
    2.42 @@ -371,6 +339,8 @@ static net_vif_t *net_find_rule(u8 nprot
    2.43          if ( ((ent->r.src_vif == src_vif)
    2.44                || (ent->r.src_vif == VIF_ANY_INTERFACE)) &&
    2.45  
    2.46 +             (src_vif != ent->r.dst_vif) &&
    2.47 +
    2.48               (!((ent->r.src_addr ^ src_addr) & ent->r.src_addr_mask )) &&
    2.49               (!((ent->r.dst_addr ^ dst_addr) & ent->r.dst_addr_mask )) &&
    2.50               (!((ent->r.src_port ^ src_port) & ent->r.src_port_mask )) &&
    2.51 @@ -504,9 +474,10 @@ long do_network_op(network_op_t *u_netwo
    2.52  
    2.53      case NETWORK_OP_GETRULELIST:
    2.54      {
    2.55 -        // This should eventually ship a rule list up to the VM
    2.56 -        // to be printed in its procfs.  For now, we just print the rules.
    2.57 -        
    2.58 +        /*
    2.59 +         * This should ship a rule list up to the guest OS. For now
    2.60 +         * we just dump the rules to our own console.
    2.61 +         */
    2.62          print_net_rule_list();
    2.63      }
    2.64      break;
    2.65 @@ -525,9 +496,29 @@ long do_network_op(network_op_t *u_netwo
    2.66  
    2.67  void __init net_init (void)
    2.68  {
    2.69 +    net_rule_t new_rule;
    2.70 +
    2.71      net_rule_list = NULL;
    2.72 -    net_vif_cache = kmem_cache_create("net_vif_cache", sizeof(net_vif_t),
    2.73 -                                    0, SLAB_HWCACHE_ALIGN, NULL, NULL);
    2.74 -    net_rule_cache = kmem_cache_create("net_rule_cache", sizeof(net_rule_ent_t),
    2.75 -                                    0, SLAB_HWCACHE_ALIGN, NULL, NULL);
    2.76 +    net_vif_cache = kmem_cache_create("net_vif_cache", 
    2.77 +                                      sizeof(net_vif_t),
    2.78 +                                      0, SLAB_HWCACHE_ALIGN, NULL, NULL);
    2.79 +    net_rule_cache = kmem_cache_create("net_rule_cache", 
    2.80 +                                       sizeof(net_rule_ent_t),
    2.81 +                                       0, SLAB_HWCACHE_ALIGN, NULL, NULL);
    2.82 +
    2.83 +    /* Bootstrap outbound rule. */
    2.84 +    memset(&new_rule, 0, sizeof(net_rule_t));
    2.85 +    new_rule.src_vif = 0;
    2.86 +    new_rule.dst_vif = VIF_PHYSICAL_INTERFACE;
    2.87 +    new_rule.action = NETWORK_ACTION_ACCEPT;
    2.88 +    new_rule.proto = NETWORK_PROTO_ANY;
    2.89 +    add_net_rule(&new_rule);
    2.90 +
    2.91 +    /* Bootstrap inbound rule. */
    2.92 +    memset(&new_rule, 0, sizeof(net_rule_t));
    2.93 +    new_rule.src_vif = VIF_ANY_INTERFACE;
    2.94 +    new_rule.dst_vif = 0;
    2.95 +    new_rule.action = NETWORK_ACTION_ACCEPT;
    2.96 +    new_rule.proto = NETWORK_PROTO_ANY;
    2.97 +    add_net_rule(&new_rule);
    2.98  }
     3.1 --- a/xen/include/xeno/vif.h	Mon Apr 28 15:11:10 2003 +0000
     3.2 +++ b/xen/include/xeno/vif.h	Tue Apr 29 10:15:57 2003 +0000
     3.3 @@ -81,7 +81,6 @@ do {                                    
     3.4  net_vif_t *create_net_vif(int domain);
     3.5  void destroy_net_vif(net_vif_t *vif);
     3.6  void unlink_net_vif(net_vif_t *vif);
     3.7 -void add_default_net_rule(unsigned long vif_id, u32 ipaddr);
     3.8  net_vif_t *net_get_target_vif(u8 *data, unsigned int len, net_vif_t *src_vif);
     3.9  net_vif_t *find_vif_by_id(unsigned long id);
    3.10  
     4.1 --- a/xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/network/network.c	Mon Apr 28 15:11:10 2003 +0000
     4.2 +++ b/xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/network/network.c	Tue Apr 29 10:15:57 2003 +0000
     4.3 @@ -58,6 +58,7 @@ struct net_private
     4.4      net_ring_t *net_ring;
     4.5      net_idx_t  *net_idx;
     4.6      spinlock_t tx_lock;
     4.7 +    unsigned int idx; /* Domain-specific index of this VIF. */
     4.8  
     4.9      /*
    4.10       * {tx,rx}_skbs store outstanding skbuffs. The first entry in each
    4.11 @@ -412,6 +413,96 @@ static struct net_device_stats *network_
    4.12  }
    4.13  
    4.14  
    4.15 +/*
    4.16 + * This notifier is installed for domain 0 only.
    4.17 + * All other domains have VFR rules installed on their behalf by domain 0
    4.18 + * when they are created. For bootstrap, Xen creates wildcard rules for
    4.19 + * domain 0 -- this notifier is used to detect when we find our proper
    4.20 + * IP address, so we can poke down proper rules and remove the wildcards.
    4.21 + */
    4.22 +static int inetdev_notify(struct notifier_block *this, 
    4.23 +                          unsigned long event, 
    4.24 +                          void *ptr)
    4.25 +{
    4.26 +    struct in_ifaddr  *ifa  = (struct in_ifaddr *)ptr; 
    4.27 +    struct net_device *dev = ifa->ifa_dev->dev;
    4.28 +    struct list_head  *ent;
    4.29 +    struct net_private *np;
    4.30 +    int idx = -1;
    4.31 +    network_op_t op;
    4.32 +    static int removed_bootstrap_rules = 0;
    4.33 +
    4.34 +    list_for_each ( ent, &dev_list )
    4.35 +    {
    4.36 +        np  = list_entry(dev_list.next, struct net_private, list);
    4.37 +        if ( np->dev == dev )
    4.38 +            idx = np->idx;
    4.39 +    }
    4.40 +
    4.41 +    if ( idx == -1 )
    4.42 +        goto out;
    4.43 +    
    4.44 +    memset(&op, 0, sizeof(op));
    4.45 +    op.u.net_rule.proto         = NETWORK_PROTO_ANY;
    4.46 +    op.u.net_rule.action        = NETWORK_ACTION_ACCEPT;
    4.47 +
    4.48 +    if ( event == NETDEV_UP )
    4.49 +        op.cmd = NETWORK_OP_ADDRULE;
    4.50 +    else if ( event == NETDEV_DOWN )
    4.51 +        op.cmd = NETWORK_OP_DELETERULE;
    4.52 +    else
    4.53 +        goto out;
    4.54 +
    4.55 +    op.u.net_rule.src_vif       = idx;
    4.56 +    op.u.net_rule.dst_vif       = VIF_PHYSICAL_INTERFACE;
    4.57 +    op.u.net_rule.src_addr      = ntohl(ifa->ifa_address);
    4.58 +    op.u.net_rule.src_addr_mask = ~0UL;
    4.59 +    op.u.net_rule.dst_addr      = 0;
    4.60 +    op.u.net_rule.dst_addr_mask = 0;
    4.61 +    (void)HYPERVISOR_network_op(&op);
    4.62 +    
    4.63 +    op.u.net_rule.src_vif       = VIF_ANY_INTERFACE;
    4.64 +    op.u.net_rule.dst_vif       = idx;
    4.65 +    op.u.net_rule.src_addr      = 0;
    4.66 +    op.u.net_rule.src_addr_mask = 0;    
    4.67 +    op.u.net_rule.dst_addr      = ntohl(ifa->ifa_address);
    4.68 +    op.u.net_rule.dst_addr_mask = ~0UL;
    4.69 +    (void)HYPERVISOR_network_op(&op);
    4.70 +
    4.71 +    /*
    4.72 +     * Xen creates a pair of bootstrap rules which allows domain 0 to
    4.73 +     * send and receive any packet. These rules can be removed once we
    4.74 +     * have configured an IP address.
    4.75 +     */
    4.76 +    if ( (idx == 0) && (event == NETDEV_UP) && !removed_bootstrap_rules )
    4.77 +    {
    4.78 +        memset(&op, 0, sizeof(op));
    4.79 +        op.cmd = NETWORK_OP_DELETERULE;
    4.80 +        op.u.net_rule.proto         = NETWORK_PROTO_ANY;
    4.81 +        op.u.net_rule.action        = NETWORK_ACTION_ACCEPT;
    4.82 +
    4.83 +        op.u.net_rule.src_vif       = 0;
    4.84 +        op.u.net_rule.dst_vif       = VIF_PHYSICAL_INTERFACE;
    4.85 +        (void)HYPERVISOR_network_op(&op);
    4.86 +
    4.87 +        op.u.net_rule.src_vif       = VIF_ANY_INTERFACE;
    4.88 +        op.u.net_rule.dst_vif       = 0;
    4.89 +        (void)HYPERVISOR_network_op(&op);
    4.90 +
    4.91 +        removed_bootstrap_rules = 1;
    4.92 +    }
    4.93 +    
    4.94 + out:
    4.95 +    return NOTIFY_DONE;
    4.96 +}
    4.97 +
    4.98 +static struct notifier_block notifier_inetdev = {
    4.99 +    .notifier_call  = inetdev_notify,
   4.100 +    .next           = NULL,
   4.101 +    .priority       = 0
   4.102 +};
   4.103 +
   4.104 +
   4.105  int __init init_module(void)
   4.106  {
   4.107      int i, fixmap_idx=-1, err;
   4.108 @@ -420,6 +511,14 @@ int __init init_module(void)
   4.109  
   4.110      INIT_LIST_HEAD(&dev_list);
   4.111  
   4.112 +    /*
   4.113 +     * Domain 0 must poke its own network rules as it discovers its IP
   4.114 +     * addresses. All other domains have a privileged "parent" to do this
   4.115 +     * for them at start of day.
   4.116 +     */
   4.117 +    if ( start_info.dom_id == 0 )
   4.118 +        (void)register_inetaddr_notifier(&notifier_inetdev);
   4.119 +
   4.120      for ( i = 0; i < MAX_DOMAIN_VIFS; i++ )
   4.121      {
   4.122          if ( start_info.net_rings[i] == 0 )
   4.123 @@ -441,6 +540,7 @@ int __init init_module(void)
   4.124          np = dev->priv;
   4.125          np->net_ring = (net_ring_t *)fix_to_virt(FIX_NETRING0_BASE+fixmap_idx);
   4.126          np->net_idx  = &HYPERVISOR_shared_info->net_idx[i];
   4.127 +        np->idx      = i;
   4.128  
   4.129          SET_MODULE_OWNER(dev);
   4.130          dev->open            = network_open;
   4.131 @@ -482,6 +582,9 @@ static void cleanup_module(void)
   4.132          unregister_netdev(dev);
   4.133          kfree(dev);
   4.134      }
   4.135 +
   4.136 +    if ( start_info.dom_id == 0 )
   4.137 +        (void)unregister_inetaddr_notifier(&notifier_inetdev);
   4.138  }
   4.139  
   4.140