diff options
author | Mike Yu <yumike@google.com> | 2019-09-23 17:47:21 +0800 |
---|---|---|
committer | Mike Yu <yumike@google.com> | 2019-10-09 21:44:33 +0800 |
commit | a772c209875d2f6f02cfddc06eb7b97c573b6c2d (patch) | |
tree | bf26dc64b738a3d7482d418d1bcb30f76ae9f615 /PrivateDnsConfiguration.cpp | |
parent | 0a423e4b35dacada4996cbf252a4f537feb1265a (diff) | |
download | DnsResolver-a772c209875d2f6f02cfddc06eb7b97c573b6c2d.tar.gz |
Make private DNS connect timeout configurable
It could take time to connect to a private DNS server if the system
allows 6 syn-retransmissions (net.ipv4.tcp_syn_retries = 6), which
can take time more than 2 minutes.
This change allows us to configure the timeout value via dnsresolver
binder service, and keep the default timeout value the same as the
original design.
Bug: 120182528
Bug: 141218721
Test: atest --include-subdirs packages/modules/DnsResolver
Test: m com.android.resolv
adb install com.android.resolv
rebooted
Change-Id: I8711a31172cfc671bf348191db363e7863831470
Diffstat (limited to 'PrivateDnsConfiguration.cpp')
-rw-r--r-- | PrivateDnsConfiguration.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/PrivateDnsConfiguration.cpp b/PrivateDnsConfiguration.cpp index 14bac16c..dbe0557f 100644 --- a/PrivateDnsConfiguration.cpp +++ b/PrivateDnsConfiguration.cpp @@ -29,6 +29,8 @@ #include "netd_resolv/resolv.h" #include "netdutils/BackoffSequence.h" +using std::chrono::milliseconds; + namespace android { namespace net { @@ -56,9 +58,9 @@ bool parseServer(const char* server, sockaddr_storage* parsed) { int PrivateDnsConfiguration::set(int32_t netId, uint32_t mark, const std::vector<std::string>& servers, const std::string& name, - const std::string& caCert) { + const std::string& caCert, int32_t connectTimeoutMs) { LOG(DEBUG) << "PrivateDnsConfiguration::set(" << netId << ", 0x" << std::hex << mark << std::dec - << ", " << servers.size() << ", " << name << ")"; + << ", " << servers.size() << ", " << name << ", " << connectTimeoutMs << "ms)"; // Parse the list of servers that has been passed in std::set<DnsTlsServer> tlsServers; @@ -70,6 +72,15 @@ int PrivateDnsConfiguration::set(int32_t netId, uint32_t mark, DnsTlsServer server(parsed); server.name = name; server.certificate = caCert; + + // connectTimeoutMs = 0: use the default timeout value. + // connectTimeoutMs < 0: invalid timeout value. + if (connectTimeoutMs > 0) { + // Set a specific timeout value but limit it to be at least 1 second. + server.connectTimeout = + (connectTimeoutMs < 1000) ? milliseconds(1000) : milliseconds(connectTimeoutMs); + } + tlsServers.insert(server); } |