From 9b8607bfe8d7492782dffcb9e271d22b2df52f90 Mon Sep 17 00:00:00 2001 From: Xadhoom <> Date: Sun, 7 Mar 2021 14:17:58 +0000 Subject: [PATCH] Fix locking bug and backport e304a89ddb8a47cc4a8c44254221f360bcc24950 --- ext/lwip-contrib | 2 +- src/VirtualTap.cpp | 4 ++++ src/lwipopts.h | 22 ++++++++++++++++++++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/ext/lwip-contrib b/ext/lwip-contrib index 07a75f9..1f9e26e 160000 --- a/ext/lwip-contrib +++ b/ext/lwip-contrib @@ -1 +1 @@ -Subproject commit 07a75f9e085663118a5f07c8aaa7f4d91c7de658 +Subproject commit 1f9e26e221a41542563834222c4ec8399be1908f diff --git a/src/VirtualTap.cpp b/src/VirtualTap.cpp index 60e0814..a5b025b 100644 --- a/src/VirtualTap.cpp +++ b/src/VirtualTap.cpp @@ -224,7 +224,9 @@ void VirtualTap::put(const MAC &from,const MAC &to,unsigned int etherType, const void *data,unsigned int len) { if (len <= _mtu && _enabled) { + LOCK_TCPIP_CORE(); _lwip_eth_rx(this, from, to, etherType, data, len); + UNLOCK_TCPIP_CORE(); } } @@ -523,12 +525,14 @@ void _lwip_eth_rx(VirtualTap *tap, const MAC &from, const MAC &to, unsigned int // Feed packet into stack int err; + if(tap->netif4) if (Utils::ntoh(ethhdr.type) == 0x800 || Utils::ntoh(ethhdr.type) == 0x806) { if ((err = ((struct netif *)tap->netif4)->input(p, (struct netif *)tap->netif4)) != ERR_OK) { DEBUG_ERROR("packet input error (%d)", err); pbuf_free(p); } } + if(tap->netif6) if (Utils::ntoh(ethhdr.type) == 0x86DD) { if ((err = ((struct netif *)tap->netif6)->input(p, (struct netif *)tap->netif6)) != ERR_OK) { DEBUG_ERROR("packet input error (%d)", err); diff --git a/src/lwipopts.h b/src/lwipopts.h index e8c4a2b..0f8c66d 100644 --- a/src/lwipopts.h +++ b/src/lwipopts.h @@ -49,8 +49,9 @@ ------------------------------------------------------------------------------*/ // Misc +#define IPV6_FRAG_COPYHEADER 1 #define LWIP_STATS_LARGE 1 -#define LWIP_NOASSERT 1 +//#define LWIP_NOASSERT 1 #if __ANDROID__ #define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS 0 #endif @@ -119,7 +120,7 @@ // tcpip #define TCPIP_MBOX_SIZE 0 #define LWIP_TCPIP_CORE_LOCKING 1 -#define LWIP_TCPIP_CORE_LOCKING_INPUT 0 +#define LWIP_TCPIP_CORE_LOCKING_INPUT 1 // netconn #define LWIP_NETCONN_FULLDUPLEX 0 // netif @@ -128,6 +129,23 @@ #define LWIP_NETIF_TX_SINGLE_PBUF 0 #define TCPIP_THREAD_PRIO 1 +#define LWIP_ASSERT_CORE_LOCKED() sys_check_core_locking() +#define LWIP_MARK_TCPIP_THREAD() sys_mark_tcpip_thread() +#define LOCK_TCPIP_CORE() sys_lock_tcpip_core() +#define UNLOCK_TCPIP_CORE() sys_unlock_tcpip_core() + +#ifdef __cplusplus +extern "C" { +#endif +void sys_check_core_locking(); +void sys_mark_tcpip_thread(); +void sys_lock_tcpip_core(); +void sys_unlock_tcpip_core(); +#ifdef __cplusplus +} +#endif + + /*------------------------------------------------------------------------------ ------------------------------------ Timers ------------------------------------ ------------------------------------------------------------------------------*/