xref: /aosp_15_r20/external/cronet/net/dns/dns_config.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2018 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_DNS_CONFIG_H_
6 #define NET_DNS_DNS_CONFIG_H_
7 
8 #include <memory>
9 #include <string>
10 #include <vector>
11 
12 #include "base/time/time.h"
13 #include "base/values.h"
14 #include "net/base/ip_endpoint.h"
15 #include "net/base/net_export.h"
16 #include "net/dns/dns_hosts.h"
17 #include "net/dns/public/dns_over_https_config.h"
18 #include "net/dns/public/secure_dns_mode.h"
19 
20 namespace net {
21 
22 constexpr base::TimeDelta kDnsDefaultFallbackPeriod = base::Seconds(1);
23 
24 // DnsConfig stores configuration of the system resolver.
25 struct NET_EXPORT DnsConfig {
26   DnsConfig();
27   DnsConfig(const DnsConfig& other);
28   DnsConfig(DnsConfig&& other);
29   explicit DnsConfig(std::vector<IPEndPoint> nameservers);
30   ~DnsConfig();
31 
32   DnsConfig& operator=(const DnsConfig& other);
33   DnsConfig& operator=(DnsConfig&& other);
34 
35   bool Equals(const DnsConfig& d) const;
36   bool operator==(const DnsConfig& d) const;
37   bool operator!=(const DnsConfig& d) const;
38 
39   bool EqualsIgnoreHosts(const DnsConfig& d) const;
40 
41   void CopyIgnoreHosts(const DnsConfig& src);
42 
43   // Returns a Dict representation of |this|. For performance reasons, the
44   // Dict only contains the number of hosts rather than the full list.
45   base::Value::Dict ToDict() const;
46 
IsValidDnsConfig47   bool IsValid() const {
48     return !nameservers.empty() || !doh_config.servers().empty();
49   }
50 
51   // List of name server addresses.
52   std::vector<IPEndPoint> nameservers;
53 
54   // Status of system DNS-over-TLS (DoT).
55   bool dns_over_tls_active = false;
56   std::string dns_over_tls_hostname;
57 
58   // Suffix search list; used on first lookup when number of dots in given name
59   // is less than |ndots|.
60   std::vector<std::string> search;
61 
62   DnsHosts hosts;
63 
64   // True if there are options set in the system configuration that are not yet
65   // supported by DnsClient.
66   bool unhandled_options = false;
67 
68   // AppendToMultiLabelName: is suffix search performed for multi-label names?
69   // True, except on Windows where it can be configured.
70   bool append_to_multi_label_name = true;
71 
72   // Resolver options; see man resolv.conf.
73 
74   // Minimum number of dots before global resolution precedes |search|.
75   int ndots = 1;
76   // Time between retransmissions, see res_state.retrans.
77   // Used by Chrome as the initial transaction attempt fallback period (before
78   // exponential backoff and dynamic period determination based on previous
79   // attempts.)
80   base::TimeDelta fallback_period = kDnsDefaultFallbackPeriod;
81   // Maximum number of attempts, see res_state.retry.
82   int attempts = 2;
83   // Maximum number of times a DoH server is attempted per attempted per DNS
84   // transaction. This is separate from the global failure limit.
85   int doh_attempts = 1;
86   // Round robin entries in |nameservers| for subsequent requests.
87   bool rotate = false;
88 
89   // Indicates system configuration uses local IPv6 connectivity, e.g.,
90   // DirectAccess. This is exposed for HostResolver to skip IPv6 probes,
91   // as it may cause them to return incorrect results.
92   bool use_local_ipv6 = false;
93 
94   // DNS over HTTPS server configuration.
95   DnsOverHttpsConfig doh_config;
96 
97   // The default SecureDnsMode to use when resolving queries. It can be
98   // overridden for individual requests (such as requests to resolve a DoH
99   // server hostname) using |HostResolver::ResolveHostParameters::
100   // secure_dns_mode_override|.
101   SecureDnsMode secure_dns_mode = SecureDnsMode::kOff;
102 
103   // If set to |true|, we will attempt to upgrade the user's DNS configuration
104   // to use DoH server(s) operated by the same provider(s) when the user is
105   // in AUTOMATIC mode and has not pre-specified DoH servers.
106   bool allow_dns_over_https_upgrade = false;
107 };
108 
109 }  // namespace net
110 
111 #endif  // NET_DNS_DNS_CONFIG_H_
112