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_QUERY_TYPE_H_ 6 #define NET_DNS_PUBLIC_DNS_QUERY_TYPE_H_ 7 8 #include <string_view> 9 10 #include "base/containers/enum_set.h" 11 #include "base/containers/fixed_flat_map.h" 12 #include "net/base/net_export.h" 13 14 namespace net { 15 16 // DNS query type for HostResolver requests. 17 // See: 18 // https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-4 19 // CAUTION: When adding new entries, remember to update `MAX` and update 20 // kDnsQueryTypes below. 21 enum class DnsQueryType : uint8_t { 22 UNSPECIFIED = 0, 23 A = 1, 24 AAAA = 2, 25 TXT = 3, 26 PTR = 4, 27 SRV = 5, 28 // 6 was INTEGRITY, used for an experiment (crbug.com/1052476). 29 HTTPS = 7, 30 // 8 was HTTPS_EXPERIMENTAL, used for an experiment (crbug.com/1052476). 31 // When adding new entries, remember to update `MAX` and update kDnsQueryTypes 32 // below. 33 MAX = HTTPS 34 }; 35 36 using DnsQueryTypeSet = 37 base::EnumSet<DnsQueryType, DnsQueryType::UNSPECIFIED, DnsQueryType::MAX>; 38 39 inline constexpr auto kDnsQueryTypes = 40 base::MakeFixedFlatMap<DnsQueryType, std::string_view>( 41 {{DnsQueryType::UNSPECIFIED, "UNSPECIFIED"}, 42 {DnsQueryType::A, "A"}, 43 {DnsQueryType::AAAA, "AAAA"}, 44 {DnsQueryType::TXT, "TXT"}, 45 {DnsQueryType::PTR, "PTR"}, 46 {DnsQueryType::SRV, "SRV"}, 47 {DnsQueryType::HTTPS, "HTTPS"}}); 48 49 // `true` iff `dns_query_type` is an address-resulting type, convertible to and 50 // from `net::AddressFamily`. 51 bool NET_EXPORT IsAddressType(DnsQueryType dns_query_type); 52 53 // `true` iff `dns_query_types` contains an address type. `dns_query_types` must 54 // be non-empty and must not contain `DnsQueryType::UNSPECIFIED`. 55 bool NET_EXPORT HasAddressType(DnsQueryTypeSet dns_query_types); 56 57 } // namespace net 58 59 #endif // NET_DNS_PUBLIC_DNS_QUERY_TYPE_H_ 60