Kea: ctrl_dhcp6_srv.cc Source File

| Kea 3.2.0-git

ctrl_dhcp6_srv.cc
Go to the documentation of this file.
1// Copyright (C) 2014-2026 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
8
9#include <asiolink/io_service_mgr.h>
10#include <asiolink/process_spawn.h>
11#include <cc/command_interpreter.h>
12#include <cc/data.h>
13#include <config/command_mgr.h>
14#include <config/http_command_mgr.h>
15#include <config/unix_command_mgr.h>
16#include <cryptolink/crypto_hash.h>
17#include <database/dbaccess_parser.h>
18#include <dhcp/libdhcp++.h>
19#include <dhcp6/ctrl_dhcp6_srv.h>
20#include <dhcp6/dhcp6_log.h>
21#include <dhcp6/dhcp6to4_ipc.h>
22#include <dhcp6/json_config_parser.h>
23#include <dhcp6/parser_context.h>
24#include <dhcpsrv/cfg_db_access.h>
25#include <dhcpsrv/cfg_multi_threading.h>
26#include <dhcpsrv/cfgmgr.h>
27#include <dhcpsrv/db_type.h>
28#include <dhcpsrv/host_mgr.h>
29#include <dhcpsrv/lease_mgr_factory.h>
30#include <dhcpsrv/memfile_lease_mgr.h>
31#include <dhcpsrv/parsers/ifaces_config_parser.h>
32#include <hooks/hooks.h>
33#include <hooks/hooks_manager.h>
34#include <process/cfgrpt/config_report.h>
35#include <stats/stats_mgr.h>
36#include <util/encode/encode.h>
37#include <util/multi_threading_mgr.h>
38
39#include <signal.h>
40
41#include <sstream>
42
43using namespace isc::asiolink;
44using namespace isc::config;
45using namespace isc::data;
46using namespace isc::db;
47using namespace isc::dhcp;
48using namespace isc::hooks;
49using namespace isc::stats;
50using namespace isc::util;
51using namespace std;
52namespace ph = std::placeholders;
53
54namespace {
55
57struct CtrlDhcp6Hooks {
58 int hooks_index_dhcp6_srv_configured_;
59
61 CtrlDhcp6Hooks() {
62 hooks_index_dhcp6_srv_configured_ = HooksManager::registerHook("dhcp6_srv_configured");
63 }
64
65};
66
67// Declare a Hooks object. As this is outside any function or method, it
68// will be instantiated (and the constructor run) when the module is loaded.
69// As a result, the hook indexes will be defined before any method in this
70// module is called.
71CtrlDhcp6Hooks Hooks;
72
73// Name of the file holding server identifier.
74static const char* SERVER_DUID_FILE = "kea-dhcp6-serverid";
75
85void signalHandler(int signo) {
86 // SIGHUP signals a request to reconfigure the server.
87 if (signo == SIGHUP) {
88 CommandMgr::instance().processCommand(createCommand("config-reload"));
89 } else if ((signo == SIGTERM) || (signo == SIGINT)) {
90 CommandMgr::instance().processCommand(createCommand("shutdown"));
91 }
92}
93
94}
95
96namespace isc {
97namespace dhcp {
98
99 ControlledDhcpv6Srv* ControlledDhcpv6Srv::server_ = 0;
100
101void
102ControlledDhcpv6Srv::init(const std::string& file_name) {
103 // Keep the call timestamp.
104 start_ = boost::posix_time::second_clock::universal_time();
105
106 // Configure the server using JSON file.
107 ConstElementPtr result = loadConfigFile(file_name);
108
109 int rcode;
110 ConstElementPtr comment = isc::config::parseAnswer(rcode, result);
111 if (rcode != CONTROL_RESULT_SUCCESS) {
112 string reason = comment ? comment->stringValue() :
113 "no details available";
114 isc_throw(isc::BadValue, reason);
115 }
116
117 // Set signal handlers. When the SIGHUP is received by the process
118 // the server reconfiguration will be triggered. When SIGTERM or
119 // SIGINT will be received, the server will start shutting down.
120 signal_set_.reset(new IOSignalSet(getIOService(), signalHandler));
121
122 signal_set_->add(SIGINT);
123 signal_set_->add(SIGHUP);
124 signal_set_->add(SIGTERM);
125}
126
127 void ControlledDhcpv6Srv::cleanup() {
128 signal_set_.reset();
129 getIOService()->stopAndPoll();
130}
131
132 ConstElementPtr
133ControlledDhcpv6Srv::loadConfigFile(const std::string& file_name) {
134 // This is a configuration backend implementation that reads the
135 // configuration from a JSON file.
136
137 isc::data::ConstElementPtr json;
138 isc::data::ConstElementPtr result;
139
140 // Basic sanity check: file name must not be empty.
141 try {
142 if (file_name.empty()) {
143 // Basic sanity check: file name must not be empty.
144 isc_throw(isc::BadValue, "JSON configuration file not specified."
145 " Please use -c command line option.");
146 }
147
148 // Read contents of the file and parse it as JSON
149 Parser6Context parser;
150 json = parser.parseFile(file_name, Parser6Context::PARSER_DHCP6);
151 if (!json) {
152 isc_throw(isc::BadValue, "no configuration found");
153 }
154
155 // Let's do sanity check before we call json->get() which
156 // works only for map.
157 if (json->getType() != isc::data::Element::map) {
158 isc_throw(isc::BadValue, "Configuration file is expected to be "
159 "a map, i.e., start with { and end with } and contain "
160 "at least an entry called 'Dhcp6' that itself is a map. "
161 << file_name
162 << " is a valid JSON, but its top element is not a map."
163 " Did you forget to add { } around your configuration?");
164 }
165
166 // Use parsed JSON structures to configure the server
167 result = CommandMgr::instance().processCommand(createCommand("config-set", json));
168 if (!result) {
169 // Undetermined status of the configuration. This should never
170 // happen, but as the configureDhcp6Server returns a pointer, it is
171 // theoretically possible that it will return NULL.
172 isc_throw(isc::BadValue, "undefined result of "
173 "process command \"config-set\"");
174 }
175
176 // Now check is the returned result is successful (rcode=0) or not
177 // (see @ref isc::config::parseAnswer).
178 int rcode;
179 ConstElementPtr comment = isc::config::parseAnswer(rcode, result);
180 if (rcode != CONTROL_RESULT_SUCCESS) {
181 string reason = comment ? comment->stringValue() :
182 "no details available";
183 isc_throw(isc::BadValue, reason);
184 }
185 } catch (const std::exception& ex) {
186 // If configuration failed at any stage, we drop the staging
187 // configuration and continue to use the previous one.
188 CfgMgr::instance().clearStagingConfiguration();
189
190 LOG_ERROR(dhcp6_logger, DHCP6_CONFIG_LOAD_FAIL)
191 .arg(file_name).arg(ex.what());
192 isc_throw(isc::BadValue, "configuration error using file '"
193 << file_name << "': " << ex.what());
194 }
195
196 LOG_INFO(dhcp6_logger, DHCP6_MULTI_THREADING_INFO)
197 .arg(MultiThreadingMgr::instance().getMode() ? "yes" : "no")
198 .arg(MultiThreadingMgr::instance().getThreadPoolSize())
199 .arg(MultiThreadingMgr::instance().getPacketQueueSize());
200
201 return (result);
202}
203
204bool
205ControlledDhcpv6Srv::getShutdown() const {
206 return (Dhcpv6Srv::shutdown_);
207}
208
209 ConstElementPtr
210ControlledDhcpv6Srv::commandShutdownHandler(const string&, ConstElementPtr args) {
211 if (!ControlledDhcpv6Srv::getInstance()) {
212 LOG_WARN(dhcp6_logger, DHCP6_NOT_RUNNING);
213 return (createAnswer(CONTROL_RESULT_ERROR, "Shutdown failure."));
214 }
215
216 int exit_value = 0;
217 if (args) {
218 // @todo Should we go ahead and shutdown even if the args are invalid?
219 if (args->getType() != Element::map) {
220 return (createAnswer(CONTROL_RESULT_ERROR, "Argument must be a map"));
221 }
222
223 ConstElementPtr param = args->get("exit-value");
224 if (param) {
225 if (param->getType() != Element::integer) {
226 return (createAnswer(CONTROL_RESULT_ERROR,
227 "parameter 'exit-value' is not an integer"));
228 }
229
230 exit_value = param->intValue();
231 }
232 }
233
234 ControlledDhcpv6Srv::getInstance()->shutdownServer(exit_value);
235 return (createAnswer(CONTROL_RESULT_SUCCESS, "Shutting down."));
236}
237
238 ConstElementPtr
239ControlledDhcpv6Srv::commandConfigReloadHandler(const string&,
240 ConstElementPtr /*args*/) {
241 if (!IfaceMgr::instance().isMainThread()) {
242 return (isc::config::createAnswer(CONTROL_RESULT_ERROR,
243 "Illegal operation executing 'config-reload' on a different thread than main thread"));
244 }
245 // Get configuration file name.
246 string file = ControlledDhcpv6Srv::getInstance()->getConfigFile();
247 try {
248 LOG_INFO(dhcp6_logger, DHCP6_DYNAMIC_RECONFIGURATION).arg(file);
249 auto result = loadConfigFile(file);
250 LOG_INFO(dhcp6_logger, DHCP6_DYNAMIC_RECONFIGURATION_SUCCESS).arg(file);
251 return (result);
252 } catch (const std::exception& ex) {
253 // Log the unsuccessful reconfiguration. The reason for failure
254 // should be already logged. Don't rethrow an exception so as
255 // the server keeps working.
256 LOG_FATAL(dhcp6_logger, DHCP6_DYNAMIC_RECONFIGURATION_FAIL)
257 .arg(file);
258 return (createAnswer(CONTROL_RESULT_ERROR,
259 "Config reload failed: " + string(ex.what())));
260 }
261}
262
263 ConstElementPtr
264ControlledDhcpv6Srv::commandConfigGetHandler(const string&,
265 ConstElementPtr /*args*/) {
266 ElementPtr config = CfgMgr::instance().getCurrentCfg()->toElement();
267 string hash = BaseCommandMgr::getHash(config);
268 config->set("hash", Element::create(hash));
269
270 return (createAnswer(CONTROL_RESULT_SUCCESS, config));
271}
272
273 ConstElementPtr
274ControlledDhcpv6Srv::commandConfigHashGetHandler(const string&,
275 ConstElementPtr /*args*/) {
276 ConstElementPtr config = CfgMgr::instance().getCurrentCfg()->toElement();
277
278 string hash = BaseCommandMgr::getHash(config);
279
280 ElementPtr params = Element::createMap();
281 params->set("hash", Element::create(hash));
282 return (createAnswer(CONTROL_RESULT_SUCCESS, params));
283}
284
285 ConstElementPtr
286ControlledDhcpv6Srv::commandConfigWriteHandler(const string&,
287 ConstElementPtr args) {
288 string filename;
289
290 if (args) {
291 if (args->getType() != Element::map) {
292 return (createAnswer(CONTROL_RESULT_ERROR, "Argument must be a map"));
293 }
294 ConstElementPtr filename_param = args->get("filename");
295 if (filename_param) {
296 if (filename_param->getType() != Element::string) {
297 return (createAnswer(CONTROL_RESULT_ERROR,
298 "passed parameter 'filename' is not a string"));
299 }
300 filename = filename_param->stringValue();
301 }
302 }
303
304 if (filename.empty()) {
305 // filename parameter was not specified, so let's use whatever we remember
306 // from the command-line
307 filename = getConfigFile();
308 if (filename.empty()) {
309 return (createAnswer(CONTROL_RESULT_ERROR, "Unable to determine filename."
310 "Please specify filename explicitly."));
311 }
312 } else {
313 try {
314 checkWriteConfigFile(filename);
315 } catch (const isc::Exception& ex) {
316 std::ostringstream msg;
317 msg << "not allowed to write config into " << filename
318 << ": " << ex.what();
319 return (createAnswer(CONTROL_RESULT_ERROR, msg.str()));
320 }
321 }
322
323 // Ok, it's time to write the file.
324 size_t size = 0;
325 try {
326 ConstElementPtr cfg = CfgMgr::instance().getCurrentCfg()->toElement();
327 size = writeConfigFile(filename, cfg);
328 } catch (const isc::Exception& ex) {
329 return (createAnswer(CONTROL_RESULT_ERROR, string("Error during config-write: ")
330 + ex.what()));
331 }
332 if (size == 0) {
333 return (createAnswer(CONTROL_RESULT_ERROR, "Error writing configuration to "
334 + filename));
335 }
336
337 // Ok, it's time to return the successful response.
338 ElementPtr params = Element::createMap();
339 params->set("size", Element::create(static_cast<long long>(size)));
340 params->set("filename", Element::create(filename));
341
342 return (createAnswer(CONTROL_RESULT_SUCCESS, "Configuration written to "
343 + filename + " successful", params));
344}
345
346 ConstElementPtr
347ControlledDhcpv6Srv::commandConfigSetHandler(const string&,
348 ConstElementPtr args) {
349 if (!IfaceMgr::instance().isMainThread()) {
350 return (isc::config::createAnswer(CONTROL_RESULT_ERROR,
351 "Illegal operation executing 'config-set' on a different thread than main thread"));
352 }
353 const int status_code = CONTROL_RESULT_ERROR;
354 ConstElementPtr dhcp6;
355 string message;
356
357 // Command arguments are expected to be:
358 // { "Dhcp6": { ... } }
359 if (!args) {
360 message = "Missing mandatory 'arguments' parameter.";
361 } else {
362 dhcp6 = args->get("Dhcp6");
363 if (!dhcp6) {
364 message = "Missing mandatory 'Dhcp6' parameter.";
365 } else if (dhcp6->getType() != Element::map) {
366 message = "'Dhcp6' parameter expected to be a map.";
367 }
368 }
369
370 // Check unsupported objects.
371 if (message.empty()) {
372 for (auto const& obj : args->mapValue()) {
373 const string& obj_name = obj.first;
374 if (obj_name != "Dhcp6") {
375 LOG_ERROR(dhcp6_logger, DHCP6_CONFIG_UNSUPPORTED_OBJECT)
376 .arg(obj_name);
377 if (message.empty()) {
378 message = "Unsupported '" + obj_name + "' parameter";
379 } else {
380 message += " (and '" + obj_name + "')";
381 }
382 }
383 }
384 if (!message.empty()) {
385 message += ".";
386 }
387 }
388
389 if (!message.empty()) {
390 // Something is amiss with arguments, return a failure response.
391 ConstElementPtr result = isc::config::createAnswer(status_code,
392 message);
393 return (result);
394 }
395
396 if (LeaseMgrFactory::haveInstance() &&
397 (LeaseMgrFactory::instance().getType() == "memfile")) {
398 Memfile_LeaseMgr& mgr = dynamic_cast<Memfile_LeaseMgr&>(LeaseMgrFactory::instance());
399 auto file_name = mgr.getLeaseFilePath(Memfile_LeaseMgr::V6);
400 if (Memfile_LeaseMgr::isLFCProcessRunning(file_name, Memfile_LeaseMgr::V6)) {
401 return (isc::config::createAnswer(CONTROL_RESULT_ERROR,
402 "Can not update configuration while lease file cleanup process is running."));
403 }
404 }
405
406 // stop thread pool (if running)
407 MultiThreadingCriticalSection cs;
408
409 // We are starting the configuration process so we should remove any
410 // staging configuration that has been created during previous
411 // configuration attempts.
412 CfgMgr::instance().clearStagingConfiguration();
413
414 // Parse the logger configuration explicitly into the staging config.
415 // Note this does not alter the current loggers, they remain in
416 // effect until we apply the logging config below. If no logging
417 // is supplied logging will revert to default logging.
418 Daemon::configureLogger(dhcp6, CfgMgr::instance().getStagingCfg());
419
420 // Let's apply the new logging. We do it early, so we'll be able to print
421 // out what exactly is wrong with the new config in case of problems.
422 CfgMgr::instance().getStagingCfg()->applyLoggingCfg();
423
424 // Now we configure the server proper.
425 ConstElementPtr result = processConfig(dhcp6);
426
427 // If the configuration parsed successfully, apply the new logger
428 // configuration and then commit the new configuration. We apply
429 // the logging first in case there's a configuration failure.
430 int rcode = 0;
431 isc::config::parseAnswer(rcode, result);
432 if (getShutdown() && (rcode == CONTROL_RESULT_SUCCESS)) {
433 // Do not return success when a fatal error was triggered.
434 rcode = CONTROL_RESULT_FATAL_ERROR;
435 message = "Reconfiguration triggered a fatal error: shutting down.";
436 result = isc::config::createAnswer(rcode, message);
437 }
438 if (rcode == CONTROL_RESULT_SUCCESS) {
439 CfgMgr::instance().getStagingCfg()->applyLoggingCfg();
440
441 // Use new configuration.
442 CfgMgr::instance().commit();
443 } else if (CfgMgr::instance().getCurrentCfg()->getSequence() != 0) {
444 // Ok, we applied the logging from the upcoming configuration, but
445 // there were problems with the config. As such, we need to back off
446 // and revert to the previous logging configuration. This is not done if
447 // sequence == 0, because that would mean always reverting to stdout by
448 // default, and it is arguably more helpful to have the error in a
449 // potential file or syslog configured in the upcoming configuration.
450 CfgMgr::instance().getCurrentCfg()->applyLoggingCfg();
451
452 if (rcode == CONTROL_RESULT_FATAL_ERROR) {
453 // Not initial configuration so someone can believe we reverted
454 // to the previous configuration. It is not the case so be clear
455 // about this.
456 LOG_FATAL(dhcp6_logger, DHCP6_CONFIG_UNRECOVERABLE_ERROR);
457 }
458 }
459
461 try {
462 // Handle events registered by hooks using external IOService objects.
463 IOServiceMgr::instance().pollIOServices();
464 } catch (const std::exception& ex) {
465 if (rcode == CONTROL_RESULT_FATAL_ERROR) {
466 return (result);
467 }
468 std::ostringstream err;
469 err << "Error initializing hooks: "
470 << ex.what();
471 return (isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str()));
472 }
473
474 return (result);
475}
476
477 ConstElementPtr
478ControlledDhcpv6Srv::commandConfigTestHandler(const string&,
479 ConstElementPtr args) {
480 if (!IfaceMgr::instance().isMainThread()) {
481 return (isc::config::createAnswer(CONTROL_RESULT_ERROR,
482 "Illegal operation executing 'config-test' on a different thread than main thread"));
483 }
484 const int status_code = CONTROL_RESULT_ERROR; // 1 indicates an error
485 ConstElementPtr dhcp6;
486 string message;
487
488 // Command arguments are expected to be:
489 // { "Dhcp6": { ... } }
490 if (!args) {
491 message = "Missing mandatory 'arguments' parameter.";
492 } else {
493 dhcp6 = args->get("Dhcp6");
494 if (!dhcp6) {
495 message = "Missing mandatory 'Dhcp6' parameter.";
496 } else if (dhcp6->getType() != Element::map) {
497 message = "'Dhcp6' parameter expected to be a map.";
498 }
499 }
500
501 // Check unsupported objects.
502 if (message.empty()) {
503 for (auto const& obj : args->mapValue()) {
504 const string& obj_name = obj.first;
505 if (obj_name != "Dhcp6") {
506 LOG_ERROR(dhcp6_logger, DHCP6_CONFIG_UNSUPPORTED_OBJECT)
507 .arg(obj_name);
508 if (message.empty()) {
509 message = "Unsupported '" + obj_name + "' parameter";
510 } else {
511 message += " (and '" + obj_name + "')";
512 }
513 }
514 }
515 if (!message.empty()) {
516 message += ".";
517 }
518 }
519
520 if (!message.empty()) {
521 // Something is amiss with arguments, return a failure response.
522 ConstElementPtr result = isc::config::createAnswer(status_code,
523 message);
524 return (result);
525 }
526
527 // stop thread pool (if running)
528 MultiThreadingCriticalSection cs;
529
530 // We are starting the configuration process so we should remove any
531 // staging configuration that has been created during previous
532 // configuration attempts.
533 CfgMgr::instance().clearStagingConfiguration();
534
535 // Now we check the server proper.
536 return (checkConfig(dhcp6));
537}
538
539 ConstElementPtr
540ControlledDhcpv6Srv::commandDhcpDisableHandler(const std::string&,
541 ConstElementPtr args) {
542 std::ostringstream message;
543 int64_t max_period = 0;
544 std::string origin;
545
546 // If the args map does not contain 'origin' parameter, the default type
547 // will be used (user command).
548 auto type = NetworkState::USER_COMMAND;
549
550 // Parse arguments to see if the 'max-period' or 'origin' parameters have
551 // been specified.
552 if (args) {
553 // Arguments must be a map.
554 if (args->getType() != Element::map) {
555 message << "arguments for the 'dhcp-disable' command must be a map";
556
557 } else {
558 ConstElementPtr max_period_element = args->get("max-period");
559 // max-period is optional.
560 if (max_period_element) {
561 // It must be an integer, if specified.
562 if (max_period_element->getType() != Element::integer) {
563 message << "'max-period' argument must be a number";
564
565 } else {
566 // It must be positive integer.
567 max_period = max_period_element->intValue();
568 if (max_period <= 0) {
569 message << "'max-period' must be positive integer";
570 }
571 }
572 }
573 // 'origin-id' replaces the older parameter 'origin' since Kea 2.5.8
574 // stable release. However, the 'origin' is kept for backward compatibility
575 // with Kea versions before 2.5.8. It is common to receive both parameters
576 // because HA hook library sends both in case the partner server hasn't been
577 // upgraded to the new version. The 'origin-id' takes precedence over the
578 // 'origin'.
579 ConstElementPtr origin_id_element = args->get("origin-id");
580 ConstElementPtr origin_element = args->get("origin");
581 // The 'origin-id' and 'origin' arguments are optional.
582 if (origin_id_element) {
583 if (origin_id_element->getType() == Element::integer) {
584 type = origin_id_element->intValue();
585 } else {
586 message << "'origin-id' argument must be a number";
587 }
588 } else if (origin_element) {
589 switch (origin_element->getType()) {
590 case Element::string:
591 origin = origin_element->stringValue();
592 if (origin == "ha-partner") {
593 type = NetworkState::HA_REMOTE_COMMAND;
594 } else if (origin != "user") {
595 if (origin.empty()) {
596 origin = "(empty string)";
597 }
598 message << "invalid value used for 'origin' parameter: "
599 << origin;
600 }
601 break;
602 case Element::integer:
603 type = origin_element->intValue();
604 break;
605 default:
606 // It must be a string or a number, if specified.
607 message << "'origin' argument must be a string or a number";
608 }
609 }
610 }
611 }
612
613 // No error occurred, so let's disable the service.
614 if (message.tellp() == 0) {
615 message << "DHCPv6 service disabled";
616 if (max_period > 0) {
617 message << " for " << max_period << " seconds";
618
619 // The user specified that the DHCP service should resume not
620 // later than in max-period seconds. If the 'dhcp-enable' command
621 // is not sent, the DHCP service will resume automatically.
622 network_state_->delayedEnableService(static_cast<unsigned>(max_period),
623 type);
624 }
625 network_state_->disableService(type);
626
627 // Success.
628 return (config::createAnswer(CONTROL_RESULT_SUCCESS, message.str()));
629 }
630
631 // Failure.
632 return (config::createAnswer(CONTROL_RESULT_ERROR, message.str()));
633}
634
635 ConstElementPtr
636ControlledDhcpv6Srv::commandDhcpEnableHandler(const std::string&,
637 ConstElementPtr args) {
638 std::ostringstream message;
639 std::string origin;
640
641 // If the args map does not contain 'origin' parameter, the default type
642 // will be used (user command).
643 auto type = NetworkState::USER_COMMAND;
644
645 // Parse arguments to see if the 'origin' parameter has been specified.
646 if (args) {
647 // Arguments must be a map.
648 if (args->getType() != Element::map) {
649 message << "arguments for the 'dhcp-enable' command must be a map";
650
651 } else {
652 // 'origin-id' replaces the older parameter 'origin' since Kea 2.5.8
653 // stable release. However, the 'origin' is kept for backward compatibility
654 // with Kea versions before 2.5.8. It is common to receive both parameters
655 // because HA hook library sends both in case the partner server hasn't been
656 // upgraded to the new version. The 'origin-id' takes precedence over the
657 // 'origin'.
658 ConstElementPtr origin_id_element = args->get("origin-id");
659 ConstElementPtr origin_element = args->get("origin");
660 // The 'origin-id' and 'origin' arguments are optional.
661 if (origin_id_element) {
662 if (origin_id_element->getType() == Element::integer) {
663 type = origin_id_element->intValue();
664 } else {
665 message << "'origin-id' argument must be a number";
666 }
667 } else if (origin_element) {
668 switch (origin_element->getType()) {
669 case Element::string:
670 origin = origin_element->stringValue();
671 if (origin == "ha-partner") {
672 type = NetworkState::HA_REMOTE_COMMAND;
673 } else if (origin != "user") {
674 if (origin.empty()) {
675 origin = "(empty string)";
676 }
677 message << "invalid value used for 'origin' parameter: "
678 << origin;
679 }
680 break;
681 case Element::integer:
682 type = origin_element->intValue();
683 break;
684 default:
685 // It must be a string or a number, if specified.
686 message << "'origin' argument must be a string or a number";
687 }
688 }
689 }
690 }
691
692 // No error occurred, so let's enable the service.
693 if (message.tellp() == 0) {
694 network_state_->enableService(type);
695
696 // Success.
697 return (config::createAnswer(CONTROL_RESULT_SUCCESS,
698 "DHCP service successfully enabled"));
699 }
700
701 // Failure.
702 return (config::createAnswer(CONTROL_RESULT_ERROR, message.str()));
703}
704
705 ConstElementPtr
706ControlledDhcpv6Srv::commandInterfaceListHandler(const std::string&,
707 ConstElementPtr) {
708 ElementPtr ifaces = Element::createMap();
709 std::string message;
710 bool error = false;
711 try {
712 ifaces->set("interfaces", IfaceMgr::instance().ifacesToElement());
713 } catch (const std::exception& ex) {
714 error = true;
715 message = ex.what();
716 } catch (...) {
717 error = true;
718 message = "unknown error";
719 }
720
721 ostringstream msg;
722 if (!error) {
723 msg << IfaceMgr::instance().getIfaces().size()
724 << " interfaces detected.";
725 return (isc::config::createAnswer(CONTROL_RESULT_SUCCESS, msg.str(), ifaces));
726 } else {
727 msg << "Unexpected error while retrieving the list of detected interfaces: " << message;
728 return (isc::config::createAnswer(CONTROL_RESULT_ERROR, msg.str()));
729 }
730}
731
732 ConstElementPtr
733ControlledDhcpv6Srv::commandInterfaceRedetectHandler(const std::string&,
734 ConstElementPtr args) {
735 if (!IfaceMgr::instance().isMainThread()) {
736 return (isc::config::createAnswer(CONTROL_RESULT_ERROR,
737 "Illegal operation executing 'interface-redetect' on a different thread than main thread"));
738 }
739 std::string message;
740 bool error = false;
741 try {
742 // stop thread pool (if running)
743 MultiThreadingCriticalSection cs;
744 ReceiverCriticalSection rcs;
745 IfaceMgr::instance().detectIfaces(true);
746 } catch (const std::exception& ex) {
747 error = true;
748 message = ex.what();
749 } catch (...) {
750 error = true;
751 message = "unknown error";
752 }
753
754 ostringstream msg;
755 if (!error) {
756 return (ControlledDhcpv6Srv::commandInterfaceListHandler("", args));
757 } else {
758 msg << "Unexpected error while retrieving the list of detected interfaces: " << message;
759 return (isc::config::createAnswer(CONTROL_RESULT_ERROR, msg.str()));
760 }
761}
762
763 ConstElementPtr
764ControlledDhcpv6Srv::commandInterfaceAddHandler(const std::string&,
765 ConstElementPtr args) {
766 if (!IfaceMgr::instance().isMainThread()) {
767 return (isc::config::createAnswer(CONTROL_RESULT_ERROR,
768 "Illegal operation executing 'interface-add' on a different thread than main thread"));
769 }
770 string message;
771 ConstElementPtr ifaces_config;
772 if (!args) {
773 message = "Missing mandatory 'arguments' parameter.";
774 } else {
775 if (args->getType() != Element::map) {
776 message = "arguments for the 'interface-add' command must be a map";
777 } else {
778 ifaces_config = args->get("interfaces");
779 if (!ifaces_config) {
780 message = "Missing mandatory 'interfaces' map parameter in 'arguments'.";
781 }
782 auto map = args->mapValue();
783 for (auto const& key : map) {
784 if (key.first != "interfaces") {
785 message = "Unsupported '" + key.first + "' map parameter in 'arguments'.";
786 break;
787 }
788 }
789 }
790 }
791
792 if (!message.empty()) {
793 return (isc::config::createAnswer(CONTROL_RESULT_ERROR, message));
794 }
795 if (!ifaces_config->size()) {
796 return (isc::config::createAnswer(CONTROL_RESULT_SUCCESS, "Interface configuration successfully updated."));
797 }
798 bool error = false;
799 try {
800 CfgIfacePtr running_cfg = CfgMgr::instance().getCurrentCfg()->getCfgIface();
801 ElementPtr ifaces = Element::createList();
802 std::set<std::string> seen;
803 auto running_ifaces = running_cfg->toElement()->get("interfaces");
804 if (running_ifaces && (running_ifaces->getType() == Element::list)) {
805 for (auto const& item : running_ifaces->listValue()) {
806 seen.insert(item->stringValue());
807 ifaces->add(item);
808 }
809 }
810 for (auto const& item : ifaces_config->listValue()) {
811 auto const& str = item->stringValue();
812 if (seen.find(item->stringValue()) != seen.end()) {
813 continue;
814 }
815 seen.insert(item->stringValue());
816 ifaces->add(item);
817 }
818 IfacesConfigParser parser(AF_INET6, true);
819 CfgIfacePtr cfg_iface(new CfgIface());
820 parser.parseInterfacesList(cfg_iface, ifaces);
821 running_cfg->update(*cfg_iface);
822 running_cfg->triggerOpenSocketsWithRetry(AF_INET6, getServerPort());
823 } catch (const std::exception& ex) {
824 error = true;
825 message = ex.what();
826 } catch (...) {
827 error = true;
828 message = "unknown error";
829 }
830
831 ostringstream msg;
832 if (!error) {
833 if (getShutdown()) {
834 return (isc::config::createAnswer(CONTROL_RESULT_FATAL_ERROR, "Interface configuration update triggered a fatal error: shutting down."));
835 }
836 return (isc::config::createAnswer(CONTROL_RESULT_SUCCESS, "Interface configuration successfully updated."));
837 } else {
838 msg << "Updating used interfaces failed: " << message;
839 return (isc::config::createAnswer(CONTROL_RESULT_ERROR, msg.str()));
840 }
841}
842
843 ConstElementPtr
844ControlledDhcpv6Srv::commandVersionGetHandler(const string&, ConstElementPtr) {
845 ElementPtr extended = Element::create(Dhcpv6Srv::getVersion(true));
846 ElementPtr arguments = Element::createMap();
847 arguments->set("extended", extended);
848 ConstElementPtr answer = isc::config::createAnswer(CONTROL_RESULT_SUCCESS,
849 Dhcpv6Srv::getVersion(false),
850 arguments);
851 return (answer);
852}
853
854 ConstElementPtr
855ControlledDhcpv6Srv::commandBuildReportHandler(const string&,
856 ConstElementPtr) {
857 ConstElementPtr answer =
858 isc::config::createAnswer(CONTROL_RESULT_SUCCESS, isc::detail::getConfigReport());
859 return (answer);
860}
861
862 ConstElementPtr
863ControlledDhcpv6Srv::commandLeasesReclaimHandler(const string&,
864 ConstElementPtr args) {
865 int status_code = CONTROL_RESULT_ERROR;
866 string message;
867
868 // args must be { "remove": <bool> }
869 if (!args) {
870 message = "Missing mandatory 'remove' parameter.";
871 } else {
872 ConstElementPtr remove_name = args->get("remove");
873 if (!remove_name) {
874 message = "Missing mandatory 'remove' parameter.";
875 } else if (remove_name->getType() != Element::boolean) {
876 message = "'remove' parameter expected to be a boolean.";
877 } else {
878 bool remove_lease = remove_name->boolValue();
879 server_->alloc_engine_->reclaimExpiredLeases6(0, 0, remove_lease);
880 status_code = 0;
881 message = "Reclamation of expired leases is complete.";
882 }
883 }
884 ConstElementPtr answer = isc::config::createAnswer(status_code, message);
885 return (answer);
886}
887
888 ConstElementPtr
889ControlledDhcpv6Srv::commandSubnet6SelectTestHandler(const string&,
890 ConstElementPtr args) {
891 if (!args) {
892 return (createAnswer(CONTROL_RESULT_ERROR, "empty arguments"));
893 }
894 if (args->getType() != Element::map) {
895 return (createAnswer(CONTROL_RESULT_ERROR, "arguments must be a map"));
896 }
897 SubnetSelector selector;
898 selector.remote_address_ = IOAddress::IPV6_ZERO_ADDRESS();
899 for (auto const& entry : args->mapValue()) {
900 ostringstream errmsg;
901 if (entry.first == "interface") {
902 if (entry.second->getType() != Element::string) {
903 errmsg << "'interface' entry must be a string";
904 return (createAnswer(CONTROL_RESULT_ERROR, errmsg.str()));
905 }
906 selector.iface_name_ = entry.second->stringValue();
907 continue;
908 } if (entry.first == "interface-id") {
909 if (entry.second->getType() != Element::string) {
910 errmsg << "'interface-id' entry must be a string";
911 return (createAnswer(CONTROL_RESULT_ERROR, errmsg.str()));
912 }
913 try {
914 string str = entry.second->stringValue();
915 vector<uint8_t> id = util::str::quotedStringToBinary(str);
916 if (id.empty()) {
917 util::str::decodeFormattedHexString(str, id);
918 }
919 if (id.empty()) {
920 errmsg << "'interface-id' must be not empty";
921 return (createAnswer(CONTROL_RESULT_ERROR, errmsg.str()));
922 }
923 selector.interface_id_ = OptionPtr(new Option(Option::V6,
924 D6O_INTERFACE_ID,
925 id));
926 continue;
927 } catch (...) {
928 errmsg << "value of 'interface-id' was not recognized";
929 return (createAnswer(CONTROL_RESULT_ERROR, errmsg.str()));
930 }
931 } else if (entry.first == "remote") {
932 if (entry.second->getType() != Element::string) {
933 errmsg << "'remote' entry must be a string";
934 return (createAnswer(CONTROL_RESULT_ERROR, errmsg.str()));
935 }
936 try {
937 IOAddress addr(entry.second->stringValue());
938 if (!addr.isV6()) {
939 errmsg << "bad 'remote' entry: not IPv6";
940 return (createAnswer(CONTROL_RESULT_ERROR, errmsg.str()));
941 }
942 selector.remote_address_ = addr;
943 continue;
944 } catch (const exception& ex) {
945 errmsg << "bad 'remote' entry: " << ex.what();
946 return (createAnswer(CONTROL_RESULT_ERROR, errmsg.str()));
947 }
948 } else if (entry.first == "link") {
949 if (entry.second->getType() != Element::string) {
950 errmsg << "'link' entry must be a string";
951 return (createAnswer(CONTROL_RESULT_ERROR, errmsg.str()));
952 }
953 try {
954 IOAddress addr(entry.second->stringValue());
955 if (!addr.isV6()) {
956 errmsg << "bad 'link' entry: not IPv6";
957 return (createAnswer(CONTROL_RESULT_ERROR, errmsg.str()));
958 }
959 selector.first_relay_linkaddr_ = addr;
960 continue;
961 } catch (const exception& ex) {
962 errmsg << "bad 'link' entry: " << ex.what();
963 return (createAnswer(CONTROL_RESULT_ERROR, errmsg.str()));
964 }
965 } else if (entry.first == "classes") {
966 if (entry.second->getType() != Element::list) {
967 return (createAnswer(CONTROL_RESULT_ERROR,
968 "'classes' entry must be a list"));
969 }
970 for (auto const& item : entry.second->listValue()) {
971 if (!item || (item->getType() != Element::string)) {
972 errmsg << "'classes' entry must be a list of strings";
973 return (createAnswer(CONTROL_RESULT_ERROR, errmsg.str()));
974 }
975 // Skip empty client classes.
976 if (!item->stringValue().empty()) {
977 selector.client_classes_.insert(item->stringValue());
978 }
979 }
980 continue;
981 } else {
982 errmsg << "unknown entry '" << entry.first << "'";
983 return (createAnswer(CONTROL_RESULT_ERROR, errmsg.str()));
984 }
985 }
986 ConstSubnet6Ptr subnet = CfgMgr::instance().getCurrentCfg()->
987 getCfgSubnets6()->selectSubnet(selector);
988 if (!subnet) {
989 return (createAnswer(CONTROL_RESULT_EMPTY, "no subnet selected"));
990 }
991 SharedNetwork6Ptr network;
992 subnet->getSharedNetwork(network);
993 ostringstream msg;
994 if (network) {
995 msg << "selected shared network '" << network->getName()
996 << "' starting with subnet '" << subnet->toText()
997 << "' id " << subnet->getID();
998 } else {
999 msg << "selected subnet '" << subnet->toText()
1000 << "' id " << subnet->getID();
1001 }
1002 return (createAnswer(CONTROL_RESULT_SUCCESS, msg.str()));
1003}
1004
1005 ConstElementPtr
1006ControlledDhcpv6Srv::commandServerTagGetHandler(const std::string&,
1007 ConstElementPtr) {
1008 const std::string& tag =
1009 CfgMgr::instance().getCurrentCfg()->getServerTag();
1010 ElementPtr response = Element::createMap();
1011 response->set("server-tag", Element::create(tag));
1012
1013 return (createAnswer(CONTROL_RESULT_SUCCESS, response));
1014}
1015
1016 ConstElementPtr
1017ControlledDhcpv6Srv::commandConfigBackendPullHandler(const std::string&,
1018 ConstElementPtr) {
1019 if (!IfaceMgr::instance().isMainThread()) {
1020 return (isc::config::createAnswer(CONTROL_RESULT_ERROR,
1021 "Illegal operation executing 'config-backend-pull' on a different thread than main thread"));
1022 }
1023 auto ctl_info = CfgMgr::instance().getCurrentCfg()->getConfigControlInfo();
1024 if (!ctl_info) {
1025 return (createAnswer(CONTROL_RESULT_EMPTY, "No config backend."));
1026 }
1027
1028 // stop thread pool (if running)
1029 MultiThreadingCriticalSection cs;
1030
1031 // Reschedule the periodic CB fetch.
1032 if (TimerMgr::instance()->isTimerRegistered("Dhcp6CBFetchTimer")) {
1033 TimerMgr::instance()->cancel("Dhcp6CBFetchTimer");
1034 TimerMgr::instance()->setup("Dhcp6CBFetchTimer");
1035 }
1036
1037 // Code from cbFetchUpdates.
1038 // The configuration to use is the current one because this is called
1039 // after the configuration manager commit.
1040 try {
1041 auto srv_cfg = CfgMgr::instance().getCurrentCfg();
1042 auto mode = CBControlDHCPv6::FetchMode::FETCH_UPDATE;
1043 server_->getCBControl()->databaseConfigFetch(srv_cfg, mode);
1044 } catch (const std::exception& ex) {
1045 LOG_ERROR(dhcp6_logger, DHCP6_CB_ON_DEMAND_FETCH_UPDATES_FAIL)
1046 .arg(ex.what());
1047 return (createAnswer(CONTROL_RESULT_ERROR,
1048 "On demand configuration update failed: " +
1049 string(ex.what())));
1050 }
1051 return (createAnswer(CONTROL_RESULT_SUCCESS,
1052 "On demand configuration update successful."));
1053}
1054
1055 ConstElementPtr
1056ControlledDhcpv6Srv::commandStatusGetHandler(const string&,
1057 ConstElementPtr /*args*/) {
1058 ElementPtr status = Element::createMap();
1059 status->set("pid", Element::create(static_cast<int>(getpid())));
1060
1061 auto now = boost::posix_time::second_clock::universal_time();
1062 // Sanity check: start_ is always initialized.
1063 if (!start_.is_not_a_date_time()) {
1064 auto uptime = now - start_;
1065 status->set("uptime", Element::create(uptime.total_seconds()));
1066 }
1067
1068 auto last_commit = CfgMgr::instance().getCurrentCfg()->getLastCommitTime();
1069 if (!last_commit.is_not_a_date_time()) {
1070 auto reload = now - last_commit;
1071 status->set("reload", Element::create(reload.total_seconds()));
1072 }
1073
1074 auto& mt_mgr = MultiThreadingMgr::instance();
1075 if (mt_mgr.getMode()) {
1076 status->set("multi-threading-enabled", Element::create(true));
1077 status->set("thread-pool-size", Element::create(static_cast<int32_t>(
1078 MultiThreadingMgr::instance().getThreadPoolSize())));
1079 status->set("packet-queue-size", Element::create(static_cast<int32_t>(
1080 MultiThreadingMgr::instance().getPacketQueueSize())));
1081 ElementPtr queue_stats = Element::createList();
1082 queue_stats->add(Element::create(mt_mgr.getThreadPool().getQueueStat(10)));
1083 queue_stats->add(Element::create(mt_mgr.getThreadPool().getQueueStat(100)));
1084 queue_stats->add(Element::create(mt_mgr.getThreadPool().getQueueStat(1000)));
1085 status->set("packet-queue-statistics", queue_stats);
1086
1087 } else {
1088 status->set("multi-threading-enabled", Element::create(false));
1089 }
1090
1091 // Merge lease manager status.
1092 ElementPtr lm_info;
1093 if (LeaseMgrFactory::haveInstance()) {
1094 lm_info = LeaseMgrFactory::instance().getStatus();
1095 }
1096 if (lm_info && (lm_info->getType() == Element::map)) {
1097 for (auto const& entry : lm_info->mapValue()) {
1098 status->set(entry.first, entry.second);
1099 }
1100 }
1101
1102 status->set("extended-info-tables", Element::create(
1103 CfgMgr::instance().getCurrentCfg()->getCfgDbAccess()->getExtendedInfoTablesEnabled()));
1104
1105 // Iterate through the interfaces and get all the errors.
1106 ElementPtr socket_errors(Element::createList());
1107 for (IfacePtr const& interface : IfaceMgr::instance().getIfaces()) {
1108 for (std::string const& error : interface->getErrors()) {
1109 socket_errors->add(Element::create(error));
1110 }
1111 }
1112
1113 // Abstract the information from all sockets into a single status.
1114 ElementPtr sockets(Element::createMap());
1115 if (socket_errors->empty()) {
1116 sockets->set("status", Element::create("ready"));
1117 } else {
1118 ReconnectCtlPtr const reconnect_ctl(
1119 CfgMgr::instance().getCurrentCfg()->getCfgIface()->getReconnectCtl());
1120 if (reconnect_ctl && reconnect_ctl->retriesLeft()) {
1121 sockets->set("status", Element::create("retrying"));
1122 } else {
1123 sockets->set("status", Element::create("failed"));
1124 }
1125 sockets->set("errors", socket_errors);
1126 }
1127 status->set("sockets", sockets);
1128
1129 status->set("dhcp-state", network_state_->toElement());
1130
1131 return (createAnswer(CONTROL_RESULT_SUCCESS, status));
1132}
1133
1134 ConstElementPtr
1135ControlledDhcpv6Srv::commandStatisticSetMaxSampleCountAllHandler(const string&,
1136 ConstElementPtr args) {
1137 StatsMgr& stats_mgr = StatsMgr::instance();
1138 ConstElementPtr answer = stats_mgr.statisticSetMaxSampleCountAllHandler(args);
1139 // Update the default parameter.
1140 long max_samples = stats_mgr.getMaxSampleCountDefault();
1141 CfgMgr::instance().getCurrentCfg()->addConfiguredGlobal(
1142 "statistic-default-sample-count", Element::create(max_samples));
1143 return (answer);
1144}
1145
1146 ConstElementPtr
1147ControlledDhcpv6Srv::commandStatisticSetMaxSampleAgeAllHandler(const string&,
1148 ConstElementPtr args) {
1149 StatsMgr& stats_mgr = StatsMgr::instance();
1150 ConstElementPtr answer = stats_mgr.statisticSetMaxSampleAgeAllHandler(args);
1151 // Update the default parameter.
1152 auto duration = stats_mgr.getMaxSampleAgeDefault();
1153 long max_age = toSeconds(duration);
1154 CfgMgr::instance().getCurrentCfg()->addConfiguredGlobal(
1155 "statistic-default-sample-age", Element::create(max_age));
1156 return (answer);
1157}
1158
1159 ConstElementPtr
1160ControlledDhcpv6Srv::commandLfcStartHandler(const string&, ConstElementPtr) {
1161 if (LeaseMgrFactory::haveInstance()) {
1162 return (LeaseMgrFactory::instance().lfcStartHandler());
1163 }
1164 return (createAnswer(CONTROL_RESULT_COMMAND_UNSUPPORTED,
1165 "no lease backend"));
1166}
1167
1168 isc::data::ConstElementPtr
1169ControlledDhcpv6Srv::processConfig(isc::data::ConstElementPtr config) {
1170 ControlledDhcpv6Srv* srv = ControlledDhcpv6Srv::getInstance();
1171
1172 // Allow DB reconnect on startup. The database connection parameters specify
1173 // respective details.
1174 DbConnectionInitWithRetry retry;
1175
1176 // Single stream instance used in all error clauses
1177 std::ostringstream err;
1178
1179 if (!srv) {
1180 err << "Server object not initialized, can't process config.";
1181 return (isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str()));
1182 }
1183
1184 LOG_DEBUG(dhcp6_logger, DBG_DHCP6_COMMAND, DHCP6_CONFIG_RECEIVED)
1185 .arg(srv->redactConfig(config)->str());
1186
1187 ConstElementPtr answer = configureDhcp6Server(*srv, config);
1188
1189 // Check that configuration was successful. If not, do not reopen sockets
1190 // and don't bother with DDNS stuff.
1191 try {
1192 int rcode = 0;
1193 isc::config::parseAnswer(rcode, answer);
1194 if (rcode != CONTROL_RESULT_SUCCESS) {
1195 return (answer);
1196 }
1197 } catch (const std::exception& ex) {
1198 err << "Failed to process configuration:" << ex.what();
1199 return (isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str()));
1200 }
1201
1202 // Enable allocator initialization prior to creating lease manager.
1203 LeaseMgrFactory::init_allocators_ = true;
1204
1205 // Re-open lease and host database with new parameters.
1206 try {
1207 DatabaseConnection::db_lost_callback_ =
1208 std::bind(&ControlledDhcpv6Srv::dbLostCallback, srv, ph::_1);
1209
1210 DatabaseConnection::db_recovered_callback_ =
1211 std::bind(&ControlledDhcpv6Srv::dbRecoveredCallback, srv, ph::_1);
1212
1213 DatabaseConnection::db_failed_callback_ =
1214 std::bind(&ControlledDhcpv6Srv::dbFailedCallback, srv, ph::_1);
1215
1216 CfgDbAccessPtr cfg_db = CfgMgr::instance().getStagingCfg()->getCfgDbAccess();
1217 string params = "universe=6";
1218 if (cfg_db->getExtendedInfoTablesEnabled()) {
1219 params += " extended-info-tables=true";
1220 }
1221 cfg_db->setAppendedParameters(params);
1222 cfg_db->createManagers();
1223 // Reset counters related to connections as all managers have been recreated.
1224 srv->getNetworkState()->resetForDbConnection();
1225 srv->getNetworkState()->resetForLocalCommands();
1226 srv->getNetworkState()->resetForRemoteCommands();
1227 } catch (const std::exception& ex) {
1228 err << "Unable to open database: " << ex.what();
1229 return (isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str()));
1230 }
1231
1232 // Regenerate server identifier if needed.
1233 try {
1234 const std::string duid_file =
1235 std::string(CfgMgr::instance().getDataDir()) + "/" +
1236 std::string(SERVER_DUID_FILE);
1237 DuidPtr duid = CfgMgr::instance().getStagingCfg()->getCfgDUID()->create(duid_file);
1238 server_->serverid_.reset(new Option(Option::V6, D6O_SERVERID, duid->getDuid()));
1239 if (duid) {
1240 LOG_INFO(dhcp6_logger, DHCP6_USING_SERVERID)
1241 .arg(duid->toText())
1242 .arg(duid_file);
1243 }
1244
1245 } catch (const std::exception& ex) {
1246 err << "unable to configure server identifier: " << ex.what();
1247 return (isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str()));
1248 }
1249
1250 // Server will start DDNS communications if its enabled.
1251 try {
1252 srv->startD2();
1253 } catch (const std::exception& ex) {
1254 err << "Error starting DHCP_DDNS client after server reconfiguration: "
1255 << ex.what();
1256 return (isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str()));
1257 }
1258
1259 // Setup DHCPv4-over-DHCPv6 IPC
1260 try {
1261 Dhcp6to4Ipc::instance().open();
1262 } catch (const std::exception& ex) {
1263 err << "error starting DHCPv4-over-DHCPv6 IPC "
1264 " after server reconfiguration: " << ex.what();
1265 return (isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str()));
1266 }
1267
1268 // Configure DHCP packet queueing
1269 try {
1270 data::ConstElementPtr qc;
1271 qc = CfgMgr::instance().getStagingCfg()->getDHCPQueueControl();
1272 if (IfaceMgr::instance().configureDHCPPacketQueue(AF_INET6, qc)) {
1273 LOG_INFO(dhcp6_logger, DHCP6_CONFIG_PACKET_QUEUE)
1274 .arg(IfaceMgr::instance().getPacketQueue6()->getInfoStr());
1275 }
1276
1277 } catch (const std::exception& ex) {
1278 err << "Error setting packet queue controls after server reconfiguration: "
1279 << ex.what();
1280 return (isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str()));
1281 }
1282
1283 // Configure a callback to shut down the server when the bind socket
1284 // attempts exceeded.
1285 CfgIface::open_sockets_failed_callback_ =
1286 std::bind(&ControlledDhcpv6Srv::openSocketsFailedCallback, srv, ph::_1);
1287
1288 // Configuration may change active interfaces. Therefore, we have to reopen
1289 // sockets according to new configuration. It is possible that this
1290 // operation will fail for some interfaces but the openSockets function
1291 // guards against exceptions and invokes a callback function to
1292 // log warnings. Since we allow that this fails for some interfaces there
1293 // is no need to rollback configuration if socket fails to open on any
1294 // of the interfaces.
1295 CfgMgr::instance().getStagingCfg()->getCfgIface()->
1296 openSockets(AF_INET6, srv->getServerPort());
1297
1298 // Install the timers for handling leases reclamation.
1299 try {
1300 CfgMgr::instance().getStagingCfg()->getCfgExpiration()->
1301 setupTimers(&ControlledDhcpv6Srv::reclaimExpiredLeases,
1302 &ControlledDhcpv6Srv::deleteExpiredReclaimedLeases,
1303 server_);
1304
1305 } catch (const std::exception& ex) {
1306 err << "unable to setup timers for periodically running the"
1307 " reclamation of the expired leases: "
1308 << ex.what() << ".";
1309 return (isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str()));
1310 }
1311
1312 // Setup config backend polling, if configured for it.
1313 auto ctl_info = CfgMgr::instance().getStagingCfg()->getConfigControlInfo();
1314 if (ctl_info) {
1315 long fetch_time = static_cast<long>(ctl_info->getConfigFetchWaitTime());
1316 // Only schedule the CB fetch timer if the fetch wait time is greater
1317 // than 0.
1318 if (fetch_time > 0) {
1319 // When we run unit tests, we want to use milliseconds unit for the
1320 // specified interval. Otherwise, we use seconds. Note that using
1321 // milliseconds as a unit in unit tests prevents us from waiting 1
1322 // second on more before the timer goes off. Instead, we wait one
1323 // millisecond which significantly reduces the test time.
1324 if (!server_->inTestMode()) {
1325 fetch_time = 1000 * fetch_time;
1326 }
1327
1328 boost::shared_ptr<unsigned> failure_count(new unsigned(0));
1329 TimerMgr::instance()->
1330 registerTimer("Dhcp6CBFetchTimer",
1331 std::bind(&ControlledDhcpv6Srv::cbFetchUpdates,
1332 server_, CfgMgr::instance().getStagingCfg(),
1333 failure_count),
1334 fetch_time,
1335 asiolink::IntervalTimer::ONE_SHOT);
1336 TimerMgr::instance()->setup("Dhcp6CBFetchTimer");
1337 }
1338 }
1339
1340 // Finally, we can commit runtime option definitions in libdhcp++. This is
1341 // exception free.
1342 LibDHCP::commitRuntimeOptionDefs();
1343
1344 auto notify_libraries = ControlledDhcpv6Srv::finishConfigHookLibraries(config);
1345 if (notify_libraries) {
1346 return (notify_libraries);
1347 }
1348
1349 // Apply multi threading settings.
1350 // @note These settings are applied/updated only if no errors occur while
1351 // applying the new configuration.
1352 // @todo This should be fixed.
1353 try {
1354 CfgMultiThreading::apply(CfgMgr::instance().getStagingCfg()->getDHCPMultiThreading());
1355 } catch (const std::exception& ex) {
1356 err << "Error applying multi threading settings: "
1357 << ex.what();
1358 return (isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str()));
1359 }
1360
1361 return (answer);
1362}
1363
1364 isc::data::ConstElementPtr
1365ControlledDhcpv6Srv::finishConfigHookLibraries(isc::data::ConstElementPtr config) {
1366 ControlledDhcpv6Srv* srv = ControlledDhcpv6Srv::getInstance();
1367 // This hook point notifies hooks libraries that the configuration of the
1368 // DHCPv6 server has completed. It provides the hook library with the pointer
1369 // to the common IO service object, new server configuration in the JSON
1370 // format and with the pointer to the configuration storage where the
1371 // parsed configuration is stored.
1372 if (HooksManager::calloutsPresent(Hooks.hooks_index_dhcp6_srv_configured_)) {
1373 CalloutHandlePtr callout_handle = HooksManager::createCalloutHandle();
1374
1375 callout_handle->setArgument("io_context", srv->getIOService());
1376 callout_handle->setArgument("network_state", srv->getNetworkState());
1377 callout_handle->setArgument("json_config", config);
1378 callout_handle->setArgument("server_config", CfgMgr::instance().getStagingCfg());
1379
1380 HooksManager::callCallouts(Hooks.hooks_index_dhcp6_srv_configured_,
1381 *callout_handle);
1382
1383 // If next step is DROP, report a configuration error.
1384 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_DROP) {
1385 string error;
1386 try {
1387 callout_handle->getArgument("error", error);
1388 } catch (NoSuchArgument const& ex) {
1389 error = "unknown error";
1390 }
1391 return (isc::config::createAnswer(CONTROL_RESULT_ERROR, error));
1392 }
1393 }
1394
1395 return (ConstElementPtr());
1396}
1397
1398 isc::data::ConstElementPtr
1399ControlledDhcpv6Srv::checkConfig(isc::data::ConstElementPtr config) {
1400 ControlledDhcpv6Srv* srv = ControlledDhcpv6Srv::getInstance();
1401
1402 if (!srv) {
1403 ConstElementPtr no_srv = isc::config::createAnswer(CONTROL_RESULT_ERROR,
1404 "Server object not initialized, can't process config.");
1405 return (no_srv);
1406 }
1407
1408 LOG_DEBUG(dhcp6_logger, DBG_DHCP6_COMMAND, DHCP6_CONFIG_RECEIVED)
1409 .arg(srv->redactConfig(config)->str());
1410
1411 return (configureDhcp6Server(*srv, config, true));
1412}
1413
1414ControlledDhcpv6Srv::ControlledDhcpv6Srv(uint16_t server_port /*= DHCP6_SERVER_PORT*/,
1415 uint16_t client_port /*= 0*/)
1416 : Dhcpv6Srv(server_port, client_port), timer_mgr_(TimerMgr::instance()) {
1417 if (getInstance()) {
1418 isc_throw(InvalidOperation,
1419 "There is another Dhcpv6Srv instance already.");
1420 }
1421 server_ = this; // remember this instance for later use in handlers
1422
1423 // ProcessSpawn uses IO service to handle signal set events.
1424 ProcessSpawn::setIOService(getIOService());
1425
1426 // TimerMgr uses IO service to run asynchronous timers.
1427 TimerMgr::instance()->setIOService(getIOService());
1428
1429 // Command managers use IO service to run asynchronous socket operations.
1430 UnixCommandMgr::instance().setIOService(getIOService());
1431 HttpCommandMgr::instance().setIOService(getIOService());
1432
1433 // Set the HTTP default socket address to the IPv6 (vs IPv4) loopback.
1434 HttpCommandConfig::DEFAULT_SOCKET_ADDRESS = IOAddress("::1");
1435
1436 // Set the HTTP authentication default realm.
1437 HttpCommandConfig::DEFAULT_AUTHENTICATION_REALM = "kea-dhcpv6-server";
1438
1439 // Set the HTTP supported service.
1440 HttpCommandConfig::SUPPORTED_SERVICE = "dhcp6";
1441
1442 // DatabaseConnection uses IO service to run asynchronous timers.
1443 DatabaseConnection::setIOService(getIOService());
1444
1445 // These are the commands always supported by the DHCPv6 server.
1446 // Please keep the list in alphabetic order.
1447 CommandMgr::instance().registerCommand("build-report",
1448 std::bind(&ControlledDhcpv6Srv::commandBuildReportHandler, this, ph::_1, ph::_2));
1449
1450 CommandMgr::instance().registerCommand("config-backend-pull",
1451 std::bind(&ControlledDhcpv6Srv::commandConfigBackendPullHandler, this, ph::_1, ph::_2));
1452
1453 CommandMgr::instance().registerCommand("config-get",
1454 std::bind(&ControlledDhcpv6Srv::commandConfigGetHandler, this, ph::_1, ph::_2));
1455
1456 CommandMgr::instance().registerCommand("config-hash-get",
1457 std::bind(&ControlledDhcpv6Srv::commandConfigHashGetHandler, this, ph::_1, ph::_2));
1458
1459 CommandMgr::instance().registerCommand("config-reload",
1460 std::bind(&ControlledDhcpv6Srv::commandConfigReloadHandler, this, ph::_1, ph::_2));
1461
1462 CommandMgr::instance().registerCommand("config-set",
1463 std::bind(&ControlledDhcpv6Srv::commandConfigSetHandler, this, ph::_1, ph::_2));
1464
1465 CommandMgr::instance().registerCommand("config-test",
1466 std::bind(&ControlledDhcpv6Srv::commandConfigTestHandler, this, ph::_1, ph::_2));
1467
1468 CommandMgr::instance().registerCommand("config-write",
1469 std::bind(&ControlledDhcpv6Srv::commandConfigWriteHandler, this, ph::_1, ph::_2));
1470
1471 CommandMgr::instance().registerCommand("dhcp-enable",
1472 std::bind(&ControlledDhcpv6Srv::commandDhcpEnableHandler, this, ph::_1, ph::_2));
1473
1474 CommandMgr::instance().registerCommand("dhcp-disable",
1475 std::bind(&ControlledDhcpv6Srv::commandDhcpDisableHandler, this, ph::_1, ph::_2));
1476
1477 CommandMgr::instance().registerCommand("interface-add",
1478 std::bind(&ControlledDhcpv6Srv::commandInterfaceAddHandler, this, ph::_1, ph::_2));
1479
1480 CommandMgr::instance().registerCommand("interface-list",
1481 std::bind(&ControlledDhcpv6Srv::commandInterfaceListHandler, this, ph::_1, ph::_2));
1482
1483 CommandMgr::instance().registerCommand("interface-redetect",
1484 std::bind(&ControlledDhcpv6Srv::commandInterfaceRedetectHandler, this, ph::_1, ph::_2));
1485
1486 CommandMgr::instance().registerCommand("kea-lfc-start",
1487 std::bind(&ControlledDhcpv6Srv::commandLfcStartHandler, this, ph::_1, ph::_2));
1488
1489 CommandMgr::instance().registerCommand("leases-reclaim",
1490 std::bind(&ControlledDhcpv6Srv::commandLeasesReclaimHandler, this, ph::_1, ph::_2));
1491
1492 CommandMgr::instance().registerCommand("subnet6-select-test",
1493 std::bind(&ControlledDhcpv6Srv::commandSubnet6SelectTestHandler, this, ph::_1, ph::_2));
1494
1495 CommandMgr::instance().registerCommand("server-tag-get",
1496 std::bind(&ControlledDhcpv6Srv::commandServerTagGetHandler, this, ph::_1, ph::_2));
1497
1498 CommandMgr::instance().registerCommand("shutdown",
1499 std::bind(&ControlledDhcpv6Srv::commandShutdownHandler, this, ph::_1, ph::_2));
1500
1501 CommandMgr::instance().registerCommand("status-get",
1502 std::bind(&ControlledDhcpv6Srv::commandStatusGetHandler, this, ph::_1, ph::_2));
1503
1504 CommandMgr::instance().registerCommand("version-get",
1505 std::bind(&ControlledDhcpv6Srv::commandVersionGetHandler, this, ph::_1, ph::_2));
1506
1507 // Register statistic related commands
1508 CommandMgr::instance().registerCommand("statistic-get",
1509 std::bind(&StatsMgr::statisticGetHandler, ph::_1, ph::_2));
1510
1511 CommandMgr::instance().registerCommand("statistic-reset",
1512 std::bind(&StatsMgr::statisticResetHandler, ph::_1, ph::_2));
1513
1514 CommandMgr::instance().registerCommand("statistic-remove",
1515 std::bind(&StatsMgr::statisticRemoveHandler, ph::_1, ph::_2));
1516
1517 CommandMgr::instance().registerCommand("statistic-get-all",
1518 std::bind(&StatsMgr::statisticGetAllHandler, ph::_1, ph::_2));
1519
1520 CommandMgr::instance().registerCommand("statistic-global-get-all",
1521 std::bind(&StatsMgr::statisticGlobalGetAllHandler, ph::_1, ph::_2));
1522
1523 CommandMgr::instance().registerCommand("statistic-reset-all",
1524 std::bind(&StatsMgr::statisticResetAllHandler, ph::_1, ph::_2));
1525
1526 CommandMgr::instance().registerCommand("statistic-remove-all",
1527 std::bind(&StatsMgr::statisticRemoveAllHandler, ph::_1, ph::_2));
1528
1529 CommandMgr::instance().registerCommand("statistic-sample-age-set",
1530 std::bind(&StatsMgr::statisticSetMaxSampleAgeHandler, ph::_1, ph::_2));
1531
1532 CommandMgr::instance().registerCommand("statistic-sample-age-set-all",
1533 std::bind(&ControlledDhcpv6Srv::commandStatisticSetMaxSampleAgeAllHandler, this, ph::_1, ph::_2));
1534
1535 CommandMgr::instance().registerCommand("statistic-sample-count-set",
1536 std::bind(&StatsMgr::statisticSetMaxSampleCountHandler, ph::_1, ph::_2));
1537
1538 CommandMgr::instance().registerCommand("statistic-sample-count-set-all",
1539 std::bind(&ControlledDhcpv6Srv::commandStatisticSetMaxSampleCountAllHandler, this, ph::_1, ph::_2));
1540}
1541
1542 void ControlledDhcpv6Srv::shutdownServer(int exit_value) {
1543 setExitValue(exit_value);
1544 getIOService()->stop(); // Stop ASIO transmissions
1545 shutdown(); // Initiate DHCPv6 shutdown procedure.
1546}
1547
1548ControlledDhcpv6Srv::~ControlledDhcpv6Srv() {
1549 try {
1550 MultiThreadingMgr::instance().apply(false, 0, 0);
1551 LeaseMgrFactory::destroy();
1552 HostMgr::create();
1553
1554 // The closure captures either a shared pointer (memory leak)
1555 // or a raw pointer (pointing to a deleted object).
1556 DatabaseConnection::db_lost_callback_ = 0;
1557 DatabaseConnection::db_recovered_callback_ = 0;
1558 DatabaseConnection::db_failed_callback_ = 0;
1559
1560 timer_mgr_->unregisterTimers();
1561
1562 cleanup();
1563
1564 // Close command sockets.
1565 UnixCommandMgr::instance().closeCommandSockets();
1566 HttpCommandMgr::instance().closeCommandSockets();
1567
1568 // Deregister any registered commands (please keep in alphabetic order)
1569 CommandMgr::instance().deregisterCommand("build-report");
1570 CommandMgr::instance().deregisterCommand("config-backend-pull");
1571 CommandMgr::instance().deregisterCommand("config-get");
1572 CommandMgr::instance().deregisterCommand("config-hash-get");
1573 CommandMgr::instance().deregisterCommand("config-reload");
1574 CommandMgr::instance().deregisterCommand("config-set");
1575 CommandMgr::instance().deregisterCommand("config-test");
1576 CommandMgr::instance().deregisterCommand("config-write");
1577 CommandMgr::instance().deregisterCommand("dhcp-disable");
1578 CommandMgr::instance().deregisterCommand("dhcp-enable");
1579 CommandMgr::instance().deregisterCommand("interface-add");
1580 CommandMgr::instance().deregisterCommand("interface-list");
1581 CommandMgr::instance().deregisterCommand("interface-redetect");
1582 CommandMgr::instance().deregisterCommand("kea-lfc-start");
1583 CommandMgr::instance().deregisterCommand("leases-reclaim");
1584 CommandMgr::instance().deregisterCommand("subnet6-select-test");
1585 CommandMgr::instance().deregisterCommand("server-tag-get");
1586 CommandMgr::instance().deregisterCommand("shutdown");
1587 CommandMgr::instance().deregisterCommand("statistic-get");
1588 CommandMgr::instance().deregisterCommand("statistic-get-all");
1589 CommandMgr::instance().deregisterCommand("statistic-global-get-all");
1590 CommandMgr::instance().deregisterCommand("statistic-remove");
1591 CommandMgr::instance().deregisterCommand("statistic-remove-all");
1592 CommandMgr::instance().deregisterCommand("statistic-reset");
1593 CommandMgr::instance().deregisterCommand("statistic-reset-all");
1594 CommandMgr::instance().deregisterCommand("statistic-sample-age-set");
1595 CommandMgr::instance().deregisterCommand("statistic-sample-age-set-all");
1596 CommandMgr::instance().deregisterCommand("statistic-sample-count-set");
1597 CommandMgr::instance().deregisterCommand("statistic-sample-count-set-all");
1598 CommandMgr::instance().deregisterCommand("status-get");
1599 CommandMgr::instance().deregisterCommand("version-get");
1600
1601 // Reset DatabaseConnection IO service.
1602 DatabaseConnection::setIOService(IOServicePtr());
1603 } catch (...) {
1604 // Don't want to throw exceptions from the destructor. The server
1605 // is shutting down anyway.
1606 }
1607
1608 server_ = NULL; // forget this instance. There should be no callback anymore
1609 // at this stage anyway.
1610}
1611
1612void
1613ControlledDhcpv6Srv::reclaimExpiredLeases(const size_t max_leases,
1614 const uint16_t timeout,
1615 const bool remove_lease,
1616 const uint16_t max_unwarned_cycles) {
1617 try {
1618 if (network_state_->isServiceEnabled()) {
1619 server_->alloc_engine_->reclaimExpiredLeases6(max_leases, timeout,
1620 remove_lease,
1621 max_unwarned_cycles);
1622 } else {
1623 LOG_DEBUG(dhcp6_logger, DBG_DHCP6_BASIC, DHCP6_RECLAIM_EXPIRED_LEASES_SKIPPED)
1624 .arg(CfgMgr::instance().getCurrentCfg()->
1625 getCfgExpiration()->getReclaimTimerWaitTime());
1626 }
1627 } catch (const std::exception& ex) {
1628 LOG_ERROR(dhcp6_logger, DHCP6_RECLAIM_EXPIRED_LEASES_FAIL)
1629 .arg(ex.what());
1630 }
1631 // We're using the ONE_SHOT timer so there is a need to re-schedule it.
1632 TimerMgr::instance()->setup(CfgExpiration::RECLAIM_EXPIRED_TIMER_NAME);
1633}
1634
1635void
1636ControlledDhcpv6Srv::deleteExpiredReclaimedLeases(const uint32_t secs) {
1637 if (network_state_->isServiceEnabled()) {
1638 server_->alloc_engine_->deleteExpiredReclaimedLeases6(secs);
1639 }
1640
1641 // We're using the ONE_SHOT timer so there is a need to re-schedule it.
1642 TimerMgr::instance()->setup(CfgExpiration::FLUSH_RECLAIMED_TIMER_NAME);
1643}
1644
1645bool
1646ControlledDhcpv6Srv::dbLostCallback(ReconnectCtlPtr db_reconnect_ctl) {
1647 if (!db_reconnect_ctl) {
1648 // This should never happen
1649 LOG_ERROR(dhcp6_logger, DHCP6_DB_RECONNECT_NO_DB_CTL);
1650 return (false);
1651 }
1652
1653 // Disable service until the connection is recovered.
1654 if (db_reconnect_ctl->retriesLeft() == db_reconnect_ctl->maxRetries() &&
1655 db_reconnect_ctl->alterServiceState()) {
1656 network_state_->disableService(NetworkState::DB_CONNECTION + db_reconnect_ctl->id());
1657 }
1658
1659 LOG_INFO(dhcp6_logger, DHCP6_DB_RECONNECT_LOST_CONNECTION)
1660 .arg(db_reconnect_ctl->id())
1661 .arg(db_reconnect_ctl->timerName());
1662
1663 // If reconnect isn't enabled log it, initiate a shutdown if needed and
1664 // return false.
1665 if (!db_reconnect_ctl->retriesLeft() ||
1666 !db_reconnect_ctl->retryInterval()) {
1667 LOG_INFO(dhcp6_logger, DHCP6_DB_RECONNECT_DISABLED)
1668 .arg(db_reconnect_ctl->retriesLeft())
1669 .arg(db_reconnect_ctl->retryInterval())
1670 .arg(db_reconnect_ctl->id())
1671 .arg(db_reconnect_ctl->timerName());
1672 if (db_reconnect_ctl->exitOnFailure()) {
1673 shutdownServer(EXIT_FAILURE);
1674 }
1675 return (false);
1676 }
1677
1678 return (true);
1679}
1680
1681bool
1682ControlledDhcpv6Srv::dbRecoveredCallback(ReconnectCtlPtr db_reconnect_ctl) {
1683 if (!db_reconnect_ctl) {
1684 // This should never happen
1685 LOG_ERROR(dhcp6_logger, DHCP6_DB_RECONNECT_NO_DB_CTL);
1686 return (false);
1687 }
1688
1689 // Enable service after the connection is recovered.
1690 if (db_reconnect_ctl->retriesLeft() != db_reconnect_ctl->maxRetries() &&
1691 db_reconnect_ctl->alterServiceState()) {
1692 network_state_->enableService(NetworkState::DB_CONNECTION + db_reconnect_ctl->id());
1693 }
1694
1695 LOG_INFO(dhcp6_logger, DHCP6_DB_RECONNECT_SUCCEEDED)
1696 .arg(db_reconnect_ctl->id())
1697 .arg(db_reconnect_ctl->timerName());
1698
1699 db_reconnect_ctl->resetRetries();
1700
1701 return (true);
1702}
1703
1704bool
1705ControlledDhcpv6Srv::dbFailedCallback(ReconnectCtlPtr db_reconnect_ctl) {
1706 if (!db_reconnect_ctl) {
1707 // This should never happen
1708 LOG_ERROR(dhcp6_logger, DHCP6_DB_RECONNECT_NO_DB_CTL);
1709 return (false);
1710 }
1711
1712 LOG_INFO(dhcp6_logger, DHCP6_DB_RECONNECT_FAILED)
1713 .arg(db_reconnect_ctl->maxRetries())
1714 .arg(db_reconnect_ctl->id())
1715 .arg(db_reconnect_ctl->timerName());
1716
1717 if (db_reconnect_ctl->exitOnFailure()) {
1718 shutdownServer(EXIT_FAILURE);
1719 }
1720
1721 return (true);
1722}
1723
1724void
1725ControlledDhcpv6Srv::openSocketsFailedCallback(ReconnectCtlPtr reconnect_ctl) {
1726 if (!reconnect_ctl) {
1727 // This should never happen
1728 LOG_ERROR(dhcp6_logger, DHCP6_OPEN_SOCKETS_NO_RECONNECT_CTL);
1729 return;
1730 }
1731
1732 if (reconnect_ctl->exitOnFailure()) {
1733 LOG_FATAL(dhcp6_logger, DHCP6_FATAL_OPEN_SOCKETS_FAILED)
1734 .arg(reconnect_ctl->maxRetries());
1735 shutdownServer(EXIT_FAILURE);
1736 } else {
1737 LOG_ERROR(dhcp6_logger, DHCP6_OPEN_SOCKETS_FAILED)
1738 .arg(reconnect_ctl->maxRetries());
1739 }
1740}
1741
1742void
1743ControlledDhcpv6Srv::cbFetchUpdates(const SrvConfigPtr& srv_cfg,
1744 boost::shared_ptr<unsigned> failure_count) {
1745 // stop thread pool (if running)
1746 MultiThreadingCriticalSection cs;
1747
1748 try {
1749 // Fetch any configuration backend updates since our last fetch.
1750 server_->getCBControl()->databaseConfigFetch(srv_cfg,
1751 CBControlDHCPv6::FetchMode::FETCH_UPDATE);
1752 (*failure_count) = 0;
1753
1754 } catch (const std::exception& ex) {
1755 LOG_ERROR(dhcp6_logger, DHCP6_CB_PERIODIC_FETCH_UPDATES_FAIL)
1756 .arg(ex.what());
1757
1758 // We allow at most 10 consecutive failures after which we stop
1759 // making further attempts to fetch the configuration updates.
1760 // Let's return without re-scheduling the timer.
1761 if (++(*failure_count) > 10) {
1762 LOG_ERROR(dhcp6_logger,
1763 DHCP6_CB_PERIODIC_FETCH_UPDATES_RETRIES_EXHAUSTED);
1764 return;
1765 }
1766 }
1767
1768 // Reschedule the timer to fetch new updates or re-try if
1769 // the previous attempt resulted in an error.
1770 if (TimerMgr::instance()->isTimerRegistered("Dhcp6CBFetchTimer")) {
1771 TimerMgr::instance()->setup("Dhcp6CBFetchTimer");
1772 }
1773}
1774
1775} // namespace dhcp
1776} // namespace isc
cfg_db_access.h
cfg_multi_threading.h
cfgmgr.h
isc::BadValue
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
Definition exceptions/exceptions.h:132
isc::Exception
This is a base class for exceptions thrown from the DNS library module.
Definition exceptions/exceptions.h:23
isc::Exception::what
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Definition exceptions/exceptions.cc:32
isc::InvalidOperation
A generic exception that is thrown if a function is called in a prohibited way.
Definition exceptions/exceptions.h:143
isc::asiolink::IOAddress
The IOAddress class represents an IP addresses (version agnostic).
Definition io_address.h:53
isc::asiolink::IOAddress::isV6
bool isV6() const
Convenience function to check for an IPv6 address.
Definition io_address.h:144
isc::asiolink::IOAddress::IPV6_ZERO_ADDRESS
static const IOAddress & IPV6_ZERO_ADDRESS()
Returns an IPv6 zero address.
Definition io_address.h:297
isc::asiolink::IOServiceMgr::instance
static IOServiceMgr & instance()
Access the IOServiceMgr singleton instance.
Definition io_service_mgr.cc:14
isc::asiolink::IOServiceMgr::pollIOServices
size_t pollIOServices()
Poll IOService objects.
Definition io_service_mgr.cc:39
isc::asiolink::IOSignalSet
Implements an asynchronous "signal" for IOService driven processing.
Definition io_service_signal.h:26
isc::asiolink::IntervalTimer::ONE_SHOT
@ ONE_SHOT
Definition interval_timer.h:72
isc::asiolink::ProcessSpawn::setIOService
static void setIOService(isc::asiolink::IOServicePtr io_service)
Set the I/O service.
Definition process_spawn.h:163
isc::config::BaseCommandMgr::processCommand
virtual isc::data::ConstElementPtr processCommand(const isc::data::ConstElementPtr &cmd)
Triggers command processing.
Definition base_command_mgr.cc:119
isc::config::BaseCommandMgr::registerCommand
void registerCommand(const std::string &cmd, CommandHandler handler)
Registers specified command handler for a given command.
Definition base_command_mgr.cc:53
isc::config::BaseCommandMgr::getHash
static std::string getHash(const isc::data::ConstElementPtr &config)
returns a hash of a given Element structure
Definition base_command_mgr.cc:193
isc::config::BaseCommandMgr::deregisterCommand
void deregisterCommand(const std::string &cmd)
Deregisters specified command handler.
Definition base_command_mgr.cc:92
isc::config::CommandMgr::instance
static CommandMgr & instance()
CommandMgr is a singleton class.
Definition command_mgr.cc:18
isc::config::HttpCommandConfig::DEFAULT_AUTHENTICATION_REALM
static std::string DEFAULT_AUTHENTICATION_REALM
Default HTTP authentication realm.
Definition http_command_config.h:177
isc::config::HttpCommandConfig::DEFAULT_SOCKET_ADDRESS
static isc::asiolink::IOAddress DEFAULT_SOCKET_ADDRESS
Default socket address (127.0.0.1).
Definition http_command_config.h:171
isc::config::HttpCommandConfig::SUPPORTED_SERVICE
static std::string SUPPORTED_SERVICE
Supported service.
Definition http_command_config.h:183
isc::config::HttpCommandMgr::closeCommandSockets
void closeCommandSockets()
Close http control sockets.
Definition http_command_mgr.cc:332
isc::config::HttpCommandMgr::instance
static HttpCommandMgr & instance()
HttpCommandMgr is a singleton class.
Definition http_command_mgr.cc:288
isc::config::HttpCommandMgr::setIOService
void setIOService(const asiolink::IOServicePtr &io_service)
Sets IO service to be used by the http command manager.
Definition http_command_mgr.cc:297
isc::config::UnixCommandMgr::instance
static UnixCommandMgr & instance()
UnixCommandMgr is a singleton class.
Definition unix_command_mgr.cc:786
isc::config::UnixCommandMgr::setIOService
void setIOService(const asiolink::IOServicePtr &io_service)
Sets IO service to be used by the unix command manager.
Definition unix_command_mgr.cc:792
isc::config::UnixCommandMgr::closeCommandSockets
void closeCommandSockets()
Shuts down any open unix control sockets.
Definition unix_command_mgr.cc:776
isc::data::Element::create
static ElementPtr create(const Position &pos=ZERO_POSITION())
Create a NullElement.
Definition data.cc:299
isc::data::Element::map
@ map
Definition data.h:160
isc::data::Element::integer
@ integer
Definition data.h:153
isc::data::Element::boolean
@ boolean
Definition data.h:155
isc::data::Element::list
@ list
Definition data.h:159
isc::data::Element::string
@ string
Definition data.h:157
isc::data::Element::createMap
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition data.cc:354
isc::data::Element::createList
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
Definition data.cc:349
isc::db::DatabaseConnection::setIOService
static void setIOService(const isc::asiolink::IOServicePtr &io_service)
Sets IO service to be used by the database backends.
Definition database_connection.h:235
isc::db::DatabaseConnection::db_recovered_callback_
static DbCallback db_recovered_callback_
Optional callback function to invoke if an opened connection recovery succeeded.
Definition database_connection.h:250
isc::db::DatabaseConnection::db_failed_callback_
static DbCallback db_failed_callback_
Optional callback function to invoke if an opened connection recovery failed.
Definition database_connection.h:254
isc::db::DatabaseConnection::db_lost_callback_
static DbCallback db_lost_callback_
Optional callback function to invoke if an opened connection is lost.
Definition database_connection.h:246
isc::db::DbConnectionInitWithRetry
RAII class to enable DB reconnect retries on server startup.
Definition database_connection.h:336
isc::dhcp::CfgExpiration::FLUSH_RECLAIMED_TIMER_NAME
static const std::string FLUSH_RECLAIMED_TIMER_NAME
Name of the timer for flushing reclaimed leases.
Definition cfg_expiration.h:117
isc::dhcp::CfgExpiration::RECLAIM_EXPIRED_TIMER_NAME
static const std::string RECLAIM_EXPIRED_TIMER_NAME
Name of the timer for reclaiming expired leases.
Definition cfg_expiration.h:114
isc::dhcp::CfgIface
Represents selection of interfaces for DHCP server.
Definition cfg_iface.h:131
isc::dhcp::CfgIface::open_sockets_failed_callback_
static OpenSocketsFailedCallback open_sockets_failed_callback_
Optional callback function to invoke if all retries of the opening sockets fail.
Definition cfg_iface.h:369
isc::dhcp::CfgMgr::instance
static CfgMgr & instance()
returns a single instance of Configuration Manager
Definition cfgmgr.cc:29
isc::dhcp::CfgMgr::getStagingCfg
SrvConfigPtr getStagingCfg()
Returns a pointer to the staging configuration.
Definition cfgmgr.cc:121
isc::dhcp::CfgMgr::commit
void commit()
Commits the staging configuration.
Definition cfgmgr.cc:93
isc::dhcp::CfgMgr::clearStagingConfiguration
void clearStagingConfiguration()
Remove staging configuration.
Definition cfgmgr.cc:88
isc::dhcp::CfgMgr::getCurrentCfg
SrvConfigPtr getCurrentCfg()
Returns a pointer to the current configuration.
Definition cfgmgr.cc:116
isc::dhcp::CfgMultiThreading::apply
static void apply(data::ConstElementPtr value)
apply multi threading configuration
Definition cfg_multi_threading.cc:21
isc::dhcp::ClientClasses::insert
void insert(const ClientClass &class_name)
Insert an element.
Definition classify.h:160
isc::dhcp::ControlledDhcpv6Srv
Controlled version of the DHCPv6 server.
Definition ctrl_dhcp6_srv.h:26
isc::dhcp::ControlledDhcpv6Srv::getShutdown
bool getShutdown() const
Return the server shutdown flag value.
Definition ctrl_dhcp6_srv.cc:205
isc::dhcp::ControlledDhcpv6Srv::commandVersionGetHandler
isc::data::ConstElementPtr commandVersionGetHandler(const std::string &command, isc::data::ConstElementPtr args)
@Brief handler for processing 'version-get' command
Definition ctrl_dhcp6_srv.cc:844
isc::dhcp::ControlledDhcpv6Srv::init
void init(const std::string &config_file)
Initializes the server.
Definition ctrl_dhcp6_srv.cc:102
isc::dhcp::ControlledDhcpv6Srv::cleanup
void cleanup()
Performs cleanup, immediately before termination.
Definition ctrl_dhcp6_srv.cc:127
isc::dhcp::ControlledDhcpv6Srv::commandConfigSetHandler
isc::data::ConstElementPtr commandConfigSetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for processing 'config-set' command
Definition ctrl_dhcp6_srv.cc:347
isc::dhcp::ControlledDhcpv6Srv::commandInterfaceAddHandler
isc::data::ConstElementPtr commandInterfaceAddHandler(const std::string &command, isc::data::ConstElementPtr args)
Handler for processing 'interface-add' command.
Definition ctrl_dhcp6_srv.cc:764
isc::dhcp::ControlledDhcpv6Srv::commandInterfaceRedetectHandler
isc::data::ConstElementPtr commandInterfaceRedetectHandler(const std::string &command, isc::data::ConstElementPtr args)
Handler for processing 'interface-redetect' command.
Definition ctrl_dhcp6_srv.cc:733
isc::dhcp::ControlledDhcpv6Srv::commandShutdownHandler
isc::data::ConstElementPtr commandShutdownHandler(const std::string &command, isc::data::ConstElementPtr args)
Handler for processing 'shutdown' command.
Definition ctrl_dhcp6_srv.cc:210
isc::dhcp::ControlledDhcpv6Srv::commandConfigBackendPullHandler
isc::data::ConstElementPtr commandConfigBackendPullHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for config-backend-pull command
Definition ctrl_dhcp6_srv.cc:1017
isc::dhcp::ControlledDhcpv6Srv::commandLfcStartHandler
isc::data::ConstElementPtr commandLfcStartHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for processing 'kea-lfc-start' command
Definition ctrl_dhcp6_srv.cc:1160
isc::dhcp::ControlledDhcpv6Srv::commandConfigHashGetHandler
isc::data::ConstElementPtr commandConfigHashGetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for processing 'config-hash-get' command
Definition ctrl_dhcp6_srv.cc:274
isc::dhcp::ControlledDhcpv6Srv::commandServerTagGetHandler
isc::data::ConstElementPtr commandServerTagGetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for server-tag-get command
Definition ctrl_dhcp6_srv.cc:1006
isc::dhcp::ControlledDhcpv6Srv::commandStatisticSetMaxSampleCountAllHandler
isc::data::ConstElementPtr commandStatisticSetMaxSampleCountAllHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for processing 'statistic-sample-count-set-all' command
Definition ctrl_dhcp6_srv.cc:1135
isc::dhcp::ControlledDhcpv6Srv::commandStatisticSetMaxSampleAgeAllHandler
isc::data::ConstElementPtr commandStatisticSetMaxSampleAgeAllHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for processing 'statistic-sample-age-set-all' command
Definition ctrl_dhcp6_srv.cc:1147
isc::dhcp::ControlledDhcpv6Srv::commandStatusGetHandler
isc::data::ConstElementPtr commandStatusGetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for processing 'status-get' command
Definition ctrl_dhcp6_srv.cc:1056
isc::dhcp::ControlledDhcpv6Srv::commandDhcpEnableHandler
isc::data::ConstElementPtr commandDhcpEnableHandler(const std::string &command, isc::data::ConstElementPtr args)
A handler for processing 'dhcp-enable' command.
Definition ctrl_dhcp6_srv.cc:636
isc::dhcp::ControlledDhcpv6Srv::commandConfigReloadHandler
isc::data::ConstElementPtr commandConfigReloadHandler(const std::string &command, isc::data::ConstElementPtr args)
Handler for processing 'config-reload' command.
Definition ctrl_dhcp6_srv.cc:239
isc::dhcp::ControlledDhcpv6Srv::commandLeasesReclaimHandler
isc::data::ConstElementPtr commandLeasesReclaimHandler(const std::string &command, isc::data::ConstElementPtr args)
Handler for processing 'leases-reclaim' command.
Definition ctrl_dhcp6_srv.cc:863
isc::dhcp::ControlledDhcpv6Srv::commandConfigWriteHandler
isc::data::ConstElementPtr commandConfigWriteHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for processing 'config-write' command
Definition ctrl_dhcp6_srv.cc:286
isc::dhcp::ControlledDhcpv6Srv::commandBuildReportHandler
isc::data::ConstElementPtr commandBuildReportHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for processing 'build-report' command
Definition ctrl_dhcp6_srv.cc:855
isc::dhcp::ControlledDhcpv6Srv::finishConfigHookLibraries
static isc::data::ConstElementPtr finishConfigHookLibraries(isc::data::ConstElementPtr config)
Configuration checker for hook libraries.
Definition ctrl_dhcp6_srv.cc:1365
isc::dhcp::ControlledDhcpv6Srv::~ControlledDhcpv6Srv
virtual ~ControlledDhcpv6Srv()
Destructor.
Definition ctrl_dhcp6_srv.cc:1548
isc::dhcp::ControlledDhcpv6Srv::processConfig
static isc::data::ConstElementPtr processConfig(isc::data::ConstElementPtr config)
Configuration processor.
Definition ctrl_dhcp6_srv.cc:1169
isc::dhcp::ControlledDhcpv6Srv::commandConfigGetHandler
isc::data::ConstElementPtr commandConfigGetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for processing 'config-get' command
Definition ctrl_dhcp6_srv.cc:264
isc::dhcp::ControlledDhcpv6Srv::shutdownServer
virtual void shutdownServer(int exit_value)
Initiates shutdown procedure for the whole DHCPv6 server.
Definition ctrl_dhcp6_srv.cc:1542
isc::dhcp::ControlledDhcpv6Srv::getInstance
static ControlledDhcpv6Srv * getInstance()
Returns pointer to the sole instance of Dhcpv6Srv.
Definition ctrl_dhcp6_srv.h:118
isc::dhcp::ControlledDhcpv6Srv::loadConfigFile
isc::data::ConstElementPtr loadConfigFile(const std::string &file_name)
Configure DHCPv6 server using the configuration file specified.
Definition ctrl_dhcp6_srv.cc:133
isc::dhcp::ControlledDhcpv6Srv::checkConfig
static isc::data::ConstElementPtr checkConfig(isc::data::ConstElementPtr config)
Configuration checker.
Definition ctrl_dhcp6_srv.cc:1399
isc::dhcp::ControlledDhcpv6Srv::commandInterfaceListHandler
isc::data::ConstElementPtr commandInterfaceListHandler(const std::string &command, isc::data::ConstElementPtr args)
Handler for processing 'interface-list' command.
Definition ctrl_dhcp6_srv.cc:706
isc::dhcp::ControlledDhcpv6Srv::commandSubnet6SelectTestHandler
isc::data::ConstElementPtr commandSubnet6SelectTestHandler(const std::string &command, isc::data::ConstElementPtr args)
Handler for processing 'subnet6-select-test' command.
Definition ctrl_dhcp6_srv.cc:889
isc::dhcp::ControlledDhcpv6Srv::ControlledDhcpv6Srv
ControlledDhcpv6Srv(uint16_t server_port=DHCP6_SERVER_PORT, uint16_t client_port=0)
Constructor.
Definition ctrl_dhcp6_srv.cc:1414
isc::dhcp::ControlledDhcpv6Srv::commandDhcpDisableHandler
isc::data::ConstElementPtr commandDhcpDisableHandler(const std::string &command, isc::data::ConstElementPtr args)
A handler for processing 'dhcp-disable' command.
Definition ctrl_dhcp6_srv.cc:540
isc::dhcp::ControlledDhcpv6Srv::commandConfigTestHandler
isc::data::ConstElementPtr commandConfigTestHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for processing 'config-test' command
Definition ctrl_dhcp6_srv.cc:478
isc::dhcp::Dhcp6to4Ipc::open
virtual void open()
Open communication socket.
Definition dhcp6to4_ipc.cc:39
isc::dhcp::Dhcp6to4Ipc::instance
static Dhcp6to4Ipc & instance()
Returns pointer to the sole instance of Dhcp6to4Ipc.
Definition dhcp6to4_ipc.cc:34
isc::dhcp::Dhcpv6Srv::shutdown
void shutdown() override
Instructs the server to shut down.
Definition dhcp6_srv.cc:371
isc::dhcp::Dhcpv6Srv::alloc_engine_
boost::shared_ptr< AllocEngine > alloc_engine_
Allocation Engine.
Definition dhcp6_srv.h:1264
isc::dhcp::Dhcpv6Srv::getServerPort
uint16_t getServerPort() const
Get UDP port on which server should listen.
Definition dhcp6_srv.cc:5454
isc::dhcp::Dhcpv6Srv::getNetworkState
NetworkStatePtr & getNetworkState()
Returns pointer to the network state used by the server.
Definition dhcp6_srv.h:115
isc::dhcp::Dhcpv6Srv::network_state_
NetworkStatePtr network_state_
Holds information about disabled DHCP service and/or disabled subnet/network scopes.
Definition dhcp6_srv.h:1272
isc::dhcp::Dhcpv6Srv::Dhcpv6Srv
Dhcpv6Srv(uint16_t server_port=DHCP6_SERVER_PORT, uint16_t client_port=0)
Default constructor.
Definition dhcp6_srv.cc:272
isc::dhcp::Dhcpv6Srv::getVersion
static std::string getVersion(bool extended)
returns Kea version on stdout and exit.
Definition dhcp6_srv.cc:5235
isc::dhcp::Dhcpv6Srv::getIOService
asiolink::IOServicePtr & getIOService()
Returns pointer to the IO service used by the server.
Definition dhcp6_srv.h:110
isc::dhcp::Dhcpv6Srv::shutdown_
volatile bool shutdown_
Indicates if shutdown is in progress.
Definition dhcp6_srv.h:1248
isc::dhcp::Dhcpv6Srv::startD2
void startD2()
Starts DHCP_DDNS client IO if DDNS updates are enabled.
Definition dhcp6_srv.cc:5201
isc::dhcp::HostMgr::create
static void create()
Creates new instance of the HostMgr.
Definition host_mgr.cc:52
isc::dhcp::IfaceCollection::size
size_t size() const
Return the number of interfaces.
Definition iface_mgr.h:635
isc::dhcp::IfaceMgr::getIfaces
const IfaceCollection & getIfaces()
Returns container with all interfaces.
Definition iface_mgr.h:942
isc::dhcp::IfaceMgr::detectIfaces
void detectIfaces(bool update_only=false)
Detects network interfaces.
isc::dhcp::IfaceMgr::instance
static IfaceMgr & instance()
IfaceMgr is a singleton class.
Definition iface_mgr.cc:52
isc::dhcp::IfacesConfigParser
Parser for the configuration of interfaces.
Definition ifaces_config_parser.h:26
isc::dhcp::IfacesConfigParser::parseInterfacesList
void parseInterfacesList(const CfgIfacePtr &cfg_iface, isc::data::ConstElementPtr ifaces_list)
parses interfaces-list structure
Definition ifaces_config_parser.cc:21
isc::dhcp::LeaseMgrFactory::instance
static TrackingLeaseMgr & instance()
Return current lease manager.
Definition lease_mgr_factory.cc:148
isc::dhcp::LeaseMgrFactory::init_allocators_
static bool init_allocators_
Flag which indicates if allocators must be initialized.
Definition lease_mgr_factory.h:166
isc::dhcp::LeaseMgrFactory::destroy
static void destroy()
Destroy lease manager.
Definition lease_mgr_factory.cc:107
isc::dhcp::LeaseMgrFactory::haveInstance
static bool haveInstance()
Indicates if the lease manager has been instantiated.
Definition lease_mgr_factory.cc:143
isc::dhcp::LeaseMgr::getStatus
virtual data::ElementPtr getStatus() const
Return status information.
Definition lease_mgr.cc:1312
isc::dhcp::LibDHCP::commitRuntimeOptionDefs
static void commitRuntimeOptionDefs()
Commits runtime option definitions.
Definition libdhcp++.cc:248
isc::dhcp::Memfile_LeaseMgr
Concrete implementation of a lease database backend using flat file.
Definition memfile_lease_mgr.h:81
isc::dhcp::Memfile_LeaseMgr::isLFCProcessRunning
static bool isLFCProcessRunning(const std::string file_name, Universe u)
Check if LFC is running.
Definition memfile_lease_mgr.cc:2464
isc::dhcp::Memfile_LeaseMgr::V6
@ V6
Definition memfile_lease_mgr.h:126
isc::dhcp::NetworkState::DB_CONNECTION
static const unsigned int DB_CONNECTION
The network state is being altered by the DB connection recovery mechanics.
Definition network_state.h:99
isc::dhcp::NetworkState::USER_COMMAND
static const unsigned int USER_COMMAND
Origin of the network state transition.
Definition network_state.h:82
isc::dhcp::NetworkState::HA_REMOTE_COMMAND
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.
Definition network_state.h:95
isc::dhcp::Option
Definition option.h:81
isc::dhcp::Option::V6
@ V6
Definition option.h:90
isc::dhcp::Parser6Context
Evaluation context, an interface to the expression evaluation.
Definition dhcp6/parser_context.h:36
isc::dhcp::Parser6Context::parseFile
isc::data::ElementPtr parseFile(const std::string &filename, ParserType parser_type)
Run the parser on the file specified.
Definition dhcp6/parser_context.cc:37
isc::dhcp::Parser6Context::PARSER_DHCP6
@ PARSER_DHCP6
This parser will parse the content as Dhcp6 config wrapped in a map (that's the regular config file).
Definition dhcp6/parser_context.h:55
isc::dhcp::ReceiverCriticalSection
RAII class creating a critical section for the receiver thread.
Definition iface_mgr.h:1867
isc::dhcp::TimerMgr
Manages a pool of asynchronous interval timers.
Definition timer_mgr.h:62
isc::dhcp::TimerMgr::instance
static const TimerMgrPtr & instance()
Returns pointer to the sole instance of the TimerMgr.
Definition timer_mgr.cc:446
isc::hooks::CalloutHandle::NEXT_STEP_DROP
@ NEXT_STEP_DROP
drop the packet
Definition callout_handle.h:89
isc::hooks::HooksManager::registerHook
static int registerHook(const std::string &name)
Register Hook.
Definition hooks_manager.cc:232
isc::hooks::HooksManager::calloutsPresent
static bool calloutsPresent(int index)
Are callouts present?
Definition hooks_manager.cc:54
isc::hooks::HooksManager::createCalloutHandle
static boost::shared_ptr< CalloutHandle > createCalloutHandle()
Return callout handle.
Definition hooks_manager.cc:203
isc::hooks::HooksManager::callCallouts
static void callCallouts(int index, CalloutHandle &handle)
Calls the callouts for a given hook.
Definition hooks_manager.cc:76
isc::hooks::NoSuchArgument
No such argument.
Definition callout_handle.h:31
isc::process::Daemon::getConfigFile
std::string getConfigFile() const
Returns config file name.
Definition daemon.cc:107
isc::process::Daemon::writeConfigFile
virtual size_t writeConfigFile(const std::string &config_file, isc::data::ConstElementPtr cfg=isc::data::ConstElementPtr()) const
Writes current configuration to specified file.
Definition daemon.cc:269
isc::process::Daemon::signal_set_
isc::asiolink::IOSignalSetPtr signal_set_
A pointer to the object installing custom signal handlers.
Definition daemon.h:272
isc::process::Daemon::start_
boost::posix_time::ptime start_
Timestamp of the start of the daemon.
Definition daemon.h:278
isc::process::Daemon::checkWriteConfigFile
void checkWriteConfigFile(std::string &file)
Checks the to-be-written configuration file name.
Definition daemon.cc:132
isc::process::Daemon::setExitValue
void setExitValue(int value)
Sets the exit value.
Definition daemon.h:242
isc::process::Daemon::redactConfig
isc::data::ConstElementPtr redactConfig(isc::data::ConstElementPtr const &config)
Redact a configuration.
Definition daemon.cc:297
isc::stats::StatsMgr
Statistics Manager class.
Definition lib/stats/stats_mgr.h:65
isc::stats::StatsMgr::instance
static StatsMgr & instance()
Statistics Manager accessor method.
Definition lib/stats/stats_mgr.cc:30
isc::util::MultiThreadingCriticalSection
RAII class creating a critical section.
Definition multi_threading_mgr.h:374
isc::util::MultiThreadingMgr::instance
static MultiThreadingMgr & instance()
Returns a single instance of Multi Threading Manager.
Definition multi_threading_mgr.cc:25
isc::util::MultiThreadingMgr::apply
void apply(bool enabled, uint32_t thread_count, uint32_t queue_size)
Apply the multi-threading related settings.
Definition multi_threading_mgr.cc:124
command_interpreter.h
This file contains several functions and constants that are used for handling commands and responses ...
command_mgr.h
config_report.h
crypto_hash.h
ctrl_dhcp6_srv.h
data.h
db_type.h
dbaccess_parser.h
Hooks
Dhcp4Hooks Hooks
Definition dhcp4_srv.cc:213
json_config_parser.h
parser_context.h
D6O_INTERFACE_ID
@ D6O_INTERFACE_ID
Definition dhcp6.h:38
D6O_SERVERID
@ D6O_SERVERID
Definition dhcp6.h:22
dhcp6_log.h
dhcp6to4_ipc.h
Defines the Dhcp6to4Ipc class.
encode.h
isc_throw
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition exceptions/exceptions.h:210
isc::stats::StatsMgr::statisticSetMaxSampleCountAllHandler
isc::data::ConstElementPtr statisticSetMaxSampleCountAllHandler(const isc::data::ConstElementPtr &params)
Handles statistic-sample-count-set-all command.
Definition lib/stats/stats_mgr.cc:482
isc::stats::StatsMgr::statisticResetHandler
static isc::data::ConstElementPtr statisticResetHandler(const std::string &name, const isc::data::ConstElementPtr &params)
Handles statistic-reset command.
Definition lib/stats/stats_mgr.cc:403
isc::stats::StatsMgr::statisticGetAllHandler
static isc::data::ConstElementPtr statisticGetAllHandler(const std::string &name, const isc::data::ConstElementPtr &params)
Handles statistic-get-all command.
Definition lib/stats/stats_mgr.cc:445
isc::stats::StatsMgr::statisticRemoveHandler
static isc::data::ConstElementPtr statisticRemoveHandler(const std::string &name, const isc::data::ConstElementPtr &params)
Handles statistic-remove command.
Definition lib/stats/stats_mgr.cc:419
isc::stats::StatsMgr::statisticGetHandler
static isc::data::ConstElementPtr statisticGetHandler(const std::string &name, const isc::data::ConstElementPtr &params)
Handles statistic-get command.
Definition lib/stats/stats_mgr.cc:392
isc::stats::StatsMgr::statisticGlobalGetAllHandler
static isc::data::ConstElementPtr statisticGlobalGetAllHandler(const std::string &name, const isc::data::ConstElementPtr &params)
Handles statistic-global-get-all command.
Definition lib/stats/stats_mgr.cc:452
isc::stats::StatsMgr::statisticSetMaxSampleAgeAllHandler
isc::data::ConstElementPtr statisticSetMaxSampleAgeAllHandler(const isc::data::ConstElementPtr &params)
Handles statistic-sample-age-set-all command.
Definition lib/stats/stats_mgr.cc:467
isc::stats::StatsMgr::statisticResetAllHandler
static isc::data::ConstElementPtr statisticResetAllHandler(const std::string &name, const isc::data::ConstElementPtr &params)
Handles statistic-reset-all command.
Definition lib/stats/stats_mgr.cc:459
isc::stats::StatsMgr::statisticSetMaxSampleAgeHandler
static isc::data::ConstElementPtr statisticSetMaxSampleAgeHandler(const std::string &name, const isc::data::ConstElementPtr &params)
Handles statistic-sample-age-set command.
Definition lib/stats/stats_mgr.cc:352
isc::stats::StatsMgr::statisticRemoveAllHandler
static isc::data::ConstElementPtr statisticRemoveAllHandler(const std::string &name, const isc::data::ConstElementPtr &params)
Handles statistic-remove-all command.
Definition lib/stats/stats_mgr.cc:436
isc::stats::StatsMgr::statisticSetMaxSampleCountHandler
static isc::data::ConstElementPtr statisticSetMaxSampleCountHandler(const std::string &name, const isc::data::ConstElementPtr &params)
Handles statistic-sample-count-set command.
Definition lib/stats/stats_mgr.cc:372
isc::stats::StatsMgr::getMaxSampleCountDefault
uint32_t getMaxSampleCountDefault() const
Get default count limit.
Definition lib/stats/stats_mgr.cc:228
isc::stats::StatsMgr::getMaxSampleAgeDefault
const StatsDuration & getMaxSampleAgeDefault() const
Get default duration limit.
Definition lib/stats/stats_mgr.cc:217
hooks.h
hooks_manager.h
host_mgr.h
http_command_mgr.h
ifaces_config_parser.h
io_service_mgr.h
lease_mgr_factory.h
stats_mgr.h
libdhcp++.h
LOG_ERROR
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
Definition macros.h:32
LOG_INFO
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
Definition macros.h:20
LOG_WARN
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
Definition macros.h:26
LOG_FATAL
#define LOG_FATAL(LOGGER, MESSAGE)
Macro to conveniently test fatal output and log it.
Definition macros.h:38
LOG_DEBUG
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
Definition macros.h:14
memfile_lease_mgr.h
multi_threading_mgr.h
isc::asiolink
Definition addr_utilities.cc:170
isc::asiolink::IOServicePtr
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
Definition io_service.h:35
isc::config
Definition command_interpreter.cc:23
isc::config::CONTROL_RESULT_EMPTY
const int CONTROL_RESULT_EMPTY
Status code indicating that the specified command was completed correctly, but failed to produce any ...
Definition command_interpreter.h:53
isc::config::parseAnswer
ConstElementPtr parseAnswer(int &rcode, const ConstElementPtr &msg)
Parses a standard config/command level answer and returns arguments or text status code.
Definition command_interpreter.cc:96
isc::config::createCommand
ConstElementPtr createCommand(const std::string &command)
Creates a standard command message with no argument (of the form { "command": "my_command" }...
Definition command_interpreter.cc:167
isc::config::CONTROL_RESULT_ERROR
const int CONTROL_RESULT_ERROR
Status code indicating a general failure.
Definition command_interpreter.h:45
isc::config::createAnswer
ConstElementPtr createAnswer(const int status_code, const std::string &text, const ConstElementPtr &arg)
Creates a standard config/command level answer message.
Definition command_interpreter.cc:34
isc::config::createAnswer
ConstElementPtr createAnswer()
Creates a standard config/command level success answer message (i.e.
Definition command_interpreter.cc:54
isc::config::CONTROL_RESULT_COMMAND_UNSUPPORTED
const int CONTROL_RESULT_COMMAND_UNSUPPORTED
Status code indicating that the specified command is not supported.
Definition command_interpreter.h:48
isc::config::CONTROL_RESULT_FATAL_ERROR
const int CONTROL_RESULT_FATAL_ERROR
Status code indicating that the command was unsuccessful and the configuration could not be reverted ...
Definition command_interpreter.h:63
isc::config::CONTROL_RESULT_SUCCESS
const int CONTROL_RESULT_SUCCESS
Status code indicating a successful operation.
Definition command_interpreter.h:42
isc::data
Definition base_stamped_element.cc:12
isc::data::ConstElementPtr
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:30
isc::data::ElementPtr
boost::shared_ptr< Element > ElementPtr
Definition data.h:29
isc::db
Definition audit_entry.cc:14
isc::db::error
@ error
Definition db_log.h:124
isc::detail::getConfigReport
std::string getConfigReport()
Definition cfgrpt.cc:20
isc::dhcp
Definition dhcp4/client_handler.cc:20
isc::dhcp::DHCP6_DB_RECONNECT_NO_DB_CTL
const isc::log::MessageID DHCP6_DB_RECONNECT_NO_DB_CTL
Definition dhcp6_messages.h:46
isc::dhcp::DHCP6_OPEN_SOCKETS_NO_RECONNECT_CTL
const isc::log::MessageID DHCP6_OPEN_SOCKETS_NO_RECONNECT_CTL
Definition dhcp6_messages.h:108
isc::dhcp::DHCP6_USING_SERVERID
const isc::log::MessageID DHCP6_USING_SERVERID
Definition dhcp6_messages.h:185
isc::dhcp::DHCP6_CONFIG_LOAD_FAIL
const isc::log::MessageID DHCP6_CONFIG_LOAD_FAIL
Definition dhcp6_messages.h:35
isc::dhcp::ConstSubnet6Ptr
boost::shared_ptr< const Subnet6 > ConstSubnet6Ptr
A const pointer to a Subnet6 object.
Definition subnet.h:620
isc::dhcp::DHCP6_DB_RECONNECT_SUCCEEDED
const isc::log::MessageID DHCP6_DB_RECONNECT_SUCCEEDED
Definition dhcp6_messages.h:47
isc::dhcp::configureDhcp6Server
isc::data::ConstElementPtr configureDhcp6Server(Dhcpv6Srv &server, isc::data::ConstElementPtr config_set, bool check_only, bool extra_checks)
Configure DHCPv6 server (Dhcpv6Srv) with a set of configuration values.
Definition dhcp6/json_config_parser.cc:870
isc::dhcp::DHCP6_RECLAIM_EXPIRED_LEASES_SKIPPED
const isc::log::MessageID DHCP6_RECLAIM_EXPIRED_LEASES_SKIPPED
Definition dhcp6_messages.h:151
isc::dhcp::CfgDbAccessPtr
boost::shared_ptr< CfgDbAccess > CfgDbAccessPtr
A pointer to the CfgDbAccess.
Definition cfg_db_access.h:151
isc::dhcp::IfacePtr
boost::shared_ptr< Iface > IfacePtr
Type definition for the pointer to an Iface object.
Definition iface_mgr.h:555
isc::dhcp::DuidPtr
boost::shared_ptr< DUID > DuidPtr
Definition duid.h:136
isc::dhcp::DBG_DHCP6_COMMAND
const int DBG_DHCP6_COMMAND
Debug level used to log receiving commands.
Definition dhcp6_log.h:28
isc::dhcp::DHCP6_CB_PERIODIC_FETCH_UPDATES_FAIL
const isc::log::MessageID DHCP6_CB_PERIODIC_FETCH_UPDATES_FAIL
Definition dhcp6_messages.h:27
isc::dhcp::DHCP6_RECLAIM_EXPIRED_LEASES_FAIL
const isc::log::MessageID DHCP6_RECLAIM_EXPIRED_LEASES_FAIL
Definition dhcp6_messages.h:150
isc::dhcp::CfgIfacePtr
boost::shared_ptr< CfgIface > CfgIfacePtr
A pointer to the CfgIface .
Definition cfg_iface.h:522
isc::dhcp::DHCP6_OPEN_SOCKETS_FAILED
const isc::log::MessageID DHCP6_OPEN_SOCKETS_FAILED
Definition dhcp6_messages.h:107
isc::dhcp::SrvConfigPtr
boost::shared_ptr< SrvConfig > SrvConfigPtr
Non-const pointer to the SrvConfig.
Definition srv_config.h:1148
isc::dhcp::DHCP6_DYNAMIC_RECONFIGURATION_SUCCESS
const isc::log::MessageID DHCP6_DYNAMIC_RECONFIGURATION_SUCCESS
Definition dhcp6_messages.h:71
isc::dhcp::DHCP6_CB_ON_DEMAND_FETCH_UPDATES_FAIL
const isc::log::MessageID DHCP6_CB_ON_DEMAND_FETCH_UPDATES_FAIL
Definition dhcp6_messages.h:26
isc::dhcp::DHCP6_CB_PERIODIC_FETCH_UPDATES_RETRIES_EXHAUSTED
const isc::log::MessageID DHCP6_CB_PERIODIC_FETCH_UPDATES_RETRIES_EXHAUSTED
Definition dhcp6_messages.h:28
isc::dhcp::DHCP6_NOT_RUNNING
const isc::log::MessageID DHCP6_NOT_RUNNING
Definition dhcp6_messages.h:104
isc::dhcp::SharedNetwork6Ptr
boost::shared_ptr< SharedNetwork6 > SharedNetwork6Ptr
Pointer to SharedNetwork6 object.
Definition shared_network.h:267
isc::dhcp::DHCP6_FATAL_OPEN_SOCKETS_FAILED
const isc::log::MessageID DHCP6_FATAL_OPEN_SOCKETS_FAILED
Definition dhcp6_messages.h:72
isc::dhcp::DHCP6_DYNAMIC_RECONFIGURATION_FAIL
const isc::log::MessageID DHCP6_DYNAMIC_RECONFIGURATION_FAIL
Definition dhcp6_messages.h:70
isc::dhcp::DHCP6_CONFIG_UNSUPPORTED_OBJECT
const isc::log::MessageID DHCP6_CONFIG_UNSUPPORTED_OBJECT
Definition dhcp6_messages.h:41
isc::dhcp::DHCP6_CONFIG_UNRECOVERABLE_ERROR
const isc::log::MessageID DHCP6_CONFIG_UNRECOVERABLE_ERROR
Definition dhcp6_messages.h:40
isc::dhcp::DHCP6_CONFIG_RECEIVED
const isc::log::MessageID DHCP6_CONFIG_RECEIVED
Definition dhcp6_messages.h:37
isc::dhcp::DHCP6_DB_RECONNECT_DISABLED
const isc::log::MessageID DHCP6_DB_RECONNECT_DISABLED
Definition dhcp6_messages.h:43
isc::dhcp::DHCP6_DYNAMIC_RECONFIGURATION
const isc::log::MessageID DHCP6_DYNAMIC_RECONFIGURATION
Definition dhcp6_messages.h:69
isc::dhcp::DHCP6_DB_RECONNECT_LOST_CONNECTION
const isc::log::MessageID DHCP6_DB_RECONNECT_LOST_CONNECTION
Definition dhcp6_messages.h:45
isc::dhcp::DBG_DHCP6_BASIC
const int DBG_DHCP6_BASIC
Debug level used to trace basic operations within the code.
Definition dhcp6_log.h:31
isc::dhcp::dhcp6_logger
isc::log::Logger dhcp6_logger(DHCP6_APP_LOGGER_NAME)
Base logger for DHCPv6 server.
Definition dhcp6_log.h:88
isc::dhcp::DHCP6_MULTI_THREADING_INFO
const isc::log::MessageID DHCP6_MULTI_THREADING_INFO
Definition dhcp6_messages.h:103
isc::dhcp::DHCP6_DB_RECONNECT_FAILED
const isc::log::MessageID DHCP6_DB_RECONNECT_FAILED
Definition dhcp6_messages.h:44
isc::dhcp::OptionPtr
boost::shared_ptr< Option > OptionPtr
Definition option.h:37
isc::dhcp::DHCP6_CONFIG_PACKET_QUEUE
const isc::log::MessageID DHCP6_CONFIG_PACKET_QUEUE
Definition dhcp6_messages.h:36
isc::hooks
Definition callout_handle.cc:21
isc::hooks::CalloutHandlePtr
boost::shared_ptr< CalloutHandle > CalloutHandlePtr
A shared pointer to a CalloutHandle object.
Definition callout_handle.h:470
isc::stats
Definition context.cc:18
isc::stats::toSeconds
long toSeconds(const StatsDuration &dur)
Returns the number of seconds in a duration.
Definition observation.h:49
isc::util::file
Definition filesystem.cc:29
isc::util::str
Definition str.cc:29
isc::util::str::decodeFormattedHexString
void decodeFormattedHexString(const string &hex_string, vector< uint8_t > &binary)
Converts a formatted string of hexadecimal digits into a vector.
Definition str.cc:212
isc::util::str::quotedStringToBinary
vector< uint8_t > quotedStringToBinary(const string &quoted_string)
Converts a string in quotes into vector.
Definition str.cc:139
isc::util
Definition time_utils.cc:43
isc::util::ReconnectCtlPtr
boost::shared_ptr< ReconnectCtl > ReconnectCtlPtr
Pointer to an instance of ReconnectCtl.
Definition reconnect_ctl.h:153
isc
Defines the logger used by the top-level component of kea-lfc.
Definition check_exists_add.cc:18
process_spawn.h
isc::dhcp::SubnetSelector
Subnet selector used to specify parameters used to select a subnet.
Definition subnet_selector.h:23
isc::dhcp::SubnetSelector::iface_name_
std::string iface_name_
Name of the interface on which the message was received.
Definition subnet_selector.h:49
isc::dhcp::SubnetSelector::client_classes_
ClientClasses client_classes_
Classes that the client belongs to.
Definition subnet_selector.h:47
isc::dhcp::SubnetSelector::remote_address_
asiolink::IOAddress remote_address_
Source address of the message.
Definition subnet_selector.h:45
isc::dhcp::SubnetSelector::interface_id_
OptionPtr interface_id_
Interface id option.
Definition subnet_selector.h:37
isc::dhcp::SubnetSelector::first_relay_linkaddr_
asiolink::IOAddress first_relay_linkaddr_
First relay link address.
Definition subnet_selector.h:39
unix_command_mgr.h