mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-05 03:53:44 +02:00
Ready to test whole new netconf refactor.
This commit is contained in:
parent
7ee3743c3d
commit
548730660b
5 changed files with 83 additions and 49 deletions
|
@ -681,12 +681,18 @@ bool IncomingPacket::_doNETWORK_CONFIG_REQUEST(const RuntimeEnvironment *RR,cons
|
||||||
const unsigned int metaDataLength = at<uint16_t>(ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_DICT_LEN);
|
const unsigned int metaDataLength = at<uint16_t>(ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_DICT_LEN);
|
||||||
const uint8_t *metaDataBytes = (const uint8_t *)field(ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_DICT,metaDataLength);
|
const uint8_t *metaDataBytes = (const uint8_t *)field(ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_DICT,metaDataLength);
|
||||||
|
|
||||||
NetworkConfigRequestMetaData metaData(false);
|
NetworkConfigRequestMetaData metaData;
|
||||||
try {
|
bool haveNewStyleMetaData = false;
|
||||||
Buffer<8194> md(metaDataBytes,metaDataLength);
|
for(unsigned int i=0;i<metaDataLength;++i) {
|
||||||
metaData.deserialize(md,0);
|
if ((metaDataBytes[i] == 0)&&(i < (metaDataLength - 2))) {
|
||||||
} catch ( ... ) { // will throw if new-style meta-data is missing or invalid
|
haveNewStyleMetaData = true;
|
||||||
metaData.clear();
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (haveNewStyleMetaData) {
|
||||||
|
Buffer<4096> md(metaDataBytes,metaDataLength);
|
||||||
|
metaData.deserialize(md,0); // the meta-data deserializer automatically skips old-style meta-data
|
||||||
|
} else {
|
||||||
#ifdef ZT_SUPPORT_OLD_STYLE_NETCONF
|
#ifdef ZT_SUPPORT_OLD_STYLE_NETCONF
|
||||||
const Dictionary oldStyleMetaData((const char *)metaDataBytes,metaDataLength);
|
const Dictionary oldStyleMetaData((const char *)metaDataBytes,metaDataLength);
|
||||||
metaData.majorVersion = (unsigned int)oldStyleMetaData.getHexUInt(ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_NODE_MAJOR_VERSION,0);
|
metaData.majorVersion = (unsigned int)oldStyleMetaData.getHexUInt(ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_NODE_MAJOR_VERSION,0);
|
||||||
|
|
|
@ -256,20 +256,16 @@ void Network::requestConfiguration()
|
||||||
|
|
||||||
TRACE("requesting netconf for network %.16llx from controller %s",(unsigned long long)_id,controller().toString().c_str());
|
TRACE("requesting netconf for network %.16llx from controller %s",(unsigned long long)_id,controller().toString().c_str());
|
||||||
|
|
||||||
// TODO: in the future we will include things like join tokens here, etc.
|
NetworkConfigRequestMetaData metaData;
|
||||||
Dictionary metaData;
|
metaData.initWithDefaults();
|
||||||
metaData.setHex(ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_NODE_MAJOR_VERSION,ZEROTIER_ONE_VERSION_MAJOR);
|
Buffer<4096> mds;
|
||||||
metaData.setHex(ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_NODE_MINOR_VERSION,ZEROTIER_ONE_VERSION_MINOR);
|
metaData.serialize(mds); // this always includes legacy fields to support old controllers
|
||||||
metaData.setHex(ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_NODE_REVISION,ZEROTIER_ONE_VERSION_REVISION);
|
|
||||||
std::string mds(metaData.toString());
|
|
||||||
|
|
||||||
Packet outp(controller(),RR->identity.address(),Packet::VERB_NETWORK_CONFIG_REQUEST);
|
Packet outp(controller(),RR->identity.address(),Packet::VERB_NETWORK_CONFIG_REQUEST);
|
||||||
outp.append((uint64_t)_id);
|
outp.append((uint64_t)_id);
|
||||||
outp.append((uint16_t)mds.length());
|
outp.append((uint16_t)mds.size());
|
||||||
outp.append((const void *)mds.data(),(unsigned int)mds.length());
|
outp.append(mds.data(),mds.size());
|
||||||
if (_config)
|
outp.append((_config) ? (uint64_t)_config.revision : (uint64_t)0);
|
||||||
outp.append((uint64_t)_config.revision);
|
|
||||||
else outp.append((uint64_t)0);
|
|
||||||
RR->sw->send(outp,true,0);
|
RR->sw->send(outp,true,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -460,6 +460,11 @@ public:
|
||||||
b.append((uint16_t)rules[i].v.frameSize[0]);
|
b.append((uint16_t)rules[i].v.frameSize[0]);
|
||||||
b.append((uint16_t)rules[i].v.frameSize[1]);
|
b.append((uint16_t)rules[i].v.frameSize[1]);
|
||||||
break;
|
break;
|
||||||
|
case ZT_NETWORK_RULE_MATCH_TCP_RELATIVE_SEQUENCE_NUMBER_RANGE:
|
||||||
|
b.append((uint8_t)8);
|
||||||
|
b.append((uint32_t)rules[i].v.tcpseq[0]);
|
||||||
|
b.append((uint32_t)rules[i].v.tcpseq[1]);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -585,6 +590,10 @@ public:
|
||||||
rules[i].v.frameSize[0] = b.template at<uint16_t>(p);
|
rules[i].v.frameSize[0] = b.template at<uint16_t>(p);
|
||||||
rules[i].v.frameSize[1] = b.template at<uint16_t>(p+2);
|
rules[i].v.frameSize[1] = b.template at<uint16_t>(p+2);
|
||||||
break;
|
break;
|
||||||
|
case ZT_NETWORK_RULE_MATCH_TCP_RELATIVE_SEQUENCE_NUMBER_RANGE:
|
||||||
|
rules[i].v.tcpseq[0] = b.template at<uint32_t>(p);
|
||||||
|
rules[i].v.tcpseq[1] = b.template at<uint32_t>(p + 4);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
p += rlen;
|
p += rlen;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,9 +26,17 @@
|
||||||
#include "Constants.hpp"
|
#include "Constants.hpp"
|
||||||
#include "NetworkConfig.hpp"
|
#include "NetworkConfig.hpp"
|
||||||
#include "Buffer.hpp"
|
#include "Buffer.hpp"
|
||||||
|
#include "Packet.hpp"
|
||||||
|
|
||||||
#include "../version.h"
|
#include "../version.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum length of the auth field (including terminating NULL, since it's a C-style string)
|
||||||
|
*
|
||||||
|
* Actual max length not including NULL is this minus one.
|
||||||
|
*/
|
||||||
|
#define ZT_NETWORK_CONFIG_REQUEST_METADATA_MAX_AUTH_LENGTH 2048
|
||||||
|
|
||||||
namespace ZeroTier {
|
namespace ZeroTier {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,20 +45,33 @@ namespace ZeroTier {
|
||||||
class NetworkConfigRequestMetaData
|
class NetworkConfigRequestMetaData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NetworkConfigRequestMetaData() :
|
/**
|
||||||
buildId(0),
|
* Construct an empty meta-data object with zero/null values
|
||||||
flags(0),
|
*/
|
||||||
vendor(ZT_VENDOR_ZEROTIER),
|
NetworkConfigRequestMetaData()
|
||||||
platform(ZT_PLATFORM_UNSPECIFIED),
|
|
||||||
architecture(ZT_ARCHITECTURE_UNSPECIFIED),
|
|
||||||
majorVersion(ZEROTIER_ONE_VERSION_MAJOR),
|
|
||||||
minorVersion(ZEROTIER_ONE_VERSION_MINOR),
|
|
||||||
revision(ZEROTIER_ONE_VERSION_REVISION)
|
|
||||||
{
|
{
|
||||||
memset(auth,0,sizeof(auth));
|
memset(this,0,sizeof(NetworkConfigRequestMetaData));
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkConfigRequestMetaData(bool foo)
|
/**
|
||||||
|
* Initialize with defaults from this node's config and version
|
||||||
|
*/
|
||||||
|
inline void initWithDefaults()
|
||||||
|
{
|
||||||
|
memset(this,0,sizeof(NetworkConfigRequestMetaData));
|
||||||
|
vendor = ZT_VENDOR_ZEROTIER;
|
||||||
|
platform = ZT_PLATFORM_UNSPECIFIED;
|
||||||
|
architecture = ZT_ARCHITECTURE_UNSPECIFIED;
|
||||||
|
majorVersion = ZEROTIER_ONE_VERSION_MAJOR;
|
||||||
|
minorVersion = ZEROTIER_ONE_VERSION_MINOR;
|
||||||
|
revision = ZEROTIER_ONE_VERSION_REVISION;
|
||||||
|
protocolVersion = ZT_PROTO_VERSION;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zero/null everything
|
||||||
|
*/
|
||||||
|
inline void clear()
|
||||||
{
|
{
|
||||||
memset(this,0,sizeof(NetworkConfigRequestMetaData));
|
memset(this,0,sizeof(NetworkConfigRequestMetaData));
|
||||||
}
|
}
|
||||||
|
@ -58,13 +79,15 @@ public:
|
||||||
template<unsigned int C>
|
template<unsigned int C>
|
||||||
inline void serialize(Buffer<C> &b) const
|
inline void serialize(Buffer<C> &b) const
|
||||||
{
|
{
|
||||||
// Unlike network config we always send the old fields. Newer network
|
/* Unlike network config we always send the old fields. Newer network
|
||||||
// controllers will detect the presence of the new serialized data by
|
* controllers will detect the presence of the new serialized data by
|
||||||
// detecting extra data after the terminating NULL. But always sending
|
* detecting extra data after the terminating NULL. But always sending
|
||||||
// these maintains backward compatibility with old controllers.
|
* these maintains backward compatibility with old controllers. This
|
||||||
b.appendCString("majv="ZEROTIER_ONE_VERSION_MAJOR_S"\nminv="ZEROTIER_ONE_VERSION_MINOR_S"\nrevv="ZEROTIER_ONE_VERSION_REVISION_S"\n");
|
* appends a terminating NULL which seperates the old legacy meta-data
|
||||||
|
* from the new packed binary format that we send after. */
|
||||||
|
b.appendCString("majv="ZEROTIER_ONE_VERSION_MAJOR_S_HEX"\nminv="ZEROTIER_ONE_VERSION_MINOR_S_HEX"\nrevv="ZEROTIER_ONE_VERSION_REVISION_S_HEX"\n");
|
||||||
|
|
||||||
b.append((uint16_t)1); // version
|
b.append((uint16_t)1); // serialization version
|
||||||
|
|
||||||
b.append((uint64_t)buildId);
|
b.append((uint64_t)buildId);
|
||||||
b.append((uint64_t)flags);
|
b.append((uint64_t)flags);
|
||||||
|
@ -74,10 +97,10 @@ public:
|
||||||
b.append((uint16_t)majorVersion);
|
b.append((uint16_t)majorVersion);
|
||||||
b.append((uint16_t)minorVersion);
|
b.append((uint16_t)minorVersion);
|
||||||
b.append((uint16_t)revision);
|
b.append((uint16_t)revision);
|
||||||
|
b.append((uint16_t)protocolVersion);
|
||||||
|
|
||||||
unsigned int tl = (unsigned int)strlen(auth);
|
const unsigned int tl = strlen(auth);
|
||||||
if (tl > 255) tl = 255; // sanity check
|
b.append((uint16_t)tl);
|
||||||
b.append((uint8_t)tl);
|
|
||||||
b.append((const void *)auth,tl);
|
b.append((const void *)auth,tl);
|
||||||
|
|
||||||
b.append((uint16_t)0); // extended bytes, currently 0 since unused
|
b.append((uint16_t)0); // extended bytes, currently 0 since unused
|
||||||
|
@ -105,10 +128,10 @@ public:
|
||||||
majorVersion = b.template at<uint16_t>(p); p += 2;
|
majorVersion = b.template at<uint16_t>(p); p += 2;
|
||||||
minorVersion = b.template at<uint16_t>(p); p += 2;
|
minorVersion = b.template at<uint16_t>(p); p += 2;
|
||||||
revision = b.template at<uint16_t>(p); p += 2;
|
revision = b.template at<uint16_t>(p); p += 2;
|
||||||
|
protocolVersion = b.template at<uint16_t>(p); p += 2;
|
||||||
|
|
||||||
unsigned int tl = (unsigned int)b[p++];
|
const unsigned int tl = b.template at<uint16_t>(p); p += 2;
|
||||||
memcpy(auth,b.field(p,tl),std::max(tl,(unsigned int)ZT_MAX_NETWORK_SHORT_NAME_LENGTH));
|
memcpy(auth,b.field(p,tl),std::max(tl,(unsigned int)(ZT_NETWORK_CONFIG_REQUEST_METADATA_MAX_AUTH_LENGTH - 1)));
|
||||||
// auth[] is ZT_MAX_NETWORK_SHORT_NAME_LENGTH + 1 and so will always end up null-terminated since we zeroed the structure
|
|
||||||
p += tl;
|
p += tl;
|
||||||
|
|
||||||
p += b.template at<uint16_t>(p) + 2;
|
p += b.template at<uint16_t>(p) + 2;
|
||||||
|
@ -116,10 +139,10 @@ public:
|
||||||
return (p - startAt);
|
return (p - startAt);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void clear()
|
/**
|
||||||
{
|
* Authentication data (e.g. bearer=<token>) as a C-style string (always null terminated)
|
||||||
memset(this,0,sizeof(NetworkConfigRequestMetaData));
|
*/
|
||||||
}
|
char auth[ZT_NETWORK_CONFIG_REQUEST_METADATA_MAX_AUTH_LENGTH];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build ID (currently unused, must be 0)
|
* Build ID (currently unused, must be 0)
|
||||||
|
@ -162,9 +185,9 @@ public:
|
||||||
unsigned int revision;
|
unsigned int revision;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Authentication data (e.g. bearer=<token>)
|
* ZeroTier protocol version
|
||||||
*/
|
*/
|
||||||
char auth[ZT_MAX_NETWORK_SHORT_NAME_LENGTH + 1];
|
unsigned int protocolVersion;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ZeroTier
|
} // namespace ZeroTier
|
||||||
|
|
|
@ -23,18 +23,18 @@
|
||||||
* Major version
|
* Major version
|
||||||
*/
|
*/
|
||||||
#define ZEROTIER_ONE_VERSION_MAJOR 1
|
#define ZEROTIER_ONE_VERSION_MAJOR 1
|
||||||
#define ZEROTIER_ONE_VERSION_MAJOR_S "1"
|
#define ZEROTIER_ONE_VERSION_MAJOR_S_HEX "1"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Minor version
|
* Minor version
|
||||||
*/
|
*/
|
||||||
#define ZEROTIER_ONE_VERSION_MINOR 1
|
#define ZEROTIER_ONE_VERSION_MINOR 1
|
||||||
#define ZEROTIER_ONE_VERSION_MINOR_S "1"
|
#define ZEROTIER_ONE_VERSION_MINOR_S_HEX "1"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Revision
|
* Revision
|
||||||
*/
|
*/
|
||||||
#define ZEROTIER_ONE_VERSION_REVISION 5
|
#define ZEROTIER_ONE_VERSION_REVISION 5
|
||||||
#define ZEROTIER_ONE_VERSION_REVISION_S "5"
|
#define ZEROTIER_ONE_VERSION_REVISION_S_HEX "5"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue