polished some rough edges
This commit is contained in:
@@ -1,10 +1,18 @@
|
|||||||
Hot-Swappable Network Stacks!
|
Hot-Swappable Network Stacks!
|
||||||
====
|
====
|
||||||
|
|
||||||
We've now enabled the ability for users to build the ZeroTier SDK with different network stacks with the mere flip of a compiler flag as well as running different stacks concurrently!
|
We've now enabled the ability for users to build the ZeroTier SDK with different network stacks with the mere flip of a compiler flag as well as running different stacks concurrently! This is perfect for embedded developers which may need a smaller code footprint and would like to use their own smaller or more specialized network stacks.
|
||||||
|
|
||||||
`SDK_LWIP=1` and `SDK_PICOTCP=1` will enable the lwIP and picoTCP network stacks respectively.
|
`SDK_LWIP=1` and `SDK_PICOTCP=1` will enable the lwIP and picoTCP network stacks respectively.
|
||||||
|
|
||||||
Currently our lwIP stack driver supports IPV4 and limited IPV6, whereas our picoTCP stack driver supports both IPV4 and IPV6 with no known issues.
|
Currently our *lwIP* stack driver supports IPV4 and limited IPV6, whereas our *picoTCP* stack driver supports both IPV4 and IPV6 with no known issues.
|
||||||
|
|
||||||
To enable specific protocol versions use `SDK_IPV4=1` and `SDK_IPV6=1` in cnojunction with the above stack selection flags.
|
To enable specific protocol versions use `SDK_IPV4=1` and `SDK_IPV6=1` in conjunction with the above stack selection flags.
|
||||||
|
|
||||||
|
## Integrating Your Own Custom Stack
|
||||||
|
|
||||||
|
If you don't know why this section exists, then I suggest turning back now. This is not for you. Now, let's get on with things, here's how you can integrate your own custom network stack if for some reason lwIP or picoTCP aren't cutting it for you.
|
||||||
|
|
||||||
|
The integration points are designated in the tap service code with the tags such as `SIP-0, SIP-1, ..., SIP-n`.
|
||||||
|
|
||||||
|
[More content to come]
|
||||||
@@ -44,11 +44,13 @@
|
|||||||
*/
|
*/
|
||||||
#include "lwip/debug.h"
|
#include "lwip/debug.h"
|
||||||
|
|
||||||
|
|
||||||
// IPV6 Related
|
// IPV6 Related
|
||||||
#define LWIP_IPV6 1
|
//#if defined(SDK_IPV6)
|
||||||
#define LWIP_IPV4 1
|
#define LWIP_IPV6 1
|
||||||
//#define LWIP_IPV6_AUTOCONFIG 1
|
//#endif
|
||||||
|
//#if defined(SDK_IPV4)
|
||||||
|
#define LWIP_IPV4 0
|
||||||
|
//#endif
|
||||||
|
|
||||||
#define IP6_DEBUG 1
|
#define IP6_DEBUG 1
|
||||||
#define LWIP_DEBUG 1
|
#define LWIP_DEBUG 1
|
||||||
|
|||||||
@@ -110,7 +110,13 @@ SIXLOWPAN=$(LWIPDIR)/netif/lowpan6.c \
|
|||||||
ARCHFILES=$(wildcard $(LWIPARCH)/*.c $(LWIPARCH)tapif.c $(LWIPARCH)/netif/list.c $(LWIPARCH)/netif/tcpdump.c)
|
ARCHFILES=$(wildcard $(LWIPARCH)/*.c $(LWIPARCH)tapif.c $(LWIPARCH)/netif/list.c $(LWIPARCH)/netif/tcpdump.c)
|
||||||
|
|
||||||
# LWIPFILES: All the above.
|
# LWIPFILES: All the above.
|
||||||
LWIPFILES=$(COREFILES) $(CORE4FILES) $(CORE6FILES) $(APIFILES) $(NETIFFILES) $(ARCHFILES)
|
LWIPFILES=$(COREFILES) $(CORE4FILES) $(APIFILES) $(NETIFFILES) $(ARCHFILES)
|
||||||
|
|
||||||
|
# ipv6 support
|
||||||
|
ifeq ($(SDK_IPV6),1)
|
||||||
|
LWIPFILES+=$(CORE6FILES)
|
||||||
|
CFLAGS+=-DSDK_IPV6=1
|
||||||
|
endif
|
||||||
LWIPFILESW=$(wildcard $(LWIPFILES))
|
LWIPFILESW=$(wildcard $(LWIPFILES))
|
||||||
LWIPOBJS=$(notdir $(LWIPFILESW:.c=.o))
|
LWIPOBJS=$(notdir $(LWIPFILESW:.c=.o))
|
||||||
|
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ INCLUDES+= -Iext \
|
|||||||
|
|
||||||
|
|
||||||
# Stack selection / parameters
|
# Stack selection / parameters
|
||||||
|
|
||||||
# lwIP debug
|
# lwIP debug
|
||||||
ifeq ($(SDK_LWIP_DEBUG),1)
|
ifeq ($(SDK_LWIP_DEBUG),1)
|
||||||
LWIP_FLAGS+=SDK_LWIP_DEBUG=1
|
LWIP_FLAGS+=SDK_LWIP_DEBUG=1
|
||||||
@@ -112,17 +113,17 @@ endif
|
|||||||
|
|
||||||
# TCP protocol version
|
# TCP protocol version
|
||||||
ifeq ($(SDK_IPV4),1)
|
ifeq ($(SDK_IPV4),1)
|
||||||
|
LWIP_FLAGS+=SDK_IPV4=1
|
||||||
STACK_FLAGS+=-DSDK_IPV4
|
STACK_FLAGS+=-DSDK_IPV4
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(SDK_IPV6),1)
|
ifeq ($(SDK_IPV6),1)
|
||||||
|
LWIP_FLAGS+=SDK_IPV6=1
|
||||||
STACK_FLAGS+=-DSDK_IPV6
|
STACK_FLAGS+=-DSDK_IPV6
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Debug output for the SDK
|
# Debug output for the SDK
|
||||||
# Specific levels can be controlled in src/SDK_Debug.h
|
# Specific levels can be controlled in src/SDK_Debug.h
|
||||||
ifeq ($(SDK_DEBUG),1)
|
ifeq ($(SDK_DEBUG),1)
|
||||||
@@ -175,8 +176,8 @@ linux_intercept:
|
|||||||
cd src ; gcc $(DEFS) $(INCLUDES) -g -O2 -Wall -std=c99 -fPIC -DVERBOSE -D_GNU_SOURCE -DSDK_INTERCEPT -nostdlib -nostdlib -shared -o ../$(INTERCEPT) SDK_Sockets.c SDK_Intercept.c SDK_RPC.c -ldl
|
cd src ; gcc $(DEFS) $(INCLUDES) -g -O2 -Wall -std=c99 -fPIC -DVERBOSE -D_GNU_SOURCE -DSDK_INTERCEPT -nostdlib -nostdlib -shared -o ../$(INTERCEPT) SDK_Sockets.c SDK_Intercept.c SDK_RPC.c -ldl
|
||||||
|
|
||||||
# Build only the SDK service
|
# Build only the SDK service
|
||||||
linux_sdk_service: $(OBJS)
|
linux_sdk_service: pico lwip $(OBJS)
|
||||||
$(CXX) $(CXXFLAGS) $(LDFLAGS) $(STACK_FLAGS) $(DEFS) $(INCLUDES) -DSDK -DZT_ONE_NO_ROOT_CHECK -o $(SDK_SERVICE) $(OBJS) $(ZT1)/service/OneService.cpp src/SDK_EthernetTap.cpp src/SDK_pico.cpp src/SDK_Proxy.cpp $(ZT1)/one.cpp src/SDK_RPC.c $(LDLIBS) -ldl
|
$(CXX) $(CXXFLAGS) $(LDFLAGS) $(STACK_FLAGS) $(DEFS) $(INCLUDES) -DSDK -DZT_ONE_NO_ROOT_CHECK -o $(SDK_SERVICE) $(OBJS) $(ZT1)/service/OneService.cpp src/SDK_EthernetTap.cpp src/SDK_Proxy.cpp $(ZT1)/one.cpp src/SDK_RPC.c $(LDLIBS) -ldl
|
||||||
ln -sf $(SDK_SERVICE_NAME) $(BUILD)/zerotier-cli
|
ln -sf $(SDK_SERVICE_NAME) $(BUILD)/zerotier-cli
|
||||||
ln -sf $(SDK_SERVICE_NAME) $(BUILD)/zerotier-idtool
|
ln -sf $(SDK_SERVICE_NAME) $(BUILD)/zerotier-idtool
|
||||||
|
|
||||||
|
|||||||
@@ -42,8 +42,9 @@
|
|||||||
#include "SDK_Debug.h"
|
#include "SDK_Debug.h"
|
||||||
|
|
||||||
#if defined(SDK_LWIP)
|
#if defined(SDK_LWIP)
|
||||||
#include "SDK_lwip.hpp"
|
#include "SDK_lwIP.hpp"
|
||||||
#elif defined(SDK_PICOTCP)
|
#elif defined(SDK_PICOTCP)
|
||||||
|
#include "SDK_picoTCP.hpp"
|
||||||
#include "pico_stack.h"
|
#include "pico_stack.h"
|
||||||
#include "pico_ipv4.h"
|
#include "pico_ipv4.h"
|
||||||
#include "pico_icmp4.h"
|
#include "pico_icmp4.h"
|
||||||
@@ -54,8 +55,6 @@
|
|||||||
#include "SDK_jip.hpp"
|
#include "SDK_jip.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "SDK_pico.hpp"
|
|
||||||
|
|
||||||
#include "Utils.hpp"
|
#include "Utils.hpp"
|
||||||
#include "OSUtils.hpp"
|
#include "OSUtils.hpp"
|
||||||
#include "Constants.hpp"
|
#include "Constants.hpp"
|
||||||
@@ -620,6 +619,9 @@ namespace ZeroTier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
-------------------------------- Tap Service ----------------------------------
|
||||||
|
------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
static err_t tapif_init(struct netif *netif)
|
static err_t tapif_init(struct netif *netif)
|
||||||
{
|
{
|
||||||
@@ -693,32 +695,29 @@ NetconEthernetTap::NetconEthernetTap(
|
|||||||
#if defined(SDK_LWIP)
|
#if defined(SDK_LWIP)
|
||||||
Utils::snprintf(stackPath,sizeof(stackPath),"%s%sliblwip.so",homePath,ZT_PATH_SEPARATOR_S);
|
Utils::snprintf(stackPath,sizeof(stackPath),"%s%sliblwip.so",homePath,ZT_PATH_SEPARATOR_S);
|
||||||
lwipstack = new lwIP_stack(stackPath);
|
lwipstack = new lwIP_stack(stackPath);
|
||||||
|
if(!lwipstack) {
|
||||||
|
DEBUG_ERROR("unable to dynamically load a new instance of (%s) (searched ZeroTier home path)", stackPath);
|
||||||
|
throw std::runtime_error("");
|
||||||
|
}
|
||||||
|
lwipstack->__lwip_init();
|
||||||
#elif defined(SDK_PICOTCP)
|
#elif defined(SDK_PICOTCP)
|
||||||
Utils::snprintf(stackPath,sizeof(stackPath),"%s%slibpicotcp.so",homePath,ZT_PATH_SEPARATOR_S);
|
Utils::snprintf(stackPath,sizeof(stackPath),"%s%slibpicotcp.so",homePath,ZT_PATH_SEPARATOR_S);
|
||||||
picostack = new picoTCP_stack(stackPath);
|
picostack = new picoTCP_stack(stackPath);
|
||||||
|
if(!picostack) {
|
||||||
|
DEBUG_ERROR("unable to dynamically load a new instance of (%s) (searched ZeroTier home path)", stackPath);
|
||||||
|
throw std::runtime_error("");
|
||||||
|
}
|
||||||
|
picostack->__pico_stack_init();
|
||||||
#elif defined(SDK_JIP)
|
#elif defined(SDK_JIP)
|
||||||
Utils::snprintf(stackPath,sizeof(stackPath),"%s%slibjip.so",homePath,ZT_PATH_SEPARATOR_S);
|
Utils::snprintf(stackPath,sizeof(stackPath),"%s%slibjip.so",homePath,ZT_PATH_SEPARATOR_S);
|
||||||
jipstack = new jip_stack(stackPath);
|
jipstack = new jip_stack(stackPath);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(!lwipstack && !picostack && !jipstack) {
|
|
||||||
DEBUG_ERROR("unable to dynamically load a new instance of (%s) (searched ZeroTier home path)", stackPath);
|
|
||||||
throw std::runtime_error("");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if(lwipstack)
|
|
||||||
lwipstack->__lwip_init();
|
|
||||||
if(picostack)
|
|
||||||
picostack->__pico_stack_init();
|
|
||||||
//if(jipstack)
|
|
||||||
// jipstack->__jip_init();
|
|
||||||
|
|
||||||
_unixListenSocket = _phy.unixListen(sockPath,(void *)this);
|
_unixListenSocket = _phy.unixListen(sockPath,(void *)this);
|
||||||
DEBUG_INFO("tap initialized on: path=%s", sockPath);
|
DEBUG_INFO("tap initialized on: path=%s", sockPath);
|
||||||
if (!_unixListenSocket)
|
if (!_unixListenSocket)
|
||||||
DEBUG_ERROR("unable to bind to: path=%s", sockPath);
|
DEBUG_ERROR("unable to bind to: path=%s", sockPath);
|
||||||
_thread = Thread::start(this);
|
_thread = Thread::start(this);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NetconEthernetTap::~NetconEthernetTap()
|
NetconEthernetTap::~NetconEthernetTap()
|
||||||
@@ -728,7 +727,15 @@ NetconEthernetTap::~NetconEthernetTap()
|
|||||||
_phy.whack(); // TODO: Rationale?
|
_phy.whack(); // TODO: Rationale?
|
||||||
Thread::join(_thread);
|
Thread::join(_thread);
|
||||||
_phy.close(_unixListenSocket,false);
|
_phy.close(_unixListenSocket,false);
|
||||||
|
#if defined(SDK_LWIP)
|
||||||
delete lwipstack;
|
delete lwipstack;
|
||||||
|
#endif
|
||||||
|
#if defined(SDK_PICOTCP)
|
||||||
|
delete picostack;
|
||||||
|
#endif
|
||||||
|
#if defined(SDK_JIP)
|
||||||
|
delete jipstack;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetconEthernetTap::setEnabled(bool en)
|
void NetconEthernetTap::setEnabled(bool en)
|
||||||
@@ -743,69 +750,69 @@ bool NetconEthernetTap::enabled() const
|
|||||||
|
|
||||||
void NetconEthernetTap::lwIP_init_interface(const InetAddress &ip)
|
void NetconEthernetTap::lwIP_init_interface(const InetAddress &ip)
|
||||||
{
|
{
|
||||||
|
#if defined(SDK_LWIP)
|
||||||
DEBUG_INFO("local_addr=%s", ip.toString().c_str());
|
DEBUG_INFO("local_addr=%s", ip.toString().c_str());
|
||||||
Mutex::Lock _l(_ips_m);
|
Mutex::Lock _l(_ips_m);
|
||||||
|
|
||||||
// SIP-1
|
|
||||||
// Initialize network stack's interface, assign addresses
|
|
||||||
|
|
||||||
if (std::find(_ips.begin(),_ips.end(),ip) == _ips.end()) {
|
if (std::find(_ips.begin(),_ips.end(),ip) == _ips.end()) {
|
||||||
_ips.push_back(ip);
|
_ips.push_back(ip);
|
||||||
std::sort(_ips.begin(),_ips.end());
|
std::sort(_ips.begin(),_ips.end());
|
||||||
|
|
||||||
/*
|
#if defined(SDK_IPV4)
|
||||||
if (ip.isV4()) {
|
if (ip.isV4()) {
|
||||||
DEBUG_INFO("IPV4");
|
DEBUG_INFO("IPV4");
|
||||||
// Set IP
|
// convert address
|
||||||
static ip4_addr ipaddr, netmask, gw;
|
static ip_addr_t ipaddr, netmask, gw;
|
||||||
IP4_ADDR(&gw,127,0,0,1);
|
IP4_ADDR((ip4_addr_t *)&gw,127,0,0,1);
|
||||||
ipaddr.addr = *((u32_t *)ip.rawIpData());
|
((ip4_addr_t *)&ipaddr)->addr = *((u32_t *)ip.rawIpData());
|
||||||
netmask.addr = *((u32_t *)ip.netmask().rawIpData());
|
((ip4_addr_t *)&netmask)->addr = *((u32_t *)ip.netmask().rawIpData());
|
||||||
|
// initialize netif
|
||||||
// Set up the lwip-netif for LWIP's sake
|
|
||||||
lwipstack->__netif_add(&interface,&ipaddr, &netmask, &gw, NULL, tapif_init, lwipstack->_ethernet_input);
|
lwipstack->__netif_add(&interface,&ipaddr, &netmask, &gw, NULL, tapif_init, lwipstack->_ethernet_input);
|
||||||
interface.state = this;
|
interface.state = this;
|
||||||
interface.output = lwipstack->_etharp_output;
|
interface.output = lwipstack->_etharp_output;
|
||||||
_mac.copyTo(interface.hwaddr, 6);
|
_mac.copyTo(interface.hwaddr, 6);
|
||||||
interface.mtu = _mtu;
|
interface.mtu = _mtu;
|
||||||
interface.name[0] = 't';
|
interface.name[0] = 'l';
|
||||||
interface.name[1] = 'p';
|
interface.name[1] = 'w';
|
||||||
|
interface.name[2] = '4';
|
||||||
interface.linkoutput = low_level_output;
|
interface.linkoutput = low_level_output;
|
||||||
interface.hwaddr_len = 6;
|
interface.hwaddr_len = 6;
|
||||||
interface.flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_IGMP;
|
interface.flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_IGMP;
|
||||||
lwipstack->__netif_set_default(&interface);
|
lwipstack->__netif_set_default(&interface);
|
||||||
lwipstack->__netif_set_up(&interface);
|
lwipstack->__netif_set_up(&interface);
|
||||||
}
|
}
|
||||||
*/
|
#endif
|
||||||
/*
|
|
||||||
if(ip.isV6())
|
|
||||||
{
|
|
||||||
DEBUG_INFO("IPV6");
|
|
||||||
static ip6_addr_t addr6;
|
|
||||||
IP6_ADDR2(&addr6, 0xfd56, 0x5799, 0xd8f6, 0x1238, 0x8c99, 0x93b4, 0x9d8e, 0x24f6);
|
|
||||||
|
|
||||||
|
#if defined(SDK_IPV6)
|
||||||
|
if(ip.isV6()) {
|
||||||
|
DEBUG_INFO("IPV6");
|
||||||
|
// convert address
|
||||||
|
static ip6_addr_t addr6;
|
||||||
|
struct sockaddr_in6 in6;
|
||||||
|
memcpy(in6.sin6_addr.s6_addr,ip.rawIpData(),16);
|
||||||
|
in6_to_ip6((ip6_addr *)&addr6, &in6);
|
||||||
|
// initialize netif
|
||||||
interface6.mtu = _mtu;
|
interface6.mtu = _mtu;
|
||||||
interface6.name[0] = 't';
|
interface6.name[0] = 'l';
|
||||||
interface6.name[1] = 'p';
|
interface6.name[1] = 'w';
|
||||||
|
interface6.name[2] = '6';
|
||||||
interface6.hwaddr_len = 6;
|
interface6.hwaddr_len = 6;
|
||||||
interface6.linkoutput = low_level_output;
|
interface6.linkoutput = low_level_output;
|
||||||
interface6.ip6_autoconfig_enabled = 1;
|
interface6.ip6_autoconfig_enabled = 1;
|
||||||
|
|
||||||
_mac.copyTo(interface6.hwaddr, interface6.hwaddr_len);
|
_mac.copyTo(interface6.hwaddr, interface6.hwaddr_len);
|
||||||
lwipstack->__netif_create_ip6_linklocal_address(&interface6, 1);
|
lwipstack->__netif_create_ip6_linklocal_address(&interface6, 1);
|
||||||
lwipstack->__netif_add(&interface6, NULL, tapif_init, lwipstack->_ethernet_input);
|
lwipstack->__netif_add(&interface6, NULL, tapif_init, lwipstack->_ethernet_input);
|
||||||
lwipstack->__netif_set_default(&interface6);
|
lwipstack->__netif_set_default(&interface6);
|
||||||
lwipstack->__netif_set_up(&interface6);
|
lwipstack->__netif_set_up(&interface6);
|
||||||
|
|
||||||
netif_ip6_addr_set_state(&interface6, 1, IP6_ADDR_TENTATIVE);
|
netif_ip6_addr_set_state(&interface6, 1, IP6_ADDR_TENTATIVE);
|
||||||
ip6_addr_copy(ip_2_ip6(interface6.ip6_addr[1]), addr6);
|
ip6_addr_copy(ip_2_ip6(interface6.ip6_addr[1]), addr6);
|
||||||
|
|
||||||
interface6.output_ip6 = lwipstack->_ethip6_output;
|
interface6.output_ip6 = lwipstack->_ethip6_output;
|
||||||
interface6.state = this;
|
interface6.state = this;
|
||||||
interface6.flags = NETIF_FLAG_LINK_UP | NETIF_FLAG_UP;
|
interface6.flags = NETIF_FLAG_LINK_UP | NETIF_FLAG_UP;
|
||||||
}
|
}
|
||||||
*/
|
#endif
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetconEthernetTap::jip_init_interface(const InetAddress &ip)
|
void NetconEthernetTap::jip_init_interface(const InetAddress &ip)
|
||||||
@@ -816,8 +823,8 @@ void NetconEthernetTap::jip_init_interface(const InetAddress &ip)
|
|||||||
bool NetconEthernetTap::addIp(const InetAddress &ip)
|
bool NetconEthernetTap::addIp(const InetAddress &ip)
|
||||||
{
|
{
|
||||||
picotap = this;
|
picotap = this;
|
||||||
// SIP-3
|
// SIP-1
|
||||||
// Initialize a new interface in the stack, assign an address
|
// Initialize network stack's interface, assign addresses
|
||||||
#if defined(SDK_LWIP)
|
#if defined(SDK_LWIP)
|
||||||
lwIP_init_interface(ip);
|
lwIP_init_interface(ip);
|
||||||
#elif defined(SDK_PICOTCP)
|
#elif defined(SDK_PICOTCP)
|
||||||
@@ -850,6 +857,7 @@ std::vector<InetAddress> NetconEthernetTap::ips() const
|
|||||||
|
|
||||||
void NetconEthernetTap::lwIP_rx(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len)
|
void NetconEthernetTap::lwIP_rx(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len)
|
||||||
{
|
{
|
||||||
|
#if defined(SDK_LWIP)
|
||||||
DEBUG_INFO();
|
DEBUG_INFO();
|
||||||
struct pbuf *p,*q;
|
struct pbuf *p,*q;
|
||||||
if (!_enabled)
|
if (!_enabled)
|
||||||
@@ -883,10 +891,18 @@ void NetconEthernetTap::lwIP_rx(const MAC &from,const MAC &to,unsigned int ether
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
#if defined(SDK_IPV6)
|
||||||
if(interface6.input(p, &interface6) != ERR_OK) {
|
if(interface6.input(p, &interface6) != ERR_OK) {
|
||||||
DEBUG_ERROR("error while RX of packet (netif->input)");
|
DEBUG_ERROR("error while feeding frame into stack interface6");
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(SDK_IPV4)
|
||||||
|
if(interface.input(p, &interface) != ERR_OK) {
|
||||||
|
DEBUG_ERROR("error while feeding frame into stack interface");
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -942,6 +958,7 @@ void NetconEthernetTap::scanMulticastGroups(std::vector<MulticastGroup> &added,s
|
|||||||
|
|
||||||
void NetconEthernetTap::lwIP_loop()
|
void NetconEthernetTap::lwIP_loop()
|
||||||
{
|
{
|
||||||
|
#if defined(SDK_LWIP)
|
||||||
DEBUG_INFO();
|
DEBUG_INFO();
|
||||||
uint64_t prev_tcp_time = 0, prev_status_time = 0, prev_discovery_time = 0;
|
uint64_t prev_tcp_time = 0, prev_status_time = 0, prev_discovery_time = 0;
|
||||||
// Main timer loop
|
// Main timer loop
|
||||||
@@ -1003,21 +1020,19 @@ void NetconEthernetTap::lwIP_loop()
|
|||||||
}
|
}
|
||||||
if (since_discovery >= DISCOVERY_INTERVAL) {
|
if (since_discovery >= DISCOVERY_INTERVAL) {
|
||||||
prev_discovery_time = now;
|
prev_discovery_time = now;
|
||||||
//#if defined(LWIP_IPV4)
|
#if defined(SDK_IPV4)
|
||||||
// DEBUG_EXTRA("etharp_tmr");
|
lwipstack->__etharp_tmr();
|
||||||
// lwipstack->__etharp_tmr();
|
#endif
|
||||||
//#endif
|
#if defined(SDK_IPV6)
|
||||||
#if defined(LWIP_IPV6)
|
|
||||||
DEBUG_EXTRA("nd6_tmr");
|
|
||||||
lwipstack->__nd6_tmr();
|
lwipstack->__nd6_tmr();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
discovery_remaining = DISCOVERY_INTERVAL - since_discovery;
|
discovery_remaining = DISCOVERY_INTERVAL - since_discovery;
|
||||||
}
|
}
|
||||||
_phy.poll((unsigned long)std::min(tcp_remaining,discovery_remaining));
|
_phy.poll((unsigned long)std::min(tcp_remaining,discovery_remaining));
|
||||||
}
|
}
|
||||||
lwipstack->close();
|
lwipstack->close();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetconEthernetTap::jip_loop()
|
void NetconEthernetTap::jip_loop()
|
||||||
@@ -1397,6 +1412,8 @@ void NetconEthernetTap::unloadRPC(void *data, pid_t &pid, pid_t &tid,
|
|||||||
--------------------------------- LWIP callbacks -------------------------------
|
--------------------------------- LWIP callbacks -------------------------------
|
||||||
------------------------------------------------------------------------------*/
|
------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#if defined(SDK_LWIP)
|
||||||
|
|
||||||
err_t NetconEthernetTap::nc_accept(void *arg, struct tcp_pcb *newPCB, err_t err)
|
err_t NetconEthernetTap::nc_accept(void *arg, struct tcp_pcb *newPCB, err_t err)
|
||||||
{
|
{
|
||||||
DEBUG_ATTN("pcb=%p", (void*)&newPCB);
|
DEBUG_ATTN("pcb=%p", (void*)&newPCB);
|
||||||
@@ -1670,6 +1687,8 @@ void NetconEthernetTap::nc_err(void *arg, err_t err)
|
|||||||
l->tap->closeConnection(l->conn);
|
l->tap->closeConnection(l->conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // SDK_LWIP
|
||||||
|
|
||||||
/*------------------------------------------------------------------------------
|
/*------------------------------------------------------------------------------
|
||||||
----------------------------- RPC Handler functions ----------------------------
|
----------------------------- RPC Handler functions ----------------------------
|
||||||
------------------------------------------------------------------------------*/
|
------------------------------------------------------------------------------*/
|
||||||
@@ -1713,13 +1732,6 @@ void NetconEthernetTap::handleBind(PhySocket *sock, PhySocket *rpcSock, void **u
|
|||||||
|
|
||||||
// lwIP
|
// lwIP
|
||||||
#if defined(SDK_LWIP)
|
#if defined(SDK_LWIP)
|
||||||
struct sockaddr_in *rawAddr = (struct sockaddr_in *) &bind_rpc->addr;
|
|
||||||
int err, port = lwipstack->__lwip_ntohs(rawAddr->sin_port);
|
|
||||||
ip_addr_t connAddr;
|
|
||||||
|
|
||||||
static ip6_addr_t ba;
|
|
||||||
IP6_ADDR2(&ba, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0);
|
|
||||||
|
|
||||||
if(!_ips.size()) {
|
if(!_ips.size()) {
|
||||||
// We haven't been given an address yet. Binding at this stage is premature
|
// We haven't been given an address yet. Binding at this stage is premature
|
||||||
DEBUG_ERROR("cannot bind yet. ZT address hasn't been provided");
|
DEBUG_ERROR("cannot bind yet. ZT address hasn't been provided");
|
||||||
@@ -1727,19 +1739,34 @@ void NetconEthernetTap::handleBind(PhySocket *sock, PhySocket *rpcSock, void **u
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ip_addr_t ba;
|
||||||
char addrstr[INET6_ADDRSTRLEN];
|
char addrstr[INET6_ADDRSTRLEN];
|
||||||
|
struct sockaddr_in6 *rawAddr = (struct sockaddr_in6 *) &bind_rpc->addr;
|
||||||
struct sockaddr *addr = (struct sockaddr*)rawAddr;
|
struct sockaddr *addr = (struct sockaddr*)rawAddr;
|
||||||
|
int err, port = lwipstack->__lwip_ntohs(rawAddr->sin6_port);
|
||||||
|
|
||||||
|
// ipv4
|
||||||
|
#if defined(SDK_IPV4)
|
||||||
|
//ip4_addr_t ba;
|
||||||
if(addr->sa_family == AF_INET) {
|
if(addr->sa_family == AF_INET) {
|
||||||
struct sockaddr_in *connaddr = (struct sockaddr_in *)addr;
|
struct sockaddr_in *connaddr = (struct sockaddr_in *)addr;
|
||||||
inet_ntop(AF_INET, &(connaddr->sin_addr), addrstr, INET_ADDRSTRLEN);
|
inet_ntop(AF_INET, &(connaddr->sin_addr), addrstr, INET_ADDRSTRLEN);
|
||||||
sprintf(addrstr, "%s:%d", addrstr, lwipstack->__lwip_ntohs(connaddr->sin_port));
|
sprintf(addrstr, "%s:%d", addrstr, lwipstack->__lwip_ntohs(connaddr->sin_port));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ipv6
|
||||||
|
#if defined(SDK_IPV6)
|
||||||
|
//ip6_addr_t ba;
|
||||||
|
struct sockaddr_in6 *in6 = (struct sockaddr_in6*)&bind_rpc->addr;
|
||||||
|
in6_to_ip6((ip6_addr *)&ba, in6);
|
||||||
|
|
||||||
if(addr->sa_family == AF_INET6) {
|
if(addr->sa_family == AF_INET6) {
|
||||||
struct sockaddr_in6 *connaddr6 = (struct sockaddr_in6 *)addr;
|
struct sockaddr_in6 *connaddr6 = (struct sockaddr_in6 *)addr;
|
||||||
inet_ntop(AF_INET6, &(connaddr6->sin6_addr), addrstr, INET6_ADDRSTRLEN);
|
inet_ntop(AF_INET6, &(connaddr6->sin6_addr), addrstr, INET6_ADDRSTRLEN);
|
||||||
sprintf(addrstr, "%s:%d", addrstr, lwipstack->__lwip_ntohs(connaddr6->sin6_port));
|
sprintf(addrstr, "%s:%d", addrstr, lwipstack->__lwip_ntohs(connaddr6->sin6_port));
|
||||||
}
|
}
|
||||||
DEBUG_INFO("addr=%s", addrstr);
|
#endif
|
||||||
|
|
||||||
Connection *conn = getConnection(sock);
|
Connection *conn = getConnection(sock);
|
||||||
DEBUG_ATTN(" sock=%p, fd=%d, port=%d", (void*)&sock, bind_rpc->fd, port);
|
DEBUG_ATTN(" sock=%p, fd=%d, port=%d", (void*)&sock, bind_rpc->fd, port);
|
||||||
@@ -1748,7 +1775,7 @@ void NetconEthernetTap::handleBind(PhySocket *sock, PhySocket *rpcSock, void **u
|
|||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
err = lwipstack->__udp_bind(conn->UDP_pcb, NULL, port);
|
err = lwipstack->__udp_bind(conn->UDP_pcb, NULL, port);
|
||||||
#else
|
#else
|
||||||
// err = lwipstack->__udp_bind(conn->UDP_pcb, &ba, port);
|
err = lwipstack->__udp_bind(conn->UDP_pcb, (const ip_addr_t *)&ba, port);
|
||||||
#endif
|
#endif
|
||||||
if(err == ERR_USE) // port in use
|
if(err == ERR_USE) // port in use
|
||||||
sendReturnValue(rpcSock, -1, EADDRINUSE);
|
sendReturnValue(rpcSock, -1, EADDRINUSE);
|
||||||
@@ -1764,7 +1791,7 @@ void NetconEthernetTap::handleBind(PhySocket *sock, PhySocket *rpcSock, void **u
|
|||||||
}
|
}
|
||||||
else if (conn->type == SOCK_STREAM) {
|
else if (conn->type == SOCK_STREAM) {
|
||||||
if(conn->TCP_pcb->state == CLOSED){
|
if(conn->TCP_pcb->state == CLOSED){
|
||||||
err = lwipstack->__tcp_bind(conn->TCP_pcb, &ba, port);
|
err = lwipstack->__tcp_bind(conn->TCP_pcb, (const ip_addr_t *)&ba, port);
|
||||||
if(err != ERR_OK) {
|
if(err != ERR_OK) {
|
||||||
DEBUG_ERROR("err=%d", err);
|
DEBUG_ERROR("err=%d", err);
|
||||||
if(err == ERR_USE)
|
if(err == ERR_USE)
|
||||||
@@ -1840,6 +1867,7 @@ void NetconEthernetTap::handleListen(PhySocket *sock, PhySocket *rpcSock, void *
|
|||||||
|
|
||||||
Connection * NetconEthernetTap::handleSocketProxy(PhySocket *sock, int socket_type)
|
Connection * NetconEthernetTap::handleSocketProxy(PhySocket *sock, int socket_type)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
Connection *conn = getConnection(sock);
|
Connection *conn = getConnection(sock);
|
||||||
if(!conn){
|
if(!conn){
|
||||||
DEBUG_ERROR("unable to locate Connection object for this PhySocket sock=%p", (void*)&sock);
|
DEBUG_ERROR("unable to locate Connection object for this PhySocket sock=%p", (void*)&sock);
|
||||||
@@ -1869,6 +1897,7 @@ Connection * NetconEthernetTap::handleSocketProxy(PhySocket *sock, int socket_ty
|
|||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
DEBUG_ERROR(" memory not available for new PCB");
|
DEBUG_ERROR(" memory not available for new PCB");
|
||||||
|
*/
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1919,6 +1948,7 @@ Connection * NetconEthernetTap::handleSocket(PhySocket *sock, void **uptr, struc
|
|||||||
|
|
||||||
int NetconEthernetTap::handleConnectProxy(PhySocket *sock, struct sockaddr_in *rawAddr)
|
int NetconEthernetTap::handleConnectProxy(PhySocket *sock, struct sockaddr_in *rawAddr)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
DEBUG_ATTN("sock=%p", (void*)&sock);
|
DEBUG_ATTN("sock=%p", (void*)&sock);
|
||||||
Mutex::Lock _l(_tcpconns_m);
|
Mutex::Lock _l(_tcpconns_m);
|
||||||
int port = rawAddr->sin_port;
|
int port = rawAddr->sin_port;
|
||||||
@@ -1977,17 +2007,16 @@ int NetconEthernetTap::handleConnectProxy(PhySocket *sock, struct sockaddr_in *r
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(err == ERR_MEM) {
|
if(err == ERR_MEM) {
|
||||||
/* Can occur for the following reasons: tcp_enqueue_flags()
|
// Can occur for the following reasons: tcp_enqueue_flags()
|
||||||
|
|
||||||
1) tcp_enqueue_flags is always called with either SYN or FIN in flags.
|
// 1) tcp_enqueue_flags is always called with either SYN or FIN in flags.
|
||||||
We need one available snd_buf byte to do that.
|
// We need one available snd_buf byte to do that.
|
||||||
This means we can't send FIN while snd_buf==0. A better fix would be to
|
// This means we can't send FIN while snd_buf==0. A better fix would be to
|
||||||
not include SYN and FIN sequence numbers in the snd_buf count.
|
// not include SYN and FIN sequence numbers in the snd_buf count.
|
||||||
|
|
||||||
2) Cannot allocate new pbuf
|
// 2) Cannot allocate new pbuf
|
||||||
3) Cannot allocate new TCP segment
|
// 3) Cannot allocate new TCP segment
|
||||||
|
|
||||||
*/
|
|
||||||
errno = EAGAIN; // TODO: Doesn't describe the problem well, but closest match
|
errno = EAGAIN; // TODO: Doesn't describe the problem well, but closest match
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -2010,6 +2039,7 @@ int NetconEthernetTap::handleConnectProxy(PhySocket *sock, struct sockaddr_in *r
|
|||||||
errno = EBADF;
|
errno = EBADF;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,8 +48,8 @@
|
|||||||
|
|
||||||
#include "SDK_defs.h"
|
#include "SDK_defs.h"
|
||||||
#include "SDK_RPC.h"
|
#include "SDK_RPC.h"
|
||||||
#include "SDK_lwip.hpp"
|
#include "SDK_lwIP.hpp"
|
||||||
#include "SDK_pico.hpp"
|
#include "SDK_picoTCP.hpp"
|
||||||
#include "SDK_jip.hpp"
|
#include "SDK_jip.hpp"
|
||||||
|
|
||||||
#include "pico_protocol.h"
|
#include "pico_protocol.h"
|
||||||
@@ -138,21 +138,6 @@ namespace ZeroTier {
|
|||||||
|
|
||||||
// SIP-
|
// SIP-
|
||||||
|
|
||||||
struct pico_device picodev;
|
|
||||||
unsigned char pico_frame_rxbuf[MAX_PICO_FRAME_RX_BUF_SZ];
|
|
||||||
int pico_frame_rxbuf_tot = 0;
|
|
||||||
Mutex _pico_frame_rxbuf_m;
|
|
||||||
|
|
||||||
void lwIP_loop();
|
|
||||||
void jip_loop();
|
|
||||||
|
|
||||||
// rx
|
|
||||||
void lwIP_rx(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len);
|
|
||||||
void jip_rx(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len);
|
|
||||||
|
|
||||||
void lwIP_init_interface(const InetAddress &ip);
|
|
||||||
void jip_init_interface(const InetAddress &ip);
|
|
||||||
|
|
||||||
void threadMain()
|
void threadMain()
|
||||||
throw();
|
throw();
|
||||||
|
|
||||||
@@ -174,10 +159,27 @@ namespace ZeroTier {
|
|||||||
|
|
||||||
std::string _homePath;
|
std::string _homePath;
|
||||||
|
|
||||||
|
// lwIP
|
||||||
|
void lwIP_loop();
|
||||||
|
void lwIP_rx(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len);
|
||||||
|
void lwIP_init_interface(const InetAddress &ip);
|
||||||
|
#if defined(SDK_LWIP)
|
||||||
lwIP_stack *lwipstack;
|
lwIP_stack *lwipstack;
|
||||||
picoTCP_stack *picostack;
|
#endif
|
||||||
|
|
||||||
|
// jip
|
||||||
|
void jip_loop();
|
||||||
|
void jip_rx(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len);
|
||||||
|
void jip_init_interface(const InetAddress &ip);
|
||||||
jip_stack *jipstack;
|
jip_stack *jipstack;
|
||||||
|
|
||||||
|
// picoTCP
|
||||||
|
struct pico_device picodev;
|
||||||
|
unsigned char pico_frame_rxbuf[MAX_PICO_FRAME_RX_BUF_SZ];
|
||||||
|
int pico_frame_rxbuf_tot = 0;
|
||||||
|
Mutex _pico_frame_rxbuf_m;
|
||||||
|
picoTCP_stack *picostack;
|
||||||
|
|
||||||
// LWIP callbacks
|
// LWIP callbacks
|
||||||
// NOTE: these are called from within LWIP, meaning that lwipstack->_lock is ALREADY
|
// NOTE: these are called from within LWIP, meaning that lwipstack->_lock is ALREADY
|
||||||
// locked in this case!
|
// locked in this case!
|
||||||
|
|||||||
@@ -1,384 +0,0 @@
|
|||||||
/*
|
|
||||||
* ZeroTier One - Network Virtualization Everywhere
|
|
||||||
* Copyright (C) 2011-2015 ZeroTier, Inc.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* --
|
|
||||||
*
|
|
||||||
* ZeroTier may be used and distributed under the terms of the GPLv3, which
|
|
||||||
* are available at: http://www.gnu.org/licenses/gpl-3.0.html
|
|
||||||
*
|
|
||||||
* If you would like to embed ZeroTier into a commercial application or
|
|
||||||
* redistribute it in a modified binary form, please contact ZeroTier Networks
|
|
||||||
* LLC. Start here: http://www.zerotier.com/
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef SDK_LWIPSTACK_H
|
|
||||||
#define SDK_LWIPSTACK_H
|
|
||||||
|
|
||||||
#include "lwip/mem.h"
|
|
||||||
#include "lwip/pbuf.h"
|
|
||||||
#include "lwip/ip_addr.h"
|
|
||||||
#include "lwip/netif.h"
|
|
||||||
#include "lwip/init.h"
|
|
||||||
#include "lwip/udp.h"
|
|
||||||
|
|
||||||
#include "Mutex.hpp"
|
|
||||||
#include "OSUtils.hpp"
|
|
||||||
#include "SDK_Debug.h"
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <dlfcn.h>
|
|
||||||
|
|
||||||
#ifdef D_GNU_SOURCE
|
|
||||||
#define _GNU_SOURCE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//typedef ip_addr ip_addr_t;
|
|
||||||
struct tcp_pcb;
|
|
||||||
|
|
||||||
// lwip General Stack API
|
|
||||||
#define PBUF_FREE_SIG struct pbuf *p
|
|
||||||
#define PBUF_ALLOC_SIG pbuf_layer layer, u16_t length, pbuf_type type
|
|
||||||
#define LWIP_HTONS_SIG u16_t x
|
|
||||||
#define LWIP_NTOHS_SIG u16_t x
|
|
||||||
#define IPADDR_NTOA_SIG const ip_addr_t *addr
|
|
||||||
|
|
||||||
#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 ETHARP_OUTPUT_SIG struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr
|
|
||||||
#define NETIF_ADD_SIG struct netif *netif, void *state, netif_init_fn init, netif_input_fn input
|
|
||||||
//#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 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
|
|
||||||
#define NETIF_SET_UP_SIG struct netif *netif
|
|
||||||
#define NETIF_POLL_SIG struct netif *netif
|
|
||||||
|
|
||||||
// lwIP UDP API
|
|
||||||
#define UDP_NEW_SIG void
|
|
||||||
#define UDP_CONNECT_SIG struct udp_pcb * pcb, ip_addr_t * ipaddr, u16_t port
|
|
||||||
#define UDP_SEND_SIG struct udp_pcb * pcb, struct pbuf * p
|
|
||||||
#define UDP_SENDTO_SIG struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *dst_ip, u16_t dst_port
|
|
||||||
#define UDP_RECV_SIG struct udp_pcb * pcb, void (* recv)(void * arg, struct udp_pcb * upcb, struct pbuf * p, ip_addr_t * addr, u16_t port), void * recv_arg
|
|
||||||
#define UDP_RECVED_SIG struct udp_pcb * pcb, u16_t len
|
|
||||||
#define UDP_BIND_SIG struct udp_pcb * pcb, const ip_addr_t * ipaddr, u16_t port
|
|
||||||
#define UDP_REMOVE_SIG struct udp_pcb *pcb
|
|
||||||
|
|
||||||
// lwIP TCP API
|
|
||||||
#define TCP_WRITE_SIG struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t apiflags
|
|
||||||
#define TCP_SENT_SIG struct tcp_pcb * pcb, err_t (* sent)(void * arg, struct tcp_pcb * tpcb, u16_t len)
|
|
||||||
#define TCP_NEW_SIG void
|
|
||||||
#define TCP_RECV_SIG struct tcp_pcb * pcb, err_t (* recv)(void * arg, struct tcp_pcb * tpcb, struct pbuf * p, err_t err)
|
|
||||||
#define TCP_RECVED_SIG struct tcp_pcb * pcb, u16_t len
|
|
||||||
#define TCP_SNDBUF_SIG struct tcp_pcb * pcb
|
|
||||||
#define TCP_CONNECT_SIG struct tcp_pcb * pcb, ip_addr_t * ipaddr, u16_t port, err_t (* connected)(void * arg, struct tcp_pcb * tpcb, err_t err)
|
|
||||||
#define TCP_RECV_SIG struct tcp_pcb * pcb, err_t (* recv)(void * arg, struct tcp_pcb * tpcb, struct pbuf * p, err_t err)
|
|
||||||
#define TCP_ERR_SIG struct tcp_pcb * pcb, void (* err)(void * arg, err_t err)
|
|
||||||
#define TCP_POLL_SIG struct tcp_pcb * pcb, err_t (* poll)(void * arg, struct tcp_pcb * tpcb), u8_t interval
|
|
||||||
#define TCP_ARG_SIG struct tcp_pcb * pcb, void * arg
|
|
||||||
#define TCP_CLOSE_SIG struct tcp_pcb * pcb
|
|
||||||
#define TCP_ABORT_SIG struct tcp_pcb * pcb
|
|
||||||
#define TCP_OUTPUT_SIG struct tcp_pcb * pcb
|
|
||||||
#define TCP_ACCEPT_SIG struct tcp_pcb * pcb, err_t (* accept)(void * arg, struct tcp_pcb * newpcb, err_t err)
|
|
||||||
#define TCP_LISTEN_SIG struct tcp_pcb * pcb
|
|
||||||
#define TCP_LISTEN_WITH_BACKLOG_SIG struct tcp_pcb * pcb, u8_t backlog
|
|
||||||
#define TCP_BIND_SIG struct tcp_pcb * pcb, const ip_addr_t * ipaddr, u16_t port
|
|
||||||
#define TCP_INPUT_SIG struct pbuf *p, struct netif *inp
|
|
||||||
|
|
||||||
void dwr(int level, const char *fmt, ... );
|
|
||||||
|
|
||||||
#define NETIF_IP6_ADDR_SET_STATE_SIG struct netif* netif, s8_t addr_idx, u8_t state
|
|
||||||
#define NETIF_LOOPIF_INIT_SIG struct netif *netif
|
|
||||||
#define NETIF_CREATE_IP6_LINKLOCAL_ADDRESS_SIG struct netif *netif, u8_t from_mac_48bit
|
|
||||||
//#define NETIF_SET_ADDR_SIG struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw
|
|
||||||
|
|
||||||
namespace ZeroTier {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads an instance of liblwip.so in a private memory arena
|
|
||||||
*
|
|
||||||
* This uses dlmopen() to load an instance of the LWIP stack into its
|
|
||||||
* own private memory space. This is done to get around the stack's
|
|
||||||
* lack of thread-safety or multi-instance support. The alternative
|
|
||||||
* would be to massively refactor the stack so everything lives in a
|
|
||||||
* state object instead of static memory space.
|
|
||||||
*/
|
|
||||||
class LWIPStack
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
void *_libref;
|
|
||||||
|
|
||||||
void close() {
|
|
||||||
#if defined(__STATIC__LWIP__)
|
|
||||||
return;
|
|
||||||
#elif defined(__DYNAMIC_LWIP__)
|
|
||||||
dlclose(_libref);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void (*_netif_init)(void);
|
|
||||||
void (*_nd6_tmr)(void);
|
|
||||||
void (*_netif_ip6_addr_set_state)(NETIF_IP6_ADDR_SET_STATE_SIG);
|
|
||||||
void (*_netif_loopif_init)(NETIF_LOOPIF_INIT_SIG);
|
|
||||||
void (*_netif_create_ip6_linklocal_address)(NETIF_CREATE_IP6_LINKLOCAL_ADDRESS_SIG);
|
|
||||||
err_t (*_ethip6_output)(ETHIP6_OUTPUT_SIG);
|
|
||||||
// void (*_netif_set_addr)(NETIF_SET_ADDR_SIG);
|
|
||||||
|
|
||||||
void (*_lwip_init)();
|
|
||||||
err_t (*_tcp_write)(TCP_WRITE_SIG);
|
|
||||||
void (*_tcp_sent)(TCP_SENT_SIG);
|
|
||||||
struct tcp_pcb * (*_tcp_new)(TCP_NEW_SIG);
|
|
||||||
u16_t (*_tcp_sndbuf)(TCP_SNDBUF_SIG);
|
|
||||||
err_t (*_tcp_connect)(TCP_CONNECT_SIG);
|
|
||||||
|
|
||||||
struct udp_pcb * (*_udp_new)(UDP_NEW_SIG);
|
|
||||||
err_t (*_udp_connect)(UDP_CONNECT_SIG);
|
|
||||||
err_t (*_udp_send)(UDP_SEND_SIG);
|
|
||||||
err_t (*_udp_sendto)(UDP_SENDTO_SIG);
|
|
||||||
void (*_udp_recv)(UDP_RECV_SIG);
|
|
||||||
void (*_udp_recved)(UDP_RECVED_SIG);
|
|
||||||
err_t (*_udp_bind)(UDP_BIND_SIG);
|
|
||||||
void (*_udp_remove)(UDP_REMOVE_SIG);
|
|
||||||
|
|
||||||
void (*_tcp_recv)(TCP_RECV_SIG);
|
|
||||||
void (*_tcp_recved)(TCP_RECVED_SIG);
|
|
||||||
void (*_tcp_err)(TCP_ERR_SIG);
|
|
||||||
void (*_tcp_poll)(TCP_POLL_SIG);
|
|
||||||
void (*_tcp_arg)(TCP_ARG_SIG);
|
|
||||||
err_t (*_tcp_close)(TCP_CLOSE_SIG);
|
|
||||||
void (*_tcp_abort)(TCP_ABORT_SIG);
|
|
||||||
err_t (*_tcp_output)(TCP_OUTPUT_SIG);
|
|
||||||
void (*_tcp_accept)(TCP_ACCEPT_SIG);
|
|
||||||
struct tcp_pcb * (*_tcp_listen)(TCP_LISTEN_SIG);
|
|
||||||
struct tcp_pcb * (*_tcp_listen_with_backlog)(TCP_LISTEN_WITH_BACKLOG_SIG);
|
|
||||||
err_t (*_tcp_bind)(TCP_BIND_SIG);
|
|
||||||
void (*_etharp_tmr)(void);
|
|
||||||
void (*_tcp_tmr)(void);
|
|
||||||
u8_t (*_pbuf_free)(PBUF_FREE_SIG);
|
|
||||||
struct pbuf * (*_pbuf_alloc)(PBUF_ALLOC_SIG);
|
|
||||||
u16_t (*_lwip_htons)(LWIP_HTONS_SIG);
|
|
||||||
u16_t (*_lwip_ntohs)(LWIP_NTOHS_SIG);
|
|
||||||
char* (*_ipaddr_ntoa)(IPADDR_NTOA_SIG);
|
|
||||||
err_t (*_etharp_output)(ETHARP_OUTPUT_SIG);
|
|
||||||
err_t (*_ethernet_input)(ETHERNET_INPUT_SIG);
|
|
||||||
void (*_tcp_input)(TCP_INPUT_SIG);
|
|
||||||
err_t (*_ip_input)(IP_INPUT_SIG);
|
|
||||||
void (*_netif_set_default)(NETIF_SET_DEFAULT_SIG);
|
|
||||||
struct netif * (*_netif_add)(NETIF_ADD_SIG);
|
|
||||||
void (*_netif_set_up)(NETIF_SET_UP_SIG);
|
|
||||||
void (*_netif_poll)(NETIF_POLL_SIG);
|
|
||||||
|
|
||||||
Mutex _lock;
|
|
||||||
Mutex _lock_mem;
|
|
||||||
|
|
||||||
LWIPStack(const char* path) :
|
|
||||||
_libref(NULL)
|
|
||||||
{
|
|
||||||
#if defined(__ANDROID__) || defined(__UNITY_3D__)
|
|
||||||
#define __STATIC_LWIP__
|
|
||||||
#elif defined(__linux__)
|
|
||||||
#define __DYNAMIC_LWIP__
|
|
||||||
// Dynamically load liblwip.so
|
|
||||||
_libref = dlmopen(LM_ID_NEWLM, path, RTLD_NOW);
|
|
||||||
#elif defined(__APPLE__)
|
|
||||||
#include "TargetConditionals.h"
|
|
||||||
#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
|
|
||||||
#include "node/Mutex.hpp"
|
|
||||||
#define __STATIC_LWIP__
|
|
||||||
// iOS Simulator or iOS device
|
|
||||||
// Do nothing, symbols are statically-linked
|
|
||||||
#elif TARGET_OS_MAC && !defined(SDK_BUNDLED)
|
|
||||||
#define __DYNAMIC_LWIP__
|
|
||||||
// Dynamically load liblwip.so
|
|
||||||
_libref = dlopen(path, RTLD_NOW);
|
|
||||||
#else
|
|
||||||
#define __STATIC_LWIP__
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __STATIC_LWIP__ // Set static references (for use in iOS)
|
|
||||||
|
|
||||||
_netif_init = (void(*)(void))&netif_init;
|
|
||||||
_nd6_tmr = (void(*)(void))&nd6_tmr;
|
|
||||||
_netif_ip6_addr_set_state = (void(*)(NETIF_IP6_ADDR_SET_STATE_SIG))&netif_ip6_addr_set_state;
|
|
||||||
_netif_loopif_init = (void(*)(NETIF_LOOPIF_INIT_SIG))&netif_loopif_init;
|
|
||||||
_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;
|
|
||||||
|
|
||||||
_ethernet_input = (err_t(*)(ETHERNET_INPUT_SIG))ðernet_input;
|
|
||||||
_etharp_output = (err_t(*)(ETHARP_OUTPUT_SIG))ðarp_output;
|
|
||||||
_lwip_init = (void(*)(void))&lwip_init;
|
|
||||||
_tcp_write = (err_t(*)(TCP_WRITE_SIG))&tcp_write;
|
|
||||||
_tcp_sent = (void(*)(TCP_SENT_SIG))&tcp_sent;
|
|
||||||
_tcp_new = (struct tcp_pcb*(*)(TCP_NEW_SIG))&tcp_new;
|
|
||||||
|
|
||||||
_udp_new = (struct udp_pcb*(*)(UDP_NEW_SIG))&udp_new;
|
|
||||||
_udp_connect = (err_t(*)(UDP_CONNECT_SIG))&udp_connect;
|
|
||||||
_udp_send = (err_t(*)(UDP_SEND_SIG))&udp_send;
|
|
||||||
_udp_sendto = (err_t(*)(UDP_SENDTO_SIG))&udp_sendto;
|
|
||||||
_udp_recv = (void(*)(UDP_RECV_SIG))&udp_recv;
|
|
||||||
_udp_bind = (err_t(*)(UDP_BIND_SIG))&udp_bind;
|
|
||||||
_udp_remove = (void(*)(UDP_REMOVE_SIG))&udp_remove;
|
|
||||||
|
|
||||||
_tcp_connect = (err_t(*)(TCP_CONNECT_SIG))&tcp_connect;
|
|
||||||
_tcp_recv = (void(*)(TCP_RECV_SIG))&tcp_recv;
|
|
||||||
_tcp_recved = (void(*)(TCP_RECVED_SIG))&tcp_recved;
|
|
||||||
_tcp_err = (void(*)(TCP_ERR_SIG))&tcp_err;
|
|
||||||
_tcp_poll = (void(*)(TCP_POLL_SIG))&tcp_poll;
|
|
||||||
_tcp_arg = (void(*)(TCP_ARG_SIG))&tcp_arg;
|
|
||||||
_tcp_close = (err_t(*)(TCP_CLOSE_SIG))&tcp_close;
|
|
||||||
_tcp_abort = (void(*)(TCP_ABORT_SIG))&tcp_abort;
|
|
||||||
_tcp_output = (err_t(*)(TCP_OUTPUT_SIG))&tcp_output;
|
|
||||||
_tcp_accept = (void(*)(TCP_ACCEPT_SIG))&tcp_accept;
|
|
||||||
_tcp_listen_with_backlog = (struct tcp_pcb*(*)(TCP_LISTEN_WITH_BACKLOG_SIG))&tcp_listen_with_backlog;
|
|
||||||
_tcp_bind = (err_t(*)(TCP_BIND_SIG))&tcp_bind;
|
|
||||||
_etharp_tmr = (void(*)(void))ðarp_tmr;
|
|
||||||
_tcp_tmr = (void(*)(void))&tcp_tmr;
|
|
||||||
_pbuf_free = (u8_t(*)(PBUF_FREE_SIG))&pbuf_free;
|
|
||||||
_pbuf_alloc = (struct pbuf*(*)(PBUF_ALLOC_SIG))&pbuf_alloc;
|
|
||||||
_lwip_htons = (u16_t(*)(LWIP_HTONS_SIG))&lwip_htons;
|
|
||||||
_lwip_ntohs = (u16_t(*)(LWIP_NTOHS_SIG))&lwip_ntohs;
|
|
||||||
_ipaddr_ntoa = (char*(*)(IPADDR_NTOA_SIG))&ipaddr_ntoa;
|
|
||||||
_tcp_input = (void(*)(TCP_INPUT_SIG))&tcp_input;
|
|
||||||
_ip_input = (err_t(*)(IP_INPUT_SIG))&ip_input;
|
|
||||||
_netif_set_default = (void(*)(NETIF_SET_DEFAULT_SIG))&netif_set_default;
|
|
||||||
_netif_add = (struct netif*(*)(NETIF_ADD_SIG))&netif_add;
|
|
||||||
_netif_set_up = (void(*)(NETIF_SET_UP_SIG))&netif_set_up;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __DYNAMIC_LWIP__ // Use dynamically-loaded symbols (for use in normal desktop applications)
|
|
||||||
|
|
||||||
if(_libref == NULL)
|
|
||||||
DEBUG_ERROR("dlerror(): %s", dlerror());
|
|
||||||
|
|
||||||
_netif_init = (void(*)(void))dlsym(_libref, "netif_init");
|
|
||||||
_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_loopif_init = (void(*)(NETIF_LOOPIF_INIT_SIG))dlsym(_libref, "netif_loopif_init");
|
|
||||||
_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");
|
|
||||||
|
|
||||||
// _netif_set_addr = (void(*))(NETIF_SET_ADDR_SIG))dlsym(_libref, "netif_set_addr");
|
|
||||||
|
|
||||||
_ethernet_input = (err_t(*)(ETHERNET_INPUT_SIG))dlsym(_libref, "ethernet_input");
|
|
||||||
_etharp_output = (err_t(*)(ETHARP_OUTPUT_SIG))dlsym(_libref, "etharp_output");
|
|
||||||
_lwip_init = (void(*)(void))dlsym(_libref, "lwip_init");
|
|
||||||
_tcp_write = (err_t(*)(TCP_WRITE_SIG))dlsym(_libref, "tcp_write");
|
|
||||||
_tcp_sent = (void(*)(TCP_SENT_SIG))dlsym(_libref, "tcp_sent");
|
|
||||||
_tcp_new = (struct tcp_pcb*(*)(TCP_NEW_SIG))dlsym(_libref, "tcp_new");
|
|
||||||
|
|
||||||
_udp_new = (struct udp_pcb*(*)(UDP_NEW_SIG))dlsym(_libref, "udp_new");
|
|
||||||
_udp_connect = (err_t(*)(UDP_CONNECT_SIG))dlsym(_libref, "udp_connect");
|
|
||||||
_udp_send = (err_t(*)(UDP_SEND_SIG))dlsym(_libref, "udp_send");
|
|
||||||
_udp_sendto = (err_t(*)(UDP_SENDTO_SIG))dlsym(_libref, "udp_sendto");
|
|
||||||
_udp_recv = (void(*)(UDP_RECV_SIG))dlsym(_libref, "udp_recv");
|
|
||||||
_udp_bind = (err_t(*)(UDP_BIND_SIG))dlsym(_libref, "udp_bind");
|
|
||||||
_udp_remove = (void(*)(UDP_REMOVE_SIG))dlsym(_libref, "udp_remove");
|
|
||||||
|
|
||||||
_tcp_sndbuf = (u16_t(*)(TCP_SNDBUF_SIG))dlsym(_libref, "tcp_sndbuf");
|
|
||||||
_tcp_connect = (err_t(*)(TCP_CONNECT_SIG))dlsym(_libref, "tcp_connect");
|
|
||||||
_tcp_recv = (void(*)(TCP_RECV_SIG))dlsym(_libref, "tcp_recv");
|
|
||||||
_tcp_recved = (void(*)(TCP_RECVED_SIG))dlsym(_libref, "tcp_recved");
|
|
||||||
_tcp_err = (void(*)(TCP_ERR_SIG))dlsym(_libref, "tcp_err");
|
|
||||||
_tcp_poll = (void(*)(TCP_POLL_SIG))dlsym(_libref, "tcp_poll");
|
|
||||||
_tcp_arg = (void(*)(TCP_ARG_SIG))dlsym(_libref, "tcp_arg");
|
|
||||||
_tcp_close = (err_t(*)(TCP_CLOSE_SIG))dlsym(_libref, "tcp_close");
|
|
||||||
_tcp_abort = (void(*)(TCP_ABORT_SIG))dlsym(_libref, "tcp_abort");
|
|
||||||
_tcp_output = (err_t(*)(TCP_OUTPUT_SIG))dlsym(_libref, "tcp_output");
|
|
||||||
_tcp_accept = (void(*)(TCP_ACCEPT_SIG))dlsym(_libref, "tcp_accept");
|
|
||||||
_tcp_listen = (struct tcp_pcb*(*)(TCP_LISTEN_SIG))dlsym(_libref, "tcp_listen");
|
|
||||||
_tcp_listen_with_backlog = (struct tcp_pcb*(*)(TCP_LISTEN_WITH_BACKLOG_SIG))dlsym(_libref, "tcp_listen_with_backlog");
|
|
||||||
_tcp_bind = (err_t(*)(TCP_BIND_SIG))dlsym(_libref, "tcp_bind");
|
|
||||||
_etharp_tmr = (void(*)(void))dlsym(_libref, "etharp_tmr");
|
|
||||||
_tcp_tmr = (void(*)(void))dlsym(_libref, "tcp_tmr");
|
|
||||||
_pbuf_free = (u8_t(*)(PBUF_FREE_SIG))dlsym(_libref, "pbuf_free");
|
|
||||||
_pbuf_alloc = (struct pbuf*(*)(PBUF_ALLOC_SIG))dlsym(_libref, "pbuf_alloc");
|
|
||||||
_lwip_htons = (u16_t(*)(LWIP_HTONS_SIG))dlsym(_libref, "lwip_htons");
|
|
||||||
_lwip_ntohs = (u16_t(*)(LWIP_NTOHS_SIG))dlsym(_libref, "lwip_ntohs");
|
|
||||||
_ipaddr_ntoa = (char*(*)(IPADDR_NTOA_SIG))dlsym(_libref, "ipaddr_ntoa");
|
|
||||||
_tcp_input = (void(*)(TCP_INPUT_SIG))dlsym(_libref, "tcp_input");
|
|
||||||
_ip_input = (err_t(*)(IP_INPUT_SIG))dlsym(_libref, "ip_input");
|
|
||||||
_netif_set_default = (void(*)(NETIF_SET_DEFAULT_SIG))dlsym(_libref, "netif_set_default");
|
|
||||||
_netif_add = (struct netif*(*)(NETIF_ADD_SIG))dlsym(_libref, "netif_add");
|
|
||||||
_netif_set_up = (void(*)(NETIF_SET_UP_SIG))dlsym(_libref, "netif_set_up");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
~LWIPStack()
|
|
||||||
{
|
|
||||||
if (_libref)
|
|
||||||
dlclose(_libref);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void __netif_init(void) throw() { Mutex::Lock _l(_lock); _netif_init(); }
|
|
||||||
inline void __nd6_tmr(void) throw() { Mutex::Lock _l(_lock); _nd6_tmr(); }
|
|
||||||
inline void __netif_ip6_addr_set_state(NETIF_IP6_ADDR_SET_STATE_SIG) throw() { Mutex::Lock _l(_lock); _netif_ip6_addr_set_state(netif, addr_idx, state); }
|
|
||||||
inline void __netif_loopif_init(NETIF_LOOPIF_INIT_SIG) throw() { Mutex::Lock _l(_lock); _netif_loopif_init(netif); }
|
|
||||||
inline void __netif_create_ip6_linklocal_address(NETIF_CREATE_IP6_LINKLOCAL_ADDRESS_SIG) throw() { Mutex::Lock _l(_lock); _netif_create_ip6_linklocal_address(netif, from_mac_48bit); }
|
|
||||||
// inline void __netif_set_addr(NETIF_SET_ADDR_SIG) throw() { Mutex::Lock _l(_lock); _netif_set_addr(netif, ipaddr, netmask, gw); }
|
|
||||||
|
|
||||||
inline void __lwip_init() throw() { Mutex::Lock _l(_lock); return _lwip_init(); }
|
|
||||||
inline err_t __tcp_write(TCP_WRITE_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_write(pcb,arg,len,apiflags); }
|
|
||||||
inline void __tcp_sent(TCP_SENT_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_sent(pcb,sent); }
|
|
||||||
inline struct tcp_pcb * __tcp_new(TCP_NEW_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_new(); }
|
|
||||||
|
|
||||||
inline struct udp_pcb * __udp_new(UDP_NEW_SIG) throw() { Mutex::Lock _l(_lock); return _udp_new(); }
|
|
||||||
inline err_t __udp_connect(UDP_CONNECT_SIG) throw() { Mutex::Lock _l(_lock); return _udp_connect(pcb,ipaddr,port); }
|
|
||||||
inline err_t __udp_send(UDP_SEND_SIG) throw() { Mutex::Lock _l(_lock); return _udp_send(pcb,p); }
|
|
||||||
inline err_t __udp_sendto(UDP_SENDTO_SIG) throw() { Mutex::Lock _l(_lock); return _udp_sendto(pcb,p,dst_ip,dst_port); }
|
|
||||||
inline void __udp_recv(UDP_RECV_SIG) throw() { Mutex::Lock _l(_lock); return _udp_recv(pcb,recv,recv_arg); }
|
|
||||||
inline err_t __udp_bind(UDP_BIND_SIG) throw() { Mutex::Lock _l(_lock); return _udp_bind(pcb,ipaddr,port); }
|
|
||||||
inline void __udp_remove(UDP_REMOVE_SIG) throw() { Mutex::Lock _l(_lock); return _udp_remove(pcb); }
|
|
||||||
|
|
||||||
inline u16_t __tcp_sndbuf(TCP_SNDBUF_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_sndbuf(pcb); }
|
|
||||||
inline err_t __tcp_connect(TCP_CONNECT_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_connect(pcb,ipaddr,port,connected); }
|
|
||||||
inline void __tcp_recv(TCP_RECV_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_recv(pcb,recv); }
|
|
||||||
inline void __tcp_recved(TCP_RECVED_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_recved(pcb,len); }
|
|
||||||
inline void __tcp_err(TCP_ERR_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_err(pcb,err); }
|
|
||||||
inline void __tcp_poll(TCP_POLL_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_poll(pcb,poll,interval); }
|
|
||||||
inline void __tcp_arg(TCP_ARG_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_arg(pcb,arg); }
|
|
||||||
inline err_t __tcp_close(TCP_CLOSE_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_close(pcb); }
|
|
||||||
inline void __tcp_abort(TCP_ABORT_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_abort(pcb); }
|
|
||||||
inline err_t __tcp_output(TCP_OUTPUT_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_output(pcb); }
|
|
||||||
inline void __tcp_accept(TCP_ACCEPT_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_accept(pcb,accept); }
|
|
||||||
inline struct tcp_pcb * __tcp_listen(TCP_LISTEN_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_listen(pcb); }
|
|
||||||
inline struct tcp_pcb * __tcp_listen_with_backlog(TCP_LISTEN_WITH_BACKLOG_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_listen_with_backlog(pcb,backlog); }
|
|
||||||
inline err_t __tcp_bind(TCP_BIND_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_bind(pcb,ipaddr,port); }
|
|
||||||
inline void __etharp_tmr(void) throw() { Mutex::Lock _l(_lock); return _etharp_tmr(); }
|
|
||||||
inline void __tcp_tmr(void) throw() { Mutex::Lock _l(_lock); return _tcp_tmr(); }
|
|
||||||
inline u8_t __pbuf_free(PBUF_FREE_SIG) throw() { Mutex::Lock _l(_lock); return _pbuf_free(p); }
|
|
||||||
inline struct pbuf * __pbuf_alloc(PBUF_ALLOC_SIG) throw() { Mutex::Lock _l(_lock_mem); return _pbuf_alloc(layer,length,type); }
|
|
||||||
inline u16_t __lwip_htons(LWIP_HTONS_SIG) throw() { Mutex::Lock _l(_lock); return _lwip_htons(x); }
|
|
||||||
inline u16_t __lwip_ntohs(LWIP_NTOHS_SIG) throw() { Mutex::Lock _l(_lock); return _lwip_ntohs(x); }
|
|
||||||
inline char* __ipaddr_ntoa(IPADDR_NTOA_SIG) throw() { Mutex::Lock _l(_lock); return _ipaddr_ntoa(addr); }
|
|
||||||
|
|
||||||
inline err_t __ethip6_output(ETHIP6_OUTPUT_SIG) throw() { Mutex::Lock _l(_lock); return _ethip6_output(netif,q,ip6addr); }
|
|
||||||
//inline err_t __etharp_output(ETHARP_OUTPUT_SIG) throw() { Mutex::Lock _l(_lock); return _etharp_output(netif,q,ipaddr); }
|
|
||||||
inline struct netif * __netif_add(NETIF_ADD_SIG) throw() { Mutex::Lock _l(_lock); return _netif_add(netif,state,init,input); }
|
|
||||||
//inline struct netif * __netif_add(NETIF_ADD_SIG) throw() { Mutex::Lock _l(_lock); return _netif_add(netif,ipaddr,netmask,gw,state,init,input); }
|
|
||||||
|
|
||||||
inline err_t __ethernet_input(ETHERNET_INPUT_SIG) throw() { Mutex::Lock _l(_lock); return _ethernet_input(p,netif); }
|
|
||||||
inline void __tcp_input(TCP_INPUT_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_input(p,inp); }
|
|
||||||
inline err_t __ip_input(IP_INPUT_SIG) throw() { Mutex::Lock _l(_lock); return _ip_input(p,inp); }
|
|
||||||
inline void __netif_set_default(NETIF_SET_DEFAULT_SIG) throw() { Mutex::Lock _l(_lock); return _netif_set_default(netif); }
|
|
||||||
inline void __netif_set_up(NETIF_SET_UP_SIG) throw() { Mutex::Lock _l(_lock); return _netif_set_up(netif); }
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ZeroTier
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -26,8 +26,27 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#define IP6_ADDR2(ipaddr, a,b,c,d,e,f,g,h) do { (ipaddr)->addr[0] = Utils::hton((u32_t)((a & 0xffff) << 16) | (b & 0xffff)); \
|
#if defined(SDK_LWIP) && defined(SDK_IPV6)
|
||||||
(ipaddr)->addr[1] = Utils::hton(((c & 0xffff) << 16) | (d & 0xffff)); \
|
#define IP6_ADDR2(ipaddr, a,b,c,d,e,f,g,h) do { (ipaddr)->addr[0] = ZeroTier::Utils::hton((u32_t)((a & 0xffff) << 16) | (b & 0xffff)); \
|
||||||
(ipaddr)->addr[2] = Utils::hton(((e & 0xffff) << 16) | (f & 0xffff)); \
|
(ipaddr)->addr[1] = ZeroTier::Utils::hton(((c & 0xffff) << 16) | (d & 0xffff)); \
|
||||||
(ipaddr)->addr[3] = Utils::hton(((g & 0xffff) << 16) | (h & 0xffff)); } while(0)
|
(ipaddr)->addr[2] = ZeroTier::Utils::hton(((e & 0xffff) << 16) | (f & 0xffff)); \
|
||||||
|
(ipaddr)->addr[3] = ZeroTier::Utils::hton(((g & 0xffff) << 16) | (h & 0xffff)); } while(0)
|
||||||
|
|
||||||
|
|
||||||
|
// Convert from standard IPV6 address structure to an lwIP native structure
|
||||||
|
void in6_to_ip6(ip6_addr_t *ba, struct sockaddr_in6 *in6)
|
||||||
|
{
|
||||||
|
uint8_t *ip = &(in6->sin6_addr).s6_addr[0];
|
||||||
|
uint16_t ip16;
|
||||||
|
IP6_ADDR2(ba,
|
||||||
|
(((ip[ 0] & 0xffff) << 8) | ((ip[ 1]) & 0xffff)),
|
||||||
|
(((ip[ 2] & 0xffff) << 8) | ((ip[ 3]) & 0xffff)),
|
||||||
|
(((ip[ 4] & 0xffff) << 8) | ((ip[ 5]) & 0xffff)),
|
||||||
|
(((ip[ 6] & 0xffff) << 8) | ((ip[ 7]) & 0xffff)),
|
||||||
|
(((ip[ 8] & 0xffff) << 8) | ((ip[ 9]) & 0xffff)),
|
||||||
|
(((ip[10] & 0xffff) << 8) | ((ip[11]) & 0xffff)),
|
||||||
|
(((ip[12] & 0xffff) << 8) | ((ip[13]) & 0xffff)),
|
||||||
|
(((ip[14] & 0xffff) << 8) | ((ip[15]) & 0xffff))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
105
src/SDK_lwip.hpp
105
src/SDK_lwip.hpp
@@ -28,6 +28,8 @@
|
|||||||
#ifndef SDK_LWIPSTACK_H
|
#ifndef SDK_LWIPSTACK_H
|
||||||
#define SDK_LWIPSTACK_H
|
#define SDK_LWIPSTACK_H
|
||||||
|
|
||||||
|
#if defined (SDK_LWIP)
|
||||||
|
|
||||||
#include "lwip/mem.h"
|
#include "lwip/mem.h"
|
||||||
#include "lwip/pbuf.h"
|
#include "lwip/pbuf.h"
|
||||||
#include "lwip/ip_addr.h"
|
#include "lwip/ip_addr.h"
|
||||||
@@ -46,7 +48,6 @@
|
|||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//typedef ip_addr ip_addr_t;
|
|
||||||
struct tcp_pcb;
|
struct tcp_pcb;
|
||||||
|
|
||||||
// lwip General Stack API
|
// lwip General Stack API
|
||||||
@@ -56,22 +57,6 @@ struct tcp_pcb;
|
|||||||
#define LWIP_NTOHS_SIG u16_t x
|
#define LWIP_NTOHS_SIG u16_t x
|
||||||
#define IPADDR_NTOA_SIG const ip_addr_t *addr
|
#define IPADDR_NTOA_SIG const ip_addr_t *addr
|
||||||
|
|
||||||
#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 ETHARP_OUTPUT_SIG struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr
|
|
||||||
|
|
||||||
//#if defined(LWIP_IPV6)
|
|
||||||
#define NETIF_ADD_SIG struct netif *netif, void *state, netif_init_fn init, netif_input_fn input
|
|
||||||
//#elif defined(LWIP_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
|
|
||||||
//#endif
|
|
||||||
|
|
||||||
#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
|
|
||||||
#define NETIF_SET_UP_SIG struct netif *netif
|
|
||||||
#define NETIF_POLL_SIG struct netif *netif
|
|
||||||
|
|
||||||
// lwIP UDP API
|
// lwIP UDP API
|
||||||
#define UDP_NEW_SIG void
|
#define UDP_NEW_SIG void
|
||||||
#define UDP_CONNECT_SIG struct udp_pcb * pcb, ip_addr_t * ipaddr, u16_t port
|
#define UDP_CONNECT_SIG struct udp_pcb * pcb, ip_addr_t * ipaddr, u16_t port
|
||||||
@@ -103,13 +88,29 @@ struct tcp_pcb;
|
|||||||
#define TCP_BIND_SIG struct tcp_pcb * pcb, const ip_addr_t * ipaddr, u16_t port
|
#define TCP_BIND_SIG struct tcp_pcb * pcb, const ip_addr_t * ipaddr, u16_t port
|
||||||
#define TCP_INPUT_SIG struct pbuf *p, struct netif *inp
|
#define TCP_INPUT_SIG struct pbuf *p, struct netif *inp
|
||||||
|
|
||||||
void dwr(int level, const char *fmt, ... );
|
// lwIP network stack interfaces
|
||||||
|
|
||||||
#define NETIF_IP6_ADDR_SET_STATE_SIG struct netif* netif, s8_t addr_idx, u8_t state
|
#define NETIF_IP6_ADDR_SET_STATE_SIG struct netif* netif, s8_t addr_idx, u8_t state
|
||||||
#define NETIF_LOOPIF_INIT_SIG struct netif *netif
|
#define NETIF_LOOPIF_INIT_SIG struct netif *netif
|
||||||
#define NETIF_CREATE_IP6_LINKLOCAL_ADDRESS_SIG struct netif *netif, u8_t from_mac_48bit
|
#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
|
||||||
|
#define NETIF_SET_UP_SIG struct netif *netif
|
||||||
|
#define NETIF_POLL_SIG struct netif *netif
|
||||||
|
|
||||||
//#define NETIF_SET_ADDR_SIG struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw
|
//#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 {
|
namespace ZeroTier {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -135,12 +136,19 @@ namespace ZeroTier {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void (*_netif_init)(void);
|
#if defined(SDK_IPV6)
|
||||||
|
err_t (*_ethip6_output)(ETHIP6_OUTPUT_SIG);
|
||||||
void (*_nd6_tmr)(void);
|
void (*_nd6_tmr)(void);
|
||||||
void (*_netif_ip6_addr_set_state)(NETIF_IP6_ADDR_SET_STATE_SIG);
|
void (*_netif_ip6_addr_set_state)(NETIF_IP6_ADDR_SET_STATE_SIG);
|
||||||
void (*_netif_loopif_init)(NETIF_LOOPIF_INIT_SIG);
|
|
||||||
void (*_netif_create_ip6_linklocal_address)(NETIF_CREATE_IP6_LINKLOCAL_ADDRESS_SIG);
|
void (*_netif_create_ip6_linklocal_address)(NETIF_CREATE_IP6_LINKLOCAL_ADDRESS_SIG);
|
||||||
err_t (*_ethip6_output)(ETHIP6_OUTPUT_SIG);
|
#endif
|
||||||
|
|
||||||
|
#if defined(SDK_IPV4)
|
||||||
|
err_t (*_etharp_output)(ETHARP_OUTPUT_SIG);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void (*_netif_init)(void);
|
||||||
|
void (*_netif_loopif_init)(NETIF_LOOPIF_INIT_SIG);
|
||||||
// void (*_netif_set_addr)(NETIF_SET_ADDR_SIG);
|
// void (*_netif_set_addr)(NETIF_SET_ADDR_SIG);
|
||||||
|
|
||||||
void (*_lwip_init)();
|
void (*_lwip_init)();
|
||||||
@@ -178,7 +186,6 @@ namespace ZeroTier {
|
|||||||
u16_t (*_lwip_htons)(LWIP_HTONS_SIG);
|
u16_t (*_lwip_htons)(LWIP_HTONS_SIG);
|
||||||
u16_t (*_lwip_ntohs)(LWIP_NTOHS_SIG);
|
u16_t (*_lwip_ntohs)(LWIP_NTOHS_SIG);
|
||||||
char* (*_ipaddr_ntoa)(IPADDR_NTOA_SIG);
|
char* (*_ipaddr_ntoa)(IPADDR_NTOA_SIG);
|
||||||
err_t (*_etharp_output)(ETHARP_OUTPUT_SIG);
|
|
||||||
err_t (*_ethernet_input)(ETHERNET_INPUT_SIG);
|
err_t (*_ethernet_input)(ETHERNET_INPUT_SIG);
|
||||||
void (*_tcp_input)(TCP_INPUT_SIG);
|
void (*_tcp_input)(TCP_INPUT_SIG);
|
||||||
err_t (*_ip_input)(IP_INPUT_SIG);
|
err_t (*_ip_input)(IP_INPUT_SIG);
|
||||||
@@ -218,14 +225,9 @@ namespace ZeroTier {
|
|||||||
#ifdef __STATIC_LWIP__ // Set static references (for use in iOS)
|
#ifdef __STATIC_LWIP__ // Set static references (for use in iOS)
|
||||||
|
|
||||||
_netif_init = (void(*)(void))&netif_init;
|
_netif_init = (void(*)(void))&netif_init;
|
||||||
_nd6_tmr = (void(*)(void))&nd6_tmr;
|
|
||||||
_netif_ip6_addr_set_state = (void(*)(NETIF_IP6_ADDR_SET_STATE_SIG))&netif_ip6_addr_set_state;
|
|
||||||
_netif_loopif_init = (void(*)(NETIF_LOOPIF_INIT_SIG))&netif_loopif_init;
|
_netif_loopif_init = (void(*)(NETIF_LOOPIF_INIT_SIG))&netif_loopif_init;
|
||||||
_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;
|
|
||||||
|
|
||||||
_ethernet_input = (err_t(*)(ETHERNET_INPUT_SIG))ðernet_input;
|
_ethernet_input = (err_t(*)(ETHERNET_INPUT_SIG))ðernet_input;
|
||||||
_etharp_output = (err_t(*)(ETHARP_OUTPUT_SIG))ðarp_output;
|
|
||||||
_lwip_init = (void(*)(void))&lwip_init;
|
_lwip_init = (void(*)(void))&lwip_init;
|
||||||
_tcp_write = (err_t(*)(TCP_WRITE_SIG))&tcp_write;
|
_tcp_write = (err_t(*)(TCP_WRITE_SIG))&tcp_write;
|
||||||
_tcp_sent = (void(*)(TCP_SENT_SIG))&tcp_sent;
|
_tcp_sent = (void(*)(TCP_SENT_SIG))&tcp_sent;
|
||||||
@@ -263,6 +265,18 @@ namespace ZeroTier {
|
|||||||
_netif_set_default = (void(*)(NETIF_SET_DEFAULT_SIG))&netif_set_default;
|
_netif_set_default = (void(*)(NETIF_SET_DEFAULT_SIG))&netif_set_default;
|
||||||
_netif_add = (struct netif*(*)(NETIF_ADD_SIG))&netif_add;
|
_netif_add = (struct netif*(*)(NETIF_ADD_SIG))&netif_add;
|
||||||
_netif_set_up = (void(*)(NETIF_SET_UP_SIG))&netif_set_up;
|
_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
|
#endif
|
||||||
|
|
||||||
#ifdef __DYNAMIC_LWIP__ // Use dynamically-loaded symbols (for use in normal desktop applications)
|
#ifdef __DYNAMIC_LWIP__ // Use dynamically-loaded symbols (for use in normal desktop applications)
|
||||||
@@ -271,16 +285,22 @@ namespace ZeroTier {
|
|||||||
DEBUG_ERROR("dlerror(): %s", dlerror());
|
DEBUG_ERROR("dlerror(): %s", dlerror());
|
||||||
|
|
||||||
_netif_init = (void(*)(void))dlsym(_libref, "netif_init");
|
_netif_init = (void(*)(void))dlsym(_libref, "netif_init");
|
||||||
|
_netif_loopif_init = (void(*)(NETIF_LOOPIF_INIT_SIG))dlsym(_libref, "netif_loopif_init");
|
||||||
|
|
||||||
|
#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");
|
_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_ip6_addr_set_state = (void(*)(NETIF_IP6_ADDR_SET_STATE_SIG))dlsym(_libref, "netif_ip6_addr_set_state");
|
||||||
_netif_loopif_init = (void(*)(NETIF_LOOPIF_INIT_SIG))dlsym(_libref, "netif_loopif_init");
|
|
||||||
_netif_create_ip6_linklocal_address = (void(*)(NETIF_CREATE_IP6_LINKLOCAL_ADDRESS_SIG))dlsym(_libref, "netif_create_ip6_linklocal_address");
|
_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");
|
_ethip6_output = (err_t(*)(ETHIP6_OUTPUT_SIG))dlsym(_libref, "ethip6_output");
|
||||||
|
#endif
|
||||||
|
|
||||||
// _netif_set_addr = (void(*))(NETIF_SET_ADDR_SIG))dlsym(_libref, "netif_set_addr");
|
// _netif_set_addr = (void(*))(NETIF_SET_ADDR_SIG))dlsym(_libref, "netif_set_addr");
|
||||||
|
|
||||||
_ethernet_input = (err_t(*)(ETHERNET_INPUT_SIG))dlsym(_libref, "ethernet_input");
|
_ethernet_input = (err_t(*)(ETHERNET_INPUT_SIG))dlsym(_libref, "ethernet_input");
|
||||||
_etharp_output = (err_t(*)(ETHARP_OUTPUT_SIG))dlsym(_libref, "etharp_output");
|
|
||||||
_lwip_init = (void(*)(void))dlsym(_libref, "lwip_init");
|
_lwip_init = (void(*)(void))dlsym(_libref, "lwip_init");
|
||||||
_tcp_write = (err_t(*)(TCP_WRITE_SIG))dlsym(_libref, "tcp_write");
|
_tcp_write = (err_t(*)(TCP_WRITE_SIG))dlsym(_libref, "tcp_write");
|
||||||
_tcp_sent = (void(*)(TCP_SENT_SIG))dlsym(_libref, "tcp_sent");
|
_tcp_sent = (void(*)(TCP_SENT_SIG))dlsym(_libref, "tcp_sent");
|
||||||
@@ -330,10 +350,7 @@ namespace ZeroTier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline void __netif_init(void) throw() { Mutex::Lock _l(_lock); _netif_init(); }
|
inline void __netif_init(void) throw() { Mutex::Lock _l(_lock); _netif_init(); }
|
||||||
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_loopif_init(NETIF_LOOPIF_INIT_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); _netif_loopif_init(netif); }
|
inline void __netif_loopif_init(NETIF_LOOPIF_INIT_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); _netif_loopif_init(netif); }
|
||||||
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 void __netif_set_addr(NETIF_SET_ADDR_SIG) throw() { Mutex::Lock _l(_lock); _netif_set_addr(netif, ipaddr, netmask, gw); }
|
// inline void __netif_set_addr(NETIF_SET_ADDR_SIG) throw() { Mutex::Lock _l(_lock); _netif_set_addr(netif, ipaddr, netmask, gw); }
|
||||||
|
|
||||||
inline void __lwip_init() throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _lwip_init(); }
|
inline void __lwip_init() throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _lwip_init(); }
|
||||||
@@ -363,26 +380,36 @@ namespace ZeroTier {
|
|||||||
inline struct tcp_pcb * __tcp_listen(TCP_LISTEN_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _tcp_listen(pcb); }
|
inline struct tcp_pcb * __tcp_listen(TCP_LISTEN_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _tcp_listen(pcb); }
|
||||||
inline struct tcp_pcb * __tcp_listen_with_backlog(TCP_LISTEN_WITH_BACKLOG_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _tcp_listen_with_backlog(pcb,backlog); }
|
inline struct tcp_pcb * __tcp_listen_with_backlog(TCP_LISTEN_WITH_BACKLOG_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _tcp_listen_with_backlog(pcb,backlog); }
|
||||||
inline err_t __tcp_bind(TCP_BIND_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _tcp_bind(pcb,ipaddr,port); }
|
inline err_t __tcp_bind(TCP_BIND_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _tcp_bind(pcb,ipaddr,port); }
|
||||||
inline void __etharp_tmr(void) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _etharp_tmr(); }
|
inline void __etharp_tmr(void) throw() { /*DEBUG_STACK();*/ Mutex::Lock _l(_lock); return _etharp_tmr(); }
|
||||||
inline void __tcp_tmr(void) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _tcp_tmr(); }
|
inline void __tcp_tmr(void) throw() { /*DEBUG_STACK();*/ Mutex::Lock _l(_lock); return _tcp_tmr(); }
|
||||||
inline u8_t __pbuf_free(PBUF_FREE_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _pbuf_free(p); }
|
inline u8_t __pbuf_free(PBUF_FREE_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _pbuf_free(p); }
|
||||||
inline struct pbuf * __pbuf_alloc(PBUF_ALLOC_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock_mem); return _pbuf_alloc(layer,length,type); }
|
inline struct pbuf * __pbuf_alloc(PBUF_ALLOC_SIG) throw() { /*DEBUG_STACK();*/ Mutex::Lock _l(_lock_mem); return _pbuf_alloc(layer,length,type); }
|
||||||
inline u16_t __lwip_htons(LWIP_HTONS_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _lwip_htons(x); }
|
inline u16_t __lwip_htons(LWIP_HTONS_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _lwip_htons(x); }
|
||||||
inline u16_t __lwip_ntohs(LWIP_NTOHS_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _lwip_ntohs(x); }
|
inline u16_t __lwip_ntohs(LWIP_NTOHS_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _lwip_ntohs(x); }
|
||||||
inline char* __ipaddr_ntoa(IPADDR_NTOA_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _ipaddr_ntoa(addr); }
|
inline char* __ipaddr_ntoa(IPADDR_NTOA_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _ipaddr_ntoa(addr); }
|
||||||
|
|
||||||
inline err_t __ethip6_output(ETHIP6_OUTPUT_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _ethip6_output(netif,q,ip6addr); }
|
|
||||||
//inline err_t __etharp_output(ETHARP_OUTPUT_SIG) throw() { Mutex::Lock _l(_lock); return _etharp_output(netif,q,ipaddr); }
|
//inline err_t __etharp_output(ETHARP_OUTPUT_SIG) throw() { Mutex::Lock _l(_lock); return _etharp_output(netif,q,ipaddr); }
|
||||||
inline struct netif * __netif_add(NETIF_ADD_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _netif_add(netif,state,init,input); }
|
|
||||||
//inline struct netif * __netif_add(NETIF_ADD_SIG) throw() { Mutex::Lock _l(_lock); return _netif_add(netif,ipaddr,netmask,gw,state,init,input); }
|
|
||||||
|
|
||||||
inline err_t __ethernet_input(ETHERNET_INPUT_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _ethernet_input(p,netif); }
|
inline err_t __ethernet_input(ETHERNET_INPUT_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _ethernet_input(p,netif); }
|
||||||
inline void __tcp_input(TCP_INPUT_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _tcp_input(p,inp); }
|
inline void __tcp_input(TCP_INPUT_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _tcp_input(p,inp); }
|
||||||
inline err_t __ip_input(IP_INPUT_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _ip_input(p,inp); }
|
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_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); }
|
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
|
} // namespace ZeroTier
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif // SDK_LWIP
|
||||||
|
|||||||
@@ -44,7 +44,6 @@
|
|||||||
|
|
||||||
#include "SDK_Debug.h"
|
#include "SDK_Debug.h"
|
||||||
#include "SDK_EthernetTap.hpp"
|
#include "SDK_EthernetTap.hpp"
|
||||||
#include "SDK_pico.hpp"
|
|
||||||
|
|
||||||
#include "pico_stack.h"
|
#include "pico_stack.h"
|
||||||
#include "pico_ipv4.h"
|
#include "pico_ipv4.h"
|
||||||
Reference in New Issue
Block a user