• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef NET_DNS_HOST_RESOLVER_MANAGER_H_
6 #define NET_DNS_HOST_RESOLVER_MANAGER_H_
7 
8 #include <stddef.h>
9 #include <stdint.h>
10 
11 #include <deque>
12 #include <map>
13 #include <memory>
14 #include <set>
15 #include <string>
16 #include <vector>
17 
18 #include "base/functional/callback.h"
19 #include "base/functional/callback_helpers.h"
20 #include "base/memory/raw_ptr.h"
21 #include "base/memory/scoped_refptr.h"
22 #include "base/memory/weak_ptr.h"
23 #include "base/observer_list.h"
24 #include "base/strings/string_piece.h"
25 #include "base/time/time.h"
26 #include "base/timer/timer.h"
27 #include "base/values.h"
28 #include "net/base/completion_once_callback.h"
29 #include "net/base/host_port_pair.h"
30 #include "net/base/network_anonymization_key.h"
31 #include "net/base/network_change_notifier.h"
32 #include "net/base/network_handle.h"
33 #include "net/base/prioritized_dispatcher.h"
34 #include "net/dns/dns_config.h"
35 #include "net/dns/host_cache.h"
36 #include "net/dns/host_resolver.h"
37 #include "net/dns/httpssvc_metrics.h"
38 #include "net/dns/public/dns_config_overrides.h"
39 #include "net/dns/public/dns_query_type.h"
40 #include "net/dns/public/secure_dns_mode.h"
41 #include "net/dns/public/secure_dns_policy.h"
42 #include "net/dns/resolve_context.h"
43 #include "net/dns/system_dns_config_change_notifier.h"
44 #include "net/log/net_log_with_source.h"
45 #include "net/socket/datagram_client_socket.h"
46 #include "third_party/abseil-cpp/absl/types/optional.h"
47 #include "third_party/abseil-cpp/absl/types/variant.h"
48 #include "url/gurl.h"
49 #include "url/scheme_host_port.h"
50 
51 namespace base {
52 class TickClock;
53 }  // namespace base
54 
55 namespace net {
56 
57 class DnsClient;
58 class DnsProbeRunner;
59 class IPAddress;
60 class MDnsClient;
61 class ClientSocketFactory;
62 class MDnsSocketFactory;
63 class NetLog;
64 
65 // Scheduler and controller of host resolution requests. Because of the global
66 // nature of host resolutions, this class is generally expected to be singleton
67 // within the browser and only be interacted with through per-context
68 // ContextHostResolver objects (which are themselves generally interacted with
69 // though the HostResolver interface).
70 //
71 // For each hostname that is requested, HostResolver creates a
72 // HostResolverManager::Job. When this job gets dispatched it creates a task
73 // (HostResolverSystemTask for the system resolver or DnsTask for the async
74 // resolver) which resolves the hostname. If requests for that same host are
75 // made during the job's lifetime, they are attached to the existing job rather
76 // than creating a new one. This avoids doing parallel resolves for the same
77 // host.
78 //
79 // The way these classes fit together is illustrated by:
80 //
81 //
82 //            +----------- HostResolverManager ----------+
83 //            |                    |                     |
84 //           Job                  Job                   Job
85 //    (for host1, fam1)    (for host2, fam2)     (for hostx, famx)
86 //       /    |   |            /   |   |             /   |   |
87 //   Request ... Request  Request ... Request   Request ... Request
88 //  (port1)     (port2)  (port3)      (port4)  (port5)      (portX)
89 //
90 // When a HostResolverManager::Job finishes, the callbacks of each waiting
91 // request are run on the origin thread.
92 //
93 // Thread safety: This class is not threadsafe, and must only be called
94 // from one thread!
95 //
96 // The HostResolverManager enforces limits on the maximum number of concurrent
97 // threads using PrioritizedDispatcher::Limits.
98 //
99 // Jobs are ordered in the queue based on their priority and order of arrival.
100 class NET_EXPORT HostResolverManager
101     : public NetworkChangeNotifier::IPAddressObserver,
102       public NetworkChangeNotifier::ConnectionTypeObserver,
103       public SystemDnsConfigChangeNotifier::Observer {
104  public:
105   using MdnsListener = HostResolver::MdnsListener;
106   using ResolveHostParameters = HostResolver::ResolveHostParameters;
107   using PassKey = base::PassKey<HostResolverManager>;
108 
109   // Creates a HostResolver as specified by |options|. Blocking tasks are run in
110   // ThreadPool.
111   //
112   // If Options.enable_caching is true, a cache is created using
113   // HostCache::CreateDefaultCache(). Otherwise no cache is used.
114   //
115   // Options.GetDispatcherLimits() determines the maximum number of jobs that
116   // the resolver will run at once. This upper-bounds the total number of
117   // outstanding DNS transactions (not counting retransmissions and retries).
118   //
119   // |net_log| and |system_dns_config_notifier|, if non-null, must remain valid
120   // for the life of the HostResolverManager.
121   HostResolverManager(const HostResolver::ManagerOptions& options,
122                       SystemDnsConfigChangeNotifier* system_dns_config_notifier,
123                       NetLog* net_log);
124 
125   HostResolverManager(const HostResolverManager&) = delete;
126   HostResolverManager& operator=(const HostResolverManager&) = delete;
127 
128   // If any completion callbacks are pending when the resolver is destroyed,
129   // the host resolutions are cancelled, and the completion callbacks will not
130   // be called.
131   ~HostResolverManager() override;
132 
133   // Same as constructor above, but binds the HostResolverManager to
134   // `target_network`: all DNS requests will be performed for `target_network`
135   // only, requests will fail if `target_network` disconnects. Only
136   // HostResolvers bound to the same network will be able to use this.
137   // Only implemented for Android.
138   static std::unique_ptr<HostResolverManager>
139   CreateNetworkBoundHostResolverManager(
140       const HostResolver::ManagerOptions& options,
141       handles::NetworkHandle target_network,
142       NetLog* net_log);
143 
144   // |resolve_context| must have already been added (via
145   // RegisterResolveContext()). If |optional_parameters| specifies any cache
146   // usage other than LOCAL_ONLY, there must be a 1:1 correspondence between
147   // |resolve_context| and |host_cache|, and both should come from the same
148   // ContextHostResolver.
149   //
150   // TODO(crbug.com/1022059): Use the HostCache out of the ResolveContext
151   // instead of passing it separately.
152   std::unique_ptr<HostResolver::ResolveHostRequest> CreateRequest(
153       absl::variant<url::SchemeHostPort, HostPortPair> host,
154       NetworkAnonymizationKey network_anonymization_key,
155       NetLogWithSource net_log,
156       absl::optional<ResolveHostParameters> optional_parameters,
157       ResolveContext* resolve_context,
158       HostCache* host_cache);
159   std::unique_ptr<HostResolver::ResolveHostRequest> CreateRequest(
160       HostResolver::Host host,
161       NetworkAnonymizationKey network_anonymization_key,
162       NetLogWithSource net_log,
163       absl::optional<ResolveHostParameters> optional_parameters,
164       ResolveContext* resolve_context,
165       HostCache* host_cache);
166   // |resolve_context| is the context to use for the probes, and it is expected
167   // to be the context of the calling ContextHostResolver.
168   std::unique_ptr<HostResolver::ProbeRequest> CreateDohProbeRequest(
169       ResolveContext* resolve_context);
170   std::unique_ptr<MdnsListener> CreateMdnsListener(const HostPortPair& host,
171                                                    DnsQueryType query_type);
172 
173   // Enables or disables the built-in asynchronous DnsClient. If enabled, by
174   // default (when no |ResolveHostParameters::source| is specified), the
175   // DnsClient will be used for resolves and, in case of failure, resolution
176   // will fallback to the system resolver (in tests, HostResolverProc from
177   // HostResolverSystemTask::Params). If the DnsClient is not pre-configured
178   // with a valid DnsConfig, a new config is fetched from NetworkChangeNotifier.
179   //
180   // Setting to |true| has no effect if |ENABLE_BUILT_IN_DNS| not defined.
181   virtual void SetInsecureDnsClientEnabled(bool enabled,
182                                            bool additional_dns_types_enabled);
183 
184   base::Value::Dict GetDnsConfigAsValue() const;
185 
186   // Sets overriding configuration that will replace or add to configuration
187   // read from the system for DnsClient resolution.
188   void SetDnsConfigOverrides(DnsConfigOverrides overrides);
189 
190   void SetIPv6ReachabilityOverride(bool reachability_override);
191 
192   // Support for invalidating cached per-context data on changes to network or
193   // DNS configuration. ContextHostResolvers should register/deregister
194   // themselves here rather than attempting to listen for relevant network
195   // change signals themselves because HostResolverManager needs to coordinate
196   // invalidations with in-progress resolves and because some invalidations are
197   // triggered by changes to manager properties/configuration rather than pure
198   // network changes.
199   //
200   // Note: Invalidation handling must not call back into HostResolverManager as
201   // the invalidation is expected to be handled atomically with other clearing
202   // and aborting actions.
203   void RegisterResolveContext(ResolveContext* context);
204   void DeregisterResolveContext(const ResolveContext* context);
205 
set_host_resolver_system_params_for_test(const HostResolverSystemTask::Params & host_resolver_system_params)206   void set_host_resolver_system_params_for_test(
207       const HostResolverSystemTask::Params& host_resolver_system_params) {
208     host_resolver_system_params_ = host_resolver_system_params;
209   }
210 
InvalidateCachesForTesting()211   void InvalidateCachesForTesting() { InvalidateCaches(); }
212 
213   void SetTickClockForTesting(const base::TickClock* tick_clock);
214 
215   // Configures maximum number of Jobs in the queue. Exposed for testing.
216   // Only allowed when the queue is empty.
217   void SetMaxQueuedJobsForTesting(size_t value);
218 
219   void SetMdnsSocketFactoryForTesting(
220       std::unique_ptr<MDnsSocketFactory> socket_factory);
221   void SetMdnsClientForTesting(std::unique_ptr<MDnsClient> client);
222 
223   // To simulate modifications it would have received if |dns_client| had been
224   // in place before calling this, DnsConfig will be set with the configuration
225   // from the previous DnsClient being replaced (including system config if
226   // |dns_client| does not already contain a system config). This means tests do
227   // not normally need to worry about ordering between setting a test client and
228   // setting DnsConfig.
229   void SetDnsClientForTesting(std::unique_ptr<DnsClient> dns_client);
230 
231   // Explicitly disable the system resolver even if tests have set a catch-all
232   // DNS block. See `ForceSystemResolverDueToTestOverride`.
DisableSystemResolverForTesting()233   void DisableSystemResolverForTesting() {
234     system_resolver_disabled_for_testing_ = true;
235   }
236 
237   // Sets the last IPv6 probe result for testing. Uses the standard timeout
238   // duration, so it's up to the test fixture to ensure it doesn't expire by
239   // mocking time, if expiration would pose a problem.
240   void SetLastIPv6ProbeResultForTesting(bool last_ipv6_probe_result);
241 
ResetIPv6ProbeTimeForTesting()242   void ResetIPv6ProbeTimeForTesting() {
243     last_ipv6_probe_time_ = base::TimeTicks();
244   }
245 
246   // Allows the tests to catch slots leaking out of the dispatcher.  One
247   // HostResolverManager::Job could occupy multiple PrioritizedDispatcher job
248   // slots.
num_running_dispatcher_jobs_for_tests()249   size_t num_running_dispatcher_jobs_for_tests() const {
250     return dispatcher_->num_running_jobs();
251   }
252 
num_jobs_for_testing()253   size_t num_jobs_for_testing() const { return jobs_.size(); }
254 
check_ipv6_on_wifi_for_testing()255   bool check_ipv6_on_wifi_for_testing() const { return check_ipv6_on_wifi_; }
256 
target_network_for_testing()257   handles::NetworkHandle target_network_for_testing() const {
258     return target_network_;
259   }
260 
https_svcb_options_for_testing()261   const HostResolver::HttpsSvcbOptions& https_svcb_options_for_testing() const {
262     return https_svcb_options_;
263   }
264 
265   // Public to be called from std::make_unique. Not to be called directly.
266   HostResolverManager(base::PassKey<HostResolverManager>,
267                       const HostResolver::ManagerOptions& options,
268                       SystemDnsConfigChangeNotifier* system_dns_config_notifier,
269                       handles::NetworkHandle target_network,
270                       NetLog* net_log);
271 
272  protected:
273   // Callback from HaveOnlyLoopbackAddresses probe.
274   void SetHaveOnlyLoopbackAddresses(bool result);
275 
276  private:
277   friend class HostResolverManagerTest;
278   friend class HostResolverManagerDnsTest;
279   class Job;
280   struct JobKey;
281   class LoopbackProbeJob;
282   class DnsTask;
283   class RequestImpl;
284   class ProbeRequestImpl;
285   using JobMap = std::map<JobKey, std::unique_ptr<Job>>;
286 
287   // Task types that a Job might run.
288   // These values are persisted to logs. Entries should not be renumbered and
289   // numeric values should never be reused
290   enum class TaskType {
291     SYSTEM = 0,
292     DNS = 1,
293     SECURE_DNS = 2,
294     MDNS = 3,
295     CACHE_LOOKUP = 4,
296     INSECURE_CACHE_LOOKUP = 5,
297     SECURE_CACHE_LOOKUP = 6,
298     CONFIG_PRESET = 7,
299     NAT64 = 8,
300     HOSTS = 9,
301 
302     kMaxValue = HOSTS,
303   };
304 
305   // Returns true if the task is local, synchronous, and instantaneous.
306   static bool IsLocalTask(TaskType task);
307 
308   // Attempts host resolution using fast local sources: IP literal resolution,
309   // cache lookup, HOSTS lookup (if enabled), and localhost. Returns results
310   // with error() OK if successful, ERR_NAME_NOT_RESOLVED if input is invalid,
311   // or ERR_DNS_CACHE_MISS if the host could not be resolved using local
312   // sources.
313   //
314   // On ERR_DNS_CACHE_MISS and OK, |out_tasks| contains the tentative
315   // sequence of tasks that a future job should run.
316   //
317   // If results are returned from the host cache, |out_stale_info| will be
318   // filled in with information on how stale or fresh the result is. Otherwise,
319   // |out_stale_info| will be set to |absl::nullopt|.
320   //
321   // If |cache_usage == ResolveHostParameters::CacheUsage::STALE_ALLOWED|, then
322   // stale cache entries can be returned.
323   HostCache::Entry ResolveLocally(
324       bool only_ipv6_reachable,
325       const JobKey& job_key,
326       const IPAddress& ip_address,
327       ResolveHostParameters::CacheUsage cache_usage,
328       SecureDnsPolicy secure_dns_policy,
329       HostResolverSource source,
330       const NetLogWithSource& source_net_log,
331       HostCache* cache,
332       std::deque<TaskType>* out_tasks,
333       absl::optional<HostCache::EntryStaleness>* out_stale_info);
334 
335   // Creates and starts a Job to asynchronously attempt to resolve
336   // |request|.
337   void CreateAndStartJob(JobKey key,
338                          std::deque<TaskType> tasks,
339                          RequestImpl* request);
340 
341   HostResolverManager::Job* AddJobWithoutRequest(
342       JobKey key,
343       ResolveHostParameters::CacheUsage cache_usage,
344       HostCache* host_cache,
345       std::deque<TaskType> tasks,
346       RequestPriority priority,
347       const NetLogWithSource& source_net_log);
348 
349   // Resolves the IP literal hostname represented by `ip_address`.
350   HostCache::Entry ResolveAsIP(DnsQueryTypeSet query_types,
351                                bool resolve_canonname,
352                                const IPAddress& ip_address);
353 
354   // Returns the result iff |cache_usage| permits cache lookups and a positive
355   // match is found for |key| in |cache|. |out_stale_info| must be non-null, and
356   // will be filled in with details of the entry's staleness if an entry is
357   // returned, otherwise it will be set to |absl::nullopt|.
358   absl::optional<HostCache::Entry> MaybeServeFromCache(
359       HostCache* cache,
360       const HostCache::Key& key,
361       ResolveHostParameters::CacheUsage cache_usage,
362       bool ignore_secure,
363       const NetLogWithSource& source_net_log,
364       absl::optional<HostCache::EntryStaleness>* out_stale_info);
365 
366   // Returns any preset resolution result from the active DoH configuration that
367   // matches |key.host|.
368   absl::optional<HostCache::Entry> MaybeReadFromConfig(const JobKey& key);
369 
370   // Populates the secure cache with an optimal entry that supersedes the
371   // bootstrap result.
372   void StartBootstrapFollowup(JobKey key,
373                               HostCache* host_cache,
374                               const NetLogWithSource& source_net_log);
375 
376   // Iff we have a DnsClient with a valid DnsConfig and we're not about to
377   // attempt a system lookup, then try to resolve the query using the HOSTS
378   // file.
379   absl::optional<HostCache::Entry> ServeFromHosts(
380       base::StringPiece hostname,
381       DnsQueryTypeSet query_types,
382       bool default_family_due_to_no_ipv6,
383       const std::deque<TaskType>& tasks);
384 
385   // Iff |key| is for a localhost name (RFC 6761) and address DNS query type,
386   // returns a results entry with the loopback IP.
387   absl::optional<HostCache::Entry> ServeLocalhost(
388       base::StringPiece hostname,
389       DnsQueryTypeSet query_types,
390       bool default_family_due_to_no_ipv6);
391 
392   // Returns the secure dns mode to use for a job, taking into account the
393   // global DnsConfig mode and any per-request policy.
394   SecureDnsMode GetEffectiveSecureDnsMode(SecureDnsPolicy secure_dns_policy);
395 
396   // Returns true when a catch-all DNS block has been set for tests, unless
397   // `SetDisableSystemResolverForTesting` has been called to explicitly disable
398   // that safety net. DnsTasks should never be issued when this returns true.
399   bool ShouldForceSystemResolverDueToTestOverride() const;
400 
401   // Helper method to add DnsTasks and related tasks based on the SecureDnsMode
402   // and fallback parameters. If |prioritize_local_lookups| is true, then we
403   // may push an insecure cache lookup ahead of a secure DnsTask.
404   void PushDnsTasks(bool system_task_allowed,
405                     SecureDnsMode secure_dns_mode,
406                     bool insecure_tasks_allowed,
407                     bool allow_cache,
408                     bool prioritize_local_lookups,
409                     ResolveContext* resolve_context,
410                     std::deque<TaskType>* out_tasks);
411 
412   // Initialized the sequence of tasks to run to resolve a request. The sequence
413   // may be adjusted later and not all tasks need to be run.
414   void CreateTaskSequence(const JobKey& job_key,
415                           ResolveHostParameters::CacheUsage cache_usage,
416                           SecureDnsPolicy secure_dns_policy,
417                           std::deque<TaskType>* out_tasks);
418 
419   // Determines "effective" request parameters using manager properties and IPv6
420   // reachability.
421   void GetEffectiveParametersForRequest(
422       const absl::variant<url::SchemeHostPort, std::string>& host,
423       DnsQueryType dns_query_type,
424       HostResolverFlags flags,
425       SecureDnsPolicy secure_dns_policy,
426       bool is_ip,
427       const NetLogWithSource& net_log,
428       DnsQueryTypeSet* out_effective_types,
429       HostResolverFlags* out_effective_flags,
430       SecureDnsMode* out_effective_secure_dns_mode);
431 
432   // Schedules probes to check IPv6 support. Returns OK if probe results are
433   // already cached, and ERR_IO_PENDING when a probe is scheduled to be
434   // completed asynchronously. When called repeatedly this method returns OK to
435   // confirm that results have been cached.
436   int StartIPv6ReachabilityCheck(const NetLogWithSource& net_log,
437                                  ClientSocketFactory* client_socket_factory,
438                                  CompletionOnceCallback callback);
439 
440   void FinishIPv6ReachabilityCheck(CompletionOnceCallback callback, int rv);
441 
442   // Sets |last_ipv6_probe_result_| and updates |last_ipv6_probe_time_|.
443   void SetLastIPv6ProbeResult(bool last_ipv6_probe_result);
444 
445   // Attempts to connect a UDP socket to |dest|:53. Virtual for testing. Returns
446   // the value of the attempted socket connection and the reachability check. If
447   // the return value from the connection is not ERR_IO_PENDING, callers must
448   // handle the results of the reachability check themselves. Otherwise the
449   // result of the reachability check will be set when `callback` is run.
450   // Returns OK if the reachability check succeeded, ERR_FAILED if it failed,
451   // ERR_IO_PENDING if it will be asynchronous.
452   virtual int StartGloballyReachableCheck(
453       const IPAddress& dest,
454       const NetLogWithSource& net_log,
455       ClientSocketFactory* client_socket_factory,
456       CompletionOnceCallback callback);
457 
458   bool FinishGloballyReachableCheck(DatagramClientSocket* socket, int rv);
459 
460   void RunFinishGloballyReachableCheck(
461       scoped_refptr<base::RefCountedData<std::unique_ptr<DatagramClientSocket>>>
462           socket,
463       CompletionOnceCallback callback,
464       int rv);
465 
466   // Asynchronously checks if only loopback IPs are available.
467   virtual void RunLoopbackProbeJob();
468 
469   // Records the result in cache if cache is present.
470   void CacheResult(HostCache* cache,
471                    const HostCache::Key& key,
472                    const HostCache::Entry& entry,
473                    base::TimeDelta ttl);
474 
475   // Removes |job_it| from |jobs_| and return.
476   std::unique_ptr<Job> RemoveJob(JobMap::iterator job_it);
477 
478   // Removes Jobs for this context.
479   void RemoveAllJobs(const ResolveContext* context);
480 
481   // Aborts all jobs (both scheduled and running) which are not targeting a
482   // specific network with ERR_NETWORK_CHANGED and notifies their requests.
483   // Aborts only running jobs if `in_progress_only` is true. Might start new
484   // jobs.
485   void AbortJobsWithoutTargetNetwork(bool in_progress_only);
486 
487   // Aborts all in progress insecure DnsTasks. In-progress jobs will fall back
488   // to HostResolverSystemTasks if able and otherwise abort with |error|. Might
489   // start new jobs, if any jobs were taking up two dispatcher slots.
490   //
491   // If |fallback_only|, insecure DnsTasks will only abort if they can fallback
492   // to HostResolverSystemTasks.
493   void AbortInsecureDnsTasks(int error, bool fallback_only);
494 
495   // Attempts to serve each Job in |jobs_| from the HOSTS file if we have
496   // a DnsClient with a valid DnsConfig.
497   void TryServingAllJobsFromHosts();
498 
499   // NetworkChangeNotifier::IPAddressObserver:
500   void OnIPAddressChanged() override;
501 
502   // NetworkChangeNotifier::ConnectionTypeObserver:
503   void OnConnectionTypeChanged(
504       NetworkChangeNotifier::ConnectionType type) override;
505 
506   // SystemDnsConfigChangeNotifier::Observer:
507   void OnSystemDnsConfigChanged(absl::optional<DnsConfig> config) override;
508 
509   void UpdateJobsForChangedConfig();
510 
511   // Called on successful resolve after falling back to HostResolverSystemTask
512   // after a failed DnsTask resolve.
513   void OnFallbackResolve(int dns_task_error);
514 
515   int GetOrCreateMdnsClient(MDnsClient** out_client);
516 
517   // |network_change| indicates whether or not the invalidation was triggered
518   // by a network connection change.
519   void InvalidateCaches(bool network_change = false);
520 
521   void UpdateConnectionType(NetworkChangeNotifier::ConnectionType type);
522 
IsBoundToNetwork()523   bool IsBoundToNetwork() const {
524     return target_network_ != handles::kInvalidNetworkHandle;
525   }
526 
527   // Returns |nullptr| if DoH probes are currently not allowed (due to
528   // configuration or current connection state).
529   std::unique_ptr<DnsProbeRunner> CreateDohProbeRunner(
530       ResolveContext* resolve_context);
531 
532   // Used for multicast DNS tasks. Created on first use using
533   // GetOrCreateMndsClient().
534   std::unique_ptr<MDnsSocketFactory> mdns_socket_factory_;
535   std::unique_ptr<MDnsClient> mdns_client_;
536 
537   // Map from HostCache::Key to a Job.
538   JobMap jobs_;
539 
540   // Starts Jobs according to their priority and the configured limits.
541   std::unique_ptr<PrioritizedDispatcher> dispatcher_;
542 
543   // Limit on the maximum number of jobs queued in |dispatcher_|.
544   size_t max_queued_jobs_ = 0;
545 
546   // Parameters for HostResolverSystemTask.
547   HostResolverSystemTask::Params host_resolver_system_params_;
548 
549   raw_ptr<NetLog> net_log_;
550 
551   // If present, used by DnsTask and ServeFromHosts to resolve requests.
552   std::unique_ptr<DnsClient> dns_client_;
553 
554   raw_ptr<SystemDnsConfigChangeNotifier> system_dns_config_notifier_;
555 
556   handles::NetworkHandle target_network_;
557 
558   // False if IPv6 should not be attempted and assumed unreachable when on a
559   // WiFi connection. See https://crbug.com/696569 for further context.
560   bool check_ipv6_on_wifi_;
561 
562   base::TimeTicks last_ipv6_probe_time_;
563   bool last_ipv6_probe_result_ = true;
564   bool probing_ipv6_ = false;
565 
566   // When true, query AAAA even when the globally reachable check failed.
567   bool ipv6_reachability_override_ = false;
568 
569   // Any resolver flags that should be added to a request by default.
570   HostResolverFlags additional_resolver_flags_ = 0;
571 
572   // Allow fallback to HostResolverSystemTask if DnsTask fails.
573   bool allow_fallback_to_systemtask_ = true;
574 
575   // Shared tick clock, overridden for testing.
576   raw_ptr<const base::TickClock> tick_clock_;
577 
578   // When true, ignore the catch-all DNS block if it exists.
579   bool system_resolver_disabled_for_testing_ = false;
580 
581   // For per-context cache invalidation notifications.
582   base::ObserverList<ResolveContext,
583                      true /* check_empty */,
584                      false /* allow_reentrancy */>
585       registered_contexts_;
586   bool invalidation_in_progress_ = false;
587 
588   // An experimental flag for features::kUseDnsHttpsSvcb.
589   HostResolver::HttpsSvcbOptions https_svcb_options_;
590 
591   std::vector<CompletionOnceCallback> ipv6_request_callbacks_;
592 
593   THREAD_CHECKER(thread_checker_);
594 
595   base::WeakPtrFactory<HostResolverManager> weak_ptr_factory_{this};
596 
597   base::WeakPtrFactory<HostResolverManager> probe_weak_ptr_factory_{this};
598 };
599 
600 // Resolves a local hostname (such as "localhost" or "vhost.localhost") into
601 // IP endpoints (with port 0). Returns true if |host| is a local
602 // hostname and false otherwise. Names will resolve to both IPv4 and IPv6.
603 // This function is only exposed so it can be unit-tested.
604 // TODO(tfarina): It would be better to change the tests so this function
605 // gets exercised indirectly through HostResolverManager.
606 NET_EXPORT_PRIVATE bool ResolveLocalHostname(
607     base::StringPiece host,
608     std::vector<IPEndPoint>* address_list);
609 
610 }  // namespace net
611 
612 #endif  // NET_DNS_HOST_RESOLVER_MANAGER_H_
613