tree: 91dedee23b26cb48b3f42fc7934ce4aae9d1e0ae [path history] [tgz]
  1. public/
  2. address_info.cc
  3. address_info.h
  4. address_info_unittest.cc
  5. address_sorter.h
  6. address_sorter_posix.cc
  7. address_sorter_posix.h
  8. address_sorter_posix_unittest.cc
  9. address_sorter_unittest.cc
  10. address_sorter_win.cc
  11. BUILD.gn
  12. context_host_resolver.cc
  13. context_host_resolver.h
  14. context_host_resolver_unittest.cc
  15. DIR_METADATA
  16. dns_alias_utility.cc
  17. dns_alias_utility.h
  18. dns_alias_utility_unittest.cc
  19. dns_client.cc
  20. dns_client.h
  21. dns_client_unittest.cc
  22. dns_config.cc
  23. dns_config.h
  24. dns_config_service.cc
  25. dns_config_service.h
  26. dns_config_service_android.cc
  27. dns_config_service_android.h
  28. dns_config_service_android_unittest.cc
  29. dns_config_service_fuchsia.cc
  30. dns_config_service_fuchsia.h
  31. dns_config_service_linux.cc
  32. dns_config_service_linux.h
  33. dns_config_service_linux_unittest.cc
  34. dns_config_service_posix.cc
  35. dns_config_service_posix.h
  36. dns_config_service_posix_unittest.cc
  37. dns_config_service_unittest.cc
  38. dns_config_service_win.cc
  39. dns_config_service_win.h
  40. dns_config_service_win_unittest.cc
  41. dns_config_watcher_mac.cc
  42. dns_config_watcher_mac.h
  43. dns_hosts.cc
  44. dns_hosts.h
  45. dns_hosts_parse_fuzzer.cc
  46. dns_hosts_unittest.cc
  47. dns_names_util.cc
  48. dns_names_util.h
  49. dns_names_util_unittest.cc
  50. dns_parse_domain_ascii_win_fuzzer.cc
  51. dns_query.cc
  52. dns_query.h
  53. dns_query_parse_fuzzer.cc
  54. dns_query_unittest.cc
  55. dns_record_fuzzer.cc
  56. dns_reloader.cc
  57. dns_reloader.h
  58. dns_response.cc
  59. dns_response.h
  60. dns_response_fuzzer.cc
  61. dns_response_result_extractor.cc
  62. dns_response_result_extractor.h
  63. dns_response_result_extractor_unittest.cc
  64. dns_response_unittest.cc
  65. dns_server_iterator.cc
  66. dns_server_iterator.h
  67. dns_session.cc
  68. dns_session.h
  69. dns_task_results_manager.cc
  70. dns_task_results_manager.h
  71. dns_task_results_manager_unittest.cc
  72. dns_test_util.cc
  73. dns_test_util.h
  74. dns_transaction.cc
  75. dns_transaction.h
  76. dns_transaction_unittest.cc
  77. dns_udp_tracker.cc
  78. dns_udp_tracker.h
  79. dns_udp_tracker_unittest.cc
  80. dns_util.cc
  81. dns_util.h
  82. dns_util_unittest.cc
  83. fuzzed_host_resolver_util.cc
  84. fuzzed_host_resolver_util.h
  85. host_cache.cc
  86. host_cache.h
  87. host_cache_fuzzer.cc
  88. host_cache_fuzzer.proto
  89. host_cache_unittest.cc
  90. host_resolver.cc
  91. host_resolver.h
  92. host_resolver_cache.cc
  93. host_resolver_cache.h
  94. host_resolver_cache_fuzzer.cc
  95. host_resolver_cache_unittest.cc
  96. host_resolver_dns_task.cc
  97. host_resolver_dns_task.h
  98. host_resolver_internal_result.cc
  99. host_resolver_internal_result.h
  100. host_resolver_internal_result_test_util.cc
  101. host_resolver_internal_result_test_util.h
  102. host_resolver_internal_result_unittest.cc
  103. host_resolver_manager.cc
  104. host_resolver_manager.h
  105. host_resolver_manager_fuzzer.cc
  106. host_resolver_manager_ipv6_reachability_override_unittest.cc
  107. host_resolver_manager_job.cc
  108. host_resolver_manager_job.h
  109. host_resolver_manager_request_impl.cc
  110. host_resolver_manager_request_impl.h
  111. host_resolver_manager_unittest.cc
  112. host_resolver_manager_unittest.h
  113. host_resolver_mdns_listener_impl.cc
  114. host_resolver_mdns_listener_impl.h
  115. host_resolver_mdns_task.cc
  116. host_resolver_mdns_task.h
  117. host_resolver_nat64_task.cc
  118. host_resolver_nat64_task.h
  119. host_resolver_proc.cc
  120. host_resolver_proc.h
  121. host_resolver_results_test_util.cc
  122. host_resolver_results_test_util.h
  123. host_resolver_system_task.cc
  124. host_resolver_system_task.h
  125. https_record_rdata.cc
  126. https_record_rdata.h
  127. https_record_rdata_fuzzer.cc
  128. https_record_rdata_unittest.cc
  129. httpssvc_metrics.cc
  130. httpssvc_metrics.h
  131. httpssvc_metrics_unittest.cc
  132. loopback_only.cc
  133. loopback_only.h
  134. loopback_only_unittest.cc
  135. mapped_host_resolver.cc
  136. mapped_host_resolver.h
  137. mapped_host_resolver_unittest.cc
  138. mdns_cache.cc
  139. mdns_cache.h
  140. mdns_cache_unittest.cc
  141. mdns_client.cc
  142. mdns_client.h
  143. mdns_client_impl.cc
  144. mdns_client_impl.h
  145. mdns_client_unittest.cc
  146. mock_host_resolver.cc
  147. mock_host_resolver.h
  148. mock_mdns_client.cc
  149. mock_mdns_client.h
  150. mock_mdns_socket_factory.cc
  151. mock_mdns_socket_factory.h
  152. netinet_in_var_ios.h
  153. notify_watcher_mac.cc
  154. notify_watcher_mac.h
  155. nsswitch_reader.cc
  156. nsswitch_reader.h
  157. nsswitch_reader_fuzzer.cc
  158. nsswitch_reader_unittest.cc
  159. opt_record_rdata.cc
  160. opt_record_rdata.h
  161. opt_record_rdata_unittest.cc
  162. OWNERS
  163. README.md
  164. record_parsed.cc
  165. record_parsed.h
  166. record_parsed_unittest.cc
  167. record_rdata.cc
  168. record_rdata.h
  169. record_rdata_unittest.cc
  170. resolve_context.cc
  171. resolve_context.h
  172. resolve_context_unittest.cc
  173. serial_worker.cc
  174. serial_worker.h
  175. serial_worker_unittest.cc
  176. system_dns_config_change_notifier.cc
  177. system_dns_config_change_notifier.h
  178. system_dns_config_change_notifier_unittest.cc
  179. test_dns_config_service.cc
  180. test_dns_config_service.h
