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

Re: [Minios-devel] [UNIKRAFT/LIBLWIP PATCH 2/5] Update to lwIP 2.1.2



Hello,

This patch seems functionally fine.

Reviewed-by: Sharan Santhanam <sharan.santhanam@xxxxxxxxx>

There are a couple minor comment we need to address.

Thanks & Regards
Sharan

On 2/8/19 12:00 AM, Simon Kuenzer wrote:
Update lwIP from 2.0.3 to the latest relase 2.1.2 from Dec 2018. We
transform the rather beta state of our glue library to a more stable
implementation based on the latest staging branch of Unikraft towards
release 0.3.

This commit provides the following features as selectable options from
lwIP:
- Two operation modes: "threaded" or as (part of a) "mainloop"
- IPv4 support
- Experimental IPv6 support (incomplete)
- Protocols: UDP, TCP, ICMP, IGMP, SNMP
- DNS resolver
- DHCPv4 client
- Socket API

Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
Signed-off-by: Florian Schmidt <florian.schmidt@xxxxxxxxx>
Signed-off-by: Yuri Volchkov <yuri.volchkov@xxxxxxxxx>
---
  Config.uk                  |  95 +++++++------
  Makefile.uk                |  77 ++--------
  alloc.c                    |  33 +++++
  include/arch/cc.h          |  33 ++---
  include/arch/sys_arch.h    |  41 +++++-
  include/arpa/inet.h        |   1 +
  include/lwipopts.h         | 280 +++++++++++++++++++++++++------------
  include/net/if.h           |   1 +
  include/netdb.h            |   1 +
  include/sys/socket.h       |  67 ++++++++-
  init.c                     |  89 ++++++++++--
  mailbox.c                  | 155 +++++++++++++-------
  mutex.c                    |  43 +++++-
  semaphore.c                |  58 ++++++--
  socket_glue.c => sockets.c | 213 ++++++++++++++++++----------
  threads.c                  |  52 +++++--
  time.c                     |  33 +++++
  17 files changed, 892 insertions(+), 380 deletions(-)
  create mode 100644 include/arpa/inet.h
  create mode 100644 include/net/if.h
  create mode 100644 include/netdb.h
  rename socket_glue.c => sockets.c (60%)

diff --git a/Config.uk b/Config.uk
index 4fcc6dc..dce5607 100644
--- a/Config.uk
+++ b/Config.uk
@@ -3,46 +3,54 @@ menuconfig LIBLWIP
        default n
        select LIBNOLIBC if !HAVE_LIBC
        select LIBUKDEBUG
+       select LIBUKSWRAND

Where is this HAVE_NW_STACK defined? This probably is missing in Unikraft mainline
+       select HAVE_NW_STACK
+
+if LIBLWIP
+choice
+       prompt "Operation mode"
+       default LWIP_THREADS
+
+config LWIP_NOTHREADS
+       bool "Mainloop (non-threaded)"
+       help
+               No thread is created to operate the stack. The stack has to be
+               called from the same context as all stack interactions. This
+               includes polling network devices. The Socket API is unavailable.
+
+config LWIP_THREADS
+       bool "Threaded"
+       select LIBUKSCHED
        select LIBUKMPI
        select LIBUKMPI_MBOX
        select LIBUKLOCK
        select LIBUKLOCK_SEMAPHORE
        select LIBUKLOCK_MUTEX
-       select LIBUKSWRAND
-       select LIBUKSCHED
-       select HAVE_NW_STACK
-
-       select LIBLWIP_HEAPONLY
+       help
+               Creates a core thread for the stack.
+endchoice
-if LIBLWIP
  choice
        prompt "Memory allocation mode"
        default LWIP_HEAP
config LWIP_HEAP
        bool "Heap only"
+       help
+               Use default ukalloc allocator for all memory allocation requests
#config LWIP_POOLS
  #     bool "Memory pools"
  endchoice
config LWIP_IPV4
-       bool "IPv4"
+       bool "IPv4 support"
        default y
config LWIP_IPV6
-       bool "IPv6"
+       bool "IPv6 support"
        default n
-
-config LWIP_RXCHECKSUM
-       bool "Check checksum on reception"
-       default n
-
-config LWIP_TXCHECKSUM
-       bool "Calculate checksum on sending"
-       default y
-
  config LWIP_UDP
        bool "UDP support"
        default y
@@ -84,16 +92,12 @@ config LWIP_SNMP
  config LWIP_DHCP
        bool "DHCP client"
        depends on LWIP_IPV4
+       select LWIP_UDP
        default n
        help
-               Query device IP address from DHCP server on network
-
-config LWIP_AUTOIP
-       bool "AutoIP"
-       depends on LWIP_IPV4
-       default n
-       help
-               Dynamic IP address assignment at device on startup
+               When LWIP_AUTOIFACE is used, the initialization routine will
+               query the IPv4 addresses for the found devices from a DHCP
+               server on network.
menuconfig LWIP_DNS
        bool "DNS Resolver"
@@ -109,58 +113,69 @@ config LWIP_DNS_TABLE_SIZE
        default 32
  endif
-config LWIP_PPP
-       bool "Point-to-Point support"
-       default n
-
-config LWIP_SLIP
-       bool "SLIP netif"
-       default n
-
-config LWIP_6LOWPAN
-       bool "6LowPAN"
-       depends on LWIP_IPV6
-       default n
-
  config LWIP_SOCKET
        bool "Socket API"
+       select LIBVFSCORE
+       depends on LWIP_THREADS && (LWIP_UDP || LWIP_TCP)
        default y
menuconfig LWIP_DEBUG
        bool "Debug messages"
        default n
+       help
+               Enables debug messages on the debug console for selected lwIP
+               message types.
if LWIP_DEBUG
  config LWIP_MAINLOOP_DEBUG
        bool "Mainloop"
        default n
+       help
+               Enables TCP_IP_DEBUG, TIMERS_DEBUG
config LWIP_IF_DEBUG
        bool "Netif"
        default n
+       help
+               Enables ETHARP_DEBUG, NETIF_DEBUG
config LWIP_IP_DEBUG
        bool "IP"
        default n
+       help
+               Enables IP_DEBUG, IP6_DEBUG, IP_REASS_DEBUG
config LWIP_UDP_DEBUG
        bool "UDP"
        default n
+       help
+               Enables UDP_DEBUG
config LWIP_TCP_DEBUG
        bool "TCP"
        default n
+       help
+               Enables TCP_DEBUG, TCP_FR_DEBUG, TCP_RTO_DEBUG, TCP_CWND_DEBUG,
+               TCP_WND_DEBUG, TCP_RST_DEBUG, TCP_QLEN_DEBUG, TCP_OUTPUT_DEBUG,
+               TCP_INPUT_DEBUG
config LWIP_SYS_DEBUG
        bool "System"
        default n
+       help
+               Enables SYS_DEBUG, PBUF_DEBUG, MEM_DEBUG, MEMP_DEBUG
config LWIP_API_DEBUG
-       bool "API"
+       bool "APIs"
        default n
+       help
+               Enables SOCKETS_DEBUG, RAW_DEBUG, API_MSG_DEBUG, API_LIB_DEBUG
config LWIP_SERVICE_DEBUG
-       bool "Service"
+       bool "Services"
        default n
+       help
+               Enables ETHARP_DEBUG, DNS_DEBUG, AUTOIP_DEBUG, DHCP_DEBUG,
+               ICMP_DEBUG, SNMP_DEBUG, SNMP_MSG_DEBUG, SNMP_MIB_DEBUG
  endif
  endif
diff --git a/Makefile.uk b/Makefile.uk
index df54787..ae3fbea 100644
--- a/Makefile.uk
+++ b/Makefile.uk
@@ -4,7 +4,8 @@
  #           Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
  #
  #
-#  Copyright (c) 2017, NEC Europe Ltd., NEC Corporation. All rights reserved.
+#  Copyright (c) 2017-2019, NEC Europe Ltd., NEC Corporation.
+#                           All rights reserved.
  #
  #  Redistribution and use in source and binary forms, with or without
  #  modification, are permitted provided that the following conditions
@@ -42,7 +43,7 @@ $(eval $(call addlib_s,liblwip,$(CONFIG_LIBLWIP)))
  
################################################################################
  # Sources
  
################################################################################
-LIBLWIP_ZIPNAME=lwip-2.0.3
+LIBLWIP_ZIPNAME=lwip-2.1.2
  
LIBLWIP_URL=http://download.savannah.nongnu.org/releases/lwip/$(LIBLWIP_ZIPNAME).zip
  LIBLWIP_PATCHDIR=$(LIBLWIP_BASE)/patches
  $(eval $(call fetch,liblwip,$(LIBLWIP_URL)))
