36struct CtrlDhcp6Hooks {
37 int hooks_index_dhcp6_srv_configured_;
53static const char* SERVER_DUID_FILE =
"kea-dhcp6-serverid";
64void signalHandler(
int signo) {
66 if (signo == SIGHUP) {
69 }
else if ((signo == SIGTERM) || (signo == SIGINT)) {
104 if (file_name.empty()) {
107 "use -c command line option.");
121 "a map, i.e., start with { and end with } and contain "
122 "at least an entry called 'Dhcp6' that itself is a map. "
124 <<
" is a valid JSON, but its top element is not a map."
125 " Did you forget to add { } around your configuration?");
135 "processCommand(\"config-set\", json)");
144 string reason = comment ? comment->stringValue() :
145 "no details available";
148 }
catch (
const std::exception& ex) {
154 .arg(file_name).arg(ex.what());
156 << file_name <<
"': " << ex.
what());
170 string reason = comment ? comment->stringValue() :
171 "no details available";
193ControlledDhcpv6Srv::commandShutdownHandler(
const string&,
ConstElementPtr) {
194 if (ControlledDhcpv6Srv::server_) {
195 ControlledDhcpv6Srv::server_->
shutdown();
206ControlledDhcpv6Srv::commandLibReloadHandler(
const string&,
ConstElementPtr) {
214 "Failed to reload hooks libraries.");
218 "Hooks libraries successfully reloaded.");
223ControlledDhcpv6Srv::commandConfigReloadHandler(
const string&,
230 }
catch (
const std::exception& ex) {
237 "Config reload failed:" +
string(ex.what())));
242ControlledDhcpv6Srv::commandConfigGetHandler(
const string&,
250ControlledDhcpv6Srv::commandConfigWriteHandler(
const string&,
ConstElementPtr args) {
258 if (filename_param) {
261 "passed parameter 'filename' is not a string"));
263 filename = filename_param->stringValue();
267 if (filename.empty()) {
273 if (filename.empty()) {
275 "Please specify filename explicitly."));
298 + filename +
" successful", params));
302ControlledDhcpv6Srv::commandConfigSetHandler(
const string&,
313 message =
"Missing mandatory 'arguments' parameter.";
315 dhcp6 = args->get(
"Dhcp6");
317 message =
"Missing mandatory 'Dhcp6' parameter.";
319 message =
"'Dhcp6' parameter expected to be a map.";
323 if (!message.empty()) {
341 Daemon::configureLogger(args->get(
"Logging"),
372ControlledDhcpv6Srv::commandConfigTestHandler(
const string&,
383 message =
"Missing mandatory 'arguments' parameter.";
385 dhcp6 = args->get(
"Dhcp6");
387 message =
"Missing mandatory 'Dhcp6' parameter.";
389 message =
"'Dhcp6' parameter expected to be a map.";
393 if (!message.empty()) {
410ControlledDhcpv6Srv::commandDhcpDisableHandler(
const std::string&,
412 std::ostringstream message;
413 int64_t max_period = 0;
419 message <<
"arguments for the 'dhcp-disable' command must be a map";
424 if (max_period_element) {
427 message <<
"'max-period' argument must be a number";
431 max_period = max_period_element->intValue();
432 if (max_period <= 0) {
433 message <<
"'max-period' must be positive integer";
439 network_state_->delayedEnableAll(
static_cast<unsigned>(max_period));
446 if (message.tellp() == 0) {
449 message <<
"DHCPv6 service disabled";
450 if (max_period > 0) {
451 message <<
" for " << max_period <<
" seconds";
462ControlledDhcpv6Srv::commandDhcpEnableHandler(
const std::string&,
ConstElementPtr) {
468ControlledDhcpv6Srv::commandVersionGetHandler(
const string&,
ConstElementPtr) {
471 arguments->set(
"extended", extended);
479ControlledDhcpv6Srv::commandBuildReportHandler(
const string&,
ConstElementPtr) {
486ControlledDhcpv6Srv::commandLeasesReclaimHandler(
const string&,
493 message =
"Missing mandatory 'remove' parameter.";
497 message =
"Missing mandatory 'remove' parameter.";
499 message =
"'remove' parameter expected to be a boolean.";
501 bool remove_lease = remove_name->boolValue();
502 server_->
alloc_engine_->reclaimExpiredLeases6(0, 0, remove_lease);
504 message =
"Reclamation of expired leases is complete.";
514 string txt = args ? args->str() :
"(none)";
517 .arg(command).arg(txt);
523 "Server object not initialized, can't process command '" +
524 command +
"', arguments: '" + txt +
"'.");
529 if (command ==
"shutdown") {
530 return (srv->commandShutdownHandler(command, args));
532 }
else if (command ==
"libreload") {
533 return (srv->commandLibReloadHandler(command, args));
535 }
else if (command ==
"config-reload") {
536 return (srv->commandConfigReloadHandler(command, args));
538 }
else if (command ==
"config-set") {
539 return (srv->commandConfigSetHandler(command, args));
541 }
else if (command ==
"config-get") {
542 return (srv->commandConfigGetHandler(command, args));
544 }
else if (command ==
"config-test") {
545 return (srv->commandConfigTestHandler(command, args));
547 }
else if (command ==
"dhcp-disable") {
548 return (srv->commandDhcpDisableHandler(command, args));
550 }
else if (command ==
"dhcp-enable") {
551 return (srv->commandDhcpEnableHandler(command, args));
553 }
else if (command ==
"version-get") {
554 return (srv->commandVersionGetHandler(command, args));
556 }
else if (command ==
"build-report") {
557 return (srv->commandBuildReportHandler(command, args));
559 }
else if (command ==
"leases-reclaim") {
560 return (srv->commandLeasesReclaimHandler(command, args));
562 }
else if (command ==
"config-write") {
563 return (srv->commandConfigWriteHandler(command, args));
572 + command +
"':" + ex.
what()));
587 "Server object not initialized, can't process config.");
601 }
catch (
const std::exception& ex) {
603 +
string(ex.what())));
609 boost::bind(&ControlledDhcpv6Srv::dbLostCallback, srv, _1);
611 cfg_db->setAppendedParameters(
"universe=6");
612 cfg_db->createManagers();
613 }
catch (
const std::exception& ex) {
615 + std::string(ex.what())));
621 std::string(SERVER_DUID_FILE);
630 }
catch (
const std::exception& ex) {
631 std::ostringstream err;
632 err <<
"unable to configure server identifier: " << ex.what();
639 }
catch (
const std::exception& ex) {
640 std::ostringstream err;
641 err <<
"error starting DHCP_DDNS client "
642 " after server reconfiguration: " << ex.what();
649 }
catch (
const std::exception& ex) {
650 std::ostringstream err;
651 err <<
"error starting DHCPv4-over-DHCPv6 IPC "
652 " after server reconfiguration: " << ex.what();
665 }
catch (
const std::exception& ex) {
666 std::ostringstream err;
667 err <<
"Error setting packet queue controls after server reconfiguration: "
684 setupTimers(&ControlledDhcpv6Srv::reclaimExpiredLeases,
685 &ControlledDhcpv6Srv::deleteExpiredReclaimedLeases,
688 }
catch (
const std::exception& ex) {
689 std::ostringstream err;
690 err <<
"unable to setup timers for periodically running the"
691 " reclamation of the expired leases: "
708 callout_handle->setArgument(
"io_context", srv->
getIOService());
710 callout_handle->setArgument(
"json_config", config);
711 callout_handle->setArgument(
"server_config",
CfgMgr::instance().getStagingCfg());
733 "Server object not initialized, can't process config.");
744 "There is another Dhcpv6Srv instance already.");
757 boost::bind(&ControlledDhcpv6Srv::commandBuildReportHandler,
this, _1, _2));
760 boost::bind(&ControlledDhcpv6Srv::commandConfigGetHandler,
this, _1, _2));
763 boost::bind(&ControlledDhcpv6Srv::commandConfigReloadHandler,
this, _1, _2));
766 boost::bind(&ControlledDhcpv6Srv::commandConfigTestHandler,
this, _1, _2));
769 boost::bind(&ControlledDhcpv6Srv::commandConfigWriteHandler,
this, _1, _2));
772 boost::bind(&ControlledDhcpv6Srv::commandDhcpDisableHandler,
this, _1, _2));
775 boost::bind(&ControlledDhcpv6Srv::commandDhcpEnableHandler,
this, _1, _2));
778 boost::bind(&ControlledDhcpv6Srv::commandLeasesReclaimHandler,
this, _1, _2));
781 boost::bind(&ControlledDhcpv6Srv::commandLibReloadHandler,
this, _1, _2));
784 boost::bind(&ControlledDhcpv6Srv::commandConfigSetHandler,
this, _1, _2));
787 boost::bind(&ControlledDhcpv6Srv::commandShutdownHandler,
this, _1, _2));
790 boost::bind(&ControlledDhcpv6Srv::commandVersionGetHandler,
this, _1, _2));
825 timer_mgr_->unregisterTimers();
860void ControlledDhcpv6Srv::sessionReader(
void) {
864 server_->io_service_.
run_one();
869ControlledDhcpv6Srv::reclaimExpiredLeases(
const size_t max_leases,
870 const uint16_t timeout,
871 const bool remove_lease,
872 const uint16_t max_unwarned_cycles) {
873 server_->
alloc_engine_->reclaimExpiredLeases6(max_leases, timeout,
875 max_unwarned_cycles);
881ControlledDhcpv6Srv::deleteExpiredReclaimedLeases(
const uint32_t secs) {
889 bool reopened =
false;
894 cfg_db->createManagers();
896 }
catch (
const std::exception& ex) {
909 db_reconnect_ctl.reset();
911 if (!db_reconnect_ctl->checkRetries()) {
913 .arg(db_reconnect_ctl->maxRetries());
919 .arg(db_reconnect_ctl->maxRetries() - db_reconnect_ctl->retriesLeft() + 1)
920 .arg(db_reconnect_ctl->maxRetries())
921 .arg(db_reconnect_ctl->retryInterval());
925 boost::bind(&ControlledDhcpv6Srv::dbReconnect,
this,
927 db_reconnect_ctl->retryInterval(),
940 if (!db_reconnect_ctl) {
947 if (!db_reconnect_ctl->retriesLeft() ||
948 !db_reconnect_ctl->retryInterval()) {
950 .arg(db_reconnect_ctl->retriesLeft())
951 .arg(db_reconnect_ctl->retryInterval());
956 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.
std::string getDataDir() const
returns path do the data directory
void commit()
Commits the staging configuration.
SrvConfigPtr getCurrentCfg()
Returns a pointer to the current configuration.
Controlled version of the DHCPv6 server.
void init(const std::string &config_file)
Initializes the server.
void cleanup()
Performs cleanup, immediately before termination.
isc::data::ConstElementPtr checkConfig(isc::data::ConstElementPtr new_config)
Configuration checker.
static isc::data::ConstElementPtr processConfig(isc::data::ConstElementPtr new_config)
configuration processor
ControlledDhcpv6Srv(uint16_t port=DHCP6_SERVER_PORT)
Constructor.
virtual ~ControlledDhcpv6Srv()
Destructor.
void shutdown()
Initiates shutdown procedure for the whole DHCPv6 server.
static ControlledDhcpv6Srv * getInstance()
returns pointer to the sole instance of Dhcpv6Srv
isc::data::ConstElementPtr loadConfigFile(const std::string &file_name)
Loads specific configuration file.
static isc::data::ConstElementPtr processCommand(const std::string &command, isc::data::ConstElementPtr args)
command processor
virtual void open()
Open communication socket.
static Dhcp6to4Ipc & instance()
Returns pointer to the sole instance of Dhcp6to4Ipc.
boost::shared_ptr< AllocEngine > alloc_engine_
Allocation Engine.
OptionPtr serverid_
Server DUID (to be sent in server-identifier option)
void shutdown()
Instructs the server to shut down.
NetworkStatePtr & getNetworkState()
Returns pointer to the network state used by the server.
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 std::string getVersion(bool extended)
returns Kea version on stdout and exit.
asiolink::IOServicePtr & getIOService()
Returns pointer to the IO service used by the server.
void startD2()
Starts DHCP_DDNS client IO if DDNS updates are enabled.
static IfaceMgr & instance()
IfaceMgr is a singleton class.
static void commitRuntimeOptionDefs()
Commits runtime option definitions.
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_DHCP6
This parser will parse the content as Dhcp6 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 ...
Defines the Dhcp6to4Ipc 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()
isc::data::ConstElementPtr configureDhcp6Server(Dhcpv6Srv &server, isc::data::ConstElementPtr config_set, bool check_only)
Configures DHCPv6 server.
boost::shared_ptr< CfgDbAccess > CfgDbAccessPtr
A pointer to the CfgDbAccess.
boost::shared_ptr< DUID > DuidPtr
const int DBG_DHCP6_COMMAND
Debug level used to log receiving commands.
isc::log::Logger dhcp6_logger(DHCP6_APP_LOGGER_NAME)
Base logger for DHCPv6 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.