duid_config_parser.cc 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright (C) 2015,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 <config.h>
  7. #include <cc/data.h>
  8. #include <dhcp/duid.h>
  9. #include <dhcpsrv/cfg_duid.h>
  10. #include <dhcpsrv/cfgmgr.h>
  11. #include <dhcpsrv/dhcpsrv_log.h>
  12. #include <dhcpsrv/parsers/duid_config_parser.h>
  13. #include <dhcpsrv/parsers/dhcp_parsers.h>
  14. #include <exceptions/exceptions.h>
  15. #include <boost/foreach.hpp>
  16. #include <boost/lexical_cast.hpp>
  17. #include <limits>
  18. #include <string>
  19. using namespace isc::data;
  20. namespace isc {
  21. namespace dhcp {
  22. void
  23. DUIDConfigParser::parse(const CfgDUIDPtr& cfg,
  24. isc::data::ConstElementPtr duid_configuration) {
  25. std::string param;
  26. try {
  27. param = "type";
  28. std::string duid_type = getString(duid_configuration, "type");
  29. // Map DUID type represented as text into numeric value.
  30. DUID::DUIDType numeric_type = DUID::DUID_UNKNOWN;
  31. if (duid_type == "LLT") {
  32. numeric_type = DUID::DUID_LLT;
  33. } else if (duid_type == "EN") {
  34. numeric_type = DUID::DUID_EN;
  35. } else if (duid_type == "LL") {
  36. numeric_type = DUID::DUID_LL;
  37. } else {
  38. isc_throw(BadValue, "unsupported DUID type '"
  39. << duid_type << "'. Expected: LLT, EN or LL");
  40. }
  41. cfg->setType(static_cast<DUID::DUIDType>(numeric_type));
  42. param = "identifier";
  43. if (duid_configuration->contains(param)) {
  44. cfg->setIdentifier(getString(duid_configuration, param));
  45. }
  46. param = "htype";
  47. if (duid_configuration->contains(param)) {
  48. cfg->setHType(getUint16(duid_configuration, param));
  49. }
  50. param = "time";
  51. if (duid_configuration->contains(param)) {
  52. cfg->setTime(getUint32(duid_configuration, param));
  53. }
  54. param = "enterprise-id";
  55. if (duid_configuration->contains(param)) {
  56. cfg->setEnterpriseId(getUint32(duid_configuration, param));
  57. }
  58. param = "persist";
  59. if (duid_configuration->contains(param)) {
  60. cfg->setPersist(getBoolean(duid_configuration, param));
  61. }
  62. } catch (const DhcpConfigError&) {
  63. throw;
  64. } catch (const std::exception& ex) {
  65. // Append position.
  66. isc_throw(DhcpConfigError, ex.what() << " ("
  67. << getPosition(param, duid_configuration) << ")");
  68. }
  69. LOG_WARN(dhcpsrv_logger, DHCPSRV_CFGMGR_CONFIGURE_SERVERID);
  70. }
  71. } // end of namespace isc::dhcp
  72. } // end of namespace isc