@@ -60,33 +61,22 @@ CINCLUDES-$(CONFIG_LIBLWIP)   += -I$(LIBLWIP_BASE)/include 
-I$(LIBLWIP_EXTRACTED
  CXXINCLUDES-$(CONFIG_LIBLWIP) += -I$(LIBLWIP_BASE)/include 
-I$(LIBLWIP_EXTRACTED)/include
################################################################################
-# Global flags
+# Library flags
  
################################################################################
-LIBLWIP_CFLAGS-y += -DCONFIG_LWIP_MINIMAL -ULWIP_TIMEVAL_PRIVATE
-
-# Suppress some warnings to make the build process look neater
-LIBLWIP_SUPPRESS_CFLAGS += -Wno-unused-parameter -Wno-unused-variable \
--Wno-unused-but-set-variable -Wno-unused-label -Wno-char-subscripts  \
--Wno-unused-function -Wno-missing-field-initializers                 \
--Wno-uninitialized -Wno-array-bounds -Wno-maybe-uninitialized        \
--Wno-pointer-sign -Wno-unused-value -Wno-unused-macros               \
--Wno-parentheses -Wno-implicit-function-declaration                  \
--Wno-shift-negative-value -Wno-missing-braces -Wno-endif-labels      \
--Wno-unused-but-set-variable -Wno-implicit-function-declaration      \
--Wno-unused-const-variable -Wno-type-limits -Wno-sign-compare
-LIBLWIP_CFLAGS-y += $(LIBLWIP_SUPPRESS_CFLAGS)
+LIBLWIP_CFLAGS-y += -Wno-type-limits -Wunused-parameter
+LIBLWIP_CFLAGS-$(CONFIG_LWIP_DEBUG) += -DUK_DEBUG
################################################################################
  # Core
  
################################################################################
  LIBLWIP_SRCS-y += $(LIBLWIP_BASE)/alloc.c|unikraft
-LIBLWIP_SRCS-y += $(LIBLWIP_BASE)/mutex.c|unikraft
-LIBLWIP_SRCS-y += $(LIBLWIP_BASE)/semaphore.c|unikraft
-LIBLWIP_SRCS-y += $(LIBLWIP_BASE)/mailbox.c|unikraft
+LIBLWIP_SRCS-$(CONFIG_LWIP_THREADS) += $(LIBLWIP_BASE)/mutex.c|unikraft
+LIBLWIP_SRCS-$(CONFIG_LWIP_THREADS) += $(LIBLWIP_BASE)/semaphore.c|unikraft
+LIBLWIP_SRCS-$(CONFIG_LWIP_THREADS) += $(LIBLWIP_BASE)/mailbox.c|unikraft
+LIBLWIP_SRCS-$(CONFIG_LWIP_THREADS) += $(LIBLWIP_BASE)/threads.c|unikraft
  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-$(CONFIG_LWIP_SOCKET) += $(LIBLWIP_BASE)/sockets.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
@@ -118,23 +108,20 @@ LIBLWIP_SRCS-y += $(LIBLWIP_EXTRACTED)/api/tcpip.c
  LIBLWIP_SRCS-$(CONFIG_LWIP_SOCKET) += $(LIBLWIP_EXTRACTED)/api/sockets.c
################################################################################
-# NETIF Helpers
+# NETIFs
  
################################################################################
  LIBLWIP_SRCS-y += $(LIBLWIP_EXTRACTED)/netif/ethernet.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_SLIP) += $(LIBLWIP_EXTRACTED)/netif/slipif.c
-LIBLWIP_SRCS-y += $(LIBLWIP_EXTRACTED)/netif/lowpan6.c
################################################################################
  # IPv4
  
################################################################################
-LIBLWIP_SRCS-$(CONFIG_LWIP_AUTOIP)  += $(LIBLWIP_EXTRACTED)/core/ipv4/autoip.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_DHCP)    += $(LIBLWIP_EXTRACTED)/core/ipv4/dhcp.c
  LIBLWIP_SRCS-$(CONFIG_LWIP_IPV4)    += $(LIBLWIP_EXTRACTED)/core/ipv4/etharp.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_IPV4)    += $(LIBLWIP_EXTRACTED)/core/ipv4/icmp.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_IPV4)    += $(LIBLWIP_EXTRACTED)/core/ipv4/igmp.c
  LIBLWIP_SRCS-$(CONFIG_LWIP_IPV4)    += 
$(LIBLWIP_EXTRACTED)/core/ipv4/ip4_frag.c
  LIBLWIP_SRCS-$(CONFIG_LWIP_IPV4)    += $(LIBLWIP_EXTRACTED)/core/ipv4/ip4.c
  LIBLWIP_SRCS-$(CONFIG_LWIP_IPV4)    += 
$(LIBLWIP_EXTRACTED)/core/ipv4/ip4_addr.c
+LIBLWIP_SRCS-$(CONFIG_LWIP_ICMP)    += $(LIBLWIP_EXTRACTED)/core/ipv4/icmp.c
+LIBLWIP_SRCS-$(CONFIG_LWIP_IGMP)    += $(LIBLWIP_EXTRACTED)/core/ipv4/igmp.c
+LIBLWIP_SRCS-$(CONFIG_LWIP_DHCP)    += $(LIBLWIP_EXTRACTED)/core/ipv4/dhcp.c
################################################################################
  # IPv6
@@ -148,37 +135,3 @@ LIBLWIP_SRCS-$(CONFIG_LWIP_IPV6) += 
$(LIBLWIP_EXTRACTED)/core/ipv6/ip6_addr.c
  LIBLWIP_SRCS-$(CONFIG_LWIP_IPV6) += $(LIBLWIP_EXTRACTED)/core/ipv6/ip6_frag.c
  LIBLWIP_SRCS-$(CONFIG_LWIP_IPV6) += $(LIBLWIP_EXTRACTED)/core/ipv6/mld6.c
  LIBLWIP_SRCS-$(CONFIG_LWIP_IPV6) += $(LIBLWIP_EXTRACTED)/core/ipv6/nd6.c
-
-################################################################################
-# Lwip code - PPP
-################################################################################
-LIBLWIP_SRCS-$(CONFIG_LWIP_PPP) += $(LIBLWIP_EXTRACTED)/netif/ppp/auth.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_PPP) += $(LIBLWIP_EXTRACTED)/netif/ppp/ccp.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_PPP) += $(LIBLWIP_EXTRACTED)/netif/ppp/chap-md5.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_PPP) += $(LIBLWIP_EXTRACTED)/netif/ppp/chap_ms.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_PPP) += $(LIBLWIP_EXTRACTED)/netif/ppp/chap-new.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_PPP) += $(LIBLWIP_EXTRACTED)/netif/ppp/demand.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_PPP) += $(LIBLWIP_EXTRACTED)/netif/ppp/eap.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_PPP) += $(LIBLWIP_EXTRACTED)/netif/ppp/ecp.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_PPP) += $(LIBLWIP_EXTRACTED)/netif/ppp/eui64.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_PPP) += $(LIBLWIP_EXTRACTED)/netif/ppp/fsm.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_PPP) += $(LIBLWIP_EXTRACTED)/netif/ppp/ipcp.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_PPP) += $(LIBLWIP_EXTRACTED)/netif/ppp/ipv6cp.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_PPP) += $(LIBLWIP_EXTRACTED)/netif/ppp/lcp.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_PPP) += $(LIBLWIP_EXTRACTED)/netif/ppp/magic.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_PPP) += $(LIBLWIP_EXTRACTED)/netif/ppp/mppe.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_PPP) += $(LIBLWIP_EXTRACTED)/netif/ppp/multilink.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_PPP) += $(LIBLWIP_EXTRACTED)/netif/ppp/ppp.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_PPP) += $(LIBLWIP_EXTRACTED)/netif/ppp/pppapi.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_PPP) += $(LIBLWIP_EXTRACTED)/netif/ppp/pppcrypt.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_PPP) += $(LIBLWIP_EXTRACTED)/netif/ppp/pppoe.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_PPP) += $(LIBLWIP_EXTRACTED)/netif/ppp/pppol2tp.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_PPP) += $(LIBLWIP_EXTRACTED)/netif/ppp/pppos.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_PPP) += $(LIBLWIP_EXTRACTED)/netif/ppp/upap.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_PPP) += $(LIBLWIP_EXTRACTED)/netif/ppp/utils.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_PPP) += $(LIBLWIP_EXTRACTED)/netif/ppp/vj.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_PPP) += 
$(LIBLWIP_EXTRACTED)/netif/ppp/polarssl/arc4.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_PPP) += 
$(LIBLWIP_EXTRACTED)/netif/ppp/polarssl/des.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_PPP) += 
$(LIBLWIP_EXTRACTED)/netif/ppp/polarssl/md4.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_PPP) += 
$(LIBLWIP_EXTRACTED)/netif/ppp/polarssl/md5.c
-LIBLWIP_SRCS-$(CONFIG_LWIP_PPP) += 
$(LIBLWIP_EXTRACTED)/netif/ppp/polarssl/sha1.c
diff --git a/alloc.c b/alloc.c
index 86e0c6b..a5b4377 100644
--- a/alloc.c
+++ b/alloc.c
@@ -1,3 +1,36 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Copyright (c) 2019, NEC Laboratories Europe GmbH, NEC Corporation.
+ *                     All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+
  #include <uk/alloc.h>
