mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 10:40:03 +01:00
minios: Automatically set IP from XenStore information
Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
This commit is contained in:
1 parent
6fef410021
commit
df4e524d8d
5 files changed
+32
-9
No files matched your search
@@ -15,16 +15,19 @@ static char message[29];
|
||||
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");
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -259,7 +259,7 @@ void netfront_select_handler(evtchn_port_t port, struct pt_regs *regs, void *dat
|
||||
}
|
||||
#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 @@ done:
|
||||
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;
|
||||
|
||||