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

Re: [Minios-devel] [UNIKRAFT/LWIP PATCH] Interface configuration and Network API integration



This patch must be applied after Unikraft Network API is upstreamed.

On Tue, Jul 24, 2018, 19:31 Razvan Cojocaru <razvan.cojocaru93@xxxxxxxxx> wrote:
Set up the lwIP stack to use uknetdev API. Added glue code
to configure network devices, configure network interfaces
and start the network subsystem.
Can obtain IP information either from the driver or via DHCP.
Can be used in polling mode or with RX interrupt callback.

The initialization functions init_netdev() and init_netif()
will be called from ukboot at the moment, but in the future
should be used in an init table.

Signed-off-by: Razvan Cojocaru <razvan.cojocaru93@xxxxxxxxx>
---
 Config.uk            |  15 ++-
 Makefile.uk          |   1 +
 include/arch/cc.h    |   2 +-
 include/lwip-netif.h |   7 +
 include/lwipopts.h   |  74 +++++++---
 init.c               |  25 ++--
 lwip-netif.c         | 371 +++++++++++++++++++++++++++++++++++++++++++++++++++
 socket_glue.c        |   2 +-
 8 files changed, 465 insertions(+), 32 deletions(-)
 create mode 100644 include/lwip-netif.h
 create mode 100644 lwip-netif.c

diff --git a/Config.uk b/Config.uk
index 4fcc6dc..3884ae2 100644
--- a/Config.uk
+++ b/Config.uk
@@ -11,7 +11,7 @@ menuconfig LIBLWIP
        select LIBUKSWRAND
        select LIBUKSCHED
        select HAVE_NW_STACK
-
+    select LIBUKNETDEV
        select LIBLWIP_HEAPONLY

 if LIBLWIP
@@ -26,6 +26,17 @@ config LWIP_HEAP
 #      bool "Memory pools"
 endchoice

+choice
+       prompt "Receive mode"
+       default LWIP_INTERRUPT
+
+config LWIP_INTERRUPT
+       bool "Interrupt-based driver"
+
+config LWIP_POLLING
+       bool "Polling-mode driver"
+endchoice
+
 config LWIP_IPV4
        bool "IPv4"
        default y
@@ -84,7 +95,7 @@ config LWIP_SNMP
 config LWIP_DHCP
        bool "DHCP client"
        depends on LWIP_IPV4
-       default n
+       default y
        help
                Query device IP address from DHCP server on network

diff --git a/Makefile.uk b/Makefile.uk
index df54787..1922640 100644
--- a/Makefile.uk
+++ b/Makefile.uk
@@ -87,6 +87,7 @@ LIBLWIP_SRCS-y += $(LIBLWIP_BASE)/init.c|unikraft
 LIBLWIP_SRCS-y += $(LIBLWIP_BASE)/threads.c|unikraft
 LIBLWIP_SRCS-y += $(LIBLWIP_BASE)/time.c|unikraft
 LIBLWIP_SRCS-y += $(LIBLWIP_BASE)/socket_glue.c|unikraft
+LIBLWIP_SRCS-y += $(LIBLWIP_BASE)/lwip-netif.c|unikraft
 LIBLWIP_SRCS-y += $(LIBLWIP_EXTRACTED)/core/init.c
 LIBLWIP_SRCS-y += $(LIBLWIP_EXTRACTED)/core/def.c
 LIBLWIP_SRCS-y += $(LIBLWIP_EXTRACTED)/core/inet_chksum.c
diff --git a/include/arch/cc.h b/include/arch/cc.h
index 099c4ac..82b2318 100644
--- a/include/arch/cc.h
+++ b/include/arch/cc.h
@@ -51,7 +51,7 @@

 /* 32 bit checksum calculation */
 #define LWIP_CHKSUM_ALGORITHM 3
-#define ETH_PAD_SIZE 2
+#define ETH_PAD_SIZE 0

 /* rand */
 #define LWIP_RAND() uk_swrand_randr()
