mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 20:43:44 +02:00
Stub out a protocol field in Endpoint INETADDR types for future use.
This commit is contained in:
parent
0598315d68
commit
8e4d7c56d8
2 changed files with 36 additions and 13 deletions
|
@ -25,7 +25,7 @@ bool Endpoint::operator==(const Endpoint &ep) const
|
||||||
case TYPE_URL: return (strcmp(_v.url,ep._v.url) == 0);
|
case TYPE_URL: return (strcmp(_v.url,ep._v.url) == 0);
|
||||||
case TYPE_ETHERNET: return (_v.eth == ep._v.eth);
|
case TYPE_ETHERNET: return (_v.eth == ep._v.eth);
|
||||||
case TYPE_INETADDR_V4:
|
case TYPE_INETADDR_V4:
|
||||||
case TYPE_INETADDR_V6: return (inetAddr() == ep.inetAddr());
|
case TYPE_INETADDR_V6: return ((asInetAddress(_v.in.sa) == asInetAddress(ep._v.in.sa))&&(_v.in.proto == ep._v.in.proto));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -45,7 +45,7 @@ bool Endpoint::operator<(const Endpoint &ep) const
|
||||||
case TYPE_URL: return (strcmp(_v.url,ep._v.url) < 0);
|
case TYPE_URL: return (strcmp(_v.url,ep._v.url) < 0);
|
||||||
case TYPE_ETHERNET: return (_v.eth < ep._v.eth);
|
case TYPE_ETHERNET: return (_v.eth < ep._v.eth);
|
||||||
case TYPE_INETADDR_V4:
|
case TYPE_INETADDR_V4:
|
||||||
case TYPE_INETADDR_V6: return (inetAddr() < ep.inetAddr());
|
case TYPE_INETADDR_V6: return ((_v.in.proto < ep._v.in.proto)||((_v.in.proto == ep._v.in.proto)&&(asInetAddress(_v.in.sa) < asInetAddress(ep._v.in.sa))));
|
||||||
default: return false;
|
default: return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,10 +100,11 @@ int Endpoint::marshal(uint8_t data[ZT_ENDPOINT_MARSHAL_SIZE_MAX]) const noexcept
|
||||||
return 13;
|
return 13;
|
||||||
case TYPE_INETADDR_V4:
|
case TYPE_INETADDR_V4:
|
||||||
case TYPE_INETADDR_V6:
|
case TYPE_INETADDR_V6:
|
||||||
p = asInetAddress(_v.sa).marshal(data + 7);
|
p = 7 + asInetAddress(_v.in.sa).marshal(data + 7);
|
||||||
if (p < 0)
|
if (p <= 7)
|
||||||
return p;
|
return -1;
|
||||||
return 7 + p;
|
data[p++] = _v.in.proto;
|
||||||
|
return p;
|
||||||
default:
|
default:
|
||||||
data[0] = (uint8_t)TYPE_NIL;
|
data[0] = (uint8_t)TYPE_NIL;
|
||||||
return 7;
|
return 7;
|
||||||
|
@ -174,10 +175,11 @@ int Endpoint::unmarshal(const uint8_t *restrict data,const int len) noexcept
|
||||||
return 13;
|
return 13;
|
||||||
case TYPE_INETADDR_V4:
|
case TYPE_INETADDR_V4:
|
||||||
case TYPE_INETADDR_V6:
|
case TYPE_INETADDR_V6:
|
||||||
p = asInetAddress(_v.sa).unmarshal(data + 7,len - 7);
|
p = 7 + asInetAddress(_v.in.sa).unmarshal(data + 7,len - 7);
|
||||||
if (p <= 0)
|
if ((p <= 7)||(p >= len))
|
||||||
return -1;
|
return -1;
|
||||||
return 7 + p;
|
_v.in.proto = data[p++];
|
||||||
|
return p;
|
||||||
default:
|
default:
|
||||||
// Unrecognized endpoint types not yet specified must start with a 16-bit
|
// Unrecognized endpoint types not yet specified must start with a 16-bit
|
||||||
// length so that older versions of ZeroTier can skip them.
|
// length so that older versions of ZeroTier can skip them.
|
||||||
|
|
|
@ -55,9 +55,21 @@ public:
|
||||||
TYPE_INETADDR_V6 = ZT_TRACE_EVENT_PATH_TYPE_INETADDR_V6
|
TYPE_INETADDR_V6 = ZT_TRACE_EVENT_PATH_TYPE_INETADDR_V6
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Protocol identifiers for INETADDR endpoint types
|
||||||
|
*
|
||||||
|
* Most of these are reserved for future use.
|
||||||
|
*/
|
||||||
|
enum Protocol
|
||||||
|
{
|
||||||
|
PROTO_UDP_ZT = 0,
|
||||||
|
PROTO_TCP_ZT = 1,
|
||||||
|
PROTO_IP_ZT = 2
|
||||||
|
};
|
||||||
|
|
||||||
ZT_ALWAYS_INLINE Endpoint() noexcept { memoryZero(this); }
|
ZT_ALWAYS_INLINE Endpoint() noexcept { memoryZero(this); }
|
||||||
|
|
||||||
explicit ZT_ALWAYS_INLINE Endpoint(const InetAddress &sa)
|
explicit ZT_ALWAYS_INLINE Endpoint(const InetAddress &sa,const Protocol proto = PROTO_UDP_ZT)
|
||||||
{
|
{
|
||||||
switch (sa.family()) {
|
switch (sa.family()) {
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
|
@ -69,7 +81,8 @@ public:
|
||||||
_t = TYPE_NIL;
|
_t = TYPE_NIL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
asInetAddress(_v.sa) = sa;
|
asInetAddress(_v.in.sa) = sa;
|
||||||
|
_v.in.proto = (uint8_t)proto;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZT_ALWAYS_INLINE Endpoint(const Address &zt,const uint8_t identityHash[ZT_IDENTITY_HASH_SIZE]) :
|
ZT_ALWAYS_INLINE Endpoint(const Address &zt,const uint8_t identityHash[ZT_IDENTITY_HASH_SIZE]) :
|
||||||
|
@ -95,7 +108,12 @@ public:
|
||||||
/**
|
/**
|
||||||
* @return InetAddress or NIL if not of this type
|
* @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.sa) : InetAddress::NIL; }
|
ZT_ALWAYS_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; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return DNS name or empty string if not of this type
|
* @return DNS name or empty string if not of this type
|
||||||
|
@ -149,7 +167,10 @@ private:
|
||||||
Type _t;
|
Type _t;
|
||||||
int _l[3]; // X,Y,Z location in kilometers from the nearest gravitational center of mass
|
int _l[3]; // X,Y,Z location in kilometers from the nearest gravitational center of mass
|
||||||
union {
|
union {
|
||||||
struct sockaddr_storage sa;
|
struct {
|
||||||
|
sockaddr_storage sa;
|
||||||
|
uint8_t proto;
|
||||||
|
} in;
|
||||||
struct {
|
struct {
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
char name[ZT_ENDPOINT_MAX_NAME_SIZE];
|
char name[ZT_ENDPOINT_MAX_NAME_SIZE];
|
||||||
|
|
Loading…
Add table
Reference in a new issue