Kea 2.0.0
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 <d2/dns_client.h>
14#include <d2srv/d2_cfg_mgr.h>
15#include <d2srv/d2_tsig_key.h>
16#include <dhcp_ddns/ncr_msg.h>
18#include <util/state_model.h>
19
20#include <boost/shared_ptr.hpp>
21#include <map>
22
23namespace isc {
24namespace d2 {
25
28public:
29 NameChangeTransactionError(const char* file, size_t line,
30 const char* what) :
31 isc::Exception(file, line, what) { };
32};
33
36
78public:
79
81
83 static const int READY_ST = SM_DERIVED_STATE_MIN + 1;
84
92
100
103
106
110
112
114
117
120
124
129
134
135 static const int UPDATE_OK_EVT = SM_DERIVED_EVENT_MIN + 6;
136
142
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
197protected:
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
294
298 void setDnsUpdateStatus(const DNSClient::Status& status);
299
304
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
352 bool selectTSIGKey();
353
357 void setUpdateAttempts(const size_t value);
358
363 return (io_service_);
364 }
365
376
387
397 void addDhcidRdata(dns::RRsetPtr& rrset);
398
408 void addPtrRdata(dns::RRsetPtr& rrset);
409
416 std::string responseString() const;
417
426 std::string transactionOutcomeString() const;
427
428public:
433
440 const TransactionKey& getTransactionKey() const;
441
450 std::string getRequestId() const;
451
462
468
474
479 const DnsServerInfoPtr& getCurrentServer() const;
480
484 const DNSClientPtr& getDNSClient() const;
485
491
497
503
511 bool getForwardChangeCompleted() const;
512
520 bool getReverseChangeCompleted() const;
521
526 size_t getUpdateAttempts() const;
527
532 const dns::RRType& getAddressRRType() const;
533
534private:
536 asiolink::IOServicePtr io_service_;
537
540
546 DdnsDomainPtr forward_domain_;
547
553 DdnsDomainPtr reverse_domain_;
554
556 DNSClientPtr dns_client_;
557
559 D2UpdateMessagePtr dns_update_request_;
560
562 DNSClient::Status dns_update_status_;
563
565 D2UpdateMessagePtr dns_update_response_;
566
568 bool forward_change_completed_;
569
571 bool reverse_change_completed_;
572
574 DnsServerInfoStoragePtr current_server_list_;
575
577 DnsServerInfoPtr current_server_;
578
583 size_t next_server_pos_;
584
586 size_t update_attempts_;
587
589 D2CfgMgrPtr cfg_mgr_;
590
592 D2TsigKeyPtr tsig_key_;
593};
594
596typedef boost::shared_ptr<NameChangeTransaction> NameChangeTransactionPtr;
597
598} // namespace isc::d2
599} // namespace isc
600#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.
Callback for the DNSClient class.
Definition: dns_client.h:74
Status
A status code of the DNSClient.
Definition: dns_client.h:60
Thrown if the transaction encounters a general error.
Definition: nc_trans.h:27
NameChangeTransactionError(const char *file, size_t line, const char *what)
Definition: nc_trans.h:29
Embodies the "life-cycle" required to carry out a DDNS update.
Definition: nc_trans.h:77
static const int SELECTING_FWD_SERVER_ST
State in which forward DNS server selection is done.
Definition: nc_trans.h:91
void retryTransition(const int fail_to_state)
Determines the state and next event based on update attempts.
Definition: nc_trans.cc:286
virtual void onModelFailure(const std::string &explanation)
Handler for fatal model execution errors.
Definition: nc_trans.cc:278
virtual void operator()(DNSClient::Status status)
Serves as the DNSClient IO completion event handler.
Definition: nc_trans.cc:120
static const unsigned int DNS_UPDATE_DEFAULT_TIMEOUT
Default time to assign to a single DNS update.
Definition: nc_trans.h:151
static const int PROCESS_TRANS_FAILED_ST
State which processes an unsuccessful transaction conclusion.
Definition: nc_trans.h:105
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
static const int READY_ST
State from which a transaction is started.
Definition: nc_trans.h:83
const D2UpdateMessagePtr & getDnsUpdateResponse() const
Fetches the most recent DNS update response packet.
Definition: nc_trans.cc:549
static const int PROCESS_TRANS_OK_ST
State which processes successful transaction conclusion.
Definition: nc_trans.h:102
static const int UPDATE_OK_EVT
Issued when the attempted update successfully completed.
Definition: nc_trans.h:135
const DNSClientPtr & getDNSClient() const
Fetches the DNSClient instance.
Definition: nc_trans.cc:524
virtual void verifyStates()
Validates the contents of the set of states.
Definition: nc_trans.cc:265
void startTransaction()
Begins execution of the transaction.
Definition: nc_trans.cc:110
virtual D2UpdateMessagePtr prepNewRequest(DdnsDomainPtr domain)
Creates a new DNS update request based on the given domain.
Definition: nc_trans.cc:339
NameChangeTransaction(asiolink::IOServicePtr &io_service, dhcp_ddns::NameChangeRequestPtr &ncr, DdnsDomainPtr &forward_domain, DdnsDomainPtr &reverse_domain, D2CfgMgrPtr &cfg_mgr)
Constructor.
Definition: nc_trans.cc:68
static const int UPDATE_FAILED_EVT
Issued when the attempted update fails to complete.
Definition: nc_trans.h:141
const D2UpdateMessagePtr & getDnsUpdateRequest() const
Fetches the current DNS update request packet.
Definition: nc_trans.cc:539
const dns::RRType & getAddressRRType() const
Returns the DHCP data type for the lease address.
Definition: nc_trans.cc:569
const dhcp_ddns::NameChangeRequestPtr & getNcr() const
Fetches the NameChangeRequest for this transaction.
Definition: nc_trans.cc:421
void initServerSelection(const DdnsDomainPtr &domain)
Initializes server selection from the given DDNS domain.
Definition: nc_trans.cc:451
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
static const int SELECT_SERVER_EVT
Issued when a server needs to be selected.
Definition: nc_trans.h:113
static const int SERVER_IO_ERROR_EVT
Issued when an update fails due to an IO error.
Definition: nc_trans.h:119
std::string getRequestId() const
Fetches the request id that identifies this transaction.
Definition: nc_trans.cc:431
virtual void defineStates()
Adds states defined by NameChangeTransaction to the state set.
Definition: nc_trans.cc:257
const TransactionKey & getTransactionKey() const
Fetches the unique key that identifies this transaction.
Definition: nc_trans.cc:426
void setUpdateAttempts(const size_t value)
Sets the update attempt count to the given value.
Definition: nc_trans.cc:334
void addLeaseAddressRdata(dns::RRsetPtr &rrset)
Adds an RData for the lease address to the given RRset.
Definition: nc_trans.cc:362
bool getForwardChangeCompleted() const
Returns whether the forward change has completed or not.
Definition: nc_trans.cc:554
virtual void sendUpdate(const std::string &comment="")
Send the update request to the current server.
Definition: nc_trans.cc:192
void setForwardChangeCompleted(const bool value)
Sets the forward change completion flag to the given value.
Definition: nc_trans.cc:324
void addPtrRdata(dns::RRsetPtr &rrset)
Adds an RData for the lease FQDN to the given RRset.
Definition: nc_trans.cc:404
void setDnsUpdateResponse(D2UpdateMessagePtr &response)
Sets the update response packet to the given packet.
Definition: nc_trans.cc:314
bool selectNextServer()
Selects the next server in the current server list.
Definition: nc_trans.cc:463
void setNcrStatus(const dhcp_ddns::NameChangeStatus &status)
Sets the status of the transaction's NameChangeRequest.
Definition: nc_trans.cc:534
DdnsDomainPtr & getForwardDomain()
Fetches the forward DdnsDomain.
Definition: nc_trans.cc:441
bool selectTSIGKey()
Selects the TSIG key.
Definition: nc_trans.cc:492
const asiolink::IOServicePtr & getIOService()
Fetches the IOService the transaction uses for IO processing.
Definition: nc_trans.h:362
virtual void verifyEvents()
Validates the contents of the set of events.
Definition: nc_trans.cc:242
void addDhcidRdata(dns::RRsetPtr &rrset)
Adds an RData for the lease client's DHCID to the given RRset.
Definition: nc_trans.cc:384
void clearDnsUpdateRequest()
Destroys the current update request packet and resets update attempts count.
Definition: nc_trans.cc:303
static const int SELECTING_REV_SERVER_ST
State in which reverse DNS server selection is done.
Definition: nc_trans.h:99
DNSClient::Status getDnsUpdateStatus() const
Fetches the most recent DNS update status.
Definition: nc_trans.cc:544
void setDnsUpdateStatus(const DNSClient::Status &status)
Sets the update status to the given status value.
Definition: nc_trans.cc:309
void setDnsUpdateRequest(D2UpdateMessagePtr &request)
Sets the update request packet to the given packet.
Definition: nc_trans.cc:298
bool getReverseChangeCompleted() const
Returns whether the reverse change has completed or not.
Definition: nc_trans.cc:559
static const int NO_MORE_SERVERS_EVT
Issued when there are no more servers from which to select.
Definition: nc_trans.h:125
dhcp_ddns::NameChangeStatus getNcrStatus() const
Fetches the NameChangeRequest status of the transaction.
Definition: nc_trans.cc:436
static const int NCT_DERIVED_EVENT_MIN
Value at which custom events in a derived class should begin.
Definition: nc_trans.h:144
virtual void defineEvents()
Adds events defined by NameChangeTransaction to the event set.
Definition: nc_trans.cc:227
void clearDnsUpdateResponse()
Destroys the current update response packet.
Definition: nc_trans.cc:319
std::string responseString() const
Returns a string version of the current response status and rcode.
Definition: nc_trans.cc:136
void setReverseChangeCompleted(const bool value)
Sets the reverse change completion flag to the given value.
Definition: nc_trans.cc:329
size_t getUpdateAttempts() const
Fetches the update attempt count for the current update.
Definition: nc_trans.cc:564
const DnsServerInfoPtr & getCurrentServer() const
Fetches the currently selected server.
Definition: nc_trans.cc:529
static const int SERVER_SELECTED_EVT
Issued when a server has been selected.
Definition: nc_trans.h:116
DdnsDomainPtr & getReverseDomain()
Fetches the reverse DdnsDomain.
Definition: nc_trans.cc:446
std::string transactionOutcomeString() const
Returns a string version of transaction outcome.
Definition: nc_trans.cc:170
virtual ~NameChangeTransaction()
Destructor.
Definition: nc_trans.cc:106
Container class for handling the DHCID value within a NameChangeRequest.
Definition: ncr_msg.h:86
The RRType class encapsulates DNS resource record types.
Definition: rrtype.h:106
Implements a finite state machine.
Definition: state_model.h:274
static const int SM_DERIVED_STATE_MIN
Value at which custom states in a derived class should begin.
Definition: state_model.h:285
static const int SM_DERIVED_EVENT_MIN
Value at which custom events in a derived class should begin.
Definition: state_model.h:304
boost::shared_ptr< D2UpdateMessage > D2UpdateMessagePtr
Pointer to the DNS Update Message.
boost::shared_ptr< DdnsDomain > DdnsDomainPtr
Defines a pointer for DdnsDomain instances.
Definition: d2_config.h:612
boost::shared_ptr< D2CfgMgr > D2CfgMgrPtr
Defines a shared pointer to D2CfgMgr.
Definition: d2_cfg_mgr.h:334
boost::shared_ptr< DnsServerInfo > DnsServerInfoPtr
Defines a pointer for DnsServerInfo instances.
Definition: d2_config.h:542
boost::shared_ptr< NameChangeTransaction > NameChangeTransactionPtr
Defines a pointer to a NameChangeTransaction.
Definition: nc_trans.h:596
boost::shared_ptr< DNSClient > DNSClientPtr
Definition: dns_client.h:21
boost::shared_ptr< DnsServerInfoStorage > DnsServerInfoStoragePtr
Defines a pointer to DnsServerInfo storage containers.
Definition: d2_config.h:548
isc::dhcp_ddns::D2Dhcid TransactionKey
Defines the type used as the unique key for transactions.
Definition: nc_trans.h:35
boost::shared_ptr< D2TsigKey > D2TsigKeyPtr
Type of pointer to a D2 TSIG key.
Definition: d2_tsig_key.h:71
NameChangeStatus
Defines the runtime processing status values for requests.
Definition: ncr_msg.h:52
boost::shared_ptr< NameChangeRequest > NameChangeRequestPtr
Defines a pointer to a NameChangeRequest.
Definition: ncr_msg.h:212
boost::shared_ptr< AbstractRRset > RRsetPtr
A pointer-like type pointing to an RRset object.
Definition: rrset.h:47
Defines the logger used by the top-level component of kea-lfc.
This file provides the classes needed to embody, compose, and decompose DNS update requests that are ...
This file defines the class StateModel.