diff --git a/include/lwip-netif.h b/include/lwip-netif.h
new file mode 100644
index 0000000..31d7b72
--- /dev/null
+++ b/include/lwip-netif.h
@@ -0,0 +1,7 @@
+#ifndef __LWIP_NETIF_H__
+#define __LWIP_NETIF_H__
+
+void init_netdev(void);
+void init_netif(void);
+
+#endif /*__LWIP_NETIF_H__ */
diff --git a/include/lwipopts.h b/include/lwipopts.h
index c6cc0bc..27626f2 100644
--- a/include/lwipopts.h
+++ b/include/lwipopts.h
@@ -12,8 +12,10 @@
 #include <inttypes.h>
 #include <uk/config.h>

+
 #define SO_REUSE 1

+
 /*
  * General options/System settings
  */
@@ -73,12 +75,14 @@ void sys_free(void *ptr);
 /*
  * Most features are selected by uk/config.h
  */
+#define LWIP_NETIF_STATUS_CALLBACK 1
 #define LWIP_NETIF_REMOVE_CALLBACK 1
 #define LWIP_TIMEVAL_PRIVATE 0

 /* disable BSD-style socket - layer is provided by libc */
 #define LWIP_COMPAT_SOCKETS 0

+
 /*
  * Thread options
  */
@@ -94,22 +98,30 @@ void sys_free(void *ptr);
 #define MEMP_NUM_ARP_QUEUE 256
 #define ETHARP_SUPPORT_STATIC_ENTRIES 1

+
+/*
+ * IP version select
+ */
+#define LWIP_IPV4 CONFIG_LWIP_IPV4
+#define LWIP_IPV6 CONFIG_LWIP_IPV6
+
+
 /*
  * UDP options
  */
+#define LWIP_UDP CONFIG_LWIP_UDP
 //#define MEMP_NUM_UDP_PCB 16

+
 /*
  * TCP options
  */
+#define LWIP_TCP CONFIG_LWIP_TCP
 #define TCP_MSS CONFIG_LWIP_TCP_MSS

-
 #define TCP_CALCULATE_EFF_SEND_MSS 1
 #define IP_FRAG 0

-
-
 #if CONFIG_LWIP_WND_SCALE
 /*
  * Maximum window and scaling factor
@@ -128,7 +140,7 @@ void sys_free(void *ptr);

 #else /* CONFIG_LWIP_WND_SCALE */
 /*
- * Options when no window scaling  is enabled
+ * Options when no window scaling is enabled
  */
 #define TCP_WND 32766 /* Ideally, TCP_WND should be link bandwidth multiplied by rtt */
 #define TCP_SND_BUF (TCP_WND + (2 * TCP_MSS))
@@ -143,13 +155,6 @@ void sys_free(void *ptr);
 #define MEMP_NUM_TCP_PCB CONFIG_LWIP_NUM_TCPCON /* max num of sim. TCP connections */
 #define MEMP_NUM_TCP_PCB_LISTEN 32 /* max num of sim. TCP listeners */

-/*
- * DNS options
- */
-#define DNS_MAX_SERVERS CONFIG_LWIP_DNS_MAX_SERVERS
-#define DNS_TABLE_SIZE CONFIG_LWIP_DNS_TABLE_SIZE
-#define DNS_LOCAL_HOST_LIST 1
-#define DNS_LOCAL_HOSTLIST_IS_DYNAMIC 1

 /*
  * Pool options
@@ -165,6 +170,7 @@ void sys_free(void *ptr);
 #define MEMP_NUM_PBUF ((MEMP_NUM_TCP_PCB * (TCP_SND_QUEUELEN)) / 2)
 #endif

+
 /*
  * Checksum options
  */
@@ -185,6 +191,38 @@ void sys_free(void *ptr);
 #define CHECKSUM_CHECK_ICMP6 CONFIG_LWIP_RXCHECKSUM
 #define CHECKSUM_CHECK_TCP CONFIG_LWIP_RXCHECKSUM

