Loading DnsTlsDispatcher.cpp +21 −4 Original line number Diff line number Diff line Loading @@ -172,7 +172,7 @@ DnsTlsTransport::Response DnsTlsDispatcher::query(const DnsTlsServer& server, un { std::lock_guard guard(sLock); if (xport = getTransport(key); xport == nullptr) { xport = addTransport(server, mark); xport = addTransport(server, mark, netId); } ++xport->useCount; } Loading Loading @@ -235,6 +235,11 @@ DnsTlsTransport::Response DnsTlsDispatcher::query(const DnsTlsServer& server, un return code; } void DnsTlsDispatcher::forceCleanup(unsigned netId) { std::lock_guard guard(sLock); forceCleanupLocked(netId); } DnsTlsTransport::Result DnsTlsDispatcher::queryInternal(Transport& xport, const netdutils::Slice query) { LOG(DEBUG) << "Sending query of length " << query.size(); Loading Loading @@ -281,8 +286,20 @@ void DnsTlsDispatcher::cleanup(std::chrono::time_point<std::chrono::steady_clock mLastCleanup = now; } // TODO: unify forceCleanupLocked() and cleanup(). void DnsTlsDispatcher::forceCleanupLocked(unsigned netId) { for (auto it = mStore.begin(); it != mStore.end();) { auto& s = it->second; if (s->useCount == 0 && s->mNetId == netId) { it = mStore.erase(it); } else { ++it; } } } DnsTlsDispatcher::Transport* DnsTlsDispatcher::addTransport(const DnsTlsServer& server, unsigned mark) { unsigned mark, unsigned netId) { const Key key = std::make_pair(mark, server); Transport* ret = getTransport(key); if (ret != nullptr) return ret; Loading @@ -309,8 +326,8 @@ DnsTlsDispatcher::Transport* DnsTlsDispatcher::addTransport(const DnsTlsServer& queryTimeout = 1000; } ret = new Transport(server, mark, mFactory.get(), revalidationEnabled, triggerThr, unusableThr, queryTimeout); ret = new Transport(server, mark, netId, mFactory.get(), revalidationEnabled, triggerThr, unusableThr, queryTimeout); LOG(DEBUG) << "Transport is initialized with { " << triggerThr << ", " << unusableThr << ", " << queryTimeout << "ms }" << " for server { " << server.toIpString() << "/" << server.name << " }"; Loading DnsTlsDispatcher.h +16 −3 Original line number Diff line number Diff line Loading @@ -65,6 +65,8 @@ class DnsTlsDispatcher : public PrivateDnsValidationObserver { // Implement PrivateDnsValidationObserver. void onValidationStateUpdate(const std::string&, Validation, uint32_t) override{}; void forceCleanup(unsigned netId) EXCLUDES(sLock); private: DnsTlsDispatcher(); Loading @@ -79,15 +81,22 @@ class DnsTlsDispatcher : public PrivateDnsValidationObserver { // Transport is a thin wrapper around DnsTlsTransport, adding reference counting and // usage monitoring so we can expire idle sessions from the cache. struct Transport { Transport(const DnsTlsServer& server, unsigned mark, IDnsTlsSocketFactory* _Nonnull factory, bool revalidationEnabled, int triggerThr, int unusableThr, int timeout) Transport(const DnsTlsServer& server, unsigned mark, unsigned netId, IDnsTlsSocketFactory* _Nonnull factory, bool revalidationEnabled, int triggerThr, int unusableThr, int timeout) : transport(server, mark, factory), mNetId(netId), revalidationEnabled(revalidationEnabled), triggerThreshold(triggerThr), unusableThreshold(unusableThr), mTimeout(timeout) {} // DnsTlsTransport is thread-safe, so it doesn't need to be guarded. DnsTlsTransport transport; // The expected network, assigned from dns_netid, to which Transport will send DNS packets. const unsigned mNetId; // This use counter and timestamp are used to ensure that only idle sessions are // destroyed. int useCount GUARDED_BY(sLock) = 0; Loading Loading @@ -135,7 +144,8 @@ class DnsTlsDispatcher : public PrivateDnsValidationObserver { const std::chrono::milliseconds mTimeout; }; Transport* _Nullable addTransport(const DnsTlsServer& server, unsigned mark) REQUIRES(sLock); Transport* _Nullable addTransport(const DnsTlsServer& server, unsigned mark, unsigned netId) REQUIRES(sLock); Transport* _Nullable getTransport(const Key& key) REQUIRES(sLock); // Cache of reusable DnsTlsTransports. Transports stay in cache as long as Loading @@ -153,6 +163,9 @@ class DnsTlsDispatcher : public PrivateDnsValidationObserver { // This function performs a linear scan of mStore. void cleanup(std::chrono::time_point<std::chrono::steady_clock> now) REQUIRES(sLock); // Force dropping any Transports whose useCount is zero. void forceCleanupLocked(unsigned netId) REQUIRES(sLock); // Return a sorted list of usable DnsTlsServers in preference order. std::list<DnsTlsServer> getOrderedAndUsableServerList(const std::list<DnsTlsServer>& tlsServers, unsigned netId, unsigned mark); Loading ResolverController.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ #include "Dns64Configuration.h" #include "DnsResolver.h" #include "DnsTlsDispatcher.h" #include "PrivateDnsConfiguration.h" #include "ResolverEventReporter.h" #include "ResolverStats.h" Loading Loading @@ -166,6 +167,9 @@ void ResolverController::destroyNetworkCache(unsigned netId) { resolv_delete_cache_for_net(netId); mDns64Configuration.stopPrefixDiscovery(netId); PrivateDnsConfiguration::getInstance().clear(netId); // Don't get this instance in PrivateDnsConfiguration. It's probe to deadlock. DnsTlsDispatcher::getInstance().forceCleanup(netId); } int ResolverController::createNetworkCache(unsigned netId) { Loading Loading
DnsTlsDispatcher.cpp +21 −4 Original line number Diff line number Diff line Loading @@ -172,7 +172,7 @@ DnsTlsTransport::Response DnsTlsDispatcher::query(const DnsTlsServer& server, un { std::lock_guard guard(sLock); if (xport = getTransport(key); xport == nullptr) { xport = addTransport(server, mark); xport = addTransport(server, mark, netId); } ++xport->useCount; } Loading Loading @@ -235,6 +235,11 @@ DnsTlsTransport::Response DnsTlsDispatcher::query(const DnsTlsServer& server, un return code; } void DnsTlsDispatcher::forceCleanup(unsigned netId) { std::lock_guard guard(sLock); forceCleanupLocked(netId); } DnsTlsTransport::Result DnsTlsDispatcher::queryInternal(Transport& xport, const netdutils::Slice query) { LOG(DEBUG) << "Sending query of length " << query.size(); Loading Loading @@ -281,8 +286,20 @@ void DnsTlsDispatcher::cleanup(std::chrono::time_point<std::chrono::steady_clock mLastCleanup = now; } // TODO: unify forceCleanupLocked() and cleanup(). void DnsTlsDispatcher::forceCleanupLocked(unsigned netId) { for (auto it = mStore.begin(); it != mStore.end();) { auto& s = it->second; if (s->useCount == 0 && s->mNetId == netId) { it = mStore.erase(it); } else { ++it; } } } DnsTlsDispatcher::Transport* DnsTlsDispatcher::addTransport(const DnsTlsServer& server, unsigned mark) { unsigned mark, unsigned netId) { const Key key = std::make_pair(mark, server); Transport* ret = getTransport(key); if (ret != nullptr) return ret; Loading @@ -309,8 +326,8 @@ DnsTlsDispatcher::Transport* DnsTlsDispatcher::addTransport(const DnsTlsServer& queryTimeout = 1000; } ret = new Transport(server, mark, mFactory.get(), revalidationEnabled, triggerThr, unusableThr, queryTimeout); ret = new Transport(server, mark, netId, mFactory.get(), revalidationEnabled, triggerThr, unusableThr, queryTimeout); LOG(DEBUG) << "Transport is initialized with { " << triggerThr << ", " << unusableThr << ", " << queryTimeout << "ms }" << " for server { " << server.toIpString() << "/" << server.name << " }"; Loading
DnsTlsDispatcher.h +16 −3 Original line number Diff line number Diff line Loading @@ -65,6 +65,8 @@ class DnsTlsDispatcher : public PrivateDnsValidationObserver { // Implement PrivateDnsValidationObserver. void onValidationStateUpdate(const std::string&, Validation, uint32_t) override{}; void forceCleanup(unsigned netId) EXCLUDES(sLock); private: DnsTlsDispatcher(); Loading @@ -79,15 +81,22 @@ class DnsTlsDispatcher : public PrivateDnsValidationObserver { // Transport is a thin wrapper around DnsTlsTransport, adding reference counting and // usage monitoring so we can expire idle sessions from the cache. struct Transport { Transport(const DnsTlsServer& server, unsigned mark, IDnsTlsSocketFactory* _Nonnull factory, bool revalidationEnabled, int triggerThr, int unusableThr, int timeout) Transport(const DnsTlsServer& server, unsigned mark, unsigned netId, IDnsTlsSocketFactory* _Nonnull factory, bool revalidationEnabled, int triggerThr, int unusableThr, int timeout) : transport(server, mark, factory), mNetId(netId), revalidationEnabled(revalidationEnabled), triggerThreshold(triggerThr), unusableThreshold(unusableThr), mTimeout(timeout) {} // DnsTlsTransport is thread-safe, so it doesn't need to be guarded. DnsTlsTransport transport; // The expected network, assigned from dns_netid, to which Transport will send DNS packets. const unsigned mNetId; // This use counter and timestamp are used to ensure that only idle sessions are // destroyed. int useCount GUARDED_BY(sLock) = 0; Loading Loading @@ -135,7 +144,8 @@ class DnsTlsDispatcher : public PrivateDnsValidationObserver { const std::chrono::milliseconds mTimeout; }; Transport* _Nullable addTransport(const DnsTlsServer& server, unsigned mark) REQUIRES(sLock); Transport* _Nullable addTransport(const DnsTlsServer& server, unsigned mark, unsigned netId) REQUIRES(sLock); Transport* _Nullable getTransport(const Key& key) REQUIRES(sLock); // Cache of reusable DnsTlsTransports. Transports stay in cache as long as Loading @@ -153,6 +163,9 @@ class DnsTlsDispatcher : public PrivateDnsValidationObserver { // This function performs a linear scan of mStore. void cleanup(std::chrono::time_point<std::chrono::steady_clock> now) REQUIRES(sLock); // Force dropping any Transports whose useCount is zero. void forceCleanupLocked(unsigned netId) REQUIRES(sLock); // Return a sorted list of usable DnsTlsServers in preference order. std::list<DnsTlsServer> getOrderedAndUsableServerList(const std::list<DnsTlsServer>& tlsServers, unsigned netId, unsigned mark); Loading
ResolverController.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ #include "Dns64Configuration.h" #include "DnsResolver.h" #include "DnsTlsDispatcher.h" #include "PrivateDnsConfiguration.h" #include "ResolverEventReporter.h" #include "ResolverStats.h" Loading Loading @@ -166,6 +167,9 @@ void ResolverController::destroyNetworkCache(unsigned netId) { resolv_delete_cache_for_net(netId); mDns64Configuration.stopPrefixDiscovery(netId); PrivateDnsConfiguration::getInstance().clear(netId); // Don't get this instance in PrivateDnsConfiguration. It's probe to deadlock. DnsTlsDispatcher::getInstance().forceCleanup(netId); } int ResolverController::createNetworkCache(unsigned netId) { Loading