Kea  2.1.7-git
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>
19 #include <exceptions/exceptions.h>
20 #include <util/buffer.h>
21 #include <util/time_utilities.h>
22 
23 #include <time.h>
24 #include <string>
25 
26 namespace isc {
27 namespace dhcp_ddns {
28 
31 public:
32  NcrMessageError(const char* file, size_t line, const char* what) :
33  isc::Exception(file, line, what) { };
34 };
35 
39 public:
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 
73 extern NameChangeFormat stringToNcrFormat(const std::string& fmt_str);
74 
81 extern std::string ncrFormatToString(NameChangeFormat format);
82 
86 class D2Dhcid {
87 public:
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 
188 private:
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 
209 std::ostream&
210 operator<<(std::ostream& os, const D2Dhcid& dhcid);
211 
214 typedef boost::shared_ptr<NameChangeRequest> NameChangeRequestPtr;
215 
217 typedef std::map<std::string, isc::data::ConstElementPtr> ElementMap;
218 
228 public:
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 
287  static NameChangeRequestPtr fromFormat(const NameChangeFormat format,
288  isc::util::InputBuffer& buffer);
289 
308  void toFormat(const NameChangeFormat format,
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 
452  void setChangeType(isc::data::ConstElementPtr element);
453 
457  bool isForwardChange() const {
458  return (forward_change_);
459  }
460 
465  void setForwardChange(const bool value);
466 
474  void setForwardChange(isc::data::ConstElementPtr element);
475 
479  bool isReverseChange() const {
480  return (reverse_change_);
481  }
482 
487  void setReverseChange(const bool value);
488 
496  void setReverseChange(isc::data::ConstElementPtr element);
497 
501  const std::string getFqdn() const {
502  return (fqdn_);
503  }
504 
508  void setFqdn(const std::string& value);
509 
516  void setFqdn(isc::data::ConstElementPtr element);
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 
557  void setIpAddress(isc::data::ConstElementPtr element);
558 
562  const D2Dhcid& getDhcid() const {
563  return (dhcid_);
564  }
565 
574  void setDhcid(const std::string& value);
575 
583  void setDhcid(isc::data::ConstElementPtr element);
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 
638  void setLeaseExpiresOn(isc::data::ConstElementPtr element);
639 
643  uint32_t getLeaseLength() const {
644  return (lease_length_);
645  }
646 
650  void setLeaseLength(const uint32_t value);
651 
658  void setLeaseLength(isc::data::ConstElementPtr element);
659 
663  bool useConflictResolution() const {
664  return (conflict_resolution_);
665  }
666 
671  void setConflictResolution(const bool value);
672 
680  void setConflictResolution(isc::data::ConstElementPtr element);
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 
715 private:
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
std::map< std::string, isc::data::ConstElementPtr > ElementMap
Defines a map of Elements, keyed by their string name.
Definition: ncr_msg.h:217
const std::vector< uint8_t > & getBytes() const
Returns a reference to the DHCID byte vector.
Definition: ncr_msg.h:169
bool operator<(const D2Dhcid &other) const
Compares two D2Dhcids lexically.
Definition: ncr_msg.h:184
NameChangeType
Defines the types of DNS updates that can be requested.
Definition: ncr_msg.h:46
bool isV4() const
Returns true if the lease address is a IPv4 lease.
Definition: ncr_msg.h:535
const asiolink::IOAddress & getIpIoAddress() const
Fetches the request IP address as an IOAddress.
Definition: ncr_msg.h:528
bool isForwardChange() const
Checks forward change flag.
Definition: ncr_msg.h:457
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
Definition: hwaddr.h:154
bool operator!=(const Element &a, const Element &b)
Definition: data.cc:214
NameChangeType getChangeType() const
Fetches the request change type.
Definition: ncr_msg.h:437
NameChangeFormat
Defines the list of data wire formats supported.
Definition: ncr_msg.h:60
boost::shared_ptr< NameChangeRequest > NameChangeRequestPtr
Defines a pointer to a NameChangeRequest.
Definition: ncr_msg.h:212
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
bool operator==(const Element &a, const Element &b)
Definition: data.cc:210
bool isReverseChange() const
Checks reverse change flag.
Definition: ncr_msg.h:479
Exception thrown when NameChangeRequest marshalling error occurs.
Definition: ncr_msg.h:30
bool operator==(const D2Dhcid &other) const
Compares two D2Dhcids for equality.
Definition: ncr_msg.h:174
Exception thrown when there is an error occurred during computation of the DHCID. ...
Definition: ncr_msg.h:38
NameChangeStatus
Defines the runtime processing status values for requests.
Definition: ncr_msg.h:52
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:27
bool operator!=(const D2Dhcid &other) const
Compares two D2Dhcids for inequality.
Definition: ncr_msg.h:179
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition: buffer.h:294
std::string getIpAddress() const
Fetches the request IP address string.
Definition: ncr_msg.h:521
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-lfc.
std::ostream & operator<<(std::ostream &os, const D2Dhcid &dhcid)
Definition: ncr_msg.cc:216
std::string ncrFormatToString(NameChangeFormat format)
Function which converts NameChangeFormat enums to text labels.
Definition: ncr_msg.cc:35
DhcidRdataComputeError(const char *file, size_t line, const char *what)
Definition: ncr_msg.h:40
bool useConflictResolution() const
Checks if conflict resolution is enabled.
Definition: ncr_msg.h:663
Container class for handling the DHCID value within a NameChangeRequest.
Definition: ncr_msg.h:86
NameChangeStatus getStatus() const
Fetches the request status.
Definition: ncr_msg.h:685
std::string getRequestId() const
Fetches the request ID.
Definition: ncr_msg.h:595
The InputBuffer class is a buffer abstraction for manipulating read-only data.
Definition: buffer.h:81
NameChangeFormat stringToNcrFormat(const std::string &fmt_str)
Function which converts labels to NameChangeFormat enum values.
Definition: ncr_msg.cc:26
uint32_t getLeaseLength() const
Fetches the request lease length.
Definition: ncr_msg.h:643
const std::string getFqdn() const
Fetches the request FQDN.
Definition: ncr_msg.h:501
bool isV6() const
Returns true if the lease address is a IPv6 lease.
Definition: ncr_msg.h:542
const D2Dhcid & getDhcid() const
Fetches the request DHCID.
Definition: ncr_msg.h:562
Represents a DHCP-DDNS client request.
Definition: ncr_msg.h:227
uint64_t getLeaseExpiresOn() const
Fetches the request lease expiration.
Definition: ncr_msg.h:603
NcrMessageError(const char *file, size_t line, const char *what)
Definition: ncr_msg.h:32
std::string format(const std::string &format, const std::vector< std::string > &args)
Apply Formatting.
Definition: strutil.cc:157