+
+/*
+ * Services
+ */
+#define LWIP_ICMP CONFIG_LWIP_ICMP
+#define LWIP_IGMP CONFIG_LWIP_IGMP
+#define LWIP_SNMP CONFIG_LWIP_SNMP
+#define LWIP_DHCP CONFIG_LWIP_DHCP
+#define LWIP_AUTOIP CONFIG_LWIP_AUTOIP
+
+#ifdef CONFIG_LWIP_DNS
+/*
+ * DNS options
+ */
+#define LWIP_DNS 1
+#define DNS_MAX_SERVERS CONFIG_LWIP_DNS_MAX_SERVERS
+#define DNS_TABLE_SIZE CONFIG_LWIP_DNS_TABLE_SIZE
+#define DNS_LOCAL_HOST_LIST 1
+#define DNS_LOCAL_HOSTLIST_IS_DYNAMIC 1
+#endif
+
+#define LWIP_PPP CONFIG_LWIP_PPP
+#define LWIP_SLIP CONFIG_LWIP_SLIP
+#define LWIP_6LOWPAN CONFIG_LWIP_6LOWPAN
+#define LWIP_SOCKET CONFIG_LWIP_SOCKET
+
+
+/*
+ * Debug options
+ */
+#define LWIP_DEBUG CONFIG_LWIP_DEBUG
+
 #ifdef CONFIG_LWIP_MAINLOOP_DEBUG
 #define IP_DEBUG         LWIP_DBG_ON
 #define TCPIP_DEBUG      LWIP_DBG_ON
@@ -213,8 +251,8 @@ void sys_free(void *ptr);
 #define TCP_WND_DEBUG    LWIP_DBG_ON
 #define TCP_RST_DEBUG    LWIP_DBG_ON
 #define TCP_QLEN_DEBUG   LWIP_DBG_ON
-//#define TCP_OUTPUT_DEBUG LWIP_DBG_ON
-//#define TCP_INPUT_DEBUG LWIP_DBG_ON
+#define TCP_OUTPUT_DEBUG LWIP_DBG_ON
+#define TCP_INPUT_DEBUG LWIP_DBG_ON
 #if LWIP_CHECKSUM_ON_COPY
 #define TCP_CHECKSUM_ON_COPY_SANITY_CHECK 1
 #endif
@@ -225,16 +263,16 @@ void sys_free(void *ptr);
 #define PBUF_DEBUG       LWIP_DBG_ON
 #define MEM_DEBUG        LWIP_DBG_ON
 #define MEMP_DEBUG       LWIP_DBG_ON
-#endif /* LWIP_SYS_DEBUG */
+#endif /* CONFIG_LWIP_SYS_DEBUG */

-#ifdef LWIP_API_DEBUG
+#ifdef CONFIG_LWIP_API_DEBUG
 #define SOCKETS_DEBUG    LWIP_DBG_ON
 #define RAW_DEBUG        LWIP_DBG_ON
 #define API_MSG_DEBUG    LWIP_DBG_ON
 #define API_LIB_DEBUG    LWIP_DBG_ON
-#endif /* LWIP_API_DEBUG */
+#endif /* CONFIG_LWIP_API_DEBUG */

-#ifdef LWIP_SERVICE_DEBUG
+#ifdef CONFIG_LWIP_SERVICE_DEBUG
 #define ETHARP_DEBUG     LWIP_DBG_ON
 #define DNS_DEBUG        LWIP_DBG_ON
 #define AUTOIP_DEBUG     LWIP_DBG_ON
@@ -245,6 +283,6 @@ void sys_free(void *ptr);
 #define SNMP_MIB_DEBUG   LWIP_DBG_ON
 #define PPP_DEBUG        LWIP_DBG_ON
 #define SLIP_DEBUG       LWIP_DBG_ON
-#endif /* LWIP_SERVICE_DEBUG */
+#endif /* CONFIG_LWIP_SERVICE_DEBUG */

 #endif /* __LWIP_LWIPOPTS_H__ */
