summaryrefslogtreecommitdiff
path: root/zto/controller
diff options
context:
space:
mode:
authorJoseph Henry <[email protected]>2017-05-30 13:11:43 -0700
committerJoseph Henry <[email protected]>2017-05-30 13:11:43 -0700
commit673d1b9a095025368177088bbf6875d7d3057f2f (patch)
tree3291ad3a81fb076055e7bf173b5766ccdca675be /zto/controller
parent5cfb4c38ef2ab3a3621bf568db6bb2b2bd83a357 (diff)
updated ZTO core1.1.2
Diffstat (limited to 'zto/controller')
-rw-r--r--zto/controller/EmbeddedNetworkController.cpp154
-rw-r--r--zto/controller/EmbeddedNetworkController.hpp8
-rw-r--r--zto/controller/JSONDB.cpp6
-rw-r--r--zto/controller/JSONDB.hpp9
4 files changed, 31 insertions, 146 deletions
diff --git a/zto/controller/EmbeddedNetworkController.cpp b/zto/controller/EmbeddedNetworkController.cpp
index 8ff8eb8..e2eaa78 100644
--- a/zto/controller/EmbeddedNetworkController.cpp
+++ b/zto/controller/EmbeddedNetworkController.cpp
@@ -487,9 +487,6 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpGET(
if ((path.size() >= 2)&&(path[1].length() == 16)) {
const uint64_t nwid = Utils::hexStrToU64(path[1].c_str());
- char nwids[24];
- Utils::snprintf(nwids,sizeof(nwids),"%.16llx",(unsigned long long)nwid);
-
json network;
if (!_db.getNetwork(nwid,network))
return 404;
@@ -499,6 +496,8 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpGET(
if (path[2] == "member") {
if (path.size() >= 4) {
+ // Get member
+
const uint64_t address = Utils::hexStrToU64(path[3].c_str());
json member;
if (!_db.getNetworkMember(nwid,address,member))
@@ -506,24 +505,29 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpGET(
_addMemberNonPersistedFields(nwid,address,member,OSUtils::now());
responseBody = OSUtils::jsonDump(member);
responseContentType = "application/json";
+
} else {
+ // List members and their revisions
+
responseBody = "{";
+ responseBody.reserve((_db.memberCount(nwid) + 1) * 32);
_db.eachMember(nwid,[&responseBody](uint64_t networkId,uint64_t nodeId,const json &member) {
if ((member.is_object())&&(member.size() > 0)) {
- responseBody.append((responseBody.length() == 1) ? "\"" : ",\"");
- responseBody.append(OSUtils::jsonString(member["id"],"0"));
- responseBody.append("\":");
- responseBody.append(OSUtils::jsonString(member["revision"],"0"));
+ char tmp[128];
+ Utils::snprintf(tmp,sizeof(tmp),"%s%.10llx\":%llu",(responseBody.length() > 1) ? ",\"" : "\"",(unsigned long long)nodeId,(unsigned long long)OSUtils::jsonInt(member["revision"],0));
+ responseBody.append(tmp);
}
});
responseBody.push_back('}');
responseContentType = "application/json";
+
}
return 200;
} // else 404
} else {
+ // Get network
const uint64_t now = OSUtils::now();
JSONDB::NetworkSummaryInfo ns;
@@ -535,12 +539,12 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpGET(
}
} else if (path.size() == 1) {
+ // List networks
std::vector<uint64_t> networkIds(_db.networkIds());
- std::sort(networkIds.begin(),networkIds.end());
-
char tmp[64];
- responseBody.push_back('[');
+ responseBody = "[";
+ responseBody.reserve((networkIds.size() + 1) * 24);
for(std::vector<uint64_t>::const_iterator i(networkIds.begin());i!=networkIds.end();++i) {
if (responseBody.length() > 1)
responseBody.push_back(',');
@@ -555,6 +559,7 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpGET(
} // else 404
} else {
+ // Controller status
char tmp[4096];
Utils::snprintf(tmp,sizeof(tmp),"{\n\t\"controller\": true,\n\t\"apiVersion\": %d,\n\t\"clock\": %llu\n}\n",ZT_NETCONF_CONTROLLER_API_VERSION,(unsigned long long)OSUtils::now());
@@ -721,59 +726,6 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST(
responseContentType = "application/json";
return 200;
- } else if ((path.size() == 3)&&(path[2] == "test")) {
-
- Mutex::Lock _l(_tests_m);
-
- _tests.push_back(ZT_CircuitTest());
- ZT_CircuitTest *const test = &(_tests.back());
- memset(test,0,sizeof(ZT_CircuitTest));
-
- Utils::getSecureRandom(&(test->testId),sizeof(test->testId));
- test->credentialNetworkId = nwid;
- test->ptr = (void *)this;
- json hops = b["hops"];
- if (hops.is_array()) {
- for(unsigned long i=0;i<hops.size();++i) {
- json &hops2 = hops[i];
- if (hops2.is_array()) {
- for(unsigned long j=0;j<hops2.size();++j) {
- std::string s = hops2[j];
- test->hops[test->hopCount].addresses[test->hops[test->hopCount].breadth++] = Utils::hexStrToU64(s.c_str()) & 0xffffffffffULL;
- }
- ++test->hopCount;
- } else if (hops2.is_string()) {
- std::string s = hops2;
- test->hops[test->hopCount].addresses[test->hops[test->hopCount].breadth++] = Utils::hexStrToU64(s.c_str()) & 0xffffffffffULL;
- ++test->hopCount;
- }
- }
- }
- test->reportAtEveryHop = (OSUtils::jsonBool(b["reportAtEveryHop"],true) ? 1 : 0);
-
- if (!test->hopCount) {
- _tests.pop_back();
- responseBody = "{ \"message\": \"a test must contain at least one hop\" }";
- responseContentType = "application/json";
- return 400;
- }
-
- test->timestamp = OSUtils::now();
-
- if (_node) {
- _node->circuitTestBegin((void *)0,test,&(EmbeddedNetworkController::_circuitTestCallback));
- } else {
- _tests.pop_back();
- return 500;
- }
-
- char json[512];
- Utils::snprintf(json,sizeof(json),"{\"testId\":\"%.16llx\",\"timestamp\":%llu}",test->testId,test->timestamp);
- responseBody = json;
- responseContentType = "application/json";
-
- return 200;
-
} // else 404
} else {
@@ -809,6 +761,7 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST(
if (b.count("enableBroadcast")) network["enableBroadcast"] = OSUtils::jsonBool(b["enableBroadcast"],false);
if (b.count("allowPassiveBridging")) network["allowPassiveBridging"] = OSUtils::jsonBool(b["allowPassiveBridging"],false);
if (b.count("multicastLimit")) network["multicastLimit"] = OSUtils::jsonInt(b["multicastLimit"],32ULL);
+ if (b.count("mtu")) network["mtu"] = std::max(std::min((unsigned int)OSUtils::jsonInt(b["mtu"],ZT_DEFAULT_MTU),(unsigned int)ZT_MAX_MTU),(unsigned int)ZT_MIN_MTU);
if (b.count("v4AssignMode")) {
json nv4m;
@@ -1112,7 +1065,6 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpDELETE(
void EmbeddedNetworkController::threadMain()
throw()
{
- uint64_t lastCircuitTestCheck = 0;
_RQEntry *qe = (_RQEntry *)0;
while ((_running)&&(_queue.get(qe))) {
try {
@@ -1124,7 +1076,7 @@ void EmbeddedNetworkController::threadMain()
std::string pong("{\"memberStatus\":{");
{
Mutex::Lock _l(_memberStatus_m);
- pong.reserve(64 * _memberStatus.size());
+ pong.reserve(48 * (_memberStatus.size() + 1));
_db.eachId([this,&pong,&now,&first](uint64_t networkId,uint64_t nodeId) {
char tmp[64];
uint64_t lrt = 0ULL;
@@ -1147,80 +1099,9 @@ void EmbeddedNetworkController::threadMain()
}
} catch ( ... ) {}
delete qe;
-
- if (_running) {
- uint64_t now = OSUtils::now();
- if ((now - lastCircuitTestCheck) > ZT_EMBEDDEDNETWORKCONTROLLER_CIRCUIT_TEST_EXPIRATION) {
- lastCircuitTestCheck = now;
- Mutex::Lock _l(_tests_m);
- for(std::list< ZT_CircuitTest >::iterator i(_tests.begin());i!=_tests.end();) {
- if ((now - i->timestamp) > ZT_EMBEDDEDNETWORKCONTROLLER_CIRCUIT_TEST_EXPIRATION) {
- _node->circuitTestEnd(&(*i));
- _tests.erase(i++);
- } else ++i;
- }
- }
- }
}
}
-void EmbeddedNetworkController::_circuitTestCallback(ZT_Node *node,ZT_CircuitTest *test,const ZT_CircuitTestReport *report)
-{
- char tmp[2048],id[128];
- EmbeddedNetworkController *const self = reinterpret_cast<EmbeddedNetworkController *>(test->ptr);
-
- if ((!test)||(!report)||(!test->credentialNetworkId)) return; // sanity check
-
- const uint64_t now = OSUtils::now();
- Utils::snprintf(id,sizeof(id),"network/%.16llx/test/%.16llx-%.16llx-%.10llx-%.10llx",test->credentialNetworkId,test->testId,now,report->upstream,report->current);
- Utils::snprintf(tmp,sizeof(tmp),
- "{\"id\": \"%s\","
- "\"objtype\": \"circuit_test\","
- "\"timestamp\": %llu,"
- "\"networkId\": \"%.16llx\","
- "\"testId\": \"%.16llx\","
- "\"upstream\": \"%.10llx\","
- "\"current\": \"%.10llx\","
- "\"receivedTimestamp\": %llu,"
- "\"sourcePacketId\": \"%.16llx\","
- "\"flags\": %llu,"
- "\"sourcePacketHopCount\": %u,"
- "\"errorCode\": %u,"
- "\"vendor\": %d,"
- "\"protocolVersion\": %u,"
- "\"majorVersion\": %u,"
- "\"minorVersion\": %u,"
- "\"revision\": %u,"
- "\"platform\": %d,"
- "\"architecture\": %d,"
- "\"receivedOnLocalAddress\": \"%s\","
- "\"receivedFromRemoteAddress\": \"%s\","
- "\"receivedFromLinkQuality\": %f}",
- id + 30, // last bit only, not leading path
- (unsigned long long)test->timestamp,
- (unsigned long long)test->credentialNetworkId,
- (unsigned long long)test->testId,
- (unsigned long long)report->upstream,
- (unsigned long long)report->current,
- (unsigned long long)now,
- (unsigned long long)report->sourcePacketId,
- (unsigned long long)report->flags,
- report->sourcePacketHopCount,
- report->errorCode,
- (int)report->vendor,
- report->protocolVersion,
- report->majorVersion,
- report->minorVersion,
- report->revision,
- (int)report->platform,
- (int)report->architecture,
- reinterpret_cast<const InetAddress *>(&(report->receivedOnLocalAddress))->toString().c_str(),
- reinterpret_cast<const InetAddress *>(&(report->receivedFromRemoteAddress))->toString().c_str(),
- ((double)report->receivedFromLinkQuality / (double)ZT_PATH_LINK_QUALITY_MAX));
-
- self->_db.writeRaw(id,std::string(tmp));
-}
-
void EmbeddedNetworkController::_request(
uint64_t nwid,
const InetAddress &fromAddr,
@@ -1424,6 +1305,7 @@ void EmbeddedNetworkController::_request(
if (OSUtils::jsonBool(network["enableBroadcast"],true)) nc->flags |= ZT_NETWORKCONFIG_FLAG_ENABLE_BROADCAST;
if (OSUtils::jsonBool(network["allowPassiveBridging"],false)) nc->flags |= ZT_NETWORKCONFIG_FLAG_ALLOW_PASSIVE_BRIDGING;
Utils::scopy(nc->name,sizeof(nc->name),OSUtils::jsonString(network["name"],"").c_str());
+ nc->mtu = std::max(std::min((unsigned int)OSUtils::jsonInt(network["mtu"],ZT_DEFAULT_MTU),(unsigned int)ZT_MAX_MTU),(unsigned int)ZT_MIN_MTU);
nc->multicastLimit = (unsigned int)OSUtils::jsonInt(network["multicastLimit"],32ULL);
for(std::vector<Address>::const_iterator ab(ns.activeBridges.begin());ab!=ns.activeBridges.end();++ab)
diff --git a/zto/controller/EmbeddedNetworkController.hpp b/zto/controller/EmbeddedNetworkController.hpp
index ade7eb2..1589ea7 100644
--- a/zto/controller/EmbeddedNetworkController.hpp
+++ b/zto/controller/EmbeddedNetworkController.hpp
@@ -45,9 +45,6 @@
#include "JSONDB.hpp"
-// TTL for circuit tests
-#define ZT_EMBEDDEDNETWORKCONTROLLER_CIRCUIT_TEST_EXPIRATION 120000
-
namespace ZeroTier {
class Node;
@@ -110,7 +107,6 @@ private:
} type;
};
- static void _circuitTestCallback(ZT_Node *node,ZT_CircuitTest *test,const ZT_CircuitTestReport *report);
void _request(uint64_t nwid,const InetAddress &fromAddr,uint64_t requestPacketId,const Identity &identity,const Dictionary<ZT_NETWORKCONFIG_METADATA_DICT_CAPACITY> &metaData);
inline void _startThreads()
@@ -162,6 +158,7 @@ private:
if (!network.count("tags")) network["tags"] = nlohmann::json::array();
if (!network.count("routes")) network["routes"] = nlohmann::json::array();
if (!network.count("ipAssignmentPools")) network["ipAssignmentPools"] = nlohmann::json::array();
+ if (!network.count("mtu")) network["mtu"] = ZT_DEFAULT_MTU;
if (!network.count("rules")) {
// If unspecified, rules are set to allow anything and behave like a flat L2 segment
network["rules"] = {{
@@ -218,9 +215,6 @@ private:
NetworkController::Sender *_sender;
Identity _signingId;
- std::list< ZT_CircuitTest > _tests;
- Mutex _tests_m;
-
struct _MemberStatusKey
{
_MemberStatusKey() : networkId(0),nodeId(0) {}
diff --git a/zto/controller/JSONDB.cpp b/zto/controller/JSONDB.cpp
index 31c0cc0..e0dd174 100644
--- a/zto/controller/JSONDB.cpp
+++ b/zto/controller/JSONDB.cpp
@@ -392,14 +392,14 @@ bool JSONDB::_load(const std::string &p)
std::string objtype(OSUtils::jsonString(j["objtype"],""));
if ((id.length() == 16)&&(objtype == "network")) {
- const uint64_t nwid = Utils::strToU64(id.c_str());
+ const uint64_t nwid = Utils::hexStrToU64(id.c_str());
if (nwid) {
Mutex::Lock _l(_networks_m);
_networks[nwid].config = nlohmann::json::to_msgpack(j);
}
} else if ((id.length() == 10)&&(objtype == "member")) {
- const uint64_t mid = Utils::strToU64(id.c_str());
- const uint64_t nwid = Utils::strToU64(OSUtils::jsonString(j["nwid"],"0").c_str());
+ const uint64_t mid = Utils::hexStrToU64(id.c_str());
+ const uint64_t nwid = Utils::hexStrToU64(OSUtils::jsonString(j["nwid"],"0").c_str());
if ((mid)&&(nwid)) {
Mutex::Lock _l(_networks_m);
_networks[nwid].members[mid] = nlohmann::json::to_msgpack(j);
diff --git a/zto/controller/JSONDB.hpp b/zto/controller/JSONDB.hpp
index 530f963..e164a14 100644
--- a/zto/controller/JSONDB.hpp
+++ b/zto/controller/JSONDB.hpp
@@ -93,6 +93,15 @@ public:
return r;
}
+ inline unsigned long memberCount(const uint64_t networkId)
+ {
+ Mutex::Lock _l(_networks_m);
+ std::unordered_map<uint64_t,_NW>::const_iterator i(_networks.find(networkId));
+ if (i != _networks.end())
+ return (unsigned long)i->second.members.size();
+ return 0;
+ }
+
template<typename F>
inline void eachMember(const uint64_t networkId,F func)
{