From 298be5ee5466fcd512672184e41a80b9501c40a5 Mon Sep 17 00:00:00 2001 From: Razvan Becheriu Date: Thu, 15 Oct 2020 18:43:46 +0300 Subject: [PATCH] [#1405] disable reservatio modes flags if any is explicitly configured --- src/bin/dhcp4/json_config_parser.cc | 39 +++++++++++++++++++---------- src/bin/dhcp6/json_config_parser.cc | 39 +++++++++++++++++++---------- 2 files changed, 52 insertions(+), 26 deletions(-) diff --git a/src/bin/dhcp4/json_config_parser.cc b/src/bin/dhcp4/json_config_parser.cc index c11a96953e..4f1a844ce4 100644 --- a/src/bin/dhcp4/json_config_parser.cc +++ b/src/bin/dhcp4/json_config_parser.cc @@ -367,22 +367,22 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set, // default values and will insert derived values as well. mutable_cfg = boost::const_pointer_cast(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) { + found = true; + } ConstElementPtr reservation_mode = mutable_cfg->get("reservation-mode"); if (reservation_mode) { // log warning for deprecated option - bool found = false; - reservation_mode = mutable_cfg->get("reservations-out-of-pool"); - if (reservation_mode) { - found = true; - } - reservation_mode = mutable_cfg->get("reservations-in-subnet"); - if (reservation_mode) { - found = true; - } - reservation_mode = mutable_cfg->get("reservations-global"); - if (reservation_mode) { - found = true; - } if (found) { isc_throw(DhcpConfigError, "invalid use of both 'reservation-mode'" " and one of 'reservations-out-of-pool'" @@ -391,6 +391,19 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set, } } + // reset all other reservation flags to overwrite default values. + if (found) { + if (!reservations_out_of_pool) { + mutable_cfg->set("reservations-out-of-pool", Element::create(false)); + } + if (!reservations_in_subnet) { + mutable_cfg->set("reservations-in-subnet", Element::create(false)); + } + if (!reservations_global) { + mutable_cfg->set("reservations-global", Element::create(false)); + } + } + // Relocate dhcp-ddns parameters that have moved to global scope. // Rule is that a global value overrides the dhcp-ddns value, so // we need to do this before we apply global defaults. diff --git a/src/bin/dhcp6/json_config_parser.cc b/src/bin/dhcp6/json_config_parser.cc index 641a8b6145..b5979dbe4e 100644 --- a/src/bin/dhcp6/json_config_parser.cc +++ b/src/bin/dhcp6/json_config_parser.cc @@ -468,22 +468,22 @@ configureDhcp6Server(Dhcpv6Srv& server, isc::data::ConstElementPtr config_set, // default values and will insert derived values as well. mutable_cfg = boost::const_pointer_cast(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) { + found = true; + } ConstElementPtr reservation_mode = mutable_cfg->get("reservation-mode"); if (reservation_mode) { // log warning for deprecated option - bool found = false; - reservation_mode = mutable_cfg->get("reservations-out-of-pool"); - if (reservation_mode) { - found = true; - } - reservation_mode = mutable_cfg->get("reservations-in-subnet"); - if (reservation_mode) { - found = true; - } - reservation_mode = mutable_cfg->get("reservations-global"); - if (reservation_mode) { - found = true; - } if (found) { isc_throw(DhcpConfigError, "invalid use of both 'reservation-mode'" " and one of 'reservations-out-of-pool'" @@ -492,6 +492,19 @@ configureDhcp6Server(Dhcpv6Srv& server, isc::data::ConstElementPtr config_set, } } + // reset all other reservation flags to overwrite default values. + if (found) { + if (!reservations_out_of_pool) { + mutable_cfg->set("reservations-out-of-pool", Element::create(false)); + } + if (!reservations_in_subnet) { + mutable_cfg->set("reservations-in-subnet", Element::create(false)); + } + if (!reservations_global) { + mutable_cfg->set("reservations-global", Element::create(false)); + } + } + // Relocate dhcp-ddns parameters that have moved to global scope. // Rule is that a global value overrides the dhcp-ddns value, so // we need to do this before we apply global defaults.