ia64/xen-unstable

changeset 17275:7fc9767f966a

minios: Automatically set IP from XenStore information

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Mar 19 16:20:14 2008 +0000 (2008-03-19)
parents 153b541c204c
children 851dc6b70494
files extras/mini-os/daytime.c extras/mini-os/include/netfront.h extras/mini-os/kernel.c extras/mini-os/lwip-net.c extras/mini-os/netfront.c
line diff
     1.1 --- a/extras/mini-os/daytime.c	Wed Mar 19 16:19:10 2008 +0000
     1.2 +++ b/extras/mini-os/daytime.c	Wed Mar 19 16:20:14 2008 +0000
     1.3 @@ -15,16 +15,19 @@ static char message[29];
     1.4  void run_server(void *p)
     1.5  {
     1.6      struct ip_addr listenaddr = { 0 };
     1.7 -    struct ip_addr ipaddr = { htonl(0x0a000001) };
     1.8 -    struct ip_addr netmask = { htonl(0xff000000) };
     1.9 -    struct ip_addr gw = { 0 };
    1.10      struct netconn *listener;
    1.11      struct netconn *session;
    1.12      struct timeval tv;
    1.13      err_t rc;
    1.14  
    1.15      start_networking();
    1.16 -    networking_set_addr(&ipaddr, &netmask, &gw);
    1.17 +
    1.18 +    if (0) {
    1.19 +        struct ip_addr ipaddr = { htonl(0x0a000001) };
    1.20 +        struct ip_addr netmask = { htonl(0xff000000) };
    1.21 +        struct ip_addr gw = { 0 };
    1.22 +        networking_set_addr(&ipaddr, &netmask, &gw);
    1.23 +    }
    1.24  
    1.25      tprintk("Opening connection\n");
    1.26  
     2.1 --- a/extras/mini-os/include/netfront.h	Wed Mar 19 16:19:10 2008 +0000
     2.2 +++ b/extras/mini-os/include/netfront.h	Wed Mar 19 16:20:14 2008 +0000
     2.3 @@ -3,7 +3,7 @@
     2.4  #include <lwip/netif.h>
     2.5  #endif
     2.6  struct netfront_dev;
     2.7 -struct netfront_dev *init_netfront(char *nodename, void (*netif_rx)(unsigned char *data, int len), unsigned char rawmac[6]);
     2.8 +struct netfront_dev *init_netfront(char *nodename, void (*netif_rx)(unsigned char *data, int len), unsigned char rawmac[6], char **ip);
     2.9  void netfront_xmit(struct netfront_dev *dev, unsigned char* data,int len);
    2.10  void shutdown_netfront(struct netfront_dev *dev);
    2.11  #ifdef HAVE_LIBC
     3.1 --- a/extras/mini-os/kernel.c	Wed Mar 19 16:19:10 2008 +0000
     3.2 +++ b/extras/mini-os/kernel.c	Wed Mar 19 16:20:14 2008 +0000
     3.3 @@ -87,7 +87,7 @@ static void periodic_thread(void *p)
     3.4  
     3.5  static void netfront_thread(void *p)
     3.6  {
     3.7 -    init_netfront(NULL, NULL, NULL);
     3.8 +    init_netfront(NULL, NULL, NULL, NULL);
     3.9  }
    3.10  
    3.11  static struct blkfront_dev *blk_dev;
     4.1 --- a/extras/mini-os/lwip-net.c	Wed Mar 19 16:19:10 2008 +0000
     4.2 +++ b/extras/mini-os/lwip-net.c	Wed Mar 19 16:20:14 2008 +0000
     4.3 @@ -339,10 +339,25 @@ void start_networking(void)
     4.4    struct ip_addr ipaddr = { htonl(IF_IPADDR) };
     4.5    struct ip_addr netmask = { htonl(IF_NETMASK) };
     4.6    struct ip_addr gw = { 0 };
     4.7 +  char *ip;
     4.8  
     4.9    tprintk("Waiting for network.\n");
    4.10  
    4.11 -  dev = init_netfront(NULL, NULL, rawmac);
    4.12 +  dev = init_netfront(NULL, NULL, rawmac, &ip);
    4.13 +  
    4.14 +  if (ip) {
    4.15 +    ipaddr.addr = inet_addr(ip);
    4.16 +    if (IN_CLASSA(ntohl(ipaddr.addr)))
    4.17 +      netmask.addr = htonl(IN_CLASSA_NET);
    4.18 +    else if (IN_CLASSB(ntohl(ipaddr.addr)))
    4.19 +      netmask.addr = htonl(IN_CLASSB_NET);
    4.20 +    else if (IN_CLASSC(ntohl(ipaddr.addr)))
    4.21 +      netmask.addr = htonl(IN_CLASSC_NET);
    4.22 +    else
    4.23 +      tprintk("Strange IP %s, leaving netmask to 0.\n", ip);
    4.24 +  }
    4.25 +  tprintk("IP %x netmask %x gateway %x.\n",
    4.26 +          ntohl(ipaddr.addr), ntohl(netmask.addr), ntohl(gw.addr));
    4.27    
    4.28    tprintk("TCP/IP bringup begins.\n");
    4.29    
     5.1 --- a/extras/mini-os/netfront.c	Wed Mar 19 16:19:10 2008 +0000
     5.2 +++ b/extras/mini-os/netfront.c	Wed Mar 19 16:20:14 2008 +0000
     5.3 @@ -259,7 +259,7 @@ void netfront_select_handler(evtchn_port
     5.4  }
     5.5  #endif
     5.6  
     5.7 -struct netfront_dev *init_netfront(char *nodename, void (*thenetif_rx)(unsigned char* data, int len), unsigned char rawmac[6])
     5.8 +struct netfront_dev *init_netfront(char *nodename, void (*thenetif_rx)(unsigned char* data, int len), unsigned char rawmac[6], char **ip)
     5.9  {
    5.10      xenbus_transaction_t xbt;
    5.11      char* err;
    5.12 @@ -402,6 +402,11 @@ done:
    5.13          xenbus_wait_for_value(path,"4");
    5.14  
    5.15          xenbus_unwatch_path(XBT_NIL, path);
    5.16 +
    5.17 +        if (ip) {
    5.18 +            snprintf(path, sizeof(path), "%s/ip", dev->backend);
    5.19 +            xenbus_read(XBT_NIL, path, ip);
    5.20 +        }
    5.21      }
    5.22  
    5.23      printk("**************************\n");
    5.24 @@ -427,7 +432,7 @@ done:
    5.25  int netfront_tap_open(char *nodename) {
    5.26      struct netfront_dev *dev;
    5.27  
    5.28 -    dev = init_netfront(nodename, NETIF_SELECT_RX, NULL);
    5.29 +    dev = init_netfront(nodename, NETIF_SELECT_RX, NULL, NULL);
    5.30      if (!dev) {
    5.31  	printk("TAP open failed\n");
    5.32  	errno = EIO;