Kea 2.7.4
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>
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
293
295 void clearUpdateAttempts();
296
300 void setDnsUpdateStatus(const DNSClient::Status& status);
301
306
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
378
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
430public:
435
442 const TransactionKey& getTransactionKey() const;
443
452 std::string getRequestId() const;
453
464
470
476
481 const DnsServerInfoPtr& getCurrentServer() const;
482
486 const DNSClientPtr& getDNSClient() const;
487
493
499
505
513 bool getForwardChangeCompleted() const;
514
522 bool getReverseChangeCompleted() const;
523
528 size_t getUpdateAttempts() const;
529
534 const dns::RRType& getAddressRRType() const;
535
536private:
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
598typedef boost::shared_ptr<NameChangeTransaction> NameChangeTransactionPtr;
599
600} // namespace isc::d2
601} // namespace isc
602#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:72
Status
A status code of the DNSClient.
Definition dns_client.h:58
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:287
virtual void onModelFailure(const std::string &explanation)
Handler for fatal model execution errors.
Definition nc_trans.cc:279
virtual void operator()(DNSClient::Status status)
Serves as the DNSClient IO completion event handler.
Definition nc_trans.cc:121
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:554
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:529
virtual void verifyStates()
Validates the contents of the set of states.
Definition nc_trans.cc:266
void startTransaction()
Begins execution of the transaction.
Definition nc_trans.cc:111
virtual D2UpdateMessagePtr prepNewRequest(DdnsDomainPtr domain)
Creates a new DNS update request based on the given domain.
Definition nc_trans.cc:344
NameChangeTransaction(asiolink::IOServicePtr &io_service, dhcp_ddns::NameChangeRequestPtr &ncr, DdnsDomainPtr &forward_domain, DdnsDomainPtr &reverse_domain, D2CfgMgrPtr &cfg_mgr)
Constructor.
Definition nc_trans.cc:69
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:544
const dns::RRType & getAddressRRType() const
Returns the DHCP data type for the lease address.
Definition nc_trans.cc:574
const dhcp_ddns::NameChangeRequestPtr & getNcr() const
Fetches the NameChangeRequest for this transaction.
Definition nc_trans.cc:426
void initServerSelection(const DdnsDomainPtr &domain)
Initializes server selection from the given DDNS domain.
Definition nc_trans.cc:456
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:436
virtual void defineStates()
Adds states defined by NameChangeTransaction to the state set.
Definition nc_trans.cc:258
const TransactionKey & getTransactionKey() const
Fetches the unique key that identifies this transaction.
Definition nc_trans.cc:431
void setUpdateAttempts(const size_t value)
Sets the update attempt count to the given value.
Definition nc_trans.cc:339
void addLeaseAddressRdata(dns::RRsetPtr &rrset)
Adds an RData for the lease address to the given RRset.
Definition nc_trans.cc:367
bool getForwardChangeCompleted() const
Returns whether the forward change has completed or not.
Definition nc_trans.cc:559
virtual void sendUpdate(const std::string &comment="")
Send the update request to the current server.
Definition nc_trans.cc:193
void setForwardChangeCompleted(const bool value)
Sets the forward change completion flag to the given value.
Definition nc_trans.cc:329
void addPtrRdata(dns::RRsetPtr &rrset)
Adds an RData for the lease FQDN to the given RRset.
Definition nc_trans.cc:409
void setDnsUpdateResponse(D2UpdateMessagePtr &response)
Sets the update response packet to the given packet.
Definition nc_trans.cc:319
bool selectNextServer()
Selects the next server in the current server list.
Definition nc_trans.cc:468
void setNcrStatus(const dhcp_ddns::NameChangeStatus &status)
Sets the status of the transaction's NameChangeRequest.
Definition nc_trans.cc:539
DdnsDomainPtr & getForwardDomain()
Fetches the forward DdnsDomain.
Definition nc_trans.cc:446
bool selectTSIGKey()
Selects the TSIG key.
Definition nc_trans.cc:497
const asiolink::IOServicePtr & getIOService()
Fetches the IOService the transaction uses for IO processing.
Definition nc_trans.h:364
virtual void verifyEvents()
Validates the contents of the set of events.
Definition nc_trans.cc:243
void addDhcidRdata(dns::RRsetPtr &rrset)
Adds an RData for the lease client's DHCID to the given RRset.
Definition nc_trans.cc:389
void clearDnsUpdateRequest()
Destroys the current update request packet.
Definition nc_trans.cc:304
void clearUpdateAttempts()
Resets the update attempts count.
Definition nc_trans.cc:309
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:549
void setDnsUpdateStatus(const DNSClient::Status &status)
Sets the update status to the given status value.
Definition nc_trans.cc:314
void setDnsUpdateRequest(D2UpdateMessagePtr &request)
Sets the update request packet to the given packet.
Definition nc_trans.cc:299
bool getReverseChangeCompleted() const
Returns whether the reverse change has completed or not.
Definition nc_trans.cc:564
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:441
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:228
void clearDnsUpdateResponse()
Destroys the current update response packet.
Definition nc_trans.cc:324
std::string responseString() const
Returns a string version of the current response status and rcode.
Definition nc_trans.cc:137
void setReverseChangeCompleted(const bool value)
Sets the reverse change completion flag to the given value.
Definition nc_trans.cc:334
size_t getUpdateAttempts() const
Fetches the update attempt count for the current update.
Definition nc_trans.cc:569
const DnsServerInfoPtr & getCurrentServer() const
Fetches the currently selected server.
Definition nc_trans.cc:534
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:451
std::string transactionOutcomeString() const
Returns a string version of transaction outcome.
Definition nc_trans.cc:171
virtual ~NameChangeTransaction()
Destructor.
Definition nc_trans.cc:107
Container class for handling the DHCID value within a NameChangeRequest.
Definition ncr_msg.h:113
The RRType class encapsulates DNS resource record types.
Definition rrtype.h:96
Implements a finite state machine.
static const int SM_DERIVED_STATE_MIN
Value at which custom states in a derived class should begin.
static const int SM_DERIVED_EVENT_MIN
Value at which custom events in a derived class should begin.
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:624
boost::shared_ptr< D2CfgMgr > D2CfgMgrPtr
Defines a shared pointer to D2CfgMgr.
Definition d2_cfg_mgr.h:367
boost::shared_ptr< DnsServerInfo > DnsServerInfoPtr
Defines a pointer for DnsServerInfo instances.
Definition d2_config.h:554
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:20
boost::shared_ptr< DnsServerInfoStorage > DnsServerInfoStoragePtr
Defines a pointer to DnsServerInfo storage containers.
Definition d2_config.h:560
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:51
boost::shared_ptr< NameChangeRequest > NameChangeRequestPtr
Defines a pointer to a NameChangeRequest.
Definition ncr_msg.h:241
boost::shared_ptr< AbstractRRset > RRsetPtr
A pointer-like type pointing to an RRset object.
Definition rrset.h:50
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.