Kea 3.2.1-git
ncr_msg.h
Go to the documentation of this file.
1// Copyright (C) 2013-2026 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 NCR_MSG_H
8#define NCR_MSG_H
9
14
15#include <cc/data.h>
16#include <dhcp/duid.h>
17#include <dhcp/hwaddr.h>
18#include <dns/name.h>
19#include <dns/time_utils.h>
21#include <util/buffer.h>
22
23#include <boost/algorithm/string/case_conv.hpp>
24#include <time.h>
25#include <string>
26
27namespace isc {
28namespace dhcp_ddns {
29
32public:
33 NcrMessageError(const char* file, size_t line, const char* what) :
34 isc::Exception(file, line, what) { }
35};
36
40public:
41 DhcidRdataComputeError(const char* file, size_t line, const char* what) :
42 isc::Exception(file, line, what) { }
43};
44
50
58
63
64// DDNS Conflict resolution modes
71
81extern NameChangeFormat stringToNcrFormat(const std::string& fmt_str);
82
89extern std::string ncrFormatToString(NameChangeFormat format);
90
101ConflictResolutionMode StringToConflictResolutionMode(const std::string& mode_str);
102
110
114class D2Dhcid {
115public:
117 D2Dhcid();
118
128 D2Dhcid(const std::string& data);
129
135 D2Dhcid(const isc::dhcp::HWAddrPtr& hwaddr,
136 const std::vector<uint8_t>& wire_fqdn);
137
143 D2Dhcid(const std::vector<uint8_t>& clientid_data,
144 const std::vector<uint8_t>& wire_fqdn);
145
151 D2Dhcid(const isc::dhcp::DUID& duid,
152 const std::vector<uint8_t>& wire_fqdn);
153
157 std::string toStr() const;
158
167 void fromStr(const std::string& data);
168
173 void fromClientId(const std::vector<uint8_t>& clientid_data,
174 const std::vector<uint8_t>& wire_fqdn);
175
184 void fromDUID(const isc::dhcp::DUID& duid,
185 const std::vector<uint8_t>& wire_fqdn);
186
191 void fromHWAddr(const isc::dhcp::HWAddrPtr& hwaddr,
192 const std::vector<uint8_t>& wire_fqdn);
193
197 const std::vector<uint8_t>& getBytes() const {
198 return (bytes_);
199 }
200
202 bool operator==(const D2Dhcid& other) const {
203 return (this->bytes_ == other.bytes_);
204 }
205
207 bool operator!=(const D2Dhcid& other) const {
208 return (this->bytes_ != other.bytes_);
209 }
210
212 bool operator<(const D2Dhcid& other) const {
213 return (this->bytes_ < other.bytes_);
214 }
215
216private:
217
229 void createDigest(const uint8_t identifier_type,
230 const std::vector<uint8_t>& identifier_data,
231 const std::vector<uint8_t>& wire_fqdn);
232
234 std::vector<uint8_t> bytes_;
235};
236
237std::ostream&
238operator<<(std::ostream& os, const D2Dhcid& dhcid);
239
240class NameChangeRequest;
242typedef boost::shared_ptr<NameChangeRequest> NameChangeRequestPtr;
243
245typedef std::map<std::string, isc::data::ConstElementPtr> ElementMap;
246
256public:
267
285 NameChangeRequest(const NameChangeType change_type,
286 const bool forward_change, const bool reverse_change,
287 const std::string& fqdn, const std::string& ip_address,
288 const D2Dhcid& dhcid,
289 const uint32_t lease_length,
291 conflict_resolution_mode = CHECK_WITH_DHCID);
292
315 isc::util::InputBuffer& buffer);
316
335 void toFormat(const NameChangeFormat format,
336 isc::util::OutputBuffer& buffer) const;
337
423 static NameChangeRequestPtr fromJSON(const std::string& json);
424
464
469 std::string toJSON() const;
470
489 void validateContent();
490
493 /// @return the change type
495 return (change_type_);
496 }
497
501 void setChangeType(const NameChangeType value);
502
510
513 /// @return a true if the forward change flag is true.
514 bool isForwardChange() const {
515 return (forward_change_);
516 }
517
522 void setForwardChange(const bool value);
523
532
535 /// @return a true if the reverse change flag is true.
536 bool isReverseChange() const {
537 return (reverse_change_);
538 }
539
544 void setReverseChange(const bool value);
545
554
557 /// @return a string containing the FQDN
558 const std::string& getFqdn() const {
559 return (fqdn_);
560 }
561
564 /// @return a string containing the FQDN lower-cased
565 std::string getFqdnLower() const {
566 return (boost::algorithm::to_lower_copy(fqdn_));
567 }
568
572 void setFqdn(const std::string& value);
573
581
584 /// @return a string containing the IP address
585 std::string getIpAddress() const {
586 return (ip_io_address_.toText());
587 }
589 const asiolink::IOAddress& getIOAddress() const {
590 return (ip_io_address_);
591 }
592
595 /// @return a asiolink::IOAddress containing the IP address
596 const asiolink::IOAddress& getIpIoAddress() const {
597 return (ip_io_address_);
598 }
599
602 /// @return boolean true if the lease address family is AF_INET.
603 bool isV4 () const {
604 return (ip_io_address_.isV4());
605 }
606
609 /// @return boolean true if the lease address family is AF_INET6.
610 bool isV6 () const {
611 return (ip_io_address_.isV6());
612 }
613
617 void setIpAddress(const std::string& value);
618
622 void setIpAddress(const asiolink::IOAddress& value);
623
631
634 /// @return a reference to the request's D2Dhcid
635 const D2Dhcid& getDhcid() const {
636 return (dhcid_);
637 }
638
647 void setDhcid(const std::string& value);
648
657
667 /// @return a string with the request's request ID (currently DHCID)
668 std::string getRequestId() const {
669 return (dhcid_.toStr());
670 }
671
674 /// @return an integer containing the lease length
675 uint32_t getLeaseLength() const {
676 return (lease_length_);
677 }
678
682 void setLeaseLength(const uint32_t value);
683
691
694 /// @return a true if the conflict resolution is enabled.
696 return (conflict_resolution_mode_);
697 }
698
704
712
725
728 /// @return the request status as a NameChangeStatus
730 return (status_);
731 }
732
735 /// @return NameChangeRequestPtr to the next NCR or an empty pointer.
737 return (next_ncr_);
738 }
739
740 /// @brief Fetches the next NCR (if one)
741 void setNextNcr(NameChangeRequestPtr next_ncr) {
742 next_ncr_ = next_ncr;
743 }
744
748 void setStatus(const NameChangeStatus value);
749
759 isc::data::ConstElementPtr getElement(const std::string& name,
760 const ElementMap& element_map) const;
761
766 std::string toText() const;
767
768 bool operator == (const NameChangeRequest& b) const;
769 bool operator != (const NameChangeRequest& b) const;
770
771private:
773 NameChangeType change_type_;
774
776 bool forward_change_;
777
779 bool reverse_change_;
780
785 std::string fqdn_;
786
793 asiolink::IOAddress ip_io_address_;
794
798 D2Dhcid dhcid_;
799
801 uint32_t lease_length_;
802
804 ConflictResolutionMode conflict_resolution_mode_;
805
807 NameChangeStatus status_;
808
810 NameChangeRequestPtr next_ncr_;
811};
812
813} // namespace dhcp_ddns
814} // namespace isc
815
816#endif
This is a base class for exceptions thrown from the DNS library module.
Exception(const char *file, size_t line, const char *what)
Constructor for a given type for exceptions with file name and file line number.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Holds DUID (DHCPv6 Unique Identifier).
Definition duid.h:142
Container class for handling the DHCID value within a NameChangeRequest.
Definition ncr_msg.h:114
bool operator<(const D2Dhcid &other) const
Compares two D2Dhcids lexically.
Definition ncr_msg.h:212
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.
Definition ncr_msg.cc:167
bool operator==(const D2Dhcid &other) const
Compares two D2Dhcids for equality.
Definition ncr_msg.h:202
bool operator!=(const D2Dhcid &other) const
Compares two D2Dhcids for inequality.
Definition ncr_msg.h:207
void fromDUID(const isc::dhcp::DUID &duid, const std::vector< uint8_t > &wire_fqdn)
Sets the DHCID value based on the DUID and FQDN.
Definition ncr_msg.cc:186
const std::vector< uint8_t > & getBytes() const
Returns a reference to the DHCID byte vector.
Definition ncr_msg.h:197
D2Dhcid()
Default constructor.
Definition ncr_msg.cc:98
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.
Definition ncr_msg.cc:136
void fromStr(const std::string &data)
Sets the DHCID value based on the given string.
Definition ncr_msg.cc:121
std::string toStr() const
Returns the DHCID value as a string of hexadecimal digits.
Definition ncr_msg.cc:131
DhcidRdataComputeError(const char *file, size_t line, const char *what)
Definition ncr_msg.h:41
Represents a DHCP-DDNS client request.
Definition ncr_msg.h:255
bool operator==(const NameChangeRequest &b) const
Definition ncr_msg.cc:727
bool operator!=(const NameChangeRequest &b) const
Definition ncr_msg.cc:739
void setStatus(const NameChangeStatus value)
Sets the request status to the given value.
Definition ncr_msg.cc:686
bool isV6() const
Returns true if the lease address is a IPv6 lease.
Definition ncr_msg.h:609
const std::string & getFqdn() const
Fetches the request FQDN.
Definition ncr_msg.h:557
void setChangeType(const NameChangeType value)
Sets the change type to the given value.
Definition ncr_msg.cc:508
std::string toText() const
Returns a text rendition of the contents of the request.
Definition ncr_msg.cc:691
uint32_t getLeaseLength() const
Fetches the request lease length.
Definition ncr_msg.h:674
const asiolink::IOAddress & getIpIoAddress() const
Fetches the request IP address as an IOAddress.
Definition ncr_msg.h:595
void setIpAddress(const std::string &value)
Sets the IP address to the given value.
Definition ncr_msg.cc:594
void translateUseConflictResolution(isc::data::ConstElementPtr element)
Sets the conflict resolution mode based on the value of the given boolean Element.
Definition ncr_msg.cc:656
const D2Dhcid & getDhcid() const
Fetches the request DHCID.
Definition ncr_msg.h:634
NameChangeRequestPtr getNextNcr() const
Fetches the next NCR (if one).
Definition ncr_msg.h:735
void setDhcid(const std::string &value)
Sets the DHCID based on the given string value.
Definition ncr_msg.cc:615
std::string toJSON() const
Instance method for marshalling the contents of the request into a string of JSON text.
Definition ncr_msg.cc:443
ConflictResolutionMode getConflictResolutionMode() const
Fetches the conflict resolution mode.
Definition ncr_msg.h:694
std::string getIpAddress() const
Fetches the request IP address string.
Definition ncr_msg.h:584
void setFqdn(const std::string &value)
Sets the FQDN to the given value.
Definition ncr_msg.cc:582
void setReverseChange(const bool value)
Sets the reverse change flag to the given value.
Definition ncr_msg.cc:556
void setNextNcr(NameChangeRequestPtr next_ncr)
Fetches the next NCR (if one).
Definition ncr_msg.h:740
void setLeaseLength(const uint32_t value)
Sets the lease length to the given value.
Definition ncr_msg.cc:625
const asiolink::IOAddress & getIOAddress() const
Definition ncr_msg.h:588
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...
Definition ncr_msg.cc:334
NameChangeRequest()
Default Constructor.
Definition ncr_msg.cc:257
NameChangeType getChangeType() const
Fetches the request change type.
Definition ncr_msg.h:493
static NameChangeRequestPtr fromJSON(const std::string &json)
Static method for creating a NameChangeRequest from a string containing a JSON rendition of a request...
Definition ncr_msg.cc:358
void setForwardChange(const bool value)
Sets the forward change flag to the given value.
Definition ncr_msg.cc:535
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.
Definition ncr_msg.cc:493
void setConflictResolutionMode(const ConflictResolutionMode value)
Sets the conflict resolution mode to the given value.
Definition ncr_msg.cc:668
std::string getRequestId() const
Fetches the request ID.
Definition ncr_msg.h:667
bool isForwardChange() const
Checks forward change flag.
Definition ncr_msg.h:513
NameChangeStatus getStatus() const
Fetches the request status.
Definition ncr_msg.h:728
bool isV4() const
Returns true if the lease address is a IPv4 lease.
Definition ncr_msg.h:602
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...
Definition ncr_msg.cc:287
void validateContent()
Validates the content of a populated request.
Definition ncr_msg.cc:472
bool isReverseChange() const
Checks reverse change flag.
Definition ncr_msg.h:535
std::string getFqdnLower() const
Fetches the request FQDN lower-cased.
Definition ncr_msg.h:564
NcrMessageError(const char *file, size_t line, const char *what)
Definition ncr_msg.h:33
The InputBuffer class is a buffer abstraction for manipulating read-only data.
Definition buffer.h:81
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition buffer.h:346
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:30
NameChangeFormat
Defines the list of data wire formats supported.
Definition ncr_msg.h:60
NameChangeStatus
Defines the runtime processing status values for requests.
Definition ncr_msg.h:52
@ NO_CHECK_WITHOUT_DHCID
Definition ncr_msg.h:69
@ CHECK_EXISTS_WITH_DHCID
Definition ncr_msg.h:68
@ NO_CHECK_WITH_DHCID
Definition ncr_msg.h:67
std::map< std::string, isc::data::ConstElementPtr > ElementMap
Defines a map of Elements, keyed by their string name.
Definition ncr_msg.h:245
std::ostream & operator<<(std::ostream &os, const D2Dhcid &dhcid)
Definition ncr_msg.cc:251
NameChangeFormat stringToNcrFormat(const std::string &fmt_str)
Function which converts labels to NameChangeFormat enum values.
Definition ncr_msg.cc:24
ConflictResolutionMode StringToConflictResolutionMode(const std::string &mode_str)
Function which converts string to ConflictResolutionMode enum values.
Definition ncr_msg.cc:42
std::string ConflictResolutionModeToString(const ConflictResolutionMode &mode)
Function which converts ConflictResolutionMode enums to text labels.
Definition ncr_msg.cc:63
boost::shared_ptr< NameChangeRequest > NameChangeRequestPtr
Defines a pointer to a NameChangeRequest.
Definition ncr_msg.h:242
std::string ncrFormatToString(NameChangeFormat format)
Function which converts NameChangeFormat enums to text labels.
Definition ncr_msg.cc:32
NameChangeType
Defines the types of DNS updates that can be requested.
Definition ncr_msg.h:46
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
Definition hwaddr.h:154
Defines the logger used by the top-level component of kea-lfc.