xref: /aosp_15_r20/external/cronet/net/dns/public/dns_config_overrides.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_PUBLIC_DNS_CONFIG_OVERRIDES_H_
6 #define NET_DNS_PUBLIC_DNS_CONFIG_OVERRIDES_H_
7 
8 #include <optional>
9 #include <string>
10 #include <vector>
11 
12 #include "base/time/time.h"
13 #include "net/base/ip_endpoint.h"
14 #include "net/base/net_export.h"
15 #include "net/dns/public/dns_over_https_config.h"
16 #include "net/dns/public/secure_dns_mode.h"
17 
18 namespace net {
19 
20 struct DnsConfig;
21 
22 // Overriding values to be applied over a DnsConfig struct.
23 struct NET_EXPORT DnsConfigOverrides {
24   DnsConfigOverrides();
25   DnsConfigOverrides(const DnsConfigOverrides& other);
26   DnsConfigOverrides(DnsConfigOverrides&& other);
27   ~DnsConfigOverrides();
28 
29   DnsConfigOverrides& operator=(const DnsConfigOverrides& other);
30   DnsConfigOverrides& operator=(DnsConfigOverrides&& other);
31 
32   bool operator==(const DnsConfigOverrides& other) const;
33   bool operator!=(const DnsConfigOverrides& other) const;
34 
35   // Creation method that initializes all values with the defaults from
36   // DnsConfig. Guarantees the result of OverridesEverything() will be |true|.
37   static DnsConfigOverrides CreateOverridingEverythingWithDefaults();
38 
39   // Creates a new DnsConfig where any field with an overriding value in |this|
40   // is replaced with that overriding value. Any field without an overriding
41   // value (|std::nullopt|) will be copied as-is from |config|.
42   DnsConfig ApplyOverrides(const DnsConfig& config) const;
43 
44   // Returns |true| if the overriding configuration is comprehensive and would
45   // override everything in a base DnsConfig. This is the case if all Optional
46   // fields have a value.
47   bool OverridesEverything() const;
48 
49   // Overriding values. See same-named fields in DnsConfig for explanations.
50   std::optional<std::vector<IPEndPoint>> nameservers;
51   std::optional<bool> dns_over_tls_active;
52   std::optional<std::string> dns_over_tls_hostname;
53   std::optional<std::vector<std::string>> search;
54   std::optional<bool> append_to_multi_label_name;
55   std::optional<int> ndots;
56   std::optional<base::TimeDelta> fallback_period;
57   std::optional<int> attempts;
58   std::optional<int> doh_attempts;
59   std::optional<bool> rotate;
60   std::optional<bool> use_local_ipv6;
61   std::optional<DnsOverHttpsConfig> dns_over_https_config;
62   std::optional<SecureDnsMode> secure_dns_mode;
63   std::optional<bool> allow_dns_over_https_upgrade;
64 
65   // |hosts| is not supported for overriding except to clear it.
66   bool clear_hosts = false;
67 
68   // Note no overriding value for |unhandled_options|. It is meta-configuration,
69   // and there should be no reason to override it.
70 };
71 
72 }  // namespace net
73 
74 #endif  // NET_DNS_PUBLIC_DNS_CONFIG_OVERRIDES_H_
75