From 559e8a907b5c4b3db36bb9f1c89efaf9cbbc172a Mon Sep 17 00:00:00 2001 From: travisladuke Date: Thu, 22 Feb 2024 09:27:59 -0800 Subject: [PATCH 1/3] Improve full controller network list api it was counting incorrectly in some cases and returning empty objects. Basically just handling if network data is null --- controller/EmbeddedNetworkController.cpp | 30 ++++++++++++++---------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/controller/EmbeddedNetworkController.cpp b/controller/EmbeddedNetworkController.cpp index a83894644..ed69a665b 100644 --- a/controller/EmbeddedNetworkController.cpp +++ b/controller/EmbeddedNetworkController.cpp @@ -918,6 +918,7 @@ void EmbeddedNetworkController::configureHTTPControlPlane( auto meta = json::object(); auto data = json::array(); + uint64_t networkCount = 0; for(std::set::const_iterator nwid(networkIds.begin()); nwid != networkIds.end(); ++nwid) { json network; @@ -927,23 +928,26 @@ void EmbeddedNetworkController::configureHTTPControlPlane( std::vector memTmp; if (_db.get(*nwid, network, memTmp)) { - uint64_t authorizedCount = 0; - uint64_t totalCount = memTmp.size(); + if (!network.is_null()) { + uint64_t authorizedCount = 0; + uint64_t totalCount = memTmp.size(); + networkCount++; - for (auto m = memTmp.begin(); m != memTmp.end(); ++m) { - bool a = OSUtils::jsonBool((*m)["authorized"], 0); - if (a) { authorizedCount++; } + for (auto m = memTmp.begin(); m != memTmp.end(); ++m) { + bool a = OSUtils::jsonBool((*m)["authorized"], 0); + if (a) { authorizedCount++; } + } + + auto nwMeta = json::object(); + nwMeta["totalMemberCount"] = totalCount; + nwMeta["authorizedMemberCount"] = authorizedCount; + network["meta"] = nwMeta; + + data.push_back(network); } - - auto nwMeta = json::object(); - nwMeta["totalMemberCount"] = totalCount; - nwMeta["authorizedMemberCount"] = authorizedCount; - network["meta"] = nwMeta; } - - data.push_back(network); } - meta["networkCount"] = networkIds.size(); + meta["networkCount"] = networkCount; auto out = json::object(); out["data"] = data; From 6e8fcce7777db0e0ac503aac78e93a5148e7ec0b Mon Sep 17 00:00:00 2001 From: travisladuke Date: Thu, 22 Feb 2024 11:34:43 -0800 Subject: [PATCH 2/3] Fix unstable network member list endpoint It was returning an array of array instead of just array --- controller/EmbeddedNetworkController.cpp | 34 ++++++++++++------------ 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/controller/EmbeddedNetworkController.cpp b/controller/EmbeddedNetworkController.cpp index ed69a665b..9cb971a58 100644 --- a/controller/EmbeddedNetworkController.cpp +++ b/controller/EmbeddedNetworkController.cpp @@ -1094,26 +1094,26 @@ void EmbeddedNetworkController::configureHTTPControlPlane( auto out = nlohmann::json::object(); auto meta = nlohmann::json::object(); - auto members = nlohmann::json::array(); std::vector memTmp; if (_db.get(nwid, network, memTmp)) { - members.push_back(memTmp); + uint64_t authorizedCount = 0; + uint64_t totalCount = memTmp.size(); + for (auto m = memTmp.begin(); m != memTmp.end(); ++m) { + bool a = OSUtils::jsonBool((*m)["authorized"], 0); + if (a) { authorizedCount++; } + } + + meta["totalCount"] = totalCount; + meta["authorizedCount"] = authorizedCount; + + out["data"] = memTmp; + out["meta"] = meta; + + setContent(req, res, out.dump()); + } else { + res.status = 404; + return; } - - uint64_t authorizedCount = 0; - uint64_t totalCount = memTmp.size(); - for (auto m = memTmp.begin(); m != memTmp.end(); ++m) { - bool a = OSUtils::jsonBool((*m)["authorized"], 0); - if (a) { authorizedCount++; } - } - - meta["totalCount"] = totalCount; - meta["authorizedCount"] = authorizedCount; - - out["data"] = members; - out["meta"] = meta; - - setContent(req, res, out.dump()); }; s.Get(memberListPath2, memberListGet2); sv6.Get(memberListPath2, memberListGet2); From 41cb6fb0d50aca74cc34e746e6bd64a5fe07dec0 Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Mon, 4 Mar 2024 16:38:10 -0800 Subject: [PATCH 3/3] Comment out debug traces in Rules Engine --- node/Network.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/node/Network.cpp b/node/Network.cpp index e13b32d53..1f49c651c 100644 --- a/node/Network.cpp +++ b/node/Network.cpp @@ -114,14 +114,14 @@ static _doZtFilterResult _doZtFilter( // uncomment for easier debugging fprintf // if (!ztDest) { return DOZTFILTER_ACCEPT; } #ifdef ZT_TRACE - char buf[40], buf2[40]; - fprintf(stderr, "\nsrc %s dest %s inbound: %d ethertype %u", ztSource.toString(buf), ztDest.toString(buf2), inbound, etherType); + //char buf[40], buf2[40]; + //fprintf(stderr, "\nsrc %s dest %s inbound: %d ethertype %u", ztSource.toString(buf), ztDest.toString(buf2), inbound, etherType); #endif for(unsigned int rn=0;rnid() == rules[rn].v.tag.id)) { const Tag *const remoteTag = ((membership) ? membership->getTag(nconf,rules[rn].v.tag.id) : (const Tag *)0); #ifdef ZT_TRACE - fprintf(stderr, "\tlocal tag [%u: %u] remote tag [%u: %u] match [%u]", + /*fprintf(stderr, "\tlocal tag [%u: %u] remote tag [%u: %u] match [%u]", !!localTag ? localTag->id() : 0, !!localTag ? localTag->value() : 0, !!remoteTag ? remoteTag->id() : 0, !!remoteTag ? remoteTag->value() : 0, - thisRuleMatches); + thisRuleMatches);*/ #endif if (remoteTag) { const uint32_t ltv = localTag->value(); @@ -501,7 +501,7 @@ static _doZtFilterResult _doZtFilter( if ((inbound)&&(!superAccept)) { thisRuleMatches = hardNo; #ifdef ZT_TRACE - fprintf(stderr, "\tinbound "); + //fprintf(stderr, "\tinbound "); #endif } else { // Outbound side is not strict since if we have to match both tags and @@ -512,7 +512,7 @@ static _doZtFilterResult _doZtFilter( skipDrop = 1; thisRuleMatches = hardYes; #ifdef ZT_TRACE - fprintf(stderr, "\toutbound "); + //fprintf(stderr, "\toutbound "); #endif } } @@ -524,13 +524,13 @@ static _doZtFilterResult _doZtFilter( case ZT_NETWORK_RULE_MATCH_TAG_RECEIVER: { const Tag *const localTag = std::lower_bound(&(nconf.tags[0]),&(nconf.tags[nconf.tagCount]),rules[rn].v.tag.id,Tag::IdComparePredicate()); #ifdef ZT_TRACE - const Tag *const remoteTag = ((membership) ? membership->getTag(nconf,rules[rn].v.tag.id) : (const Tag *)0); + /*const Tag *const remoteTag = ((membership) ? membership->getTag(nconf,rules[rn].v.tag.id) : (const Tag *)0); fprintf(stderr, "\tlocal tag [%u: %u] remote tag [%u: %u] match [%u]", !!localTag ? localTag->id() : 0, !!localTag ? localTag->value() : 0, !!remoteTag ? remoteTag->id() : 0, !!remoteTag ? remoteTag->value() : 0, - thisRuleMatches); + thisRuleMatches);*/ #endif if (superAccept) { skipDrop = 1;