diff --git a/init.c b/init.c
index 0326662..2c2b761 100644
--- a/init.c
+++ b/init.c
@@ -2,6 +2,7 @@
 #include <lwip/tcpip.h>
 #include <lwip/init.h>
 #include <uk/plat/ctors.h>
+#include <lwip-netif.h>

 /* This function is called before the any other sys_arch-function is
  * called and is meant to be used to initialize anything that has to
@@ -12,16 +13,20 @@ void sys_init(void)
     return;
 }

-/*
- * This function initializing the lwip network stack
- *
- */
-int liblwip_init(void)
+/* Initialize and configure the network devices */
+int liblwip_init_netdev(void)
 {
-#if CONFIG_LIBUKSCHED
-        tcpip_init(NULL, NULL);
-#else
-        lwip_init();
-#endif /* CONFIG_LIBUKSCHED */
+       init_netdev();
+       /* TODO add some error handling */
+       return 0;
+}
+
+/* Initialize the lwip network interfaces.
+ * Set up ip params, set interfaces as UP.
+ * Must be called after liblwip_init_netdev */
+int liblwip_init_netif(void)
+{
+       init_netif();
+       /* TODO add some error handling */
        return 0;
 }
diff --git a/lwip-netif.c b/lwip-netif.c
new file mode 100644
index 0000000..72389a0
--- /dev/null
+++ b/lwip-netif.c
@@ -0,0 +1,371 @@
+#include <lwip-netif.h>
+#include <stdio.h>
+#include <string.h>
+#include <uk/print.h>
+#include <uk/netdev.h>
+#include <uk/thread.h>
+#include <uk/semaphore.h>
+#include <lwip/dhcp.h>
+#include <lwip/netif.h>
+#include <lwip/tcpip.h>
+#include <lwip/ip_addr.h>
+#include <lwip/etharp.h>
+
+/* Define those to better describe your network interface. */
+#define IFNAME0 'e'
+#define IFNAME1 'n'
+
+#define MAX_INTERFACES 1
+
+/* Network interfaces and netdevs are associated 1:1 */
+static struct uk_netdev *netdev[MAX_INTERFACES];
+static struct netif *netif_array[MAX_INTERFACES];
+
+/**
+ * Is called from the lwip thread when finishing set up.
+ */
+struct uk_semaphore tcpip_is_up[MAX_INTERFACES];
+static void tcpip_bringup_finished(void *p)
+{
+       struct netif *netif = (struct netif *)p;
+
+       uk_printd(DLVL_INFO, "TCP/IP bring up ends. Netif%d\n", netif->num);
+       uk_semaphore_up(&tcpip_is_up[netif->num]);
+}
+
+/**
+ * Should do the actual transmission of the packet. The packet is
+ * contained in the pbuf that is passed to the function. This pbuf
+ * might be chained.
+ */
+static err_t low_level_output(struct netif *netif, struct pbuf *p)
+{
+       struct uk_netdev *dev;
+       struct uk_netdev_mbuf mbuf;
+
+       dev = netdev[netif->num];
+       if (!dev)
+               return ERR_OK;
+#ifdef ETH_PAD_SIZE
+       pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
+#endif
+
+       /* Send the data from the pbuf to the interface, one pbuf at a
+        * time. The size of the data in each pbuf is kept in the ->len
+        * variable.
+        */
+       if (!p->next) {
+               /* Only one fragment, can send it directly */
+               mbuf.payload = p->payload;
+               mbuf.len = p->len;
+               uk_netdev_tx(dev, 0, &mbuf);
+       } else {
+               unsigned char data[p->tot_len], *cur;
+               struct pbuf *q;
+
+               for (q = p, cur = data; q != NULL; cur += q->len, q = q->next)
+                       memcpy(cur, q->payload, q->len);
+               mbuf.payload = data;
+               mbuf.len = p->tot_len;
+               uk_netdev_tx(dev, 0, &mbuf);
+       }
+
+#if ETH_PAD_SIZE
+       pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
+#endif
+
+       LINK_STATS_INC(link.xmit);
+
+       return ERR_OK;
+}
+
+/**
+ * This function should be called when a packet is ready to be read
+ * from the interface.
+ * Pulls received packets into a pbuf queue for the low_level_input()
+ * function to pass up to lwIP.
+ */
+static void netfront_input(struct netif *netif, unsigned char *data, u32_t len)
+{
+       struct pbuf *p = NULL;
+
+       if (len >= 0) {
+               p = pbuf_alloc(PBUF_RAW, (u16_t) len, PBUF_POOL);
+               if (p != NULL) {
+#if ETH_PAD_SIZE
+                       pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
+#endif
+                       pbuf_take(p, data, (u16_t) len);
+               } else {
+                       LWIP_DEBUGF(NETIF_DEBUG, ("could not allocate pbuf\n"));
+               }
+       }
+       if ((p != NULL) && (netif->input(p, netif) != ERR_OK)) {
+               LWIP_DEBUGF(NETIF_DEBUG, ("netif input error\n"));
+               pbuf_free(p);
+       }
+#if ETH_PAD_SIZE
+       else {
+               pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
+       }
+#endif
+}
+
+#ifdef CONFIG_LWIP_POLLING
+/**
+ * Used in the driver polling mode.
+ * Must be run on a dedicated thread.
+ *
+ * @param arg
+ *     The network interface on which to send packets up to the stack
+ */
+void poll_driver(void *arg)
+{
+       struct netif *netif;
+       struct uk_netdev *dev;
+       struct uk_netdev_mbuf mbuf;
+
+       netif = (struct netif *)arg;
+       dev = netdev[netif->num];
+       mbuf.payload = malloc(dev->data->mtu);
+
+       while (1) {
+               uk_sched_yield();
+               if (uk_netdev_rx(dev, 0, &mbuf) > 0)
+                       netfront_input(netif, mbuf.payload, mbuf.len);
+       }
+}
+#endif
+
+#ifdef CONFIG_LWIP_INTERRUPT
+void *packet_buffer;
+
+/**
+ * Used by the driver interrupt callback.
+ */
+void netif_rx(struct uk_netdev *dev, uint16_t queue)
+{
+       uint16_t id = dev->data->id;
+
+       if (netif_array[id] != NULL && (netif_array[id]->flags & NETIF_FLAG_UP)) {
+               struct uk_netdev_mbuf mbuf;
+
+               mbuf.payload = packet_buffer;
+               if (uk_netdev_rx(dev, 0, &mbuf) > 0)
+                       netfront_input(netif_array[id], mbuf.payload, mbuf.len);
+       }
+}
+#endif
+
+/**
+ * Should be called at the beginning of the program to set up the
+ * network interface.
+ * Sent as parameter and called by netif_add().
+ */
+err_t netif_netfront_init(struct netif *netif)
+{
+       unsigned char *mac = netif->state;
+
+       netif->name[0] = IFNAME0;
+       netif->name[1] = IFNAME1;
+       netif->output = etharp_output;
+       netif->linkoutput = low_level_output;
+
+       /* set MAC hardware address */
+       netif->hwaddr_len = 6;
+       netif->hwaddr[0] = mac[0];
+       netif->hwaddr[1] = mac[1];
+       netif->hwaddr[2] = mac[2];
+       netif->hwaddr[3] = mac[3];
+       netif->hwaddr[4] = mac[4];
+       netif->hwaddr[5] = mac[5];
+
+       /* No interesting per-interface state */
+       netif->state = NULL;
+
+       /* maximum transfer unit */
+       netif->mtu = netdev[netif->num]->data->mtu;
+
+       /* broadcast capability */
+       netif->flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP |
+                       NETIF_FLAG_LINK_UP | NETIF_FLAG_ETHERNET;
+
+       return ERR_OK;
+}
+
+/**
+ * Initialization function, configures one uk_netdev.
+ */
+void setup_netdev(uint8_t num)
+{
+       netdev[num] = uk_netdev_get(num);
+       if (uk_netdev_configure(netdev[num], NULL) < 0) {
+               uk_printd(DLVL_ERR, "Can not configure netdev%d\n", num);
+               return;
+       }
+
+       struct uk_netdev_rxqueue_conf rxconf = {
+#ifdef CONFIG_LWIP_INTERRUPT
+                       .rx_cb = netif_rx,
+#elif CONFIG_LWIP_POLLING
+                       .rx_cb = NULL,
+#endif
+       };
+       uk_netdev_rx_queue_setup(netdev[num], 0, &rxconf);
+       uk_netdev_tx_queue_setup(netdev[num], 0, NULL);
+       uk_netdev_start(netdev[num]);
+}
+
+static void netif_status(struct netif *netif)
+{
+       struct uk_netdev *n = NULL;
+       int i;
+
+       for (i = 0; i < uk_netdev_count(); i++) {
+               if (netif_array[i] == netif) {
+                       n = netdev[i];
+                       break;
+               }
+       }
+
+       UK_ASSERT(n != NULL);
+
+       uk_printd(DLVL_INFO, "IP address of interface %s set to %u.%u.%u.%u\n",
+               netif->name,
+           ip4_addr1_16(netif_ip4_addr(netif)),
+           ip4_addr2_16(netif_ip4_addr(netif)),
+           ip4_addr3_16(netif_ip4_addr(netif)),
+           ip4_addr4_16(netif_ip4_addr(netif)));
+}
+
+int get_driver_econf(struct netif *netif, struct uk_netdev *uk_netdev)
+{
+       const char *ip_addr_str, *ip_mask_str, *ip_gw_str;
+       ip4_addr_t *ipaddr = mem_malloc(sizeof(ip4_addr_t));
+       ip4_addr_t *netmaskaddr = mem_malloc(sizeof(ip4_addr_t));
+       ip4_addr_t *gwaddr = mem_malloc(sizeof(ip4_addr_t));
+
+       ip_addr_str = uk_netdev_extra_conf_get(uk_netdev, IPv4ADDR_STR);
+       if (ip_addr_str == NULL)
+               goto no_econf;
+       ipaddr->addr = ipaddr_addr(ip_addr_str);
+       if (ipaddr->addr == IPADDR_NONE)
+               goto no_econf;
+       netif_set_ipaddr(netif, ipaddr);
+
+       ip_mask_str = uk_netdev_extra_conf_get(uk_netdev, IPv4MASK_STR);
+       if (ip_mask_str == NULL)
+               goto no_econf;
+       netmaskaddr->addr = ipaddr_addr(ip_mask_str);
+       if (netmaskaddr->addr == IPADDR_NONE)
+               goto no_econf;
+       netif_set_netmask(netif, netmaskaddr);
+
+       ip_gw_str = uk_netdev_extra_conf_get(uk_netdev, IPv4GW_STR);
+       if (ip_gw_str == NULL)
+               goto no_econf;
+       gwaddr->addr = ipaddr_addr(ip_gw_str);
+       if (gwaddr->addr == IPADDR_NONE)
+               goto no_econf;
+       netif_set_gw(netif, gwaddr);
+
+       return 0;
+
+no_econf:
+       free(ipaddr);
+       free(netmaskaddr);
+       free(gwaddr);
+       return -1;
+}
+
+/**
+ * Initialization function, configures one lwip network interface.
+ * Configures a static IP address if provided by the driver or starts a DHCP
+ * client otherwise.
+ */
+void setup_netif(uint8_t num)
+{
+       ip4_addr_t *ipaddr = mem_malloc(sizeof(ip4_addr_t));
+       ip4_addr_t *netmaskaddr = mem_malloc(sizeof(ip4_addr_t));
+       ip4_addr_t *gwaddr = mem_malloc(sizeof(ip4_addr_t));
+
+       netif_array[num] = malloc(sizeof(struct netif));
+       memset(netif_array[num], 0, sizeof(struct netif));
+       netif_array[num]->num = num;
+
+       uk_printk("TCP/IP bring up begins.\n");
+
+       uk_semaphore_init(&tcpip_is_up[num], 0);
+       tcpip_init(tcpip_bringup_finished, netif_array[num]);
+
+       /* NULL ip config will be filled in later */
+       if (netif_add(netif_array[num], ipaddr, netmaskaddr, gwaddr,
+                         netdev[num]->data->mac_addr.addr_bytes,
+                         netif_netfront_init, tcpip_input) == NULL) {
+               uk_printd(DLVL_ERR, "Error adding netif\n");
+       }
+       netif_set_up(netif_array[num]);
+
+       if (get_driver_econf(netif_array[num], netdev[num]) < 0) {
+               uk_printd(DLVL_INFO, "No IP from driver, starting DHCP\n");
+
+               netif_array[num]->status_callback = netif_status;
+
+               int err = dhcp_start(netif_array[num]);
+
+               if (err != ERR_OK)
+                       uk_printd(DLVL_ERR, "Error starting DHCP client. ERR %d\n", err);
+       }
+
+       uk_semaphore_down(&tcpip_is_up[num]);
+#ifdef CONFIG_LWIP_INTERRUPT
+               packet_buffer = malloc(uk_netdev_mtu_get(netdev[num]));
+               uk_netdev_rx_enable_intr(netdev[num], 0);
+#elif CONFIG_LWIP_POLLING
+               uk_printd(DLVL_INFO, "Starting driver poll\n");
+               uk_thread_create("poll_driver", poll_driver, netif_array[num]);
+#endif
+}
+
+/**
+ * Initialization utility function to configure all the network devices.
+ * Depending on the rx mode chosen, configures rx interrupt callback or starts
+ * the polling thread.
+ */
+void init_netdev(void)
+{
+       uint8_t i;
+
+       uk_printd(DLVL_INFO, "Setting up network devices.\n");
+
+       for (i = 0; i < uk_netdev_count(); i++)
+               setup_netdev(i);
+}
+
+/**
+ * Initialization utility function to setup the lwip network interfaces.
+ * Configures IP parameters and associates lwip netif with unikraft netdev.
+ */
+void init_netif(void)
+{
+       uint8_t i;
+       const struct uk_hwaddr *mac;
+
+       uk_printd(DLVL_INFO, "Setting up network interfaces.\n");
+
+       for (i = 0; i < uk_netdev_count(); i++)
+               setup_netif(i);
+
+       /* Set the first interface as the default route */
+       netif_set_default(netif_array[0]);
+
+       for (i = 0; i < uk_netdev_count(); i++) {
+               mac = uk_netdev_mac_addr_get(netdev[i]);
+               uk_printd(DLVL_INFO, "NETIF%d mac: %hhx:%hhx:%hhx:%hhx:%hhx:%hhx\n",
+                               i, mac->addr_bytes[0], mac->addr_bytes[1],
+                               mac->addr_bytes[2], mac->addr_bytes[3],
+                               mac->addr_bytes[4], mac->addr_bytes[5]);
+       }
+
+       uk_printd(DLVL_INFO, "Network is ready.\n");
+}
diff --git a/socket_glue.c b/socket_glue.c
index e7dc33c..654ab24 100644
--- a/socket_glue.c
+++ b/socket_glue.c
@@ -109,7 +109,7 @@ static ssize_t sock_net_read(struct vfscore_file *vfscore_file, void *buf,
        struct sock_net_file *file = NULL;
        file = __containerof(vfscore_file, struct sock_net_file,
                                vfscore_file);
-       uk_printd(DLVL_EXTRA, NET_LIB_NAME": write %d (%x):%s\n",
+       uk_printd(DLVL_EXTRA, NET_LIB_NAME": read %d (%x):%s\n",
                        file->vfscore_file.fd, file->sock_fd, (char *) buf);
        ret = lwip_read(file->sock_fd, buf, count);
        return ret;
--
2.7.4

_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

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