diff --git a/ext/ZeroTierOne.patch b/ext/ZeroTierOne.patch index 7ffc17b..5a766ab 100644 --- a/ext/ZeroTierOne.patch +++ b/ext/ZeroTierOne.patch @@ -1,3 +1,41 @@ +diff --git a/node/RingBuffer.hpp b/node/RingBuffer.hpp +index dab81b9e..0d90152b 100644 +--- a/node/RingBuffer.hpp ++++ b/node/RingBuffer.hpp +@@ -72,6 +72,11 @@ public: + memset(buf, 0, sizeof(T) * size); + } + ++ ~RingBuffer() ++ { ++ delete [] buf; ++ } ++ + /** + * @return A pointer to the underlying buffer + */ +diff --git a/node/Switch.cpp b/node/Switch.cpp +index 74c22d33..58979e26 100644 +--- a/node/Switch.cpp ++++ b/node/Switch.cpp +@@ -532,7 +532,7 @@ void Switch::aqm_enqueue(void *tPtr, const SharedPtr &network, Packet & + TXQueueEntry *txEntry = new TXQueueEntry(dest,RR->node->now(),packet,encrypt); + + ManagedQueue *selectedQueue = nullptr; +- for (int i=0; ioldQueues.size()) { // search old queues first (I think this is best since old would imply most recent usage of the queue) + if (nqcb->oldQueues[i]->id == qosBucket) { + selectedQueue = nqcb->oldQueues[i]; +@@ -568,7 +568,7 @@ void Switch::aqm_enqueue(void *tPtr, const SharedPtr &network, Packet & + { + // DEBUG_INFO("too many enqueued packets (%d), finding packet to drop", nqcb->_currEnqueuedPackets); + int maxQueueLength = 0; +- for (int i=0; ioldQueues.size()) { + if (nqcb->oldQueues[i]->byteLength > maxQueueLength) { + maxQueueLength = nqcb->oldQueues[i]->byteLength; diff --git a/service/OneService.cpp b/service/OneService.cpp index a1c53764..757863a8 100644 --- a/service/OneService.cpp diff --git a/ext/lwip b/ext/lwip index 92f23d6..159e31b 160000 --- a/ext/lwip +++ b/ext/lwip @@ -1 +1 @@ -Subproject commit 92f23d6ca0971a32f2085b9480e738d34174417b +Subproject commit 159e31b689577dbf69cf0683bbaffbd71fa5ee10 diff --git a/ext/lwip-contrib b/ext/lwip-contrib index 4d18380..35b011d 160000 --- a/ext/lwip-contrib +++ b/ext/lwip-contrib @@ -1 +1 @@ -Subproject commit 4d1838043ec8d31ff308fa10326ea8e3a61063cd +Subproject commit 35b011d4cf4c4b480f8859c456587a884ec9d287 diff --git a/ext/lwip-contrib.patch b/ext/lwip-contrib.patch index 6f5d026..8d80f11 100644 --- a/ext/lwip-contrib.patch +++ b/ext/lwip-contrib.patch @@ -1,17 +1,17 @@ diff --git a/ports/unix/port/include/arch/cc.h b/ports/unix/port/include/arch/cc.h -index a3dac04..424285e 100644 +index 80b37d8..ae46d76 100644 --- a/ports/unix/port/include/arch/cc.h +++ b/ports/unix/port/include/arch/cc.h @@ -32,6 +32,8 @@ #ifndef LWIP_ARCH_CC_H #define LWIP_ARCH_CC_H -+#include "include/Debug.hpp" ++#include "include/Debug.hpp" // libzt + /* see https://sourceforge.net/p/predef/wiki/OperatingSystems/ */ #if defined __ANDROID__ #define LWIP_UNIX_ANDROID -@@ -55,7 +57,7 @@ +@@ -65,7 +67,7 @@ #endif #if defined(LWIP_UNIX_ANDROID) && defined(FD_SET) @@ -19,27 +19,14 @@ index a3dac04..424285e 100644 +//typedef __kernel_fd_set fd_set; #endif - struct sio_status_s; -@@ -63,4 +65,7 @@ typedef struct sio_status_s sio_status_t; + #if defined(LWIP_UNIX_MACH) +@@ -81,6 +83,9 @@ typedef struct sio_status_s sio_status_t; #define sio_fd_t sio_status_t* #define __sio_fd_t_defined +// Comment out the following line to use lwIP's default diagnostic printing routine +#define LWIP_PLATFORM_DIAG(x) do {DEBUG_INFO x;} while(0) + + typedef unsigned int sys_prot_t; + #endif /* LWIP_ARCH_CC_H */ -diff --git a/ports/win32/include/arch/cc.h b/ports/win32/include/arch/cc.h -index 334be07..9384b70 100644 ---- a/ports/win32/include/arch/cc.h -+++ b/ports/win32/include/arch/cc.h -@@ -78,8 +78,8 @@ typedef int sys_prot_t; - - #ifdef _MSC_VER - /* C runtime functions redefined */ --#define snprintf _snprintf --#define strdup _strdup -+//#define snprintf _snprintf -+//#define strdup _strdup - #endif - - #define PPP_INCLUDE_SETTINGS_HEADER diff --git a/ext/lwip.patch b/ext/lwip.patch deleted file mode 100644 index 047f87f..0000000 --- a/ext/lwip.patch +++ /dev/null @@ -1,232 +0,0 @@ -diff --git a/src/api/sockets.c b/src/api/sockets.c -index b7632489..786a294e 100644 ---- a/src/api/sockets.c -+++ b/src/api/sockets.c -@@ -44,6 +44,8 @@ - * - */ - -+//#include -+ - #include "lwip/opt.h" - - #if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */ -diff --git a/src/api/tcpip.c b/src/api/tcpip.c -index 07b2f984..f10136e2 100644 ---- a/src/api/tcpip.c -+++ b/src/api/tcpip.c -@@ -150,6 +150,11 @@ tcpip_thread(void *arg) - msg->msg.cb.function(msg->msg.cb.ctx); - break; - -+ case TCPIP_MSG_SHUTDOWN: -+ LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: SHUTDOWN %p\n", (void *)msg)); -+ sys_sem_signal(msg->msg.api_call.sem); -+ return; -+ - default: - LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: invalid message: %d\n", msg->type)); - LWIP_ASSERT("tcpip_thread: invalid message", 0); -@@ -158,6 +163,49 @@ tcpip_thread(void *arg) - } - } - -+err_t -+tcpip_shutdown(void) -+{ -+ //struct tcpip_msg msg; -+ sys_sem_t sem; -+ -+ /* If there is no tcpip mailbox, leave */ -+ if (mbox == SYS_MBOX_NULL) -+ return ERR_OK; -+ -+ /* Create semaphore for message */ -+ sys_sem_new(&sem, 0); -+ LWIP_ASSERT("tcpip_terminate: failed to create semaphore\n", -+ sem != SYS_SEM_NULL); -+ if (sem == SYS_SEM_NULL) { -+ return ERR_MEM; -+ } -+ -+ /* TODO: do we need to stop the timers? if so, how? */ -+ -+ struct tcpip_msg *msg; -+ LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(mbox)); -+ msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_INPKT); -+ -+ /* Tell tcpip thread to exit, and wait */ -+ msg->msg.api_call.sem = &sem; -+ msg->type = TCPIP_MSG_SHUTDOWN; -+ -+ if (sys_mbox_trypost(&mbox, msg) != ERR_OK) { -+ memp_free(MEMP_TCPIP_MSG_INPKT, msg); -+ return ERR_MEM; -+ } -+ -+ sys_arch_sem_wait(&sem, 0); -+ -+ /* clean up tcpip thread resources */ -+ -+ //sys_mbox_free(&mbox); -+ sys_sem_free(&sem); -+ mbox = SYS_MBOX_NULL; -+ return ERR_OK; -+} -+ - /** - * Pass a received packet to tcpip_thread for input processing - * -diff --git a/src/core/ipv6/ip6.c b/src/core/ipv6/ip6.c -index f14e3342..facd3b21 100644 ---- a/src/core/ipv6/ip6.c -+++ b/src/core/ipv6/ip6.c -@@ -264,6 +264,17 @@ ip6_select_source_address(struct netif *netif, const ip6_addr_t *dest) - } - } - -+ /* Choose a ZeroTier adhoc with matching prefix. */ -+ if (ip6_addr_is_zt_adhoc(dest)) { -+ for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) { -+ if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) && -+ ip6_addr_is_zt_adhoc(netif_ip6_addr(netif, i)) && -+ ip6_addr_6plane_cmp(dest, netif_ip6_addr(netif, i))) { -+ return netif_ip_addr6(netif, i); -+ } -+ } -+ } -+ - /* Last resort: see if arbitrary prefix matches. */ - for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) { - if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) && -diff --git a/src/core/ipv6/nd6.c b/src/core/ipv6/nd6.c -index 0b367181..2a5b77d4 100644 ---- a/src/core/ipv6/nd6.c -+++ b/src/core/ipv6/nd6.c -@@ -1361,8 +1361,13 @@ nd6_is_prefix_in_netif(const ip6_addr_t *ip6addr, struct netif *netif) - } - /* Check to see if address prefix matches a (manually?) configured address. */ - for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) { -- if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) && -- ip6_addr_netcmp(ip6addr, netif_ip6_addr(netif, i))) { -+ int prefix_match = 0; -+ if (ip6_addr_is_zt_6plane(ip6addr) || ip6_addr_is_zt_adhoc(ip6addr)) { -+ prefix_match = ip6_addr_6plane_cmp(ip6addr, netif_ip6_addr(netif, i)); -+ } else { -+ prefix_match = ip6_addr_netcmp(ip6addr, netif_ip6_addr(netif, i)); -+ } -+ if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) && prefix_match) { - return 1; - } - } -diff --git a/src/core/timeouts.c b/src/core/timeouts.c -index 8bf209a5..cf4e556a 100644 ---- a/src/core/timeouts.c -+++ b/src/core/timeouts.c -@@ -186,6 +186,19 @@ void sys_timeouts_init(void) - timeouts_last_time = sys_now(); - } - -+/** Remove all timeouts */ -+void sys_timeouts_free(void) -+{ -+ size_t i; -+ for (i = (LWIP_TCP ? 1 : 0); i < LWIP_ARRAYSIZE(lwip_cyclic_timers); i++) { -+ /* we have to cast via size_t to get rid of const warning -+ (this is OK as cyclic_timer() casts back to const* */ -+ sys_untimeout(cyclic_timer, LWIP_CONST_CAST(void*, &lwip_cyclic_timers[i])); -+ } -+ /* Initialise timestamp for sys_check_timeouts */ -+ timeouts_last_time = sys_now(); -+} -+ - /** - * Create a one-shot timer (aka timeout). Timeouts are processed in the - * following cases: -diff --git a/src/include/lwip/errno.h b/src/include/lwip/errno.h -index 641cffb0..cec43f7f 100644 ---- a/src/include/lwip/errno.h -+++ b/src/include/lwip/errno.h -@@ -174,7 +174,11 @@ extern "C" { - #define EMEDIUMTYPE 124 /* Wrong medium type */ - - #ifndef errno --extern int errno; -+#if defined(__linux__) && !defined(__ANDROID__) -+ #include -+#else -+ extern int errno; -+#endif - #endif - - #else /* LWIP_PROVIDE_ERRNO */ -diff --git a/src/include/lwip/ip6_addr.h b/src/include/lwip/ip6_addr.h -index ee381aeb..b879f212 100644 ---- a/src/include/lwip/ip6_addr.h -+++ b/src/include/lwip/ip6_addr.h -@@ -133,6 +133,14 @@ typedef struct ip6_addr ip6_addr_t; - #define ip6_addr_netcmp(addr1, addr2) (((addr1)->addr[0] == (addr2)->addr[0]) && \ - ((addr1)->addr[1] == (addr2)->addr[1])) - -+#define ip6_addr_is_zt_6plane(addr1) (((addr1)->addr[0] & PP_HTONL(0xffffffffUL)) == PP_HTONL(0xfc937e7fUL) && \ -+ ((addr1)->addr[1] & PP_HTONL(0xff000000UL)) == PP_HTONL(0x72000000UL)) -+ -+#define ip6_addr_is_zt_adhoc(addr1) (((addr1)->addr[0] & PP_HTONL(0xffff0000UL)) == PP_HTONL(0xfce90000UL)) -+ -+#define ip6_addr_6plane_cmp(addr1, addr2) (((addr1)->addr[0] == (addr2)->addr[0]) && \ -+ ((addr1)->addr[1] & PP_HTONL(0xff000000UL)) == ((addr2)->addr[1] & PP_HTONL(0xff000000UL))) -+ - #define ip6_addr_cmp(addr1, addr2) (((addr1)->addr[0] == (addr2)->addr[0]) && \ - ((addr1)->addr[1] == (addr2)->addr[1]) && \ - ((addr1)->addr[2] == (addr2)->addr[2]) && \ -diff --git a/src/include/lwip/priv/tcpip_priv.h b/src/include/lwip/priv/tcpip_priv.h -index 630efb14..41fb3e60 100644 ---- a/src/include/lwip/priv/tcpip_priv.h -+++ b/src/include/lwip/priv/tcpip_priv.h -@@ -117,7 +117,8 @@ enum tcpip_msg_type { - TCPIP_MSG_UNTIMEOUT, - #endif /* LWIP_TCPIP_TIMEOUT && LWIP_TIMERS */ - TCPIP_MSG_CALLBACK, -- TCPIP_MSG_CALLBACK_STATIC -+ TCPIP_MSG_CALLBACK_STATIC, -+ TCPIP_MSG_SHUTDOWN - }; - - struct tcpip_msg { -diff --git a/src/include/lwip/sockets.h b/src/include/lwip/sockets.h -index 2522056d..1af0c989 100644 ---- a/src/include/lwip/sockets.h -+++ b/src/include/lwip/sockets.h -@@ -104,7 +104,7 @@ struct sockaddr_storage { - - /* If your port already typedef's socklen_t, define SOCKLEN_T_DEFINED - to prevent this code from redefining it. */ --#if !defined(socklen_t) && !defined(SOCKLEN_T_DEFINED) -+#if !defined(socklen_t) && !defined(SOCKLEN_T_DEFINED) && !defined(__ANDROID__) - typedef u32_t socklen_t; - #endif - -diff --git a/src/include/lwip/tcpip.h b/src/include/lwip/tcpip.h -index f2f6b469..60d3578b 100644 ---- a/src/include/lwip/tcpip.h -+++ b/src/include/lwip/tcpip.h -@@ -73,6 +73,7 @@ typedef void (*tcpip_callback_fn)(void *ctx); - struct tcpip_callback_msg; - - void tcpip_init(tcpip_init_done_fn tcpip_init_done, void *arg); -+err_t tcpip_shutdown(); - - err_t tcpip_inpkt(struct pbuf *p, struct netif *inp, netif_input_fn input_fn); - err_t tcpip_input(struct pbuf *p, struct netif *inp); -diff --git a/src/include/lwip/timeouts.h b/src/include/lwip/timeouts.h -index c9b93aa0..74385dd4 100644 ---- a/src/include/lwip/timeouts.h -+++ b/src/include/lwip/timeouts.h -@@ -94,6 +94,7 @@ struct sys_timeo { - }; - - void sys_timeouts_init(void); -+void sys_timeouts_free(void); - - #if LWIP_DEBUG_TIMERNAMES - void sys_timeout_debug(u32_t msecs, sys_timeout_handler handler, void *arg, const char* handler_name); diff --git a/include/lwIP.h b/include/lwIP.h index 258db2f..22c40e3 100644 --- a/include/lwIP.h +++ b/include/lwIP.h @@ -102,6 +102,23 @@ void lwip_dns_init(); */ void lwip_start_dhcp(void *netif); +/** + * @brief Called when the status of a netif changes: + * - Interface is up/down (ZTS_EVENT_NETIF_UP, ZTS_EVENT_NETIF_DOWN) + * - Address changes while up (ZTS_EVENT_NETIF_NEW_ADDRESS) + */ +static void netif_status_callback(struct netif *netif); + +/** + * @brief Called when a netif is removed (ZTS_EVENT_NETIF_INTERFACE_REMOVED) + */ +static void netif_remove_callback(struct netif *netif); + +/** + * @brief Called when a link is brought up or down (ZTS_EVENT_NETIF_LINK_UP, ZTS_EVENT_NETIF_LINK_DOWN) + */ +static void netif_link_callback(struct netif *netif); + /** * @brief Set up an interface in the network stack for the VirtualTap. * diff --git a/include/lwipopts.h b/include/lwipopts.h index 7f96921..e72350d 100644 --- a/include/lwipopts.h +++ b/include/lwipopts.h @@ -33,11 +33,17 @@ /** * @file * - * lwIP options configuration + * lwIP Options Configuration */ -#ifndef __LWIPOPTS_H__ -#define __LWIPOPTS_H__ +/* + * NOTE: || defined __DOXYGEN__ is a workaround for doxygen bug - + * without this, doxygen does not see the actual #define + */ + +#ifndef _LWIPOPTS_H_ +#define _LWIPOPTS_H_ + /*------------------------------------------------------------------------------ ------------------- Custom additions to lwipopts.h for libzt ------------------- ------------------------------------------------------------------------------*/ @@ -55,7 +61,7 @@ /** * Disable assertions */ -#define LWIP_NOASSERT 1 +#define LWIP_NOASSERT 0 /** * Don't redefine byte-order functions if they're already available @@ -101,7 +107,6 @@ ----------------------- Below: Modified contents of opt.h ---------------------- ------------------------------------------------------------------------------*/ - /** * @defgroup lwip_opts Options (lwipopts.h) * @ingroup lwip @@ -195,6 +200,15 @@ #if !defined SMEMCPY || defined __DOXYGEN__ #define SMEMCPY(dst,src,len) memcpy(dst,src,len) #endif + +/** + * MEMMOVE: override this if you have a faster implementation at hand than the + * one included in your C library. lwIP currently uses MEMMOVE only when IPv6 + * fragmentation support is enabled. + */ +#if !defined MEMMOVE || defined __DOXYGEN__ +#define MEMMOVE(dst,src,len) memmove(dst,src,len) +#endif /** * @} */ @@ -229,7 +243,7 @@ * Your system should provide mutexes supporting priority inversion to use this. */ #if !defined LWIP_TCPIP_CORE_LOCKING || defined __DOXYGEN__ -#define LWIP_TCPIP_CORE_LOCKING 1 +#define LWIP_TCPIP_CORE_LOCKING 0 #endif /** @@ -254,6 +268,29 @@ #if !defined SYS_LIGHTWEIGHT_PROT || defined __DOXYGEN__ #define SYS_LIGHTWEIGHT_PROT 1 #endif + +/** + * Macro/function to check whether lwIP's threading/locking + * requirements are satisfied during current function call. + * This macro usually calls a function that is implemented in the OS-dependent + * sys layer and performs the following checks: + * - Not in ISR (this should be checked for NO_SYS==1, too!) + * - If @ref LWIP_TCPIP_CORE_LOCKING = 1: TCPIP core lock is held + * - If @ref LWIP_TCPIP_CORE_LOCKING = 0: function is called from TCPIP thread + * @see @ref multithreading + */ +#if !defined LWIP_ASSERT_CORE_LOCKED || defined __DOXYGEN__ +#define LWIP_ASSERT_CORE_LOCKED() +#endif + +/** + * Called as first thing in the lwIP TCPIP thread. Can be used in conjunction + * with @ref LWIP_ASSERT_CORE_LOCKED to check core locking. + * @see @ref multithreading + */ +#if !defined LWIP_MARK_TCPIP_THREAD || defined __DOXYGEN__ +#define LWIP_MARK_TCPIP_THREAD() +#endif /** * @} */ @@ -290,6 +327,15 @@ #define MEMP_MEM_MALLOC 1 #endif +/** + * MEMP_MEM_INIT==1: Force use of memset to initialize pool memory. + * Useful if pool are moved in uninitialized section of memory. This will ensure + * default values in pcbs struct are well initialized in all conditions. + */ +#if !defined MEMP_MEM_INIT || defined __DOXYGEN__ +#define MEMP_MEM_INIT 0 +#endif + /** * MEM_ALIGNMENT: should be set to the alignment of the CPU * 4 byte alignment -> \#define MEM_ALIGNMENT 4 @@ -303,9 +349,8 @@ * MEM_SIZE: the size of the heap memory. If the application will send * a lot of data that needs to be copied, this should be set high. */ - #if !defined MEM_SIZE || defined __DOXYGEN__ -#define MEM_SIZE 1024*1024 +#define MEM_SIZE 1600 #endif /** @@ -329,6 +374,27 @@ #define MEMP_SANITY_CHECK 0 #endif +/** + * MEM_OVERFLOW_CHECK: mem overflow protection reserves a configurable + * amount of bytes before and after each heap allocation chunk and fills + * it with a prominent default value. + * MEM_OVERFLOW_CHECK == 0 no checking + * MEM_OVERFLOW_CHECK == 1 checks each element when it is freed + * MEM_OVERFLOW_CHECK >= 2 checks all heap elements every time + * mem_malloc() or mem_free() is called (useful but slow!) + */ +#if !defined MEM_OVERFLOW_CHECK || defined __DOXYGEN__ +#define MEM_OVERFLOW_CHECK 0 +#endif + +/** + * MEM_SANITY_CHECK==1: run a sanity check after each mem_free() to make + * sure that the linked list of heap elements is not corrupted. + */ +#if !defined MEM_SANITY_CHECK || defined __DOXYGEN__ +#define MEM_SANITY_CHECK 0 +#endif + /** * MEM_USE_POOLS==1: Use an alternative to malloc() by allocating from a set * of memory pools of various sizes. When mem_malloc is called, an element of @@ -398,7 +464,7 @@ * this should be set high. */ #if !defined MEMP_NUM_PBUF || defined __DOXYGEN__ -#define MEMP_NUM_PBUF 256 +#define MEMP_NUM_PBUF 16 #endif /** @@ -406,7 +472,7 @@ * (requires the LWIP_RAW option) */ #if !defined MEMP_NUM_RAW_PCB || defined __DOXYGEN__ -#define MEMP_NUM_RAW_PCB 128 +#define MEMP_NUM_RAW_PCB 4 #endif /** @@ -415,7 +481,7 @@ * (requires the LWIP_UDP option) */ #if !defined MEMP_NUM_UDP_PCB || defined __DOXYGEN__ -#define MEMP_NUM_UDP_PCB 128 +#define MEMP_NUM_UDP_PCB 4 #endif /** @@ -423,7 +489,7 @@ * (requires the LWIP_TCP option) */ #if !defined MEMP_NUM_TCP_PCB || defined __DOXYGEN__ -#define MEMP_NUM_TCP_PCB 128 +#define MEMP_NUM_TCP_PCB 5 #endif /** @@ -431,7 +497,7 @@ * (requires the LWIP_TCP option) */ #if !defined MEMP_NUM_TCP_PCB_LISTEN || defined __DOXYGEN__ -#define MEMP_NUM_TCP_PCB_LISTEN 128 +#define MEMP_NUM_TCP_PCB_LISTEN 8 #endif /** @@ -439,7 +505,17 @@ * (requires the LWIP_TCP option) */ #if !defined MEMP_NUM_TCP_SEG || defined __DOXYGEN__ -#define MEMP_NUM_TCP_SEG 512 +#define MEMP_NUM_TCP_SEG 16 +#endif + +/** + * MEMP_NUM_ALTCP_PCB: the number of simultaneously active altcp layer pcbs. + * (requires the LWIP_ALTCP option) + * Connections with multiple layers require more than one altcp_pcb (e.g. TLS + * over TCP requires 2 altcp_pcbs, one for TLS and one for TCP). + */ +#if !defined MEMP_NUM_ALTCP_PCB || defined __DOXYGEN__ +#define MEMP_NUM_ALTCP_PCB MEMP_NUM_TCP_PCB #endif /** @@ -447,7 +523,7 @@ * reassembly (whole packets, not fragments!) */ #if !defined MEMP_NUM_REASSDATA || defined __DOXYGEN__ -#define MEMP_NUM_REASSDATA 32 +#define MEMP_NUM_REASSDATA 5 #endif /** @@ -481,13 +557,19 @@ #define MEMP_NUM_IGMP_GROUP 8 #endif +/** + * The number of sys timeouts used by the core stack (not apps) + * The default number of timeouts is calculated here for all enabled modules. + */ +#define LWIP_NUM_SYS_TIMEOUT_INTERNAL (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + PPP_NUM_TIMEOUTS + (LWIP_IPV6 * (1 + LWIP_IPV6_REASS + LWIP_IPV6_MLD))) + /** * MEMP_NUM_SYS_TIMEOUT: the number of simultaneously active timeouts. * The default number of timeouts is calculated here for all enabled modules. * The formula expects settings to be either '0' or '1'. */ #if !defined MEMP_NUM_SYS_TIMEOUT || defined __DOXYGEN__ -#define MEMP_NUM_SYS_TIMEOUT (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + (PPP_SUPPORT*6*MEMP_NUM_PPP_PCB) + (LWIP_IPV6 ? (1 + LWIP_IPV6_REASS + LWIP_IPV6_MLD) : 0)) +#define MEMP_NUM_SYS_TIMEOUT LWIP_NUM_SYS_TIMEOUT_INTERNAL #endif /** @@ -503,7 +585,16 @@ * (only needed if you use the sequential API, like api_lib.c) */ #if !defined MEMP_NUM_NETCONN || defined __DOXYGEN__ -#define MEMP_NUM_NETCONN 128 +#define MEMP_NUM_NETCONN 4 +#endif + +/** + * MEMP_NUM_SELECT_CB: the number of struct lwip_select_cb. + * (Only needed if you have LWIP_MPU_COMPATIBLE==1 and use the socket API. + * In that case, you need one per thread calling lwip_select.) + */ +#if !defined MEMP_NUM_SELECT_CB || defined __DOXYGEN__ +#define MEMP_NUM_SELECT_CB 4 #endif /** @@ -512,7 +603,7 @@ * (only needed if you use tcpip.c) */ #if !defined MEMP_NUM_TCPIP_MSG_API || defined __DOXYGEN__ -#define MEMP_NUM_TCPIP_MSG_API 128 +#define MEMP_NUM_TCPIP_MSG_API 8 #endif /** @@ -521,7 +612,7 @@ * (only needed if you use tcpip.c) */ #if !defined MEMP_NUM_TCPIP_MSG_INPKT || defined __DOXYGEN__ -#define MEMP_NUM_TCPIP_MSG_INPKT 128 +#define MEMP_NUM_TCPIP_MSG_INPKT 8 #endif /** @@ -544,7 +635,7 @@ * PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */ #if !defined PBUF_POOL_SIZE || defined __DOXYGEN__ -#define PBUF_POOL_SIZE 512 +#define PBUF_POOL_SIZE 16 #endif /** MEMP_NUM_API_MSG: the number of concurrently active calls to various @@ -598,7 +689,7 @@ * ARP_TABLE_SIZE: Number of active MAC-IP address pairs cached. */ #if !defined ARP_TABLE_SIZE || defined __DOXYGEN__ -#define ARP_TABLE_SIZE 64 +#define ARP_TABLE_SIZE 10 #endif /** the time an ARP entry stays valid after its last update, @@ -625,7 +716,7 @@ * Old packets are dropped, new packets are queued. */ #if !defined ARP_QUEUE_LEN || defined __DOXYGEN__ -#define ARP_QUEUE_LEN 8 +#define ARP_QUEUE_LEN 3 #endif /** @@ -669,7 +760,7 @@ * (but this should only occur for AutoIP). */ #if !defined ETHARP_TABLE_MATCH_NETIF || defined __DOXYGEN__ -#define ETHARP_TABLE_MATCH_NETIF 0 +#define ETHARP_TABLE_MATCH_NETIF !LWIP_SINGLE_NETIF #endif /** * @} @@ -744,7 +835,7 @@ * in this time, the whole packet is discarded. */ #if !defined IP_REASS_MAXAGE || defined __DOXYGEN__ -#define IP_REASS_MAXAGE 3 +#define IP_REASS_MAXAGE 15 #endif /** @@ -752,9 +843,11 @@ * Since the received pbufs are enqueued, be sure to configure * PBUF_POOL_SIZE > IP_REASS_MAX_PBUFS so that the stack is still able to receive * packets even if the maximum amount of fragments is enqueued for reassembly! + * When IPv4 *and* IPv6 are enabled, this even changes to + * (PBUF_POOL_SIZE > 2 * IP_REASS_MAX_PBUFS)! */ #if !defined IP_REASS_MAX_PBUFS || defined __DOXYGEN__ -#define IP_REASS_MAX_PBUFS 32 +#define IP_REASS_MAX_PBUFS 10 #endif /** @@ -791,15 +884,6 @@ #if !defined IP_FORWARD_ALLOW_TX_ON_RX_NETIF || defined __DOXYGEN__ #define IP_FORWARD_ALLOW_TX_ON_RX_NETIF 0 #endif - -/** - * LWIP_RANDOMIZE_INITIAL_LOCAL_PORTS==1: randomize the local port for the first - * local TCP/UDP pcb (default==0). This can prevent creating predictable port - * numbers after booting a device. - */ -#if !defined LWIP_RANDOMIZE_INITIAL_LOCAL_PORTS || defined __DOXYGEN__ -#define LWIP_RANDOMIZE_INITIAL_LOCAL_PORTS 0 -#endif /** * @} */ @@ -826,7 +910,7 @@ * ICMP_TTL: Default value for Time-To-Live used by ICMP packets. */ #if !defined ICMP_TTL || defined __DOXYGEN__ -#define ICMP_TTL (IP_DEFAULT_TTL) +#define ICMP_TTL IP_DEFAULT_TTL #endif /** @@ -867,7 +951,7 @@ * LWIP_RAW==1: Enable application layer to hook into the IP layer itself. */ #if !defined RAW_TTL || defined __DOXYGEN__ -#define RAW_TTL (IP_DEFAULT_TTL) +#define RAW_TTL IP_DEFAULT_TTL #endif /** * @} @@ -899,17 +983,7 @@ * DHCP_DOES_ARP_CHECK==1: Do an ARP check on the offered address. */ #if !defined DHCP_DOES_ARP_CHECK || defined __DOXYGEN__ -#define DHCP_DOES_ARP_CHECK ((LWIP_DHCP) && (LWIP_ARP)) -#endif - -/** - * LWIP_DHCP_CHECK_LINK_UP==1: dhcp_start() only really starts if the netif has - * NETIF_FLAG_LINK_UP set in its flags. As this is only an optimization and - * netif drivers might not set this flag, the default is off. If enabled, - * netif_set_link_up() must be called to continue dhcp starting. - */ -#if !defined LWIP_DHCP_CHECK_LINK_UP -#define LWIP_DHCP_CHECK_LINK_UP 0 +#define DHCP_DOES_ARP_CHECK (LWIP_DHCP && LWIP_ARP) #endif /** @@ -937,7 +1011,7 @@ /** * LWIP_DHCP_MAX_DNS_SERVERS > 0: Request DNS servers with discover/select. - * DHCP servers received in the response are passed to DNS via @ref dns_setserver() + * DNS servers received in the response are passed to DNS via @ref dns_setserver() * (up to the maximum limit defined here). */ #if !defined LWIP_DHCP_MAX_DNS_SERVERS || defined __DOXYGEN__ @@ -1015,7 +1089,29 @@ /* ---------------------------------- - ----- Multicast/IGMP options ----- + -------- Multicast options ------- + ---------------------------------- +*/ +/** + * @defgroup lwip_opts_multicast Multicast + * @ingroup lwip_opts_infrastructure + * @{ + */ +/** + * LWIP_MULTICAST_TX_OPTIONS==1: Enable multicast TX support like the socket options + * IP_MULTICAST_TTL/IP_MULTICAST_IF/IP_MULTICAST_LOOP, as well as (currently only) + * core support for the corresponding IPv6 options. + */ +#if !defined LWIP_MULTICAST_TX_OPTIONS || defined __DOXYGEN__ +#define LWIP_MULTICAST_TX_OPTIONS ((LWIP_IGMP || LWIP_IPV6_MLD) && (LWIP_UDP || LWIP_RAW)) +#endif +/** + * @} + */ + +/* + ---------------------------------- + ---------- IGMP options ---------- ---------------------------------- */ /** @@ -1033,14 +1129,6 @@ #undef LWIP_IGMP #define LWIP_IGMP 0 #endif - -/** - * LWIP_MULTICAST_TX_OPTIONS==1: Enable multicast TX support like the socket options - * IP_MULTICAST_TTL/IP_MULTICAST_IF/IP_MULTICAST_LOOP - */ -#if !defined LWIP_MULTICAST_TX_OPTIONS || defined __DOXYGEN__ -#define LWIP_MULTICAST_TX_OPTIONS (LWIP_IGMP && LWIP_UDP) -#endif /** * @} */ @@ -1081,6 +1169,11 @@ #define DNS_MAX_SERVERS 2 #endif +/** DNS maximum number of retries when asking for a name, before "timeout". */ +#if !defined DNS_MAX_RETRIES || defined __DOXYGEN__ +#define DNS_MAX_RETRIES 4 +#endif + /** DNS do a name checking between the query and the response. */ #if !defined DNS_DOES_NAME_CHECK || defined __DOXYGEN__ #define DNS_DOES_NAME_CHECK 1 @@ -1120,7 +1213,7 @@ /** Set this to 1 to enable querying ".local" names via mDNS * using a One-Shot Multicast DNS Query */ #if !defined LWIP_DNS_SUPPORT_MDNS_QUERIES || defined __DOXYGEN__ -#define LWIP_DNS_SUPPORT_MDNS_QUERIES 0 +#define LWIP_DNS_SUPPORT_MDNS_QUERIES 0 #endif /** * @} @@ -1154,7 +1247,7 @@ * UDP_TTL: Default Time-To-Live value. */ #if !defined UDP_TTL || defined __DOXYGEN__ -#define UDP_TTL (IP_DEFAULT_TTL) +#define UDP_TTL IP_DEFAULT_TTL #endif /** @@ -1188,7 +1281,7 @@ * TCP_TTL: Default Time-To-Live value. */ #if !defined TCP_TTL || defined __DOXYGEN__ -#define TCP_TTL (IP_DEFAULT_TTL) +#define TCP_TTL IP_DEFAULT_TTL #endif /** @@ -1199,7 +1292,7 @@ * will be TCP_WND >> TCP_RCV_SCALE */ #if !defined TCP_WND || defined __DOXYGEN__ -#define TCP_WND 0xffff // was (4 * TCP_MSS) +#define TCP_WND (4 * TCP_MSS) #endif /** @@ -1221,7 +1314,28 @@ * Define to 0 if your device is low on memory. */ #if !defined TCP_QUEUE_OOSEQ || defined __DOXYGEN__ -#define TCP_QUEUE_OOSEQ (LWIP_TCP) +#define TCP_QUEUE_OOSEQ LWIP_TCP +#endif + +/** + * LWIP_TCP_SACK_OUT==1: TCP will support sending selective acknowledgements (SACKs). + */ +#if !defined LWIP_TCP_SACK_OUT || defined __DOXYGEN__ +#define LWIP_TCP_SACK_OUT 0 +#endif + +/** + * LWIP_TCP_MAX_SACK_NUM: The maximum number of SACK values to include in TCP segments. + * Must be at least 1, but is only used if LWIP_TCP_SACK_OUT is enabled. + * NOTE: Even though we never send more than 3 or 4 SACK ranges in a single segment + * (depending on other options), setting this option to values greater than 4 is not pointless. + * This is basically the max number of SACK ranges we want to keep track of. + * As new data is delivered, some of the SACK ranges may be removed or merged. + * In that case some of those older SACK ranges may be used again. + * The amount of memory used to store SACK ranges is LWIP_TCP_MAX_SACK_NUM * 8 bytes for each TCP PCB. + */ +#if !defined LWIP_TCP_MAX_SACK_NUM || defined __DOXYGEN__ +#define LWIP_TCP_MAX_SACK_NUM 4 #endif /** @@ -1253,7 +1367,7 @@ * To achieve good performance, this should be at least 2 * TCP_MSS. */ #if !defined TCP_SND_BUF || defined __DOXYGEN__ -#define TCP_SND_BUF TCP_WND // was (2 * TCP_MSS) +#define TCP_SND_BUF (2 * TCP_MSS) #endif /** @@ -1261,7 +1375,7 @@ * as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work. */ #if !defined TCP_SND_QUEUELEN || defined __DOXYGEN__ -#define TCP_SND_QUEUELEN ((8 * (TCP_SND_BUF) + (TCP_MSS - 1))/(TCP_MSS)) +#define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1))/(TCP_MSS)) #endif /** @@ -1283,21 +1397,51 @@ #endif /** - * TCP_OOSEQ_MAX_BYTES: The maximum number of bytes queued on ooseq per pcb. - * Default is 0 (no limit). Only valid for TCP_QUEUE_OOSEQ==1. + * TCP_OOSEQ_MAX_BYTES: The default maximum number of bytes queued on ooseq per + * pcb if TCP_OOSEQ_BYTES_LIMIT is not defined. Default is 0 (no limit). + * Only valid for TCP_QUEUE_OOSEQ==1. */ #if !defined TCP_OOSEQ_MAX_BYTES || defined __DOXYGEN__ #define TCP_OOSEQ_MAX_BYTES 0 #endif /** - * TCP_OOSEQ_MAX_PBUFS: The maximum number of pbufs queued on ooseq per pcb. - * Default is 0 (no limit). Only valid for TCP_QUEUE_OOSEQ==1. + * TCP_OOSEQ_BYTES_LIMIT(pcb): Return the maximum number of bytes to be queued + * on ooseq per pcb, given the pcb. Only valid for TCP_QUEUE_OOSEQ==1 && + * TCP_OOSEQ_MAX_BYTES==1. + * Use this to override TCP_OOSEQ_MAX_BYTES to a dynamic value per pcb. + */ +#if !defined TCP_OOSEQ_BYTES_LIMIT +#if TCP_OOSEQ_MAX_BYTES +#define TCP_OOSEQ_BYTES_LIMIT(pcb) TCP_OOSEQ_MAX_BYTES +#elif defined __DOXYGEN__ +#define TCP_OOSEQ_BYTES_LIMIT(pcb) +#endif +#endif + +/** + * TCP_OOSEQ_MAX_PBUFS: The default maximum number of pbufs queued on ooseq per + * pcb if TCP_OOSEQ_BYTES_LIMIT is not defined. Default is 0 (no limit). + * Only valid for TCP_QUEUE_OOSEQ==1. */ #if !defined TCP_OOSEQ_MAX_PBUFS || defined __DOXYGEN__ #define TCP_OOSEQ_MAX_PBUFS 0 #endif +/** + * TCP_OOSEQ_PBUFS_LIMIT(pcb): Return the maximum number of pbufs to be queued + * on ooseq per pcb, given the pcb. Only valid for TCP_QUEUE_OOSEQ==1 && + * TCP_OOSEQ_MAX_PBUFS==1. + * Use this to override TCP_OOSEQ_MAX_PBUFS to a dynamic value per pcb. + */ +#if !defined TCP_OOSEQ_PBUFS_LIMIT +#if TCP_OOSEQ_MAX_PBUFS +#define TCP_OOSEQ_PBUFS_LIMIT(pcb) TCP_OOSEQ_MAX_PBUFS +#elif defined __DOXYGEN__ +#define TCP_OOSEQ_PBUFS_LIMIT(pcb) +#endif +#endif + /** * TCP_LISTEN_BACKLOG: Enable the backlog option for tcp listen pcb. */ @@ -1347,7 +1491,7 @@ * explicit window update */ #if !defined TCP_WND_UPDATE_THRESHOLD || defined __DOXYGEN__ -#define TCP_WND_UPDATE_THRESHOLD LWIP_MIN((TCP_WND / 4), (TCP_MSS * 4)) +#define TCP_WND_UPDATE_THRESHOLD LWIP_MIN((TCP_WND / 4), (TCP_MSS * 4)) #endif /** @@ -1381,6 +1525,41 @@ #define LWIP_WND_SCALE 0 #define TCP_RCV_SCALE 0 #endif + +/** + * LWIP_TCP_PCB_NUM_EXT_ARGS: + * When this is > 0, every tcp pcb (including listen pcb) includes a number of + * additional argument entries in an array (see tcp_ext_arg_alloc_id) + */ +#if !defined LWIP_TCP_PCB_NUM_EXT_ARGS || defined __DOXYGEN__ +#define LWIP_TCP_PCB_NUM_EXT_ARGS 0 +#endif + +/** LWIP_ALTCP==1: enable the altcp API. + * altcp is an abstraction layer that prevents applications linking against the + * tcp.h functions but provides the same functionality. It is used to e.g. add + * SSL/TLS or proxy-connect support to an application written for the tcp callback + * API without that application knowing the protocol details. + * + * With LWIP_ALTCP==0, applications written against the altcp API can still be + * compiled but are directly linked against the tcp.h callback API and then + * cannot use layered protocols. + * + * See @ref altcp_api + */ +#if !defined LWIP_ALTCP || defined __DOXYGEN__ +#define LWIP_ALTCP 0 +#endif + +/** LWIP_ALTCP_TLS==1: enable TLS support for altcp API. + * This needs a port of the functions in altcp_tls.h to a TLS library. + * A port to ARM mbedtls is provided with lwIP, see apps/altcp_tls/ directory + * and LWIP_ALTCP_TLS_MBEDTLS option. + */ +#if !defined LWIP_ALTCP_TLS || defined __DOXYGEN__ +#define LWIP_ALTCP_TLS 0 +#endif + /** * @} */ @@ -1413,7 +1592,7 @@ * for an additional encapsulation header before ethernet headers (e.g. 802.11) */ #if !defined PBUF_LINK_ENCAPSULATION_HLEN || defined __DOXYGEN__ -#define PBUF_LINK_ENCAPSULATION_HLEN 0u +#define PBUF_LINK_ENCAPSULATION_HLEN 0 #endif /** @@ -1424,6 +1603,14 @@ #if !defined PBUF_POOL_BUFSIZE || defined __DOXYGEN__ #define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+40+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN) #endif + +/** + * LWIP_PBUF_REF_T: Refcount type in pbuf. + * Default width of u8_t can be increased if 255 refs are not enough for you. + */ +#if !defined LWIP_PBUF_REF_T || defined __DOXYGEN__ +#define LWIP_PBUF_REF_T u8_t +#endif /** * @} */ @@ -1438,6 +1625,14 @@ * @ingroup lwip_opts * @{ */ +/** + * LWIP_SINGLE_NETIF==1: use a single netif only. This is the common case for + * small real-life targets. Some code like routing etc. can be left out. + */ +#if !defined LWIP_SINGLE_NETIF || defined __DOXYGEN__ +#define LWIP_SINGLE_NETIF 0 +#endif + /** * LWIP_NETIF_HOSTNAME==1: use DHCP_OPTION_HOSTNAME with netif's hostname * field. @@ -1458,7 +1653,16 @@ * changes its up/down status (i.e., due to DHCP IP acquisition) */ #if !defined LWIP_NETIF_STATUS_CALLBACK || defined __DOXYGEN__ -#define LWIP_NETIF_STATUS_CALLBACK 0 +#define LWIP_NETIF_STATUS_CALLBACK 1 +#endif + +/** + * LWIP_NETIF_EXT_STATUS_CALLBACK==1: Support an extended callback function + * for several netif related event that supports multiple subscribers. + * @see netif_ext_status_callback + */ +#if !defined LWIP_NETIF_EXT_STATUS_CALLBACK || defined __DOXYGEN__ +#define LWIP_NETIF_EXT_STATUS_CALLBACK 1 #endif /** @@ -1466,7 +1670,7 @@ * whenever the link changes (i.e., link down) */ #if !defined LWIP_NETIF_LINK_CALLBACK || defined __DOXYGEN__ -#define LWIP_NETIF_LINK_CALLBACK 0 +#define LWIP_NETIF_LINK_CALLBACK 1 #endif /** @@ -1474,7 +1678,7 @@ * when a netif has been removed */ #if !defined LWIP_NETIF_REMOVE_CALLBACK || defined __DOXYGEN__ -#define LWIP_NETIF_REMOVE_CALLBACK 0 +#define LWIP_NETIF_REMOVE_CALLBACK 1 #endif /** @@ -1485,28 +1689,37 @@ * if you have a tiny ARP table or if there never are concurrent connections. */ #if !defined LWIP_NETIF_HWADDRHINT || defined __DOXYGEN__ -#define LWIP_NETIF_HWADDRHINT 1 +#define LWIP_NETIF_HWADDRHINT 0 #endif /** - * LWIP_NETIF_TX_SINGLE_PBUF: if this is set to 1, lwIP tries to put all data + * LWIP_NETIF_TX_SINGLE_PBUF: if this is set to 1, lwIP *tries* to put all data * to be sent into one single pbuf. This is for compatibility with DMA-enabled * MACs that do not support scatter-gather. * Beware that this might involve CPU-memcpy before transmitting that would not * be needed without this flag! Use this only if you need to! * - * @todo: TCP and IP-frag do not work with this, yet: + * ATTENTION: a driver should *NOT* rely on getting single pbufs but check TX + * pbufs for being in one piece. If not, @ref pbuf_clone can be used to get + * a single pbuf: + * if (p->next != NULL) { + * struct pbuf *q = pbuf_clone(PBUF_RAW, PBUF_RAM, p); + * if (q == NULL) { + * return ERR_MEM; + * } + * p = q; ATTENTION: do NOT free the old 'p' as the ref belongs to the caller! + * } */ #if !defined LWIP_NETIF_TX_SINGLE_PBUF || defined __DOXYGEN__ -#define LWIP_NETIF_TX_SINGLE_PBUF 0 +#define LWIP_NETIF_TX_SINGLE_PBUF 0 #endif /* LWIP_NETIF_TX_SINGLE_PBUF */ /** * LWIP_NUM_NETIF_CLIENT_DATA: Number of clients that may store - * data in client_data member array of struct netif. + * data in client_data member array of struct netif (max. 256). */ #if !defined LWIP_NUM_NETIF_CLIENT_DATA || defined __DOXYGEN__ -#define LWIP_NUM_NETIF_CLIENT_DATA 0 +#define LWIP_NUM_NETIF_CLIENT_DATA 0 #endif /** * @} @@ -1528,14 +1741,14 @@ * netif is available, loopback traffic uses this netif. */ #if !defined LWIP_HAVE_LOOPIF || defined __DOXYGEN__ -#define LWIP_HAVE_LOOPIF LWIP_NETIF_LOOPBACK +#define LWIP_HAVE_LOOPIF (LWIP_NETIF_LOOPBACK && !LWIP_SINGLE_NETIF) #endif /** * LWIP_LOOPIF_MULTICAST==1: Support multicast/IGMP on loop interface (127.0.0.1). */ #if !defined LWIP_LOOPIF_MULTICAST || defined __DOXYGEN__ -#define LWIP_LOOPIF_MULTICAST 0 +#define LWIP_LOOPIF_MULTICAST 0 #endif /** @@ -1588,7 +1801,7 @@ * TCPIP_THREAD_NAME: The name assigned to the main tcpip thread. */ #if !defined TCPIP_THREAD_NAME || defined __DOXYGEN__ -#define TCPIP_THREAD_NAME "tcpip_thread" +#define TCPIP_THREAD_NAME "tcpip_thread" #endif /** @@ -1630,7 +1843,7 @@ * SLIPIF_THREAD_NAME: The name assigned to the slipif_loop thread. */ #if !defined SLIPIF_THREAD_NAME || defined __DOXYGEN__ -#define SLIPIF_THREAD_NAME "slipif_loop" +#define SLIPIF_THREAD_NAME "slipif_loop" #endif /** @@ -1655,7 +1868,7 @@ * DEFAULT_THREAD_NAME: The name assigned to any other lwIP thread. */ #if !defined DEFAULT_THREAD_NAME || defined __DOXYGEN__ -#define DEFAULT_THREAD_NAME "lwIP" +#define DEFAULT_THREAD_NAME "lwIP" #endif /** @@ -1785,13 +1998,6 @@ #define LWIP_SOCKET 1 #endif -/* LWIP_SOCKET_SET_ERRNO==1: Set errno when socket functions cannot complete - * successfully, as required by POSIX. Default is POSIX-compliant. - */ -#if !defined LWIP_SOCKET_SET_ERRNO || defined __DOXYGEN__ -#define LWIP_SOCKET_SET_ERRNO 1 -#endif - /** * LWIP_COMPAT_SOCKETS==1: Enable BSD-style sockets functions names through defines. * LWIP_COMPAT_SOCKETS==2: Same as ==1 but correctly named functions are created. @@ -1799,7 +2005,7 @@ * (only used if you use sockets.c) */ #if !defined LWIP_COMPAT_SOCKETS || defined __DOXYGEN__ -#define LWIP_COMPAT_SOCKETS 0 +#define LWIP_COMPAT_SOCKETS 1 #endif /** @@ -1808,7 +2014,7 @@ * names (read, write & close). (only used if you use sockets.c) */ #if !defined LWIP_POSIX_SOCKETS_IO_NAMES || defined __DOXYGEN__ -#define LWIP_POSIX_SOCKETS_IO_NAMES 0 +#define LWIP_POSIX_SOCKETS_IO_NAMES 1 #endif /** @@ -1910,6 +2116,24 @@ #if !defined LWIP_FIONREAD_LINUXMODE || defined __DOXYGEN__ #define LWIP_FIONREAD_LINUXMODE 1 #endif + +/** + * LWIP_SOCKET_SELECT==1 (default): enable select() for sockets (uses a netconn + * callback to keep track of events). + * This saves RAM (counters per socket) and code (netconn event callback), which + * should improve performance a bit). + */ +#if !defined LWIP_SOCKET_SELECT || defined __DOXYGEN__ +#define LWIP_SOCKET_SELECT 1 +#endif + +/** + * LWIP_SOCKET_POLL==1 (default): enable poll() for sockets (including + * struct pollfd, nfds_t, and constants) + */ +#if !defined LWIP_SOCKET_POLL || defined __DOXYGEN__ +#define LWIP_SOCKET_POLL 1 +#endif /** * @} */ @@ -1928,7 +2152,7 @@ * LWIP_STATS==1: Enable statistics collection in lwip_stats. */ #if !defined LWIP_STATS || defined __DOXYGEN__ -#define LWIP_STATS 0 +#define LWIP_STATS 1 #endif #if LWIP_STATS @@ -1937,7 +2161,7 @@ * LWIP_STATS_DISPLAY==1: Compile in the statistics output functions. */ #if !defined LWIP_STATS_DISPLAY || defined __DOXYGEN__ -#define LWIP_STATS_DISPLAY 0 +#define LWIP_STATS_DISPLAY 1 #endif /** @@ -1958,7 +2182,7 @@ * IP_STATS==1: Enable IP stats. */ #if !defined IP_STATS || defined __DOXYGEN__ -#define IP_STATS 1 +#define IP_STATS 0 #endif /** @@ -2146,35 +2370,35 @@ * CHECKSUM_CHECK_IP==1: Check checksums in software for incoming IP packets. */ #if !defined CHECKSUM_CHECK_IP || defined __DOXYGEN__ -#define CHECKSUM_CHECK_IP 0 // turned off since ZeroTier CRC's entire payload +#define CHECKSUM_CHECK_IP 0 #endif /** * CHECKSUM_CHECK_UDP==1: Check checksums in software for incoming UDP packets. */ #if !defined CHECKSUM_CHECK_UDP || defined __DOXYGEN__ -#define CHECKSUM_CHECK_UDP 0 // turned off since ZeroTier CRC's entire payload +#define CHECKSUM_CHECK_UDP 0 #endif /** * CHECKSUM_CHECK_TCP==1: Check checksums in software for incoming TCP packets. */ #if !defined CHECKSUM_CHECK_TCP || defined __DOXYGEN__ -#define CHECKSUM_CHECK_TCP 0 // turned off since ZeroTier CRC's entire payload +#define CHECKSUM_CHECK_TCP 0 #endif /** * CHECKSUM_CHECK_ICMP==1: Check checksums in software for incoming ICMP packets. */ #if !defined CHECKSUM_CHECK_ICMP || defined __DOXYGEN__ -#define CHECKSUM_CHECK_ICMP 0 // turned off since ZeroTier CRC's entire payload +#define CHECKSUM_CHECK_ICMP 0 #endif /** * CHECKSUM_CHECK_ICMP6==1: Check checksums in software for incoming ICMPv6 packets */ #if !defined CHECKSUM_CHECK_ICMP6 || defined __DOXYGEN__ -#define CHECKSUM_CHECK_ICMP6 0 // turned off since ZeroTier CRC's entire payload +#define CHECKSUM_CHECK_ICMP6 0 #endif /** @@ -2182,7 +2406,7 @@ * application buffers to pbufs. */ #if !defined LWIP_CHECKSUM_ON_COPY || defined __DOXYGEN__ -#define LWIP_CHECKSUM_ON_COPY 0 // turned off since ZeroTier CRC's entire payload +#define LWIP_CHECKSUM_ON_COPY 0 #endif /** * @} @@ -2205,6 +2429,46 @@ #define LWIP_IPV6 1 #endif +/** + * IPV6_REASS_MAXAGE: Maximum time (in multiples of IP6_REASS_TMR_INTERVAL - so seconds, normally) + * a fragmented IP packet waits for all fragments to arrive. If not all fragments arrived + * in this time, the whole packet is discarded. + */ +#if !defined IPV6_REASS_MAXAGE || defined __DOXYGEN__ +#define IPV6_REASS_MAXAGE 60 +#endif + +/** + * LWIP_IPV6_SCOPES==1: Enable support for IPv6 address scopes, ensuring that + * e.g. link-local addresses are really treated as link-local. Disable this + * setting only for single-interface configurations. + * All addresses that have a scope according to the default policy (link-local + * unicast addresses, interface-local and link-local multicast addresses) should + * now have a zone set on them before being passed to the core API, although + * lwIP will currently attempt to select a zone on the caller's behalf when + * necessary. Applications that directly assign IPv6 addresses to interfaces + * (which is NOT recommended) must now ensure that link-local addresses carry + * the netif's zone. See the new ip6_zone.h header file for more information and + * relevant macros. For now it is still possible to turn off scopes support + * through the new LWIP_IPV6_SCOPES option. When upgrading an implementation that + * uses the core API directly, it is highly recommended to enable + * LWIP_IPV6_SCOPES_DEBUG at least for a while, to ensure e.g. proper address + * initialization. + */ +#if !defined LWIP_IPV6_SCOPES || defined __DOXYGEN__ +#define LWIP_IPV6_SCOPES (LWIP_IPV6 && !LWIP_SINGLE_NETIF) +#endif + +/** + * LWIP_IPV6_SCOPES_DEBUG==1: Perform run-time checks to verify that addresses + * are properly zoned (see ip6_zone.h on what that means) where it matters. + * Enabling this setting is highly recommended when upgrading from an existing + * installation that is not yet scope-aware; otherwise it may be too expensive. + */ +#if !defined LWIP_IPV6_SCOPES_DEBUG || defined __DOXYGEN__ +#define LWIP_IPV6_SCOPES_DEBUG 0 +#endif + /** * LWIP_IPV6_NUM_ADDRESSES: Number of IPv6 addresses per netif. */ @@ -2230,7 +2494,7 @@ * LWIP_IPV6_REASS==1: reassemble incoming IPv6 packets that fragmented */ #if !defined LWIP_IPV6_REASS || defined __DOXYGEN__ -#define LWIP_IPV6_REASS (LWIP_IPV6) +#define LWIP_IPV6_REASS LWIP_IPV6 #endif /** @@ -2245,7 +2509,18 @@ * LWIP_IPV6_AUTOCONFIG==1: Enable stateless address autoconfiguration as per RFC 4862. */ #if !defined LWIP_IPV6_AUTOCONFIG || defined __DOXYGEN__ -#define LWIP_IPV6_AUTOCONFIG (LWIP_IPV6) +#define LWIP_IPV6_AUTOCONFIG LWIP_IPV6 +#endif + +/** + * LWIP_IPV6_ADDRESS_LIFETIMES==1: Keep valid and preferred lifetimes for each + * IPv6 address. Required for LWIP_IPV6_AUTOCONFIG. May still be enabled + * otherwise, in which case the application may assign address lifetimes with + * the appropriate macros. Addresses with no lifetime are assumed to be static. + * If this option is disabled, all addresses are assumed to be static. + */ +#if !defined LWIP_IPV6_ADDRESS_LIFETIMES || defined __DOXYGEN__ +#define LWIP_IPV6_ADDRESS_LIFETIMES LWIP_IPV6_AUTOCONFIG #endif /** @@ -2267,7 +2542,7 @@ * LWIP_ICMP6==1: Enable ICMPv6 (mandatory per RFC) */ #if !defined LWIP_ICMP6 || defined __DOXYGEN__ -#define LWIP_ICMP6 (LWIP_IPV6) +#define LWIP_ICMP6 LWIP_IPV6 #endif /** @@ -2299,7 +2574,7 @@ * indiscriminately pass all inbound IPv6 multicast traffic to lwIP. */ #if !defined LWIP_IPV6_MLD || defined __DOXYGEN__ -#define LWIP_IPV6_MLD (LWIP_IPV6) +#define LWIP_IPV6_MLD LWIP_IPV6 #endif /** @@ -2325,7 +2600,7 @@ * is being resolved. */ #if !defined LWIP_ND6_QUEUEING || defined __DOXYGEN__ -#define LWIP_ND6_QUEUEING (LWIP_IPV6) +#define LWIP_ND6_QUEUEING LWIP_IPV6 #endif /** @@ -2339,28 +2614,28 @@ * LWIP_ND6_NUM_NEIGHBORS: Number of entries in IPv6 neighbor cache */ #if !defined LWIP_ND6_NUM_NEIGHBORS || defined __DOXYGEN__ -#define LWIP_ND6_NUM_NEIGHBORS 32 +#define LWIP_ND6_NUM_NEIGHBORS 10 #endif /** * LWIP_ND6_NUM_DESTINATIONS: number of entries in IPv6 destination cache */ #if !defined LWIP_ND6_NUM_DESTINATIONS || defined __DOXYGEN__ -#define LWIP_ND6_NUM_DESTINATIONS 32 +#define LWIP_ND6_NUM_DESTINATIONS 10 #endif /** * LWIP_ND6_NUM_PREFIXES: number of entries in IPv6 on-link prefixes cache */ #if !defined LWIP_ND6_NUM_PREFIXES || defined __DOXYGEN__ -#define LWIP_ND6_NUM_PREFIXES 16 +#define LWIP_ND6_NUM_PREFIXES 5 #endif /** * LWIP_ND6_NUM_ROUTERS: number of entries in IPv6 default router cache */ #if !defined LWIP_ND6_NUM_ROUTERS || defined __DOXYGEN__ -#define LWIP_ND6_NUM_ROUTERS 8 +#define LWIP_ND6_NUM_ROUTERS 3 #endif /** @@ -2446,12 +2721,60 @@ */ /** - * LWIP_IPV6_DHCP6==1: enable DHCPv6 stateful address autoconfiguration. + * @defgroup lwip_opts_dhcpv6 DHCPv6 + * @ingroup lwip_opts_ipv6 + * @{ + */ +/** + * LWIP_IPV6_DHCP6==1: enable DHCPv6 stateful/stateless address autoconfiguration. */ #if !defined LWIP_IPV6_DHCP6 || defined __DOXYGEN__ #define LWIP_IPV6_DHCP6 0 #endif +/** + * LWIP_IPV6_DHCP6_STATEFUL==1: enable DHCPv6 stateful address autoconfiguration. + * (not supported, yet!) + */ +#if !defined LWIP_IPV6_DHCP6_STATEFUL || defined __DOXYGEN__ +#define LWIP_IPV6_DHCP6_STATEFUL 0 +#endif + +/** + * LWIP_IPV6_DHCP6_STATELESS==1: enable DHCPv6 stateless address autoconfiguration. + */ +#if !defined LWIP_IPV6_DHCP6_STATELESS || defined __DOXYGEN__ +#define LWIP_IPV6_DHCP6_STATELESS LWIP_IPV6_DHCP6 +#endif + +/** + * LWIP_DHCP6_GETS_NTP==1: Request NTP servers via DHCPv6. For each + * response packet, a callback is called, which has to be provided by the port: + * void dhcp6_set_ntp_servers(u8_t num_ntp_servers, ip_addr_t* ntp_server_addrs); +*/ +#if !defined LWIP_DHCP6_GET_NTP_SRV || defined __DOXYGEN__ +#define LWIP_DHCP6_GET_NTP_SRV 0 +#endif + +/** + * The maximum of NTP servers requested + */ +#if !defined LWIP_DHCP6_MAX_NTP_SERVERS || defined __DOXYGEN__ +#define LWIP_DHCP6_MAX_NTP_SERVERS 1 +#endif + +/** + * LWIP_DHCP6_MAX_DNS_SERVERS > 0: Request DNS servers via DHCPv6. + * DNS servers received in the response are passed to DNS via @ref dns_setserver() + * (up to the maximum limit defined here). + */ +#if !defined LWIP_DHCP6_MAX_DNS_SERVERS || defined __DOXYGEN__ +#define LWIP_DHCP6_MAX_DNS_SERVERS DNS_MAX_SERVERS +#endif +/** + * @} + */ + /* --------------------------------------- ---------- Hook options --------------- @@ -2466,8 +2789,8 @@ */ /** - * LWIP_HOOK_FILENAME: Custom filename to #include in files that provide hooks. - * Declare your hook function prototypes in there, you may also #include all headers + * LWIP_HOOK_FILENAME: Custom filename to \#include in files that provide hooks. + * Declare your hook function prototypes in there, you may also \#include all headers * providing data types that are need in this file. */ #ifdef __DOXYGEN__ @@ -2483,7 +2806,9 @@ * or any other desired algorithm as a replacement. * Called from tcp_connect() and tcp_listen_input() when an ISN is needed for * a new TCP connection, if TCP support (@ref LWIP_TCP) is enabled.\n - * Signature: u32_t my_hook_tcp_isn(const ip_addr_t* local_ip, u16_t local_port, const ip_addr_t* remote_ip, u16_t remote_port); + * Signature:\code{.c} + * u32_t my_hook_tcp_isn(const ip_addr_t* local_ip, u16_t local_port, const ip_addr_t* remote_ip, u16_t remote_port); + * \endcode * - it may be necessary to use "struct ip_addr" (ip4_addr, ip6_addr) instead of "ip_addr_t" in function declarations\n * Arguments: * - local_ip: pointer to the local IP address of the connection @@ -2497,9 +2822,89 @@ #define LWIP_HOOK_TCP_ISN(local_ip, local_port, remote_ip, remote_port) #endif +/** + * LWIP_HOOK_TCP_INPACKET_PCB: + * Hook for intercepting incoming packets before they are passed to a pcb. This + * allows updating some state or even dropping a packet. + * Signature:\code{.c} + * err_t my_hook_tcp_inpkt(struct tcp_pcb *pcb, struct tcp_hdr *hdr, u16_t optlen, u16_t opt1len, u8_t *opt2, struct pbuf *p); + * \endcode + * Arguments: + * - pcb: tcp_pcb selected for input of this packet (ATTENTION: this may be + * struct tcp_pcb_listen if pcb->state == LISTEN) + * - hdr: pointer to tcp header (ATTENTION: tcp options may not be in one piece!) + * - optlen: tcp option length + * - opt1len: tcp option length 1st part + * - opt2: if this is != NULL, tcp options are split among 2 pbufs. In that case, + * options start at right after the tcp header ('(u8_t*)(hdr + 1)') for + * the first 'opt1len' bytes and the rest starts at 'opt2'. opt2len can + * be simply calculated: 'opt2len = optlen - opt1len;' + * - p: input packet, p->payload points to application data (that's why tcp hdr + * and options are passed in seperately) + * Return value: + * - ERR_OK: continue input of this packet as normal + * - != ERR_OK: drop this packet for input (don't continue input processing) + * + * ATTENTION: don't call any tcp api functions that might change tcp state (pcb + * state or any pcb lists) from this callback! + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_TCP_INPACKET_PCB(pcb, hdr, optlen, opt1len, opt2, p) +#endif + +/** + * LWIP_HOOK_TCP_OUT_TCPOPT_LENGTH: + * Hook for increasing the size of the options allocated with a tcp header. + * Together with LWIP_HOOK_TCP_OUT_ADD_TCPOPTS, this can be used to add custom + * options to outgoing tcp segments. + * Signature:\code{.c} + * u8_t my_hook_tcp_out_tcpopt_length(const struct tcp_pcb *pcb, u8_t internal_option_length); + * \endcode + * Arguments: + * - pcb: tcp_pcb that transmits (ATTENTION: this may be NULL or + * struct tcp_pcb_listen if pcb->state == LISTEN) + * - internal_option_length: tcp option length used by the stack internally + * Return value: + * - a number of bytes to allocate for tcp options (internal_option_length <= ret <= 40) + * + * ATTENTION: don't call any tcp api functions that might change tcp state (pcb + * state or any pcb lists) from this callback! + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_TCP_OUT_TCPOPT_LENGTH(pcb, internal_len) +#endif + +/** + * LWIP_HOOK_TCP_OUT_ADD_TCPOPTS: + * Hook for adding custom options to outgoing tcp segments. + * Space for these custom options has to be reserved via LWIP_HOOK_TCP_OUT_TCPOPT_LENGTH. + * Signature:\code{.c} + * u32_t *my_hook_tcp_out_add_tcpopts(struct pbuf *p, struct tcp_hdr *hdr, const struct tcp_pcb *pcb, u32_t *opts); + * \endcode + * Arguments: + * - p: output packet, p->payload pointing to tcp header, data follows + * - hdr: tcp header + * - pcb: tcp_pcb that transmits (ATTENTION: this may be NULL or + * struct tcp_pcb_listen if pcb->state == LISTEN) + * - opts: pointer where to add the custom options (there may already be options + * between the header and these) + * Return value: + * - pointer pointing directly after the inserted options + * + * ATTENTION: don't call any tcp api functions that might change tcp state (pcb + * state or any pcb lists) from this callback! + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_TCP_OUT_ADD_TCPOPTS(p, hdr, pcb, opts) +#endif + /** * LWIP_HOOK_IP4_INPUT(pbuf, input_netif): - * - called from ip_input() (IPv4) + * Called from ip_input() (IPv4) + * Signature:\code{.c} + * int my_hook(struct pbuf *pbuf, struct netif *input_netif); + * \endcode + * Arguments: * - pbuf: received struct pbuf passed to ip_input() * - input_netif: struct netif on which the packet has been received * Return values: @@ -2514,30 +2919,71 @@ /** * LWIP_HOOK_IP4_ROUTE(dest): - * - called from ip_route() (IPv4) + * Called from ip_route() (IPv4) + * Signature:\code{.c} + * struct netif *my_hook(const ip4_addr_t *dest); + * \endcode + * Arguments: * - dest: destination IPv4 address - * Returns the destination netif or NULL if no destination netif is found. In - * that case, ip_route() continues as normal. + * Returns values: + * - the destination netif + * - NULL if no destination netif is found. In that case, ip_route() continues as normal. */ #ifdef __DOXYGEN__ #define LWIP_HOOK_IP4_ROUTE() #endif /** - * LWIP_HOOK_IP4_ROUTE_SRC(dest, src): - * - source-based routing for IPv4 (see LWIP_HOOK_IP4_ROUTE(), src may be NULL) + * LWIP_HOOK_IP4_ROUTE_SRC(src, dest): + * Source-based routing for IPv4 - called from ip_route() (IPv4) + * Signature:\code{.c} + * struct netif *my_hook(const ip4_addr_t *src, const ip4_addr_t *dest); + * \endcode + * Arguments: + * - src: local/source IPv4 address + * - dest: destination IPv4 address + * Returns values: + * - the destination netif + * - NULL if no destination netif is found. In that case, ip_route() continues as normal. */ #ifdef __DOXYGEN__ -#define LWIP_HOOK_IP4_ROUTE_SRC(dest, src) +#define LWIP_HOOK_IP4_ROUTE_SRC(src, dest) +#endif + +/** + * LWIP_HOOK_IP4_CANFORWARD(src, dest): + * Check if an IPv4 can be forwarded - called from: + * ip4_input() -> ip4_forward() -> ip4_canforward() (IPv4) + * - source address is available via ip4_current_src_addr() + * - calling an output function in this context (e.g. multicast router) is allowed + * Signature:\code{.c} + * int my_hook(struct pbuf *p, u32_t dest_addr_hostorder); + * \endcode + * Arguments: + * - p: packet to forward + * - dest: destination IPv4 address + * Returns values: + * - 1: forward + * - 0: don't forward + * - -1: no decision. In that case, ip4_canforward() continues as normal. + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_IP4_CANFORWARD(src, dest) #endif /** * LWIP_HOOK_ETHARP_GET_GW(netif, dest): - * - called from etharp_output() (IPv4) + * Called from etharp_output() (IPv4) + * Signature:\code{.c} + * const ip4_addr_t *my_hook(struct netif *netif, const ip4_addr_t *dest); + * \endcode + * Arguments: * - netif: the netif used for sending * - dest: the destination IPv4 address - * Returns the IPv4 address of the gateway to handle the specified destination - * IPv4 address. If NULL is returned, the netif's default gateway is used. + * Return values: + * - the IPv4 address of the gateway to handle the specified destination IPv4 address + * - NULL, in which case the netif's default gateway is used + * * The returned address MUST be directly reachable on the specified netif! * This function is meant to implement advanced IPv4 routing together with * LWIP_HOOK_IP4_ROUTE(). The actual routing/gateway table implementation is @@ -2549,7 +2995,11 @@ /** * LWIP_HOOK_IP6_INPUT(pbuf, input_netif): - * - called from ip6_input() (IPv6) + * Called from ip6_input() (IPv6) + * Signature:\code{.c} + * int my_hook(struct pbuf *pbuf, struct netif *input_netif); + * \endcode + * Arguments: * - pbuf: received struct pbuf passed to ip6_input() * - input_netif: struct netif on which the packet has been received * Return values: @@ -2564,11 +3014,16 @@ /** * LWIP_HOOK_IP6_ROUTE(src, dest): - * - called from ip6_route() (IPv6) - * - src: sourc IPv6 address + * Called from ip_route() (IPv6) + * Signature:\code{.c} + * struct netif *my_hook(const ip6_addr_t *dest, const ip6_addr_t *src); + * \endcode + * Arguments: + * - src: source IPv6 address * - dest: destination IPv6 address - * Returns the destination netif or NULL if no destination netif is found. In - * that case, ip6_route() continues as normal. + * Return values: + * - the destination netif + * - NULL if no destination netif is found. In that case, ip6_route() continues as normal. */ #ifdef __DOXYGEN__ #define LWIP_HOOK_IP6_ROUTE(src, dest) @@ -2576,11 +3031,17 @@ /** * LWIP_HOOK_ND6_GET_GW(netif, dest): - * - called from nd6_get_next_hop_entry() (IPv6) + * Called from nd6_get_next_hop_entry() (IPv6) + * Signature:\code{.c} + * const ip6_addr_t *my_hook(struct netif *netif, const ip6_addr_t *dest); + * \endcode + * Arguments: * - netif: the netif used for sending * - dest: the destination IPv6 address - * Returns the IPv6 address of the next hop to handle the specified destination - * IPv6 address. If NULL is returned, a NDP-discovered router is used instead. + * Return values: + * - the IPv6 address of the next hop to handle the specified destination IPv6 address + * - NULL, in which case a NDP-discovered router is used instead + * * The returned address MUST be directly reachable on the specified netif! * This function is meant to implement advanced IPv6 routing together with * LWIP_HOOK_IP6_ROUTE(). The actual routing/gateway table implementation is @@ -2592,7 +3053,11 @@ /** * LWIP_HOOK_VLAN_CHECK(netif, eth_hdr, vlan_hdr): - * - called from ethernet_input() if VLAN support is enabled + * Called from ethernet_input() if VLAN support is enabled + * Signature:\code{.c} + * int my_hook(struct netif *netif, struct eth_hdr *eth_hdr, struct eth_vlan_hdr *vlan_hdr); + * \endcode + * Arguments: * - netif: struct netif on which the packet has been received * - eth_hdr: struct eth_hdr of the packet * - vlan_hdr: struct eth_vlan_hdr of the packet @@ -2609,7 +3074,9 @@ * Hook can be used to set prio_vid field of vlan_hdr. If you need to store data * on per-netif basis to implement this callback, see @ref netif_cd. * Called from ethernet_output() if VLAN support (@ref ETHARP_SUPPORT_VLAN) is enabled.\n - * Signature: s32_t my_hook_vlan_set(struct netif* netif, struct pbuf* pbuf, const struct eth_addr* src, const struct eth_addr* dst, u16_t eth_type);\n + * Signature:\code{.c} + * s32_t my_hook_vlan_set(struct netif* netif, struct pbuf* pbuf, const struct eth_addr* src, const struct eth_addr* dst, u16_t eth_type);\n + * \endcode * Arguments: * - netif: struct netif that the packet will be sent through * - p: struct pbuf packet to be sent @@ -2628,7 +3095,10 @@ /** * LWIP_HOOK_MEMP_AVAILABLE(memp_t_type): - * - called from memp_free() when a memp pool was empty and an item is now available + * Called from memp_free() when a memp pool was empty and an item is now available + * Signature:\code{.c} + * void my_hook(memp_t type); + * \endcode */ #ifdef __DOXYGEN__ #define LWIP_HOOK_MEMP_AVAILABLE(memp_t_type) @@ -2637,12 +3107,175 @@ /** * LWIP_HOOK_UNKNOWN_ETH_PROTOCOL(pbuf, netif): * Called from ethernet_input() when an unknown eth type is encountered. - * Return ERR_OK if packet is accepted, any error code otherwise. + * Signature:\code{.c} + * err_t my_hook(struct pbuf* pbuf, struct netif* netif); + * \endcode + * Arguments: + * - p: rx packet with unknown eth type + * - netif: netif on which the packet has been received + * Return values: + * - ERR_OK if packet is accepted (hook function now owns the pbuf) + * - any error code otherwise (pbuf is freed) + * * Payload points to ethernet header! */ #ifdef __DOXYGEN__ #define LWIP_HOOK_UNKNOWN_ETH_PROTOCOL(pbuf, netif) #endif + +/** + * LWIP_HOOK_DHCP_APPEND_OPTIONS(netif, dhcp, state, msg, msg_type, options_len_ptr): + * Called from various dhcp functions when sending a DHCP message. + * This hook is called just before the DHCP message trailer is added, so the + * options are at the end of a DHCP message. + * Signature:\code{.c} + * void my_hook(struct netif *netif, struct dhcp *dhcp, u8_t state, struct dhcp_msg *msg, + * u8_t msg_type, u16_t *options_len_ptr); + * \endcode + * Arguments: + * - netif: struct netif that the packet will be sent through + * - dhcp: struct dhcp on that netif + * - state: current dhcp state (dhcp_state_enum_t as an u8_t) + * - msg: struct dhcp_msg that will be sent + * - msg_type: dhcp message type to be sent (u8_t) + * - options_len_ptr: pointer to the current length of options in the dhcp_msg "msg" + * (must be increased when options are added!) + * + * Options need to appended like this: + * LWIP_ASSERT("dhcp option overflow", *options_len_ptr + option_len + 2 <= DHCP_OPTIONS_LEN); + * msg->options[(*options_len_ptr)++] = <option_number>; + * msg->options[(*options_len_ptr)++] = <option_len>; + * msg->options[(*options_len_ptr)++] = <option_bytes>; + * [...] + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_DHCP_APPEND_OPTIONS(netif, dhcp, state, msg, msg_type, options_len_ptr) +#endif + +/** + * LWIP_HOOK_DHCP_PARSE_OPTION(netif, dhcp, state, msg, msg_type, option, len, pbuf, option_value_offset): + * Called from dhcp_parse_reply when receiving a DHCP message. + * This hook is called for every option in the received message that is not handled internally. + * Signature:\code{.c} + * void my_hook(struct netif *netif, struct dhcp *dhcp, u8_t state, struct dhcp_msg *msg, + * u8_t msg_type, u8_t option, u8_t option_len, struct pbuf *pbuf, u16_t option_value_offset); + * \endcode + * Arguments: + * - netif: struct netif that the packet will be sent through + * - dhcp: struct dhcp on that netif + * - state: current dhcp state (dhcp_state_enum_t as an u8_t) + * - msg: struct dhcp_msg that was received + * - msg_type: dhcp message type received (u8_t, ATTENTION: only valid after + * the message type option has been parsed!) + * - option: option value (u8_t) + * - len: option data length (u8_t) + * - pbuf: pbuf where option data is contained + * - option_value_offset: offset in pbuf where option data begins + * + * A nice way to get the option contents is pbuf_get_contiguous(): + * u8_t buf[32]; + * u8_t *ptr = (u8_t*)pbuf_get_contiguous(p, buf, sizeof(buf), LWIP_MIN(option_len, sizeof(buf)), offset); + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_DHCP_PARSE_OPTION(netif, dhcp, state, msg, msg_type, option, len, pbuf, offset) +#endif + +/** + * LWIP_HOOK_DHCP6_APPEND_OPTIONS(netif, dhcp6, state, msg, msg_type, options_len_ptr, max_len): + * Called from various dhcp6 functions when sending a DHCP6 message. + * This hook is called just before the DHCP6 message is sent, so the + * options are at the end of a DHCP6 message. + * Signature:\code{.c} + * void my_hook(struct netif *netif, struct dhcp6 *dhcp, u8_t state, struct dhcp6_msg *msg, + * u8_t msg_type, u16_t *options_len_ptr); + * \endcode + * Arguments: + * - netif: struct netif that the packet will be sent through + * - dhcp6: struct dhcp6 on that netif + * - state: current dhcp6 state (dhcp6_state_enum_t as an u8_t) + * - msg: struct dhcp6_msg that will be sent + * - msg_type: dhcp6 message type to be sent (u8_t) + * - options_len_ptr: pointer to the current length of options in the dhcp6_msg "msg" + * (must be increased when options are added!) + * + * Options need to appended like this: + * u8_t *options = (u8_t *)(msg + 1); + * LWIP_ASSERT("dhcp option overflow", sizeof(struct dhcp6_msg) + *options_len_ptr + newoptlen <= max_len); + * options[(*options_len_ptr)++] = <option_data>; + * [...] + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_DHCP6_APPEND_OPTIONS(netif, dhcp6, state, msg, msg_type, options_len_ptr, max_len) +#endif + +/** + * LWIP_HOOK_SOCKETS_SETSOCKOPT(s, sock, level, optname, optval, optlen, err) + * Called from socket API to implement setsockopt() for options not provided by lwIP. + * Core lock is held when this hook is called. + * Signature:\code{.c} + * int my_hook(int s, struct lwip_sock *sock, int level, int optname, const void *optval, socklen_t optlen, int *err) + * \endcode + * Arguments: + * - s: socket file descriptor + * - sock: internal socket descriptor (see lwip/priv/sockets_priv.h) + * - level: protocol level at which the option resides + * - optname: option to set + * - optval: value to set + * - optlen: size of optval + * - err: output error + * Return values: + * - 0: Hook has not consumed the option, code continues as normal (to internal options) + * - != 0: Hook has consumed the option, 'err' is returned + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_SOCKETS_SETSOCKOPT(s, sock, level, optname, optval, optlen, err) +#endif + +/** + * LWIP_HOOK_SOCKETS_GETSOCKOPT(s, sock, level, optname, optval, optlen, err) + * Called from socket API to implement getsockopt() for options not provided by lwIP. + * Core lock is held when this hook is called. + * Signature:\code{.c} + * int my_hook(int s, struct lwip_sock *sock, int level, int optname, void *optval, socklen_t *optlen, int *err) + * \endcode + * Arguments: + * - s: socket file descriptor + * - sock: internal socket descriptor (see lwip/priv/sockets_priv.h) + * - level: protocol level at which the option resides + * - optname: option to get + * - optval: value to get + * - optlen: size of optval + * - err: output error + * Return values: + * - 0: Hook has not consumed the option, code continues as normal (to internal options) + * - != 0: Hook has consumed the option, 'err' is returned + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_SOCKETS_GETSOCKOPT(s, sock, level, optname, optval, optlen, err) +#endif + +/** + * LWIP_HOOK_NETCONN_EXTERNAL_RESOLVE(name, addr, addrtype, err) + * Called from netconn APIs (not usable with callback apps) allowing an + * external DNS resolver (which uses sequential API) to handle the query. + * Signature:\code{.c} + * int my_hook(const char *name, ip_addr_t *addr, u8_t addrtype, err_t *err) + * \endcode + * Arguments: + * - name: hostname to resolve + * - addr: output host address + * - addrtype: type of address to query + * - err: output error + * Return values: + * - 0: Hook has not consumed hostname query, query continues into DNS module + * - != 0: Hook has consumed the query + * + * err must also be checked to determine if the hook consumed the query, but + * the query failed + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_NETCONN_EXTERNAL_RESOLVE(name, addr, addrtype, err) +#endif /** * @} */ @@ -2900,10 +3533,24 @@ #if !defined IP6_DEBUG || defined __DOXYGEN__ #define IP6_DEBUG LWIP_DBG_OFF #endif + +/** + * DHCP6_DEBUG: Enable debugging in dhcp6.c. + */ +#if !defined DHCP6_DEBUG || defined __DOXYGEN__ +#define DHCP6_DEBUG LWIP_DBG_OFF +#endif /** * @} */ +/** + * LWIP_TESTMODE: Changes to make unit test possible + */ +#if !defined LWIP_TESTMODE +#define LWIP_TESTMODE 0 +#endif + /* -------------------------------------------------- ---------- Performance tracking options ---------- diff --git a/src/libzt.cpp b/src/libzt.cpp index f0245d9..8e1d520 100644 --- a/src/libzt.cpp +++ b/src/libzt.cpp @@ -79,24 +79,33 @@ int lwip_getpeername (int s, struct sockaddr *name, socklen_t *namelen); int lwip_getsockname (int s, struct sockaddr *name, socklen_t *namelen); int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen); int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen); -int lwip_close(int s); + int lwip_close(int s); int lwip_connect(int s, const struct sockaddr *name, socklen_t namelen); int lwip_listen(int s, int backlog); -int lwip_recv(int s, void *mem, size_t len, int flags); -int lwip_read(int s, void *mem, size_t len); -int lwip_recvfrom(int s, void *mem, size_t len, int flags, +ssize_t lwip_recv(int s, void *mem, size_t len, int flags); +ssize_t lwip_read(int s, void *mem, size_t len); +ssize_t lwip_readv(int s, const struct iovec *iov, int iovcnt); +ssize_t lwip_recvfrom(int s, void *mem, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen); -int lwip_send(int s, const void *dataptr, size_t size, int flags); -int lwip_sendmsg(int s, const struct msghdr *message, int flags); -int lwip_sendto(int s, const void *dataptr, size_t size, int flags, +ssize_t lwip_recvmsg(int s, struct msghdr *message, int flags); +ssize_t lwip_send(int s, const void *dataptr, size_t size, int flags); +ssize_t lwip_sendmsg(int s, const struct msghdr *message, int flags); +ssize_t lwip_sendto(int s, const void *dataptr, size_t size, int flags, const struct sockaddr *to, socklen_t tolen); int lwip_socket(int domain, int type, int protocol); -int lwip_write(int s, const void *dataptr, size_t size); -int lwip_writev(int s, const struct iovec *iov, int iovcnt); +ssize_t lwip_write(int s, const void *dataptr, size_t size); +ssize_t lwip_writev(int s, const struct iovec *iov, int iovcnt); +#if LWIP_SOCKET_SELECT int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, struct timeval *timeout); +#endif +#if LWIP_SOCKET_POLL +int lwip_poll(struct pollfd *fds, nfds_t nfds, int timeout); +#endif int lwip_ioctl(int s, long cmd, void *argp); int lwip_fcntl(int s, int cmd, int val); +const char *lwip_inet_ntop(int af, const void *src, char *dst, socklen_t size); +int lwip_inet_pton(int af, const char *src, void *dst); // Copied from lwip/src/include/sockets.h and renamed to prevent a name collision // with system definitions