Kea  2.3.5-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 <d2srv/dns_client.h>
14 #include <d2srv/d2_cfg_mgr.h>
15 #include <d2srv/d2_tsig_key.h>
16 #include <dhcp_ddns/ncr_msg.h>
17 #include <exceptions/exceptions.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 
91  static const int SELECTING_FWD_SERVER_ST = SM_DERIVED_STATE_MIN + 2;
92 
99  static const int SELECTING_REV_SERVER_ST = SM_DERIVED_STATE_MIN + 3;
100 
102  static const int PROCESS_TRANS_OK_ST = SM_DERIVED_STATE_MIN + 4;
103 
105  static const int PROCESS_TRANS_FAILED_ST = SM_DERIVED_STATE_MIN + 5;
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 
116  static const int SERVER_SELECTED_EVT = SM_DERIVED_EVENT_MIN + 2;
117 
119  static const int SERVER_IO_ERROR_EVT = SM_DERIVED_EVENT_MIN + 3;
120 
124 
125  static const int NO_MORE_SERVERS_EVT =SM_DERIVED_EVENT_MIN + 4;
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 
289  void setDnsUpdateRequest(D2UpdateMessagePtr& request);
290 
292  void clearDnsUpdateRequest();
293 
295  void clearUpdateAttempts();
296 
300  void setDnsUpdateStatus(const DNSClient::Status& status);
301 
305  void setDnsUpdateResponse(D2UpdateMessagePtr& response);
306 
308  void clearDnsUpdateResponse();
309 
313  void setForwardChangeCompleted(const bool value);
314 
318  void setReverseChangeCompleted(const bool value);
319 
323  void setNcrStatus(const dhcp_ddns::NameChangeStatus& status);
324 
335  void initServerSelection(const DdnsDomainPtr& domain);
336 
346  bool selectNextServer();
347 
354  bool selectTSIGKey();
355 
359  void setUpdateAttempts(const size_t value);
360 
365  return (io_service_);
366  }
367 
377  virtual D2UpdateMessagePtr prepNewRequest(DdnsDomainPtr domain);
378 
388  void addLeaseAddressRdata(dns::RRsetPtr& rrset);
389 
399  void addDhcidRdata(dns::RRsetPtr& rrset);
400 
410  void addPtrRdata(dns::RRsetPtr& rrset);
411 
418  std::string responseString() const;
419 
428  std::string transactionOutcomeString() const;
429 
430 public:
434  const dhcp_ddns::NameChangeRequestPtr& getNcr() const;
435 
442  const TransactionKey& getTransactionKey() const;
443 
452  std::string getRequestId() const;
453 
463  dhcp_ddns::NameChangeStatus getNcrStatus() const;
464 
469  DdnsDomainPtr& getForwardDomain();
470 
475  DdnsDomainPtr& getReverseDomain();
476 
481  const DnsServerInfoPtr& getCurrentServer() const;
482 
486  const DNSClientPtr& getDNSClient() const;
487 
492  const D2UpdateMessagePtr& getDnsUpdateRequest() const;
493 
498  DNSClient::Status getDnsUpdateStatus() const;
499 
504  const D2UpdateMessagePtr& getDnsUpdateResponse() const;
505 
513  bool getForwardChangeCompleted() const;
514 
522  bool getReverseChangeCompleted() const;
523 
528  size_t getUpdateAttempts() const;
529 
534  const dns::RRType& getAddressRRType() const;
535 
536 private:
538  asiolink::IOServicePtr io_service_;
539 
542 
548  DdnsDomainPtr forward_domain_;
549 
555  DdnsDomainPtr reverse_domain_;
556 
558  DNSClientPtr dns_client_;
559 
561  D2UpdateMessagePtr dns_update_request_;
562 
564  DNSClient::Status dns_update_status_;
565 
567  D2UpdateMessagePtr dns_update_response_;
568 
570  bool forward_change_completed_;
571 
573  bool reverse_change_completed_;
574 
576  DnsServerInfoStoragePtr current_server_list_;
577 
579  DnsServerInfoPtr current_server_;
580 
585  size_t next_server_pos_;
586 
588  size_t update_attempts_;
589 
591  D2CfgMgrPtr cfg_mgr_;
592 
594  D2TsigKeyPtr tsig_key_;
595 };
596 
598 typedef boost::shared_ptr<NameChangeTransaction> NameChangeTransactionPtr;
599 
600 } // namespace isc::d2
601 } // namespace isc
602 #endif
Implements a finite state machine.
Definition: state_model.h:274
Thrown if the transaction encounters a general error.
Definition: nc_trans.h:27
boost::shared_ptr< NameChangeTransaction > NameChangeTransactionPtr
Defines a pointer to a NameChangeTransaction.
Definition: nc_trans.h:598
boost::shared_ptr< DNSClient > DNSClientPtr
Definition: dns_client.h:19
boost::shared_ptr< DdnsDomain > DdnsDomainPtr
Defines a pointer for DdnsDomain instances.
Definition: d2_config.h:612
boost::shared_ptr< D2UpdateMessage > D2UpdateMessagePtr
Pointer to the DNS Update Message.
boost::shared_ptr< D2TsigKey > D2TsigKeyPtr
Type of pointer to a D2 TSIG key.
Definition: d2_tsig_key.h:71
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.
Callback for the DNSClient class.
Definition: dns_client.h:72
isc::dhcp_ddns::D2Dhcid TransactionKey
Defines the type used as the unique key for transactions.
Definition: nc_trans.h:35
Status
A status code of the DNSClient.
Definition: dns_client.h:58
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
const asiolink::IOServicePtr & getIOService()
Fetches the IOService the transaction uses for IO processing.
Definition: nc_trans.h:364
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.
NameChangeTransactionError(const char *file, size_t line, const char *what)
Definition: nc_trans.h:29
The RRType class encapsulates DNS resource record types.
Definition: rrtype.h:106
Container class for handling the DHCID value within a NameChangeRequest.
Definition: ncr_msg.h:86
Embodies the "life-cycle" required to carry out a DDNS update.
Definition: nc_trans.h:77
boost::shared_ptr< AbstractRRset > RRsetPtr
A pointer-like type pointing to an RRset object.
Definition: rrset.h:47
boost::shared_ptr< DnsServerInfoStorage > DnsServerInfoStoragePtr
Defines a pointer to DnsServerInfo storage containers.
Definition: d2_config.h:548
This file defines the class StateModel.
This file provides the classes needed to embody, compose, and decompose DNS update requests that are ...
boost::shared_ptr< DnsServerInfo > DnsServerInfoPtr
Defines a pointer for DnsServerInfo instances.
Definition: d2_config.h:542