mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-05 03:53:44 +02:00
Refactor controller to send both old and new format netconf.
This commit is contained in:
parent
37b89b3944
commit
7ee3743c3d
2 changed files with 311 additions and 258 deletions
|
@ -49,6 +49,7 @@
|
||||||
#include "../node/Utils.hpp"
|
#include "../node/Utils.hpp"
|
||||||
#include "../node/CertificateOfMembership.hpp"
|
#include "../node/CertificateOfMembership.hpp"
|
||||||
#include "../node/NetworkConfig.hpp"
|
#include "../node/NetworkConfig.hpp"
|
||||||
|
#include "../node/NetworkConfigRequestMetaData.hpp"
|
||||||
#include "../node/InetAddress.hpp"
|
#include "../node/InetAddress.hpp"
|
||||||
#include "../node/MAC.hpp"
|
#include "../node/MAC.hpp"
|
||||||
#include "../node/Address.hpp"
|
#include "../node/Address.hpp"
|
||||||
|
@ -1170,6 +1171,7 @@ unsigned int SqliteNetworkController::_doCPGet(
|
||||||
// will contain an extra field called _testConf. This will contain several
|
// will contain an extra field called _testConf. This will contain several
|
||||||
// fields that report the result of doNetworkConfigRequest() for this member.
|
// fields that report the result of doNetworkConfigRequest() for this member.
|
||||||
std::string testFields;
|
std::string testFields;
|
||||||
|
/*
|
||||||
{
|
{
|
||||||
Identity testOutputSigningId;
|
Identity testOutputSigningId;
|
||||||
std::map<std::string,std::string>::const_iterator sid(urlArgs.find("testSigningId"));
|
std::map<std::string,std::string>::const_iterator sid(urlArgs.find("testSigningId"));
|
||||||
|
@ -1188,7 +1190,7 @@ unsigned int SqliteNetworkController::_doCPGet(
|
||||||
testOutputSigningId,
|
testOutputSigningId,
|
||||||
Identity(memberIdStr),
|
Identity(memberIdStr),
|
||||||
nwid,
|
nwid,
|
||||||
Dictionary(), // TODO: allow passing of meta-data for testing
|
NetworkConfigRequestMetaData(), // TODO: allow passing of meta-data for testing
|
||||||
testNetconf);
|
testNetconf);
|
||||||
char rcs[16];
|
char rcs[16];
|
||||||
Utils::snprintf(rcs,sizeof(rcs),"%d,\n",(int)rc);
|
Utils::snprintf(rcs,sizeof(rcs),"%d,\n",(int)rc);
|
||||||
|
@ -1209,6 +1211,7 @@ unsigned int SqliteNetworkController::_doCPGet(
|
||||||
testFields.append("\t},\n");
|
testFields.append("\t},\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
Utils::snprintf(json,sizeof(json),
|
Utils::snprintf(json,sizeof(json),
|
||||||
"{\n%s"
|
"{\n%s"
|
||||||
|
@ -1651,23 +1654,14 @@ NetworkController::ResultCode SqliteNetworkController::_doNetworkConfigRequest(c
|
||||||
{
|
{
|
||||||
// Assumes _lock is locked
|
// Assumes _lock is locked
|
||||||
|
|
||||||
const bool clientIs104 = (Utils::compareVersion(metaData.majorVersion,metaData.minorVersion,metaData.revision,1,0,4) >= 0);
|
if (((!signingId)||(!signingId.hasPrivate()))||(signingId.address().toInt() != (nwid >> 24))) {
|
||||||
|
return NetworkController::NETCONF_QUERY_INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
// Note: we can't reuse prepared statements that return const char * pointers without
|
// Note: we can't reuse prepared statements that return const char * pointers without
|
||||||
// making our own copy in e.g. a std::string first.
|
// making our own copy in e.g. a std::string first.
|
||||||
|
|
||||||
Dictionary legacy;
|
const bool clientIs104 = (Utils::compareVersion(metaData.majorVersion,metaData.minorVersion,metaData.revision,1,0,4) >= 0);
|
||||||
NetworkConfig nc;
|
|
||||||
|
|
||||||
if ((!signingId)||(!signingId.hasPrivate())) {
|
|
||||||
//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";
|
|
||||||
return NetworkController::NETCONF_QUERY_INTERNAL_SERVER_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
const uint64_t now = OSUtils::now();
|
const uint64_t now = OSUtils::now();
|
||||||
|
|
||||||
// Check rate limit circuit breaker to prevent flooding
|
// Check rate limit circuit breaker to prevent flooding
|
||||||
|
@ -1704,7 +1698,6 @@ NetworkController::ResultCode SqliteNetworkController::_doNetworkConfigRequest(c
|
||||||
sqlite3_bind_text(_sCreateOrReplaceNode,1,member.nodeId,10,SQLITE_STATIC);
|
sqlite3_bind_text(_sCreateOrReplaceNode,1,member.nodeId,10,SQLITE_STATIC);
|
||||||
sqlite3_bind_text(_sCreateOrReplaceNode,2,idstr.c_str(),-1,SQLITE_STATIC);
|
sqlite3_bind_text(_sCreateOrReplaceNode,2,idstr.c_str(),-1,SQLITE_STATIC);
|
||||||
if (sqlite3_step(_sCreateOrReplaceNode) != SQLITE_DONE) {
|
if (sqlite3_step(_sCreateOrReplaceNode) != SQLITE_DONE) {
|
||||||
netconf["error"] = "unable to create new Node record";
|
|
||||||
return NetworkController::NETCONF_QUERY_INTERNAL_SERVER_ERROR;
|
return NetworkController::NETCONF_QUERY_INTERNAL_SERVER_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1752,7 +1745,6 @@ NetworkController::ResultCode SqliteNetworkController::_doNetworkConfigRequest(c
|
||||||
sqlite3_bind_int(_sCreateMember,3,(member.authorized ? 1 : 0));
|
sqlite3_bind_int(_sCreateMember,3,(member.authorized ? 1 : 0));
|
||||||
sqlite3_bind_text(_sCreateMember,4,network.id,16,SQLITE_STATIC);
|
sqlite3_bind_text(_sCreateMember,4,network.id,16,SQLITE_STATIC);
|
||||||
if (sqlite3_step(_sCreateMember) != SQLITE_DONE) {
|
if (sqlite3_step(_sCreateMember) != SQLITE_DONE) {
|
||||||
netconf["error"] = "unable to create new member record";
|
|
||||||
return NetworkController::NETCONF_QUERY_INTERNAL_SERVER_ERROR;
|
return NetworkController::NETCONF_QUERY_INTERNAL_SERVER_ERROR;
|
||||||
}
|
}
|
||||||
member.rowid = (int64_t)sqlite3_last_insert_rowid(_db);
|
member.rowid = (int64_t)sqlite3_last_insert_rowid(_db);
|
||||||
|
@ -1773,9 +1765,6 @@ NetworkController::ResultCode SqliteNetworkController::_doNetworkConfigRequest(c
|
||||||
nextVC = (int64_t)sqlite3_column_int64(_sGetMaxNodeHistoryNetworkVisitCounter,0) + 1;
|
nextVC = (int64_t)sqlite3_column_int64(_sGetMaxNodeHistoryNetworkVisitCounter,0) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string mdstr(metaData.toString());
|
|
||||||
if (mdstr.length() > 1024)
|
|
||||||
mdstr = mdstr.substr(0,1024);
|
|
||||||
std::string fastr;
|
std::string fastr;
|
||||||
if (fromAddr)
|
if (fromAddr)
|
||||||
fastr = fromAddr.toString();
|
fastr = fromAddr.toString();
|
||||||
|
@ -1786,10 +1775,10 @@ NetworkController::ResultCode SqliteNetworkController::_doNetworkConfigRequest(c
|
||||||
sqlite3_bind_int64(_sAddNodeHistoryEntry,3,nextVC);
|
sqlite3_bind_int64(_sAddNodeHistoryEntry,3,nextVC);
|
||||||
sqlite3_bind_int(_sAddNodeHistoryEntry,4,(member.authorized ? 1 : 0));
|
sqlite3_bind_int(_sAddNodeHistoryEntry,4,(member.authorized ? 1 : 0));
|
||||||
sqlite3_bind_int64(_sAddNodeHistoryEntry,5,(long long)now);
|
sqlite3_bind_int64(_sAddNodeHistoryEntry,5,(long long)now);
|
||||||
sqlite3_bind_int(_sAddNodeHistoryEntry,6,(int)clientMajorVersion);
|
sqlite3_bind_int(_sAddNodeHistoryEntry,6,(int)metaData.majorVersion);
|
||||||
sqlite3_bind_int(_sAddNodeHistoryEntry,7,(int)clientMinorVersion);
|
sqlite3_bind_int(_sAddNodeHistoryEntry,7,(int)metaData.minorVersion);
|
||||||
sqlite3_bind_int(_sAddNodeHistoryEntry,8,(int)clientRevision);
|
sqlite3_bind_int(_sAddNodeHistoryEntry,8,(int)metaData.revision);
|
||||||
sqlite3_bind_text(_sAddNodeHistoryEntry,9,mdstr.c_str(),-1,SQLITE_STATIC);
|
sqlite3_bind_text(_sAddNodeHistoryEntry,9,"",-1,SQLITE_STATIC);
|
||||||
if (fastr.length() > 0)
|
if (fastr.length() > 0)
|
||||||
sqlite3_bind_text(_sAddNodeHistoryEntry,10,fastr.c_str(),-1,SQLITE_STATIC);
|
sqlite3_bind_text(_sAddNodeHistoryEntry,10,fastr.c_str(),-1,SQLITE_STATIC);
|
||||||
else sqlite3_bind_null(_sAddNodeHistoryEntry,10);
|
else sqlite3_bind_null(_sAddNodeHistoryEntry,10);
|
||||||
|
@ -1810,283 +1799,348 @@ NetworkController::ResultCode SqliteNetworkController::_doNetworkConfigRequest(c
|
||||||
if (!member.authorized)
|
if (!member.authorized)
|
||||||
return NetworkController::NETCONF_QUERY_ACCESS_DENIED;
|
return NetworkController::NETCONF_QUERY_ACCESS_DENIED;
|
||||||
|
|
||||||
// Create and sign netconf
|
// Create network configuration -- we create both legacy and new types and send both for backward compatibility
|
||||||
|
|
||||||
netconf.clear();
|
Dictionary legacy;
|
||||||
|
NetworkConfig nc;
|
||||||
|
|
||||||
|
nc.networkId = Utils::hexStrToU64(network.id);
|
||||||
|
nc.type = network.isPrivate ? ZT_NETWORK_TYPE_PRIVATE : ZT_NETWORK_TYPE_PUBLIC;
|
||||||
|
nc.timestamp = now;
|
||||||
|
nc.revision = network.revision;
|
||||||
|
nc.issuedTo = member.nodeId;
|
||||||
|
if (network.enableBroadcast) nc.flags |= ZT_NETWORKCONFIG_FLAG_ENABLE_BROADCAST;
|
||||||
|
if (network.allowPassiveBridging) nc.flags |= ZT_NETWORKCONFIG_FLAG_ALLOW_PASSIVE_BRIDGING;
|
||||||
|
memcpy(nc.name,network.name,std::min((unsigned int)ZT_MAX_NETWORK_SHORT_NAME_LENGTH,(unsigned int)strlen(network.name)));
|
||||||
|
|
||||||
|
char tss[24],rs[24];
|
||||||
|
Utils::snprintf(tss,sizeof(tss),"%.16llx",(unsigned long long)now);
|
||||||
|
Utils::snprintf(rs,sizeof(rs),"%.16llx",(unsigned long long)network.revision);
|
||||||
|
legacy[ZT_NETWORKCONFIG_DICT_KEY_TIMESTAMP] = tss;
|
||||||
|
legacy[ZT_NETWORKCONFIG_DICT_KEY_REVISION] = rs;
|
||||||
|
legacy[ZT_NETWORKCONFIG_DICT_KEY_NETWORK_ID] = network.id;
|
||||||
|
legacy[ZT_NETWORKCONFIG_DICT_KEY_ISSUED_TO] = member.nodeId;
|
||||||
|
legacy[ZT_NETWORKCONFIG_DICT_KEY_PRIVATE] = network.isPrivate ? "1" : "0";
|
||||||
|
legacy[ZT_NETWORKCONFIG_DICT_KEY_NAME] = (network.name) ? network.name : "";
|
||||||
|
legacy[ZT_NETWORKCONFIG_DICT_KEY_ENABLE_BROADCAST] = network.enableBroadcast ? "1" : "0";
|
||||||
|
legacy[ZT_NETWORKCONFIG_DICT_KEY_ALLOW_PASSIVE_BRIDGING] = network.allowPassiveBridging ? "1" : "0";
|
||||||
|
|
||||||
|
{ // TODO: right now only etherTypes are supported in rules
|
||||||
|
std::vector<int> allowedEtherTypes;
|
||||||
|
sqlite3_reset(_sGetEtherTypesFromRuleTable);
|
||||||
|
sqlite3_bind_text(_sGetEtherTypesFromRuleTable,1,network.id,16,SQLITE_STATIC);
|
||||||
|
while (sqlite3_step(_sGetEtherTypesFromRuleTable) == SQLITE_ROW) {
|
||||||
|
if (sqlite3_column_type(_sGetEtherTypesFromRuleTable,0) == SQLITE_NULL) {
|
||||||
|
allowedEtherTypes.clear();
|
||||||
|
allowedEtherTypes.push_back(0); // NULL 'allow' matches ANY
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
int et = sqlite3_column_int(_sGetEtherTypesFromRuleTable,0);
|
||||||
|
if ((et >= 0)&&(et <= 0xffff))
|
||||||
|
allowedEtherTypes.push_back(et);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::sort(allowedEtherTypes.begin(),allowedEtherTypes.end());
|
||||||
|
allowedEtherTypes.erase(std::unique(allowedEtherTypes.begin(),allowedEtherTypes.end()),allowedEtherTypes.end());
|
||||||
|
|
||||||
|
for(long i=0,k=0;((i<(long)allowedEtherTypes.size())&&(k<ZT_MAX_NETWORK_RULES));++i) {
|
||||||
|
if (allowedEtherTypes[i] > 0) {
|
||||||
|
nc.rules[k].t = ZT_NETWORK_RULE_MATCH_ETHERTYPE;
|
||||||
|
nc.rules[k].v.etherType = (uint16_t)allowedEtherTypes[i];
|
||||||
|
++k;
|
||||||
|
}
|
||||||
|
nc.rules[k++].t = ZT_NETWORK_RULE_ACTION_ACCEPT;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string allowedEtherTypesCsv;
|
||||||
|
for(std::vector<int>::const_iterator i(allowedEtherTypes.begin());i!=allowedEtherTypes.end();++i) {
|
||||||
|
if (allowedEtherTypesCsv.length())
|
||||||
|
allowedEtherTypesCsv.push_back(',');
|
||||||
|
char tmp[16];
|
||||||
|
Utils::snprintf(tmp,sizeof(tmp),"%.4x",(unsigned int)*i);
|
||||||
|
allowedEtherTypesCsv.append(tmp);
|
||||||
|
}
|
||||||
|
legacy[ZT_NETWORKCONFIG_DICT_KEY_ALLOWED_ETHERNET_TYPES] = allowedEtherTypesCsv;
|
||||||
|
}
|
||||||
|
|
||||||
|
nc.multicastLimit = network.multicastLimit;
|
||||||
|
if (network.multicastLimit > 0) {
|
||||||
|
char ml[16];
|
||||||
|
Utils::snprintf(ml,sizeof(ml),"%lx",(unsigned long)network.multicastLimit);
|
||||||
|
legacy[ZT_NETWORKCONFIG_DICT_KEY_MULTICAST_LIMIT] = ml;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool amActiveBridge = false;
|
||||||
{
|
{
|
||||||
char tss[24],rs[24];
|
std::string activeBridges;
|
||||||
Utils::snprintf(tss,sizeof(tss),"%.16llx",(unsigned long long)now);
|
sqlite3_reset(_sGetActiveBridges);
|
||||||
Utils::snprintf(rs,sizeof(rs),"%.16llx",(unsigned long long)network.revision);
|
sqlite3_bind_text(_sGetActiveBridges,1,network.id,16,SQLITE_STATIC);
|
||||||
netconf[ZT_NETWORKCONFIG_DICT_KEY_TIMESTAMP] = tss;
|
while (sqlite3_step(_sGetActiveBridges) == SQLITE_ROW) {
|
||||||
netconf[ZT_NETWORKCONFIG_DICT_KEY_REVISION] = rs;
|
const char *ab = (const char *)sqlite3_column_text(_sGetActiveBridges,0);
|
||||||
netconf[ZT_NETWORKCONFIG_DICT_KEY_NETWORK_ID] = network.id;
|
if ((ab)&&(strlen(ab) == 10)) {
|
||||||
netconf[ZT_NETWORKCONFIG_DICT_KEY_ISSUED_TO] = member.nodeId;
|
const uint64_t ab2 = Utils::hexStrToU64(ab);
|
||||||
netconf[ZT_NETWORKCONFIG_DICT_KEY_PRIVATE] = network.isPrivate ? "1" : "0";
|
if ((ab2)&&(nc.specialistCount < ZT_MAX_NETWORK_SPECIALISTS)) {
|
||||||
netconf[ZT_NETWORKCONFIG_DICT_KEY_NAME] = (network.name) ? network.name : "";
|
nc.specialists[nc.specialistCount++] = ab2 | ZT_NETWORKCONFIG_SPECIALIST_TYPE_ACTIVE_BRIDGE;
|
||||||
netconf[ZT_NETWORKCONFIG_DICT_KEY_ENABLE_BROADCAST] = network.enableBroadcast ? "1" : "0";
|
|
||||||
netconf[ZT_NETWORKCONFIG_DICT_KEY_ALLOW_PASSIVE_BRIDGING] = network.allowPassiveBridging ? "1" : "0";
|
|
||||||
|
|
||||||
{ // TODO: right now only etherTypes are supported in rules
|
|
||||||
std::vector<int> allowedEtherTypes;
|
|
||||||
sqlite3_reset(_sGetEtherTypesFromRuleTable);
|
|
||||||
sqlite3_bind_text(_sGetEtherTypesFromRuleTable,1,network.id,16,SQLITE_STATIC);
|
|
||||||
while (sqlite3_step(_sGetEtherTypesFromRuleTable) == SQLITE_ROW) {
|
|
||||||
if (sqlite3_column_type(_sGetEtherTypesFromRuleTable,0) == SQLITE_NULL) {
|
|
||||||
allowedEtherTypes.clear();
|
|
||||||
allowedEtherTypes.push_back(0); // NULL 'allow' matches ANY
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
int et = sqlite3_column_int(_sGetEtherTypesFromRuleTable,0);
|
|
||||||
if ((et >= 0)&&(et <= 0xffff))
|
|
||||||
allowedEtherTypes.push_back(et);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
std::sort(allowedEtherTypes.begin(),allowedEtherTypes.end());
|
|
||||||
allowedEtherTypes.erase(std::unique(allowedEtherTypes.begin(),allowedEtherTypes.end()),allowedEtherTypes.end());
|
|
||||||
std::string allowedEtherTypesCsv;
|
|
||||||
for(std::vector<int>::const_iterator i(allowedEtherTypes.begin());i!=allowedEtherTypes.end();++i) {
|
|
||||||
if (allowedEtherTypesCsv.length())
|
|
||||||
allowedEtherTypesCsv.push_back(',');
|
|
||||||
char tmp[16];
|
|
||||||
Utils::snprintf(tmp,sizeof(tmp),"%.4x",(unsigned int)*i);
|
|
||||||
allowedEtherTypesCsv.append(tmp);
|
|
||||||
}
|
|
||||||
netconf[ZT_NETWORKCONFIG_DICT_KEY_ALLOWED_ETHERNET_TYPES] = allowedEtherTypesCsv;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (network.multicastLimit > 0) {
|
if (activeBridges.length())
|
||||||
char ml[16];
|
activeBridges.push_back(',');
|
||||||
Utils::snprintf(ml,sizeof(ml),"%lx",(unsigned long)network.multicastLimit);
|
activeBridges.append(ab);
|
||||||
netconf[ZT_NETWORKCONFIG_DICT_KEY_MULTICAST_LIMIT] = ml;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool amActiveBridge = false;
|
if (!strcmp(member.nodeId,ab))
|
||||||
{
|
amActiveBridge = true;
|
||||||
std::string activeBridges;
|
|
||||||
sqlite3_reset(_sGetActiveBridges);
|
|
||||||
sqlite3_bind_text(_sGetActiveBridges,1,network.id,16,SQLITE_STATIC);
|
|
||||||
while (sqlite3_step(_sGetActiveBridges) == SQLITE_ROW) {
|
|
||||||
const char *ab = (const char *)sqlite3_column_text(_sGetActiveBridges,0);
|
|
||||||
if ((ab)&&(strlen(ab) == 10)) {
|
|
||||||
if (activeBridges.length())
|
|
||||||
activeBridges.push_back(',');
|
|
||||||
activeBridges.append(ab);
|
|
||||||
if (!strcmp(member.nodeId,ab))
|
|
||||||
amActiveBridge = true;
|
|
||||||
}
|
|
||||||
if (activeBridges.length() > 1024) // sanity check -- you can't have too many active bridges at the moment
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if (activeBridges.length())
|
if (activeBridges.length() > 1024) // sanity check -- you can't have too many active bridges at the moment
|
||||||
netconf[ZT_NETWORKCONFIG_DICT_KEY_ACTIVE_BRIDGES] = activeBridges;
|
break;
|
||||||
}
|
}
|
||||||
|
if (activeBridges.length())
|
||||||
|
legacy[ZT_NETWORKCONFIG_DICT_KEY_ACTIVE_BRIDGES] = activeBridges;
|
||||||
|
}
|
||||||
|
|
||||||
// Do not send relays to 1.1.0 since it had a serious bug in using them
|
// Do not send relays to 1.1.0 since it had a serious bug in using them
|
||||||
// 1.1.0 will still work, it'll just fall back to roots instead of using network preferred relays
|
// 1.1.0 will still work, it'll just fall back to roots instead of using network preferred relays
|
||||||
if (!((clientMajorVersion == 1)&&(clientMinorVersion == 1)&&(clientRevision == 0))) {
|
if (!((metaData.majorVersion == 1)&&(metaData.minorVersion == 1)&&(metaData.revision == 0))) {
|
||||||
std::string relays;
|
std::string relays;
|
||||||
sqlite3_reset(_sGetRelays);
|
sqlite3_reset(_sGetRelays);
|
||||||
sqlite3_bind_text(_sGetRelays,1,network.id,16,SQLITE_STATIC);
|
sqlite3_bind_text(_sGetRelays,1,network.id,16,SQLITE_STATIC);
|
||||||
while (sqlite3_step(_sGetRelays) == SQLITE_ROW) {
|
while (sqlite3_step(_sGetRelays) == SQLITE_ROW) {
|
||||||
const char *n = (const char *)sqlite3_column_text(_sGetRelays,0);
|
const char *n = (const char *)sqlite3_column_text(_sGetRelays,0);
|
||||||
const char *a = (const char *)sqlite3_column_text(_sGetRelays,1);
|
const char *a = (const char *)sqlite3_column_text(_sGetRelays,1);
|
||||||
if ((n)&&(a)) {
|
if ((n)&&(a)) {
|
||||||
Address node(n);
|
Address node(n);
|
||||||
InetAddress addr(a);
|
InetAddress addr(a);
|
||||||
if ((node)&&(addr)) {
|
if (node) {
|
||||||
if (relays.length())
|
bool sf = false;
|
||||||
relays.push_back(',');
|
for(unsigned int k=0;k<nc.specialistCount;++k) {
|
||||||
relays.append(node.toString());
|
if ((nc.specialists[k] & 0xffffffffffULL) == node.toInt()) {
|
||||||
|
nc.specialists[k] |= ZT_NETWORKCONFIG_SPECIALIST_TYPE_NETWORK_PREFERRED_RELAY;
|
||||||
|
sf = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((!sf)&&(nc.specialistCount < ZT_MAX_NETWORK_SPECIALISTS)) {
|
||||||
|
nc.specialists[nc.specialistCount++] = node.toInt() | ZT_NETWORKCONFIG_SPECIALIST_TYPE_NETWORK_PREFERRED_RELAY;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (relays.length())
|
||||||
|
relays.push_back(',');
|
||||||
|
relays.append(node.toString());
|
||||||
|
if (addr) {
|
||||||
relays.push_back(';');
|
relays.push_back(';');
|
||||||
relays.append(addr.toString());
|
relays.append(addr.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (relays.length())
|
|
||||||
netconf[ZT_NETWORKCONFIG_DICT_KEY_RELAYS] = relays;
|
|
||||||
}
|
}
|
||||||
|
if (relays.length())
|
||||||
|
legacy[ZT_NETWORKCONFIG_DICT_KEY_RELAYS] = relays;
|
||||||
|
}
|
||||||
|
|
||||||
{
|
// TODO: this should be routes, going to redo DB
|
||||||
char tmp[128];
|
/*
|
||||||
std::string gateways;
|
{
|
||||||
sqlite3_reset(_sGetGateways);
|
char tmp[128];
|
||||||
sqlite3_bind_text(_sGetGateways,1,network.id,16,SQLITE_STATIC);
|
std::string gateways;
|
||||||
while (sqlite3_step(_sGetGateways) == SQLITE_ROW) {
|
sqlite3_reset(_sGetGateways);
|
||||||
const unsigned char *ip = (const unsigned char *)sqlite3_column_blob(_sGetGateways,0);
|
sqlite3_bind_text(_sGetGateways,1,network.id,16,SQLITE_STATIC);
|
||||||
switch(sqlite3_column_int(_sGetGateways,1)) { // ipVersion
|
while (sqlite3_step(_sGetGateways) == SQLITE_ROW) {
|
||||||
case 4:
|
const unsigned char *ip = (const unsigned char *)sqlite3_column_blob(_sGetGateways,0);
|
||||||
Utils::snprintf(tmp,sizeof(tmp),"%s%d.%d.%d.%d/%d",
|
switch(sqlite3_column_int(_sGetGateways,1)) { // ipVersion
|
||||||
(gateways.length() > 0) ? "," : "",
|
case 4:
|
||||||
(int)ip[12],
|
Utils::snprintf(tmp,sizeof(tmp),"%s%d.%d.%d.%d/%d",
|
||||||
(int)ip[13],
|
(gateways.length() > 0) ? "," : "",
|
||||||
(int)ip[14],
|
(int)ip[12],
|
||||||
(int)ip[15],
|
(int)ip[13],
|
||||||
(int)sqlite3_column_int(_sGetGateways,2)); // metric
|
(int)ip[14],
|
||||||
gateways.append(tmp);
|
(int)ip[15],
|
||||||
break;
|
(int)sqlite3_column_int(_sGetGateways,2)); // metric
|
||||||
case 6:
|
gateways.append(tmp);
|
||||||
Utils::snprintf(tmp,sizeof(tmp),"%s%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x/%d",
|
break;
|
||||||
(gateways.length() > 0) ? "," : "",
|
case 6:
|
||||||
(int)ip[0],
|
Utils::snprintf(tmp,sizeof(tmp),"%s%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x/%d",
|
||||||
(int)ip[1],
|
(gateways.length() > 0) ? "," : "",
|
||||||
(int)ip[2],
|
(int)ip[0],
|
||||||
(int)ip[3],
|
(int)ip[1],
|
||||||
(int)ip[4],
|
(int)ip[2],
|
||||||
(int)ip[5],
|
(int)ip[3],
|
||||||
(int)ip[6],
|
(int)ip[4],
|
||||||
(int)ip[7],
|
(int)ip[5],
|
||||||
(int)ip[8],
|
(int)ip[6],
|
||||||
(int)ip[9],
|
(int)ip[7],
|
||||||
(int)ip[10],
|
(int)ip[8],
|
||||||
(int)ip[11],
|
(int)ip[9],
|
||||||
(int)ip[12],
|
(int)ip[10],
|
||||||
(int)ip[13],
|
(int)ip[11],
|
||||||
(int)ip[14],
|
(int)ip[12],
|
||||||
(int)ip[15],
|
(int)ip[13],
|
||||||
(int)sqlite3_column_int(_sGetGateways,2)); // metric
|
(int)ip[14],
|
||||||
gateways.append(tmp);
|
(int)ip[15],
|
||||||
break;
|
(int)sqlite3_column_int(_sGetGateways,2)); // metric
|
||||||
}
|
gateways.append(tmp);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (gateways.length())
|
|
||||||
netconf[ZT_NETWORKCONFIG_DICT_KEY_GATEWAYS] = gateways;
|
|
||||||
}
|
}
|
||||||
|
if (gateways.length())
|
||||||
|
netconf[ZT_NETWORKCONFIG_DICT_KEY_GATEWAYS] = gateways;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
if ((network.v4AssignMode)&&(!strcmp(network.v4AssignMode,"zt"))) {
|
if ((network.v4AssignMode)&&(!strcmp(network.v4AssignMode,"zt"))) {
|
||||||
std::string v4s;
|
std::string v4s;
|
||||||
|
std::vector< std::pair<uint32_t,int> > routedNetworks;
|
||||||
|
bool haveStaticIpAssignment = false;
|
||||||
|
|
||||||
// Get existing IPv4 IP assignments and network routes -- keep routes in a
|
sqlite3_reset(_sGetIpAssignmentsForNode);
|
||||||
// vector for use in auto-assign if we need them.
|
sqlite3_bind_text(_sGetIpAssignmentsForNode,1,network.id,16,SQLITE_STATIC);
|
||||||
std::vector< std::pair<uint32_t,int> > routedNetworks;
|
sqlite3_bind_text(_sGetIpAssignmentsForNode,2,member.nodeId,10,SQLITE_STATIC);
|
||||||
bool haveStaticIpAssignment = false;
|
sqlite3_bind_int(_sGetIpAssignmentsForNode,3,4); // 4 == IPv4
|
||||||
sqlite3_reset(_sGetIpAssignmentsForNode);
|
while (sqlite3_step(_sGetIpAssignmentsForNode) == SQLITE_ROW) {
|
||||||
sqlite3_bind_text(_sGetIpAssignmentsForNode,1,network.id,16,SQLITE_STATIC);
|
const unsigned char *const ip = (const unsigned char *)sqlite3_column_blob(_sGetIpAssignmentsForNode,1);
|
||||||
sqlite3_bind_text(_sGetIpAssignmentsForNode,2,member.nodeId,10,SQLITE_STATIC);
|
if ((!ip)||(sqlite3_column_bytes(_sGetIpAssignmentsForNode,1) != 16))
|
||||||
sqlite3_bind_int(_sGetIpAssignmentsForNode,3,4); // 4 == IPv4
|
continue;
|
||||||
while (sqlite3_step(_sGetIpAssignmentsForNode) == SQLITE_ROW) {
|
int ipNetmaskBits = sqlite3_column_int(_sGetIpAssignmentsForNode,2);
|
||||||
const unsigned char *ip = (const unsigned char *)sqlite3_column_blob(_sGetIpAssignmentsForNode,1);
|
if ((ipNetmaskBits <= 0)||(ipNetmaskBits > 32))
|
||||||
if ((!ip)||(sqlite3_column_bytes(_sGetIpAssignmentsForNode,1) != 16))
|
continue;
|
||||||
|
|
||||||
|
char ips[32];
|
||||||
|
Utils::snprintf(ips,sizeof(ips),"%d.%d.%d.%d/%d",(int)ip[12],(int)ip[13],(int)ip[14],(int)ip[15],ipNetmaskBits);
|
||||||
|
|
||||||
|
const IpAssignmentType ipt = (IpAssignmentType)sqlite3_column_int(_sGetIpAssignmentsForNode,0);
|
||||||
|
switch(ipt) {
|
||||||
|
case ZT_IP_ASSIGNMENT_TYPE_ADDRESS:
|
||||||
|
haveStaticIpAssignment = true;
|
||||||
|
break;
|
||||||
|
case ZT_IP_ASSIGNMENT_TYPE_NETWORK:
|
||||||
|
routedNetworks.push_back(std::pair<uint32_t,int>(Utils::ntoh(*(reinterpret_cast<const uint32_t *>(ip + 12))),ipNetmaskBits));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
continue;
|
continue;
|
||||||
int ipNetmaskBits = sqlite3_column_int(_sGetIpAssignmentsForNode,2);
|
|
||||||
if ((ipNetmaskBits <= 0)||(ipNetmaskBits > 32))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
const IpAssignmentType ipt = (IpAssignmentType)sqlite3_column_int(_sGetIpAssignmentsForNode,0);
|
|
||||||
switch(ipt) {
|
|
||||||
case ZT_IP_ASSIGNMENT_TYPE_ADDRESS:
|
|
||||||
haveStaticIpAssignment = true;
|
|
||||||
break;
|
|
||||||
case ZT_IP_ASSIGNMENT_TYPE_NETWORK:
|
|
||||||
routedNetworks.push_back(std::pair<uint32_t,int>(Utils::ntoh(*(reinterpret_cast<const uint32_t *>(ip + 12))),ipNetmaskBits));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1.0.4 or newer clients support network routes in addition to IPs.
|
|
||||||
// Older clients only support IP address / netmask entries.
|
|
||||||
if ((clientIs104)||(ipt == ZT_IP_ASSIGNMENT_TYPE_ADDRESS)) {
|
|
||||||
char tmp[32];
|
|
||||||
Utils::snprintf(tmp,sizeof(tmp),"%d.%d.%d.%d/%d",(int)ip[12],(int)ip[13],(int)ip[14],(int)ip[15],ipNetmaskBits);
|
|
||||||
if (v4s.length())
|
|
||||||
v4s.push_back(',');
|
|
||||||
v4s.append(tmp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!haveStaticIpAssignment)&&(!amActiveBridge)) {
|
if ((ipt == ZT_IP_ASSIGNMENT_TYPE_ADDRESS)&&(nc.staticIpCount < ZT_MAX_ZT_ASSIGNED_ADDRESSES)) {
|
||||||
// Attempt to auto-assign an IPv4 address from an available routed pool
|
InetAddress tmp2(ips);
|
||||||
sqlite3_reset(_sGetIpAssignmentPools);
|
if (tmp2)
|
||||||
sqlite3_bind_text(_sGetIpAssignmentPools,1,network.id,16,SQLITE_STATIC);
|
nc.staticIps[nc.staticIpCount++] = tmp2;
|
||||||
sqlite3_bind_int(_sGetIpAssignmentPools,2,4); // 4 == IPv4
|
}
|
||||||
|
// TODO: add routed networks to nc
|
||||||
|
|
||||||
while (sqlite3_step(_sGetIpAssignmentPools) == SQLITE_ROW) {
|
// 1.0.4 or newer clients support network routes in addition to IPs.
|
||||||
const unsigned char *ipRangeStartB = reinterpret_cast<const unsigned char *>(sqlite3_column_blob(_sGetIpAssignmentPools,0));
|
// Older clients only support IP address / netmask entries.
|
||||||
const unsigned char *ipRangeEndB = reinterpret_cast<const unsigned char *>(sqlite3_column_blob(_sGetIpAssignmentPools,1));
|
if ((clientIs104)||(ipt == ZT_IP_ASSIGNMENT_TYPE_ADDRESS)) {
|
||||||
if ((!ipRangeStartB)||(!ipRangeEndB)||(sqlite3_column_bytes(_sGetIpAssignmentPools,0) != 16)||(sqlite3_column_bytes(_sGetIpAssignmentPools,1) != 16))
|
if (v4s.length())
|
||||||
continue;
|
v4s.push_back(',');
|
||||||
|
v4s.append(ips);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t ipRangeStart = Utils::ntoh(*(reinterpret_cast<const uint32_t *>(ipRangeStartB + 12)));
|
if ((!haveStaticIpAssignment)&&(!amActiveBridge)) {
|
||||||
uint32_t ipRangeEnd = Utils::ntoh(*(reinterpret_cast<const uint32_t *>(ipRangeEndB + 12)));
|
// Attempt to auto-assign an IPv4 address from an available routed pool
|
||||||
if ((ipRangeEnd <= ipRangeStart)||(ipRangeStart == 0))
|
sqlite3_reset(_sGetIpAssignmentPools);
|
||||||
continue;
|
sqlite3_bind_text(_sGetIpAssignmentPools,1,network.id,16,SQLITE_STATIC);
|
||||||
uint32_t ipRangeLen = ipRangeEnd - ipRangeStart;
|
sqlite3_bind_int(_sGetIpAssignmentPools,2,4); // 4 == IPv4
|
||||||
|
|
||||||
// Start with the LSB of the member's address
|
while (sqlite3_step(_sGetIpAssignmentPools) == SQLITE_ROW) {
|
||||||
uint32_t ipTrialCounter = (uint32_t)(identity.address().toInt() & 0xffffffff);
|
const unsigned char *ipRangeStartB = reinterpret_cast<const unsigned char *>(sqlite3_column_blob(_sGetIpAssignmentPools,0));
|
||||||
|
const unsigned char *ipRangeEndB = reinterpret_cast<const unsigned char *>(sqlite3_column_blob(_sGetIpAssignmentPools,1));
|
||||||
|
if ((!ipRangeStartB)||(!ipRangeEndB)||(sqlite3_column_bytes(_sGetIpAssignmentPools,0) != 16)||(sqlite3_column_bytes(_sGetIpAssignmentPools,1) != 16))
|
||||||
|
continue;
|
||||||
|
|
||||||
for(uint32_t k=ipRangeStart,l=0;(k<=ipRangeEnd)&&(l < 1000000);++k,++l) {
|
uint32_t ipRangeStart = Utils::ntoh(*(reinterpret_cast<const uint32_t *>(ipRangeStartB + 12)));
|
||||||
uint32_t ip = (ipRangeLen > 0) ? (ipRangeStart + (ipTrialCounter % ipRangeLen)) : ipRangeStart;
|
uint32_t ipRangeEnd = Utils::ntoh(*(reinterpret_cast<const uint32_t *>(ipRangeEndB + 12)));
|
||||||
++ipTrialCounter;
|
if ((ipRangeEnd <= ipRangeStart)||(ipRangeStart == 0))
|
||||||
if ((ip & 0x000000ff) == 0x000000ff)
|
continue;
|
||||||
continue; // don't allow addresses that end in .255
|
uint32_t ipRangeLen = ipRangeEnd - ipRangeStart;
|
||||||
|
|
||||||
for(std::vector< std::pair<uint32_t,int> >::const_iterator r(routedNetworks.begin());r!=routedNetworks.end();++r) {
|
// Start with the LSB of the member's address
|
||||||
if ((ip & (0xffffffff << (32 - r->second))) == r->first) {
|
uint32_t ipTrialCounter = (uint32_t)(identity.address().toInt() & 0xffffffff);
|
||||||
// IP is included in a routed network, so check if it's allocated
|
|
||||||
|
|
||||||
uint32_t ipBlob[4];
|
for(uint32_t k=ipRangeStart,l=0;(k<=ipRangeEnd)&&(l < 1000000);++k,++l) {
|
||||||
ipBlob[0] = 0; ipBlob[1] = 0; ipBlob[2] = 0; ipBlob[3] = Utils::hton(ip);
|
uint32_t ip = (ipRangeLen > 0) ? (ipRangeStart + (ipTrialCounter % ipRangeLen)) : ipRangeStart;
|
||||||
|
++ipTrialCounter;
|
||||||
|
if ((ip & 0x000000ff) == 0x000000ff)
|
||||||
|
continue; // don't allow addresses that end in .255
|
||||||
|
|
||||||
sqlite3_reset(_sCheckIfIpIsAllocated);
|
for(std::vector< std::pair<uint32_t,int> >::const_iterator r(routedNetworks.begin());r!=routedNetworks.end();++r) {
|
||||||
sqlite3_bind_text(_sCheckIfIpIsAllocated,1,network.id,16,SQLITE_STATIC);
|
if ((ip & (0xffffffff << (32 - r->second))) == r->first) {
|
||||||
sqlite3_bind_blob(_sCheckIfIpIsAllocated,2,(const void *)ipBlob,16,SQLITE_STATIC);
|
// IP is included in a routed network, so check if it's allocated
|
||||||
sqlite3_bind_int(_sCheckIfIpIsAllocated,3,4); // 4 == IPv4
|
|
||||||
sqlite3_bind_int(_sCheckIfIpIsAllocated,4,(int)ZT_IP_ASSIGNMENT_TYPE_ADDRESS);
|
uint32_t ipBlob[4];
|
||||||
if (sqlite3_step(_sCheckIfIpIsAllocated) != SQLITE_ROW) {
|
ipBlob[0] = 0; ipBlob[1] = 0; ipBlob[2] = 0; ipBlob[3] = Utils::hton(ip);
|
||||||
// No rows returned, so the IP is available
|
|
||||||
sqlite3_reset(_sAllocateIp);
|
sqlite3_reset(_sCheckIfIpIsAllocated);
|
||||||
sqlite3_bind_text(_sAllocateIp,1,network.id,16,SQLITE_STATIC);
|
sqlite3_bind_text(_sCheckIfIpIsAllocated,1,network.id,16,SQLITE_STATIC);
|
||||||
sqlite3_bind_text(_sAllocateIp,2,member.nodeId,10,SQLITE_STATIC);
|
sqlite3_bind_blob(_sCheckIfIpIsAllocated,2,(const void *)ipBlob,16,SQLITE_STATIC);
|
||||||
sqlite3_bind_int(_sAllocateIp,3,(int)ZT_IP_ASSIGNMENT_TYPE_ADDRESS);
|
sqlite3_bind_int(_sCheckIfIpIsAllocated,3,4); // 4 == IPv4
|
||||||
sqlite3_bind_blob(_sAllocateIp,4,(const void *)ipBlob,16,SQLITE_STATIC);
|
sqlite3_bind_int(_sCheckIfIpIsAllocated,4,(int)ZT_IP_ASSIGNMENT_TYPE_ADDRESS);
|
||||||
sqlite3_bind_int(_sAllocateIp,5,r->second); // IP netmask bits from matching route
|
if (sqlite3_step(_sCheckIfIpIsAllocated) != SQLITE_ROW) {
|
||||||
sqlite3_bind_int(_sAllocateIp,6,4); // 4 == IPv4
|
// No rows returned, so the IP is available
|
||||||
if (sqlite3_step(_sAllocateIp) == SQLITE_DONE) {
|
sqlite3_reset(_sAllocateIp);
|
||||||
char tmp[32];
|
sqlite3_bind_text(_sAllocateIp,1,network.id,16,SQLITE_STATIC);
|
||||||
Utils::snprintf(tmp,sizeof(tmp),"%d.%d.%d.%d/%d",(int)((ip >> 24) & 0xff),(int)((ip >> 16) & 0xff),(int)((ip >> 8) & 0xff),(int)(ip & 0xff),r->second);
|
sqlite3_bind_text(_sAllocateIp,2,member.nodeId,10,SQLITE_STATIC);
|
||||||
if (v4s.length())
|
sqlite3_bind_int(_sAllocateIp,3,(int)ZT_IP_ASSIGNMENT_TYPE_ADDRESS);
|
||||||
v4s.push_back(',');
|
sqlite3_bind_blob(_sAllocateIp,4,(const void *)ipBlob,16,SQLITE_STATIC);
|
||||||
v4s.append(tmp);
|
sqlite3_bind_int(_sAllocateIp,5,r->second); // IP netmask bits from matching route
|
||||||
haveStaticIpAssignment = true; // break outer loop
|
sqlite3_bind_int(_sAllocateIp,6,4); // 4 == IPv4
|
||||||
|
if (sqlite3_step(_sAllocateIp) == SQLITE_DONE) {
|
||||||
|
char ips[32];
|
||||||
|
Utils::snprintf(ips,sizeof(ips),"%d.%d.%d.%d/%d",(int)((ip >> 24) & 0xff),(int)((ip >> 16) & 0xff),(int)((ip >> 8) & 0xff),(int)(ip & 0xff),r->second);
|
||||||
|
|
||||||
|
if (nc.staticIpCount < ZT_MAX_ZT_ASSIGNED_ADDRESSES) {
|
||||||
|
InetAddress tmp2(ips);
|
||||||
|
if (tmp2)
|
||||||
|
nc.staticIps[nc.staticIpCount++] = tmp2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (v4s.length())
|
||||||
|
v4s.push_back(',');
|
||||||
|
v4s.append(ips);
|
||||||
|
|
||||||
|
haveStaticIpAssignment = true; // break outer loop
|
||||||
}
|
}
|
||||||
|
|
||||||
break; // stop checking routed networks
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (haveStaticIpAssignment)
|
break; // stop checking routed networks
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (haveStaticIpAssignment)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (v4s.length())
|
|
||||||
netconf[ZT_NETWORKCONFIG_DICT_KEY_IPV4_STATIC] = v4s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((network.v6AssignMode)&&(!strcmp(network.v6AssignMode,"rfc4193"))) {
|
if (v4s.length())
|
||||||
InetAddress rfc4193Addr(InetAddress::makeIpv6rfc4193(nwid,identity.address().toInt()));
|
legacy[ZT_NETWORKCONFIG_DICT_KEY_IPV4_STATIC] = v4s;
|
||||||
netconf[ZT_NETWORKCONFIG_DICT_KEY_IPV6_STATIC] = rfc4193Addr.toString();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (network.isPrivate) {
|
if ((network.v6AssignMode)&&(!strcmp(network.v6AssignMode,"rfc4193"))) {
|
||||||
CertificateOfMembership com(now,ZT_NETWORK_COM_DEFAULT_REVISION_MAX_DELTA,nwid,identity.address());
|
InetAddress rfc4193Addr(InetAddress::makeIpv6rfc4193(nwid,identity.address().toInt()));
|
||||||
if (com.sign(signingId)) // basically can't fail unless our identity is invalid
|
legacy[ZT_NETWORKCONFIG_DICT_KEY_IPV6_STATIC] = rfc4193Addr.toString();
|
||||||
netconf[ZT_NETWORKCONFIG_DICT_KEY_CERTIFICATE_OF_MEMBERSHIP] = com.toString();
|
if (nc.staticIpCount < ZT_MAX_ZT_ASSIGNED_ADDRESSES)
|
||||||
else {
|
nc.staticIps[nc.staticIpCount++] = rfc4193Addr;
|
||||||
netconf["error"] = "unable to sign COM";
|
}
|
||||||
return NETCONF_QUERY_INTERNAL_SERVER_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!netconf.sign(signingId,now)) {
|
if (network.isPrivate) {
|
||||||
netconf["error"] = "unable to sign netconf dictionary";
|
CertificateOfMembership com(now,ZT_NETWORK_COM_DEFAULT_REVISION_MAX_DELTA,nwid,identity.address());
|
||||||
|
if (com.sign(signingId)) {
|
||||||
|
legacy[ZT_NETWORKCONFIG_DICT_KEY_CERTIFICATE_OF_MEMBERSHIP] = com.toString();
|
||||||
|
nc.com = com;
|
||||||
|
} else {
|
||||||
return NETCONF_QUERY_INTERNAL_SERVER_ERROR;
|
return NETCONF_QUERY_INTERNAL_SERVER_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!legacy.sign(signingId,now)) {
|
||||||
|
return NETCONF_QUERY_INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
// First append the legacy dictionary and a terminating NULL, then serialize the new-format one.
|
||||||
|
// Newer clients will use the new-format dictionary and older ones will use the old one.
|
||||||
|
std::string legacyStr(legacy.toString());
|
||||||
|
netconf.append((const void *)legacyStr.data(),(unsigned int)legacyStr.length());
|
||||||
|
netconf.append((uint8_t)0);
|
||||||
|
nc.serialize(netconf);
|
||||||
|
|
||||||
return NetworkController::NETCONF_QUERY_OK;
|
return NetworkController::NETCONF_QUERY_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -168,8 +168,7 @@ void NetworkConfig::fromDictionary(const char *ds,unsigned int dslen)
|
||||||
rules[ruleCount].v.etherType = (uint16_t)et2;
|
rules[ruleCount].v.etherType = (uint16_t)et2;
|
||||||
++ruleCount;
|
++ruleCount;
|
||||||
}
|
}
|
||||||
rules[ruleCount].t = ZT_NETWORK_RULE_ACTION_ACCEPT;
|
rules[ruleCount++].t = ZT_NETWORK_RULE_ACTION_ACCEPT;
|
||||||
++ruleCount;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue