2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-30 05:27:55 +00:00

[#1405] in-subnet is equivalent to all

This commit is contained in:
Razvan Becheriu 2020-10-27 19:49:22 +02:00
parent ab2f01f8c0
commit 21f9a8f82c
20 changed files with 78 additions and 98 deletions

View File

@ -706,7 +706,7 @@
"reservations-in-subnet": true,
// Specify if server should lookup out-of-pool reservations.
"reservations-out-of-pool": true,
"reservations-out-of-pool": false,
// List of client classes which must be evaluated when this shared
// network is selected for client assignments.
@ -880,7 +880,7 @@
"reservations-in-subnet": true,
// Specify if server should lookup out-of-pool reservations.
"reservations-out-of-pool": true,
"reservations-out-of-pool": false,
// Subnet level compute T1 and T2 timers.
"calculate-tee-times": true,
@ -1019,7 +1019,7 @@
"reservations-in-subnet": true,
// Specify if server should lookup out-of-pool reservations.
"reservations-out-of-pool": true,
"reservations-out-of-pool": false,
// Global compute T1 and T2 timers.
"calculate-tee-times": true,

View File

@ -664,7 +664,7 @@
"reservations-in-subnet": true,
// Specify if server should lookup out-of-pool reservations.
"reservations-out-of-pool": true,
"reservations-out-of-pool": false,
// List of client classes which must be evaluated when this shared
// network is selected for client assignments.
@ -861,7 +861,7 @@
"reservations-in-subnet": true,
// Specify if server should lookup out-of-pool reservations.
"reservations-out-of-pool": true,
"reservations-out-of-pool": false,
// Subnet level compute T1 and T2 timers.
"calculate-tee-times": true,
@ -997,7 +997,7 @@
"reservations-in-subnet": true,
// Specify if server should lookup out-of-pool reservations.
"reservations-out-of-pool": true,
"reservations-out-of-pool": false,
// Data directory.
"data-directory": "/tmp",

View File

@ -4661,7 +4661,7 @@ The correspondence of old values are:
"Dhcp4": {
"reservations-global": false,
"reservations-in-subnet": false,
"reservations-in-subnet": true,
"reservations-out-of-pool": true,
...
}
@ -4674,7 +4674,7 @@ The correspondence of old values are:
"reservations-global": false,
"reservations-in-subnet": true,
"reservations-out-of-pool": true,
"reservations-out-of-pool": false,
...
}
@ -4686,7 +4686,7 @@ To activate both ``global`` and ``all``, the following combination can be used:
"reservations-global": true,
"reservations-in-subnet": true,
"reservations-out-of-pool": true,
"reservations-out-of-pool": false,
...
}

View File

@ -4106,7 +4106,7 @@ The correspondence of old values are:
"Dhcp6": {
"reservations-global": false,
"reservations-in-subnet": false,
"reservations-in-subnet": true,
"reservations-out-of-pool": true,
...
}
@ -4119,7 +4119,7 @@ The correspondence of old values are:
"reservations-global": false,
"reservations-in-subnet": true,
"reservations-out-of-pool": true,
"reservations-out-of-pool": false,
...
}
@ -4131,7 +4131,7 @@ To activate both ``global`` and ``all``, the following combination can be used:
"reservations-global": true,
"reservations-in-subnet": true,
"reservations-out-of-pool": true,
"reservations-out-of-pool": false,
...
}

View File

