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());
46 if (mode_str ==
"check-with-dhcid") {
50 if (mode_str ==
"no-check-with-dhcid") {
54 if (mode_str ==
"check-exists-with-dhcid") {
58 if (mode_str ==
"no-check-without-dhcid") {
69 return (
"check-with-dhcid");
71 return (
"no-check-with-dhcid");
73 return (
"check-exists-with-dhcid");
75 return (
"no-check-without-dhcid");
80 std::ostringstream stream;
81 stream <<
"unknown(" << mode <<
")";
82 return (stream.str());
93const uint8_t DHCID_ID_HWADDR = 0x0;
95const uint8_t DHCID_ID_CLIENTID = 0x1;
97const uint8_t DHCID_ID_DUID = 0x2;
109 const std::vector<uint8_t>& wire_fqdn) {
114 const std::vector<uint8_t>& wire_fqdn) {
119 const std::vector<uint8_t>& wire_fqdn) {
141 const std::vector<uint8_t>& wire_fqdn) {
147 if (!clientid_data.empty() && clientid_data[0] == 255) {
148 if (clientid_data.size() <= 5) {
150 "unable to compute DHCID from client identifier, embedded DUID "
151 "length of: " << clientid_data.size() <<
", is too short");
156 if (clientid_data.size() > 135) {
158 "unable to compute DHCID from client identifier, embedded DUID "
159 "length of: " << clientid_data.size() <<
", is too long");
161 std::vector<uint8_t>::const_iterator start = clientid_data.begin() + 5;
162 std::vector<uint8_t>::const_iterator end = clientid_data.end();
163 std::vector<uint8_t> duid(start, end);
164 createDigest(DHCID_ID_DUID, duid, wire_fqdn);
166 createDigest(DHCID_ID_CLIENTID, clientid_data, wire_fqdn);
172 const std::vector<uint8_t>& wire_fqdn) {
175 "unable to compute DHCID from the HW address, "
176 "NULL pointer has been specified");
177 }
else if (hwaddr->hwaddr_.empty()) {
179 "unable to compute DHCID from the HW address, "
180 "HW address is empty");
182 std::vector<uint8_t> hwaddr_data;
183 hwaddr_data.push_back(hwaddr->htype_);
184 hwaddr_data.insert(hwaddr_data.end(), hwaddr->hwaddr_.begin(),
185 hwaddr->hwaddr_.end());
186 createDigest(DHCID_ID_HWADDR, hwaddr_data, wire_fqdn);
192 const std::vector<uint8_t>& wire_fqdn) {
194 createDigest(DHCID_ID_DUID, duid.
getDuid(), wire_fqdn);
198D2Dhcid::createDigest(
const uint8_t identifier_type,
199 const std::vector<uint8_t>& identifier_data,
200 const std::vector<uint8_t>& wire_fqdn) {
204 if (wire_fqdn.empty()) {
206 "empty FQDN used to create DHCID");
213 if (identifier_data.empty()) {
215 "empty DUID used to create DHCID");
219 std::vector<uint8_t> data = identifier_data;
222 data.insert(data.end(), wire_fqdn.begin(), wire_fqdn.end());
231 }
catch (
const std::exception& ex) {
233 "error while generating DHCID from DUID: "
245 bytes_.resize(3 + hash.getLength());
248 bytes_[1] = identifier_type;
252 std::memcpy(&bytes_[3], hash.getData(), hash.getLength());
266 : change_type_(
CHG_ADD), forward_change_(false),
267 reverse_change_(false), fqdn_(
""), ip_io_address_(
"0.0.0.0"),
268 dhcid_(), lease_expires_on_(), lease_length_(0),
274 const bool forward_change,
const bool reverse_change,
275 const std::string& fqdn,
const std::string& ip_address,
277 const uint64_t lease_expires_on,
278 const uint32_t lease_length,
280 : change_type_(change_type), forward_change_(forward_change),
281 reverse_change_(reverse_change), fqdn_(fqdn), ip_io_address_(
"0.0.0.0"),
282 dhcid_(dhcid), lease_expires_on_(lease_expires_on),
283 lease_length_(lease_length),
284 conflict_resolution_mode_(conflict_resolution_mode),
308 size_t len = buffer.readUint16();
311 std::vector<uint8_t> vec;
312 buffer.readVector(vec, len);
315 std::string string_data(vec.begin(), vec.end());
346 std::string json =
toJSON();
347 uint16_t length = json.size();
351 buffer.writeUint16(length);
352 buffer.writeData(json.c_str(), length);
374 "Malformed NameChangeRequest JSON: " << ex.
what());
378 ElementMap element_map = elements->mapValue();
390 element = ncr->getElement(
"change-type", element_map);
391 ncr->setChangeType(element);
393 element = ncr->getElement(
"forward-change", element_map);
394 ncr->setForwardChange(element);
396 element = ncr->getElement(
"reverse-change", element_map);
397 ncr->setReverseChange(element);
399 element = ncr->getElement(
"fqdn", element_map);
400 ncr->setFqdn(element);
402 element = ncr->getElement(
"ip-address", element_map);
403 ncr->setIpAddress(element);
405 element = ncr->getElement(
"dhcid", element_map);
406 ncr->setDhcid(element);
408 element = ncr->getElement(
"lease-expires-on", element_map);
409 ncr->setLeaseExpiresOn(element);
411 element = ncr->getElement(
"lease-length", element_map);
412 ncr->setLeaseLength(element);
417 auto found = element_map.find(
"conflict-resolution-mode");
418 if (found != element_map.end()) {
419 ncr->setConflictResolutionMode(found->second);
421 found = element_map.find(
"use-conflict-resolution");
422 if (found != element_map.end()) {
423 ncr->translateUseConflictResolution(found->second);
432 ncr->validateContent();
443 std::ostringstream stream;
446 <<
"\"forward-change\":"
448 <<
"\"reverse-change\":"
450 <<
"\"fqdn\":\"" <<
getFqdn() <<
"\","
452 <<
"\"dhcid\":\"" <<
getDhcid().toStr() <<
"\","
455 <<
"\"conflict-resolution-mode\":"
459 return (stream.str());
473 if (dhcid_.
getBytes().size() == 0) {
478 if (!forward_change_ && !reverse_change_) {
480 "Invalid Request, forward and reverse flags are both false");
488 ElementMap::const_iterator it = element_map.find(name);
489 if (it == element_map.end()) {
492 "NameChangeRequest value missing for: " << name );
501 change_type_ = value;
510 raw_value = element->intValue();
514 "Wrong data type for change_type: " << ex.
what());
520 "Invalid data value for change_type: " << raw_value);
529 forward_change_ = value;
537 value = element->boolValue();
541 "Wrong data type for forward-change: " << ex.
what());
550 reverse_change_ = value;
558 value = element->boolValue();
562 "Wrong data type for reverse_change: " << ex.
what());
572 setFqdn(element->stringValue());
579 fqdn_ = tmp.toText();
580 }
catch (
const std::exception& ex) {
582 "Invalid FQDN value: " << value <<
", reason: "
594 "Invalid ip address string for ip_address: " << value);
626 "Invalid date-time string: [" << value <<
"]");
638 lease_length_ = value;
646 value = element->intValue();
650 "Wrong data type for lease_length: " << ex.
what());
654 if (value > std::numeric_limits<uint32_t>::max()) {
656 "is too large for unsigned 32-bit integer.");
660 "is negative. It must greater than or equal to zero ");
670 bool value = element->boolValue();
681 conflict_resolution_mode_ = value;
704 std::ostringstream stream;
706 stream <<
"Type: " <<
static_cast<int>(change_type_) <<
" (";
707 switch (change_type_) {
709 stream <<
"CHG_ADD)\n";
712 stream <<
"CHG_REMOVE)\n";
716 stream <<
"Invalid Value\n";
719 stream <<
"Forward Change: " << (forward_change_ ?
"yes" :
"no")
721 <<
"Reverse Change: " << (reverse_change_ ?
"yes" :
"no")
723 <<
"FQDN: [" << fqdn_ <<
"]" << std::endl
724 <<
"IP Address: [" << ip_io_address_ <<
"]" << std::endl
725 <<
"DHCID: [" << dhcid_.
toStr() <<
"]" << std::endl
727 <<
"Lease Length: " << lease_length_ << std::endl
728 <<
"Conflict Resolution Mode: "
732 return (stream.str());
737 return ((change_type_ == other.change_type_) &&
738 (forward_change_ == other.forward_change_) &&
739 (reverse_change_ == other.reverse_change_) &&
740 (fqdn_ == other.fqdn_) &&
741 (ip_io_address_ == other.ip_io_address_) &&
742 (dhcid_ == other.dhcid_) &&
743 (lease_expires_on_ == other.lease_expires_on_) &&
744 (lease_length_ == other.lease_length_) &&
745 (conflict_resolution_mode_ == other.conflict_resolution_mode_));
750 return (!(*
this == other));
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.
The IOAddress class represents an IP addresses (version agnostic)
An exception that is thrown if an error occurs within the IO module.
static ElementPtr fromJSON(const std::string &in, bool preproc=false)
These functions will parse the given string (JSON) representation of a compound element.
A standard Data module exception that is thrown if a parse error is encountered when constructing an ...
A standard Data module exception that is thrown if a function is called for an Element that has a wro...
Holds DUID (DHCPv6 Unique Identifier)
const std::vector< uint8_t > & getDuid() const
Returns a const reference to the actual DUID value.
Container class for handling the DHCID value within a NameChangeRequest.
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.
void fromDUID(const isc::dhcp::DUID &duid, const std::vector< uint8_t > &wire_fqdn)
Sets the DHCID value based on the DUID and FQDN.
const std::vector< uint8_t > & getBytes() const
Returns a reference to the DHCID byte vector.
D2Dhcid()
Default constructor.
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.
std::string toStr() const
Returns the DHCID value as a string of hexadecimal digits.
Exception thrown when there is an error occurred during computation of the DHCID.
Represents a DHCP-DDNS client request.
bool operator==(const NameChangeRequest &b) const
bool operator!=(const NameChangeRequest &b) const
void setStatus(const NameChangeStatus value)
Sets the request status to the given value.
void setChangeType(const NameChangeType value)
Sets the change type to the given value.
std::string toText() const
Returns a text rendition of the contents of the request.
void setDhcid(isc::data::ConstElementPtr element)
Sets the DHCID based on the value of the given Element.
uint32_t getLeaseLength() const
Fetches the request lease length.
void setIpAddress(const std::string &value)
Sets the IP address to the given value.
void translateUseConflictResolution(isc::data::ConstElementPtr element)
Sets the conflict resolution mode based on the value of the given boolean Element.
const D2Dhcid & getDhcid() const
Fetches the request DHCID.
void setDhcid(const std::string &value)
Sets the DHCID based on the given string value.
std::string toJSON() const
Instance method for marshalling the contents of the request into a string of JSON text.
ConflictResolutionMode getConflictResolutionMode() const
Fetches the conflict resolution mode.
std::string getIpAddress() const
Fetches the request IP address string.
void setFqdn(const std::string &value)
Sets the FQDN to the given value.
void setReverseChange(const bool value)
Sets the reverse change flag to the given value.
void setLeaseLength(const uint32_t value)
Sets the lease length to the given value.
void setLeaseExpiresOn(const std::string &value)
Sets the lease expiration based on the given string.
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...
NameChangeRequest()
Default Constructor.
NameChangeType getChangeType() const
Fetches the request change type.
static NameChangeRequestPtr fromJSON(const std::string &json)
Static method for creating a NameChangeRequest from a string containing a JSON rendition of a request...
void setForwardChange(const bool value)
Sets the forward change flag to the given value.
std::string getLeaseExpiresOnStr() const
Fetches the request lease expiration as string.
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.
void setConflictResolutionMode(const ConflictResolutionMode value)
Sets the conflict resolution mode to the given value.
bool isForwardChange() const
Checks forward change flag.
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...
void validateContent()
Validates the content of a populated request.
const std::string getFqdn() const
Fetches the request FQDN.
bool isReverseChange() const
Checks reverse change flag.
Exception thrown when NameChangeRequest marshalling error occurs.
The Name class encapsulates DNS names.
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
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.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
NameChangeFormat
Defines the list of data wire formats supported.
NameChangeStatus
Defines the runtime processing status values for requests.
@ CHECK_EXISTS_WITH_DHCID
std::map< std::string, isc::data::ConstElementPtr > ElementMap
Defines a map of Elements, keyed by their string name.
std::ostream & operator<<(std::ostream &os, const D2Dhcid &dhcid)
NameChangeFormat stringToNcrFormat(const std::string &fmt_str)
Function which converts labels to NameChangeFormat enum values.
ConflictResolutionMode StringToConflictResolutionMode(const std::string &mode_str)
Function which converts string to ConflictResolutionMode enum values.
std::string ConflictResolutionModeToString(const ConflictResolutionMode &mode)
Function which converts ConflictResolutionMode enums to text labels.
boost::shared_ptr< NameChangeRequest > NameChangeRequestPtr
Defines a pointer to a NameChangeRequest.
std::string ncrFormatToString(NameChangeFormat format)
Function which converts NameChangeFormat enums to text labels.
NameChangeType
Defines the types of DNS updates that can be requested.
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
void decodeHex(const string &encoded_str, vector< uint8_t > &output)
Decode a base16 encoded string into binary data.
string encodeHex(const vector< uint8_t > &binary)
Encode binary data in the base16 format.
string timeToText64(uint64_t value)
Convert integral DNSSEC time to textual form, 64-bit version.
uint64_t timeFromText64(const string &time_txt)
Convert textual DNSSEC time to integer, 64-bit version.
Defines the logger used by the top-level component of kea-lfc.
This file provides the classes needed to embody, compose, and decompose DNS update requests that are ...