16 #include <boost/algorithm/string/predicate.hpp> 27 if (boost::iequals(fmt_str,
"JSON")) {
40 std::ostringstream stream;
41 stream <<
"UNKNOWN(" << format <<
")";
42 return (stream.str());
52 const uint8_t DHCID_ID_HWADDR = 0x0;
55 const uint8_t DHCID_ID_CLIENTID = 0x1;
57 const uint8_t DHCID_ID_DUID = 0x2;
69 const std::vector<uint8_t>& wire_fqdn) {
74 const std::vector<uint8_t>& wire_fqdn) {
79 const std::vector<uint8_t>& wire_fqdn) {
101 const std::vector<uint8_t>& wire_fqdn) {
107 if (!clientid_data.empty() && clientid_data[0] == 255) {
108 if (clientid_data.size() <= 5) {
110 "unable to compute DHCID from client identifier, embedded DUID " 111 "length of: " << clientid_data.size() <<
", is too short");
116 if (clientid_data.size() > 135) {
118 "unable to compute DHCID from client identifier, embedded DUID " 119 "length of: " << clientid_data.size() <<
", is too long");
121 std::vector<uint8_t>::const_iterator start = clientid_data.begin() + 5;
122 std::vector<uint8_t>::const_iterator end = clientid_data.end();
123 std::vector<uint8_t> duid(start, end);
124 createDigest(DHCID_ID_DUID, duid, wire_fqdn);
126 createDigest(DHCID_ID_CLIENTID, clientid_data, wire_fqdn);
132 const std::vector<uint8_t>& wire_fqdn) {
135 "unable to compute DHCID from the HW address, " 136 "NULL pointer has been specified");
137 }
else if (hwaddr->hwaddr_.empty()) {
139 "unable to compute DHCID from the HW address, " 140 "HW address is empty");
142 std::vector<uint8_t> hwaddr_data;
143 hwaddr_data.push_back(hwaddr->htype_);
144 hwaddr_data.insert(hwaddr_data.end(), hwaddr->hwaddr_.begin(),
145 hwaddr->hwaddr_.end());
146 createDigest(DHCID_ID_HWADDR, hwaddr_data, wire_fqdn);
152 const std::vector<uint8_t>& wire_fqdn) {
154 createDigest(DHCID_ID_DUID, duid.
getDuid(), wire_fqdn);
158 D2Dhcid::createDigest(
const uint8_t identifier_type,
159 const std::vector<uint8_t>& identifier_data,
160 const std::vector<uint8_t>& wire_fqdn) {
164 if (wire_fqdn.empty()) {
166 "empty FQDN used to create DHCID");
173 if (identifier_data.empty()) {
175 "empty DUID used to create DHCID");
179 std::vector<uint8_t> data = identifier_data;
182 data.insert(data.end(), wire_fqdn.begin(), wire_fqdn.end());
191 }
catch (
const std::exception& ex) {
193 "error while generating DHCID from DUID: " 208 bytes_[1] = identifier_type;
226 : change_type_(
CHG_ADD), forward_change_(false),
227 reverse_change_(false), fqdn_(
""), ip_io_address_(
"0.0.0.0"),
228 dhcid_(), lease_expires_on_(), lease_length_(0), conflict_resolution_(true),
233 const bool forward_change,
const bool reverse_change,
234 const std::string& fqdn,
const std::string& ip_address,
236 const uint64_t lease_expires_on,
237 const uint32_t lease_length,
238 const bool conflict_resolution)
239 : change_type_(change_type), forward_change_(forward_change),
240 reverse_change_(reverse_change), fqdn_(fqdn), ip_io_address_(
"0.0.0.0"),
241 dhcid_(dhcid), lease_expires_on_(lease_expires_on),
242 lease_length_(lease_length), conflict_resolution_(conflict_resolution),
269 std::vector<uint8_t> vec;
273 std::string string_data(vec.begin(), vec.end());
304 std::string json =
toJSON();
305 uint16_t length = json.size();
332 "Malformed NameChangeRequest JSON: " << ex.
what());
336 ElementMap element_map = elements->mapValue();
348 element = ncr->getElement(
"change-type", element_map);
349 ncr->setChangeType(element);
351 element = ncr->getElement(
"forward-change", element_map);
352 ncr->setForwardChange(element);
354 element = ncr->getElement(
"reverse-change", element_map);
355 ncr->setReverseChange(element);
357 element = ncr->getElement(
"fqdn", element_map);
358 ncr->setFqdn(element);
360 element = ncr->getElement(
"ip-address", element_map);
361 ncr->setIpAddress(element);
363 element = ncr->getElement(
"dhcid", element_map);
364 ncr->setDhcid(element);
366 element = ncr->getElement(
"lease-expires-on", element_map);
367 ncr->setLeaseExpiresOn(element);
369 element = ncr->getElement(
"lease-length", element_map);
370 ncr->setLeaseLength(element);
374 auto found = element_map.find(
"use-conflict-resolution");
375 if (found != element_map.end()) {
376 ncr->setConflictResolution(found->second);
378 ncr->setConflictResolution(
true);
384 ncr->validateContent();
395 std::ostringstream stream;
398 <<
"\"forward-change\":" 400 <<
"\"reverse-change\":" 402 <<
"\"fqdn\":\"" <<
getFqdn() <<
"\"," 407 <<
"\"use-conflict-resolution\":" 410 return (stream.str());
424 if (dhcid_.
getBytes().size() == 0) {
429 if (!forward_change_ && !reverse_change_) {
431 "Invalid Request, forward and reverse flags are both false");
439 ElementMap::const_iterator it = element_map.find(name);
440 if (it == element_map.end()) {
443 "NameChangeRequest value missing for: " << name );
452 change_type_ = value;
461 raw_value = element->intValue();
465 "Wrong data type for change_type: " << ex.
what());
471 "Invalid data value for change_type: " << raw_value);
480 forward_change_ = value;
488 value = element->boolValue();
492 "Wrong data type for forward-change: " << ex.
what());
501 reverse_change_ = value;
509 value = element->boolValue();
513 "Wrong data type for reverse_change: " << ex.
what());
523 setFqdn(element->stringValue());
531 }
catch (
const std::exception& ex) {
533 "Invalid FQDN value: " << value <<
", reason: " 545 "Invalid ip address string for ip_address: " << value);
577 "Invalid date-time string: [" << value <<
"]");
589 lease_length_ = value;
597 value = element->intValue();
601 "Wrong data type for lease_length: " << ex.
what());
605 if (value > std::numeric_limits<uint32_t>::max()) {
607 "is too large for unsigned 32-bit integer.");
611 "is negative. It must greater than or equal to zero ");
620 conflict_resolution_ = value;
628 value = element->boolValue();
632 "Wrong data type for use-conflict-resolution: " << ex.
what());
646 std::ostringstream stream;
648 stream <<
"Type: " <<
static_cast<int>(change_type_) <<
" (";
649 switch (change_type_) {
651 stream <<
"CHG_ADD)\n";
654 stream <<
"CHG_REMOVE)\n";
658 stream <<
"Invalid Value\n";
661 stream <<
"Forward Change: " << (forward_change_ ?
"yes" :
"no")
663 <<
"Reverse Change: " << (reverse_change_ ?
"yes" :
"no")
665 <<
"FQDN: [" << fqdn_ <<
"]" << std::endl
666 <<
"IP Address: [" << ip_io_address_ <<
"]" << std::endl
667 <<
"DHCID: [" << dhcid_.
toStr() <<
"]" << std::endl
669 <<
"Lease Length: " << lease_length_ << std::endl
670 <<
"Conflict Resolution: " << (conflict_resolution_ ?
"yes" :
"no")
673 return (stream.str());
678 return ((change_type_ == other.change_type_) &&
679 (forward_change_ == other.forward_change_) &&
680 (reverse_change_ == other.reverse_change_) &&
681 (fqdn_ == other.fqdn_) &&
682 (ip_io_address_ == other.ip_io_address_) &&
683 (dhcid_ == other.dhcid_) &&
684 (lease_expires_on_ == other.lease_expires_on_) &&
685 (lease_length_ == other.lease_length_) &&
686 (conflict_resolution_ == other.conflict_resolution_));
691 return (!(*
this == other));
The Name class encapsulates DNS names.
std::map< std::string, isc::data::ConstElementPtr > ElementMap
Defines a map of Elements, keyed by their string name.
const std::vector< uint8_t > & getBytes() const
Returns a reference to the DHCID byte vector.
void fromDUID(const isc::dhcp::DUID &duid, const std::vector< uint8_t > &wire_fqdn)
Sets the DHCID value based on the DUID and FQDN.
NameChangeType
Defines the types of DNS updates that can be requested.
static NameChangeRequestPtr fromFormat(const NameChangeFormat format, isc::util::InputBuffer &buffer)
Static method for creating a NameChangeRequest from a buffer containing a marshalled request in a giv...
std::string toText() const
Returns a text rendition of the contents of the request.
bool isForwardChange() const
Checks forward change flag.
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
A standard Data module exception that is thrown if a parse error is encountered when constructing an ...
isc::data::ConstElementPtr getElement(const std::string &name, const ElementMap &element_map) const
Given a name, finds and returns an element from a map of elements.
std::string getLeaseExpiresOnStr() const
Fetches the request lease expiration as string.
uint64_t timeFromText64(const string &time_txt)
Convert textual DNSSEC time to integer, 64-bit version.
NameChangeType getChangeType() const
Fetches the request change type.
boost::shared_ptr< Element > ElementPtr
static ElementPtr fromJSON(const std::string &in, bool preproc=false)
These functions will parse the given string (JSON) representation of a compound element.
void setStatus(const NameChangeStatus value)
Sets the request status to the given value.
NameChangeFormat
Defines the list of data wire formats supported.
void fromHWAddr(const isc::dhcp::HWAddrPtr &hwaddr, const std::vector< uint8_t > &wire_fqdn)
Sets the DHCID value based on the HW address and FQDN.
boost::shared_ptr< NameChangeRequest > NameChangeRequestPtr
Defines a pointer to a NameChangeRequest.
std::string toStr() const
Returns the DHCID value as a string of hexadecimal digits.
static NameChangeRequestPtr fromJSON(const std::string &json)
Static method for creating a NameChangeRequest from a string containing a JSON rendition of a request...
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Holds DUID (DHCPv6 Unique Identifier)
void toFormat(const NameChangeFormat format, isc::util::OutputBuffer &buffer) const
Instance method for marshalling the contents of the request into the given buffer in the given format...
void writeData(const void *data, size_t len)
Copy an arbitrary length of data into the buffer.
bool isReverseChange() const
Checks reverse change flag.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
D2Dhcid()
Default constructor.
Exception thrown when NameChangeRequest marshalling error occurs.
void validateContent()
Validates the content of a populated request.
void setFqdn(const std::string &value)
Sets the FQDN to the given value.
bool operator!=(const NameChangeRequest &b) const
void setLeaseLength(const uint32_t value)
Sets the lease length to the given value.
Exception thrown when there is an error occurred during computation of the DHCID. ...
void decodeHex(const string &input, vector< uint8_t > &result)
Decode a text encoded in the base16 ('hex') format into the original data.
NameChangeRequest()
Default Constructor.
NameChangeStatus
Defines the runtime processing status values for requests.
boost::shared_ptr< const Element > ConstElementPtr
const void * getData() const
Return a pointer to the head of the data stored in the buffer.
A standard DNS module exception that is thrown if an out-of-range buffer operation is being performed...
A standard Data module exception that is thrown if a function is called for an Element that has a wro...
std::string toText(bool omit_final_dot=false) const
Convert the Name to a string.
void setReverseChange(const bool value)
Sets the reverse change flag to the given value.
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
const std::vector< uint8_t > & getDuid() const
Returns a const reference to the actual DUID value.
std::string getIpAddress() const
Fetches the request IP address string.
std::string toJSON() const
Instance method for marshalling the contents of the request into a string of JSON text...
size_t getLength() const
Return the length of data written in the buffer.
void setConflictResolution(const bool value)
Sets the conflict resolution flag to the given value.
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-lfc.
string encodeHex(const vector< uint8_t > &binary)
Encode binary data in the base16 ('hex') format.
std::ostream & operator<<(std::ostream &os, const D2Dhcid &dhcid)
void digest(const void *data, const size_t data_len, const HashAlgorithm hash_algorithm, isc::util::OutputBuffer &result, size_t len)
Create an Hash digest for the given data.
void setLeaseExpiresOn(const std::string &value)
Sets the lease expiration based on the given string.
std::string ncrFormatToString(NameChangeFormat format)
Function which converts NameChangeFormat enums to text labels.
bool useConflictResolution() const
Checks if conflict resolution is enabled.
Container class for handling the DHCID value within a NameChangeRequest.
void writeUint16(uint16_t data)
Write an unsigned 16-bit integer in host byte order into the buffer in network byte order...
An exception that is thrown if an error occurs within the IO module.
NameChangeFormat stringToNcrFormat(const std::string &fmt_str)
Function which converts labels to NameChangeFormat enum values.
uint32_t getLeaseLength() const
Fetches the request lease length.
void fromClientId(const std::vector< uint8_t > &clientid_data, const std::vector< uint8_t > &wire_fqdn)
Sets the DHCID value based on the Client Identifier.
void fromStr(const std::string &data)
Sets the DHCID value based on the given string.
const std::string getFqdn() const
Fetches the request FQDN.
The IOAddress class represents an IP addresses (version agnostic)
const D2Dhcid & getDhcid() const
Fetches the request DHCID.
void setIpAddress(const std::string &value)
Sets the IP address to the given value.
void setChangeType(const NameChangeType value)
Sets the change type to the given value.
Represents a DHCP-DDNS client request.
This file provides the classes needed to embody, compose, and decompose DNS update requests that are ...
string timeToText64(uint64_t value)
Convert integral DNSSEC time to textual form, 64-bit version.
void setForwardChange(const bool value)
Sets the forward change flag to the given value.
void setDhcid(const std::string &value)
Sets the DHCID based on the given string value.
bool operator==(const NameChangeRequest &b) const
std::string format(const std::string &format, const std::vector< std::string > &args)
Apply Formatting.