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 #include "net/dns/public/dns_config_overrides.h" 6 7 #include "net/dns/dns_config.h" 8 9 namespace net { 10 11 DnsConfigOverrides::DnsConfigOverrides() = default; 12 13 DnsConfigOverrides::DnsConfigOverrides(const DnsConfigOverrides& other) = 14 default; 15 16 DnsConfigOverrides::DnsConfigOverrides(DnsConfigOverrides&& other) = default; 17 18 DnsConfigOverrides::~DnsConfigOverrides() = default; 19 20 DnsConfigOverrides& DnsConfigOverrides::operator=( 21 const DnsConfigOverrides& other) = default; 22 23 DnsConfigOverrides& DnsConfigOverrides::operator=(DnsConfigOverrides&& other) = 24 default; 25 operator ==(const DnsConfigOverrides & other) const26bool DnsConfigOverrides::operator==(const DnsConfigOverrides& other) const { 27 return nameservers == other.nameservers && 28 dns_over_tls_active == other.dns_over_tls_active && 29 dns_over_tls_hostname == other.dns_over_tls_hostname && 30 search == other.search && 31 append_to_multi_label_name == other.append_to_multi_label_name && 32 ndots == other.ndots && fallback_period == other.fallback_period && 33 attempts == other.attempts && doh_attempts == other.doh_attempts && 34 rotate == other.rotate && use_local_ipv6 == other.use_local_ipv6 && 35 dns_over_https_config == other.dns_over_https_config && 36 secure_dns_mode == other.secure_dns_mode && 37 allow_dns_over_https_upgrade == other.allow_dns_over_https_upgrade && 38 clear_hosts == other.clear_hosts; 39 } 40 operator !=(const DnsConfigOverrides & other) const41bool DnsConfigOverrides::operator!=(const DnsConfigOverrides& other) const { 42 return !(*this == other); 43 } 44 45 // static 46 DnsConfigOverrides CreateOverridingEverythingWithDefaults()47DnsConfigOverrides::CreateOverridingEverythingWithDefaults() { 48 DnsConfig defaults; 49 50 DnsConfigOverrides overrides; 51 overrides.nameservers = defaults.nameservers; 52 overrides.dns_over_tls_active = defaults.dns_over_tls_active; 53 overrides.dns_over_tls_hostname = defaults.dns_over_tls_hostname; 54 overrides.search = defaults.search; 55 overrides.append_to_multi_label_name = defaults.append_to_multi_label_name; 56 overrides.ndots = defaults.ndots; 57 overrides.fallback_period = defaults.fallback_period; 58 overrides.attempts = defaults.attempts; 59 overrides.doh_attempts = defaults.doh_attempts; 60 overrides.rotate = defaults.rotate; 61 overrides.use_local_ipv6 = defaults.use_local_ipv6; 62 overrides.dns_over_https_config = defaults.doh_config; 63 overrides.secure_dns_mode = defaults.secure_dns_mode; 64 overrides.allow_dns_over_https_upgrade = 65 defaults.allow_dns_over_https_upgrade; 66 overrides.clear_hosts = true; 67 68 return overrides; 69 } 70 OverridesEverything() const71bool DnsConfigOverrides::OverridesEverything() const { 72 return nameservers && dns_over_tls_active && dns_over_tls_hostname && 73 search && append_to_multi_label_name && ndots && fallback_period && 74 attempts && doh_attempts && rotate && use_local_ipv6 && 75 dns_over_https_config && secure_dns_mode && 76 allow_dns_over_https_upgrade && clear_hosts; 77 } 78 ApplyOverrides(const DnsConfig & config) const79DnsConfig DnsConfigOverrides::ApplyOverrides(const DnsConfig& config) const { 80 DnsConfig overridden; 81 82 if (!OverridesEverything()) 83 overridden = config; 84 85 if (nameservers) 86 overridden.nameservers = nameservers.value(); 87 if (dns_over_tls_active) 88 overridden.dns_over_tls_active = dns_over_tls_active.value(); 89 if (dns_over_tls_hostname) 90 overridden.dns_over_tls_hostname = dns_over_tls_hostname.value(); 91 if (search) 92 overridden.search = search.value(); 93 if (append_to_multi_label_name) 94 overridden.append_to_multi_label_name = append_to_multi_label_name.value(); 95 if (ndots) 96 overridden.ndots = ndots.value(); 97 if (fallback_period) 98 overridden.fallback_period = fallback_period.value(); 99 if (attempts) 100 overridden.attempts = attempts.value(); 101 if (doh_attempts) 102 overridden.doh_attempts = doh_attempts.value(); 103 if (rotate) 104 overridden.rotate = rotate.value(); 105 if (use_local_ipv6) 106 overridden.use_local_ipv6 = use_local_ipv6.value(); 107 if (dns_over_https_config) 108 overridden.doh_config = dns_over_https_config.value(); 109 if (secure_dns_mode) 110 overridden.secure_dns_mode = secure_dns_mode.value(); 111 if (allow_dns_over_https_upgrade) { 112 overridden.allow_dns_over_https_upgrade = 113 allow_dns_over_https_upgrade.value(); 114 } 115 if (clear_hosts) 116 overridden.hosts.clear(); 117 118 return overridden; 119 } 120 121 } // namespace net 122