void *sys_malloc(size_t size)
diff --git a/include/arch/cc.h b/include/arch/cc.h
index 099c4ac..a1d0c34 100644
--- a/include/arch/cc.h
+++ b/include/arch/cc.h
@@ -62,28 +62,25 @@
  #define PACK_STRUCT_BEGIN
  #define PACK_STRUCT_END
-/* platform specific diagnostic output */
  #define LWIP_PLATFORM_DIAG(_x) \
-       do {                                     \
-               if (DLVL_INFO <= DLVL_MAX) {  \
-                       _lwip_platform_diag _x;  \
-               }                                \
-       } while(0)
+       ({ uk_pr_debug _x; })
-static inline void _lwip_platform_diag(const char *fmt, ...)
-{
-       va_list ap;
+#if CONFIG_LIBUKDEBUG_ENABLE_ASSERT
+#define LWIP_PLATFORM_ASSERT(_x) \
+       do { uk_pr_crit(_x); UK_BUG(); } while (0)
+#else
+#define LWIP_PLATFORM_ASSERT(_x) \
+       do { } while (0)
+#endif /* CONFIG_LIBUKDEBUG_ENABLE_ASSERT */
- va_start(ap, fmt);
-       uk_vprintd(DLVL_INFO, fmt, ap);
-       va_end(ap);
-}
+/* lightweight synchronization mechanisms */
+#define SYS_ARCH_DECL_PROTECT(_x) \
+       unsigned long (_x)
-#define LWIP_PLATFORM_ASSERT(_x) UK_ASSERT((_x))
+#define SYS_ARCH_PROTECT(_x) \
+       ({ (_x) = ukplat_lcpu_save_irqf(); })
-/* lightweight synchronization mechanisms */
-#define SYS_ARCH_DECL_PROTECT(_x)  unsigned long (_x)
-#define SYS_ARCH_PROTECT(_x)       do { (_x) = ukplat_lcpu_save_irqf(); } 
while(0)
-#define SYS_ARCH_UNPROTECT(_x)     ukplat_lcpu_restore_irqf((_x))
+#define SYS_ARCH_UNPROTECT(_x) \
+       ukplat_lcpu_restore_irqf((_x))
#endif /* __LWIP_ARCH_CC_H__ */
diff --git a/include/arch/sys_arch.h b/include/arch/sys_arch.h
index 3b1fbef..62510ee 100644
--- a/include/arch/sys_arch.h
+++ b/include/arch/sys_arch.h
@@ -1,3 +1,35 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Copyright (c) 2019, NEC Laboratories Europe GmbH, NEC Corporation.
+ *                     All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
  /*
   * lwip/arch/sys_arch.h
   *
@@ -16,9 +48,10 @@
  #include <uk/mutex.h>
  #include <uk/semaphore.h>
  #include <uk/mbox.h>
-#if CONFIG_LIBUKSCHED
+
+#if CONFIG_LWIP_THREADS
  #include <uk/thread.h>
-#endif /* CONFIG_LIBUKSCHED */
+#endif /* CONFIG_LWIP_THREADS */
#if CONFIG_LWIP_SOCKET && CONFIG_HAVE_LIBC
  #include <fcntl.h>
@@ -44,9 +77,9 @@ typedef struct {
        int valid;
  } sys_mbox_t;
-#if CONFIG_LIBUKSCHED
+#if CONFIG_LWIP_THREADS
  typedef struct uk_thread *sys_thread_t;
-#endif /* CONFIG_LIBUKSCHED */
+#endif /* CONFIG_LWIP_THREADS */
typedef unsigned long sys_prot_t; diff --git a/include/arpa/inet.h b/include/arpa/inet.h
new file mode 100644
index 0000000..c2fc6c3
--- /dev/null
+++ b/include/arpa/inet.h
@@ -0,0 +1 @@
+#include <compat/posix/arpa/inet.h>
diff --git a/include/lwipopts.h b/include/lwipopts.h
index c6cc0bc..749b2a9 100644
--- a/include/lwipopts.h
+++ b/include/lwipopts.h
@@ -4,24 +4,20 @@
   * Configuration for lwIP running on mini-os
   *
   * Tim Deegan <Tim.Deegan@xxxxxxxxxxxxx>, July 2007
- * Simon Kuenzer <simon.kuenzer@xxxxxxxxx>, October 2013
+ * Simon Kuenzer <simon.kuenzer@xxxxxxxxx>, 2013-2019
   */
  #ifndef __LWIP_LWIPOPTS_H__
  #define __LWIP_LWIPOPTS_H__
#include <inttypes.h>
+#include <sys/time.h>
  #include <uk/config.h>
-#define SO_REUSE 1
-
-/*
- * General options/System settings
+/**
+ * Memory mode
   */
-/* lightweight protection */
-#define SYS_LIGHTWEIGHT_PROT 1
-
  /* provide malloc/free by Unikraft */
-#if CONFIG_LWIP_HEAP /* default */
+#if CONFIG_LWIP_HEAP
    /* Only use malloc/free for lwIP.
     * Every allocation is done by the heap.
     * Note: This setting results in the smallest binary
@@ -29,10 +25,9 @@
     *       network processing.
     */
    #define MEM_LIBC_MALLOC 1 /* enable heap */
-  #define MEMP_MEM_MALLOC 1 /* pool allocations via malloc (thus not from pool 
in data segment) */
+  #define MEMP_MEM_MALLOC 1 /* pool allocations via malloc */
  #elif CONFIG_LWIP_POOLS
-  /* This is the default configuration (mixed).
-   * Pools are used for pool allocations and the heap
+  /* Pools are used for pool allocations and the heap
     * is used for all the rest of allocations.
     * Note: Per design, lwIP allocates outgoing packet buffers
     *       from heap (via PBUF_RAM) and incoming from pools (via PBUF_POOL)
@@ -46,15 +41,10 @@
   #error Configuration error!
  #endif /* CONFIG_LWIP_HEAP_ONLY / CONFIG_LWIP_POOLS_ONLY */
-#define MEMP_SEPARATE_POOLS 1 /* for each pool use a separate array in data segment */
-
-//#ifdef CONFIG_LWIP_POOLS_ON_HEAP /* not supported yet */
-//#define MEMP_POOLS_ON_HEAP 1 /* allocate pools on system's heap */
-//#endif
-
-#define MEM_ALIGNMENT 4
-
  #if MEM_LIBC_MALLOC
+/*
+ * alloc.c binding to the stack
+ */
  #include <stddef.h> /* size_t */
  void *sys_malloc(size_t size);
  void *sys_calloc(int num, size_t size);
@@ -66,56 +56,92 @@ void sys_free(void *ptr);
  #endif /* MEM_LIBC_MALLOC */
#if MEM_USE_POOLS
-/* requires lwippools.h */
-#define MEMP_USE_CUSTOM_POOLS 0
-#endif /* MEM_USE_POOLS */
-
  /*
- * Most features are selected by uk/config.h
+ * Use lwIP's pools
   */
-#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
+#define MEMP_USE_CUSTOM_POOLS 0
+/* for each pool use a separate array in data segment */
+#define MEMP_SEPARATE_POOLS 1
+#endif /* MEM_USE_POOLS */
-/*
- * Thread options
+/**
+ * Operation mode (threaded, mainloop)
   */
-#ifndef CONFIG_LWIP_NOTHREADS
+#if CONFIG_LWIP_NOTHREADS
+#define NO_SYS 1
+#else  /* CONFIG_LWIP_NOTHREADS */
+#define NO_SYS 0
+/* lightweight protection */
+#define SYS_LIGHTWEIGHT_PROT 1
  #define TCPIP_THREAD_NAME "lwip"
  #define TCPIP_MBOX_SIZE 256
-#define MEMP_NUM_TCPIP_MSG_INPKT 256
  #endif /* CONFIG_LWIP_NOTHREADS */
-/*
+/**
+ * Pbuf options
+ */
+#define LWIP_SUPPORT_CUSTOM_PBUF 1
+
+/**
+ * Netif options
+ */
+#define LWIP_NETIF_REMOVE_CALLBACK 1
+#define LWIP_TIMEVAL_PRIVATE 0
+#define LWIP_NETIF_STATUS_CALLBACK 1
+
+/**
   * ARP options
   */
  #define MEMP_NUM_ARP_QUEUE 256
  #define ETHARP_SUPPORT_STATIC_ENTRIES 1