net/dns/README.md

Chrome Host Resolution

Implementation and support of host resolution for the Chrome network stack. Includes client implementations of host resolution protocols (DNS and mDNS), host resolution caching, support for dealing with system host resolution (including reading HOSTS files and tracking system network settings related to host resolution), and various related utilities.

Note: “DNS” in this directory (including the directory name) is often used as shorthand for all host resolution, not just that using the Domain Name System. This document attempts to use “DNS” only to refer to the actual Domain Name System, except when referring to strings or paths that contain other usage of “DNS”.

Usage

From outside the network service

Most interaction with host resolution should be through the network service network::HostResolver, retrieved from network::NetworkContext using network::NetworkContext::CreateHostResolver().

Host resolution is requested using network::HostResolver::ResolveHost(). There is also a shortcut using network::NetworkContext::ResolveHost() when a separate passable object is not needed.

Some general utilities are also available in /net/dns/public/ that are intended for use by any code, inside or outside the network service. Otherwise, code outside the network service should never interact directly with the code in /net/dns/.

From inside the network service

Inside the network service or inside the Chrome networking stack, host resolution goes through net::HostResolver, retrieved from net::URLRequestContext.

Stand-alone tools

Tests and stand-alone tools not part of the browser may interact with host resolution directly by creating their own HostResolvers using net::HostResolver::CreateStandaloneResolver().

