direct-io.hg
changeset 11:515c1cd5de05
bitkeeper revision 1.7.1.2 (3ded082dh5rzdrKVMq0ag5OcobG2yQ)
allow access to console over network; nice for demos :-)
allow access to console over network; nice for demos :-)
author | smh22@boulderdash.cl.cam.ac.uk |
---|---|
date | Tue Dec 03 19:38:21 2002 +0000 (2002-12-03) |
parents | 6ae46e3dd10a |
children | 03538a2243c1 6a5ecb7d90d1 |
files | BitKeeper/etc/ignore xen-2.4.16/common/kernel.c |
line diff
1.1 --- a/BitKeeper/etc/ignore Tue Dec 03 13:09:50 2002 +0000 1.2 +++ b/BitKeeper/etc/ignore Tue Dec 03 19:38:21 2002 +0000 1.3 @@ -1,2 +1,3 @@ 1.4 BitKeeper/*/* 1.5 PENDING/* 1.6 +xen-2.4.16/common/kernel.c.old
2.1 --- a/xen-2.4.16/common/kernel.c Tue Dec 03 13:09:50 2002 +0000 2.2 +++ b/xen-2.4.16/common/kernel.c Tue Dec 03 19:38:21 2002 +0000 2.3 @@ -12,6 +12,8 @@ 2.4 #include <asm/msr.h> 2.5 #include <asm/uaccess.h> 2.6 #include <xeno/dom0_ops.h> 2.7 +#include <asm/byteorder.h> 2.8 +#include <linux/if_ether.h> 2.9 2.10 /* VGA text definitions. */ 2.11 #define COLUMNS 80 2.12 @@ -326,33 +328,175 @@ asmlinkage long sys_ni_syscall(void) 2.13 } 2.14 2.15 2.16 +unsigned short compute_cksum(unsigned short *buf, int count) 2.17 +{ 2.18 + /* Function written by ek247 2.19 + * Computes IP and UDP checksum. 2.20 + * To be used for the fake console packets 2.21 + * created in console_export 2.22 + */ 2.23 + 2.24 + unsigned long sum=0; 2.25 + 2.26 + while (count--) 2.27 + { 2.28 + sum+=*buf++; 2.29 + if (sum & 0xFFFF0000) 2.30 + { 2.31 + //carry occured, so wrap around 2.32 + sum &=0xFFFF; 2.33 + sum++; 2.34 + } 2.35 + } 2.36 + return ~(sum & 0xFFFF); 2.37 +} 2.38 + 2.39 + 2.40 + 2.41 +/* XXX SMH: below is rather vile; pulled in to allow network console */ 2.42 + 2.43 +extern int netif_rx(struct sk_buff *); 2.44 + 2.45 +typedef struct my_udphdr { 2.46 + __u16 source; 2.47 + __u16 dest; 2.48 + __u16 len; 2.49 + __u16 check; 2.50 +} my_udphdr_t; 2.51 + 2.52 + 2.53 +typedef struct my_iphdr { 2.54 +#if defined(__LITTLE_ENDIAN_BITFIELD) 2.55 + __u8 ihl:4, 2.56 + version:4; 2.57 +#elif defined (__BIG_ENDIAN_BITFIELD) 2.58 + __u8 version:4, 2.59 + ihl:4; 2.60 +#else 2.61 +#error "Please fix <asm/byteorder.h>" 2.62 +#endif 2.63 + __u8 tos; 2.64 + __u16 tot_len; 2.65 + __u16 id; 2.66 + __u16 frag_off; 2.67 + __u8 ttl; 2.68 + __u8 protocol; 2.69 + __u16 check; 2.70 + __u32 saddr; 2.71 + __u32 daddr; 2.72 +} my_iphdr_t; 2.73 + 2.74 + 2.75 +typedef struct my_ethhdr { 2.76 + unsigned char h_dest[6]; 2.77 + unsigned char h_source[6]; 2.78 + unsigned short h_proto; 2.79 +} my_ethhdr_t; 2.80 + 2.81 + 2.82 +int console_export(char *str, int len) 2.83 +{ 2.84 + /* Function written by ek247 2.85 + * Exports console output from all domains upwards 2.86 + * to domain0, by stuffing it into a fake network 2.87 + * packet 2.88 + */ 2.89 + struct sk_buff *console_packet; 2.90 + struct my_iphdr *iph = NULL; 2.91 + struct my_udphdr *udph = NULL; 2.92 + struct my_ethhdr *ethh = NULL; 2.93 + int hdr_size = sizeof(struct my_iphdr) + sizeof(struct my_udphdr); 2.94 + 2.95 + // Prepare console packet 2.96 + console_packet = alloc_skb(sizeof(struct my_ethhdr) + hdr_size + len, 2.97 + GFP_KERNEL); 2.98 + skb_reserve(console_packet, sizeof(struct my_ethhdr)); 2.99 + ethh = (struct my_ethhdr *)console_packet->head; 2.100 + 2.101 + skb_put(console_packet, hdr_size + len); 2.102 + iph = (struct my_iphdr *)console_packet->data; 2.103 + udph = (struct my_udphdr *)(iph + 1); 2.104 + memcpy((char *)(udph + 1), str, len); 2.105 + 2.106 + // Build IP header 2.107 + iph->version = 4; 2.108 + iph->ihl = 5; 2.109 + iph->frag_off= 0; 2.110 + iph->id = 0xdead; 2.111 + iph->ttl = 255; 2.112 + iph->protocol= 17; 2.113 + iph->daddr = htonl(opt_ipbase); 2.114 + iph->saddr = htonl(0xa9fe0001); 2.115 + iph->tot_len = htons(hdr_size + len); 2.116 + 2.117 + // Calculating IP checksum 2.118 + iph->check = 0; 2.119 + iph->check = compute_cksum((__u16 *)iph, sizeof(struct my_iphdr)/2); 2.120 + 2.121 + 2.122 + // Build UDP header 2.123 + udph->source = htons(current->domain); 2.124 + udph->dest = htons(666); 2.125 + udph->len = htons(sizeof(struct my_udphdr) + len); 2.126 + udph->check = 0; 2.127 + 2.128 + // Fix Ethernet header 2.129 + memcpy(ethh->h_source, "000000", 6); 2.130 + memcpy(ethh->h_dest, "000000", 6); 2.131 + ethh->h_proto = htons(ETH_P_IP); 2.132 + console_packet->mac.ethernet= (struct ethhdr *)ethh; 2.133 + 2.134 + // Pass the packet to netif_rx 2.135 + (void)netif_rx(console_packet); 2.136 + 2.137 + return 1; 2.138 +} 2.139 + 2.140 + 2.141 long do_console_write(char *str, int count) 2.142 { 2.143 #define SIZEOF_BUF 256 2.144 unsigned char safe_str[SIZEOF_BUF]; 2.145 + unsigned char exported_str[SIZEOF_BUF]; 2.146 unsigned long flags; 2.147 - int i; 2.148 + int i=0; 2.149 + int j=0; 2.150 unsigned char prev = '\n'; 2.151 - 2.152 + 2.153 if ( count > SIZEOF_BUF ) count = SIZEOF_BUF; 2.154 - 2.155 + 2.156 if ( copy_from_user(safe_str, str, count) ) 2.157 return -EFAULT; 2.158 - 2.159 + 2.160 spin_lock_irqsave(&console_lock, flags); 2.161 + 2.162 + __putstr("DOM"); 2.163 + putchar(current->domain+'0'); 2.164 + __putstr(": "); 2.165 + 2.166 for ( i = 0; i < count; i++ ) 2.167 { 2.168 + exported_str[j++]=safe_str[i]; 2.169 + 2.170 + if ( !safe_str[i] ) break; 2.171 + putchar(prev = safe_str[i]); 2.172 + 2.173 if ( prev == '\n' ) 2.174 { 2.175 - __putstr("DOM"); 2.176 - putchar(current->domain+'0'); 2.177 - __putstr(": "); 2.178 + exported_str[j]='\0'; 2.179 + console_export(exported_str, j-1); 2.180 + j=0; 2.181 } 2.182 - if ( !safe_str[i] ) break; 2.183 - putchar(prev = safe_str[i]); 2.184 + 2.185 } 2.186 - if ( prev != '\n' ) putchar('\n'); 2.187 + if ( prev != '\n' ) 2.188 + { 2.189 + putchar('\n'); 2.190 + exported_str[j]='\0'; 2.191 + console_export(exported_str, j-1); 2.192 + } 2.193 + 2.194 spin_unlock_irqrestore(&console_lock, flags); 2.195 - 2.196 + 2.197 return(0); 2.198 }