26 return (cloneInternal<Option4Dnr>());
33 buf.
writeUint16(dnr_instance.getDnrInstanceDataLength());
36 dnr_instance.packAdn(buf);
37 if (dnr_instance.isAdnOnlyMode()) {
42 dnr_instance.packAddresses(buf);
43 dnr_instance.packSvcParams(buf);
50 while (begin != end) {
54 <<
"DNR instance data truncated to size "
55 << std::distance(begin, end));
68 dnr_instance.
unpackAdn(begin, dnr_instance_end);
70 if (begin == dnr_instance_end) {
90 std::ostringstream stream;
91 std::string in(indent,
' ');
92 stream << in <<
"type=" <<
type_ <<
"(V4_DNR), "
96 stream <<
", DNR Instance " << ++i
97 <<
"(Instance len=" << dnr_instance.getDnrInstanceDataLength() <<
", "
98 << dnr_instance.getDnrInstanceAsText() <<
")";
101 return (stream.str());
108 len += dnr_instance.getDnrInstanceDataLength() +
109 dnr_instance.getDnrInstanceDataLengthSize();
123 : universe_(universe), dnr_instance_data_length_(0), service_priority_(0),
124 adn_length_(0), addr_length_(0), svc_params_length_(0),
125 adn_only_mode_(true), dnr_instance_data_length_size_(0),
126 adn_length_size_(0), addr_length_size_(0), minimal_length_(0) {
131 const uint16_t service_priority,
132 const std::string& adn,
134 const std::string& svc_params)
135 : universe_(universe), dnr_instance_data_length_(0),
136 service_priority_(service_priority), adn_length_(0),
137 addr_length_(0), ip_addresses_(ip_addresses), svc_params_length_(0),
138 adn_only_mode_(true), svc_params_(svc_params),
139 dnr_instance_data_length_size_(0), adn_length_size_(0),
140 addr_length_size_(0), minimal_length_(0) {
147 const uint16_t service_priority,
148 const std::string& adn)
149 : universe_(universe), dnr_instance_data_length_(0),
150 service_priority_(service_priority), adn_length_(0),
151 addr_length_(0), svc_params_length_(0), adn_only_mode_(true),
152 dnr_instance_data_length_size_(0), adn_length_size_(0),
153 addr_length_size_(0), minimal_length_(0) {
164 <<
"Mandatory Authentication Domain Name fully "
165 "qualified domain-name is missing");
170 size_t data_length = 0;
171 const uint8_t* data = label_sequence.
getData(&data_length);
178 AddressContainer::const_iterator address =
ip_addresses_.begin();
194 return (
adn_) ? (
adn_->toText()) : (
"");
199 std::string trimmed_adn =
str::trim(adn);
200 if (trimmed_adn.empty()) {
202 <<
"Mandatory Authentication Domain Name fully "
203 "qualified domain-name must not be empty");
210 <<
"Failed to parse "
211 "fully qualified domain-name from string - "
217 label_sequence.
getData(&adn_len);
218 if (adn_len > std::numeric_limits<uint16_t>::max()) {
220 <<
" is bigger than uint_16 MAX");
234 adn_tuple.
unpack(begin, end);
237 <<
" - " << ex.
what());
246 <<
"Mandatory Authentication Domain Name fully "
247 "qualified domain-name is missing");
255 <<
"Failed to parse "
256 "fully qualified domain-name from wire format "
266 if (svc_params.empty()) {
268 <<
"Provided Svc Params field is empty");
271 if (!from_wire_data) {
274 auto svc_params_len = svc_params.length();
275 if (svc_params_len > std::numeric_limits<uint16_t>::max()) {
277 <<
"Given Svc Params length " << svc_params_len
278 <<
" is bigger than uint_16 MAX");
295 std::unordered_set<std::string> keys;
300 std::string regex =
"[^a-z0-9-]";
304 for (
const std::string& token :
tokens) {
305 std::vector<std::string> key_val =
str::tokens(token,
"=");
306 if (key_val.size() > 2) {
308 getLogPrefix() <<
"Wrong Svc Params syntax - more than one "
309 "equals sign found in SvcParamKey=SvcParamValue pair");
313 std::string key = key_val[0];
314 if (key.length() > 63) {
316 getLogPrefix() <<
"Wrong Svc Params syntax - key had more than 63 "
317 "characters - " << key);
322 << key <<
" must not be used");
325 auto insert_res = keys.insert(key);
326 if (!insert_res.second) {
328 << key <<
" was duplicated");
331 std::string sanitized_key = sanitizer->scrub(key);
332 if (sanitized_key.size() < key.size()) {
335 <<
"Wrong Svc Params syntax - invalid character used in key - " << key);
352 "mode, at least one valid IP address must "
362 const uint16_t max_addr_len = (
universe_ ==
Option::V4) ? std::numeric_limits<uint8_t>::max() :
363 std::numeric_limits<uint16_t>::max();
365 if (addr_len > max_addr_len) {
367 <<
" is bigger than MAX " << max_addr_len);
378 std::ostringstream stream;
382 stream <<
", addr_length=" <<
addr_length_ <<
", address(es):";
384 stream <<
" " << address.toText();
392 return (stream.str());
416 <<
"DNR instance data truncated to size "
417 << std::distance(begin, end) <<
" but it was supposed to be "
432 addr_tuple.
unpack(begin, end);
435 <<
" - " << ex.
what());
442 <<
"Addr Len=" <<
addr_length_ <<
" is not divisible by 4");
451 <<
" but it must contain at least one valid IP address");
458 while (addr_begin != addr_end) {
459 const uint8_t* ptr = &(*addr_begin);
461 addr_begin += V4ADDRESS_LEN;
462 begin += V4ADDRESS_LEN;
477DnrInstance::initMembers() {
484 (
"DHCPv4 Encrypted DNS Option (" + std::to_string(
DHO_V4_DNR) +
") malformed: ") :
485 (
"DHCPv6 Encrypted DNS Option (" + std::to_string(
D6O_V6_DNR) +
") malformed: ");
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
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.
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
The IOAddress class represents an IP addresses (version agnostic)
Represents DNR Instance which is used both in DHCPv4 and DHCPv6 Encrypted DNS Option.
Option::Universe universe_
Either V4 or V6 Option universe.
std::vector< isc::asiolink::IOAddress > AddressContainer
A Type defined for container holding IP addresses.
std::string getDnrInstanceAsText() const
Returns string representation of the DNR instance.
void unpackSvcParams(OptionBufferConstIter &begin, OptionBufferConstIter end)
Unpacks Service Parameters from wire data buffer and stores it in svc_params_.
void setAdnOnlyMode(bool adn_only_mode)
Setter of the adn_only_mode_ field.
uint16_t dnr_instance_data_length_
Length of all following data inside this DNR instance in octets.
uint16_t getDnrInstanceDataLength() const
Getter of the dnr_instance_data_length_.
uint8_t getMinimalLength() const
Returns minimal length of the DNR instance data (without headers) in octets.
AddressContainer ip_addresses_
Vector container holding one or more IP addresses.
uint8_t getAdnLengthSize() const
Returns size in octets of ADN Length field.
void unpackDnrInstanceDataLength(OptionBufferConstIter &begin, OptionBufferConstIter end)
Unpacks DNR Instance Data Length from wire data buffer and stores it in dnr_instance_data_length_.
void packAdn(isc::util::OutputBuffer &buf) const
Writes the ADN FQDN in the wire format into a buffer.
uint16_t addr_length_
Length of included IP addresses in octets.
virtual void unpackAddresses(OptionBufferConstIter &begin, OptionBufferConstIter end)
Unpacks IP address(es) from wire data and stores it/them in ip_addresses_.
uint8_t getAddrLengthSize() const
Returns size in octets of Addr Length field.
uint16_t svc_params_length_
Length of Service Parameters field in octets.
void unpackServicePriority(OptionBufferConstIter &begin)
Unpacks Service Priority from wire data buffer and stores it in service_priority_.
uint16_t service_priority_
The priority of this instance compared to other DNR instances.
void checkSvcParams(bool from_wire_data=true)
Checks SvcParams field if encoded correctly and throws in case of issue found.
void packSvcParams(isc::util::OutputBuffer &buf) const
Writes the Service Parameters in the wire format into a buffer.
virtual void packAddresses(isc::util::OutputBuffer &buf) const
Writes the IP address(es) in the wire format into a buffer.
std::string getAdnAsText() const
Returns the Authentication domain name in the text format.
std::string getLogPrefix() const
Returns Log prefix depending on V4/V6 Option universe.
static const std::unordered_set< std::string > FORBIDDEN_SVC_PARAMS
Set of forbidden SvcParams.
void checkFields()
Checks IP address(es) field if data is correct and throws in case of issue found.
bool adn_only_mode_
Flag stating whether ADN only mode is used or not.
void setAdn(const std::string &adn)
Sets Authentication domain name from given string.
uint16_t adn_length_
Length of the authentication-domain-name data in octets.
uint16_t dnrInstanceLen() const
Calculates and returns length of DNR Instance data in octets.
void addIpAddress(const asiolink::IOAddress &ip_address)
Adds IP address to ip_addresses_ container.
void unpackAdn(OptionBufferConstIter &begin, OptionBufferConstIter end)
Unpacks the ADN from given wire data buffer and stores it in adn_ field.
static const uint8_t SERVICE_PRIORITY_SIZE
Size in octets of Service Priority field.
uint8_t getDnrInstanceDataLengthSize() const
Returns size in octets of DNR Instance Data Length field.
boost::shared_ptr< isc::dns::Name > adn_
Authentication domain name field of variable length.
std::string svc_params_
Service Parameters (SvcParams) (variable length).
DnrInstance(Option::Universe universe)
Constructor of the empty DNR Instance.
Exception thrown when invalid domain name is specified.
Exception thrown when Service parameters have wrong format.
Represents a single instance of the opaque data preceded by length.
const Buffer & getData() const
Returns a reference to the buffer holding tuple data.
LengthFieldType
Size of the length field in the tuple.
void unpack(InputIterator begin, InputIterator end)
Parses wire data and creates a tuple from it.
size_t getLength() const
Returns the length of the data in the tuple.
OptionPtr clone() const override
Copies this option and returns a pointer to the copy.
void addDnrInstance(DnrInstance &dnr_instance)
Adds given DNR instance to Option's DNR Instance container.
std::string toText(int indent=0) const override
Returns string representation of the option.
void unpack(OptionBufferConstIter begin, OptionBufferConstIter end) override
Parses received wire data buffer.
DnrInstanceContainer dnr_instances_
Container holding DNR Instances.
uint16_t len() const override
Returns length of the complete option (data length + DHCPv4/DHCPv6 option header)
void pack(util::OutputBuffer &buf, bool check=true) const override
Writes option in wire-format to a buffer.
Option4Dnr()
Constructor of the empty Option.
static OpaqueDataTuple::LengthFieldType getTupleLenFieldType(Option::Universe u)
Returns Length Field Type for a tuple.
uint16_t type_
option type (0-255 for DHCPv4, 0-65535 for DHCPv6)
virtual uint16_t getHeaderLen() const
Returns length of header (2 for v4, 4 for v6)
Universe
defines option universe DHCPv4 or DHCPv6
void setData(InputIterator first, InputIterator last)
Sets content of this option from buffer.
void packHeader(isc::util::OutputBuffer &buf, bool check=true) const
Store option's header in a buffer.
void check() const
A protected method used for option correctness.
static const size_t OPTION4_HDR_LEN
length of the usual DHCPv4 option header (there are exceptions)
Light-weight Accessor to Name data.
const uint8_t * getData(size_t *len) const
Return the wire-format data for this LabelSequence.
size_t getDataLength() const
Return the length of the wire-format data of this LabelSequence.
The Name class encapsulates DNS names.
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
void writeUint8(uint8_t data)
Write an unsigned 8-bit integer into the buffer.
void writeUint16(uint16_t data)
Write an unsigned 16-bit integer in host byte order into the buffer in network byte order.
void writeData(const void *data, size_t len)
Copy an arbitrary length of data into the buffer.
void writeUint32(uint32_t data)
Write an unsigned 32-bit integer in host byte order into the buffer in network byte order.
Implements a regular expression based string scrubber.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
OptionBuffer::const_iterator OptionBufferConstIter
const_iterator for walking over OptionBuffer
boost::shared_ptr< Option > OptionPtr
boost::shared_ptr< StringSanitizer > StringSanitizerPtr
Type representing the pointer to the StringSanitizer.
string trim(const string &instring)
Trim Leading and Trailing Spaces.
vector< string > tokens(const std::string &text, const std::string &delim, bool escape)
Split String into Tokens.
uint32_t readUint32(const void *buffer, size_t length)
Read Unsigned 32-Bit Integer from Buffer.
uint16_t readUint16(const void *buffer, size_t length)
Read Unsigned 16-Bit Integer from Buffer.
Defines the logger used by the top-level component of kea-lfc.