43 namespace ph = std::placeholders;
48 struct CtrlDhcp4Hooks {
49 int hooks_index_dhcp4_srv_configured_;
53 hooks_index_dhcp4_srv_configured_ = HooksManager::registerHook(
"dhcp4_srv_configured");
73 void signalHandler(
int signo) {
75 if (signo == SIGHUP) {
76 ControlledDhcpv4Srv::processCommand(
"config-reload",
78 }
else if ((signo == SIGTERM) || (signo == SIGINT)) {
79 ControlledDhcpv4Srv::processCommand(
"shutdown",
92 ControlledDhcpv4Srv::init(
const std::string& file_name) {
94 start_ = boost::posix_time::second_clock::universal_time();
102 string reason = comment ? comment->stringValue() :
103 "no details available";
114 signal_set_.reset(
new IOSignalSet(getIOService(), signalHandler));
116 signal_set_->add(SIGINT);
117 signal_set_->add(SIGHUP);
118 signal_set_->add(SIGTERM);
121 void ControlledDhcpv4Srv::cleanup() {
126 ControlledDhcpv4Srv::loadConfigFile(
const std::string& file_name) {
135 if (file_name.empty()) {
138 " Please use -c command line option.");
143 json = parser.
parseFile(file_name, Parser4Context::PARSER_DHCP4);
152 "a map, i.e., start with { and end with } and contain "
153 "at least an entry called 'Dhcp4' that itself is a map. "
155 <<
" is a valid JSON, but its top element is not a map."
156 " Did you forget to add { } around your configuration?");
160 result = ControlledDhcpv4Srv::processCommand(
"config-set", json);
166 "processCommand(\"config-set\", json)");
174 string reason = comment ? comment->stringValue() :
175 "no details available";
178 }
catch (
const std::exception& ex) {
181 CfgMgr::instance().rollback();
184 .arg(file_name).arg(ex.what());
186 << file_name <<
"': " << ex.
what());
190 .arg(MultiThreadingMgr::instance().getMode() ?
"yes" :
"no")
191 .arg(MultiThreadingMgr::instance().getThreadPoolSize())
192 .arg(MultiThreadingMgr::instance().getPacketQueueSize());
198 ControlledDhcpv4Srv::commandShutdownHandler(
const string&,
ConstElementPtr args) {
199 if (!ControlledDhcpv4Srv::getInstance()) {
207 if (args->getType() != Element::map) {
213 if (param->getType() != Element::integer) {
215 "parameter 'exit-value' is not an integer"));
218 exit_value = param->intValue();
222 ControlledDhcpv4Srv::getInstance()->shutdownServer(exit_value);
227 ControlledDhcpv4Srv::commandLibReloadHandler(
const string&,
ConstElementPtr) {
232 MultiThreadingMgr::instance().getThreadPool().reset();
237 HooksManager::prepareUnloadLibraries();
238 static_cast<void>(HooksManager::unloadLibraries());
239 bool status = HooksManager::loadLibraries(loaded);
241 isc_throw(Unexpected,
"Failed to reload hooks libraries.");
243 }
catch (
const std::exception& ex) {
249 "Hooks libraries successfully reloaded.");
254 ControlledDhcpv4Srv::commandConfigReloadHandler(
const string&,
257 std::string file = ControlledDhcpv4Srv::getInstance()->getConfigFile();
260 return (loadConfigFile(file));
261 }
catch (
const std::exception& ex) {
268 "Config reload failed: " +
string(ex.what())));
273 ControlledDhcpv4Srv::commandConfigGetHandler(
const string&,
275 ConstElementPtr config = CfgMgr::instance().getCurrentCfg()->toElement();
281 ControlledDhcpv4Srv::commandConfigWriteHandler(
const string&,
286 if (args->getType() != Element::map) {
290 if (filename_param) {
291 if (filename_param->getType() != Element::string) {
293 "passed parameter 'filename' is not a string"));
295 filename = filename_param->stringValue();
299 if (filename.empty()) {
302 filename = getConfigFile();
305 if (filename.empty()) {
307 "Please specify filename explicitly."));
314 size = writeConfigFile(filename, cfg);
326 params->set(
"size", Element::create(static_cast<long long>(size)));
327 params->set(
"filename", Element::create(filename));
330 + filename +
" successful", params));
334 ControlledDhcpv4Srv::commandConfigSetHandler(
const string&,
343 message =
"Missing mandatory 'arguments' parameter.";
345 dhcp4 = args->get(
"Dhcp4");
347 message =
"Missing mandatory 'Dhcp4' parameter.";
348 }
else if (dhcp4->getType() != Element::map) {
349 message =
"'Dhcp4' parameter expected to be a map.";
354 if (message.empty()) {
355 for (
auto obj : args->mapValue()) {
356 const string& obj_name = obj.first;
357 if (obj_name !=
"Dhcp4") {
360 if (message.empty()) {
361 message =
"Unsupported '" + obj_name +
"' parameter";
363 message +=
" (and '" + obj_name +
"')";
367 if (!message.empty()) {
372 if (!message.empty()) {
385 MultiThreadingMgr::instance().apply(
false, 0, 0);
390 CfgMgr::instance().rollback();
396 Daemon::configureLogger(dhcp4, CfgMgr::instance().getStagingCfg());
400 CfgMgr::instance().getStagingCfg()->applyLoggingCfg();
411 CfgMgr::instance().getStagingCfg()->applyLoggingCfg();
414 CfgMgr::instance().commit();
419 CfgMgr::instance().getCurrentCfg()->applyLoggingCfg();
421 if (CfgMgr::instance().getCurrentCfg()->getSequence() != 0) {
433 ControlledDhcpv4Srv::commandConfigTestHandler(
const string&,
442 message =
"Missing mandatory 'arguments' parameter.";
444 dhcp4 = args->get(
"Dhcp4");
446 message =
"Missing mandatory 'Dhcp4' parameter.";
447 }
else if (dhcp4->getType() != Element::map) {
448 message =
"'Dhcp4' parameter expected to be a map.";
453 if (message.empty()) {
454 for (
auto obj : args->mapValue()) {
455 const string& obj_name = obj.first;
456 if (obj_name !=
"Dhcp4") {
459 if (message.empty()) {
460 message =
"Unsupported '" + obj_name +
"' parameter";
462 message +=
" (and '" + obj_name +
"')";
466 if (!message.empty()) {
471 if (!message.empty()) {
484 CfgMgr::instance().rollback();
487 return (checkConfig(dhcp4));
491 ControlledDhcpv4Srv::commandDhcpDisableHandler(
const std::string&,
493 std::ostringstream message;
494 int64_t max_period = 0;
505 if (args->getType() != Element::map) {
506 message <<
"arguments for the 'dhcp-disable' command must be a map";
511 if (max_period_element) {
513 if (max_period_element->getType() != Element::integer) {
514 message <<
"'max-period' argument must be a number";
518 max_period = max_period_element->intValue();
519 if (max_period <= 0) {
520 message <<
"'max-period' must be positive integer";
526 if (origin_element) {
528 if (origin_element->getType() != Element::string) {
529 message <<
"'origin' argument must be a string";
532 origin = origin_element->stringValue();
533 if (origin ==
"ha-partner") {
534 type = NetworkState::Origin::HA_COMMAND;
535 }
else if (origin !=
"user") {
536 if (origin.empty()) {
537 origin =
"(empty string)";
539 message <<
"invalid value used for 'origin' parameter: "
548 if (message.tellp() == 0) {
549 message <<
"DHCPv4 service disabled";
550 if (max_period > 0) {
551 message <<
" for " << max_period <<
" seconds";
556 network_state_->delayedEnableAll(static_cast<unsigned>(max_period),
559 network_state_->disableService(type);
570 ControlledDhcpv4Srv::commandDhcpEnableHandler(
const std::string&,
572 std::ostringstream message;
582 if (args->getType() != Element::map) {
583 message <<
"arguments for the 'dhcp-enable' command must be a map";
588 if (origin_element) {
590 if (origin_element->getType() != Element::string) {
591 message <<
"'origin' argument must be a string";
594 origin = origin_element->stringValue();
595 if (origin ==
"ha-partner") {
596 type = NetworkState::Origin::HA_COMMAND;
597 }
else if (origin !=
"user") {
598 if (origin.empty()) {
599 origin =
"(empty string)";
601 message <<
"invalid value used for 'origin' parameter: "
610 if (message.tellp() == 0) {
611 network_state_->enableService(type);
615 "DHCP service successfully enabled"));
623 ControlledDhcpv4Srv::commandVersionGetHandler(
const string&,
ConstElementPtr) {
624 ElementPtr extended = Element::create(Dhcpv4Srv::getVersion(
true));
626 arguments->set(
"extended", extended);
628 Dhcpv4Srv::getVersion(
false),
634 ControlledDhcpv4Srv::commandBuildReportHandler(
const string&,
642 ControlledDhcpv4Srv::commandLeasesReclaimHandler(
const string&,
649 message =
"Missing mandatory 'remove' parameter.";
653 message =
"Missing mandatory 'remove' parameter.";
654 }
else if (remove_name->getType() != Element::boolean) {
655 message =
"'remove' parameter expected to be a boolean.";
657 bool remove_lease = remove_name->boolValue();
658 server_->alloc_engine_->reclaimExpiredLeases4(0, 0, remove_lease);
660 message =
"Reclamation of expired leases is complete.";
668 ControlledDhcpv4Srv::commandServerTagGetHandler(
const std::string&,
670 const std::string& tag =
671 CfgMgr::instance().getCurrentCfg()->getServerTag();
673 response->set(
"server-tag", Element::create(tag));
679 ControlledDhcpv4Srv::commandConfigBackendPullHandler(
const std::string&,
681 auto ctl_info = CfgMgr::instance().getCurrentCfg()->getConfigControlInfo();
690 if (TimerMgr::instance()->isTimerRegistered(
"Dhcp4CBFetchTimer")) {
691 TimerMgr::instance()->cancel(
"Dhcp4CBFetchTimer");
692 TimerMgr::instance()->setup(
"Dhcp4CBFetchTimer");
699 auto srv_cfg = CfgMgr::instance().getCurrentCfg();
700 auto mode = CBControlDHCPv4::FetchMode::FETCH_UPDATE;
701 server_->getCBControl()->databaseConfigFetch(srv_cfg, mode);
702 }
catch (
const std::exception& ex) {
706 "On demand configuration update failed: " +
710 "On demand configuration update successful."));
714 ControlledDhcpv4Srv::commandStatusGetHandler(
const string&,
717 status->set(
"pid", Element::create(static_cast<int>(getpid())));
719 auto now = boost::posix_time::second_clock::universal_time();
721 if (!start_.is_not_a_date_time()) {
722 auto uptime = now - start_;
723 status->set(
"uptime", Element::create(uptime.total_seconds()));
726 auto last_commit = CfgMgr::instance().getCurrentCfg()->getLastCommitTime();
727 if (!last_commit.is_not_a_date_time()) {
728 auto reload = now - last_commit;
729 status->set(
"reload", Element::create(reload.total_seconds()));
732 auto& mt_mgr = MultiThreadingMgr::instance();
733 if (mt_mgr.getMode()) {
734 status->set(
"multi-threading-enabled", Element::create(
true));
735 status->set(
"thread-pool-size", Element::create(static_cast<int32_t>(
736 MultiThreadingMgr::instance().getThreadPoolSize())));
737 status->set(
"packet-queue-size", Element::create(static_cast<int32_t>(
738 MultiThreadingMgr::instance().getPacketQueueSize())));
739 ElementPtr queue_stats = Element::createList();
740 queue_stats->add(Element::create(mt_mgr.getThreadPool().getQueueStat(10)));
741 queue_stats->add(Element::create(mt_mgr.getThreadPool().getQueueStat(100)));
742 queue_stats->add(Element::create(mt_mgr.getThreadPool().getQueueStat(1000)));
743 status->set(
"packet-queue-statistics", queue_stats);
746 status->set(
"multi-threading-enabled", Element::create(
false));
753 ControlledDhcpv4Srv::commandStatisticSetMaxSampleCountAllHandler(
const string&,
755 StatsMgr& stats_mgr = StatsMgr::instance();
759 CfgMgr::instance().getCurrentCfg()->addConfiguredGlobal(
760 "statistic-default-sample-count", Element::create(max_samples));
765 ControlledDhcpv4Srv::commandStatisticSetMaxSampleAgeAllHandler(
const string&,
767 StatsMgr& stats_mgr = StatsMgr::instance();
772 CfgMgr::instance().getCurrentCfg()->addConfiguredGlobal(
773 "statistic-default-sample-age", Element::create(max_age));
778 ControlledDhcpv4Srv::processCommand(
const string& command,
780 string txt = args ? args->str() :
"(none)";
783 .arg(command).arg(txt);
789 "Server object not initialized, so can't process command '" +
790 command +
"', arguments: '" + txt +
"'.");
795 if (command ==
"shutdown") {
796 return (srv->commandShutdownHandler(command, args));
798 }
else if (command ==
"libreload") {
799 return (srv->commandLibReloadHandler(command, args));
801 }
else if (command ==
"config-reload") {
802 return (srv->commandConfigReloadHandler(command, args));
804 }
else if (command ==
"config-set") {
805 return (srv->commandConfigSetHandler(command, args));
807 }
else if (command ==
"config-get") {
808 return (srv->commandConfigGetHandler(command, args));
810 }
else if (command ==
"config-test") {
811 return (srv->commandConfigTestHandler(command, args));
813 }
else if (command ==
"dhcp-disable") {
814 return (srv->commandDhcpDisableHandler(command, args));
816 }
else if (command ==
"dhcp-enable") {
817 return (srv->commandDhcpEnableHandler(command, args));
819 }
else if (command ==
"version-get") {
820 return (srv->commandVersionGetHandler(command, args));
822 }
else if (command ==
"build-report") {
823 return (srv->commandBuildReportHandler(command, args));
825 }
else if (command ==
"leases-reclaim") {
826 return (srv->commandLeasesReclaimHandler(command, args));
828 }
else if (command ==
"config-write") {
829 return (srv->commandConfigWriteHandler(command, args));
831 }
else if (command ==
"server-tag-get") {
832 return (srv->commandServerTagGetHandler(command, args));
834 }
else if (command ==
"config-backend-pull") {
835 return (srv->commandConfigBackendPullHandler(command, args));
837 }
else if (command ==
"status-get") {
838 return (srv->commandStatusGetHandler(command, args));
846 + command +
"':" + ex.
what() +
847 ", params: '" + txt +
"'"));
856 std::ostringstream err;
859 err <<
"Server object not initialized, can't process config.";
876 }
catch (
const std::exception& ex) {
877 err <<
"Failed to process configuration:" << ex.what();
883 DatabaseConnection::db_lost_callback_ =
884 std::bind(&ControlledDhcpv4Srv::dbLostCallback, srv, ph::_1);
886 DatabaseConnection::db_recovered_callback_ =
887 std::bind(&ControlledDhcpv4Srv::dbRecoveredCallback, srv, ph::_1);
889 DatabaseConnection::db_failed_callback_ =
890 std::bind(&ControlledDhcpv4Srv::dbFailedCallback, srv, ph::_1);
892 CfgDbAccessPtr cfg_db = CfgMgr::instance().getStagingCfg()->getCfgDbAccess();
893 cfg_db->setAppendedParameters(
"universe=4");
894 cfg_db->createManagers();
897 }
catch (
const std::exception& ex) {
898 err <<
"Unable to open database: " << ex.what();
905 }
catch (
const std::exception& ex) {
906 err <<
"Error starting DHCP_DDNS client after server reconfiguration: "
913 Dhcp4to6Ipc::instance().open();
914 }
catch (
const std::exception& ex) {
915 std::ostringstream err;
916 err <<
"error starting DHCPv4-over-DHCPv6 IPC "
917 " after server reconfiguration: " << ex.what();
924 qc = CfgMgr::instance().getStagingCfg()->getDHCPQueueControl();
925 if (IfaceMgr::instance().configureDHCPPacketQueue(AF_INET, qc)) {
927 .arg(IfaceMgr::instance().getPacketQueue4()->getInfoStr());
930 }
catch (
const std::exception& ex) {
931 err <<
"Error setting packet queue controls after server reconfiguration: "
943 CfgMgr::instance().getStagingCfg()->getCfgIface()->
945 getInstance()->useBroadcast());
949 CfgMgr::instance().getStagingCfg()->getCfgExpiration()->
950 setupTimers(&ControlledDhcpv4Srv::reclaimExpiredLeases,
951 &ControlledDhcpv4Srv::deleteExpiredReclaimedLeases,
954 }
catch (
const std::exception& ex) {
955 err <<
"unable to setup timers for periodically running the"
956 " reclamation of the expired leases: "
962 auto ctl_info = CfgMgr::instance().getStagingCfg()->getConfigControlInfo();
964 long fetch_time =
static_cast<long>(ctl_info->getConfigFetchWaitTime());
967 if (fetch_time > 0) {
973 if (!server_->inTestMode()) {
974 fetch_time = 1000 * fetch_time;
977 boost::shared_ptr<unsigned> failure_count(
new unsigned(0));
978 TimerMgr::instance()->
979 registerTimer(
"Dhcp4CBFetchTimer",
980 std::bind(&ControlledDhcpv4Srv::cbFetchUpdates,
981 server_, CfgMgr::instance().getStagingCfg(),
985 TimerMgr::instance()->setup(
"Dhcp4CBFetchTimer");
991 LibDHCP::commitRuntimeOptionDefs();
998 if (HooksManager::calloutsPresent(Hooks.hooks_index_dhcp4_srv_configured_)) {
1001 callout_handle->setArgument(
"io_context", srv->
getIOService());
1003 callout_handle->setArgument(
"json_config", config);
1004 callout_handle->setArgument(
"server_config", CfgMgr::instance().getStagingCfg());
1006 HooksManager::callCallouts(Hooks.hooks_index_dhcp4_srv_configured_,
1018 CfgMultiThreading::apply(CfgMgr::instance().getStagingCfg()->getDHCPMultiThreading());
1019 }
catch (
const std::exception& ex) {
1020 err <<
"Error applying multi threading settings: "
1037 std::ostringstream err;
1040 err <<
"Server object not initialized, can't process config.";
1047 ControlledDhcpv4Srv::ControlledDhcpv4Srv(uint16_t server_port ,
1048 uint16_t client_port )
1052 "There is another Dhcpv4Srv instance already.");
1070 CommandMgr::instance().registerCommand(
"build-report",
1071 std::bind(&ControlledDhcpv4Srv::commandBuildReportHandler,
this, ph::_1, ph::_2));
1073 CommandMgr::instance().registerCommand(
"config-backend-pull",
1074 std::bind(&ControlledDhcpv4Srv::commandConfigBackendPullHandler,
this, ph::_1, ph::_2));
1076 CommandMgr::instance().registerCommand(
"config-get",
1077 std::bind(&ControlledDhcpv4Srv::commandConfigGetHandler,
this, ph::_1, ph::_2));
1079 CommandMgr::instance().registerCommand(
"config-reload",
1080 std::bind(&ControlledDhcpv4Srv::commandConfigReloadHandler,
this, ph::_1, ph::_2));
1082 CommandMgr::instance().registerCommand(
"config-set",
1083 std::bind(&ControlledDhcpv4Srv::commandConfigSetHandler,
this, ph::_1, ph::_2));
1085 CommandMgr::instance().registerCommand(
"config-test",
1086 std::bind(&ControlledDhcpv4Srv::commandConfigTestHandler,
this, ph::_1, ph::_2));
1088 CommandMgr::instance().registerCommand(
"config-write",
1089 std::bind(&ControlledDhcpv4Srv::commandConfigWriteHandler,
this, ph::_1, ph::_2));
1091 CommandMgr::instance().registerCommand(
"dhcp-enable",
1092 std::bind(&ControlledDhcpv4Srv::commandDhcpEnableHandler,
this, ph::_1, ph::_2));
1094 CommandMgr::instance().registerCommand(
"dhcp-disable",
1095 std::bind(&ControlledDhcpv4Srv::commandDhcpDisableHandler,
this, ph::_1, ph::_2));
1097 CommandMgr::instance().registerCommand(
"libreload",
1098 std::bind(&ControlledDhcpv4Srv::commandLibReloadHandler,
this, ph::_1, ph::_2));
1100 CommandMgr::instance().registerCommand(
"leases-reclaim",
1101 std::bind(&ControlledDhcpv4Srv::commandLeasesReclaimHandler,
this, ph::_1, ph::_2));
1103 CommandMgr::instance().registerCommand(
"server-tag-get",
1104 std::bind(&ControlledDhcpv4Srv::commandServerTagGetHandler,
this, ph::_1, ph::_2));
1106 CommandMgr::instance().registerCommand(
"shutdown",
1107 std::bind(&ControlledDhcpv4Srv::commandShutdownHandler,
this, ph::_1, ph::_2));
1109 CommandMgr::instance().registerCommand(
"status-get",
1110 std::bind(&ControlledDhcpv4Srv::commandStatusGetHandler,
this, ph::_1, ph::_2));
1112 CommandMgr::instance().registerCommand(
"version-get",
1113 std::bind(&ControlledDhcpv4Srv::commandVersionGetHandler,
this, ph::_1, ph::_2));
1116 CommandMgr::instance().registerCommand(
"statistic-get",
1117 std::bind(&StatsMgr::statisticGetHandler, ph::_1, ph::_2));
1119 CommandMgr::instance().registerCommand(
"statistic-reset",
1120 std::bind(&StatsMgr::statisticResetHandler, ph::_1, ph::_2));
1122 CommandMgr::instance().registerCommand(
"statistic-remove",
1123 std::bind(&StatsMgr::statisticRemoveHandler, ph::_1, ph::_2));
1125 CommandMgr::instance().registerCommand(
"statistic-get-all",
1126 std::bind(&StatsMgr::statisticGetAllHandler, ph::_1, ph::_2));
1128 CommandMgr::instance().registerCommand(
"statistic-reset-all",
1129 std::bind(&StatsMgr::statisticResetAllHandler, ph::_1, ph::_2));
1131 CommandMgr::instance().registerCommand(
"statistic-remove-all",
1132 std::bind(&StatsMgr::statisticRemoveAllHandler, ph::_1, ph::_2));
1134 CommandMgr::instance().registerCommand(
"statistic-sample-age-set",
1135 std::bind(&StatsMgr::statisticSetMaxSampleAgeHandler, ph::_1, ph::_2));
1137 CommandMgr::instance().registerCommand(
"statistic-sample-age-set-all",
1138 std::bind(&ControlledDhcpv4Srv::commandStatisticSetMaxSampleAgeAllHandler,
this, ph::_1, ph::_2));
1140 CommandMgr::instance().registerCommand(
"statistic-sample-count-set",
1141 std::bind(&StatsMgr::statisticSetMaxSampleCountHandler, ph::_1, ph::_2));
1143 CommandMgr::instance().registerCommand(
"statistic-sample-count-set-all",
1144 std::bind(&ControlledDhcpv4Srv::commandStatisticSetMaxSampleCountAllHandler,
this, ph::_1, ph::_2));
1165 timer_mgr_->unregisterTimers();
1168 CommandMgr::instance().closeCommandSocket();
1171 CommandMgr::instance().deregisterCommand(
"build-report");
1172 CommandMgr::instance().deregisterCommand(
"config-backend-pull");
1173 CommandMgr::instance().deregisterCommand(
"config-get");
1174 CommandMgr::instance().deregisterCommand(
"config-reload");
1175 CommandMgr::instance().deregisterCommand(
"config-set");
1176 CommandMgr::instance().deregisterCommand(
"config-test");
1177 CommandMgr::instance().deregisterCommand(
"config-write");
1178 CommandMgr::instance().deregisterCommand(
"dhcp-disable");
1179 CommandMgr::instance().deregisterCommand(
"dhcp-enable");
1180 CommandMgr::instance().deregisterCommand(
"leases-reclaim");
1181 CommandMgr::instance().deregisterCommand(
"libreload");
1182 CommandMgr::instance().deregisterCommand(
"server-tag-get");
1183 CommandMgr::instance().deregisterCommand(
"shutdown");
1184 CommandMgr::instance().deregisterCommand(
"statistic-get");
1185 CommandMgr::instance().deregisterCommand(
"statistic-get-all");
1186 CommandMgr::instance().deregisterCommand(
"statistic-remove");
1187 CommandMgr::instance().deregisterCommand(
"statistic-remove-all");
1188 CommandMgr::instance().deregisterCommand(
"statistic-reset");
1189 CommandMgr::instance().deregisterCommand(
"statistic-reset-all");
1190 CommandMgr::instance().deregisterCommand(
"statistic-sample-age-set");
1191 CommandMgr::instance().deregisterCommand(
"statistic-sample-age-set-all");
1192 CommandMgr::instance().deregisterCommand(
"statistic-sample-count-set");
1193 CommandMgr::instance().deregisterCommand(
"statistic-sample-count-set-all");
1194 CommandMgr::instance().deregisterCommand(
"status-get");
1195 CommandMgr::instance().deregisterCommand(
"version-get");
1213 ControlledDhcpv4Srv::reclaimExpiredLeases(
const size_t max_leases,
1214 const uint16_t timeout,
1215 const bool remove_lease,
1216 const uint16_t max_unwarned_cycles) {
1218 server_->
alloc_engine_->reclaimExpiredLeases4(max_leases, timeout,
1220 max_unwarned_cycles);
1221 }
catch (
const std::exception& ex) {
1230 ControlledDhcpv4Srv::deleteExpiredReclaimedLeases(
const uint32_t secs) {
1231 server_->
alloc_engine_->deleteExpiredReclaimedLeases4(secs);
1237 ControlledDhcpv4Srv::dbLostCallback(
ReconnectCtlPtr db_reconnect_ctl) {
1238 if (!db_reconnect_ctl) {
1245 if (db_reconnect_ctl->retriesLeft() == db_reconnect_ctl->maxRetries() &&
1246 db_reconnect_ctl->alterServiceState()) {
1254 if (!db_reconnect_ctl->retriesLeft() ||
1255 !db_reconnect_ctl->retryInterval()) {
1257 .arg(db_reconnect_ctl->retriesLeft())
1258 .arg(db_reconnect_ctl->retryInterval());
1259 if (db_reconnect_ctl->exitOnFailure()) {
1269 ControlledDhcpv4Srv::dbRecoveredCallback(
ReconnectCtlPtr db_reconnect_ctl) {
1270 if (!db_reconnect_ctl) {
1277 if (db_reconnect_ctl->alterServiceState()) {
1283 db_reconnect_ctl->resetRetries();
1289 ControlledDhcpv4Srv::dbFailedCallback(
ReconnectCtlPtr db_reconnect_ctl) {
1290 if (!db_reconnect_ctl) {
1297 .arg(db_reconnect_ctl->maxRetries());
1299 if (db_reconnect_ctl->exitOnFailure()) {
1307 ControlledDhcpv4Srv::cbFetchUpdates(
const SrvConfigPtr& srv_cfg,
1308 boost::shared_ptr<unsigned> failure_count) {
1315 CBControlDHCPv4::FetchMode::FETCH_UPDATE);
1316 (*failure_count) = 0;
1318 }
catch (
const std::exception& ex) {
1325 if (++(*failure_count) > 10) {
RAII class creating a critical section.
const isc::log::MessageID DHCP4_RECLAIM_EXPIRED_LEASES_FAIL
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
const isc::log::MessageID DHCP4_DB_RECONNECT_LOST_CONNECTION
const isc::log::MessageID DHCP4_DYNAMIC_RECONFIGURATION_FAIL
static DbCallback db_lost_callback_
Optional callback function to invoke if an opened connection is lost.
isc::data::ElementPtr parseFile(const std::string &filename, ParserType parser_type)
Run the parser on the file specified.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
ConstElementPtr createAnswer(const int status_code, const std::string &text, const ConstElementPtr &arg)
const int CONTROL_RESULT_SUCCESS
Status code indicating a successful operation.
static void setIOService(const isc::asiolink::IOServicePtr &io_service)
Sets IO service to be used by the Host Manager.
isc::data::ConstElementPtr statisticSetMaxSampleCountAllHandler(const isc::data::ConstElementPtr ¶ms)
Handles statistic-sample-count-set-all command.
Evaluation context, an interface to the expression evaluation.
static void destroy()
Destroy lease manager.
const isc::log::MessageID DHCP4_DB_RECONNECT_NO_DB_CTL
const isc::log::MessageID DHCP4_DB_RECONNECT_FAILED
Manages a pool of asynchronous interval timers.
boost::shared_ptr< SrvConfig > SrvConfigPtr
Non-const pointer to the SrvConfig.
The network state is being altered by the DB connection recovery mechanics.
ConstElementPtr redactConfig(ConstElementPtr const &element, list< string > const &json_path)
Redact a configuration.
const isc::log::MessageID DHCP4_CB_ON_DEMAND_FETCH_UPDATES_FAIL
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
const isc::log::MessageID DHCP4_MULTI_THREADING_INFO
const int CONTROL_RESULT_ERROR
Status code indicating a general failure.
boost::shared_ptr< Element > ElementPtr
const isc::log::MessageID DHCP4_CONFIG_PACKET_QUEUE
const isc::log::MessageID DHCP4_CONFIG_UNSUPPORTED_OBJECT
uint16_t getServerPort() const
Get UDP port on which server should listen.
static DbCallback db_failed_callback_
Optional callback function to invoke if an opened connection recovery failed.
Statistics Manager class.
isc::data::ConstElementPtr configureDhcp4Server(Dhcpv4Srv &server, isc::data::ConstElementPtr config_set, bool check_only)
Configure DHCPv4 server (Dhcpv4Srv) with a set of configuration values.
std::vector< HookLibInfo > HookLibsCollection
A storage for information about hook libraries.
const int CONTROL_RESULT_EMPTY
Status code indicating that the specified command was completed correctly, but failed to produce any ...
isc::log::Logger dhcp4_logger(DHCP4_APP_LOGGER_NAME)
Base logger for DHCPv4 server.
Origin
Origin of the network state transition.
const isc::log::MessageID DHCP4_DB_RECONNECT_SUCCEEDED
#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...
static const std::string FLUSH_RECLAIMED_TIMER_NAME
Name of the timer for flushing reclaimed leases.
asiolink::IOServicePtr & getIOService()
Returns pointer to the IO service used by the server.
virtual ~ControlledDhcpv4Srv()
Destructor.
Implements an asynchronous "signal" for IOService driven processing.
boost::shared_ptr< CfgDbAccess > CfgDbAccessPtr
A pointer to the CfgDbAccess.
static void create()
Creates new instance of the HostMgr.
const isc::log::MessageID DHCP4_CB_PERIODIC_FETCH_UPDATES_FAIL
static DbCallback db_recovered_callback_
Optional callback function to invoke if an opened connection recovery succeeded.
const isc::log::MessageID DHCP4_DYNAMIC_RECONFIGURATION
boost::shared_ptr< const Element > ConstElementPtr
isc::data::ConstElementPtr redactConfig(isc::data::ConstElementPtr const &config)
Redact a configuration.
void cleanup()
Performs cleanup, immediately before termination.
const isc::log::MessageID DHCP4_CONFIG_UNRECOVERABLE_ERROR
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
boost::shared_ptr< AllocEngine > alloc_engine_
Allocation Engine.
This is a base class for exceptions thrown from the DNS library module.
ConstElementPtr parseAnswer(int &rcode, const ConstElementPtr &msg)
Defines the logger used by the top-level component of kea-dhcp-ddns.
NetworkStatePtr network_state_
Holds information about disabled DHCP service and/or disabled subnet/network scopes.
void startD2()
Starts DHCP_DDNS client IO if DDNS updates are enabled.
const isc::log::MessageID DHCP4_CB_PERIODIC_FETCH_UPDATES_RETRIES_EXHAUSTED
void setExitValue(int value)
Sets the exit value.
boost::shared_ptr< CalloutHandle > CalloutHandlePtr
A shared pointer to a CalloutHandle object.
static const std::string RECLAIM_EXPIRED_TIMER_NAME
Name of the timer for reclaiming expired leases.
const isc::log::MessageID DHCP4_CONFIG_RECEIVED
This file contains several functions and constants that are used for handling commands and responses ...
const isc::log::MessageID DHCP4_HOOKS_LIBS_RELOAD_FAIL
const isc::log::MessageID DHCP4_CONFIG_LOAD_FAIL
A generic exception that is thrown if a function is called in a prohibited way.
const isc::log::MessageID DHCP4_NOT_RUNNING
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
isc::data::ConstElementPtr statisticSetMaxSampleAgeAllHandler(const isc::data::ConstElementPtr ¶ms)
Handles statistic-sample-age-set-all command.
static ControlledDhcpv4Srv * getInstance()
Returns pointer to the sole instance of Dhcpv4Srv.
const isc::log::MessageID DHCP4_DB_RECONNECT_DISABLED
Controlled version of the DHCPv4 server.
std::string getConfigReport()
const StatsDuration & getMaxSampleAgeDefault() const
Get default duration limit.
Defines the Dhcp4o6Ipc class.
static void setIOService(const isc::asiolink::IOServicePtr &io_service)
Sets IO service to be used by the Lease Manager.
uint32_t getMaxSampleCountDefault() const
Get default count limit.
const isc::log::MessageID DHCP4_COMMAND_RECEIVED
#define LOG_FATAL(LOGGER, MESSAGE)
Macro to conveniently test fatal output and log it.
void shutdown() override
Instructs the server to shut down.
static const TimerMgrPtr & instance()
Returns pointer to the sole instance of the TimerMgr.
const int DBG_DHCP4_COMMAND
Debug level used to log receiving commands.
boost::shared_ptr< ReconnectCtl > ReconnectCtlPtr
Pointer to an instance of ReconnectCtl.
CBControlDHCPv4Ptr getCBControl() const
Returns an object which controls access to the configuration backends.
NetworkStatePtr & getNetworkState()
Returns pointer to the network state used by the server.
void shutdownServer(int exit_value)
Initiates shutdown procedure for the whole DHCPv4 server.
Contains declarations for loggers used by the DHCPv4 server component.
long toSeconds(const StatsDuration &dur)
Returns the number of seconds in a duration.