Kea 2.5.5
ncr_msg.h
Go to the documentation of this file.
1// Copyright (C) 2013-2023 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>
20#include <util/buffer.h>
21#include <util/time_utilities.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
44
49};
50
57};
58
62};
63
64// DDNS Conflict resolution modes
70};
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
287 NameChangeRequest(const NameChangeType change_type,
288 const bool forward_change, const bool reverse_change,
289 const std::string& fqdn, const std::string& ip_address,
290 const D2Dhcid& dhcid,
291 const uint64_t lease_expires_on,
292 const uint32_t lease_length,
294 conflict_resolution_mode = CHECK_WITH_DHCID);
295
318 isc::util::InputBuffer& buffer);
319
339 isc::util::OutputBuffer& buffer) const;
340
436 static NameChangeRequestPtr fromJSON(const std::string& json);
437
442 std::string toJSON() const;
443
462 void validateContent();
463
468 return (change_type_);
469 }
470
474 void setChangeType(const NameChangeType value);
475
483
487 bool isForwardChange() const {
488 return (forward_change_);
489 }
490
495 void setForwardChange(const bool value);
496
505
509 bool isReverseChange() const {
510 return (reverse_change_);
511 }
512
517 void setReverseChange(const bool value);
518
527
531 const std::string getFqdn() const {
532 return (fqdn_);
533 }
534
538 void setFqdn(const std::string& value);
539
547
551 std::string getIpAddress() const {
552 return (ip_io_address_.toText());
553 }
554
559 return (ip_io_address_);
560 }
561
565 bool isV4 () const {
566 return (ip_io_address_.isV4());
567 }
568
572 bool isV6 () const {
573 return (ip_io_address_.isV6());
574 }
575
579 void setIpAddress(const std::string& value);
580
588
592 const D2Dhcid& getDhcid() const {
593 return (dhcid_);
594 }
595
604 void setDhcid(const std::string& value);
605
614
625 std::string getRequestId() const {
626 return (dhcid_.toStr());
627 }
628
633 uint64_t getLeaseExpiresOn() const {
634 return (lease_expires_on_);
635 }
636
647 std::string getLeaseExpiresOnStr() const;
648
660 void setLeaseExpiresOn(const std::string& value);
661
669
673 uint32_t getLeaseLength() const {
674 return (lease_length_);
675 }
676
680 void setLeaseLength(const uint32_t value);
681
689
694 return (conflict_resolution_mode_);
695 }
696
702
710
723
728 return (status_);
729 }
730
734 void setStatus(const NameChangeStatus value);
735
745 isc::data::ConstElementPtr getElement(const std::string& name,
746 const ElementMap& element_map) const;
747
752 std::string toText() const;
753
754 bool operator == (const NameChangeRequest& b) const;
755 bool operator != (const NameChangeRequest& b) const;
756
757private:
759 NameChangeType change_type_;
760
762 bool forward_change_;
763
765 bool reverse_change_;
766
771 std::string fqdn_;
772
779 asiolink::IOAddress ip_io_address_;
780
784 D2Dhcid dhcid_;
785
787 uint64_t lease_expires_on_;
788
790 uint32_t lease_length_;
791
793 ConflictResolutionMode conflict_resolution_mode_;
794
796 NameChangeStatus status_;
797};
798
799
800}; // end of isc::dhcp_ddns namespace
801}; // end of isc namespace
802
803#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:138
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:171
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:191
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: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:255
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:572
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:673
const asiolink::IOAddress & getIpIoAddress() const
Fetches the request IP address as an IOAddress.
Definition: ncr_msg.h:558
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:592
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:693
std::string getIpAddress() const
Fetches the request IP address string.
Definition: ncr_msg.h:551
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:467
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:633
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:625
bool isForwardChange() const
Checks forward change flag.
Definition: ncr_msg.h:487
NameChangeStatus getStatus() const
Fetches the request status.
Definition: ncr_msg.h:727
bool isV4() const
Returns true if the lease address is a IPv4 lease.
Definition: ncr_msg.h:565
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:531
bool isReverseChange() const
Checks reverse change flag.
Definition: ncr_msg.h:509
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:294
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:29
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
ConflictResolutionMode
Definition: ncr_msg.h:65
@ CHECK_WITH_DHCID
Definition: ncr_msg.h:66
@ 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: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:242
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:46
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
Definition: hwaddr.h:154
std::string format(const std::string &format, const std::vector< std::string > &args)
Apply Formatting.
Definition: strutil.cc:157
Defines the logger used by the top-level component of kea-lfc.