-/*
+/**
+ * IP options
+ */
+#if CONFIG_LWIP_IPV4
+#define LWIP_IPV4 1
+#else
+#define LWIP_IPV4 0
+#endif
+
+#if CONFIG_LWIP_IPV6
+#define LWIP_IPV6 1
+#define IPV6_FRAG_COPYHEADER 1
+
+#else
+#define LWIP_IPV6 0
+#endif
+
+#if ((!LWIP_IPV4) && (!LWIP_IPV6))
+#error No IP protocol was selected! Please choose at least one of LWIP_IPV4 
and LWIP_IPV6
+#endif
+
+/**
   * UDP options
   */
-//#define MEMP_NUM_UDP_PCB 16
+#if CONFIG_LWIP_UDP
+#define LWIP_UDP 1
+#else
+#define LWIP_UDP 0
+#endif
-/*
+/**
   * TCP options
   */
-#define TCP_MSS CONFIG_LWIP_TCP_MSS
-
+#if CONFIG_LWIP_TCP
+#define LWIP_TCP 1
+#else
+#define LWIP_TCP 0
+#endif
+#if 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
- * Optimal settings for RX performance are:
- *     TCP_WND         262143
- *     TCP_RCV_SCALE   5
   */
  #define LWIP_WND_SCALE  1
  #if defined CONFIG_LWIP_WND_SCALE_FACTOR && CONFIG_LWIP_WND_SCALE_FACTOR >= 1
@@ -128,11 +154,12 @@ 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 LWIP_WND_SCALE 0
  #define TCP_WND 32766 /* Ideally, TCP_WND should be link bandwidth multiplied 
by rtt */
  #define TCP_SND_BUF (TCP_WND + (2 * TCP_MSS))
-#endif /* LWIP_WND_SCALE */
+#endif /* CONFIG_LWIP_WND_SCALE */
#define TCP_SNDLOWAT (4 * TCP_MSS)
  #define TCP_SND_QUEUELEN (2 * (TCP_SND_BUF) / (TCP_MSS))
@@ -142,70 +169,152 @@ 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 */
+#endif /* LWIP_TCP */
+
+/**
+ * Socket options
+ */
+#if CONFIG_LWIP_SOCKET
+#define LWIP_SOCKET 1
+#else
+#define LWIP_SOCKET 0
+#endif
+
+#if LWIP_SOCKET
+/* Stop lwip to provide fd_set */
+#include <sys/select.h>
+
+#ifndef FD_SET
+#define FD_SET
+#endif
/*
+ * disable BSD-style socket interface
+ * We will provide the layer with socket.c|unikraft
+ */
+#define LWIP_COMPAT_SOCKETS 0
+
+/* enable SO_REUSEADDR option */
+#define SO_REUSE 1
+#endif /* LWIP_SOCKET */
+
+/**
   * DNS options
   */
+#if CONFIG_LWIP_DNS
+#define LWIP_DNS 1
+#else
+#define LWIP_DNS 0
+#endif
+
+#if LWIP_DNS
  #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 /* LWIP_DNS */
+/**
+ * Memory pool sizes
+ */
+#if MEM_USE_POOLS
  /*
- * Pool options
+ * We dimension pool sizes on previous stack configurations so we have to do
+ * this at the very last point in this configuration file.
   */
-/* PBUF pools */
  #ifndef PBUF_POOL_SIZE
  #define PBUF_POOL_SIZE ((TCP_WND + TCP_MSS - 1) / TCP_MSS)
  #endif
-#ifndef CONFIG_NETFRONT_PERSISTENT_GRANTS
-#define LWIP_SUPPORT_CUSTOM_PBUF 1
-#endif
  #ifndef MEMP_NUM_PBUF
  #define MEMP_NUM_PBUF ((MEMP_NUM_TCP_PCB * (TCP_SND_QUEUELEN)) / 2)
  #endif
+#define MEMP_NUM_TCPIP_MSG_INPKT TCPIP_MBOX_SIZE
+#endif /* MEM_USE_POOLS */
-/*
+/**
+ * Additional features
+ */
+#if CONFIG_LWIP_ICMP
+#define LWIP_ICMP 1
+#else
+#define LWIP_ICMP 0
+#endif
+
+#if CONFIG_LWIP_IGMP
+#define LWIP_IGMP 1
+#else
+#define LWIP_IGMP 0
+#endif
+
+#if CONFIG_LWIP_SNMP
+#define LWIP_SNMP 1
+#else
+#define LWIP_SNMP 0
+#endif
+
+#if CONFIG_LWIP_DHCP
+#define LWIP_DHCP 1
+#else
+#define LWIP_DHCP 0
+#endif
+
+#if CONFIG_LWIP_NOTHREADS
+#define LWIP_NETCONN 0
+#else
+#define LWIP_NETCONN 1
+#endif
+
+/**
   * Checksum options
   */
-#define CHECKSUM_GEN_IP CONFIG_LWIP_TXCHECKSUM
-#define CHECKSUM_GEN_IP6 CONFIG_LWIP_TXCHECKSUM
-#define CHECKSUM_GEN_ICMP CONFIG_LWIP_TXCHECKSUM
-#define CHECKSUM_GEN_ICMP6 CONFIG_LWIP_TXCHECKSUM
-#define CHECKSUM_GEN_UDP CONFIG_LWIP_TXCHECKSUM
-#define CHECKSUM_GEN_TCP CONFIG_LWIP_TXCHECKSUM
-#define LWIP_CHECKSUM_ON_COPY 1
-
-/* Checksum checking is offloaded to the host (lwip-net is a virtual interface)
- * TODO: better solution is when netfront forwards checksum flags to lwIP */
-#define CHECKSUM_CHECK_IP CONFIG_LWIP_RXCHECKSUM
-#define CHECKSUM_CHECK_UDP CONFIG_LWIP_RXCHECKSUM
-#define CHECKSUM_CHECK_TCP CONFIG_LWIP_RXCHECKSUM
-#define CHECKSUM_CHECK_ICMP CONFIG_LWIP_RXCHECKSUM
-#define CHECKSUM_CHECK_ICMP6 CONFIG_LWIP_RXCHECKSUM
-#define CHECKSUM_CHECK_TCP CONFIG_LWIP_RXCHECKSUM
-
-#ifdef CONFIG_LWIP_MAINLOOP_DEBUG
-#define IP_DEBUG         LWIP_DBG_ON
+/*
+ * We enable the option that each netif can enable and disable
+ * individually which checksums should be checked/calculated by the stack
+ */
+#define LWIP_CHECKSUM_CTRL_PER_NETIF 1
+
+#define CHECKSUM_GEN_IP      1
+#define CHECKSUM_GEN_IP6     1
+#define CHECKSUM_GEN_ICMP    1
+#define CHECKSUM_GEN_ICMP6   1
+#define CHECKSUM_GEN_UDP     1
+#define CHECKSUM_GEN_TCP     1
+#define CHECKSUM_CHECK_IP    1
+#define CHECKSUM_CHECK_UDP   1
+#define CHECKSUM_CHECK_TCP   1
+#define CHECKSUM_CHECK_ICMP  1
+#define CHECKSUM_CHECK_ICMP6 1
+#define CHECKSUM_CHECK_TCP   1
+
+/**
+ * Debugging options
+ */
+#if CONFIG_LWIP_DEBUG
+#define LWIP_DEBUG
+#define LWIP_DBG_MIN_LEVEL   LWIP_DBG_LEVEL_ALL
+#define LWIP_DBG_TYPES_ON    LWIP_DBG_ON
+
+#if CONFIG_LWIP_MAINLOOP_DEBUG
  #define TCPIP_DEBUG      LWIP_DBG_ON
  #define TIMERS_DEBUG     LWIP_DBG_ON
  #endif /* CONFIG_LWIP_MAINLOOP_DEBUG */
-#ifdef CONFIG_LWIP_IF_DEBUG
+#if CONFIG_LWIP_IF_DEBUG
+#define ETHARP_DEBUG     LWIP_DBG_ON
  #define NETIF_DEBUG      LWIP_DBG_ON
  #endif /* CONFIG_LWIP_IF_DEBUG */
-#ifdef CONFIG_LWIP_IP_DEBUG
+#if CONFIG_LWIP_IP_DEBUG
  #define IP_DEBUG         LWIP_DBG_ON
  #define IP6_DEBUG        LWIP_DBG_ON
  #define IP_REASS_DEBUG   LWIP_DBG_ON
  #endif /* CONFIG_LWIP_IP_DEBUG */
-#ifdef CONFIG_LWIP_UDP_DEBUG
+#if CONFIG_LWIP_UDP_DEBUG
  #define UDP_DEBUG        LWIP_DBG_ON
  #endif /* CONFIG_LWIP_UDP_DEBUG */
-#ifdef CONFIG_LWIP_TCP_DEBUG
+#if CONFIG_LWIP_TCP_DEBUG
  #define TCP_DEBUG        LWIP_DBG_ON
  #define TCP_FR_DEBUG     LWIP_DBG_ON
  #define TCP_RTO_DEBUG    LWIP_DBG_ON