Test support

MockHostResolver

net::MockHostResolver

Tests with the ability to inject and replace the used net::HostResolver should replace it with a net::MockHostResolver, allowing rule-based results. net::MockCachingHostResolver is the same except it includes basic support for the caching functionality normally done by prod net::HostResolvers.

Some tests may also find net::HangingHostResolver useful. It will begin host resolution requests, but never complete them until cancellation.

TestHostResolver

content::TestHostResolver

Used by most browser tests (via content::BrowserTestBase), content::TestHostResolver installs itself on creation globally into all host resolvers in the process. By default, only allows resolution of the local host and returns net::ERR_NAME_NOT_RESOLVED for other hostnames. Allows setting rules for other results using a net::RuleBasedHostResolverProc.

Warning: content::TestHostResolver only replaces host address resolution to the system and then artificially uses such system resolution for many requests that would normally be handled differently (e.g. using the built-in DNS client). This means a significant amount of normal prod host resolution logic will be bypassed in tests using content::TestHostResolver.

Request remapping

Most prod logic for creating HostResolvers will check if any global remappings have been requested. In the browser, this is requested using the “host-resolver-rules” commandline flag.

See net::HostMappingRules for details on the format of the rules string. Allows remapping any request hostname to another hostname, an IP address, or a NOTFOUND error.

Implementation

HostResolver

net::HostResolver

The main interface for requesting host resolution within the network stack or network service. In prod, generally owned, and retrieved as-needed from net::URLRequestContexts. Created using net::HostResolver::CreateResolver() or net::HostResolver::CreateStandaloneResolver().

Various implementations are used in prod.

ContextHostResolver

net::ContextHostResolver

The main prod implementation of net::HostResolver. Expected to be owned 1:1 by a single net::URLRequestContext, the net::ContextHostResolver owns or keeps references to per-URLRequestContext properties used for host resolution, including an owned net::HostCache.

On resolution, calls into an underlying net::HostResolverManager with the per- context properties.

On destruction, silently cancels all host resolution requests made through the net::ContextHostResolver instance. This prevents the underlying net::HostResolverManager from continuing to reference the per-context properties that may be destroyed on destruction of the net::URLRequestContext or net::ContextHostResolver.

MappedHostResolver

net::MappedHostResolver

A wrapping implementation around another net::HostResolver. Maintains request remapping rules to remap request hostnames to other hostnames or IP addresses.

Used to implement the “host-resolver-rules” commandline flag.

StaleHostResolver

cronet::StaleHostResolver

A wrapping implementation around another net::HostResolver. Returns stale (expired or invalidated by network changes) data from the net::HostCache when non-stale results take longer than a configurable timeout. Reduces host resolution latency at the expense of accuracy.

Only used and created by Cronet.

HostResolverManager

net::HostResolverManager

Scheduler and controller of host resolution requests. Contains the logic for immediate host resolution from fast local sources (e.g. querying net::HostCaches, IP address literals, etc). Throttles, schedules, and merges asynchronous jobs for resolution from slower network sources.

On destruction, silently cancels all in-progress host resolution requests.

In prod, a single shared net::HostResolverManager is generally used for the entire browser. The shared manager is owned and configured by the network::NetworkService.

Request

net::HostResolverManager::RequestImpl

Implementation of net::HostResolver::ResolveHostRequest and overall representation of a single request for resolution from a net::HostResolverManager. The RequestImpl object itself primarily acts only as a container of parameters and results for the request, leaving the actual logic to the net::HostResolverManager itself.

Data collected at this layer:

  • “Net.DNS.Request.TotalTime” (recommended for experiments)
  • “Net.DNS.Request.TotalTimeAsync”

Job

net::HostResolverManager::Job

Representation of an asynchronous job for resolution from slower network sources. Contains the logic to determine and query the appropriate source for host resolution results with retry and fallback support to other sources. On completion adds results to relevant net::HostCaches and invokes request callbacks.