@ -2663,7 +2663,7 @@ An example response could look as follows:
# Specify if server should lookup in-subnet reservations.
"reservations-in-subnet": true,
# Specify if server should lookup out-of-pool reservations.
"reservations-out-of-pool": true,
"reservations-out-of-pool": false,
"subnet4": [
{
"subnet": "192.0.2.0/24",

View File

@ -369,15 +369,9 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
bool found = false;
ConstElementPtr reservations_out_of_pool = mutable_cfg->get("reservations-out-of-pool");
if (reservations_out_of_pool) {
found = true;
}
ConstElementPtr reservations_in_subnet = mutable_cfg->get("reservations-in-subnet");
if (reservations_in_subnet) {
found = true;
}
ConstElementPtr reservations_global = mutable_cfg->get("reservations-global");
if (reservations_global) {
if (reservations_out_of_pool || reservations_in_subnet || reservations_global) {
found = true;
}
ConstElementPtr reservation_mode = mutable_cfg->get("reservation-mode");
@ -393,11 +387,21 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
// reset all other reservation flags to overwrite default values.
if (found) {
bool force_true = false;
if (!reservations_out_of_pool) {
mutable_cfg->set("reservations-out-of-pool", Element::create(false));
} else {
force_true = reservations_out_of_pool->boolValue();
}
if (!reservations_in_subnet) {
mutable_cfg->set("reservations-in-subnet", Element::create(false));
if (force_true) {
mutable_cfg->set("reservations-in-subnet", Element::create(true));
} else {
mutable_cfg->set("reservations-in-subnet", Element::create(false));
}
} else if (force_true && !reservations_in_subnet->boolValue()) {
isc_throw(DhcpConfigError, "invalid use of disabled 'reservations-in-subnet'"
" when enabled 'reservations-out-of-pool'");
}
if (!reservations_global) {
mutable_cfg->set("reservations-global", Element::create(false));

View File

@ -5386,7 +5386,6 @@ TEST_F(Dhcp4ParserTest, hostReservationModesPerSubnet) {
"\"subnet4\": [ { "
" \"pools\": [ { \"pool\": \"192.0.1.0/24\" } ],"
" \"subnet\": \"192.0.1.0/24\", "
" \"reservations-out-of-pool\": true,"
" \"reservations-in-subnet\": true"
" },"
" {"
@ -5413,7 +5412,7 @@ TEST_F(Dhcp4ParserTest, hostReservationModesPerSubnet) {
" {"
" \"pools\": [ { \"pool\": \"192.0.6.0/24\" } ],"
" \"subnet\": \"192.0.6.0/24\", "
" \"reservations-out-of-pool\": true,"
" \"reservations-out-of-pool\": false,"
" \"reservations-in-subnet\": true,"
" \"reservations-global\": true"
" } ],"
@ -5547,7 +5546,6 @@ TEST_F(Dhcp4ParserTest, hostReservationModesGlobal) {
"\"subnet4\": [ { "
" \"pools\": [ { \"pool\": \"192.0.2.0/24\" } ],"
" \"subnet\": \"192.0.2.0/24\", "
" \"reservations-out-of-pool\": true,"
" \"reservations-in-subnet\": true"
" },"
" {"

View File

@ -157,7 +157,6 @@ const char* CONFIGS[] = {
" \"id\": 10,"
" \"pools\": [ { \"pool\": \"10.0.0.10-10.0.0.100\" } ],\n"
" \"interface\": \"eth0\",\n"
" \"reservations-out-of-pool\": true,\n"
" \"reservations-in-subnet\": true,\n"
" \"reservations\": [ \n"
" {\n"

View File

@ -470,15 +470,9 @@ configureDhcp6Server(Dhcpv6Srv& server, isc::data::ConstElementPtr config_set,
bool found = false;
ConstElementPtr reservations_out_of_pool = mutable_cfg->get("reservations-out-of-pool");
if (reservations_out_of_pool) {
found = true;
}
ConstElementPtr reservations_in_subnet = mutable_cfg->get("reservations-in-subnet");
if (reservations_in_subnet) {
found = true;
}
ConstElementPtr reservations_global = mutable_cfg->get("reservations-global");
if (reservations_global) {
if (reservations_out_of_pool || reservations_in_subnet || reservations_global) {
found = true;
}
ConstElementPtr reservation_mode = mutable_cfg->get("reservation-mode");
@ -494,11 +488,21 @@ configureDhcp6Server(Dhcpv6Srv& server, isc::data::ConstElementPtr config_set,
// reset all other reservation flags to overwrite default values.
if (found) {
bool force_true = false;
if (!reservations_out_of_pool) {
mutable_cfg->set("reservations-out-of-pool", Element::create(false));
} else {
force_true = reservations_out_of_pool->boolValue();
}
if (!reservations_in_subnet) {
mutable_cfg->set("reservations-in-subnet", Element::create(false));
if (force_true) {
mutable_cfg->set("reservations-in-subnet", Element::create(true));
} else {
mutable_cfg->set("reservations-in-subnet", Element::create(false));
}
} else if (force_true && !reservations_in_subnet->boolValue()) {
isc_throw(DhcpConfigError, "invalid use of disabled 'reservations-in-subnet'"
" when enabled 'reservations-out-of-pool'");
}
if (!reservations_global) {
mutable_cfg->set("reservations-global", Element::create(false));

View File

@ -5750,7 +5750,7 @@ TEST_F(Dhcp6ParserTest, hostReservationModesPerSubnet) {
/// - 2001:db8:3::/64 (reservations disabled)
/// - 2001:db8:4::/64 (global reservations)
/// - 2001:db8:5::/64 (reservations not specified)
/// - 2001:db8:5::/64 (global + all enabled)
/// - 2001:db8:6::/64 (global + all enabled)
const char* hr_config =
"{"
"\"preferred-lifetime\": 3000,"
@ -5759,7 +5759,6 @@ TEST_F(Dhcp6ParserTest, hostReservationModesPerSubnet) {
"\"subnet6\": [ { "
" \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ],"
" \"subnet\": \"2001:db8:1::/48\", "
" \"reservations-out-of-pool\": true,"
" \"reservations-in-subnet\": true"
" },"
" {"
@ -5786,7 +5785,7 @@ TEST_F(Dhcp6ParserTest, hostReservationModesPerSubnet) {
" {"
" \"pools\": [ { \"pool\": \"2001:db8:6::/64\" } ],"
" \"subnet\": \"2001:db8:6::/48\", "
" \"reservations-out-of-pool\": true,"
" \"reservations-out-of-pool\": false,"
" \"reservations-in-subnet\": true,"
" \"reservations-global\": true"
" } ],"
@ -5918,7 +5917,6 @@ TEST_F(Dhcp6ParserTest, hostReservationModesGlobal) {
"\"subnet6\": [ { "
" \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ],"
" \"subnet\": \"2001:db8:1::/48\", "
" \"reservations-out-of-pool\": true,"
" \"reservations-in-subnet\": true"
" },"
" {"

View File

@ -23,7 +23,7 @@ const uint8_t Network::HR_DISABLED = 0;
const uint8_t Network::HR_OUT_OF_POOL = 1 << 0;
const uint8_t Network::HR_IN_SUBNET = 1 << 1;
const uint8_t Network::HR_GLOBAL = 1 << 2;
const uint8_t Network::HR_ALL = Network::HR_IN_SUBNET | Network::HR_OUT_OF_POOL;
const uint8_t Network::HR_ALL = Network::HR_IN_SUBNET;
void
Network::RelayInfo::addAddress(const asiolink::IOAddress& addr) {
@ -235,6 +235,7 @@ Network::toElement() const {
}
if (hr_out_of_pool) {
map->set("reservations-out-of-pool", Element::create(true));
map->set("reservations-in-subnet", Element::create(true));
}
}
}

View File

@ -152,33 +152,34 @@ public:
IOAddressList addresses_;
};
/// @brief Specifies allowed host reservation mode.
///
/// None - host reservation is disabled. No reservation types
/// are allowed.
static const uint8_t HR_DISABLED;
static const uint8_t HR_DISABLED; // value: 0
/// Only out-of-pool reservations is allowed. This mode
/// allows AllocEngine to skip reservation checks when
/// dealing with with addresses that are in pool.
/// When HR_IN_SUBNET is set, this is always enabled as well.
static const uint8_t HR_OUT_OF_POOL;
/// Only out-of-pool reservations is allowed. This mode allows AllocEngine
/// to skip reservation checks for dynamically allocated addressed.
/// When this is set, HR_IN_SUBNET is always enabled as well as there can
/// can be no reservations that are out-of-pool but not in-subnet.
static const uint8_t HR_OUT_OF_POOL; // value: 1 << 0
/// The in-pool reservations is allowed. This mode actually
/// behaves as if out-of-pool reservations are active as well.
static const uint8_t HR_IN_SUBNET;
/// The in-subnet mode which also allows in-pool reservations.
/// This is equivalent to HR_ALL flag.
static const uint8_t HR_IN_SUBNET; // value: 1 << 1
/// Only global reservations are allowed. This mode
/// instructs AllocEngine to only look at global reservations.
static const uint8_t HR_GLOBAL;
/// Only global reservations are allowed. This mode instructs AllocEngine
/// to only look at global reservations.
static const uint8_t HR_GLOBAL; // value: 1 << 2
/// Both out-of-pool and in-pool reservations are allowed. This is the
/// most flexible mode, where sysadmin have biggest liberty. However,
/// there is a non-trivial performance penalty for it, as the
/// AllocEngine code has to check whether there are reservations, even
/// when dealing with reservations from within the dynamic pools.
static const uint8_t HR_ALL;
/// Both out-of-pool and in-pool reservations are allowed. This is the most
/// flexible mode, where sysadmin have biggest liberty. However, there is a
/// non-trivial performance penalty for it, as the AllocEngine code has to
/// check whether there are reservations, even when dealing with
/// reservations from within the dynamic pools. This is required so that the
/// dynamically allocated addresses don't match any of the reservations.
/// This is the default mode.
static const uint8_t HR_ALL; // value: HR_IN_SUBNET
/// @brief Bitset used to store @ref HRModeFlag flags.
typedef uint8_t HRMode;
@ -405,8 +406,8 @@ public:
///
/// Host reservations may be any of the combinations of in-subnet (they
/// reserve an address that is in the subnet either in-pool or out-of-pool),
/// out-of-pool (they reserve an address that is not in the dynamic pool) or
/// global (they are defined at global level). HR may also be completely
/// out-of-pool (they reserve an address that is in-subnet but not in-pool)
/// or global (they are defined at global level). HR may also be completely
/// disabled for performance reasons.
///
/// @param inheritance inheritance mode to be used.
@ -468,7 +469,7 @@ public:
"reservations-out-of-pool");
if (!hr_mode_out_of_pool.unspecified()) {
if (hr_mode_out_of_pool.get()) {
flags |= Network::HR_OUT_OF_POOL;
flags |= Network::HR_IN_SUBNET | Network::HR_OUT_OF_POOL;
}
found = true;
}

View File

@ -203,13 +203,9 @@ BaseNetworkParser::parseHostReservationMode(const data::ConstElementPtr& network
NetworkPtr& network) {
if (network_data->contains("reservation-mode")) {
bool found = false;
if (network_data->contains("reservations-out-of-pool")) {
found = true;
}
if (network_data->contains("reservations-in-subnet")) {
found = true;
}
if (network_data->contains("reservations-global")) {
if (network_data->contains("reservations-out-of-pool") ||
network_data->contains("reservations-in-subnet") ||
network_data->contains("reservations-global")) {
found = true;
}
if (found) {
@ -233,13 +229,9 @@ void
BaseNetworkParser::parseHostReservationModes(const data::ConstElementPtr& network_data,
NetworkPtr& network) {
bool found = false;
if (network_data->contains("reservations-out-of-pool")) {
found = true;
}
if (network_data->contains("reservations-in-subnet")) {
found = true;
}
if (network_data->contains("reservations-global")) {
if (network_data->contains("reservations-out-of-pool") ||
network_data->contains("reservations-in-subnet") ||
network_data->contains("reservations-global")) {
found = true;
}
if (network_data->contains("reservation-mode")) {

View File

@ -49,7 +49,7 @@ HostReservationModesParser::parse(const ConstElementPtr& config_elem) {
if (elem) {
bool value = elem->boolValue();
if (value) {
flags |= Network::HR_OUT_OF_POOL;
flags |= Network::HR_IN_SUBNET | Network::HR_OUT_OF_POOL;
}
}
} catch (const Exception& ex) {

View File

@ -113,7 +113,7 @@ const SimpleDefaults SimpleParser4::GLOBAL4_DEFAULTS = {
{ "server-hostname", Element::string, "" },
{ "boot-file-name", Element::string, "" },
{ "server-tag", Element::string, "" },
{ "reservations-out-of-pool", Element::boolean, "true" },
{ "reservations-out-of-pool", Element::boolean, "false" },
{ "reservations-in-subnet", Element::boolean, "true" },
{ "reservations-global", Element::boolean, "false" },
{ "calculate-tee-times", Element::boolean, "false" },

View File

@ -109,7 +109,7 @@ const SimpleDefaults SimpleParser6::GLOBAL6_DEFAULTS = {
{ "decline-probation-period", Element::integer, "86400" }, // 24h
{ "dhcp4o6-port", Element::integer, "0" },
{ "server-tag", Element::string, "" },
{ "reservations-out-of-pool", Element::boolean, "true" },
{ "reservations-out-of-pool", Element::boolean, "false" },
{ "reservations-in-subnet", Element::boolean, "true" },
{ "reservations-global", Element::boolean, "false" },
{ "calculate-tee-times", Element::boolean, "true" },

View File

@ -1116,7 +1116,6 @@ TEST(CfgSubnets4Test, unparseSubnet) {
" \"4o6-subnet\": \"\",\n"
" \"authoritative\": false,\n"
" \"reservations-in-subnet\": true,\n"
" \"reservations-out-of-pool\": true,\n"
" \"option-data\": [ ],\n"
" \"pools\": [ ]\n,"
" \"require-client-classes\": [ \"foo\", \"bar\" ],\n"
@ -1284,7 +1283,6 @@ TEST(CfgSubnets4Test, teeTimePercentValidation) {
" \"client-class\": \"\", \n"
" \"require-client-classes\": [] \n,"
" \"reservations-in-subnet\": true,\n"
" \"reservations-out-of-pool\": true,\n"
" \"4o6-interface\": \"\", \n"
" \"4o6-interface-id\": \"\", \n"
" \"4o6-subnet\": \"\" \n"
@ -1352,7 +1350,6 @@ TEST(CfgSubnets4Test, validLifetimeValidation) {
" \"client-class\": \"\", \n"
" \"require-client-classes\": [] \n,"
" \"reservations-in-subnet\": true,\n"
" \"reservations-out-of-pool\": true,\n"
" \"4o6-interface\": \"\", \n"
" \"4o6-interface-id\": \"\", \n"
" \"4o6-subnet\": \"\" \n"
@ -1595,7 +1592,6 @@ TEST(CfgSubnets4Test, hostnameSanitizierValidation) {
" \"client-class\": \"\", \n"
" \"require-client-classes\": [] \n,"
" \"reservations-in-subnet\": true,\n"
" \"reservations-out-of-pool\": true,\n"
" \"4o6-interface\": \"\", \n"
" \"4o6-interface-id\": \"\", \n"
" \"4o6-subnet\": \"\" \n"
@ -1674,7 +1670,6 @@ TEST(CfgSubnets4Test, cacheParamValidation) {
" \"client-class\": \"\", \n"
" \"require-client-classes\": [] \n,"
" \"reservations-in-subnet\": true,\n"
" \"reservations-out-of-pool\": true,\n"
" \"4o6-interface\": \"\", \n"
" \"4o6-interface-id\": \"\", \n"
" \"4o6-subnet\": \"\" \n"

View File

@ -711,7 +711,6 @@ TEST(CfgSubnets6Test, unparseSubnet) {
" \"max-valid-lifetime\": 300,\n"
" \"rapid-commit\": false,\n"
" \"reservations-in-subnet\": true,\n"
" \"reservations-out-of-pool\": true,\n"
" \"pools\": [ ],\n"
" \"pd-pools\": [ ],\n"
" \"option-data\": [ ],\n"
@ -1080,8 +1079,7 @@ TEST(CfgSubnets6Test, teeTimePercentValidation) {
" \"valid-lifetime\": 300, \n"
" \"client-class\": \"\", \n"
" \"require-client-classes\": [] \n,"
" \"reservations-in-subnet\": true,\n"
" \"reservations-out-of-pool\": true\n"
" \"reservations-in-subnet\": true\n"
" }";
@ -1144,8 +1142,7 @@ TEST(CfgSubnets6Test, preferredLifetimeValidation) {
" \"valid-lifetime\": 300, \n"
" \"client-class\": \"\", \n"
" \"require-client-classes\": [] \n,"
" \"reservations-in-subnet\": true,\n"
" \"reservations-out-of-pool\": true\n"
" \"reservations-in-subnet\": true\n"
" }";
@ -1380,8 +1377,7 @@ TEST(CfgSubnets6Test, hostnameSanitizierValidation) {
" \"valid-lifetime\": 300, \n"
" \"client-class\": \"\", \n"
" \"require-client-classes\": [] \n,"
" \"reservations-in-subnet\": true,\n"
" \"reservations-out-of-pool\": true\n"
" \"reservations-in-subnet\": true\n"
" }";
data::ElementPtr elems;
@ -1451,8 +1447,7 @@ TEST(CfgSubnets6Test, cacheParamValidation) {
" \"valid-lifetime\": 300, \n"
" \"client-class\": \"\", \n"
" \"require-client-classes\": [] \n,"
" \"reservations-in-subnet\": true,\n"
" \"reservations-out-of-pool\": true\n"
" \"reservations-in-subnet\": true\n"
" }";
data::ElementPtr elems;

View File

@ -174,7 +174,6 @@ public:
" \"client-class\": \"\","
" \"require-client-classes\": []\n,"
" \"reservations-in-subnet\": true,"
" \"reservations-out-of-pool\": true,"
" \"4o6-interface\": \"\","
" \"4o6-interface-id\": \"\","
" \"4o6-subnet\": \"\","
@ -200,7 +199,6 @@ public:
" \"client-class\": \"\","
" \"require-client-classes\": []\n,"
" \"reservations-in-subnet\": true,"
" \"reservations-out-of-pool\": true,"
" \"4o6-interface\": \"\","
" \"4o6-interface-id\": \"\","
" \"4o6-subnet\": \"\","
@ -592,7 +590,6 @@ public:
" \"client-class\": \"\","
" \"require-client-classes\": []\n,"
" \"reservations-in-subnet\": true,"
" \"reservations-out-of-pool\": true,"
" \"rapid-commit\": false,"
" \"hostname-char-set\": \"\""
" },"
@ -608,7 +605,6 @@ public:
" \"client-class\": \"\","
" \"require-client-classes\": []\n,"
" \"reservations-in-subnet\": true,"
" \"reservations-out-of-pool\": true,"
" \"rapid-commit\": false"
" }"
" ]"

View File

@ -18,7 +18,6 @@
#include <gtest/gtest.h>
#include <cstdint>
#include <vector>
using namespace isc;
using namespace isc::asiolink;
using namespace isc::dhcp;
@ -641,7 +640,6 @@ TEST(SharedNetwork4Test, unparse) {
" \"renew-timer\": 100,\n"
" \"require-client-classes\": [ \"foo\" ],\n"
" \"reservations-in-subnet\": true,\n"
" \"reservations-out-of-pool\": true,\n"
" \"subnet4\": [\n"
" {\n"
" \"4o6-interface\": \"\",\n"
@ -1333,7 +1331,6 @@ TEST(SharedNetwork6Test, unparse) {
" \"renew-timer\": 100,\n"
" \"require-client-classes\": [ \"foo\" ],\n"
" \"reservations-in-subnet\": true,\n"
" \"reservations-out-of-pool\": true,\n"
" \"subnet6\": [\n"
" {\n"
" \"id\": 1,\n"