Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


*** empty log message ***
Jack Lange [Tue, 9 Sep 2008 22:51:07 +0000 (22:51 +0000)]
palacios/build/Makefile
palacios/include/geekos/socket.h
palacios/src/geekos/main.c
palacios/src/geekos/socket.c

index 7c689c1..7a147f4 100644 (file)
@@ -1,6 +1,6 @@
 # Makefile for GeekOS kernel, userspace, and tools
 # Copyright (c) 2004,2005 David H. Hovemeyer <daveho@cs.umd.edu>
-# $Revision: 1.68 $
+# $Revision: 1.69 $
 
 # This is free software.  You are permitted to use,
 # redistribute, and modify it as specified in the file "COPYING".
@@ -141,6 +141,8 @@ endif
 endif
 
 
+DEBUG_SECTIONS := $(DEBUG_SECTIONS) -DTEST_NE2K
+
 ifeq ($(DEBUG),1)
   JRLDEBUG= -DSERIAL_PRINT_DEBUG=1 -DSERIAL_PRINT_DEBUG_LEVEL=10 -DSERIAL_PRINT=1 -DVMM_DEBUG=1 -DVMM_INFO=1 -DVMM_TRACE=1 $(DEBUG_SECTIONS)
 
index cdd17d2..77c20b8 100644 (file)
@@ -5,12 +5,18 @@
 #include <uip/uip.h>
 #include <geekos/kthread.h>
 
+
+typedef enum {WAITING, CLOSED, LISTEN, ESTABLISHED} sock_state_t;
+
 struct socket {
   int in_use;
   struct Thread_Queue recv_wait_queue;
   struct ring_buffer *send_buf;
   struct ring_buffer *recv_buf;
   struct uip_conn *con;
+
+  sock_state_t state;
+
 };
 
 
@@ -21,4 +27,7 @@ int close(const int sockfd);
 int recv(int sockfd, void * buf, uint_t len);
 int send(int sockfd, void * buf, uint_t len);
 
+void set_ip_addr(uchar_t addr[4]);
+
+
 #endif
index f634c96..eab0aa0 100644 (file)
@@ -3,7 +3,7 @@
  * Copyright (c) 2001,2003,2004 David H. Hovemeyer <daveho@cs.umd.edu>
  * Copyright (c) 2003, Jeffrey K. Hollingsworth <hollings@cs.umd.edu>
  * Copyright (c) 2004, Iulian Neamtiu <neamtiu@cs.umd.edu>
- * $Revision: 1.44 $
+ * $Revision: 1.45 $
  * 
  * This is free software.  You are permitted to use,
  * redistribute, and modify it as specified in the file "COPYING".
 
 #include <geekos/pci.h>
 
+#if 0
 #include <geekos/ne2k.h>
 #include <uip/uip.h>
 #include <uip/uip_arp.h>
+#endif
 
-#include <geekos/ring_buffer.h>
+#include <geekos/socket.h>
+//#include <geekos/ring_buffer.h>
 
 #define SPEAKER_PORT 0x61
 #define TEST_NE2K 0
@@ -247,7 +250,28 @@ void Main(struct Boot_Info* bootInfo)
   Init_Stubs();
 
 
-#if TEST_NE2K
+#ifdef TEST_NE2K
+  {
+    init_network();
+    uchar_t local_addr[4];
+    uchar_t remote_addr[4];
+
+    local_addr[0] = 10;
+    local_addr[1] = 0;
+    local_addr[2] = 2;
+    local_addr[3] = 20;
+
+    set_ip_addr(local_addr);
+
+    remote_addr[0] = 10;
+    remote_addr[1] = 0;
+    remote_addr[2] = 2;
+    remote_addr[3] = 21;
+
+
+    connect(remote_addr, 4301);
+  }
+#elif 0
   Init_Ne2k(&Packet_Received);
   uip_init();
   uip_arp_init();
index 64b5f00..a3966e1 100644 (file)
@@ -1,12 +1,11 @@
 #include <geekos/socket.h>
 #include <geekos/malloc.h>
-#include <palacios/vmm_types.h>
 #include <geekos/ne2k.h>
 #include <uip/uip.h>
 #include <uip/uip_arp.h>
 #include <geekos/vmm_stubs.h>
+#include <geekos/debug.h>
 
-#define NULL (void *)0
 
 
 #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
@@ -16,7 +15,6 @@
 
 struct socket sockets[MAX_SOCKS];
 
