mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-04-09 04:04:13 +00:00
Simplify a bunch of NetworkConfig stuff by eliminating accessors, also makes network controller easier to refactor.
This commit is contained in:
parent
529515d1d1
commit
8b9519f0af
@ -353,7 +353,7 @@ SqliteNetworkController::~SqliteNetworkController()
|
||||
}
|
||||
}
|
||||
|
||||
NetworkController::ResultCode SqliteNetworkController::doNetworkConfigRequest(const InetAddress &fromAddr,const Identity &signingId,const Identity &identity,uint64_t nwid,const Dictionary &metaData,Dictionary &netconf)
|
||||
NetworkController::ResultCode SqliteNetworkController::doNetworkConfigRequest(const InetAddress &fromAddr,const Identity &signingId,const Identity &identity,uint64_t nwid,const NetworkConfigRequestMetaData &metaData,Buffer<8194> &netconf)
|
||||
{
|
||||
Mutex::Lock _l(_lock);
|
||||
return _doNetworkConfigRequest(fromAddr,signingId,identity,nwid,metaData,netconf);
|
||||
@ -1647,25 +1647,24 @@ unsigned int SqliteNetworkController::_doCPGet(
|
||||
return 404;
|
||||
}
|
||||
|
||||
NetworkController::ResultCode SqliteNetworkController::_doNetworkConfigRequest(const InetAddress &fromAddr,const Identity &signingId,const Identity &identity,uint64_t nwid,const Dictionary &metaData,Dictionary &netconf)
|
||||
NetworkController::ResultCode SqliteNetworkController::_doNetworkConfigRequest(const InetAddress &fromAddr,const Identity &signingId,const Identity &identity,uint64_t nwid,const NetworkConfigRequestMetaData &metaData,Buffer<8194> &netconf)
|
||||
{
|
||||
// Assumes _lock is locked
|
||||
|
||||
// Decode some stuff from metaData
|
||||
const unsigned int clientMajorVersion = (unsigned int)metaData.getHexUInt(ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_NODE_MAJOR_VERSION,0);
|
||||
const unsigned int clientMinorVersion = (unsigned int)metaData.getHexUInt(ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_NODE_MINOR_VERSION,0);
|
||||
const unsigned int clientRevision = (unsigned int)metaData.getHexUInt(ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_NODE_REVISION,0);
|
||||
const bool clientIs104 = (Utils::compareVersion(clientMajorVersion,clientMinorVersion,clientRevision,1,0,4) >= 0);
|
||||
const bool clientIs104 = (Utils::compareVersion(metaData.majorVersion,metaData.minorVersion,metaData.revision,1,0,4) >= 0);
|
||||
|
||||
// Note: we can't reuse prepared statements that return const char * pointers without
|
||||
// making our own copy in e.g. a std::string first.
|
||||
|
||||
Dictionary legacy;
|
||||
NetworkConfig nc;
|
||||
|
||||
if ((!signingId)||(!signingId.hasPrivate())) {
|
||||
netconf["error"] = "signing identity invalid or lacks private key";
|
||||
//netconf["error"] = "signing identity invalid or lacks private key";
|
||||
return NetworkController::NETCONF_QUERY_INTERNAL_SERVER_ERROR;
|
||||
}
|
||||
if (signingId.address().toInt() != (nwid >> 24)) {
|
||||
netconf["error"] = "signing identity address does not match most significant 40 bits of network ID";
|
||||
//netconf["error"] = "signing identity address does not match most significant 40 bits of network ID";
|
||||
return NetworkController::NETCONF_QUERY_INTERNAL_SERVER_ERROR;
|
||||
}
|
||||
|
||||
|
@ -62,8 +62,8 @@ public:
|
||||
const Identity &signingId,
|
||||
const Identity &identity,
|
||||
uint64_t nwid,
|
||||
const Dictionary &metaData,
|
||||
Dictionary &netconf);
|
||||
const NetworkConfigRequestMetaData &metaData,
|
||||
Buffer<8194> &netconf);
|
||||
|
||||
unsigned int handleControlPlaneHttpGET(
|
||||
const std::vector<std::string> &path,
|
||||
@ -111,8 +111,8 @@ private:
|
||||
const Identity &signingId,
|
||||
const Identity &identity,
|
||||
uint64_t nwid,
|
||||
const Dictionary &metaData,
|
||||
Dictionary &netconf);
|
||||
const NetworkConfigRequestMetaData &metaData,
|
||||
Buffer<8194> &netconf);
|
||||
|
||||
static void _circuitTestCallback(ZT_Node *node,ZT_CircuitTest *test,const ZT_CircuitTestReport *report);
|
||||
|
||||
|
@ -99,7 +99,7 @@ extern "C" {
|
||||
/**
|
||||
* Maximum number of static physical to ZeroTier address mappings (typically relays, etc.)
|
||||
*/
|
||||
#define ZT_MAX_NETWORK_STATIC_PHYSICAL_ADDRESSES 16
|
||||
#define ZT_MAX_NETWORK_PINNED 16
|
||||
|
||||
/**
|
||||
* Maximum number of rule table entries per network (can be increased)
|
||||
|
@ -146,13 +146,11 @@ bool IncomingPacket::_doERROR(const RuntimeEnvironment *RR,const SharedPtr<Peer>
|
||||
* who asks. We won't communicate unless we also get a certificate
|
||||
* from the remote that agrees. */
|
||||
SharedPtr<Network> network(RR->node->network(at<uint64_t>(ZT_PROTO_VERB_ERROR_IDX_PAYLOAD)));
|
||||
if (network) {
|
||||
if ((network->hasConfig())&&(network->config().com())) {
|
||||
Packet outp(peer->address(),RR->identity.address(),Packet::VERB_NETWORK_MEMBERSHIP_CERTIFICATE);
|
||||
network->config().com().serialize(outp);
|
||||
outp.armor(peer->key(),true);
|
||||
RR->node->putPacket(_localAddress,_remoteAddress,outp.data(),outp.size());
|
||||
}
|
||||
if ((network)&&(network->hasConfig())&&(network->config().com)) {
|
||||
Packet outp(peer->address(),RR->identity.address(),Packet::VERB_NETWORK_MEMBERSHIP_CERTIFICATE);
|
||||
network->config().com.serialize(outp);
|
||||
outp.armor(peer->key(),true);
|
||||
RR->node->putPacket(_localAddress,_remoteAddress,outp.data(),outp.size());
|
||||
}
|
||||
} break;
|
||||
|
||||
@ -679,8 +677,24 @@ bool IncomingPacket::_doNETWORK_CONFIG_REQUEST(const RuntimeEnvironment *RR,cons
|
||||
{
|
||||
try {
|
||||
const uint64_t nwid = at<uint64_t>(ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_NETWORK_ID);
|
||||
|
||||
const unsigned int metaDataLength = at<uint16_t>(ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_DICT_LEN);
|
||||
const Dictionary metaData((const char *)field(ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_DICT,metaDataLength),metaDataLength);
|
||||
const uint8_t *metaDataBytes = (const uint8_t *)field(ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_DICT,metaDataLength);
|
||||
|
||||
NetworkConfigRequestMetaData metaData(false);
|
||||
try {
|
||||
Buffer<8194> md(metaDataBytes,metaDataLength);
|
||||
metaData.deserialize(md,0);
|
||||
} catch ( ... ) { // will throw if new-style meta-data is missing or invalid
|
||||
metaData.clear();
|
||||
#ifdef ZT_SUPPORT_OLD_STYLE_NETCONF
|
||||
const Dictionary oldStyleMetaData((const char *)metaDataBytes,metaDataLength);
|
||||
metaData.majorVersion = (unsigned int)oldStyleMetaData.getHexUInt(ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_NODE_MAJOR_VERSION,0);
|
||||
metaData.minorVersion = (unsigned int)oldStyleMetaData.getHexUInt(ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_NODE_MINOR_VERSION,0);
|
||||
metaData.revision = (unsigned int)oldStyleMetaData.getHexUInt(ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_NODE_REVISION,0);
|
||||
#endif
|
||||
}
|
||||
|
||||
//const uint64_t haveRevision = ((ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_DICT + metaDataLength + 8) <= size()) ? at<uint64_t>(ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_DICT + metaDataLength) : 0ULL;
|
||||
|
||||
const unsigned int h = hops();
|
||||
@ -688,27 +702,22 @@ bool IncomingPacket::_doNETWORK_CONFIG_REQUEST(const RuntimeEnvironment *RR,cons
|
||||
peer->received(_localAddress,_remoteAddress,h,pid,Packet::VERB_NETWORK_CONFIG_REQUEST,0,Packet::VERB_NOP);
|
||||
|
||||
if (RR->localNetworkController) {
|
||||
Dictionary netconf;
|
||||
Buffer<8194> netconf;
|
||||
switch(RR->localNetworkController->doNetworkConfigRequest((h > 0) ? InetAddress() : _remoteAddress,RR->identity,peer->identity(),nwid,metaData,netconf)) {
|
||||
|
||||
case NetworkController::NETCONF_QUERY_OK: {
|
||||
const std::string netconfStr(netconf.toString());
|
||||
if (netconfStr.length() > 0xffff) { // sanity check since field ix 16-bit
|
||||
Packet outp(peer->address(),RR->identity.address(),Packet::VERB_OK);
|
||||
outp.append((unsigned char)Packet::VERB_NETWORK_CONFIG_REQUEST);
|
||||
outp.append(pid);
|
||||
outp.append(nwid);
|
||||
outp.append((uint16_t)netconf.size());
|
||||
outp.append(netconf.data(),(unsigned int)netconf.size());
|
||||
outp.compress();
|
||||
outp.armor(peer->key(),true);
|
||||
if (outp.size() > ZT_PROTO_MAX_PACKET_LENGTH) { // sanity check
|
||||
TRACE("NETWORK_CONFIG_REQUEST failed: internal error: netconf size %u is too large",(unsigned int)netconfStr.length());
|
||||
} else {
|
||||
Packet outp(peer->address(),RR->identity.address(),Packet::VERB_OK);
|
||||
outp.append((unsigned char)Packet::VERB_NETWORK_CONFIG_REQUEST);
|
||||
outp.append(pid);
|
||||
outp.append(nwid);
|
||||
outp.append((uint16_t)netconfStr.length());
|
||||
outp.append(netconfStr.data(),(unsigned int)netconfStr.length());
|
||||
outp.compress();
|
||||
outp.armor(peer->key(),true);
|
||||
if (outp.size() > ZT_PROTO_MAX_PACKET_LENGTH) { // sanity check
|
||||
TRACE("NETWORK_CONFIG_REQUEST failed: internal error: netconf size %u is too large",(unsigned int)netconfStr.length());
|
||||
} else {
|
||||
RR->node->putPacket(_localAddress,_remoteAddress,outp.data(),outp.size());
|
||||
}
|
||||
RR->node->putPacket(_localAddress,_remoteAddress,outp.data(),outp.size());
|
||||
}
|
||||
} break;
|
||||
|
||||
@ -1047,7 +1056,7 @@ bool IncomingPacket::_doCIRCUIT_TEST(const RuntimeEnvironment *RR,const SharedPt
|
||||
SharedPtr<Network> nw(RR->node->network(originatorCredentialNetworkId));
|
||||
if ((nw)&&(nw->hasConfig())) {
|
||||
originatorCredentialNetworkConfig = nw->config();
|
||||
if ( ( (originatorCredentialNetworkConfig.isPublic()) || (peer->address() == originatorAddress) || ((originatorCredentialNetworkConfig.com())&&(previousHopCom)&&(originatorCredentialNetworkConfig.com().agreesWith(previousHopCom))) ) ) {
|
||||
if ( ( (originatorCredentialNetworkConfig.isPublic()) || (peer->address() == originatorAddress) || ((originatorCredentialNetworkConfig.com)&&(previousHopCom)&&(originatorCredentialNetworkConfig.com.agreesWith(previousHopCom))) ) ) {
|
||||
TRACE("CIRCUIT_TEST %.16llx received from hop %s(%s) and originator %s with valid network ID credential %.16llx (verified from originator and next hop)",testId,source().toString().c_str(),_remoteAddress.toString().c_str(),originatorAddress.toString().c_str(),originatorCredentialNetworkId);
|
||||
} else {
|
||||
TRACE("dropped CIRCUIT_TEST from %s(%s): originator %s specified network ID %.16llx as credential, and previous hop %s did not supply a valid COM",source().toString().c_str(),_remoteAddress.toString().c_str(),originatorAddress.toString().c_str(),originatorCredentialNetworkId,peer->address().toString().c_str());
|
||||
@ -1122,9 +1131,9 @@ bool IncomingPacket::_doCIRCUIT_TEST(const RuntimeEnvironment *RR,const SharedPt
|
||||
outp.append(field(ZT_PACKET_IDX_PAYLOAD,lengthOfSignedPortionAndSignature),lengthOfSignedPortionAndSignature);
|
||||
const unsigned int previousHopCredentialPos = outp.size();
|
||||
outp.append((uint16_t)0); // no previous hop credentials: default
|
||||
if ((originatorCredentialNetworkConfig)&&(!originatorCredentialNetworkConfig.isPublic())&&(originatorCredentialNetworkConfig.com())) {
|
||||
if ((originatorCredentialNetworkConfig)&&(!originatorCredentialNetworkConfig.isPublic())&&(originatorCredentialNetworkConfig.com)) {
|
||||
outp.append((uint8_t)0x01); // COM
|
||||
originatorCredentialNetworkConfig.com().serialize(outp);
|
||||
originatorCredentialNetworkConfig.com.serialize(outp);
|
||||
outp.setAt<uint16_t>(previousHopCredentialPos,(uint16_t)(outp.size() - (previousHopCredentialPos + 2)));
|
||||
}
|
||||
if (remainingHopsPtr < size())
|
||||
|
@ -238,8 +238,8 @@ void Multicaster::send(
|
||||
const CertificateOfMembership *com = (CertificateOfMembership *)0;
|
||||
{
|
||||
SharedPtr<Network> nw(RR->node->network(nwid));
|
||||
if ((nw)&&(nw->hasConfig())&&(nw->config().com())&&(nw->config().isPrivate())&&(p->needsOurNetworkMembershipCertificate(nwid,now,true)))
|
||||
com = &(nw->config().com());
|
||||
if ((nw)&&(nw->hasConfig())&&(nw->config().com)&&(nw->config().isPrivate())&&(p->needsOurNetworkMembershipCertificate(nwid,now,true)))
|
||||
com = &(nw->config().com);
|
||||
}
|
||||
|
||||
Packet outp(p->address(),RR->identity.address(),Packet::VERB_MULTICAST_GATHER);
|
||||
|
@ -153,7 +153,7 @@ bool Network::applyConfiguration(const NetworkConfig &conf)
|
||||
if (_destroyed) // sanity check
|
||||
return false;
|
||||
try {
|
||||
if ((conf.networkId() == _id)&&(conf.issuedTo() == RR->identity.address())) {
|
||||
if ((conf.networkId == _id)&&(conf.issuedTo == RR->identity.address())) {
|
||||
ZT_VirtualNetworkConfig ctmp;
|
||||
bool portInitialized;
|
||||
{
|
||||
@ -234,12 +234,11 @@ void Network::requestConfiguration()
|
||||
|
||||
if (controller() == RR->identity.address()) {
|
||||
if (RR->localNetworkController) {
|
||||
Dictionary newconf;
|
||||
switch(RR->localNetworkController->doNetworkConfigRequest(InetAddress(),RR->identity,RR->identity,_id,Dictionary(),newconf)) {
|
||||
case NetworkController::NETCONF_QUERY_OK: {
|
||||
std::string tmp(newconf.toString());
|
||||
this->setConfiguration((const void *)tmp.data(),(unsigned int)tmp.length(),true);
|
||||
} return;
|
||||
Buffer<8194> tmp;
|
||||
switch(RR->localNetworkController->doNetworkConfigRequest(InetAddress(),RR->identity,RR->identity,_id,NetworkConfigRequestMetaData(),tmp)) {
|
||||
case NetworkController::NETCONF_QUERY_OK:
|
||||
this->setConfiguration(tmp.data(),tmp.size(),true);
|
||||
return;
|
||||
case NetworkController::NETCONF_QUERY_OBJECT_NOT_FOUND:
|
||||
this->setNotFound();
|
||||
return;
|
||||
@ -269,7 +268,7 @@ void Network::requestConfiguration()
|
||||
outp.append((uint16_t)mds.length());
|
||||
outp.append((const void *)mds.data(),(unsigned int)mds.length());
|
||||
if (_config)
|
||||
outp.append((uint64_t)_config.revision());
|
||||
outp.append((uint64_t)_config.revision);
|
||||
else outp.append((uint64_t)0);
|
||||
RR->sw->send(outp,true,0);
|
||||
}
|
||||
@ -380,7 +379,7 @@ void Network::_externalConfig(ZT_VirtualNetworkConfig *ec) const
|
||||
ec->nwid = _id;
|
||||
ec->mac = _mac.toInt();
|
||||
if (_config)
|
||||
Utils::scopy(ec->name,sizeof(ec->name),_config.name());
|
||||
Utils::scopy(ec->name,sizeof(ec->name),_config.name);
|
||||
else ec->name[0] = (char)0;
|
||||
ec->status = _status();
|
||||
ec->type = (_config) ? (_config.isPrivate() ? ZT_NETWORK_TYPE_PRIVATE : ZT_NETWORK_TYPE_PUBLIC) : ZT_NETWORK_TYPE_PRIVATE;
|
||||
@ -391,7 +390,7 @@ void Network::_externalConfig(ZT_VirtualNetworkConfig *ec) const
|
||||
ec->broadcastEnabled = (_config) ? (_config.enableBroadcast() ? 1 : 0) : 0;
|
||||
ec->portError = _portError;
|
||||
ec->enabled = (_enabled) ? 1 : 0;
|
||||
ec->netconfRevision = (_config) ? (unsigned long)_config.revision() : 0;
|
||||
ec->netconfRevision = (_config) ? (unsigned long)_config.revision : 0;
|
||||
|
||||
ec->multicastSubscriptionCount = std::min((unsigned int)_myMulticastGroups.size(),(unsigned int)ZT_MAX_NETWORK_MULTICAST_SUBSCRIPTIONS);
|
||||
for(unsigned int i=0;i<ec->multicastSubscriptionCount;++i) {
|
||||
@ -399,13 +398,14 @@ void Network::_externalConfig(ZT_VirtualNetworkConfig *ec) const
|
||||
ec->multicastSubscriptions[i].adi = _myMulticastGroups[i].adi();
|
||||
}
|
||||
|
||||
std::vector<InetAddress> sips(_config.staticIps());
|
||||
ec->assignedAddressCount = 0;
|
||||
for(unsigned long i=0;i<ZT_MAX_ZT_ASSIGNED_ADDRESSES;++i) {
|
||||
if (i < sips.size()) {
|
||||
memcpy(&(ec->assignedAddresses[i]),&(sips[i]),sizeof(struct sockaddr_storage));
|
||||
for(unsigned int i=0;i<ZT_MAX_ZT_ASSIGNED_ADDRESSES;++i) {
|
||||
if (i < _config.staticIpCount) {
|
||||
memcpy(&(ec->assignedAddresses[i]),&(_config.staticIps[i]),sizeof(struct sockaddr_storage));
|
||||
++ec->assignedAddressCount;
|
||||
} else memset(&(ec->assignedAddresses[i]),0,sizeof(struct sockaddr_storage));
|
||||
} else {
|
||||
memset(&(ec->assignedAddresses[i]),0,sizeof(struct sockaddr_storage));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -417,7 +417,7 @@ bool Network::_isAllowed(const SharedPtr<Peer> &peer) const
|
||||
return false;
|
||||
if (_config.isPublic())
|
||||
return true;
|
||||
return ((_config.com())&&(peer->networkMembershipCertificatesAgree(_id,_config.com())));
|
||||
return ((_config.com)&&(peer->networkMembershipCertificatesAgree(_id,_config.com)));
|
||||
} catch (std::exception &exc) {
|
||||
TRACE("isAllowed() check failed for peer %s: unexpected exception: %s",peer->address().toString().c_str(),exc.what());
|
||||
} catch ( ... ) {
|
||||
@ -469,9 +469,9 @@ void Network::_announceMulticastGroupsTo(const SharedPtr<Peer> &peer,const std::
|
||||
|
||||
// We push COMs ahead of MULTICAST_LIKE since they're used for access control -- a COM is a public
|
||||
// credential so "over-sharing" isn't really an issue (and we only do so with roots).
|
||||
if ((_config)&&(_config.com())&&(!_config.isPublic())&&(peer->needsOurNetworkMembershipCertificate(_id,RR->node->now(),true))) {
|
||||
if ((_config)&&(_config.com)&&(!_config.isPublic())&&(peer->needsOurNetworkMembershipCertificate(_id,RR->node->now(),true))) {
|
||||
Packet outp(peer->address(),RR->identity.address(),Packet::VERB_NETWORK_MEMBERSHIP_CERTIFICATE);
|
||||
_config.com().serialize(outp);
|
||||
_config.com.serialize(outp);
|
||||
RR->sw->send(outp,true,0);
|
||||
}
|
||||
|
||||
|
@ -36,25 +36,25 @@ void NetworkConfig::fromDictionary(const char *ds,unsigned int dslen)
|
||||
|
||||
// NOTE: d.get(name) throws if not found, d.get(name,default) returns default
|
||||
|
||||
_nwid = Utils::hexStrToU64(d.get(ZT_NETWORKCONFIG_DICT_KEY_NETWORK_ID,"0").c_str());
|
||||
if (!_nwid)
|
||||
networkId = Utils::hexStrToU64(d.get(ZT_NETWORKCONFIG_DICT_KEY_NETWORK_ID,"0").c_str());
|
||||
if (!networkId)
|
||||
throw std::invalid_argument("configuration contains zero network ID");
|
||||
|
||||
_timestamp = Utils::hexStrToU64(d.get(ZT_NETWORKCONFIG_DICT_KEY_TIMESTAMP,"0").c_str());
|
||||
_revision = Utils::hexStrToU64(d.get(ZT_NETWORKCONFIG_DICT_KEY_REVISION,"1").c_str()); // older controllers don't send this, so default to 1
|
||||
_issuedTo = Address(d.get(ZT_NETWORKCONFIG_DICT_KEY_ISSUED_TO,"0"));
|
||||
timestamp = Utils::hexStrToU64(d.get(ZT_NETWORKCONFIG_DICT_KEY_TIMESTAMP,"0").c_str());
|
||||
revision = Utils::hexStrToU64(d.get(ZT_NETWORKCONFIG_DICT_KEY_REVISION,"1").c_str()); // older controllers don't send this, so default to 1
|
||||
issuedTo = Address(d.get(ZT_NETWORKCONFIG_DICT_KEY_ISSUED_TO,"0"));
|
||||
|
||||
_multicastLimit = Utils::hexStrToUInt(d.get(ZT_NETWORKCONFIG_DICT_KEY_MULTICAST_LIMIT,zero).c_str());
|
||||
if (_multicastLimit == 0) _multicastLimit = ZT_MULTICAST_DEFAULT_LIMIT;
|
||||
multicastLimit = Utils::hexStrToUInt(d.get(ZT_NETWORKCONFIG_DICT_KEY_MULTICAST_LIMIT,zero).c_str());
|
||||
if (multicastLimit == 0) multicastLimit = ZT_MULTICAST_DEFAULT_LIMIT;
|
||||
|
||||
_flags |= ((Utils::hexStrToUInt(d.get(ZT_NETWORKCONFIG_DICT_KEY_ALLOW_PASSIVE_BRIDGING,zero).c_str()) != 0) ? ZT_NETWORKCONFIG_FLAG_ALLOW_PASSIVE_BRIDGING : 0);
|
||||
_flags |= ((Utils::hexStrToUInt(d.get(ZT_NETWORKCONFIG_DICT_KEY_ENABLE_BROADCAST,one).c_str()) != 0) ? ZT_NETWORKCONFIG_FLAG_ENABLE_BROADCAST : 0);
|
||||
flags |= ((Utils::hexStrToUInt(d.get(ZT_NETWORKCONFIG_DICT_KEY_ALLOW_PASSIVE_BRIDGING,zero).c_str()) != 0) ? ZT_NETWORKCONFIG_FLAG_ALLOW_PASSIVE_BRIDGING : 0);
|
||||
flags |= ((Utils::hexStrToUInt(d.get(ZT_NETWORKCONFIG_DICT_KEY_ENABLE_BROADCAST,one).c_str()) != 0) ? ZT_NETWORKCONFIG_FLAG_ENABLE_BROADCAST : 0);
|
||||
|
||||
_type = (Utils::hexStrToUInt(d.get(ZT_NETWORKCONFIG_DICT_KEY_PRIVATE,one).c_str()) != 0) ? ZT_NETWORK_TYPE_PRIVATE : ZT_NETWORK_TYPE_PUBLIC;
|
||||
this->type = (Utils::hexStrToUInt(d.get(ZT_NETWORKCONFIG_DICT_KEY_PRIVATE,one).c_str()) != 0) ? ZT_NETWORK_TYPE_PRIVATE : ZT_NETWORK_TYPE_PUBLIC;
|
||||
|
||||
std::string nametmp(d.get(ZT_NETWORKCONFIG_DICT_KEY_NAME,""));
|
||||
for(unsigned long i=0;((i<ZT_MAX_NETWORK_SHORT_NAME_LENGTH)&&(i<nametmp.length()));++i)
|
||||
_name[i] = (char)nametmp[i];
|
||||
name[i] = (char)nametmp[i];
|
||||
// we zeroed the entire structure above and _name is ZT_MAX_NETWORK_SHORT_NAME_LENGTH+1, so it will always null-terminate
|
||||
|
||||
std::vector<std::string> activeBridgesSplit(Utils::split(d.get(ZT_NETWORKCONFIG_DICT_KEY_ACTIVE_BRIDGES,"").c_str(),",","",""));
|
||||
@ -63,15 +63,15 @@ void NetworkConfig::fromDictionary(const char *ds,unsigned int dslen)
|
||||
Address tmp(*a);
|
||||
if (!tmp.isReserved()) {
|
||||
uint64_t specialist = tmp.toInt();
|
||||
for(unsigned int i=0;i<_specialistCount;++i) {
|
||||
if ((_specialists[i] & 0xffffffffffULL) == specialist) {
|
||||
_specialists[i] |= ZT_NETWORKCONFIG_SPECIALIST_TYPE_ACTIVE_BRIDGE;
|
||||
for(unsigned int i=0;i<specialistCount;++i) {
|
||||
if ((specialists[i] & 0xffffffffffULL) == specialist) {
|
||||
specialists[i] |= ZT_NETWORKCONFIG_SPECIALIST_TYPE_ACTIVE_BRIDGE;
|
||||
specialist = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((specialist)&&(_specialistCount < ZT_MAX_NETWORK_SPECIALISTS))
|
||||
_specialists[_specialistCount++] = specialist | ZT_NETWORKCONFIG_SPECIALIST_TYPE_ACTIVE_BRIDGE;
|
||||
if ((specialist)&&(specialistCount < ZT_MAX_NETWORK_SPECIALISTS))
|
||||
specialists[specialistCount++] = specialist | ZT_NETWORKCONFIG_SPECIALIST_TYPE_ACTIVE_BRIDGE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -101,11 +101,11 @@ void NetworkConfig::fromDictionary(const char *ds,unsigned int dslen)
|
||||
continue;
|
||||
}
|
||||
if (!addr.isNetwork()) {
|
||||
if ((_staticIpCount < ZT_MAX_ZT_ASSIGNED_ADDRESSES)&&(std::find(&(_staticIps[0]),&(_staticIps[_staticIpCount]),addr) == &(_staticIps[_staticIpCount])))
|
||||
_staticIps[_staticIpCount++] = addr;
|
||||
if ((staticIpCount < ZT_MAX_ZT_ASSIGNED_ADDRESSES)&&(std::find(&(staticIps[0]),&(staticIps[staticIpCount]),addr) == &(staticIps[staticIpCount])))
|
||||
staticIps[staticIpCount++] = addr;
|
||||
}
|
||||
}
|
||||
std::sort(&(_staticIps[0]),&(_staticIps[_staticIpCount]));
|
||||
std::sort(&(staticIps[0]),&(staticIps[staticIpCount]));
|
||||
|
||||
/* Old versions don't support gateways anyway, so ignore this in old netconfs
|
||||
std::vector<std::string> gatewaysSplit(Utils::split(d.get(ZT_NETWORKCONFIG_DICT_KEY_GATEWAYS,"").c_str(),",","",""));
|
||||
@ -135,26 +135,26 @@ void NetworkConfig::fromDictionary(const char *ds,unsigned int dslen)
|
||||
}
|
||||
|
||||
uint64_t specialist = zt.toInt();
|
||||
for(unsigned int i=0;i<_specialistCount;++i) {
|
||||
if ((_specialists[i] & 0xffffffffffULL) == specialist) {
|
||||
_specialists[i] |= ZT_NETWORKCONFIG_SPECIALIST_TYPE_NETWORK_PREFERRED_RELAY;
|
||||
for(unsigned int i=0;i<specialistCount;++i) {
|
||||
if ((specialists[i] & 0xffffffffffULL) == specialist) {
|
||||
specialists[i] |= ZT_NETWORKCONFIG_SPECIALIST_TYPE_NETWORK_PREFERRED_RELAY;
|
||||
specialist = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((specialist)&&(_specialistCount < ZT_MAX_NETWORK_SPECIALISTS))
|
||||
_specialists[_specialistCount++] = specialist | ZT_NETWORKCONFIG_SPECIALIST_TYPE_NETWORK_PREFERRED_RELAY;
|
||||
if ((specialist)&&(specialistCount < ZT_MAX_NETWORK_SPECIALISTS))
|
||||
specialists[specialistCount++] = specialist | ZT_NETWORKCONFIG_SPECIALIST_TYPE_NETWORK_PREFERRED_RELAY;
|
||||
|
||||
if ((phy[0])&&(_staticCount < ZT_MAX_NETWORK_STATIC_PHYSICAL_ADDRESSES)) {
|
||||
_static[_staticCount].zt = zt;
|
||||
_static[_staticCount].phy = phy[0];
|
||||
++_staticCount;
|
||||
if ((phy[0])&&(pinnedCount < ZT_MAX_NETWORK_PINNED)) {
|
||||
pinned[pinnedCount].zt = zt;
|
||||
pinned[pinnedCount].phy = phy[0];
|
||||
++pinnedCount;
|
||||
}
|
||||
if ((phy[1])&&(_staticCount < ZT_MAX_NETWORK_STATIC_PHYSICAL_ADDRESSES)) {
|
||||
_static[_staticCount].zt = zt;
|
||||
_static[_staticCount].phy = phy[0];
|
||||
++_staticCount;
|
||||
if ((phy[1])&&(pinnedCount < ZT_MAX_NETWORK_PINNED)) {
|
||||
pinned[pinnedCount].zt = zt;
|
||||
pinned[pinnedCount].phy = phy[0];
|
||||
++pinnedCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -162,18 +162,18 @@ void NetworkConfig::fromDictionary(const char *ds,unsigned int dslen)
|
||||
std::vector<std::string> ets(Utils::split(d.get(ZT_NETWORKCONFIG_DICT_KEY_ALLOWED_ETHERNET_TYPES,"").c_str(),",","",""));
|
||||
for(std::vector<std::string>::const_iterator et(ets.begin());et!=ets.end();++et) {
|
||||
unsigned int et2 = Utils::hexStrToUInt(et->c_str()) & 0xffff;
|
||||
if ((_ruleCount + 1) < ZT_MAX_NETWORK_RULES) {
|
||||
if ((ruleCount + 1) < ZT_MAX_NETWORK_RULES) {
|
||||
if (et2) {
|
||||
_rules[_ruleCount].t = ZT_NETWORK_RULE_MATCH_ETHERTYPE;
|
||||
_rules[_ruleCount].v.etherType = (uint16_t)et2;
|
||||
++_ruleCount;
|
||||
rules[ruleCount].t = ZT_NETWORK_RULE_MATCH_ETHERTYPE;
|
||||
rules[ruleCount].v.etherType = (uint16_t)et2;
|
||||
++ruleCount;
|
||||
}
|
||||
_rules[_ruleCount].t = ZT_NETWORK_RULE_ACTION_ACCEPT;
|
||||
++_ruleCount;
|
||||
rules[ruleCount].t = ZT_NETWORK_RULE_ACTION_ACCEPT;
|
||||
++ruleCount;
|
||||
}
|
||||
}
|
||||
|
||||
_com.fromString(d.get(ZT_NETWORKCONFIG_DICT_KEY_CERTIFICATE_OF_MEMBERSHIP,std::string()));
|
||||
this->com.fromString(d.get(ZT_NETWORKCONFIG_DICT_KEY_CERTIFICATE_OF_MEMBERSHIP,std::string()));
|
||||
}
|
||||
|
||||
#endif // ZT_SUPPORT_OLD_STYLE_NETCONF
|
||||
|
@ -128,6 +128,8 @@ class NetworkConfig
|
||||
public:
|
||||
/**
|
||||
* Network preferred relay with optional physical endpoint addresses
|
||||
*
|
||||
* This is used by the convenience relays() method.
|
||||
*/
|
||||
struct Relay
|
||||
{
|
||||
@ -148,30 +150,30 @@ public:
|
||||
{
|
||||
NetworkConfig nc;
|
||||
|
||||
nc._nwid = ZT_TEST_NETWORK_ID;
|
||||
nc._timestamp = 1;
|
||||
nc._revision = 1;
|
||||
nc._issuedTo = self;
|
||||
nc._multicastLimit = ZT_MULTICAST_DEFAULT_LIMIT;
|
||||
nc._flags = ZT_NETWORKCONFIG_FLAG_ENABLE_BROADCAST;
|
||||
nc._type = ZT_NETWORK_TYPE_PUBLIC;
|
||||
nc.networkId = ZT_TEST_NETWORK_ID;
|
||||
nc.timestamp = 1;
|
||||
nc.revision = 1;
|
||||
nc.issuedTo = self;
|
||||
nc.multicastLimit = ZT_MULTICAST_DEFAULT_LIMIT;
|
||||
nc.flags = ZT_NETWORKCONFIG_FLAG_ENABLE_BROADCAST;
|
||||
nc.type = ZT_NETWORK_TYPE_PUBLIC;
|
||||
|
||||
nc._rules[nc._ruleCount].t = ZT_NETWORK_RULE_ACTION_ACCEPT;
|
||||
nc._ruleCount = 1;
|
||||
nc.rules[0].t = ZT_NETWORK_RULE_ACTION_ACCEPT;
|
||||
nc.ruleCount = 1;
|
||||
|
||||
Utils::snprintf(nc._name,sizeof(nc._name),"ZT_TEST_NETWORK");
|
||||
Utils::snprintf(nc.name,sizeof(nc.name),"ZT_TEST_NETWORK");
|
||||
|
||||
// Make up a V4 IP from 'self' in the 10.0.0.0/8 range -- no
|
||||
// guarantee of uniqueness but collisions are unlikely.
|
||||
uint32_t ip = (uint32_t)((self.toInt() & 0x00ffffff) | 0x0a000000); // 10.x.x.x
|
||||
if ((ip & 0x000000ff) == 0x000000ff) ip ^= 0x00000001; // but not ending in .255
|
||||
if ((ip & 0x000000ff) == 0x00000000) ip ^= 0x00000001; // or .0
|
||||
nc._staticIps[0] = InetAddress(Utils::hton(ip),8);
|
||||
nc.staticIps[0] = InetAddress(Utils::hton(ip),8);
|
||||
|
||||
// Assign an RFC4193-compliant IPv6 address -- will never collide
|
||||
nc._staticIps[1] = InetAddress::makeIpv6rfc4193(ZT_TEST_NETWORK_ID,self.toInt());
|
||||
nc.staticIps[1] = InetAddress::makeIpv6rfc4193(ZT_TEST_NETWORK_ID,self.toInt());
|
||||
|
||||
nc._staticIpCount = 2;
|
||||
nc.staticIpCount = 2;
|
||||
|
||||
return nc;
|
||||
}
|
||||
@ -199,10 +201,10 @@ public:
|
||||
inline bool permitsEtherType(unsigned int etherType) const
|
||||
{
|
||||
unsigned int et = 0;
|
||||
for(unsigned int i=0;i<_ruleCount;++i) {
|
||||
ZT_VirtualNetworkRuleType rt = (ZT_VirtualNetworkRuleType)(_rules[i].t & 0x7f);
|
||||
for(unsigned int i=0;i<ruleCount;++i) {
|
||||
ZT_VirtualNetworkRuleType rt = (ZT_VirtualNetworkRuleType)(rules[i].t & 0x7f);
|
||||
if (rt == ZT_NETWORK_RULE_MATCH_ETHERTYPE) {
|
||||
et = _rules[i].v.etherType;
|
||||
et = rules[i].v.etherType;
|
||||
} else if (rt == ZT_NETWORK_RULE_ACTION_ACCEPT) {
|
||||
if ((!et)||(et == etherType))
|
||||
return true;
|
||||
@ -212,76 +214,25 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Network ID that this config applies to
|
||||
*/
|
||||
inline uint64_t networkId() const throw() { return _nwid; }
|
||||
|
||||
/**
|
||||
* @return Timestamp of this config (controller-side)
|
||||
*/
|
||||
inline uint64_t timestamp() const throw() { return _timestamp; }
|
||||
|
||||
/**
|
||||
* @return Config revision number
|
||||
*/
|
||||
inline uint64_t revision() const throw() { return _revision; }
|
||||
|
||||
/**
|
||||
* @return ZeroTier address of device to which this config was issued
|
||||
*/
|
||||
inline const Address &issuedTo() const throw() { return _issuedTo; }
|
||||
|
||||
/**
|
||||
* @return Maximum number of multicast recipients or 0 to disable multicast
|
||||
*/
|
||||
inline unsigned int multicastLimit() const throw() { return _multicastLimit; }
|
||||
|
||||
/**
|
||||
* @return True if passive bridging is allowed (experimental)
|
||||
*/
|
||||
inline bool allowPassiveBridging() const throw() { return ((_flags & ZT_NETWORKCONFIG_FLAG_ALLOW_PASSIVE_BRIDGING) != 0); }
|
||||
inline bool allowPassiveBridging() const throw() { return ((this->flags & ZT_NETWORKCONFIG_FLAG_ALLOW_PASSIVE_BRIDGING) != 0); }
|
||||
|
||||
/**
|
||||
* @return True if broadcast (ff:ff:ff:ff:ff:ff) address should work on this network
|
||||
*/
|
||||
inline bool enableBroadcast() const throw() { return ((_flags & ZT_NETWORKCONFIG_FLAG_ENABLE_BROADCAST) != 0); }
|
||||
|
||||
/**
|
||||
* @return Type of network (currently public or private)
|
||||
*/
|
||||
inline ZT_VirtualNetworkType type() const throw() { return _type; }
|
||||
inline bool enableBroadcast() const throw() { return ((this->flags & ZT_NETWORKCONFIG_FLAG_ENABLE_BROADCAST) != 0); }
|
||||
|
||||
/**
|
||||
* @return Network type is public (no access control)
|
||||
*/
|
||||
inline bool isPublic() const throw() { return (_type == ZT_NETWORK_TYPE_PUBLIC); }
|
||||
inline bool isPublic() const throw() { return (this->type == ZT_NETWORK_TYPE_PUBLIC); }
|
||||
|
||||
/**
|
||||
* @return Network type is private (certificate access control)
|
||||
*/
|
||||
inline bool isPrivate() const throw() { return (_type == ZT_NETWORK_TYPE_PRIVATE); }
|
||||
|
||||
/**
|
||||
* @return Short network name
|
||||
*/
|
||||
inline const char *name() const throw() { return _name; }
|
||||
|
||||
/**
|
||||
* @return Network certificate of membership or NULL COM object if none (public network)
|
||||
*/
|
||||
inline const CertificateOfMembership &com() const throw() { return _com; }
|
||||
|
||||
/**
|
||||
* @return ZeroTier-managed static IPs assigned to this device on this network
|
||||
*/
|
||||
inline std::vector<InetAddress> staticIps() const
|
||||
{
|
||||
std::vector<InetAddress> r;
|
||||
for(unsigned int i=0;i<_staticIpCount;++i)
|
||||
r.push_back(_staticIps[i]);
|
||||
return r;
|
||||
}
|
||||
inline bool isPrivate() const throw() { return (this->type == ZT_NETWORK_TYPE_PRIVATE); }
|
||||
|
||||
/**
|
||||
* @return ZeroTier addresses of devices on this network designated as active bridges
|
||||
@ -289,9 +240,9 @@ public:
|
||||
inline std::vector<Address> activeBridges() const
|
||||
{
|
||||
std::vector<Address> r;
|
||||
for(unsigned int i=0;i<_specialistCount;++i) {
|
||||
if ((_specialists[i] & ZT_NETWORKCONFIG_SPECIALIST_TYPE_ACTIVE_BRIDGE) != 0)
|
||||
r.push_back(Address(_specialists[i]));
|
||||
for(unsigned int i=0;i<specialistCount;++i) {
|
||||
if ((specialists[i] & ZT_NETWORKCONFIG_SPECIALIST_TYPE_ACTIVE_BRIDGE) != 0)
|
||||
r.push_back(Address(specialists[i]));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
@ -302,26 +253,26 @@ public:
|
||||
inline std::vector<Address> anchors() const
|
||||
{
|
||||
std::vector<Address> r;
|
||||
for(unsigned int i=0;i<_specialistCount;++i) {
|
||||
if ((_specialists[i] & ZT_NETWORKCONFIG_SPECIALIST_TYPE_ANCHOR) != 0)
|
||||
r.push_back(Address(_specialists[i]));
|
||||
for(unsigned int i=0;i<specialistCount;++i) {
|
||||
if ((specialists[i] & ZT_NETWORKCONFIG_SPECIALIST_TYPE_ANCHOR) != 0)
|
||||
r.push_back(Address(specialists[i]));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up a static physical address for a given ZeroTier address
|
||||
* Get pinned physical address for a given ZeroTier address, if any
|
||||
*
|
||||
* @param zt ZeroTier address
|
||||
* @param af Address family (e.g. AF_INET) or 0 for the first we find of any type
|
||||
* @return Physical address, if any
|
||||
*/
|
||||
inline InetAddress staticPhysicalAddress(const Address &zt,unsigned int af) const
|
||||
inline InetAddress findPinnedAddress(const Address &zt,unsigned int af) const
|
||||
{
|
||||
for(unsigned int i=0;i<_staticCount;++i) {
|
||||
if (_static[i].zt == zt) {
|
||||
if ((af == 0)||((unsigned int)_static[i].phy.ss_family == af))
|
||||
return _static[i].phy;
|
||||
for(unsigned int i=0;i<pinnedCount;++i) {
|
||||
if (pinned[i].zt == zt) {
|
||||
if ((af == 0)||((unsigned int)pinned[i].phy.ss_family == af))
|
||||
return pinned[i].phy;
|
||||
}
|
||||
}
|
||||
return InetAddress();
|
||||
@ -335,12 +286,12 @@ public:
|
||||
inline std::vector<Relay> relays() const
|
||||
{
|
||||
std::vector<Relay> r;
|
||||
for(unsigned int i=0;i<_specialistCount;++i) {
|
||||
if ((_specialists[i] & ZT_NETWORKCONFIG_SPECIALIST_TYPE_NETWORK_PREFERRED_RELAY) != 0) {
|
||||
for(unsigned int i=0;i<specialistCount;++i) {
|
||||
if ((specialists[i] & ZT_NETWORKCONFIG_SPECIALIST_TYPE_NETWORK_PREFERRED_RELAY) != 0) {
|
||||
r.push_back(Relay());
|
||||
r.back().address = _specialists[i];
|
||||
r.back().phy4 = staticPhysicalAddress(r.back().address,AF_INET);
|
||||
r.back().phy6 = staticPhysicalAddress(r.back().address,AF_INET6);
|
||||
r.back().address = specialists[i];
|
||||
r.back().phy4 = findPinnedAddress(r.back().address,AF_INET);
|
||||
r.back().phy6 = findPinnedAddress(r.back().address,AF_INET6);
|
||||
}
|
||||
}
|
||||
return r;
|
||||
@ -352,10 +303,10 @@ public:
|
||||
*/
|
||||
inline bool permitsBridging(const Address &fromPeer) const
|
||||
{
|
||||
if ((_flags & ZT_NETWORKCONFIG_FLAG_ALLOW_PASSIVE_BRIDGING) != 0)
|
||||
if ((flags & ZT_NETWORKCONFIG_FLAG_ALLOW_PASSIVE_BRIDGING) != 0)
|
||||
return true;
|
||||
for(unsigned int i=0;i<_specialistCount;++i) {
|
||||
if ((fromPeer == _specialists[i])&&((_specialists[i] & ZT_NETWORKCONFIG_SPECIALIST_TYPE_ACTIVE_BRIDGE) != 0))
|
||||
for(unsigned int i=0;i<specialistCount;++i) {
|
||||
if ((fromPeer == specialists[i])&&((specialists[i] & ZT_NETWORKCONFIG_SPECIALIST_TYPE_ACTIVE_BRIDGE) != 0))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -369,9 +320,9 @@ public:
|
||||
*/
|
||||
Address nextRelay(unsigned int &ptr) const
|
||||
{
|
||||
while (ptr < _specialistCount) {
|
||||
if ((_specialists[ptr] & ZT_NETWORKCONFIG_SPECIALIST_TYPE_NETWORK_PREFERRED_RELAY) != 0) {
|
||||
return Address(_specialists[ptr]);
|
||||
while (ptr < specialistCount) {
|
||||
if ((specialists[ptr] & ZT_NETWORKCONFIG_SPECIALIST_TYPE_NETWORK_PREFERRED_RELAY) != 0) {
|
||||
return Address(specialists[ptr]);
|
||||
}
|
||||
++ptr;
|
||||
}
|
||||
@ -384,8 +335,8 @@ public:
|
||||
*/
|
||||
bool isRelay(const Address &zt) const
|
||||
{
|
||||
for(unsigned int i=0;i<_specialistCount;++i) {
|
||||
if ((zt == _specialists[i])&&((_specialists[i] & ZT_NETWORKCONFIG_SPECIALIST_TYPE_NETWORK_PREFERRED_RELAY) != 0))
|
||||
for(unsigned int i=0;i<specialistCount;++i) {
|
||||
if ((zt == specialists[i])&&((specialists[i] & ZT_NETWORKCONFIG_SPECIALIST_TYPE_NETWORK_PREFERRED_RELAY) != 0))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -394,7 +345,7 @@ public:
|
||||
/**
|
||||
* @return True if this network config is non-NULL
|
||||
*/
|
||||
inline operator bool() const throw() { return (_nwid != 0); }
|
||||
inline operator bool() const throw() { return (networkId != 0); }
|
||||
|
||||
inline bool operator==(const NetworkConfig &nc) const { return (memcmp(this,&nc,sizeof(NetworkConfig)) == 0); }
|
||||
inline bool operator!=(const NetworkConfig &nc) const { return (!(*this == nc)); }
|
||||
@ -404,43 +355,43 @@ public:
|
||||
{
|
||||
b.append((uint16_t)1); // version
|
||||
|
||||
b.append((uint64_t)_nwid);
|
||||
b.append((uint64_t)_timestamp);
|
||||
b.append((uint64_t)_revision);
|
||||
_issuedTo.appendTo(b);
|
||||
b.append((uint32_t)_multicastLimit);
|
||||
b.append((uint32_t)_flags);
|
||||
b.append((uint8_t)_type);
|
||||
b.append((uint64_t)networkId);
|
||||
b.append((uint64_t)timestamp);
|
||||
b.append((uint64_t)revision);
|
||||
issuedTo.appendTo(b);
|
||||
b.append((uint32_t)multicastLimit);
|
||||
b.append((uint32_t)flags);
|
||||
b.append((uint8_t)type);
|
||||
|
||||
unsigned int nl = (unsigned int)strlen(_name);
|
||||
unsigned int nl = (unsigned int)strlen(name);
|
||||
if (nl > 255) nl = 255; // sanity check
|
||||
b.append((uint8_t)nl);
|
||||
b.append((const void *)_name,nl);
|
||||
b.append((const void *)name,nl);
|
||||
|
||||
b.append((uint16_t)_specialistCount);
|
||||
for(unsigned int i=0;i<_specialistCount;++i)
|
||||
b.append((uint64_t)_specialists[i]);
|
||||
b.append((uint16_t)specialistCount);
|
||||
for(unsigned int i=0;i<specialistCount;++i)
|
||||
b.append((uint64_t)specialists[i]);
|
||||
|
||||
b.append((uint16_t)_routeCount);
|
||||
for(unsigned int i=0;i<_routeCount;++i) {
|
||||
reinterpret_cast<const InetAddress *>(&(_routes[i].target))->serialize(b);
|
||||
reinterpret_cast<const InetAddress *>(&(_routes[i].via))->serialize(b);
|
||||
b.append((uint16_t)routeCount);
|
||||
for(unsigned int i=0;i<routeCount;++i) {
|
||||
reinterpret_cast<const InetAddress *>(&(routes[i].target))->serialize(b);
|
||||
reinterpret_cast<const InetAddress *>(&(routes[i].via))->serialize(b);
|
||||
}
|
||||
|
||||
b.append((uint16_t)_staticIpCount);
|
||||
for(unsigned int i=0;i<_staticIpCount;++i)
|
||||
_staticIps[i].serialize(b);
|
||||
b.append((uint16_t)staticIpCount);
|
||||
for(unsigned int i=0;i<staticIpCount;++i)
|
||||
staticIps[i].serialize(b);
|
||||
|
||||
b.append((uint16_t)_staticCount);
|
||||
for(unsigned int i=0;i<_staticCount;++i) {
|
||||
_static[i].zt.appendTo(b);
|
||||
_static[i].phy.serialize(b);
|
||||
b.append((uint16_t)pinnedCount);
|
||||
for(unsigned int i=0;i<pinnedCount;++i) {
|
||||
pinned[i].zt.appendTo(b);
|
||||
pinned[i].phy.serialize(b);
|
||||
}
|
||||
|
||||
b.append((uint16_t)_ruleCount);
|
||||
for(unsigned int i=0;i<_ruleCount;++i) {
|
||||
b.append((uint8_t)_rules[i].t);
|
||||
switch((ZT_VirtualNetworkRuleType)(_rules[i].t & 0x7f)) {
|
||||
b.append((uint16_t)ruleCount);
|
||||
for(unsigned int i=0;i<ruleCount;++i) {
|
||||
b.append((uint8_t)rules[i].t);
|
||||
switch((ZT_VirtualNetworkRuleType)(rules[i].t & 0x7f)) {
|
||||
//case ZT_NETWORK_RULE_ACTION_DROP:
|
||||
//case ZT_NETWORK_RULE_ACTION_ACCEPT:
|
||||
default:
|
||||
@ -451,68 +402,68 @@ public:
|
||||
case ZT_NETWORK_RULE_MATCH_SOURCE_ZEROTIER_ADDRESS:
|
||||
case ZT_NETWORK_RULE_MATCH_DEST_ZEROTIER_ADDRESS:
|
||||
b.append((uint8_t)5);
|
||||
Address(_rules[i].v.zt).appendTo(b);
|
||||
Address(rules[i].v.zt).appendTo(b);
|
||||
break;
|
||||
case ZT_NETWORK_RULE_MATCH_VLAN_ID:
|
||||
b.append((uint8_t)2);
|
||||
b.append((uint16_t)_rules[i].v.vlanId);
|
||||
b.append((uint16_t)rules[i].v.vlanId);
|
||||
break;
|
||||
case ZT_NETWORK_RULE_MATCH_VLAN_PCP:
|
||||
b.append((uint8_t)1);
|
||||
b.append((uint8_t)_rules[i].v.vlanPcp);
|
||||
b.append((uint8_t)rules[i].v.vlanPcp);
|
||||
break;
|
||||
case ZT_NETWORK_RULE_MATCH_VLAN_DEI:
|
||||
b.append((uint8_t)1);
|
||||
b.append((uint8_t)_rules[i].v.vlanDei);
|
||||
b.append((uint8_t)rules[i].v.vlanDei);
|
||||
break;
|
||||
case ZT_NETWORK_RULE_MATCH_ETHERTYPE:
|
||||
b.append((uint8_t)2);
|
||||
b.append((uint16_t)_rules[i].v.etherType);
|
||||
b.append((uint16_t)rules[i].v.etherType);
|
||||
break;
|
||||
case ZT_NETWORK_RULE_MATCH_MAC_SOURCE:
|
||||
case ZT_NETWORK_RULE_MATCH_MAC_DEST:
|
||||
b.append((uint8_t)6);
|
||||
b.append(_rules[i].v.mac,6);
|
||||
b.append(rules[i].v.mac,6);
|
||||
break;
|
||||
case ZT_NETWORK_RULE_MATCH_IPV4_SOURCE:
|
||||
case ZT_NETWORK_RULE_MATCH_IPV4_DEST:
|
||||
b.append((uint8_t)5);
|
||||
b.append(&(_rules[i].v.ipv4.ip),4);
|
||||
b.append((uint8_t)_rules[i].v.ipv4.mask);
|
||||
b.append(&(rules[i].v.ipv4.ip),4);
|
||||
b.append((uint8_t)rules[i].v.ipv4.mask);
|
||||
break;
|
||||
case ZT_NETWORK_RULE_MATCH_IPV6_SOURCE:
|
||||
case ZT_NETWORK_RULE_MATCH_IPV6_DEST:
|
||||
b.append((uint8_t)17);
|
||||
b.append(_rules[i].v.ipv6.ip,16);
|
||||
b.append((uint8_t)_rules[i].v.ipv6.mask);
|
||||
b.append(rules[i].v.ipv6.ip,16);
|
||||
b.append((uint8_t)rules[i].v.ipv6.mask);
|
||||
break;
|
||||
case ZT_NETWORK_RULE_MATCH_IP_TOS:
|
||||
b.append((uint8_t)1);
|
||||
b.append((uint8_t)_rules[i].v.ipTos);
|
||||
b.append((uint8_t)rules[i].v.ipTos);
|
||||
break;
|
||||
case ZT_NETWORK_RULE_MATCH_IP_PROTOCOL:
|
||||
b.append((uint8_t)1);
|
||||
b.append((uint8_t)_rules[i].v.ipProtocol);
|
||||
b.append((uint8_t)rules[i].v.ipProtocol);
|
||||
break;
|
||||
case ZT_NETWORK_RULE_MATCH_IP_SOURCE_PORT_RANGE:
|
||||
case ZT_NETWORK_RULE_MATCH_IP_DEST_PORT_RANGE:
|
||||
b.append((uint8_t)4);
|
||||
b.append((uint16_t)_rules[i].v.port[0]);
|
||||
b.append((uint16_t)_rules[i].v.port[1]);
|
||||
b.append((uint16_t)rules[i].v.port[0]);
|
||||
b.append((uint16_t)rules[i].v.port[1]);
|
||||
break;
|
||||
case ZT_NETWORK_RULE_MATCH_CHARACTERISTICS:
|
||||
b.append((uint8_t)8);
|
||||
b.append((uint64_t)_rules[i].v.characteristics);
|
||||
b.append((uint64_t)rules[i].v.characteristics);
|
||||
break;
|
||||
case ZT_NETWORK_RULE_MATCH_FRAME_SIZE_RANGE:
|
||||
b.append((uint8_t)4);
|
||||
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[0]);
|
||||
b.append((uint16_t)rules[i].v.frameSize[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_com.serialize(b);
|
||||
this->com.serialize(b);
|
||||
|
||||
b.append((uint16_t)0); // extended bytes, currently 0 since unused
|
||||
}
|
||||
@ -528,56 +479,56 @@ public:
|
||||
throw std::invalid_argument("unrecognized version");
|
||||
p += 2;
|
||||
|
||||
_nwid = b.template at<uint64_t>(p); p += 8;
|
||||
_timestamp = b.template at<uint64_t>(p); p += 8;
|
||||
_revision = b.template at<uint64_t>(p); p += 8;
|
||||
_issuedTo.setTo(b.field(p,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH); p += ZT_ADDRESS_LENGTH;
|
||||
_multicastLimit = (unsigned int)b.template at<uint32_t>(p); p += 4;
|
||||
_flags = (unsigned int)b.template at<uint32_t>(p); p += 4;
|
||||
_type = (ZT_VirtualNetworkType)b[p++];
|
||||
networkId = b.template at<uint64_t>(p); p += 8;
|
||||
timestamp = b.template at<uint64_t>(p); p += 8;
|
||||
revision = b.template at<uint64_t>(p); p += 8;
|
||||
issuedTo.setTo(b.field(p,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH); p += ZT_ADDRESS_LENGTH;
|
||||
multicastLimit = (unsigned int)b.template at<uint32_t>(p); p += 4;
|
||||
flags = (unsigned int)b.template at<uint32_t>(p); p += 4;
|
||||
type = (ZT_VirtualNetworkType)b[p++];
|
||||
|
||||
unsigned int nl = (unsigned int)b[p++];
|
||||
memcpy(_name,b.field(p,nl),std::max(nl,(unsigned int)ZT_MAX_NETWORK_SHORT_NAME_LENGTH));
|
||||
memcpy(this->name,b.field(p,nl),std::max(nl,(unsigned int)ZT_MAX_NETWORK_SHORT_NAME_LENGTH));
|
||||
p += nl;
|
||||
// _name will always be null terminated since field size is ZT_MAX_NETWORK_SHORT_NAME_LENGTH + 1
|
||||
|
||||
_specialistCount = (unsigned int)b.template at<uint16_t>(p); p += 2;
|
||||
if (_specialistCount > ZT_MAX_NETWORK_SPECIALISTS)
|
||||
specialistCount = (unsigned int)b.template at<uint16_t>(p); p += 2;
|
||||
if (specialistCount > ZT_MAX_NETWORK_SPECIALISTS)
|
||||
throw std::invalid_argument("overflow (specialists)");
|
||||
for(unsigned int i=0;i<_specialistCount;++i) {
|
||||
_specialists[i] = b.template at<uint64_t>(p); p += 8;
|
||||
for(unsigned int i=0;i<specialistCount;++i) {
|
||||
specialists[i] = b.template at<uint64_t>(p); p += 8;
|
||||
}
|
||||
|
||||
_routeCount = (unsigned int)b.template at<uint16_t>(p); p += 2;
|
||||
if (_routeCount > ZT_MAX_NETWORK_ROUTES)
|
||||
routeCount = (unsigned int)b.template at<uint16_t>(p); p += 2;
|
||||
if (routeCount > ZT_MAX_NETWORK_ROUTES)
|
||||
throw std::invalid_argument("overflow (routes)");
|
||||
for(unsigned int i=0;i<_routeCount;++i) {
|
||||
p += reinterpret_cast<InetAddress *>(&(_routes[i].target))->deserialize(b,p);
|
||||
p += reinterpret_cast<InetAddress *>(&(_routes[i].via))->deserialize(b,p);
|
||||
for(unsigned int i=0;i<routeCount;++i) {
|
||||
p += reinterpret_cast<InetAddress *>(&(routes[i].target))->deserialize(b,p);
|
||||
p += reinterpret_cast<InetAddress *>(&(routes[i].via))->deserialize(b,p);
|
||||
}
|
||||
|
||||
_staticIpCount = (unsigned int)b.template at<uint16_t>(p); p += 2;
|
||||
if (_staticIpCount > ZT_MAX_ZT_ASSIGNED_ADDRESSES)
|
||||
staticIpCount = (unsigned int)b.template at<uint16_t>(p); p += 2;
|
||||
if (staticIpCount > ZT_MAX_ZT_ASSIGNED_ADDRESSES)
|
||||
throw std::invalid_argument("overflow (static IPs)");
|
||||
for(unsigned int i=0;i<_staticIpCount;++i) {
|
||||
p += _staticIps[i].deserialize(b,p);
|
||||
for(unsigned int i=0;i<staticIpCount;++i) {
|
||||
p += staticIps[i].deserialize(b,p);
|
||||
}
|
||||
|
||||
_staticCount = (unsigned int)b.template at<uint16_t>(p); p += 2;
|
||||
if (_staticCount > ZT_MAX_NETWORK_STATIC_PHYSICAL_ADDRESSES)
|
||||
pinnedCount = (unsigned int)b.template at<uint16_t>(p); p += 2;
|
||||
if (pinnedCount > ZT_MAX_NETWORK_PINNED)
|
||||
throw std::invalid_argument("overflow (static addresses)");
|
||||
for(unsigned int i=0;i<_staticCount;++i) {
|
||||
_static[i].zt.setTo(b.field(p,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH); p += ZT_ADDRESS_LENGTH;
|
||||
p += _static[i].phy.deserialize(b,p);
|
||||
for(unsigned int i=0;i<pinnedCount;++i) {
|
||||
pinned[i].zt.setTo(b.field(p,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH); p += ZT_ADDRESS_LENGTH;
|
||||
p += pinned[i].phy.deserialize(b,p);
|
||||
}
|
||||
|
||||
_ruleCount = (unsigned int)b.template at<uint16_t>(p); p += 2;
|
||||
if (_ruleCount > ZT_MAX_NETWORK_RULES)
|
||||
ruleCount = (unsigned int)b.template at<uint16_t>(p); p += 2;
|
||||
if (ruleCount > ZT_MAX_NETWORK_RULES)
|
||||
throw std::invalid_argument("overflow (rules)");
|
||||
for(unsigned int i=0;i<_ruleCount;++i) {
|
||||
_rules[i].t = (uint8_t)b[p++];
|
||||
for(unsigned int i=0;i<ruleCount;++i) {
|
||||
rules[i].t = (uint8_t)b[p++];
|
||||
unsigned int rlen = (unsigned int)b[p++];
|
||||
switch((ZT_VirtualNetworkRuleType)(_rules[i].t & 0x7f)) {
|
||||
switch((ZT_VirtualNetworkRuleType)(rules[i].t & 0x7f)) {
|
||||
//case ZT_NETWORK_RULE_ACTION_DROP:
|
||||
//case ZT_NETWORK_RULE_ACTION_ACCEPT:
|
||||
default:
|
||||
@ -588,57 +539,57 @@ public:
|
||||
case ZT_NETWORK_RULE_MATCH_DEST_ZEROTIER_ADDRESS: {
|
||||
Address tmp;
|
||||
tmp.setTo(b.field(p,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH);
|
||||
_rules[i].v.zt = tmp.toInt();
|
||||
rules[i].v.zt = tmp.toInt();
|
||||
} break;
|
||||
case ZT_NETWORK_RULE_MATCH_VLAN_ID:
|
||||
_rules[i].v.vlanId = b.template at<uint16_t>(p);
|
||||
rules[i].v.vlanId = b.template at<uint16_t>(p);
|
||||
break;
|
||||
case ZT_NETWORK_RULE_MATCH_VLAN_PCP:
|
||||
_rules[i].v.vlanPcp = (uint8_t)b[p];
|
||||
rules[i].v.vlanPcp = (uint8_t)b[p];
|
||||
break;
|
||||
case ZT_NETWORK_RULE_MATCH_VLAN_DEI:
|
||||
_rules[i].v.vlanDei = (uint8_t)b[p];
|
||||
rules[i].v.vlanDei = (uint8_t)b[p];
|
||||
break;
|
||||
case ZT_NETWORK_RULE_MATCH_ETHERTYPE:
|
||||
_rules[i].v.etherType = b.template at<uint16_t>(p);
|
||||
rules[i].v.etherType = b.template at<uint16_t>(p);
|
||||
break;
|
||||
case ZT_NETWORK_RULE_MATCH_MAC_SOURCE:
|
||||
case ZT_NETWORK_RULE_MATCH_MAC_DEST:
|
||||
memcpy(_rules[i].v.mac,b.field(p,6),6);
|
||||
memcpy(rules[i].v.mac,b.field(p,6),6);
|
||||
break;
|
||||
case ZT_NETWORK_RULE_MATCH_IPV4_SOURCE:
|
||||
case ZT_NETWORK_RULE_MATCH_IPV4_DEST:
|
||||
memcpy(&(_rules[i].v.ipv4.ip),b.field(p,4),4);
|
||||
_rules[i].v.ipv4.mask = (uint8_t)b[p+4];
|
||||
memcpy(&(rules[i].v.ipv4.ip),b.field(p,4),4);
|
||||
rules[i].v.ipv4.mask = (uint8_t)b[p+4];
|
||||
break;
|
||||
case ZT_NETWORK_RULE_MATCH_IPV6_SOURCE:
|
||||
case ZT_NETWORK_RULE_MATCH_IPV6_DEST:
|
||||
memcpy(_rules[i].v.ipv6.ip,b.field(p,16),16);
|
||||
_rules[i].v.ipv6.mask = (uint8_t)b[p+16];
|
||||
memcpy(rules[i].v.ipv6.ip,b.field(p,16),16);
|
||||
rules[i].v.ipv6.mask = (uint8_t)b[p+16];
|
||||
break;
|
||||
case ZT_NETWORK_RULE_MATCH_IP_TOS:
|
||||
_rules[i].v.ipTos = (uint8_t)b[p];
|
||||
rules[i].v.ipTos = (uint8_t)b[p];
|
||||
break;
|
||||
case ZT_NETWORK_RULE_MATCH_IP_PROTOCOL:
|
||||
_rules[i].v.ipProtocol = (uint8_t)b[p];
|
||||
rules[i].v.ipProtocol = (uint8_t)b[p];
|
||||
break;
|
||||
case ZT_NETWORK_RULE_MATCH_IP_SOURCE_PORT_RANGE:
|
||||
case ZT_NETWORK_RULE_MATCH_IP_DEST_PORT_RANGE:
|
||||
_rules[i].v.port[0] = b.template at<uint16_t>(p);
|
||||
_rules[i].v.port[1] = b.template at<uint16_t>(p+2);
|
||||
rules[i].v.port[0] = b.template at<uint16_t>(p);
|
||||
rules[i].v.port[1] = b.template at<uint16_t>(p+2);
|
||||
break;
|
||||
case ZT_NETWORK_RULE_MATCH_CHARACTERISTICS:
|
||||
_rules[i].v.characteristics = b.template at<uint64_t>(p);
|
||||
rules[i].v.characteristics = b.template at<uint64_t>(p);
|
||||
break;
|
||||
case ZT_NETWORK_RULE_MATCH_FRAME_SIZE_RANGE:
|
||||
_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[0] = b.template at<uint16_t>(p);
|
||||
rules[i].v.frameSize[1] = b.template at<uint16_t>(p+2);
|
||||
break;
|
||||
}
|
||||
p += rlen;
|
||||
}
|
||||
|
||||
p += _com.deserialize(b,p);
|
||||
p += this->com.deserialize(b,p);
|
||||
|
||||
p += b.template at<uint16_t>(p) + 2;
|
||||
|
||||
@ -649,40 +600,109 @@ public:
|
||||
void fromDictionary(const char *ds,unsigned int dslen);
|
||||
#endif
|
||||
|
||||
protected: // protected so that a subclass can fill this out in network controller code
|
||||
uint64_t _nwid;
|
||||
uint64_t _timestamp;
|
||||
uint64_t _revision;
|
||||
Address _issuedTo;
|
||||
unsigned int _multicastLimit;
|
||||
unsigned int _flags;
|
||||
ZT_VirtualNetworkType _type;
|
||||
/**
|
||||
* Network ID that this configuration applies to
|
||||
*/
|
||||
uint64_t networkId;
|
||||
|
||||
char _name[ZT_MAX_NETWORK_SHORT_NAME_LENGTH + 1];
|
||||
/**
|
||||
* Controller-side time of config generation/issue
|
||||
*/
|
||||
uint64_t timestamp;
|
||||
|
||||
// Special ZeroTier addresses -- most significant 40 bits are address, least 24 are specialist type flags
|
||||
uint64_t _specialists[ZT_MAX_NETWORK_SPECIALISTS];
|
||||
/**
|
||||
* Controller-side revision counter for this configuration
|
||||
*/
|
||||
uint64_t revision;
|
||||
|
||||
// ZeroTier-managed IPs and routing table entries and stuff
|
||||
ZT_VirtualNetworkRoute _routes[ZT_MAX_NETWORK_ROUTES];
|
||||
InetAddress _staticIps[ZT_MAX_ZT_ASSIGNED_ADDRESSES];
|
||||
/**
|
||||
* Address of device to which this config is issued
|
||||
*/
|
||||
Address issuedTo;
|
||||
|
||||
// ZeroTier to physical static mappings
|
||||
/**
|
||||
* Maximum number of recipients per multicast (not including active bridges)
|
||||
*/
|
||||
unsigned int multicastLimit;
|
||||
|
||||
/**
|
||||
* Flags (32-bit)
|
||||
*/
|
||||
unsigned int flags;
|
||||
|
||||
/**
|
||||
* Number of specialists
|
||||
*/
|
||||
unsigned int specialistCount;
|
||||
|
||||
/**
|
||||
* Number of routes
|
||||
*/
|
||||
unsigned int routeCount;
|
||||
|
||||
/**
|
||||
* Number of ZT-managed static IP assignments
|
||||
*/
|
||||
unsigned int staticIpCount;
|
||||
|
||||
/**
|
||||
* Number of pinned devices (devices with physical address hints)
|
||||
*/
|
||||
unsigned int pinnedCount;
|
||||
|
||||
/**
|
||||
* Number of rule table entries
|
||||
*/
|
||||
unsigned int ruleCount;
|
||||
|
||||
/**
|
||||
* Specialist devices
|
||||
*
|
||||
* For each entry the least significant 40 bits are the device's ZeroTier
|
||||
* address and the most significant 24 bits are flags indicating its role.
|
||||
*/
|
||||
uint64_t specialists[ZT_MAX_NETWORK_SPECIALISTS];
|
||||
|
||||
/**
|
||||
* Statically defined "pushed" routes (including default gateways)
|
||||
*/
|
||||
ZT_VirtualNetworkRoute routes[ZT_MAX_NETWORK_ROUTES];
|
||||
|
||||
/**
|
||||
* Static IP assignments
|
||||
*/
|
||||
InetAddress staticIps[ZT_MAX_ZT_ASSIGNED_ADDRESSES];
|
||||
|
||||
/**
|
||||
* Pinned devices with physical address hints
|
||||
*
|
||||
* These can be used to specify a physical address where a given device
|
||||
* can be reached. It's usually used with network relays (specialists).
|
||||
*/
|
||||
struct {
|
||||
Address zt;
|
||||
InetAddress phy;
|
||||
} _static[ZT_MAX_NETWORK_STATIC_PHYSICAL_ADDRESSES];
|
||||
} pinned[ZT_MAX_NETWORK_PINNED];
|
||||
|
||||
// Network rules (only Ethernet type filtering is currently supported)
|
||||
ZT_VirtualNetworkRule _rules[ZT_MAX_NETWORK_RULES];
|
||||
/**
|
||||
* Rules table
|
||||
*/
|
||||
ZT_VirtualNetworkRule rules[ZT_MAX_NETWORK_RULES];
|
||||
|
||||
unsigned int _specialistCount;
|
||||
unsigned int _routeCount;
|
||||
unsigned int _staticIpCount;
|
||||
unsigned int _staticCount;
|
||||
unsigned int _ruleCount;
|
||||
/**
|
||||
* Network type (currently just public or private)
|
||||
*/
|
||||
ZT_VirtualNetworkType type;
|
||||
|
||||
CertificateOfMembership _com;
|
||||
/**
|
||||
* Network short name or empty string if not defined
|
||||
*/
|
||||
char name[ZT_MAX_NETWORK_SHORT_NAME_LENGTH + 1];
|
||||
|
||||
/**
|
||||
* Certficiate of membership (for private networks)
|
||||
*/
|
||||
CertificateOfMembership com;
|
||||
};
|
||||
|
||||
} // namespace ZeroTier
|
||||
|
@ -29,11 +29,6 @@
|
||||
|
||||
#include "../version.h"
|
||||
|
||||
#ifdef ZT_SUPPORT_OLD_STYLE_NETCONF
|
||||
#include <string>
|
||||
#include "Dictionary.hpp"
|
||||
#endif
|
||||
|
||||
namespace ZeroTier {
|
||||
|
||||
/**
|
||||
@ -42,7 +37,20 @@ namespace ZeroTier {
|
||||
class NetworkConfigRequestMetaData
|
||||
{
|
||||
public:
|
||||
NetworkConfigRequestMetaData()
|
||||
NetworkConfigRequestMetaData() :
|
||||
buildId(0),
|
||||
flags(0),
|
||||
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)
|
||||
{
|
||||
memset(auth,0,sizeof(auth));
|
||||
}
|
||||
|
||||
NetworkConfigRequestMetaData(bool foo)
|
||||
{
|
||||
memset(this,0,sizeof(NetworkConfigRequestMetaData));
|
||||
}
|
||||
@ -67,7 +75,7 @@ public:
|
||||
b.append((uint16_t)minorVersion);
|
||||
b.append((uint16_t)revision);
|
||||
|
||||
unsigned int tl = (unsigned int)strlen(_auth);
|
||||
unsigned int tl = (unsigned int)strlen(auth);
|
||||
if (tl > 255) tl = 255; // sanity check
|
||||
b.append((uint8_t)tl);
|
||||
b.append((const void *)auth,tl);
|
||||
@ -108,6 +116,11 @@ public:
|
||||
return (p - startAt);
|
||||
}
|
||||
|
||||
inline void clear()
|
||||
{
|
||||
memset(this,0,sizeof(NetworkConfigRequestMetaData));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build ID (currently unused, must be 0)
|
||||
*/
|
||||
|
@ -23,9 +23,10 @@
|
||||
|
||||
#include "Constants.hpp"
|
||||
#include "InetAddress.hpp"
|
||||
#include "Dictionary.hpp"
|
||||
#include "Address.hpp"
|
||||
#include "Identity.hpp"
|
||||
#include "NetworkConfigRequestMetaData.hpp"
|
||||
#include "Buffer.hpp"
|
||||
|
||||
namespace ZeroTier {
|
||||
|
||||
@ -65,8 +66,8 @@ public:
|
||||
* @param signingId Identity that should be used to sign results -- must include private key
|
||||
* @param identity Originating peer ZeroTier identity
|
||||
* @param nwid 64-bit network ID
|
||||
* @param metaData Meta-data bundled with request (empty if none)
|
||||
* @param result Dictionary to receive resulting signed netconf on success
|
||||
* @param metaData Meta-data bundled with request (if any)
|
||||
* @param result Buffer to receive serialized network configuration data (any existing data in buffer is preserved)
|
||||
* @return Returns NETCONF_QUERY_OK if result dictionary is valid, or an error code on error
|
||||
*/
|
||||
virtual NetworkController::ResultCode doNetworkConfigRequest(
|
||||
@ -74,8 +75,8 @@ public:
|
||||
const Identity &signingId,
|
||||
const Identity &identity,
|
||||
uint64_t nwid,
|
||||
const Dictionary &metaData,
|
||||
Dictionary &result) = 0;
|
||||
const NetworkConfigRequestMetaData &metaData,
|
||||
Buffer<8194> &result) = 0;
|
||||
};
|
||||
|
||||
} // namespace ZeroTier
|
||||
|
@ -677,11 +677,9 @@ bool Node::shouldUsePathForZeroTierTraffic(const InetAddress &localAddress,const
|
||||
Mutex::Lock _l(_networks_m);
|
||||
for(std::vector< std::pair< uint64_t, SharedPtr<Network> > >::const_iterator i=_networks.begin();i!=_networks.end();++i) {
|
||||
if (i->second->hasConfig()) {
|
||||
std::vector<InetAddress> sips(i->second->config().staticIps());
|
||||
for(std::vector<InetAddress>::const_iterator a(sips.begin());a!=sips.end();++a) {
|
||||
if (a->containsAddress(remoteAddress)) {
|
||||
for(unsigned int k=0;k<i->second->config().staticIpCount;++k) {
|
||||
if (i->second->config().staticIps[k].containsAddress(remoteAddress))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -361,8 +361,8 @@ void Switch::onLocalEthernet(const SharedPtr<Network> &network,const MAC &from,c
|
||||
* themselves, they can look these addresses up with NDP and it will
|
||||
* work just fine. */
|
||||
if ((reinterpret_cast<const uint8_t *>(data)[6] == 0x3a)&&(reinterpret_cast<const uint8_t *>(data)[40] == 0x87)) { // ICMPv6 neighbor solicitation
|
||||
std::vector<InetAddress> sips(network->config().staticIps());
|
||||
for(std::vector<InetAddress>::const_iterator sip(sips.begin());sip!=sips.end();++sip) {
|
||||
for(unsigned int sipk=0;sipk<network->config().staticIpCount;++sipk) {
|
||||
const InetAddress *sip = &(network->config().staticIps[sipk]);
|
||||
if ((sip->ss_family == AF_INET6)&&(Utils::ntoh((uint16_t)reinterpret_cast<const struct sockaddr_in6 *>(&(*sip))->sin6_port) == 88)) {
|
||||
const uint8_t *my6 = reinterpret_cast<const uint8_t *>(reinterpret_cast<const struct sockaddr_in6 *>(&(*sip))->sin6_addr.s6_addr);
|
||||
if ((my6[0] == 0xfd)&&(my6[9] == 0x99)&&(my6[10] == 0x93)) { // ZT-RFC4193 == fd__:____:____:____:__99:93__:____:____ / 88
|
||||
@ -425,8 +425,8 @@ void Switch::onLocalEthernet(const SharedPtr<Network> &network,const MAC &from,c
|
||||
//TRACE("%.16llx: MULTICAST %s -> %s %s %u",network->id(),from.toString().c_str(),mg.toString().c_str(),etherTypeName(etherType),len);
|
||||
|
||||
RR->mc->send(
|
||||
((!network->config().isPublic())&&(network->config().com())) ? &(network->config().com()) : (const CertificateOfMembership *)0,
|
||||
network->config().multicastLimit(),
|
||||
((!network->config().isPublic())&&(network->config().com)) ? &(network->config().com) : (const CertificateOfMembership *)0,
|
||||
network->config().multicastLimit,
|
||||
RR->node->now(),
|
||||
network->id(),
|
||||
network->config().activeBridges(),
|
||||
@ -444,13 +444,13 @@ void Switch::onLocalEthernet(const SharedPtr<Network> &network,const MAC &from,c
|
||||
|
||||
Address toZT(to.toAddress(network->id())); // since in-network MACs are derived from addresses and network IDs, we can reverse this
|
||||
SharedPtr<Peer> toPeer(RR->topology->getPeer(toZT));
|
||||
const bool includeCom = ( (network->config().isPrivate()) && (network->config().com()) && ((!toPeer)||(toPeer->needsOurNetworkMembershipCertificate(network->id(),RR->node->now(),true))) );
|
||||
const bool includeCom = ( (network->config().isPrivate()) && (network->config().com) && ((!toPeer)||(toPeer->needsOurNetworkMembershipCertificate(network->id(),RR->node->now(),true))) );
|
||||
if ((fromBridged)||(includeCom)) {
|
||||
Packet outp(toZT,RR->identity.address(),Packet::VERB_EXT_FRAME);
|
||||
outp.append(network->id());
|
||||
if (includeCom) {
|
||||
outp.append((unsigned char)0x01); // 0x01 -- COM included
|
||||
network->config().com().serialize(outp);
|
||||
network->config().com.serialize(outp);
|
||||
} else {
|
||||
outp.append((unsigned char)0x00);
|
||||
}
|
||||
@ -513,9 +513,9 @@ void Switch::onLocalEthernet(const SharedPtr<Network> &network,const MAC &from,c
|
||||
SharedPtr<Peer> bridgePeer(RR->topology->getPeer(bridges[b]));
|
||||
Packet outp(bridges[b],RR->identity.address(),Packet::VERB_EXT_FRAME);
|
||||
outp.append(network->id());
|
||||
if ( (network->config().isPrivate()) && (network->config().com()) && ((!bridgePeer)||(bridgePeer->needsOurNetworkMembershipCertificate(network->id(),RR->node->now(),true))) ) {
|
||||
if ( (network->config().isPrivate()) && (network->config().com) && ((!bridgePeer)||(bridgePeer->needsOurNetworkMembershipCertificate(network->id(),RR->node->now(),true))) ) {
|
||||
outp.append((unsigned char)0x01); // 0x01 -- COM included
|
||||
network->config().com().serialize(outp);
|
||||
network->config().com.serialize(outp);
|
||||
} else {
|
||||
outp.append((unsigned char)0);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user