1 // Copyright 2012 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_WIN_DNS_SYSTEM_SETTINGS_H_ 6 #define NET_DNS_PUBLIC_WIN_DNS_SYSTEM_SETTINGS_H_ 7 8 #include <winsock2.h> 9 #include <iphlpapi.h> 10 #include <iptypes.h> 11 12 #include <memory> 13 #include <string> 14 #include <vector> 15 16 #include "base/memory/free_deleter.h" 17 #include "base/strings/string_piece_forward.h" 18 #include "net/base/ip_endpoint.h" 19 #include "net/base/net_export.h" 20 #include "third_party/abseil-cpp/absl/types/optional.h" 21 22 namespace net { 23 24 // This is an aggregate representation of Windows system DNS configuration and 25 // can be easily built manually in tests. 26 struct NET_EXPORT WinDnsSystemSettings { 27 struct NET_EXPORT DevolutionSetting { 28 DevolutionSetting(); 29 DevolutionSetting(absl::optional<DWORD> enabled, 30 absl::optional<DWORD> level); 31 DevolutionSetting(const DevolutionSetting&); 32 DevolutionSetting& operator=(const DevolutionSetting&); 33 ~DevolutionSetting(); 34 35 // UseDomainNameDevolution 36 absl::optional<DWORD> enabled; 37 // DomainNameDevolutionLevel 38 absl::optional<DWORD> level; 39 }; 40 41 // Returns true iff |address| is DNS address from IPv6 stateless discovery, 42 // i.e., matches fec0:0:0:ffff::{1,2,3}. 43 // http://tools.ietf.org/html/draft-ietf-ipngwg-dns-discovery 44 static bool IsStatelessDiscoveryAddress(const IPAddress& address); 45 46 WinDnsSystemSettings(); 47 ~WinDnsSystemSettings(); 48 49 WinDnsSystemSettings(WinDnsSystemSettings&&); 50 WinDnsSystemSettings& operator=(WinDnsSystemSettings&&); 51 52 // List of nameserver IP addresses. 53 std::unique_ptr<IP_ADAPTER_ADDRESSES, base::FreeDeleter> addresses; 54 55 // SOFTWARE\Policies\Microsoft\Windows NT\DNSClient\SearchList 56 absl::optional<std::wstring> policy_search_list; 57 // SYSTEM\CurrentControlSet\Tcpip\Parameters\SearchList 58 absl::optional<std::wstring> tcpip_search_list; 59 // SYSTEM\CurrentControlSet\Tcpip\Parameters\Domain 60 absl::optional<std::wstring> tcpip_domain; 61 // SOFTWARE\Policies\Microsoft\System\DNSClient\PrimaryDnsSuffix 62 absl::optional<std::wstring> primary_dns_suffix; 63 64 // SOFTWARE\Policies\Microsoft\Windows NT\DNSClient 65 DevolutionSetting policy_devolution; 66 // SYSTEM\CurrentControlSet\Dnscache\Parameters 67 DevolutionSetting dnscache_devolution; 68 // SYSTEM\CurrentControlSet\Tcpip\Parameters 69 DevolutionSetting tcpip_devolution; 70 71 // SOFTWARE\Policies\Microsoft\Windows NT\DNSClient\AppendToMultiLabelName 72 absl::optional<DWORD> append_to_multi_label_name; 73 74 // True when the Name Resolution Policy Table (NRPT) has at least one rule: 75 // SOFTWARE\Policies\Microsoft\Windows NT\DNSClient\DnsPolicyConfig\Rule* 76 // (or) 77 // SYSTEM\CurrentControlSet\Services\Dnscache\Parameters\DnsPolicyConfig\Rule* 78 bool have_name_resolution_policy = false; 79 80 // True when a proxy is configured via at least one rule: 81 // SYSTEM\CurrentControlSet\Services\Dnscache\Parameters\DnsConnections 82 // (or) 83 // SYSTEM\CurrentControlSet\Services\Dnscache\Parameters\DnsActiveIfs 84 // (or) 85 // SYSTEM\CurrentControlSet\Services\Dnscache\Parameters\DnsConnectionsProxies 86 bool have_proxy = false; 87 88 // Gets Windows configured DNS servers from all network adapters, with the 89 // exception of stateless discovery addresses (see IsStatelessDiscoveryAddress 90 // above). 91 absl::optional<std::vector<IPEndPoint>> GetAllNameservers(); 92 }; 93 94 // Reads WinDnsSystemSettings from IpHelper and the registry, or nullopt on 95 // errors reading them. 96 NET_EXPORT absl::optional<WinDnsSystemSettings> ReadWinSystemDnsSettings(); 97 98 } // namespace net 99 100 #endif // NET_DNS_PUBLIC_WIN_DNS_SYSTEM_SETTINGS_H_ 101