@@ -213,28 +322,28 @@ 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
  #endif /* CONFIG_LWIP_TCP_DEBUG */
-#ifdef CONFIG_LWIP_SYS_DEBUG
+#if CONFIG_LWIP_SYS_DEBUG
  #define SYS_DEBUG        LWIP_DBG_ON
  #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
+#if 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
+#if CONFIG_LWIP_SERVICE_DEBUG
  #define ETHARP_DEBUG     LWIP_DBG_ON
  #define DNS_DEBUG        LWIP_DBG_ON
  #define AUTOIP_DEBUG     LWIP_DBG_ON
@@ -243,8 +352,7 @@ void sys_free(void *ptr);
  #define SNMP_DEBUG       LWIP_DBG_ON
  #define SNMP_MSG_DEBUG   LWIP_DBG_ON
  #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 /* CONFIG_LWIP_DEBUG */
#endif /* __LWIP_LWIPOPTS_H__ */
diff --git a/include/net/if.h b/include/net/if.h
new file mode 100644
index 0000000..3fbfdec
--- /dev/null
+++ b/include/net/if.h
@@ -0,0 +1 @@
+#include <compat/posix/net/if.h>
diff --git a/include/netdb.h b/include/netdb.h
new file mode 100644
index 0000000..5e2eb60
--- /dev/null
+++ b/include/netdb.h
@@ -0,0 +1 @@
+#include <compat/posix/netdb.h>
diff --git a/include/sys/socket.h b/include/sys/socket.h
index 5f496cb..2a01877 100644
--- a/include/sys/socket.h
+++ b/include/sys/socket.h
@@ -1,13 +1,68 @@
-#ifndef UK_LWIP_SOCKET_H
-#include <uk/config.h>
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Copyright (c) 2019, NEC Laboratories Europe GmbH, NEC Corporation.
+ *                     All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+#ifndef _UK_LWIP_SOCKET_H_ -#if CONFIG_LIBLWIP
-#include <lwip/inet.h>
+#include <uk/config.h>
  #include <lwip/sockets.h>
-#endif /* CONFIG_LIBLWIP */
+#ifndef SOCK_CLOEXEC
  #define SOCK_CLOEXEC    0x10000000
+#endif
+
+#ifndef SOCK_NONBLOCK
  #define SOCK_NONBLOCK   0x20000000
+#endif
+
+#ifdef CONFIG_LIBNOLIBC
+int socket(int domain, int type, int protocol);
+int accept(int s, struct sockaddr *addr, socklen_t *addrlen);
+int bind(int s, const struct sockaddr *name, socklen_t namelen);
+int shutdown(int s, int how);
+int getpeername(int s, struct sockaddr *name, socklen_t *namelen);
+int getsockname(int s, struct sockaddr *name, socklen_t *namelen);
+int getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen);
+int setsockopt(int s, int level, int optname, const void *optval,
+              socklen_t optlen);
+int connect(int s, const struct sockaddr *name, socklen_t namelen);
+int listen(int s, int backlog);
+int recv(int s, void *mem, size_t len, int flags);
+int recvfrom(int s, void *mem, size_t len, int flags,
+            struct sockaddr *from, socklen_t *fromlen);
+int send(int s, const void *dataptr, size_t size, int flags);
+int sendmsg(int s, const struct msghdr *message, int flags);
+int sendto(int s, const void *dataptr, size_t size, int flags,
+          const struct sockaddr *to, socklen_t tolen);
+#endif /* CONFIG_LIBNOLIBC */
-#endif /* UK_LWIP_SOCKET_H */
+#endif /* _UK_LWIP_SOCKET_H_ */
diff --git a/init.c b/init.c
index 0326662..ece363d 100644
--- a/init.c
+++ b/init.c
@@ -1,27 +1,86 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
+ *
+ * Copyright (c) 2019, NEC Laboratories Europe GmbH, NEC Corporation.
+ *                     All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+
  #include <uk/config.h>
-#include <lwip/tcpip.h>
-#include <lwip/init.h>
-#include <uk/plat/ctors.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
- * be up and running for the rest of the functions to work. for
- * example to set up a pool of semaphores. */
+#include "lwip/opt.h"
+#include "lwip/tcpip.h"
+#include "lwip/init.h"
+#include "lwip/dhcp.h"
+#if CONFIG_LWIP_NOTHREADS
+#include "lwip/timeouts.h"
+#else /* CONFIG_LWIP_NOTHREADS */
+#include <uk/semaphore.h>
+#endif /* CONFIG_LWIP_NOTHREADS */
+
  void sys_init(void)
  {
-    return;
+       /*
+        * 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
+        * be up and running for the rest of the functions to work. for
+        * example to set up a pool of semaphores.
+        */
  }
+#if !CONFIG_LWIP_NOTHREADS
+static struct uk_semaphore _lwip_init_sem;
+
+static void _lwip_init_done(void *arg __unused)
+{
+       uk_semaphore_up(&_lwip_init_sem);
+}
+#endif /* !CONFIG_LWIP_NOTHREADS */
+
  /*
   * This function initializing the lwip network stack
- *
   */
  int liblwip_init(void)
  {
-#if CONFIG_LIBUKSCHED
-        tcpip_init(NULL, NULL);
-#else
-        lwip_init();
-#endif /* CONFIG_LIBUKSCHED */
+
+#if !CONFIG_LWIP_NOTHREADS
+       uk_semaphore_init(&_lwip_init_sem, 0);
+#endif /* !CONFIG_LWIP_NOTHREADS */
+
+#if CONFIG_LWIP_NOTHREADS
+       lwip_init();
+#else /* CONFIG_LWIP_NOTHREADS */
+       tcpip_init(_lwip_init_done, NULL);
+
+       /* Wait until stack is booted */
+       uk_semaphore_down(&_lwip_init_sem);
+#endif /* CONFIG_LWIP_NOTHREADS */
+
        return 0;
  }
diff --git a/mailbox.c b/mailbox.c
index 8a6cb13..6fb5fda 100644
--- a/mailbox.c
+++ b/mailbox.c
@@ -1,3 +1,36 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Copyright (c) 2019, NEC Laboratories Europe GmbH, NEC Corporation.
+ *                     All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+
  #include <uk/mbox.h>
  #include <uk/arch/time.h>
  #include <lwip/sys.h>
@@ -7,67 +40,80 @@
  /* Creates an empty mailbox. */
  err_t sys_mbox_new(sys_mbox_t *mbox, int size)
  {
-    if (size <= 0)
-        size = 32;
-
-    UK_ASSERT(mbox);
-    mbox->a = uk_alloc_get_default();
-    UK_ASSERT(mbox->a);
-    mbox->mbox = uk_mbox_create(mbox->a, size);
-    if (!mbox->mbox)
-        return ERR_MEM;
-    mbox->valid = 1;
-    return ERR_OK;
+       if (size <= 0)
+               size = 32;
+
+       UK_ASSERT(mbox);
+       mbox->a = uk_alloc_get_default();
+       UK_ASSERT(mbox->a);
+       mbox->mbox = uk_mbox_create(mbox->a, size);
+       if (!mbox->mbox)
+               return ERR_MEM;
+       mbox->valid = 1;
+       return ERR_OK;
  }
int sys_mbox_valid(sys_mbox_t *mbox)
  {
-    if (!mbox)
-        return 0;
-    return (mbox->valid == 1);
+       if (!mbox)
+               return 0;
+       return (mbox->valid == 1);
  }
void sys_mbox_set_invalid(sys_mbox_t *mbox)
  {
-    UK_ASSERT(mbox);
-    mbox->valid = 0;
+       UK_ASSERT(mbox);
+       mbox->valid = 0;
  }
-/* Deallocates a mailbox. If there are messages still present in the
+/**
+ * Deallocates a mailbox. If there are messages still present in the
   * mailbox when the mailbox is deallocated, it is an indication of a
- * programming error in lwIP and the developer should be notified. */
+ * programming error in lwIP and the developer should be notified.
+ */
  void sys_mbox_free(sys_mbox_t *mbox)
  {
-    UK_ASSERT(sys_mbox_valid(mbox));
+       UK_ASSERT(sys_mbox_valid(mbox));
- uk_mbox_free(mbox->a, mbox->mbox);
-    sys_mbox_set_invalid(mbox);
+       uk_mbox_free(mbox->a, mbox->mbox);
+       sys_mbox_set_invalid(mbox);
  }
-/* Posts the "msg" to the mailbox. */
+/* Posts "msg" to the mailbox, NULL msg's are not supported */
  void sys_mbox_post(sys_mbox_t *mbox, void *msg)
  {
-    UK_ASSERT(sys_mbox_valid(mbox));
+       UK_ASSERT(sys_mbox_valid(mbox));
- if (!msg) { /* FIXME? */
-        uk_printd(DLVL_WARN, "Ignore posting NULL message");
-       return;
-    }
+       if (!msg) {
+               uk_pr_debug("Ignored posting NULL message");
+               return;
+       }
- uk_mbox_post(mbox->mbox, msg);
+       uk_mbox_post(mbox->mbox, msg);
  }
