From: Razvan Becheriu Date: Tue, 12 Jan 2021 17:22:59 +0000 (+0200) Subject: [1598] convert reservation-mode from CB to new flags X-Git-Tag: Kea-1.9.4~62 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d66b4b70a09ea3bd7a7d8bcb24243f86892baa87;p=thirdparty%2Fkea.git [1598] convert reservation-mode from CB to new flags --- diff --git a/src/lib/dhcpsrv/parsers/base_network_parser.cc b/src/lib/dhcpsrv/parsers/base_network_parser.cc index 55f3dc9ec6..b372445421 100644 --- a/src/lib/dhcpsrv/parsers/base_network_parser.cc +++ b/src/lib/dhcpsrv/parsers/base_network_parser.cc @@ -25,7 +25,7 @@ BaseNetworkParser::moveReservationMode(ElementPtr config) { config->contains("reservations-in-subnet") || config->contains("reservations-out-of-pool")) { isc_throw(DhcpConfigError, "invalid use of both 'reservation-mode'" - " one of 'reservations-global', 'reservations-in-subnet'" + " and one of 'reservations-global', 'reservations-in-subnet'" " or 'reservations-out-of-pool' parameters"); } std::string hr_mode = getString(config, "reservation-mode"); diff --git a/src/lib/dhcpsrv/parsers/simple_parser4.cc b/src/lib/dhcpsrv/parsers/simple_parser4.cc index 5095451f95..48d4a3efbd 100644 --- a/src/lib/dhcpsrv/parsers/simple_parser4.cc +++ b/src/lib/dhcpsrv/parsers/simple_parser4.cc @@ -70,6 +70,7 @@ const SimpleKeywords SimpleParser4::GLOBAL4_PARAMETERS = { { "reservations", Element::list }, { "config-control", Element::map }, { "server-tag", Element::string }, + { "reservation-mode", Element::string }, { "reservations-global", Element::boolean }, { "reservations-in-subnet", Element::boolean }, { "reservations-out-of-pool", Element::boolean }, diff --git a/src/lib/dhcpsrv/parsers/simple_parser6.cc b/src/lib/dhcpsrv/parsers/simple_parser6.cc index e9317d7187..7b71508292 100644 --- a/src/lib/dhcpsrv/parsers/simple_parser6.cc +++ b/src/lib/dhcpsrv/parsers/simple_parser6.cc @@ -71,6 +71,7 @@ const SimpleKeywords SimpleParser6::GLOBAL6_PARAMETERS = { { "reservations", Element::list }, { "config-control", Element::map }, { "server-tag", Element::string }, + { "reservation-mode", Element::string }, { "reservations-global", Element::boolean }, { "reservations-in-subnet", Element::boolean }, { "reservations-out-of-pool", Element::boolean }, diff --git a/src/lib/dhcpsrv/srv_config.cc b/src/lib/dhcpsrv/srv_config.cc index a0f0fee87a..81698ff221 100644 --- a/src/lib/dhcpsrv/srv_config.cc +++ b/src/lib/dhcpsrv/srv_config.cc @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -218,30 +219,39 @@ SrvConfig::merge6(SrvConfig& other) { void SrvConfig::mergeGlobals(SrvConfig& other) { + auto config_set = getConfiguredGlobals(); + ElementPtr mutable_cfg = boost::const_pointer_cast(config_set); + // If the deprecated reservation-mode is found in database, overwrite other + // reservation flags so there is no conflict when merging to new flags. + if (other.getConfiguredGlobals()->find("reservation-mode")) { + mutable_cfg->remove("reservations-global"); + mutable_cfg->remove("reservations-in-subnet"); + mutable_cfg->remove("reservations-out-of-pool"); + } // Iterate over the "other" globals, adding/overwriting them into // this config's list of globals. for (auto other_global : other.getConfiguredGlobals()->mapValue()) { addConfiguredGlobal(other_global.first, other_global.second); } + // Merge the reservation-mode to new reservation flags. + BaseNetworkParser::moveReservationMode(mutable_cfg); + // A handful of values are stored as members in SrvConfig. So we'll - // iterate over the merged globals, setting approprate members. - for (auto merged_global : getConfiguredGlobals()->mapValue()) { + // iterate over the merged globals, setting appropriate members. + for (auto merged_global : config_set->mapValue()) { std::string name = merged_global.first; ConstElementPtr element = merged_global.second; try { if (name == "decline-probation-period") { setDeclinePeriod(element->intValue()); - } - else if (name == "echo-client-id") { + } else if (name == "echo-client-id") { // echo-client-id is v4 only, but we'll let upstream // worry about that. setEchoClientId(element->boolValue()); - } - else if (name == "dhcp4o6-port") { + } else if (name == "dhcp4o6-port") { setDhcp4o6Port(element->intValue()); - } - else if (name == "server-tag") { + } else if (name == "server-tag") { setServerTag(element->stringValue()); } else if (name == "ip-reservations-unique") { setIPReservationsUnique(element->boolValue()); diff --git a/src/lib/dhcpsrv/tests/network_unittest.cc b/src/lib/dhcpsrv/tests/network_unittest.cc index c8312fd477..4b8ff07122 100644 --- a/src/lib/dhcpsrv/tests/network_unittest.cc +++ b/src/lib/dhcpsrv/tests/network_unittest.cc @@ -638,7 +638,7 @@ TEST_F(NetworkReservationTest, errors) { "\"reservations-global\": true\n" "}"; std::string expected = "invalid use of both 'reservation-mode'" - " one of 'reservations-global', 'reservations-in-subnet'" + " and one of 'reservations-global', 'reservations-in-subnet'" " or 'reservations-out-of-pool' parameters"; TestError(config, expected);