[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] minios: Automatically set IP from XenStore information
# HG changeset patch # User Keir Fraser <keir.fraser@xxxxxxxxxx> # Date 1205943614 0 # Node ID 7fc9767f966aabaae6ea1c497b2aeb23c5387de5 # Parent 153b541c204c9eff9c38765d2a688b51d6d847d5 minios: Automatically set IP from XenStore information Signed-off-by: Samuel Thibault <samuel.thibault@xxxxxxxxxxxxx> --- extras/mini-os/daytime.c | 11 +++++++---- extras/mini-os/include/netfront.h | 2 +- extras/mini-os/kernel.c | 2 +- extras/mini-os/lwip-net.c | 17 ++++++++++++++++- extras/mini-os/netfront.c | 9 +++++++-- 5 files changed, 32 insertions(+), 9 deletions(-) diff -r 153b541c204c -r 7fc9767f966a extras/mini-os/daytime.c --- a/extras/mini-os/daytime.c Wed Mar 19 16:19:10 2008 +0000 +++ b/extras/mini-os/daytime.c Wed Mar 19 16:20:14 2008 +0000 @@ -15,16 +15,19 @@ void run_server(void *p) 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"); diff -r 153b541c204c -r 7fc9767f966a extras/mini-os/include/netfront.h --- a/extras/mini-os/include/netfront.h Wed Mar 19 16:19:10 2008 +0000 +++ b/extras/mini-os/include/netfront.h Wed Mar 19 16:20:14 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 diff -r 153b541c204c -r 7fc9767f966a extras/mini-os/kernel.c --- a/extras/mini-os/kernel.c Wed Mar 19 16:19:10 2008 +0000 +++ b/extras/mini-os/kernel.c Wed Mar 19 16:20:14 2008 +0000 @@ -87,7 +87,7 @@ static void periodic_thread(void *p) static void netfront_thread(void *p) { - init_netfront(NULL, NULL, NULL); + init_netfront(NULL, NULL, NULL, NULL); } static struct blkfront_dev *blk_dev; diff -r 153b541c204c -r 7fc9767f966a extras/mini-os/lwip-net.c --- a/extras/mini-os/lwip-net.c Wed Mar 19 16:19:10 2008 +0000 +++ b/extras/mini-os/lwip-net.c Wed Mar 19 16:20:14 2008 +0000 @@ -339,10 +339,25 @@ void start_networking(void) 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"); diff -r 153b541c204c -r 7fc9767f966a extras/mini-os/netfront.c --- a/extras/mini-os/netfront.c Wed Mar 19 16:19:10 2008 +0000 +++ b/extras/mini-os/netfront.c Wed Mar 19 16:20:14 2008 +0000 @@ -259,7 +259,7 @@ void netfront_select_handler(evtchn_port } #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 @@ done: 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) { 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-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |