2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-31 14:05:33 +00:00

[1598] convert reservation-mode from CB to new flags

This commit is contained in:
Razvan Becheriu
2021-01-12 19:22:59 +02:00
parent d33589a76f
commit d66b4b70a0
5 changed files with 22 additions and 10 deletions

View File

@@ -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");

View File

@@ -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 },

View File

@@ -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 },

View File

@@ -7,6 +7,7 @@
#include <config.h>
#include <exceptions/exceptions.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/parsers/base_network_parser.h>
#include <dhcpsrv/parsers/simple_parser4.h>
#include <dhcpsrv/srv_config.h>
#include <dhcpsrv/lease_mgr_factory.h>
@@ -218,30 +219,39 @@ SrvConfig::merge6(SrvConfig& other) {
void
SrvConfig::mergeGlobals(SrvConfig& other) {
auto config_set = getConfiguredGlobals();
ElementPtr mutable_cfg = boost::const_pointer_cast<Element>(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());

View File

@@ -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);