WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] minios: Automatically set IP from XenStore informati

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] minios: Automatically set IP from XenStore information
From: Samuel Thibault <samuel.thibault@xxxxxxxxxxxxx>
Date: Wed, 19 Mar 2008 15:21:42 +0000
Delivery-date: Wed, 19 Mar 2008 08:22:53 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Mail-followup-to: Samuel Thibault <samuel.thibault@xxxxxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mutt/1.5.12-2006-07-14
minios: Automatically set IP from XenStore information

Signed-off-by: Samuel Thibault <samuel.thibault@xxxxxxxxxxxxx>

diff -r 82aa9c991ee8 extras/mini-os/Makefile
--- a/extras/mini-os/Makefile   Wed Mar 19 14:16:08 2008 +0000
+++ b/extras/mini-os/Makefile   Wed Mar 19 15:18:19 2008 +0000
@@ -100,7 +100,7 @@
 LDLIBS += -lc
 endif
 
-ifneq ($(caml)-$(qemu)-$(CDIR)-$(lwip),--y)
+ifneq ($(caml)-$(qemu)-$(CDIR)-$(lwip),---y)
 OBJS := $(filter-out daytime.o, $(OBJS))
 endif
 
--- a/extras/mini-os/daytime.c  Wed Mar 19 14:16:08 2008 +0000
+++ b/extras/mini-os/daytime.c  Wed Mar 19 15:18:19 2008 +0000
@@ -15,16 +15,19 @@
 void run_server(void *p)
 {
     struct ip_addr listenaddr = { 0 };
-    struct ip_addr ipaddr = { htonl(0x0a000001) };
-    struct ip_addr netmask = { htonl(0xff000000) };
-    struct ip_addr gw = { 0 };
     struct netconn *listener;
     struct netconn *session;
     struct timeval tv;
     err_t rc;
 
     start_networking();
-    networking_set_addr(&ipaddr, &netmask, &gw);
+
+    if (0) {
+        struct ip_addr ipaddr = { htonl(0x0a000001) };
+        struct ip_addr netmask = { htonl(0xff000000) };
+        struct ip_addr gw = { 0 };
+        networking_set_addr(&ipaddr, &netmask, &gw);
+    }
 
     tprintk("Opening connection\n");
 
--- a/extras/mini-os/include/netfront.h Wed Mar 19 14:16:08 2008 +0000
+++ b/extras/mini-os/include/netfront.h Wed Mar 19 15:18:19 2008 +0000
@@ -3,7 +3,7 @@
 #include <lwip/netif.h>
 #endif
 struct netfront_dev;
-struct netfront_dev *init_netfront(char *nodename, void (*netif_rx)(unsigned 
char *data, int len), unsigned char rawmac[6]);
+struct netfront_dev *init_netfront(char *nodename, void (*netif_rx)(unsigned 
char *data, int len), unsigned char rawmac[6], char **ip);
 void netfront_xmit(struct netfront_dev *dev, unsigned char* data,int len);
 void shutdown_netfront(struct netfront_dev *dev);
 #ifdef HAVE_LIBC
--- a/extras/mini-os/kernel.c   Wed Mar 19 14:16:08 2008 +0000
+++ b/extras/mini-os/kernel.c   Wed Mar 19 15:18:19 2008 +0000
@@ -87,7 +87,7 @@
 
 static void netfront_thread(void *p)
 {
-    init_netfront(NULL, NULL, NULL);
+    init_netfront(NULL, NULL, NULL, NULL);
 }
 
 static struct blkfront_dev *blk_dev;
--- a/extras/mini-os/lwip-net.c Wed Mar 19 14:16:08 2008 +0000
+++ b/extras/mini-os/lwip-net.c Wed Mar 19 15:18:19 2008 +0000
@@ -339,10 +339,25 @@
   struct ip_addr ipaddr = { htonl(IF_IPADDR) };
   struct ip_addr netmask = { htonl(IF_NETMASK) };
   struct ip_addr gw = { 0 };
+  char *ip;
 
   tprintk("Waiting for network.\n");
 
-  dev = init_netfront(NULL, NULL, rawmac);
+  dev = init_netfront(NULL, NULL, rawmac, &ip);
+  
+  if (ip) {
+    ipaddr.addr = inet_addr(ip);
+    if (IN_CLASSA(ntohl(ipaddr.addr)))
+      netmask.addr = htonl(IN_CLASSA_NET);
+    else if (IN_CLASSB(ntohl(ipaddr.addr)))
+      netmask.addr = htonl(IN_CLASSB_NET);
+    else if (IN_CLASSC(ntohl(ipaddr.addr)))
+      netmask.addr = htonl(IN_CLASSC_NET);
+    else
+      tprintk("Strange IP %s, leaving netmask to 0.\n", ip);
+  }
+  tprintk("IP %x netmask %x gateway %x.\n",
+          ntohl(ipaddr.addr), ntohl(netmask.addr), ntohl(gw.addr));
   
   tprintk("TCP/IP bringup begins.\n");
   
--- a/extras/mini-os/netfront.c Wed Mar 19 14:16:08 2008 +0000
+++ b/extras/mini-os/netfront.c Wed Mar 19 15:18:19 2008 +0000
@@ -259,7 +259,7 @@
 }
 #endif
 
-struct netfront_dev *init_netfront(char *nodename, void 
(*thenetif_rx)(unsigned char* data, int len), unsigned char rawmac[6])
+struct netfront_dev *init_netfront(char *nodename, void 
(*thenetif_rx)(unsigned char* data, int len), unsigned char rawmac[6], char 
**ip)
 {
     xenbus_transaction_t xbt;
     char* err;
@@ -402,6 +402,11 @@
         xenbus_wait_for_value(path,"4");
 
         xenbus_unwatch_path(XBT_NIL, path);
+
+        if (ip) {
+            snprintf(path, sizeof(path), "%s/ip", dev->backend);
+            xenbus_read(XBT_NIL, path, ip);
+        }
     }
 
     printk("**************************\n");
@@ -427,7 +432,7 @@
 int netfront_tap_open(char *nodename) {
     struct netfront_dev *dev;
 
-    dev = init_netfront(nodename, NETIF_SELECT_RX, NULL);
+    dev = init_netfront(nodename, NETIF_SELECT_RX, NULL, NULL);
     if (!dev) {
        printk("TAP open failed\n");
        errno = EIO;

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>