Kea 3.2.1-git
nc_trans.h
Go to the documentation of this file.
1// Copyright (C) 2013-2026 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 <dns/name.h>
17#include <dhcp_ddns/ncr_msg.h>
19#include <util/state_model.h>
20
21#include <boost/shared_ptr.hpp>
22#include <map>
23
24namespace isc {
25namespace d2 {
26
29public:
30 NameChangeTransactionError(const char* file, size_t line,
31 const char* what) :
32 isc::Exception(file, line, what) { }
33};
34
37
79public:
80
82
84 static const int READY_ST = SM_DERIVED_STATE_MIN + 1;
85
93
101
104
107
111
113
115
118
121
125
130
135
136 static const int UPDATE_OK_EVT = SM_DERIVED_EVENT_MIN + 6;
137
143
147
152 static const unsigned int DNS_UPDATE_DEFAULT_TIMEOUT = 100;
153
155 static const unsigned int MAX_UPDATE_TRIES_PER_SERVER = 3;
156
172 DdnsDomainPtr& forward_domain,
173 DdnsDomainPtr& reverse_domain,
174 D2CfgMgrPtr& cfg_mgr);
175
177 virtual ~NameChangeTransaction();
178
184 void startTransaction();
185
196 virtual void operator()(DNSClient::Status status);
197
198protected:
214 virtual void sendUpdate(const std::string& comment = "");
215
225 virtual void defineEvents();
226
236 virtual void verifyEvents();
237
247 virtual void defineStates();
248
258 virtual void verifyStates();
259
271 virtual void onModelFailure(const std::string& explanation);
272
285 void retryTransition(const int fail_to_state);
286
291
294
296 void clearUpdateAttempts();
297
301 void setDnsUpdateStatus(const DNSClient::Status& status);
302
307
310
314 void setForwardChangeCompleted(const bool value);
315
319 void setReverseChangeCompleted(const bool value);
320
324 void setNcrStatus(const dhcp_ddns::NameChangeStatus& status);
325
336 void initServerSelection(const DdnsDomainPtr& domain);
337
347 bool selectNextServer();
348
355 bool selectTSIGKey();
356
360 void setUpdateAttempts(const size_t value);
361
366 return (io_service_);
367 }
368
379
390
400 void addDhcidRdata(dns::RRsetPtr& rrset);
401
411 void addPtrRdata(dns::RRsetPtr& rrset);
412
419 std::string responseString() const;
420
429 std::string transactionOutcomeString() const;
430
431public:
436
443 const TransactionKey& getTransactionKey() const;
444
448 const std::string& getFqdn() const;
449
453 std::string getFqdnLower() const;
454
458 const asiolink::IOAddress& getIOAddress() const;
459
468 std::string getRequestId() const;
469
480
486
492
497 const DnsServerInfoPtr& getCurrentServer() const;
498
502 const DNSClientPtr& getDNSClient() const;
503
509
515
521
529 bool getForwardChangeCompleted() const;
530
538 bool getReverseChangeCompleted() const;
539
544 size_t getUpdateAttempts() const;
545
550 const dns::RRType& getAddressRRType() const;
551
552private:
554 asiolink::IOServicePtr io_service_;
555
559
565 DdnsDomainPtr forward_domain_;
566
572 DdnsDomainPtr reverse_domain_;
573
575 DNSClientPtr dns_client_;
576
578 D2UpdateMessagePtr dns_update_request_;
579
581 DNSClient::Status dns_update_status_;
582
584 D2UpdateMessagePtr dns_update_response_;
585
587 bool forward_change_completed_;
588
590 bool reverse_change_completed_;
591
593 DnsServerInfoStoragePtr current_server_list_;
594
596 DnsServerInfoPtr current_server_;
597
602 size_t next_server_pos_;
603
605 size_t update_attempts_;
606
608 D2CfgMgrPtr cfg_mgr_;
609
611 D2TsigKeyPtr tsig_key_;
612};
613
615typedef boost::shared_ptr<NameChangeTransaction> NameChangeTransactionPtr;
616
617} // namespace isc::d2
618} // namespace isc
619#endif
This is a base class for exceptions thrown from the DNS library module.
Exception(const char *file, size_t line, const char *what)
Constructor for a given type for exceptions with file name and file line number.
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:89
Status
A status code of the DNSClient.
Definition dns_client.h:58
NameChangeTransactionError(const char *file, size_t line, const char *what)
Definition nc_trans.h:30
static const int SELECTING_FWD_SERVER_ST
State in which forward DNS server selection is done.
Definition nc_trans.h:92
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:122
static const unsigned int DNS_UPDATE_DEFAULT_TIMEOUT
Default time to assign to a single DNS update.
Definition nc_trans.h:152
static const int PROCESS_TRANS_FAILED_ST
State which processes an unsuccessful transaction conclusion.
Definition nc_trans.h:106
static const unsigned int MAX_UPDATE_TRIES_PER_SERVER
Maximum times to attempt a single update on a given server.
Definition nc_trans.h:155
const asiolink::IOAddress & getIOAddress() const
Fetches the request IP address.
Definition nc_trans.cc:446
static const int READY_ST
State from which a transaction is started.
Definition nc_trans.h:84
const D2UpdateMessagePtr & getDnsUpdateResponse() const
Fetches the most recent DNS update response packet.
Definition nc_trans.cc:569
static const int PROCESS_TRANS_OK_ST
State which processes successful transaction conclusion.
Definition nc_trans.h:103
const std::string & getFqdn() const
Fetches the request FQDN.
Definition nc_trans.cc:436
static const int UPDATE_OK_EVT
Issued when the attempted update successfully completed.
Definition nc_trans.h:136
const DNSClientPtr & getDNSClient() const
Fetches the DNSClient instance.
Definition nc_trans.cc:544
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:112
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:70
static const int UPDATE_FAILED_EVT
Issued when the attempted update fails to complete.
Definition nc_trans.h:142
const D2UpdateMessagePtr & getDnsUpdateRequest() const
Fetches the current DNS update request packet.
Definition nc_trans.cc:559
const dns::RRType & getAddressRRType() const
Returns the DHCP data type for the lease address.
Definition nc_trans.cc:589
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:471
static const int IO_COMPLETED_EVT
Issued when a DNS update packet exchange has completed.
Definition nc_trans.h:131
static const int NCT_DERIVED_STATE_MIN
Value at which custom states in a derived class should begin.
Definition nc_trans.h:109
static const int SELECT_SERVER_EVT
Issued when a server needs to be selected.
Definition nc_trans.h:114
static const int SERVER_IO_ERROR_EVT
Issued when an update fails due to an IO error.
Definition nc_trans.h:120
std::string getRequestId() const
Fetches the request id that identifies this transaction.
Definition nc_trans.cc:451
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
std::string getFqdnLower() const
Fetches the request FQDN converted to lower-case.
Definition nc_trans.cc:441
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:574
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:483
void setNcrStatus(const dhcp_ddns::NameChangeStatus &status)
Sets the status of the transaction's NameChangeRequest.
Definition nc_trans.cc:554
DdnsDomainPtr & getForwardDomain()
Fetches the forward DdnsDomain.
Definition nc_trans.cc:461
bool selectTSIGKey()
Selects the TSIG key.
Definition nc_trans.cc:512
const asiolink::IOServicePtr & getIOService()
Fetches the IOService the transaction uses for IO processing.
Definition nc_trans.h:365
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:100
DNSClient::Status getDnsUpdateStatus() const
Fetches the most recent DNS update status.
Definition nc_trans.cc:564
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:579
static const int NO_MORE_SERVERS_EVT
Issued when there are no more servers from which to select.
Definition nc_trans.h:126
dhcp_ddns::NameChangeStatus getNcrStatus() const
Fetches the NameChangeRequest status of the transaction.
Definition nc_trans.cc:456
static const int NCT_DERIVED_EVENT_MIN
Value at which custom events in a derived class should begin.
Definition nc_trans.h:145
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:138
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:584
const DnsServerInfoPtr & getCurrentServer() const
Fetches the currently selected server.
Definition nc_trans.cc:549
static const int SERVER_SELECTED_EVT
Issued when a server has been selected.
Definition nc_trans.h:117
DdnsDomainPtr & getReverseDomain()
Fetches the reverse DdnsDomain.
Definition nc_trans.cc:466
std::string transactionOutcomeString() const
Returns a string version of transaction outcome.
Definition nc_trans.cc:171
Container class for handling the DHCID value within a NameChangeRequest.
Definition ncr_msg.h:114
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:615
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:36
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:242
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.