From 68bfa90266263638f4d61f6aae68fb308a3336ee Mon Sep 17 00:00:00 2001 From: Marcin Siodelski Date: Tue, 17 Mar 2015 11:53:46 +0100 Subject: [PATCH 1/3] [3744] Parse lease db after subnets configuration This patch runs the database parser last (after subnets have been parsed). This allows, for example, to access the subnets staging configuration when leases are being loaded from disk. --- src/bin/dhcp4/json_config_parser.cc | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/bin/dhcp4/json_config_parser.cc b/src/bin/dhcp4/json_config_parser.cc index a3a28c0b1b..30b070a632 100644 --- a/src/bin/dhcp4/json_config_parser.cc +++ b/src/bin/dhcp4/json_config_parser.cc @@ -414,12 +414,13 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) { // depend on the global values. Also, option values configuration // must be performed after the option definitions configurations. // Thus we group parsers and will fire them in the right order: - // all parsers other than subnet4 and option-data parser, - // option-data parser, subnet4 parser. + // all parsers other than: lease-database, subnet4 and option-data parser, + // then: option-data parser, subnet4 parser, lease-database parser. ParserCollection independent_parsers; ParserPtr subnet_parser; ParserPtr option_parser; ParserPtr iface_parser; + ParserPtr leases_parser; // Some of the parsers alter the state of the system in a way that can't // easily be undone. (Or alter it in a way such that undoing the change has @@ -455,6 +456,8 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) { .arg(config_pair.first); if (config_pair.first == "subnet4") { 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") { @@ -489,7 +492,7 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) { option_parser->commit(); } - // The subnet parser is the last one to be run. + // The subnet parser is the next one to be run. std::map::const_iterator subnet_config = values_map.find("subnet4"); if (subnet_config != values_map.end()) { @@ -497,6 +500,15 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) { subnet_parser->build(subnet_config->second); } + // the leases database parser is the last to be run. + std::map::const_iterator leases_config = + values_map.find("lease-database"); + if (leases_config != values_map.end()) { + config_pair.first = "lease-database"; + leases_parser->build(leases_config->second); + leases_parser->commit(); + } + } catch (const isc::Exception& ex) { LOG_ERROR(dhcp4_logger, DHCP4_PARSER_FAIL) .arg(config_pair.first).arg(ex.what()); From b35be4576fcd079093ccb64337411f0b95950fe3 Mon Sep 17 00:00:00 2001 From: Marcin Siodelski Date: Tue, 17 Mar 2015 12:19:59 +0100 Subject: [PATCH 2/3] [3744] Lease database parser executed as the last one for DHCPv6 server. --- src/bin/dhcp6/json_config_parser.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/bin/dhcp6/json_config_parser.cc b/src/bin/dhcp6/json_config_parser.cc index b170b534b1..315de5d08c 100644 --- a/src/bin/dhcp6/json_config_parser.cc +++ b/src/bin/dhcp6/json_config_parser.cc @@ -632,6 +632,7 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) { ParserPtr subnet_parser; ParserPtr option_parser; ParserPtr iface_parser; + ParserPtr leases_parser; // Some of the parsers alter state of the system that can't easily // be undone. (Or alter it in a way such that undoing the change @@ -668,6 +669,8 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) { .arg(config_pair.first); if (config_pair.first == "subnet6") { 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 == "hooks-libraries") { @@ -703,7 +706,7 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) { option_parser->commit(); } - // The subnet parser is the last one to be run. + // The subnet parser is the next one to be run. std::map::const_iterator subnet_config = values_map.find("subnet6"); if (subnet_config != values_map.end()) { @@ -711,6 +714,15 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) { subnet_parser->build(subnet_config->second); } + // The lease database parser is the last to be run. + std::map::const_iterator leases_config = + values_map.find("lease-database"); + if (leases_config != values_map.end()) { + config_pair.first = "lease-database"; + leases_parser->build(leases_config->second); + leases_parser->commit(); + } + } catch (const isc::Exception& ex) { LOG_ERROR(dhcp6_logger, DHCP6_PARSER_FAIL) .arg(config_pair.first).arg(ex.what()); From 81b5979918d5c000f01cef311ad5ca5b501b0e48 Mon Sep 17 00:00:00 2001 From: Marcin Siodelski Date: Tue, 17 Mar 2015 12:34:28 +0100 Subject: [PATCH 3/3] [3744] Minor comments update in the JSON parsers. --- src/bin/dhcp4/json_config_parser.cc | 1 + src/bin/dhcp6/json_config_parser.cc | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/bin/dhcp4/json_config_parser.cc b/src/bin/dhcp4/json_config_parser.cc index 30b070a632..f127c16307 100644 --- a/src/bin/dhcp4/json_config_parser.cc +++ b/src/bin/dhcp4/json_config_parser.cc @@ -416,6 +416,7 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) { // Thus we group parsers and will fire them in the right order: // all parsers other than: lease-database, subnet4 and option-data parser, // then: option-data parser, subnet4 parser, lease-database parser. + // Please do not change this order! ParserCollection independent_parsers; ParserPtr subnet_parser; ParserPtr option_parser; diff --git a/src/bin/dhcp6/json_config_parser.cc b/src/bin/dhcp6/json_config_parser.cc index 315de5d08c..8e5a6ddaf2 100644 --- a/src/bin/dhcp6/json_config_parser.cc +++ b/src/bin/dhcp6/json_config_parser.cc @@ -626,8 +626,10 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) { // depend on the global values. Also, option values configuration // must be performed after the option definitions configurations. // Thus we group parsers and will fire them in the right order: - // all parsers other than subnet6 and option-data parser, - // option-data parser, subnet6 parser. + // all parsers other than lease-database, subnet6 and + // option-data parser, then option-data parser, subnet6 parser, + // lease-database parser. + // Please do not change this order! ParserCollection independent_parsers; ParserPtr subnet_parser; ParserPtr option_parser;