IPV6 update

This commit is contained in:
Joseph Henry
2016-09-28 16:46:30 -07:00
parent 3bd9561246
commit f3570584ce
619 changed files with 7019 additions and 193742 deletions

View File

@@ -83,7 +83,7 @@ extern "C" {
//#if defined(SDK_DEBUG)
#if DEBUG_LEVEL >= MSG_ERROR
#define DEBUG_ERROR(fmt, args...) fprintf(stderr, RED"ZT_ERROR: %20s:%4d:%20s: " fmt "\n"RESET, __FILENAME__, __LINE__, __FUNCTION__, ##args)
#define DEBUG_ERROR(fmt, args...) fprintf(stderr, RED "ZT_ERROR: %20s:%4d:%20s: " fmt "\n" RESET, __FILENAME__, __LINE__, __FUNCTION__, ##args)
#else
#define DEBUG_ERROR(fmt, args...)
#endif
@@ -93,7 +93,7 @@ extern "C" {
#define DEBUG_BLANK(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "ZT_INFO : %20s:%4d:" fmt "\n", __FILENAME__, __LINE__, __FUNCTION__, ##args))
#else
#define DEBUG_INFO(fmt, args...) fprintf(stderr, "ZT_INFO : %20s:%4d:%20s: " fmt "\n", __FILENAME__, __LINE__, __FUNCTION__, ##args)
#define DEBUG_ATTN(fmt, args...) fprintf(stderr, CYN"ZT_INFO : %20s:%4d:%20s: " fmt "\n"RESET, __FILENAME__, __LINE__, __FUNCTION__, ##args)
#define DEBUG_ATTN(fmt, args...) fprintf(stderr, CYN "ZT_INFO : %20s:%4d:%20s: " fmt "\n" RESET, __FILENAME__, __LINE__, __FUNCTION__, ##args)
#define DEBUG_BLANK(fmt, args...) fprintf(stderr, "ZT_INFO : %20s:%4d:" fmt "\n", __FILENAME__, __LINE__, ##args)
#endif
#else
@@ -104,7 +104,7 @@ extern "C" {
#if defined(__ANDROID__)
#define DEBUG_TRANS(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "ZT_TRANS : %20s:%4d:%20s: " fmt "\n", __FILENAME__, __LINE__, __FUNCTION__, ##args))
#else
#define DEBUG_TRANS(fmt, args...) fprintf(stderr, GRN"ZT_TRANS: %20s:%4d:%20s: " fmt "\n"RESET, __FILENAME__, __LINE__, __FUNCTION__, ##args)
#define DEBUG_TRANS(fmt, args...) fprintf(stderr, GRN "ZT_TRANS: %20s:%4d:%20s: " fmt "\n" RESET, __FILENAME__, __LINE__, __FUNCTION__, ##args)
#endif
#else
#define DEBUG_TRANS(fmt, args...)

View File

@@ -69,6 +69,8 @@
#include "SDK.h"
#include "SDK_Debug.h"
#include "Mutex.hpp"
//#if !defined(__IOS__) && !defined(__ANDROID__) && !defined(__UNITY_3D__) && !defined(__XCODE__)
// const ip_addr_t ip_addr_any = { IPADDR_ANY };
@@ -128,7 +130,7 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p)
Utils::ntoh((uint16_t)ethhdr->type),0,buf + sizeof(struct eth_hdr),totalLength - sizeof(struct eth_hdr));
return ERR_OK;
}
// ---------------------------------------------------------------------------
NetconEthernetTap::NetconEthernetTap(
@@ -243,16 +245,13 @@ bool NetconEthernetTap::addIp(const InetAddress &ip)
interface6.ip6_autoconfig_enabled = 1;
_mac.copyTo(interface6.hwaddr, interface6.hwaddr_len);
lwipstack->__netif_create_ip6_linklocal_address(&interface6, 1);
lwipstack->__netif_add(&interface6, NULL, tapif_init, lwipstack->_ethernet_input);
netif_ip6_addr_set_state(&interface6, 1, IP6_ADDR_TENTATIVE);
lwipstack->__netif_set_default(&interface6);
interface6.output_ip6 = lwipstack->_ethip6_output;
lwipstack->__netif_set_up(&interface6);
lwipstack->__netif_set_up(&interface6);
ip6_addr_copy(ip_2_ip6(interface6.ip6_addr[1]), addr6);
interface6.state = this;
}
}
@@ -285,18 +284,17 @@ void NetconEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherType
if (!_enabled)
return;
#if defined(LWIP_IPV6)
//#if defined(LWIP_IPV6)
DEBUG_EXTRA("IPV6");
DEBUG_EXTRA("sizeof(struct eth_hdr) = %d", sizeof(struct eth_hdr));
struct eth_hdr ethhdr;
from.copyTo(ethhdr.src.addr, 6);
to.copyTo(ethhdr.dest.addr, 6);
ethhdr.type = Utils::hton((uint16_t)etherType);
ethhdr.type = Utils::hton((uint16_t)etherType);
p = lwipstack->__pbuf_alloc(PBUF_RAW, len+sizeof(struct eth_hdr), PBUF_POOL);
if (p != NULL) {
DEBUG_EXTRA("p != NULL");
const char *dataptr = reinterpret_cast<const char *>(data);
// First pbuf gets ethernet header at start
q = p;
@@ -322,6 +320,7 @@ void NetconEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherType
}
// IPV4
/*
#elif defined(LWIP_IPV4)
DEBUG_EXTRA("IPV4");
struct eth_hdr ethhdr;
@@ -355,7 +354,7 @@ void NetconEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherType
return;
}
#endif
*/
{
if(interface6.input(p, &interface6) != ERR_OK) {
DEBUG_ERROR("error while RX of packet (netif->input)");

View File

@@ -444,7 +444,7 @@ namespace ZeroTier {
void phyOnTcpData(PhySocket *sock,void **uptr,void *data,unsigned long len);
void processReceivedData(PhySocket *sock,void **uptr,bool lwip_invoked);
void phyOnTcpWritable(PhySocket *sock,void **uptr,bool lwip_invoked);
void phyOnTcpWritable(PhySocket *sock,void **uptr);
/*
* Signals us to close the TcpConnection associated with this PhySocket

View File

@@ -39,11 +39,6 @@
#include "OSUtils.hpp"
#include "SDK_Debug.h"
#if defined(LWIP_VERSION_2) // 2.0.0
#else // 1.4.1
// #include "lwip/tcp_impl.h"
#endif
#include <stdio.h>
#include <dlfcn.h>
@@ -67,7 +62,6 @@ struct tcp_pcb;
#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
@@ -143,8 +137,7 @@ namespace ZeroTier {
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 (*_netif_set_addr)(NETIF_SET_ADDR_SIG);
void (*_lwip_init)();
err_t (*_tcp_write)(TCP_WRITE_SIG);
@@ -190,8 +183,9 @@ namespace ZeroTier {
void (*_netif_set_up)(NETIF_SET_UP_SIG);
void (*_netif_poll)(NETIF_POLL_SIG);
Mutex _lock;
Mutex _lock;
Mutex _lock_mem;
LWIPStack(const char* path) :
_libref(NULL)
{
@@ -368,18 +362,16 @@ namespace ZeroTier {
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); return _pbuf_alloc(layer,length,type); }
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); }

View File

@@ -443,10 +443,10 @@ namespace ZeroTier
closeConnection(sock);
}
void NetconEthernetTap::phyOnTcpWritable(PhySocket *sock,void **uptr, bool lwip_invoked)
void NetconEthernetTap::phyOnTcpWritable(PhySocket *sock,void **uptr/*, bool lwip_invoked*/)
{
DEBUG_INFO("sock=%p", (void*)&sock);
processReceivedData(sock,uptr,lwip_invoked);
processReceivedData(sock,uptr,true);
}
// RX data on stream socks and send back over client sock's underlying fd