/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 |
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 | | }; |
48 | | |
49 | | //! empty Param, unusable |
50 | | SvcParam() = delete; |
51 | | |
52 | | //! To create a value-less SvcParam (like no-default-alpn) |
53 | | SvcParam(const SvcParamKey& key); |
54 | | |
55 | | //! To create a "generic" SvcParam (for keyNNNNN and ech) |
56 | | SvcParam(const SvcParamKey& key, const std::string& value); |
57 | | |
58 | | //! To create a multi-value SvcParam (like mandatory) |
59 | | SvcParam(const SvcParamKey& key, std::set<std::string>&& value); |
60 | | |
61 | | //! To create a multi-value SvcParam (like alpn) |
62 | | SvcParam(const SvcParamKey& key, std::vector<std::string>&& value); |
63 | | |
64 | | //! To create a multi-value SvcParam with key values (like mandatory) |
65 | | SvcParam(const SvcParamKey& key, std::set<SvcParamKey>&& value); |
66 | | |
67 | | //! To create an ipv{4,6}hints SvcParam |
68 | | SvcParam(const SvcParamKey& key, std::vector<ComboAddress>&& value); |
69 | | |
70 | | //! To create a tls-supported-groups SvcParam |
71 | | SvcParam(const SvcParamKey& key, std::vector<uint16_t>&& value); |
72 | | |
73 | | //! To create a port SvcParam |
74 | | SvcParam(const SvcParamKey& key, const uint16_t value); |
75 | | |
76 | | //! Returns the SvcParamKey based on the input |
77 | | static SvcParamKey keyFromString(const std::string& k); |
78 | | |
79 | | //! Returns the SvcParamKey based on the input, generic is true when the format was 'keyNNNN' |
80 | | static SvcParamKey keyFromString(const std::string& k, bool& generic); |
81 | | |
82 | | //! Returns the string value of the SvcParamKey |
83 | | static std::string keyToString(const SvcParamKey& k); |
84 | | |
85 | | bool operator<(const SvcParam& other) const; |
86 | | |
87 | | bool operator==(const SvcParam& other) const; |
88 | | |
89 | | bool operator!=(const SvcParam& other) const; |
90 | | |
91 | | bool operator==(const SvcParamKey& key) const |
92 | 0 | { |
93 | 0 | return key == d_key; |
94 | 0 | } |
95 | | |
96 | | SvcParamKey getKey() const |
97 | 4.44k | { |
98 | 4.44k | return d_key; |
99 | 4.44k | } |
100 | | |
101 | | uint16_t getPort() const; |
102 | | const std::vector<ComboAddress>& getIPHints() const; |
103 | | const std::vector<std::string>& getALPN() const; |
104 | | const std::set<SvcParamKey>& getMandatory() const; |
105 | | const std::string& getECH() const; |
106 | | const std::string& getValue() const; |
107 | | const std::vector<uint16_t>& getTLSSupportedGroups() const; |
108 | | |
109 | 0 | bool getAutoHint() const { return d_autohint; }; |
110 | 735 | void setAutoHint(const bool value) { d_autohint = value; }; |
111 | | |
112 | | private: |
113 | | SvcParamKey d_key; |
114 | | std::string d_value; // For keyNNNNN vals |
115 | | |
116 | | std::vector<std::string> d_alpn; // For ALPN |
117 | | std::set<SvcParamKey> d_mandatory; // For mandatory |
118 | | std::vector<ComboAddress> d_ipHints; // For ipv{6,4}hints |
119 | | std::string d_ech; // For Encrypted Client Hello |
120 | | std::vector<uint16_t> d_tls_supported_groups; // For tls-supported-groups |
121 | | uint16_t d_port{0}; // For port |
122 | | |
123 | | // Set to true if we encountered an "auto" field in hints |
124 | | // Can only be true when we read SVCParams from text |
125 | | bool d_autohint{false}; |
126 | | |
127 | | static const std::map<std::string, SvcParamKey> SvcParams; |
128 | | }; |