From: Samuel Thibault <samuel.thibault@eu.citrix.com>
To: xen-devel@lists.xensource.com
Subject: Re: [PATCH] minios: Automatically set IP from XenStore information
Date: Wed, 19 Mar 2008 16:11:45 +0000 [thread overview]
Message-ID: <20080319161145.GB9372@implementation.uk.xensource.com> (raw)
In-Reply-To: <20080319152142.GX4333@implementation.uk.xensource.com>
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@eu.citrix.com>
--- 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;
prev parent reply other threads:[~2008-03-19 16:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-19 15:21 [PATCH] minios: Automatically set IP from XenStore information Samuel Thibault
2008-03-19 16:11 ` Samuel Thibault [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080319161145.GB9372@implementation.uk.xensource.com \
--to=samuel.thibault@eu.citrix.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.