cfg_host_operations.cc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright (C) 2016-2017 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. #include <exceptions/exceptions.h>
  7. #include <dhcpsrv/cfg_host_operations.h>
  8. #include <algorithm>
  9. #include <string>
  10. using namespace isc::data;
  11. namespace isc {
  12. namespace dhcp {
  13. CfgHostOperations::CfgHostOperations()
  14. : identifier_types_() {
  15. }
  16. CfgHostOperationsPtr
  17. CfgHostOperations::createConfig4() {
  18. // If this list is modified, please update reservations4-tuning section in
  19. // doc/guide/dhcp4-srv.xml
  20. CfgHostOperationsPtr cfg(new CfgHostOperations());
  21. cfg->addIdentifierType("hw-address");
  22. cfg->addIdentifierType("duid");
  23. cfg->addIdentifierType("circuit-id");
  24. return (cfg);
  25. }
  26. CfgHostOperationsPtr
  27. CfgHostOperations::createConfig6() {
  28. // If this list is modified, please update reservations6-tuning section in
  29. // doc/guide/dhcp6-srv.xml
  30. CfgHostOperationsPtr cfg(new CfgHostOperations());
  31. cfg->addIdentifierType("hw-address");
  32. cfg->addIdentifierType("duid");
  33. return (cfg);
  34. }
  35. void
  36. CfgHostOperations::addIdentifierType(const std::string& identifier_name) {
  37. Host::IdentifierType identifier_type = Host::getIdentifierType(identifier_name);
  38. if (std::find(identifier_types_.begin(), identifier_types_.end(),
  39. identifier_type) != identifier_types_.end()) {
  40. isc_throw(isc::BadValue, "duplicate host identifier '"
  41. << identifier_name << "'");
  42. }
  43. identifier_types_.push_back(identifier_type);
  44. }
  45. void
  46. CfgHostOperations::clearIdentifierTypes() {
  47. identifier_types_.clear();
  48. }
  49. ElementPtr
  50. CfgHostOperations::toElement() const {
  51. ElementPtr result = Element::createList();
  52. for (IdentifierTypes::const_iterator id = identifier_types_.begin();
  53. id != identifier_types_.end(); ++id) {
  54. const std::string& name = Host::getIdentifierName(*id);
  55. result->add(Element::create(name));
  56. }
  57. return (result);
  58. }
  59. }
  60. }