[email protected] | 78eac2a | 2012-03-14 19:09:27 | [diff] [blame] | 1 | // 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] | 78eac2a | 2012-03-14 19:09:27 | [diff] [blame] | 7 | |
danakj | 22f90e7 | 2016-04-16 01:55:40 | [diff] [blame] | 8 | #include <memory> |
| 9 | |
Eric Orth | 394db173 | 2019-08-27 20:09:39 | [diff] [blame] | 10 | #include "base/optional.h" |
[email protected] | 78eac2a | 2012-03-14 19:09:27 | [diff] [blame] | 11 | #include "net/base/net_export.h" |
mmenke | 91c1716 | 2016-06-02 16:03:23 | [diff] [blame] | 12 | #include "net/base/rand_callback.h" |
Eric Orth | 394db173 | 2019-08-27 20:09:39 | [diff] [blame] | 13 | #include "net/dns/dns_config.h" |
| 14 | #include "net/dns/dns_config_overrides.h" |
| 15 | #include "net/dns/dns_hosts.h" |
dalyk | c2adf18 | 2019-09-02 14:31:22 | [diff] [blame] | 16 | #include "net/url_request/url_request_context.h" |
[email protected] | 78eac2a | 2012-03-14 19:09:27 | [diff] [blame] | 17 | |
| 18 | namespace net { |
| 19 | |
[email protected] | 0adcb2b | 2012-08-15 21:30:46 | [diff] [blame] | 20 | class AddressSorter; |
mmenke | 91c1716 | 2016-06-02 16:03:23 | [diff] [blame] | 21 | class ClientSocketFactory; |
[email protected] | 78eac2a | 2012-03-14 19:09:27 | [diff] [blame] | 22 | class DnsTransactionFactory; |
| 23 | class NetLog; |
| 24 | |
Eric Orth | 394db173 | 2019-08-27 20:09:39 | [diff] [blame] | 25 | // 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] | 78eac2a | 2012-03-14 19:09:27 | [diff] [blame] | 28 | class NET_EXPORT DnsClient { |
| 29 | public: |
Eric Orth | 394db173 | 2019-08-27 20:09:39 | [diff] [blame] | 30 | static const int kMaxInsecureFallbackFailures = 16; |
| 31 | |
[email protected] | 78eac2a | 2012-03-14 19:09:27 | [diff] [blame] | 32 | virtual ~DnsClient() {} |
| 33 | |
Eric Orth | 394db173 | 2019-08-27 20:09:39 | [diff] [blame] | 34 | // 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] | 78eac2a | 2012-03-14 19:09:27 | [diff] [blame] | 37 | |
Eric Orth | 394db173 | 2019-08-27 20:09:39 | [diff] [blame] | 38 | // 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] | 78eac2a | 2012-03-14 19:09:27 | [diff] [blame] | 43 | |
dalyk | c2adf18 | 2019-09-02 14:31:22 | [diff] [blame] | 44 | // 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 Orth | 394db173 | 2019-08-27 20:09:39 | [diff] [blame] | 48 | // 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 | |
dalyk | c2adf18 | 2019-09-02 14:31:22 | [diff] [blame] | 66 | // Sets the URLRequestContext to use for issuing DoH probes. |
| 67 | virtual void SetRequestContextForProbes( |
| 68 | URLRequestContext* url_request_context) = 0; |
| 69 | |
Eric Orth | 394db173 | 2019-08-27 20:09:39 | [diff] [blame] | 70 | // Returns null if the current config is not valid. |
[email protected] | 78eac2a | 2012-03-14 19:09:27 | [diff] [blame] | 71 | virtual DnsTransactionFactory* GetTransactionFactory() = 0; |
| 72 | |
[email protected] | 0adcb2b | 2012-08-15 21:30:46 | [diff] [blame] | 73 | virtual AddressSorter* GetAddressSorter() = 0; |
| 74 | |
Eric Orth | 394db173 | 2019-08-27 20:09:39 | [diff] [blame] | 75 | 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 | |
dalyk | c2adf18 | 2019-09-02 14:31:22 | [diff] [blame] | 81 | virtual void SetProbeSuccessForTest(unsigned index, bool success) = 0; |
| 82 | |
[email protected] | 78eac2a | 2012-03-14 19:09:27 | [diff] [blame] | 83 | // Creates default client. |
danakj | 22f90e7 | 2016-04-16 01:55:40 | [diff] [blame] | 84 | static std::unique_ptr<DnsClient> CreateClient(NetLog* net_log); |
mmenke | 91c1716 | 2016-06-02 16:03:23 | [diff] [blame] | 85 | |
| 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] | 78eac2a | 2012-03-14 19:09:27 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | } // namespace net |
| 96 | |
| 97 | #endif // NET_DNS_DNS_CLIENT_H_ |