mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-07 13:03:45 +02:00
Code formatting and similar.
This commit is contained in:
parent
d18c33d6df
commit
016d85b169
22 changed files with 918 additions and 683 deletions
|
@ -34,10 +34,10 @@ Global Options:
|
||||||
Commands:
|
Commands:
|
||||||
help Show this help
|
help Show this help
|
||||||
version Print version
|
version Print version
|
||||||
service Start a node (see below)
|
service Start node (see below)
|
||||||
status Show node status and configuration
|
status Show node status and configuration
|
||||||
join [-options] <network> Join a virtual network
|
join [-options] <network> Join a virtual network
|
||||||
-a <token> Join authorization token
|
-a <token> Token to submit to controller
|
||||||
-c <identity|fingerprint> Controller identity or fingerprint
|
-c <identity|fingerprint> Controller identity or fingerprint
|
||||||
leave <network> Leave a virtual network
|
leave <network> Leave a virtual network
|
||||||
networks List VL2 virtual networks
|
networks List VL2 virtual networks
|
||||||
|
|
|
@ -30,9 +30,14 @@ template<typename T>
|
||||||
class SharedPtr : public TriviallyCopyable
|
class SharedPtr : public TriviallyCopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ZT_INLINE SharedPtr() noexcept : m_ptr((T *)0) {}
|
ZT_INLINE SharedPtr() noexcept: m_ptr((T *)0)
|
||||||
explicit ZT_INLINE SharedPtr(T *obj) noexcept : m_ptr(obj) { if (likely(obj != nullptr)) ++*const_cast<std::atomic<int> *>(&(obj->__refCount)); }
|
{}
|
||||||
ZT_INLINE SharedPtr(const SharedPtr &sp) noexcept : m_ptr(sp._getAndInc()) {}
|
|
||||||
|
explicit ZT_INLINE SharedPtr(T *obj) noexcept: m_ptr(obj)
|
||||||
|
{ if (likely(obj != nullptr)) ++*const_cast<std::atomic< int > *>(&(obj->__refCount)); }
|
||||||
|
|
||||||
|
ZT_INLINE SharedPtr(const SharedPtr &sp) noexcept: m_ptr(sp._getAndInc())
|
||||||
|
{}
|
||||||
|
|
||||||
ZT_INLINE ~SharedPtr()
|
ZT_INLINE ~SharedPtr()
|
||||||
{
|
{
|
||||||
|
@ -77,7 +82,8 @@ public:
|
||||||
*
|
*
|
||||||
* @param ptr Pointer to set
|
* @param ptr Pointer to set
|
||||||
*/
|
*/
|
||||||
ZT_INLINE void unsafeSet(T *ptr) noexcept { m_ptr = ptr; }
|
ZT_INLINE void unsafeSet(T *ptr) noexcept
|
||||||
|
{ m_ptr = ptr; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Swap with another pointer 'for free' without ref count overhead
|
* Swap with another pointer 'for free' without ref count overhead
|
||||||
|
@ -109,15 +115,20 @@ public:
|
||||||
from.m_ptr = nullptr;
|
from.m_ptr = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZT_INLINE operator bool() const noexcept { return (m_ptr != nullptr); }
|
ZT_INLINE operator bool() const noexcept
|
||||||
|
{ return (m_ptr != nullptr); }
|
||||||
|
|
||||||
ZT_INLINE T &operator*() const noexcept { return *m_ptr; }
|
ZT_INLINE T &operator*() const noexcept
|
||||||
ZT_INLINE T *operator->() const noexcept { return m_ptr; }
|
{ return *m_ptr; }
|
||||||
|
|
||||||
|
ZT_INLINE T *operator->() const noexcept
|
||||||
|
{ return m_ptr; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Raw pointer to held object
|
* @return Raw pointer to held object
|
||||||
*/
|
*/
|
||||||
ZT_INLINE T *ptr() const noexcept { return m_ptr; }
|
ZT_INLINE T *ptr() const noexcept
|
||||||
|
{ return m_ptr; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set this pointer to NULL
|
* Set this pointer to NULL
|
||||||
|
@ -166,12 +177,23 @@ public:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZT_INLINE bool operator==(const SharedPtr &sp) const noexcept { return (m_ptr == sp.m_ptr); }
|
ZT_INLINE bool operator==(const SharedPtr &sp) const noexcept
|
||||||
ZT_INLINE bool operator!=(const SharedPtr &sp) const noexcept { return (m_ptr != sp.m_ptr); }
|
{ return (m_ptr == sp.m_ptr); }
|
||||||
ZT_INLINE bool operator>(const SharedPtr &sp) const noexcept { return (m_ptr > sp.m_ptr); }
|
|
||||||
ZT_INLINE bool operator<(const SharedPtr &sp) const noexcept { return (m_ptr < sp.m_ptr); }
|
ZT_INLINE bool operator!=(const SharedPtr &sp) const noexcept
|
||||||
ZT_INLINE bool operator>=(const SharedPtr &sp) const noexcept { return (m_ptr >= sp.m_ptr); }
|
{ return (m_ptr != sp.m_ptr); }
|
||||||
ZT_INLINE bool operator<=(const SharedPtr &sp) const noexcept { return (m_ptr <= sp.m_ptr); }
|
|
||||||
|
ZT_INLINE bool operator>(const SharedPtr &sp) const noexcept
|
||||||
|
{ return (m_ptr > sp.m_ptr); }
|
||||||
|
|
||||||
|
ZT_INLINE bool operator<(const SharedPtr &sp) const noexcept
|
||||||
|
{ return (m_ptr < sp.m_ptr); }
|
||||||
|
|
||||||
|
ZT_INLINE bool operator>=(const SharedPtr &sp) const noexcept
|
||||||
|
{ return (m_ptr >= sp.m_ptr); }
|
||||||
|
|
||||||
|
ZT_INLINE bool operator<=(const SharedPtr &sp) const noexcept
|
||||||
|
{ return (m_ptr <= sp.m_ptr); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ZT_INLINE T *_getAndInc() const noexcept
|
ZT_INLINE T *_getAndInc() const noexcept
|
||||||
|
@ -180,6 +202,7 @@ private:
|
||||||
++*const_cast<std::atomic< int > *>(&(m_ptr->__refCount));
|
++*const_cast<std::atomic< int > *>(&(m_ptr->__refCount));
|
||||||
return m_ptr;
|
return m_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
T *m_ptr;
|
T *m_ptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -187,7 +210,8 @@ private:
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
template< typename T >
|
template< typename T >
|
||||||
ZT_INLINE void swap(ZeroTier::SharedPtr<T> &a,ZeroTier::SharedPtr<T> &b) noexcept { a.swap(b); }
|
ZT_INLINE void swap(ZeroTier::SharedPtr< T > &a, ZeroTier::SharedPtr< T > &b) noexcept
|
||||||
|
{ a.swap(b); }
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
90
core/Tag.hpp
90
core/Tag.hpp
|
@ -48,9 +48,11 @@ class Tag : public Credential
|
||||||
friend class Credential;
|
friend class Credential;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static constexpr ZT_CredentialType credentialType() noexcept { return ZT_CREDENTIAL_TYPE_TAG; }
|
static constexpr ZT_CredentialType credentialType() noexcept
|
||||||
|
{ return ZT_CREDENTIAL_TYPE_TAG; }
|
||||||
|
|
||||||
ZT_INLINE Tag() noexcept { memoryZero(this); }
|
ZT_INLINE Tag() noexcept
|
||||||
|
{ memoryZero(this); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param nwid Network ID
|
* @param nwid Network ID
|
||||||
|
@ -70,14 +72,29 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ZT_INLINE uint32_t id() const noexcept { return m_id; }
|
ZT_INLINE uint32_t id() const noexcept
|
||||||
ZT_INLINE const uint32_t &value() const noexcept { return m_value; }
|
{ return m_id; }
|
||||||
ZT_INLINE uint64_t networkId() const noexcept { return m_networkId; }
|
|
||||||
ZT_INLINE int64_t timestamp() const noexcept { return m_ts; }
|
ZT_INLINE const uint32_t &value() const noexcept
|
||||||
ZT_INLINE const Address &issuedTo() const noexcept { return m_issuedTo; }
|
{ return m_value; }
|
||||||
ZT_INLINE const Address &signer() const noexcept { return m_signedBy; }
|
|
||||||
ZT_INLINE const uint8_t *signature() const noexcept { return m_signature; }
|
ZT_INLINE uint64_t networkId() const noexcept
|
||||||
ZT_INLINE unsigned int signatureLength() const noexcept { return m_signatureLength; }
|
{ return m_networkId; }
|
||||||
|
|
||||||
|
ZT_INLINE int64_t timestamp() const noexcept
|
||||||
|
{ return m_ts; }
|
||||||
|
|
||||||
|
ZT_INLINE const Address &issuedTo() const noexcept
|
||||||
|
{ return m_issuedTo; }
|
||||||
|
|
||||||
|
ZT_INLINE const Address &signer() const noexcept
|
||||||
|
{ return m_signedBy; }
|
||||||
|
|
||||||
|
ZT_INLINE const uint8_t *signature() const noexcept
|
||||||
|
{ return m_signature; }
|
||||||
|
|
||||||
|
ZT_INLINE unsigned int signatureLength() const noexcept
|
||||||
|
{ return m_signatureLength; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sign this tag
|
* Sign this tag
|
||||||
|
@ -93,30 +110,55 @@ public:
|
||||||
* @param RR Runtime environment to allow identity lookup for signedBy
|
* @param RR Runtime environment to allow identity lookup for signedBy
|
||||||
* @param tPtr Thread pointer to be handed through to any callbacks called as a result of this call
|
* @param tPtr Thread pointer to be handed through to any callbacks called as a result of this call
|
||||||
*/
|
*/
|
||||||
ZT_INLINE Credential::VerifyResult verify(const RuntimeEnvironment *RR,void *tPtr) const noexcept { return _verify(RR,tPtr,*this); }
|
ZT_INLINE Credential::VerifyResult verify(const RuntimeEnvironment *RR, void *tPtr) const noexcept
|
||||||
|
{ return _verify(RR, tPtr, *this); }
|
||||||
|
|
||||||
|
static constexpr int marshalSizeMax() noexcept
|
||||||
|
{ return ZT_TAG_MARSHAL_SIZE_MAX; }
|
||||||
|
|
||||||
static constexpr int marshalSizeMax() noexcept { return ZT_TAG_MARSHAL_SIZE_MAX; }
|
|
||||||
int marshal(uint8_t data[ZT_TAG_MARSHAL_SIZE_MAX], bool forSign = false) const noexcept;
|
int marshal(uint8_t data[ZT_TAG_MARSHAL_SIZE_MAX], bool forSign = false) const noexcept;
|
||||||
|
|
||||||
int unmarshal(const uint8_t *data, int len) noexcept;
|
int unmarshal(const uint8_t *data, int len) noexcept;
|
||||||
|
|
||||||
// Provides natural sort order by ID
|
// Provides natural sort order by ID
|
||||||
ZT_INLINE bool operator<(const Tag &t) const noexcept { return (m_id < t.m_id); }
|
ZT_INLINE bool operator<(const Tag &t) const noexcept
|
||||||
|
{ return (m_id < t.m_id); }
|
||||||
|
|
||||||
ZT_INLINE bool operator==(const Tag &t) const noexcept { return (memcmp(this,&t,sizeof(Tag)) == 0); }
|
ZT_INLINE bool operator==(const Tag &t) const noexcept
|
||||||
ZT_INLINE bool operator!=(const Tag &t) const noexcept { return (memcmp(this,&t,sizeof(Tag)) != 0); }
|
{ return (memcmp(this, &t, sizeof(Tag)) == 0); }
|
||||||
|
|
||||||
|
ZT_INLINE bool operator!=(const Tag &t) const noexcept
|
||||||
|
{ return (memcmp(this, &t, sizeof(Tag)) != 0); }
|
||||||
|
|
||||||
// For searching sorted arrays or lists of Tags by ID
|
// For searching sorted arrays or lists of Tags by ID
|
||||||
struct IdComparePredicate
|
struct IdComparePredicate
|
||||||
{
|
{
|
||||||
ZT_INLINE bool operator()(const Tag &a,const Tag &b) const noexcept { return (a.id() < b.id()); }
|
ZT_INLINE bool operator()(const Tag &a, const Tag &b) const noexcept
|
||||||
ZT_INLINE bool operator()(const uint32_t a,const Tag &b) const noexcept { return (a < b.id()); }
|
{ return (a.id() < b.id()); }
|
||||||
ZT_INLINE bool operator()(const Tag &a,const uint32_t b) const noexcept { return (a.id() < b); }
|
|
||||||
ZT_INLINE bool operator()(const Tag *a,const Tag *b) const noexcept { return (a->id() < b->id()); }
|
ZT_INLINE bool operator()(const uint32_t a, const Tag &b) const noexcept
|
||||||
ZT_INLINE bool operator()(const Tag *a,const Tag &b) const noexcept { return (a->id() < b.id()); }
|
{ return (a < b.id()); }
|
||||||
ZT_INLINE bool operator()(const Tag &a,const Tag *b) const noexcept { return (a.id() < b->id()); }
|
|
||||||
ZT_INLINE bool operator()(const uint32_t a,const Tag *b) const noexcept { return (a < b->id()); }
|
ZT_INLINE bool operator()(const Tag &a, const uint32_t b) const noexcept
|
||||||
ZT_INLINE bool operator()(const Tag *a,const uint32_t b) const noexcept { return (a->id() < b); }
|
{ return (a.id() < b); }
|
||||||
ZT_INLINE bool operator()(const uint32_t a,const uint32_t b) const noexcept { return (a < b); }
|
|
||||||
|
ZT_INLINE bool operator()(const Tag *a, const Tag *b) const noexcept
|
||||||
|
{ return (a->id() < b->id()); }
|
||||||
|
|
||||||
|
ZT_INLINE bool operator()(const Tag *a, const Tag &b) const noexcept
|
||||||
|
{ return (a->id() < b.id()); }
|
||||||
|
|
||||||
|
ZT_INLINE bool operator()(const Tag &a, const Tag *b) const noexcept
|
||||||
|
{ return (a.id() < b->id()); }
|
||||||
|
|
||||||
|
ZT_INLINE bool operator()(const uint32_t a, const Tag *b) const noexcept
|
||||||
|
{ return (a < b->id()); }
|
||||||
|
|
||||||
|
ZT_INLINE bool operator()(const Tag *a, const uint32_t b) const noexcept
|
||||||
|
{ return (a->id() < b); }
|
||||||
|
|
||||||
|
ZT_INLINE bool operator()(const uint32_t a, const uint32_t b) const noexcept
|
||||||
|
{ return (a < b); }
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -208,7 +208,9 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void m_loadCached(void *tPtr, const Address &zta, SharedPtr< Peer > &peer);
|
void m_loadCached(void *tPtr, const Address &zta, SharedPtr< Peer > &peer);
|
||||||
|
|
||||||
void m_writeRootList(void *tPtr);
|
void m_writeRootList(void *tPtr);
|
||||||
|
|
||||||
void m_updateRootPeers(void *tPtr);
|
void m_updateRootPeers(void *tPtr);
|
||||||
|
|
||||||
// This gets an integer key from an InetAddress for looking up paths.
|
// This gets an integer key from an InetAddress for looking up paths.
|
||||||
|
|
|
@ -17,9 +17,11 @@
|
||||||
#include "SHA512.hpp"
|
#include "SHA512.hpp"
|
||||||
|
|
||||||
#ifdef __UNIX_LIKE__
|
#ifdef __UNIX_LIKE__
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
@ -33,6 +35,7 @@ namespace ZeroTier {
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
#ifdef ZT_ARCH_X64
|
#ifdef ZT_ARCH_X64
|
||||||
|
|
||||||
CPUIDRegisters::CPUIDRegisters() noexcept
|
CPUIDRegisters::CPUIDRegisters() noexcept
|
||||||
{
|
{
|
||||||
uint32_t eax, ebx, ecx, edx;
|
uint32_t eax, ebx, ecx, edx;
|
||||||
|
@ -77,6 +80,7 @@ CPUIDRegisters::CPUIDRegisters() noexcept
|
||||||
sha = ((ebx & (1U << 29U)) != 0);
|
sha = ((ebx & (1U << 29U)) != 0);
|
||||||
fsrm = sha = ((edx & (1U << 4U)) != 0);
|
fsrm = sha = ((edx & (1U << 4U)) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
const CPUIDRegisters CPUID;
|
const CPUIDRegisters CPUID;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -98,8 +102,11 @@ static void _Utils_doBurn(volatile uint8_t *ptr,unsigned int len)
|
||||||
for (unsigned int i = 0; i < len; ++i)
|
for (unsigned int i = 0; i < len; ++i)
|
||||||
ptr[i] = 0;
|
ptr[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void (*volatile _Utils_doBurn_ptr)(volatile uint8_t *, unsigned int) = _Utils_doBurn;
|
static void (*volatile _Utils_doBurn_ptr)(volatile uint8_t *, unsigned int) = _Utils_doBurn;
|
||||||
void burn(void *ptr,unsigned int len) { (_Utils_doBurn_ptr)((volatile uint8_t *)ptr,len); }
|
|
||||||
|
void burn(void *ptr, unsigned int len)
|
||||||
|
{ (_Utils_doBurn_ptr)((volatile uint8_t *)ptr, len); }
|
||||||
|
|
||||||
static unsigned long _Utils_itoa(unsigned long n, char *s)
|
static unsigned long _Utils_itoa(unsigned long n, char *s)
|
||||||
{
|
{
|
||||||
|
@ -111,6 +118,7 @@ static unsigned long _Utils_itoa(unsigned long n,char *s)
|
||||||
s[pos] = (char)('0' + (n % 10));
|
s[pos] = (char)('0' + (n % 10));
|
||||||
return pos + 1;
|
return pos + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *decimal(unsigned long n, char s[24]) noexcept
|
char *decimal(unsigned long n, char s[24]) noexcept
|
||||||
{
|
{
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
|
|
178
core/Utils.hpp
178
core/Utils.hpp
|
@ -25,7 +25,9 @@ namespace ZeroTier {
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
#ifndef __WINDOWS__
|
#ifndef __WINDOWS__
|
||||||
|
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Macros to convert endian-ness at compile time for constants.
|
// Macros to convert endian-ness at compile time for constants.
|
||||||
|
@ -51,9 +53,11 @@ namespace Utils {
|
||||||
#define ZT_ROL32(x, r) (((x) << (r)) | ((x) >> (32 - (r))))
|
#define ZT_ROL32(x, r) (((x) << (r)) | ((x) >> (32 - (r))))
|
||||||
|
|
||||||
#ifdef ZT_ARCH_X64
|
#ifdef ZT_ARCH_X64
|
||||||
|
|
||||||
struct CPUIDRegisters
|
struct CPUIDRegisters
|
||||||
{
|
{
|
||||||
CPUIDRegisters() noexcept;
|
CPUIDRegisters() noexcept;
|
||||||
|
|
||||||
bool rdrand;
|
bool rdrand;
|
||||||
bool aes;
|
bool aes;
|
||||||
bool avx;
|
bool avx;
|
||||||
|
@ -64,6 +68,7 @@ struct CPUIDRegisters
|
||||||
bool sha;
|
bool sha;
|
||||||
bool fsrm;
|
bool fsrm;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const CPUIDRegisters CPUID;
|
extern const CPUIDRegisters CPUID;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -337,10 +342,19 @@ static ZT_INLINE uint32_t fnv1a32(const void *const data,const unsigned int len)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
static ZT_INLINE unsigned int countBits(const uint8_t v) noexcept { return (unsigned int)__builtin_popcount((unsigned int)v); }
|
|
||||||
static ZT_INLINE unsigned int countBits(const uint16_t v) noexcept { return (unsigned int)__builtin_popcount((unsigned int)v); }
|
static ZT_INLINE unsigned int countBits(const uint8_t v) noexcept
|
||||||
static ZT_INLINE unsigned int countBits(const uint32_t v) noexcept { return (unsigned int)__builtin_popcountl((unsigned long)v); }
|
{ return (unsigned int)__builtin_popcount((unsigned int)v); }
|
||||||
static ZT_INLINE unsigned int countBits(const uint64_t v) noexcept{ return (unsigned int)__builtin_popcountll((unsigned long long)v); }
|
|
||||||
|
static ZT_INLINE unsigned int countBits(const uint16_t v) noexcept
|
||||||
|
{ return (unsigned int)__builtin_popcount((unsigned int)v); }
|
||||||
|
|
||||||
|
static ZT_INLINE unsigned int countBits(const uint32_t v) noexcept
|
||||||
|
{ return (unsigned int)__builtin_popcountl((unsigned long)v); }
|
||||||
|
|
||||||
|
static ZT_INLINE unsigned int countBits(const uint64_t v) noexcept
|
||||||
|
{ return (unsigned int)__builtin_popcountll((unsigned long long)v); }
|
||||||
|
|
||||||
#else
|
#else
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static ZT_INLINE unsigned int countBits(T v) noexcept
|
static ZT_INLINE unsigned int countBits(T v) noexcept
|
||||||
|
@ -422,34 +436,108 @@ static ZT_INLINE uint16_t swapBytes(const uint16_t n) noexcept
|
||||||
// to work with all typedef'd variants, signed/unsigned, etc.
|
// to work with all typedef'd variants, signed/unsigned, etc.
|
||||||
template< typename I, unsigned int S >
|
template< typename I, unsigned int S >
|
||||||
class _swap_bytes_bysize;
|
class _swap_bytes_bysize;
|
||||||
|
|
||||||
template< typename I >
|
template< typename I >
|
||||||
class _swap_bytes_bysize<I,1> { public: static ZT_INLINE I s(const I n) noexcept { return n; } };
|
class _swap_bytes_bysize< I, 1 >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static ZT_INLINE I s(const I n) noexcept
|
||||||
|
{ return n; }
|
||||||
|
};
|
||||||
|
|
||||||
template< typename I >
|
template< typename I >
|
||||||
class _swap_bytes_bysize<I,2> { public: static ZT_INLINE I s(const I n) noexcept { return (I)swapBytes((uint16_t)n); } };
|
class _swap_bytes_bysize< I, 2 >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static ZT_INLINE I s(const I n) noexcept
|
||||||
|
{ return (I)swapBytes((uint16_t)n); }
|
||||||
|
};
|
||||||
|
|
||||||
template< typename I >
|
template< typename I >
|
||||||
class _swap_bytes_bysize<I,4> { public: static ZT_INLINE I s(const I n) noexcept { return (I)swapBytes((uint32_t)n); } };
|
class _swap_bytes_bysize< I, 4 >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static ZT_INLINE I s(const I n) noexcept
|
||||||
|
{ return (I)swapBytes((uint32_t)n); }
|
||||||
|
};
|
||||||
|
|
||||||
template< typename I >
|
template< typename I >
|
||||||
class _swap_bytes_bysize<I,8> { public: static ZT_INLINE I s(const I n) noexcept { return (I)swapBytes((uint64_t)n); } };
|
class _swap_bytes_bysize< I, 8 >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static ZT_INLINE I s(const I n) noexcept
|
||||||
|
{ return (I)swapBytes((uint64_t)n); }
|
||||||
|
};
|
||||||
|
|
||||||
template< typename I, unsigned int S >
|
template< typename I, unsigned int S >
|
||||||
class _load_be_bysize;
|
class _load_be_bysize;
|
||||||
|
|
||||||
template< typename I >
|
template< typename I >
|
||||||
class _load_be_bysize<I,1> { public: static ZT_INLINE I l(const uint8_t *const p) noexcept { return p[0]; }};
|
class _load_be_bysize< I, 1 >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static ZT_INLINE I l(const uint8_t *const p) noexcept
|
||||||
|
{ return p[0]; }
|
||||||
|
};
|
||||||
|
|
||||||
template< typename I >
|
template< typename I >
|
||||||
class _load_be_bysize<I,2> { public: static ZT_INLINE I l(const uint8_t *const p) noexcept { return (I)(((unsigned int)p[0] << 8U) | (unsigned int)p[1]); }};
|
class _load_be_bysize< I, 2 >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static ZT_INLINE I l(const uint8_t *const p) noexcept
|
||||||
|
{ return (I)(((unsigned int)p[0] << 8U) | (unsigned int)p[1]); }
|
||||||
|
};
|
||||||
|
|
||||||
template< typename I >
|
template< typename I >
|
||||||
class _load_be_bysize<I,4> { public: static ZT_INLINE I l(const uint8_t *const p) noexcept { return (I)(((uint32_t)p[0] << 24U) | ((uint32_t)p[1] << 16U) | ((uint32_t)p[2] << 8U) | (uint32_t)p[3]); }};
|
class _load_be_bysize< I, 4 >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static ZT_INLINE I l(const uint8_t *const p) noexcept
|
||||||
|
{ return (I)(((uint32_t)p[0] << 24U) | ((uint32_t)p[1] << 16U) | ((uint32_t)p[2] << 8U) | (uint32_t)p[3]); }
|
||||||
|
};
|
||||||
|
|
||||||
template< typename I >
|
template< typename I >
|
||||||
class _load_be_bysize<I,8> { public: static ZT_INLINE I l(const uint8_t *const p) noexcept { return (I)(((uint64_t)p[0] << 56U) | ((uint64_t)p[1] << 48U) | ((uint64_t)p[2] << 40U) | ((uint64_t)p[3] << 32U) | ((uint64_t)p[4] << 24U) | ((uint64_t)p[5] << 16U) | ((uint64_t)p[6] << 8U) | (uint64_t)p[7]); }};
|
class _load_be_bysize< I, 8 >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static ZT_INLINE I l(const uint8_t *const p) noexcept
|
||||||
|
{ return (I)(((uint64_t)p[0] << 56U) | ((uint64_t)p[1] << 48U) | ((uint64_t)p[2] << 40U) | ((uint64_t)p[3] << 32U) | ((uint64_t)p[4] << 24U) | ((uint64_t)p[5] << 16U) | ((uint64_t)p[6] << 8U) | (uint64_t)p[7]); }
|
||||||
|
};
|
||||||
|
|
||||||
template< typename I, unsigned int S >
|
template< typename I, unsigned int S >
|
||||||
class _load_le_bysize;
|
class _load_le_bysize;
|
||||||
|
|
||||||
template< typename I >
|
template< typename I >
|
||||||
class _load_le_bysize<I,1> { public: static ZT_INLINE I l(const uint8_t *const p) noexcept { return p[0]; }};
|
class _load_le_bysize< I, 1 >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static ZT_INLINE I l(const uint8_t *const p) noexcept
|
||||||
|
{ return p[0]; }
|
||||||
|
};
|
||||||
|
|
||||||
template< typename I >
|
template< typename I >
|
||||||
class _load_le_bysize<I,2> { public: static ZT_INLINE I l(const uint8_t *const p) noexcept { return (I)((unsigned int)p[0] | ((unsigned int)p[1] << 8U)); }};
|
class _load_le_bysize< I, 2 >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static ZT_INLINE I l(const uint8_t *const p) noexcept
|
||||||
|
{ return (I)((unsigned int)p[0] | ((unsigned int)p[1] << 8U)); }
|
||||||
|
};
|
||||||
|
|
||||||
template< typename I >
|
template< typename I >
|
||||||
class _load_le_bysize<I,4> { public: static ZT_INLINE I l(const uint8_t *const p) noexcept { return (I)((uint32_t)p[0] | ((uint32_t)p[1] << 8U) | ((uint32_t)p[2] << 16U) | ((uint32_t)p[3] << 24U)); }};
|
class _load_le_bysize< I, 4 >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static ZT_INLINE I l(const uint8_t *const p) noexcept
|
||||||
|
{ return (I)((uint32_t)p[0] | ((uint32_t)p[1] << 8U) | ((uint32_t)p[2] << 16U) | ((uint32_t)p[3] << 24U)); }
|
||||||
|
};
|
||||||
|
|
||||||
template< typename I >
|
template< typename I >
|
||||||
class _load_le_bysize<I,8> { public: static ZT_INLINE I l(const uint8_t *const p) noexcept { return (I)((uint64_t)p[0] | ((uint64_t)p[1] << 8U) | ((uint64_t)p[2] << 16U) | ((uint64_t)p[3] << 24U) | ((uint64_t)p[4] << 32U) | ((uint64_t)p[5] << 40U) | ((uint64_t)p[6] << 48U) | ((uint64_t)p[7]) << 56U); }};
|
class _load_le_bysize< I, 8 >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static ZT_INLINE I l(const uint8_t *const p) noexcept
|
||||||
|
{ return (I)((uint64_t)p[0] | ((uint64_t)p[1] << 8U) | ((uint64_t)p[2] << 16U) | ((uint64_t)p[3] << 24U) | ((uint64_t)p[4] << 32U) | ((uint64_t)p[5] << 40U) | ((uint64_t)p[6] << 48U) | ((uint64_t)p[7]) << 56U); }
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert any signed or unsigned integer type to big-endian ("network") byte order
|
* Convert any signed or unsigned integer type to big-endian ("network") byte order
|
||||||
|
@ -664,7 +752,8 @@ static ZT_INLINE void copy(void *const dest,const void *const src) noexcept
|
||||||
* @param src Source memory
|
* @param src Source memory
|
||||||
* @param len Bytes to copy
|
* @param len Bytes to copy
|
||||||
*/
|
*/
|
||||||
static ZT_INLINE void copy(void *const dest,const void *const src,unsigned int len) noexcept { memcpy(dest,src,len); }
|
static ZT_INLINE void copy(void *const dest, const void *const src, unsigned int len) noexcept
|
||||||
|
{ memcpy(dest, src, len); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Zero memory block whose size is known at compile time
|
* Zero memory block whose size is known at compile time
|
||||||
|
@ -720,7 +809,8 @@ static ZT_INLINE void zero(void *const dest) noexcept
|
||||||
* @param dest Memory to zero
|
* @param dest Memory to zero
|
||||||
* @param len Size in bytes
|
* @param len Size in bytes
|
||||||
*/
|
*/
|
||||||
static ZT_INLINE void zero(void *const dest,const unsigned int len) noexcept { memset(dest,0,len); }
|
static ZT_INLINE void zero(void *const dest, const unsigned int len) noexcept
|
||||||
|
{ memset(dest, 0, len); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple malloc/free based C++ STL allocator.
|
* Simple malloc/free based C++ STL allocator.
|
||||||
|
@ -742,11 +832,23 @@ struct Mallocator
|
||||||
typedef const T &const_reference;
|
typedef const T &const_reference;
|
||||||
typedef T value_type;
|
typedef T value_type;
|
||||||
|
|
||||||
template <class U> struct rebind { typedef Mallocator<U> other; };
|
template< class U >
|
||||||
ZT_INLINE Mallocator() noexcept {}
|
struct rebind
|
||||||
ZT_INLINE Mallocator(const Mallocator&) noexcept {}
|
{
|
||||||
template <class U> ZT_INLINE Mallocator(const Mallocator<U>&) noexcept {}
|
typedef Mallocator< U > other;
|
||||||
ZT_INLINE ~Mallocator() noexcept {}
|
};
|
||||||
|
ZT_INLINE Mallocator() noexcept
|
||||||
|
{}
|
||||||
|
|
||||||
|
ZT_INLINE Mallocator(const Mallocator &) noexcept
|
||||||
|
{}
|
||||||
|
|
||||||
|
template< class U >
|
||||||
|
ZT_INLINE Mallocator(const Mallocator< U > &) noexcept
|
||||||
|
{}
|
||||||
|
|
||||||
|
ZT_INLINE ~Mallocator() noexcept
|
||||||
|
{}
|
||||||
|
|
||||||
ZT_INLINE pointer allocate(size_type s, void const * = nullptr)
|
ZT_INLINE pointer allocate(size_type s, void const * = nullptr)
|
||||||
{
|
{
|
||||||
|
@ -758,15 +860,29 @@ struct Mallocator
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZT_INLINE pointer address(reference x) const { return &x; }
|
ZT_INLINE pointer address(reference x) const
|
||||||
ZT_INLINE const_pointer address(const_reference x) const { return &x; }
|
{ return &x; }
|
||||||
ZT_INLINE void deallocate(pointer p,size_type) { free(p); }
|
|
||||||
ZT_INLINE size_type max_size() const noexcept { return std::numeric_limits<size_t>::max() / sizeof(T); }
|
|
||||||
ZT_INLINE void construct(pointer p,const T& val) { new((void *)p) T(val); }
|
|
||||||
ZT_INLINE void destroy(pointer p) { p->~T(); }
|
|
||||||
|
|
||||||
constexpr bool operator==(const Mallocator &) const noexcept { return true; }
|
ZT_INLINE const_pointer address(const_reference x) const
|
||||||
constexpr bool operator!=(const Mallocator &) const noexcept { return false; }
|
{ return &x; }
|
||||||
|
|
||||||
|
ZT_INLINE void deallocate(pointer p, size_type)
|
||||||
|
{ free(p); }
|
||||||
|
|
||||||
|
ZT_INLINE size_type max_size() const noexcept
|
||||||
|
{ return std::numeric_limits< size_t >::max() / sizeof(T); }
|
||||||
|
|
||||||
|
ZT_INLINE void construct(pointer p, const T &val)
|
||||||
|
{ new((void *)p) T(val); }
|
||||||
|
|
||||||
|
ZT_INLINE void destroy(pointer p)
|
||||||
|
{ p->~T(); }
|
||||||
|
|
||||||
|
constexpr bool operator==(const Mallocator &) const noexcept
|
||||||
|
{ return true; }
|
||||||
|
|
||||||
|
constexpr bool operator!=(const Mallocator &) const noexcept
|
||||||
|
{ return false; }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
|
12
core/VL1.cpp
12
core/VL1.cpp
|
@ -254,7 +254,8 @@ void VL1::onRemotePacket(void *const tPtr, const int64_t localSocket, const Inet
|
||||||
}
|
}
|
||||||
|
|
||||||
auth = ZT_VL1_AUTH_RESULT_FLAG_AUTHENTICATED;
|
auth = ZT_VL1_AUTH_RESULT_FLAG_AUTHENTICATED;
|
||||||
} break;
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case ZT_PROTO_CIPHER_SUITE__POLY1305_SALSA2012: {
|
case ZT_PROTO_CIPHER_SUITE__POLY1305_SALSA2012: {
|
||||||
uint8_t perPacketKey[ZT_SALSA20_KEY_SIZE];
|
uint8_t perPacketKey[ZT_SALSA20_KEY_SIZE];
|
||||||
|
@ -277,15 +278,18 @@ void VL1::onRemotePacket(void *const tPtr, const int64_t localSocket, const Inet
|
||||||
}
|
}
|
||||||
|
|
||||||
auth = ZT_VL1_AUTH_RESULT_FLAG_AUTHENTICATED | ZT_VL1_AUTH_RESULT_FLAG_ENCRYPTED;
|
auth = ZT_VL1_AUTH_RESULT_FLAG_AUTHENTICATED | ZT_VL1_AUTH_RESULT_FLAG_ENCRYPTED;
|
||||||
} break;
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case ZT_PROTO_CIPHER_SUITE__NONE: {
|
case ZT_PROTO_CIPHER_SUITE__NONE: {
|
||||||
// TODO
|
// TODO
|
||||||
} break;
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case ZT_PROTO_CIPHER_SUITE__AES_GMAC_SIV: {
|
case ZT_PROTO_CIPHER_SUITE__AES_GMAC_SIV: {
|
||||||
// TODO
|
// TODO
|
||||||
} break;
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
RR->t->incomingPacketDropped(tPtr, 0x5b001099, packetId, 0, identityFromPeerPtr(peer), path->address(), hops, Protocol::VERB_NOP, ZT_TRACE_PACKET_DROP_REASON_INVALID_OBJECT);
|
RR->t->incomingPacketDropped(tPtr, 0x5b001099, packetId, 0, identityFromPeerPtr(peer), path->address(), hops, Protocol::VERB_NOP, ZT_TRACE_PACKET_DROP_REASON_INVALID_OBJECT);
|
||||||
|
|
15
core/VL1.hpp
15
core/VL1.hpp
|
@ -32,7 +32,9 @@
|
||||||
namespace ZeroTier {
|
namespace ZeroTier {
|
||||||
|
|
||||||
class RuntimeEnvironment;
|
class RuntimeEnvironment;
|
||||||
|
|
||||||
class Peer;
|
class Peer;
|
||||||
|
|
||||||
class VL2;
|
class VL2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -66,17 +68,25 @@ private:
|
||||||
const RuntimeEnvironment *RR;
|
const RuntimeEnvironment *RR;
|
||||||
|
|
||||||
void m_relay(void *tPtr, const SharedPtr< Path > &path, Address destination, SharedPtr< Buf > &pkt, int pktSize);
|
void m_relay(void *tPtr, const SharedPtr< Path > &path, Address destination, SharedPtr< Buf > &pkt, int pktSize);
|
||||||
|
|
||||||
void m_sendPendingWhois(void *tPtr, int64_t now);
|
void m_sendPendingWhois(void *tPtr, int64_t now);
|
||||||
|
|
||||||
SharedPtr< Peer > m_HELLO(void *tPtr, const SharedPtr< Path > &path, Buf &pkt, int packetSize);
|
SharedPtr< Peer > m_HELLO(void *tPtr, const SharedPtr< Path > &path, Buf &pkt, int packetSize);
|
||||||
|
|
||||||
bool m_ERROR(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, const SharedPtr< Peer > &peer, Buf &pkt, int packetSize, Protocol::Verb &inReVerb);
|
bool m_ERROR(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, const SharedPtr< Peer > &peer, Buf &pkt, int packetSize, Protocol::Verb &inReVerb);
|
||||||
|
|
||||||
bool m_OK(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, const SharedPtr< Peer > &peer, Buf &pkt, int packetSize, Protocol::Verb &inReVerb);
|
bool m_OK(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, const SharedPtr< Peer > &peer, Buf &pkt, int packetSize, Protocol::Verb &inReVerb);
|
||||||
|
|
||||||
bool m_WHOIS(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, const SharedPtr< Peer > &peer, Buf &pkt, int packetSize);
|
bool m_WHOIS(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, const SharedPtr< Peer > &peer, Buf &pkt, int packetSize);
|
||||||
|
|
||||||
bool m_RENDEZVOUS(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, const SharedPtr< Peer > &peer, Buf &pkt, int packetSize);
|
bool m_RENDEZVOUS(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, const SharedPtr< Peer > &peer, Buf &pkt, int packetSize);
|
||||||
|
|
||||||
bool m_ECHO(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, const SharedPtr< Peer > &peer, Buf &pkt, int packetSize);
|
bool m_ECHO(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, const SharedPtr< Peer > &peer, Buf &pkt, int packetSize);
|
||||||
|
|
||||||
bool m_PUSH_DIRECT_PATHS(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, const SharedPtr< Peer > &peer, Buf &pkt, int packetSize);
|
bool m_PUSH_DIRECT_PATHS(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, const SharedPtr< Peer > &peer, Buf &pkt, int packetSize);
|
||||||
|
|
||||||
bool m_USER_MESSAGE(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, const SharedPtr< Peer > &peer, Buf &pkt, int packetSize);
|
bool m_USER_MESSAGE(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, const SharedPtr< Peer > &peer, Buf &pkt, int packetSize);
|
||||||
|
|
||||||
bool m_ENCAP(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, const SharedPtr< Peer > &peer, Buf &pkt, int packetSize);
|
bool m_ENCAP(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, const SharedPtr< Peer > &peer, Buf &pkt, int packetSize);
|
||||||
|
|
||||||
// Defragmentation engine for handling inbound packets with more than one fragment.
|
// Defragmentation engine for handling inbound packets with more than one fragment.
|
||||||
|
@ -85,13 +95,16 @@ private:
|
||||||
// Queue of outbound WHOIS reqeusts and packets waiting on them.
|
// Queue of outbound WHOIS reqeusts and packets waiting on them.
|
||||||
struct p_WhoisQueueItem
|
struct p_WhoisQueueItem
|
||||||
{
|
{
|
||||||
ZT_INLINE p_WhoisQueueItem() : lastRetry(0),retries(0),waitingPacketCount(0) {}
|
ZT_INLINE p_WhoisQueueItem() : lastRetry(0), retries(0), waitingPacketCount(0)
|
||||||
|
{}
|
||||||
|
|
||||||
int64_t lastRetry;
|
int64_t lastRetry;
|
||||||
unsigned int retries;
|
unsigned int retries;
|
||||||
unsigned int waitingPacketCount;
|
unsigned int waitingPacketCount;
|
||||||
unsigned int waitingPacketSize[ZT_VL1_MAX_WHOIS_WAITING_PACKETS];
|
unsigned int waitingPacketSize[ZT_VL1_MAX_WHOIS_WAITING_PACKETS];
|
||||||
SharedPtr< Buf > waitingPacket[ZT_VL1_MAX_WHOIS_WAITING_PACKETS];
|
SharedPtr< Buf > waitingPacket[ZT_VL1_MAX_WHOIS_WAITING_PACKETS];
|
||||||
};
|
};
|
||||||
|
|
||||||
Map< Address, p_WhoisQueueItem > m_whoisQueue;
|
Map< Address, p_WhoisQueueItem > m_whoisQueue;
|
||||||
Mutex m_whoisQueue_l;
|
Mutex m_whoisQueue_l;
|
||||||
};
|
};
|
||||||
|
|
13
core/VL2.hpp
13
core/VL2.hpp
|
@ -25,10 +25,15 @@
|
||||||
namespace ZeroTier {
|
namespace ZeroTier {
|
||||||
|
|
||||||
class Path;
|
class Path;
|
||||||
|
|
||||||
class Peer;
|
class Peer;
|
||||||
|
|
||||||
class RuntimeEnvironment;
|
class RuntimeEnvironment;
|
||||||
|
|
||||||
class VL1;
|
class VL1;
|
||||||
|
|
||||||
class Network;
|
class Network;
|
||||||
|
|
||||||
class MAC;
|
class MAC;
|
||||||
|
|
||||||
class VL2
|
class VL2
|
||||||
|
@ -54,13 +59,21 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool m_FRAME(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, SharedPtr< Peer > &peer, Buf &pkt, int packetSize);
|
bool m_FRAME(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, SharedPtr< Peer > &peer, Buf &pkt, int packetSize);
|
||||||
|
|
||||||
bool m_EXT_FRAME(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, SharedPtr< Peer > &peer, Buf &pkt, int packetSize);
|
bool m_EXT_FRAME(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, SharedPtr< Peer > &peer, Buf &pkt, int packetSize);
|
||||||
|
|
||||||
bool m_MULTICAST_LIKE(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, SharedPtr< Peer > &peer, Buf &pkt, int packetSize);
|
bool m_MULTICAST_LIKE(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, SharedPtr< Peer > &peer, Buf &pkt, int packetSize);
|
||||||
|
|
||||||
bool m_NETWORK_CREDENTIALS(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, SharedPtr< Peer > &peer, Buf &pkt, int packetSize);
|
bool m_NETWORK_CREDENTIALS(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, SharedPtr< Peer > &peer, Buf &pkt, int packetSize);
|
||||||
|
|
||||||
bool m_NETWORK_CONFIG_REQUEST(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, SharedPtr< Peer > &peer, Buf &pkt, int packetSize);
|
bool m_NETWORK_CONFIG_REQUEST(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, SharedPtr< Peer > &peer, Buf &pkt, int packetSize);
|
||||||
|
|
||||||
bool m_NETWORK_CONFIG(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, SharedPtr< Peer > &peer, Buf &pkt, int packetSize);
|
bool m_NETWORK_CONFIG(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, SharedPtr< Peer > &peer, Buf &pkt, int packetSize);
|
||||||
|
|
||||||
bool m_MULTICAST_GATHER(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, SharedPtr< Peer > &peer, Buf &pkt, int packetSize);
|
bool m_MULTICAST_GATHER(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, SharedPtr< Peer > &peer, Buf &pkt, int packetSize);
|
||||||
|
|
||||||
bool m_MULTICAST_FRAME_deprecated(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, SharedPtr< Peer > &peer, Buf &pkt, int packetSize);
|
bool m_MULTICAST_FRAME_deprecated(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, SharedPtr< Peer > &peer, Buf &pkt, int packetSize);
|
||||||
|
|
||||||
bool m_MULTICAST(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, SharedPtr< Peer > &peer, Buf &pkt, int packetSize);
|
bool m_MULTICAST(void *tPtr, uint64_t packetId, unsigned int auth, const SharedPtr< Path > &path, SharedPtr< Peer > &peer, Buf &pkt, int packetSize);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -591,7 +591,7 @@ func (n *Node) runMaintenance() {
|
||||||
addrs, _ := i.Addrs()
|
addrs, _ := i.Addrs()
|
||||||
for _, a := range addrs {
|
for _, a := range addrs {
|
||||||
ipn, _ := a.(*net.IPNet)
|
ipn, _ := a.(*net.IPNet)
|
||||||
if ipn != nil && len(ipn.IP) > 0 && ipn.IP.IsGlobalUnicast() {
|
if ipn != nil && len(ipn.IP) > 0 && !ipn.IP.IsLoopback() && !ipn.IP.IsMulticast() && !ipn.IP.IsInterfaceLocalMulticast() && !ipn.IP.IsLinkLocalMulticast() && !ipn.IP.IsLinkLocalUnicast() {
|
||||||
isTemporary := false
|
isTemporary := false
|
||||||
if len(ipn.IP) == 16 {
|
if len(ipn.IP) == 16 {
|
||||||
var ss C.struct_sockaddr_storage
|
var ss C.struct_sockaddr_storage
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "../osdep/EthernetTap.hpp"
|
#include "../osdep/EthernetTap.hpp"
|
||||||
|
|
||||||
#ifndef __WINDOWS__
|
#ifndef __WINDOWS__
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
|
@ -32,11 +33,16 @@
|
||||||
#include <ifaddrs.h>
|
#include <ifaddrs.h>
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#if __has_include(<netinet/in6_var.h>)
|
|
||||||
|
#ifdef __BSD__
|
||||||
|
|
||||||
#include <netinet6/in6_var.h>
|
#include <netinet6/in6_var.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#ifdef __LINUX__
|
#ifdef __LINUX__
|
||||||
#ifndef IPV6_DONTFRAG
|
#ifndef IPV6_DONTFRAG
|
||||||
#define IPV6_DONTFRAG 62
|
#define IPV6_DONTFRAG 62
|
||||||
|
@ -162,7 +168,9 @@ static void ZT_GoNode_StatePutFunction(
|
||||||
len);
|
len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _freeFunc(void *p) { if (p) free(p); }
|
static void _freeFunc(void *p)
|
||||||
|
{ if (p) free(p); }
|
||||||
|
|
||||||
static int ZT_GoNode_StateGetFunction(
|
static int ZT_GoNode_StateGetFunction(
|
||||||
ZT_Node *node,
|
ZT_Node *node,
|
||||||
void *uptr,
|
void *uptr,
|
||||||
|
@ -689,9 +697,13 @@ extern "C" void ZT_GoTap_setMtu(ZT_GoTap *tap,unsigned int mtu)
|
||||||
reinterpret_cast<EthernetTap *>(tap)->setMtu(mtu);
|
reinterpret_cast<EthernetTap *>(tap)->setMtu(mtu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(IFA_F_SECONDARY) && !defined(IFA_F_TEMPORARY)
|
||||||
|
#define IFA_F_TEMPORARY IFA_F_SECONDARY
|
||||||
|
#endif
|
||||||
|
|
||||||
extern "C" int ZT_isTemporaryV6Address(const char *ifname, const struct sockaddr_storage *a)
|
extern "C" int ZT_isTemporaryV6Address(const char *ifname, const struct sockaddr_storage *a)
|
||||||
{
|
{
|
||||||
#ifdef IN6_IFF_TEMPORARY
|
#if defined(IN6_IFF_TEMPORARY) && defined(SIOCGIFAFLAG_IN6)
|
||||||
static ZT_SOCKET s_tmpV6Socket = ZT_INVALID_SOCKET;
|
static ZT_SOCKET s_tmpV6Socket = ZT_INVALID_SOCKET;
|
||||||
static std::mutex s_lock;
|
static std::mutex s_lock;
|
||||||
std::lock_guard< std::mutex > l(s_lock);
|
std::lock_guard< std::mutex > l(s_lock);
|
||||||
|
@ -701,6 +713,7 @@ extern "C" int ZT_isTemporaryV6Address(const char *ifname,const struct sockaddr_
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
struct in6_ifreq ifr;
|
struct in6_ifreq ifr;
|
||||||
|
memset(&ifr, 0, sizeof(ifr));
|
||||||
strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
|
strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
|
||||||
memcpy(&(ifr.ifr_addr), a, sizeof(sockaddr_in6));
|
memcpy(&(ifr.ifr_addr), a, sizeof(sockaddr_in6));
|
||||||
if (ioctl(s_tmpV6Socket, SIOCGIFAFLAG_IN6, &ifr) < 0) {
|
if (ioctl(s_tmpV6Socket, SIOCGIFAFLAG_IN6, &ifr) < 0) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue