MERGE current "dev" into "netcon" -- should not affect netcon itself but will retest -- brings ZeroTier core up to 1.1.0

This commit is contained in:
Adam Ierymenko 2015-11-23 10:46:52 -08:00
commit a18336fa18
324 changed files with 23680 additions and 15524 deletions

View file

@ -104,11 +104,11 @@ uint32_t Arp::processIncomingArp(const void *arp,unsigned int len,void *response
return ip;
}
MAC Arp::query(const MAC &localMac,uint32_t ip,void *query,unsigned int &queryLen,MAC &queryDest)
MAC Arp::query(const MAC &localMac,uint32_t localIp,uint32_t targetIp,void *query,unsigned int &queryLen,MAC &queryDest)
{
const uint64_t now = OSUtils::now();
_ArpEntry &e = _cache[ip];
_ArpEntry &e = _cache[targetIp];
if ( ((e.mac)&&((now - e.lastResponseReceived) >= (ZT_ARP_EXPIRE / 3))) ||
((!e.mac)&&((now - e.lastQuerySent) >= ZT_ARP_QUERY_INTERVAL)) ) {
@ -116,9 +116,10 @@ MAC Arp::query(const MAC &localMac,uint32_t ip,void *query,unsigned int &queryLe
uint8_t *q = reinterpret_cast<uint8_t *>(query);
memcpy(q,ARP_REQUEST_HEADER,8); q += 8; // ARP request header information, always the same
localMac.copyTo(q,6); q += 6; // sending host address
memset(q,0,10); q += 10; // sending IP and target media address are ignored in requests
memcpy(q,&ip,4); // target IP address for resolution (IP already in big-endian byte order)
localMac.copyTo(q,6); q += 6; // sending host MAC address
memcpy(q,&localIp,4); q += 4; // sending host IP (IP already in big-endian byte order)
memset(q,0,6); q += 6; // sending zeros for target MAC address as thats what we want to find
memcpy(q,&targetIp,4); // target IP address for resolution (IP already in big-endian byte order)
queryLen = 28;
if (e.mac)
queryDest = e.mac; // confirmation query, send directly to address holder

View file

@ -129,13 +129,14 @@ public:
* MAC returned is non-null.
*
* @param localMac Local MAC address of host interface
* @param ip IP to look up
* @param localIp Local IP address of host interface
* @param targetIp IP to look up
* @param query Buffer for generated query -- MUST be a minimum of ZT_ARP_BUF_LENGTH in size
* @param queryLen Length of generated query, or set to 0 if no query generated
* @param queryDest Destination of query, or set to null if no query generated
* @return MAC or 0 if no cached entry for this IP
*/
MAC query(const MAC &localMac,uint32_t ip,void *query,unsigned int &queryLen,MAC &queryDest);
MAC query(const MAC &localMac,uint32_t localIp,uint32_t targetIp,void *query,unsigned int &queryLen,MAC &queryDest);
private:
struct _ArpEntry

View file

@ -206,7 +206,7 @@ skip_add_inetaddr:
bool OSUtils::readFile(const char *path,std::string &buf)
{
char tmp[4096];
char tmp[1024];
FILE *f = fopen(path,"rb");
if (f) {
for(;;) {

View file

@ -95,7 +95,6 @@ public:
static inline bool rm(const std::string &path) throw() { return rm(path.c_str()); }
static inline bool mkdir(const char *path)
throw()
{
#ifdef __WINDOWS__
if (::PathIsDirectoryA(path))

View file

@ -64,6 +64,12 @@
#include <netinet/in.h>
#include <netinet/tcp.h>
#if defined(__linux__) || defined(linux) || defined(__LINUX__) || defined(__linux)
#ifndef IPV6_DONTFRAG
#define IPV6_DONTFRAG 62
#endif
#endif
#define ZT_PHY_SOCKFD_TYPE int
#define ZT_PHY_SOCKFD_NULL (-1)
#define ZT_PHY_SOCKFD_VALID(s) ((s) > -1)
@ -364,6 +370,9 @@ public:
f = 1; setsockopt(s,IPPROTO_IPV6,IPV6_V6ONLY,(void *)&f,sizeof(f));
#ifdef IPV6_MTU_DISCOVER
f = 0; setsockopt(s,IPPROTO_IPV6,IPV6_MTU_DISCOVER,&f,sizeof(f));
#endif
#ifdef IPV6_DONTFRAG
f = 0; setsockopt(s,IPPROTO_IPV6,IPV6_DONTFRAG,&f,sizeof(f));
#endif
}
f = 0; setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(void *)&f,sizeof(f));
@ -413,6 +422,24 @@ public:
return (PhySocket *)&sws;
}
/**
* Set the IP TTL for the next outgoing packet (for IPv4 UDP sockets only)
*
* @param ttl New TTL (0 or >255 will set it to 255)
* @return True on success
*/
inline bool setIp4UdpTtl(PhySocket *sock,unsigned int ttl)
{
PhySocketImpl &sws = *(reinterpret_cast<PhySocketImpl *>(sock));
#if defined(_WIN32) || defined(_WIN64)
DWORD tmp = ((ttl == 0)||(ttl > 255)) ? 255 : (DWORD)ttl;
return (::setsockopt(sws.sock,IPPROTO_IP,IP_TTL,(const char *)&tmp,sizeof(tmp)) == 0);
#else
int tmp = ((ttl == 0)||(ttl > 255)) ? 255 : (int)ttl;
return (::setsockopt(sws.sock,IPPROTO_IP,IP_TTL,(void *)&tmp,sizeof(tmp)) == 0);
#endif
}
/**
* Send a UDP packet
*
@ -654,6 +681,36 @@ public:
return (PhySocket *)&sws;
}
/**
* Try to set buffer sizes as close to the given value as possible
*
* This will try the specified value and then lower values in 16K increments
* until one works.
*
* @param sock Socket
* @param bufferSize Desired buffer sizes
*/
inline void setBufferSizes(const PhySocket *sock,int bufferSize)
{
PhySocketImpl &sws = *(reinterpret_cast<PhySocketImpl *>(sock));
if (bufferSize > 0) {
int bs = bufferSize;
while (bs >= 65536) {
int tmpbs = bs;
if (::setsockopt(sws.sock,SOL_SOCKET,SO_RCVBUF,(const char *)&tmpbs,sizeof(tmpbs)) == 0)
break;
bs -= 16384;
}
bs = bufferSize;
while (bs >= 65536) {
int tmpbs = bs;
if (::setsockopt(sws.sock,SOL_SOCKET,SO_SNDBUF,(const char *)&tmpbs,sizeof(tmpbs)) == 0)
break;
bs -= 16384;
}
}
}
/**
* Attempt to send data to a stream socket (non-blocking)
*

View file

@ -46,8 +46,8 @@
#endif
#endif
#include "../ext/bin/miniupnpc/include/miniupnpc/miniupnpc.h"
#include "../ext/bin/miniupnpc/include/miniupnpc/upnpcommands.h"
#include "../ext/miniupnpc/miniupnpc.h"
#include "../ext/miniupnpc/upnpcommands.h"
namespace ZeroTier {
@ -81,7 +81,7 @@ public:
while (run) {
{
int upnpError = 0;
UPNPDev *devlist = upnpDiscover(2000,(const char *)0,(const char *)0,0,0,&upnpError);
UPNPDev *devlist = upnpDiscover(2000,(const char *)0,(const char *)0,0,0,0,&upnpError);
if (devlist) {
#ifdef ZT_UPNP_TRACE
{
@ -115,7 +115,7 @@ public:
Utils::snprintf(outport,sizeof(outport),"%u",tryPort);
int mapResult = 0;
if ((mapResult = UPNP_AddPortMapping(urls.controlURL,data.first.servicetype,outport,inport,lanaddr,"ZeroTier","UDP",(const char *)0,ZT_UPNP_LEASE_DURATION)) == UPNPCOMMAND_SUCCESS) {
if ((mapResult = UPNP_AddPortMapping(urls.controlURL,data.first.servicetype,outport,inport,lanaddr,"ZeroTier","UDP",(const char *)0,"0")) == UPNPCOMMAND_SUCCESS) {
#ifdef ZT_UPNP_TRACE
fprintf(stderr,"UPNPClient: reserved external port: %s"ZT_EOL_S,outport);
#endif

View file

@ -42,11 +42,6 @@
*/
#define ZT_UPNP_CLIENT_REFRESH_DELAY 600000
/**
* UPNP lease duration in seconds (as string)
*/
#define ZT_UPNP_LEASE_DURATION "3600"
namespace ZeroTier {
class UPNPClientImpl;

View file

@ -213,7 +213,7 @@ std::string WindowsEthernetTap::addNewPersistentTapDevice(const char *pathToInf,
Mutex::Lock _l(_systemDeviceManagementLock);
GUID classGuid;
char className[4096];
char className[1024];
if (!WINENV.SetupDiGetINFClassA(pathToInf,&classGuid,className,sizeof(className),(PDWORD)0)) {
return std::string("SetupDiGetINFClassA() failed -- unable to read zttap driver INF file");
}
@ -269,9 +269,9 @@ std::string WindowsEthernetTap::addNewPersistentTapDevice(const char *pathToInf,
std::string WindowsEthernetTap::destroyAllLegacyPersistentTapDevices()
{
char subkeyName[4096];
char subkeyClass[4096];
char data[4096];
char subkeyName[1024];
char subkeyClass[1024];
char data[1024];
std::set<std::string> instanceIdPathsToRemove;
{
@ -321,9 +321,9 @@ std::string WindowsEthernetTap::destroyAllLegacyPersistentTapDevices()
std::string WindowsEthernetTap::destroyAllPersistentTapDevices()
{
char subkeyName[4096];
char subkeyClass[4096];
char data[4096];
char subkeyName[1024];
char subkeyClass[1024];
char data[1024];
std::set<std::string> instanceIdPathsToRemove;
{
@ -479,9 +479,9 @@ WindowsEthernetTap::WindowsEthernetTap(
_initialized(false),
_enabled(true)
{
char subkeyName[4096];
char subkeyClass[4096];
char data[4096];
char subkeyName[1024];
char subkeyClass[1024];
char data[1024];
char tag[24];
std::string mySubkeyName;