23 name_change_sender_(), private_io_service_(),
24 registered_select_fd_(util::WatchSocket::SOCKET_NOT_VALID) {
38 d2_client_config_->enableUpdates(
false);
39 if (name_change_sender_) {
49 "D2ClientMgr cannot set DHCP-DDNS configuration to NULL.");
53 if (*d2_client_config_ != *new_config) {
56 if (!new_config->getEnableUpdates()) {
59 name_change_sender_.reset();
62 switch (new_config->getNcrProtocol()) {
66 new_config->getSenderIp(),
67 new_config->getSenderPort(),
68 new_config->getServerIp(),
69 new_config->getServerPort(),
70 new_config->getNcrFormat(),
72 new_config->getMaxQueueSize()));
78 << new_config->getNcrProtocol());
88 if (name_change_sender_) {
89 new_sender->assumeQueue(*name_change_sender_);
93 name_change_sender_ = new_sender;
98 d2_client_config_ = new_config;
100 .arg(!
ddnsEnabled() ?
"DHCP-DDNS updates disabled" :
101 "DHCP_DDNS updates enabled");
106 return (d2_client_config_->getEnableUpdates());
111 return (d2_client_config_);
116 bool& server_s,
bool& server_n,
131 const uint8_t mask = ((client_n ? 2 : 0) + (client_s ? 1 : 0));
148 server_n = !server_s;
156 server_n = !server_s;
162 "Invalid client FQDN - N and S cannot both be 1");
170 const bool trailing_dot)
const {
171 std::string hostname = address.
toText();
172 std::replace(hostname.begin(), hostname.end(),
173 (address.
isV4() ?
'.' :
':'),
'-');
175 std::ostringstream gen_name;
177 return (
qualifyName(gen_name.str(), ddns_params, trailing_dot));
184 const bool trailing_dot)
const {
185 std::ostringstream gen_name;
187 gen_name << partial_name;
189 if (!suffix.empty()) {
190 std::string str = gen_name.str();
191 size_t len = str.length();
192 if ((len > 0) && (str[len - 1] !=
'.')) {
199 std::string str = gen_name.str();
200 size_t len = str.length();
205 if ((len > 0) && (str[len - 1] !=
'.')) {
212 if ((len > 0) && (str[len - 1] ==
'.')) {
213 gen_name.str(str.substr(0,len-1));
218 return (gen_name.str());
232 .arg(d2_client_config_->toText());
242 if (!name_change_sender_) {
246 if (!error_handler) {
251 client_error_handler_ = error_handler;
254 name_change_sender_->startSending(io_service);
259 registered_select_fd_ = name_change_sender_->getSelectFd();
267 return (name_change_sender_ && name_change_sender_->amSending());
280 name_change_sender_->stopSending();
293 name_change_sender_->sendRequest(ncr);
294 }
catch (
const std::exception& ex) {
296 .arg(ex.what()).arg((ncr ? ncr->toText() :
" NULL "));
306 if (!client_error_handler_) {
311 (client_error_handler_)(result, ncr);
312 }
catch (
const std::exception& ex) {
321 if (!name_change_sender_) {
325 return(name_change_sender_->getQueueSize());
330 if (!name_change_sender_) {
334 return(name_change_sender_->getQueueMaxSize());
341 if (!name_change_sender_) {
345 return (name_change_sender_->peekAt(index));
350 if (!name_change_sender_) {
354 name_change_sender_->clearSendQueue();
372 " not in send mode");
375 return (name_change_sender_->getSelectFd());
380 if (!name_change_sender_) {
383 " name_change_sender is null");
386 name_change_sender_->runReadyIO();
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
const isc::log::MessageID DHCPSRV_DHCP_DDNS_NCR_REJECTED
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
void addExternalSocket(int socketfd, SocketCallback callback)
Adds external socket and a callback.
~D2ClientMgr()
Destructor.
void startSender(D2ClientErrorHandler error_handler, isc::asiolink::IOService &io_service)
Enables sending NameChangeRequests to kea-dhcp-ddns.
Result
Defines the outcome of an asynchronous NCR send.
const isc::log::MessageID DHCPSRV_DHCP_DDNS_SENDER_STARTED
virtual void operator()(const dhcp_ddns::NameChangeSender::Result result, dhcp_ddns::NameChangeRequestPtr &ncr)
Function operator implementing the NCR sender callback.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
const isc::log::MessageID DHCPSRV_DHCP_DDNS_ERROR_EXCEPTION
This file provides UDP socket based implementation for sending and receiving NameChangeRequests.
boost::shared_ptr< NameChangeRequest > NameChangeRequestPtr
Defines a pointer to a NameChangeRequest.
void sendRequest(dhcp_ddns::NameChangeRequestPtr &ncr)
Send the given NameChangeRequests to kea-dhcp-ddns.
bool isV4() const
Convenience function to check for an IPv4 address.
The IOService class is a wrapper for the ASIO io_service class.
std::string generateFqdn(const asiolink::IOAddress &address, const DdnsParams &ddns_params, const bool trailing_dot=true) const
Builds a FQDN based on the configuration and given IP address.
const isc::log::MessageID DHCPSRV_DHCP_DDNS_NCR_SENT
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
const D2ClientConfigPtr & getD2ClientConfig() const
Fetches the DHCP-DDNS configuration pointer.
An exception that is thrown if an error occurs while configuring the D2 DHCP DDNS client...
bool getEnableUpdates() const
Returns whether or not DHCP DDNS updating is enabled.
const int DHCPSRV_DBG_TRACE_DETAIL
Additional information.
Acts as a storage vault for D2 client configuration.
size_t getQueueMaxSize() const
Returns the maximum number of NCRs allowed in the queue.
void deleteExternalSocket(int socketfd)
Deletes external socket.
const dhcp_ddns::NameChangeRequestPtr & peekAt(const size_t index) const
Returns the nth NCR queued for transmission.
bool ddnsEnabled()
Convenience method for checking if DHCP-DDNS is enabled.
void clearQueue()
Removes all NCRs queued for transmission.
void invokeClientErrorHandler(const dhcp_ddns::NameChangeSender::Result result, dhcp_ddns::NameChangeRequestPtr &ncr)
Calls the client's error handler.
Provides the ability to send NameChangeRequests via UDP socket.
void analyzeFqdn(const bool client_s, const bool client_n, bool &server_s, bool &server_n, const DdnsParams &ddns_params) const
Determines server flags based on configuration and client flags.
boost::shared_ptr< NameChangeSender > NameChangeSenderPtr
Defines a smart pointer to an instance of a sender.
Convenience container for conveying DDNS behavioral parameters It is intended to be created per Packe...
Defines the logger used by the top-level component of kea-dhcp-ddns.
const isc::log::MessageID DHCPSRV_DHCP_DDNS_HANDLER_NULL
bool getOverrideClientUpdate() const
Returns whether or not Kea should perform updates, even if client requested delegation.
size_t getQueueSize() const
Returns the number of NCRs queued for transmission.
std::string qualifyName(const std::string &partial_name, const DdnsParams &ddns_params, const bool trailing_dot) const
Adds a qualifying suffix to a given domain name.
const isc::log::MessageID DHCPSRV_DHCP_DDNS_SENDER_STOPPED
static IfaceMgr & instance()
IfaceMgr is a singleton class.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
std::string toText() const
Convert the address to a string.
const int DHCPSRV_DBG_TRACE
DHCP server library logging levels.
std::string getGeneratedPrefix() const
Returns the Prefix Kea should use when generating domain-names.
void suspendUpdates()
Suspends sending requests.
Abstract interface for sending NameChangeRequests.
isc::log::Logger dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
bool getOverrideNoUpdate() const
Returns whether or not Kea should perform updates, even if client requested no updates.
int getSelectFd()
Fetches the sender's select-fd.
std::function< void(const dhcp_ddns::NameChangeSender::Result result, dhcp_ddns::NameChangeRequestPtr &ncr)> D2ClientErrorHandler
Defines the type for D2 IO error handler.
bool amSending() const
Returns true if the sender is in send mode, false otherwise.
The IOAddress class represents an IP addresses (version agnostic)
const isc::log::MessageID DHCPSRV_DHCP_DDNS_SUSPEND_UPDATES
boost::shared_ptr< D2ClientConfig > D2ClientConfigPtr
Defines a pointer for D2ClientConfig instances.
std::string getQualifyingSuffix() const
Returns the suffix Kea should use when to qualify partial domain-names.
Defines the D2ClientMgr class.
const isc::log::MessageID DHCPSRV_CFGMGR_CFG_DHCP_DDNS
void runReadyIO()
Processes sender IO events.
void setD2ClientConfig(D2ClientConfigPtr &new_config)
Updates the DHCP-DDNS client configuration to the given value.
static const int SOCKET_NOT_VALID
Value used to signify an invalid descriptor.
void stopSender()
Disables sending NameChangeRequests to kea-dhcp-ddns.