Kea 2.2.0
ncr_msg.h
Go to the documentation of this file.
1// Copyright (C) 2013-2021 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
73extern NameChangeFormat stringToNcrFormat(const std::string& fmt_str);
74
81extern std::string ncrFormatToString(NameChangeFormat format);
82
86class D2Dhcid {
87public:
89 D2Dhcid();
90
100 D2Dhcid(const std::string& data);
101
107 D2Dhcid(const isc::dhcp::HWAddrPtr& hwaddr,
108 const std::vector<uint8_t>& wire_fqdn);
109
115 D2Dhcid(const std::vector<uint8_t>& clientid_data,
116 const std::vector<uint8_t>& wire_fqdn);
117
123 D2Dhcid(const isc::dhcp::DUID& duid,
124 const std::vector<uint8_t>& wire_fqdn);
125
129 std::string toStr() const;
130
139 void fromStr(const std::string& data);
140
145 void fromClientId(const std::vector<uint8_t>& clientid_data,
146 const std::vector<uint8_t>& wire_fqdn);
147
156 void fromDUID(const isc::dhcp::DUID& duid,
157 const std::vector<uint8_t>& wire_fqdn);
158
163 void fromHWAddr(const isc::dhcp::HWAddrPtr& hwaddr,
164 const std::vector<uint8_t>& wire_fqdn);
165
169 const std::vector<uint8_t>& getBytes() const {
170 return (bytes_);
171 }
172
174 bool operator==(const D2Dhcid& other) const {
175 return (this->bytes_ == other.bytes_);
176 }
177
179 bool operator!=(const D2Dhcid& other) const {
180 return (this->bytes_ != other.bytes_);
181 }
182
184 bool operator<(const D2Dhcid& other) const {
185 return (this->bytes_ < other.bytes_);
186 }
187
188private:
189
201 void createDigest(const uint8_t identifier_type,
202 const std::vector<uint8_t>& identifier_data,
203 const std::vector<uint8_t>& wire_fqdn);
204
206 std::vector<uint8_t> bytes_;
207};
208
209std::ostream&
210operator<<(std::ostream& os, const D2Dhcid& dhcid);
211
212class NameChangeRequest;
214typedef boost::shared_ptr<NameChangeRequest> NameChangeRequestPtr;
215
217typedef std::map<std::string, isc::data::ConstElementPtr> ElementMap;
218
228public:
239
258 NameChangeRequest(const NameChangeType change_type,
259 const bool forward_change, const bool reverse_change,
260 const std::string& fqdn, const std::string& ip_address,
261 const D2Dhcid& dhcid,
262 const uint64_t lease_expires_on,
263 const uint32_t lease_length,
264 const bool conflict_resolution = true);
265
288 isc::util::InputBuffer& buffer);
289
309 isc::util::OutputBuffer& buffer) const;
310
406 static NameChangeRequestPtr fromJSON(const std::string& json);
407
412 std::string toJSON() const;
413
432 void validateContent();
433
438 return (change_type_);
439 }
440
444 void setChangeType(const NameChangeType value);
445
453
457 bool isForwardChange() const {
458 return (forward_change_);
459 }
460
465 void setForwardChange(const bool value);
466
475
479 bool isReverseChange() const {
480 return (reverse_change_);
481 }
482
487 void setReverseChange(const bool value);
488
497
501 const std::string getFqdn() const {
502 return (fqdn_);
503 }
504
508 void setFqdn(const std::string& value);
509
517
521 std::string getIpAddress() const {
522 return (ip_io_address_.toText());
523 }
524
529 return (ip_io_address_);
530 }
531
535 bool isV4 () const {
536 return (ip_io_address_.isV4());
537 }
538
542 bool isV6 () const {
543 return (ip_io_address_.isV6());
544 }
545
549 void setIpAddress(const std::string& value);
550
558
562 const D2Dhcid& getDhcid() const {
563 return (dhcid_);
564 }
565
574 void setDhcid(const std::string& value);
575
584
595 std::string getRequestId() const {
596 return (dhcid_.toStr());
597 }
598
603 uint64_t getLeaseExpiresOn() const {
604 return (lease_expires_on_);
605 }
606
617 std::string getLeaseExpiresOnStr() const;
618
630 void setLeaseExpiresOn(const std::string& value);
631
639
643 uint32_t getLeaseLength() const {
644 return (lease_length_);
645 }
646
650 void setLeaseLength(const uint32_t value);
651
659
664 return (conflict_resolution_);
665 }
666
671 void setConflictResolution(const bool value);
672
681
686 return (status_);
687 }
688
692 void setStatus(const NameChangeStatus value);
693
703 isc::data::ConstElementPtr getElement(const std::string& name,
704 const ElementMap& element_map) const;
705
710 std::string toText() const;
711
712 bool operator == (const NameChangeRequest& b);
713 bool operator != (const NameChangeRequest& b);
714
715private:
717 NameChangeType change_type_;
718
720 bool forward_change_;
721
723 bool reverse_change_;
724
729 std::string fqdn_;
730
737 asiolink::IOAddress ip_io_address_;
738
742 D2Dhcid dhcid_;
743
745 uint64_t lease_expires_on_;
746
748 uint32_t lease_length_;
749
751 bool conflict_resolution_;
752
754 NameChangeStatus status_;
755};
756
757
758}; // end of isc::dhcp_ddns namespace
759}; // end of isc namespace
760
761#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:27
Container class for handling the DHCID value within a NameChangeRequest.
Definition: ncr_msg.h:86
bool operator<(const D2Dhcid &other) const
Compares two D2Dhcids lexically.
Definition: ncr_msg.h:184
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:131
bool operator==(const D2Dhcid &other) const
Compares two D2Dhcids for equality.
Definition: ncr_msg.h:174
bool operator!=(const D2Dhcid &other) const
Compares two D2Dhcids for inequality.
Definition: ncr_msg.h:179
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:151
const std::vector< uint8_t > & getBytes() const
Returns a reference to the DHCID byte vector.
Definition: ncr_msg.h:169
D2Dhcid()
Default constructor.
Definition: ncr_msg.cc:61
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:100
void fromStr(const std::string &data)
Sets the DHCID value based on the given string.
Definition: ncr_msg.cc:85
std::string toStr() const
Returns the DHCID value as a string of hexadecimal digits.
Definition: ncr_msg.cc:95
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:227
bool useConflictResolution() const
Checks if conflict resolution is enabled.
Definition: ncr_msg.h:663
void setStatus(const NameChangeStatus value)
Sets the request status to the given value.
Definition: ncr_msg.cc:640
bool isV6() const
Returns true if the lease address is a IPv6 lease.
Definition: ncr_msg.h:542
void setChangeType(const NameChangeType value)
Sets the change type to the given value.
Definition: ncr_msg.cc:451
std::string toText() const
Returns a text rendition of the contents of the request.
Definition: ncr_msg.cc:645
uint32_t getLeaseLength() const
Fetches the request lease length.
Definition: ncr_msg.h:643
const asiolink::IOAddress & getIpIoAddress() const
Fetches the request IP address as an IOAddress.
Definition: ncr_msg.h:528
void setIpAddress(const std::string &value)
Sets the IP address to the given value.
Definition: ncr_msg.cc:539
const D2Dhcid & getDhcid() const
Fetches the request DHCID.
Definition: ncr_msg.h:562
void setDhcid(const std::string &value)
Sets the DHCID based on the given string value.
Definition: ncr_msg.cc:556
std::string toJSON() const
Instance method for marshalling the contents of the request into a string of JSON text.
Definition: ncr_msg.cc:391
std::string getIpAddress() const
Fetches the request IP address string.
Definition: ncr_msg.h:521
void setFqdn(const std::string &value)
Sets the FQDN to the given value.
Definition: ncr_msg.cc:527
void setReverseChange(const bool value)
Sets the reverse change flag to the given value.
Definition: ncr_msg.cc:500
bool operator!=(const NameChangeRequest &b)
Definition: ncr_msg.cc:690
void setLeaseLength(const uint32_t value)
Sets the lease length to the given value.
Definition: ncr_msg.cc:588
bool operator==(const NameChangeRequest &b)
Definition: ncr_msg.cc:677
void setLeaseExpiresOn(const std::string &value)
Sets the lease expiration based on the given string.
Definition: ncr_msg.cc:571
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:297
NameChangeRequest()
Default Constructor.
Definition: ncr_msg.cc:225
NameChangeType getChangeType() const
Fetches the request change type.
Definition: ncr_msg.h:437
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:321
void setForwardChange(const bool value)
Sets the forward change flag to the given value.
Definition: ncr_msg.cc:479
std::string getLeaseExpiresOnStr() const
Fetches the request lease expiration as string.
Definition: ncr_msg.cc:566
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:436
uint64_t getLeaseExpiresOn() const
Fetches the request lease expiration.
Definition: ncr_msg.h:603
void setConflictResolution(const bool value)
Sets the conflict resolution flag to the given value.
Definition: ncr_msg.cc:619
std::string getRequestId() const
Fetches the request ID.
Definition: ncr_msg.h:595
bool isForwardChange() const
Checks forward change flag.
Definition: ncr_msg.h:457
NameChangeStatus getStatus() const
Fetches the request status.
Definition: ncr_msg.h:685
bool isV4() const
Returns true if the lease address is a IPv4 lease.
Definition: ncr_msg.h:535
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:257
void validateContent()
Validates the content of a populated request.
Definition: ncr_msg.cc:415
const std::string getFqdn() const
Fetches the request FQDN.
Definition: ncr_msg.h:501
bool isReverseChange() const
Checks reverse change flag.
Definition: ncr_msg.h:479
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:27
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
std::map< std::string, isc::data::ConstElementPtr > ElementMap
Defines a map of Elements, keyed by their string name.
Definition: ncr_msg.h:217
std::ostream & operator<<(std::ostream &os, const D2Dhcid &dhcid)
Definition: ncr_msg.cc:216
NameChangeFormat stringToNcrFormat(const std::string &fmt_str)
Function which converts labels to NameChangeFormat enum values.
Definition: ncr_msg.cc:26
boost::shared_ptr< NameChangeRequest > NameChangeRequestPtr
Defines a pointer to a NameChangeRequest.
Definition: ncr_msg.h:212
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.