Multiple requests can be merged into a single Job if compatible. This includes merging newly-started Jobs with already-running Jobs.

net::HostResolverManager schedules and throttles running net::HostResolverManager::Jobs using a net::PrioritizedDispatcher. The throttling is important to avoid overworking network sources, especially poorly designed home routers that may crash on only a small number of concurrent DNS resolves.

Data collected at this layer:

  • “Net.DNS.ResolveSuccessTime”
  • “Net.DNS.ResolveFailureTime”
  • “Net.DNS.ResolveCategory”
  • “Net.DNS.ResolveError.Fast”
  • “Net.DNS.ResolveError.Slow”

Host resolution sources

Various sources are used to query host resolution. The sources to be used by a net::HostResolverManager::Job are determined in advance of running the Job by net::HostResolverManager::CreateTaskSequence(), which outputs a list of net::HostResolverManager::TaskType specifying the order of sources to attempt. By default, this will use internal logic to decide the source to use and will often allow fallback to additional sources.

The sources chosen by default are also affected by the Secure DNS mode, by default determined from net::DnsConfig::secure_dns_mode but overridable for individual requests using net::HostResolver::ResolveHostParameters::secure_dns_mode_override.

Specific sources for a request can be specified using net::HostResolver::ResolveHostParameters::source and net::HostResolverSource.

The Job will then use *Task objects that implement the behavior specific to the particular resolution sources.

SYSTEM

net::HostResolverSource::SYSTEM net::HostResolverManager::TaskType::SYSTEM

Implemented by: net::HostResolverSystemTask

Usually called the “system resolver” or sometimes the “proc resolver” (because it was historically always implemented using net::HostResolverProc). Results are queried from the system or OS using the getaddrinfo() OS API call. This source is only capable of address (A and AAAA) resolves but will also query for canonname info if the request includes the HOST_RESOLVER_CANONNAME flag. The system will query from its own internal cache, HOSTS files, DNS, and sometimes mDNS, depending on the capabilities of the system.

When host resolution requests do not specify a source, the system resolver will always be used for address resolves when any of the following are true:

  • Requests with the HOST_RESOLVER_CANONNAME flag
  • For hostnames ending in “.local”
  • When the Secure DNS mode is net::SecureDnsMode::OFF and net::HostResolverSource::DNS is not enabled via net::HostResolverManager::SetInsecureDnsClientEnabled(true)
  • When a system DNS configuration could not be determined

Secure DNS requests cannot be made using the system resolver.

net::HostResolverSystemTask's behavior can be overridden by an asynchronous global override (e.g. in case resolution needs to be brokered out of the current process for sandboxing reasons). Otherwise, it posts a blocking task to a base::ThreadPool to make blocking resolution requests in-process. On a timeout, additional attempts are made, but previous attempts are not cancelled as there is no cancellation mechanism for getaddrinfo(). The first attempt to complete is used and any other attempt completions are ignored.

In prod, the blocking task runner always calls SystemHostResolverCall(), which makes the actual call to getaddrinfo() using the net::AddressInfo helper. In tests, the blocking task runner may use a test implementation of net::HostResolverProc, which itself can be chained.

Data collected specifically for this source:

  • “Net.DNS.SystemTask.SuccessTime”
  • “Net.DNS.SystemTask.FailureTime”

DNS

net::HostResolverSource::DNS net::HostResolverManager::TaskType::DNS net::HostResolverManager::TaskType::SECURE_DNS

Implemented by: net::HostResolverManager::DnsTask

Usually called the “built-in resolver” or the “async resolver”. Results are queried from DNS using net::DnsClient, a Chrome network stack implementation of a DNS “stub resolver” or “DNS client”.

When host resolution requests do not specify a source, the built-in resolver will be used when all of the following are true:

  • DnsClient is enabled for insecure requests enabled via net::HostResolverManager::SetInsecureDnsClientEnabled(true) or the Secure DNS mode is not net::SecureDnsMode::OFF.
  • The system DNS configuration could be determined successfully
  • The request hostname does not end in “.local”
  • The request is not an address query with the HOST_RESOLVER_CANONNAME flag

