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