25 int hooks_index_select_key_;
46 const int NameChangeTransaction::READY_ST;
47 const int NameChangeTransaction::SELECTING_FWD_SERVER_ST;
48 const int NameChangeTransaction::SELECTING_REV_SERVER_ST;
49 const int NameChangeTransaction::PROCESS_TRANS_OK_ST;
50 const int NameChangeTransaction::PROCESS_TRANS_FAILED_ST;
52 const int NameChangeTransaction::NCT_DERIVED_STATE_MIN;
55 const int NameChangeTransaction::SELECT_SERVER_EVT;
56 const int NameChangeTransaction::SERVER_SELECTED_EVT;
57 const int NameChangeTransaction::SERVER_IO_ERROR_EVT;
58 const int NameChangeTransaction::NO_MORE_SERVERS_EVT;
59 const int NameChangeTransaction::IO_COMPLETED_EVT;
60 const int NameChangeTransaction::UPDATE_OK_EVT;
61 const int NameChangeTransaction::UPDATE_FAILED_EVT;
63 const int NameChangeTransaction::NCT_DERIVED_EVENT_MIN;
65 const unsigned int NameChangeTransaction::MAX_UPDATE_TRIES_PER_SERVER;
67 NameChangeTransaction::
73 : io_service_(io_service), ncr_(ncr), forward_domain_(forward_domain),
74 reverse_domain_(reverse_domain), dns_client_(), dns_update_request_(),
75 dns_update_status_(
DNSClient::OTHER), dns_update_response_(),
76 forward_change_completed_(false), reverse_change_completed_(false),
77 current_server_list_(), current_server_(), next_server_pos_(0),
78 update_attempts_(0), cfg_mgr_(cfg_mgr), tsig_key_() {
87 "NameChangeRequest cannot be null");
90 if (ncr_->isForwardChange() && !(forward_domain_)) {
92 "Forward change must have a forward domain");
95 if (ncr_->isReverseChange() && !(reverse_domain_)) {
97 "Reverse change must have a reverse domain");
102 "Configuration manager cannot be null");
129 .arg(current_server_->toText())
137 std::ostringstream stream;
140 stream <<
"SUCCESS, rcode: ";
144 stream <<
" update response is NULL";
151 stream <<
"IO_STOPPED";
154 stream <<
"INVALID_RESPONSE";
166 return (stream.str());
171 std::ostringstream stream;
173 ?
"Completed, " :
"Failed, ")
176 if (ncr_->isForwardChange()) {
178 ?
" completed, " :
" failed, ");
181 if (ncr_->isReverseChange()) {
183 ?
" completed, " :
" failed, ");
186 stream <<
" request: " << ncr_->toText();
187 return (stream.str());
200 dns_client_->doUpdate(*io_service_, current_server_->getIpAddress(),
201 current_server_->getPort(), *dns_update_request_,
202 d2_params->getDnsServerTimeout(), tsig_key_);
209 .arg(current_server_->toText());
210 }
catch (
const std::exception& ex) {
299 dns_update_request_ = request;
304 dns_update_request_.reset();
309 update_attempts_ = 0;
314 dns_update_status_ = status;
319 dns_update_response_ = response;
324 dns_update_response_.reset();
329 forward_change_completed_ = value;
334 reverse_change_completed_ = value;
339 update_attempts_ = value;
346 "prepNewRequest - domain cannot be null");
359 }
catch (
const std::exception& ex) {
369 "addLeaseAddressRdata - RRset cannot cannot be null");
380 rrset->addRdata(rdata);
381 }
catch (
const std::exception& ex) {
391 "addDhcidRdata - RRset cannot cannot be null");
395 const std::vector<uint8_t>& ncr_dhcid = ncr_->getDhcid().getBytes();
398 DHCID(buffer, ncr_dhcid.size()));
399 rrset->addRdata(rdata);
400 }
catch (
const std::exception& ex) {
411 "addPtrRdata - RRset cannot cannot be null");
416 PTR(
getNcr()->getFqdn()));
417 rrset->addRdata(rdata);
418 }
catch (
const std::exception& ex) {
431 return (ncr_->getDhcid());
436 return (ncr_->getRequestId());
441 return (ncr_->getStatus());
446 return (forward_domain_);
451 return (reverse_domain_);
458 "initServerSelection called with an empty domain");
461 current_server_list_ = domain->getServers();
462 next_server_pos_ = 0;
463 current_server_.reset();
469 if ((current_server_list_) &&
470 (next_server_pos_ < current_server_list_->size())) {
471 current_server_ = (*current_server_list_)[next_server_pos_];
473 dns_update_response_.reset();
485 dns_client_.reset(
new DNSClient(dns_update_response_,
this,
499 tsig_key_ = tsig_key_info->getTSIGKey();
505 if (HooksManager::calloutsPresent(
Hooks.hooks_index_select_key_)) {
508 callout_handle->setArgument(
"current_server", current_server_);
509 callout_handle->setArgument(
"tsig_key", tsig_key_);
511 HooksManager::callCallouts(
Hooks.hooks_index_select_key_,
515 if (callout_handle->getStatus() != CalloutHandle::NEXT_STEP_CONTINUE) {
520 callout_handle->getArgument(
"tsig_key", tsig_key_);
529 return (dns_client_);
534 return (current_server_);
539 return (ncr_->setStatus(status));
544 return (dns_update_request_);
549 return (dns_update_status_);
554 return (dns_update_response_);
559 return (forward_change_completed_);
564 return (reverse_change_completed_);
569 return (update_attempts_);
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
The D2UpdateMessage encapsulates a DNS Update message.
The DNSClient class handles communication with the DNS server.
Status
A status code of the DNSClient.
@ IO_STOPPED
IO was stopped.
@ TIMEOUT
No response, timeout.
@ OTHER
Other, unclassified error.
@ INVALID_RESPONSE
Response received but invalid.
@ SUCCESS
Response received and is ok.
Thrown if the transaction encounters a general error.
static const int SELECTING_FWD_SERVER_ST
State in which forward DNS server selection is done.
void retryTransition(const int fail_to_state)
Determines the state and next event based on update attempts.
virtual void onModelFailure(const std::string &explanation)
Handler for fatal model execution errors.
virtual void operator()(DNSClient::Status status)
Serves as the DNSClient IO completion event handler.
static const int PROCESS_TRANS_FAILED_ST
State which processes an unsuccessful transaction conclusion.
static const unsigned int MAX_UPDATE_TRIES_PER_SERVER
Maximum times to attempt a single update on a given server.
static const int READY_ST
State from which a transaction is started.
const D2UpdateMessagePtr & getDnsUpdateResponse() const
Fetches the most recent DNS update response packet.
static const int PROCESS_TRANS_OK_ST
State which processes successful transaction conclusion.
static const int UPDATE_OK_EVT
Issued when the attempted update successfully completed.
const DNSClientPtr & getDNSClient() const
Fetches the DNSClient instance.
virtual void verifyStates()
Validates the contents of the set of states.
void startTransaction()
Begins execution of the transaction.
virtual D2UpdateMessagePtr prepNewRequest(DdnsDomainPtr domain)
Creates a new DNS update request based on the given domain.
static const int UPDATE_FAILED_EVT
Issued when the attempted update fails to complete.
const D2UpdateMessagePtr & getDnsUpdateRequest() const
Fetches the current DNS update request packet.
const dns::RRType & getAddressRRType() const
Returns the DHCP data type for the lease address.
const dhcp_ddns::NameChangeRequestPtr & getNcr() const
Fetches the NameChangeRequest for this transaction.
void initServerSelection(const DdnsDomainPtr &domain)
Initializes server selection from the given DDNS domain.
static const int IO_COMPLETED_EVT
Issued when a DNS update packet exchange has completed.
static const int SELECT_SERVER_EVT
Issued when a server needs to be selected.
static const int SERVER_IO_ERROR_EVT
Issued when an update fails due to an IO error.
std::string getRequestId() const
Fetches the request id that identifies this transaction.
virtual void defineStates()
Adds states defined by NameChangeTransaction to the state set.
const TransactionKey & getTransactionKey() const
Fetches the unique key that identifies this transaction.
void setUpdateAttempts(const size_t value)
Sets the update attempt count to the given value.
void addLeaseAddressRdata(dns::RRsetPtr &rrset)
Adds an RData for the lease address to the given RRset.
bool getForwardChangeCompleted() const
Returns whether the forward change has completed or not.
virtual void sendUpdate(const std::string &comment="")
Send the update request to the current server.
void setForwardChangeCompleted(const bool value)
Sets the forward change completion flag to the given value.
void addPtrRdata(dns::RRsetPtr &rrset)
Adds an RData for the lease FQDN to the given RRset.
void setDnsUpdateResponse(D2UpdateMessagePtr &response)
Sets the update response packet to the given packet.
bool selectNextServer()
Selects the next server in the current server list.
void setNcrStatus(const dhcp_ddns::NameChangeStatus &status)
Sets the status of the transaction's NameChangeRequest.
DdnsDomainPtr & getForwardDomain()
Fetches the forward DdnsDomain.
bool selectTSIGKey()
Selects the TSIG key.
virtual void verifyEvents()
Validates the contents of the set of events.
void addDhcidRdata(dns::RRsetPtr &rrset)
Adds an RData for the lease client's DHCID to the given RRset.
void clearDnsUpdateRequest()
Destroys the current update request packet.
void clearUpdateAttempts()
Resets the update attempts count.
static const int SELECTING_REV_SERVER_ST
State in which reverse DNS server selection is done.
DNSClient::Status getDnsUpdateStatus() const
Fetches the most recent DNS update status.
void setDnsUpdateStatus(const DNSClient::Status &status)
Sets the update status to the given status value.
void setDnsUpdateRequest(D2UpdateMessagePtr &request)
Sets the update request packet to the given packet.
bool getReverseChangeCompleted() const
Returns whether the reverse change has completed or not.
static const int NO_MORE_SERVERS_EVT
Issued when there are no more servers from which to select.
dhcp_ddns::NameChangeStatus getNcrStatus() const
Fetches the NameChangeRequest status of the transaction.
virtual void defineEvents()
Adds events defined by NameChangeTransaction to the event set.
void clearDnsUpdateResponse()
Destroys the current update response packet.
std::string responseString() const
Returns a string version of the current response status and rcode.
void setReverseChangeCompleted(const bool value)
Sets the reverse change completion flag to the given value.
size_t getUpdateAttempts() const
Fetches the update attempt count for the current update.
const DnsServerInfoPtr & getCurrentServer() const
Fetches the currently selected server.
static const int SERVER_SELECTED_EVT
Issued when a server has been selected.
DdnsDomainPtr & getReverseDomain()
Fetches the reverse DdnsDomain.
std::string transactionOutcomeString() const
Returns a string version of transaction outcome.
virtual ~NameChangeTransaction()
Destructor.
Container class for handling the DHCID value within a NameChangeRequest.
The Name class encapsulates DNS names.
static QidGenerator & getInstance()
Returns the singleton instance of the QidGenerator.
static const RRClass & IN()
The RRType class encapsulates DNS resource record types.
static const RRType & AAAA()
static const RRType & A()
static int registerHook(const std::string &name)
Register Hook.
const EventPtr & getEvent(unsigned int value)
Fetches the event referred to by value.
virtual void runModel(unsigned int event)
Processes events through the state model.
virtual void defineEvents()
Populates the set of events.
void postNextEvent(unsigned int event)
Sets the next event to the given event value.
virtual void verifyStates()
Validates the contents of the set of states.
unsigned int getNextEvent() const
Fetches the model's next event.
void defineEvent(unsigned int value, const std::string &label)
Adds an event value and associated label to the set of events.
void transition(unsigned int state, unsigned int event)
Sets up the model to transition into given state with a given event.
virtual void verifyEvents()
Validates the contents of the set of events.
static const int NOP_EVT
Signifies that no event has occurred.
std::string getEventLabel(const int event) const
Fetches the label associated with an event value.
void startModel(const int start_state)
Begins execution of the model.
virtual void defineStates()
Populates the set of states.
const StatePtr getStateInternal(unsigned int value)
Fetches the state referred to by value.
unsigned int getCurrState() const
Fetches the model's current state.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
const isc::log::MessageID DHCP_DDNS_STARTING_TRANSACTION
boost::shared_ptr< D2UpdateMessage > D2UpdateMessagePtr
Pointer to the DNS Update Message.
boost::shared_ptr< DdnsDomain > DdnsDomainPtr
Defines a pointer for DdnsDomain instances.
boost::shared_ptr< D2CfgMgr > D2CfgMgrPtr
Defines a shared pointer to D2CfgMgr.
boost::shared_ptr< DnsServerInfo > DnsServerInfoPtr
Defines a pointer for DnsServerInfo instances.
isc::log::Logger d2_to_dns_logger("d2-to-dns")
const isc::log::MessageID DHCP_DDNS_TRANS_SEND_ERROR
boost::shared_ptr< TSIGKeyInfo > TSIGKeyInfoPtr
Defines a pointer for TSIGKeyInfo instances.
boost::shared_ptr< DNSClient > DNSClientPtr
const isc::log::MessageID DHCP_DDNS_STATE_MODEL_UNEXPECTED_ERROR
boost::shared_ptr< D2Params > D2ParamsPtr
Defines a pointer for D2Params instances.
const isc::log::MessageID DHCP_DDNS_UPDATE_RESPONSE_RECEIVED
const isc::log::MessageID DHCP_DDNS_UPDATE_REQUEST_SENT
NameChangeStatus
Defines the runtime processing status values for requests.
boost::shared_ptr< NameChangeRequest > NameChangeRequestPtr
Defines a pointer to a NameChangeRequest.
boost::shared_ptr< const Rdata > ConstRdataPtr
boost::shared_ptr< AbstractRRset > RRsetPtr
A pointer-like type pointing to an RRset object.
boost::shared_ptr< CalloutHandle > CalloutHandlePtr
A shared pointer to a CalloutHandle object.
const int DBGLVL_TRACE_DETAIL
Trace detailed operations.
Defines the logger used by the top-level component of kea-lfc.
This file defines the class NameChangeTransaction.