mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-03 07:25:18 +00:00
[1598] convert reservation-mode from CB to new flags
This commit is contained in:
@@ -25,7 +25,7 @@ BaseNetworkParser::moveReservationMode(ElementPtr config) {
|
|||||||
config->contains("reservations-in-subnet") ||
|
config->contains("reservations-in-subnet") ||
|
||||||
config->contains("reservations-out-of-pool")) {
|
config->contains("reservations-out-of-pool")) {
|
||||||
isc_throw(DhcpConfigError, "invalid use of both 'reservation-mode'"
|
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");
|
" or 'reservations-out-of-pool' parameters");
|
||||||
}
|
}
|
||||||
std::string hr_mode = getString(config, "reservation-mode");
|
std::string hr_mode = getString(config, "reservation-mode");
|
||||||
|
@@ -70,6 +70,7 @@ const SimpleKeywords SimpleParser4::GLOBAL4_PARAMETERS = {
|
|||||||
{ "reservations", Element::list },
|
{ "reservations", Element::list },
|
||||||
{ "config-control", Element::map },
|
{ "config-control", Element::map },
|
||||||
{ "server-tag", Element::string },
|
{ "server-tag", Element::string },
|
||||||
|
{ "reservation-mode", Element::string },
|
||||||
{ "reservations-global", Element::boolean },
|
{ "reservations-global", Element::boolean },
|
||||||
{ "reservations-in-subnet", Element::boolean },
|
{ "reservations-in-subnet", Element::boolean },
|
||||||
{ "reservations-out-of-pool", Element::boolean },
|
{ "reservations-out-of-pool", Element::boolean },
|
||||||
|
@@ -71,6 +71,7 @@ const SimpleKeywords SimpleParser6::GLOBAL6_PARAMETERS = {
|
|||||||
{ "reservations", Element::list },
|
{ "reservations", Element::list },
|
||||||
{ "config-control", Element::map },
|
{ "config-control", Element::map },
|
||||||
{ "server-tag", Element::string },
|
{ "server-tag", Element::string },
|
||||||
|
{ "reservation-mode", Element::string },
|
||||||
{ "reservations-global", Element::boolean },
|
{ "reservations-global", Element::boolean },
|
||||||
{ "reservations-in-subnet", Element::boolean },
|
{ "reservations-in-subnet", Element::boolean },
|
||||||
{ "reservations-out-of-pool", Element::boolean },
|
{ "reservations-out-of-pool", Element::boolean },
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <exceptions/exceptions.h>
|
#include <exceptions/exceptions.h>
|
||||||
#include <dhcpsrv/cfgmgr.h>
|
#include <dhcpsrv/cfgmgr.h>
|
||||||
|
#include <dhcpsrv/parsers/base_network_parser.h>
|
||||||
#include <dhcpsrv/parsers/simple_parser4.h>
|
#include <dhcpsrv/parsers/simple_parser4.h>
|
||||||
#include <dhcpsrv/srv_config.h>
|
#include <dhcpsrv/srv_config.h>
|
||||||
#include <dhcpsrv/lease_mgr_factory.h>
|
#include <dhcpsrv/lease_mgr_factory.h>
|
||||||
@@ -218,30 +219,39 @@ SrvConfig::merge6(SrvConfig& other) {
|
|||||||
|
|
||||||
void
|
void
|
||||||
SrvConfig::mergeGlobals(SrvConfig& other) {
|
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
|
// Iterate over the "other" globals, adding/overwriting them into
|
||||||
// this config's list of globals.
|
// this config's list of globals.
|
||||||
for (auto other_global : other.getConfiguredGlobals()->mapValue()) {
|
for (auto other_global : other.getConfiguredGlobals()->mapValue()) {
|
||||||
addConfiguredGlobal(other_global.first, other_global.second);
|
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
|
// A handful of values are stored as members in SrvConfig. So we'll
|
||||||
// iterate over the merged globals, setting approprate members.
|
// iterate over the merged globals, setting appropriate members.
|
||||||
for (auto merged_global : getConfiguredGlobals()->mapValue()) {
|
for (auto merged_global : config_set->mapValue()) {
|
||||||
std::string name = merged_global.first;
|
std::string name = merged_global.first;
|
||||||
ConstElementPtr element = merged_global.second;
|
ConstElementPtr element = merged_global.second;
|
||||||
try {
|
try {
|
||||||
if (name == "decline-probation-period") {
|
if (name == "decline-probation-period") {
|
||||||
setDeclinePeriod(element->intValue());
|
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
|
// echo-client-id is v4 only, but we'll let upstream
|
||||||
// worry about that.
|
// worry about that.
|
||||||
setEchoClientId(element->boolValue());
|
setEchoClientId(element->boolValue());
|
||||||
}
|
} else if (name == "dhcp4o6-port") {
|
||||||
else if (name == "dhcp4o6-port") {
|
|
||||||
setDhcp4o6Port(element->intValue());
|
setDhcp4o6Port(element->intValue());
|
||||||
}
|
} else if (name == "server-tag") {
|
||||||
else if (name == "server-tag") {
|
|
||||||
setServerTag(element->stringValue());
|
setServerTag(element->stringValue());
|
||||||
} else if (name == "ip-reservations-unique") {
|
} else if (name == "ip-reservations-unique") {
|
||||||
setIPReservationsUnique(element->boolValue());
|
setIPReservationsUnique(element->boolValue());
|
||||||
|
@@ -638,7 +638,7 @@ TEST_F(NetworkReservationTest, errors) {
|
|||||||
"\"reservations-global\": true\n"
|
"\"reservations-global\": true\n"
|
||||||
"}";
|
"}";
|
||||||
std::string expected = "invalid use of both 'reservation-mode'"
|
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";
|
" or 'reservations-out-of-pool' parameters";
|
||||||
TestError(config, expected);
|
TestError(config, expected);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user