Kea 2.5.8
option4_dnr.h
Go to the documentation of this file.
1// Copyright (C) 2023-2024 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef OPTION4_DNR_H
8#define OPTION4_DNR_H
9
10#include <asiolink/io_address.h>
11#include <boost/assign.hpp>
12#include <boost/bimap.hpp>
13#include <dhcp/dhcp4.h>
14#include <dhcp/dhcp6.h>
15#include <dhcp/option.h>
17#include <dns/name.h>
18#include <util/encode/utf8.h>
19
20#include <map>
21#include <set>
22#include <string>
23#include <unordered_set>
24
25namespace isc {
26namespace dhcp {
27
30public:
31 InvalidOptionDnrDomainName(const char* file, size_t line, const char* what)
32 : isc::Exception(file, line, what) {
33 }
34};
35
38public:
39 InvalidOptionDnrSvcParams(const char* file, size_t line, const char* what)
40 : isc::Exception(file, line, what) {
41 }
42};
43
56public:
58 typedef std::vector<isc::asiolink::IOAddress> AddressContainer;
59
61 typedef boost::bimap<std::string, uint16_t> SvcParamsMap;
62
64 static const uint8_t SERVICE_PRIORITY_SIZE = 2;
65
71 static const std::unordered_set<std::string> FORBIDDEN_SVC_PARAMS;
72
77
91 static const std::set<uint8_t> SUPPORTED_SVC_PARAMS;
92
97 static const std::unordered_set<std::string> ALPN_IDS;
98
102 explicit DnrInstance(Option::Universe universe);
103
105 virtual ~DnrInstance() = default;
106
110 uint16_t getDnrInstanceDataLength() const {
112 }
113
117 uint16_t getServicePriority() const {
118 return (service_priority_);
119 }
120
124 uint16_t getAdnLength() const {
125 return (adn_length_);
126 }
127
133 std::string getAdnAsText() const;
134
138 std::string getDnrInstanceAsText() const;
139
143 uint16_t getAddrLength() const {
144 return (addr_length_);
145 }
146
150 uint16_t getSvcParamsLength() const {
151 return (svc_params_length_);
152 }
153
163 return (ip_addresses_);
164 }
165
169 const OptionBuffer& getSvcParams() const {
170 return (svc_params_buf_);
171 }
172
176 uint8_t getMinimalLength() const {
177 return (minimal_length_);
178 }
179
181 uint8_t getAddrLengthSize() const {
182 return (addr_length_size_);
183 }
184
187 return (dnr_instance_data_length_size_);
188 }
189
191 uint8_t getAdnLengthSize() const {
192 return (adn_length_size_);
193 }
194
198 std::string getLogPrefix() const {
199 return (log_prefix_);
200 }
201
203 bool isAdnOnlyMode() const {
204 return (adn_only_mode_);
205 }
206
210 void setAdnOnlyMode(bool adn_only_mode) {
211 adn_only_mode_ = adn_only_mode;
212 }
213
221 }
222
231 void packAdn(isc::util::OutputBuffer& buf) const;
232
239 virtual void packAddresses(isc::util::OutputBuffer& buf) const;
240
247 void packSvcParams(isc::util::OutputBuffer& buf) const;
248
259
264
276
288
297
301 void addIpAddress(const asiolink::IOAddress& ip_address);
302
327 void parseDnrInstanceConfigData(const std::string& config_txt);
328
329protected:
332
338 boost::shared_ptr<isc::dns::Name> adn_;
339
344
347
349 uint16_t adn_length_;
350
352 uint16_t addr_length_;
353
361
364
370
376
386 std::map<uint16_t, OpaqueDataTuple> svc_params_map_;
387
390 uint16_t dnrInstanceLen() const;
391
395
396private:
400 uint8_t dnr_instance_data_length_size_;
401
403 uint8_t adn_length_size_;
404
406 uint8_t addr_length_size_;
407
415 uint8_t minimal_length_;
416
418 std::string log_prefix_;
419
423 void initMembers();
424
433 std::string svcParamValAsText(const std::pair<uint16_t, OpaqueDataTuple>& svc_param) const;
434
440 void parseIpAddresses(const std::string& txt_addresses);
441
448 void parseSvcParams(const std::string& txt_svc_params);
449
456 void parseAlpnSvcParam(const std::string& svc_param_val);
457
464 void parsePortSvcParam(const std::string& svc_param_val);
465
472 void parseDohpathSvcParam(const std::string& svc_param_val);
473};
474
490class Option4Dnr : public Option {
491public:
493 typedef std::vector<DnrInstance> DnrInstanceContainer;
494
513 bool convenient_notation = false);
514
517 void addDnrInstance(DnrInstance& dnr_instance);
518
522 return (dnr_instances_);
523 }
524
528 OptionPtr clone() const override;
529
543 void pack(util::OutputBuffer& buf, bool check = true) const override;
544
554 void unpack(OptionBufferConstIter begin, OptionBufferConstIter end) override;
555
561 std::string toText(int indent = 0) const override;
562
567 uint16_t len() const override;
568
569protected:
572
573private:
576 bool convenient_notation_;
577
589 void parseConfigData(const std::string& config_txt);
590};
591
593typedef boost::shared_ptr<Option4Dnr> Option4DnrPtr;
594
595} // namespace dhcp
596} // namespace isc
597
598#endif // OPTION4_DNR_H
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Represents DNR Instance which is used both in DHCPv4 and DHCPv6 Encrypted DNS Option.
Definition: option4_dnr.h:55
Option::Universe universe_
Either V4 or V6 Option universe.
Definition: option4_dnr.h:331
std::vector< isc::asiolink::IOAddress > AddressContainer
A Type defined for container holding IP addresses.
Definition: option4_dnr.h:58
static const std::set< uint8_t > SUPPORTED_SVC_PARAMS
Ordered set of supported SvcParamKeys.
Definition: option4_dnr.h:91
std::string getDnrInstanceAsText() const
Returns string representation of the DNR instance.
Definition: option4_dnr.cc:345
void unpackSvcParams(OptionBufferConstIter &begin, OptionBufferConstIter end)
Unpacks Service Parameters from wire data buffer and stores it in svc_params_buf_.
Definition: option4_dnr.cc:448
void setAdnOnlyMode(bool adn_only_mode)
Setter of the adn_only_mode_ field.
Definition: option4_dnr.h:210
uint16_t getAddrLength() const
Getter of the addr_length_.
Definition: option4_dnr.h:143
std::map< uint16_t, OpaqueDataTuple > svc_params_map_
Service Parameters stored in a map.
Definition: option4_dnr.h:386
uint16_t dnr_instance_data_length_
Length of all following data inside this DNR instance in octets.
Definition: option4_dnr.h:343
uint16_t getDnrInstanceDataLength() const
Getter of the dnr_instance_data_length_.
Definition: option4_dnr.h:110
uint8_t getMinimalLength() const
Returns minimal length of the DNR instance data (without headers) in octets.
Definition: option4_dnr.h:176
OptionBuffer svc_params_buf_
Service Parameters (SvcParams) (variable length) as on-wire data buffer.
Definition: option4_dnr.h:375
AddressContainer ip_addresses_
Vector container holding one or more IP addresses.
Definition: option4_dnr.h:360
uint8_t getAdnLengthSize() const
Returns size in octets of ADN Length field.
Definition: option4_dnr.h:191
void unpackDnrInstanceDataLength(OptionBufferConstIter &begin, OptionBufferConstIter end)
Unpacks DNR Instance Data Length from wire data buffer and stores it in dnr_instance_data_length_.
Definition: option4_dnr.cc:392
const OptionBuffer & getSvcParams() const
Returns a reference to the buffer holding SvcParam data.
Definition: option4_dnr.h:169
void packAdn(isc::util::OutputBuffer &buf) const
Writes the ADN FQDN in the wire format into a buffer.
Definition: option4_dnr.cc:221
void setDnrInstanceDataLength()
Setter of the dnr_instance_data_length_ field.
Definition: option4_dnr.h:219
uint16_t addr_length_
Length of included IP addresses in octets.
Definition: option4_dnr.h:352
virtual void unpackAddresses(OptionBufferConstIter &begin, OptionBufferConstIter end)
Unpacks IP address(es) from wire data and stores it/them in ip_addresses_.
Definition: option4_dnr.cc:410
uint8_t getAddrLengthSize() const
Returns size in octets of Addr Length field.
Definition: option4_dnr.h:181
uint16_t svc_params_length_
Length of Service Parameters field in octets.
Definition: option4_dnr.h:363
void parseDnrInstanceConfigData(const std::string &config_txt)
Parses a convenient notation of the option data, which may be used in config.
Definition: option4_dnr.cc:551
void unpackServicePriority(OptionBufferConstIter &begin)
Unpacks Service Priority from wire data buffer and stores it in service_priority_.
Definition: option4_dnr.cc:404
uint16_t service_priority_
The priority of this instance compared to other DNR instances.
Definition: option4_dnr.h:346
void packSvcParams(isc::util::OutputBuffer &buf) const
Writes the Service Parameters in the wire format into a buffer.
Definition: option4_dnr.cc:248
boost::bimap< std::string, uint16_t > SvcParamsMap
A Type defined for boost Bimap holding SvcParamKeys.
Definition: option4_dnr.h:61
bool isAdnOnlyMode() const
Returns whether ADN only mode is enabled or disabled.
Definition: option4_dnr.h:203
uint16_t getSvcParamsLength() const
Getter of the svc_params_length_.
Definition: option4_dnr.h:150
virtual void packAddresses(isc::util::OutputBuffer &buf) const
Writes the IP address(es) in the wire format into a buffer.
Definition: option4_dnr.cc:239
bool alpn_http_
Indicates whether the "alpn" SvcParam contains support for HTTP.
Definition: option4_dnr.h:394
std::string getAdnAsText() const
Returns the Authentication domain name in the text format.
Definition: option4_dnr.cc:255
std::string getLogPrefix() const
Returns Log prefix depending on V4/V6 Option universe.
Definition: option4_dnr.h:198
uint16_t getServicePriority() const
Getter of the service_priority_.
Definition: option4_dnr.h:117
static const SvcParamsMap SVC_PARAMS
Service parameters, used in DNR options in DHCPv4 and DHCPv6, but also in RA and DNS.
Definition: option4_dnr.h:76
static const std::unordered_set< std::string > ALPN_IDS
Possible ALPN protocol IDs.
Definition: option4_dnr.h:97
static const std::unordered_set< std::string > FORBIDDEN_SVC_PARAMS
Set of forbidden SvcParams.
Definition: option4_dnr.h:71
bool adn_only_mode_
Flag stating whether ADN only mode is used or not.
Definition: option4_dnr.h:369
uint16_t adn_length_
Length of the authentication-domain-name data in octets.
Definition: option4_dnr.h:349
uint16_t dnrInstanceLen() const
Calculates and returns length of DNR Instance data in octets.
Definition: option4_dnr.cc:377
virtual ~DnrInstance()=default
Default destructor.
void addIpAddress(const asiolink::IOAddress &ip_address)
Adds IP address to ip_addresses_ container.
Definition: option4_dnr.cc:387
uint16_t getAdnLength() const
Getter of the adn_length_.
Definition: option4_dnr.h:124
void unpackAdn(OptionBufferConstIter &begin, OptionBufferConstIter end)
Unpacks the ADN from given wire data buffer and stores it in adn_ field.
Definition: option4_dnr.cc:260
static const uint8_t SERVICE_PRIORITY_SIZE
Size in octets of Service Priority field.
Definition: option4_dnr.h:64
uint8_t getDnrInstanceDataLengthSize() const
Returns size in octets of DNR Instance Data Length field.
Definition: option4_dnr.h:186
boost::shared_ptr< isc::dns::Name > adn_
Authentication domain name field of variable length.
Definition: option4_dnr.h:338
AddressContainer getAddresses() const
Returns vector with addresses.
Definition: option4_dnr.h:162
Exception thrown when invalid domain name is specified.
Definition: option4_dnr.h:29
InvalidOptionDnrDomainName(const char *file, size_t line, const char *what)
Definition: option4_dnr.h:31
Exception thrown when Service parameters have wrong format.
Definition: option4_dnr.h:37
InvalidOptionDnrSvcParams(const char *file, size_t line, const char *what)
Definition: option4_dnr.h:39
Represents DHCPv4 Encrypted DNS Option (code 162).
Definition: option4_dnr.h:490
std::vector< DnrInstance > DnrInstanceContainer
A Type defined for container holding DNR Instances.
Definition: option4_dnr.h:493
OptionPtr clone() const override
Copies this option and returns a pointer to the copy.
Definition: option4_dnr.cc:28
void addDnrInstance(DnrInstance &dnr_instance)
Adds given DNR instance to Option's DNR Instance container.
Definition: option4_dnr.cc:125
std::string toText(int indent=0) const override
Returns string representation of the option.
Definition: option4_dnr.cc:98
void unpack(OptionBufferConstIter begin, OptionBufferConstIter end) override
Parses received wire data buffer.
Definition: option4_dnr.cc:51
DnrInstanceContainer dnr_instances_
Container holding DNR Instances.
Definition: option4_dnr.h:571
const DnrInstanceContainer & getDnrInstances() const
Getter of the dnr_instances_ field.
Definition: option4_dnr.h:521
uint16_t len() const override
Returns length of the complete option (data length + DHCPv4/DHCPv6 option header)
Definition: option4_dnr.cc:114
void pack(util::OutputBuffer &buf, bool check=true) const override
Writes option in wire-format to a buffer.
Definition: option4_dnr.cc:33
Universe
defines option universe DHCPv4 or DHCPv6
Definition: option.h:83
void check() const
A protected method used for option correctness.
Definition: option.cc:90
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition: buffer.h:347
boost::shared_ptr< Option4Dnr > Option4DnrPtr
A pointer to the OptionDnr4 object.
Definition: option4_dnr.h:593
OptionBuffer::const_iterator OptionBufferConstIter
const_iterator for walking over OptionBuffer
Definition: option.h:30
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
Definition: option.h:24
boost::shared_ptr< Option > OptionPtr
Definition: option.h:37
Defines the logger used by the top-level component of kea-lfc.