Kea 3.3.4
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 <cstdint>
24#include <string>
25
26#include <boost/algorithm/string/case_conv.hpp>
27
28#include <time.h>
29
30namespace isc {
31namespace dhcp_ddns {
32
35public:
36 NcrMessageError(const char* file, size_t line, const char* what) :
37 isc::Exception(file, line, what) { }
38};
39
43public:
44 DhcidRdataComputeError(const char* file, size_t line, const char* what) :
45 isc::Exception(file, line, what) { }
46};
47
49enum NameChangeType : uint16_t {
52};
53
61
63enum NameChangeFormat : uint16_t {
65};
66
67// DDNS Conflict resolution modes
74
84extern NameChangeFormat stringToNcrFormat(const std::string& fmt_str);
85
92extern std::string ncrFormatToString(NameChangeFormat format);
93
104ConflictResolutionMode StringToConflictResolutionMode(const std::string& mode_str);
105
113
117class D2Dhcid {
118public:
120 D2Dhcid();
121
131 D2Dhcid(const std::string& data);
132
138 D2Dhcid(const isc::dhcp::HWAddrPtr& hwaddr,
139 const std::vector<uint8_t>& wire_fqdn);
140
146 D2Dhcid(const std::vector<uint8_t>& clientid_data,
147 const std::vector<uint8_t>& wire_fqdn);
148
154 D2Dhcid(const isc::dhcp::DUID& duid,
155 const std::vector<uint8_t>& wire_fqdn);
156
160 std::string toStr() const;
161
170 void fromStr(const std::string& data);
171
176 void fromClientId(const std::vector<uint8_t>& clientid_data,
177 const std::vector<uint8_t>& wire_fqdn);
178
187 void fromDUID(const isc::dhcp::DUID& duid,
188 const std::vector<uint8_t>& wire_fqdn);
189
194 void fromHWAddr(const isc::dhcp::HWAddrPtr& hwaddr,
195 const std::vector<uint8_t>& wire_fqdn);
196
200 const std::vector<uint8_t>& getBytes() const {
201 return (bytes_);
202 }
203
205 bool operator==(const D2Dhcid& other) const {
206 return (this->bytes_ == other.bytes_);
207 }
208
210 bool operator!=(const D2Dhcid& other) const {
211 return (this->bytes_ != other.bytes_);
212 }
213
215 bool operator<(const D2Dhcid& other) const {
216 return (this->bytes_ < other.bytes_);
217 }
218
219private:
220
232 void createDigest(const uint8_t identifier_type,
233 const std::vector<uint8_t>& identifier_data,
234 const std::vector<uint8_t>& wire_fqdn);
235
237 std::vector<uint8_t> bytes_;
238};
239
240std::ostream&
241operator<<(std::ostream& os, const D2Dhcid& dhcid);
242
243class NameChangeRequest;
245typedef boost::shared_ptr<NameChangeRequest> NameChangeRequestPtr;
246
248typedef std::map<std::string, isc::data::ConstElementPtr> ElementMap;
249
259public:
270
289 NameChangeRequest(const NameChangeType change_type,
290 const bool forward_change, const bool reverse_change,
291 const std::string& fqdn, const std::string& ip_address,
292 const D2Dhcid& dhcid,
293 const uint32_t lease_length,
295 conflict_resolution_mode = CHECK_WITH_DHCID,
296 const std::string& reverse_zone = "");
297
320 isc::util::InputBuffer& buffer);
321
340 void toFormat(const NameChangeFormat format,
341 isc::util::OutputBuffer& buffer) const;
342
433 static NameChangeRequestPtr fromJSON(const std::string& json);
434
474
479 std::string toJSON() const;
480
499 void validateContent();
500
503 /// @return the change type
505 return (change_type_);
506 }
507
511 void setChangeType(const NameChangeType value);
512
520
523 /// @return a true if the forward change flag is true.
524 bool isForwardChange() const {
525 return (forward_change_);
526 }
527
532 void setForwardChange(const bool value);
533
542
545 /// @return a true if the reverse change flag is true.
546 bool isReverseChange() const {
547 return (reverse_change_);
548 }
549
554 void setReverseChange(const bool value);
555
564
567 /// @return a string containing the FQDN
568 const std::string& getFqdn() const {
569 return (fqdn_);
570 }
571
574 /// @return a string containing the FQDN lower-cased
575 std::string getFqdnLower() const {
576 return (boost::algorithm::to_lower_copy(fqdn_));
577 }
578
582 void setFqdn(const std::string& value);
583
591
594 /// @return a string containing the IP address
595 std::string getIpAddress() const {
596 return (ip_io_address_.toText());
597 }
599 const asiolink::IOAddress& getIOAddress() const {
600 return (ip_io_address_);
601 }
602
605 /// @return a asiolink::IOAddress containing the IP address
606 const asiolink::IOAddress& getIpIoAddress() const {
607 return (ip_io_address_);
608 }
609
612 /// @return boolean true if the lease address family is AF_INET.
613 bool isV4 () const {
614 return (ip_io_address_.isV4());
615 }
616
619 /// @return boolean true if the lease address family is AF_INET6.
620 bool isV6 () const {
621 return (ip_io_address_.isV6());
622 }
623
627 void setIpAddress(const std::string& value);
628
632 void setIpAddress(const asiolink::IOAddress& value);
633
641
644 /// @return a reference to the request's D2Dhcid
645 const D2Dhcid& getDhcid() const {
646 return (dhcid_);
647 }
648
657 void setDhcid(const std::string& value);
658
667
677 /// @return a string with the request's request ID (currently DHCID)
678 std::string getRequestId() const {
679 return (dhcid_.toStr());
680 }
681
684 /// @return an integer containing the lease length
685 uint32_t getLeaseLength() const {
686 return (lease_length_);
687 }
688
692 void setLeaseLength(const uint32_t value);
693
701
704 /// @return a true if the conflict resolution is enabled.
706 return (conflict_resolution_mode_);
707 }
708
714
722
735
738 /// @return the request status as a NameChangeStatus
740 return (status_);
741 }
742
745 /// @return NameChangeRequestPtr to the next NCR or an empty pointer.
747 return (next_ncr_);
748 }
749
750 /// @brief Fetches the next NCR (if one)
751 void setNextNcr(NameChangeRequestPtr next_ncr) {
752 next_ncr_ = next_ncr;
753 }
754
757 /// @return a string containing the reverse zone
758 const std::string getReverseZone() const {
759 return (reverse_zone_);
760 }
761
765 void setReverseZone(const std::string& value);
766
774
778 void setStatus(const NameChangeStatus value);
779
789 isc::data::ConstElementPtr getElement(const std::string& name,
790 const ElementMap& element_map) const;
791
796 std::string toText() const;
797
798 bool operator == (const NameChangeRequest& b) const;
799 bool operator != (const NameChangeRequest& b) const;
800
801private:
803 NameChangeType change_type_;
804
806 bool forward_change_;
807
809 bool reverse_change_;
810
815 std::string fqdn_;
816
823 asiolink::IOAddress ip_io_address_;
824
828 D2Dhcid dhcid_;
829
831 uint32_t lease_length_;
832
834 ConflictResolutionMode conflict_resolution_mode_;
835
837 NameChangeStatus status_;
838
840 NameChangeRequestPtr next_ncr_;
841
845 std::string reverse_zone_;
846};
847
848} // namespace dhcp_ddns
849} // namespace isc
850
851#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:117
bool operator<(const D2Dhcid &other) const
Compares two D2Dhcids lexically.
Definition ncr_msg.h:215
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:205
bool operator!=(const D2Dhcid &other) const
Compares two D2Dhcids for inequality.
Definition ncr_msg.h:210
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:200
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:44
Represents a DHCP-DDNS client request.
Definition ncr_msg.h:258
bool operator==(const NameChangeRequest &b) const
Definition ncr_msg.cc:768
bool operator!=(const NameChangeRequest &b) const
Definition ncr_msg.cc:781
const std::string getReverseZone() const
Fetches the request reverse zone.
Definition ncr_msg.h:757
void setStatus(const NameChangeStatus value)
Sets the request status to the given value.
Definition ncr_msg.cc:723
bool isV6() const
Returns true if the lease address is a IPv6 lease.
Definition ncr_msg.h:619
const std::string & getFqdn() const
Fetches the request FQDN.
Definition ncr_msg.h:567
void setChangeType(const NameChangeType value)
Sets the change type to the given value.
Definition ncr_msg.cc:523
std::string toText() const
Returns a text rendition of the contents of the request.
Definition ncr_msg.cc:728
uint32_t getLeaseLength() const
Fetches the request lease length.
Definition ncr_msg.h:684
const asiolink::IOAddress & getIpIoAddress() const
Fetches the request IP address as an IOAddress.
Definition ncr_msg.h:605
void setIpAddress(const std::string &value)
Sets the IP address to the given value.
Definition ncr_msg.cc:609
void translateUseConflictResolution(isc::data::ConstElementPtr element)
Sets the conflict resolution mode based on the value of the given boolean Element.
Definition ncr_msg.cc:671
const D2Dhcid & getDhcid() const
Fetches the request DHCID.
Definition ncr_msg.h:644
NameChangeRequestPtr getNextNcr() const
Fetches the next NCR (if one).
Definition ncr_msg.h:745
void setDhcid(const std::string &value)
Sets the DHCID based on the given string value.
Definition ncr_msg.cc:630
std::string toJSON() const
Instance method for marshalling the contents of the request into a string of JSON text.
Definition ncr_msg.cc:454
ConflictResolutionMode getConflictResolutionMode() const
Fetches the conflict resolution mode.
Definition ncr_msg.h:704
std::string getIpAddress() const
Fetches the request IP address string.
Definition ncr_msg.h:594
void setFqdn(const std::string &value)
Sets the FQDN to the given value.
Definition ncr_msg.cc:597
void setReverseZone(const std::string &value)
Sets the reverse zone override to the given value.
Definition ncr_msg.cc:706
void setReverseChange(const bool value)
Sets the reverse change flag to the given value.
Definition ncr_msg.cc:571
void setNextNcr(NameChangeRequestPtr next_ncr)
Fetches the next NCR (if one).
Definition ncr_msg.h:750
void setLeaseLength(const uint32_t value)
Sets the lease length to the given value.
Definition ncr_msg.cc:640
const asiolink::IOAddress & getIOAddress() const
Definition ncr_msg.h:598
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:339
NameChangeRequest()
Default Constructor.
Definition ncr_msg.cc:257
NameChangeType getChangeType() const
Fetches the request change type.
Definition ncr_msg.h:503
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:363
void setForwardChange(const bool value)
Sets the forward change flag to the given value.
Definition ncr_msg.cc:550
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:508
void setConflictResolutionMode(const ConflictResolutionMode value)
Sets the conflict resolution mode to the given value.
Definition ncr_msg.cc:683
std::string getRequestId() const
Fetches the request ID.
Definition ncr_msg.h:677
bool isForwardChange() const
Checks forward change flag.
Definition ncr_msg.h:523
NameChangeStatus getStatus() const
Fetches the request status.
Definition ncr_msg.h:738
bool isV4() const
Returns true if the lease address is a IPv4 lease.
Definition ncr_msg.h:612
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:292
void validateContent()
Validates the content of a populated request.
Definition ncr_msg.cc:487
bool isReverseChange() const
Checks reverse change flag.
Definition ncr_msg.h:545
std::string getFqdnLower() const
Fetches the request FQDN lower-cased.
Definition ncr_msg.h:574
NcrMessageError(const char *file, size_t line, const char *what)
Definition ncr_msg.h:36
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:355
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:30
NameChangeFormat
Defines the list of data wire formats supported.
Definition ncr_msg.h:63
NameChangeStatus
Defines the runtime processing status values for requests.
Definition ncr_msg.h:55
NameChangeType
Defines the types of DNS updates that can be requested.
Definition ncr_msg.h:49
@ NO_CHECK_WITHOUT_DHCID
Definition ncr_msg.h:72
@ CHECK_EXISTS_WITH_DHCID
Definition ncr_msg.h:71
@ NO_CHECK_WITH_DHCID
Definition ncr_msg.h:70
std::map< std::string, isc::data::ConstElementPtr > ElementMap
Defines a map of Elements, keyed by their string name.
Definition ncr_msg.h:248
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:245
std::string ncrFormatToString(NameChangeFormat format)
Function which converts NameChangeFormat enums to text labels.
Definition ncr_msg.cc:32
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
Definition hwaddr.h:166
Defines the logger used by the top-level component of kea-lfc.