mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-02 06:55:16 +00:00
[5014_phase2] SimpleParser implemented, 4 parsers converted
- SimpleParser concept implemented - Converted 4 parsers (option data, option data list, option defintion, option definition list) - updated unit-tests - converted other parsers (HostReservationParser{4,6}, ClientClassDefParser) to use those new parsers - converted kea-dhcp{4,6} to use those new parsers Conflicts: src/bin/dhcp6/json_config_parser.cc src/lib/dhcpsrv/parsers/dhcp_parsers.cc
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include <dhcpsrv/parsers/host_reservation_parser.h>
|
||||
#include <dhcpsrv/parsers/host_reservations_list_parser.h>
|
||||
#include <dhcpsrv/parsers/ifaces_config_parser.h>
|
||||
#include <dhcpsrv/parsers/simple_parser.h>
|
||||
#include <dhcpsrv/timer_mgr.h>
|
||||
#include <config/command_mgr.h>
|
||||
#include <util/encode/hex.h>
|
||||
@@ -190,8 +191,7 @@ protected:
|
||||
parser = new Pools4ListParser(config_id, pools_);
|
||||
} else if (config_id.compare("relay") == 0) {
|
||||
parser = new RelayInfoParser(config_id, relay_info_, Option::V4);
|
||||
} else if (config_id.compare("option-data") == 0) {
|
||||
parser = new OptionDataListParser(config_id, options_, AF_INET);
|
||||
// option-data has been converted to SimpleParser already.
|
||||
} else if (config_id.compare("match-client-id") == 0) {
|
||||
parser = new BooleanParser(config_id, boolean_values_);
|
||||
} else if (config_id.compare("4o6-subnet") == 0) {
|
||||
@@ -424,10 +424,7 @@ DhcpConfigParser* createGlobalDhcp4ConfigParser(const std::string& config_id,
|
||||
parser = new IfacesConfigParser4();
|
||||
} else if (config_id.compare("subnet4") == 0) {
|
||||
parser = new Subnets4ListConfigParser(config_id);
|
||||
} else if (config_id.compare("option-data") == 0) {
|
||||
parser = new OptionDataListParser(config_id, CfgOptionPtr(), AF_INET);
|
||||
} else if (config_id.compare("option-def") == 0) {
|
||||
parser = new OptionDefListParser(config_id, globalContext());
|
||||
// option-data and option-def have been converted to SimpleParser already.
|
||||
} else if ((config_id.compare("version") == 0) ||
|
||||
(config_id.compare("next-server") == 0)) {
|
||||
parser = new StringParser(config_id,
|
||||
@@ -538,7 +535,6 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
|
||||
// Please do not change this order!
|
||||
ParserCollection independent_parsers;
|
||||
ParserPtr subnet_parser;
|
||||
ParserPtr option_parser;
|
||||
ParserPtr iface_parser;
|
||||
ParserPtr leases_parser;
|
||||
ParserPtr client_classes_parser;
|
||||
@@ -567,10 +563,43 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
|
||||
// the name of the failing parser can be retrieved in the "catch" clause.
|
||||
ConfigPair config_pair;
|
||||
try {
|
||||
|
||||
// This is a way to convert ConstElementPtr to ElementPtr.
|
||||
// We need a config that can be edited, because we will insert
|
||||
// default values and will insert derived values as well.
|
||||
std::map<std::string, ConstElementPtr> values;
|
||||
config_set->getValue(values);
|
||||
ElementPtr mutable_cfg(new MapElement());
|
||||
mutable_cfg->setValue(values);
|
||||
|
||||
// Set all default values if not specified by the user.
|
||||
SimpleParser::setAllDefaults(mutable_cfg, false);
|
||||
|
||||
// We need definitions first
|
||||
ConstElementPtr option_defs = mutable_cfg->get("option-def");
|
||||
if (option_defs) {
|
||||
OptionDefListParser parser(AF_INET);
|
||||
CfgOptionDefPtr cfg_option_def = CfgMgr::instance().getStagingCfg()->getCfgOptionDef();
|
||||
parser.parse(cfg_option_def, option_defs);
|
||||
}
|
||||
|
||||
// Make parsers grouping.
|
||||
const std::map<std::string, ConstElementPtr>& values_map =
|
||||
config_set->mapValue();
|
||||
mutable_cfg->mapValue();
|
||||
BOOST_FOREACH(config_pair, values_map) {
|
||||
|
||||
if (config_pair.first == "option-def") {
|
||||
// This is converted to SimpleParser and is handled already above.
|
||||
continue;
|
||||
}
|
||||
|
||||
if (config_pair.first == "option-data") {
|
||||
OptionDataListParser parser(AF_INET);
|
||||
CfgOptionPtr cfg_option = CfgMgr::instance().getStagingCfg()->getCfgOption();
|
||||
parser.parse(cfg_option, config_pair.second);
|
||||
continue;
|
||||
}
|
||||
|
||||
ParserPtr parser(createGlobalDhcp4ConfigParser(config_pair.first,
|
||||
config_pair.second));
|
||||
LOG_DEBUG(dhcp4_logger, DBG_DHCP4_DETAIL, DHCP4_PARSER_CREATED)
|
||||
@@ -579,8 +608,6 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
|
||||
subnet_parser = parser;
|
||||
} else if (config_pair.first == "lease-database") {
|
||||
leases_parser = parser;
|
||||
} else if (config_pair.first == "option-data") {
|
||||
option_parser = parser;
|
||||
} else if (config_pair.first == "interfaces-config") {
|
||||
// The interface parser is independent from any other
|
||||
// parser and can be run here before any other parsers.
|
||||
@@ -606,15 +633,6 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
|
||||
}
|
||||
}
|
||||
|
||||
// The option values parser is the next one to be run.
|
||||
std::map<std::string, ConstElementPtr>::const_iterator option_config =
|
||||
values_map.find("option-data");
|
||||
if (option_config != values_map.end()) {
|
||||
config_pair.first = "option-data";
|
||||
option_parser->build(option_config->second);
|
||||
option_parser->commit();
|
||||
}
|
||||
|
||||
// The class definitions parser is the next one to be run.
|
||||
std::map<std::string, ConstElementPtr>::const_iterator cc_config =
|
||||
values_map.find("client-classes");
|
||||
|
Reference in New Issue
Block a user