-/* Try to post the "msg" to the mailbox. */
+/* Try to post "msg" to the mailbox. */
  err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg)
  {
-    UK_ASSERT(sys_mbox_valid(mbox));
+       UK_ASSERT(sys_mbox_valid(mbox));
- if (uk_mbox_post_try(mbox->mbox, msg) < 0)
-        return ERR_MEM;
-    return ERR_OK;
+       if (uk_mbox_post_try(mbox->mbox, msg) < 0)
+               return ERR_MEM;
+       return ERR_OK;
  }
-/* Blocks the thread until a message arrives in the mailbox, but does
+/* Try to post the "msg" to the mailbox from ISR context. */
+err_t sys_mbox_trypost_fromisr(sys_mbox_t *mbox, void *msg)
+{
+       UK_ASSERT(sys_mbox_valid(mbox));
+
+       if (uk_mbox_post_try(mbox->mbox, msg) < 0)
+               return ERR_MEM;
+       return ERR_OK;
+}
+
+/**
+ * Blocks the thread until a message arrives in the mailbox, but does
   * not block the thread longer than "timeout" milliseconds (similar to
   * the sys_arch_sem_wait() function). The "msg" argument is a result
   * parameter that is set by the function (i.e., by doing "*msg =
@@ -76,21 +122,23 @@ err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg)
   *
   * The return values are the same as for the sys_arch_sem_wait() function:
   * Number of milliseconds spent waiting or SYS_ARCH_TIMEOUT if there was a
- * timeout. */
+ * timeout.
+ */
  u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout)
  {
-    __nsec nsret;
+       __nsec nsret;
- UK_ASSERT(sys_mbox_valid(mbox));
+       UK_ASSERT(sys_mbox_valid(mbox));
- nsret = uk_mbox_recv_to(mbox->mbox, msg,
-                               ukarch_time_msec_to_nsec((__nsec) timeout));
-    if (unlikely(nsret == __NSEC_MAX))
-        return SYS_ARCH_TIMEOUT;
-    return (u32_t) ukarch_time_nsec_to_msec(nsret);
+       nsret = uk_mbox_recv_to(mbox->mbox, msg,
+                               ukarch_time_msec_to_nsec((__nsec) timeout));
+       if (unlikely(nsret == __NSEC_MAX))
+               return SYS_ARCH_TIMEOUT;
+       return (u32_t) ukarch_time_nsec_to_msec(nsret);
  }
-/* This is similar to sys_arch_mbox_fetch, however if a message is not
+/**
+ * This is similar to sys_arch_mbox_fetch, however if a message is not
   * present in the mailbox, it immediately returns with the code
   * SYS_MBOX_EMPTY. On success 0 is returned.
   *
@@ -99,17 +147,18 @@ u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, 
u32_t timeout)
   * example, a naive implementation could be:
   *   #define sys_arch_mbox_tryfetch(mbox,msg) \
   *     sys_arch_mbox_fetch(mbox,msg,1)
- * although this would introduce unnecessary delays. */
-
-u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg) {
-    void *rmsg;
+ * although this would introduce unnecessary delays.
+ */
+u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg)
+{
+       void *rmsg;
- UK_ASSERT(sys_mbox_valid(mbox));
+       UK_ASSERT(sys_mbox_valid(mbox));
- if (uk_mbox_recv_try(mbox->mbox, &rmsg) < 0)
-       return SYS_MBOX_EMPTY;
+       if (uk_mbox_recv_try(mbox->mbox, &rmsg) < 0)
+               return SYS_MBOX_EMPTY;
- if (msg)
-        *msg = rmsg;
-    return 0;
+       if (msg)
+               *msg = rmsg;
+       return 0;
  }
diff --git a/mutex.c b/mutex.c
index aaa1085..2f8d4c5 100644
--- a/mutex.c
+++ b/mutex.c
@@ -1,11 +1,46 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Copyright (c) 2019, NEC Laboratories Europe GmbH, NEC Corporation.
+ *                     All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+
  #include <uk/mutex.h>
  #include <uk/arch/time.h>
  #include <lwip/sys.h>
#include <uk/essentials.h> -/* Initializes a new semaphore. The "count" argument specifies
- * the initial state of the semaphore. */
+/**
+ * Initializes a new semaphore. The "count" argument specifies
+ * the initial state of the semaphore.
+ */
  err_t sys_mutex_new(sys_mutex_t *mtx)
  {
        uk_mutex_init(&mtx->mtx);
@@ -31,10 +66,10 @@ void sys_mutex_free(sys_mutex_t *mtx)
  /* Signals a mtxaphore. */
    s/mtxaphore/mutex
  void sys_mutex_lock(sys_mutex_t *mtx)
  {
-       uk_mutex_hold(&mtx->mtx);
+       uk_mutex_lock(&mtx->mtx);
  }
void sys_mutex_unlock(sys_mutex_t *mtx)
  {
-       uk_mutex_release(&mtx->mtx);
+       uk_mutex_unlock(&mtx->mtx);
  }
diff --git a/semaphore.c b/semaphore.c
index 8b1b15f..16da316 100644
--- a/semaphore.c
+++ b/semaphore.c
@@ -1,11 +1,46 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Copyright (c) 2019, NEC Laboratories Europe GmbH, NEC Corporation.
+ *                     All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+
  #include <uk/semaphore.h>
  #include <uk/arch/time.h>
  #include <lwip/sys.h>
#include <uk/essentials.h> -/* Initializes a new semaphore. The "count" argument specifies
- * the initial state of the semaphore. */
+/**
+ * Initializes a new semaphore. The "count" argument specifies
+ * the initial state of the semaphore.
+ */
  err_t sys_sem_new(sys_sem_t *sem, u8_t count)
  {
        uk_semaphore_init(&sem->sem, (long) count);
@@ -34,7 +69,8 @@ void sys_sem_signal(sys_sem_t *sem)
        uk_semaphore_up(&sem->sem);
  }
-/* Blocks the thread while waiting for the semaphore to be
+/**
+ * Blocks the thread while waiting for the semaphore to be
   * signaled. If the "timeout" argument is non-zero, the thread should
   * only be blocked for the specified time (measured in
   * milliseconds).
@@ -43,14 +79,16 @@ void sys_sem_signal(sys_sem_t *sem)
   * milliseconds spent waiting for the semaphore to be signaled. If the
   * semaphore wasn't signaled within the specified time, the return value is
   * SYS_ARCH_TIMEOUT. If the thread didn't have to wait for the semaphore
- * (i.e., it was already signaled), the function may return zero. */
+ * (i.e., it was already signaled), the function may return zero.
+ */
  u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout)
  {
-    __nsec nsret;
+       __nsec nsret;
- nsret = uk_semaphore_down_to(&sem->sem,
-                                    ukarch_time_msec_to_nsec((__nsec) 
timeout));
-    if (unlikely(nsret == __NSEC_MAX))
-        return SYS_ARCH_TIMEOUT;
-    return (u32_t) ukarch_time_nsec_to_msec(nsret);
+       nsret = uk_semaphore_down_to(&sem->sem,
+                                    ukarch_time_msec_to_nsec((__nsec)
+                                                             timeout));
+       if (unlikely(nsret == __NSEC_MAX))
+               return SYS_ARCH_TIMEOUT;
+       return (u32_t) ukarch_time_nsec_to_msec(nsret);
  }
diff --git a/socket_glue.c b/sockets.c
similarity index 60%
rename from socket_glue.c
rename to sockets.c
index e7dc33c..bdf21ad 100644
--- a/socket_glue.c
+++ b/sockets.c
@@ -1,20 +1,50 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Sharan Santhanam <sharan.santhanam@xxxxxxxxx>
+ *
+ * Copyright (c) 2019, NEC Laboratories Europe GmbH, NEC Corporation.
+ *                     All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+
  /* network stub calls */
  #include <sys/time.h>
  #include <vfscore/file.h>
  #include <uk/alloc.h>
  #include <uk/essentials.h>
-#include <uk/print.h>
  #include <uk/errptr.h>
  #include <stdio.h>
  #include <errno.h>
  #include <lwip/sockets.h>
