Kea 2.7.0
ncr_msg.h
Go to the documentation of this file.
1// Copyright (C) 2013-2024 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 <time.h>
24#include <string>
25
26namespace isc {
27namespace dhcp_ddns {
28
31public:
32 NcrMessageError(const char* file, size_t line, const char* what) :
33 isc::Exception(file, line, what) { };
34};
35
39public:
40 DhcidRdataComputeError(const char* file, size_t line, const char* what) :
41 isc::Exception(file, line, what) { };
42};
43
49
57
62
63// DDNS Conflict resolution modes
70
80extern NameChangeFormat stringToNcrFormat(const std::string& fmt_str);
81
88extern std::string ncrFormatToString(NameChangeFormat format);
89
100ConflictResolutionMode StringToConflictResolutionMode(const std::string& mode_str);
101
109
113class D2Dhcid {
114public:
116 D2Dhcid();
117
127 D2Dhcid(const std::string& data);
128
134 D2Dhcid(const isc::dhcp::HWAddrPtr& hwaddr,
135 const std::vector<uint8_t>& wire_fqdn);
136
142 D2Dhcid(const std::vector<uint8_t>& clientid_data,
143 const std::vector<uint8_t>& wire_fqdn);
144
150 D2Dhcid(const isc::dhcp::DUID& duid,
151 const std::vector<uint8_t>& wire_fqdn);
152
156 std::string toStr() const;
157
166 void fromStr(const std::string& data);
167
172 void fromClientId(const std::vector<uint8_t>& clientid_data,
173 const std::vector<uint8_t>& wire_fqdn);
174
183 void fromDUID(const isc::dhcp::DUID& duid,
184 const std::vector<uint8_t>& wire_fqdn);
185
190 void fromHWAddr(const isc::dhcp::HWAddrPtr& hwaddr,
191 const std::vector<uint8_t>& wire_fqdn);
192
196 const std::vector<uint8_t>& getBytes() const {
197 return (bytes_);
198 }
199
201 bool operator==(const D2Dhcid& other) const {
202 return (this->bytes_ == other.bytes_);
203 }
204
206 bool operator!=(const D2Dhcid& other) const {
207 return (this->bytes_ != other.bytes_);
208 }
209
211 bool operator<(const D2Dhcid& other) const {
212 return (this->bytes_ < other.bytes_);
213 }
214
215private:
216
228 void createDigest(const uint8_t identifier_type,
229 const std::vector<uint8_t>& identifier_data,
230 const std::vector<uint8_t>& wire_fqdn);
231
233 std::vector<uint8_t> bytes_;
234};
235
236std::ostream&
237operator<<(std::ostream& os, const D2Dhcid& dhcid);
238
239class NameChangeRequest;
241typedef boost::shared_ptr<NameChangeRequest> NameChangeRequestPtr;
242
244typedef std::map<std::string, isc::data::ConstElementPtr> ElementMap;
245
255public:
266
286 NameChangeRequest(const NameChangeType change_type,
287 const bool forward_change, const bool reverse_change,
288 const std::string& fqdn, const std::string& ip_address,
289 const D2Dhcid& dhcid,
290 const uint64_t lease_expires_on,
291 const uint32_t lease_length,
293 conflict_resolution_mode = CHECK_WITH_DHCID);
294
317 isc::util::InputBuffer& buffer);
318
337 void toFormat(const NameChangeFormat format,
338 isc::util::OutputBuffer& buffer) const;
339
435 static NameChangeRequestPtr fromJSON(const std::string& json);
436
441 std::string toJSON() const;
442
461 void validateContent();
462
467 return (change_type_);
468 }
469
473 void setChangeType(const NameChangeType value);
474
482
486 bool isForwardChange() const {
487 return (forward_change_);
488 }
489
494 void setForwardChange(const bool value);
495
504
508 bool isReverseChange() const {
509 return (reverse_change_);
510 }
511
516 void setReverseChange(const bool value);
517
526
530 const std::string getFqdn() const {
531 return (fqdn_);
532 }
533
537 void setFqdn(const std::string& value);
538
546
550 std::string getIpAddress() const {
551 return (ip_io_address_.toText());
552 }
553
557 const asiolink::IOAddress& getIpIoAddress() const {
558 return (ip_io_address_);
559 }
560
564 bool isV4 () const {
565 return (ip_io_address_.isV4());
566 }
567
571 bool isV6 () const {
572 return (ip_io_address_.isV6());
573 }
574
578 void setIpAddress(const std::string& value);
579
587
591 const D2Dhcid& getDhcid() const {
592 return (dhcid_);
593 }
594
603 void setDhcid(const std::string& value);
604
613
624 std::string getRequestId() const {
625 return (dhcid_.toStr());
626 }
627
632 uint64_t getLeaseExpiresOn() const {
633 return (lease_expires_on_);
634 }
635
646 std::string getLeaseExpiresOnStr() const;
647
659 void setLeaseExpiresOn(const std::string& value);
660
668
672 uint32_t getLeaseLength() const {
673 return (lease_length_);
674 }
675
679 void setLeaseLength(const uint32_t value);
680
688
693 return (conflict_resolution_mode_);
694 }
695
701
709
722
727 return (status_);
728 }
729
733 void setStatus(const NameChangeStatus value);
734
744 isc::data::ConstElementPtr getElement(const std::string& name,
745 const ElementMap& element_map) const;
746
751 std::string toText() const;
752
753 bool operator == (const NameChangeRequest& b) const;
754 bool operator != (const NameChangeRequest& b) const;
755
756private:
758 NameChangeType change_type_;
759
761 bool forward_change_;
762
764 bool reverse_change_;
765
770 std::string fqdn_;
771
778 asiolink::IOAddress ip_io_address_;
779
783 D2Dhcid dhcid_;
784
786 uint64_t lease_expires_on_;
787
789 uint32_t lease_length_;
790
792 ConflictResolutionMode conflict_resolution_mode_;
793
795 NameChangeStatus status_;
796};
797
798
799}; // end of isc::dhcp_ddns namespace
800}; // end of isc namespace
801
802#endif
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.
Holds DUID (DHCPv6 Unique Identifier)
Definition duid.h:142
Container class for handling the DHCID value within a NameChangeRequest.
Definition ncr_msg.h:113
bool operator<(const D2Dhcid &other) const
Compares two D2Dhcids lexically.
Definition ncr_msg.h:211
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:171
bool operator==(const D2Dhcid &other) const
Compares two D2Dhcids for equality.
Definition ncr_msg.h:201
bool operator!=(const D2Dhcid &other) const
Compares two D2Dhcids for inequality.
Definition ncr_msg.h:206
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:191
const std::vector< uint8_t > & getBytes() const
Returns a reference to the DHCID byte vector.
Definition ncr_msg.h:196
D2Dhcid()
Default constructor.
Definition ncr_msg.cc:101
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:140
void fromStr(const std::string &data)
Sets the DHCID value based on the given string.
Definition ncr_msg.cc:125
std::string toStr() const
Returns the DHCID value as a string of hexadecimal digits.
Definition ncr_msg.cc:135
Exception thrown when there is an error occurred during computation of the DHCID.
Definition ncr_msg.h:38
DhcidRdataComputeError(const char *file, size_t line, const char *what)
Definition ncr_msg.h:40
Represents a DHCP-DDNS client request.
Definition ncr_msg.h:254
bool operator==(const NameChangeRequest &b) const
Definition ncr_msg.cc:736
bool operator!=(const NameChangeRequest &b) const
Definition ncr_msg.cc:749
void setStatus(const NameChangeStatus value)
Sets the request status to the given value.
Definition ncr_msg.cc:698
bool isV6() const
Returns true if the lease address is a IPv6 lease.
Definition ncr_msg.h:570
void setChangeType(const NameChangeType value)
Sets the change type to the given value.
Definition ncr_msg.cc:500
std::string toText() const
Returns a text rendition of the contents of the request.
Definition ncr_msg.cc:703
uint32_t getLeaseLength() const
Fetches the request lease length.
Definition ncr_msg.h:671
const asiolink::IOAddress & getIpIoAddress() const
Fetches the request IP address as an IOAddress.
Definition ncr_msg.h:556
void setIpAddress(const std::string &value)
Sets the IP address to the given value.
Definition ncr_msg.cc:588
void translateUseConflictResolution(isc::data::ConstElementPtr element)
Sets the conflict resolution mode based on the value of the given boolean Element.
Definition ncr_msg.cc:668
const D2Dhcid & getDhcid() const
Fetches the request DHCID.
Definition ncr_msg.h:590
void setDhcid(const std::string &value)
Sets the DHCID based on the given string value.
Definition ncr_msg.cc:605
std::string toJSON() const
Instance method for marshalling the contents of the request into a string of JSON text.
Definition ncr_msg.cc:439
ConflictResolutionMode getConflictResolutionMode() const
Fetches the conflict resolution mode.
Definition ncr_msg.h:691
std::string getIpAddress() const
Fetches the request IP address string.
Definition ncr_msg.h:549
void setFqdn(const std::string &value)
Sets the FQDN to the given value.
Definition ncr_msg.cc:576
void setReverseChange(const bool value)
Sets the reverse change flag to the given value.
Definition ncr_msg.cc:549
void setLeaseLength(const uint32_t value)
Sets the lease length to the given value.
Definition ncr_msg.cc:637
void setLeaseExpiresOn(const std::string &value)
Sets the lease expiration based on the given string.
Definition ncr_msg.cc:620
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:265
NameChangeType getChangeType() const
Fetches the request change type.
Definition ncr_msg.h:465
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:528
std::string getLeaseExpiresOnStr() const
Fetches the request lease expiration as string.
Definition ncr_msg.cc:615
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:485
uint64_t getLeaseExpiresOn() const
Fetches the request lease expiration.
Definition ncr_msg.h:631
void setConflictResolutionMode(const ConflictResolutionMode value)
Sets the conflict resolution mode to the given value.
Definition ncr_msg.cc:680
std::string getRequestId() const
Fetches the request ID.
Definition ncr_msg.h:623
bool isForwardChange() const
Checks forward change flag.
Definition ncr_msg.h:485
NameChangeStatus getStatus() const
Fetches the request status.
Definition ncr_msg.h:725
bool isV4() const
Returns true if the lease address is a IPv4 lease.
Definition ncr_msg.h:563
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:299
void validateContent()
Validates the content of a populated request.
Definition ncr_msg.cc:464
const std::string getFqdn() const
Fetches the request FQDN.
Definition ncr_msg.h:529
bool isReverseChange() const
Checks reverse change flag.
Definition ncr_msg.h:507
Exception thrown when NameChangeRequest marshalling error occurs.
Definition ncr_msg.h:30
NcrMessageError(const char *file, size_t line, const char *what)
Definition ncr_msg.h:32
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:343
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
NameChangeFormat
Defines the list of data wire formats supported.
Definition ncr_msg.h:59
NameChangeStatus
Defines the runtime processing status values for requests.
Definition ncr_msg.h:51
@ NO_CHECK_WITHOUT_DHCID
Definition ncr_msg.h:68
@ CHECK_EXISTS_WITH_DHCID
Definition ncr_msg.h:67
@ NO_CHECK_WITH_DHCID
Definition ncr_msg.h:66
std::map< std::string, isc::data::ConstElementPtr > ElementMap
Defines a map of Elements, keyed by their string name.
Definition ncr_msg.h:244
std::ostream & operator<<(std::ostream &os, const D2Dhcid &dhcid)
Definition ncr_msg.cc:256
NameChangeFormat stringToNcrFormat(const std::string &fmt_str)
Function which converts labels to NameChangeFormat enum values.
Definition ncr_msg.cc:26
ConflictResolutionMode StringToConflictResolutionMode(const std::string &mode_str)
Function which converts string to ConflictResolutionMode enum values.
Definition ncr_msg.cc:45
std::string ConflictResolutionModeToString(const ConflictResolutionMode &mode)
Function which converts ConflictResolutionMode enums to text labels.
Definition ncr_msg.cc:66
boost::shared_ptr< NameChangeRequest > NameChangeRequestPtr
Defines a pointer to a NameChangeRequest.
Definition ncr_msg.h:241
std::string ncrFormatToString(NameChangeFormat format)
Function which converts NameChangeFormat enums to text labels.
Definition ncr_msg.cc:35
NameChangeType
Defines the types of DNS updates that can be requested.
Definition ncr_msg.h:45
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.