ia64/xen-unstable
changeset 405:e82d0032ab3f
bitkeeper revision 1.193 (3eae9e8fDbEyBEL7yKPAlkULZMIM4g)
network.c, dev.c, vif.h, hypervisor-if.h, kernel.c, domain.c:
Allow DHCP from domain-0 Xenolinux. Link-local IP addresses are now allocated consecutively from 169.254.1.0.
network.c, dev.c, vif.h, hypervisor-if.h, kernel.c, domain.c:
Allow DHCP from domain-0 Xenolinux. Link-local IP addresses are now allocated consecutively from 169.254.1.0.
author | kaf24@scramble.cl.cam.ac.uk |
---|---|
date | Tue Apr 29 15:47:27 2003 +0000 (2003-04-29) |
parents | 3ac10ab82d37 |
children | ca730caf1aad |
files | xen/common/domain.c xen/common/kernel.c xen/common/network.c xen/include/hypervisor-ifs/hypervisor-if.h xen/include/xeno/vif.h xen/net/dev.c xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/network/network.c |
line diff
1.1 --- a/xen/common/domain.c Tue Apr 29 10:15:57 2003 +0000 1.2 +++ b/xen/common/domain.c Tue Apr 29 15:47:27 2003 +0000 1.3 @@ -377,6 +377,8 @@ int final_setup_guestos(struct task_stru 1.4 if ( p->net_vif_list[i] == NULL ) continue; 1.5 virt_startinfo_addr->net_rings[i] = 1.6 virt_to_phys(p->net_vif_list[i]->shared_rings); 1.7 + memcpy(virt_startinfo_addr->net_vmac[i], 1.8 + p->net_vif_list[i]->vmac, ETH_ALEN); 1.9 } 1.10 1.11 /* Add block io interface */ 1.12 @@ -645,6 +647,8 @@ int setup_guestos(struct task_struct *p, 1.13 if ( p->net_vif_list[i] == NULL ) continue; 1.14 virt_startinfo_address->net_rings[i] = 1.15 virt_to_phys(p->net_vif_list[i]->shared_rings); 1.16 + memcpy(virt_startinfo_address->net_vmac[i], 1.17 + p->net_vif_list[i]->vmac, ETH_ALEN); 1.18 } 1.19 1.20 /* Add block io interface */
2.1 --- a/xen/common/kernel.c Tue Apr 29 10:15:57 2003 +0000 2.2 +++ b/xen/common/kernel.c Tue Apr 29 15:47:27 2003 +0000 2.3 @@ -424,7 +424,6 @@ unsigned short compute_cksum(unsigned sh 2.4 /* XXX SMH: below is rather vile; pulled in to allow network console */ 2.5 2.6 extern int netif_rx(struct sk_buff *); 2.7 -extern struct net_device *the_dev; 2.8 2.9 typedef struct my_udphdr { 2.10 __u16 source; 2.11 @@ -499,8 +498,8 @@ int console_export(char *str, int len) 2.12 iph->id = 0xdead; 2.13 iph->ttl = 255; 2.14 iph->protocol= 17; 2.15 - iph->daddr = htonl(0xa9fe0001); /* 169.254.0.1 */ 2.16 - iph->saddr = htonl(0xa9fe0001); /* 169.254.0.1 */ 2.17 + iph->daddr = htonl(0xa9fe0100); /* 169.254.1.0 */ 2.18 + iph->saddr = htonl(0xa9fe0100); /* 169.254.1.0 */ 2.19 iph->tot_len = htons(hdr_size + len); 2.20 iph->check = 0; 2.21 iph->check = compute_cksum((__u16 *)iph, sizeof(struct my_iphdr)/2);
3.1 --- a/xen/common/network.c Tue Apr 29 10:15:57 2003 +0000 3.2 +++ b/xen/common/network.c Tue Apr 29 15:47:27 2003 +0000 3.3 @@ -104,6 +104,14 @@ net_vif_t *create_net_vif(int domain) 3.4 spin_lock_init(&new_vif->rx_lock); 3.5 spin_lock_init(&new_vif->tx_lock); 3.6 3.7 + /* 3.8 + * Virtual MAC is a hash of the real physical MAC. Chosen so that the 3.9 + * first vif of domain 0 gets the physical MAC address. 3.10 + */ 3.11 + memcpy(new_vif->vmac, the_dev->dev_addr, ETH_ALEN); 3.12 + ((unsigned short *)new_vif->vmac)[1] ^= htons(p->domain); 3.13 + ((unsigned short *)new_vif->vmac)[2] ^= htons(dom_vif_idx); 3.14 + 3.15 p->net_vif_list[dom_vif_idx] = new_vif; 3.16 3.17 write_unlock_irqrestore(&tasklist_lock, flags); 3.18 @@ -496,8 +504,6 @@ long do_network_op(network_op_t *u_netwo 3.19 3.20 void __init net_init (void) 3.21 { 3.22 - net_rule_t new_rule; 3.23 - 3.24 net_rule_list = NULL; 3.25 net_vif_cache = kmem_cache_create("net_vif_cache", 3.26 sizeof(net_vif_t), 3.27 @@ -505,20 +511,4 @@ void __init net_init (void) 3.28 net_rule_cache = kmem_cache_create("net_rule_cache", 3.29 sizeof(net_rule_ent_t), 3.30 0, SLAB_HWCACHE_ALIGN, NULL, NULL); 3.31 - 3.32 - /* Bootstrap outbound rule. */ 3.33 - memset(&new_rule, 0, sizeof(net_rule_t)); 3.34 - new_rule.src_vif = 0; 3.35 - new_rule.dst_vif = VIF_PHYSICAL_INTERFACE; 3.36 - new_rule.action = NETWORK_ACTION_ACCEPT; 3.37 - new_rule.proto = NETWORK_PROTO_ANY; 3.38 - add_net_rule(&new_rule); 3.39 - 3.40 - /* Bootstrap inbound rule. */ 3.41 - memset(&new_rule, 0, sizeof(net_rule_t)); 3.42 - new_rule.src_vif = VIF_ANY_INTERFACE; 3.43 - new_rule.dst_vif = 0; 3.44 - new_rule.action = NETWORK_ACTION_ACCEPT; 3.45 - new_rule.proto = NETWORK_PROTO_ANY; 3.46 - add_net_rule(&new_rule); 3.47 }
4.1 --- a/xen/include/hypervisor-ifs/hypervisor-if.h Tue Apr 29 10:15:57 2003 +0000 4.2 +++ b/xen/include/hypervisor-ifs/hypervisor-if.h Tue Apr 29 15:47:27 2003 +0000 4.3 @@ -241,6 +241,7 @@ typedef struct start_info_st { 4.4 unsigned long mod_len; /* size (bytes) of pre-loaded module */ 4.5 /* Machine address of net rings for each VIF. Will be page aligned. */ 4.6 unsigned long net_rings[MAX_DOMAIN_VIFS]; 4.7 + unsigned char net_vmac[MAX_DOMAIN_VIFS][6]; 4.8 /* Machine address of block-device ring. Will be page aligned. */ 4.9 unsigned long blk_ring; 4.10 unsigned int dom_id;
5.1 --- a/xen/include/xeno/vif.h Tue Apr 29 10:15:57 2003 +0000 5.2 +++ b/xen/include/xeno/vif.h Tue Apr 29 15:47:27 2003 +0000 5.3 @@ -20,6 +20,10 @@ 5.4 5.5 #include <hypervisor-ifs/network.h> 5.6 5.7 +#include <xeno/if_ether.h> 5.8 + 5.9 +extern struct net_device *the_dev; 5.10 + 5.11 /* 5.12 * shadow ring structures are used to protect the descriptors from 5.13 * tampering after they have been passed to the hypervisor. 5.14 @@ -69,6 +73,7 @@ typedef struct net_vif_st { 5.15 struct list_head list; /* scheduling list */ 5.16 atomic_t refcnt; 5.17 spinlock_t rx_lock, tx_lock; 5.18 + unsigned char vmac[ETH_ALEN]; 5.19 } net_vif_t; 5.20 5.21 #define get_vif(_v) (atomic_inc(&(_v)->refcnt))
6.1 --- a/xen/net/dev.c Tue Apr 29 10:15:57 2003 +0000 6.2 +++ b/xen/net/dev.c Tue Apr 29 15:47:27 2003 +0000 6.3 @@ -500,9 +500,9 @@ void deliver_packet(struct sk_buff *skb, 6.4 unsigned short size; 6.5 unsigned char offset, status = RING_STATUS_OK; 6.6 6.7 - memset(skb->mac.ethernet->h_dest, 0, ETH_ALEN); 6.8 + memcpy(skb->mac.ethernet->h_dest, vif->vmac, ETH_ALEN); 6.9 if ( ntohs(skb->mac.ethernet->h_proto) == ETH_P_ARP ) 6.10 - memset(skb->nh.raw + 18, 0, ETH_ALEN); 6.11 + memcpy(skb->nh.raw + 18, vif->vmac, ETH_ALEN); 6.12 6.13 if ( (i = vif->rx_cons) == vif->rx_prod ) 6.14 return; 6.15 @@ -741,7 +741,7 @@ static void net_tx_action(unsigned long 6.16 add_to_net_schedule_list_tail(vif); 6.17 6.18 skb->destructor = tx_skb_release; 6.19 - 6.20 + 6.21 skb->head = skb->data = tx->header; 6.22 skb->end = skb->tail = skb->head + PKT_PROT_LEN; 6.23 6.24 @@ -1728,7 +1728,7 @@ inline int init_tx_header(u8 *data, unsi 6.25 { 6.26 case ETH_P_ARP: 6.27 if ( len < 42 ) break; 6.28 - memcpy(data + 22, dev->dev_addr, 6); 6.29 + memcpy(data + 22, dev->dev_addr, ETH_ALEN); 6.30 return ETH_P_ARP; 6.31 case ETH_P_IP: 6.32 return ETH_P_IP; 6.33 @@ -1939,7 +1939,7 @@ long do_net_update(void) 6.34 (PGT_writeable_page | current->domain)) || 6.35 (buf_page->tot_count != 1) ) 6.36 { 6.37 - DPRINTK("Need a mapped-once writeable page (%d/%d/%08x)\n", 6.38 + DPRINTK("Need a mapped-once writeable page (%ld/%ld/%08lx)\n", 6.39 buf_page->type_count, buf_page->tot_count, buf_page->flags); 6.40 make_rx_response(vif, rx.id, 0, RING_STATUS_BAD_PAGE, 0); 6.41 goto rx_unmap_and_continue;
7.1 --- a/xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/network/network.c Tue Apr 29 10:15:57 2003 +0000 7.2 +++ b/xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/network/network.c Tue Apr 29 15:47:27 2003 +0000 7.3 @@ -470,9 +470,9 @@ static int inetdev_notify(struct notifie 7.4 (void)HYPERVISOR_network_op(&op); 7.5 7.6 /* 7.7 - * Xen creates a pair of bootstrap rules which allows domain 0 to 7.8 - * send and receive any packet. These rules can be removed once we 7.9 - * have configured an IP address. 7.10 + * When the first real interface is brought up we delete the start-of-day 7.11 + * bootstrap rules -- they were only installed to allow an initial DHCP 7.12 + * request and response. 7.13 */ 7.14 if ( (idx == 0) && (event == NETDEV_UP) && !removed_bootstrap_rules ) 7.15 { 7.16 @@ -480,11 +480,9 @@ static int inetdev_notify(struct notifie 7.17 op.cmd = NETWORK_OP_DELETERULE; 7.18 op.u.net_rule.proto = NETWORK_PROTO_ANY; 7.19 op.u.net_rule.action = NETWORK_ACTION_ACCEPT; 7.20 - 7.21 op.u.net_rule.src_vif = 0; 7.22 op.u.net_rule.dst_vif = VIF_PHYSICAL_INTERFACE; 7.23 (void)HYPERVISOR_network_op(&op); 7.24 - 7.25 op.u.net_rule.src_vif = VIF_ANY_INTERFACE; 7.26 op.u.net_rule.dst_vif = 0; 7.27 (void)HYPERVISOR_network_op(&op); 7.28 @@ -511,13 +509,32 @@ int __init init_module(void) 7.29 7.30 INIT_LIST_HEAD(&dev_list); 7.31 7.32 - /* 7.33 - * Domain 0 must poke its own network rules as it discovers its IP 7.34 - * addresses. All other domains have a privileged "parent" to do this 7.35 - * for them at start of day. 7.36 - */ 7.37 if ( start_info.dom_id == 0 ) 7.38 + { 7.39 + /* 7.40 + * Domain 0 creates wildcard rules to allow DHCP to find its first IP 7.41 + * address. These wildcard rules are deleted when the first inet 7.42 + * interface is brought up. 7.43 + */ 7.44 + network_op_t op; 7.45 + memset(&op, 0, sizeof(op)); 7.46 + op.cmd = NETWORK_OP_ADDRULE; 7.47 + op.u.net_rule.proto = NETWORK_PROTO_ANY; 7.48 + op.u.net_rule.action = NETWORK_ACTION_ACCEPT; 7.49 + op.u.net_rule.src_vif = 0; 7.50 + op.u.net_rule.dst_vif = VIF_PHYSICAL_INTERFACE; 7.51 + (void)HYPERVISOR_network_op(&op); 7.52 + op.u.net_rule.src_vif = VIF_ANY_INTERFACE; 7.53 + op.u.net_rule.dst_vif = 0; 7.54 + (void)HYPERVISOR_network_op(&op); 7.55 + 7.56 + /* 7.57 + * Domain 0 must poke its own network rules as it discovers its IP 7.58 + * addresses. All other domains have a privileged "parent" to do this 7.59 + * for them at start of day. 7.60 + */ 7.61 (void)register_inetaddr_notifier(¬ifier_inetdev); 7.62 + } 7.63 7.64 for ( i = 0; i < MAX_DOMAIN_VIFS; i++ ) 7.65 { 7.66 @@ -548,8 +565,7 @@ int __init init_module(void) 7.67 dev->stop = network_close; 7.68 dev->get_stats = network_get_stats; 7.69 7.70 - memset(dev->dev_addr, 0, ETH_ALEN); 7.71 - *(unsigned int *)(dev->dev_addr + 1) = i; 7.72 + memcpy(dev->dev_addr, start_info.net_vmac[i], ETH_ALEN); 7.73 7.74 if ( (err = register_netdev(dev)) != 0 ) 7.75 {