The net::HostResolverManager::DnsTask will create and run a net::DnsTransaction for each DNS name/type pair to be queried. The task will then process successful results from the returned net::DnsResponse.

When a request requires both A and AAAA results, they are handled via two separate net::DnsTransactions and the net::HostResolverManager::DnsTask will request a second slots from the net::PrioritizedDispatcher used by net::HostResolverManager. The A transaction is started immediately on starting the net::HostResolverManager::DnsTask, and the AAAA transaction is started once a second dispatcher slot can be obtained.

Each net::DnsTransaction internally makes a series of net::DnsAttempts, each representing an individual DNS request. A single net::DnsTransaction can run many net::DnsAttempts due to retry logic, fallback between multiple configured DNS servers, and name permutation due to configured search suffixes.

Data collected specifically for this source (more internally to net::DnsTransaction implementation not listed here):

  • “Net.DNS.DnsTask.SuccessTime”
  • “Net.DNS.InsecureDnsTask.FailureTime”
  • “Net.DNS.JobQueueTime.PerTransaction”
  • “Net.DNS.JobQueueTime.Failure”
  • “Net.DNS.JobQueueTime.Success”

MULTICAST_DNS

net::HostResolverSource::MULTICAST_DNS net::HostResolverManager::TaskType::MDNS

Implemented by net::HostResolverMdnsTask

Results are queried from mDNS using net::MDnsClient.

When host resolution requests do not specify a source, mDNS is only used for non-address requests when the request hostname ends in “.local”.

mDNS requests start with net::HostResolverMdnsTask, which will create and run a net::MDnsTransaction for each query type needed.

Unlike net::HostResolverManager::DnsTask, each net::HostResolverMdnsTask will only ever use a single dispatcher slot, even when both A and AAAA types are queried concurrently.

net::MDnsClient maintains its own cache, separate from the main net::HostCache owned by the net::ContextHostResolver. As such, mDNS results are never cached in the net::HostCache.

IPv6 and connectivity

Some poorly written DNS servers, especially on home routers, are unaware of the existence of IPv6 and will result in bad performance or even crash when sent AAAA DNS queries.

To avoid such issues, net::HostResolverManager heuristically detects IPv4-only networks by attempting a UDP connection to 2001:4860:4860::8888 (the IPv6 address for Google Public DNS). If the connection fails, Chrome will convert host resolution requests for net::DnsQueryType::UNSPECIFIED to net::DnsQueryType::A. This generally results in disallowing AAAA requests.

Exceptions when AAAA requests are always allowed despite a failed connectivity check:

  • The host resolution request explicitly requests net::DnsQueryType::AAAA
  • IP address literal resolution including when a hostname request has been rewritten to an IP address literal using net::MappedHostResolver
  • Results read from HOSTS files where there is no non-loopback IPv4 result. Note that this exception only applies when Chrome does the read from HOSTS. When Chrome's built-in DNS client is not used, HOSTS is only read by the system where Chrome would only request A results to avoid the system making AAAA DNS queries.

The heuristic for detecting IPv4-only networks is not perfect. E.g., it fails and disallows AAAA requests in private (no global internet access including to Google Public DNS) IPv6-only networks, which could then break most Chrome usage on the network because, being an IPv6-only network, AAAA results are necessary.

Workarounds to allow Chrome to attempt to load IPv6 endpoints when the connectivity check fails:

  • Starting Chrome with --host-resolver-rules="MAP the.hostname.com [dead::beef]" where the.hostname.com is the hostname to allow resolving and dead::beef is the IPv6 address to resolve it to. net::MappedHostResolver acts at a level before IPv6 connectivity checks, and if a hostname is remapped to an IP literal, connectivity checks do not apply.
  • Add entries for the hostnames to resolve to the HOSTS file with just IPv6 results. Only works with the built-in DNS client is used.
  • Add a network route to 2001:4860:4860::8888. Doesn't have to actually be functional (could just drop requests to it). As long as Chrome can connect a UDP socket to the address, it will pass the heuristic checking IPv6-connectivity.