2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
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.
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.
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.
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.
30 enum SvcParamKey: uint16_t {
31 // TODO link to IANA registry
32 /* When adding new values, you *must* update SvcParam::SvcParam(const std::string &key, const std::string &value)
33 * in svc-record.cc with the new numbers
44 //! empty Param, unusable
47 //! To create a value-less SvcParam (like no-default-alpn)
48 SvcParam(const SvcParamKey &key);
50 //! To create a "generic" SvcParam (for keyNNNNN and ech)
51 SvcParam(const SvcParamKey &key, const std::string &value);
53 //! To create a multi-value SvcParam (like mandatory)
54 SvcParam(const SvcParamKey &key, std::set<std::string> &&value);
56 //! To create a multi-value SvcParam (like alpn)
57 SvcParam(const SvcParamKey &key, std::vector<std::string> &&value);
59 //! To create a multi-value SvcParam with key values (like mandatory)
60 SvcParam(const SvcParamKey &key, std::set<SvcParamKey> &&value);
62 //! To create and ipv{4,6}hists SvcParam
63 SvcParam(const SvcParamKey &key, std::vector<ComboAddress> &&value);
65 //! To create a port SvcParam
66 SvcParam(const SvcParamKey &key, const uint16_t value);
68 //! Returns the SvcParamKey based on the input
69 static SvcParamKey keyFromString(const std::string &k);
71 //! Returns the SvcParamKey based on the input, generic is true when the format was 'keyNNNN'
72 static SvcParamKey keyFromString(const std::string &k, bool &generic);
74 //! Returns the string value of the SvcParamKey
75 static std::string keyToString(const SvcParamKey &k);
77 bool operator< (const SvcParam &other) const;
79 SvcParamKey getKey() const {
83 uint16_t getPort() const;
84 const std::vector<ComboAddress>& getIPHints() const;
85 const std::vector<std::string>& getALPN() const;
86 const std::set<SvcParamKey>& getMandatory() const;
87 const std::string& getECH() const;
88 const std::string& getValue() const;
90 bool getAutoHint() const { return d_autohint; };
91 void setAutoHint(const bool value) { d_autohint = value; };
95 std::string d_value; // For keyNNNNN vals
97 std::vector<std::string> d_alpn; // For ALPN
98 std::set<SvcParamKey> d_mandatory; // For mandatory
99 std::vector<ComboAddress> d_ipHints; // For ipv{6,4}hints
100 std::string d_ech; // For Encrypted Client Hello
101 uint16_t d_port{0}; // For port
103 // Set to true if we encountered an "auto" field in hints
104 // Can only be true when we read SVCParams from text
105 bool d_autohint{false};
107 static const std::map<std::string, SvcParamKey> SvcParams;