|
@@ -1,4 +1,4 @@
|
|
|
-// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
|
|
|
+// Copyright (C) 2015,2017 Internet Systems Consortium, Inc. ("ISC")
|
|
|
//
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
@@ -11,6 +11,7 @@
|
|
|
#include <dhcpsrv/cfgmgr.h>
|
|
|
#include <dhcpsrv/dhcpsrv_log.h>
|
|
|
#include <dhcpsrv/parsers/duid_config_parser.h>
|
|
|
+#include <dhcpsrv/parsers/dhcp_parsers.h>
|
|
|
#include <exceptions/exceptions.h>
|
|
|
#include <boost/foreach.hpp>
|
|
|
#include <boost/lexical_cast.hpp>
|
|
@@ -22,28 +23,28 @@ using namespace isc::data;
|
|
|
namespace isc {
|
|
|
namespace dhcp {
|
|
|
|
|
|
-DUIDConfigParser::DUIDConfigParser()
|
|
|
- : DhcpConfigParser() {
|
|
|
-}
|
|
|
-
|
|
|
void
|
|
|
-DUIDConfigParser::build(isc::data::ConstElementPtr duid_configuration) {
|
|
|
+DUIDConfigParser::parse(const CfgDUIDPtr& cfg, isc::data::ConstElementPtr duid_configuration) {
|
|
|
+ if (!cfg) {
|
|
|
+ isc_throw(DhcpConfigError, "Must provide valid pointer to cfg when parsing duid");
|
|
|
+ }
|
|
|
+
|
|
|
bool type_present = false;
|
|
|
BOOST_FOREACH(ConfigPair element, duid_configuration->mapValue()) {
|
|
|
try {
|
|
|
if (element.first == "type") {
|
|
|
type_present = true;
|
|
|
- setType(element.second->stringValue());
|
|
|
+ setType(cfg, element.second->stringValue());
|
|
|
} else if (element.first == "identifier") {
|
|
|
- setIdentifier(element.second->stringValue());
|
|
|
+ setIdentifier(cfg, element.second->stringValue());
|
|
|
} else if (element.first == "htype") {
|
|
|
- setHType(element.second->intValue());
|
|
|
+ setHType(cfg, element.second->intValue());
|
|
|
} else if (element.first == "time") {
|
|
|
- setTime(element.second->intValue());
|
|
|
+ setTime(cfg, element.second->intValue());
|
|
|
} else if (element.first == "enterprise-id") {
|
|
|
- setEnterpriseId(element.second->intValue());
|
|
|
+ setEnterpriseId(cfg, element.second->intValue());
|
|
|
} else if (element.first == "persist") {
|
|
|
- setPersist(element.second->boolValue());
|
|
|
+ setPersist(cfg, element.second->boolValue());
|
|
|
} else {
|
|
|
isc_throw(DhcpConfigError, "unsupported configuration "
|
|
|
"parameter '" << element.first << "'");
|
|
@@ -66,7 +67,7 @@ DUIDConfigParser::build(isc::data::ConstElementPtr duid_configuration) {
|
|
|
}
|
|
|
|
|
|
void
|
|
|
-DUIDConfigParser::setType(const std::string& duid_type) const {
|
|
|
+DUIDConfigParser::setType(const CfgDUIDPtr& cfg, const std::string& duid_type) const {
|
|
|
// Map DUID type represented as text into numeric value.
|
|
|
DUID::DUIDType numeric_type = DUID::DUID_UNKNOWN;
|
|
|
if (duid_type == "LLT") {
|
|
@@ -80,41 +81,34 @@ DUIDConfigParser::setType(const std::string& duid_type) const {
|
|
|
<< duid_type << "'. Expected: LLT, EN or LL");
|
|
|
}
|
|
|
|
|
|
- const CfgDUIDPtr& cfg = CfgMgr::instance().getStagingCfg()->getCfgDUID();
|
|
|
cfg->setType(static_cast<DUID::DUIDType>(numeric_type));
|
|
|
}
|
|
|
|
|
|
void
|
|
|
-DUIDConfigParser::setIdentifier(const std::string& identifier) const {
|
|
|
- const CfgDUIDPtr& cfg = CfgMgr::instance().getStagingCfg()->getCfgDUID();
|
|
|
+DUIDConfigParser::setIdentifier(const CfgDUIDPtr& cfg, const std::string& identifier) const {
|
|
|
cfg->setIdentifier(identifier);
|
|
|
}
|
|
|
|
|
|
void
|
|
|
-DUIDConfigParser::setHType(const int64_t htype) const {
|
|
|
- const CfgDUIDPtr& cfg = CfgMgr::instance().getStagingCfg()->getCfgDUID();
|
|
|
+DUIDConfigParser::setHType(const CfgDUIDPtr& cfg, const int64_t htype) const {
|
|
|
checkRange<uint16_t>("htype", htype);
|
|
|
cfg->setHType(static_cast<uint16_t>(htype));
|
|
|
-
|
|
|
}
|
|
|
|
|
|
void
|
|
|
-DUIDConfigParser::setTime(const int64_t new_time) const {
|
|
|
- const CfgDUIDPtr& cfg = CfgMgr::instance().getStagingCfg()->getCfgDUID();
|
|
|
+DUIDConfigParser::setTime(const CfgDUIDPtr& cfg, const int64_t new_time) const {
|
|
|
checkRange<uint32_t>("time", new_time);
|
|
|
cfg->setTime(static_cast<uint32_t>(new_time));
|
|
|
}
|
|
|
|
|
|
void
|
|
|
-DUIDConfigParser::setEnterpriseId(const int64_t enterprise_id) const {
|
|
|
- const CfgDUIDPtr& cfg = CfgMgr::instance().getStagingCfg()->getCfgDUID();
|
|
|
+DUIDConfigParser::setEnterpriseId(const CfgDUIDPtr& cfg, const int64_t enterprise_id) const {
|
|
|
checkRange<uint32_t>("enterprise-id", enterprise_id);
|
|
|
cfg->setEnterpriseId(static_cast<uint32_t>(enterprise_id));
|
|
|
}
|
|
|
|
|
|
void
|
|
|
-DUIDConfigParser::setPersist(const bool persist) {
|
|
|
- const CfgDUIDPtr& cfg = CfgMgr::instance().getStagingCfg()->getCfgDUID();
|
|
|
+DUIDConfigParser::setPersist(const CfgDUIDPtr& cfg, const bool persist) {
|
|
|
cfg->setPersist(persist);
|
|
|
}
|
|
|
|