Kea  1.9.9-git
nc_trans.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 NC_TRANS_H
8 #define NC_TRANS_H
9 
11 
12 #include <asiolink/io_service.h>
13 #include <exceptions/exceptions.h>
14 #include <d2/d2_cfg_mgr.h>
15 #include <d2/dns_client.h>
16 #include <dhcp_ddns/ncr_msg.h>
17 #include <dns/tsig.h>
18 #include <util/state_model.h>
19 
20 #include <boost/shared_ptr.hpp>
21 #include <map>
22 
23 namespace isc {
24 namespace d2 {
25 
28 public:
29  NameChangeTransactionError(const char* file, size_t line,
30  const char* what) :
31  isc::Exception(file, line, what) { };
32 };
33 
36 
78 public:
79 
81 
83  static const int READY_ST = SM_DERIVED_STATE_MIN + 1;
84 
92 
100 
103 
106 
108  static const int NCT_DERIVED_STATE_MIN = SM_DERIVED_STATE_MIN + 101;
110 
112  static const int SELECT_SERVER_EVT = SM_DERIVED_EVENT_MIN + 1;
114 
117 
120 
124 
129 
130  static const int IO_COMPLETED_EVT = SM_DERIVED_EVENT_MIN + 5;
134 
135  static const int UPDATE_OK_EVT = SM_DERIVED_EVENT_MIN + 6;
136 
141  static const int UPDATE_FAILED_EVT = SM_DERIVED_EVENT_MIN + 7;
142 
144  static const int NCT_DERIVED_EVENT_MIN = SM_DERIVED_EVENT_MIN + 101;
146 
151  static const unsigned int DNS_UPDATE_DEFAULT_TIMEOUT = 100;
152 
154  static const unsigned int MAX_UPDATE_TRIES_PER_SERVER = 3;
155 
171  DdnsDomainPtr& forward_domain,
172  DdnsDomainPtr& reverse_domain,
173  D2CfgMgrPtr& cfg_mgr);
174 
176  virtual ~NameChangeTransaction();
177 
183  void startTransaction();
184 
195  virtual void operator()(DNSClient::Status status);
196 
197 protected:
213  virtual void sendUpdate(const std::string& comment = "");
214 
224  virtual void defineEvents();
225 
235  virtual void verifyEvents();
236 
246  virtual void defineStates();
247 
257  virtual void verifyStates();
258 
270  virtual void onModelFailure(const std::string& explanation);
271 
284  void retryTransition(const int fail_to_state);
285 
290 
293  void clearDnsUpdateRequest();
294 
298  void setDnsUpdateStatus(const DNSClient::Status& status);
299 
304 
306  void clearDnsUpdateResponse();
307 
311  void setForwardChangeCompleted(const bool value);
312 
316  void setReverseChangeCompleted(const bool value);
317 
321  void setNcrStatus(const dhcp_ddns::NameChangeStatus& status);
322 
333  void initServerSelection(const DdnsDomainPtr& domain);
334 
344  bool selectNextServer();
345 
349  void setUpdateAttempts(const size_t value);
350 
355  return (io_service_);
356  }
357 
368 
378  void addLeaseAddressRdata(dns::RRsetPtr& rrset);
379 
389  void addDhcidRdata(dns::RRsetPtr& rrset);
390 
400  void addPtrRdata(dns::RRsetPtr& rrset);
401 
408  std::string responseString() const;
409 
418  std::string transactionOutcomeString() const;
419 
420 public:
425 
432  const TransactionKey& getTransactionKey() const;
433 
442  std::string getRequestId() const;
443 
454 
460 
466 
471  const DnsServerInfoPtr& getCurrentServer() const;
472 
476  const DNSClientPtr& getDNSClient() const;
477 
483 
489 
495 
503  bool getForwardChangeCompleted() const;
504 
512  bool getReverseChangeCompleted() const;
513 
518  size_t getUpdateAttempts() const;
519 
524  const dns::RRType& getAddressRRType() const;
525 
526 private:
528  asiolink::IOServicePtr io_service_;
529 
532 
538  DdnsDomainPtr forward_domain_;
539 
545  DdnsDomainPtr reverse_domain_;
546 
548  DNSClientPtr dns_client_;
549 
551  D2UpdateMessagePtr dns_update_request_;
552 
554  DNSClient::Status dns_update_status_;
555 
557  D2UpdateMessagePtr dns_update_response_;
558 
560  bool forward_change_completed_;
561 
563  bool reverse_change_completed_;
564 
566  DnsServerInfoStoragePtr current_server_list_;
567 
569  DnsServerInfoPtr current_server_;
570 
575  size_t next_server_pos_;
576 
578  size_t update_attempts_;
579 
581  D2CfgMgrPtr cfg_mgr_;
582 
584  dns::TSIGKeyPtr tsig_key_;
585 };
586 
588 typedef boost::shared_ptr<NameChangeTransaction> NameChangeTransactionPtr;
589 
590 } // namespace isc::d2
591 } // namespace isc
592 #endif
virtual D2UpdateMessagePtr prepNewRequest(DdnsDomainPtr domain)
Creates a new DNS update request based on the given domain.
Definition: nc_trans.cc:316
virtual void sendUpdate(const std::string &comment="")
Send the update request to the current server.
Definition: nc_trans.cc:169
size_t getUpdateAttempts() const
Fetches the update attempt count for the current update.
Definition: nc_trans.cc:509
Implements a finite state machine.
Definition: state_model.h:274
static const int PROCESS_TRANS_OK_ST
State which processes successful transaction conclusion.
Definition: nc_trans.h:102
Thrown if the transaction encounters a general error.
Definition: nc_trans.h:27
static const unsigned int MAX_UPDATE_TRIES_PER_SERVER
Maximum times to attempt a single update on a given server.
Definition: nc_trans.h:154
boost::shared_ptr< NameChangeTransaction > NameChangeTransactionPtr
Defines a pointer to a NameChangeTransaction.
Definition: nc_trans.h:588
boost::shared_ptr< DNSClient > DNSClientPtr
Definition: dns_client.h:21
boost::shared_ptr< DdnsDomain > DdnsDomainPtr
Defines a pointer for DdnsDomain instances.
Definition: d2_config.h:591
virtual void onModelFailure(const std::string &explanation)
Handler for fatal model execution errors.
Definition: nc_trans.cc:255
boost::shared_ptr< D2UpdateMessage > D2UpdateMessagePtr
Pointer to the DNS Update Message.
void setNcrStatus(const dhcp_ddns::NameChangeStatus &status)
Sets the status of the transaction's NameChangeRequest.
Definition: nc_trans.cc:479
bool getForwardChangeCompleted() const
Returns whether the forward change has completed or not.
Definition: nc_trans.cc:499
static const int SELECTING_FWD_SERVER_ST
State in which forward DNS server selection is done.
Definition: nc_trans.h:91
std::string transactionOutcomeString() const
Returns a string version of transaction outcome.
Definition: nc_trans.cc:147
boost::shared_ptr< NameChangeRequest > NameChangeRequestPtr
Defines a pointer to a NameChangeRequest.
Definition: ncr_msg.h:212
void startTransaction()
Begins execution of the transaction.
Definition: nc_trans.cc:87
static const int SERVER_IO_ERROR_EVT
Issued when an update fails due to an IO error.
Definition: nc_trans.h:119
const dhcp_ddns::NameChangeRequestPtr & getNcr() const
Fetches the NameChangeRequest for this transaction.
Definition: nc_trans.cc:398
static const int IO_COMPLETED_EVT
Issued when a DNS update packet exchange has completed.
Definition: nc_trans.h:130
static const int NCT_DERIVED_STATE_MIN
Value at which custom states in a derived class should begin.
Definition: nc_trans.h:108
bool getReverseChangeCompleted() const
Returns whether the reverse change has completed or not.
Definition: nc_trans.cc:504
Callback for the DNSClient class.
Definition: dns_client.h:74
static const int NCT_DERIVED_EVENT_MIN
Value at which custom events in a derived class should begin.
Definition: nc_trans.h:144
void setForwardChangeCompleted(const bool value)
Sets the forward change completion flag to the given value.
Definition: nc_trans.cc:301
void addDhcidRdata(dns::RRsetPtr &rrset)
Adds an RData for the lease client's DHCID to the given RRset.
Definition: nc_trans.cc:361
std::string getRequestId() const
Fetches the request id that identifies this transaction.
Definition: nc_trans.cc:408
static const int SERVER_SELECTED_EVT
Issued when a server has been selected.
Definition: nc_trans.h:116
void retryTransition(const int fail_to_state)
Determines the state and next event based on update attempts.
Definition: nc_trans.cc:263
isc::dhcp_ddns::D2Dhcid TransactionKey
Defines the type used as the unique key for transactions.
Definition: nc_trans.h:35
const D2UpdateMessagePtr & getDnsUpdateRequest() const
Fetches the current DNS update request packet.
Definition: nc_trans.cc:484
Status
A status code of the DNSClient.
Definition: dns_client.h:60
NameChangeStatus
Defines the runtime processing status values for requests.
Definition: ncr_msg.h:52
boost::shared_ptr< D2CfgMgr > D2CfgMgrPtr
Defines a shared pointer to D2CfgMgr.
Definition: d2_cfg_mgr.h:334
DNSClient::Status getDnsUpdateStatus() const
Fetches the most recent DNS update status.
Definition: nc_trans.cc:489
virtual void defineStates()
Adds states defined by NameChangeTransaction to the state set.
Definition: nc_trans.cc:234
boost::shared_ptr< TSIGKey > TSIGKeyPtr
Definition: tsig.h:436
static const int SM_DERIVED_EVENT_MIN
Value at which custom events in a derived class should begin.
Definition: state_model.h:304
void setReverseChangeCompleted(const bool value)
Sets the reverse change completion flag to the given value.
Definition: nc_trans.cc:306
static const unsigned int DNS_UPDATE_DEFAULT_TIMEOUT
Default time to assign to a single DNS update.
Definition: nc_trans.h:151
const asiolink::IOServicePtr & getIOService()
Fetches the IOService the transaction uses for IO processing.
Definition: nc_trans.h:354
static const int SM_DERIVED_STATE_MIN
Value at which custom states in a derived class should begin.
Definition: state_model.h:285
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
static const int SELECTING_REV_SERVER_ST
State in which reverse DNS server selection is done.
Definition: nc_trans.h:99
void setDnsUpdateStatus(const DNSClient::Status &status)
Sets the update status to the given status value.
Definition: nc_trans.cc:286
DdnsDomainPtr & getForwardDomain()
Fetches the forward DdnsDomain.
Definition: nc_trans.cc:418
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-dhcp-ddns.
NameChangeTransactionError(const char *file, size_t line, const char *what)
Definition: nc_trans.h:29
void addPtrRdata(dns::RRsetPtr &rrset)
Adds an RData for the lease FQDN to the given RRset.
Definition: nc_trans.cc:381
const D2UpdateMessagePtr & getDnsUpdateResponse() const
Fetches the most recent DNS update response packet.
Definition: nc_trans.cc:494
static const int NO_MORE_SERVERS_EVT
Issued when there are no more servers from which to select.
Definition: nc_trans.h:125
virtual void operator()(DNSClient::Status status)
Serves as the DNSClient IO completion event handler.
Definition: nc_trans.cc:97
void setUpdateAttempts(const size_t value)
Sets the update attempt count to the given value.
Definition: nc_trans.cc:311
const DNSClientPtr & getDNSClient() const
Fetches the DNSClient instance.
Definition: nc_trans.cc:469
static const int PROCESS_TRANS_FAILED_ST
State which processes an unsuccessful transaction conclusion.
Definition: nc_trans.h:105
const DnsServerInfoPtr & getCurrentServer() const
Fetches the currently selected server.
Definition: nc_trans.cc:474
std::string responseString() const
Returns a string version of the current response status and rcode.
Definition: nc_trans.cc:113
The RRType class encapsulates DNS resource record types.
Definition: rrtype.h:106
static const int SELECT_SERVER_EVT
Issued when a server needs to be selected.
Definition: nc_trans.h:113
void clearDnsUpdateRequest()
Destroys the current update request packet and resets update attempts count.
Definition: nc_trans.cc:280
Container class for handling the DHCID value within a NameChangeRequest.
Definition: ncr_msg.h:86
static const int READY_ST
State from which a transaction is started.
Definition: nc_trans.h:83
void setDnsUpdateRequest(D2UpdateMessagePtr &request)
Sets the update request packet to the given packet.
Definition: nc_trans.cc:275
virtual void defineEvents()
Adds events defined by NameChangeTransaction to the event set.
Definition: nc_trans.cc:204
Embodies the "life-cycle" required to carry out a DDNS update.
Definition: nc_trans.h:77
static const int UPDATE_OK_EVT
Issued when the attempted update successfully completed.
Definition: nc_trans.h:135
const dns::RRType & getAddressRRType() const
Returns the DHCP data type for the lease address.
Definition: nc_trans.cc:514
void clearDnsUpdateResponse()
Destroys the current update response packet.
Definition: nc_trans.cc:296
NameChangeTransaction(asiolink::IOServicePtr &io_service, dhcp_ddns::NameChangeRequestPtr &ncr, DdnsDomainPtr &forward_domain, DdnsDomainPtr &reverse_domain, D2CfgMgrPtr &cfg_mgr)
Constructor.
Definition: nc_trans.cc:45
dhcp_ddns::NameChangeStatus getNcrStatus() const
Fetches the NameChangeRequest status of the transaction.
Definition: nc_trans.cc:413
boost::shared_ptr< AbstractRRset > RRsetPtr
A pointer-like type pointing to an RRset object.
Definition: rrset.h:47
DdnsDomainPtr & getReverseDomain()
Fetches the reverse DdnsDomain.
Definition: nc_trans.cc:423
boost::shared_ptr< DnsServerInfoStorage > DnsServerInfoStoragePtr
Defines a pointer to DnsServerInfo storage containers.
Definition: d2_config.h:520
This file defines the class StateModel.
static const int UPDATE_FAILED_EVT
Issued when the attempted update fails to complete.
Definition: nc_trans.h:141
This file provides the classes needed to embody, compose, and decompose DNS update requests that are ...
virtual void verifyEvents()
Validates the contents of the set of events.
Definition: nc_trans.cc:219
void addLeaseAddressRdata(dns::RRsetPtr &rrset)
Adds an RData for the lease address to the given RRset.
Definition: nc_trans.cc:339
const TransactionKey & getTransactionKey() const
Fetches the unique key that identifies this transaction.
Definition: nc_trans.cc:403
void initServerSelection(const DdnsDomainPtr &domain)
Initializes server selection from the given DDNS domain.
Definition: nc_trans.cc:428
virtual ~NameChangeTransaction()
Destructor.
Definition: nc_trans.cc:83
void setDnsUpdateResponse(D2UpdateMessagePtr &response)
Sets the update response packet to the given packet.
Definition: nc_trans.cc:291
boost::shared_ptr< DnsServerInfo > DnsServerInfoPtr
Defines a pointer for DnsServerInfo instances.
Definition: d2_config.h:514
bool selectNextServer()
Selects the next server in the current server list.
Definition: nc_trans.cc:448
virtual void verifyStates()
Validates the contents of the set of states.
Definition: nc_trans.cc:242