-#define NET_LIB_NAME "lwip-socket"
-#define  SOCK_NET_SET_ERRNO(errcode) \
-                       do {\
-                               errno = -(errcode);\
-                       } while(0)
-
+#define SOCK_NET_SET_ERRNO(errcode) \
+       (errno = -(errcode))
struct sock_net_file {
        struct vfscore_file vfscore_file;
@@ -25,9 +55,11 @@ static inline struct sock_net_file *sock_net_file_get(int fd)
  {
        struct sock_net_file *file = NULL;
        struct vfscore_file *fos;
+
        fos  = vfscore_get_file(fd);
-       if(NULL == fos) {
-               uk_printd(DLVL_ERR,"failed with invalid descriptor\n");
+       if (!fos) {
+               LWIP_DEBUGF(SOCKETS_DEBUG,
+                           ("failed with invalid descriptor\n"));
                file = ERR2PTR(-EINVAL);
                goto EXIT;
        }
@@ -46,20 +78,22 @@ static int sock_fd_alloc(struct vfscore_fops *fops, int 
sock_fd)
        vfs_fd = vfscore_alloc_fd();
        if (vfs_fd < 0) {
                ret = -ENFILE;
-               uk_printd(DLVL_ERR, "failed to allocate socket fd\n");
+               LWIP_DEBUGF(SOCKETS_DEBUG, ("failed to allocate socket fd\n"));
                goto EXIT;
        }
file = uk_malloc(uk_alloc_get_default(), sizeof(*file));
        if (!file) {
                ret = -ENOMEM;
-               uk_printd(DLVL_ERR, "failed to allocate socket fd - no mem\n");
+               LWIP_DEBUGF(SOCKETS_DEBUG,
+                           ("failed to allocate socket fd: no mem\n"));
                goto UK_MEM_ALLOC_ERR;
        }
        file->vfscore_file.fops = fops;
        file->sock_fd = sock_fd;
-       uk_printd(DLVL_EXTRA, NET_LIB_NAME":allocated socket %d (%x)\n",
-                       file->vfscore_file.fd, file->sock_fd);
+       LWIP_DEBUGF(SOCKETS_DEBUG, ("allocated socket %d (%x)\n",
+                                   file->vfscore_file.fd,
+                                   file->sock_fd));
        /* Storing the information within the vfs structure */
        vfscore_install_fd(vfs_fd, &file->vfscore_file);
        ret = vfs_fd;
@@ -73,12 +107,14 @@ UK_MEM_ALLOC_ERR:
static int sock_net_close(struct vfscore_file *vfscore_file)
  {
-       int    ret = 0;
+       int ret = 0;
        struct sock_net_file *file = NULL;
+
        file = __containerof(vfscore_file, struct sock_net_file, vfscore_file);
- uk_printd(DLVL_EXTRA, NET_LIB_NAME": close() %d (%x)\n",
-                       file->vfscore_file.fd, file->sock_fd);
+       LWIP_DEBUGF(SOCKETS_DEBUG, ("close %d (%x)\n",
+                                   file->vfscore_file.fd,
+                                   file->sock_fd));
/* Close and release the lwip socket */
        ret = lwip_close(file->sock_fd);
@@ -89,15 +125,18 @@ static int sock_net_close(struct vfscore_file 
*vfscore_file)
        return ret;
  }
-static ssize_t sock_net_write(struct vfscore_file *vfscore_file, const void *buf,
-                            size_t count)
+static ssize_t sock_net_write(struct vfscore_file *vfscore_file,
+                             const void *buf, size_t count)
  {
        int ret = 0;
        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",
-                       file->vfscore_file.fd, file->sock_fd, (char *) buf);
+                            vfscore_file);
+       LWIP_DEBUGF(SOCKETS_DEBUG, ("write %d (%x):%s\n",
+                                   file->vfscore_file.fd,
+                                   file->sock_fd,
+                                   (char *) buf));
        ret = lwip_write(file->sock_fd, buf, count);
        return ret;
  }
@@ -107,10 +146,13 @@ static ssize_t sock_net_read(struct vfscore_file 
*vfscore_file, void *buf,
  {
        int ret = 0;
        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",
-                       file->vfscore_file.fd, file->sock_fd, (char *) buf);
+                            vfscore_file);
+       LWIP_DEBUGF(SOCKETS_DEBUG, ("write %d (%x):%s\n",
+                                   file->vfscore_file.fd,
+                                   file->sock_fd,
+                                   (char *) buf));
        ret = lwip_read(file->sock_fd, buf, count);
        return ret;
  }
@@ -129,16 +171,19 @@ int socket(int domain, int type, int protocol)
/* Create lwip_socket */
        sock_fd = lwip_socket(domain, type, protocol);
