| Kea 3.0.2-git

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>
16#include <dhcp/option_data_types.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
25 namespace isc {
26 namespace dhcp {
27
29 class InvalidOptionDnrDomainName : public Exception {
30 public:
31 InvalidOptionDnrDomainName(const char* file, size_t line, const char* what)
32 : isc::Exception(file, line, what) {
33 }
34};
35
37 class InvalidOptionDnrSvcParams : public Exception {
38 public:
39 InvalidOptionDnrSvcParams(const char* file, size_t line, const char* what)
40 : isc::Exception(file, line, what) {
41 }
42};
43
55 class DnrInstance {
56 public:
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
76 static const SvcParamsMap SVC_PARAMS;
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 {
111 return (dnr_instance_data_length_);
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
162 AddressContainer getAddresses() const {
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
186 uint8_t getDnrInstanceDataLengthSize() const {
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
219 void setDnrInstanceDataLength() {
220 dnr_instance_data_length_ = dnrInstanceLen();
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
258 void unpackDnrInstanceDataLength(OptionBufferConstIter& begin, OptionBufferConstIter end);
259
263 void unpackServicePriority(OptionBufferConstIter& begin);
264
275 void unpackAdn(OptionBufferConstIter& begin, OptionBufferConstIter end);
276
287 virtual void unpackAddresses(OptionBufferConstIter& begin, OptionBufferConstIter end);
288
296 void unpackSvcParams(OptionBufferConstIter& begin, OptionBufferConstIter end);
297
301 void addIpAddress(const asiolink::IOAddress& ip_address);
302
327 void parseDnrInstanceConfigData(const std::string& config_txt);
328
329 protected:
331 Option::Universe universe_;
332
338 boost::shared_ptr<isc::dns::Name> adn_;
339
343 uint16_t dnr_instance_data_length_;
344
346 uint16_t service_priority_;
347
349 uint16_t adn_length_;
350
352 uint16_t addr_length_;
353
360 AddressContainer ip_addresses_;
361
363 uint16_t svc_params_length_;
364
369 bool adn_only_mode_;
370
375 OptionBuffer svc_params_buf_;
376
386 std::map<uint16_t, OpaqueDataTuple> svc_params_map_;
387
390 uint16_t dnrInstanceLen() const;
391
394 bool alpn_http_;
395
396 private:
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
490 class Option4Dnr : public Option {
491 public:
493 typedef std::vector<DnrInstance> DnrInstanceContainer;
494
511 Option4Dnr(OptionBufferConstIter begin,
512 OptionBufferConstIter end,
513 bool convenient_notation = false);
514
517 void addDnrInstance(DnrInstance& dnr_instance);
518
521 const DnrInstanceContainer& getDnrInstances() const {
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
569 protected:
571 DnrInstanceContainer dnr_instances_;
572
573 private:
576 bool convenient_notation_;
577
589 void parseConfigData(const std::string& config_txt);
590};
591
593 typedef boost::shared_ptr<Option4Dnr> Option4DnrPtr;
594
595} // namespace dhcp
596} // namespace isc
597
598#endif // OPTION4_DNR_H
isc::Exception::Exception
Exception(const char *file, size_t line, const char *what)
Constructor for a given type for exceptions with file name and file line number.
Definition exceptions/exceptions.cc:17
isc::Exception::what
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Definition exceptions/exceptions.cc:32
isc::asiolink::IOAddress
The IOAddress class represents an IP addresses (version agnostic).
Definition io_address.h:45
isc::dhcp::DnrInstance
Represents DNR Instance which is used both in DHCPv4 and DHCPv6 Encrypted DNS Option.
Definition option4_dnr.h:55
isc::dhcp::DnrInstance::universe_
Option::Universe universe_
Either V4 or V6 Option universe.
Definition option4_dnr.h:331
isc::dhcp::DnrInstance::AddressContainer
std::vector< isc::asiolink::IOAddress > AddressContainer
A Type defined for container holding IP addresses.
Definition option4_dnr.h:58
isc::dhcp::DnrInstance::SUPPORTED_SVC_PARAMS
static const std::set< uint8_t > SUPPORTED_SVC_PARAMS
Ordered set of supported SvcParamKeys.
Definition option4_dnr.h:91
isc::dhcp::DnrInstance::getDnrInstanceAsText
std::string getDnrInstanceAsText() const
Returns string representation of the DNR instance.
Definition option4_dnr.cc:345
isc::dhcp::DnrInstance::unpackSvcParams
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
isc::dhcp::DnrInstance::setAdnOnlyMode
void setAdnOnlyMode(bool adn_only_mode)
Setter of the adn_only_mode_ field.
Definition option4_dnr.h:210
isc::dhcp::DnrInstance::getAddrLength
uint16_t getAddrLength() const
Getter of the addr_length_.
Definition option4_dnr.h:143
isc::dhcp::DnrInstance::svc_params_map_
std::map< uint16_t, OpaqueDataTuple > svc_params_map_
Service Parameters stored in a map.
Definition option4_dnr.h:386
isc::dhcp::DnrInstance::dnr_instance_data_length_
uint16_t dnr_instance_data_length_
Length of all following data inside this DNR instance in octets.
Definition option4_dnr.h:343
isc::dhcp::DnrInstance::getDnrInstanceDataLength
uint16_t getDnrInstanceDataLength() const
Getter of the dnr_instance_data_length_.
Definition option4_dnr.h:110
isc::dhcp::DnrInstance::getMinimalLength
uint8_t getMinimalLength() const
Returns minimal length of the DNR instance data (without headers) in octets.
Definition option4_dnr.h:176
isc::dhcp::DnrInstance::svc_params_buf_
OptionBuffer svc_params_buf_
Service Parameters (SvcParams) (variable length) as on-wire data buffer.
Definition option4_dnr.h:375
isc::dhcp::DnrInstance::ip_addresses_
AddressContainer ip_addresses_
Vector container holding one or more IP addresses.
Definition option4_dnr.h:360
isc::dhcp::DnrInstance::getAdnLengthSize
uint8_t getAdnLengthSize() const
Returns size in octets of ADN Length field.
Definition option4_dnr.h:191
isc::dhcp::DnrInstance::unpackDnrInstanceDataLength
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
isc::dhcp::DnrInstance::getSvcParams
const OptionBuffer & getSvcParams() const
Returns a reference to the buffer holding SvcParam data.
Definition option4_dnr.h:169
isc::dhcp::DnrInstance::packAdn
void packAdn(isc::util::OutputBuffer &buf) const
Writes the ADN FQDN in the wire format into a buffer.
Definition option4_dnr.cc:221
isc::dhcp::DnrInstance::setDnrInstanceDataLength
void setDnrInstanceDataLength()
Setter of the dnr_instance_data_length_ field.
Definition option4_dnr.h:219
isc::dhcp::DnrInstance::addr_length_
uint16_t addr_length_
Length of included IP addresses in octets.
Definition option4_dnr.h:352
isc::dhcp::DnrInstance::unpackAddresses
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
isc::dhcp::DnrInstance::getAddrLengthSize
uint8_t getAddrLengthSize() const
Returns size in octets of Addr Length field.
Definition option4_dnr.h:181
isc::dhcp::DnrInstance::svc_params_length_
uint16_t svc_params_length_
Length of Service Parameters field in octets.
Definition option4_dnr.h:363
isc::dhcp::DnrInstance::parseDnrInstanceConfigData
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
isc::dhcp::DnrInstance::unpackServicePriority
void unpackServicePriority(OptionBufferConstIter &begin)
Unpacks Service Priority from wire data buffer and stores it in service_priority_.
Definition option4_dnr.cc:404
isc::dhcp::DnrInstance::service_priority_
uint16_t service_priority_
The priority of this instance compared to other DNR instances.
Definition option4_dnr.h:346
isc::dhcp::DnrInstance::packSvcParams
void packSvcParams(isc::util::OutputBuffer &buf) const
Writes the Service Parameters in the wire format into a buffer.
Definition option4_dnr.cc:248
isc::dhcp::DnrInstance::SvcParamsMap
boost::bimap< std::string, uint16_t > SvcParamsMap
A Type defined for boost Bimap holding SvcParamKeys.
Definition option4_dnr.h:61
isc::dhcp::DnrInstance::isAdnOnlyMode
bool isAdnOnlyMode() const
Returns whether ADN only mode is enabled or disabled.
Definition option4_dnr.h:203
isc::dhcp::DnrInstance::getSvcParamsLength
uint16_t getSvcParamsLength() const
Getter of the svc_params_length_.
Definition option4_dnr.h:150
isc::dhcp::DnrInstance::packAddresses
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
isc::dhcp::DnrInstance::alpn_http_
bool alpn_http_
Indicates whether the "alpn" SvcParam contains support for HTTP.
Definition option4_dnr.h:394
isc::dhcp::DnrInstance::getAdnAsText
std::string getAdnAsText() const
Returns the Authentication domain name in the text format.
Definition option4_dnr.cc:255
isc::dhcp::DnrInstance::getLogPrefix
std::string getLogPrefix() const
Returns Log prefix depending on V4/V6 Option universe.
Definition option4_dnr.h:198
isc::dhcp::DnrInstance::getServicePriority
uint16_t getServicePriority() const
Getter of the service_priority_.
Definition option4_dnr.h:117
isc::dhcp::DnrInstance::SVC_PARAMS
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
isc::dhcp::DnrInstance::ALPN_IDS
static const std::unordered_set< std::string > ALPN_IDS
Possible ALPN protocol IDs.
Definition option4_dnr.h:97
isc::dhcp::DnrInstance::FORBIDDEN_SVC_PARAMS
static const std::unordered_set< std::string > FORBIDDEN_SVC_PARAMS
Set of forbidden SvcParams.
Definition option4_dnr.h:71
isc::dhcp::DnrInstance::adn_only_mode_
bool adn_only_mode_
Flag stating whether ADN only mode is used or not.
Definition option4_dnr.h:369
isc::dhcp::DnrInstance::adn_length_
uint16_t adn_length_
Length of the authentication-domain-name data in octets.
Definition option4_dnr.h:349
isc::dhcp::DnrInstance::dnrInstanceLen
uint16_t dnrInstanceLen() const
Calculates and returns length of DNR Instance data in octets.
Definition option4_dnr.cc:377
isc::dhcp::DnrInstance::~DnrInstance
virtual ~DnrInstance()=default
Default destructor.
isc::dhcp::DnrInstance::addIpAddress
void addIpAddress(const asiolink::IOAddress &ip_address)
Adds IP address to ip_addresses_ container.
Definition option4_dnr.cc:387
isc::dhcp::DnrInstance::getAdnLength
uint16_t getAdnLength() const
Getter of the adn_length_.
Definition option4_dnr.h:124
isc::dhcp::DnrInstance::unpackAdn
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
isc::dhcp::DnrInstance::SERVICE_PRIORITY_SIZE
static const uint8_t SERVICE_PRIORITY_SIZE
Size in octets of Service Priority field.
Definition option4_dnr.h:64
isc::dhcp::DnrInstance::getDnrInstanceDataLengthSize
uint8_t getDnrInstanceDataLengthSize() const
Returns size in octets of DNR Instance Data Length field.
Definition option4_dnr.h:186
isc::dhcp::DnrInstance::adn_
boost::shared_ptr< isc::dns::Name > adn_
Authentication domain name field of variable length.
Definition option4_dnr.h:338
isc::dhcp::DnrInstance::DnrInstance
DnrInstance(Option::Universe universe)
Constructor of the empty DNR Instance.
Definition option4_dnr.cc:212
isc::dhcp::DnrInstance::getAddresses
AddressContainer getAddresses() const
Returns vector with addresses.
Definition option4_dnr.h:162
isc::dhcp::InvalidOptionDnrDomainName::InvalidOptionDnrDomainName
InvalidOptionDnrDomainName(const char *file, size_t line, const char *what)
Definition option4_dnr.h:31
isc::dhcp::InvalidOptionDnrSvcParams::InvalidOptionDnrSvcParams
InvalidOptionDnrSvcParams(const char *file, size_t line, const char *what)
Definition option4_dnr.h:39
isc::dhcp::Option4Dnr::DnrInstanceContainer
std::vector< DnrInstance > DnrInstanceContainer
A Type defined for container holding DNR Instances.
Definition option4_dnr.h:493
isc::dhcp::Option4Dnr::clone
OptionPtr clone() const override
Copies this option and returns a pointer to the copy.
Definition option4_dnr.cc:28
isc::dhcp::Option4Dnr::addDnrInstance
void addDnrInstance(DnrInstance &dnr_instance)
Adds given DNR instance to Option's DNR Instance container.
Definition option4_dnr.cc:125
isc::dhcp::Option4Dnr::toText
std::string toText(int indent=0) const override
Returns string representation of the option.
Definition option4_dnr.cc:98
isc::dhcp::Option4Dnr::Option4Dnr
Option4Dnr(OptionBufferConstIter begin, OptionBufferConstIter end, bool convenient_notation=false)
Constructor of the Option from on-wire data.
Definition option4_dnr.cc:20
isc::dhcp::Option4Dnr::unpack
void unpack(OptionBufferConstIter begin, OptionBufferConstIter end) override
Parses received wire data buffer.
Definition option4_dnr.cc:51
isc::dhcp::Option4Dnr::dnr_instances_
DnrInstanceContainer dnr_instances_
Container holding DNR Instances.
Definition option4_dnr.h:571
isc::dhcp::Option4Dnr::getDnrInstances
const DnrInstanceContainer & getDnrInstances() const
Getter of the dnr_instances_ field.
Definition option4_dnr.h:521
isc::dhcp::Option4Dnr::len
uint16_t len() const override
Returns length of the complete option (data length + DHCPv4/DHCPv6 option header).
Definition option4_dnr.cc:114
isc::dhcp::Option4Dnr::pack
void pack(util::OutputBuffer &buf, bool check=true) const override
Writes option in wire-format to a buffer.
Definition option4_dnr.cc:33
isc::dhcp::Option::Universe
Universe
defines option universe DHCPv4 or DHCPv6
Definition option.h:90
isc::dhcp::Option::Option
Option(Universe u, uint16_t type)
ctor, used for options constructed, usually during transmission
Definition option.cc:39
isc::dhcp::Option::check
void check() const
A protected method used for option correctness.
Definition option.cc:90
isc::util::OutputBuffer
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition buffer.h:346
dhcp4.h
dhcp6.h
io_address.h
name.h
isc::dhcp
Definition dhcp4/client_handler.cc:20
isc::dhcp::Option4DnrPtr
boost::shared_ptr< Option4Dnr > Option4DnrPtr
A pointer to the OptionDnr4 object.
Definition option4_dnr.h:593
isc::dhcp::OptionBufferConstIter
OptionBuffer::const_iterator OptionBufferConstIter
const_iterator for walking over OptionBuffer
Definition option.h:30
isc::dhcp::OptionBuffer
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
Definition option.h:24
isc::dhcp::OptionPtr
boost::shared_ptr< Option > OptionPtr
Definition option.h:37
isc::util::file
Definition filesystem.cc:28
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148
option.h
option_data_types.h
utf8.h