diff --git a/simgear/io/DNSClient.cxx b/simgear/io/DNSClient.cxx index de0a22a2..268f0a82 100644 --- a/simgear/io/DNSClient.cxx +++ b/simgear/io/DNSClient.cxx @@ -37,8 +37,8 @@ namespace DNS { class Client::ClientPrivate { public: - ClientPrivate() { - + ClientPrivate(const std::string& nameserver) + { if( instanceCounter++ == 0 ) if (dns_init(NULL, 0) < 0) SG_LOG(SG_IO, SG_ALERT, "Can't init udns library" ); @@ -48,6 +48,11 @@ public: if (dns_init(ctx, 0) < 0) SG_LOG(SG_IO, SG_ALERT, "Can't create udns context" ); + if (!nameserver.empty()) { + dns_add_serv(ctx, nullptr); + dns_add_serv(ctx, nameserver.c_str()); + } + if( dns_open(ctx) < 0 ) SG_LOG(SG_IO, SG_ALERT, "Can't open udns context" ); } @@ -254,13 +259,11 @@ void NAPTRRequest::submit( Client * client ) _query = q; } - -Client::~Client() +Client::Client(const std::string& nameserver) : d(new ClientPrivate{nameserver}) { } -Client::Client() : - d(new ClientPrivate) +Client::~Client() { } diff --git a/simgear/io/DNSClient.hxx b/simgear/io/DNSClient.hxx index a71b6c6b..1703cb63 100644 --- a/simgear/io/DNSClient.hxx +++ b/simgear/io/DNSClient.hxx @@ -133,7 +133,7 @@ public: class Client { public: - Client(); + Client(const std::string& nameserver = {}); ~Client(); void update(int waitTimeout = 0); diff --git a/simgear/scene/tsync/terrasync.cxx b/simgear/scene/tsync/terrasync.cxx index 9e1c267a..86f1eeac 100644 --- a/simgear/scene/tsync/terrasync.cxx +++ b/simgear/scene/tsync/terrasync.cxx @@ -317,6 +317,11 @@ public: _isAutomaticServer = (server == "automatic"); } + void setDNSServer(const std::string& nameserver) + { + _dnsNameserver = nameserver; + } + void setDNSDN( const std::string & dn ) { _dnsdn = simgear::strutils::strip(dn); @@ -414,6 +419,7 @@ public: string _sceneryVersion; string _protocol; string _dnsdn; + string _dnsNameserver; TerrasyncThreadState _state; mutable std::mutex _stateLock; @@ -537,7 +543,7 @@ std::string SGTerraSync::WorkerThread::dnsSelectServerForService(const std::stri naptrRequest->qflags = "U"; DNS::Request_ptr r(naptrRequest); - DNS::Client dnsClient; + DNS::Client dnsClient{_dnsNameserver}; dnsClient.makeRequest(r); SG_LOG(SG_TERRASYNC,SG_DEBUG,"DNS NAPTR query for '" << _dnsdn << "' '" << naptrRequest->qservice << "'" ); while (!r->isComplete() && !r->isTimeout()) { @@ -1170,6 +1176,16 @@ void SGTerraSync::reinit() _workerThread->setSceneryVersion( _terraRoot->getStringValue("scenery-version","ws20") ); _workerThread->setOSMCityVersion(_terraRoot->getStringValue("osm2city-version", "o2c")); _workerThread->setProtocol( _terraRoot->getStringValue("protocol","") ); + + if (_terraRoot->hasChild("dns-server")) { + auto ns = _terraRoot->getStringValue("dns-server"); + if (ns == "google") { + ns = "8.8.8.8"; + } + + SG_LOG(SG_TERRASYNC,SG_INFO,"DNS server override:" << ns); + _workerThread->setDNSServer(ns); + } #if 1 // leave it hardcoded for now, not sure about the security implications for now _workerThread->setDNSDN( "terrasync.flightgear.org");