diff --git a/controller/EmbeddedNetworkController.hpp b/controller/EmbeddedNetworkController.hpp index 0772c036f..d01a16b63 100644 --- a/controller/EmbeddedNetworkController.hpp +++ b/controller/EmbeddedNetworkController.hpp @@ -104,8 +104,8 @@ private: struct _MemberStatusKey { - ZT_ALWAYS_INLINE _MemberStatusKey() : networkId(0),nodeId(0) {} - ZT_ALWAYS_INLINE _MemberStatusKey(const uint64_t nwid,const uint64_t nid) : networkId(nwid),nodeId(nid) {} + ZT_INLINE _MemberStatusKey() : networkId(0),nodeId(0) {} + ZT_INLINE _MemberStatusKey(const uint64_t nwid,const uint64_t nid) : networkId(nwid),nodeId(nid) {} uint64_t networkId; uint64_t nodeId; inline bool operator==(const _MemberStatusKey &k) const { return ((k.networkId == networkId)&&(k.nodeId == nodeId)); } @@ -113,7 +113,7 @@ private: struct _MemberStatus { - ZT_ALWAYS_INLINE _MemberStatus() : lastRequestTime(0),vMajor(-1),vMinor(-1),vRev(-1),vProto(-1) {} + ZT_INLINE _MemberStatus() : lastRequestTime(0),vMajor(-1),vMinor(-1),vRev(-1),vProto(-1) {} uint64_t lastRequestTime; int vMajor,vMinor,vRev,vProto; Dictionary lastRequestMetaData; @@ -123,7 +123,7 @@ private: struct _MemberStatusHash { - ZT_ALWAYS_INLINE std::size_t operator()(const _MemberStatusKey &networkIdNodeId) const + ZT_INLINE std::size_t operator()(const _MemberStatusKey &networkIdNodeId) const { return (std::size_t)(networkIdNodeId.networkId + networkIdNodeId.nodeId); } diff --git a/go/native/GoGlue.cpp b/go/native/GoGlue.cpp index 0def57cfc..a157d84a2 100644 --- a/go/native/GoGlue.cpp +++ b/go/native/GoGlue.cpp @@ -182,7 +182,7 @@ static int ZT_GoNode_StateGetFunction( data); } -static ZT_ALWAYS_INLINE void doUdpSend(ZT_SOCKET sock,const struct sockaddr_storage *addr,const void *data,const unsigned int len,const unsigned int ipTTL) +static ZT_INLINE void doUdpSend(ZT_SOCKET sock,const struct sockaddr_storage *addr,const void *data,const unsigned int len,const unsigned int ipTTL) { switch(addr->ss_family) { case AF_INET: diff --git a/node/AES.cpp b/node/AES.cpp index 1182ca41e..641ef06ea 100644 --- a/node/AES.cpp +++ b/node/AES.cpp @@ -24,7 +24,7 @@ namespace { #ifdef ZT_HAVE_UINT128 -ZT_ALWAYS_INLINE void s_bmul64(const uint64_t x,const uint64_t y,uint64_t &r_high,uint64_t &r_low) noexcept +ZT_INLINE void s_bmul64(const uint64_t x,const uint64_t y,uint64_t &r_high,uint64_t &r_low) noexcept { static uint128_t m1 = (uint128_t)0x2108421084210842ULL << 64U | 0x1084210842108421ULL; static uint128_t m2 = (uint128_t)0x4210842108421084ULL << 64U | 0x2108421084210842ULL; @@ -77,7 +77,7 @@ void s_gfmul(const uint64_t h_high,const uint64_t h_low,uint64_t &y0, uint64_t & #else -ZT_ALWAYS_INLINE void s_bmul32(uint32_t x,uint32_t y,uint32_t &r_high,uint32_t &r_low) noexcept +ZT_INLINE void s_bmul32(uint32_t x,uint32_t y,uint32_t &r_high,uint32_t &r_low) noexcept { const uint32_t m1 = (uint32_t)0x11111111; const uint32_t m2 = (uint32_t)0x22222222; @@ -1128,7 +1128,7 @@ void AES::_decryptSW(const uint8_t in[16],uint8_t out[16]) const noexcept // SSE shuffle parameter to reverse bytes in a 128-bit vector. const __m128i AES::s_shuf = _mm_set_epi8(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15); -static ZT_ALWAYS_INLINE __m128i _init256_1_aesni(__m128i a,__m128i b) noexcept +static ZT_INLINE __m128i _init256_1_aesni(__m128i a,__m128i b) noexcept { __m128i x,y; b = _mm_shuffle_epi32(b,0xff); @@ -1142,7 +1142,7 @@ static ZT_ALWAYS_INLINE __m128i _init256_1_aesni(__m128i a,__m128i b) noexcept return x; } -static ZT_ALWAYS_INLINE __m128i _init256_2_aesni(__m128i a,__m128i b) noexcept +static ZT_INLINE __m128i _init256_2_aesni(__m128i a,__m128i b) noexcept { __m128i x,y,z; y = _mm_aeskeygenassist_si128(a,0x00); diff --git a/node/AES.hpp b/node/AES.hpp index 3adf35b7f..631b7392b 100644 --- a/node/AES.hpp +++ b/node/AES.hpp @@ -45,7 +45,7 @@ public: /** * @return True if this system has hardware AES acceleration */ - static ZT_ALWAYS_INLINE bool accelerated() + static ZT_INLINE bool accelerated() { #ifdef ZT_AES_AESNI return Utils::CPUID.aes; @@ -57,23 +57,23 @@ public: /** * Create an un-initialized AES instance (must call init() before use) */ - ZT_ALWAYS_INLINE AES() noexcept {} + ZT_INLINE AES() noexcept {} /** * Create an AES instance with the given key * * @param key 256-bit key */ - explicit ZT_ALWAYS_INLINE AES(const void *const key) noexcept { this->init(key); } + explicit ZT_INLINE AES(const void *const key) noexcept { this->init(key); } - ZT_ALWAYS_INLINE ~AES() { Utils::burn(&_k,sizeof(_k)); } + ZT_INLINE ~AES() { Utils::burn(&_k,sizeof(_k)); } /** * Set (or re-set) this AES256 cipher's key * * @param key 256-bit / 32-byte key */ - ZT_ALWAYS_INLINE void init(const void *key) noexcept + ZT_INLINE void init(const void *key) noexcept { #ifdef ZT_AES_AESNI if (likely(Utils::CPUID.aes)) { @@ -90,7 +90,7 @@ public: * @param in Input block * @param out Output block (can be same as input) */ - ZT_ALWAYS_INLINE void encrypt(const void *const in,void *const out) const noexcept + ZT_INLINE void encrypt(const void *const in,void *const out) const noexcept { #ifdef ZT_AES_AESNI if (likely(Utils::CPUID.aes)) { @@ -107,7 +107,7 @@ public: * @param in Input block * @param out Output block (can be same as input) */ - ZT_ALWAYS_INLINE void decrypt(const void *const in,void *const out) const noexcept + ZT_INLINE void decrypt(const void *const in,void *const out) const noexcept { #ifdef ZT_AES_AESNI if (likely(Utils::CPUID.aes)) { @@ -129,14 +129,14 @@ public: * * @param aes Keyed AES instance to use */ - ZT_ALWAYS_INLINE GMAC(const AES &aes) : _aes(aes) {} + ZT_INLINE GMAC(const AES &aes) : _aes(aes) {} /** * Reset and initialize for a new GMAC calculation * * @param iv 96-bit initialization vector (pad with zeroes if actual IV is shorter) */ - ZT_ALWAYS_INLINE void init(const uint8_t iv[12]) noexcept + ZT_INLINE void init(const uint8_t iv[12]) noexcept { _rp = 0; _len = 0; @@ -191,7 +191,7 @@ public: class CTR { public: - ZT_ALWAYS_INLINE CTR(const AES &aes) noexcept : _aes(aes) {} + ZT_INLINE CTR(const AES &aes) noexcept : _aes(aes) {} /** * Initialize this CTR instance to encrypt a new stream @@ -199,7 +199,7 @@ public: * @param iv Unique initialization vector * @param output Buffer to which to store output (MUST be large enough for total bytes processed!) */ - ZT_ALWAYS_INLINE void init(const uint8_t iv[16],void *const output) noexcept + ZT_INLINE void init(const uint8_t iv[16],void *const output) noexcept { _ctr[0] = Utils::loadAsIsEndian(iv); _ctr[1] = Utils::loadAsIsEndian(iv + 8); @@ -266,7 +266,7 @@ private: void _init_aesni(const uint8_t key[32]) noexcept; - ZT_ALWAYS_INLINE void _encrypt_aesni(const void *const in,void *const out) const noexcept + ZT_INLINE void _encrypt_aesni(const void *const in,void *const out) const noexcept { __m128i tmp = _mm_loadu_si128((const __m128i *)in); tmp = _mm_xor_si128(tmp,_k.ni.k[0]); @@ -286,7 +286,7 @@ private: _mm_storeu_si128((__m128i *)out,_mm_aesenclast_si128(tmp,_k.ni.k[14])); } - ZT_ALWAYS_INLINE void _decrypt_aesni(const void *in,void *out) const noexcept + ZT_INLINE void _decrypt_aesni(const void *in,void *out) const noexcept { __m128i tmp = _mm_loadu_si128((const __m128i *)in); tmp = _mm_xor_si128(tmp,_k.ni.k[14]); @@ -306,7 +306,7 @@ private: _mm_storeu_si128((__m128i *)out,_mm_aesdeclast_si128(tmp,_k.ni.k[0])); } - static ZT_ALWAYS_INLINE __m128i _mult_block_aesni(const __m128i shuf,const __m128i h,__m128i y) noexcept + static ZT_INLINE __m128i _mult_block_aesni(const __m128i shuf,const __m128i h,__m128i y) noexcept { y = _mm_shuffle_epi8(y,shuf); __m128i t1 = _mm_clmulepi64_si128(h,y,0x00); diff --git a/node/Address.hpp b/node/Address.hpp index 72785670d..61a2527f6 100644 --- a/node/Address.hpp +++ b/node/Address.hpp @@ -28,17 +28,17 @@ namespace ZeroTier { class Address : public TriviallyCopyable { public: - ZT_ALWAYS_INLINE Address() noexcept : _a(0) {} - explicit ZT_ALWAYS_INLINE Address(const uint64_t a) noexcept : _a(a) {} - explicit ZT_ALWAYS_INLINE Address(const uint8_t b[5]) noexcept : _a(((uint64_t)b[0] << 32U) | ((uint64_t)b[1] << 24U) | ((uint64_t)b[2] << 16U) | ((uint64_t)b[3] << 8U) | (uint64_t)b[4]) {} + ZT_INLINE Address() noexcept : _a(0) {} + explicit ZT_INLINE Address(const uint64_t a) noexcept : _a(a) {} + explicit ZT_INLINE Address(const uint8_t b[5]) noexcept : _a(((uint64_t)b[0] << 32U) | ((uint64_t)b[1] << 24U) | ((uint64_t)b[2] << 16U) | ((uint64_t)b[3] << 8U) | (uint64_t)b[4]) {} - ZT_ALWAYS_INLINE Address &operator=(const uint64_t a) noexcept { _a = a; return *this; } + ZT_INLINE Address &operator=(const uint64_t a) noexcept { _a = a; return *this; } /** * @param bits Raw address -- 5 bytes, big-endian byte order * @param len Length of array */ - ZT_ALWAYS_INLINE void setTo(const uint8_t b[5]) noexcept + ZT_INLINE void setTo(const uint8_t b[5]) noexcept { _a = ((uint64_t)b[0] << 32U) | ((uint64_t)b[1] << 24U) | ((uint64_t)b[2] << 16U) | ((uint64_t)b[3] << 8U) | (uint64_t)b[4]; } @@ -47,7 +47,7 @@ public: * @param bits Buffer to hold 5-byte address in big-endian byte order * @param len Length of array */ - ZT_ALWAYS_INLINE void copyTo(uint8_t b[5]) const noexcept + ZT_INLINE void copyTo(uint8_t b[5]) const noexcept { const uint64_t a = _a; b[0] = (uint8_t)(a >> 32U); @@ -60,23 +60,23 @@ public: /** * @return Integer containing address (0 to 2^40) */ - ZT_ALWAYS_INLINE uint64_t toInt() const noexcept { return _a; } + ZT_INLINE uint64_t toInt() const noexcept { return _a; } /** * Set address to zero/NIL */ - ZT_ALWAYS_INLINE void zero() noexcept { _a = 0; } + ZT_INLINE void zero() noexcept { _a = 0; } /** * @return Hash code for use with Hashtable */ - ZT_ALWAYS_INLINE unsigned long hashCode() const noexcept { return (unsigned long)_a; } + ZT_INLINE unsigned long hashCode() const noexcept { return (unsigned long)_a; } /** * @param s String with at least 11 characters of space available (10 + terminating NULL) * @return Hexadecimal string */ - ZT_ALWAYS_INLINE char *toString(char s[ZT_ADDRESS_STRING_SIZE_MAX]) const noexcept + ZT_INLINE char *toString(char s[ZT_ADDRESS_STRING_SIZE_MAX]) const noexcept { const uint64_t a = _a; const unsigned int m = 0xf; @@ -103,16 +103,16 @@ public: * * @return True if address is reserved and may not be used */ - ZT_ALWAYS_INLINE bool isReserved() const noexcept { return ((!_a)||((_a >> 32U) == ZT_ADDRESS_RESERVED_PREFIX)); } + ZT_INLINE bool isReserved() const noexcept { return ((!_a) || ((_a >> 32U) == ZT_ADDRESS_RESERVED_PREFIX)); } - ZT_ALWAYS_INLINE operator bool() const noexcept { return (_a != 0); } + ZT_INLINE operator bool() const noexcept { return (_a != 0); } - ZT_ALWAYS_INLINE bool operator==(const Address &a) const noexcept { return _a == a._a; } - ZT_ALWAYS_INLINE bool operator!=(const Address &a) const noexcept { return _a != a._a; } - ZT_ALWAYS_INLINE bool operator>(const Address &a) const noexcept { return _a > a._a; } - ZT_ALWAYS_INLINE bool operator<(const Address &a) const noexcept { return _a < a._a; } - ZT_ALWAYS_INLINE bool operator>=(const Address &a) const noexcept { return _a >= a._a; } - ZT_ALWAYS_INLINE bool operator<=(const Address &a) const noexcept { return _a <= a._a; } + ZT_INLINE bool operator==(const Address &a) const noexcept { return _a == a._a; } + ZT_INLINE bool operator!=(const Address &a) const noexcept { return _a != a._a; } + ZT_INLINE bool operator>(const Address &a) const noexcept { return _a > a._a; } + ZT_INLINE bool operator<(const Address &a) const noexcept { return _a < a._a; } + ZT_INLINE bool operator>=(const Address &a) const noexcept { return _a >= a._a; } + ZT_INLINE bool operator<=(const Address &a) const noexcept { return _a <= a._a; } #if 0 /** diff --git a/node/Buf.hpp b/node/Buf.hpp index 3722a4582..4d8a1e576 100644 --- a/node/Buf.hpp +++ b/node/Buf.hpp @@ -108,12 +108,12 @@ public: */ struct Slice : TriviallyCopyable { - ZT_ALWAYS_INLINE Slice(const SharedPtr &b_,const unsigned int s_,const unsigned int e_) noexcept : b(b_),s(s_),e(e_) {} - ZT_ALWAYS_INLINE Slice() noexcept : b(),s(0),e(0) {} + ZT_INLINE Slice(const SharedPtr &b_,const unsigned int s_,const unsigned int e_) noexcept : b(b_),s(s_),e(e_) {} + ZT_INLINE Slice() noexcept : b(),s(0),e(0) {} - ZT_ALWAYS_INLINE operator bool() const noexcept { return (b); } - ZT_ALWAYS_INLINE unsigned int size() const noexcept { return (e - s); } - ZT_ALWAYS_INLINE void zero() noexcept { b.zero(); s = 0; e = 0; } + ZT_INLINE operator bool() const noexcept { return (b); } + ZT_INLINE unsigned int size() const noexcept { return (e - s); } + ZT_INLINE void zero() noexcept { b.zero(); s = 0; e = 0; } /** * Buffer holding slice data @@ -146,7 +146,7 @@ public: * @return Single slice containing fully assembled buffer (empty on error) */ template - static ZT_ALWAYS_INLINE Buf::Slice assembleSliceVector(FCV &fcv) noexcept + static ZT_INLINE Buf::Slice assembleSliceVector(FCV &fcv) noexcept { Buf::Slice r; @@ -177,16 +177,16 @@ public: /** * Create a new uninitialized buffer with undefined contents (use clear() to zero if needed) */ - ZT_ALWAYS_INLINE Buf() noexcept : __nextInPool(0),__refCount(0) {} + ZT_INLINE Buf() noexcept : __nextInPool(0),__refCount(0) {} /** * Create a new buffer and copy data into it */ - ZT_ALWAYS_INLINE Buf(const void *const data,const unsigned int len) noexcept : __nextInPool(0),__refCount(0) { memcpy(unsafeData,data,len); } + ZT_INLINE Buf(const void *const data,const unsigned int len) noexcept : __nextInPool(0),__refCount(0) { memcpy(unsafeData,data,len); } - ZT_ALWAYS_INLINE Buf(const Buf &b2) noexcept : __nextInPool(0),__refCount(0) { memcpy(unsafeData,b2.unsafeData,ZT_BUF_MEM_SIZE); } + ZT_INLINE Buf(const Buf &b2) noexcept : __nextInPool(0),__refCount(0) { memcpy(unsafeData,b2.unsafeData,ZT_BUF_MEM_SIZE); } - ZT_ALWAYS_INLINE Buf &operator=(const Buf &b2) noexcept + ZT_INLINE Buf &operator=(const Buf &b2) noexcept { if (this != &b2) memcpy(unsafeData,b2.unsafeData,ZT_BUF_MEM_SIZE); @@ -202,7 +202,7 @@ public: * @param ii Iterator to check * @return True if iterator has read past the size of the buffer */ - static ZT_ALWAYS_INLINE bool writeOverflow(const int &ii) noexcept { return ((ii - ZT_BUF_MEM_SIZE) > 0); } + static ZT_INLINE bool writeOverflow(const int &ii) noexcept { return ((ii - ZT_BUF_MEM_SIZE) > 0); } /** * Check for overflow beyond the size of the data that should be in the buffer @@ -214,17 +214,17 @@ public: * @param size Size of data that should be in buffer * @return True if iterator has read past the size of the data */ - static ZT_ALWAYS_INLINE bool readOverflow(const int &ii,const unsigned int size) noexcept { return ((ii - (int)size) > 0); } + static ZT_INLINE bool readOverflow(const int &ii,const unsigned int size) noexcept { return ((ii - (int)size) > 0); } /** * Set all memory to zero */ - ZT_ALWAYS_INLINE void clear() noexcept { memset(unsafeData,0,ZT_BUF_MEM_SIZE); } + ZT_INLINE void clear() noexcept { memset(unsafeData,0,ZT_BUF_MEM_SIZE); } /** * Zero security critical data using Utils::burn() to ensure it's never optimized out. */ - ZT_ALWAYS_INLINE void burn() noexcept { Utils::burn(unsafeData,ZT_BUF_MEM_SIZE); } + ZT_INLINE void burn() noexcept { Utils::burn(unsafeData,ZT_BUF_MEM_SIZE); } /** * Read a byte @@ -232,7 +232,7 @@ public: * @param ii Index value-result parameter (incremented by 1) * @return Byte (undefined on overflow) */ - ZT_ALWAYS_INLINE uint8_t rI8(int &ii) const noexcept + ZT_INLINE uint8_t rI8(int &ii) const noexcept { const int s = ii++; return unsafeData[(unsigned int)s & ZT_BUF_MEM_MASK]; @@ -244,7 +244,7 @@ public: * @param ii Index value-result parameter (incremented by 2) * @return Integer (undefined on overflow) */ - ZT_ALWAYS_INLINE uint16_t rI16(int &ii) const noexcept + ZT_INLINE uint16_t rI16(int &ii) const noexcept { const unsigned int s = (unsigned int)ii & ZT_BUF_MEM_MASK; ii += 2; @@ -263,7 +263,7 @@ public: * @param ii Index value-result parameter (incremented by 4) * @return Integer (undefined on overflow) */ - ZT_ALWAYS_INLINE uint32_t rI32(int &ii) const noexcept + ZT_INLINE uint32_t rI32(int &ii) const noexcept { const unsigned int s = (unsigned int)ii & ZT_BUF_MEM_MASK; ii += 4; @@ -284,7 +284,7 @@ public: * @param ii Index value-result parameter (incremented by 8) * @return Integer (undefined on overflow) */ - ZT_ALWAYS_INLINE uint64_t rI64(int &ii) const noexcept + ZT_INLINE uint64_t rI64(int &ii) const noexcept { const unsigned int s = (unsigned int)ii & ZT_BUF_MEM_MASK; ii += 8; @@ -319,7 +319,7 @@ public: * @return Bytes read or a negative value on unmarshal error (passed from object) or overflow */ template - ZT_ALWAYS_INLINE int rO(int &ii,T &obj) const noexcept + ZT_INLINE int rO(int &ii,T &obj) const noexcept { if (ii < ZT_BUF_MEM_SIZE) { int ms = obj.unmarshal(unsafeData + ii,ZT_BUF_MEM_SIZE - ii); @@ -341,7 +341,7 @@ public: * @param bufSize Capacity of buffer in bytes * @return Pointer to buf or NULL on overflow or error */ - ZT_ALWAYS_INLINE char *rS(int &ii,char *const buf,const unsigned int bufSize) const noexcept + ZT_INLINE char *rS(int &ii,char *const buf,const unsigned int bufSize) const noexcept { const char *const s = (const char *)(unsafeData + ii); const int sii = ii; @@ -367,7 +367,7 @@ public: * @param ii Index value-result parameter (incremented by length of string) * @return Pointer to null-terminated C-style string or NULL on overflow or error */ - ZT_ALWAYS_INLINE const char *rSnc(int &ii) const noexcept + ZT_INLINE const char *rSnc(int &ii) const noexcept { const char *const s = (const char *)(unsafeData + ii); while (ii < ZT_BUF_MEM_SIZE) { @@ -388,7 +388,7 @@ public: * @param len Length of buffer * @return Pointer to data or NULL on overflow or error */ - ZT_ALWAYS_INLINE uint8_t *rB(int &ii,void *const bytes,const unsigned int len) const noexcept + ZT_INLINE uint8_t *rB(int &ii,void *const bytes,const unsigned int len) const noexcept { if ((ii += (int)len) <= ZT_BUF_MEM_SIZE) { memcpy(bytes,unsafeData + ii,len); @@ -410,7 +410,7 @@ public: * @param len Length of data field to obtain a pointer to * @return Pointer to field or NULL on overflow */ - ZT_ALWAYS_INLINE const uint8_t *rBnc(int &ii,unsigned int len) const noexcept + ZT_INLINE const uint8_t *rBnc(int &ii,unsigned int len) const noexcept { const uint8_t *const b = unsafeData + ii; return ((ii += (int)len) <= ZT_BUF_MEM_SIZE) ? b : nullptr; @@ -423,7 +423,7 @@ public: * will not necessarily result in a 'true' return from readOverflow(). It does * however subject 'ii' to soft bounds masking like the gI??() methods. */ - ZT_ALWAYS_INLINE uint8_t lI8(const int ii) const noexcept + ZT_INLINE uint8_t lI8(const int ii) const noexcept { return unsafeData[(unsigned int)ii & ZT_BUF_MEM_MASK]; } @@ -435,7 +435,7 @@ public: * will not necessarily result in a 'true' return from readOverflow(). It does * however subject 'ii' to soft bounds masking like the gI??() methods. */ - ZT_ALWAYS_INLINE uint16_t lI16(const int ii) const noexcept + ZT_INLINE uint16_t lI16(const int ii) const noexcept { const unsigned int s = (unsigned int)ii & ZT_BUF_MEM_MASK; #ifdef ZT_NO_UNALIGNED_ACCESS @@ -454,7 +454,7 @@ public: * will not necessarily result in a 'true' return from readOverflow(). It does * however subject 'ii' to soft bounds masking like the gI??() methods. */ - ZT_ALWAYS_INLINE uint32_t lI32(const int ii) const noexcept + ZT_INLINE uint32_t lI32(const int ii) const noexcept { const unsigned int s = (unsigned int)ii & ZT_BUF_MEM_MASK; #ifdef ZT_NO_UNALIGNED_ACCESS @@ -475,7 +475,7 @@ public: * will not necessarily result in a 'true' return from readOverflow(). It does * however subject 'ii' to soft bounds masking like the gI??() methods. */ - ZT_ALWAYS_INLINE uint8_t lI64(const int ii) const noexcept + ZT_INLINE uint8_t lI64(const int ii) const noexcept { const unsigned int s = (unsigned int)ii & ZT_BUF_MEM_MASK; #ifdef ZT_NO_UNALIGNED_ACCESS @@ -499,7 +499,7 @@ public: * @param ii Index value-result parameter (incremented by 1) * @param n Byte */ - ZT_ALWAYS_INLINE void wI8(int &ii,const uint8_t n) noexcept + ZT_INLINE void wI8(int &ii,const uint8_t n) noexcept { const int s = ii++; unsafeData[(unsigned int)s & ZT_BUF_MEM_MASK] = n; @@ -511,7 +511,7 @@ public: * @param ii Index value-result parameter (incremented by 2) * @param n Integer */ - ZT_ALWAYS_INLINE void wI16(int &ii,const uint16_t n) noexcept + ZT_INLINE void wI16(int &ii,const uint16_t n) noexcept { const unsigned int s = ((unsigned int)ii) & ZT_BUF_MEM_MASK; ii += 2; @@ -529,7 +529,7 @@ public: * @param ii Index value-result parameter (incremented by 4) * @param n Integer */ - ZT_ALWAYS_INLINE void wI32(int &ii,const uint32_t n) noexcept + ZT_INLINE void wI32(int &ii,const uint32_t n) noexcept { const unsigned int s = ((unsigned int)ii) & ZT_BUF_MEM_MASK; ii += 4; @@ -549,7 +549,7 @@ public: * @param ii Index value-result parameter (incremented by 8) * @param n Integer */ - ZT_ALWAYS_INLINE void wI64(int &ii,const uint64_t n) noexcept + ZT_INLINE void wI64(int &ii,const uint64_t n) noexcept { const unsigned int s = ((unsigned int)ii) & ZT_BUF_MEM_MASK; ii += 8; @@ -575,7 +575,7 @@ public: * @param t Object to write */ template - ZT_ALWAYS_INLINE void wO(int &ii,T &t) noexcept + ZT_INLINE void wO(int &ii,T &t) noexcept { const int s = ii; if ((s + T::marshalSizeMax()) <= ZT_BUF_MEM_SIZE) { @@ -593,7 +593,7 @@ public: * @param ii Index value-result parameter (incremented by length of string) * @param s String to write (writes an empty string if this is NULL) */ - ZT_ALWAYS_INLINE void wS(int &ii,const char *s) noexcept + ZT_INLINE void wS(int &ii,const char *s) noexcept { if (s) { char c; @@ -613,7 +613,7 @@ public: * @param bytes Bytes to write * @param len Size of data in bytes */ - ZT_ALWAYS_INLINE void wB(int &ii,const void *const bytes,const unsigned int len) noexcept + ZT_INLINE void wB(int &ii,const void *const bytes,const unsigned int len) noexcept { const int s = ii; if ((ii += (int)len) <= ZT_BUF_MEM_SIZE) @@ -623,7 +623,7 @@ public: /** * Store a byte without advancing the index */ - ZT_ALWAYS_INLINE void sI8(const int ii,const uint8_t n) noexcept + ZT_INLINE void sI8(const int ii,const uint8_t n) noexcept { unsafeData[(unsigned int)ii & ZT_BUF_MEM_MASK] = n; } @@ -631,7 +631,7 @@ public: /** * Store an integer without advancing the index */ - ZT_ALWAYS_INLINE void sI16(const int ii,const uint16_t n) noexcept + ZT_INLINE void sI16(const int ii,const uint16_t n) noexcept { const unsigned int s = ((unsigned int)ii) & ZT_BUF_MEM_MASK; #ifdef ZT_NO_UNALIGNED_ACCESS @@ -645,7 +645,7 @@ public: /** * Store an integer without advancing the index */ - ZT_ALWAYS_INLINE void sI32(const int ii,const uint32_t n) noexcept + ZT_INLINE void sI32(const int ii,const uint32_t n) noexcept { const unsigned int s = ((unsigned int)ii) & ZT_BUF_MEM_MASK; #ifdef ZT_NO_UNALIGNED_ACCESS @@ -661,7 +661,7 @@ public: /** * Store an integer without advancing the index */ - ZT_ALWAYS_INLINE void sI64(const int ii,const uint64_t n) noexcept + ZT_INLINE void sI64(const int ii,const uint64_t n) noexcept { const unsigned int s = ((unsigned int)ii) & ZT_BUF_MEM_MASK; #ifdef ZT_NO_UNALIGNED_ACCESS @@ -695,7 +695,7 @@ public: * @return Reference to 'b' cast to type T */ template - ZT_ALWAYS_INLINE T &as(const unsigned int i = 0) noexcept { return *reinterpret_cast(unsafeData + i); } + ZT_INLINE T &as(const unsigned int i = 0) noexcept { return *reinterpret_cast(unsafeData + i); } /** * Cast data in 'b' to a (usually packed) structure type (const) @@ -709,7 +709,7 @@ public: * @return Reference to 'b' cast to type T */ template - ZT_ALWAYS_INLINE const T &as(const unsigned int i = 0) const noexcept { return *reinterpret_cast(unsafeData + i); } + ZT_INLINE const T &as(const unsigned int i = 0) const noexcept { return *reinterpret_cast(unsafeData + i); } /** * Raw data held in buffer diff --git a/node/C25519.cpp b/node/C25519.cpp index 3c7ff0d1e..48b8916dd 100644 --- a/node/C25519.cpp +++ b/node/C25519.cpp @@ -31,7 +31,7 @@ typedef uint8_t u8; typedef int32_t s32; typedef int64_t limb; -ZT_ALWAYS_INLINE void fsum(limb *output, const limb *in) { +ZT_INLINE void fsum(limb *output,const limb *in) { unsigned i; for (i = 0; i < 10; i += 2) { output[0+i] = output[0+i] + in[0+i]; @@ -39,21 +39,21 @@ ZT_ALWAYS_INLINE void fsum(limb *output, const limb *in) { } } -ZT_ALWAYS_INLINE void fdifference(limb *output, const limb *in) { +ZT_INLINE void fdifference(limb *output,const limb *in) { unsigned i; for (i = 0; i < 10; ++i) { output[i] = in[i] - output[i]; } } -ZT_ALWAYS_INLINE void fscalar_product(limb *output, const limb *in, const limb scalar) { +ZT_INLINE void fscalar_product(limb *output,const limb *in,const limb scalar) { unsigned i; for (i = 0; i < 10; ++i) { output[i] = in[i] * scalar; } } -ZT_ALWAYS_INLINE void fproduct(limb *output, const limb *in2, const limb *in) { +ZT_INLINE void fproduct(limb *output,const limb *in2,const limb *in) { output[0] = ((limb) ((s32) in2[0])) * ((s32) in[0]); output[1] = ((limb) ((s32) in2[0])) * ((s32) in[1]) + ((limb) ((s32) in2[1])) * ((s32) in[0]); @@ -190,7 +190,7 @@ void freduce_degree(limb *output) { #error "This code only works on a two's complement system" #endif -ZT_ALWAYS_INLINE limb div_by_2_26(const limb v) +ZT_INLINE limb div_by_2_26(const limb v) { /* High word of v; no shift needed. */ const uint32_t highword = (uint32_t) (((uint64_t) v) >> 32); @@ -202,7 +202,7 @@ ZT_ALWAYS_INLINE limb div_by_2_26(const limb v) return (v + roundoff) >> 26; } -ZT_ALWAYS_INLINE limb div_by_2_25(const limb v) +ZT_INLINE limb div_by_2_25(const limb v) { /* High word of v; no shift needed*/ const uint32_t highword = (uint32_t) (((uint64_t) v) >> 32); @@ -257,7 +257,7 @@ void freduce_coefficients(limb *output) { * bound on |output[1]| is sufficient to meet our needs. */ } -ZT_ALWAYS_INLINE void fmul(limb *output, const limb *in, const limb *in2) { +ZT_INLINE void fmul(limb *output,const limb *in,const limb *in2) { limb t[19]; fproduct(t, in, in2); /* |t[i]| < 14*2^54 */ @@ -325,7 +325,7 @@ void fsquare_inner(limb *output, const limb *in) { output[18] = 2 * ((limb) ((s32) in[9])) * ((s32) in[9]); } -ZT_ALWAYS_INLINE void fsquare(limb *output, const limb *in) { +ZT_INLINE void fsquare(limb *output,const limb *in) { limb t[19]; fsquare_inner(t, in); /* |t[i]| < 14*2^54 because the largest product of two limbs will be < @@ -337,7 +337,7 @@ ZT_ALWAYS_INLINE void fsquare(limb *output, const limb *in) { memcpy(output, t, sizeof(limb) * 10); } -ZT_ALWAYS_INLINE void fexpand(limb *output, const u8 *input) { +ZT_INLINE void fexpand(limb *output,const u8 *input) { #define F(n,start,shift,mask) \ output[n] = ((((limb) input[start + 0]) | \ ((limb) input[start + 1]) << 8 | \ @@ -360,7 +360,7 @@ ZT_ALWAYS_INLINE void fexpand(limb *output, const u8 *input) { #error "This code only works when >> does sign-extension on negative numbers" #endif -ZT_ALWAYS_INLINE s32 s32_eq(s32 a, s32 b) { +ZT_INLINE s32 s32_eq(s32 a,s32 b) { a = ~(a ^ b); a &= a << 16; a &= a << 8; @@ -370,13 +370,13 @@ ZT_ALWAYS_INLINE s32 s32_eq(s32 a, s32 b) { return a >> 31; } -ZT_ALWAYS_INLINE s32 s32_gte(s32 a, s32 b) { +ZT_INLINE s32 s32_gte(s32 a,s32 b) { a -= b; /* a >= 0 iff a >= b. */ return ~(a >> 31); } -ZT_ALWAYS_INLINE void fcontract(u8 *output, limb *input_limbs) { +ZT_INLINE void fcontract(u8 *output,limb *input_limbs) { int i; int j; s32 input[10]; @@ -475,10 +475,10 @@ ZT_ALWAYS_INLINE void fcontract(u8 *output, limb *input_limbs) { #undef F } -ZT_ALWAYS_INLINE void fmonty(limb *x2, limb *z2, /* output 2Q */ - limb *x3, limb *z3, /* output Q + Q' */ - limb *x, limb *z, /* input Q */ - limb *xprime, limb *zprime, /* input Q' */ +ZT_INLINE void fmonty(limb *x2,limb *z2, /* output 2Q */ + limb *x3,limb *z3, /* output Q + Q' */ + limb *x,limb *z, /* input Q */ + limb *xprime,limb *zprime, /* input Q' */ const limb *qmqp /* input Q - Q' */) { limb origx[10], origxprime[10], zzz[19], xx[19], zz[19], xxprime[19], zzprime[19], zzzprime[19], xxxprime[19]; @@ -550,7 +550,7 @@ ZT_ALWAYS_INLINE void fmonty(limb *x2, limb *z2, /* output 2Q */ /* |z2|i| < 2^26 */ } -ZT_ALWAYS_INLINE void swap_conditional(limb a[19], limb b[19], limb iswap) { +ZT_INLINE void swap_conditional(limb a[19],limb b[19],limb iswap) { unsigned i; const s32 swap = (s32) -iswap; @@ -561,7 +561,7 @@ ZT_ALWAYS_INLINE void swap_conditional(limb a[19], limb b[19], limb iswap) { } } -ZT_ALWAYS_INLINE void cmult(limb *resultx, limb *resultz, const u8 *n, const limb *q) { +ZT_INLINE void cmult(limb *resultx,limb *resultz,const u8 *n,const limb *q) { limb a[19] = {0}, b[19] = {1}, c[19] = {1}, d[19] = {0}; limb *nqpqx = a, *nqpqz = b, *nqx = c, *nqz = d, *t; limb e[19] = {0}, f[19] = {1}, g[19] = {0}, h[19] = {1}; @@ -607,7 +607,7 @@ ZT_ALWAYS_INLINE void cmult(limb *resultx, limb *resultz, const u8 *n, const lim memcpy(resultz, nqz, sizeof(limb) * 10); } -ZT_ALWAYS_INLINE void crecip(limb *out, const limb *z) { +ZT_INLINE void crecip(limb *out,const limb *z) { limb z2[10]; limb z9[10]; limb z11[10]; @@ -691,7 +691,7 @@ void crypto_scalarmult(u8 *mypublic, const u8 *secret, const u8 *basepoint) { } static const unsigned char base[32] = {9}; -ZT_ALWAYS_INLINE void crypto_scalarmult_base(unsigned char *q,const unsigned char *n) { crypto_scalarmult(q,n,base); } +ZT_INLINE void crypto_scalarmult_base(unsigned char *q,const unsigned char *n) { crypto_scalarmult(q,n,base); } // -------------------------------------------------------------------------------------------------------------------- @@ -748,7 +748,7 @@ typedef struct void fe25519_sub(fe25519 *r, const fe25519 *x, const fe25519 *y); -ZT_ALWAYS_INLINE crypto_uint32 equal(crypto_uint32 a,crypto_uint32 b) /* 16-bit inputs */ +ZT_INLINE crypto_uint32 equal(crypto_uint32 a,crypto_uint32 b) /* 16-bit inputs */ { crypto_uint32 x = a ^ b; /* 0: yes; 1..65535: no */ x -= 1; /* 4294967295: yes; 0..65534: no */ @@ -756,7 +756,7 @@ ZT_ALWAYS_INLINE crypto_uint32 equal(crypto_uint32 a,crypto_uint32 b) /* 16-bit return x; } -ZT_ALWAYS_INLINE crypto_uint32 ge(crypto_uint32 a,crypto_uint32 b) /* 16-bit inputs */ +ZT_INLINE crypto_uint32 ge(crypto_uint32 a,crypto_uint32 b) /* 16-bit inputs */ { unsigned int x = a; x -= (unsigned int) b; /* 0..65535: yes; 4294901761..4294967295: no */ @@ -765,10 +765,10 @@ ZT_ALWAYS_INLINE crypto_uint32 ge(crypto_uint32 a,crypto_uint32 b) /* 16-bit inp return x; } -ZT_ALWAYS_INLINE crypto_uint32 times19(crypto_uint32 a) { return (a << 4) + (a << 1) + a; } -ZT_ALWAYS_INLINE crypto_uint32 times38(crypto_uint32 a) { return (a << 5) + (a << 2) + (a << 1); } +ZT_INLINE crypto_uint32 times19(crypto_uint32 a) { return (a << 4) + (a << 1) + a; } +ZT_INLINE crypto_uint32 times38(crypto_uint32 a) { return (a << 5) + (a << 2) + (a << 1); } -ZT_ALWAYS_INLINE void reduce_add_sub(fe25519 *r) +ZT_INLINE void reduce_add_sub(fe25519 *r) { int i,rep; for(rep=0;rep<4;rep++) @@ -786,7 +786,7 @@ ZT_ALWAYS_INLINE void reduce_add_sub(fe25519 *r) } } -ZT_ALWAYS_INLINE void reduce_mul(fe25519 *r) +ZT_INLINE void reduce_mul(fe25519 *r) { int i,rep; for(rep=0;rep<2;rep++) @@ -804,7 +804,7 @@ ZT_ALWAYS_INLINE void reduce_mul(fe25519 *r) } } -ZT_ALWAYS_INLINE void fe25519_freeze(fe25519 *r) +ZT_INLINE void fe25519_freeze(fe25519 *r) { int i; crypto_uint32 mm = equal(r->v[31],127); @@ -820,14 +820,14 @@ ZT_ALWAYS_INLINE void fe25519_freeze(fe25519 *r) r->v[0] -= mm&237; } -ZT_ALWAYS_INLINE void fe25519_unpack(fe25519 *r, const unsigned char x[32]) +ZT_INLINE void fe25519_unpack(fe25519 *r,const unsigned char x[32]) { int i; for(i=0;i<32;i++) r->v[i] = x[i]; r->v[31] &= 127; } -ZT_ALWAYS_INLINE void fe25519_pack(unsigned char r[32], const fe25519 *x) +ZT_INLINE void fe25519_pack(unsigned char r[32],const fe25519 *x) { int i; fe25519 y = *x; @@ -848,7 +848,7 @@ int fe25519_iseq_vartime(const fe25519 *x, const fe25519 *y) return 1; } -ZT_ALWAYS_INLINE void fe25519_cmov(fe25519 *r, const fe25519 *x, unsigned char b) +ZT_INLINE void fe25519_cmov(fe25519 *r,const fe25519 *x,unsigned char b) { int i; crypto_uint32 mask = b; @@ -856,21 +856,21 @@ ZT_ALWAYS_INLINE void fe25519_cmov(fe25519 *r, const fe25519 *x, unsigned char b for(i=0;i<32;i++) r->v[i] ^= mask & (x->v[i] ^ r->v[i]); } -ZT_ALWAYS_INLINE unsigned char fe25519_getparity(const fe25519 *x) +ZT_INLINE unsigned char fe25519_getparity(const fe25519 *x) { fe25519 t = *x; fe25519_freeze(&t); return t.v[0] & 1; } -ZT_ALWAYS_INLINE void fe25519_setone(fe25519 *r) +ZT_INLINE void fe25519_setone(fe25519 *r) { int i; r->v[0] = 1; for(i=1;i<32;i++) r->v[i]=0; } -ZT_ALWAYS_INLINE void fe25519_setzero(fe25519 *r) +ZT_INLINE void fe25519_setzero(fe25519 *r) { int i; for(i=0;i<32;i++) r->v[i]=0; @@ -920,7 +920,7 @@ void fe25519_mul(fe25519 *r, const fe25519 *x, const fe25519 *y) reduce_mul(r); } -ZT_ALWAYS_INLINE void fe25519_square(fe25519 *r, const fe25519 *x) { fe25519_mul(r, x, x); } +ZT_INLINE void fe25519_square(fe25519 *r,const fe25519 *x) { fe25519_mul(r,x,x); } void fe25519_invert(fe25519 *r, const fe25519 *x) { @@ -1046,7 +1046,7 @@ void fe25519_pow2523(fe25519 *r, const fe25519 *x) const crypto_uint32 m[32] = {0xED, 0xD3, 0xF5, 0x5C, 0x1A, 0x63, 0x12, 0x58, 0xD6, 0x9C, 0xF7, 0xA2, 0xDE, 0xF9, 0xDE, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10}; const crypto_uint32 mu[33] = {0x1B, 0x13, 0x2C, 0x0A, 0xA3, 0xE5, 0x9C, 0xED, 0xA7, 0x29, 0x63, 0x08, 0x5D, 0x21, 0x06, 0x21, 0xEB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F}; -ZT_ALWAYS_INLINE crypto_uint32 lt(crypto_uint32 a,crypto_uint32 b) /* 16-bit inputs */ +ZT_INLINE crypto_uint32 lt(crypto_uint32 a,crypto_uint32 b) /* 16-bit inputs */ { unsigned int x = a; x -= (unsigned int) b; /* 0..65535: no; 4294901761..4294967295: yes */ @@ -1116,7 +1116,7 @@ void barrett_reduce(sc25519 *r, const crypto_uint32 x[64]) reduce_add_sub(r); } -ZT_ALWAYS_INLINE void sc25519_from32bytes(sc25519 *r, const unsigned char x[32]) +ZT_INLINE void sc25519_from32bytes(sc25519 *r,const unsigned char x[32]) { int i; crypto_uint32 t[64]; @@ -1125,7 +1125,7 @@ ZT_ALWAYS_INLINE void sc25519_from32bytes(sc25519 *r, const unsigned char x[32]) barrett_reduce(r, t); } -ZT_ALWAYS_INLINE void sc25519_from64bytes(sc25519 *r, const unsigned char x[64]) +ZT_INLINE void sc25519_from64bytes(sc25519 *r,const unsigned char x[64]) { int i; crypto_uint32 t[64]; @@ -1133,13 +1133,13 @@ ZT_ALWAYS_INLINE void sc25519_from64bytes(sc25519 *r, const unsigned char x[64]) barrett_reduce(r, t); } -ZT_ALWAYS_INLINE void sc25519_to32bytes(unsigned char r[32], const sc25519 *x) +ZT_INLINE void sc25519_to32bytes(unsigned char r[32],const sc25519 *x) { int i; for(i=0;i<32;i++) r[i] = x->v[i]; } -ZT_ALWAYS_INLINE void sc25519_add(sc25519 *r, const sc25519 *x, const sc25519 *y) +ZT_INLINE void sc25519_add(sc25519 *r,const sc25519 *x,const sc25519 *y) { int i; for(i=0;i<32;i++) r->v[i] = x->v[i] + y->v[i]; @@ -1207,7 +1207,7 @@ void sc25519_window3(signed char r[85], const sc25519 *s) r[84] += carry; } -ZT_ALWAYS_INLINE void sc25519_2interleave2(unsigned char r[127], const sc25519 *s1, const sc25519 *s2) +ZT_INLINE void sc25519_2interleave2(unsigned char r[127],const sc25519 *s1,const sc25519 *s2) { int i; for(i=0;i<31;i++) @@ -2096,27 +2096,27 @@ static const ge25519_aff ge25519_base_multiples_affine[425] = { {{0x69, 0x3e, 0x47, 0x97, 0x2c, 0xaf, 0x52, 0x7c, 0x78, 0x83, 0xad, 0x1b, 0x39, 0x82, 0x2f, 0x02, 0x6f, 0x47, 0xdb, 0x2a, 0xb0, 0xe1, 0x91, 0x99, 0x55, 0xb8, 0x99, 0x3a, 0xa0, 0x44, 0x11, 0x51}}} }; -ZT_ALWAYS_INLINE void p1p1_to_p2(ge25519_p2 *r, const ge25519_p1p1 *p) +ZT_INLINE void p1p1_to_p2(ge25519_p2 *r,const ge25519_p1p1 *p) { fe25519_mul(&r->x, &p->x, &p->t); fe25519_mul(&r->y, &p->y, &p->z); fe25519_mul(&r->z, &p->z, &p->t); } -ZT_ALWAYS_INLINE void p1p1_to_p2_2(ge25519_p3 *r, const ge25519_p1p1 *p) +ZT_INLINE void p1p1_to_p2_2(ge25519_p3 *r,const ge25519_p1p1 *p) { fe25519_mul(&r->x, &p->x, &p->t); fe25519_mul(&r->y, &p->y, &p->z); fe25519_mul(&r->z, &p->z, &p->t); } -ZT_ALWAYS_INLINE void p1p1_to_p3(ge25519_p3 *r, const ge25519_p1p1 *p) +ZT_INLINE void p1p1_to_p3(ge25519_p3 *r,const ge25519_p1p1 *p) { p1p1_to_p2_2(r, p); fe25519_mul(&r->t, &p->x, &p->y); } -ZT_ALWAYS_INLINE void ge25519_mixadd2(ge25519_p3 *r, const ge25519_aff *q) +ZT_INLINE void ge25519_mixadd2(ge25519_p3 *r,const ge25519_aff *q) { fe25519 a,b,t1,t2,c,d,e,f,g,h,qt; fe25519_mul(&qt, &q->x, &q->y); @@ -2139,7 +2139,7 @@ ZT_ALWAYS_INLINE void ge25519_mixadd2(ge25519_p3 *r, const ge25519_aff *q) fe25519_mul(&r->t, &e, &h); } -ZT_ALWAYS_INLINE void add_p1p1(ge25519_p1p1 *r, const ge25519_p3 *p, const ge25519_p3 *q) +ZT_INLINE void add_p1p1(ge25519_p1p1 *r,const ge25519_p3 *p,const ge25519_p3 *q) { fe25519 a, b, c, d, t; @@ -2160,7 +2160,7 @@ ZT_ALWAYS_INLINE void add_p1p1(ge25519_p1p1 *r, const ge25519_p3 *p, const ge255 } /* See http://www.hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html#doubling-dbl-2008-hwcd */ -ZT_ALWAYS_INLINE void dbl_p1p1(ge25519_p1p1 *r, const ge25519_p2 *p) +ZT_INLINE void dbl_p1p1(ge25519_p1p1 *r,const ge25519_p2 *p) { fe25519 a,b,c,d; fe25519_square(&a, &p->x); @@ -2179,13 +2179,13 @@ ZT_ALWAYS_INLINE void dbl_p1p1(ge25519_p1p1 *r, const ge25519_p2 *p) } /* Constant-time version of: if(b) r = p */ -ZT_ALWAYS_INLINE void cmov_aff(ge25519_aff *r, const ge25519_aff *p, unsigned char b) +ZT_INLINE void cmov_aff(ge25519_aff *r,const ge25519_aff *p,unsigned char b) { fe25519_cmov(&r->x, &p->x, b); fe25519_cmov(&r->y, &p->y, b); } -ZT_ALWAYS_INLINE unsigned char equal(signed char b,signed char c) +ZT_INLINE unsigned char equal(signed char b,signed char c) { unsigned char ub = b; unsigned char uc = c; @@ -2196,14 +2196,14 @@ ZT_ALWAYS_INLINE unsigned char equal(signed char b,signed char c) return (unsigned char)y; } -ZT_ALWAYS_INLINE unsigned char negative(signed char b) +ZT_INLINE unsigned char negative(signed char b) { unsigned long long x = b; /* 18446744073709551361..18446744073709551615: yes; 0..255: no */ x >>= 63; /* 1: yes; 0: no */ return (unsigned char)x; } -ZT_ALWAYS_INLINE void choose_t(ge25519_aff *t, unsigned long long pos, signed char b) +ZT_INLINE void choose_t(ge25519_aff *t,unsigned long long pos,signed char b) { /* constant time */ fe25519 v; @@ -2216,7 +2216,7 @@ ZT_ALWAYS_INLINE void choose_t(ge25519_aff *t, unsigned long long pos, signed ch fe25519_cmov(&t->x, &v, negative(b)); } -ZT_ALWAYS_INLINE void setneutral(ge25519 *r) +ZT_INLINE void setneutral(ge25519 *r) { fe25519_setzero(&r->x); fe25519_setone(&r->y); @@ -2272,7 +2272,7 @@ int ge25519_unpackneg_vartime(ge25519_p3 *r, const unsigned char p[32]) return 0; } -ZT_ALWAYS_INLINE void ge25519_pack(unsigned char r[32], const ge25519_p3 *p) +ZT_INLINE void ge25519_pack(unsigned char r[32],const ge25519_p3 *p) { fe25519 tx, ty, zi; fe25519_invert(&zi, &p->z); @@ -2328,7 +2328,7 @@ void ge25519_double_scalarmult_vartime(ge25519_p3 *r, const ge25519_p3 *p1, cons } } -ZT_ALWAYS_INLINE void ge25519_scalarmult_base(ge25519_p3 *r, const sc25519 *s) +ZT_INLINE void ge25519_scalarmult_base(ge25519_p3 *r,const sc25519 *s) { signed char b[85]; int i; @@ -2345,7 +2345,7 @@ ZT_ALWAYS_INLINE void ge25519_scalarmult_base(ge25519_p3 *r, const sc25519 *s) } } -ZT_ALWAYS_INLINE void get_hram(unsigned char *hram, const unsigned char *sm, const unsigned char *pk, unsigned char *playground, unsigned long long smlen) +ZT_INLINE void get_hram(unsigned char *hram,const unsigned char *sm,const unsigned char *pk,unsigned char *playground,unsigned long long smlen) { unsigned long long i; diff --git a/node/C25519.hpp b/node/C25519.hpp index 7b79173a2..a47271823 100644 --- a/node/C25519.hpp +++ b/node/C25519.hpp @@ -52,7 +52,7 @@ public: * @tparam F Type of 'cond' */ template - static ZT_ALWAYS_INLINE void generateSatisfying(F cond,uint8_t pub[ZT_C25519_PUBLIC_KEY_LEN],uint8_t priv[ZT_C25519_PRIVATE_KEY_LEN]) + static ZT_INLINE void generateSatisfying(F cond,uint8_t pub[ZT_C25519_PUBLIC_KEY_LEN],uint8_t priv[ZT_C25519_PRIVATE_KEY_LEN]) { Utils::getSecureRandom(priv,ZT_C25519_PRIVATE_KEY_LEN); _calcPubED(pub,priv); // do Ed25519 key -- bytes 32-63 of pub and priv diff --git a/node/Capability.hpp b/node/Capability.hpp index db7bf8a68..392fc30d0 100644 --- a/node/Capability.hpp +++ b/node/Capability.hpp @@ -64,7 +64,7 @@ class Capability : public Credential public: static constexpr ZT_CredentialType credentialType() noexcept { return ZT_CREDENTIAL_TYPE_CAPABILITY; } - ZT_ALWAYS_INLINE Capability() noexcept { memoryZero(this); } + ZT_INLINE Capability() noexcept { memoryZero(this); } /** * @param id Capability ID @@ -74,7 +74,7 @@ public: * @param rules Network flow rules for this capability * @param ruleCount Number of flow rules */ - ZT_ALWAYS_INLINE Capability(const uint32_t id,const uint64_t nwid,const int64_t ts,const unsigned int mccl,const ZT_VirtualNetworkRule *const rules,const unsigned int ruleCount) noexcept : + ZT_INLINE Capability(const uint32_t id,const uint64_t nwid,const int64_t ts,const unsigned int mccl,const ZT_VirtualNetworkRule *const rules,const unsigned int ruleCount) noexcept : _nwid(nwid), _ts(ts), _id(id), @@ -88,32 +88,32 @@ public: /** * @return Rules -- see ruleCount() for size of array */ - ZT_ALWAYS_INLINE const ZT_VirtualNetworkRule *rules() const noexcept { return _rules; } + ZT_INLINE const ZT_VirtualNetworkRule *rules() const noexcept { return _rules; } /** * @return Number of rules in rules() */ - ZT_ALWAYS_INLINE unsigned int ruleCount() const noexcept { return _ruleCount; } + ZT_INLINE unsigned int ruleCount() const noexcept { return _ruleCount; } /** * @return ID and evaluation order of this capability in network */ - ZT_ALWAYS_INLINE uint32_t id() const noexcept { return _id; } + ZT_INLINE uint32_t id() const noexcept { return _id; } /** * @return Network ID for which this capability was issued */ - ZT_ALWAYS_INLINE uint64_t networkId() const noexcept { return _nwid; } + ZT_INLINE uint64_t networkId() const noexcept { return _nwid; } /** * @return Timestamp */ - ZT_ALWAYS_INLINE int64_t timestamp() const noexcept { return _ts; } + ZT_INLINE int64_t timestamp() const noexcept { return _ts; } /** * @return Last 'to' address in chain of custody */ - ZT_ALWAYS_INLINE Address issuedTo() const noexcept + ZT_INLINE Address issuedTo() const noexcept { Address i2; for(int i=0;i(this),0,sizeof(CertificateOfOwnership)); _networkId = nwid; @@ -71,19 +71,19 @@ public: _issuedTo = issuedTo; } - ZT_ALWAYS_INLINE uint64_t networkId() const noexcept { return _networkId; } - ZT_ALWAYS_INLINE int64_t timestamp() const noexcept { return _ts; } - ZT_ALWAYS_INLINE uint32_t id() const noexcept { return _id; } - ZT_ALWAYS_INLINE const Address &issuedTo() const noexcept { return _issuedTo; } - ZT_ALWAYS_INLINE const Address &signer() const noexcept { return _signedBy; } - ZT_ALWAYS_INLINE const uint8_t *signature() const noexcept { return _signature; } - ZT_ALWAYS_INLINE unsigned int signatureLength() const noexcept { return _signatureLength; } + ZT_INLINE uint64_t networkId() const noexcept { return _networkId; } + ZT_INLINE int64_t timestamp() const noexcept { return _ts; } + ZT_INLINE uint32_t id() const noexcept { return _id; } + ZT_INLINE const Address &issuedTo() const noexcept { return _issuedTo; } + ZT_INLINE const Address &signer() const noexcept { return _signedBy; } + ZT_INLINE const uint8_t *signature() const noexcept { return _signature; } + ZT_INLINE unsigned int signatureLength() const noexcept { return _signatureLength; } - ZT_ALWAYS_INLINE unsigned int thingCount() const noexcept { return (unsigned int)_thingCount; } - ZT_ALWAYS_INLINE Thing thingType(const unsigned int i) const noexcept { return (Thing)_thingTypes[i]; } - ZT_ALWAYS_INLINE const uint8_t *thingValue(const unsigned int i) const noexcept { return _thingValues[i]; } + ZT_INLINE unsigned int thingCount() const noexcept { return (unsigned int)_thingCount; } + ZT_INLINE Thing thingType(const unsigned int i) const noexcept { return (Thing)_thingTypes[i]; } + ZT_INLINE const uint8_t *thingValue(const unsigned int i) const noexcept { return _thingValues[i]; } - ZT_ALWAYS_INLINE bool owns(const InetAddress &ip) const noexcept + ZT_INLINE bool owns(const InetAddress &ip) const noexcept { if (ip.family() == AF_INET) return this->_owns(THING_IPV4_ADDRESS,&(reinterpret_cast(&ip)->sin_addr.s_addr),4); @@ -92,7 +92,7 @@ public: return false; } - ZT_ALWAYS_INLINE bool owns(const MAC &mac) const noexcept + ZT_INLINE bool owns(const MAC &mac) const noexcept { uint8_t tmp[6]; mac.copyTo(tmp); @@ -132,20 +132,20 @@ public: * @param tPtr That pointer we pass around * @return Credential verification result: OK, bad signature, or identity needed */ - ZT_ALWAYS_INLINE Credential::VerifyResult verify(const RuntimeEnvironment *RR,void *tPtr) const { return _verify(RR,tPtr,*this); } + ZT_INLINE Credential::VerifyResult verify(const RuntimeEnvironment *RR,void *tPtr) const { return _verify(RR,tPtr,*this); } static constexpr int marshalSizeMax() noexcept { return ZT_CERTIFICATEOFOWNERSHIP_MARSHAL_SIZE_MAX; } int marshal(uint8_t data[ZT_CERTIFICATEOFOWNERSHIP_MARSHAL_SIZE_MAX],bool forSign = false) const noexcept; int unmarshal(const uint8_t *data,int len) noexcept; // Provides natural sort order by ID - ZT_ALWAYS_INLINE bool operator<(const CertificateOfOwnership &coo) const noexcept { return (_id < coo._id); } + ZT_INLINE bool operator<(const CertificateOfOwnership &coo) const noexcept { return (_id < coo._id); } - ZT_ALWAYS_INLINE bool operator==(const CertificateOfOwnership &coo) const noexcept { return (memcmp(this,&coo,sizeof(CertificateOfOwnership)) == 0); } - ZT_ALWAYS_INLINE bool operator!=(const CertificateOfOwnership &coo) const noexcept { return (memcmp(this,&coo,sizeof(CertificateOfOwnership)) != 0); } + ZT_INLINE bool operator==(const CertificateOfOwnership &coo) const noexcept { return (memcmp(this,&coo,sizeof(CertificateOfOwnership)) == 0); } + ZT_INLINE bool operator!=(const CertificateOfOwnership &coo) const noexcept { return (memcmp(this,&coo,sizeof(CertificateOfOwnership)) != 0); } private: - ZT_ALWAYS_INLINE bool _owns(const Thing &t,const void *v,unsigned int l) const noexcept + ZT_INLINE bool _owns(const Thing &t,const void *v,unsigned int l) const noexcept { for(unsigned int i=0,j=_thingCount;i -static ZT_ALWAYS_INLINE Credential::VerifyResult _credVerify(const RuntimeEnvironment *RR,void *tPtr,CRED credential) +static ZT_INLINE Credential::VerifyResult _credVerify(const RuntimeEnvironment *RR,void *tPtr,CRED credential) { uint8_t tmp[ZT_BUF_MEM_SIZE + 16]; diff --git a/node/Defragmenter.hpp b/node/Defragmenter.hpp index 161aa1d83..025592f47 100644 --- a/node/Defragmenter.hpp +++ b/node/Defragmenter.hpp @@ -89,7 +89,7 @@ public: ERR_OUT_OF_MEMORY }; - ZT_ALWAYS_INLINE Defragmenter() : + ZT_INLINE Defragmenter() : _messages(GCT * 2) { } @@ -136,7 +136,7 @@ public: * @param maxIncomingFragmentsPerPath If via is non-NULL this is a cutoff for maximum fragments in flight via this path * @return Result code */ - ZT_ALWAYS_INLINE ResultCode assemble( + ZT_INLINE ResultCode assemble( const uint64_t messageId, FCV< Buf::Slice,MF > &message, SharedPtr &fragment, @@ -277,7 +277,7 @@ public: /** * Erase all message entries in the internal queue */ - ZT_ALWAYS_INLINE void clear() + ZT_INLINE void clear() { RWMutex::Lock ml(_messages_l); _messages.clear(); @@ -286,7 +286,7 @@ public: /** * @return Number of entries currently in message defragmentation cache */ - ZT_ALWAYS_INLINE unsigned int cacheSize() noexcept + ZT_INLINE unsigned int cacheSize() noexcept { RWMutex::RLock ml(_messages_l); return _messages.size(); @@ -295,8 +295,8 @@ public: private: struct _E { - ZT_ALWAYS_INLINE _E() noexcept : id(0),lastUsed(0),totalFragmentsExpected(0),fragmentsReceived(0),via(),message(),lock() {} - ZT_ALWAYS_INLINE ~_E() + ZT_INLINE _E() noexcept : id(0),lastUsed(0),totalFragmentsExpected(0),fragmentsReceived(0),via(),message(),lock() {} + ZT_INLINE ~_E() { if (via) { via->_inboundFragmentedMessages_l.lock(); diff --git a/node/Dictionary.hpp b/node/Dictionary.hpp index 04b9c6285..458e182c3 100644 --- a/node/Dictionary.hpp +++ b/node/Dictionary.hpp @@ -81,9 +81,9 @@ public: */ void add(const char *k,uint64_t v); - ZT_ALWAYS_INLINE void add(const char *k,int16_t v) { add(k,(uint16_t)v); } - ZT_ALWAYS_INLINE void add(const char *k,int32_t v) { add(k,(uint32_t)v); } - ZT_ALWAYS_INLINE void add(const char *k,int64_t v) { add(k,(uint64_t)v); } + ZT_INLINE void add(const char *k,int16_t v) { add(k,(uint16_t)v); } + ZT_INLINE void add(const char *k,int32_t v) { add(k,(uint32_t)v); } + ZT_INLINE void add(const char *k,int64_t v) { add(k,(uint64_t)v); } /** * Add an address in 10-digit hex string format @@ -138,12 +138,12 @@ public: /** * @return Number of entries */ - ZT_ALWAYS_INLINE unsigned int size() const noexcept { return _t.size(); } + ZT_INLINE unsigned int size() const noexcept { return _t.size(); } /** * @return True if dictionary is not empty */ - ZT_ALWAYS_INLINE bool empty() const noexcept { return _t.empty(); } + ZT_INLINE bool empty() const noexcept { return _t.empty(); } /** * Encode to a string in the supplied vector diff --git a/node/ECC384.cpp b/node/ECC384.cpp index 2274ac3d3..9f1d1dc25 100644 --- a/node/ECC384.cpp +++ b/node/ECC384.cpp @@ -49,13 +49,13 @@ const EccPoint curve_G = CONCAT(Curve_G_, ECC_CURVE); const uint64_t curve_n[NUM_ECC_DIGITS] = CONCAT(Curve_N_, ECC_CURVE); // Use ZeroTier's secure PRNG -ZT_ALWAYS_INLINE int getRandomNumber(uint64_t *p_vli) +ZT_INLINE int getRandomNumber(uint64_t *p_vli) { Utils::getSecureRandom(p_vli,ECC_BYTES); return 1; } -ZT_ALWAYS_INLINE void vli_clear(uint64_t *p_vli) +ZT_INLINE void vli_clear(uint64_t *p_vli) { uint i; for(i=0; i= 0; --i) @@ -147,7 +147,7 @@ ZT_ALWAYS_INLINE int vli_cmp(const uint64_t *p_left, const uint64_t *p_right) } /* Computes p_result = p_in << c, returning carry. Can modify in place (if p_result == p_in). 0 < p_shift < 64. */ -ZT_ALWAYS_INLINE uint64_t vli_lshift(uint64_t *p_result, const uint64_t *p_in, uint p_shift) +ZT_INLINE uint64_t vli_lshift(uint64_t *p_result,const uint64_t *p_in,uint p_shift) { uint64_t l_carry = 0; uint i; @@ -162,7 +162,7 @@ ZT_ALWAYS_INLINE uint64_t vli_lshift(uint64_t *p_result, const uint64_t *p_in, u } /* Computes p_vli = p_vli >> 1. */ -ZT_ALWAYS_INLINE void vli_rshift1(uint64_t *p_vli) +ZT_INLINE void vli_rshift1(uint64_t *p_vli) { uint64_t *l_end = p_vli; uint64_t l_carry = 0; @@ -177,7 +177,7 @@ ZT_ALWAYS_INLINE void vli_rshift1(uint64_t *p_vli) } /* Computes p_result = p_left + p_right, returning carry. Can modify in place. */ -ZT_ALWAYS_INLINE uint64_t vli_add(uint64_t *p_result, const uint64_t *p_left, const uint64_t *p_right) +ZT_INLINE uint64_t vli_add(uint64_t *p_result,const uint64_t *p_left,const uint64_t *p_right) { uint64_t l_carry = 0; uint i; @@ -194,7 +194,7 @@ ZT_ALWAYS_INLINE uint64_t vli_add(uint64_t *p_result, const uint64_t *p_left, co } /* Computes p_result = p_left - p_right, returning borrow. Can modify in place. */ -ZT_ALWAYS_INLINE uint64_t vli_sub(uint64_t *p_result, const uint64_t *p_left, const uint64_t *p_right) +ZT_INLINE uint64_t vli_sub(uint64_t *p_result,const uint64_t *p_left,const uint64_t *p_right) { uint64_t l_borrow = 0; uint i; @@ -296,7 +296,7 @@ uint128_t mul_64_64(uint64_t p_left, uint64_t p_right) return l_result; } -ZT_ALWAYS_INLINE uint128_t add_128_128(uint128_t a, uint128_t b) +ZT_INLINE uint128_t add_128_128(uint128_t a, uint128_t b) { uint128_t l_result; l_result.m_low = a.m_low + b.m_low; @@ -449,7 +449,7 @@ void vli_mmod_fast(uint64_t *p_result, uint64_t *p_product) } /* Computes p_result = (p_left * p_right) % curve_p. */ -ZT_ALWAYS_INLINE void vli_modMult_fast(uint64_t *p_result, uint64_t *p_left, const uint64_t *p_right) +ZT_INLINE void vli_modMult_fast(uint64_t *p_result,uint64_t *p_left,const uint64_t *p_right) { uint64_t l_product[2 * NUM_ECC_DIGITS]; vli_mult(l_product, p_left, p_right); @@ -457,7 +457,7 @@ ZT_ALWAYS_INLINE void vli_modMult_fast(uint64_t *p_result, uint64_t *p_left, con } /* Computes p_result = p_left^2 % curve_p. */ -ZT_ALWAYS_INLINE void vli_modSquare_fast(uint64_t *p_result, uint64_t *p_left) +ZT_INLINE void vli_modSquare_fast(uint64_t *p_result,uint64_t *p_left) { uint64_t l_product[2 * NUM_ECC_DIGITS]; vli_square(l_product, p_left); @@ -561,7 +561,7 @@ void vli_modInv(uint64_t *p_result, uint64_t *p_input, const uint64_t *p_mod) /* ------ Point operations ------ */ /* Returns 1 if p_point is the point at infinity, 0 otherwise. */ -ZT_ALWAYS_INLINE int EccPoint_isZero(EccPoint *p_point) +ZT_INLINE int EccPoint_isZero(EccPoint *p_point) { return (vli_isZero(p_point->x) && vli_isZero(p_point->y)); } @@ -757,7 +757,7 @@ void EccPoint_mult(EccPoint *p_result, const EccPoint *p_point, uint64_t *p_scal vli_set(p_result->y, Ry[0]); } -ZT_ALWAYS_INLINE void ecc_bytes2native(uint64_t p_native[NUM_ECC_DIGITS], const uint8_t p_bytes[ECC_BYTES]) +ZT_INLINE void ecc_bytes2native(uint64_t p_native[NUM_ECC_DIGITS],const uint8_t p_bytes[ECC_BYTES]) { unsigned i; for(i=0; i b ? a : b); } -ZT_ALWAYS_INLINE int ecdsa_sign(const uint8_t p_privateKey[ECC_BYTES], const uint8_t p_hash[ECC_BYTES], uint8_t p_signature[ECC_BYTES*2]) +ZT_INLINE int ecdsa_sign(const uint8_t p_privateKey[ECC_BYTES],const uint8_t p_hash[ECC_BYTES],uint8_t p_signature[ECC_BYTES * 2]) { uint64_t k[NUM_ECC_DIGITS]; uint64_t l_tmp[NUM_ECC_DIGITS]; @@ -998,7 +998,7 @@ ZT_ALWAYS_INLINE int ecdsa_sign(const uint8_t p_privateKey[ECC_BYTES], const uin return 1; } -ZT_ALWAYS_INLINE int ecdsa_verify(const uint8_t p_publicKey[ECC_BYTES+1], const uint8_t p_hash[ECC_BYTES], const uint8_t p_signature[ECC_BYTES*2]) +ZT_INLINE int ecdsa_verify(const uint8_t p_publicKey[ECC_BYTES + 1],const uint8_t p_hash[ECC_BYTES],const uint8_t p_signature[ECC_BYTES * 2]) { uint64_t u1[NUM_ECC_DIGITS], u2[NUM_ECC_DIGITS]; uint64_t z[NUM_ECC_DIGITS]; diff --git a/node/Endpoint.cpp b/node/Endpoint.cpp index 9f8c5989b..69949996e 100644 --- a/node/Endpoint.cpp +++ b/node/Endpoint.cpp @@ -20,7 +20,7 @@ bool Endpoint::operator==(const Endpoint &ep) const if (_t == ep._t) { switch(_t) { default: return true; - case TYPE_ZEROTIER: return ((_v.zt.a == ep._v.zt.a)&&(memcmp(_v.zt.idh,ep._v.zt.idh,sizeof(_v.zt.idh)) == 0)); + case TYPE_ZEROTIER: return ((_v.zt.address == ep._v.zt.address)&&(memcmp(_v.zt.hash,ep._v.zt.hash,sizeof(_v.zt.hash)) == 0)); case TYPE_DNSNAME: return ((_v.dns.port == ep._v.dns.port)&&(strcmp(_v.dns.name,ep._v.dns.name) == 0)); case TYPE_URL: return (strcmp(_v.url,ep._v.url) == 0); case TYPE_ETHERNET: return (_v.eth == ep._v.eth); @@ -38,7 +38,7 @@ bool Endpoint::operator<(const Endpoint &ep) const } else if (_t == ep._t) { int ncmp; switch(_t) { - case TYPE_ZEROTIER: return (_v.zt.a < ep._v.zt.a) ? true : ((_v.zt.a == ep._v.zt.a)&&(memcmp(_v.zt.idh,ep._v.zt.idh,sizeof(_v.zt.idh)) < 0)); + case TYPE_ZEROTIER: return (_v.zt.address < ep._v.zt.address) ? true : ((_v.zt.address == ep._v.zt.address)&&(memcmp(_v.zt.hash,ep._v.zt.hash,sizeof(_v.zt.hash)) < 0)); case TYPE_DNSNAME: ncmp = strcmp(_v.dns.name,ep._v.dns.name); return ((ncmp < 0) ? true : (ncmp == 0)&&(_v.dns.port < ep._v.dns.port)); @@ -61,12 +61,12 @@ int Endpoint::marshal(uint8_t data[ZT_ENDPOINT_MARSHAL_SIZE_MAX]) const noexcept Utils::storeBigEndian(data + 5,(uint16_t)_l[2]); switch(_t) { case TYPE_ZEROTIER: - data[7] = (uint8_t)(_v.zt.a >> 32U); - data[8] = (uint8_t)(_v.zt.a >> 24U); - data[9] = (uint8_t)(_v.zt.a >> 16U); - data[10] = (uint8_t)(_v.zt.a >> 8U); - data[11] = (uint8_t)_v.zt.a; - memcpy(data + 12,_v.zt.idh,ZT_IDENTITY_HASH_SIZE); + data[7] = (uint8_t)(_v.zt.address >> 32U); + data[8] = (uint8_t)(_v.zt.address >> 24U); + data[9] = (uint8_t)(_v.zt.address >> 16U); + data[10] = (uint8_t)(_v.zt.address >> 8U); + data[11] = (uint8_t)_v.zt.address; + memcpy(data + 12,_v.zt.hash,ZT_IDENTITY_HASH_SIZE); return ZT_IDENTITY_HASH_SIZE + 12; case TYPE_DNSNAME: p = 7; @@ -126,12 +126,12 @@ int Endpoint::unmarshal(const uint8_t *restrict data,const int len) noexcept case TYPE_ZEROTIER: if (len < (12 + ZT_IDENTITY_HASH_SIZE)) return -1; - _v.zt.a = ((uint64_t)data[7]) << 32U; - _v.zt.a |= ((uint64_t)data[8]) << 24U; - _v.zt.a |= ((uint64_t)data[9]) << 16U; - _v.zt.a |= ((uint64_t)data[10]) << 8U; - _v.zt.a |= (uint64_t)data[11]; - memcpy(_v.zt.idh,data + 12,ZT_IDENTITY_HASH_SIZE); + _v.zt.address = ((uint64_t)data[7]) << 32U; + _v.zt.address |= ((uint64_t)data[8]) << 24U; + _v.zt.address |= ((uint64_t)data[9]) << 16U; + _v.zt.address |= ((uint64_t)data[10]) << 8U; + _v.zt.address |= (uint64_t)data[11]; + memcpy(_v.zt.hash,data + 12,ZT_IDENTITY_HASH_SIZE); return 60; case TYPE_DNSNAME: if (len < 10) diff --git a/node/Endpoint.hpp b/node/Endpoint.hpp index 5abdfd7ab..988245584 100644 --- a/node/Endpoint.hpp +++ b/node/Endpoint.hpp @@ -19,6 +19,7 @@ #include "Address.hpp" #include "Utils.hpp" #include "TriviallyCopyable.hpp" +#include "Fingerprint.hpp" #include #include @@ -67,9 +68,9 @@ public: PROTO_IP_ZT = 2 }; - ZT_ALWAYS_INLINE Endpoint() noexcept { memoryZero(this); } + ZT_INLINE Endpoint() noexcept { memoryZero(this); } - explicit ZT_ALWAYS_INLINE Endpoint(const InetAddress &sa,const Protocol proto = PROTO_UDP_ZT) + ZT_INLINE Endpoint(const InetAddress &sa,const Protocol proto = PROTO_UDP_ZT) { switch (sa.family()) { case AF_INET: @@ -85,21 +86,21 @@ public: _v.in.proto = (uint8_t)proto; } - ZT_ALWAYS_INLINE Endpoint(const Address &zt,const uint8_t identityHash[ZT_IDENTITY_HASH_SIZE]) : + ZT_INLINE Endpoint(const Address &zt,const uint8_t identityHash[ZT_IDENTITY_HASH_SIZE]) : _t(TYPE_ZEROTIER) { - _v.zt.a = zt.toInt(); - memcpy(_v.zt.idh,identityHash,ZT_IDENTITY_HASH_SIZE); + _v.zt.address = zt.toInt(); + memcpy(_v.zt.hash,identityHash,ZT_IDENTITY_HASH_SIZE); } - ZT_ALWAYS_INLINE Endpoint(const char *name,const int port) : + ZT_INLINE Endpoint(const char *name,const int port) : _t(TYPE_DNSNAME) { _v.dns.port = port; Utils::scopy(_v.dns.name,sizeof(_v.dns.name),name); } - explicit ZT_ALWAYS_INLINE Endpoint(const char *url) : + explicit ZT_INLINE Endpoint(const char *url) : _t(TYPE_URL) { Utils::scopy(_v.url,sizeof(_v.url),url); @@ -108,56 +109,56 @@ public: /** * @return InetAddress or NIL if not of this type */ - ZT_ALWAYS_INLINE const InetAddress &inetAddr() const noexcept { return ((_t == TYPE_INETADDR_V4)||(_t == TYPE_INETADDR_V6)) ? asInetAddress(_v.in.sa) : InetAddress::NIL; } + ZT_INLINE const InetAddress &inetAddr() const noexcept { return ((_t == TYPE_INETADDR_V4) || (_t == TYPE_INETADDR_V6)) ? asInetAddress(_v.in.sa) : InetAddress::NIL; } /** * @return Protocol for INETADDR types, undefined for other endpoint types */ - ZT_ALWAYS_INLINE Protocol inetAddrProto() const noexcept { return (Protocol)_v.in.proto; } + ZT_INLINE Protocol inetAddrProto() const noexcept { return (Protocol)_v.in.proto; } /** * @return DNS name or empty string if not of this type */ - ZT_ALWAYS_INLINE const char *dnsName() const noexcept { return (_t == TYPE_DNSNAME) ? _v.dns.name : ""; } + ZT_INLINE const char *dnsName() const noexcept { return (_t == TYPE_DNSNAME) ? _v.dns.name : ""; } /** * @return Port associated with DNS name or -1 if not of this type */ - ZT_ALWAYS_INLINE int dnsPort() const noexcept { return (_t == TYPE_DNSNAME) ? _v.dns.port : -1; } + ZT_INLINE int dnsPort() const noexcept { return (_t == TYPE_DNSNAME) ? _v.dns.port : -1; } /** * @return ZeroTier address or NIL if not of this type */ - ZT_ALWAYS_INLINE Address ztAddress() const noexcept { return Address((_t == TYPE_ZEROTIER) ? _v.zt.a : (uint64_t)0); } + ZT_INLINE Address ztAddress() const noexcept { return Address((_t == TYPE_ZEROTIER) ? _v.zt.address : (uint64_t)0); } /** * @return 384-bit hash of identity keys or NULL if not of this type */ - ZT_ALWAYS_INLINE const uint8_t *ztIdentityHash() const noexcept { return (_t == TYPE_ZEROTIER) ? _v.zt.idh : nullptr; } + ZT_INLINE const Fingerprint &ztFingerprint() const noexcept { return *reinterpret_cast(&_v.zt); } /** * @return URL or empty string if not of this type */ - ZT_ALWAYS_INLINE const char *url() const noexcept { return (_t == TYPE_URL) ? _v.url : ""; } + ZT_INLINE const char *url() const noexcept { return (_t == TYPE_URL) ? _v.url : ""; } /** * @return Ethernet address or NIL if not of this type */ - ZT_ALWAYS_INLINE MAC ethernet() const noexcept { return (_t == TYPE_ETHERNET) ? MAC(_v.eth) : MAC(); } + ZT_INLINE MAC ethernet() const noexcept { return (_t == TYPE_ETHERNET) ? MAC(_v.eth) : MAC(); } /** * @return Endpoint type or NIL if unset/empty */ - ZT_ALWAYS_INLINE Type type() const noexcept { return _t; } + ZT_INLINE Type type() const noexcept { return _t; } - explicit ZT_ALWAYS_INLINE operator bool() const noexcept { return _t != TYPE_NIL; } + ZT_INLINE operator bool() const noexcept { return _t != TYPE_NIL; } bool operator==(const Endpoint &ep) const; - ZT_ALWAYS_INLINE bool operator!=(const Endpoint &ep) const { return (!(*this == ep)); } + ZT_INLINE bool operator!=(const Endpoint &ep) const { return (!(*this == ep)); } bool operator<(const Endpoint &ep) const; - ZT_ALWAYS_INLINE bool operator>(const Endpoint &ep) const { return (ep < *this); } - ZT_ALWAYS_INLINE bool operator<=(const Endpoint &ep) const { return !(ep < *this); } - ZT_ALWAYS_INLINE bool operator>=(const Endpoint &ep) const { return !(*this < ep); } + ZT_INLINE bool operator>(const Endpoint &ep) const { return (ep < *this); } + ZT_INLINE bool operator<=(const Endpoint &ep) const { return !(ep < *this); } + ZT_INLINE bool operator>=(const Endpoint &ep) const { return !(*this < ep); } static constexpr int marshalSizeMax() noexcept { return ZT_ENDPOINT_MARSHAL_SIZE_MAX; } int marshal(uint8_t data[ZT_ENDPOINT_MARSHAL_SIZE_MAX]) const noexcept; @@ -175,10 +176,7 @@ private: uint16_t port; char name[ZT_ENDPOINT_MAX_NAME_SIZE]; } dns; - struct { - uint64_t a; - uint8_t idh[ZT_IDENTITY_HASH_SIZE]; - } zt; + ZT_Fingerprint zt; char url[ZT_ENDPOINT_MAX_NAME_SIZE]; uint64_t eth; } _v; diff --git a/node/Expect.hpp b/node/Expect.hpp index e6f1039ed..1a869ccd9 100644 --- a/node/Expect.hpp +++ b/node/Expect.hpp @@ -47,7 +47,7 @@ namespace ZeroTier { class Expect { public: - ZT_ALWAYS_INLINE Expect() : _salt(Utils::getSecureRandomU64()) {} + ZT_INLINE Expect() : _salt(Utils::getSecureRandomU64()) {} /** * Called by other code when something is sending a packet that may receive an OK response @@ -55,7 +55,7 @@ public: * @param packetId Packet ID of packet being sent (be sure it's post-armor()) * @param now Current time */ - ZT_ALWAYS_INLINE void sending(const uint64_t packetId,const int64_t now) noexcept + ZT_INLINE void sending(const uint64_t packetId,const int64_t now) noexcept { _packetIdSent[Utils::hash64(packetId ^ _salt) % ZT_EXPECT_BUCKETS].store((int32_t)(now / ZT_EXPECT_TTL)); } @@ -67,7 +67,7 @@ public: * @param now * @return */ - ZT_ALWAYS_INLINE bool expecting(const uint64_t inRePacketId,const int64_t now) const noexcept + ZT_INLINE bool expecting(const uint64_t inRePacketId,const int64_t now) const noexcept { return (((now / ZT_EXPECT_TTL) - (int64_t)_packetIdSent[Utils::hash64(inRePacketId ^ _salt) % ZT_EXPECT_BUCKETS].load()) <= 1); } diff --git a/node/FCV.hpp b/node/FCV.hpp index ea4f35b34..da9fd3f5c 100644 --- a/node/FCV.hpp +++ b/node/FCV.hpp @@ -43,12 +43,12 @@ public: typedef T * iterator; typedef const T * const_iterator; - ZT_ALWAYS_INLINE FCV() noexcept : _s(0) {} - ZT_ALWAYS_INLINE FCV(const FCV &v) : _s(0) { *this = v; } + ZT_INLINE FCV() noexcept : _s(0) {} + ZT_INLINE FCV(const FCV &v) : _s(0) { *this = v; } - ZT_ALWAYS_INLINE ~FCV() { this->clear(); } + ZT_INLINE ~FCV() { this->clear(); } - ZT_ALWAYS_INLINE FCV &operator=(const FCV &v) + ZT_INLINE FCV &operator=(const FCV &v) { if (&v != this) { this->clear(); @@ -63,7 +63,7 @@ public: /** * Clear this vector, destroying all content objects */ - ZT_ALWAYS_INLINE void clear() + ZT_INLINE void clear() { const unsigned int s = _s; _s = 0; @@ -74,7 +74,7 @@ public: /** * Clear without calling destructors (same as unsafeResize(0)) */ - ZT_ALWAYS_INLINE void unsafeClear() noexcept { _s = 0; } + ZT_INLINE void unsafeClear() noexcept { _s = 0; } /** * This does a straight copy of one vector's data to another @@ -88,7 +88,7 @@ public: * @param v Other vector to copy to this one */ template - ZT_ALWAYS_INLINE void unsafeAssign(const FCV &v) noexcept + ZT_INLINE void unsafeAssign(const FCV &v) noexcept { _s = ((C2 > C)&&(v._s > C)) ? C : v._s; memcpy(_m,v._m,_s * sizeof(T)); @@ -102,22 +102,22 @@ public: * * @param v Target vector */ - ZT_ALWAYS_INLINE void unsafeMoveTo(FCV &v) noexcept + ZT_INLINE void unsafeMoveTo(FCV &v) noexcept { memcpy(v._m,_m,(v._s = _s) * sizeof(T)); _s = 0; } - ZT_ALWAYS_INLINE iterator begin() noexcept { return reinterpret_cast(_m); } - ZT_ALWAYS_INLINE const_iterator begin() const noexcept { return reinterpret_cast(_m); } - ZT_ALWAYS_INLINE iterator end() noexcept { return reinterpret_cast(_m) + _s; } - ZT_ALWAYS_INLINE const_iterator end() const noexcept { return reinterpret_cast(_m) + _s; } + ZT_INLINE iterator begin() noexcept { return reinterpret_cast(_m); } + ZT_INLINE const_iterator begin() const noexcept { return reinterpret_cast(_m); } + ZT_INLINE iterator end() noexcept { return reinterpret_cast(_m) + _s; } + ZT_INLINE const_iterator end() const noexcept { return reinterpret_cast(_m) + _s; } - ZT_ALWAYS_INLINE T &operator[](const unsigned int i) noexcept { return reinterpret_cast(_m)[i]; } - ZT_ALWAYS_INLINE const T &operator[](const unsigned int i) const noexcept { return reinterpret_cast(_m)[i]; } + ZT_INLINE T &operator[](const unsigned int i) noexcept { return reinterpret_cast(_m)[i]; } + ZT_INLINE const T &operator[](const unsigned int i) const noexcept { return reinterpret_cast(_m)[i]; } - ZT_ALWAYS_INLINE unsigned int size() const noexcept { return _s; } - ZT_ALWAYS_INLINE bool empty() const noexcept { return (_s == 0); } + ZT_INLINE unsigned int size() const noexcept { return _s; } + ZT_INLINE bool empty() const noexcept { return (_s == 0); } static constexpr unsigned int capacity() noexcept { return C; } /** @@ -127,7 +127,7 @@ public: * * @param v Value to push */ - ZT_ALWAYS_INLINE void push_back(const T &v) + ZT_INLINE void push_back(const T &v) { if (_s < C) new (reinterpret_cast(_m) + _s++) T(v); @@ -138,7 +138,7 @@ public: * * @return Reference to new item */ - ZT_ALWAYS_INLINE T &push() + ZT_INLINE T &push() { if (_s < C) { return *(new(reinterpret_cast(_m) + _s++) T()); @@ -152,7 +152,7 @@ public: * * @return Reference to new item */ - ZT_ALWAYS_INLINE T &push(const T &v) + ZT_INLINE T &push(const T &v) { if (_s < C) { return *(new(reinterpret_cast(_m) + _s++) T(v)); @@ -166,7 +166,7 @@ public: /** * Remove the last element if this vector is not empty */ - ZT_ALWAYS_INLINE void pop_back() + ZT_INLINE void pop_back() { if (_s != 0) (reinterpret_cast(_m) + --_s)->~T(); @@ -177,7 +177,7 @@ public: * * @param ns New size (clipped to C if larger than capacity) */ - ZT_ALWAYS_INLINE void resize(unsigned int ns) + ZT_INLINE void resize(unsigned int ns) { if (ns > C) ns = C; @@ -197,7 +197,7 @@ public: * * @param ns New size (clipped to C if larger than capacity) */ - ZT_ALWAYS_INLINE void unsafeResize(const unsigned int ns) noexcept { _s = (ns > C) ? C : ns; } + ZT_INLINE void unsafeResize(const unsigned int ns) noexcept { _s = (ns > C) ? C : ns; } /** * This is a bounds checked auto-resizing variant of the [] operator @@ -208,7 +208,7 @@ public: * @param i Index to obtain as a reference, resizing if needed * @return Reference to value at this index */ - ZT_ALWAYS_INLINE T &at(unsigned int i) + ZT_INLINE T &at(unsigned int i) { if (i >= _s) { if (unlikely(i >= C)) @@ -230,7 +230,7 @@ public: * @param end Ending iterator (must be greater than start) */ template - ZT_ALWAYS_INLINE void assign(X start,const X &end) + ZT_INLINE void assign(X start,const X &end) { const int l = std::min((int)std::distance(start,end),(int)C); if (l > 0) { @@ -242,7 +242,7 @@ public: } } - ZT_ALWAYS_INLINE bool operator==(const FCV &v) const noexcept + ZT_INLINE bool operator==(const FCV &v) const noexcept { if (_s == v._s) { for(unsigned int i=0;i<_s;++i) { @@ -253,11 +253,11 @@ public: } return false; } - ZT_ALWAYS_INLINE bool operator!=(const FCV &v) const noexcept { return (!(*this == v)); } - ZT_ALWAYS_INLINE bool operator<(const FCV &v) const noexcept { return std::lexicographical_compare(begin(),end(),v.begin(),v.end()); } - ZT_ALWAYS_INLINE bool operator>(const FCV &v) const noexcept { return (v < *this); } - ZT_ALWAYS_INLINE bool operator<=(const FCV &v) const noexcept { return !(v < *this); } - ZT_ALWAYS_INLINE bool operator>=(const FCV &v) const noexcept { return !(*this < v); } + ZT_INLINE bool operator!=(const FCV &v) const noexcept { return (!(*this == v)); } + ZT_INLINE bool operator<(const FCV &v) const noexcept { return std::lexicographical_compare(begin(),end(),v.begin(),v.end()); } + ZT_INLINE bool operator>(const FCV &v) const noexcept { return (v < *this); } + ZT_INLINE bool operator<=(const FCV &v) const noexcept { return !(v < *this); } + ZT_INLINE bool operator>=(const FCV &v) const noexcept { return !(*this < v); } private: unsigned int _s; diff --git a/node/Fingerprint.hpp b/node/Fingerprint.hpp index 476ea10e3..e401cd96f 100644 --- a/node/Fingerprint.hpp +++ b/node/Fingerprint.hpp @@ -28,14 +28,10 @@ namespace ZeroTier { class Identity; /** - * Container for 384-bit identity hashes + * Address and full hash of an identity's public keys. * - * The size of the hash used with this container must be a multiple of 64 bits. - * Currently it's used as H<384> and H<512>. - * - * Warning: the [] operator is not bounds checked. - * - * @tparam BITS Bits in hash, must be a multiple of 64 + * This is the same size as ZT_Fingerprint and should be cast-able back and forth. + * This is checked in Tests.cpp. */ class Fingerprint : public TriviallyCopyable { @@ -45,29 +41,29 @@ public: /** * Create an empty/nil fingerprint */ - ZT_ALWAYS_INLINE Fingerprint() noexcept { memoryZero(this); } + ZT_INLINE Fingerprint() noexcept { memoryZero(this); } - ZT_ALWAYS_INLINE Address address() const noexcept { return Address(_fp.address); } - ZT_ALWAYS_INLINE const uint8_t *hash() const noexcept { return _fp.hash; } + ZT_INLINE Address address() const noexcept { return Address(_fp.address); } + ZT_INLINE const uint8_t *hash() const noexcept { return _fp.hash; } /** * Copy into ZT_Fingerprint struct as used in API and trace messages * * @param fp ZT_Fingerprint */ - ZT_ALWAYS_INLINE void getAPIFingerprint(ZT_Fingerprint *fp) const noexcept { memcpy(fp,&_fp,sizeof(ZT_Fingerprint)); } + ZT_INLINE void getAPIFingerprint(ZT_Fingerprint *fp) const noexcept { memcpy(fp,&_fp,sizeof(ZT_Fingerprint)); } /** * @return Pointer to ZT_Fingerprint for API use */ - ZT_ALWAYS_INLINE const ZT_Fingerprint *apiFingerprint() const noexcept { return &_fp; } + ZT_INLINE const ZT_Fingerprint *apiFingerprint() const noexcept { return &_fp; } /** * Get a base32-encoded representation of this fingerprint * * @param s Base32 string */ - ZT_ALWAYS_INLINE void toString(char s[ZT_FINGERPRINT_STRING_BUFFER_LENGTH]) + ZT_INLINE void toString(char s[ZT_FINGERPRINT_STRING_BUFFER_LENGTH]) { uint8_t tmp[48 + 5]; address().copyTo(tmp); @@ -82,7 +78,7 @@ public: * @param s String to decode * @return True if string appears to be valid and of the proper length (no other checking is done) */ - ZT_ALWAYS_INLINE bool fromString(const char *s) + ZT_INLINE bool fromString(const char *s) { uint8_t tmp[48 + 5]; if (Utils::b32d(s,tmp,sizeof(tmp)) != sizeof(tmp)) @@ -92,17 +88,17 @@ public: return true; } - ZT_ALWAYS_INLINE void zero() noexcept { memoryZero(this); } - ZT_ALWAYS_INLINE unsigned long hashCode() const noexcept { return _fp.address; } + ZT_INLINE void zero() noexcept { memoryZero(this); } + ZT_INLINE unsigned long hashCode() const noexcept { return _fp.address; } - ZT_ALWAYS_INLINE operator bool() const noexcept { return (_fp.address != 0); } + ZT_INLINE operator bool() const noexcept { return (_fp.address != 0); } - ZT_ALWAYS_INLINE bool operator==(const Fingerprint &h) const noexcept { return ((_fp.address == h._fp.address)&&(memcmp(_fp.hash,h._fp.hash,ZT_IDENTITY_HASH_SIZE) == 0)); } - ZT_ALWAYS_INLINE bool operator!=(const Fingerprint &h) const noexcept { return !(*this == h); } - ZT_ALWAYS_INLINE bool operator<(const Fingerprint &h) const noexcept { return ((_fp.address < h._fp.address) || ((_fp.address == h._fp.address)&&(memcmp(_fp.hash,h._fp.hash,ZT_IDENTITY_HASH_SIZE) < 0))); } - ZT_ALWAYS_INLINE bool operator>(const Fingerprint &h) const noexcept { return (h < *this); } - ZT_ALWAYS_INLINE bool operator<=(const Fingerprint &h) const noexcept { return !(h < *this); } - ZT_ALWAYS_INLINE bool operator>=(const Fingerprint &h) const noexcept { return !(*this < h); } + ZT_INLINE bool operator==(const Fingerprint &h) const noexcept { return ((_fp.address == h._fp.address) && (memcmp(_fp.hash,h._fp.hash,ZT_IDENTITY_HASH_SIZE) == 0)); } + ZT_INLINE bool operator!=(const Fingerprint &h) const noexcept { return !(*this == h); } + ZT_INLINE bool operator<(const Fingerprint &h) const noexcept { return ((_fp.address < h._fp.address) || ((_fp.address == h._fp.address) && (memcmp(_fp.hash,h._fp.hash,ZT_IDENTITY_HASH_SIZE) < 0))); } + ZT_INLINE bool operator>(const Fingerprint &h) const noexcept { return (h < *this); } + ZT_INLINE bool operator<=(const Fingerprint &h) const noexcept { return !(h < *this); } + ZT_INLINE bool operator>=(const Fingerprint &h) const noexcept { return !(*this < h); } private: ZT_Fingerprint _fp; diff --git a/node/Hashtable.hpp b/node/Hashtable.hpp index 1072cb915..4ef84e5bf 100644 --- a/node/Hashtable.hpp +++ b/node/Hashtable.hpp @@ -34,10 +34,10 @@ class Hashtable private: struct _Bucket { - ZT_ALWAYS_INLINE _Bucket(const K &k,const V &v) : k(k),v(v) {} - explicit ZT_ALWAYS_INLINE _Bucket(const K &k) : k(k),v() {} - ZT_ALWAYS_INLINE _Bucket(const _Bucket &b) : k(b.k),v(b.v) {} - ZT_ALWAYS_INLINE _Bucket &operator=(const _Bucket &b) { k = b.k; v = b.v; return *this; } + ZT_INLINE _Bucket(const K &k,const V &v) : k(k),v(v) {} + explicit ZT_INLINE _Bucket(const K &k) : k(k),v() {} + ZT_INLINE _Bucket(const _Bucket &b) : k(b.k),v(b.v) {} + ZT_INLINE _Bucket &operator=(const _Bucket &b) { k = b.k; v = b.v; return *this; } _Bucket *next; // must be set manually for each _Bucket const K k; V v; @@ -57,7 +57,7 @@ public: /** * @param ht Hash table to iterate over */ - explicit ZT_ALWAYS_INLINE Iterator(Hashtable &ht) noexcept : + explicit ZT_INLINE Iterator(Hashtable &ht) noexcept : _idx(0), _ht(&ht), _b(ht._t[0]) @@ -69,7 +69,7 @@ public: * @param vptr Pointer to set to point to next value * @return True if kptr and vptr are set, false if no more entries */ - ZT_ALWAYS_INLINE bool next(K *&kptr,V *&vptr) + ZT_INLINE bool next(K *&kptr,V *&vptr) { for(;;) { if (_b) { @@ -95,7 +95,7 @@ public: /** * @param bc Initial capacity in buckets (default: 32, must be nonzero) */ - explicit ZT_ALWAYS_INLINE Hashtable(unsigned long bc = 32) : + explicit ZT_INLINE Hashtable(unsigned long bc = 32) : _t(reinterpret_cast<_Bucket **>(::malloc(sizeof(_Bucket *) * bc))), _bc(bc), _s(0) @@ -105,19 +105,19 @@ public: memset(_t,0,sizeof(_Bucket *) * bc); } - ZT_ALWAYS_INLINE Hashtable(const Hashtable &ht) : + ZT_INLINE Hashtable(const Hashtable &ht) : Hashtable() { *this = ht; } - ZT_ALWAYS_INLINE ~Hashtable() + ZT_INLINE ~Hashtable() { this->clear(); ::free(_t); } - ZT_ALWAYS_INLINE Hashtable &operator=(const Hashtable &ht) + ZT_INLINE Hashtable &operator=(const Hashtable &ht) { this->clear(); if (ht._s) { @@ -135,7 +135,7 @@ public: /** * Erase all entries */ - ZT_ALWAYS_INLINE void clear() + ZT_INLINE void clear() { if (_s) { for(unsigned long i=0;i<_bc;++i) { @@ -154,7 +154,7 @@ public: /** * @return Vector of all keys */ - ZT_ALWAYS_INLINE typename std::vector keys() const + ZT_INLINE typename std::vector keys() const { typename std::vector k; if (_s) { @@ -177,7 +177,7 @@ public: * @tparam Type of V (generally inferred) */ template - ZT_ALWAYS_INLINE void appendKeys(C &v) const + ZT_INLINE void appendKeys(C &v) const { if (_s) { for(unsigned long i=0;i<_bc;++i) { @@ -193,7 +193,7 @@ public: /** * @return Vector of all entries (pairs of K,V) */ - ZT_ALWAYS_INLINE typename std::vector< std::pair > entries() const + ZT_INLINE typename std::vector< std::pair > entries() const { typename std::vector< std::pair > k; if (_s) { @@ -213,7 +213,7 @@ public: * @param k Key * @return Pointer to value or NULL if not found */ - ZT_ALWAYS_INLINE V *get(const K k) + ZT_INLINE V *get(const K k) { _Bucket *b = _t[_hc(k) % _bc]; while (b) { @@ -223,14 +223,14 @@ public: } return (V *)0; } - ZT_ALWAYS_INLINE const V *get(const K k) const { return const_cast(this)->get(k); } + ZT_INLINE const V *get(const K k) const { return const_cast(this)->get(k); } /** * @param k Key * @param v Value to fill with result * @return True if value was found and set (if false, v is not modified) */ - ZT_ALWAYS_INLINE bool get(const K &k,V &v) const + ZT_INLINE bool get(const K &k,V &v) const { _Bucket *b = _t[_hc(k) % _bc]; while (b) { @@ -247,7 +247,7 @@ public: * @param k Key to check * @return True if key is present */ - ZT_ALWAYS_INLINE bool contains(const K &k) const + ZT_INLINE bool contains(const K &k) const { _Bucket *b = _t[_hc(k) % _bc]; while (b) { @@ -262,7 +262,7 @@ public: * @param k Key * @return True if value was present */ - ZT_ALWAYS_INLINE bool erase(const K &k) + ZT_INLINE bool erase(const K &k) { const unsigned long bidx = _hc(k) % _bc; _Bucket *lastb = (_Bucket *)0; @@ -287,7 +287,7 @@ public: * @param v Value * @return Reference to value in table */ - ZT_ALWAYS_INLINE V &set(const K &k,const V &v) + ZT_INLINE V &set(const K &k,const V &v) { const unsigned long h = _hc(k); unsigned long bidx = h % _bc; @@ -317,7 +317,7 @@ public: * @param k Key * @return Value, possibly newly created */ - ZT_ALWAYS_INLINE V &operator[](const K k) + ZT_INLINE V &operator[](const K k) { const unsigned long h = _hc(k); unsigned long bidx = h % _bc; @@ -344,28 +344,28 @@ public: /** * @return Number of entries */ - ZT_ALWAYS_INLINE unsigned long size() const noexcept { return _s; } + ZT_INLINE unsigned long size() const noexcept { return _s; } /** * @return True if table is empty */ - ZT_ALWAYS_INLINE bool empty() const noexcept { return (_s == 0); } + ZT_INLINE bool empty() const noexcept { return (_s == 0); } private: template - static ZT_ALWAYS_INLINE unsigned long _hc(const O &obj) { return (unsigned long)obj.hashCode(); } - static ZT_ALWAYS_INLINE unsigned long _hc(const uint64_t i) noexcept { return (unsigned long)(i ^ (i >> 32U)); } - static ZT_ALWAYS_INLINE unsigned long _hc(const uint32_t i) noexcept { return ((unsigned long)i * (unsigned long)0x9e3779b1); } - static ZT_ALWAYS_INLINE unsigned long _hc(const uint16_t i) noexcept { return ((unsigned long)i * (unsigned long)0x9e3779b1); } - static ZT_ALWAYS_INLINE unsigned long _hc(const uint8_t i) noexcept { return ((unsigned long)i * (unsigned long)0x9e3779b1); } - static ZT_ALWAYS_INLINE unsigned long _hc(const int64_t i) noexcept { return (unsigned long)((unsigned long long)i ^ ((unsigned long long)i >> 32U)); } - static ZT_ALWAYS_INLINE unsigned long _hc(const int32_t i) noexcept { return ((unsigned long)i * (unsigned long)0x9e3779b1); } - static ZT_ALWAYS_INLINE unsigned long _hc(const int16_t i) noexcept { return ((unsigned long)i * (unsigned long)0x9e3779b1); } - static ZT_ALWAYS_INLINE unsigned long _hc(const int8_t i) noexcept { return ((unsigned long)i * (unsigned long)0x9e3779b1); } - static ZT_ALWAYS_INLINE unsigned long _hc(void *p) noexcept { return ((unsigned long)((uintptr_t)p) * (unsigned long)0x9e3779b1); } - static ZT_ALWAYS_INLINE unsigned long _hc(const void *p) noexcept { return ((unsigned long)((uintptr_t)p) * (unsigned long)0x9e3779b1); } + static ZT_INLINE unsigned long _hc(const O &obj) { return (unsigned long)obj.hashCode(); } + static ZT_INLINE unsigned long _hc(const uint64_t i) noexcept { return (unsigned long)(i ^ (i >> 32U)); } + static ZT_INLINE unsigned long _hc(const uint32_t i) noexcept { return ((unsigned long)i * (unsigned long)0x9e3779b1); } + static ZT_INLINE unsigned long _hc(const uint16_t i) noexcept { return ((unsigned long)i * (unsigned long)0x9e3779b1); } + static ZT_INLINE unsigned long _hc(const uint8_t i) noexcept { return ((unsigned long)i * (unsigned long)0x9e3779b1); } + static ZT_INLINE unsigned long _hc(const int64_t i) noexcept { return (unsigned long)((unsigned long long)i ^ ((unsigned long long)i >> 32U)); } + static ZT_INLINE unsigned long _hc(const int32_t i) noexcept { return ((unsigned long)i * (unsigned long)0x9e3779b1); } + static ZT_INLINE unsigned long _hc(const int16_t i) noexcept { return ((unsigned long)i * (unsigned long)0x9e3779b1); } + static ZT_INLINE unsigned long _hc(const int8_t i) noexcept { return ((unsigned long)i * (unsigned long)0x9e3779b1); } + static ZT_INLINE unsigned long _hc(void *p) noexcept { return ((unsigned long)((uintptr_t)p) * (unsigned long)0x9e3779b1); } + static ZT_INLINE unsigned long _hc(const void *p) noexcept { return ((unsigned long)((uintptr_t)p) * (unsigned long)0x9e3779b1); } - ZT_ALWAYS_INLINE void _grow() + ZT_INLINE void _grow() { const unsigned long nc = _bc * 2; _Bucket **nt = reinterpret_cast<_Bucket **>(::malloc(sizeof(_Bucket *) * nc)); diff --git a/node/Identity.cpp b/node/Identity.cpp index 3303f2522..103cd4ff4 100644 --- a/node/Identity.cpp +++ b/node/Identity.cpp @@ -66,9 +66,9 @@ static void _computeMemoryHardHash(const void *const publicKey,unsigned int publ } struct _v0_identity_generate_cond { - ZT_ALWAYS_INLINE _v0_identity_generate_cond() noexcept {} - ZT_ALWAYS_INLINE _v0_identity_generate_cond(unsigned char *sb,char *gm) noexcept : digest(sb),genmem(gm) {} - ZT_ALWAYS_INLINE bool operator()(const uint8_t pub[ZT_C25519_PUBLIC_KEY_LEN]) const noexcept + ZT_INLINE _v0_identity_generate_cond() noexcept {} + ZT_INLINE _v0_identity_generate_cond(unsigned char *sb,char *gm) noexcept : digest(sb),genmem(gm) {} + ZT_INLINE bool operator()(const uint8_t pub[ZT_C25519_PUBLIC_KEY_LEN]) const noexcept { _computeMemoryHardHash(pub,ZT_C25519_PUBLIC_KEY_LEN,digest,genmem); return (digest[0] < 17); diff --git a/node/Identity.hpp b/node/Identity.hpp index b40bb528e..cfd14ad2a 100644 --- a/node/Identity.hpp +++ b/node/Identity.hpp @@ -63,8 +63,8 @@ public: */ static const Identity NIL; - ZT_ALWAYS_INLINE Identity() noexcept { memoryZero(this); } - ZT_ALWAYS_INLINE ~Identity() { Utils::burn(reinterpret_cast(&this->_priv),sizeof(this->_priv)); } + ZT_INLINE Identity() noexcept { memoryZero(this); } + ZT_INLINE ~Identity() { Utils::burn(reinterpret_cast(&this->_priv),sizeof(this->_priv)); } /** * Construct identity from string @@ -74,17 +74,17 @@ public: * * @param str Identity in canonical string format */ - explicit ZT_ALWAYS_INLINE Identity(const char *str) { fromString(str); } + explicit ZT_INLINE Identity(const char *str) { fromString(str); } /** * Set identity to NIL value (all zero) */ - ZT_ALWAYS_INLINE void zero() noexcept { memoryZero(this); } + ZT_INLINE void zero() noexcept { memoryZero(this); } /** * @return Identity type (undefined if identity is null or invalid) */ - ZT_ALWAYS_INLINE Type type() const noexcept { return _type; } + ZT_INLINE Type type() const noexcept { return _type; } /** * Generate a new identity (address, key pair) @@ -110,7 +110,7 @@ public: /** * @return True if this identity contains a private key */ - ZT_ALWAYS_INLINE bool hasPrivate() const noexcept { return _hasPrivate; } + ZT_INLINE bool hasPrivate() const noexcept { return _hasPrivate; } /** * Get a 384-bit hash of this identity's public key(s) @@ -124,7 +124,7 @@ public: * * @return Hash of public key(s) */ - ZT_ALWAYS_INLINE const Fingerprint &fingerprint() const noexcept { return _fp; } + ZT_INLINE const Fingerprint &fingerprint() const noexcept { return _fp; } /** * Compute a hash of this identity's public and private keys. @@ -174,7 +174,7 @@ public: /** * @return This identity's address */ - ZT_ALWAYS_INLINE const Address &address() const noexcept { return _address; } + ZT_INLINE const Address &address() const noexcept { return _address; } /** * Serialize to a more human-friendly string @@ -199,16 +199,16 @@ public: /** * @return True if this identity contains something */ - explicit ZT_ALWAYS_INLINE operator bool() const noexcept { return (_address); } + explicit ZT_INLINE operator bool() const noexcept { return (_address); } - ZT_ALWAYS_INLINE unsigned long hashCode() const noexcept { return _fp.hashCode(); } + ZT_INLINE unsigned long hashCode() const noexcept { return _fp.hashCode(); } - ZT_ALWAYS_INLINE bool operator==(const Identity &id) const noexcept { return (_fp == id._fp); } - ZT_ALWAYS_INLINE bool operator!=(const Identity &id) const noexcept { return !(*this == id); } - ZT_ALWAYS_INLINE bool operator<(const Identity &id) const noexcept { return (_fp < id._fp); } - ZT_ALWAYS_INLINE bool operator>(const Identity &id) const noexcept { return (id < *this); } - ZT_ALWAYS_INLINE bool operator<=(const Identity &id) const noexcept { return !(id < *this); } - ZT_ALWAYS_INLINE bool operator>=(const Identity &id) const noexcept { return !(*this < id); } + ZT_INLINE bool operator==(const Identity &id) const noexcept { return (_fp == id._fp); } + ZT_INLINE bool operator!=(const Identity &id) const noexcept { return !(*this == id); } + ZT_INLINE bool operator<(const Identity &id) const noexcept { return (_fp < id._fp); } + ZT_INLINE bool operator>(const Identity &id) const noexcept { return (id < *this); } + ZT_INLINE bool operator<=(const Identity &id) const noexcept { return !(id < *this); } + ZT_INLINE bool operator>=(const Identity &id) const noexcept { return !(*this < id); } static constexpr int marshalSizeMax() noexcept { return ZT_IDENTITY_MARSHAL_SIZE_MAX; } int marshal(uint8_t data[ZT_IDENTITY_MARSHAL_SIZE_MAX],bool includePrivate = false) const noexcept; diff --git a/node/InetAddress.cpp b/node/InetAddress.cpp index 553897a2e..214c94316 100644 --- a/node/InetAddress.cpp +++ b/node/InetAddress.cpp @@ -279,7 +279,10 @@ bool InetAddress::containsAddress(const InetAddress &addr) const noexcept const unsigned int bits = netmaskBits(); if (bits == 0) return true; - return ( (Utils::ntoh((uint32_t)reinterpret_cast(&addr)->sin_addr.s_addr) >> (32 - bits)) == (Utils::ntoh((uint32_t)reinterpret_cast(this)->sin_addr.s_addr) >> (32 - bits)) ); + return ( + (Utils::ntoh((uint32_t)reinterpret_cast(&addr)->sin_addr.s_addr) >> (32 - bits)) == + (Utils::ntoh((uint32_t)reinterpret_cast(this)->sin_addr.s_addr) >> (32 - bits)) + ); } case AF_INET6: { const InetAddress mask(netmask()); diff --git a/node/InetAddress.hpp b/node/InetAddress.hpp index c76eafe72..5c9313772 100644 --- a/node/InetAddress.hpp +++ b/node/InetAddress.hpp @@ -41,7 +41,7 @@ struct InetAddress : public TriviallyCopyable private: // Internal function to copy any sockaddr_X structure to this one even if it's smaller and unpadded. template - ZT_ALWAYS_INLINE void copySockaddrToThis(const SA *sa) noexcept + ZT_INLINE void copySockaddrToThis(const SA *sa) noexcept { memcpy(reinterpret_cast(this),sa,sizeof(SA)); if (sizeof(SA) < sizeof(InetAddress)) @@ -84,61 +84,61 @@ public: }; // Hasher for unordered sets and maps in C++11 - struct Hasher { ZT_ALWAYS_INLINE std::size_t operator()(const InetAddress &a) const noexcept { return (std::size_t)a.hashCode(); } }; + struct Hasher { ZT_INLINE std::size_t operator()(const InetAddress &a) const noexcept { return (std::size_t)a.hashCode(); } }; - ZT_ALWAYS_INLINE InetAddress() noexcept { memoryZero(this); } - ZT_ALWAYS_INLINE InetAddress(const InetAddress &a) noexcept { memoryCopy(this,&a); } - explicit ZT_ALWAYS_INLINE InetAddress(const sockaddr_storage &ss) noexcept { *this = ss; } - explicit ZT_ALWAYS_INLINE InetAddress(const sockaddr_storage *ss) noexcept { *this = ss; } - explicit ZT_ALWAYS_INLINE InetAddress(const sockaddr &sa) noexcept { *this = sa; } - explicit ZT_ALWAYS_INLINE InetAddress(const sockaddr *sa) noexcept { *this = sa; } - explicit ZT_ALWAYS_INLINE InetAddress(const sockaddr_in &sa) noexcept { *this = sa; } - explicit ZT_ALWAYS_INLINE InetAddress(const sockaddr_in *sa) noexcept { *this = sa; } - explicit ZT_ALWAYS_INLINE InetAddress(const sockaddr_in6 &sa) noexcept { *this = sa; } - explicit ZT_ALWAYS_INLINE InetAddress(const sockaddr_in6 *sa) noexcept { *this = sa; } - ZT_ALWAYS_INLINE InetAddress(const void *ipBytes,unsigned int ipLen,unsigned int port) noexcept { this->set(ipBytes,ipLen,port); } - ZT_ALWAYS_INLINE InetAddress(const uint32_t ipv4,unsigned int port) noexcept { this->set(&ipv4,4,port); } - explicit ZT_ALWAYS_INLINE InetAddress(const char *ipSlashPort) noexcept { this->fromString(ipSlashPort); } + ZT_INLINE InetAddress() noexcept { memoryZero(this); } + ZT_INLINE InetAddress(const InetAddress &a) noexcept { memoryCopy(this,&a); } + explicit ZT_INLINE InetAddress(const sockaddr_storage &ss) noexcept { *this = ss; } + explicit ZT_INLINE InetAddress(const sockaddr_storage *ss) noexcept { *this = ss; } + explicit ZT_INLINE InetAddress(const sockaddr &sa) noexcept { *this = sa; } + explicit ZT_INLINE InetAddress(const sockaddr *sa) noexcept { *this = sa; } + explicit ZT_INLINE InetAddress(const sockaddr_in &sa) noexcept { *this = sa; } + explicit ZT_INLINE InetAddress(const sockaddr_in *sa) noexcept { *this = sa; } + explicit ZT_INLINE InetAddress(const sockaddr_in6 &sa) noexcept { *this = sa; } + explicit ZT_INLINE InetAddress(const sockaddr_in6 *sa) noexcept { *this = sa; } + ZT_INLINE InetAddress(const void *ipBytes,unsigned int ipLen,unsigned int port) noexcept { this->set(ipBytes,ipLen,port); } + ZT_INLINE InetAddress(const uint32_t ipv4,unsigned int port) noexcept { this->set(&ipv4,4,port); } + explicit ZT_INLINE InetAddress(const char *ipSlashPort) noexcept { this->fromString(ipSlashPort); } - ZT_ALWAYS_INLINE void clear() noexcept { memoryZero(this); } + ZT_INLINE void clear() noexcept { memoryZero(this); } - ZT_ALWAYS_INLINE InetAddress &operator=(const sockaddr_storage &ss) noexcept + ZT_INLINE InetAddress &operator=(const sockaddr_storage &ss) noexcept { memoryCopyUnsafe(this,&ss); return *this; } - ZT_ALWAYS_INLINE InetAddress &operator=(const sockaddr_storage *ss) noexcept + ZT_INLINE InetAddress &operator=(const sockaddr_storage *ss) noexcept { if (ss) memoryCopyUnsafe(this,ss); else memoryZero(this); return *this; } - ZT_ALWAYS_INLINE InetAddress &operator=(const sockaddr_in &sa) noexcept + ZT_INLINE InetAddress &operator=(const sockaddr_in &sa) noexcept { copySockaddrToThis(&sa); return *this; } - ZT_ALWAYS_INLINE InetAddress &operator=(const sockaddr_in *sa) noexcept + ZT_INLINE InetAddress &operator=(const sockaddr_in *sa) noexcept { if (sa) copySockaddrToThis(sa); else memset(reinterpret_cast(this),0,sizeof(InetAddress)); return *this; } - ZT_ALWAYS_INLINE InetAddress &operator=(const sockaddr_in6 &sa) noexcept + ZT_INLINE InetAddress &operator=(const sockaddr_in6 &sa) noexcept { copySockaddrToThis(&sa); return *this; } - ZT_ALWAYS_INLINE InetAddress &operator=(const sockaddr_in6 *sa) noexcept + ZT_INLINE InetAddress &operator=(const sockaddr_in6 *sa) noexcept { if (sa) copySockaddrToThis(sa); else memset(reinterpret_cast(this),0,sizeof(InetAddress)); return *this; } - ZT_ALWAYS_INLINE InetAddress &operator=(const sockaddr &sa) noexcept + ZT_INLINE InetAddress &operator=(const sockaddr &sa) noexcept { if (sa.sa_family == AF_INET) copySockaddrToThis(reinterpret_cast(&sa)); @@ -147,7 +147,7 @@ public: else memset(reinterpret_cast(this),0,sizeof(InetAddress)); return *this; } - ZT_ALWAYS_INLINE InetAddress &operator=(const sockaddr *sa) noexcept + ZT_INLINE InetAddress &operator=(const sockaddr *sa) noexcept { if (sa) { if (sa->sa_family == AF_INET) @@ -164,7 +164,7 @@ public: /** * @return Address family (ss_family in sockaddr_storage) */ - ZT_ALWAYS_INLINE uint8_t family() const noexcept { return _data.ss_family; } + ZT_INLINE uint8_t family() const noexcept { return _data.ss_family; } /** * @return IP scope classification (e.g. loopback, link-local, private, global) @@ -185,7 +185,7 @@ public: * * @param port Port, 0 to 65535 */ - ZT_ALWAYS_INLINE void setPort(unsigned int port) noexcept + ZT_INLINE void setPort(unsigned int port) noexcept { switch(_data.ss_family) { case AF_INET: @@ -221,7 +221,7 @@ public: /** * @return Port or 0 if no port component defined */ - ZT_ALWAYS_INLINE unsigned int port() const noexcept + ZT_INLINE unsigned int port() const noexcept { switch(_data.ss_family) { case AF_INET: return Utils::ntoh((uint16_t)(reinterpret_cast(this)->sin_port)); @@ -239,12 +239,12 @@ public: * * @return Netmask bits */ - ZT_ALWAYS_INLINE unsigned int netmaskBits() const noexcept { return port(); } + ZT_INLINE unsigned int netmaskBits() const noexcept { return port(); } /** * @return True if netmask bits is valid for the address type */ - ZT_ALWAYS_INLINE bool netmaskBitsValid() const noexcept + ZT_INLINE bool netmaskBitsValid() const noexcept { const unsigned int n = port(); switch(_data.ss_family) { @@ -262,7 +262,7 @@ public: * * @return Gateway metric */ - ZT_ALWAYS_INLINE unsigned int metric() const noexcept { return port(); } + ZT_INLINE unsigned int metric() const noexcept { return port(); } /** * Construct a full netmask as an InetAddress @@ -307,17 +307,17 @@ public: /** * @return True if this is an IPv4 address */ - ZT_ALWAYS_INLINE bool isV4() const noexcept { return (family() == AF_INET); } + ZT_INLINE bool isV4() const noexcept { return (family() == AF_INET); } /** * @return True if this is an IPv6 address */ - ZT_ALWAYS_INLINE bool isV6() const noexcept { return (family() == AF_INET6); } + ZT_INLINE bool isV6() const noexcept { return (family() == AF_INET6); } /** * @return pointer to raw address bytes or NULL if not available */ - ZT_ALWAYS_INLINE const void *rawIpData() const noexcept + ZT_INLINE const void *rawIpData() const noexcept { switch(_data.ss_family) { case AF_INET: return (const void *)&(reinterpret_cast(this)->sin_addr.s_addr); @@ -329,7 +329,7 @@ public: /** * @return InetAddress containing only the IP portion of this address and a zero port, or NULL if not IPv4 or IPv6 */ - ZT_ALWAYS_INLINE InetAddress ipOnly() const noexcept + ZT_INLINE InetAddress ipOnly() const noexcept { InetAddress r; switch(_data.ss_family) { @@ -351,7 +351,7 @@ public: * @param a InetAddress to compare again * @return True if only IP portions are equal (false for non-IP or null addresses) */ - ZT_ALWAYS_INLINE bool ipsEqual(const InetAddress &a) const noexcept + ZT_INLINE bool ipsEqual(const InetAddress &a) const noexcept { const uint8_t f = _data.ss_family; if (f == a._data.ss_family) { @@ -372,7 +372,7 @@ public: * @param a InetAddress to compare again * @return True if only IP portions are equal (false for non-IP or null addresses) */ - ZT_ALWAYS_INLINE bool ipsEqual2(const InetAddress &a) const noexcept + ZT_INLINE bool ipsEqual2(const InetAddress &a) const noexcept { const uint8_t f = _data.ss_family; if (f == a._data.ss_family) { @@ -407,7 +407,7 @@ public: /** * @return True if address family is non-zero */ - explicit ZT_ALWAYS_INLINE operator bool() const noexcept { return (family() != 0); } + explicit ZT_INLINE operator bool() const noexcept { return (family() != 0); } static constexpr int marshalSizeMax() noexcept { return ZT_INETADDRESS_MARSHAL_SIZE_MAX; } int marshal(uint8_t data[ZT_INETADDRESS_MARSHAL_SIZE_MAX]) const noexcept; @@ -415,10 +415,10 @@ public: bool operator==(const InetAddress &a) const noexcept; bool operator<(const InetAddress &a) const noexcept; - ZT_ALWAYS_INLINE bool operator!=(const InetAddress &a) const noexcept { return !(*this == a); } - ZT_ALWAYS_INLINE bool operator>(const InetAddress &a) const noexcept { return (a < *this); } - ZT_ALWAYS_INLINE bool operator<=(const InetAddress &a) const noexcept { return !(a < *this); } - ZT_ALWAYS_INLINE bool operator>=(const InetAddress &a) const noexcept { return !(*this < a); } + ZT_INLINE bool operator!=(const InetAddress &a) const noexcept { return !(*this == a); } + ZT_INLINE bool operator>(const InetAddress &a) const noexcept { return (a < *this); } + ZT_INLINE bool operator<=(const InetAddress &a) const noexcept { return !(a < *this); } + ZT_INLINE bool operator>=(const InetAddress &a) const noexcept { return !(*this < a); } /** * Compute an IPv6 link-local address @@ -480,22 +480,22 @@ private: sockaddr_storage _data; }; -static ZT_ALWAYS_INLINE InetAddress *asInetAddress(sockaddr_in *p) noexcept { return reinterpret_cast(p); } -static ZT_ALWAYS_INLINE InetAddress *asInetAddress(sockaddr_in6 *p) noexcept { return reinterpret_cast(p); } -static ZT_ALWAYS_INLINE InetAddress *asInetAddress(sockaddr *p) noexcept { return reinterpret_cast(p); } -static ZT_ALWAYS_INLINE InetAddress *asInetAddress(sockaddr_storage *p) noexcept { return reinterpret_cast(p); } -static ZT_ALWAYS_INLINE const InetAddress *asInetAddress(const sockaddr_in *p) noexcept { return reinterpret_cast(p); } -static ZT_ALWAYS_INLINE const InetAddress *asInetAddress(const sockaddr_in6 *p) noexcept { return reinterpret_cast(p); } -static ZT_ALWAYS_INLINE const InetAddress *asInetAddress(const sockaddr *p) noexcept { return reinterpret_cast(p); } -static ZT_ALWAYS_INLINE const InetAddress *asInetAddress(const sockaddr_storage *p) noexcept { return reinterpret_cast(p); } -static ZT_ALWAYS_INLINE InetAddress &asInetAddress(sockaddr_in &p) noexcept { return *reinterpret_cast(&p); } -static ZT_ALWAYS_INLINE InetAddress &asInetAddress(sockaddr_in6 &p) noexcept { return *reinterpret_cast(&p); } -static ZT_ALWAYS_INLINE InetAddress &asInetAddress(sockaddr &p) noexcept { return *reinterpret_cast(&p); } -static ZT_ALWAYS_INLINE InetAddress &asInetAddress(sockaddr_storage &p) noexcept { return *reinterpret_cast(&p); } -static ZT_ALWAYS_INLINE const InetAddress &asInetAddress(const sockaddr_in &p) noexcept { return *reinterpret_cast(&p); } -static ZT_ALWAYS_INLINE const InetAddress &asInetAddress(const sockaddr_in6 &p) noexcept { return *reinterpret_cast(&p); } -static ZT_ALWAYS_INLINE const InetAddress &asInetAddress(const sockaddr &p) noexcept { return *reinterpret_cast(&p); } -static ZT_ALWAYS_INLINE const InetAddress &asInetAddress(const sockaddr_storage &p) noexcept { return *reinterpret_cast(&p); } +static ZT_INLINE InetAddress *asInetAddress(sockaddr_in *p) noexcept { return reinterpret_cast(p); } +static ZT_INLINE InetAddress *asInetAddress(sockaddr_in6 *p) noexcept { return reinterpret_cast(p); } +static ZT_INLINE InetAddress *asInetAddress(sockaddr *p) noexcept { return reinterpret_cast(p); } +static ZT_INLINE InetAddress *asInetAddress(sockaddr_storage *p) noexcept { return reinterpret_cast(p); } +static ZT_INLINE const InetAddress *asInetAddress(const sockaddr_in *p) noexcept { return reinterpret_cast(p); } +static ZT_INLINE const InetAddress *asInetAddress(const sockaddr_in6 *p) noexcept { return reinterpret_cast(p); } +static ZT_INLINE const InetAddress *asInetAddress(const sockaddr *p) noexcept { return reinterpret_cast(p); } +static ZT_INLINE const InetAddress *asInetAddress(const sockaddr_storage *p) noexcept { return reinterpret_cast(p); } +static ZT_INLINE InetAddress &asInetAddress(sockaddr_in &p) noexcept { return *reinterpret_cast(&p); } +static ZT_INLINE InetAddress &asInetAddress(sockaddr_in6 &p) noexcept { return *reinterpret_cast(&p); } +static ZT_INLINE InetAddress &asInetAddress(sockaddr &p) noexcept { return *reinterpret_cast(&p); } +static ZT_INLINE InetAddress &asInetAddress(sockaddr_storage &p) noexcept { return *reinterpret_cast(&p); } +static ZT_INLINE const InetAddress &asInetAddress(const sockaddr_in &p) noexcept { return *reinterpret_cast(&p); } +static ZT_INLINE const InetAddress &asInetAddress(const sockaddr_in6 &p) noexcept { return *reinterpret_cast(&p); } +static ZT_INLINE const InetAddress &asInetAddress(const sockaddr &p) noexcept { return *reinterpret_cast(&p); } +static ZT_INLINE const InetAddress &asInetAddress(const sockaddr_storage &p) noexcept { return *reinterpret_cast(&p); } } // namespace ZeroTier diff --git a/node/LZ4.cpp b/node/LZ4.cpp index 50532609a..ccff0bab4 100644 --- a/node/LZ4.cpp +++ b/node/LZ4.cpp @@ -48,7 +48,7 @@ #pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */ #pragma warning(disable : 4293) /* disable: C4293: too large shift (32-bits) */ #else -#define FORCE_INLINE ZT_ALWAYS_INLINE +#define FORCE_INLINE ZT_INLINE #endif namespace ZeroTier { @@ -563,7 +563,7 @@ FORCE_INLINE int LZ4_compress_generic( return (int) (((char*)op)-dest); } -ZT_ALWAYS_INLINE int LZ4_compress_fast_extState(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int acceleration) +ZT_INLINE int LZ4_compress_fast_extState(void* state,const char* source,char* dest,int inputSize,int maxOutputSize,int acceleration) { LZ4_stream_t_internal* ctx = &((LZ4_stream_t*)state)->internal_donotuse; LZ4_resetStream((LZ4_stream_t*)state); diff --git a/node/Locator.hpp b/node/Locator.hpp index f4db23804..cbc17a018 100644 --- a/node/Locator.hpp +++ b/node/Locator.hpp @@ -37,42 +37,42 @@ namespace ZeroTier { class Locator : public TriviallyCopyable { public: - ZT_ALWAYS_INLINE Locator() noexcept { memoryZero(this); } + ZT_INLINE Locator() noexcept { memoryZero(this); } /** * Zero the Locator data structure */ - ZT_ALWAYS_INLINE void clear() noexcept { memoryZero(this); } + ZT_INLINE void clear() noexcept { memoryZero(this); } /** * @return Timestamp (a.k.a. revision number) set by Location signer */ - ZT_ALWAYS_INLINE int64_t timestamp() const noexcept { return _ts; } + ZT_INLINE int64_t timestamp() const noexcept { return _ts; } /** * @return True if locator is signed */ - ZT_ALWAYS_INLINE bool isSigned() const noexcept { return (_signatureLength > 0); } + ZT_INLINE bool isSigned() const noexcept { return (_signatureLength > 0); } /** * @return Length of signature in bytes or 0 if none */ - ZT_ALWAYS_INLINE unsigned int signatureLength() const noexcept { return _signatureLength; } + ZT_INLINE unsigned int signatureLength() const noexcept { return _signatureLength; } /** * @return Pointer to signature bytes */ - ZT_ALWAYS_INLINE const uint8_t *signature() const noexcept { return _signature; } + ZT_INLINE const uint8_t *signature() const noexcept { return _signature; } /** * @return Number of endpoints in this locator */ - ZT_ALWAYS_INLINE unsigned int endpointCount() const noexcept { return _endpointCount; } + ZT_INLINE unsigned int endpointCount() const noexcept { return _endpointCount; } /** * @return Pointer to array of endpoints */ - ZT_ALWAYS_INLINE const Endpoint *endpoints() const noexcept { return _at; } + ZT_INLINE const Endpoint *endpoints() const noexcept { return _at; } /** * Add an endpoint to this locator @@ -83,7 +83,7 @@ public: * @param ep Endpoint to add * @return True if endpoint was added (or already present), false if locator is full */ - ZT_ALWAYS_INLINE bool add(const Endpoint &ep) noexcept + ZT_INLINE bool add(const Endpoint &ep) noexcept { if (_endpointCount >= ZT_LOCATOR_MAX_ENDPOINTS) return false; @@ -110,7 +110,7 @@ public: */ bool verify(const Identity &id) const noexcept; - explicit ZT_ALWAYS_INLINE operator bool() const noexcept { return (_ts != 0); } + explicit ZT_INLINE operator bool() const noexcept { return (_ts != 0); } static constexpr int marshalSizeMax() noexcept { return ZT_LOCATOR_MARSHAL_SIZE_MAX; } int marshal(uint8_t data[ZT_LOCATOR_MARSHAL_SIZE_MAX],bool excludeSignature = false) const noexcept; diff --git a/node/MAC.hpp b/node/MAC.hpp index 06af8962d..dc01e319d 100644 --- a/node/MAC.hpp +++ b/node/MAC.hpp @@ -31,32 +31,32 @@ namespace ZeroTier { class MAC : public TriviallyCopyable { public: - ZT_ALWAYS_INLINE MAC() noexcept : _m(0ULL) {} - ZT_ALWAYS_INLINE MAC(const uint8_t a,const uint8_t b,const uint8_t c,const uint8_t d,const uint8_t e,const uint8_t f) noexcept : _m( (((uint64_t)a) << 40U) | (((uint64_t)b) << 32U) | (((uint64_t)c) << 24U) | (((uint64_t)d) << 16U) | (((uint64_t)e) << 8U) | ((uint64_t)f) ) {} - explicit ZT_ALWAYS_INLINE MAC(const uint64_t m) noexcept : _m(m) {} - explicit ZT_ALWAYS_INLINE MAC(const uint8_t b[6]) noexcept { setTo(b); } - ZT_ALWAYS_INLINE MAC(const Address &ztaddr,uint64_t nwid) noexcept { fromAddress(ztaddr,nwid); } + ZT_INLINE MAC() noexcept : _m(0ULL) {} + ZT_INLINE MAC(const uint8_t a,const uint8_t b,const uint8_t c,const uint8_t d,const uint8_t e,const uint8_t f) noexcept : _m((((uint64_t)a) << 40U) | (((uint64_t)b) << 32U) | (((uint64_t)c) << 24U) | (((uint64_t)d) << 16U) | (((uint64_t)e) << 8U) | ((uint64_t)f) ) {} + explicit ZT_INLINE MAC(const uint64_t m) noexcept : _m(m) {} + explicit ZT_INLINE MAC(const uint8_t b[6]) noexcept { setTo(b); } + ZT_INLINE MAC(const Address &ztaddr,uint64_t nwid) noexcept { fromAddress(ztaddr,nwid); } /** * @return MAC in 64-bit integer */ - ZT_ALWAYS_INLINE uint64_t toInt() const noexcept { return _m; } + ZT_INLINE uint64_t toInt() const noexcept { return _m; } /** * Set MAC to zero */ - ZT_ALWAYS_INLINE void zero() noexcept { _m = 0ULL; } + ZT_INLINE void zero() noexcept { _m = 0ULL; } /** * @return True if MAC is non-zero */ - ZT_ALWAYS_INLINE operator bool() const noexcept { return (_m != 0ULL); } + ZT_INLINE operator bool() const noexcept { return (_m != 0ULL); } /** * @param bits Raw MAC in big-endian byte order * @param len Length, must be >= 6 or result is zero */ - ZT_ALWAYS_INLINE void setTo(const uint8_t b[6]) noexcept + ZT_INLINE void setTo(const uint8_t b[6]) noexcept { _m = ((uint64_t)b[0] << 40U) | ((uint64_t)b[1] << 32U) | ((uint64_t)b[2] << 24U) | ((uint64_t)b[3] << 16U) | ((uint64_t)b[4] << 8U) | (uint64_t)b[5]; } @@ -65,7 +65,7 @@ public: * @param buf Destination buffer for MAC in big-endian byte order * @param len Length of buffer, must be >= 6 or nothing is copied */ - ZT_ALWAYS_INLINE void copyTo(uint8_t b[6]) const noexcept + ZT_INLINE void copyTo(uint8_t b[6]) const noexcept { b[0] = (uint8_t)(_m >> 40U); b[1] = (uint8_t)(_m >> 32U); @@ -78,12 +78,12 @@ public: /** * @return True if this is broadcast (all 0xff) */ - ZT_ALWAYS_INLINE bool isBroadcast() const noexcept { return _m; } + ZT_INLINE bool isBroadcast() const noexcept { return _m; } /** * @return True if this is a multicast MAC */ - ZT_ALWAYS_INLINE bool isMulticast() const noexcept { return ((_m & 0x010000000000ULL) != 0ULL); } + ZT_INLINE bool isMulticast() const noexcept { return ((_m & 0x010000000000ULL) != 0ULL); } /** * Set this MAC to a MAC derived from an address and a network ID @@ -91,7 +91,7 @@ public: * @param ztaddr ZeroTier address * @param nwid 64-bit network ID */ - ZT_ALWAYS_INLINE void fromAddress(const Address &ztaddr,uint64_t nwid) noexcept + ZT_INLINE void fromAddress(const Address &ztaddr,uint64_t nwid) noexcept { uint64_t m = ((uint64_t)firstOctetForNetwork(nwid)) << 40U; m |= ztaddr.toInt(); // a is 40 bits @@ -110,7 +110,7 @@ public: * * @param nwid Network ID */ - ZT_ALWAYS_INLINE Address toAddress(uint64_t nwid) const noexcept + ZT_INLINE Address toAddress(uint64_t nwid) const noexcept { uint64_t a = _m & 0xffffffffffULL; // least significant 40 bits of MAC are formed from address a ^= ((nwid >> 8U) & 0xffU) << 32U; // ... XORed with bits 8-48 of the nwid in little-endian byte order, so unmask it @@ -125,7 +125,7 @@ public: * @param nwid Network ID * @return First octet of MAC for this network */ - static ZT_ALWAYS_INLINE unsigned char firstOctetForNetwork(uint64_t nwid) noexcept + static ZT_INLINE unsigned char firstOctetForNetwork(uint64_t nwid) noexcept { const uint8_t a = ((uint8_t)(nwid & 0xfeU) | 0x02U); // locally administered, not multicast, from LSB of network ID return ((a == 0x52) ? 0x32 : a); // blacklist 0x52 since it's used by KVM, libvirt, and other popular virtualization engines... seems de-facto standard on Linux @@ -135,16 +135,16 @@ public: * @param i Value from 0 to 5 (inclusive) * @return Byte at said position (address interpreted in big-endian order) */ - ZT_ALWAYS_INLINE uint8_t operator[](unsigned int i) const noexcept { return (uint8_t)(_m >> (40 - (i * 8))); } + ZT_INLINE uint8_t operator[](unsigned int i) const noexcept { return (uint8_t)(_m >> (40 - (i * 8))); } /** * @return 6, which is the number of bytes in a MAC, for container compliance */ - ZT_ALWAYS_INLINE unsigned int size() const noexcept { return 6; } + ZT_INLINE unsigned int size() const noexcept { return 6; } - ZT_ALWAYS_INLINE unsigned long hashCode() const noexcept { return (unsigned long)_m; } + ZT_INLINE unsigned long hashCode() const noexcept { return (unsigned long)_m; } - ZT_ALWAYS_INLINE char *toString(char buf[18]) const noexcept + ZT_INLINE char *toString(char buf[18]) const noexcept { buf[0] = Utils::HEXCHARS[(_m >> 44U) & 0xfU]; buf[1] = Utils::HEXCHARS[(_m >> 40U) & 0xfU]; @@ -167,14 +167,14 @@ public: return buf; } - ZT_ALWAYS_INLINE MAC &operator=(const uint64_t m) noexcept { _m = m; return *this; } + ZT_INLINE MAC &operator=(const uint64_t m) noexcept { _m = m; return *this; } - ZT_ALWAYS_INLINE bool operator==(const MAC &m) const noexcept { return (_m == m._m); } - ZT_ALWAYS_INLINE bool operator!=(const MAC &m) const noexcept { return (_m != m._m); } - ZT_ALWAYS_INLINE bool operator<(const MAC &m) const noexcept { return (_m < m._m); } - ZT_ALWAYS_INLINE bool operator<=(const MAC &m) const noexcept { return (_m <= m._m); } - ZT_ALWAYS_INLINE bool operator>(const MAC &m) const noexcept { return (_m > m._m); } - ZT_ALWAYS_INLINE bool operator>=(const MAC &m) const noexcept { return (_m >= m._m); } + ZT_INLINE bool operator==(const MAC &m) const noexcept { return (_m == m._m); } + ZT_INLINE bool operator!=(const MAC &m) const noexcept { return (_m != m._m); } + ZT_INLINE bool operator<(const MAC &m) const noexcept { return (_m < m._m); } + ZT_INLINE bool operator<=(const MAC &m) const noexcept { return (_m <= m._m); } + ZT_INLINE bool operator>(const MAC &m) const noexcept { return (_m > m._m); } + ZT_INLINE bool operator>=(const MAC &m) const noexcept { return (_m >= m._m); } private: uint64_t _m; diff --git a/node/MIMC52.cpp b/node/MIMC52.cpp index ef291c51a..ab710da5b 100644 --- a/node/MIMC52.cpp +++ b/node/MIMC52.cpp @@ -26,7 +26,7 @@ namespace { const uint64_t s_mimc52Primes[512] = { 4503599627332907ULL,4503599627332943ULL,4503599627333243ULL,4503599627333321ULL,4503599627333393ULL,4503599627333423ULL,4503599627333549ULL,4503599627333603ULL,4503599627333771ULL,4503599627333813ULL,4503599627333921ULL,4503599627333951ULL,4503599627334077ULL,4503599627334131ULL,4503599627334161ULL,4503599627334167ULL,4503599627334173ULL,4503599627334221ULL,4503599627334251ULL,4503599627334257ULL,4503599627334263ULL,4503599627334419ULL,4503599627334473ULL,4503599627334539ULL,4503599627334623ULL,4503599627334641ULL,4503599627334653ULL,4503599627334767ULL,4503599627334839ULL,4503599627334917ULL,4503599627335097ULL,4503599627335169ULL,4503599627335223ULL,4503599627335253ULL,4503599627335439ULL,4503599627335499ULL,4503599627335643ULL,4503599627335871ULL,4503599627335877ULL,4503599627335931ULL,4503599627335943ULL,4503599627335967ULL,4503599627335973ULL,4503599627335979ULL,4503599627336081ULL,4503599627336099ULL,4503599627336129ULL,4503599627336267ULL,4503599627336477ULL,4503599627336507ULL,4503599627336543ULL,4503599627336651ULL,4503599627336723ULL,4503599627336963ULL,4503599627336993ULL,4503599627337029ULL,4503599627337047ULL,4503599627337071ULL,4503599627337197ULL,4503599627337233ULL,4503599627337311ULL,4503599627337407ULL,4503599627337443ULL,4503599627337467ULL,4503599627337479ULL,4503599627337491ULL,4503599627337527ULL,4503599627337563ULL,4503599627337623ULL,4503599627337689ULL,4503599627337761ULL,4503599627338067ULL,4503599627338121ULL,4503599627338169ULL,4503599627338337ULL,4503599627338439ULL,4503599627338499ULL,4503599627338631ULL,4503599627338739ULL,4503599627338829ULL,4503599627338901ULL,4503599627338991ULL,4503599627338997ULL,4503599627339003ULL,4503599627339159ULL,4503599627339201ULL,4503599627339207ULL,4503599627339237ULL,4503599627339279ULL,4503599627339327ULL,4503599627339363ULL,4503599627339447ULL,4503599627339507ULL,4503599627339531ULL,4503599627339609ULL,4503599627339651ULL,4503599627339801ULL,4503599627339807ULL,4503599627339819ULL,4503599627339867ULL,4503599627339909ULL,4503599627339933ULL,4503599627339951ULL,4503599627339963ULL,4503599627340029ULL,4503599627340137ULL,4503599627340197ULL,4503599627340227ULL,4503599627340251ULL,4503599627340293ULL,4503599627340377ULL,4503599627340413ULL,4503599627340491ULL,4503599627340581ULL,4503599627340617ULL,4503599627340629ULL,4503599627340881ULL,4503599627340893ULL,4503599627340953ULL,4503599627340971ULL,4503599627341013ULL,4503599627341037ULL,4503599627341091ULL,4503599627341169ULL,4503599627341271ULL,4503599627341301ULL,4503599627341523ULL,4503599627341571ULL,4503599627341601ULL,4503599627341667ULL,4503599627341673ULL,4503599627341721ULL,4503599627341799ULL,4503599627341931ULL,4503599627341979ULL,4503599627342033ULL,4503599627342099ULL,4503599627342177ULL,4503599627342183ULL,4503599627342267ULL,4503599627342327ULL,4503599627342423ULL,4503599627342477ULL,4503599627342531ULL,4503599627342537ULL,4503599627342591ULL,4503599627342657ULL,4503599627342759ULL,4503599627342873ULL,4503599627342891ULL,4503599627343101ULL,4503599627343191ULL,4503599627343287ULL,4503599627343293ULL,4503599627343389ULL,4503599627343413ULL,4503599627343617ULL,4503599627343857ULL,4503599627343899ULL,4503599627343953ULL,4503599627344001ULL,4503599627344073ULL,4503599627344151ULL,4503599627344247ULL,4503599627344343ULL,4503599627344361ULL,4503599627344427ULL,4503599627344481ULL,4503599627344577ULL,4503599627344709ULL,4503599627344751ULL,4503599627344901ULL,4503599627344931ULL,4503599627344967ULL,4503599627345111ULL,4503599627345123ULL,4503599627345243ULL,4503599627345339ULL,4503599627345513ULL,4503599627345543ULL,4503599627345573ULL,4503599627345627ULL,4503599627345729ULL,4503599627345801ULL,4503599627345849ULL,4503599627345873ULL,4503599627345879ULL,4503599627345933ULL,4503599627345969ULL,4503599627346011ULL,4503599627346161ULL,4503599627346329ULL,4503599627346341ULL,4503599627346419ULL,4503599627346569ULL,4503599627346623ULL,4503599627346671ULL,4503599627346851ULL,4503599627346887ULL,4503599627346917ULL,4503599627346929ULL,4503599627346947ULL,4503599627346959ULL,4503599627347013ULL,4503599627347019ULL,4503599627347091ULL,4503599627347277ULL,4503599627347391ULL,4503599627347433ULL,4503599627347439ULL,4503599627347553ULL,4503599627347589ULL,4503599627347781ULL,4503599627347823ULL,4503599627347829ULL,4503599627347859ULL,4503599627348021ULL,4503599627348231ULL,4503599627348357ULL,4503599627348411ULL,4503599627348429ULL,4503599627348501ULL,4503599627348537ULL,4503599627348543ULL,4503599627348711ULL,4503599627348747ULL,4503599627348867ULL,4503599627348909ULL,4503599627348957ULL,4503599627349041ULL,4503599627349191ULL,4503599627349233ULL,4503599627349299ULL,4503599627349353ULL,4503599627349677ULL,4503599627349887ULL,4503599627349947ULL,4503599627350157ULL,4503599627350193ULL,4503599627350223ULL,4503599627350331ULL,4503599627350367ULL,4503599627350487ULL,4503599627350511ULL,4503599627350613ULL,4503599627350781ULL,4503599627350799ULL,4503599627350871ULL,4503599627351051ULL,4503599627351159ULL,4503599627351267ULL,4503599627351273ULL,4503599627351393ULL,4503599627351459ULL,4503599627351621ULL,4503599627351651ULL,4503599627351813ULL,4503599627351873ULL,4503599627352083ULL,4503599627352227ULL,4503599627352257ULL,4503599627352269ULL,4503599627352719ULL,4503599627352731ULL,4503599627352803ULL,4503599627352809ULL,4503599627352827ULL,4503599627352893ULL,4503599627352929ULL,4503599627352941ULL,4503599627353007ULL,4503599627353121ULL,4503599627353139ULL,4503599627353181ULL,4503599627353193ULL,4503599627353283ULL,4503599627353373ULL,4503599627353397ULL,4503599627353451ULL,4503599627353487ULL,4503599627353517ULL,4503599627353523ULL,4503599627353529ULL,4503599627353781ULL,4503599627353793ULL,4503599627353817ULL,4503599627353829ULL,4503599627353913ULL,4503599627354129ULL,4503599627354351ULL,4503599627354363ULL,4503599627354369ULL,4503599627354579ULL,4503599627354783ULL,4503599627354813ULL,4503599627355053ULL,4503599627355107ULL,4503599627355113ULL,4503599627355137ULL,4503599627355161ULL,4503599627355263ULL,4503599627355383ULL,4503599627355593ULL,4503599627355743ULL,4503599627355749ULL,4503599627355797ULL,4503599627355827ULL,4503599627355887ULL,4503599627355923ULL,4503599627355929ULL,4503599627355989ULL,4503599627356019ULL,4503599627356073ULL,4503599627356091ULL,4503599627356103ULL,4503599627356169ULL,4503599627356199ULL,4503599627356223ULL,4503599627356307ULL,4503599627356373ULL,4503599627356481ULL,4503599627356541ULL,4503599627356631ULL,4503599627356799ULL,4503599627356889ULL,4503599627356919ULL,4503599627357027ULL,4503599627357087ULL,4503599627357177ULL,4503599627357273ULL,4503599627357279ULL,4503599627357357ULL,4503599627357417ULL,4503599627357483ULL,4503599627357807ULL,4503599627357867ULL,4503599627358059ULL,4503599627358101ULL,4503599627358173ULL,4503599627358281ULL,4503599627358437ULL,4503599627358473ULL,4503599627358527ULL,4503599627358641ULL,4503599627358707ULL,4503599627358791ULL,4503599627358989ULL,4503599627359031ULL,4503599627359037ULL,4503599627359127ULL,4503599627359163ULL,4503599627359169ULL,4503599627359187ULL,4503599627359241ULL,4503599627359247ULL,4503599627359397ULL,4503599627359523ULL,4503599627359559ULL,4503599627359751ULL,4503599627359793ULL,4503599627359823ULL,4503599627359829ULL,4503599627359841ULL,4503599627359919ULL,4503599627359961ULL,4503599627359967ULL,4503599627359997ULL,4503599627360021ULL,4503599627360033ULL,4503599627360237ULL,4503599627360279ULL,4503599627360303ULL,4503599627360381ULL,4503599627360549ULL,4503599627360579ULL,4503599627360633ULL,4503599627360663ULL,4503599627360711ULL,4503599627360777ULL,4503599627360927ULL,4503599627361059ULL,4503599627361077ULL,4503599627361239ULL,4503599627361353ULL,4503599627361509ULL,4503599627361617ULL,4503599627361641ULL,4503599627361893ULL,4503599627361917ULL,4503599627361953ULL,4503599627362103ULL,4503599627362109ULL,4503599627362217ULL,4503599627362271ULL,4503599627362307ULL,4503599627362361ULL,4503599627362457ULL,4503599627362499ULL,4503599627362529ULL,4503599627362631ULL,4503599627362793ULL,4503599627362799ULL,4503599627362859ULL,4503599627363093ULL,4503599627363117ULL,4503599627363183ULL,4503599627363201ULL,4503599627363231ULL,4503599627363261ULL,4503599627363279ULL,4503599627363297ULL,4503599627363471ULL,4503599627363483ULL,4503599627363549ULL,4503599627363567ULL,4503599627363621ULL,4503599627363729ULL,4503599627363741ULL,4503599627363783ULL,4503599627363813ULL,4503599627363873ULL,4503599627363891ULL,4503599627363897ULL,4503599627363987ULL,4503599627364119ULL,4503599627364203ULL,4503599627364239ULL,4503599627364353ULL,4503599627364359ULL,4503599627364371ULL,4503599627364521ULL,4503599627364611ULL,4503599627364671ULL,4503599627364707ULL,4503599627364737ULL,4503599627364869ULL,4503599627364917ULL,4503599627364941ULL,4503599627365073ULL,4503599627365259ULL,4503599627365337ULL,4503599627365367ULL,4503599627365463ULL,4503599627365481ULL,4503599627365511ULL,4503599627365541ULL,4503599627365613ULL,4503599627365721ULL,4503599627365763ULL,4503599627365961ULL,4503599627366093ULL,4503599627366303ULL,4503599627366363ULL,4503599627366423ULL,4503599627366513ULL,4503599627366549ULL,4503599627366627ULL,4503599627366747ULL,4503599627366759ULL,4503599627366921ULL,4503599627366999ULL,4503599627367017ULL,4503599627367101ULL,4503599627367119ULL,4503599627367221ULL,4503599627367479ULL,4503599627367497ULL,4503599627367563ULL,4503599627367587ULL,4503599627367611ULL,4503599627367767ULL,4503599627367803ULL,4503599627367887ULL,4503599627367977ULL,4503599627368241ULL,4503599627368271ULL,4503599627368319ULL,4503599627368421ULL,4503599627368451ULL,4503599627368487ULL,4503599627368613ULL,4503599627368769ULL,4503599627368847ULL,4503599627368871ULL,4503599627368889ULL,4503599627368979ULL,4503599627369039ULL,4503599627369093ULL,4503599627369291ULL,4503599627369309ULL,4503599627369327ULL,4503599627369357ULL,4503599627369387ULL,4503599627369399ULL,4503599627369411ULL,4503599627369603ULL,4503599627369657ULL,4503599627369699ULL,4503599627369741ULL,4503599627369837ULL,4503599627369861ULL,4503599627369939ULL,4503599627370023ULL,4503599627370083ULL,4503599627370101ULL,4503599627370161ULL,4503599627370227ULL,4503599627370287ULL,4503599627370299ULL,4503599627370323ULL,4503599627370353ULL,4503599627370449ULL }; #ifdef ZT_MIMC52_NO_FPU -#if defined(ZT_ARCH_X64) && defined(__GCC__) +#if defined(ZT_ARCH_X64) && defined(__GNUC__) // r = (a * b) % m #define x64_mulmod(r,a,b,m) __asm__( \ "mulq %2;" \ @@ -49,7 +49,7 @@ const uint64_t s_mimc52Primes[512] = { 4503599627332907ULL,4503599627332943ULL,4 #endif #ifdef ZT_MIMC52_NO_FPU -ZT_ALWAYS_INLINE uint64_t mulmod52(uint64_t a,uint64_t b,uint64_t m) noexcept +ZT_INLINE uint64_t mulmod52(uint64_t a,uint64_t b,uint64_t m) noexcept { #ifdef x64_mulmod uint64_t r; @@ -76,7 +76,7 @@ ZT_ALWAYS_INLINE uint64_t mulmod52(uint64_t a,uint64_t b,uint64_t m) noexcept #endif // Compute ((a ^ e) % m) with 52 bits of integer precision. -ZT_ALWAYS_INLINE uint64_t modpow52(uint64_t a,uint64_t e,const uint64_t p) noexcept +ZT_INLINE uint64_t modpow52(uint64_t a,uint64_t e,const uint64_t p) noexcept { #ifndef ZT_MIMC52_NO_FPU uint64_t one = 1; @@ -101,7 +101,7 @@ ZT_ALWAYS_INLINE uint64_t modpow52(uint64_t a,uint64_t e,const uint64_t p) noexc #define SPECK_ROL(x,r) ((x << r) | (x >> (64U - r))) #define SPECK_R(x,y,k) (x = SPECK_ROR(x,8U), x += y, x ^= k, y = SPECK_ROL(y,3U), y ^= x) -ZT_ALWAYS_INLINE void mimc52Init(uint64_t k[128],const void *const salt,const unsigned int saltSize,uint64_t &p,uint64_t &x) noexcept +ZT_INLINE void mimc52Init(uint64_t k[128],const void *const salt,const unsigned int saltSize,uint64_t &p,uint64_t &x) noexcept { uint64_t hash[6]; SHA384(hash,salt,saltSize); diff --git a/node/Membership.cpp b/node/Membership.cpp index fd636d11d..1490c87cf 100644 --- a/node/Membership.cpp +++ b/node/Membership.cpp @@ -159,7 +159,7 @@ Membership::AddCredentialResult Membership::addCredential(const RuntimeEnvironme // 3/5 of the credential types have identical addCredential() code template -static ZT_ALWAYS_INLINE Membership::AddCredentialResult _addCredImpl( +static ZT_INLINE Membership::AddCredentialResult _addCredImpl( Hashtable &remoteCreds, const Hashtable &revocations, const RuntimeEnvironment *const RR, diff --git a/node/Membership.hpp b/node/Membership.hpp index 18dee3540..193dc09fb 100644 --- a/node/Membership.hpp +++ b/node/Membership.hpp @@ -65,7 +65,7 @@ public: /** * @return Time we last pushed credentials to this member */ - ZT_ALWAYS_INLINE int64_t lastPushedCredentials() const noexcept { return _lastPushedCredentials; } + ZT_INLINE int64_t lastPushedCredentials() const noexcept { return _lastPushedCredentials; } /** * Check whether the peer represented by this Membership should be allowed on this network at all @@ -73,7 +73,7 @@ public: * @param nconf Our network config * @return True if this peer is allowed on this network at all */ - ZT_ALWAYS_INLINE bool isAllowedOnNetwork(const NetworkConfig &nconf) const noexcept + ZT_INLINE bool isAllowedOnNetwork(const NetworkConfig &nconf) const noexcept { if (nconf.isPublic()) return true; // public network if (_com.timestamp() <= _comRevocationThreshold) return false; // COM has been revoked @@ -89,7 +89,7 @@ public: * @return True if this peer has a certificate of ownership for the given resource */ template - ZT_ALWAYS_INLINE bool peerOwnsAddress(const NetworkConfig &nconf,const T &r) const noexcept + ZT_INLINE bool peerOwnsAddress(const NetworkConfig &nconf,const T &r) const noexcept { if (_isUnspoofableAddress(nconf,r)) return true; @@ -110,7 +110,7 @@ public: * @param id Tag ID * @return Pointer to tag or NULL if not found */ - ZT_ALWAYS_INLINE const Tag *getTag(const NetworkConfig &nconf,const uint32_t id) const noexcept + ZT_INLINE const Tag *getTag(const NetworkConfig &nconf,const uint32_t id) const noexcept { const Tag *const t = _remoteTags.get(id); return (((t)&&(_isCredentialTimestampValid(nconf,*t))) ? t : (Tag *)0); @@ -127,7 +127,7 @@ public: /** * Generates a key for internal use in indexing credentials by type and credential ID */ - static ZT_ALWAYS_INLINE uint64_t credentialKey(const ZT_CredentialType &t,const uint32_t i) noexcept { return (((uint64_t)t << 32U) | (uint64_t)i); } + static ZT_INLINE uint64_t credentialKey(const ZT_CredentialType &t,const uint32_t i) noexcept { return (((uint64_t)t << 32U) | (uint64_t)i); } AddCredentialResult addCredential(const RuntimeEnvironment *RR,void *tPtr,const Identity &sourcePeerIdentity,const NetworkConfig &nconf,const CertificateOfMembership &com); AddCredentialResult addCredential(const RuntimeEnvironment *RR,void *tPtr,const Identity &sourcePeerIdentity,const NetworkConfig &nconf,const Tag &tag); @@ -139,13 +139,13 @@ private: // This returns true if a resource is an IPv6 NDP-emulated address. These embed the ZT // address of the peer and therefore cannot be spoofed, causing peerOwnsAddress() to // always return true for them. A certificate is not required for these. - ZT_ALWAYS_INLINE bool _isUnspoofableAddress(const NetworkConfig &nconf,const MAC &m) const noexcept { return false; } + ZT_INLINE bool _isUnspoofableAddress(const NetworkConfig &nconf,const MAC &m) const noexcept { return false; } bool _isUnspoofableAddress(const NetworkConfig &nconf,const InetAddress &ip) const noexcept; // This compares the remote credential's timestamp to the timestamp in our network config // plus or minus the permitted maximum timestamp delta. template - ZT_ALWAYS_INLINE bool _isCredentialTimestampValid(const NetworkConfig &nconf,const C &remoteCredential) const noexcept + ZT_INLINE bool _isCredentialTimestampValid(const NetworkConfig &nconf,const C &remoteCredential) const noexcept { const int64_t ts = remoteCredential.timestamp(); if (((ts >= nconf.timestamp) ? (ts - nconf.timestamp) : (nconf.timestamp - ts)) <= nconf.credentialTimeMaxDelta) { @@ -156,7 +156,7 @@ private: } template - ZT_ALWAYS_INLINE void _cleanCredImpl(const NetworkConfig &nconf,Hashtable &remoteCreds) + ZT_INLINE void _cleanCredImpl(const NetworkConfig &nconf,Hashtable &remoteCreds) { uint32_t *k = nullptr; C *v = nullptr; @@ -188,7 +188,7 @@ public: class CapabilityIterator { public: - ZT_ALWAYS_INLINE CapabilityIterator(Membership &m,const NetworkConfig &nconf) noexcept : + ZT_INLINE CapabilityIterator(Membership &m,const NetworkConfig &nconf) noexcept : _hti(m._remoteCaps), _k(nullptr), _c(nullptr), @@ -197,7 +197,7 @@ public: { } - ZT_ALWAYS_INLINE Capability *next() noexcept + ZT_INLINE Capability *next() noexcept { while (_hti.next(_k,_c)) { if (_m._isCredentialTimestampValid(_nconf,*_c)) diff --git a/node/Meter.hpp b/node/Meter.hpp index 49db8328b..7ee979856 100644 --- a/node/Meter.hpp +++ b/node/Meter.hpp @@ -43,7 +43,7 @@ public: * * @param now Start time */ - ZT_ALWAYS_INLINE Meter() noexcept {} + ZT_INLINE Meter() noexcept {} /** * Add a measurement @@ -51,7 +51,7 @@ public: * @param now Current time * @param count Count of items (usually bytes) */ - ZT_ALWAYS_INLINE void log(const int64_t now,uint64_t count) noexcept + ZT_INLINE void log(const int64_t now,uint64_t count) noexcept { // We log by choosing a log bucket based on the current time in units modulo // the log size and then if it's a new bucket setting it or otherwise adding @@ -71,7 +71,7 @@ public: * @param rate Result parameter: rate in count/TUNIT * @param total Total count for life of object */ - ZT_ALWAYS_INLINE void rate(double &rate,uint64_t &total) const noexcept + ZT_INLINE void rate(double &rate,uint64_t &total) const noexcept { total = 0; for(unsigned long i=0;i(const MulticastGroup &g) const noexcept { return (g < *this); } - ZT_ALWAYS_INLINE bool operator<=(const MulticastGroup &g) const noexcept { return !(g < *this); } - ZT_ALWAYS_INLINE bool operator>=(const MulticastGroup &g) const noexcept { return !(*this < g); } + ZT_INLINE bool operator>(const MulticastGroup &g) const noexcept { return (g < *this); } + ZT_INLINE bool operator<=(const MulticastGroup &g) const noexcept { return !(g < *this); } + ZT_INLINE bool operator>=(const MulticastGroup &g) const noexcept { return !(*this < g); } - ZT_ALWAYS_INLINE unsigned long hashCode() const noexcept { return (_mac.hashCode() ^ (unsigned long)_adi); } + ZT_INLINE unsigned long hashCode() const noexcept { return (_mac.hashCode() ^ (unsigned long)_adi); } private: MAC _mac; diff --git a/node/Mutex.hpp b/node/Mutex.hpp index 78ccce5bc..20d75672a 100644 --- a/node/Mutex.hpp +++ b/node/Mutex.hpp @@ -28,25 +28,25 @@ namespace ZeroTier { class Mutex { public: - ZT_ALWAYS_INLINE Mutex() noexcept { pthread_mutex_init(&_mh,0); } - ZT_ALWAYS_INLINE ~Mutex() noexcept { pthread_mutex_destroy(&_mh); } + ZT_INLINE Mutex() noexcept { pthread_mutex_init(&_mh,0); } + ZT_INLINE ~Mutex() noexcept { pthread_mutex_destroy(&_mh); } - ZT_ALWAYS_INLINE void lock() const noexcept { pthread_mutex_lock(&((const_cast (this))->_mh)); } - ZT_ALWAYS_INLINE void unlock() const noexcept { pthread_mutex_unlock(&((const_cast (this))->_mh)); } + ZT_INLINE void lock() const noexcept { pthread_mutex_lock(&((const_cast (this))->_mh)); } + ZT_INLINE void unlock() const noexcept { pthread_mutex_unlock(&((const_cast (this))->_mh)); } class Lock { public: - ZT_ALWAYS_INLINE Lock(Mutex &m) noexcept : _m(&m) { m.lock(); } - ZT_ALWAYS_INLINE Lock(const Mutex &m) noexcept : _m(const_cast(&m)) { _m->lock(); } - ZT_ALWAYS_INLINE ~Lock() { _m->unlock(); } + ZT_INLINE Lock(Mutex &m) noexcept : _m(&m) { m.lock(); } + ZT_INLINE Lock(const Mutex &m) noexcept : _m(const_cast(&m)) { _m->lock(); } + ZT_INLINE ~Lock() { _m->unlock(); } private: Mutex *const _m; }; private: - ZT_ALWAYS_INLINE Mutex(const Mutex &) noexcept {} - ZT_ALWAYS_INLINE const Mutex &operator=(const Mutex &) noexcept { return *this; } + ZT_INLINE Mutex(const Mutex &) noexcept {} + ZT_INLINE const Mutex &operator=(const Mutex &) noexcept { return *this; } pthread_mutex_t _mh; }; @@ -54,13 +54,13 @@ private: class RWMutex { public: - ZT_ALWAYS_INLINE RWMutex() noexcept { pthread_rwlock_init(&_mh,0); } - ZT_ALWAYS_INLINE ~RWMutex() noexcept { pthread_rwlock_destroy(&_mh); } + ZT_INLINE RWMutex() noexcept { pthread_rwlock_init(&_mh,0); } + ZT_INLINE ~RWMutex() noexcept { pthread_rwlock_destroy(&_mh); } - ZT_ALWAYS_INLINE void lock() const noexcept { pthread_rwlock_wrlock(&((const_cast (this))->_mh)); } - ZT_ALWAYS_INLINE void rlock() const noexcept { pthread_rwlock_rdlock(&((const_cast (this))->_mh)); } - ZT_ALWAYS_INLINE void unlock() const noexcept { pthread_rwlock_unlock(&((const_cast (this))->_mh)); } - ZT_ALWAYS_INLINE void runlock() const noexcept { pthread_rwlock_unlock(&((const_cast (this))->_mh)); } + ZT_INLINE void lock() const noexcept { pthread_rwlock_wrlock(&((const_cast (this))->_mh)); } + ZT_INLINE void rlock() const noexcept { pthread_rwlock_rdlock(&((const_cast (this))->_mh)); } + ZT_INLINE void unlock() const noexcept { pthread_rwlock_unlock(&((const_cast (this))->_mh)); } + ZT_INLINE void runlock() const noexcept { pthread_rwlock_unlock(&((const_cast (this))->_mh)); } /** * RAAI locker that acquires only the read lock (shared read) @@ -68,9 +68,9 @@ public: class RLock { public: - ZT_ALWAYS_INLINE RLock(RWMutex &m) noexcept : _m(&m) { m.rlock(); } - ZT_ALWAYS_INLINE RLock(const RWMutex &m) noexcept : _m(const_cast(&m)) { _m->rlock(); } - ZT_ALWAYS_INLINE ~RLock() { _m->runlock(); } + ZT_INLINE RLock(RWMutex &m) noexcept : _m(&m) { m.rlock(); } + ZT_INLINE RLock(const RWMutex &m) noexcept : _m(const_cast(&m)) { _m->rlock(); } + ZT_INLINE ~RLock() { _m->runlock(); } private: RWMutex *const _m; }; @@ -81,9 +81,9 @@ public: class Lock { public: - ZT_ALWAYS_INLINE Lock(RWMutex &m) noexcept : _m(&m) { m.lock(); } - ZT_ALWAYS_INLINE Lock(const RWMutex &m) noexcept : _m(const_cast(&m)) { _m->lock(); } - ZT_ALWAYS_INLINE ~Lock() { _m->unlock(); } + ZT_INLINE Lock(RWMutex &m) noexcept : _m(&m) { m.lock(); } + ZT_INLINE Lock(const RWMutex &m) noexcept : _m(const_cast(&m)) { _m->lock(); } + ZT_INLINE ~Lock() { _m->unlock(); } private: RWMutex *const _m; }; @@ -97,19 +97,19 @@ public: class RMaybeWLock { public: - ZT_ALWAYS_INLINE RMaybeWLock(RWMutex &m) noexcept : _m(&m),_w(false) { m.rlock(); } - ZT_ALWAYS_INLINE RMaybeWLock(const RWMutex &m) noexcept : _m(const_cast(&m)),_w(false) { _m->rlock(); } - ZT_ALWAYS_INLINE void writing() noexcept { if (!_w) { _w = true; _m->runlock(); _m->lock(); } } - ZT_ALWAYS_INLINE void reading() noexcept { if (_w) { _w = false; _m->unlock(); _m->rlock(); } } - ZT_ALWAYS_INLINE ~RMaybeWLock() { if (_w) _m->unlock(); else _m->runlock(); } + ZT_INLINE RMaybeWLock(RWMutex &m) noexcept : _m(&m),_w(false) { m.rlock(); } + ZT_INLINE RMaybeWLock(const RWMutex &m) noexcept : _m(const_cast(&m)),_w(false) { _m->rlock(); } + ZT_INLINE void writing() noexcept { if (!_w) { _w = true; _m->runlock(); _m->lock(); } } + ZT_INLINE void reading() noexcept { if (_w) { _w = false; _m->unlock(); _m->rlock(); } } + ZT_INLINE ~RMaybeWLock() { if (_w) _m->unlock(); else _m->runlock(); } private: RWMutex *const _m; bool _w; }; private: - ZT_ALWAYS_INLINE RWMutex(const RWMutex &) noexcept {} - ZT_ALWAYS_INLINE const RWMutex &operator=(const RWMutex &) noexcept { return *this; } + ZT_INLINE RWMutex(const RWMutex &) noexcept {} + ZT_INLINE const RWMutex &operator=(const RWMutex &) noexcept { return *this; } pthread_rwlock_t _mh; }; @@ -124,26 +124,26 @@ namespace ZeroTier { class Mutex { public: - ZT_ALWAYS_INLINE Mutex() { InitializeCriticalSection(&_cs); } - ZT_ALWAYS_INLINE ~Mutex() { DeleteCriticalSection(&_cs); } - ZT_ALWAYS_INLINE void lock() { EnterCriticalSection(&_cs); } - ZT_ALWAYS_INLINE void unlock() { LeaveCriticalSection(&_cs); } - ZT_ALWAYS_INLINE void lock() const { (const_cast (this))->lock(); } - ZT_ALWAYS_INLINE void unlock() const { (const_cast (this))->unlock(); } + ZT_INLINE Mutex() { InitializeCriticalSection(&_cs); } + ZT_INLINE ~Mutex() { DeleteCriticalSection(&_cs); } + ZT_INLINE void lock() { EnterCriticalSection(&_cs); } + ZT_INLINE void unlock() { LeaveCriticalSection(&_cs); } + ZT_INLINE void lock() const { (const_cast (this))->lock(); } + ZT_INLINE void unlock() const { (const_cast (this))->unlock(); } class Lock { public: - ZT_ALWAYS_INLINE Lock(Mutex &m) : _m(&m) { m.lock(); } - ZT_ALWAYS_INLINE Lock(const Mutex &m) : _m(const_cast(&m)) { _m->lock(); } - ZT_ALWAYS_INLINE ~Lock() { _m->unlock(); } + ZT_INLINE Lock(Mutex &m) : _m(&m) { m.lock(); } + ZT_INLINE Lock(const Mutex &m) : _m(const_cast(&m)) { _m->lock(); } + ZT_INLINE ~Lock() { _m->unlock(); } private: Mutex *const _m; }; private: - ZT_ALWAYS_INLINE Mutex(const Mutex &) {} - ZT_ALWAYS_INLINE const Mutex &operator=(const Mutex &) { return *this; } + ZT_INLINE Mutex(const Mutex &) {} + ZT_INLINE const Mutex &operator=(const Mutex &) { return *this; } CRITICAL_SECTION _cs; }; diff --git a/node/Network.cpp b/node/Network.cpp index d15e12570..1820d9661 100644 --- a/node/Network.cpp +++ b/node/Network.cpp @@ -1368,9 +1368,9 @@ void Network::_requestConfiguration(void *tPtr) Dictionary rmd; rmd.add(ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_NODE_VENDOR,(uint64_t)1); // 1 == ZeroTier, no other vendors at the moment rmd.add(ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_PROTOCOL_VERSION,(uint64_t)ZT_PROTO_VERSION); - rmd.add(ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_NODE_MAJOR_VERSION,(uint64_t)ZEROTIER_ONE_VERSION_MAJOR); - rmd.add(ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_NODE_MINOR_VERSION,(uint64_t)ZEROTIER_ONE_VERSION_MINOR); - rmd.add(ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_NODE_REVISION,(uint64_t)ZEROTIER_ONE_VERSION_REVISION); + rmd.add(ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_NODE_MAJOR_VERSION,(uint64_t)ZEROTIER_VERSION_MAJOR); + rmd.add(ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_NODE_MINOR_VERSION,(uint64_t)ZEROTIER_VERSION_MINOR); + rmd.add(ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_NODE_REVISION,(uint64_t)ZEROTIER_VERSION_REVISION); rmd.add(ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_MAX_NETWORK_RULES,(uint64_t)ZT_MAX_NETWORK_RULES); rmd.add(ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_MAX_NETWORK_CAPABILITIES,(uint64_t)ZT_MAX_NETWORK_CAPABILITIES); rmd.add(ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_MAX_CAPABILITY_RULES,(uint64_t)ZT_MAX_CAPABILITY_RULES); diff --git a/node/Network.hpp b/node/Network.hpp index b7d660cbe..13109b912 100644 --- a/node/Network.hpp +++ b/node/Network.hpp @@ -56,7 +56,7 @@ public: /** * Compute primary controller device ID from network ID */ - static ZT_ALWAYS_INLINE Address controllerFor(uint64_t nwid) noexcept { return Address(nwid >> 24U); } + static ZT_INLINE Address controllerFor(uint64_t nwid) noexcept { return Address(nwid >> 24U); } /** * Construct a new network @@ -74,14 +74,14 @@ public: ~Network(); - ZT_ALWAYS_INLINE uint64_t id() const noexcept { return _id; } - ZT_ALWAYS_INLINE Address controller() const noexcept { return Address(_id >> 24U); } - ZT_ALWAYS_INLINE bool multicastEnabled() const noexcept { return (_config.multicastLimit > 0); } - ZT_ALWAYS_INLINE bool hasConfig() const noexcept { return (_config); } - ZT_ALWAYS_INLINE uint64_t lastConfigUpdate() const noexcept { return _lastConfigUpdate; } - ZT_ALWAYS_INLINE ZT_VirtualNetworkStatus status() const noexcept { return _status(); } - ZT_ALWAYS_INLINE const NetworkConfig &config() const noexcept { return _config; } - ZT_ALWAYS_INLINE const MAC &mac() const noexcept { return _mac; } + ZT_INLINE uint64_t id() const noexcept { return _id; } + ZT_INLINE Address controller() const noexcept { return Address(_id >> 24U); } + ZT_INLINE bool multicastEnabled() const noexcept { return (_config.multicastLimit > 0); } + ZT_INLINE bool hasConfig() const noexcept { return (_config); } + ZT_INLINE uint64_t lastConfigUpdate() const noexcept { return _lastConfigUpdate; } + ZT_INLINE ZT_VirtualNetworkStatus status() const noexcept { return _status(); } + ZT_INLINE const NetworkConfig &config() const noexcept { return _config; } + ZT_INLINE const MAC &mac() const noexcept { return _mac; } /** * Apply filters to an outgoing packet @@ -153,7 +153,7 @@ public: * @param includeBridgedGroups If true, also check groups we've learned via bridging * @return True if this network endpoint / peer is a member */ - ZT_ALWAYS_INLINE bool subscribedToMulticastGroup(const MulticastGroup &mg,const bool includeBridgedGroups) const + ZT_INLINE bool subscribedToMulticastGroup(const MulticastGroup &mg,const bool includeBridgedGroups) const { Mutex::Lock l(_myMulticastGroups_l); if (std::binary_search(_myMulticastGroups.begin(),_myMulticastGroups.end(),mg)) @@ -213,12 +213,12 @@ public: /** * Set netconf failure to 'access denied' -- called in IncomingPacket when controller reports this */ - ZT_ALWAYS_INLINE void setAccessDenied() noexcept { _netconfFailure = NETCONF_FAILURE_ACCESS_DENIED; } + ZT_INLINE void setAccessDenied() noexcept { _netconfFailure = NETCONF_FAILURE_ACCESS_DENIED; } /** * Set netconf failure to 'not found' -- called by IncomingPacket when controller reports this */ - ZT_ALWAYS_INLINE void setNotFound() noexcept { _netconfFailure = NETCONF_FAILURE_NOT_FOUND; } + ZT_INLINE void setNotFound() noexcept { _netconfFailure = NETCONF_FAILURE_NOT_FOUND; } /** * Determine whether this peer is permitted to communicate on this network @@ -239,7 +239,7 @@ public: * @param mac MAC address * @return ZeroTier address of bridge to this MAC */ - ZT_ALWAYS_INLINE Address findBridgeTo(const MAC &mac) const + ZT_INLINE Address findBridgeTo(const MAC &mac) const { Mutex::Lock _l(_remoteBridgeRoutes_l); const Address *const br = _remoteBridgeRoutes.get(mac); @@ -261,7 +261,7 @@ public: * @param mg Multicast group * @param now Current time */ - ZT_ALWAYS_INLINE void learnBridgedMulticastGroup(void *tPtr,const MulticastGroup &mg,int64_t now) + ZT_INLINE void learnBridgedMulticastGroup(void *tPtr,const MulticastGroup &mg,int64_t now) { Mutex::Lock l(_myMulticastGroups_l); _multicastGroupsBehindMe.set(mg,now); @@ -308,7 +308,7 @@ public: * @param to Destination peer address * @param now Current time */ - ZT_ALWAYS_INLINE void pushCredentialsIfNeeded(void *tPtr,const Address &to,const int64_t now) + ZT_INLINE void pushCredentialsIfNeeded(void *tPtr,const Address &to,const int64_t now) { const int64_t tout = std::min(_config.credentialTimeMaxDelta,(int64_t)ZT_PEER_ACTIVITY_TIMEOUT); Mutex::Lock _l(_memberships_l); @@ -338,7 +338,7 @@ public: * @param f Function of (const Address,const Membership) */ template - ZT_ALWAYS_INLINE void eachMember(F f) + ZT_INLINE void eachMember(F f) { Mutex::Lock ml(_memberships_l); Hashtable::Iterator i(_memberships); @@ -353,7 +353,7 @@ public: /** * @return Externally usable pointer-to-pointer exported via the core API */ - ZT_ALWAYS_INLINE void **userPtr() noexcept { return &_uPtr; } + ZT_INLINE void **userPtr() noexcept { return &_uPtr; } private: void _requestConfiguration(void *tPtr); @@ -378,7 +378,7 @@ private: struct _IncomingConfigChunk { - ZT_ALWAYS_INLINE _IncomingConfigChunk() : touchCtr(0),updateId(0) {} + ZT_INLINE _IncomingConfigChunk() : touchCtr(0),updateId(0) {} uint64_t touchCtr; uint64_t updateId; std::map< int,std::vector > chunks; diff --git a/node/NetworkConfig.hpp b/node/NetworkConfig.hpp index 6845a3085..8434452c7 100644 --- a/node/NetworkConfig.hpp +++ b/node/NetworkConfig.hpp @@ -163,7 +163,7 @@ namespace ZeroTier { */ struct NetworkConfig : TriviallyCopyable { - ZT_ALWAYS_INLINE NetworkConfig() noexcept { memoryZero(this); } + ZT_INLINE NetworkConfig() noexcept { memoryZero(this); } /** * Write this network config to a dictionary for transport @@ -185,28 +185,28 @@ struct NetworkConfig : TriviallyCopyable /** * @return True if broadcast (ff:ff:ff:ff:ff:ff) address should work on this network */ - ZT_ALWAYS_INLINE bool enableBroadcast() const noexcept { return ((this->flags & ZT_NETWORKCONFIG_FLAG_ENABLE_BROADCAST) != 0); } + ZT_INLINE bool enableBroadcast() const noexcept { return ((this->flags & ZT_NETWORKCONFIG_FLAG_ENABLE_BROADCAST) != 0); } /** * @return True if IPv6 NDP emulation should be allowed for certain "magic" IPv6 address patterns */ - ZT_ALWAYS_INLINE bool ndpEmulation() const noexcept { return ((this->flags & ZT_NETWORKCONFIG_FLAG_ENABLE_IPV6_NDP_EMULATION) != 0); } + ZT_INLINE bool ndpEmulation() const noexcept { return ((this->flags & ZT_NETWORKCONFIG_FLAG_ENABLE_IPV6_NDP_EMULATION) != 0); } /** * @return Network type is public (no access control) */ - ZT_ALWAYS_INLINE bool isPublic() const noexcept { return (this->type == ZT_NETWORK_TYPE_PUBLIC); } + ZT_INLINE bool isPublic() const noexcept { return (this->type == ZT_NETWORK_TYPE_PUBLIC); } /** * @return Network type is private (certificate access control) */ - ZT_ALWAYS_INLINE bool isPrivate() const noexcept { return (this->type == ZT_NETWORK_TYPE_PRIVATE); } + ZT_INLINE bool isPrivate() const noexcept { return (this->type == ZT_NETWORK_TYPE_PRIVATE); } /** * @param fromPeer Peer attempting to bridge other Ethernet peers onto network * @return True if this network allows bridging */ - ZT_ALWAYS_INLINE bool permitsBridging(const Address &fromPeer) const noexcept + ZT_INLINE bool permitsBridging(const Address &fromPeer) const noexcept { for(unsigned int i=0;i &a,const SharedPtr &b) const { return (a->address() < b->address()); } + ZT_INLINE bool operator()(const SharedPtr &a,const SharedPtr &b) const { return (a->address() < b->address()); } }; } // anonymous namespace @@ -197,7 +197,7 @@ struct _processBackgroundTasks_ping_eachPeer void *tPtr; bool online; std::vector
rootsNotOnline; - ZT_ALWAYS_INLINE void operator()(const SharedPtr &peer,const bool isRoot) + ZT_INLINE void operator()(const SharedPtr &peer,const bool isRoot) { peer->ping(tPtr,now,isRoot); if (isRoot) { @@ -216,7 +216,7 @@ struct _processBackgroundTasks_path_keepalive int64_t now; RuntimeEnvironment *RR; void *tPtr; - ZT_ALWAYS_INLINE void operator()(const SharedPtr &path) + ZT_INLINE void operator()(const SharedPtr &path) { if ((now - path->lastOut()) >= ZT_PATH_KEEPALIVE_PERIOD) { ++keepAlivePayload; diff --git a/node/Node.hpp b/node/Node.hpp index f87cadbd5..dd30e0e62 100644 --- a/node/Node.hpp +++ b/node/Node.hpp @@ -110,7 +110,7 @@ public: /** * @return Most recent time value supplied to core via API */ - ZT_ALWAYS_INLINE int64_t now() const noexcept { return _now; } + ZT_INLINE int64_t now() const noexcept { return _now; } /** * Send packet to to the physical wire via callback @@ -123,7 +123,7 @@ public: * @param ttl TTL or 0 for default/max * @return True if send appears successful */ - ZT_ALWAYS_INLINE bool putPacket(void *tPtr,const int64_t localSocket,const InetAddress &addr,const void *data,unsigned int len,unsigned int ttl = 0) noexcept + ZT_INLINE bool putPacket(void *tPtr,const int64_t localSocket,const InetAddress &addr,const void *data,unsigned int len,unsigned int ttl = 0) noexcept { return (_cb.wirePacketSendFunction( reinterpret_cast(this), @@ -149,7 +149,7 @@ public: * @param data Ethernet frame data * @param len Ethernet frame length in bytes */ - ZT_ALWAYS_INLINE void putFrame(void *tPtr,uint64_t nwid,void **nuptr,const MAC &source,const MAC &dest,unsigned int etherType,unsigned int vlanId,const void *data,unsigned int len) noexcept + ZT_INLINE void putFrame(void *tPtr,uint64_t nwid,void **nuptr,const MAC &source,const MAC &dest,unsigned int etherType,unsigned int vlanId,const void *data,unsigned int len) noexcept { _cb.virtualNetworkFrameFunction( reinterpret_cast(this), @@ -169,7 +169,7 @@ public: * @param nwid Network ID * @return Network associated with ID */ - ZT_ALWAYS_INLINE SharedPtr network(uint64_t nwid) const noexcept + ZT_INLINE SharedPtr network(uint64_t nwid) const noexcept { RWMutex::RLock l(_networks_m); return _networks[(unsigned long)((nwid + (nwid >> 32U)) & _networksMask)]; @@ -178,7 +178,7 @@ public: /** * @return Known local interface addresses for this node */ - ZT_ALWAYS_INLINE std::vector localInterfaceAddresses() const + ZT_INLINE std::vector localInterfaceAddresses() const { Mutex::Lock _l(_localInterfaceAddresses_m); return _localInterfaceAddresses; @@ -191,7 +191,7 @@ public: * @param ev Event object * @param md Event data or NULL if none */ - ZT_ALWAYS_INLINE void postEvent(void *tPtr,ZT_Event ev,const void *md = nullptr) noexcept + ZT_INLINE void postEvent(void *tPtr,ZT_Event ev,const void *md = nullptr) noexcept { _cb.eventCallback(reinterpret_cast(this),_uPtr,tPtr,ev,md); } @@ -205,7 +205,7 @@ public: * @param op Config operation or event type * @param nc Network config info */ - ZT_ALWAYS_INLINE void configureVirtualNetworkPort(void *tPtr,uint64_t nwid,void **nuptr,ZT_VirtualNetworkConfigOperation op,const ZT_VirtualNetworkConfig *nc) noexcept + ZT_INLINE void configureVirtualNetworkPort(void *tPtr,uint64_t nwid,void **nuptr,ZT_VirtualNetworkConfigOperation op,const ZT_VirtualNetworkConfig *nc) noexcept { _cb.virtualNetworkConfigFunction(reinterpret_cast(this),_uPtr,tPtr,nwid,nuptr,op,nc); } @@ -213,7 +213,7 @@ public: /** * @return True if node appears online */ - ZT_ALWAYS_INLINE bool online() const noexcept { return _online; } + ZT_INLINE bool online() const noexcept { return _online; } /** * Get a state object @@ -234,7 +234,7 @@ public: * @param data Data to store * @param len Length of data */ - ZT_ALWAYS_INLINE void stateObjectPut(void *const tPtr,ZT_StateObjectType type,const uint64_t id[2],const void *const data,const unsigned int len) noexcept + ZT_INLINE void stateObjectPut(void *const tPtr,ZT_StateObjectType type,const uint64_t id[2],const void *const data,const unsigned int len) noexcept { if (_cb.statePutFunction) _cb.statePutFunction(reinterpret_cast(this),_uPtr,tPtr,type,id,data,(int)len); @@ -247,7 +247,7 @@ public: * @param type Object type to delete * @param id Object ID */ - ZT_ALWAYS_INLINE void stateObjectDelete(void *const tPtr,ZT_StateObjectType type,const uint64_t id[2]) noexcept + ZT_INLINE void stateObjectDelete(void *const tPtr,ZT_StateObjectType type,const uint64_t id[2]) noexcept { if (_cb.statePutFunction) _cb.statePutFunction(reinterpret_cast(this),_uPtr,tPtr,type,id,(const void *)0,-1); @@ -289,12 +289,12 @@ public: /** * @return This node's identity */ - ZT_ALWAYS_INLINE const Identity &identity() const noexcept { return _RR.identity; } + ZT_INLINE const Identity &identity() const noexcept { return _RR.identity; } /** * @return True if aggressive NAT-traversal mechanisms like scanning of <1024 ports are enabled */ - ZT_ALWAYS_INLINE bool natMustDie() const noexcept { return _natMustDie; } + ZT_INLINE bool natMustDie() const noexcept { return _natMustDie; } /** * Wake any peers with the given address by calling their alarm() methods at or after the specified time @@ -302,7 +302,7 @@ public: * @param peerAddress Peer address * @param triggerTime Time alarm should go off */ - ZT_ALWAYS_INLINE void setPeerAlarm(const Address &peerAddress,const int64_t triggerTime) + ZT_INLINE void setPeerAlarm(const Address &peerAddress,const int64_t triggerTime) { RWMutex::Lock l(_peerAlarms_l); int64_t &t = _peerAlarms[peerAddress]; @@ -354,10 +354,10 @@ private: struct _LocalControllerAuth { uint64_t nwid,address; - ZT_ALWAYS_INLINE _LocalControllerAuth(const uint64_t nwid_,const Address &address_) noexcept: nwid(nwid_),address(address_.toInt()) {} - ZT_ALWAYS_INLINE unsigned long hashCode() const noexcept { return (unsigned long)(nwid ^ address); } - ZT_ALWAYS_INLINE bool operator==(const _LocalControllerAuth &a) const noexcept { return ((a.nwid == nwid)&&(a.address == address)); } - ZT_ALWAYS_INLINE bool operator!=(const _LocalControllerAuth &a) const noexcept { return ((a.nwid != nwid)||(a.address != address)); } + ZT_INLINE _LocalControllerAuth(const uint64_t nwid_,const Address &address_) noexcept: nwid(nwid_),address(address_.toInt()) {} + ZT_INLINE unsigned long hashCode() const noexcept { return (unsigned long)(nwid ^ address); } + ZT_INLINE bool operator==(const _LocalControllerAuth &a) const noexcept { return ((a.nwid == nwid) && (a.address == address)); } + ZT_INLINE bool operator!=(const _LocalControllerAuth &a) const noexcept { return ((a.nwid != nwid) || (a.address != address)); } }; Hashtable< _LocalControllerAuth,int64_t > _localControllerAuthorizations; Mutex _localControllerAuthorizations_m; diff --git a/node/OS.hpp b/node/OS.hpp index 78ccb2e65..6f94d70d7 100644 --- a/node/OS.hpp +++ b/node/OS.hpp @@ -11,55 +11,15 @@ */ /****/ +// This include file uses various macros and other tricks to auto-detect, define, and +// canonicalize a bunch of macros and types used throughout the ZeroTier core. + #ifndef ZT_OS_HPP #define ZT_OS_HPP #include - -// -// This include file also auto-detects and canonicalizes some environment -// information defines: -// -// __LINUX__ -// __APPLE__ -// __BSD__ (OSX also defines this) -// __UNIX_LIKE__ (Linux, BSD, etc.) -// __WINDOWS__ -// -// Also makes sure __BYTE_ORDER is defined reasonably. -// - -#ifndef __GCC__ -#if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1) || defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2) || defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) || defined(__INTEL_COMPILER) || defined(__clang__) -#define __GCC__ -#endif -#endif -#if defined(__GCC__) && !defined(__GNUC__) -#define __GNUC__ -#endif - -#if defined(__SIZEOF_INT128__) || ((defined(__GCC__) || defined(__GNUC__) || defined(__clang)) && (defined(__amd64) || defined(__amd64__) || defined(__x86_64) || defined(__x86_64__) || defined(__AMD64) || defined(__AMD64__) || defined(_M_X64) || defined(__aarch64__))) -#if defined(__SIZEOF_INT128__) -#define ZT_HAVE_UINT128 1 -typedef unsigned __int128 uint128_t; -#else -#define ZT_HAVE_UINT128 1 -typedef unsigned uint128_t __attribute__((mode(TI))); -#endif -#endif - -#if (defined(__amd64) || defined(__amd64__) || defined(__x86_64) || defined(__x86_64__) || defined(__AMD64) || defined(__AMD64__) || defined(_M_X64)) -#define ZT_ARCH_X64 1 -#endif - -// As far as we know it's only generally safe to do unaligned type casts in all -// cases on x86 and x64 architectures. Others such as ARM and MIPS will generate -// a fault or exhibit undefined behavior that varies by vendor. -#if (!(defined(ZT_ARCH_X64) || defined(i386) || defined(__i386) || defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || defined(_M_IX86) || defined(__X86__) || defined(_X86_) || defined(__I86__) || defined(__INTEL__) || defined(__386))) -#ifndef ZT_NO_UNALIGNED_ACCESS -#define ZT_NO_UNALIGNED_ACCESS 1 -#endif -#endif +#include +#include #if defined(_WIN32) || defined(_WIN64) #ifdef _MSC_VER @@ -77,65 +37,31 @@ typedef unsigned uint128_t __attribute__((mode(TI))); #undef __BSD__ #include #include +#include #endif -#if defined(__linux__) || defined(linux) || defined(__LINUX__) || defined(__linux) -#ifndef __LINUX__ -#define __LINUX__ 1 -#endif -#ifndef __UNIX_LIKE__ -#define __UNIX_LIKE__ 1 -#endif -#include +#if !defined(__GNUC__) && (defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1) || defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2) || defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) || defined(__INTEL_COMPILER) || defined(__clang__)) +#define __GNUC__ 3 #endif -#ifdef __APPLE__ -#include -#ifndef __UNIX_LIKE__ -#define __UNIX_LIKE__ 1 +#if __cplusplus > 199711L +#include +#ifndef __CPP11__ +#define __CPP11__ #endif -#ifndef __BSD__ -#define __BSD__ 1 -#endif -#include -#ifndef __BYTE_ORDER -#define __BYTE_ORDER __DARWIN_BYTE_ORDER -#define __BIG_ENDIAN __DARWIN_BIG_ENDIAN -#define __LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN #endif +#ifndef __CPP11__ +// Beyond that defining nullptr, constexpr, and noexcept should allow us to still build on these. So far we've +// avoided deeper C++11 features like lambdas in the core until we're 100% sure all the ancient targets are gone. +#error TODO: to build on pre-c++11 compilers we'll need to make a subset "polyfill" of std::atomic for integers +#define nullptr (0) +#define constexpr ZT_INLINE +#define noexcept throw() #endif -#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) -#ifndef __UNIX_LIKE__ -#define __UNIX_LIKE__ 1 -#endif -#ifndef __BSD__ -#define __BSD__ 1 -#endif -#include -#ifndef RTF_MULTICAST -#define RTF_MULTICAST 0x20000000 -#endif -#endif - -// It would probably be safe to assume LE everywhere except on very specific architectures as there -// are few BE chips remaining in the wild that are powerful enough to run this, but for now we'll -// try to include endian.h and error out if it doesn't exist. -#ifndef __BYTE_ORDER -#ifdef _BYTE_ORDER -#define __BYTE_ORDER _BYTE_ORDER -#define __LITTLE_ENDIAN _LITTLE_ENDIAN -#define __BIG_ENDIAN _BIG_ENDIAN -#else -#include -#endif -#endif - -#if (defined(__GNUC__) && (__GNUC__ >= 3)) || (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 800)) || defined(__clang__) -#ifdef ZT_DEBUG -#define ZT_ALWAYS_INLINE -#else -#define ZT_ALWAYS_INLINE __attribute__((always_inline)) inline +#ifdef __GNUC__ +#ifndef ZT_DEBUG +#define ZT_INLINE __attribute__((always_inline)) inline #endif #ifndef restrict #define restrict __restrict__ @@ -158,31 +84,66 @@ typedef unsigned uint128_t __attribute__((mode(TI))); #endif #endif -#if __cplusplus > 199711L -#include -#ifndef __CPP11__ -#define __CPP11__ +#if (defined(__amd64) || defined(__amd64__) || defined(__x86_64) || defined(__x86_64__) || defined(__AMD64) || defined(__AMD64__) || defined(_M_X64)) +#define ZT_ARCH_X64 1 #endif -#endif -#ifndef __CPP11__ -// TODO: we'll need to "polyfill" a subset of std::atomic for integers if we want to build on pre-C++11 compilers. -// Beyond that defining nullptr, constexpr, and noexcept should allow us to still build on these. So far we've -// avoided deeper C++11 features like lambdas in the core until we're 100% sure all the ancient targets are gone. -#error need pre-c++11 std::atomic implementation -#define nullptr (0) -#define constexpr ZT_ALWAYS_INLINE -#define noexcept throw() +#if defined(ZT_ARCH_X64) || defined(i386) || defined(__i386) || defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || defined(_M_IX86) || defined(__X86__) || defined(_X86_) || defined(__I86__) || defined(__INTEL__) || defined(__386) +#define ZT_ARCH_X86 1 #endif -#ifdef SOCKET -#define ZT_SOCKET SOCKET -#else -#define ZT_SOCKET int +#if !defined(ZT_ARCH_X86) +#ifndef ZT_NO_UNALIGNED_ACCESS +#define ZT_NO_UNALIGNED_ACCESS 1 #endif -#ifdef INVALID_SOCKET -#define ZT_INVALID_SOCKET INVALID_SOCKET +#endif + +#if defined(__SIZEOF_INT128__) || ((defined(ZT_ARCH_X64) || defined(__aarch64__)) && defined(__GNUC__)) +#ifdef __SIZEOF_INT128__ +#define ZT_HAVE_UINT128 1 +typedef unsigned __int128 uint128_t; #else -#define ZT_INVALID_SOCKET -1 +#define ZT_HAVE_UINT128 1 +typedef unsigned uint128_t __attribute__((mode(TI))); +#endif +#endif + +#if defined(__linux__) || defined(linux) || defined(__LINUX__) || defined(__linux) +#ifndef __LINUX__ +#define __LINUX__ 1 +#endif +#ifndef __UNIX_LIKE__ +#define __UNIX_LIKE__ 1 +#endif +#include +#endif + +#ifdef __APPLE__ +#include +#include +#ifndef __UNIX_LIKE__ +#define __UNIX_LIKE__ 1 +#endif +#ifndef __BSD__ +#define __BSD__ 1 +#endif +#ifndef __BYTE_ORDER +#define __BYTE_ORDER __DARWIN_BYTE_ORDER +#define __BIG_ENDIAN __DARWIN_BIG_ENDIAN +#define __LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN +#endif +#endif + +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) +#ifndef __UNIX_LIKE__ +#define __UNIX_LIKE__ 1 +#endif +#ifndef __BSD__ +#define __BSD__ 1 +#endif +#include +#ifndef RTF_MULTICAST +#define RTF_MULTICAST 0x20000000 +#endif #endif #ifdef __WINDOWS__ @@ -195,19 +156,28 @@ typedef unsigned uint128_t __attribute__((mode(TI))); #define ZT_EOL_S "\n" #endif -#ifndef ZT_ALWAYS_INLINE +#if !defined(__BYTE_ORDER) && defined(__BYTE_ORDER__) +#define __BYTE_ORDER __BYTE_ORDER__ +#define __LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__ +#define __BIG_ENDIAN __ORDER_BIG_ENDIAN__ +#endif +#if !defined(__BYTE_ORDER) && defined(BYTE_ORDER) +#define __BYTE_ORDER BYTE_ORDER +#define __LITTLE_ENDIAN LITTLE_ENDIAN +#define __BIG_ENDIAN BIG_ENDIAN +#endif +#if !defined(__BYTE_ORDER) && defined(_BYTE_ORDER) +#define __BYTE_ORDER _BYTE_ORDER +#define __LITTLE_ENDIAN _LITTLE_ENDIAN +#define __BIG_ENDIAN _BIG_ENDIAN +#endif + +#ifndef ZT_INLINE #ifdef ZT_DEBUG -#define ZT_ALWAYS_INLINE +#define ZT_INLINE #else -#define ZT_ALWAYS_INLINE inline +#define ZT_INLINE inline #endif #endif -// Macro to avoid calling hton() on values known at compile time. -#if __BYTE_ORDER == __LITTLE_ENDIAN -#define ZT_CONST_TO_BE_UINT16(x) ((uint16_t)((uint16_t)((uint16_t)(x) << 8U) | (uint16_t)((uint16_t)(x) >> 8U))) -#else -#define ZT_CONST_TO_BE_UINT16(x) ((uint16_t)(x)) -#endif - #endif diff --git a/node/Path.hpp b/node/Path.hpp index b22943459..619e798c8 100644 --- a/node/Path.hpp +++ b/node/Path.hpp @@ -47,7 +47,7 @@ class Path friend class Defragmenter; public: - ZT_ALWAYS_INLINE Path(const int64_t l,const InetAddress &r) noexcept : + ZT_INLINE Path(const int64_t l,const InetAddress &r) noexcept : _localSocket(l), _lastIn(0), _lastOut(0), @@ -73,7 +73,7 @@ public: * @param now Time of send * @param bytes Bytes sent */ - ZT_ALWAYS_INLINE void sent(const int64_t now,const unsigned int bytes) noexcept + ZT_INLINE void sent(const int64_t now,const unsigned int bytes) noexcept { _lastOut.store(now); _outMeter.log(now,bytes); @@ -85,7 +85,7 @@ public: * @param now Time of receive * @param bytes Bytes received */ - ZT_ALWAYS_INLINE void received(const int64_t now,const unsigned int bytes) noexcept + ZT_INLINE void received(const int64_t now,const unsigned int bytes) noexcept { _lastIn.store(now); _inMeter.log(now,bytes); @@ -96,27 +96,27 @@ public: * * @param now Current time */ - ZT_ALWAYS_INLINE bool alive(const int64_t now) const noexcept { return ((now - _lastIn.load()) < ZT_PATH_ALIVE_TIMEOUT); } + ZT_INLINE bool alive(const int64_t now) const noexcept { return ((now - _lastIn.load()) < ZT_PATH_ALIVE_TIMEOUT); } /** * @return Physical address */ - ZT_ALWAYS_INLINE const InetAddress &address() const noexcept { return _addr; } + ZT_INLINE const InetAddress &address() const noexcept { return _addr; } /** * @return Local socket as specified by external code */ - ZT_ALWAYS_INLINE int64_t localSocket() const noexcept { return _localSocket; } + ZT_INLINE int64_t localSocket() const noexcept { return _localSocket; } /** * @return Last time we received anything */ - ZT_ALWAYS_INLINE int64_t lastIn() const noexcept { return _lastIn.load(); } + ZT_INLINE int64_t lastIn() const noexcept { return _lastIn.load(); } /** * @return Last time we sent something */ - ZT_ALWAYS_INLINE int64_t lastOut() const noexcept { return _lastOut.load(); } + ZT_INLINE int64_t lastOut() const noexcept { return _lastOut.load(); } private: const int64_t _localSocket; diff --git a/node/Peer.cpp b/node/Peer.cpp index 2d3d1c0a7..8bcc72939 100644 --- a/node/Peer.cpp +++ b/node/Peer.cpp @@ -28,7 +28,7 @@ namespace ZeroTier { struct _PathPriorityComparisonOperator { - ZT_ALWAYS_INLINE bool operator()(const SharedPtr &a,const SharedPtr &b) const + ZT_INLINE bool operator()(const SharedPtr &a,const SharedPtr &b) const { return ( ((a)&&(a->lastIn() > 0)) && ((!b)||(b->lastIn() <= 0)||(a->lastIn() < b->lastIn())) ); } diff --git a/node/Peer.hpp b/node/Peer.hpp index 894a90a67..51b7c386f 100644 --- a/node/Peer.hpp +++ b/node/Peer.hpp @@ -48,7 +48,7 @@ class Peer friend class Topology; private: - ZT_ALWAYS_INLINE Peer() {} + ZT_INLINE Peer() {} public: /** @@ -61,7 +61,7 @@ public: */ explicit Peer(const RuntimeEnvironment *renv); - ZT_ALWAYS_INLINE ~Peer() { Utils::burn(_key,sizeof(_key)); } + ZT_INLINE ~Peer() { Utils::burn(_key,sizeof(_key)); } /** * Initialize peer with an identity @@ -74,17 +74,17 @@ public: /** * @return This peer's ZT address (short for identity().address()) */ - ZT_ALWAYS_INLINE const Address &address() const noexcept { return _id.address(); } + ZT_INLINE const Address &address() const noexcept { return _id.address(); } /** * @return This peer's identity */ - ZT_ALWAYS_INLINE const Identity &identity() const noexcept { return _id; } + ZT_INLINE const Identity &identity() const noexcept { return _id; } /** * @return Copy of current locator */ - ZT_ALWAYS_INLINE Locator locator() const noexcept + ZT_INLINE Locator locator() const noexcept { RWMutex::RLock l(_lock); return _locator; @@ -172,7 +172,7 @@ public: /** * @return Bootstrap address or NULL if none */ - ZT_ALWAYS_INLINE const Endpoint &bootstrap() const noexcept + ZT_INLINE const Endpoint &bootstrap() const noexcept { RWMutex::RLock l(_lock); return _bootstrap; @@ -183,7 +183,7 @@ public: * * @param ep Bootstrap endpoint */ - ZT_ALWAYS_INLINE void setBootstrap(const Endpoint &ep) noexcept + ZT_INLINE void setBootstrap(const Endpoint &ep) noexcept { RWMutex::Lock l(_lock); _bootstrap = ep; @@ -192,32 +192,32 @@ public: /** * @return Time of last receive of anything, whether direct or relayed */ - ZT_ALWAYS_INLINE int64_t lastReceive() const noexcept { return _lastReceive; } + ZT_INLINE int64_t lastReceive() const noexcept { return _lastReceive; } /** * @return True if we've heard from this peer in less than ZT_PEER_ALIVE_TIMEOUT */ - ZT_ALWAYS_INLINE bool alive(const int64_t now) const noexcept { return ((now - _lastReceive) < ZT_PEER_ALIVE_TIMEOUT); } + ZT_INLINE bool alive(const int64_t now) const noexcept { return ((now - _lastReceive) < ZT_PEER_ALIVE_TIMEOUT); } /** * @return True if we've heard from this peer in less than ZT_PEER_ACTIVITY_TIMEOUT */ - ZT_ALWAYS_INLINE bool active(const int64_t now) const noexcept { return ((now - _lastReceive) < ZT_PEER_ACTIVITY_TIMEOUT); } + ZT_INLINE bool active(const int64_t now) const noexcept { return ((now - _lastReceive) < ZT_PEER_ACTIVITY_TIMEOUT); } /** * @return Latency in milliseconds of best/aggregate path or 0xffff if unknown */ - ZT_ALWAYS_INLINE unsigned int latency() const noexcept { return _latency; } + ZT_INLINE unsigned int latency() const noexcept { return _latency; } /** * @return 256-bit secret symmetric encryption key */ - ZT_ALWAYS_INLINE const unsigned char *key() const noexcept { return _key; } + ZT_INLINE const unsigned char *key() const noexcept { return _key; } /** * @return Preferred cipher suite for normal encrypted P2P communication */ - ZT_ALWAYS_INLINE uint8_t cipher() const noexcept + ZT_INLINE uint8_t cipher() const noexcept { return ZT_PROTO_CIPHER_SUITE__POLY1305_SALSA2012; } @@ -225,7 +225,7 @@ public: /** * @return Incoming probe packet (in big-endian byte order) 0 */ - ZT_ALWAYS_INLINE uint64_t incomingProbe() const noexcept { return _incomingProbe; } + ZT_INLINE uint64_t incomingProbe() const noexcept { return _incomingProbe; } /** * Set the currently known remote version of this peer's client @@ -235,7 +235,7 @@ public: * @param vmin Minor version * @param vrev Revision */ - ZT_ALWAYS_INLINE void setRemoteVersion(unsigned int vproto,unsigned int vmaj,unsigned int vmin,unsigned int vrev) noexcept + ZT_INLINE void setRemoteVersion(unsigned int vproto,unsigned int vmaj,unsigned int vmin,unsigned int vrev) noexcept { _vProto = (uint16_t)vproto; _vMajor = (uint16_t)vmaj; @@ -243,16 +243,16 @@ public: _vRevision = (uint16_t)vrev; } - ZT_ALWAYS_INLINE unsigned int remoteVersionProtocol() const noexcept { return _vProto; } - ZT_ALWAYS_INLINE unsigned int remoteVersionMajor() const noexcept { return _vMajor; } - ZT_ALWAYS_INLINE unsigned int remoteVersionMinor() const noexcept { return _vMinor; } - ZT_ALWAYS_INLINE unsigned int remoteVersionRevision() const noexcept { return _vRevision; } - ZT_ALWAYS_INLINE bool remoteVersionKnown() const noexcept { return ((_vMajor > 0)||(_vMinor > 0)||(_vRevision > 0)); } + ZT_INLINE unsigned int remoteVersionProtocol() const noexcept { return _vProto; } + ZT_INLINE unsigned int remoteVersionMajor() const noexcept { return _vMajor; } + ZT_INLINE unsigned int remoteVersionMinor() const noexcept { return _vMinor; } + ZT_INLINE unsigned int remoteVersionRevision() const noexcept { return _vRevision; } + ZT_INLINE bool remoteVersionKnown() const noexcept { return ((_vMajor > 0) || (_vMinor > 0) || (_vRevision > 0)); } /** * Rate limit gate for inbound WHOIS requests */ - ZT_ALWAYS_INLINE bool rateGateInboundWhoisRequest(const int64_t now) noexcept + ZT_INLINE bool rateGateInboundWhoisRequest(const int64_t now) noexcept { if ((now - _lastWhoisRequestReceived) >= ZT_PEER_WHOIS_RATE_LIMIT) { _lastWhoisRequestReceived = now; @@ -264,7 +264,7 @@ public: /** * Rate limit gate for inbound PUSH_DIRECT_PATHS requests */ - ZT_ALWAYS_INLINE bool rateGateInboundPushDirectPaths(const int64_t now) noexcept + ZT_INLINE bool rateGateInboundPushDirectPaths(const int64_t now) noexcept { if ((now - _lastPushDirectPathsReceived) >= ZT_DIRECT_PATH_PUSH_INTERVAL) { _lastPushDirectPathsReceived = now; @@ -276,7 +276,7 @@ public: /** * Rate limit attempts in response to incoming short probe packets */ - ZT_ALWAYS_INLINE bool rateGateInboundProbe(const int64_t now) noexcept + ZT_INLINE bool rateGateInboundProbe(const int64_t now) noexcept { if ((now - _lastProbeReceived) >= ZT_DIRECT_PATH_PUSH_INTERVAL) { _lastProbeReceived = now; @@ -288,7 +288,7 @@ public: /** * Rate limit gate for inbound ECHO requests */ - ZT_ALWAYS_INLINE bool rateGateEchoRequest(const int64_t now) noexcept + ZT_INLINE bool rateGateEchoRequest(const int64_t now) noexcept { if ((now - _lastEchoRequestReceived) >= ZT_PEER_GENERAL_RATE_LIMIT) { _lastEchoRequestReceived = now; @@ -379,12 +379,12 @@ private: // Queue of batches of one or more physical addresses to try at some point in the future (for NAT traversal logic) struct _ContactQueueItem { - ZT_ALWAYS_INLINE _ContactQueueItem() {} - ZT_ALWAYS_INLINE _ContactQueueItem(const InetAddress &a,const uint16_t *pstart,const uint16_t *pend,const unsigned int apt) : + ZT_INLINE _ContactQueueItem() {} + ZT_INLINE _ContactQueueItem(const InetAddress &a,const uint16_t *pstart,const uint16_t *pend,const unsigned int apt) : address(a), ports(pstart,pend), alivePathThreshold(apt) {} - ZT_ALWAYS_INLINE _ContactQueueItem(const InetAddress &a,const unsigned int apt) : + ZT_INLINE _ContactQueueItem(const InetAddress &a,const unsigned int apt) : address(a), ports(), alivePathThreshold(apt) {} diff --git a/node/Poly1305.cpp b/node/Poly1305.cpp index 0fc8e4cce..3c95e8636 100644 --- a/node/Poly1305.cpp +++ b/node/Poly1305.cpp @@ -49,7 +49,7 @@ typedef struct poly1305_state_internal_t { unsigned char final; } poly1305_state_internal_t; -ZT_ALWAYS_INLINE void poly1305_init(poly1305_context *ctx, const unsigned char key[32]) +ZT_INLINE void poly1305_init(poly1305_context *ctx,const unsigned char key[32]) { poly1305_state_internal_t *st = (poly1305_state_internal_t *)ctx; unsigned long long t0,t1; @@ -126,7 +126,7 @@ void poly1305_blocks(poly1305_state_internal_t *st, const unsigned char *m, size st->h[2] = h2; } -ZT_ALWAYS_INLINE void poly1305_finish(poly1305_context *ctx, unsigned char mac[16]) +ZT_INLINE void poly1305_finish(poly1305_context *ctx,unsigned char mac[16]) { poly1305_state_internal_t *st = (poly1305_state_internal_t *)ctx; unsigned long long h0,h1,h2,c; @@ -210,7 +210,7 @@ typedef struct poly1305_state_internal_t { unsigned char final; } poly1305_state_internal_t; -ZT_ALWAYS_INLINE void poly1305_init(poly1305_context *ctx, const unsigned char key[32]) +ZT_INLINE void poly1305_init(poly1305_context *ctx, const unsigned char key[32]) { poly1305_state_internal_t *st = (poly1305_state_internal_t *)ctx; @@ -297,7 +297,7 @@ void poly1305_blocks(poly1305_state_internal_t *st, const unsigned char *m, size st->h[4] = h4; } -ZT_ALWAYS_INLINE void poly1305_finish(poly1305_context *ctx, unsigned char mac[16]) +ZT_INLINE void poly1305_finish(poly1305_context *ctx, unsigned char mac[16]) { poly1305_state_internal_t *st = (poly1305_state_internal_t *)ctx; unsigned long h0,h1,h2,h3,h4,c; @@ -386,7 +386,7 @@ ZT_ALWAYS_INLINE void poly1305_finish(poly1305_context *ctx, unsigned char mac[1 #endif // uint128_t or portable version? -ZT_ALWAYS_INLINE void poly1305_update(poly1305_context *ctx, const unsigned char *m, size_t bytes) noexcept +ZT_INLINE void poly1305_update(poly1305_context *ctx,const unsigned char *m,size_t bytes) noexcept { poly1305_state_internal_t *st = (poly1305_state_internal_t *)ctx; size_t i; diff --git a/node/Protocol.hpp b/node/Protocol.hpp index 0eeda037e..46eb75fd2 100644 --- a/node/Protocol.hpp +++ b/node/Protocol.hpp @@ -969,31 +969,31 @@ ZT_PACKED_STRUCT(struct UNSUPPORTED_OPERATION__NETWORK_CONFIG_REQUEST * @param packetSize Packet's actual size in bytes * @return Packet ID or 0 if packet size is less than 8 */ -static ZT_ALWAYS_INLINE uint64_t packetId(const Buf &pkt,const unsigned int packetSize) noexcept { return (packetSize >= 8) ? Utils::loadBigEndian(pkt.unsafeData) : 0ULL; } +static ZT_INLINE uint64_t packetId(const Buf &pkt,const unsigned int packetSize) noexcept { return (packetSize >= 8) ? Utils::loadBigEndian(pkt.unsafeData) : 0ULL; } /** * @param Packet to extract hops from * @param packetSize Packet's actual size in bytes * @return 3-bit hops field embedded in packet flags field */ -static ZT_ALWAYS_INLINE uint8_t packetHops(const Buf &pkt,const unsigned int packetSize) noexcept { return (packetSize >= ZT_PROTO_PACKET_FLAGS_INDEX) ? (pkt.unsafeData[ZT_PROTO_PACKET_FLAGS_INDEX] & ZT_PROTO_FLAG_FIELD_HOPS_MASK) : 0; } +static ZT_INLINE uint8_t packetHops(const Buf &pkt,const unsigned int packetSize) noexcept { return (packetSize >= ZT_PROTO_PACKET_FLAGS_INDEX) ? (pkt.unsafeData[ZT_PROTO_PACKET_FLAGS_INDEX] & ZT_PROTO_FLAG_FIELD_HOPS_MASK) : 0; } /** * @param Packet to extract cipher ID from * @param packetSize Packet's actual size in bytes * @return 3-bit cipher field embedded in packet flags field */ -static ZT_ALWAYS_INLINE uint8_t packetCipher(const Buf &pkt,const unsigned int packetSize) noexcept { return (packetSize >= ZT_PROTO_PACKET_FLAGS_INDEX) ? ((pkt.unsafeData[ZT_PROTO_PACKET_FLAGS_INDEX] >> 3U) & 0x07U) : 0; } +static ZT_INLINE uint8_t packetCipher(const Buf &pkt,const unsigned int packetSize) noexcept { return (packetSize >= ZT_PROTO_PACKET_FLAGS_INDEX) ? ((pkt.unsafeData[ZT_PROTO_PACKET_FLAGS_INDEX] >> 3U) & 0x07U) : 0; } /** * @return 3-bit hops field embedded in packet flags field */ -static ZT_ALWAYS_INLINE uint8_t packetHops(const Header &ph) noexcept { return (ph.flags & 0x07U); } +static ZT_INLINE uint8_t packetHops(const Header &ph) noexcept { return (ph.flags & 0x07U); } /** * @return 3-bit cipher field embedded in packet flags field */ -static ZT_ALWAYS_INLINE uint8_t packetCipher(const Header &ph) noexcept { return ((ph.flags >> 3U) & 0x07U); } +static ZT_INLINE uint8_t packetCipher(const Header &ph) noexcept { return ((ph.flags >> 3U) & 0x07U); } /** * Deterministically mangle a 256-bit crypto key based on packet characteristics @@ -1005,7 +1005,7 @@ static ZT_ALWAYS_INLINE uint8_t packetCipher(const Header &ph) noexcept { return * @param in Input key (32 bytes) * @param out Output buffer (32 bytes) */ -static ZT_ALWAYS_INLINE void salsa2012DeriveKey(const uint8_t *const in,uint8_t *const out,const Buf &packet,const unsigned int packetSize) noexcept +static ZT_INLINE void salsa2012DeriveKey(const uint8_t *const in,uint8_t *const out,const Buf &packet,const unsigned int packetSize) noexcept { // IV and source/destination addresses. Using the addresses divides the // key space into two halves-- A->B and B->A (since order will change). @@ -1056,7 +1056,7 @@ extern std::atomic _s_packetIdCtr; * * @return Next packet ID */ -static ZT_ALWAYS_INLINE uint64_t getPacketId() noexcept { return ++_s_packetIdCtr; } +static ZT_INLINE uint64_t getPacketId() noexcept { return ++_s_packetIdCtr; } /** * Encrypt and compute packet MAC diff --git a/node/Revocation.hpp b/node/Revocation.hpp index ec656a264..f79d28466 100644 --- a/node/Revocation.hpp +++ b/node/Revocation.hpp @@ -47,7 +47,7 @@ class Revocation : public Credential public: static constexpr ZT_CredentialType credentialType() noexcept { return ZT_CREDENTIAL_TYPE_REVOCATION; } - ZT_ALWAYS_INLINE Revocation() noexcept { memoryZero(this); } + ZT_INLINE Revocation() noexcept { memoryZero(this); } /** * @param i ID (arbitrary for revocations, currently random) @@ -58,7 +58,7 @@ public: * @param tgt Target node whose credential(s) are being revoked * @param ct Credential type being revoked */ - ZT_ALWAYS_INLINE Revocation(const uint32_t i,const uint64_t nwid,const uint32_t cid,const uint64_t thr,const uint64_t fl,const Address &tgt,const ZT_CredentialType ct) noexcept : + ZT_INLINE Revocation(const uint32_t i,const uint64_t nwid,const uint32_t cid,const uint64_t thr,const uint64_t fl,const Address &tgt,const ZT_CredentialType ct) noexcept : _id(i), _credentialId(cid), _networkId(nwid), @@ -71,16 +71,16 @@ public: { } - ZT_ALWAYS_INLINE uint32_t id() const noexcept { return _id; } - ZT_ALWAYS_INLINE uint32_t credentialId() const noexcept { return _credentialId; } - ZT_ALWAYS_INLINE uint64_t networkId() const noexcept { return _networkId; } - ZT_ALWAYS_INLINE int64_t threshold() const noexcept { return _threshold; } - ZT_ALWAYS_INLINE const Address &target() const noexcept { return _target; } - ZT_ALWAYS_INLINE const Address &signer() const noexcept { return _signedBy; } - ZT_ALWAYS_INLINE ZT_CredentialType typeBeingRevoked() const noexcept { return _type; } - ZT_ALWAYS_INLINE const uint8_t *signature() const noexcept { return _signature; } - ZT_ALWAYS_INLINE unsigned int signatureLength() const noexcept { return _signatureLength; } - ZT_ALWAYS_INLINE bool fastPropagate() const noexcept { return ((_flags & ZT_REVOCATION_FLAG_FAST_PROPAGATE) != 0); } + ZT_INLINE uint32_t id() const noexcept { return _id; } + ZT_INLINE uint32_t credentialId() const noexcept { return _credentialId; } + ZT_INLINE uint64_t networkId() const noexcept { return _networkId; } + ZT_INLINE int64_t threshold() const noexcept { return _threshold; } + ZT_INLINE const Address &target() const noexcept { return _target; } + ZT_INLINE const Address &signer() const noexcept { return _signedBy; } + ZT_INLINE ZT_CredentialType typeBeingRevoked() const noexcept { return _type; } + ZT_INLINE const uint8_t *signature() const noexcept { return _signature; } + ZT_INLINE unsigned int signatureLength() const noexcept { return _signatureLength; } + ZT_INLINE bool fastPropagate() const noexcept { return ((_flags & ZT_REVOCATION_FLAG_FAST_PROPAGATE) != 0); } /** * @param signer Signing identity, must have private key @@ -94,7 +94,7 @@ public: * @param RR Runtime environment to provide for peer lookup, etc. * @param tPtr Thread pointer to be handed through to any callbacks called as a result of this call */ - ZT_ALWAYS_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_REVOCATION_MARSHAL_SIZE_MAX; } int marshal(uint8_t data[ZT_REVOCATION_MARSHAL_SIZE_MAX],bool forSign = false) const noexcept; diff --git a/node/RuntimeEnvironment.hpp b/node/RuntimeEnvironment.hpp index bc9019cee..23cfa72cc 100644 --- a/node/RuntimeEnvironment.hpp +++ b/node/RuntimeEnvironment.hpp @@ -40,7 +40,7 @@ class Expect; class RuntimeEnvironment { public: - ZT_ALWAYS_INLINE RuntimeEnvironment(Node *n) noexcept : + ZT_INLINE RuntimeEnvironment(Node *n) noexcept : node(n), localNetworkController(nullptr), rtmem(nullptr), @@ -55,7 +55,7 @@ public: secretIdentityStr[0] = (char)0; } - ZT_ALWAYS_INLINE ~RuntimeEnvironment() + ZT_INLINE ~RuntimeEnvironment() { Utils::burn(secretIdentityStr,sizeof(secretIdentityStr)); } diff --git a/node/SHA512.cpp b/node/SHA512.cpp index 93d286787..17549e95d 100644 --- a/node/SHA512.cpp +++ b/node/SHA512.cpp @@ -55,7 +55,7 @@ static const uint64_t K[80] = { #define Gamma0(x) (S(x, 1) ^ S(x, 8) ^ R(x, 7)) #define Gamma1(x) (S(x, 19) ^ S(x, 61) ^ R(x, 6)) -static ZT_ALWAYS_INLINE void sha512_compress(sha512_state *const md,uint8_t *const buf) +static ZT_INLINE void sha512_compress(sha512_state *const md,uint8_t *const buf) { uint64_t S[8], W[80], t0, t1; int i; @@ -88,7 +88,7 @@ static ZT_ALWAYS_INLINE void sha512_compress(sha512_state *const md,uint8_t *con md->state[i] = md->state[i] + S[i]; } -static ZT_ALWAYS_INLINE void sha384_init(sha512_state *const md) +static ZT_INLINE void sha384_init(sha512_state *const md) { md->curlen = 0; md->length = 0; @@ -102,7 +102,7 @@ static ZT_ALWAYS_INLINE void sha384_init(sha512_state *const md) md->state[7] = 0x47b5481dbefa4fa4ULL; } -static ZT_ALWAYS_INLINE void sha512_init(sha512_state *const md) +static ZT_INLINE void sha512_init(sha512_state *const md) { md->curlen = 0; md->length = 0; @@ -139,7 +139,7 @@ static void sha512_process(sha512_state *const md,const uint8_t *in,unsigned lon } } -static ZT_ALWAYS_INLINE void sha512_done(sha512_state *const md,uint8_t *out) +static ZT_INLINE void sha512_done(sha512_state *const md,uint8_t *out) { int i; diff --git a/node/SHA512.hpp b/node/SHA512.hpp index 29335e378..dacc9e727 100644 --- a/node/SHA512.hpp +++ b/node/SHA512.hpp @@ -33,21 +33,21 @@ namespace ZeroTier { // SHA384 and SHA512 are actually in the standard libraries on MacOS and iOS #ifdef __APPLE__ #define ZT_HAVE_NATIVE_SHA512 1 -static ZT_ALWAYS_INLINE void SHA512(void *digest,const void *data,unsigned int len) +static ZT_INLINE void SHA512(void *digest,const void *data,unsigned int len) { CC_SHA512_CTX ctx; CC_SHA512_Init(&ctx); CC_SHA512_Update(&ctx,data,len); CC_SHA512_Final(reinterpret_cast(digest),&ctx); } -static ZT_ALWAYS_INLINE void SHA384(void *digest,const void *data,unsigned int len) +static ZT_INLINE void SHA384(void *digest,const void *data,unsigned int len) { CC_SHA512_CTX ctx; CC_SHA384_Init(&ctx); CC_SHA384_Update(&ctx,data,len); CC_SHA384_Final(reinterpret_cast(digest),&ctx); } -static ZT_ALWAYS_INLINE void SHA384(void *digest,const void *data0,unsigned int len0,const void *data1,unsigned int len1) +static ZT_INLINE void SHA384(void *digest,const void *data0,unsigned int len0,const void *data1,unsigned int len1) { CC_SHA512_CTX ctx; CC_SHA384_Init(&ctx); diff --git a/node/Salsa20.hpp b/node/Salsa20.hpp index 780c8db10..cfe7e345d 100644 --- a/node/Salsa20.hpp +++ b/node/Salsa20.hpp @@ -43,14 +43,14 @@ public: static constexpr bool accelerated() noexcept { return false; } #endif - ZT_ALWAYS_INLINE Salsa20() noexcept {} - ZT_ALWAYS_INLINE ~Salsa20() { Utils::burn(&_state,sizeof(_state)); } + ZT_INLINE Salsa20() noexcept {} + ZT_INLINE ~Salsa20() { Utils::burn(&_state,sizeof(_state)); } /** * @param key 256-bit (32 byte) key * @param iv 64-bit initialization vector */ - ZT_ALWAYS_INLINE Salsa20(const void *key,const void *iv) noexcept { init(key,iv); } + ZT_INLINE Salsa20(const void *key,const void *iv) noexcept { init(key,iv); } /** * Initialize cipher diff --git a/node/ScopedPtr.hpp b/node/ScopedPtr.hpp index eee00d0a0..1c18a7efa 100644 --- a/node/ScopedPtr.hpp +++ b/node/ScopedPtr.hpp @@ -28,30 +28,30 @@ template class ScopedPtr : public TriviallyCopyable { public: - explicit ZT_ALWAYS_INLINE ScopedPtr(T *const p) noexcept : _p(p) {} - ZT_ALWAYS_INLINE ~ScopedPtr() { delete _p; } + explicit ZT_INLINE ScopedPtr(T *const p) noexcept : _p(p) {} + ZT_INLINE ~ScopedPtr() { delete _p; } - ZT_ALWAYS_INLINE T *operator->() const noexcept { return _p; } - ZT_ALWAYS_INLINE T &operator*() const noexcept { return *_p; } - explicit ZT_ALWAYS_INLINE operator bool() const noexcept { return (_p != (T *)0); } - ZT_ALWAYS_INLINE T *ptr() const noexcept { return _p; } + ZT_INLINE T *operator->() const noexcept { return _p; } + ZT_INLINE T &operator*() const noexcept { return *_p; } + explicit ZT_INLINE operator bool() const noexcept { return (_p != (T *)0); } + ZT_INLINE T *ptr() const noexcept { return _p; } - ZT_ALWAYS_INLINE void swap(const ScopedPtr &p) noexcept + ZT_INLINE void swap(const ScopedPtr &p) noexcept { T *const tmp = _p; _p = p._p; p._p = tmp; } - ZT_ALWAYS_INLINE bool operator==(const ScopedPtr &p) const noexcept { return (_p == p._p); } - ZT_ALWAYS_INLINE bool operator!=(const ScopedPtr &p) const noexcept { return (_p != p._p); } - ZT_ALWAYS_INLINE bool operator==(T *const p) const noexcept { return (_p == p); } - ZT_ALWAYS_INLINE bool operator!=(T *const p) const noexcept { return (_p != p); } + ZT_INLINE bool operator==(const ScopedPtr &p) const noexcept { return (_p == p._p); } + ZT_INLINE bool operator!=(const ScopedPtr &p) const noexcept { return (_p != p._p); } + ZT_INLINE bool operator==(T *const p) const noexcept { return (_p == p); } + ZT_INLINE bool operator!=(T *const p) const noexcept { return (_p != p); } private: - ZT_ALWAYS_INLINE ScopedPtr() noexcept {} - ZT_ALWAYS_INLINE ScopedPtr(const ScopedPtr &p) noexcept : _p(nullptr) {} - ZT_ALWAYS_INLINE ScopedPtr &operator=(const ScopedPtr &p) noexcept { return *this; } + ZT_INLINE ScopedPtr() noexcept {} + ZT_INLINE ScopedPtr(const ScopedPtr &p) noexcept : _p(nullptr) {} + ZT_INLINE ScopedPtr &operator=(const ScopedPtr &p) noexcept { return *this; } T *const _p; }; @@ -60,7 +60,7 @@ private: namespace std { template -ZT_ALWAYS_INLINE void swap(ZeroTier::ScopedPtr &a,ZeroTier::ScopedPtr &b) noexcept { a.swap(b); } +ZT_INLINE void swap(ZeroTier::ScopedPtr &a,ZeroTier::ScopedPtr &b) noexcept { a.swap(b); } } #endif diff --git a/node/SelfAwareness.cpp b/node/SelfAwareness.cpp index e57d5087d..fa45e8b47 100644 --- a/node/SelfAwareness.cpp +++ b/node/SelfAwareness.cpp @@ -30,13 +30,13 @@ namespace ZeroTier { class _ResetWithinScope { public: - ZT_ALWAYS_INLINE _ResetWithinScope(void *tPtr,int64_t now,int inetAddressFamily,InetAddress::IpScope scope) : + ZT_INLINE _ResetWithinScope(void *tPtr,int64_t now,int inetAddressFamily,InetAddress::IpScope scope) : _now(now), _tPtr(tPtr), _family(inetAddressFamily), _scope(scope) {} - ZT_ALWAYS_INLINE void operator()(const SharedPtr &p) { p->resetWithinScope(_tPtr,_scope,_family,_now); } + ZT_INLINE void operator()(const SharedPtr &p) { p->resetWithinScope(_tPtr,_scope,_family,_now); } private: int64_t _now; diff --git a/node/SelfAwareness.hpp b/node/SelfAwareness.hpp index bc372c766..8f87c96c9 100644 --- a/node/SelfAwareness.hpp +++ b/node/SelfAwareness.hpp @@ -72,13 +72,13 @@ private: InetAddress reporterPhysicalAddress; InetAddress::IpScope scope; - ZT_ALWAYS_INLINE PhySurfaceKey() {} - ZT_ALWAYS_INLINE PhySurfaceKey(const Address &r,const int64_t rol,const InetAddress &ra,InetAddress::IpScope s) : reporter(r),receivedOnLocalSocket(rol),reporterPhysicalAddress(ra),scope(s) {} + ZT_INLINE PhySurfaceKey() {} + ZT_INLINE PhySurfaceKey(const Address &r,const int64_t rol,const InetAddress &ra,InetAddress::IpScope s) : reporter(r),receivedOnLocalSocket(rol),reporterPhysicalAddress(ra),scope(s) {} - ZT_ALWAYS_INLINE unsigned long hashCode() const { return ((unsigned long)reporter.toInt() + (unsigned long)receivedOnLocalSocket + (unsigned long)scope); } + ZT_INLINE unsigned long hashCode() const { return ((unsigned long)reporter.toInt() + (unsigned long)receivedOnLocalSocket + (unsigned long)scope); } - ZT_ALWAYS_INLINE bool operator==(const PhySurfaceKey &k) const { return ((reporter == k.reporter)&&(receivedOnLocalSocket == k.receivedOnLocalSocket)&&(reporterPhysicalAddress == k.reporterPhysicalAddress)&&(scope == k.scope)); } - ZT_ALWAYS_INLINE bool operator!=(const PhySurfaceKey &k) const { return (!(*this == k)); } + ZT_INLINE bool operator==(const PhySurfaceKey &k) const { return ((reporter == k.reporter) && (receivedOnLocalSocket == k.receivedOnLocalSocket) && (reporterPhysicalAddress == k.reporterPhysicalAddress) && (scope == k.scope)); } + ZT_INLINE bool operator!=(const PhySurfaceKey &k) const { return (!(*this == k)); } }; struct PhySurfaceEntry @@ -87,8 +87,8 @@ private: uint64_t ts; bool trusted; - ZT_ALWAYS_INLINE PhySurfaceEntry() : mySurface(),ts(0),trusted(false) {} - ZT_ALWAYS_INLINE PhySurfaceEntry(const InetAddress &a,const uint64_t t) : mySurface(a),ts(t),trusted(false) {} + ZT_INLINE PhySurfaceEntry() : mySurface(),ts(0),trusted(false) {} + ZT_INLINE PhySurfaceEntry(const InetAddress &a,const uint64_t t) : mySurface(a),ts(t),trusted(false) {} }; const RuntimeEnvironment *RR; diff --git a/node/SharedPtr.hpp b/node/SharedPtr.hpp index 19025b56a..15c7d3647 100644 --- a/node/SharedPtr.hpp +++ b/node/SharedPtr.hpp @@ -34,11 +34,11 @@ template class SharedPtr : public TriviallyCopyable { public: - ZT_ALWAYS_INLINE SharedPtr() noexcept : _ptr((T *)0) {} - explicit ZT_ALWAYS_INLINE SharedPtr(T *obj) noexcept : _ptr(obj) { ++obj->__refCount; } - ZT_ALWAYS_INLINE SharedPtr(const SharedPtr &sp) noexcept : _ptr(sp._getAndInc()) {} + ZT_INLINE SharedPtr() noexcept : _ptr((T *)0) {} + explicit ZT_INLINE SharedPtr(T *obj) noexcept : _ptr(obj) { ++obj->__refCount; } + ZT_INLINE SharedPtr(const SharedPtr &sp) noexcept : _ptr(sp._getAndInc()) {} - ZT_ALWAYS_INLINE ~SharedPtr() + ZT_INLINE ~SharedPtr() { if (_ptr) { if (--_ptr->__refCount <= 0) @@ -46,7 +46,7 @@ public: } } - ZT_ALWAYS_INLINE SharedPtr &operator=(const SharedPtr &sp) + ZT_INLINE SharedPtr &operator=(const SharedPtr &sp) { if (_ptr != sp._ptr) { T *p = sp._getAndInc(); @@ -67,7 +67,7 @@ public: * * @param ptr Naked pointer to assign */ - ZT_ALWAYS_INLINE void set(T *ptr) noexcept + ZT_INLINE void set(T *ptr) noexcept { zero(); ++ptr->__refCount; @@ -81,14 +81,14 @@ public: * * @param ptr Pointer to set */ - ZT_ALWAYS_INLINE void unsafeSet(T *ptr) noexcept { _ptr = ptr; } + ZT_INLINE void unsafeSet(T *ptr) noexcept { _ptr = ptr; } /** * Swap with another pointer 'for free' without ref count overhead * * @param with Pointer to swap with */ - ZT_ALWAYS_INLINE void swap(SharedPtr &with) noexcept + ZT_INLINE void swap(SharedPtr &with) noexcept { T *tmp = _ptr; _ptr = with._ptr; @@ -103,7 +103,7 @@ public: * * @param from Origin pointer; will be zeroed */ - ZT_ALWAYS_INLINE void move(SharedPtr &from) + ZT_INLINE void move(SharedPtr &from) { if (_ptr) { if (--_ptr->__refCount <= 0) @@ -113,20 +113,20 @@ public: from._ptr = nullptr; } - ZT_ALWAYS_INLINE operator bool() const noexcept { return (_ptr != nullptr); } + ZT_INLINE operator bool() const noexcept { return (_ptr != nullptr); } - ZT_ALWAYS_INLINE T &operator*() const noexcept { return *_ptr; } - ZT_ALWAYS_INLINE T *operator->() const noexcept { return _ptr; } + ZT_INLINE T &operator*() const noexcept { return *_ptr; } + ZT_INLINE T *operator->() const noexcept { return _ptr; } /** * @return Raw pointer to held object */ - ZT_ALWAYS_INLINE T *ptr() const noexcept { return _ptr; } + ZT_INLINE T *ptr() const noexcept { return _ptr; } /** * Set this pointer to NULL */ - ZT_ALWAYS_INLINE void zero() + ZT_INLINE void zero() { if (_ptr) { if (--_ptr->__refCount <= 0) @@ -138,22 +138,22 @@ public: /** * @return Number of references according to this object's ref count or 0 if NULL */ - ZT_ALWAYS_INLINE int references() noexcept + ZT_INLINE int references() noexcept { if (_ptr) return _ptr->__refCount; return 0; } - ZT_ALWAYS_INLINE bool operator==(const SharedPtr &sp) const noexcept { return (_ptr == sp._ptr); } - ZT_ALWAYS_INLINE bool operator!=(const SharedPtr &sp) const noexcept { return (_ptr != sp._ptr); } - ZT_ALWAYS_INLINE bool operator>(const SharedPtr &sp) const noexcept { return (_ptr > sp._ptr); } - ZT_ALWAYS_INLINE bool operator<(const SharedPtr &sp) const noexcept { return (_ptr < sp._ptr); } - ZT_ALWAYS_INLINE bool operator>=(const SharedPtr &sp) const noexcept { return (_ptr >= sp._ptr); } - ZT_ALWAYS_INLINE bool operator<=(const SharedPtr &sp) const noexcept { return (_ptr <= sp._ptr); } + ZT_INLINE bool operator==(const SharedPtr &sp) const noexcept { return (_ptr == sp._ptr); } + ZT_INLINE bool operator!=(const SharedPtr &sp) const noexcept { return (_ptr != sp._ptr); } + ZT_INLINE bool operator>(const SharedPtr &sp) const noexcept { return (_ptr > sp._ptr); } + ZT_INLINE bool operator<(const SharedPtr &sp) const noexcept { return (_ptr < sp._ptr); } + ZT_INLINE bool operator>=(const SharedPtr &sp) const noexcept { return (_ptr >= sp._ptr); } + ZT_INLINE bool operator<=(const SharedPtr &sp) const noexcept { return (_ptr <= sp._ptr); } private: - ZT_ALWAYS_INLINE T *_getAndInc() const noexcept + ZT_INLINE T *_getAndInc() const noexcept { if (_ptr) ++_ptr->__refCount; @@ -166,7 +166,7 @@ private: namespace std { template -ZT_ALWAYS_INLINE void swap(ZeroTier::SharedPtr &a,ZeroTier::SharedPtr &b) noexcept { a.swap(b); } +ZT_INLINE void swap(ZeroTier::SharedPtr &a,ZeroTier::SharedPtr &b) noexcept { a.swap(b); } } #endif diff --git a/node/Tag.hpp b/node/Tag.hpp index f403ac3a5..e23974b1c 100644 --- a/node/Tag.hpp +++ b/node/Tag.hpp @@ -55,7 +55,7 @@ class Tag : public Credential public: static constexpr ZT_CredentialType credentialType() noexcept { return ZT_CREDENTIAL_TYPE_TAG; } - ZT_ALWAYS_INLINE Tag() noexcept { memoryZero(this); } + ZT_INLINE Tag() noexcept { memoryZero(this); } /** * @param nwid Network ID @@ -64,7 +64,7 @@ public: * @param id Tag ID * @param value Tag value */ - ZT_ALWAYS_INLINE Tag(const uint64_t nwid,const int64_t ts,const Address &issuedTo,const uint32_t id,const uint32_t value) noexcept : + ZT_INLINE Tag(const uint64_t nwid,const int64_t ts,const Address &issuedTo,const uint32_t id,const uint32_t value) noexcept : _id(id), _value(value), _networkId(nwid), @@ -75,14 +75,14 @@ public: { } - ZT_ALWAYS_INLINE uint32_t id() const noexcept { return _id; } - ZT_ALWAYS_INLINE const uint32_t &value() const noexcept { return _value; } - ZT_ALWAYS_INLINE uint64_t networkId() const noexcept { return _networkId; } - ZT_ALWAYS_INLINE int64_t timestamp() const noexcept { return _ts; } - ZT_ALWAYS_INLINE const Address &issuedTo() const noexcept { return _issuedTo; } - ZT_ALWAYS_INLINE const Address &signer() const noexcept { return _signedBy; } - ZT_ALWAYS_INLINE const uint8_t *signature() const noexcept { return _signature; } - ZT_ALWAYS_INLINE unsigned int signatureLength() const noexcept { return _signatureLength; } + ZT_INLINE uint32_t id() const noexcept { return _id; } + ZT_INLINE const uint32_t &value() const noexcept { return _value; } + ZT_INLINE uint64_t networkId() const noexcept { return _networkId; } + ZT_INLINE int64_t timestamp() const noexcept { return _ts; } + ZT_INLINE const Address &issuedTo() const noexcept { return _issuedTo; } + ZT_INLINE const Address &signer() const noexcept { return _signedBy; } + ZT_INLINE const uint8_t *signature() const noexcept { return _signature; } + ZT_INLINE unsigned int signatureLength() const noexcept { return _signatureLength; } /** * Sign this tag @@ -98,30 +98,30 @@ public: * @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 */ - ZT_ALWAYS_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; } int marshal(uint8_t data[ZT_TAG_MARSHAL_SIZE_MAX],bool forSign = false) const noexcept; int unmarshal(const uint8_t *data,int len) noexcept; // Provides natural sort order by ID - ZT_ALWAYS_INLINE bool operator<(const Tag &t) const noexcept { return (_id < t._id); } + ZT_INLINE bool operator<(const Tag &t) const noexcept { return (_id < t._id); } - ZT_ALWAYS_INLINE bool operator==(const Tag &t) const noexcept { return (memcmp(this,&t,sizeof(Tag)) == 0); } - ZT_ALWAYS_INLINE bool operator!=(const Tag &t) const noexcept { return (memcmp(this,&t,sizeof(Tag)) != 0); } + 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 { return (memcmp(this,&t,sizeof(Tag)) != 0); } // For searching sorted arrays or lists of Tags by ID struct IdComparePredicate { - ZT_ALWAYS_INLINE bool operator()(const Tag &a,const Tag &b) const noexcept { return (a.id() < b.id()); } - ZT_ALWAYS_INLINE bool operator()(const uint32_t a,const Tag &b) const noexcept { return (a < b.id()); } - ZT_ALWAYS_INLINE bool operator()(const Tag &a,const uint32_t b) const noexcept { return (a.id() < b); } - ZT_ALWAYS_INLINE bool operator()(const Tag *a,const Tag *b) const noexcept { return (a->id() < b->id()); } - ZT_ALWAYS_INLINE bool operator()(const Tag *a,const Tag &b) const noexcept { return (a->id() < b.id()); } - ZT_ALWAYS_INLINE bool operator()(const Tag &a,const Tag *b) const noexcept { return (a.id() < b->id()); } - ZT_ALWAYS_INLINE bool operator()(const uint32_t a,const Tag *b) const noexcept { return (a < b->id()); } - ZT_ALWAYS_INLINE bool operator()(const Tag *a,const uint32_t b) const noexcept { return (a->id() < b); } - ZT_ALWAYS_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 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 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: diff --git a/node/Tests.cpp b/node/Tests.cpp index 080869a7d..ba08ddf0f 100644 --- a/node/Tests.cpp +++ b/node/Tests.cpp @@ -207,25 +207,25 @@ ZT_PACKED_STRUCT(struct StructPackingTestSample { class LifeCycleTracker { public: - ZT_ALWAYS_INLINE LifeCycleTracker() : + ZT_INLINE LifeCycleTracker() : cnt(nullptr) { } - ZT_ALWAYS_INLINE LifeCycleTracker(const LifeCycleTracker <c) : + ZT_INLINE LifeCycleTracker(const LifeCycleTracker <c) : cnt(ltc.cnt) { if (cnt) ++*cnt; } - explicit ZT_ALWAYS_INLINE LifeCycleTracker(long &c) : + explicit ZT_INLINE LifeCycleTracker(long &c) : cnt(&c) { ++c; } - ZT_ALWAYS_INLINE ~LifeCycleTracker() + ZT_INLINE ~LifeCycleTracker() { if (cnt) --*cnt; } - ZT_ALWAYS_INLINE LifeCycleTracker &operator=(const LifeCycleTracker <c) + ZT_INLINE LifeCycleTracker &operator=(const LifeCycleTracker <c) { if (<c != this) { if (cnt) --*cnt; @@ -642,6 +642,11 @@ extern "C" const char *ZTT_general() ZT_T_PRINTF("OK (cache remaining: %u)" ZT_EOL_S,defrag.cacheSize()); } + { + ZT_T_PRINTF("[general] Testing Endpoint... "); + ZT_T_PRINTF("OK" ZT_EOL_S); + } + { ZT_T_PRINTF("[general] Testing Identity type 0 (C25519)... "); Identity id; diff --git a/node/Topology.cpp b/node/Topology.cpp index e27619e85..d1b6e53d3 100644 --- a/node/Topology.cpp +++ b/node/Topology.cpp @@ -20,8 +20,8 @@ const uint64_t Topology::s_pathHashSalt = Utils::getSecureRandomU64(); // Sorts roots so as to put the lowest latency alive root first. struct _RootSortComparisonOperator { - ZT_ALWAYS_INLINE _RootSortComparisonOperator(const int64_t now) : _now(now) {} - ZT_ALWAYS_INLINE bool operator()(const SharedPtr &a,const SharedPtr &b) + ZT_INLINE _RootSortComparisonOperator(const int64_t now) : _now(now) {} + ZT_INLINE bool operator()(const SharedPtr &a,const SharedPtr &b) { const int64_t now = _now; if (a->active(now)) { diff --git a/node/Topology.hpp b/node/Topology.hpp index e817bf071..d25b1cb38 100644 --- a/node/Topology.hpp +++ b/node/Topology.hpp @@ -64,7 +64,7 @@ public: * @param loadFromCached If false do not load from cache if not in memory (default: true) * @return Peer or NULL if not found */ - ZT_ALWAYS_INLINE SharedPtr peer(void *tPtr,const Address &zta,const bool loadFromCached = true) + ZT_INLINE SharedPtr peer(void *tPtr,const Address &zta,const bool loadFromCached = true) { { RWMutex::RLock l(_peers_l); @@ -94,7 +94,7 @@ public: * @param hash Identity hash * @return Peer or NULL if no peer is currently in memory for this hash (cache is not checked in this case) */ - ZT_ALWAYS_INLINE SharedPtr peerByHash(const Fingerprint &hash) + ZT_INLINE SharedPtr peerByHash(const Fingerprint &hash) { RWMutex::RLock _l(_peers_l); const SharedPtr *const ap = _peersByIdentityHash.get(hash); @@ -109,7 +109,7 @@ public: * @param probe Short probe payload (in big-endian byte order) * @return Peer or NULL if no peer is currently in memory matching this probe (cache is not checked in this case) */ - ZT_ALWAYS_INLINE SharedPtr peerByProbe(const uint64_t probe) + ZT_INLINE SharedPtr peerByProbe(const uint64_t probe) { RWMutex::RLock _l(_peers_l); const SharedPtr *const ap = _peersByIncomingProbe.get(probe); @@ -125,7 +125,7 @@ public: * @param r Remote address * @return Pointer to canonicalized Path object or NULL on error */ - ZT_ALWAYS_INLINE SharedPtr path(const int64_t l,const InetAddress &r) + ZT_INLINE SharedPtr path(const int64_t l,const InetAddress &r) { const uint64_t k = _pathHash(l,r); { @@ -148,7 +148,7 @@ public: /** * @return Current best root server */ - ZT_ALWAYS_INLINE SharedPtr root() const + ZT_INLINE SharedPtr root() const { RWMutex::RLock l(_peers_l); if (_rootPeers.empty()) @@ -160,7 +160,7 @@ public: * @param id Identity to check * @return True if this identity corresponds to a root */ - ZT_ALWAYS_INLINE bool isRoot(const Identity &id) const + ZT_INLINE bool isRoot(const Identity &id) const { RWMutex::RLock l(_peers_l); return (_roots.count(id) > 0); @@ -176,7 +176,7 @@ public: * @tparam F Function or function object type */ template - ZT_ALWAYS_INLINE void eachPeer(F f) const + ZT_INLINE void eachPeer(F f) const { RWMutex::RLock l(_peers_l); Hashtable< Address,SharedPtr >::Iterator i(const_cast(this)->_peers); @@ -196,7 +196,7 @@ public: * @tparam F Function or function object type */ template - ZT_ALWAYS_INLINE void eachPeerWithRoot(F f) const + ZT_INLINE void eachPeerWithRoot(F f) const { RWMutex::RLock l(_peers_l); @@ -222,7 +222,7 @@ public: * @param f */ template - ZT_ALWAYS_INLINE void eachPath(F f) const + ZT_INLINE void eachPath(F f) const { RWMutex::RLock l(_paths_l); Hashtable< uint64_t,SharedPtr >::Iterator i(const_cast(this)->_paths); @@ -246,7 +246,7 @@ public: * @param mtu Variable set to MTU * @param trustedPathId Variable set to trusted path ID */ - ZT_ALWAYS_INLINE void getOutboundPathInfo(const InetAddress &physicalAddress,unsigned int &mtu,uint64_t &trustedPathId) + ZT_INLINE void getOutboundPathInfo(const InetAddress &physicalAddress,unsigned int &mtu,uint64_t &trustedPathId) { for(unsigned int i=0,j=_numConfiguredPhysicalPaths;i(&r)->sin_addr.s_addr)) + (uint64_t)Utils::ntoh(reinterpret_cast(&r)->sin_port) + (uint64_t)l; diff --git a/node/Trace.hpp b/node/Trace.hpp index acc82a3cc..26f635243 100644 --- a/node/Trace.hpp +++ b/node/Trace.hpp @@ -60,15 +60,15 @@ public: { uint8_t l[ZT_MAX_NETWORK_RULES / 2]; // ZT_MAX_NETWORK_RULES 4-bit fields - ZT_ALWAYS_INLINE void log(const unsigned int rn,const uint8_t thisRuleMatches,const uint8_t thisSetMatches) + ZT_INLINE void log(const unsigned int rn,const uint8_t thisRuleMatches,const uint8_t thisSetMatches) { l[rn >> 1U] |= ( ((thisRuleMatches + 1U) << 2U) | (thisSetMatches + 1U) ) << ((rn & 1U) << 2U); } - ZT_ALWAYS_INLINE void logSkipped(const unsigned int rn,const uint8_t thisSetMatches) + ZT_INLINE void logSkipped(const unsigned int rn,const uint8_t thisSetMatches) { l[rn >> 1U] |= (thisSetMatches + 1U) << ((rn & 1U) << 2U); } - ZT_ALWAYS_INLINE void clear() + ZT_INLINE void clear() { memset(l,0,sizeof(l)); } @@ -82,7 +82,7 @@ public: template struct Str { - ZT_ALWAYS_INLINE Str() { memset(s,0,sizeof(s)); } + ZT_INLINE Str() { memset(s,0,sizeof(s)); } constexpr static unsigned int capacity() { return C; } char s[C]; }; @@ -99,7 +99,7 @@ public: const char *message, ...); - ZT_ALWAYS_INLINE void resettingPathsInScope( + ZT_INLINE void resettingPathsInScope( void *const tPtr, const uint32_t codeLocation, const Identity &reporter, @@ -111,7 +111,7 @@ public: if (_vl1) _resettingPathsInScope(tPtr,codeLocation,reporter,from,oldExternal,newExternal,scope); } - ZT_ALWAYS_INLINE void tryingNewPath( + ZT_INLINE void tryingNewPath( void *const tPtr, const uint32_t codeLocation, const Identity &trying, @@ -125,7 +125,7 @@ public: if (_vl1) _tryingNewPath(tPtr,codeLocation,trying,physicalAddress,triggerAddress,triggeringPacketId,triggeringPacketVerb,triggeringPeer,reason); } - ZT_ALWAYS_INLINE void learnedNewPath( + ZT_INLINE void learnedNewPath( void *const tPtr, const uint32_t codeLocation, uint64_t packetId, @@ -136,7 +136,7 @@ public: if (_vl1) _learnedNewPath(tPtr,codeLocation,packetId,peerIdentity,physicalAddress,replaced); } - ZT_ALWAYS_INLINE void incomingPacketDropped( + ZT_INLINE void incomingPacketDropped( void *const tPtr, const uint32_t codeLocation, uint64_t packetId, @@ -150,7 +150,7 @@ public: if (_vl1) _incomingPacketDropped(tPtr,codeLocation,packetId,networkId,peerIdentity,physicalAddress,hops,verb,reason); } - ZT_ALWAYS_INLINE void outgoingNetworkFrameDropped( + ZT_INLINE void outgoingNetworkFrameDropped( void *const tPtr, const uint32_t codeLocation, uint64_t networkId, @@ -164,7 +164,7 @@ public: if (_vl2) _outgoingNetworkFrameDropped(tPtr,codeLocation,networkId,sourceMac,destMac,etherType,frameLength,frameData,reason); } - ZT_ALWAYS_INLINE void incomingNetworkFrameDropped( + ZT_INLINE void incomingNetworkFrameDropped( void *const tPtr, const uint32_t codeLocation, uint64_t networkId, @@ -182,7 +182,7 @@ public: if (_vl2) _incomingNetworkFrameDropped(tPtr,codeLocation,networkId,sourceMac,destMac,peerIdentity,physicalAddress,hops,frameLength,frameData,verb,credentialRequestSent,reason); } - ZT_ALWAYS_INLINE void networkConfigRequestSent( + ZT_INLINE void networkConfigRequestSent( void *const tPtr, const uint32_t codeLocation, uint64_t networkId) @@ -190,7 +190,7 @@ public: if (_vl2) _networkConfigRequestSent(tPtr,codeLocation,networkId); } - ZT_ALWAYS_INLINE void networkFilter( + ZT_INLINE void networkFilter( void *const tPtr, const uint32_t codeLocation, uint64_t networkId, @@ -233,7 +233,7 @@ public: } } - ZT_ALWAYS_INLINE void credentialRejected( + ZT_INLINE void credentialRejected( void *const tPtr, const uint32_t codeLocation, uint64_t networkId, diff --git a/node/TriviallyCopyable.hpp b/node/TriviallyCopyable.hpp index 9525be997..1f074b38e 100644 --- a/node/TriviallyCopyable.hpp +++ b/node/TriviallyCopyable.hpp @@ -36,7 +36,7 @@ ZT_PACKED_STRUCT(struct TriviallyCopyable * @param obj Any TriviallyCopyable object */ template - static ZT_ALWAYS_INLINE void memoryBurn(T *obj) noexcept + static ZT_INLINE void memoryBurn(T *obj) noexcept { TriviallyCopyable *const tmp = obj; Utils::burn(tmp,sizeof(T)); @@ -49,7 +49,7 @@ ZT_PACKED_STRUCT(struct TriviallyCopyable * @param obj Any TriviallyCopyable object */ template - static ZT_ALWAYS_INLINE void memoryBurn(T &obj) noexcept + static ZT_INLINE void memoryBurn(T &obj) noexcept { TriviallyCopyable *const tmp = &obj; Utils::burn(tmp,sizeof(T)); @@ -62,7 +62,7 @@ ZT_PACKED_STRUCT(struct TriviallyCopyable * @param obj Any TriviallyCopyable object */ template - static ZT_ALWAYS_INLINE void memoryZero(T *obj) noexcept + static ZT_INLINE void memoryZero(T *obj) noexcept { TriviallyCopyable *const tmp = obj; memset(tmp,0,sizeof(T)); @@ -75,7 +75,7 @@ ZT_PACKED_STRUCT(struct TriviallyCopyable * @param obj Any TriviallyCopyable object */ template - static ZT_ALWAYS_INLINE void memoryZero(T &obj) noexcept + static ZT_INLINE void memoryZero(T &obj) noexcept { TriviallyCopyable *const tmp = &obj; memset(tmp,0,sizeof(T)); @@ -89,7 +89,7 @@ ZT_PACKED_STRUCT(struct TriviallyCopyable * @param src Source memory of same size or less than sizeof(dest) */ template - static ZT_ALWAYS_INLINE void memoryCopyUnsafe(T *dest,const void *src) noexcept + static ZT_INLINE void memoryCopyUnsafe(T *dest,const void *src) noexcept { TriviallyCopyable *const tmp = dest; memcpy(tmp,src,sizeof(T)); @@ -103,7 +103,7 @@ ZT_PACKED_STRUCT(struct TriviallyCopyable * @param src Source memory of same size or less than sizeof(dest) */ template - static ZT_ALWAYS_INLINE void memoryCopyUnsafe(T &dest,const void *src) noexcept + static ZT_INLINE void memoryCopyUnsafe(T &dest,const void *src) noexcept { TriviallyCopyable *const tmp = &dest; memcpy(tmp,src,sizeof(T)); @@ -117,7 +117,7 @@ ZT_PACKED_STRUCT(struct TriviallyCopyable * @param src Source TriviallyCopyable object */ template - static ZT_ALWAYS_INLINE void memoryCopy(T *dest,const T *src) noexcept + static ZT_INLINE void memoryCopy(T *dest,const T *src) noexcept { TriviallyCopyable *const tmp = dest; memcpy(tmp,src,sizeof(T)); @@ -131,7 +131,7 @@ ZT_PACKED_STRUCT(struct TriviallyCopyable * @param src Source TriviallyCopyable object */ template - static ZT_ALWAYS_INLINE void memoryCopy(T *dest,const T &src) noexcept + static ZT_INLINE void memoryCopy(T *dest,const T &src) noexcept { TriviallyCopyable *const tmp = dest; memcpy(tmp,&src,sizeof(T)); @@ -145,7 +145,7 @@ ZT_PACKED_STRUCT(struct TriviallyCopyable * @param src Source TriviallyCopyable object */ template - static ZT_ALWAYS_INLINE void memoryCopy(T &dest,const T *src) noexcept + static ZT_INLINE void memoryCopy(T &dest,const T *src) noexcept { TriviallyCopyable *const tmp = &dest; memcpy(tmp,src,sizeof(T)); @@ -159,7 +159,7 @@ ZT_PACKED_STRUCT(struct TriviallyCopyable * @param src Source TriviallyCopyable object */ template - static ZT_ALWAYS_INLINE void memoryCopy(T &dest,const T &src) noexcept + static ZT_INLINE void memoryCopy(T &dest,const T &src) noexcept { TriviallyCopyable *const tmp = &dest; memcpy(tmp,&src,sizeof(T)); diff --git a/node/Utils.cpp b/node/Utils.cpp index 5e9ad0988..5d9e76d98 100644 --- a/node/Utils.cpp +++ b/node/Utils.cpp @@ -34,7 +34,7 @@ namespace ZeroTier { namespace Utils { -#if (defined(__amd64) || defined(__amd64__) || defined(__x86_64) || defined(__x86_64__) || defined(__AMD64) || defined(__AMD64__) || defined(_M_X64)) +#ifdef ZT_ARCH_X64 CPUIDRegisters::CPUIDRegisters() { #ifdef __WINDOWS__ @@ -71,22 +71,6 @@ bool secureEq(const void *a,const void *b,unsigned int len) noexcept // Crazy hack to force memory to be securely zeroed in spite of the best efforts of optimizing compilers. static void _Utils_doBurn(volatile uint8_t *ptr,unsigned int len) { -#ifndef ZT_NO_UNALIGNED_ACCESS - const uint64_t z = 0; - while (len >= 32) { - *reinterpret_cast(ptr) = z; - *reinterpret_cast(ptr + 8) = z; - *reinterpret_cast(ptr + 16) = z; - *reinterpret_cast(ptr + 24) = z; - ptr += 32; - len -= 32; - } - while (len >= 8) { - *reinterpret_cast(ptr) = z; - ptr += 8; - len -= 8; - } -#endif for(unsigned int i=0;i -#include +#if __BYTE_ORDER == __LITTLE_ENDIAN +#define ZT_CONST_TO_BE_UINT16(x) ((uint16_t)((uint16_t)((uint16_t)(x) << 8U) | (uint16_t)((uint16_t)(x) >> 8U))) +#else +#define ZT_CONST_TO_BE_UINT16(x) ((uint16_t)(x)) +#endif namespace ZeroTier { @@ -192,14 +195,14 @@ uint64_t random() noexcept; bool scopy(char *dest,unsigned int len,const char *src) noexcept; /** - * Mix bits in a 64-bit integer + * Mix bits in a 64-bit integer (non-cryptographic) * * https://nullprogram.com/blog/2018/07/31/ * * @param x Integer to mix * @return Hashed value */ -static ZT_ALWAYS_INLINE uint64_t hash64(uint64_t x) noexcept +static ZT_INLINE uint64_t hash64(uint64_t x) noexcept { x ^= x >> 30U; x *= 0xbf58476d1ce4e5b9ULL; @@ -210,18 +213,13 @@ static ZT_ALWAYS_INLINE uint64_t hash64(uint64_t x) noexcept } /** - * @param b Buffer to check - * @param l Length of buffer - * @return True if buffer is all zero + * Check if a buffer's contents are all zero */ -static ZT_ALWAYS_INLINE bool allZero(const void *const b,const unsigned int l) noexcept +static ZT_INLINE bool allZero(const void *const b,unsigned int l) noexcept { - const uint8_t *x = reinterpret_cast(b); - const uint8_t *const y = x + l; - while (x != y) { - if (*x != 0) + for(unsigned int i=0;i(b)[i] != 0) return false; - ++x; } return true; } @@ -234,7 +232,7 @@ static ZT_ALWAYS_INLINE bool allZero(const void *const b,const unsigned int l) n * @param saveptr Pointer to pointer where function can save state * @return Next token or NULL if none */ -static ZT_ALWAYS_INLINE char *stok(char *str,const char *delim,char **saveptr) noexcept +static ZT_INLINE char *stok(char *str,const char *delim,char **saveptr) noexcept { #ifdef __WINDOWS__ return strtok_s(str,delim,saveptr); @@ -243,12 +241,12 @@ static ZT_ALWAYS_INLINE char *stok(char *str,const char *delim,char **saveptr) n #endif } -static ZT_ALWAYS_INLINE unsigned int strToUInt(const char *s) noexcept +static ZT_INLINE unsigned int strToUInt(const char *s) noexcept { return (unsigned int)strtoul(s,nullptr,10); } -static ZT_ALWAYS_INLINE unsigned long long hexStrToU64(const char *s) noexcept +static ZT_INLINE unsigned long long hexStrToU64(const char *s) noexcept { #ifdef __WINDOWS__ return (unsigned long long)_strtoui64(s,nullptr,16); @@ -266,7 +264,7 @@ static ZT_ALWAYS_INLINE unsigned long long hexStrToU64(const char *s) noexcept * @param len Length of data * @return FNV1a checksum */ -static ZT_ALWAYS_INLINE uint32_t fnv1a32(const void *const data,const unsigned int len) noexcept +static ZT_INLINE uint32_t fnv1a32(const void *const data,const unsigned int len) noexcept { uint32_t h = 0x811c9dc5; const uint32_t p = 0x01000193; @@ -276,13 +274,13 @@ static ZT_ALWAYS_INLINE uint32_t fnv1a32(const void *const data,const unsigned i } #ifdef __GNUC__ -static ZT_ALWAYS_INLINE unsigned int countBits(const uint8_t v) noexcept { return (unsigned int)__builtin_popcount((unsigned int)v); } -static ZT_ALWAYS_INLINE unsigned int countBits(const uint16_t v) noexcept { return (unsigned int)__builtin_popcount((unsigned int)v); } -static ZT_ALWAYS_INLINE unsigned int countBits(const uint32_t v) noexcept { return (unsigned int)__builtin_popcountl((unsigned long)v); } -static ZT_ALWAYS_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 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 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 template -static ZT_ALWAYS_INLINE unsigned int countBits(T v) noexcept +static ZT_INLINE unsigned int countBits(T v) noexcept { v = v - ((v >> 1) & (T)~(T)0/3); v = (v & (T)~(T)0/15*3) + ((v >> 2) & (T)~(T)0/15*3); @@ -297,7 +295,7 @@ static ZT_ALWAYS_INLINE unsigned int countBits(T v) noexcept * @param n Integer to swap * @return Integer with bytes reversed */ -static ZT_ALWAYS_INLINE uint64_t swapBytes(const uint64_t n) noexcept +static ZT_INLINE uint64_t swapBytes(const uint64_t n) noexcept { #ifdef __GNUC__ return __builtin_bswap64(n); @@ -325,9 +323,9 @@ static ZT_ALWAYS_INLINE uint64_t swapBytes(const uint64_t n) noexcept * @param n Integer to swap * @return Integer with bytes reversed */ -static ZT_ALWAYS_INLINE uint32_t swapBytes(const uint32_t n) noexcept +static ZT_INLINE uint32_t swapBytes(const uint32_t n) noexcept { -#if defined(__GCC__) +#if defined(__GNUC__) return __builtin_bswap32(n); #else #ifdef _MSC_VER @@ -344,9 +342,9 @@ static ZT_ALWAYS_INLINE uint32_t swapBytes(const uint32_t n) noexcept * @param n Integer to swap * @return Integer with bytes reversed */ -static ZT_ALWAYS_INLINE uint16_t swapBytes(const uint16_t n) noexcept +static ZT_INLINE uint16_t swapBytes(const uint16_t n) noexcept { -#if defined(__GCC__) +#if defined(__GNUC__) return __builtin_bswap16(n); #else #ifdef _MSC_VER @@ -362,33 +360,33 @@ static ZT_ALWAYS_INLINE uint16_t swapBytes(const uint16_t n) noexcept template class _swap_bytes_bysize; template -class _swap_bytes_bysize { public: static ZT_ALWAYS_INLINE I s(const I n) noexcept { return n; } }; +class _swap_bytes_bysize { public: static ZT_INLINE I s(const I n) noexcept { return n; } }; template -class _swap_bytes_bysize { public: static ZT_ALWAYS_INLINE I s(const I n) noexcept { return (I)swapBytes((uint16_t)n); } }; +class _swap_bytes_bysize { public: static ZT_INLINE I s(const I n) noexcept { return (I)swapBytes((uint16_t)n); } }; template -class _swap_bytes_bysize { public: static ZT_ALWAYS_INLINE I s(const I n) noexcept { return (I)swapBytes((uint32_t)n); } }; +class _swap_bytes_bysize { public: static ZT_INLINE I s(const I n) noexcept { return (I)swapBytes((uint32_t)n); } }; template -class _swap_bytes_bysize { public: static ZT_ALWAYS_INLINE I s(const I n) noexcept { return (I)swapBytes((uint64_t)n); } }; +class _swap_bytes_bysize { public: static ZT_INLINE I s(const I n) noexcept { return (I)swapBytes((uint64_t)n); } }; template class _load_be_bysize; template -class _load_be_bysize { public: static ZT_ALWAYS_INLINE I l(const uint8_t *const p) noexcept { return p[0]; }}; +class _load_be_bysize { public: static ZT_INLINE I l(const uint8_t *const p) noexcept { return p[0]; }}; template -class _load_be_bysize { public: static ZT_ALWAYS_INLINE I l(const uint8_t *const p) noexcept { return (I)(((unsigned int)p[0] << 8U) | (unsigned int)p[1]); }}; +class _load_be_bysize { public: static ZT_INLINE I l(const uint8_t *const p) noexcept { return (I)(((unsigned int)p[0] << 8U) | (unsigned int)p[1]); }}; template -class _load_be_bysize { public: static ZT_ALWAYS_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 { 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 -class _load_be_bysize { public: static ZT_ALWAYS_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 { 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 class _load_le_bysize; template -class _load_le_bysize { public: static ZT_ALWAYS_INLINE I l(const uint8_t *const p) noexcept { return p[0]; }}; +class _load_le_bysize { public: static ZT_INLINE I l(const uint8_t *const p) noexcept { return p[0]; }}; template -class _load_le_bysize { public: static ZT_ALWAYS_INLINE I l(const uint8_t *const p) noexcept { return (I)((unsigned int)p[0] | ((unsigned int)p[1] << 8U)); }}; +class _load_le_bysize { public: static ZT_INLINE I l(const uint8_t *const p) noexcept { return (I)((unsigned int)p[0] | ((unsigned int)p[1] << 8U)); }}; template -class _load_le_bysize { public: static ZT_ALWAYS_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 { 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 -class _load_le_bysize { public: static ZT_ALWAYS_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 { 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 @@ -398,7 +396,7 @@ class _load_le_bysize { public: static ZT_ALWAYS_INLINE I l(const uint8_t * * @return Value in big-endian order */ template -static ZT_ALWAYS_INLINE I hton(const I n) noexcept +static ZT_INLINE I hton(const I n) noexcept { #if __BYTE_ORDER == __LITTLE_ENDIAN return _swap_bytes_bysize::s(n); @@ -415,7 +413,7 @@ static ZT_ALWAYS_INLINE I hton(const I n) noexcept * @return Value in host byte order */ template -static ZT_ALWAYS_INLINE I ntoh(const I n) noexcept +static ZT_INLINE I ntoh(const I n) noexcept { #if __BYTE_ORDER == __LITTLE_ENDIAN return _swap_bytes_bysize::s(n); @@ -432,7 +430,7 @@ static ZT_ALWAYS_INLINE I ntoh(const I n) noexcept * @return Loaded raw integer */ template -static ZT_ALWAYS_INLINE I loadAsIsEndian(const void *const p) noexcept +static ZT_INLINE I loadAsIsEndian(const void *const p) noexcept { #ifdef ZT_NO_UNALIGNED_ACCESS #if __BYTE_ORDER == __LITTLE_ENDIAN @@ -453,7 +451,7 @@ static ZT_ALWAYS_INLINE I loadAsIsEndian(const void *const p) noexcept * @param i Integer to store */ template -static ZT_ALWAYS_INLINE void storeAsIsEndian(void *const p,const I i) noexcept +static ZT_INLINE void storeAsIsEndian(void *const p,const I i) noexcept { #ifdef ZT_NO_UNALIGNED_ACCESS for(unsigned int k=0;k -static ZT_ALWAYS_INLINE I loadBigEndian(const void *const p) noexcept +static ZT_INLINE I loadBigEndian(const void *const p) noexcept { #ifdef ZT_NO_UNALIGNED_ACCESS return _load_be_bysize::l(reinterpret_cast(p)); @@ -488,7 +486,7 @@ static ZT_ALWAYS_INLINE I loadBigEndian(const void *const p) noexcept * #param i Integer to write */ template -static ZT_ALWAYS_INLINE void storeBigEndian(void *const p,I i) noexcept +static ZT_INLINE void storeBigEndian(void *const p,I i) noexcept { #ifdef ZT_NO_UNALIGNED_ACCESS storeAsIsEndian(p,hton(i)); @@ -505,7 +503,7 @@ static ZT_ALWAYS_INLINE void storeBigEndian(void *const p,I i) noexcept * @return Decoded integer */ template -static ZT_ALWAYS_INLINE I loadLittleEndian(const void *const p) noexcept +static ZT_INLINE I loadLittleEndian(const void *const p) noexcept { #if __BYTE_ORDER == __BIG_ENDIAN || defined(ZT_NO_UNALIGNED_ACCESS) return _load_le_bysize::l(reinterpret_cast(p)); @@ -522,7 +520,7 @@ static ZT_ALWAYS_INLINE I loadLittleEndian(const void *const p) noexcept * #param i Integer to write */ template -static ZT_ALWAYS_INLINE void storeLittleEndian(void *const p,const I i) noexcept +static ZT_INLINE void storeLittleEndian(void *const p,const I i) noexcept { #if __BYTE_ORDER == __BIG_ENDIAN || defined(ZT_NO_UNALIGNED_ACCESS) storeAsIsEndian(p,_swap_bytes_bysize::s(i)); diff --git a/node/VL1.cpp b/node/VL1.cpp index 89dfdb308..7bd744b50 100644 --- a/node/VL1.cpp +++ b/node/VL1.cpp @@ -30,7 +30,7 @@ namespace ZeroTier { namespace { -ZT_ALWAYS_INLINE const Identity &identityFromPeerPtr(const SharedPtr &p) +ZT_INLINE const Identity &identityFromPeerPtr(const SharedPtr &p) { if (p) return p->identity(); diff --git a/node/VL1.hpp b/node/VL1.hpp index bc6ab4349..1f61543ec 100644 --- a/node/VL1.hpp +++ b/node/VL1.hpp @@ -81,7 +81,7 @@ private: struct _WhoisQueueItem { - ZT_ALWAYS_INLINE _WhoisQueueItem() : lastRetry(0),inboundPackets(),retries(0) {} + ZT_INLINE _WhoisQueueItem() : lastRetry(0),inboundPackets(),retries(0) {} int64_t lastRetry; FCV inboundPackets; // capacity can be changed but this should be plenty unsigned int retries; diff --git a/osdep/BlockingQueue.hpp b/osdep/BlockingQueue.hpp index 67e37b777..213ab14d3 100644 --- a/osdep/BlockingQueue.hpp +++ b/osdep/BlockingQueue.hpp @@ -40,16 +40,16 @@ public: STOP }; - ZT_ALWAYS_INLINE BlockingQueue(void) : r(true) {} + ZT_INLINE BlockingQueue(void) : r(true) {} - ZT_ALWAYS_INLINE void post(T t) + ZT_INLINE void post(T t) { std::lock_guard lock(m); q.push(t); c.notify_one(); } - ZT_ALWAYS_INLINE void postLimit(T t,const unsigned long limit) + ZT_INLINE void postLimit(T t,const unsigned long limit) { std::unique_lock lock(m); for(;;) { @@ -64,7 +64,7 @@ public: } } - ZT_ALWAYS_INLINE void stop(void) + ZT_INLINE void stop(void) { std::lock_guard lock(m); r = false; @@ -72,7 +72,7 @@ public: gc.notify_all(); } - ZT_ALWAYS_INLINE bool get(T &value) + ZT_INLINE bool get(T &value) { std::unique_lock lock(m); if (!r) return false; @@ -89,7 +89,7 @@ public: return true; } - ZT_ALWAYS_INLINE TimedWaitResult get(T &value,const unsigned long ms) + ZT_INLINE TimedWaitResult get(T &value,const unsigned long ms) { const std::chrono::milliseconds ms2{ms}; std::unique_lock lock(m); diff --git a/osdep/EthernetTap.hpp b/osdep/EthernetTap.hpp index 23f97f495..e7e6d6b08 100644 --- a/osdep/EthernetTap.hpp +++ b/osdep/EthernetTap.hpp @@ -58,7 +58,7 @@ public: virtual void scanMulticastGroups(std::vector &added,std::vector &removed) = 0; virtual void setMtu(unsigned int mtu) = 0; - ZT_ALWAYS_INLINE int addRoute(const InetAddress &target,const InetAddress &via,const unsigned int metric) + ZT_INLINE int addRoute(const InetAddress &target,const InetAddress &via,const unsigned int metric) { const std::string dn(this->routingDeviceName()); const char *const dnp = (dn.length() > 0) ? dn.c_str() : (const char *)0; @@ -67,14 +67,14 @@ public: return 0; } - ZT_ALWAYS_INLINE int removeRoute(const InetAddress &target,const InetAddress &via,const unsigned int metric) + ZT_INLINE int removeRoute(const InetAddress &target,const InetAddress &via,const unsigned int metric) { std::lock_guard l(_managedRoutes_l); _managedRoutes.erase(std::pair(target,metric)); return 0; } - ZT_ALWAYS_INLINE int syncRoutes() + ZT_INLINE int syncRoutes() { std::lock_guard l(_managedRoutes_l); for(auto r=_managedRoutes.begin();r!=_managedRoutes.end();++r) { diff --git a/osdep/ManagedRoute.hpp b/osdep/ManagedRoute.hpp index 287485677..6ef50e159 100644 --- a/osdep/ManagedRoute.hpp +++ b/osdep/ManagedRoute.hpp @@ -35,7 +35,7 @@ class ManagedRoute friend class SharedPtr; public: - ZT_ALWAYS_INLINE ManagedRoute(const InetAddress &target,const InetAddress &via,const char *device) + ZT_INLINE ManagedRoute(const InetAddress &target,const InetAddress &via,const char *device) { _target = target; _via = via; @@ -47,7 +47,7 @@ public: _systemDevice[0] = (char)0; } - ZT_ALWAYS_INLINE ~ManagedRoute() { this->remove(); } + ZT_INLINE ~ManagedRoute() { this->remove(); } /** * Set or update currently set route @@ -68,13 +68,13 @@ public: */ void remove(); - ZT_ALWAYS_INLINE const InetAddress &target() const { return _target; } - ZT_ALWAYS_INLINE const InetAddress &via() const { return _via; } - ZT_ALWAYS_INLINE const char *device() const { return _device; } + ZT_INLINE const InetAddress &target() const { return _target; } + ZT_INLINE const InetAddress &via() const { return _via; } + ZT_INLINE const char *device() const { return _device; } private: - ZT_ALWAYS_INLINE ManagedRoute(const ManagedRoute &) {} - ZT_ALWAYS_INLINE ManagedRoute &operator=(const ManagedRoute &) { return *this; } + ZT_INLINE ManagedRoute(const ManagedRoute &) {} + ZT_INLINE ManagedRoute &operator=(const ManagedRoute &) { return *this; } InetAddress _target; InetAddress _via; diff --git a/osdep/OSUtils.hpp b/osdep/OSUtils.hpp index cd1cb2107..48ea69520 100644 --- a/osdep/OSUtils.hpp +++ b/osdep/OSUtils.hpp @@ -78,7 +78,7 @@ public: * @param path Path to delete * @return True if delete was successful */ - static ZT_ALWAYS_INLINE bool rm(const char *path) + static ZT_INLINE bool rm(const char *path) { #ifdef __WINDOWS__ return (DeleteFileA(path) != FALSE); @@ -86,9 +86,9 @@ public: return (unlink(path) == 0); #endif } - static ZT_ALWAYS_INLINE bool rm(const std::string &path) { return rm(path.c_str()); } + static ZT_INLINE bool rm(const std::string &path) { return rm(path.c_str()); } - static ZT_ALWAYS_INLINE bool mkdir(const char *path) + static ZT_INLINE bool mkdir(const char *path) { #ifdef __WINDOWS__ if (::PathIsDirectoryA(path)) @@ -100,9 +100,9 @@ public: return true; #endif } - static ZT_ALWAYS_INLINE bool mkdir(const std::string &path) { return OSUtils::mkdir(path.c_str()); } + static ZT_INLINE bool mkdir(const std::string &path) { return OSUtils::mkdir(path.c_str()); } - static ZT_ALWAYS_INLINE bool rename(const char *o,const char *n) + static ZT_INLINE bool rename(const char *o,const char *n) { #ifdef __WINDOWS__ DeleteFileA(n); @@ -150,7 +150,7 @@ public: /** * @return Current time in milliseconds since epoch */ - static ZT_ALWAYS_INLINE int64_t now() + static ZT_INLINE int64_t now() { #ifdef __WINDOWS__ FILETIME ft; @@ -212,7 +212,7 @@ public: * @param s Data to write * @return True if entire file was successfully written */ - static ZT_ALWAYS_INLINE bool writeFile(const char *path,const std::string &s) { return writeFile(path,s.data(),(unsigned int)s.length()); } + static ZT_INLINE bool writeFile(const char *path,const std::string &s) { return writeFile(path,s.data(),(unsigned int)s.length()); } /** * @return Platform default ZeroTier One home path diff --git a/root/root.cpp b/root/root.cpp index 1aec8d53d..c9a94297d 100644 --- a/root/root.cpp +++ b/root/root.cpp @@ -127,8 +127,8 @@ using json = nlohmann::json; */ struct RootPeer { - ZT_ALWAYS_INLINE RootPeer() : lastSend(0),lastReceive(0),lastEcho(0),lastHello(0),vProto(-1),vMajor(-1),vMinor(-1),vRev(-1) {} - ZT_ALWAYS_INLINE ~RootPeer() { Utils::burn(key,sizeof(key)); } + ZT_INLINE RootPeer() : lastSend(0),lastReceive(0),lastEcho(0),lastHello(0),vProto(-1),vMajor(-1),vMinor(-1),vRev(-1) {} + ZT_INLINE ~RootPeer() { Utils::burn(key,sizeof(key)); } Identity id; // Identity uint8_t key[32]; // Shared secret key @@ -144,10 +144,10 @@ struct RootPeer }; // Hashers for std::unordered_map -struct IdentityHasher { ZT_ALWAYS_INLINE std::size_t operator()(const Identity &id) const { return (std::size_t)id.hashCode(); } }; -struct AddressHasher { ZT_ALWAYS_INLINE std::size_t operator()(const Address &a) const { return (std::size_t)a.toInt(); } }; -struct InetAddressHasher { ZT_ALWAYS_INLINE std::size_t operator()(const InetAddress &ip) const { return (std::size_t)ip.hashCode(); } }; -struct MulticastGroupHasher { ZT_ALWAYS_INLINE std::size_t operator()(const MulticastGroup &mg) const { return (std::size_t)mg.hashCode(); } }; +struct IdentityHasher { ZT_INLINE std::size_t operator()(const Identity &id) const { return (std::size_t)id.hashCode(); } }; +struct AddressHasher { ZT_INLINE std::size_t operator()(const Address &a) const { return (std::size_t)a.toInt(); } }; +struct InetAddressHasher { ZT_INLINE std::size_t operator()(const InetAddress &ip) const { return (std::size_t)ip.hashCode(); } }; +struct MulticastGroupHasher { ZT_INLINE std::size_t operator()(const MulticastGroup &mg) const { return (std::size_t)mg.hashCode(); } }; // An ordered tuple key representing an introduction of one peer to another struct RendezvousKey @@ -163,9 +163,9 @@ struct RendezvousKey } } Address a,b; - ZT_ALWAYS_INLINE bool operator==(const RendezvousKey &k) const { return ((a == k.a)&&(b == k.b)); } - ZT_ALWAYS_INLINE bool operator!=(const RendezvousKey &k) const { return ((a != k.a)||(b != k.b)); } - struct Hasher { ZT_ALWAYS_INLINE std::size_t operator()(const RendezvousKey &k) const { return (std::size_t)(k.a.toInt() ^ k.b.toInt()); } }; + ZT_INLINE bool operator==(const RendezvousKey &k) const { return ((a == k.a) && (b == k.b)); } + ZT_INLINE bool operator!=(const RendezvousKey &k) const { return ((a != k.a) || (b != k.b)); } + struct Hasher { ZT_INLINE std::size_t operator()(const RendezvousKey &k) const { return (std::size_t)(k.a.toInt() ^ k.b.toInt()); } }; }; struct RendezvousStats @@ -215,13 +215,13 @@ static std::mutex s_rendezvousTracking_l; ////////////////////////////////////////////////////////////////////////////// // Construct GeoIP key for IPv4 IPs -static ZT_ALWAYS_INLINE uint32_t ip4ToH32(const InetAddress &ip) +static ZT_INLINE uint32_t ip4ToH32(const InetAddress &ip) { return Utils::ntoh((uint32_t)(((const struct sockaddr_in *)&ip)->sin_addr.s_addr)); } // Construct GeoIP key for IPv6 IPs -static ZT_ALWAYS_INLINE std::array< uint64_t,2 > ip6ToH128(const InetAddress &ip) +static ZT_INLINE std::array< uint64_t,2 > ip6ToH128(const InetAddress &ip) { std::array i128; memcpy(i128.data(),ip.rawIpData(),16);