diff --git a/ext/lwipopts.h b/ext/lwipopts.h index 1667439..91dafe0 100644 --- a/ext/lwipopts.h +++ b/ext/lwipopts.h @@ -52,6 +52,7 @@ #define LWIP_IPV4 1 //#endif +#define LWIP_TCP 1 #define IP6_DEBUG 1 #define LWIP_DEBUG 1 #define IP_DEBUG LWIP_DBG_ON diff --git a/integrations/apple/ZeroTierSDK_Apple/ZeroTierSDK_Apple.xcodeproj/project.pbxproj b/integrations/apple/ZeroTierSDK_Apple/ZeroTierSDK_Apple.xcodeproj/project.pbxproj index 229d389..3fb2713 100644 --- a/integrations/apple/ZeroTierSDK_Apple/ZeroTierSDK_Apple.xcodeproj/project.pbxproj +++ b/integrations/apple/ZeroTierSDK_Apple/ZeroTierSDK_Apple.xcodeproj/project.pbxproj @@ -366,6 +366,9 @@ 7CEAF5891DBAD0BF006585E7 /* DeferredPackets.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DeferredPackets.cpp; path = ../../../zerotierone/node/DeferredPackets.cpp; sourceTree = ""; }; 7CEAF58A1DBAD0BF006585E7 /* DeferredPackets.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = DeferredPackets.hpp; path = ../../../zerotierone/node/DeferredPackets.hpp; sourceTree = ""; }; 7CEAF58E1DBAD10A006585E7 /* BackgroundResolver.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = BackgroundResolver.cpp; path = ../../../zerotierone/osdep/BackgroundResolver.cpp; sourceTree = ""; }; + 7CEAF5901DBADA69006585E7 /* tcp_in.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = tcp_in.c; path = ../../../ext/lwip/src/core/tcp_in.c; sourceTree = ""; }; + 7CEAF5911DBADA69006585E7 /* tcp_out.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = tcp_out.c; path = ../../../ext/lwip/src/core/tcp_out.c; sourceTree = ""; }; + 7CEAF5921DBADA69006585E7 /* tcp.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = tcp.c; path = ../../../ext/lwip/src/core/tcp.c; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -410,6 +413,9 @@ 7CC002FB1D12164D003E68DC = { isa = PBXGroup; children = ( + 7CEAF5901DBADA69006585E7 /* tcp_in.c */, + 7CEAF5911DBADA69006585E7 /* tcp_out.c */, + 7CEAF5921DBADA69006585E7 /* tcp.c */, 7CEAF58E1DBAD10A006585E7 /* BackgroundResolver.cpp */, 7CEAF5871DBACEC3006585E7 /* err.c */, 7CEAF5851DBACE7E006585E7 /* ethernet.c */, @@ -951,6 +957,9 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 7C969BCE1DB99F9E00BD3F7F /* tcp_in.c in Sources */, + 7C969BCF1DB99F9E00BD3F7F /* tcp_out.c in Sources */, + 7C969BD01DB99F9E00BD3F7F /* tcp.c in Sources */, 7CEAF58F1DBAD10A006585E7 /* BackgroundResolver.cpp in Sources */, 7CEAF58C1DBAD0E1006585E7 /* DeferredPackets.cpp in Sources */, 7CEAF58D1DBAD0E1006585E7 /* OneService.cpp in Sources */, @@ -1005,9 +1014,6 @@ 7C969BCB1DB99F9E00BD3F7F /* raw.c in Sources */, 7C969BCC1DB99F9E00BD3F7F /* stats.c in Sources */, 7C969BCD1DB99F9E00BD3F7F /* sys.c in Sources */, - 7C969BCE1DB99F9E00BD3F7F /* tcp_in.c in Sources */, - 7C969BCF1DB99F9E00BD3F7F /* tcp_out.c in Sources */, - 7C969BD01DB99F9E00BD3F7F /* tcp.c in Sources */, 7C969BD11DB99F9E00BD3F7F /* timeouts.c in Sources */, 7C969BD21DB99F9E00BD3F7F /* udp.c in Sources */, 7C6F654E1D6F6BA1004F6CDF /* SDK_Service.cpp in Sources */, @@ -1273,6 +1279,8 @@ "-DLWIP_DEBUG", "-DSDK_IPV4", "-DUSING_BRIDGING_HEADER", + "-DSDK_LWIP", + "-D__APP_FRAMEWORK__", ); PRODUCT_BUNDLE_IDENTIFIER = "zerotier.ZeroTierSDK-OSX"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -1304,6 +1312,7 @@ "-DSDK_SERVICE", "-DSDK_BUNDLED", "-D__XCODE__", + "-D__APP_FRAMEWORK__", ); PRODUCT_BUNDLE_IDENTIFIER = "zerotier.ZeroTierSDK-OSX"; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/integrations/apple/example_app/OSX/Example_OSX_App.xcodeproj/xcuserdata/Joseph.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/integrations/apple/example_app/OSX/Example_OSX_App.xcodeproj/xcuserdata/Joseph.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 3c19311..d923050 100644 --- a/integrations/apple/example_app/OSX/Example_OSX_App.xcodeproj/xcuserdata/Joseph.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/integrations/apple/example_app/OSX/Example_OSX_App.xcodeproj/xcuserdata/Joseph.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -15,7 +15,7 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "174" endingLineNumber = "174" - landmarkName = "UI_SendData(_:)" + landmarkName = "UI_ReadData(_:)" landmarkType = "5"> @@ -31,7 +31,7 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "194" endingLineNumber = "194" - landmarkName = "UI_ReadData(_:)" + landmarkName = "update_rx()" landmarkType = "5"> @@ -47,7 +47,7 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "50" endingLineNumber = "50" - landmarkName = "zt_join_network(const char * nwid)" + landmarkName = "zt_stop_service()" landmarkType = "7"> @@ -63,7 +63,7 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "193" endingLineNumber = "193" - landmarkName = "UI_ReadData(_:)" + landmarkName = "update_rx()" landmarkType = "5"> diff --git a/src/SDK_Debug.h b/src/SDK_Debug.h index 0a4fe6b..9613238 100644 --- a/src/SDK_Debug.h +++ b/src/SDK_Debug.h @@ -40,7 +40,11 @@ #define __SHOW_FILENAMES__ true #define __SHOW_COLOR__ true -#if defined(__SHOW_COLOR__) +// Colors +#if defined(__APPLE__) + #include "TargetConditionals.h" +#endif +#if defined(__SHOW_COLOR__) && !defined(__ANDROID__) && !defined(TARGET_OS_IPHONE) && !defined(TARGET_IPHONE_SIMULATOR) && !defined(__APP_FRAMEWORK__) #define RED "\x1B[31m" #define GRN "\x1B[32m" #define YEL "\x1B[33m" diff --git a/src/SDK_EthernetTap.cpp b/src/SDK_EthernetTap.cpp index cfa39d9..fdf0dae 100644 --- a/src/SDK_EthernetTap.cpp +++ b/src/SDK_EthernetTap.cpp @@ -694,8 +694,9 @@ NetconEthernetTap::NetconEthernetTap( // SIP-0 // Load and initialize network stack library - #if defined(SDK_LWIP) + DEBUG_INFO("Did I get here?"); + Utils::snprintf(stackPath,sizeof(stackPath),"%s%sliblwip.so",homePath,ZT_PATH_SEPARATOR_S); lwipstack = new lwIP_stack(stackPath); if(!lwipstack) { @@ -703,6 +704,7 @@ NetconEthernetTap::NetconEthernetTap( throw std::runtime_error(""); } lwipstack->__lwip_init(); + DEBUG_EXTRA("network stack initialized (%p)", lwipstack); #elif defined(SDK_PICOTCP) Utils::snprintf(stackPath,sizeof(stackPath),"%s%slibpicotcp.so",homePath,ZT_PATH_SEPARATOR_S); picostack = new picoTCP_stack(stackPath); @@ -711,6 +713,7 @@ NetconEthernetTap::NetconEthernetTap( throw std::runtime_error(""); } picostack->__pico_stack_init(); + DEBUG_EXTRA("network stack initialized (%p)", picostack); #elif defined(SDK_JIP) Utils::snprintf(stackPath,sizeof(stackPath),"%s%slibjip.so",homePath,ZT_PATH_SEPARATOR_S); jipstack = new jip_stack(stackPath); diff --git a/src/SDK_lwip.hpp b/src/SDK_lwip.hpp index c15d459..2e4719c 100644 --- a/src/SDK_lwip.hpp +++ b/src/SDK_lwip.hpp @@ -37,6 +37,8 @@ #include "lwip/init.h" #include "lwip/udp.h" #include "lwip/tcp.h" +#include "lwip/priv/tcp_priv.h" + #include "Mutex.hpp" #include "OSUtils.hpp" @@ -51,6 +53,19 @@ struct tcp_pcb; +#if defined(SDK_IPV4) + #define NETIF_ADD_SIG struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw, void *state, netif_init_fn init, netif_input_fn input + #define ETHARP_OUTPUT_SIG struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr +#endif + +#if defined(SDK_IPV6) + #define NETIF_ADD_SIG struct netif *netif, void *state, netif_init_fn init, netif_input_fn input + #define ETHIP6_OUTPUT_SIG struct netif *netif, struct pbuf *q, const ip6_addr_t *ip6addr + #define ETHARP_OUTPUT_SIG struct netif *netif, struct pbuf *q, const ip6_addr_t *ipaddr + #define NETIF_IP6_ADDR_SET_STATE_SIG struct netif* netif, s8_t addr_idx, u8_t state + #define NETIF_CREATE_IP6_LINKLOCAL_ADDRESS_SIG struct netif *netif, u8_t from_mac_48bit +#endif + // lwip General Stack API #define PBUF_FREE_SIG struct pbuf *p #define PBUF_ALLOC_SIG pbuf_layer layer, u16_t length, pbuf_type type @@ -89,8 +104,6 @@ struct tcp_pcb; #define TCP_INPUT_SIG struct pbuf *p, struct netif *inp // lwIP network stack interfaces -#define NETIF_IP6_ADDR_SET_STATE_SIG struct netif* netif, s8_t addr_idx, u8_t state -#define NETIF_CREATE_IP6_LINKLOCAL_ADDRESS_SIG struct netif *netif, u8_t from_mac_48bit #define ETHERNET_INPUT_SIG struct pbuf *p, struct netif *netif #define IP_INPUT_SIG struct pbuf *p, struct netif *inp #define NETIF_SET_DEFAULT_SIG struct netif *netif @@ -99,17 +112,6 @@ struct tcp_pcb; //#define NETIF_SET_ADDR_SIG struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw -#if defined(SDK_IPV6) - #define NETIF_ADD_SIG struct netif *netif, void *state, netif_init_fn init, netif_input_fn input - #define ETHIP6_OUTPUT_SIG struct netif *netif, struct pbuf *q, const ip6_addr_t *ip6addr - #define ETHARP_OUTPUT_SIG struct netif *netif, struct pbuf *q, const ip6_addr_t *ipaddr -#endif - -#if defined(SDK_IPV4) - #define NETIF_ADD_SIG struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw, void *state, netif_init_fn init, netif_input_fn input - #define ETHARP_OUTPUT_SIG struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr -#endif - namespace ZeroTier { /** @@ -135,6 +137,10 @@ namespace ZeroTier { #endif } + #if defined(SDK_IPV4) + err_t (*_etharp_output)(ETHARP_OUTPUT_SIG); + #endif + #if defined(SDK_IPV6) err_t (*_ethip6_output)(ETHIP6_OUTPUT_SIG); void (*_nd6_tmr)(void); @@ -142,10 +148,6 @@ namespace ZeroTier { void (*_netif_create_ip6_linklocal_address)(NETIF_CREATE_IP6_LINKLOCAL_ADDRESS_SIG); #endif - #if defined(SDK_IPV4) - err_t (*_etharp_output)(ETHARP_OUTPUT_SIG); - #endif - void (*_netif_init)(void); // void (*_netif_set_addr)(NETIF_SET_ADDR_SIG); @@ -221,6 +223,17 @@ namespace ZeroTier { #ifdef __STATIC_LWIP__ // Set static references (for use in iOS) + #if defined(SDK_IPV4) + _etharp_output = (err_t(*)(ETHARP_OUTPUT_SIG))ðarp_output; + #endif + + #if defined(SDK_IPV6) + _nd6_tmr = (void(*)(void))&nd6_tmr; + _netif_ip6_addr_set_state = (void(*)(NETIF_IP6_ADDR_SET_STATE_SIG))&netif_ip6_addr_set_state; + _netif_create_ip6_linklocal_address = (void(*)(NETIF_CREATE_IP6_LINKLOCAL_ADDRESS_SIG))&netif_create_ip6_linklocal_address; + _ethip6_output = (err_t(*)(ETHIP6_OUTPUT_SIG))ðip6_output; + #endif + _netif_init = (void(*)(void))&netif_init; _ethernet_input = (err_t(*)(ETHERNET_INPUT_SIG))ðernet_input; _lwip_init = (void(*)(void))&lwip_init; @@ -260,17 +273,6 @@ namespace ZeroTier { _netif_add = (struct netif*(*)(NETIF_ADD_SIG))&netif_add; _netif_set_up = (void(*)(NETIF_SET_UP_SIG))&netif_set_up; - #if defined(SDK_IPV6) - _nd6_tmr = (void(*)(void))&nd6_tmr; - _netif_ip6_addr_set_state = (void(*)(NETIF_IP6_ADDR_SET_STATE_SIG))&netif_ip6_addr_set_state; - _netif_create_ip6_linklocal_address = (void(*)(NETIF_CREATE_IP6_LINKLOCAL_ADDRESS_SIG))&netif_create_ip6_linklocal_address; - _ethip6_output = (err_t(*)(ETHIP6_OUTPUT_SIG))ðip6_output; - #endif - - #if defined(SDK_IPV6) - _etharp_output = (err_t(*)(ETHARP_OUTPUT_SIG))ðarp_output; - #endif - #endif #ifdef __DYNAMIC_LWIP__ // Use dynamically-loaded symbols (for use in normal desktop applications) @@ -278,16 +280,16 @@ namespace ZeroTier { if(_libref == NULL) DEBUG_ERROR("dlerror(): %s", dlerror()); - #if defined(SDK_IPV4) - _etharp_output = (err_t(*)(ETHARP_OUTPUT_SIG))dlsym(_libref, "etharp_output"); - #endif + #if defined(SDK_IPV4) + _etharp_output = (err_t(*)(ETHARP_OUTPUT_SIG))dlsym(_libref, "etharp_output"); + #endif - #if defined(SDK_IPV6) - _nd6_tmr = (void(*)(void))dlsym(_libref, "nd6_tmr"); - _netif_ip6_addr_set_state = (void(*)(NETIF_IP6_ADDR_SET_STATE_SIG))dlsym(_libref, "netif_ip6_addr_set_state"); - _netif_create_ip6_linklocal_address = (void(*)(NETIF_CREATE_IP6_LINKLOCAL_ADDRESS_SIG))dlsym(_libref, "netif_create_ip6_linklocal_address"); - _ethip6_output = (err_t(*)(ETHIP6_OUTPUT_SIG))dlsym(_libref, "ethip6_output"); - #endif + #if defined(SDK_IPV6) + _nd6_tmr = (void(*)(void))dlsym(_libref, "nd6_tmr"); + _netif_ip6_addr_set_state = (void(*)(NETIF_IP6_ADDR_SET_STATE_SIG))dlsym(_libref, "netif_ip6_addr_set_state"); + _netif_create_ip6_linklocal_address = (void(*)(NETIF_CREATE_IP6_LINKLOCAL_ADDRESS_SIG))dlsym(_libref, "netif_create_ip6_linklocal_address"); + _ethip6_output = (err_t(*)(ETHIP6_OUTPUT_SIG))dlsym(_libref, "ethip6_output"); + #endif _netif_init = (void(*)(void))dlsym(_libref, "netif_init"); // _netif_set_addr = (void(*))(NETIF_SET_ADDR_SIG))dlsym(_libref, "netif_set_addr"); @@ -340,6 +342,19 @@ namespace ZeroTier { dlclose(_libref); } + + #if defined(SDK_IPV4) + inline struct netif * __netif_add(NETIF_ADD_SIG) throw() { Mutex::Lock _l(_lock); return _netif_add(netif,ipaddr,netmask,gw,state,init,input); } + #endif + + #if defined(SDK_IPV6) + inline struct netif * __netif_add(NETIF_ADD_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _netif_add(netif,state,init,input); } + inline void __nd6_tmr(void) throw() { /*DEBUG_STACK();*/ Mutex::Lock _l(_lock); _nd6_tmr(); } + inline void __netif_ip6_addr_set_state(NETIF_IP6_ADDR_SET_STATE_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); _netif_ip6_addr_set_state(netif, addr_idx, state); } + inline void __netif_create_ip6_linklocal_address(NETIF_CREATE_IP6_LINKLOCAL_ADDRESS_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); _netif_create_ip6_linklocal_address(netif, from_mac_48bit); } + inline err_t __ethip6_output(ETHIP6_OUTPUT_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _ethip6_output(netif,q,ip6addr); } + #endif + inline void __netif_init(void) throw() { Mutex::Lock _l(_lock); _netif_init(); } // inline void __netif_set_addr(NETIF_SET_ADDR_SIG) throw() { Mutex::Lock _l(_lock); _netif_set_addr(netif, ipaddr, netmask, gw); } @@ -384,17 +399,6 @@ namespace ZeroTier { inline err_t __ip_input(IP_INPUT_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _ip_input(p,inp); } inline void __netif_set_default(NETIF_SET_DEFAULT_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _netif_set_default(netif); } inline void __netif_set_up(NETIF_SET_UP_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _netif_set_up(netif); } - - #if defined(SDK_IPV6) - inline struct netif * __netif_add(NETIF_ADD_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _netif_add(netif,state,init,input); } - inline void __nd6_tmr(void) throw() { /*DEBUG_STACK();*/ Mutex::Lock _l(_lock); _nd6_tmr(); } - inline void __netif_ip6_addr_set_state(NETIF_IP6_ADDR_SET_STATE_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); _netif_ip6_addr_set_state(netif, addr_idx, state); } - inline void __netif_create_ip6_linklocal_address(NETIF_CREATE_IP6_LINKLOCAL_ADDRESS_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); _netif_create_ip6_linklocal_address(netif, from_mac_48bit); } - inline err_t __ethip6_output(ETHIP6_OUTPUT_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _ethip6_output(netif,q,ip6addr); } - #endif - #if defined(SDK_IPV4) - inline struct netif * __netif_add(NETIF_ADD_SIG) throw() { Mutex::Lock _l(_lock); return _netif_add(netif,ipaddr,netmask,gw,state,init,input); } - #endif }; } // namespace ZeroTier diff --git a/zerotierone/osdep/Http.cpp b/zerotierone/osdep/Http.cpp index ccdc6ba..6e3135d 100644 --- a/zerotierone/osdep/Http.cpp +++ b/zerotierone/osdep/Http.cpp @@ -80,7 +80,7 @@ struct HttpPhyHandler phy->close(sock); } - inline void phyOnTcpWritable(PhySocket *sock,void **uptr, bool lwip_invoked) + inline void phyOnTcpWritable(PhySocket *sock,void **uptr) { if (writePtr < writeSize) { long n = phy->streamSend(sock,writeBuf + writePtr,writeSize - writePtr,true); diff --git a/zerotierone/osdep/Phy.hpp b/zerotierone/osdep/Phy.hpp index 307cc50..1603790 100644 --- a/zerotierone/osdep/Phy.hpp +++ b/zerotierone/osdep/Phy.hpp @@ -918,7 +918,7 @@ public: } if ((FD_ISSET(sock,&wfds))&&(FD_ISSET(sock,&_writefds))) { try { - _handler->phyOnTcpWritable((PhySocket *)&(*s),&(s->uptr),false); + _handler->phyOnTcpWritable((PhySocket *)&(*s),&(s->uptr)); } catch ( ... ) {} } } break; diff --git a/zerotierone/service/OneService.cpp b/zerotierone/service/OneService.cpp index 405b3ff..d6ad592 100755 --- a/zerotierone/service/OneService.cpp +++ b/zerotierone/service/OneService.cpp @@ -1182,7 +1182,7 @@ public: } } - inline void phyOnTcpWritable(PhySocket *sock,void **uptr,bool lwip_invoked) + inline void phyOnTcpWritable(PhySocket *sock,void **uptr) { TcpConnection *tc = reinterpret_cast(*uptr); Mutex::Lock _l(tc->writeBuf_m);