[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



Oops, sorry, it was against the stubdom tree, here is a fixed version
(basically the same, without Makefile change)

minios: Automatically set IP from XenStore information

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

--- 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


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.