Kea  1.9.9-git
ctrl_dhcp6_srv.cc
Go to the documentation of this file.
1 // Copyright (C) 2014-2021 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 
10 #include <cc/data.h>
11 #include <cfgrpt/config_report.h>
12 #include <config/command_mgr.h>
13 #include <dhcp/libdhcp++.h>
14 #include <dhcp6/ctrl_dhcp6_srv.h>
15 #include <dhcp6/dhcp6_log.h>
16 #include <dhcp6/dhcp6to4_ipc.h>
18 #include <dhcp6/parser_context.h>
19 #include <dhcpsrv/cfg_db_access.h>
21 #include <dhcpsrv/cfgmgr.h>
22 #include <dhcpsrv/db_type.h>
24 #include <dhcpsrv/host_mgr.h>
25 #include <hooks/hooks.h>
26 #include <hooks/hooks_manager.h>
27 #include <stats/stats_mgr.h>
29 
30 #include <signal.h>
31 
32 #include <sstream>
33 
34 using namespace isc::asiolink;
35 using namespace isc::config;
36 using namespace isc::data;
37 using namespace isc::db;
38 using namespace isc::dhcp;
39 using namespace isc::hooks;
40 using namespace isc::stats;
41 using namespace isc::util;
42 using namespace std;
43 namespace ph = std::placeholders;
44 
45 namespace {
46 
48 struct CtrlDhcp6Hooks {
49  int hooks_index_dhcp6_srv_configured_;
50 
52  CtrlDhcp6Hooks() {
53  hooks_index_dhcp6_srv_configured_ = HooksManager::registerHook("dhcp6_srv_configured");
54  }
55 
56 };
57 
58 // Declare a Hooks object. As this is outside any function or method, it
59 // will be instantiated (and the constructor run) when the module is loaded.
60 // As a result, the hook indexes will be defined before any method in this
61 // module is called.
62 CtrlDhcp6Hooks Hooks;
63 
64 // Name of the file holding server identifier.
65 static const char* SERVER_DUID_FILE = "kea-dhcp6-serverid";
66 
76 void signalHandler(int signo) {
77  // SIGHUP signals a request to reconfigure the server.
78  if (signo == SIGHUP) {
79  ControlledDhcpv6Srv::processCommand("config-reload",
80  ConstElementPtr());
81  } else if ((signo == SIGTERM) || (signo == SIGINT)) {
82  ControlledDhcpv6Srv::processCommand("shutdown",
83  ConstElementPtr());
84  }
85 }
86 
87 }
88 
89 namespace isc {
90 namespace dhcp {
91 
92 ControlledDhcpv6Srv* ControlledDhcpv6Srv::server_ = NULL;
93 
95 ControlledDhcpv6Srv::loadConfigFile(const std::string& file_name) {
96  // This is a configuration backend implementation that reads the
97  // configuration from a JSON file.
98 
101 
102  // Basic sanity check: file name must not be empty.
103  try {
104  if (file_name.empty()) {
105  // Basic sanity check: file name must not be empty.
106  isc_throw(isc::BadValue, "JSON configuration file not specified. Please "
107  "use -c command line option.");
108  }
109 
110  // Read contents of the file and parse it as JSON
111  Parser6Context parser;
112  json = parser.parseFile(file_name, Parser6Context::PARSER_DHCP6);
113  if (!json) {
114  isc_throw(isc::BadValue, "no configuration found");
115  }
116 
117  // Let's do sanity check before we call json->get() which
118  // works only for map.
119  if (json->getType() != isc::data::Element::map) {
120  isc_throw(isc::BadValue, "Configuration file is expected to be "
121  "a map, i.e., start with { and end with } and contain "
122  "at least an entry called 'Dhcp6' that itself is a map. "
123  << file_name
124  << " is a valid JSON, but its top element is not a map."
125  " Did you forget to add { } around your configuration?");
126  }
127 
128  // Use parsed JSON structures to configure the server
129  result = ControlledDhcpv6Srv::processCommand("config-set", json);
130  if (!result) {
131  // Undetermined status of the configuration. This should never
132  // happen, but as the configureDhcp6Server returns a pointer, it is
133  // theoretically possible that it will return NULL.
134  isc_throw(isc::BadValue, "undefined result of "
135  "processCommand(\"config-set\", json)");
136  }
137 
138  // Now check is the returned result is successful (rcode=0) or not
139  // (see @ref isc::config::parseAnswer).
140  int rcode;
141  ConstElementPtr comment = isc::config::parseAnswer(rcode, result);
142  if (rcode != CONTROL_RESULT_SUCCESS) {
143  string reason = comment ? comment->stringValue() :
144  "no details available";
145  isc_throw(isc::BadValue, reason);
146  }
147  } catch (const std::exception& ex) {
148  // If configuration failed at any stage, we drop the staging
149  // configuration and continue to use the previous one.
150  CfgMgr::instance().rollback();
151 
153  .arg(file_name).arg(ex.what());
154  isc_throw(isc::BadValue, "configuration error using file '"
155  << file_name << "': " << ex.what());
156  }
157 
159  .arg(MultiThreadingMgr::instance().getMode() ? "yes" : "no")
160  .arg(MultiThreadingMgr::instance().getThreadPoolSize())
161  .arg(MultiThreadingMgr::instance().getPacketQueueSize());
162 
163  return (result);
164 }
165 
166 void
167 ControlledDhcpv6Srv::init(const std::string& file_name) {
168  // Keep the call timestamp.
169  start_ = boost::posix_time::second_clock::universal_time();
170 
171  // Configure the server using JSON file.
172  ConstElementPtr result = loadConfigFile(file_name);
173 
174  int rcode;
175  ConstElementPtr comment = isc::config::parseAnswer(rcode, result);
176  if (rcode != CONTROL_RESULT_SUCCESS) {
177  string reason = comment ? comment->stringValue() :
178  "no details available";
179  isc_throw(isc::BadValue, reason);
180  }
181 
182  // We don't need to call openActiveSockets() or startD2() as these
183  // methods are called in processConfig() which is called by
184  // processCommand("config-set", ...)
185 
186  // Set signal handlers. When the SIGHUP is received by the process
187  // the server reconfiguration will be triggered. When SIGTERM or
188  // SIGINT will be received, the server will start shutting down.
189  signal_set_.reset(new IOSignalSet(getIOService(), signalHandler));
190 
191  signal_set_->add(SIGINT);
192  signal_set_->add(SIGHUP);
193  signal_set_->add(SIGTERM);
194 }
195 
196 void ControlledDhcpv6Srv::cleanup() {
197  // Nothing to do here. No need to disconnect from anything.
198 }
199 
201 ControlledDhcpv6Srv::commandShutdownHandler(const string&, ConstElementPtr args) {
202  if (!ControlledDhcpv6Srv::getInstance()) {
204  return(createAnswer(CONTROL_RESULT_ERROR, "Shutdown failure."));
205  }
206 
207  int exit_value = 0;
208  if (args) {
209  // @todo Should we go ahead and shutdown even if the args are invalid?
210  if (args->getType() != Element::map) {
211  return (createAnswer(CONTROL_RESULT_ERROR, "Argument must be a map"));
212  }
213 
214  ConstElementPtr param = args->get("exit-value");
215  if (param) {
216  if (param->getType() != Element::integer) {
218  "parameter 'exit-value' is not an integer"));
219  }
220 
221  exit_value = param->intValue();
222  }
223  }
224 
225  ControlledDhcpv6Srv::getInstance()->shutdownServer(exit_value);
226  return (createAnswer(CONTROL_RESULT_SUCCESS, "Shutting down."));
227 }
228 
230 ControlledDhcpv6Srv::commandLibReloadHandler(const string&, ConstElementPtr) {
231  // stop thread pool (if running)
233 
234  // Clear the packet queue.
235  MultiThreadingMgr::instance().getThreadPool().reset();
236 
237  try {
239  HookLibsCollection loaded = HooksManager::getLibraryInfo();
240  HooksManager::prepareUnloadLibraries();
241  static_cast<void>(HooksManager::unloadLibraries());
242  bool status = HooksManager::loadLibraries(loaded);
243  if (!status) {
244  isc_throw(Unexpected, "Failed to reload hooks libraries.");
245  }
246  } catch (const std::exception& ex) {
248  ConstElementPtr answer = isc::config::createAnswer(1, ex.what());
249  return (answer);
250  }
252  "Hooks libraries successfully reloaded.");
253  return (answer);
254 }
255 
257 ControlledDhcpv6Srv::commandConfigReloadHandler(const string&,
258  ConstElementPtr /*args*/) {
259  // Get configuration file name.
260  std::string file = ControlledDhcpv6Srv::getInstance()->getConfigFile();
261  try {
263  return (loadConfigFile(file));
264  } catch (const std::exception& ex) {
265  // Log the unsuccessful reconfiguration. The reason for failure
266  // should be already logged. Don't rethrow an exception so as
267  // the server keeps working.
269  .arg(file);
271  "Config reload failed: " + string(ex.what())));
272  }
273 }
274 
276 ControlledDhcpv6Srv::commandConfigGetHandler(const string&,
277  ConstElementPtr /*args*/) {
278  ConstElementPtr config = CfgMgr::instance().getCurrentCfg()->toElement();
279 
280  return (createAnswer(0, config));
281 }
282 
284 ControlledDhcpv6Srv::commandConfigWriteHandler(const string&,
285  ConstElementPtr args) {
286  string filename;
287 
288  if (args) {
289  if (args->getType() != Element::map) {
290  return (createAnswer(CONTROL_RESULT_ERROR, "Argument must be a map"));
291  }
292  ConstElementPtr filename_param = args->get("filename");
293  if (filename_param) {
294  if (filename_param->getType() != Element::string) {
296  "passed parameter 'filename' is not a string"));
297  }
298  filename = filename_param->stringValue();
299  }
300  }
301 
302  if (filename.empty()) {
303  // filename parameter was not specified, so let's use whatever we remember
304  // from the command-line
305  filename = getConfigFile();
306  }
307 
308  if (filename.empty()) {
309  return (createAnswer(CONTROL_RESULT_ERROR, "Unable to determine filename."
310  "Please specify filename explicitly."));
311  }
312 
313  // Ok, it's time to write the file.
314  size_t size = 0;
315  try {
316  ConstElementPtr cfg = CfgMgr::instance().getCurrentCfg()->toElement();
317  size = writeConfigFile(filename, cfg);
318  } catch (const isc::Exception& ex) {
319  return (createAnswer(CONTROL_RESULT_ERROR, string("Error during write-config:")
320  + ex.what()));
321  }
322  if (size == 0) {
323  return (createAnswer(CONTROL_RESULT_ERROR, "Error writing configuration to "
324  + filename));
325  }
326 
327  // Ok, it's time to return the successful response.
328  ElementPtr params = Element::createMap();
329  params->set("size", Element::create(static_cast<long long>(size)));
330  params->set("filename", Element::create(filename));
331 
332  return (createAnswer(CONTROL_RESULT_SUCCESS, "Configuration written to "
333  + filename + " successful", params));
334 }
335 
337 ControlledDhcpv6Srv::commandConfigSetHandler(const string&,
338  ConstElementPtr args) {
339  const int status_code = CONTROL_RESULT_ERROR;
340  ConstElementPtr dhcp6;
341  string message;
342 
343  // Command arguments are expected to be:
344  // { "Dhcp6": { ... } }
345  if (!args) {
346  message = "Missing mandatory 'arguments' parameter.";
347  } else {
348  dhcp6 = args->get("Dhcp6");
349  if (!dhcp6) {
350  message = "Missing mandatory 'Dhcp6' parameter.";
351  } else if (dhcp6->getType() != Element::map) {
352  message = "'Dhcp6' parameter expected to be a map.";
353  }
354  }
355 
356  // Check unsupported objects.
357  if (message.empty()) {
358  for (auto obj : args->mapValue()) {
359  const string& obj_name = obj.first;
360  if (obj_name != "Dhcp6") {
362  .arg(obj_name);
363  if (message.empty()) {
364  message = "Unsupported '" + obj_name + "' parameter";
365  } else {
366  message += " (and '" + obj_name + "')";
367  }
368  }
369  }
370  if (!message.empty()) {
371  message += ".";
372  }
373  }
374 
375  if (!message.empty()) {
376  // Something is amiss with arguments, return a failure response.
377  ConstElementPtr result = isc::config::createAnswer(status_code,
378  message);
379  return (result);
380  }
381 
382  // stop thread pool (if running)
384 
385  // disable multi-threading (it will be applied by new configuration)
386  // this must be done in order to properly handle MT to ST transition
387  // when 'multi-threading' structure is missing from new config
388  MultiThreadingMgr::instance().apply(false, 0, 0);
389 
390  // We are starting the configuration process so we should remove any
391  // staging configuration that has been created during previous
392  // configuration attempts.
393  CfgMgr::instance().rollback();
394 
395  // Parse the logger configuration explicitly into the staging config.
396  // Note this does not alter the current loggers, they remain in
397  // effect until we apply the logging config below. If no logging
398  // is supplied logging will revert to default logging.
399  Daemon::configureLogger(dhcp6, CfgMgr::instance().getStagingCfg());
400 
401  // Let's apply the new logging. We do it early, so we'll be able to print
402  // out what exactly is wrong with the new config in case of problems.
403  CfgMgr::instance().getStagingCfg()->applyLoggingCfg();
404 
405  // Now we configure the server proper.
406  ConstElementPtr result = processConfig(dhcp6);
407 
408  // If the configuration parsed successfully, apply the new logger
409  // configuration and the commit the new configuration. We apply
410  // the logging first in case there's a configuration failure.
411  int rcode = 0;
412  isc::config::parseAnswer(rcode, result);
413  if (rcode == CONTROL_RESULT_SUCCESS) {
414  CfgMgr::instance().getStagingCfg()->applyLoggingCfg();
415 
416  // Use new configuration.
417  CfgMgr::instance().commit();
418  } else {
419  // Ok, we applied the logging from the upcoming configuration, but
420  // there were problems with the config. As such, we need to back off
421  // and revert to the previous logging configuration.
422  CfgMgr::instance().getCurrentCfg()->applyLoggingCfg();
423 
424  if (CfgMgr::instance().getCurrentCfg()->getSequence() != 0) {
425  // Not initial configuration so someone can believe we reverted
426  // to the previous configuration. It is not the case so be clear
427  // about this.
429  }
430  }
431 
432  return (result);
433 }
434 
436 ControlledDhcpv6Srv::commandConfigTestHandler(const string&,
437  ConstElementPtr args) {
438  const int status_code = CONTROL_RESULT_ERROR; // 1 indicates an error
439  ConstElementPtr dhcp6;
440  string message;
441 
442  // Command arguments are expected to be:
443  // { "Dhcp6": { ... } }
444  if (!args) {
445  message = "Missing mandatory 'arguments' parameter.";
446  } else {
447  dhcp6 = args->get("Dhcp6");
448  if (!dhcp6) {
449  message = "Missing mandatory 'Dhcp6' parameter.";
450  } else if (dhcp6->getType() != Element::map) {
451  message = "'Dhcp6' parameter expected to be a map.";
452  }
453  }
454 
455  // Check unsupported objects.
456  if (message.empty()) {
457  for (auto obj : args->mapValue()) {
458  const string& obj_name = obj.first;
459  if (obj_name != "Dhcp6") {
461  .arg(obj_name);
462  if (message.empty()) {
463  message = "Unsupported '" + obj_name + "' parameter";
464  } else {
465  message += " (and '" + obj_name + "')";
466  }
467  }
468  }
469  if (!message.empty()) {
470  message += ".";
471  }
472  }
473 
474  if (!message.empty()) {
475  // Something is amiss with arguments, return a failure response.
476  ConstElementPtr result = isc::config::createAnswer(status_code,
477  message);
478  return (result);
479  }
480 
481  // stop thread pool (if running)
483 
484  // We are starting the configuration process so we should remove any
485  // staging configuration that has been created during previous
486  // configuration attempts.
487  CfgMgr::instance().rollback();
488 
489  // Now we check the server proper.
490  return (checkConfig(dhcp6));
491 }
492 
494 ControlledDhcpv6Srv::commandDhcpDisableHandler(const std::string&,
495  ConstElementPtr args) {
496  std::ostringstream message;
497  int64_t max_period = 0;
498  std::string origin;
499 
500  // If the args map does not contain 'origin' parameter, the default type
501  // will be used (user command).
502  NetworkState::Origin type = NetworkState::Origin::USER_COMMAND;
503 
504  // Parse arguments to see if the 'max-period' or 'origin' parameters have
505  // been specified.
506  if (args) {
507  // Arguments must be a map.
508  if (args->getType() != Element::map) {
509  message << "arguments for the 'dhcp-disable' command must be a map";
510 
511  } else {
512  ConstElementPtr max_period_element = args->get("max-period");
513  // max-period is optional.
514  if (max_period_element) {
515  // It must be an integer, if specified.
516  if (max_period_element->getType() != Element::integer) {
517  message << "'max-period' argument must be a number";
518 
519  } else {
520  // It must be positive integer.
521  max_period = max_period_element->intValue();
522  if (max_period <= 0) {
523  message << "'max-period' must be positive integer";
524  }
525  }
526  }
527  ConstElementPtr origin_element = args->get("origin");
528  // The 'origin' parameter is optional.
529  if (origin_element) {
530  // It must be a string, if specified.
531  if (origin_element->getType() != Element::string) {
532  message << "'origin' argument must be a string";
533 
534  } else {
535  origin = origin_element->stringValue();
536  if (origin == "ha-partner") {
537  type = NetworkState::Origin::HA_COMMAND;
538  } else if (origin != "user") {
539  if (origin.empty()) {
540  origin = "(empty string)";
541  }
542  message << "invalid value used for 'origin' parameter: "
543  << origin;
544  }
545  }
546  }
547  }
548  }
549 
550  // No error occurred, so let's disable the service.
551  if (message.tellp() == 0) {
552  message << "DHCPv6 service disabled";
553  if (max_period > 0) {
554  message << " for " << max_period << " seconds";
555 
556  // The user specified that the DHCP service should resume not
557  // later than in max-period seconds. If the 'dhcp-enable' command
558  // is not sent, the DHCP service will resume automatically.
559  network_state_->delayedEnableAll(static_cast<unsigned>(max_period),
560  type);
561  }
562  network_state_->disableService(type);
563 
564  // Success.
565  return (config::createAnswer(CONTROL_RESULT_SUCCESS, message.str()));
566  }
567 
568  // Failure.
569  return (config::createAnswer(CONTROL_RESULT_ERROR, message.str()));
570 }
571 
573 ControlledDhcpv6Srv::commandDhcpEnableHandler(const std::string&,
574  ConstElementPtr args) {
575  std::ostringstream message;
576  std::string origin;
577 
578  // If the args map does not contain 'origin' parameter, the default type
579  // will be used (user command).
580  NetworkState::Origin type = NetworkState::Origin::USER_COMMAND;
581 
582  // Parse arguments to see if the 'origin' parameter has been specified.
583  if (args) {
584  // Arguments must be a map.
585  if (args->getType() != Element::map) {
586  message << "arguments for the 'dhcp-enable' command must be a map";
587 
588  } else {
589  ConstElementPtr origin_element = args->get("origin");
590  // The 'origin' parameter is optional.
591  if (origin_element) {
592  // It must be a string, if specified.
593  if (origin_element->getType() != Element::string) {
594  message << "'origin' argument must be a string";
595 
596  } else {
597  origin = origin_element->stringValue();
598  if (origin == "ha-partner") {
599  type = NetworkState::Origin::HA_COMMAND;
600  } else if (origin != "user") {
601  if (origin.empty()) {
602  origin = "(empty string)";
603  }
604  message << "invalid value used for 'origin' parameter: "
605  << origin;
606  }
607  }
608  }
609  }
610  }
611 
612  // No error occurred, so let's enable the service.
613  if (message.tellp() == 0) {
614  network_state_->enableService(type);
615 
616  // Success.
618  "DHCP service successfully enabled"));
619  }
620 
621  // Failure.
622  return (config::createAnswer(CONTROL_RESULT_ERROR, message.str()));
623 }
624 
626 ControlledDhcpv6Srv::commandVersionGetHandler(const string&, ConstElementPtr) {
627  ElementPtr extended = Element::create(Dhcpv6Srv::getVersion(true));
628  ElementPtr arguments = Element::createMap();
629  arguments->set("extended", extended);
631  Dhcpv6Srv::getVersion(false),
632  arguments);
633  return (answer);
634 }
635 
637 ControlledDhcpv6Srv::commandBuildReportHandler(const string&,
638  ConstElementPtr) {
639  ConstElementPtr answer =
641  return (answer);
642 }
643 
645 ControlledDhcpv6Srv::commandLeasesReclaimHandler(const string&,
646  ConstElementPtr args) {
647  int status_code = CONTROL_RESULT_ERROR;
648  string message;
649 
650  // args must be { "remove": <bool> }
651  if (!args) {
652  message = "Missing mandatory 'remove' parameter.";
653  } else {
654  ConstElementPtr remove_name = args->get("remove");
655  if (!remove_name) {
656  message = "Missing mandatory 'remove' parameter.";
657  } else if (remove_name->getType() != Element::boolean) {
658  message = "'remove' parameter expected to be a boolean.";
659  } else {
660  bool remove_lease = remove_name->boolValue();
661  server_->alloc_engine_->reclaimExpiredLeases6(0, 0, remove_lease);
662  status_code = 0;
663  message = "Reclamation of expired leases is complete.";
664  }
665  }
666  ConstElementPtr answer = isc::config::createAnswer(status_code, message);
667  return (answer);
668 }
669 
671 ControlledDhcpv6Srv::commandServerTagGetHandler(const std::string&,
672  ConstElementPtr) {
673  const std::string& tag =
674  CfgMgr::instance().getCurrentCfg()->getServerTag();
675  ElementPtr response = Element::createMap();
676  response->set("server-tag", Element::create(tag));
677 
678  return (createAnswer(CONTROL_RESULT_SUCCESS, response));
679 }
680 
682 ControlledDhcpv6Srv::commandConfigBackendPullHandler(const std::string&,
683  ConstElementPtr) {
684  auto ctl_info = CfgMgr::instance().getCurrentCfg()->getConfigControlInfo();
685  if (!ctl_info) {
686  return (createAnswer(CONTROL_RESULT_EMPTY, "No config backend."));
687  }
688 
689  // stop thread pool (if running)
691 
692  // Reschedule the periodic CB fetch.
693  if (TimerMgr::instance()->isTimerRegistered("Dhcp6CBFetchTimer")) {
694  TimerMgr::instance()->cancel("Dhcp6CBFetchTimer");
695  TimerMgr::instance()->setup("Dhcp6CBFetchTimer");
696  }
697 
698  // Code from cbFetchUpdates.
699  // The configuration to use is the current one because this is called
700  // after the configuration manager commit.
701  try {
702  auto srv_cfg = CfgMgr::instance().getCurrentCfg();
703  auto mode = CBControlDHCPv6::FetchMode::FETCH_UPDATE;
704  server_->getCBControl()->databaseConfigFetch(srv_cfg, mode);
705  } catch (const std::exception& ex) {
707  .arg(ex.what());
709  "On demand configuration update failed: " +
710  string(ex.what())));
711  }
713  "On demand configuration update successful."));
714 }
715 
717 ControlledDhcpv6Srv::commandStatusGetHandler(const string&,
718  ConstElementPtr /*args*/) {
719  ElementPtr status = Element::createMap();
720  status->set("pid", Element::create(static_cast<int>(getpid())));
721 
722  auto now = boost::posix_time::second_clock::universal_time();
723  // Sanity check: start_ is always initialized.
724  if (!start_.is_not_a_date_time()) {
725  auto uptime = now - start_;
726  status->set("uptime", Element::create(uptime.total_seconds()));
727  }
728 
729  auto last_commit = CfgMgr::instance().getCurrentCfg()->getLastCommitTime();
730  if (!last_commit.is_not_a_date_time()) {
731  auto reload = now - last_commit;
732  status->set("reload", Element::create(reload.total_seconds()));
733  }
734 
735  auto& mt_mgr = MultiThreadingMgr::instance();
736  if (mt_mgr.getMode()) {
737  status->set("multi-threading-enabled", Element::create(true));
738  status->set("thread-pool-size", Element::create(static_cast<int32_t>(
739  MultiThreadingMgr::instance().getThreadPoolSize())));
740  status->set("packet-queue-size", Element::create(static_cast<int32_t>(
741  MultiThreadingMgr::instance().getPacketQueueSize())));
742  ElementPtr queue_stats = Element::createList();
743  queue_stats->add(Element::create(mt_mgr.getThreadPool().getQueueStat(10)));
744  queue_stats->add(Element::create(mt_mgr.getThreadPool().getQueueStat(100)));
745  queue_stats->add(Element::create(mt_mgr.getThreadPool().getQueueStat(1000)));
746  status->set("packet-queue-statistics", queue_stats);
747 
748  } else {
749  status->set("multi-threading-enabled", Element::create(false));
750  }
751 
752  return (createAnswer(0, status));
753 }
754 
756 ControlledDhcpv6Srv::commandStatisticSetMaxSampleCountAllHandler(const string&,
757  ConstElementPtr args) {
758  StatsMgr& stats_mgr = StatsMgr::instance();
759  ConstElementPtr answer = stats_mgr.statisticSetMaxSampleCountAllHandler(args);
760  // Update the default parameter.
761  long max_samples = stats_mgr.getMaxSampleCountDefault();
762  CfgMgr::instance().getCurrentCfg()->addConfiguredGlobal(
763  "statistic-default-sample-count", Element::create(max_samples));
764  return (answer);
765 }
766 
768 ControlledDhcpv6Srv::commandStatisticSetMaxSampleAgeAllHandler(const string&,
769  ConstElementPtr args) {
770  StatsMgr& stats_mgr = StatsMgr::instance();
771  ConstElementPtr answer = stats_mgr.statisticSetMaxSampleAgeAllHandler(args);
772  // Update the default parameter.
773  auto duration = stats_mgr.getMaxSampleAgeDefault();
774  long max_age = toSeconds(duration);
775  CfgMgr::instance().getCurrentCfg()->addConfiguredGlobal(
776  "statistic-default-sample-age", Element::create(max_age));
777  return (answer);
778 }
779 
781 ControlledDhcpv6Srv::processCommand(const string& command,
782  ConstElementPtr args) {
783  string txt = args ? args->str() : "(none)";
784 
786  .arg(command).arg(txt);
787 
788  ControlledDhcpv6Srv* srv = ControlledDhcpv6Srv::getInstance();
789 
790  if (!srv) {
792  "Server object not initialized, so can't process command '" +
793  command + "', arguments: '" + txt + "'.");
794  return (no_srv);
795  }
796 
797  try {
798  if (command == "shutdown") {
799  return (srv->commandShutdownHandler(command, args));
800 
801  } else if (command == "libreload") {
802  return (srv->commandLibReloadHandler(command, args));
803 
804  } else if (command == "config-reload") {
805  return (srv->commandConfigReloadHandler(command, args));
806 
807  } else if (command == "config-set") {
808  return (srv->commandConfigSetHandler(command, args));
809 
810  } else if (command == "config-get") {
811  return (srv->commandConfigGetHandler(command, args));
812 
813  } else if (command == "config-test") {
814  return (srv->commandConfigTestHandler(command, args));
815 
816  } else if (command == "dhcp-disable") {
817  return (srv->commandDhcpDisableHandler(command, args));
818 
819  } else if (command == "dhcp-enable") {
820  return (srv->commandDhcpEnableHandler(command, args));
821 
822  } else if (command == "version-get") {
823  return (srv->commandVersionGetHandler(command, args));
824 
825  } else if (command == "build-report") {
826  return (srv->commandBuildReportHandler(command, args));
827 
828  } else if (command == "leases-reclaim") {
829  return (srv->commandLeasesReclaimHandler(command, args));
830 
831  } else if (command == "config-write") {
832  return (srv->commandConfigWriteHandler(command, args));
833 
834  } else if (command == "server-tag-get") {
835  return (srv->commandServerTagGetHandler(command, args));
836 
837  } else if (command == "config-backend-pull") {
838  return (srv->commandConfigBackendPullHandler(command, args));
839 
840  } else if (command == "status-get") {
841  return (srv->commandStatusGetHandler(command, args));
842  }
843 
844  return (isc::config::createAnswer(1, "Unrecognized command:"
845  + command));
846 
847  } catch (const isc::Exception& ex) {
848  return (isc::config::createAnswer(1, "Error while processing command '"
849  + command + "':" + ex.what() +
850  ", params: '" + txt + "'"));
851  }
852 }
853 
855 ControlledDhcpv6Srv::processConfig(isc::data::ConstElementPtr config) {
856 
857  ControlledDhcpv6Srv* srv = ControlledDhcpv6Srv::getInstance();
858 
859  // Single stream instance used in all error clauses
860  std::ostringstream err;
861 
862  if (!srv) {
863  err << "Server object not initialized, can't process config.";
864  return (isc::config::createAnswer(1, err.str()));
865  }
866 
868  .arg(srv->redactConfig(config)->str());
869 
870  ConstElementPtr answer = configureDhcp6Server(*srv, config);
871 
872  // Check that configuration was successful. If not, do not reopen sockets
873  // and don't bother with DDNS stuff.
874  try {
875  int rcode = 0;
876  isc::config::parseAnswer(rcode, answer);
877  if (rcode != 0) {
878  return (answer);
879  }
880  } catch (const std::exception& ex) {
881  err << "Failed to process configuration:" << ex.what();
882  return (isc::config::createAnswer(1, err.str()));
883  }
884 
885  // Re-open lease and host database with new parameters.
886  try {
887  DatabaseConnection::db_lost_callback_ =
888  std::bind(&ControlledDhcpv6Srv::dbLostCallback, srv, ph::_1);
889 
890  DatabaseConnection::db_recovered_callback_ =
891  std::bind(&ControlledDhcpv6Srv::dbRecoveredCallback, srv, ph::_1);
892 
893  DatabaseConnection::db_failed_callback_ =
894  std::bind(&ControlledDhcpv6Srv::dbFailedCallback, srv, ph::_1);
895 
896  CfgDbAccessPtr cfg_db = CfgMgr::instance().getStagingCfg()->getCfgDbAccess();
897  cfg_db->setAppendedParameters("universe=6");
898  cfg_db->createManagers();
899  // Reset counters related to connections as all managers have been recreated.
900  srv->getNetworkState()->reset(NetworkState::Origin::DB_CONNECTION);
901  } catch (const std::exception& ex) {
902  err << "Unable to open database: " << ex.what();
903  return (isc::config::createAnswer(1, err.str()));
904  }
905 
906  // Regenerate server identifier if needed.
907  try {
908  const std::string duid_file =
909  std::string(CfgMgr::instance().getDataDir()) + "/" +
910  std::string(SERVER_DUID_FILE);
911  DuidPtr duid = CfgMgr::instance().getStagingCfg()->getCfgDUID()->create(duid_file);
912  server_->serverid_.reset(new Option(Option::V6, D6O_SERVERID, duid->getDuid()));
913  if (duid) {
915  .arg(duid->toText())
916  .arg(duid_file);
917  }
918 
919  } catch (const std::exception& ex) {
920  std::ostringstream err;
921  err << "unable to configure server identifier: " << ex.what();
922  return (isc::config::createAnswer(1, err.str()));
923  }
924 
925  // Server will start DDNS communications if its enabled.
926  try {
927  srv->startD2();
928  } catch (const std::exception& ex) {
929  err << "Error starting DHCP_DDNS client after server reconfiguration: "
930  << ex.what();
931  return (isc::config::createAnswer(1, err.str()));
932  }
933 
934  // Setup DHCPv4-over-DHCPv6 IPC
935  try {
936  Dhcp6to4Ipc::instance().open();
937  } catch (const std::exception& ex) {
938  std::ostringstream err;
939  err << "error starting DHCPv4-over-DHCPv6 IPC "
940  " after server reconfiguration: " << ex.what();
941  return (isc::config::createAnswer(1, err.str()));
942  }
943 
944  // Configure DHCP packet queueing
945  try {
947  qc = CfgMgr::instance().getStagingCfg()->getDHCPQueueControl();
948  if (IfaceMgr::instance().configureDHCPPacketQueue(AF_INET6, qc)) {
950  .arg(IfaceMgr::instance().getPacketQueue6()->getInfoStr());
951  }
952 
953  } catch (const std::exception& ex) {
954  err << "Error setting packet queue controls after server reconfiguration: "
955  << ex.what();
956  return (isc::config::createAnswer(1, err.str()));
957  }
958 
959  // Configuration may change active interfaces. Therefore, we have to reopen
960  // sockets according to new configuration. It is possible that this
961  // operation will fail for some interfaces but the openSockets function
962  // guards against exceptions and invokes a callback function to
963  // log warnings. Since we allow that this fails for some interfaces there
964  // is no need to rollback configuration if socket fails to open on any
965  // of the interfaces.
966  CfgMgr::instance().getStagingCfg()->getCfgIface()->
967  openSockets(AF_INET6, srv->getServerPort());
968 
969  // Install the timers for handling leases reclamation.
970  try {
971  CfgMgr::instance().getStagingCfg()->getCfgExpiration()->
972  setupTimers(&ControlledDhcpv6Srv::reclaimExpiredLeases,
973  &ControlledDhcpv6Srv::deleteExpiredReclaimedLeases,
974  server_);
975 
976  } catch (const std::exception& ex) {
977  err << "unable to setup timers for periodically running the"
978  " reclamation of the expired leases: "
979  << ex.what() << ".";
980  return (isc::config::createAnswer(1, err.str()));
981  }
982 
983  // Setup config backend polling, if configured for it.
984  auto ctl_info = CfgMgr::instance().getStagingCfg()->getConfigControlInfo();
985  if (ctl_info) {
986  long fetch_time = static_cast<long>(ctl_info->getConfigFetchWaitTime());
987  // Only schedule the CB fetch timer if the fetch wait time is greater
988  // than 0.
989  if (fetch_time > 0) {
990  // When we run unit tests, we want to use milliseconds unit for the
991  // specified interval. Otherwise, we use seconds. Note that using
992  // milliseconds as a unit in unit tests prevents us from waiting 1
993  // second on more before the timer goes off. Instead, we wait one
994  // millisecond which significantly reduces the test time.
995  if (!server_->inTestMode()) {
996  fetch_time = 1000 * fetch_time;
997  }
998 
999  boost::shared_ptr<unsigned> failure_count(new unsigned(0));
1000  TimerMgr::instance()->
1001  registerTimer("Dhcp6CBFetchTimer",
1002  std::bind(&ControlledDhcpv6Srv::cbFetchUpdates,
1003  server_, CfgMgr::instance().getStagingCfg(),
1004  failure_count),
1005  fetch_time,
1007  TimerMgr::instance()->setup("Dhcp6CBFetchTimer");
1008  }
1009  }
1010 
1011  // Finally, we can commit runtime option definitions in libdhcp++. This is
1012  // exception free.
1013  LibDHCP::commitRuntimeOptionDefs();
1014 
1015  // This hook point notifies hooks libraries that the configuration of the
1016  // DHCPv6 server has completed. It provides the hook library with the pointer
1017  // to the common IO service object, new server configuration in the JSON
1018  // format and with the pointer to the configuration storage where the
1019  // parsed configuration is stored.
1020  if (HooksManager::calloutsPresent(Hooks.hooks_index_dhcp6_srv_configured_)) {
1021  CalloutHandlePtr callout_handle = HooksManager::createCalloutHandle();
1022 
1023  callout_handle->setArgument("io_context", srv->getIOService());
1024  callout_handle->setArgument("network_state", srv->getNetworkState());
1025  callout_handle->setArgument("json_config", config);
1026  callout_handle->setArgument("server_config", CfgMgr::instance().getStagingCfg());
1027 
1028  HooksManager::callCallouts(Hooks.hooks_index_dhcp6_srv_configured_,
1029  *callout_handle);
1030 
1031  // Ignore status code as none of them would have an effect on further
1032  // operation.
1033  }
1034 
1035  // Apply multi threading settings.
1036  // @note These settings are applied/updated only if no errors occur while
1037  // applying the new configuration.
1038  // @todo This should be fixed.
1039  try {
1040  CfgMultiThreading::apply(CfgMgr::instance().getStagingCfg()->getDHCPMultiThreading());
1041  } catch (const std::exception& ex) {
1042  err << "Error applying multi threading settings: "
1043  << ex.what();
1044  return (isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str()));
1045  }
1046 
1047  return (answer);
1048 }
1049 
1051 ControlledDhcpv6Srv::checkConfig(isc::data::ConstElementPtr config) {
1052 
1054  .arg(redactConfig(config)->str());
1055 
1056  ControlledDhcpv6Srv* srv = ControlledDhcpv6Srv::getInstance();
1057 
1058  if (!srv) {
1060  "Server object not initialized, can't process config.");
1061  return (no_srv);
1062  }
1063 
1064  return (configureDhcp6Server(*srv, config, true));
1065 }
1066 
1067 ControlledDhcpv6Srv::ControlledDhcpv6Srv(uint16_t server_port,
1068  uint16_t client_port)
1069  : Dhcpv6Srv(server_port, client_port), timer_mgr_(TimerMgr::instance()) {
1070  if (getInstance()) {
1072  "There is another Dhcpv6Srv instance already.");
1073  }
1074  server_ = this; // remember this instance for later use in handlers
1075 
1076  // TimerMgr uses IO service to run asynchronous timers.
1077  TimerMgr::instance()->setIOService(getIOService());
1078 
1079  // CommandMgr uses IO service to run asynchronous socket operations.
1080  CommandMgr::instance().setIOService(getIOService());
1081 
1082  // LeaseMgr uses IO service to run asynchronous timers.
1084 
1085  // HostMgr uses IO service to run asynchronous timers.
1087 
1088  // These are the commands always supported by the DHCPv6 server.
1089  // Please keep the list in alphabetic order.
1090  CommandMgr::instance().registerCommand("build-report",
1091  std::bind(&ControlledDhcpv6Srv::commandBuildReportHandler, this, ph::_1, ph::_2));
1092 
1093  CommandMgr::instance().registerCommand("config-backend-pull",
1094  std::bind(&ControlledDhcpv6Srv::commandConfigBackendPullHandler, this, ph::_1, ph::_2));
1095 
1096  CommandMgr::instance().registerCommand("config-get",
1097  std::bind(&ControlledDhcpv6Srv::commandConfigGetHandler, this, ph::_1, ph::_2));
1098 
1099  CommandMgr::instance().registerCommand("config-reload",
1100  std::bind(&ControlledDhcpv6Srv::commandConfigReloadHandler, this, ph::_1, ph::_2));
1101 
1102  CommandMgr::instance().registerCommand("config-test",
1103  std::bind(&ControlledDhcpv6Srv::commandConfigTestHandler, this, ph::_1, ph::_2));
1104 
1105  CommandMgr::instance().registerCommand("config-write",
1106  std::bind(&ControlledDhcpv6Srv::commandConfigWriteHandler, this, ph::_1, ph::_2));
1107 
1108  CommandMgr::instance().registerCommand("dhcp-disable",
1109  std::bind(&ControlledDhcpv6Srv::commandDhcpDisableHandler, this, ph::_1, ph::_2));
1110 
1111  CommandMgr::instance().registerCommand("dhcp-enable",
1112  std::bind(&ControlledDhcpv6Srv::commandDhcpEnableHandler, this, ph::_1, ph::_2));
1113 
1114  CommandMgr::instance().registerCommand("leases-reclaim",
1115  std::bind(&ControlledDhcpv6Srv::commandLeasesReclaimHandler, this, ph::_1, ph::_2));
1116 
1117  CommandMgr::instance().registerCommand("server-tag-get",
1118  std::bind(&ControlledDhcpv6Srv::commandServerTagGetHandler, this, ph::_1, ph::_2));
1119 
1120  CommandMgr::instance().registerCommand("libreload",
1121  std::bind(&ControlledDhcpv6Srv::commandLibReloadHandler, this, ph::_1, ph::_2));
1122 
1123  CommandMgr::instance().registerCommand("config-set",
1124  std::bind(&ControlledDhcpv6Srv::commandConfigSetHandler, this, ph::_1, ph::_2));
1125 
1126  CommandMgr::instance().registerCommand("shutdown",
1127  std::bind(&ControlledDhcpv6Srv::commandShutdownHandler, this, ph::_1, ph::_2));
1128 
1129  CommandMgr::instance().registerCommand("status-get",
1130  std::bind(&ControlledDhcpv6Srv::commandStatusGetHandler, this, ph::_1, ph::_2));
1131 
1132  CommandMgr::instance().registerCommand("version-get",
1133  std::bind(&ControlledDhcpv6Srv::commandVersionGetHandler, this, ph::_1, ph::_2));
1134 
1135  // Register statistic related commands
1136  CommandMgr::instance().registerCommand("statistic-get",
1137  std::bind(&StatsMgr::statisticGetHandler, ph::_1, ph::_2));
1138 
1139  CommandMgr::instance().registerCommand("statistic-get-all",
1140  std::bind(&StatsMgr::statisticGetAllHandler, ph::_1, ph::_2));
1141 
1142  CommandMgr::instance().registerCommand("statistic-reset",
1143  std::bind(&StatsMgr::statisticResetHandler, ph::_1, ph::_2));
1144 
1145  CommandMgr::instance().registerCommand("statistic-reset-all",
1146  std::bind(&StatsMgr::statisticResetAllHandler, ph::_1, ph::_2));
1147 
1148  CommandMgr::instance().registerCommand("statistic-remove",
1149  std::bind(&StatsMgr::statisticRemoveHandler, ph::_1, ph::_2));
1150 
1151  CommandMgr::instance().registerCommand("statistic-remove-all",
1152  std::bind(&StatsMgr::statisticRemoveAllHandler, ph::_1, ph::_2));
1153 
1154  CommandMgr::instance().registerCommand("statistic-sample-age-set",
1155  std::bind(&StatsMgr::statisticSetMaxSampleAgeHandler, ph::_1, ph::_2));
1156 
1157  CommandMgr::instance().registerCommand("statistic-sample-age-set-all",
1158  std::bind(&ControlledDhcpv6Srv::commandStatisticSetMaxSampleAgeAllHandler, this, ph::_1, ph::_2));
1159 
1160  CommandMgr::instance().registerCommand("statistic-sample-count-set",
1161  std::bind(&StatsMgr::statisticSetMaxSampleCountHandler, ph::_1, ph::_2));
1162 
1163  CommandMgr::instance().registerCommand("statistic-sample-count-set-all",
1164  std::bind(&ControlledDhcpv6Srv::commandStatisticSetMaxSampleCountAllHandler, this, ph::_1, ph::_2));
1165 }
1166 
1168  setExitValue(exit_value);
1169  getIOService()->stop(); // Stop ASIO transmissions
1170  shutdown(); // Initiate DHCPv6 shutdown procedure.
1171 }
1172 
1174  try {
1176  HostMgr::create();
1177  cleanup();
1178 
1179  // The closure captures either a shared pointer (memory leak)
1180  // or a raw pointer (pointing to a deleted object).
1184 
1185  timer_mgr_->unregisterTimers();
1186 
1187  // Close the command socket (if it exists).
1188  CommandMgr::instance().closeCommandSocket();
1189 
1190  // Deregister any registered commands (please keep in alphabetic order)
1191  CommandMgr::instance().deregisterCommand("build-report");
1192  CommandMgr::instance().deregisterCommand("config-backend-pull");
1193  CommandMgr::instance().deregisterCommand("config-get");
1194  CommandMgr::instance().deregisterCommand("config-reload");
1195  CommandMgr::instance().deregisterCommand("config-set");
1196  CommandMgr::instance().deregisterCommand("config-test");
1197  CommandMgr::instance().deregisterCommand("config-write");
1198  CommandMgr::instance().deregisterCommand("dhcp-disable");
1199  CommandMgr::instance().deregisterCommand("dhcp-enable");
1200  CommandMgr::instance().deregisterCommand("leases-reclaim");
1201  CommandMgr::instance().deregisterCommand("libreload");
1202  CommandMgr::instance().deregisterCommand("server-tag-get");
1203  CommandMgr::instance().deregisterCommand("shutdown");
1204  CommandMgr::instance().deregisterCommand("statistic-get");
1205  CommandMgr::instance().deregisterCommand("statistic-get-all");
1206  CommandMgr::instance().deregisterCommand("statistic-remove");
1207  CommandMgr::instance().deregisterCommand("statistic-remove-all");
1208  CommandMgr::instance().deregisterCommand("statistic-reset");
1209  CommandMgr::instance().deregisterCommand("statistic-reset-all");
1210  CommandMgr::instance().deregisterCommand("statistic-sample-age-set");
1211  CommandMgr::instance().deregisterCommand("statistic-sample-age-set-all");
1212  CommandMgr::instance().deregisterCommand("statistic-sample-count-set");
1213  CommandMgr::instance().deregisterCommand("statistic-sample-count-set-all");
1214  CommandMgr::instance().deregisterCommand("status-get");
1215  CommandMgr::instance().deregisterCommand("version-get");
1216 
1217  // LeaseMgr uses IO service to run asynchronous timers.
1219 
1220  // HostMgr uses IO service to run asynchronous timers.
1222  } catch (...) {
1223  // Don't want to throw exceptions from the destructor. The server
1224  // is shutting down anyway.
1225  ;
1226  }
1227 
1228  server_ = NULL; // forget this instance. There should be no callback anymore
1229  // at this stage anyway.
1230 }
1231 
1232 void
1233 ControlledDhcpv6Srv::reclaimExpiredLeases(const size_t max_leases,
1234  const uint16_t timeout,
1235  const bool remove_lease,
1236  const uint16_t max_unwarned_cycles) {
1237  try {
1238  server_->alloc_engine_->reclaimExpiredLeases6(max_leases, timeout,
1239  remove_lease,
1240  max_unwarned_cycles);
1241  } catch (const std::exception& ex) {
1243  .arg(ex.what());
1244  }
1245  // We're using the ONE_SHOT timer so there is a need to re-schedule it.
1247 }
1248 
1249 void
1250 ControlledDhcpv6Srv::deleteExpiredReclaimedLeases(const uint32_t secs) {
1251  server_->alloc_engine_->deleteExpiredReclaimedLeases6(secs);
1252  // We're using the ONE_SHOT timer so there is a need to re-schedule it.
1254 }
1255 
1256 bool
1257 ControlledDhcpv6Srv::dbLostCallback(ReconnectCtlPtr db_reconnect_ctl) {
1258  if (!db_reconnect_ctl) {
1259  // This should never happen
1261  return (false);
1262  }
1263 
1264  // Disable service until the connection is recovered.
1265  if (db_reconnect_ctl->retriesLeft() == db_reconnect_ctl->maxRetries() &&
1266  db_reconnect_ctl->alterServiceState()) {
1268  }
1269 
1271 
1272  // If reconnect isn't enabled log it, initiate a shutdown if needed and
1273  // return false.
1274  if (!db_reconnect_ctl->retriesLeft() ||
1275  !db_reconnect_ctl->retryInterval()) {
1277  .arg(db_reconnect_ctl->retriesLeft())
1278  .arg(db_reconnect_ctl->retryInterval());
1279  if (db_reconnect_ctl->exitOnFailure()) {
1280  shutdownServer(EXIT_FAILURE);
1281  }
1282  return (false);
1283  }
1284 
1285  return (true);
1286 }
1287 
1288 bool
1289 ControlledDhcpv6Srv::dbRecoveredCallback(ReconnectCtlPtr db_reconnect_ctl) {
1290  if (!db_reconnect_ctl) {
1291  // This should never happen
1293  return (false);
1294  }
1295 
1296  // Enable service after the connection is recovered.
1297  if (db_reconnect_ctl->alterServiceState()) {
1299  }
1300 
1302 
1303  db_reconnect_ctl->resetRetries();
1304 
1305  return (true);
1306 }
1307 
1308 bool
1309 ControlledDhcpv6Srv::dbFailedCallback(ReconnectCtlPtr db_reconnect_ctl) {
1310  if (!db_reconnect_ctl) {
1311  // This should never happen
1313  return (false);
1314  }
1315 
1317  .arg(db_reconnect_ctl->maxRetries());
1318 
1319  if (db_reconnect_ctl->exitOnFailure()) {
1320  shutdownServer(EXIT_FAILURE);
1321  }
1322 
1323  return (true);
1324 }
1325 
1326 void
1327 ControlledDhcpv6Srv::cbFetchUpdates(const SrvConfigPtr& srv_cfg,
1328  boost::shared_ptr<unsigned> failure_count) {
1329  // stop thread pool (if running)
1331 
1332  try {
1333  // Fetch any configuration backend updates since our last fetch.
1334  server_->getCBControl()->databaseConfigFetch(srv_cfg,
1335  CBControlDHCPv6::FetchMode::FETCH_UPDATE);
1336  (*failure_count) = 0;
1337 
1338  } catch (const std::exception& ex) {
1340  .arg(ex.what());
1341 
1342  // We allow at most 10 consecutive failures after which we stop
1343  // making further attempts to fetch the configuration updates.
1344  // Let's return without re-scheduling the timer.
1345  if (++(*failure_count) > 10) {
1348  return;
1349  }
1350  }
1351 
1352  // Reschedule the timer to fetch new updates or re-try if
1353  // the previous attempt resulted in an error.
1354  if (TimerMgr::instance()->isTimerRegistered("Dhcp6CBFetchTimer")) {
1355  TimerMgr::instance()->setup("Dhcp6CBFetchTimer");
1356  }
1357 }
1358 
1359 } // namespace dhcp
1360 } // namespace isc
RAII class creating a critical section.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
Definition: macros.h:26
boost::shared_ptr< DUID > DuidPtr
Definition: duid.h:20
virtual void shutdownServer(int exit_value)
Initiates shutdown procedure for the whole DHCPv6 server.
static ControlledDhcpv6Srv * getInstance()
Returns pointer to the sole instance of Dhcpv6Srv.
virtual ~ControlledDhcpv6Srv()
Destructor.
static DbCallback db_lost_callback_
Optional callback function to invoke if an opened connection is lost.
const isc::log::MessageID DHCP6_USING_SERVERID
isc::data::ConstElementPtr configureDhcp6Server(Dhcpv6Srv &server, isc::data::ConstElementPtr config_set, bool check_only)
Configures DHCPv6 server.
const isc::log::MessageID DHCP6_CONFIG_LOAD_FAIL
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
Definition: macros.h:20
ConstElementPtr createAnswer(const int status_code, const std::string &text, const ConstElementPtr &arg)
const int CONTROL_RESULT_SUCCESS
Status code indicating a successful operation.
isc::data::ElementPtr parseFile(const std::string &filename, ParserType parser_type)
Run the parser on the file specified.
const isc::log::MessageID DHCP6_CB_PERIODIC_FETCH_UPDATES_RETRIES_EXHAUSTED
void shutdown() override
Instructs the server to shut down.
Definition: dhcp6_srv.cc:300
static void setIOService(const isc::asiolink::IOServicePtr &io_service)
Sets IO service to be used by the Host Manager.
Definition: host_mgr.h:638
isc::data::ConstElementPtr statisticSetMaxSampleCountAllHandler(const isc::data::ConstElementPtr &params)
Handles statistic-sample-count-set-all command.
static void destroy()
Destroy lease manager.
const isc::log::MessageID DHCP6_RECLAIM_EXPIRED_LEASES_FAIL
const isc::log::MessageID DHCP6_CONFIG_PACKET_QUEUE
Manages a pool of asynchronous interval timers.
Definition: timer_mgr.h:62
boost::shared_ptr< SrvConfig > SrvConfigPtr
Non-const pointer to the SrvConfig.
Definition: srv_config.h:1036
The network state is being altered by the DB connection recovery mechanics.
ConstElementPtr redactConfig(ConstElementPtr const &element, list< string > const &json_path)
Redact a configuration.
uint16_t getServerPort() const
Get UDP port on which server should listen.
Definition: dhcp6_srv.h:216
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
Definition: macros.h:32
const int CONTROL_RESULT_ERROR
Status code indicating a general failure.
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
STL namespace.
Evaluation context, an interface to the expression evaluation.
const isc::log::MessageID DHCP6_DYNAMIC_RECONFIGURATION
const isc::log::MessageID DHCP6_CB_ON_DEMAND_FETCH_UPDATES_FAIL
const isc::log::MessageID DHCP6_DB_RECONNECT_NO_DB_CTL
const isc::log::MessageID DHCP6_COMMAND_RECEIVED
static DbCallback db_failed_callback_
Optional callback function to invoke if an opened connection recovery failed.
Statistics Manager class.
std::vector< HookLibInfo > HookLibsCollection
A storage for information about hook libraries.
Definition: libinfo.h:31
const isc::log::MessageID DHCP6_DB_RECONNECT_DISABLED
const int CONTROL_RESULT_EMPTY
Status code indicating that the specified command was completed correctly, but failed to produce any ...
NetworkStatePtr & getNetworkState()
Returns pointer to the network state used by the server.
Definition: dhcp6_srv.h:115
Origin
Origin of the network state transition.
Definition: network_state.h:84
const isc::log::MessageID DHCP6_DYNAMIC_RECONFIGURATION_FAIL
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
static const std::string FLUSH_RECLAIMED_TIMER_NAME
Name of the timer for flushing reclaimed leases.
const isc::log::MessageID DHCP6_CONFIG_UNSUPPORTED_OBJECT
const isc::log::MessageID DHCP6_CB_PERIODIC_FETCH_UPDATES_FAIL
Definition: edns.h:19
boost::shared_ptr< CfgDbAccess > CfgDbAccessPtr
A pointer to the CfgDbAccess.
const int DBG_DHCP6_COMMAND
Debug level used to log receiving commands.
Definition: dhcp6_log.h:27
static void create()
Creates new instance of the HostMgr.
Definition: host_mgr.cc:43
static DbCallback db_recovered_callback_
Optional callback function to invoke if an opened connection recovery succeeded.
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:23
Defines the Dhcp6to4Ipc class.
NetworkStatePtr network_state_
Holds information about disabled DHCP service and/or disabled subnet/network scopes.
Definition: dhcp6_srv.h:1171
const isc::log::MessageID DHCP6_DB_RECONNECT_LOST_CONNECTION
isc::data::ConstElementPtr redactConfig(isc::data::ConstElementPtr const &config)
Redact a configuration.
Definition: daemon.cc:257
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
This is a base class for exceptions thrown from the DNS library module.
ConstElementPtr parseAnswer(int &rcode, const ConstElementPtr &msg)
Defines the logger used by the top-level component of kea-dhcp-ddns.
CBControlDHCPv6Ptr getCBControl() const
Returns an object which controls access to the configuration backends.
Definition: dhcp6_srv.h:124
const isc::log::MessageID DHCP6_DB_RECONNECT_SUCCEEDED
void setExitValue(int value)
Sets the exit value.
Definition: daemon.h:227
void startD2()
Starts DHCP_DDNS client IO if DDNS updates are enabled.
Definition: dhcp6_srv.cc:4050
boost::shared_ptr< CalloutHandle > CalloutHandlePtr
A shared pointer to a CalloutHandle object.
static const std::string RECLAIM_EXPIRED_TIMER_NAME
Name of the timer for reclaiming expired leases.
This file contains several functions and constants that are used for handling commands and responses ...
asiolink::IOServicePtr & getIOService()
Returns pointer to the IO service used by the server.
Definition: dhcp6_srv.h:110
CtrlAgentHooks Hooks
const isc::log::MessageID DHCP6_CONFIG_UNRECOVERABLE_ERROR
A generic exception that is thrown if a function is called in a prohibited way.
const isc::log::MessageID DHCP6_MULTI_THREADING_INFO
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
Definition: macros.h:14
void cleanup()
Performs cleanup, immediately before termination.
const isc::log::MessageID DHCP6_CONFIG_RECEIVED
isc::data::ConstElementPtr statisticSetMaxSampleAgeAllHandler(const isc::data::ConstElementPtr &params)
Handles statistic-sample-age-set-all command.
boost::shared_ptr< AllocEngine > alloc_engine_
Allocation Engine.
Definition: dhcp6_srv.h:1163
std::string getConfigReport()
Definition: cfgrpt.cc:20
const StatsDuration & getMaxSampleAgeDefault() const
Get default duration limit.
static void setIOService(const isc::asiolink::IOServicePtr &io_service)
Sets IO service to be used by the Lease Manager.
Definition: lease_mgr.h:753
uint32_t getMaxSampleCountDefault() const
Get default count limit.
const isc::log::MessageID DHCP6_DB_RECONNECT_FAILED
#define LOG_FATAL(LOGGER, MESSAGE)
Macro to conveniently test fatal output and log it.
Definition: macros.h:38
Controlled version of the DHCPv6 server.
static const TimerMgrPtr & instance()
Returns pointer to the sole instance of the TimerMgr.
Definition: timer_mgr.cc:441
boost::shared_ptr< ReconnectCtl > ReconnectCtlPtr
Pointer to an instance of ReconnectCtl.
DHCPv6 server service.
Definition: dhcp6_srv.h:66
const isc::log::MessageID DHCP6_NOT_RUNNING
isc::log::Logger dhcp6_logger(DHCP6_APP_LOGGER_NAME)
Base logger for DHCPv6 server.
Definition: dhcp6_log.h:87
long toSeconds(const StatsDuration &dur)
Returns the number of seconds in a duration.
Definition: observation.h:45
const isc::log::MessageID DHCP6_HOOKS_LIBS_RELOAD_FAIL