-extern void* memcpy(void *dst, const void* src, int n);
 
 
 int Packet_Received(struct NE2K_Packet_Info* info, uchar_t *pkt);
@@ -28,6 +26,7 @@ void init_network() {
       sockets[i].in_use = 0;
       sockets[i].send_buf = NULL;
       sockets[i].recv_buf = NULL;
+      sockets[i].state = CLOSED;
    }
 
 
@@ -42,6 +41,16 @@ void init_network() {
 
 }
 
+
+
+
+void set_ip_addr(uchar_t addr[4]) {
+  uip_ipaddr_t ipaddr;
+  uip_ipaddr(ipaddr, addr[0], addr[1], addr[2], addr[3]);  /* Local IP address */
+  uip_sethostaddr(ipaddr);
+}
+
+
 static int allocate_socket_fd() {
   int i = 0;
   
@@ -70,6 +79,7 @@ static int release_socket_fd(int sockfd){
                free_ring_buffer(sockets[sockfd].recv_buf);
                sockets[sockfd].send_buf = NULL;
                sockets[sockfd].recv_buf = NULL;
+               sockets[sockfd].state = CLOSED;
        }
 
        return 0;
@@ -91,6 +101,8 @@ int connect(const uchar_t ip_addr[4], ushort_t port) {
   }
 
   uip_ipaddr(&ipaddr, ip_addr[0], ip_addr[1], ip_addr[2], ip_addr[3]);  
+
+  sockets[sockfd].state = WAITING;
   
   sockets[sockfd].con = uip_connect((uip_ipaddr_t *)&ip_addr, htons(port));
 
@@ -100,6 +112,22 @@ int connect(const uchar_t ip_addr[4], ushort_t port) {
     return -1;
   }
 
+
+  PrintBoth("Connection start\n");
+
+  while(sockets[sockfd].state == WAITING) {
+    timer_int_handler(NULL);
+  }
+
+    
+  PrintBoth("Connected\n");
+
+  if (sockets[sockfd].state != ESTABLISHED) {
+    release_socket_fd(sockfd);
+    return -1;
+  }
+
+
   return sockfd;
 }
 
@@ -141,8 +169,14 @@ void timer_int_Handler(struct Interrupt_State * state){
 }
 
 // a series of utilities to handle conncetion states
-static void connected(int sockfd){
+static void connected(int sockfd) {
+  struct socket * sock = get_socket_from_fd(sockfd);
+
+  PrintBoth("Connected Interrupt\n");
 
+  sock->state = ESTABLISHED;
+
+  Wake_Up(&(sock->recv_wait_queue));
 }
 
 static void closed(int sockfd){
@@ -180,12 +214,19 @@ static void newdata(int sockfd){
 }
 
 // not finished yet
-static void
-senddata(int sockfd){
+static void send_to_driver(int sockfd) {
+
+  PrintBoth("Sending data to driver\n");
+
+}
+
+
+
+int send(int sockfd, void * buf, uint_t len) {
   struct socket * sock = get_socket_from_fd(sockfd);
-  int mss = uip_mss();
-  int pending_bytes = rb_data_len(sock->send_buf);
-  int len = (mss < pending_bytes) ? mss: pending_bytes;
+  //int mss = uip_mss();
+  //int pending_bytes = rb_data_len(sock->send_buf);
+  //int len = (mss < pending_bytes) ? mss: pending_bytes;
   int bytes_read = 0;
   uchar_t * send_buf = uip_appdata;
   
@@ -193,16 +234,18 @@ senddata(int sockfd){
 
   if (bytes_read == 0) {
     // no packet for send
-    return;
+    return -1;
   }
 
   uip_send(send_buf, len);
+
+  return len;
 }
 
 
 
 //get the socket id by the local tcp port
-static int  get_socket_from_port(ushort_t lport) {
+static int get_socket_from_port(ushort_t lport) {
   int i;
   
 
@@ -223,6 +266,8 @@ void socket_appcall(void) {
   
   sockfd = get_socket_from_port(uip_conn->lport);
 
+  PrintBoth("Appcall\n");
+
   
   if (sockfd == -1) {
     return;
@@ -251,7 +296,7 @@ void socket_appcall(void) {
       uip_acked() ||
       uip_connected() ||
       uip_poll()) {
-    senddata(sockfd);
+    send_to_driver(sockfd);
   }
 }