36struct CtrlDhcp4Hooks {
37 int hooks_index_dhcp4_srv_configured_;
61void signalHandler(
int signo) {
63 if (signo == SIGHUP) {
66 }
else if ((signo == SIGTERM) || (signo == SIGINT)) {
86 string reason = comment ? comment->stringValue() :
87 "no details available";
129 if (file_name.empty()) {
132 " Please use -c command line option.");
146 "a map, i.e., start with { and end with } and contain "
147 "at least an entry called 'Dhcp4' that itself is a map. "
149 <<
" is a valid JSON, but its top element is not a map."
150 " Did you forget to add { } around your configuration?");
160 "processCommand(\"config-set\", json)");
168 string reason = comment ? comment->stringValue() :
169 "no details available";
172 }
catch (
const std::exception& ex) {
178 .arg(file_name).arg(ex.what());
180 << file_name <<
"': " << ex.
what());
188ControlledDhcpv4Srv::commandShutdownHandler(
const string&,
ConstElementPtr) {
194 "Shutdown failure.");
202ControlledDhcpv4Srv::commandLibReloadHandler(
const string&,
ConstElementPtr) {
211 "Failed to reload hooks libraries.");
215 "Hooks libraries successfully reloaded.");
220ControlledDhcpv4Srv::commandConfigReloadHandler(
const string&,
228 }
catch (
const std::exception& ex) {
235 "Config reload failed:" +
string(ex.what())));
240ControlledDhcpv4Srv::commandConfigGetHandler(
const string&,
248ControlledDhcpv4Srv::commandConfigWriteHandler(
const string&,
257 if (filename_param) {
260 "passed parameter 'filename' is not a string"));
262 filename = filename_param->stringValue();
266 if (filename.empty()) {
271 if (filename.empty()) {
273 "Please specify filename explicitly."));
296 + filename +
" successful", params));
300ControlledDhcpv4Srv::commandConfigSetHandler(
const string&,
311 message =
"Missing mandatory 'arguments' parameter.";
313 dhcp4 = args->get(
"Dhcp4");
315 message =
"Missing mandatory 'Dhcp4' parameter.";
317 message =
"'Dhcp4' parameter expected to be a map.";
321 if (!message.empty()) {
339 Daemon::configureLogger(args->get(
"Logging"),
370ControlledDhcpv4Srv::commandConfigTestHandler(
const string&,
381 message =
"Missing mandatory 'arguments' parameter.";
383 dhcp4 = args->get(
"Dhcp4");
385 message =
"Missing mandatory 'Dhcp4' parameter.";
387 message =
"'Dhcp4' parameter expected to be a map.";
391 if (!message.empty()) {
408ControlledDhcpv4Srv::commandDhcpDisableHandler(
const std::string&,
410 std::ostringstream message;
411 int64_t max_period = 0;
417 message <<
"arguments for the 'dhcp-disable' command must be a map";
422 if (max_period_element) {
425 message <<
"'max-period' argument must be a number";
429 max_period = max_period_element->intValue();
430 if (max_period <= 0) {
431 message <<
"'max-period' must be positive integer";
437 network_state_->delayedEnableAll(
static_cast<unsigned>(max_period));
444 if (message.tellp() == 0) {
447 message <<
"DHCPv4 service disabled";
448 if (max_period > 0) {
449 message <<
" for " << max_period <<
" seconds";
460ControlledDhcpv4Srv::commandDhcpEnableHandler(
const std::string&,
ConstElementPtr) {
466ControlledDhcpv4Srv::commandVersionGetHandler(
const string&,
ConstElementPtr) {
469 arguments->set(
"extended", extended);
477ControlledDhcpv4Srv::commandBuildReportHandler(
const string&,
485ControlledDhcpv4Srv::commandLeasesReclaimHandler(
const string&,
492 message =
"Missing mandatory 'remove' parameter.";
496 message =
"Missing mandatory 'remove' parameter.";
498 message =
"'remove' parameter expected to be a boolean.";
500 bool remove_lease = remove_name->boolValue();
501 server_->
alloc_engine_->reclaimExpiredLeases4(0, 0, remove_lease);
503 message =
"Reclamation of expired leases is complete.";
513 string txt = args ? args->str() :
"(none)";
516 .arg(command).arg(txt);
522 "Server object not initialized, so can't process command '" +
523 command +
"', arguments: '" + txt +
"'.");
528 if (command ==
"shutdown") {
529 return (srv->commandShutdownHandler(command, args));
531 }
else if (command ==
"libreload") {
532 return (srv->commandLibReloadHandler(command, args));
534 }
else if (command ==
"config-reload") {
535 return (srv->commandConfigReloadHandler(command, args));
537 }
else if (command ==
"config-set") {
538 return (srv->commandConfigSetHandler(command, args));
540 }
else if (command ==
"config-get") {
541 return (srv->commandConfigGetHandler(command, args));
543 }
else if (command ==
"config-test") {
544 return (srv->commandConfigTestHandler(command, args));
546 }
else if (command ==
"dhcp-disable") {
547 return (srv->commandDhcpDisableHandler(command, args));
549 }
else if (command ==
"dhcp-enable") {
550 return (srv->commandDhcpEnableHandler(command, args));
552 }
else if (command ==
"version-get") {
553 return (srv->commandVersionGetHandler(command, args));
555 }
else if (command ==
"build-report") {
556 return (srv->commandBuildReportHandler(command, args));
558 }
else if (command ==
"leases-reclaim") {
559 return (srv->commandLeasesReclaimHandler(command, args));
561 }
else if (command ==
"config-write") {
562 return (srv->commandConfigWriteHandler(command, args));
566 "Unrecognized command:" + command);
570 + command +
"':" + ex.
what() +
571 ", params: '" + txt +
"'"));
584 std::ostringstream err;
587 err <<
"Server object not initialized, can't process config.";
601 }
catch (
const std::exception& ex) {
602 err <<
"Failed to process configuration:" << ex.what();
609 boost::bind(&ControlledDhcpv4Srv::dbLostCallback, srv, _1);
611 cfg_db->setAppendedParameters(
"universe=4");
612 cfg_db->createManagers();
613 }
catch (
const std::exception& ex) {
614 err <<
"Unable to open database: " << ex.what();
621 }
catch (
const std::exception& ex) {
622 err <<
"Error starting DHCP_DDNS client after server reconfiguration: "
630 }
catch (
const std::exception& ex) {
631 std::ostringstream err;
632 err <<
"error starting DHCPv4-over-DHCPv6 IPC "
633 " after server reconfiguration: " << ex.what();
646 }
catch (
const std::exception& ex) {
647 err <<
"Error setting packet queue controls after server reconfiguration: "
665 setupTimers(&ControlledDhcpv4Srv::reclaimExpiredLeases,
666 &ControlledDhcpv4Srv::deleteExpiredReclaimedLeases,
669 }
catch (
const std::exception& ex) {
670 err <<
"unable to setup timers for periodically running the"
671 " reclamation of the expired leases: "
684 callout_handle->setArgument(
"io_context", srv->
getIOService());
686 callout_handle->setArgument(
"json_config", config);
687 callout_handle->setArgument(
"server_config",
CfgMgr::instance().getStagingCfg());
708 std::ostringstream err;
711 err <<
"Server object not initialized, can't process config.";
722 "There is another Dhcpv4Srv instance already.");
735 boost::bind(&ControlledDhcpv4Srv::commandBuildReportHandler,
this, _1, _2));
738 boost::bind(&ControlledDhcpv4Srv::commandConfigGetHandler,
this, _1, _2));
741 boost::bind(&ControlledDhcpv4Srv::commandConfigReloadHandler,
this, _1, _2));
744 boost::bind(&ControlledDhcpv4Srv::commandConfigSetHandler,
this, _1, _2));
747 boost::bind(&ControlledDhcpv4Srv::commandConfigTestHandler,
this, _1, _2));
750 boost::bind(&ControlledDhcpv4Srv::commandConfigWriteHandler,
this, _1, _2));
753 boost::bind(&ControlledDhcpv4Srv::commandDhcpEnableHandler,
this, _1, _2));
756 boost::bind(&ControlledDhcpv4Srv::commandDhcpDisableHandler,
this, _1, _2));
759 boost::bind(&ControlledDhcpv4Srv::commandLibReloadHandler,
this, _1, _2));
762 boost::bind(&ControlledDhcpv4Srv::commandLeasesReclaimHandler,
this, _1, _2));
765 boost::bind(&ControlledDhcpv4Srv::commandShutdownHandler,
this, _1, _2));
768 boost::bind(&ControlledDhcpv4Srv::commandVersionGetHandler,
this, _1, _2));
804 timer_mgr_->unregisterTimers();
839void ControlledDhcpv4Srv::sessionReader(
void) {
848ControlledDhcpv4Srv::reclaimExpiredLeases(
const size_t max_leases,
849 const uint16_t timeout,
850 const bool remove_lease,
851 const uint16_t max_unwarned_cycles) {
852 server_->
alloc_engine_->reclaimExpiredLeases4(max_leases, timeout,
854 max_unwarned_cycles);
860ControlledDhcpv4Srv::deleteExpiredReclaimedLeases(
const uint32_t secs) {
868 bool reopened =
false;
873 cfg_db->createManagers();
875 }
catch (
const std::exception& ex) {
889 db_reconnect_ctl.reset();
891 if (!db_reconnect_ctl->checkRetries()) {
893 .arg(db_reconnect_ctl->maxRetries());
899 .arg(db_reconnect_ctl->maxRetries() - db_reconnect_ctl->retriesLeft() + 1)
900 .arg(db_reconnect_ctl->maxRetries())
901 .arg(db_reconnect_ctl->retryInterval());
905 boost::bind(&ControlledDhcpv4Srv::dbReconnect,
this,
907 db_reconnect_ctl->retryInterval(),
920 if (!db_reconnect_ctl) {
927 if (!db_reconnect_ctl->retriesLeft() ||
928 !db_reconnect_ctl->retryInterval()) {
930 .arg(db_reconnect_ctl->retriesLeft())
931 .arg(db_reconnect_ctl->retryInterval());
936 dbReconnect(db_reconnect_ctl);
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
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.
A generic exception that is thrown if a function is called in a prohibited way.
void run_one()
Run the underlying event loop for a single event.
void stop()
Stop the underlying event loop.
void registerCommand(const std::string &cmd, CommandHandler handler)
Registers specified command handler for a given command.
void deregisterCommand(const std::string &cmd)
Deregisters specified command handler.
void closeCommandSocket()
Shuts down any open control sockets.
static CommandMgr & instance()
CommandMgr is a singleton class.
void setIOService(const asiolink::IOServicePtr &io_service)
Sets IO service to be used by the command manager.
static ElementPtr create(const Position &pos=ZERO_POSITION())
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
static DbLostCallback db_lost_callback
Optional call back function to invoke if a successfully open connection subsequently fails.
static const std::string FLUSH_RECLAIMED_TIMER_NAME
Name of the timer for flushing reclaimed leases.
static const std::string RECLAIM_EXPIRED_TIMER_NAME
Name of the timer for reclaiming expired leases.
void rollback()
Removes staging configuration.
static CfgMgr & instance()
returns a single instance of Configuration Manager
SrvConfigPtr getStagingCfg()
Returns a pointer to the staging configuration.
void commit()
Commits the staging configuration.
SrvConfigPtr getCurrentCfg()
Returns a pointer to the current configuration.
Controlled version of the DHCPv4 server.
static isc::data::ConstElementPtr processConfig(isc::data::ConstElementPtr new_config)
Configuration processor.
~ControlledDhcpv4Srv()
Destructor.
void shutdown()
Initiates shutdown procedure for the whole DHCPv4 server.
isc::data::ConstElementPtr loadConfigFile(const std::string &file_name)
Loads specific config file.
void cleanup()
Performs cleanup, immediately before termination.
static isc::data::ConstElementPtr processCommand(const std::string &command, isc::data::ConstElementPtr args)
Command processor.
void init(const std::string &config_file)
Initializes the server.
ControlledDhcpv4Srv(uint16_t port=DHCP4_SERVER_PORT)
Constructor.
static ControlledDhcpv4Srv * getInstance()
Returns pointer to the sole instance of Dhcpv4Srv.
isc::data::ConstElementPtr checkConfig(isc::data::ConstElementPtr new_config)
Configuration checker.
static Dhcp4to6Ipc & instance()
Returns pointer to the sole instance of Dhcp4to6Ipc.
virtual void open()
Open communication socket.
void shutdown()
Instructs the server to shut down.
void startD2()
Starts DHCP_DDNS client IO if DDNS updates are enabled.
asiolink::IOServicePtr & getIOService()
Returns pointer to the IO service used by the server.
boost::shared_ptr< AllocEngine > alloc_engine_
Allocation Engine.
NetworkStatePtr & getNetworkState()
Returns pointer to the network state used by the server.
static std::string getVersion(bool extended)
returns Kea version on stdout and exit.
bool useBroadcast() const
Return bool value indicating that broadcast flags should be set on sockets.
NetworkStatePtr network_state_
Holds information about disabled DHCP service and/or disabled subnet/network scopes.
uint16_t getPort() const
Get UDP port on which server should listen.
static IfaceMgr & instance()
IfaceMgr is a singleton class.
Evaluation context, an interface to the expression evaluation.
isc::data::ElementPtr parseFile(const std::string &filename, ParserType parser_type)
Run the parser on the file specified.
@ PARSER_DHCP4
This parser will parse the content as Dhcp4 config wrapped in a map (that's the regular config file)
Manages a pool of asynchronous interval timers.
static const TimerMgrPtr & instance()
Returns pointer to the sole instance of the TimerMgr.
static int registerHook(const std::string &name)
Register Hook.
static bool calloutsPresent(int index)
Are callouts present?
static bool loadLibraries(const HookLibsCollection &libraries)
Load and reload libraries.
static boost::shared_ptr< CalloutHandle > createCalloutHandle()
Return callout handle.
static void callCallouts(int index, CalloutHandle &handle)
Calls the callouts for a given hook.
static HookLibsCollection getLibraryInfo()
Return list of loaded libraries with its parameters.
std::string getConfigFile() const
Returns config file name.
virtual size_t writeConfigFile(const std::string &config_file, isc::data::ConstElementPtr cfg=isc::data::ConstElementPtr()) const
Writes current configuration to specified file.
isc::util::SignalSetPtr signal_set_
A pointer to the object installing custom signal handlers.
isc::util::SignalHandler signal_handler_
Pointer to the common signal handler invoked by the handleSignal function.
Represents a collection of signals handled in a customized way.
This file contains several functions and constants that are used for handling commands and responses ...
Contains declarations for loggers used by the DHCPv4 server component.
Defines the Dhcp4o6Ipc class.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
static isc::data::ConstElementPtr statisticResetHandler(const std::string &name, const isc::data::ConstElementPtr ¶ms)
Handles statistic-reset command.
static isc::data::ConstElementPtr statisticResetAllHandler(const std::string &name, const isc::data::ConstElementPtr ¶ms)
Handles statistic-reset-all command.
static isc::data::ConstElementPtr statisticRemoveHandler(const std::string &name, const isc::data::ConstElementPtr ¶ms)
Handles statistic-remove command.
static isc::data::ConstElementPtr statisticRemoveAllHandler(const std::string &name, const isc::data::ConstElementPtr ¶ms)
Handles statistic-remove-all command.
static isc::data::ConstElementPtr statisticGetHandler(const std::string &name, const isc::data::ConstElementPtr ¶ms)
Handles statistic-get command.
static isc::data::ConstElementPtr statisticGetAllHandler(const std::string &name, const isc::data::ConstElementPtr ¶ms)
Handles statistic-get-all command.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
const int CONTROL_RESULT_ERROR
Status code indicating a general failure.
ConstElementPtr createAnswer()
Creates a standard config/command level success answer message (i.e.
ConstElementPtr parseAnswer(int &rcode, const ConstElementPtr &msg)
const int CONTROL_RESULT_SUCCESS
Status code indicating a successful operation.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
boost::shared_ptr< ReconnectCtl > ReconnectCtlPtr
Pointer to an instance of ReconnectCtl.
std::string getConfigReport()
boost::shared_ptr< CfgDbAccess > CfgDbAccessPtr
A pointer to the CfgDbAccess.
isc::data::ConstElementPtr configureDhcp4Server(Dhcpv4Srv &server, isc::data::ConstElementPtr config_set, bool check_only)
Configure DHCPv4 server (Dhcpv4Srv) with a set of configuration values.
const int DBG_DHCP4_COMMAND
Debug level used to log receiving commands.
isc::log::Logger dhcp4_logger(DHCP4_APP_LOGGER_NAME)
Base logger for DHCPv4 server.
std::vector< HookLibInfo > HookLibsCollection
A storage for information about hook libraries.
boost::shared_ptr< CalloutHandle > CalloutHandlePtr
A shared pointer to a CalloutHandle object.
Defines the logger used by the top-level component of kea-dhcp-ddns.