52namespace ph = std::placeholders;
57struct CtrlDhcp4Hooks {
58 int hooks_index_dhcp4_srv_configured_;
82void signalHandler(
int signo) {
84 if (signo == SIGHUP) {
86 }
else if ((signo == SIGTERM) || (signo == SIGINT)) {
101 start_ = boost::posix_time::second_clock::universal_time();
109 string reason = comment ? comment->stringValue() :
110 "no details available";
139 if (file_name.empty()) {
142 " Please use -c command line option.");
156 "a map, i.e., start with { and end with } and contain "
157 "at least an entry called 'Dhcp4' that itself is a map. "
159 <<
" is a valid JSON, but its top element is not a map."
160 " Did you forget to add { } around your configuration?");
170 "process command \"config-set\"");
178 string reason = comment ? comment->stringValue() :
179 "no details available";
182 }
catch (
const std::exception& ex) {
188 .arg(file_name).arg(ex.what());
190 << file_name <<
"': " << ex.what());
224 "parameter 'exit-value' is not an integer"));
227 exit_value = param->intValue();
240 "Illegal operation executing 'config-reload' on a different thread than main thread"));
249 }
catch (
const std::exception& ex) {
256 "Config reload failed: " +
string(ex.what())));
292 if (filename_param) {
295 "passed parameter 'filename' is not a string"));
297 filename = filename_param->stringValue();
301 if (filename.empty()) {
305 if (filename.empty()) {
307 "Please specify filename explicitly."));
313 std::ostringstream msg;
314 msg <<
"not allowed to write config into " << filename
315 <<
": " << ex.
what();
340 + filename +
" successful", params));
348 "Illegal operation executing 'config-set' on a different thread than main thread"));
357 message =
"Missing mandatory 'arguments' parameter.";
359 dhcp4 = args->get(
"Dhcp4");
361 message =
"Missing mandatory 'Dhcp4' parameter.";
363 message =
"'Dhcp4' parameter expected to be a map.";
368 if (message.empty()) {
369 for (
auto const& obj : args->mapValue()) {
370 const string& obj_name = obj.first;
371 if (obj_name !=
"Dhcp4") {
374 if (message.empty()) {
375 message =
"Unsupported '" + obj_name +
"' parameter";
377 message +=
" (and '" + obj_name +
"')";
381 if (!message.empty()) {
386 if (!message.empty()) {
399 "Can not update configuration while lease file cleanup process is running."));
432 message =
"Reconfiguration triggered a fatal error: shutting down.";
461 }
catch (
const std::exception& ex) {
465 std::ostringstream err;
466 err <<
"Error initializing hooks: "
479 "Illegal operation executing 'config-test' on a different thread than main thread"));
488 message =
"Missing mandatory 'arguments' parameter.";
490 dhcp4 = args->get(
"Dhcp4");
492 message =
"Missing mandatory 'Dhcp4' parameter.";
494 message =
"'Dhcp4' parameter expected to be a map.";
499 if (message.empty()) {
500 for (
auto const& obj : args->mapValue()) {
501 const string& obj_name = obj.first;
502 if (obj_name !=
"Dhcp4") {
505 if (message.empty()) {
506 message =
"Unsupported '" + obj_name +
"' parameter";
508 message +=
" (and '" + obj_name +
"')";
512 if (!message.empty()) {
517 if (!message.empty()) {
539 std::ostringstream message;
540 int64_t max_period = 0;
552 message <<
"arguments for the 'dhcp-disable' command must be a map";
557 if (max_period_element) {
560 message <<
"'max-period' argument must be a number";
564 max_period = max_period_element->intValue();
565 if (max_period <= 0) {
566 message <<
"'max-period' must be positive integer";
579 if (origin_id_element) {
581 type = origin_id_element->intValue();
583 message <<
"'origin-id' argument must be a number";
585 }
else if (origin_element) {
586 switch (origin_element->getType()) {
588 origin = origin_element->stringValue();
589 if (origin ==
"ha-partner") {
591 }
else if (origin !=
"user") {
592 if (origin.empty()) {
593 origin =
"(empty string)";
595 message <<
"invalid value used for 'origin' parameter: "
600 type = origin_element->intValue();
604 message <<
"'origin' argument must be a string or a number";
611 if (message.tellp() == 0) {
612 message <<
"DHCPv4 service disabled";
613 if (max_period > 0) {
614 message <<
" for " << max_period <<
" seconds";
619 network_state_->delayedEnableService(
static_cast<unsigned>(max_period),
635 std::ostringstream message;
646 message <<
"arguments for the 'dhcp-enable' command must be a map";
658 if (origin_id_element) {
660 type = origin_id_element->intValue();
662 message <<
"'origin-id' argument must be a number";
664 }
else if (origin_element) {
665 switch (origin_element->getType()) {
667 origin = origin_element->stringValue();
668 if (origin ==
"ha-partner") {
670 }
else if (origin !=
"user") {
671 if (origin.empty()) {
672 origin =
"(empty string)";
674 message <<
"invalid value used for 'origin' parameter: "
679 type = origin_element->intValue();
683 message <<
"'origin' argument must be a string or a number";
690 if (message.tellp() == 0) {
695 "DHCP service successfully enabled"));
710 }
catch (
const std::exception& ex) {
715 message =
"unknown error";
721 <<
" interfaces detected.";
724 msg <<
"Unexpected error while retrieving the list of detected interfaces: " << message;
734 "Illegal operation executing 'interface-redetect' on a different thread than main thread"));
743 }
catch (
const std::exception& ex) {
748 message =
"unknown error";
755 msg <<
"Unexpected error while retrieving the list of detected interfaces: " << message;
765 "Illegal operation executing 'interface-add' on a different thread than main thread"));
770 message =
"Missing mandatory 'arguments' parameter.";
773 message =
"arguments for the 'interface-add' command must be a map";
775 ifaces_config = args->get(
"interfaces");
776 if (!ifaces_config) {
777 message =
"Missing mandatory 'interfaces' map parameter in 'arguments'.";
779 auto map = args->mapValue();
780 for (
auto const& key : map) {
781 if (key.first !=
"interfaces") {
782 message =
"Unsupported '" + key.first +
"' map parameter in 'arguments'.";
789 if (!message.empty()) {
792 if (!ifaces_config->size()) {
799 std::set<std::string> seen;
800 auto running_ifaces = running_cfg->toElement()->get(
"interfaces");
801 if (running_ifaces && (running_ifaces->getType() ==
Element::list)) {
802 for (
auto const& item : running_ifaces->listValue()) {
803 seen.insert(item->stringValue());
807 for (
auto const& item : ifaces_config->listValue()) {
808 auto const&
str = item->stringValue();
809 if (seen.find(item->stringValue()) != seen.end()) {
812 seen.insert(item->stringValue());
818 running_cfg->update(*cfg_iface);
820 }
catch (
const std::exception& ex) {
825 message =
"unknown error";
835 msg <<
"Updating used interfaces failed: " << message;
844 arguments->set(
"extended", extended);
867 message =
"Missing mandatory 'remove' parameter.";
871 message =
"Missing mandatory 'remove' parameter.";
873 message =
"'remove' parameter expected to be a boolean.";
875 bool remove_lease = remove_name->boolValue();
876 server_->alloc_engine_->reclaimExpiredLeases4(0, 0, remove_lease);
878 message =
"Reclamation of expired leases is complete.";
894 bool ignore_link_sel =
897 for (
auto const& entry : args->mapValue()) {
898 ostringstream errmsg;
899 if (entry.first ==
"interface") {
901 errmsg <<
"'interface' entry must be a string";
904 selector.
iface_name_ = entry.second->stringValue();
906 }
else if (entry.first ==
"address") {
908 errmsg <<
"'address' entry must be a string";
912 IOAddress addr(entry.second->stringValue());
914 errmsg <<
"bad 'address' entry: not IPv4";
919 }
catch (
const exception& ex) {
920 errmsg <<
"bad 'address' entry: " << ex.what();
923 }
else if (entry.first ==
"relay") {
925 errmsg <<
"'relay' entry must be a string";
929 IOAddress addr(entry.second->stringValue());
931 errmsg <<
"bad 'relay' entry: not IPv4";
936 }
catch (
const exception& ex) {
937 errmsg <<
"bad 'relay' entry: " << ex.what();
940 }
else if (entry.first ==
"local") {
942 errmsg <<
"'local' entry must be a string";
946 IOAddress addr(entry.second->stringValue());
948 errmsg <<
"bad 'local' entry: not IPv4";
953 }
catch (
const exception& ex) {
954 errmsg <<
"bad 'local' entry: " << ex.what();
957 }
else if (entry.first ==
"remote") {
959 errmsg <<
"'remote' entry must be a string";
963 IOAddress addr(entry.second->stringValue());
965 errmsg <<
"bad 'remote' entry: not IPv4";
970 }
catch (
const exception& ex) {
971 errmsg <<
"bad 'remote' entry: " << ex.what();
974 }
else if (entry.first ==
"link") {
976 errmsg <<
"'link' entry must be a string";
980 IOAddress addr(entry.second->stringValue());
982 errmsg <<
"bad 'link' entry: not IPv4";
985 if (!ignore_link_sel) {
989 }
catch (
const exception& ex) {
990 errmsg <<
"bad 'link' entry: " << ex.what();
993 }
else if (entry.first ==
"subnet") {
995 if (args->contains(
"link") && !ignore_link_sel) {
999 errmsg <<
"'subnet' entry must be a string";
1003 IOAddress addr(entry.second->stringValue());
1005 errmsg <<
"bad 'subnet' entry: not IPv4";
1010 }
catch (
const exception& ex) {
1011 errmsg <<
"bad 'subnet' entry: " << ex.what();
1014 }
else if (entry.first ==
"classes") {
1017 "'classes' entry must be a list"));
1019 for (
auto const& item : entry.second->listValue()) {
1021 errmsg <<
"'classes' entry must be a list of strings";
1025 if (!item->stringValue().empty()) {
1031 errmsg <<
"unknown entry '" << entry.first <<
"'";
1036 getCfgSubnets4()->selectSubnet(selector);
1041 subnet->getSharedNetwork(network);
1044 msg <<
"selected shared network '" << network->getName()
1045 <<
"' starting with subnet '" << subnet->toText()
1046 <<
"' id " << subnet->getID();
1048 msg <<
"selected subnet '" << subnet->toText()
1049 <<
"' id " << subnet->getID();
1067 for (
auto const& entry : args->mapValue()) {
1068 ostringstream errmsg;
1069 if (entry.first ==
"interface") {
1071 errmsg <<
"'interface' entry must be a string";
1074 selector.
iface_name_ = entry.second->stringValue();
1076 }
if (entry.first ==
"interface-id") {
1078 errmsg <<
"'interface-id' entry must be a string";
1082 string str = entry.second->stringValue();
1088 errmsg <<
"'interface-id' must be not empty";
1096 errmsg <<
"value of 'interface-id' was not recognized";
1099 }
else if (entry.first ==
"address") {
1101 errmsg <<
"'address' entry must be a string";
1105 IOAddress addr(entry.second->stringValue());
1107 errmsg <<
"bad 'address' entry: not IPv4";
1112 }
catch (
const exception& ex) {
1113 errmsg <<
"bad 'address' entry: " << ex.what();
1116 }
else if (entry.first ==
"relay") {
1118 errmsg <<
"'relay' entry must be a string";
1122 IOAddress addr(entry.second->stringValue());
1124 errmsg <<
"bad 'relay' entry: not IPv4";
1129 }
catch (
const exception& ex) {
1130 errmsg <<
"bad 'relay' entry: " << ex.what();
1133 }
else if (entry.first ==
"local") {
1135 errmsg <<
"'local' entry must be a string";
1139 IOAddress addr(entry.second->stringValue());
1141 errmsg <<
"bad 'local' entry: not IPv6";
1146 }
catch (
const exception& ex) {
1147 errmsg <<
"bad 'local' entry: " << ex.what();
1150 }
else if (entry.first ==
"remote") {
1152 errmsg <<
"'remote' entry must be a string";
1156 IOAddress addr(entry.second->stringValue());
1158 errmsg <<
"bad 'remote' entry: not IPv6";
1163 }
catch (
const exception& ex) {
1164 errmsg <<
"bad 'remote' entry: " << ex.what();
1167 }
else if (entry.first ==
"link") {
1169 errmsg <<
"'link' entry must be a string";
1173 IOAddress addr(entry.second->stringValue());
1175 errmsg <<
"bad 'link' entry: not IPv6";
1180 }
catch (
const exception& ex) {
1181 errmsg <<
"bad 'link' entry: " << ex.what();
1184 }
else if (entry.first ==
"subnet") {
1186 errmsg <<
"'subnet' entry must be a string";
1190 IOAddress addr(entry.second->stringValue());
1192 errmsg <<
"bad 'subnet' entry: not IPv4";
1197 }
catch (
const exception& ex) {
1198 errmsg <<
"bad 'subnet' entry: " << ex.what();
1201 }
else if (entry.first ==
"classes") {
1204 "'classes' entry must be a list"));
1206 for (
auto const& item : entry.second->listValue()) {
1208 errmsg <<
"'classes' entry must be a list of strings";
1212 if (!item->stringValue().empty()) {
1218 errmsg <<
"unknown entry '" << entry.first <<
"'";
1223 getCfgSubnets4()->selectSubnet4o6(selector);
1228 subnet->getSharedNetwork(network);
1231 msg <<
"selected shared network '" << network->getName()
1232 <<
"' starting with subnet '" << subnet->toText()
1233 <<
"' id " << subnet->getID();
1235 msg <<
"selected subnet '" << subnet->toText()
1236 <<
"' id " << subnet->getID();
1244 const std::string& tag =
1257 "Illegal operation executing 'config-backend-pull' on a different thread than main thread"));
1278 auto mode = CBControlDHCPv4::FetchMode::FETCH_UPDATE;
1279 server_->getCBControl()->databaseConfigFetch(srv_cfg, mode);
1280 }
catch (
const std::exception& ex) {
1284 "On demand configuration update failed: " +
1285 string(ex.what())));
1288 "On demand configuration update successful."));
1297 auto now = boost::posix_time::second_clock::universal_time();
1299 if (!
start_.is_not_a_date_time()) {
1300 auto uptime = now -
start_;
1305 if (!last_commit.is_not_a_date_time()) {
1306 auto reload = now - last_commit;
1311 if (mt_mgr.getMode()) {
1315 status->set(
"packet-queue-size",
Element::create(
static_cast<int32_t
>(
1318 queue_stats->add(
Element::create(mt_mgr.getThreadPool().getQueueStat(10)));
1319 queue_stats->add(
Element::create(mt_mgr.getThreadPool().getQueueStat(100)));
1320 queue_stats->add(
Element::create(mt_mgr.getThreadPool().getQueueStat(1000)));
1321 status->set(
"packet-queue-statistics", queue_stats);
1333 for (
auto const& entry : lm_info->mapValue()) {
1334 status->set(entry.first, entry.second);
1341 for (std::string
const&
error : interface->getErrors()) {
1348 if (socket_errors->empty()) {
1353 if (reconnect_ctl && reconnect_ctl->retriesLeft()) {
1358 sockets->set(
"errors", socket_errors);
1360 status->set(
"sockets", sockets);
1398 "no lease backend"));
1410 std::ostringstream err;
1413 err <<
"Server object not initialized, can't process config.";
1430 }
catch (
const std::exception& ex) {
1431 err <<
"Failed to process configuration:" << ex.what();
1441 std::bind(&ControlledDhcpv4Srv::dbLostCallback, srv, ph::_1);
1444 std::bind(&ControlledDhcpv4Srv::dbRecoveredCallback, srv, ph::_1);
1447 std::bind(&ControlledDhcpv4Srv::dbFailedCallback, srv, ph::_1);
1450 string params =
"universe=4";
1451 cfg_db->setAppendedParameters(params);
1452 cfg_db->createManagers();
1457 }
catch (
const std::exception& ex) {
1458 err <<
"Unable to open database: " << ex.what();
1465 }
catch (
const std::exception& ex) {
1466 err <<
"Error starting DHCP_DDNS client after server reconfiguration: "
1474 }
catch (
const std::exception& ex) {
1475 err <<
"error starting DHCPv4-over-DHCPv6 IPC "
1476 " after server reconfiguration: " << ex.what();
1489 }
catch (
const std::exception& ex) {
1490 err <<
"Error setting packet queue controls after server reconfiguration: "
1498 std::bind(&ControlledDhcpv4Srv::openSocketsFailedCallback, srv, ph::_1);
1514 setupTimers(&ControlledDhcpv4Srv::reclaimExpiredLeases,
1515 &ControlledDhcpv4Srv::deleteExpiredReclaimedLeases,
1518 }
catch (
const std::exception& ex) {
1519 err <<
"unable to setup timers for periodically running the"
1520 " reclamation of the expired leases: "
1521 << ex.what() <<
".";
1528 long fetch_time =
static_cast<long>(ctl_info->getConfigFetchWaitTime());
1531 if (fetch_time > 0) {
1537 if (!server_->inTestMode()) {
1538 fetch_time = 1000 * fetch_time;
1541 boost::shared_ptr<unsigned> failure_count(
new unsigned(0));
1543 registerTimer(
"Dhcp4CBFetchTimer",
1544 std::bind(&ControlledDhcpv4Srv::cbFetchUpdates,
1558 if (notify_libraries) {
1559 return (notify_libraries);
1568 }
catch (
const std::exception& ex) {
1569 err <<
"Error applying multi threading settings: "
1588 callout_handle->setArgument(
"io_context", srv->
getIOService());
1590 callout_handle->setArgument(
"json_config",
config);
1591 callout_handle->setArgument(
"server_config",
CfgMgr::instance().getStagingCfg());
1600 callout_handle->getArgument(
"error",
error);
1602 error =
"unknown error";
1617 "Server object not initialized, can't process config.");
1628 uint16_t client_port )
1632 "There is another Dhcpv4Srv instance already.");
1773 timer_mgr_->unregisterTimers();
1827ControlledDhcpv4Srv::reclaimExpiredLeases(
const size_t max_leases,
1828 const uint16_t timeout,
1829 const bool remove_lease,
1830 const uint16_t max_unwarned_cycles) {
1833 server_->
alloc_engine_->reclaimExpiredLeases4(max_leases, timeout,
1835 max_unwarned_cycles);
1839 getCfgExpiration()->getReclaimTimerWaitTime());
1841 }
catch (
const std::exception& ex) {
1850ControlledDhcpv4Srv::deleteExpiredReclaimedLeases(
const uint32_t secs) {
1852 server_->alloc_engine_->deleteExpiredReclaimedLeases4(secs);
1860ControlledDhcpv4Srv::dbLostCallback(
ReconnectCtlPtr db_reconnect_ctl) {
1861 if (!db_reconnect_ctl) {
1868 if (db_reconnect_ctl->retriesLeft() == db_reconnect_ctl->maxRetries() &&
1869 db_reconnect_ctl->alterServiceState()) {
1874 .arg(db_reconnect_ctl->id())
1875 .arg(db_reconnect_ctl->timerName());;
1879 if (!db_reconnect_ctl->retriesLeft() ||
1880 !db_reconnect_ctl->retryInterval()) {
1882 .arg(db_reconnect_ctl->retriesLeft())
1883 .arg(db_reconnect_ctl->retryInterval())
1884 .arg(db_reconnect_ctl->id())
1885 .arg(db_reconnect_ctl->timerName());
1886 if (db_reconnect_ctl->exitOnFailure()) {
1896ControlledDhcpv4Srv::dbRecoveredCallback(
ReconnectCtlPtr db_reconnect_ctl) {
1897 if (!db_reconnect_ctl) {
1904 if (db_reconnect_ctl->retriesLeft() != db_reconnect_ctl->maxRetries() &&
1905 db_reconnect_ctl->alterServiceState()) {
1910 .arg(db_reconnect_ctl->id())
1911 .arg(db_reconnect_ctl->timerName());
1913 db_reconnect_ctl->resetRetries();
1919ControlledDhcpv4Srv::dbFailedCallback(
ReconnectCtlPtr db_reconnect_ctl) {
1920 if (!db_reconnect_ctl) {
1927 .arg(db_reconnect_ctl->maxRetries())
1928 .arg(db_reconnect_ctl->id())
1929 .arg(db_reconnect_ctl->timerName());
1931 if (db_reconnect_ctl->exitOnFailure()) {
1939ControlledDhcpv4Srv::openSocketsFailedCallback(
ReconnectCtlPtr reconnect_ctl) {
1940 if (!reconnect_ctl) {
1946 if (reconnect_ctl->exitOnFailure()) {
1948 .arg(reconnect_ctl->maxRetries());
1952 .arg(reconnect_ctl->maxRetries());
1957ControlledDhcpv4Srv::cbFetchUpdates(
const SrvConfigPtr& srv_cfg,
1958 boost::shared_ptr<unsigned> failure_count) {
1960 MultiThreadingCriticalSection cs;
1964 server_->getCBControl()->databaseConfigFetch(srv_cfg,
1965 CBControlDHCPv4::FetchMode::FETCH_UPDATE);
1966 (*failure_count) = 0;
1968 }
catch (
const std::exception& ex) {
1975 if (++(*failure_count) > 10) {
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.
The IOAddress class represents an IP addresses (version agnostic).
bool isV6() const
Convenience function to check for an IPv6 address.
bool isV4() const
Convenience function to check for an IPv4 address.
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.
static std::string SUPPORTED_SERVICE
Supported service.
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())
Create a NullElement.
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.
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.
Represents selection of interfaces for DHCP server.
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.
isc::data::ConstElementPtr commandConfigReloadHandler(const std::string &command, isc::data::ConstElementPtr args)
Handler for processing 'config-reload' command.
isc::data::ConstElementPtr commandLeasesReclaimHandler(const std::string &command, isc::data::ConstElementPtr args)
Handler for processing 'leases-reclaim' command.
isc::data::ConstElementPtr commandLfcStartHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for processing 'kea-lfc-start' command
virtual ~ControlledDhcpv4Srv()
Destructor.
isc::data::ConstElementPtr commandConfigSetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for processing 'config-set' command
isc::data::ConstElementPtr commandStatusGetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for processing 'status-get' command
isc::data::ConstElementPtr commandConfigGetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for processing 'config-get' command
isc::data::ConstElementPtr commandInterfaceRedetectHandler(const std::string &command, isc::data::ConstElementPtr args)
Handler for processing 'interface-redetect' command.
bool getShutdown() const
Return the server shutdown flag value.
isc::data::ConstElementPtr commandConfigWriteHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for processing 'config-write' command
static isc::data::ConstElementPtr finishConfigHookLibraries(isc::data::ConstElementPtr config)
Configuration checker for hook libraries.
isc::data::ConstElementPtr commandInterfaceListHandler(const std::string &command, isc::data::ConstElementPtr args)
Handler for processing 'interface-list' command.
isc::data::ConstElementPtr commandShutdownHandler(const std::string &command, isc::data::ConstElementPtr args)
Handler for processing 'shutdown' command.
isc::data::ConstElementPtr loadConfigFile(const std::string &file_name)
Configure DHCPv4 server using the configuration file specified.
void cleanup()
Performs cleanup, immediately before termination.
isc::data::ConstElementPtr commandSubnet4o6SelectTestHandler(const std::string &command, isc::data::ConstElementPtr args)
Handler for processing 'subnet4o6-select-test' command.
isc::data::ConstElementPtr commandBuildReportHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for processing 'build-report' command
ControlledDhcpv4Srv(uint16_t server_port=DHCP4_SERVER_PORT, uint16_t client_port=0)
Constructor.
isc::data::ConstElementPtr commandConfigTestHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for processing 'config-test' command
isc::data::ConstElementPtr commandDhcpEnableHandler(const std::string &command, isc::data::ConstElementPtr args)
A handler for processing 'dhcp-enable' command.
isc::data::ConstElementPtr commandConfigBackendPullHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for config-backend-pull command
isc::data::ConstElementPtr commandVersionGetHandler(const std::string &command, isc::data::ConstElementPtr args)
@Brief handler for processing 'version-get' command
static isc::data::ConstElementPtr checkConfig(isc::data::ConstElementPtr config)
Configuration checker.
isc::data::ConstElementPtr commandServerTagGetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for server-tag-get command
void init(const std::string &config_file)
Initializes the server.
isc::data::ConstElementPtr commandStatisticSetMaxSampleCountAllHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for processing 'statistic-sample-count-set-all' command
isc::data::ConstElementPtr commandInterfaceAddHandler(const std::string &command, isc::data::ConstElementPtr args)
Handler for processing 'interface-add' command.
isc::data::ConstElementPtr commandSubnet4SelectTestHandler(const std::string &command, isc::data::ConstElementPtr args)
Handler for processing 'subnet4-select-test' command.
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.
isc::data::ConstElementPtr commandConfigHashGetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for processing 'config-hash-get' command
isc::data::ConstElementPtr commandStatisticSetMaxSampleAgeAllHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for processing 'statistic-sample-age-set-all' command
isc::data::ConstElementPtr commandDhcpDisableHandler(const std::string &command, isc::data::ConstElementPtr args)
A handler for processing 'dhcp-disable' command.
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.
volatile bool shutdown_
Indicates if shutdown is in progress.
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.
size_t size() const
Return the number of interfaces.
const IfaceCollection & getIfaces()
Returns container with all interfaces.
void detectIfaces(bool update_only=false)
Detects network interfaces.
static IfaceMgr & instance()
IfaceMgr is a singleton class.
Parser for the configuration of interfaces.
void parseInterfacesList(const CfgIfacePtr &cfg_iface, isc::data::ConstElementPtr ifaces_list)
parses interfaces-list structure
static TrackingLeaseMgr & instance()
Return current lease manager.
static bool init_allocators_
Flag which indicates if allocators must be initialized.
static void destroy()
Destroy lease manager.
static bool haveInstance()
Indicates if the lease manager has been instantiated.
virtual data::ElementPtr getStatus() const
Return status information.
static void commitRuntimeOptionDefs()
Commits runtime option definitions.
Concrete implementation of a lease database backend using flat file.
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).
RAII class creating a critical section for the receiver thread.
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.
Statistics Manager class.
static StatsMgr & instance()
Statistics Manager accessor method.
RAII class creating a critical section.
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.
static isc::data::ConstElementPtr statisticGlobalGetAllHandler(const std::string &name, const isc::data::ConstElementPtr ¶ms)
Handles statistic-global-get-all 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_COMMAND_UNSUPPORTED
Status code indicating that the specified command is not supported.
const int CONTROL_RESULT_FATAL_ERROR
Status code indicating that the command was unsuccessful and the configuration could not be reverted ...
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
boost::shared_ptr< CfgIface > CfgIfacePtr
A pointer to the CfgIface .
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_FATAL_OPEN_SOCKETS_FAILED
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.
Subnet selector used to specify parameters used to select a subnet.
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.