1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/dns/dns_config.h"
#include <utility>
#include "base/values.h"
namespace net {
// Default values are taken from glibc resolv.h except timeout which is set to
// |kDnsDefaultTimeoutMs|.
DnsConfig::DnsConfig() : DnsConfig(std::vector<IPEndPoint>()) {}
DnsConfig::DnsConfig(const DnsConfig& other) = default;
DnsConfig::DnsConfig(DnsConfig&& other) = default;
DnsConfig::DnsConfig(std::vector<IPEndPoint> nameservers)
: nameservers(std::move(nameservers)),
dns_over_tls_active(false),
dns_over_tls_hostname(std::string()),
unhandled_options(false),
append_to_multi_label_name(true),
randomize_ports(false),
ndots(1),
timeout(kDnsDefaultTimeout),
attempts(2),
doh_attempts(1),
rotate(false),
use_local_ipv6(false),
secure_dns_mode(SecureDnsMode::OFF),
allow_dns_over_https_upgrade(false) {}
DnsConfig::~DnsConfig() = default;
DnsConfig& DnsConfig::operator=(const DnsConfig& other) = default;
DnsConfig& DnsConfig::operator=(DnsConfig&& other) = default;
bool DnsConfig::Equals(const DnsConfig& d) const {
return EqualsIgnoreHosts(d) && (hosts == d.hosts);
}
bool DnsConfig::operator==(const DnsConfig& d) const {
return Equals(d);
}
bool DnsConfig::operator!=(const DnsConfig& d) const {
return !Equals(d);
}
bool DnsConfig::EqualsIgnoreHosts(const DnsConfig& d) const {
return (nameservers == d.nameservers) &&
(dns_over_tls_active == d.dns_over_tls_active) &&
(dns_over_tls_hostname == d.dns_over_tls_hostname) &&
(search == d.search) && (unhandled_options == d.unhandled_options) &&
(append_to_multi_label_name == d.append_to_multi_label_name) &&
(ndots == d.ndots) && (timeout == d.timeout) &&
(attempts == d.attempts) && (doh_attempts == d.doh_attempts) &&
(rotate == d.rotate) && (use_local_ipv6 == d.use_local_ipv6) &&
(dns_over_https_servers == d.dns_over_https_servers) &&
(secure_dns_mode == d.secure_dns_mode) &&
(allow_dns_over_https_upgrade == d.allow_dns_over_https_upgrade) &&
(disabled_upgrade_providers == d.disabled_upgrade_providers);
}
void DnsConfig::CopyIgnoreHosts(const DnsConfig& d) {
nameservers = d.nameservers;
dns_over_tls_active = d.dns_over_tls_active;
dns_over_tls_hostname = d.dns_over_tls_hostname;
search = d.search;
unhandled_options = d.unhandled_options;
append_to_multi_label_name = d.append_to_multi_label_name;
ndots = d.ndots;
timeout = d.timeout;
attempts = d.attempts;
doh_attempts = d.doh_attempts;
rotate = d.rotate;
use_local_ipv6 = d.use_local_ipv6;
dns_over_https_servers = d.dns_over_https_servers;
secure_dns_mode = d.secure_dns_mode;
allow_dns_over_https_upgrade = d.allow_dns_over_https_upgrade;
disabled_upgrade_providers = d.disabled_upgrade_providers;
}
std::unique_ptr<base::Value> DnsConfig::ToValue() const {
auto dict = std::make_unique<base::DictionaryValue>();
auto list = std::make_unique<base::ListValue>();
for (size_t i = 0; i < nameservers.size(); ++i)
list->AppendString(nameservers[i].ToString());
dict->Set("nameservers", std::move(list));
dict->SetBoolean("dns_over_tls_active", dns_over_tls_active);
dict->SetString("dns_over_tls_hostname", dns_over_tls_hostname);
list = std::make_unique<base::ListValue>();
for (size_t i = 0; i < search.size(); ++i)
list->AppendString(search[i]);
dict->Set("search", std::move(list));
dict->SetBoolean("unhandled_options", unhandled_options);
dict->SetBoolean("append_to_multi_label_name", append_to_multi_label_name);
dict->SetInteger("ndots", ndots);
dict->SetDouble("timeout", timeout.InSecondsF());
dict->SetInteger("attempts", attempts);
dict->SetInteger("doh_attempts", doh_attempts);
dict->SetBoolean("rotate", rotate);
dict->SetBoolean("use_local_ipv6", use_local_ipv6);
dict->SetInteger("num_hosts", hosts.size());
list = std::make_unique<base::ListValue>();
for (auto& server : dns_over_https_servers) {
base::Value val(base::Value::Type::DICTIONARY);
base::DictionaryValue* dict;
val.GetAsDictionary(&dict);
dict->SetString("server_template", server.server_template);
dict->SetBoolean("use_post", server.use_post);
list->Append(std::move(val));
}
dict->Set("doh_servers", std::move(list));
dict->SetInteger("secure_dns_mode", static_cast<int>(secure_dns_mode));
dict->SetBoolean("allow_dns_over_https_upgrade",
allow_dns_over_https_upgrade);
list = std::make_unique<base::ListValue>();
for (const auto& provider : disabled_upgrade_providers)
list->AppendString(provider);
dict->Set("disabled_upgrade_providers", std::move(list));
return std::move(dict);
}
} // namespace net
|