-       if(0 > sock_fd) {
-               uk_printd(DLVL_ERR, "failed to create socket %d\n", errno);
+       if (sock_fd < 0) {
+               LWIP_DEBUGF(SOCKETS_DEBUG, ("failed to create socket %d\n",
+                                           errno));
                ret = -1;
                goto EXIT;
        }
/* Allocate the file descriptor */
        vfs_fd = sock_fd_alloc(&sock_net_fops, sock_fd);
-       if(0 > vfs_fd) {
-               uk_printd(DLVL_ERR, "failed to allocate descriptor %d\n", 
errno);
+       if (vfs_fd < 0) {
+               LWIP_DEBUGF(SOCKETS_DEBUG,
+                           ("failed to allocate descriptor %d\n",
+                            errno));
                ret = -1;
                /* Setting the errno */
                SOCK_NET_SET_ERRNO(vfs_fd);
@@ -160,28 +205,31 @@ int accept(int s, struct sockaddr *addr, socklen_t 
*addrlen)
        int ret = 0;
        struct sock_net_file *file;
        int sock_fd, vfs_fd;
+
        file = sock_net_file_get(s);
-       if(PTRISERR(file)) {
-               uk_printd(DLVL_ERR, "failed to accept incomingi connection \n");
+       if (PTRISERR(file)) {
+               LWIP_DEBUGF(SOCKETS_DEBUG,
+                           ("failed to accept incomingi connection\n"));
                ret = -1;
                /* Setting the errno */
                SOCK_NET_SET_ERRNO(PTR2ERR(file));
-               goto EXIT;
+               goto EXIT;
        }
/* Accept an incoming connection */
        sock_fd = lwip_accept(file->sock_fd, addr, addrlen);
-       if(0 > sock_fd) {
-               uk_printd(DLVL_ERR, "failed to accept incoming connection \n");
+       if (sock_fd < 0) {
+               LWIP_DEBUGF(SOCKETS_DEBUG,
+                           ("failed to accept incoming connection\n"));
                ret = -1;
                goto EXIT;
        }
/* Allocate the file descriptor for the accepted connection */
        vfs_fd = sock_fd_alloc(&sock_net_fops, sock_fd);
-       if(0 > vfs_fd) {
-               uk_printd(DLVL_ERR, "failed to allocate    descriptor for the"
-                       "accepted connection \n");
+       if (vfs_fd < 0) {
+               LWIP_DEBUGF(SOCKETS_DEBUG,
+                           ("failed to allocate descriptor for accepted 
connection\n"));
                ret = -1;
                /* Setting the errno */
                SOCK_NET_SET_ERRNO(vfs_fd);
@@ -200,9 +248,11 @@ int bind(int s, const struct sockaddr *name, socklen_t 
namelen)
  {
        int ret = 0;
        struct sock_net_file *file = NULL;
+
        file = sock_net_file_get(s);
-       if(PTRISERR(file)) {
-               uk_printd(DLVL_ERR, "failed to identify the socket descriptor 
\n");
+       if (PTRISERR(file)) {
+               LWIP_DEBUGF(SOCKETS_DEBUG,
+                           ("failed to identify socket descriptor\n"));
                ret = -1;
                /* Setting the errno */
                SOCK_NET_SET_ERRNO(PTR2ERR(file));
@@ -210,8 +260,9 @@ int bind(int s, const struct sockaddr *name, socklen_t 
namelen)
        }
        /* Bind an incoming connection */
        ret = lwip_bind(file->sock_fd, name, namelen);
-       if(0 > ret) {
-               uk_printd(DLVL_ERR, "failed to bind with the socket \n");
+       if (ret < 0) {
+               LWIP_DEBUGF(SOCKETS_DEBUG,
+                           ("failed to bind with socket\n"));
                ret = -1;
                goto EXIT;
        }
@@ -223,9 +274,11 @@ int shutdown(int s, int how)
  {
        int ret = 0;
        struct sock_net_file *file = NULL;
+
        file = sock_net_file_get(s);
-       if(PTRISERR(file)) {
-               uk_printd(DLVL_ERR, "failed to identify the socket descriptor 
\n");
+       if (PTRISERR(file)) {
+               LWIP_DEBUGF(SOCKETS_DEBUG,
+                           ("failed to identify socket descriptor\n"));
                ret = -1;
                /* Setting the errno */
                SOCK_NET_SET_ERRNO(PTR2ERR(file));
@@ -241,9 +294,10 @@ int getpeername(int s, struct sockaddr *name, socklen_t 
*namelen)
  {
        int ret = 0;
        struct sock_net_file *file = NULL;
+
        file = sock_net_file_get(s);
-       if(PTRISERR(file)) {
-               uk_printd(DLVL_ERR, "failed to identify the socket\n");
+       if (PTRISERR(file)) {
+               LWIP_DEBUGF(SOCKETS_DEBUG, ("failed to identify socket\n"));
                ret = -1;
                SOCK_NET_SET_ERRNO(PTR2ERR(file));
                goto EXIT;
@@ -257,9 +311,10 @@ int getsockname(int s, struct sockaddr *name, socklen_t 
*namelen)
  {
        int ret = 0;
        struct sock_net_file *file = NULL;
+
        file = sock_net_file_get(s);
-       if(PTRISERR(file)) {
-               uk_printd(DLVL_ERR, "failed to identify the socket\n");
+       if (PTRISERR(file)) {
+               LWIP_DEBUGF(SOCKETS_DEBUG, ("failed to identify socket\n"));
                ret = -1;
                SOCK_NET_SET_ERRNO(PTR2ERR(file));
                goto EXIT;
@@ -273,9 +328,11 @@ int getsockopt(int s, int level, int optname, void 
*optval, socklen_t *optlen)
  {
        int ret = 0;
        struct sock_net_file *file = NULL;
+
        file = sock_net_file_get(s);
-       if(PTRISERR(file)) {
-               uk_printd(DLVL_ERR, "failed to identify the socket descriptor 
\n");
+       if (PTRISERR(file)) {
+               LWIP_DEBUGF(SOCKETS_DEBUG,
+                           ("failed to identify socket descriptor\n"));
                ret = -1;
                SOCK_NET_SET_ERRNO(PTR2ERR(file));
                goto EXIT;
@@ -285,14 +342,16 @@ EXIT:
        return ret;
  }
-int setsockopt (int s, int level, int optname, const void *optval,
-               socklen_t optlen)
+int setsockopt(int s, int level, int optname, const void *optval,
+              socklen_t optlen)
  {
        int ret = 0;
        struct sock_net_file *file = NULL;
+
        file = sock_net_file_get(s);
-       if(PTRISERR(file)) {
-               uk_printd(DLVL_ERR, "failed to identify the socket descriptor 
\n");
+       if (PTRISERR(file)) {
+               LWIP_DEBUGF(SOCKETS_DEBUG,
+                           ("failed to identify socket descriptor\n"));
                ret = -1;
                SOCK_NET_SET_ERRNO(PTR2ERR(file));
                goto EXIT;
@@ -306,9 +365,11 @@ int connect(int s, const struct sockaddr *name, socklen_t 
namelen)
  {
        int ret = 0;
        struct sock_net_file *file = NULL;
+
        file = sock_net_file_get(s);
-       if(PTRISERR(file)) {
-               uk_printd(DLVL_ERR, "failed to identify the socket descriptor 
\n");
+       if (PTRISERR(file)) {
+               LWIP_DEBUGF(SOCKETS_DEBUG,
+                           ("failed to identify socket descriptor\n"));
                ret = -1;
                SOCK_NET_SET_ERRNO(PTR2ERR(file));
                goto EXIT;
@@ -322,9 +383,11 @@ int listen(int s, int backlog)
  {
        int ret = 0;
        struct sock_net_file *file = NULL;
+
        file = sock_net_file_get(s);
-       if(PTRISERR(file)) {
-               uk_printd(DLVL_ERR, "failed to identify the socket descriptor 
\n");
+       if (PTRISERR(file)) {
+               LWIP_DEBUGF(SOCKETS_DEBUG,
+                           ("failed to identify socket descriptor\n"));
                ret = -1;
                SOCK_NET_SET_ERRNO(PTR2ERR(file));
                goto EXIT;
@@ -338,9 +401,11 @@ int recv(int s, void *mem, size_t len, int flags)
  {
        int ret = 0;
        struct sock_net_file *file = NULL;
+
        file = sock_net_file_get(s);
-       if(PTRISERR(file)) {
-               uk_printd(DLVL_ERR, "failed to identify the socket descriptor 
\n");
+       if (PTRISERR(file)) {
+               LWIP_DEBUGF(SOCKETS_DEBUG,
+                           ("failed to identify socket descriptor\n"));
                ret = -1;
                SOCK_NET_SET_ERRNO(PTR2ERR(file));
                goto EXIT;
@@ -355,9 +420,11 @@ int recvfrom(int s, void *mem, size_t len, int flags,
  {
        int ret = 0;
        struct sock_net_file *file = NULL;
+
        file = sock_net_file_get(s);
-       if(PTRISERR(file)) {
-               uk_printd(DLVL_ERR, "failed to identify the socket descriptor 
\n");
+       if (PTRISERR(file)) {
+               LWIP_DEBUGF(SOCKETS_DEBUG,
+                           ("failed to identify socket descriptor\n"));
                ret = -1;
                SOCK_NET_SET_ERRNO(PTR2ERR(file));
                goto EXIT;
@@ -371,9 +438,11 @@ int send(int s, const void *dataptr, size_t size, int 
flags)
  {
        int ret = 0;
        struct sock_net_file *file = NULL;
+
        file = sock_net_file_get(s);
-       if(PTRISERR(file)) {
-               uk_printd(DLVL_ERR, "failed to identify the socket descriptor 
\n");
+       if (PTRISERR(file)) {
+               LWIP_DEBUGF(SOCKETS_DEBUG,
+                           ("failed to identify socket descriptor\n"));
                ret = -1;
                SOCK_NET_SET_ERRNO(PTR2ERR(file));
                goto EXIT;
@@ -387,9 +456,11 @@ int sendmsg(int s, const struct msghdr *message, int flags)
  {
        int ret = 0;
        struct sock_net_file *file = NULL;
+
        file = sock_net_file_get(s);
-       if(PTRISERR(file)) {
-               uk_printd(DLVL_ERR, "failed to identify the socket descriptor 
\n");
+       if (PTRISERR(file)) {
+               LWIP_DEBUGF(SOCKETS_DEBUG,
+                           ("failed to identify socket descriptor\n"));
                ret = -1;
                SOCK_NET_SET_ERRNO(PTR2ERR(file));
                goto EXIT;
@@ -404,9 +475,11 @@ int sendto(int s, const void *dataptr, size_t size, int 
flags,
  {
        int ret = 0;
        struct sock_net_file *file = NULL;
+
        file = sock_net_file_get(s);
-       if(PTRISERR(file)) {
-               uk_printd(DLVL_ERR, "failed to identify the socket descriptor 
\n");
+       if (PTRISERR(file)) {
+               LWIP_DEBUGF(SOCKETS_DEBUG,
+                           ("failed to identify socket descriptor\n"));
                ret = -1;
                SOCK_NET_SET_ERRNO(PTR2ERR(file));
                goto EXIT;
@@ -415,11 +488,3 @@ int sendto(int s, const void *dataptr, size_t size, int 
flags,
  EXIT:
        return ret;
  }
-
-int select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set
-               *exceptset, struct timeval *timeout)
-{
-       int ret = -1;
-       SOCK_NET_SET_ERRNO(-ENOTSUP);
-       return ret;
-}
diff --git a/threads.c b/threads.c
index 1e6be4d..3ec06fa 100644
--- a/threads.c
+++ b/threads.c
@@ -1,23 +1,59 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Copyright (c) 2019, NEC Laboratories Europe GmbH, NEC Corporation.
+ *                     All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+
  #include <uk/arch/limits.h>
  #include <uk/sched.h>
  #include <uk/thread.h>
  #include <uk/print.h>
  #include <uk/assert.h>
  #include <lwip/sys.h>
+#include <uk/essentials.h>
-/* Starts a new thread with priority "prio" that will begin its execution in the
+/**
+ * Starts a new thread with priority "prio" that will begin its execution in 
the
   * function "thread()". The "arg" argument will be passed as an argument to 
the
   * thread() function. The id of the new thread is returned. Both the id and
- * the priority are system dependent. */
+ * the priority are system dependent.
+ */
  sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void 
*arg,
-                               int stacksize, int prio)
+                           int stacksize, int prio __unused)
  {
        struct uk_thread *t;
-       if (stacksize > __STACK_SIZE) {
-               uk_printd(DLVL_CRIT, "Can't create lwIP thread: stack size %u is too 
large (> %u)\n",
-                                       stacksize, __STACK_SIZE);
-               UK_CRASH("Dying\n");
+
+       if (stacksize > (__ssz) __STACK_SIZE) {
+               UK_CRASH("Can't create lwIP thread: stack size %u is too large (> 
%llu). Dying...\n",
+                        stacksize, __STACK_SIZE);
        }
-       t = uk_thread_create((char *) name, thread, arg);
+       t = uk_thread_create(name, thread, arg);
        return t;
  }
diff --git a/time.c b/time.c
index ca6be8f..f6b1050 100644
--- a/time.c
+++ b/time.c
@@ -1,3 +1,36 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Copyright (c) 2019, NEC Laboratories Europe GmbH, NEC Corporation.
+ *                     All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+
  #include <uk/arch/time.h>
  #include <uk/plat/time.h>
  #include <lwip/sys.h>


_______________________________________________
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®.