/src/pdns/pdns/dnsdistdist/svc-records.hh
Line | Count | Source |
1 | | /* |
2 | | * This file is part of PowerDNS or dnsdist. |
3 | | * Copyright -- PowerDNS.COM B.V. and its contributors |
4 | | * |
5 | | * This program is free software; you can redistribute it and/or modify |
6 | | * it under the terms of version 2 of the GNU General Public License as |
7 | | * published by the Free Software Foundation. |
8 | | * |
9 | | * In addition, for the avoidance of any doubt, permission is granted to |
10 | | * link this program with OpenSSL and to (re)distribute the binaries |
11 | | * produced as the result of such linking. |
12 | | * |
13 | | * This program is distributed in the hope that it will be useful, |
14 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | | * GNU General Public License for more details. |
17 | | * |
18 | | * You should have received a copy of the GNU General Public License |
19 | | * along with this program; if not, write to the Free Software |
20 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
21 | | */ |
22 | | #pragma once |
23 | | #include <string> |
24 | | #include <map> |
25 | | #include <set> |
26 | | #include "iputils.hh" |
27 | | |
28 | | class SvcParam |
29 | | { |
30 | | public: |
31 | | enum SvcParamKey : uint16_t // NOLINT(performance-enum-size) |
32 | | { |
33 | | // https://www.iana.org/assignments/dns-svcb/dns-svcb.xhtml#dns-svcparamkeys |
34 | | /* When adding new values, you *must* update SvcParam::SvcParam(const std::string &key, const std::string &value) |
35 | | * in svc-record.cc with the new numbers |
36 | | */ |
37 | | mandatory = 0, |
38 | | alpn = 1, |
39 | | no_default_alpn = 2, |
40 | | port = 3, |
41 | | ipv4hint = 4, |
42 | | ech = 5, |
43 | | ipv6hint = 6, |
44 | | dohpath = 7, |
45 | | ohttp = 8, |
46 | | tls_supported_groups = 9, /* https://datatracker.ietf.org/doc/draft-ietf-tls-key-share-prediction/ */ |
47 | | docpath = 10, // https://datatracker.ietf.org/doc/html/rfc9953 |
48 | | pvd = 11, // https://datatracker.ietf.org/doc/html/draft-ietf-intarea-proxy-config-13#section-2.1 |
49 | | }; |
50 | | |
51 | | //! empty Param, unusable |
52 | | SvcParam() = delete; |
53 | | |
54 | | //! To create a value-less SvcParam (like no-default-alpn) |
55 | | SvcParam(const SvcParamKey& key); |
56 | | |
57 | | //! To create a "generic" SvcParam (for keyNNNNN and ech) |
58 | | SvcParam(const SvcParamKey& key, const std::string& value); |
59 | | |
60 | | //! To create a multi-value SvcParam (like mandatory) |
61 | | SvcParam(const SvcParamKey& key, std::set<std::string>&& value); |
62 | | |
63 | | //! To create a multi-value SvcParam (like alpn and docpath) |
64 | | SvcParam(const SvcParamKey& key, std::vector<std::string>&& value); |
65 | | |
66 | | //! To create a multi-value SvcParam with key values (like mandatory) |
67 | | SvcParam(const SvcParamKey& key, std::set<SvcParamKey>&& value); |
68 | | |
69 | | //! To create an ipv{4,6}hints SvcParam |
70 | | SvcParam(const SvcParamKey& key, std::vector<ComboAddress>&& value); |
71 | | |
72 | | //! To create a tls-supported-groups SvcParam |
73 | | SvcParam(const SvcParamKey& key, std::vector<uint16_t>&& value); |
74 | | |
75 | | //! To create a port SvcParam |
76 | | SvcParam(const SvcParamKey& key, const uint16_t value); |
77 | | |
78 | | //! Returns the SvcParamKey based on the input |
79 | | static SvcParamKey keyFromString(const std::string& k); |
80 | | |
81 | | //! Returns the SvcParamKey based on the input, generic is true when the format was 'keyNNNN' |
82 | | static SvcParamKey keyFromString(const std::string& k, bool& generic); |
83 | | |
84 | | //! Returns the string value of the SvcParamKey |
85 | | static std::string keyToString(const SvcParamKey& k); |
86 | | |
87 | | bool operator<(const SvcParam& other) const; |
88 | | |
89 | | bool operator==(const SvcParam& other) const; |
90 | | |
91 | | bool operator!=(const SvcParam& other) const; |
92 | | |
93 | | bool operator==(const SvcParamKey& key) const |
94 | 0 | { |
95 | 0 | return key == d_key; |
96 | 0 | } |
97 | | |
98 | | SvcParamKey getKey() const |
99 | 403k | { |
100 | 403k | return d_key; |
101 | 403k | } |
102 | | |
103 | | uint16_t getPort() const; |
104 | | const std::vector<ComboAddress>& getIPHints() const; |
105 | | const std::vector<std::string>& getALPN() const; |
106 | | const std::set<SvcParamKey>& getMandatory() const; |
107 | | const std::string& getECH() const; |
108 | | const std::string& getValue() const; |
109 | | const std::vector<uint16_t>& getTLSSupportedGroups() const; |
110 | | |
111 | 865 | bool getAutoHint() const { return d_autohint; }; |
112 | 2.92k | void setAutoHint(const bool value) { d_autohint = value; }; |
113 | | |
114 | | private: |
115 | | SvcParamKey d_key; |
116 | | std::string d_value; // For keyNNNNN vals |
117 | | |
118 | | std::vector<std::string> d_alpn; // For ALPN and docpath |
119 | | std::set<SvcParamKey> d_mandatory; // For mandatory |
120 | | std::vector<ComboAddress> d_ipHints; // For ipv{6,4}hints |
121 | | std::string d_ech; // For Encrypted Client Hello |
122 | | std::vector<uint16_t> d_tls_supported_groups; // For tls-supported-groups |
123 | | uint16_t d_port{0}; // For port |
124 | | |
125 | | // Set to true if we encountered an "auto" field in hints |
126 | | // Can only be true when we read SVCParams from text |
127 | | bool d_autohint{false}; |
128 | | |
129 | | static const std::map<std::string, SvcParamKey> SvcParams; |
130 | | }; |