51namespace ph = std::placeholders;
56struct CtrlDhcp4Hooks {
57 int hooks_index_dhcp4_srv_configured_;
81void signalHandler(
int signo) {
83 if (signo == SIGHUP) {
85 }
else if ((signo == SIGTERM) || (signo == SIGINT)) {
100 start_ = boost::posix_time::second_clock::universal_time();
108 string reason = comment ? comment->stringValue() :
109 "no details available";
138 if (file_name.empty()) {
141 " Please use -c command line option.");
155 "a map, i.e., start with { and end with } and contain "
156 "at least an entry called 'Dhcp4' that itself is a map. "
158 <<
" is a valid JSON, but its top element is not a map."
159 " Did you forget to add { } around your configuration?");
169 "process command \"config-set\"");
177 string reason = comment ? comment->stringValue() :
178 "no details available";
181 }
catch (
const std::exception& ex) {
187 .arg(file_name).arg(ex.what());
189 << file_name <<
"': " << ex.what());
201ControlledDhcpv4Srv::commandShutdownHandler(
const string&,
ConstElementPtr args) {
218 "parameter 'exit-value' is not an integer"));
221 exit_value = param->intValue();
230ControlledDhcpv4Srv::commandConfigReloadHandler(
const string&,
239 }
catch (
const std::exception& ex) {
246 "Config reload failed: " +
string(ex.what())));
251ControlledDhcpv4Srv::commandConfigGetHandler(
const string&,
261ControlledDhcpv4Srv::commandConfigHashGetHandler(
const string&,
273ControlledDhcpv4Srv::commandConfigWriteHandler(
const string&,
282 if (filename_param) {
285 "passed parameter 'filename' is not a string"));
287 filename = filename_param->stringValue();
291 if (filename.empty()) {
295 if (filename.empty()) {
297 "Please specify filename explicitly."));
302 }
catch (
const isc::Exception& ex) {
303 std::ostringstream msg;
304 msg <<
"not allowed to write config into " << filename
305 <<
": " << ex.
what();
315 }
catch (
const isc::Exception& ex) {
330 + filename +
" successful", params));
334ControlledDhcpv4Srv::commandConfigSetHandler(
const string&,
343 message =
"Missing mandatory 'arguments' parameter.";
345 dhcp4 = args->get(
"Dhcp4");
347 message =
"Missing mandatory 'Dhcp4' parameter.";
349 message =
"'Dhcp4' parameter expected to be a map.";
354 if (message.empty()) {
355 for (
auto const& 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()) {
380 if (lease_database) {
381 db::DbAccessParser parser;
382 std::string access_string;
383 parser.
parse(access_string, lease_database);
385 if (params[
"type"] ==
"memfile") {
386 string file_name = params[
"name"];
389 "Can not update configuration while lease file cleanup process is running."));
395 MultiThreadingCriticalSection cs;
444 }
catch (
const std::exception& ex) {
445 std::ostringstream err;
446 err <<
"Error initializing hooks: "
455ControlledDhcpv4Srv::commandConfigTestHandler(
const string&,
464 message =
"Missing mandatory 'arguments' parameter.";
466 dhcp4 = args->get(
"Dhcp4");
468 message =
"Missing mandatory 'Dhcp4' parameter.";
470 message =
"'Dhcp4' parameter expected to be a map.";
475 if (message.empty()) {
476 for (
auto const& obj : args->mapValue()) {
477 const string& obj_name = obj.first;
478 if (obj_name !=
"Dhcp4") {
481 if (message.empty()) {
482 message =
"Unsupported '" + obj_name +
"' parameter";
484 message +=
" (and '" + obj_name +
"')";
488 if (!message.empty()) {
493 if (!message.empty()) {
501 MultiThreadingCriticalSection cs;
513ControlledDhcpv4Srv::commandDhcpDisableHandler(
const std::string&,
515 std::ostringstream message;
516 int64_t max_period = 0;
528 message <<
"arguments for the 'dhcp-disable' command must be a map";
533 if (max_period_element) {
536 message <<
"'max-period' argument must be a number";
540 max_period = max_period_element->intValue();
541 if (max_period <= 0) {
542 message <<
"'max-period' must be positive integer";
555 if (origin_id_element) {
557 type = origin_id_element->intValue();
559 message <<
"'origin-id' argument must be a number";
561 }
else if (origin_element) {
562 switch (origin_element->getType()) {
564 origin = origin_element->stringValue();
565 if (origin ==
"ha-partner") {
567 }
else if (origin !=
"user") {
568 if (origin.empty()) {
569 origin =
"(empty string)";
571 message <<
"invalid value used for 'origin' parameter: "
576 type = origin_element->intValue();
580 message <<
"'origin' argument must be a string or a number";
587 if (message.tellp() == 0) {
588 message <<
"DHCPv4 service disabled";
589 if (max_period > 0) {
590 message <<
" for " << max_period <<
" seconds";
595 network_state_->delayedEnableService(
static_cast<unsigned>(max_period),
609ControlledDhcpv4Srv::commandDhcpEnableHandler(
const std::string&,
611 std::ostringstream message;
622 message <<
"arguments for the 'dhcp-enable' command must be a map";
634 if (origin_id_element) {
636 type = origin_id_element->intValue();
638 message <<
"'origin-id' argument must be a number";
640 }
else if (origin_element) {
641 switch (origin_element->getType()) {
643 origin = origin_element->stringValue();
644 if (origin ==
"ha-partner") {
646 }
else if (origin !=
"user") {
647 if (origin.empty()) {
648 origin =
"(empty string)";
650 message <<
"invalid value used for 'origin' parameter: "
655 type = origin_element->intValue();
659 message <<
"'origin' argument must be a string or a number";
666 if (message.tellp() == 0) {
671 "DHCP service successfully enabled"));
679ControlledDhcpv4Srv::commandVersionGetHandler(
const string&,
ConstElementPtr) {
682 arguments->set(
"extended", extended);
690ControlledDhcpv4Srv::commandBuildReportHandler(
const string&,
698ControlledDhcpv4Srv::commandLeasesReclaimHandler(
const string&,
705 message =
"Missing mandatory 'remove' parameter.";
709 message =
"Missing mandatory 'remove' parameter.";
711 message =
"'remove' parameter expected to be a boolean.";
713 bool remove_lease = remove_name->boolValue();
714 server_->alloc_engine_->reclaimExpiredLeases4(0, 0, remove_lease);
716 message =
"Reclamation of expired leases is complete.";
724ControlledDhcpv4Srv::commandSubnet4SelectTestHandler(
const string&,
732 bool ignore_link_sel =
734 SubnetSelector selector;
735 for (
auto const& entry : args->mapValue()) {
736 ostringstream errmsg;
737 if (entry.first ==
"interface") {
739 errmsg <<
"'interface' entry must be a string";
742 selector.
iface_name_ = entry.second->stringValue();
744 }
else if (entry.first ==
"address") {
746 errmsg <<
"'address' entry must be a string";
750 IOAddress addr(entry.second->stringValue());
752 errmsg <<
"bad 'address' entry: not IPv4";
757 }
catch (
const exception& ex) {
758 errmsg <<
"bad 'address' entry: " << ex.what();
761 }
else if (entry.first ==
"relay") {
763 errmsg <<
"'relay' entry must be a string";
767 IOAddress addr(entry.second->stringValue());
769 errmsg <<
"bad 'relay' entry: not IPv4";
774 }
catch (
const exception& ex) {
775 errmsg <<
"bad 'relay' entry: " << ex.what();
778 }
else if (entry.first ==
"local") {
780 errmsg <<
"'local' entry must be a string";
784 IOAddress addr(entry.second->stringValue());
786 errmsg <<
"bad 'local' entry: not IPv4";
791 }
catch (
const exception& ex) {
792 errmsg <<
"bad 'local' entry: " << ex.what();
795 }
else if (entry.first ==
"remote") {
797 errmsg <<
"'remote' entry must be a string";
801 IOAddress addr(entry.second->stringValue());
803 errmsg <<
"bad 'remote' entry: not IPv4";
808 }
catch (
const exception& ex) {
809 errmsg <<
"bad 'remote' entry: " << ex.what();
812 }
else if (entry.first ==
"link") {
814 errmsg <<
"'link' entry must be a string";
818 IOAddress addr(entry.second->stringValue());
820 errmsg <<
"bad 'link' entry: not IPv4";
823 if (!ignore_link_sel) {
827 }
catch (
const exception& ex) {
828 errmsg <<
"bad 'link' entry: " << ex.what();
831 }
else if (entry.first ==
"subnet") {
833 if (args->contains(
"link") && !ignore_link_sel) {
837 errmsg <<
"'subnet' entry must be a string";
841 IOAddress addr(entry.second->stringValue());
843 errmsg <<
"bad 'subnet' entry: not IPv4";
848 }
catch (
const exception& ex) {
849 errmsg <<
"bad 'subnet' entry: " << ex.what();
852 }
else if (entry.first ==
"classes") {
855 "'classes' entry must be a list"));
857 for (
auto const& item : entry.second->listValue()) {
859 errmsg <<
"'classes' entry must be a list of strings";
863 if (!item->stringValue().empty()) {
869 errmsg <<
"unknown entry '" << entry.first <<
"'";
874 getCfgSubnets4()->selectSubnet(selector);
879 subnet->getSharedNetwork(network);
882 msg <<
"selected shared network '" << network->getName()
883 <<
"' starting with subnet '" << subnet->toText()
884 <<
"' id " << subnet->getID();
886 msg <<
"selected subnet '" << subnet->toText()
887 <<
"' id " << subnet->getID();
893ControlledDhcpv4Srv::commandSubnet4o6SelectTestHandler(
const string&,
901 SubnetSelector selector;
905 for (
auto const& entry : args->mapValue()) {
906 ostringstream errmsg;
907 if (entry.first ==
"interface") {
909 errmsg <<
"'interface' entry must be a string";
912 selector.
iface_name_ = entry.second->stringValue();
914 }
if (entry.first ==
"interface-id") {
916 errmsg <<
"'interface-id' entry must be a string";
920 string str = entry.second->stringValue();
926 errmsg <<
"'interface-id' must be not empty";
934 errmsg <<
"value of 'interface-id' was not recognized";
937 }
else if (entry.first ==
"address") {
939 errmsg <<
"'address' entry must be a string";
943 IOAddress addr(entry.second->stringValue());
945 errmsg <<
"bad 'address' entry: not IPv4";
950 }
catch (
const exception& ex) {
951 errmsg <<
"bad 'address' entry: " << ex.what();
954 }
else if (entry.first ==
"relay") {
956 errmsg <<
"'relay' entry must be a string";
960 IOAddress addr(entry.second->stringValue());
962 errmsg <<
"bad 'relay' entry: not IPv4";
967 }
catch (
const exception& ex) {
968 errmsg <<
"bad 'relay' entry: " << ex.what();
971 }
else if (entry.first ==
"local") {
973 errmsg <<
"'local' entry must be a string";
977 IOAddress addr(entry.second->stringValue());
979 errmsg <<
"bad 'local' entry: not IPv6";
984 }
catch (
const exception& ex) {
985 errmsg <<
"bad 'local' entry: " << ex.what();
988 }
else if (entry.first ==
"remote") {
990 errmsg <<
"'remote' entry must be a string";
994 IOAddress addr(entry.second->stringValue());
996 errmsg <<
"bad 'remote' entry: not IPv6";
1001 }
catch (
const exception& ex) {
1002 errmsg <<
"bad 'remote' entry: " << ex.what();
1005 }
else if (entry.first ==
"link") {
1007 errmsg <<
"'link' entry must be a string";
1011 IOAddress addr(entry.second->stringValue());
1013 errmsg <<
"bad 'link' entry: not IPv6";
1018 }
catch (
const exception& ex) {
1019 errmsg <<
"bad 'link' entry: " << ex.what();
1022 }
else if (entry.first ==
"subnet") {
1024 errmsg <<
"'subnet' entry must be a string";
1028 IOAddress addr(entry.second->stringValue());
1030 errmsg <<
"bad 'subnet' entry: not IPv4";
1035 }
catch (
const exception& ex) {
1036 errmsg <<
"bad 'subnet' entry: " << ex.what();
1039 }
else if (entry.first ==
"classes") {
1042 "'classes' entry must be a list"));
1044 for (
auto const& item : entry.second->listValue()) {
1046 errmsg <<
"'classes' entry must be a list of strings";
1050 if (!item->stringValue().empty()) {
1056 errmsg <<
"unknown entry '" << entry.first <<
"'";
1061 getCfgSubnets4()->selectSubnet4o6(selector);
1066 subnet->getSharedNetwork(network);
1069 msg <<
"selected shared network '" << network->getName()
1070 <<
"' starting with subnet '" << subnet->toText()
1071 <<
"' id " << subnet->getID();
1073 msg <<
"selected subnet '" << subnet->toText()
1074 <<
"' id " << subnet->getID();
1080ControlledDhcpv4Srv::commandServerTagGetHandler(
const std::string&,
1082 const std::string& tag =
1091ControlledDhcpv4Srv::commandConfigBackendPullHandler(
const std::string&,
1099 MultiThreadingCriticalSection cs;
1112 auto mode = CBControlDHCPv4::FetchMode::FETCH_UPDATE;
1113 server_->getCBControl()->databaseConfigFetch(srv_cfg, mode);
1114 }
catch (
const std::exception& ex) {
1118 "On demand configuration update failed: " +
1119 string(ex.what())));
1122 "On demand configuration update successful."));
1126ControlledDhcpv4Srv::commandStatusGetHandler(
const string&,
1131 auto now = boost::posix_time::second_clock::universal_time();
1133 if (!
start_.is_not_a_date_time()) {
1134 auto uptime = now -
start_;
1139 if (!last_commit.is_not_a_date_time()) {
1140 auto reload = now - last_commit;
1145 if (mt_mgr.getMode()) {
1149 status->set(
"packet-queue-size",
Element::create(
static_cast<int32_t
>(
1152 queue_stats->add(
Element::create(mt_mgr.getThreadPool().getQueueStat(10)));
1153 queue_stats->add(
Element::create(mt_mgr.getThreadPool().getQueueStat(100)));
1154 queue_stats->add(
Element::create(mt_mgr.getThreadPool().getQueueStat(1000)));
1155 status->set(
"packet-queue-statistics", queue_stats);
1164 for (std::string
const&
error : interface->getErrors()) {
1171 if (socket_errors->empty()) {
1176 if (reconnect_ctl && reconnect_ctl->retriesLeft()) {
1181 sockets->set(
"errors", socket_errors);
1183 status->set(
"sockets", sockets);
1191ControlledDhcpv4Srv::commandStatisticSetMaxSampleCountAllHandler(
const string&,
1203ControlledDhcpv4Srv::commandStatisticSetMaxSampleAgeAllHandler(
const string&,
1224 std::ostringstream err;
1227 err <<
"Server object not initialized, can't process config.";
1250 }
catch (
const std::exception& ex) {
1251 err <<
"Failed to process configuration:" << ex.what();
1258 std::bind(&ControlledDhcpv4Srv::dbLostCallback, srv, ph::_1);
1261 std::bind(&ControlledDhcpv4Srv::dbRecoveredCallback, srv, ph::_1);
1264 std::bind(&ControlledDhcpv4Srv::dbFailedCallback, srv, ph::_1);
1267 string params =
"universe=4";
1268 cfg_db->setAppendedParameters(params);
1269 cfg_db->createManagers();
1274 }
catch (
const std::exception& ex) {
1275 err <<
"Unable to open database: " << ex.what();
1282 }
catch (
const std::exception& ex) {
1283 err <<
"Error starting DHCP_DDNS client after server reconfiguration: "
1291 }
catch (
const std::exception& ex) {
1292 err <<
"error starting DHCPv4-over-DHCPv6 IPC "
1293 " after server reconfiguration: " << ex.what();
1306 }
catch (
const std::exception& ex) {
1307 err <<
"Error setting packet queue controls after server reconfiguration: "
1315 std::bind(&ControlledDhcpv4Srv::openSocketsFailedCallback, srv, ph::_1);
1331 setupTimers(&ControlledDhcpv4Srv::reclaimExpiredLeases,
1332 &ControlledDhcpv4Srv::deleteExpiredReclaimedLeases,
1335 }
catch (
const std::exception& ex) {
1336 err <<
"unable to setup timers for periodically running the"
1337 " reclamation of the expired leases: "
1338 << ex.what() <<
".";
1345 long fetch_time =
static_cast<long>(ctl_info->getConfigFetchWaitTime());
1348 if (fetch_time > 0) {
1354 if (!server_->inTestMode()) {
1355 fetch_time = 1000 * fetch_time;
1358 boost::shared_ptr<unsigned> failure_count(
new unsigned(0));
1360 registerTimer(
"Dhcp4CBFetchTimer",
1361 std::bind(&ControlledDhcpv4Srv::cbFetchUpdates,
1375 if (notify_libraries) {
1376 return (notify_libraries);
1385 }
catch (
const std::exception& ex) {
1386 err <<
"Error initializing the lease allocators: "
1397 }
catch (
const std::exception& ex) {
1398 err <<
"Error applying multi threading settings: "
1417 callout_handle->setArgument(
"io_context", srv->
getIOService());
1419 callout_handle->setArgument(
"json_config",
config);
1420 callout_handle->setArgument(
"server_config",
CfgMgr::instance().getStagingCfg());
1429 callout_handle->getArgument(
"error",
error);
1431 error =
"unknown error";
1446 "Server object not initialized, can't process config.");
1457 uint16_t client_port )
1461 "There is another Dhcpv4Srv instance already.");
1484 std::bind(&ControlledDhcpv4Srv::commandBuildReportHandler,
this, ph::_1, ph::_2));
1487 std::bind(&ControlledDhcpv4Srv::commandConfigBackendPullHandler,
this, ph::_1, ph::_2));
1490 std::bind(&ControlledDhcpv4Srv::commandConfigGetHandler,
this, ph::_1, ph::_2));
1493 std::bind(&ControlledDhcpv4Srv::commandConfigHashGetHandler,
this, ph::_1, ph::_2));
1496 std::bind(&ControlledDhcpv4Srv::commandConfigReloadHandler,
this, ph::_1, ph::_2));
1499 std::bind(&ControlledDhcpv4Srv::commandConfigSetHandler,
this, ph::_1, ph::_2));
1502 std::bind(&ControlledDhcpv4Srv::commandConfigTestHandler,
this, ph::_1, ph::_2));
1505 std::bind(&ControlledDhcpv4Srv::commandConfigWriteHandler,
this, ph::_1, ph::_2));
1508 std::bind(&ControlledDhcpv4Srv::commandDhcpEnableHandler,
this, ph::_1, ph::_2));
1511 std::bind(&ControlledDhcpv4Srv::commandDhcpDisableHandler,
this, ph::_1, ph::_2));
1514 std::bind(&ControlledDhcpv4Srv::commandLeasesReclaimHandler,
this, ph::_1, ph::_2));
1517 std::bind(&ControlledDhcpv4Srv::commandSubnet4SelectTestHandler,
this, ph::_1, ph::_2));
1520 std::bind(&ControlledDhcpv4Srv::commandSubnet4o6SelectTestHandler,
this, ph::_1, ph::_2));
1523 std::bind(&ControlledDhcpv4Srv::commandServerTagGetHandler,
this, ph::_1, ph::_2));
1526 std::bind(&ControlledDhcpv4Srv::commandShutdownHandler,
this, ph::_1, ph::_2));
1529 std::bind(&ControlledDhcpv4Srv::commandStatusGetHandler,
this, ph::_1, ph::_2));
1532 std::bind(&ControlledDhcpv4Srv::commandVersionGetHandler,
this, ph::_1, ph::_2));
1557 std::bind(&ControlledDhcpv4Srv::commandStatisticSetMaxSampleAgeAllHandler,
this, ph::_1, ph::_2));
1563 std::bind(&ControlledDhcpv4Srv::commandStatisticSetMaxSampleCountAllHandler,
this, ph::_1, ph::_2));
1584 timer_mgr_->unregisterTimers();
1633ControlledDhcpv4Srv::reclaimExpiredLeases(
const size_t max_leases,
1634 const uint16_t timeout,
1635 const bool remove_lease,
1636 const uint16_t max_unwarned_cycles) {
1639 server_->
alloc_engine_->reclaimExpiredLeases4(max_leases, timeout,
1641 max_unwarned_cycles);
1645 getCfgExpiration()->getReclaimTimerWaitTime());
1647 }
catch (
const std::exception& ex) {
1656ControlledDhcpv4Srv::deleteExpiredReclaimedLeases(
const uint32_t secs) {
1658 server_->alloc_engine_->deleteExpiredReclaimedLeases4(secs);
1666ControlledDhcpv4Srv::dbLostCallback(
ReconnectCtlPtr db_reconnect_ctl) {
1667 if (!db_reconnect_ctl) {
1674 if (db_reconnect_ctl->retriesLeft() == db_reconnect_ctl->maxRetries() &&
1675 db_reconnect_ctl->alterServiceState()) {
1680 .arg(db_reconnect_ctl->id())
1681 .arg(db_reconnect_ctl->timerName());;
1685 if (!db_reconnect_ctl->retriesLeft() ||
1686 !db_reconnect_ctl->retryInterval()) {
1688 .arg(db_reconnect_ctl->retriesLeft())
1689 .arg(db_reconnect_ctl->retryInterval())
1690 .arg(db_reconnect_ctl->id())
1691 .arg(db_reconnect_ctl->timerName());
1692 if (db_reconnect_ctl->exitOnFailure()) {
1702ControlledDhcpv4Srv::dbRecoveredCallback(
ReconnectCtlPtr db_reconnect_ctl) {
1703 if (!db_reconnect_ctl) {
1710 if (db_reconnect_ctl->retriesLeft() != db_reconnect_ctl->maxRetries() &&
1711 db_reconnect_ctl->alterServiceState()) {
1716 .arg(db_reconnect_ctl->id())
1717 .arg(db_reconnect_ctl->timerName());
1719 db_reconnect_ctl->resetRetries();
1725ControlledDhcpv4Srv::dbFailedCallback(
ReconnectCtlPtr db_reconnect_ctl) {
1726 if (!db_reconnect_ctl) {
1733 .arg(db_reconnect_ctl->maxRetries())
1734 .arg(db_reconnect_ctl->id())
1735 .arg(db_reconnect_ctl->timerName());
1737 if (db_reconnect_ctl->exitOnFailure()) {
1745ControlledDhcpv4Srv::openSocketsFailedCallback(
ReconnectCtlPtr reconnect_ctl) {
1746 if (!reconnect_ctl) {
1753 .arg(reconnect_ctl->maxRetries());
1755 if (reconnect_ctl->exitOnFailure()) {
1761ControlledDhcpv4Srv::cbFetchUpdates(
const SrvConfigPtr& srv_cfg,
1762 boost::shared_ptr<unsigned> failure_count) {
1764 MultiThreadingCriticalSection cs;
1768 server_->getCBControl()->databaseConfigFetch(srv_cfg,
1769 CBControlDHCPv4::FetchMode::FETCH_UPDATE);
1770 (*failure_count) = 0;
1772 }
catch (
const std::exception& ex) {
1779 if (++(*failure_count) > 10) {
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
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.
static const IOAddress & IPV6_ZERO_ADDRESS()
Returns an IPv6 zero address.
static IOServiceMgr & instance()
Access the IOServiceMgr singleton instance.
size_t pollIOServices()
Poll IOService objects.
Implements an asynchronous "signal" for IOService driven processing.
static void setIOService(isc::asiolink::IOServicePtr io_service)
Set the I/O service.
virtual isc::data::ConstElementPtr processCommand(const isc::data::ConstElementPtr &cmd)
Triggers command processing.
void registerCommand(const std::string &cmd, CommandHandler handler)
Registers specified command handler for a given command.
static std::string getHash(const isc::data::ConstElementPtr &config)
returns a hash of a given Element structure
void deregisterCommand(const std::string &cmd)
Deregisters specified command handler.
static CommandMgr & instance()
CommandMgr is a singleton class.
static std::string DEFAULT_AUTHENTICATION_REALM
Default HTTP authentication realm.
void closeCommandSockets()
Close http control sockets.
static HttpCommandMgr & instance()
HttpCommandMgr is a singleton class.
void setIOService(const asiolink::IOServicePtr &io_service)
Sets IO service to be used by the http command manager.
static UnixCommandMgr & instance()
UnixCommandMgr is a singleton class.
void setIOService(const asiolink::IOServicePtr &io_service)
Sets IO service to be used by the unix command manager.
void closeCommandSockets()
Shuts down any open unix control sockets.
static ElementPtr create(const Position &pos=ZERO_POSITION())
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
static void setIOService(const isc::asiolink::IOServicePtr &io_service)
Sets IO service to be used by the database backends.
static DbCallback db_recovered_callback_
Optional callback function to invoke if an opened connection recovery succeeded.
static DbCallback db_failed_callback_
Optional callback function to invoke if an opened connection recovery failed.
static DbCallback db_lost_callback_
Optional callback function to invoke if an opened connection is lost.
void parse(std::string &access_string, isc::data::ConstElementPtr database_config)
Parse configuration value.
const DatabaseConnection::ParameterMap & getDbAccessParameters() const
Get database access parameters.
RAII class to enable DB reconnect retries on server startup.
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.
static OpenSocketsFailedCallback open_sockets_failed_callback_
Optional callback function to invoke if all retries of the opening sockets fail.
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.
void clearStagingConfiguration()
Remove staging configuration.
SrvConfigPtr getCurrentCfg()
Returns a pointer to the current configuration.
static void apply(data::ConstElementPtr value)
apply multi threading configuration
void insert(const ClientClass &class_name)
Insert an element.
Controlled version of the DHCPv4 server.
virtual ~ControlledDhcpv4Srv()
Destructor.
static isc::data::ConstElementPtr finishConfigHookLibraries(isc::data::ConstElementPtr config)
Configuration checker for hook libraries.
isc::data::ConstElementPtr loadConfigFile(const std::string &file_name)
Configure DHCPv4 server using the configuration file specified.
void cleanup()
Performs cleanup, immediately before termination.
ControlledDhcpv4Srv(uint16_t server_port=DHCP4_SERVER_PORT, uint16_t client_port=0)
Constructor.
static isc::data::ConstElementPtr checkConfig(isc::data::ConstElementPtr config)
Configuration checker.
void init(const std::string &config_file)
Initializes the server.
static isc::data::ConstElementPtr processConfig(isc::data::ConstElementPtr config)
Configuration processor.
static ControlledDhcpv4Srv * getInstance()
Returns pointer to the sole instance of Dhcpv4Srv.
virtual void shutdownServer(int exit_value)
Initiates shutdown procedure for the whole DHCPv4 server.
static Dhcp4to6Ipc & instance()
Returns pointer to the sole instance of Dhcp4to6Ipc.
virtual void open()
Open communication socket.
void startD2()
Starts DHCP_DDNS client IO if DDNS updates are enabled.
Dhcpv4Srv(uint16_t server_port=DHCP4_SERVER_PORT, uint16_t client_port=0, const bool use_bcast=true, const bool direct_response_desired=true)
Default constructor.
void shutdown() override
Instructs the server to shut down.
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 getServerPort() const
Get UDP port on which server should listen.
static void create()
Creates new instance of the HostMgr.
static IfaceMgr & instance()
IfaceMgr is a singleton class.
static void destroy()
Destroy lease manager.
static void commitRuntimeOptionDefs()
Commits runtime option definitions.
static bool isLFCProcessRunning(const std::string file_name, Universe u)
Check if LFC is running.
static const unsigned int DB_CONNECTION
The network state is being altered by the DB connection recovery mechanics.
static const unsigned int USER_COMMAND
Origin of the network state transition.
static const unsigned int HA_REMOTE_COMMAND
The network state is being altered by a "dhcp-disable" or "dhcp-enable" command sent by a HA partner.
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.
@ NEXT_STEP_DROP
drop the packet
static int registerHook(const std::string &name)
Register Hook.
static bool calloutsPresent(int index)
Are callouts present?
static boost::shared_ptr< CalloutHandle > createCalloutHandle()
Return callout handle.
static void callCallouts(int index, CalloutHandle &handle)
Calls the callouts for a given hook.
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::asiolink::IOSignalSetPtr signal_set_
A pointer to the object installing custom signal handlers.
boost::posix_time::ptime start_
Timestamp of the start of the daemon.
void checkWriteConfigFile(std::string &file)
Checks the to-be-written configuration file name.
void setExitValue(int value)
Sets the exit value.
isc::data::ConstElementPtr redactConfig(isc::data::ConstElementPtr const &config)
Redact a configuration.
static StatsMgr & instance()
Statistics Manager accessor method.
static MultiThreadingMgr & instance()
Returns a single instance of Multi Threading Manager.
void apply(bool enabled, uint32_t thread_count, uint32_t queue_size)
Apply the multi-threading related settings.
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.
isc::data::ConstElementPtr statisticSetMaxSampleCountAllHandler(const isc::data::ConstElementPtr ¶ms)
Handles statistic-sample-count-set-all command.
static isc::data::ConstElementPtr statisticResetHandler(const std::string &name, const isc::data::ConstElementPtr ¶ms)
Handles statistic-reset command.
static isc::data::ConstElementPtr statisticGetAllHandler(const std::string &name, const isc::data::ConstElementPtr ¶ms)
Handles statistic-get-all command.
static isc::data::ConstElementPtr statisticRemoveHandler(const std::string &name, const isc::data::ConstElementPtr ¶ms)
Handles statistic-remove command.
static isc::data::ConstElementPtr statisticGetHandler(const std::string &name, const isc::data::ConstElementPtr ¶ms)
Handles statistic-get command.
isc::data::ConstElementPtr statisticSetMaxSampleAgeAllHandler(const isc::data::ConstElementPtr ¶ms)
Handles statistic-sample-age-set-all command.
static isc::data::ConstElementPtr statisticResetAllHandler(const std::string &name, const isc::data::ConstElementPtr ¶ms)
Handles statistic-reset-all command.
static isc::data::ConstElementPtr statisticSetMaxSampleAgeHandler(const std::string &name, const isc::data::ConstElementPtr ¶ms)
Handles statistic-sample-age-set command.
static isc::data::ConstElementPtr statisticRemoveAllHandler(const std::string &name, const isc::data::ConstElementPtr ¶ms)
Handles statistic-remove-all command.
static isc::data::ConstElementPtr statisticSetMaxSampleCountHandler(const std::string &name, const isc::data::ConstElementPtr ¶ms)
Handles statistic-sample-count-set command.
uint32_t getMaxSampleCountDefault() const
Get default count limit.
const StatsDuration & getMaxSampleAgeDefault() const
Get default duration limit.
#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_FATAL(LOGGER, MESSAGE)
Macro to conveniently test fatal 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 int CONTROL_RESULT_EMPTY
Status code indicating that the specified command was completed correctly, but failed to produce any ...
ConstElementPtr parseAnswer(int &rcode, const ConstElementPtr &msg)
Parses a standard config/command level answer and returns arguments or text status code.
ConstElementPtr createCommand(const std::string &command)
Creates a standard command message with no argument (of the form { "command": "my_command" }...
const int CONTROL_RESULT_ERROR
Status code indicating a general failure.
ConstElementPtr createAnswer(const int status_code, const std::string &text, const ConstElementPtr &arg)
Creates a standard config/command level answer message.
ConstElementPtr createAnswer()
Creates a standard config/command level success answer message (i.e.
const int CONTROL_RESULT_SUCCESS
Status code indicating a successful operation.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
std::string getConfigReport()
const isc::log::MessageID DHCP4_NOT_RUNNING
const isc::log::MessageID DHCP4_DYNAMIC_RECONFIGURATION_FAIL
const isc::log::MessageID DHCP4_CONFIG_RECEIVED
const isc::log::MessageID DHCP4_DYNAMIC_RECONFIGURATION_SUCCESS
boost::shared_ptr< const Subnet4 > ConstSubnet4Ptr
A const pointer to a Subnet4 object.
boost::shared_ptr< CfgDbAccess > CfgDbAccessPtr
A pointer to the CfgDbAccess.
boost::shared_ptr< Iface > IfacePtr
Type definition for the pointer to an Iface object.
const isc::log::MessageID DHCP4_DB_RECONNECT_NO_DB_CTL
const isc::log::MessageID DHCP4_CB_PERIODIC_FETCH_UPDATES_RETRIES_EXHAUSTED
const isc::log::MessageID DHCP4_CONFIG_PACKET_QUEUE
boost::shared_ptr< SrvConfig > SrvConfigPtr
Non-const pointer to the SrvConfig.
const isc::log::MessageID DHCP4_CB_ON_DEMAND_FETCH_UPDATES_FAIL
const isc::log::MessageID DHCP4_CONFIG_LOAD_FAIL
const int DBG_DHCP4_COMMAND
Debug level used to log receiving commands.
const isc::log::MessageID DHCP4_DB_RECONNECT_DISABLED
const isc::log::MessageID DHCP4_CONFIG_UNRECOVERABLE_ERROR
const int DBG_DHCP4_BASIC
Debug level used to trace basic operations within the code.
const isc::log::MessageID DHCP4_DB_RECONNECT_SUCCEEDED
isc::data::ConstElementPtr configureDhcp4Server(Dhcpv4Srv &server, isc::data::ConstElementPtr config_set, bool check_only, bool extra_checks)
Configure DHCPv4 server (Dhcpv4Srv) with a set of configuration values.
const isc::log::MessageID DHCP4_MULTI_THREADING_INFO
const isc::log::MessageID DHCP4_OPEN_SOCKETS_NO_RECONNECT_CTL
const isc::log::MessageID DHCP4_RECLAIM_EXPIRED_LEASES_SKIPPED
isc::log::Logger dhcp4_logger(DHCP4_APP_LOGGER_NAME)
Base logger for DHCPv4 server.
boost::shared_ptr< SharedNetwork4 > SharedNetwork4Ptr
Pointer to SharedNetwork4 object.
const isc::log::MessageID DHCP4_DB_RECONNECT_FAILED
const isc::log::MessageID DHCP4_OPEN_SOCKETS_FAILED
const isc::log::MessageID DHCP4_DYNAMIC_RECONFIGURATION
const isc::log::MessageID DHCP4_RECLAIM_EXPIRED_LEASES_FAIL
boost::shared_ptr< Option > OptionPtr
const isc::log::MessageID DHCP4_CONFIG_UNSUPPORTED_OBJECT
const isc::log::MessageID DHCP4_CB_PERIODIC_FETCH_UPDATES_FAIL
const isc::log::MessageID DHCP4_DB_RECONNECT_LOST_CONNECTION
boost::shared_ptr< CalloutHandle > CalloutHandlePtr
A shared pointer to a CalloutHandle object.
long toSeconds(const StatsDuration &dur)
Returns the number of seconds in a duration.
void decodeFormattedHexString(const string &hex_string, vector< uint8_t > &binary)
Converts a formatted string of hexadecimal digits into a vector.
vector< uint8_t > quotedStringToBinary(const string "ed_string)
Converts a string in quotes into vector.
boost::shared_ptr< ReconnectCtl > ReconnectCtlPtr
Pointer to an instance of ReconnectCtl.
Defines the logger used by the top-level component of kea-lfc.
asiolink::IOAddress local_address_
Address on which the message was received.
bool dhcp4o6_
Specifies if the packet is DHCP4o6.
asiolink::IOAddress option_select_
RAI link select or subnet select option.
std::string iface_name_
Name of the interface on which the message was received.
asiolink::IOAddress ciaddr_
ciaddr from the client's message.
ClientClasses client_classes_
Classes that the client belongs to.
asiolink::IOAddress remote_address_
Source address of the message.
OptionPtr interface_id_
Interface id option.
asiolink::IOAddress first_relay_linkaddr_
First relay link address.
asiolink::IOAddress giaddr_
giaddr from the client's message.