blob: 8e71e8525fb0f64d8592a322bf9e295de5b3324c [file] [log] [blame]
[email protected]78eac2a2012-03-14 19:09:271// Copyright (c) 2012 The Chromium Authors. All rights reserved.
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_DNS_CLIENT_H_
6#define NET_DNS_DNS_CLIENT_H_
[email protected]78eac2a2012-03-14 19:09:277
danakj22f90e72016-04-16 01:55:408#include <memory>
9
Eric Orth394db1732019-08-27 20:09:3910#include "base/optional.h"
[email protected]78eac2a2012-03-14 19:09:2711#include "net/base/net_export.h"
mmenke91c17162016-06-02 16:03:2312#include "net/base/rand_callback.h"
Eric Orth394db1732019-08-27 20:09:3913#include "net/dns/dns_config.h"
14#include "net/dns/dns_config_overrides.h"
15#include "net/dns/dns_hosts.h"
dalykc2adf182019-09-02 14:31:2216#include "net/url_request/url_request_context.h"
[email protected]78eac2a2012-03-14 19:09:2717
18namespace net {
19
[email protected]0adcb2b2012-08-15 21:30:4620class AddressSorter;
mmenke91c17162016-06-02 16:03:2321class ClientSocketFactory;
[email protected]78eac2a2012-03-14 19:09:2722class DnsTransactionFactory;
23class NetLog;
24
Eric Orth394db1732019-08-27 20:09:3925// Entry point for HostResolverManager to interact with the built-in async
26// resolver, as implemented by DnsTransactionFactory. Manages configuration and
27// status of the resolver.
[email protected]78eac2a2012-03-14 19:09:2728class NET_EXPORT DnsClient {
29 public:
Eric Orth394db1732019-08-27 20:09:3930 static const int kMaxInsecureFallbackFailures = 16;
31
[email protected]78eac2a2012-03-14 19:09:2732 virtual ~DnsClient() {}
33
Eric Orth394db1732019-08-27 20:09:3934 // Returns true if the DnsClient is able and allowed to make secure DNS
35 // transactions. If false, secure transactions should not be created.
36 virtual bool CanUseSecureDnsTransactions() const = 0;
[email protected]78eac2a2012-03-14 19:09:2737
Eric Orth394db1732019-08-27 20:09:3938 // Returns true if the DnsClient is able and allowed to make insecure DNS
39 // transactions. If false, insecure transactions should not be created. Will
40 // always be false unless SetInsecureEnabled(true) has been called.
41 virtual bool CanUseInsecureDnsTransactions() const = 0;
42 virtual void SetInsecureEnabled(bool enabled) = 0;
[email protected]78eac2a2012-03-14 19:09:2743
dalykc2adf182019-09-02 14:31:2244 // When true, DoH should not be used in AUTOMATIC mode since no DoH servers
45 // have a successful probe state.
46 virtual bool FallbackFromSecureTransactionPreferred() const = 0;
47
Eric Orth394db1732019-08-27 20:09:3948 // When true, insecure DNS transactions should not be used when reasonable
49 // fallback alternatives, e.g. system resolution can be used instead.
50 virtual bool FallbackFromInsecureTransactionPreferred() const = 0;
51
52 // Updates DNS config. If effective config has changed, destroys the current
53 // DnsTransactionFactory and creates a new one according to the effective
54 // config, unless it is invalid or has |unhandled_options|.
55 //
56 // Returns whether or not the effective config changed.
57 virtual bool SetSystemConfig(base::Optional<DnsConfig> system_config) = 0;
58 virtual bool SetConfigOverrides(DnsConfigOverrides config_overrides) = 0;
59
60 // Retrieve the current DNS configuration that would be used if transactions
61 // were otherwise currently allowed. Returns null if configuration is
62 // invalid or a configuration has not yet been read from the system.
63 virtual const DnsConfig* GetEffectiveConfig() const = 0;
64 virtual const DnsHosts* GetHosts() const = 0;
65
dalykc2adf182019-09-02 14:31:2266 // Sets the URLRequestContext to use for issuing DoH probes.
67 virtual void SetRequestContextForProbes(
68 URLRequestContext* url_request_context) = 0;
69
Eric Orth394db1732019-08-27 20:09:3970 // Returns null if the current config is not valid.
[email protected]78eac2a2012-03-14 19:09:2771 virtual DnsTransactionFactory* GetTransactionFactory() = 0;
72
[email protected]0adcb2b2012-08-15 21:30:4673 virtual AddressSorter* GetAddressSorter() = 0;
74
Eric Orth394db1732019-08-27 20:09:3975 virtual void IncrementInsecureFallbackFailures() = 0;
76 virtual void ClearInsecureFallbackFailures() = 0;
77
78 virtual base::Optional<DnsConfig> GetSystemConfigForTesting() const = 0;
79 virtual DnsConfigOverrides GetConfigOverridesForTesting() const = 0;
80
dalykc2adf182019-09-02 14:31:2281 virtual void SetProbeSuccessForTest(unsigned index, bool success) = 0;
82
[email protected]78eac2a2012-03-14 19:09:2783 // Creates default client.
danakj22f90e72016-04-16 01:55:4084 static std::unique_ptr<DnsClient> CreateClient(NetLog* net_log);
mmenke91c17162016-06-02 16:03:2385
86 // Creates a client for testing. Allows using a mock ClientSocketFactory and
87 // a deterministic random number generator. |socket_factory| must outlive
88 // the returned DnsClient.
89 static std::unique_ptr<DnsClient> CreateClientForTesting(
90 NetLog* net_log,
91 ClientSocketFactory* socket_factory,
92 const RandIntCallback& rand_int_callback);
[email protected]78eac2a2012-03-14 19:09:2793};
94
95} // namespace net
96
97#endif // NET_DNS_DNS_CLIENT_H_