polished some rough edges

This commit is contained in:
Joseph Henry
2016-10-20 17:26:37 -07:00
parent 3f69aba15f
commit f6a6f991e7
10 changed files with 360 additions and 650 deletions

View File

@@ -28,6 +28,8 @@
#ifndef SDK_LWIPSTACK_H
#define SDK_LWIPSTACK_H
#if defined (SDK_LWIP)
#include "lwip/mem.h"
#include "lwip/pbuf.h"
#include "lwip/ip_addr.h"
@@ -46,7 +48,6 @@
#define _GNU_SOURCE
#endif
//typedef ip_addr ip_addr_t;
struct tcp_pcb;
// lwip General Stack API
@@ -56,22 +57,6 @@ struct tcp_pcb;
#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
//#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
#define UDP_NEW_SIG void
#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_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_LOOPIF_INIT_SIG struct netif *netif
#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
#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,12 +136,19 @@ namespace ZeroTier {
#endif
}
#if defined(SDK_IPV6)
err_t (*_ethip6_output)(ETHIP6_OUTPUT_SIG);
void (*_nd6_tmr)(void);
void (*_netif_ip6_addr_set_state)(NETIF_IP6_ADDR_SET_STATE_SIG);
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 (*_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)();
@@ -178,7 +186,6 @@ namespace ZeroTier {
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);
@@ -218,14 +225,9 @@ namespace ZeroTier {
#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))&ethip6_output;
_ethernet_input = (err_t(*)(ETHERNET_INPUT_SIG))&ethernet_input;
_etharp_output = (err_t(*)(ETHARP_OUTPUT_SIG))&etharp_output;
_lwip_init = (void(*)(void))&lwip_init;
_tcp_write = (err_t(*)(TCP_WRITE_SIG))&tcp_write;
_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_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))&ethip6_output;
#endif
#if defined(SDK_IPV6)
_etharp_output = (err_t(*)(ETHARP_OUTPUT_SIG))&etharp_output;
#endif
#endif
#ifdef __DYNAMIC_LWIP__ // Use dynamically-loaded symbols (for use in normal desktop applications)
@@ -271,16 +285,22 @@ namespace ZeroTier {
DEBUG_ERROR("dlerror(): %s", dlerror());
_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");
_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");
#endif
// _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");
@@ -330,10 +350,7 @@ namespace ZeroTier {
}
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_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 __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_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 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 __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 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_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 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 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 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 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
#endif
#endif // SDK_LWIP