This commit is contained in:
Grant Limberg 2020-08-04 13:52:57 -07:00
parent 2e52a1eebf
commit 88a3c685fb
No known key found for this signature in database
GPG Key ID: 2BA62CCABBB4095A
4 changed files with 27 additions and 0 deletions

View File

@ -48,6 +48,8 @@ void DB::initNetwork(nlohmann::json &network)
{ "type","ACTION_ACCEPT" }
}};
}
if (!network.count("dns")) network["dns"] = nlohmann::json::array();
network["objtype"] = "network";
}
@ -110,6 +112,7 @@ bool DB::get(const uint64_t networkId,nlohmann::json &network)
std::lock_guard<std::mutex> l2(nw->lock);
network = nw->config;
}
fprintf(stderr, "DB::get(uint64_t,json): %s %s\n", OSUtils::jsonString(network["nwid"],"").c_str(), OSUtils::jsonDump(network["dns"], 2).c_str());
return true;
}
@ -132,6 +135,7 @@ bool DB::get(const uint64_t networkId,nlohmann::json &network,const uint64_t mem
return false;
member = m->second;
}
fprintf(stderr, "DB::get(uint64_t,json,uint64_t,mjson): %s %s\n", OSUtils::jsonString(network["nwid"],"").c_str(), OSUtils::jsonDump(network["dns"], 2).c_str());
return true;
}
@ -155,6 +159,7 @@ bool DB::get(const uint64_t networkId,nlohmann::json &network,const uint64_t mem
return false;
member = m->second;
}
fprintf(stderr, "DB::get(uint64_t,json,uint64_t,mjson,summary): %s %s\n", OSUtils::jsonString(network["nwid"],"").c_str(), OSUtils::jsonDump(network["dns"], 2).c_str());
return true;
}
@ -175,6 +180,7 @@ bool DB::get(const uint64_t networkId,nlohmann::json &network,std::vector<nlohma
for(auto m=nw->members.begin();m!=nw->members.end();++m)
members.push_back(m->second);
}
fprintf(stderr, "DB::get(uint64_t,json,members): %s %s\n", OSUtils::jsonString(network["nwid"],"").c_str(), OSUtils::jsonDump(network["dns"], 2).c_str());
return true;
}
@ -305,6 +311,7 @@ void DB::_networkChanged(nlohmann::json &old,nlohmann::json &networkConfig,bool
{
if (networkConfig.is_object()) {
const std::string ids = networkConfig["id"];
fprintf(stderr, "DB::_networkChanged(): %s\n", OSUtils::jsonDump(networkConfig["dns"]).c_str());
const uint64_t networkId = Utils::hexStrToU64(ids.c_str());
if (networkId) {
std::shared_ptr<_Network> nw;

View File

@ -1390,6 +1390,7 @@ void EmbeddedNetworkController::_request(
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);
std::string rtt(OSUtils::jsonString(member["remoteTraceTarget"],""));
if (rtt.length() == 10) {
nc->remoteTraceTarget = Address(Utils::hexStrToU64(rtt.c_str()));
@ -1713,9 +1714,11 @@ void EmbeddedNetworkController::_request(
}
if(dns.is_array()) {
fprintf(stderr, "dns is array of size %d\n", dns.size());
nc->dnsCount = 0;
for(unsigned int p=0; p < dns.size(); ++p) {
json &d = dns[p];
fprintf(stderr, "%s\n", OSUtils::jsonDump(d, 2).c_str());
if (d.is_object()) {
std::string domain = OSUtils::jsonString(d["domain"],"");
memcpy(nc->dns[nc->dnsCount].domain, domain.c_str(), domain.size());
@ -1730,6 +1733,7 @@ void EmbeddedNetworkController::_request(
}
}
} else {
fprintf(stderr, "dns is NOT an array\n");
dns = json::array();
}

View File

@ -1429,6 +1429,7 @@ void Network::_externalConfig(ZT_VirtualNetworkConfig *ec) const
}
ec->dnsCount = _config.dnsCount;
fprintf(stderr, "Network::_externalConfig dnsCount: %d\n", ec->dnsCount);
if (ec->dnsCount > 0) {
memcpy(&ec->dns, &_config.dns, sizeof(ZT_VirtualNetworkDNS));
}

View File

@ -231,6 +231,21 @@ static void _networkToJson(nlohmann::json &nj,const ZT_VirtualNetworkConfig *nc,
mca.push_back(m);
}
nj["multicastSubscriptions"] = mca;
nj["dns"] = nlohmann::json::array();
for(unsigned int i=0;i<nc->dnsCount;++i) {
nlohmann::json m;
m["domain"] = nc->dns[i].domain;
m["servers"] = nlohmann::json::array();
for(int j=0;j<ZT_MAX_DNS_SERVERS;++j) {
InetAddress a(nc->dns[i].server_addr[j]);
if (a.isV4() || a.isV6()) {
char buf[256];
m["servers"].push_back(a.toIpString(buf));
}
}
}
}
static void _peerToJson(nlohmann::json &pj,const ZT_Peer *peer)