default n
select LIBNOLIBC if !HAVE_LIBC
select LIBUKDEBUG
+ select LIBUKSWRAND
+ 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
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"
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
# Simon Kuenzer <simon.kuenzer@neclab.eu>
#
#
-# 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
################################################################################
# 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)))
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
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
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
+/* 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)
#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__ */
+/* 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
*
#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>
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;
--- /dev/null
+#include <compat/posix/arpa/inet.h>
* Configuration for lwIP running on mini-os
*
* Tim Deegan <Tim.Deegan@eu.citrix.net>, July 2007
- * Simon Kuenzer <simon.kuenzer@neclab.eu>, October 2013
+ * Simon Kuenzer <simon.kuenzer@neclab.eu>, 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
* 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)
#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);
#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
#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))
#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
#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
#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__ */
--- /dev/null
+#include <compat/posix/net/if.h>
--- /dev/null
+#include <compat/posix/netdb.h>
-#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_ */
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Simon Kuenzer <simon.kuenzer@neclab.eu>
+ *
+ * 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;
}
+/* 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>
/* 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 =
*
* 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.
*
* 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;
}
+/* 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);
sys_mutex_set_invalid(mtx);
}
-/* Signals a mtxaphore. */
void sys_mutex_lock(sys_mutex_t *mtx)
{
- uk_mutex_hold(&mtx->mtx);
+ uk_mutex_lock(&mtx->mtx);
}
+/* Signals on mutex. */
void sys_mutex_unlock(sys_mutex_t *mtx)
{
- uk_mutex_release(&mtx->mtx);
+ uk_mutex_unlock(&mtx->mtx);
}
+/* 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);
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).
* 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);
}
+++ /dev/null
-/* 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)
-
-
-struct sock_net_file {
- struct vfscore_file vfscore_file;
- int sock_fd;
-};
-
-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");
- file = ERR2PTR(-EINVAL);
- goto EXIT;
- }
- file = __containerof(fos, struct sock_net_file, vfscore_file);
-EXIT:
- return file;
-}
-
-static int sock_fd_alloc(struct vfscore_fops *fops, int sock_fd)
-{
- int ret = 0;
- int vfs_fd;
- struct sock_net_file *file = NULL;
-
- /* Allocate file descriptor */
- vfs_fd = vfscore_alloc_fd();
- if (vfs_fd < 0) {
- ret = -ENFILE;
- uk_printd(DLVL_ERR, "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");
- 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);
- /* Storing the information within the vfs structure */
- vfscore_install_fd(vfs_fd, &file->vfscore_file);
- ret = vfs_fd;
-EXIT:
- return ret;
-
-UK_MEM_ALLOC_ERR:
- vfscore_put_fd(vfs_fd);
- goto EXIT;
-}
-
-static int sock_net_close(struct vfscore_file *vfscore_file)
-{
- 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);
-
- /* Close and release the lwip socket */
- ret = lwip_close(file->sock_fd);
- /* Release the file descriptor */
- vfscore_put_fd(file->vfscore_file.fd);
- /* Free the sock net structure */
- uk_free(uk_alloc_get_default(), file);
- return ret;
-}
-
-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);
- ret = lwip_write(file->sock_fd, buf, count);
- return ret;
-}
-
-static ssize_t sock_net_read(struct vfscore_file *vfscore_file, 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);
- ret = lwip_read(file->sock_fd, buf, count);
- return ret;
-}
-
-static struct vfscore_fops sock_net_fops = {
- .close = sock_net_close,
- .write = sock_net_write,
- .read = sock_net_read,
-};
-
-int socket(int domain, int type, int protocol)
-{
- int ret = 0;
- int vfs_fd = 0xff;
- int sock_fd = 0;
-
- /* 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);
- 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);
- ret = -1;
- /* Setting the errno */
- SOCK_NET_SET_ERRNO(vfs_fd);
- goto LWIP_SOCKET_CLEANUP;
- }
-
- /* Returning the file descriptor to the user */
- ret = vfs_fd;
-EXIT:
- return ret;
-LWIP_SOCKET_CLEANUP:
- /* Cleanup the lwip socket */
- lwip_close(sock_fd);
- goto EXIT;
-}
-
-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");
- ret = -1;
- /* Setting the errno */
- SOCK_NET_SET_ERRNO(PTR2ERR(file));
- 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");
- 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");
- ret = -1;
- /* Setting the errno */
- SOCK_NET_SET_ERRNO(vfs_fd);
- goto LWIP_SOCKET_CLEANUP;
- }
- ret = vfs_fd;
-EXIT:
- return ret;
-
-LWIP_SOCKET_CLEANUP:
- lwip_close(sock_fd);
- goto EXIT;
-}
-
-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");
- ret = -1;
- /* Setting the errno */
- SOCK_NET_SET_ERRNO(PTR2ERR(file));
- goto EXIT;
- }
- /* 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");
- ret = -1;
- goto EXIT;
- }
-EXIT:
- return ret;
-}
-
-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");
- ret = -1;
- /* Setting the errno */
- SOCK_NET_SET_ERRNO(PTR2ERR(file));
- goto EXIT;
- }
- /* Shutdown of the descriptor */
- ret = lwip_shutdown(file->sock_fd, how);
-EXIT:
- return ret;
-}
-
-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");
- ret = -1;
- SOCK_NET_SET_ERRNO(PTR2ERR(file));
- goto EXIT;
- }
- ret = lwip_getpeername(file->sock_fd, name, namelen);
-EXIT:
- return ret;
-}
-
-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");
- ret = -1;
- SOCK_NET_SET_ERRNO(PTR2ERR(file));
- goto EXIT;
- }
- ret = lwip_getsockname(file->sock_fd, name, namelen);
-EXIT:
- return ret;
-}
-
-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");
- ret = -1;
- SOCK_NET_SET_ERRNO(PTR2ERR(file));
- goto EXIT;
- }
- ret = lwip_getsockopt(file->sock_fd, level, optname, optval, optlen);
-EXIT:
- return ret;
-}
-
-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");
- ret = -1;
- SOCK_NET_SET_ERRNO(PTR2ERR(file));
- goto EXIT;
- }
- ret = lwip_setsockopt(file->sock_fd, level, optname, optval, optlen);
-EXIT:
- return ret;
-}
-
-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");
- ret = -1;
- SOCK_NET_SET_ERRNO(PTR2ERR(file));
- goto EXIT;
- }
- ret = lwip_connect(file->sock_fd, name, namelen);
-EXIT:
- return ret;
-}
-
-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");
- ret = -1;
- SOCK_NET_SET_ERRNO(PTR2ERR(file));
- goto EXIT;
- }
- ret = lwip_listen(file->sock_fd, backlog);
-EXIT:
- return ret;
-}
-
-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");
- ret = -1;
- SOCK_NET_SET_ERRNO(PTR2ERR(file));
- goto EXIT;
- }
- ret = lwip_recv(file->sock_fd, mem, len, flags);
-EXIT:
- return ret;
-}
-
-int recvfrom(int s, void *mem, size_t len, int flags,
- struct sockaddr *from, socklen_t *fromlen)
-{
- 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");
- ret = -1;
- SOCK_NET_SET_ERRNO(PTR2ERR(file));
- goto EXIT;
- }
- ret = lwip_recvfrom(file->sock_fd, mem, len, flags, from, fromlen);
-EXIT:
- return ret;
-}
-
-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");
- ret = -1;
- SOCK_NET_SET_ERRNO(PTR2ERR(file));
- goto EXIT;
- }
- ret = lwip_send(file->sock_fd, dataptr, size, flags);
-EXIT:
- return ret;
-}
-
-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");
- ret = -1;
- SOCK_NET_SET_ERRNO(PTR2ERR(file));
- goto EXIT;
- }
- ret = lwip_sendmsg(file->sock_fd, message, flags);
-EXIT:
- return ret;
-}
-
-int sendto(int s, const void *dataptr, size_t size, int flags,
- const struct sockaddr *to, socklen_t tolen)
-{
- 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");
- ret = -1;
- SOCK_NET_SET_ERRNO(PTR2ERR(file));
- goto EXIT;
- }
- ret = lwip_sendto(file->sock_fd, dataptr, size, flags, to, tolen);
-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;
-}
--- /dev/null
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Sharan Santhanam <sharan.santhanam@neclab.eu>
+ *
+ * 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/errptr.h>
+#include <stdio.h>
+#include <errno.h>
+#include <lwip/sockets.h>
+
+#define SOCK_NET_SET_ERRNO(errcode) \
+ (errno = -(errcode))
+
+struct sock_net_file {
+ struct vfscore_file vfscore_file;
+ int sock_fd;
+};
+
+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 (!fos) {
+ LWIP_DEBUGF(SOCKETS_DEBUG,
+ ("failed with invalid descriptor\n"));
+ file = ERR2PTR(-EINVAL);
+ goto EXIT;
+ }
+ file = __containerof(fos, struct sock_net_file, vfscore_file);
+EXIT:
+ return file;
+}
+
+static int sock_fd_alloc(struct vfscore_fops *fops, int sock_fd)
+{
+ int ret = 0;
+ int vfs_fd;
+ struct sock_net_file *file = NULL;
+
+ /* Allocate file descriptor */
+ vfs_fd = vfscore_alloc_fd();
+ if (vfs_fd < 0) {
+ ret = -ENFILE;
+ 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;
+ 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;
+ 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;
+EXIT:
+ return ret;
+
+UK_MEM_ALLOC_ERR:
+ vfscore_put_fd(vfs_fd);
+ goto EXIT;
+}
+
+static int sock_net_close(struct vfscore_file *vfscore_file)
+{
+ int ret = 0;
+ struct sock_net_file *file = NULL;
+
+ file = __containerof(vfscore_file, struct sock_net_file, vfscore_file);
+
+ 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);
+ /* Release the file descriptor */
+ vfscore_put_fd(file->vfscore_file.fd);
+ /* Free the sock net structure */
+ uk_free(uk_alloc_get_default(), file);
+ return ret;
+}
+
+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);
+ 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;
+}
+
+static ssize_t sock_net_read(struct vfscore_file *vfscore_file, void *buf,
+ size_t count)
+{
+ int ret = 0;
+ struct sock_net_file *file = NULL;
+
+ file = __containerof(vfscore_file, struct sock_net_file,
+ 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;
+}
+
+static struct vfscore_fops sock_net_fops = {
+ .close = sock_net_close,
+ .write = sock_net_write,
+ .read = sock_net_read,
+};
+
+int socket(int domain, int type, int protocol)
+{
+ int ret = 0;
+ int vfs_fd = 0xff;
+ int sock_fd = 0;
+
+ /* Create lwip_socket */
+ sock_fd = lwip_socket(domain, type, protocol);
+ 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 (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);
+ goto LWIP_SOCKET_CLEANUP;
+ }
+
+ /* Returning the file descriptor to the user */
+ ret = vfs_fd;
+EXIT:
+ return ret;
+LWIP_SOCKET_CLEANUP:
+ /* Cleanup the lwip socket */
+ lwip_close(sock_fd);
+ goto EXIT;
+}
+
+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)) {
+ LWIP_DEBUGF(SOCKETS_DEBUG,
+ ("failed to accept incomingi connection\n"));
+ ret = -1;
+ /* Setting the errno */
+ SOCK_NET_SET_ERRNO(PTR2ERR(file));
+ goto EXIT;
+ }
+
+ /* Accept an incoming connection */
+ sock_fd = lwip_accept(file->sock_fd, addr, addrlen);
+ 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 (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);
+ goto LWIP_SOCKET_CLEANUP;
+ }
+ ret = vfs_fd;
+EXIT:
+ return ret;
+
+LWIP_SOCKET_CLEANUP:
+ lwip_close(sock_fd);
+ goto EXIT;
+}
+
+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)) {
+ LWIP_DEBUGF(SOCKETS_DEBUG,
+ ("failed to identify socket descriptor\n"));
+ ret = -1;
+ /* Setting the errno */
+ SOCK_NET_SET_ERRNO(PTR2ERR(file));
+ goto EXIT;
+ }
+ /* Bind an incoming connection */
+ ret = lwip_bind(file->sock_fd, name, namelen);
+ if (ret < 0) {
+ LWIP_DEBUGF(SOCKETS_DEBUG,
+ ("failed to bind with socket\n"));
+ ret = -1;
+ goto EXIT;
+ }
+EXIT:
+ return ret;
+}
+
+int shutdown(int s, int how)
+{
+ int ret = 0;
+ struct sock_net_file *file = NULL;
+
+ file = sock_net_file_get(s);
+ if (PTRISERR(file)) {
+ LWIP_DEBUGF(SOCKETS_DEBUG,
+ ("failed to identify socket descriptor\n"));
+ ret = -1;
+ /* Setting the errno */
+ SOCK_NET_SET_ERRNO(PTR2ERR(file));
+ goto EXIT;
+ }
+ /* Shutdown of the descriptor */
+ ret = lwip_shutdown(file->sock_fd, how);
+EXIT:
+ return ret;
+}
+
+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)) {
+ LWIP_DEBUGF(SOCKETS_DEBUG, ("failed to identify socket\n"));
+ ret = -1;
+ SOCK_NET_SET_ERRNO(PTR2ERR(file));
+ goto EXIT;
+ }
+ ret = lwip_getpeername(file->sock_fd, name, namelen);
+EXIT:
+ return ret;
+}
+
+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)) {
+ LWIP_DEBUGF(SOCKETS_DEBUG, ("failed to identify socket\n"));
+ ret = -1;
+ SOCK_NET_SET_ERRNO(PTR2ERR(file));
+ goto EXIT;
+ }
+ ret = lwip_getsockname(file->sock_fd, name, namelen);
+EXIT:
+ return ret;
+}
+
+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)) {
+ LWIP_DEBUGF(SOCKETS_DEBUG,
+ ("failed to identify socket descriptor\n"));
+ ret = -1;
+ SOCK_NET_SET_ERRNO(PTR2ERR(file));
+ goto EXIT;
+ }
+ ret = lwip_getsockopt(file->sock_fd, level, optname, optval, optlen);
+EXIT:
+ return ret;
+}
+
+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)) {
+ LWIP_DEBUGF(SOCKETS_DEBUG,
+ ("failed to identify socket descriptor\n"));
+ ret = -1;
+ SOCK_NET_SET_ERRNO(PTR2ERR(file));
+ goto EXIT;
+ }
+ ret = lwip_setsockopt(file->sock_fd, level, optname, optval, optlen);
+EXIT:
+ return ret;
+}
+
+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)) {
+ LWIP_DEBUGF(SOCKETS_DEBUG,
+ ("failed to identify socket descriptor\n"));
+ ret = -1;
+ SOCK_NET_SET_ERRNO(PTR2ERR(file));
+ goto EXIT;
+ }
+ ret = lwip_connect(file->sock_fd, name, namelen);
+EXIT:
+ return ret;
+}
+
+int listen(int s, int backlog)
+{
+ int ret = 0;
+ struct sock_net_file *file = NULL;
+
+ file = sock_net_file_get(s);
+ if (PTRISERR(file)) {
+ LWIP_DEBUGF(SOCKETS_DEBUG,
+ ("failed to identify socket descriptor\n"));
+ ret = -1;
+ SOCK_NET_SET_ERRNO(PTR2ERR(file));
+ goto EXIT;
+ }
+ ret = lwip_listen(file->sock_fd, backlog);
+EXIT:
+ return ret;
+}
+
+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)) {
+ LWIP_DEBUGF(SOCKETS_DEBUG,
+ ("failed to identify socket descriptor\n"));
+ ret = -1;
+ SOCK_NET_SET_ERRNO(PTR2ERR(file));
+ goto EXIT;
+ }
+ ret = lwip_recv(file->sock_fd, mem, len, flags);
+EXIT:
+ return ret;
+}
+
+int recvfrom(int s, void *mem, size_t len, int flags,
+ struct sockaddr *from, socklen_t *fromlen)
+{
+ int ret = 0;
+ struct sock_net_file *file = NULL;
+
+ file = sock_net_file_get(s);
+ if (PTRISERR(file)) {
+ LWIP_DEBUGF(SOCKETS_DEBUG,
+ ("failed to identify socket descriptor\n"));
+ ret = -1;
+ SOCK_NET_SET_ERRNO(PTR2ERR(file));
+ goto EXIT;
+ }
+ ret = lwip_recvfrom(file->sock_fd, mem, len, flags, from, fromlen);
+EXIT:
+ return ret;
+}
+
+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)) {
+ LWIP_DEBUGF(SOCKETS_DEBUG,
+ ("failed to identify socket descriptor\n"));
+ ret = -1;
+ SOCK_NET_SET_ERRNO(PTR2ERR(file));
+ goto EXIT;
+ }
+ ret = lwip_send(file->sock_fd, dataptr, size, flags);
+EXIT:
+ return ret;
+}
+
+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)) {
+ LWIP_DEBUGF(SOCKETS_DEBUG,
+ ("failed to identify socket descriptor\n"));
+ ret = -1;
+ SOCK_NET_SET_ERRNO(PTR2ERR(file));
+ goto EXIT;
+ }
+ ret = lwip_sendmsg(file->sock_fd, message, flags);
+EXIT:
+ return ret;
+}
+
+int sendto(int s, const void *dataptr, size_t size, int flags,
+ const struct sockaddr *to, socklen_t tolen)
+{
+ int ret = 0;
+ struct sock_net_file *file = NULL;
+
+ file = sock_net_file_get(s);
+ if (PTRISERR(file)) {
+ LWIP_DEBUGF(SOCKETS_DEBUG,
+ ("failed to identify socket descriptor\n"));
+ ret = -1;
+ SOCK_NET_SET_ERRNO(PTR2ERR(file));
+ goto EXIT;
+ }
+ ret = lwip_sendto(file->sock_fd, dataptr, size, flags, to, tolen);
+EXIT:
+ return ret;
+}
+/* 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;
}
+/* 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>