]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3108] added warning message to disable "ip-reservations-unique"
authorRazvan Becheriu <razvan@isc.org>
Thu, 9 Nov 2023 10:46:08 +0000 (12:46 +0200)
committerRazvan Becheriu <razvan@isc.org>
Mon, 18 Dec 2023 16:48:26 +0000 (18:48 +0200)
 - suggest disabling "ip-reservations-unique" flag if multiple reservations
   for the same IP address are found

src/lib/dhcpsrv/alloc_engine.cc
src/lib/dhcpsrv/dhcpsrv_messages.cc
src/lib/dhcpsrv/dhcpsrv_messages.h
src/lib/dhcpsrv/dhcpsrv_messages.mes

index c1fe319fe2250c968c0714e8eae4500d43df8bfd..8097e5ffc4ead00809ed9edaa89b87007e54e12a 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <config.h>
 
+#include <database/db_exceptions.h>
 #include <dhcp/dhcp6.h>
 #include <dhcp/pkt4.h>
 #include <dhcp/pkt6.h>
@@ -42,6 +43,7 @@
 #include <vector>
 
 using namespace isc::asiolink;
+using namespace isc::db;
 using namespace isc::dhcp;
 using namespace isc::dhcp_ddns;
 using namespace isc::hooks;
@@ -123,9 +125,18 @@ getIPv6Resrv(const SubnetID& subnet_id, const IOAddress& address) {
     // the mode in which non-unique reservations are allowed the backends which
     // don't support it are not used and we can safely call getAll6.
     if (CfgMgr::instance().getCurrentCfg()->getCfgDbAccess()->getIPReservationsUnique()) {
-        auto host = HostMgr::instance().get6(subnet_id, address);
-        if (host) {
-            reserved.push_back(host);
+        try {
+            // Reservations are unique. It is safe to call get6 to get the unique host.
+            auto host = HostMgr::instance().get6(subnet_id, address);
+            if (host) {
+                reserved.push_back(host);
+            }
+        } catch (const MultipleRecords& ex) {
+            LOG_WARN(dhcpsrv_logger, DHCPSRV_CFGMGR_IP_RESERVATIONS_UNIQUE_DUPLICATES_DETECTED)
+                .arg(address)
+                .arg(subnet_id)
+                .arg(ex.what());
+            throw;
         }
     } else {
         auto hosts = HostMgr::instance().getAll6(subnet_id, address);
@@ -3340,10 +3351,18 @@ addressReserved(const IOAddress& address, const AllocEngine::ClientContext4& ctx
         // don't support it are not used and we can safely call getAll4.
         ConstHostCollection hosts;
         if (CfgMgr::instance().getCurrentCfg()->getCfgDbAccess()->getIPReservationsUnique()) {
-            // Reservations are unique. It is safe to call get4 to get the unique host.
-            ConstHostPtr host = HostMgr::instance().get4(ctx.subnet_->getID(), address);
-            if (host) {
-                hosts.push_back(host);
+            try {
+                // Reservations are unique. It is safe to call get4 to get the unique host.
+                ConstHostPtr host = HostMgr::instance().get4(ctx.subnet_->getID(), address);
+                if (host) {
+                    hosts.push_back(host);
+                }
+            } catch (const MultipleRecords& ex) {
+                LOG_WARN(dhcpsrv_logger, DHCPSRV_CFGMGR_IP_RESERVATIONS_UNIQUE_DUPLICATES_DETECTED)
+                    .arg(address)
+                    .arg(ctx.subnet_->getID())
+                    .arg(ex.what());
+                throw;
             }
         } else {
             // Reservations can be non-unique. Need to get all reservations for that address.
index 42fa843e0c47fed14eb207020fd649eef36d18f3..a9288a11a4c182010fc3ec9523f2c110c1a42c15 100644 (file)
@@ -26,6 +26,7 @@ extern const isc::log::MessageID DHCPSRV_CFGMGR_FLQ_POPULATE_FREE_PREFIX_LEASES
 extern const isc::log::MessageID DHCPSRV_CFGMGR_FLQ_POPULATE_FREE_PREFIX_LEASES_DONE = "DHCPSRV_CFGMGR_FLQ_POPULATE_FREE_PREFIX_LEASES_DONE";
 extern const isc::log::MessageID DHCPSRV_CFGMGR_IPV4_RESERVATIONS_NON_UNIQUE_IGNORED = "DHCPSRV_CFGMGR_IPV4_RESERVATIONS_NON_UNIQUE_IGNORED";
 extern const isc::log::MessageID DHCPSRV_CFGMGR_IPV6_RESERVATIONS_NON_UNIQUE_IGNORED = "DHCPSRV_CFGMGR_IPV6_RESERVATIONS_NON_UNIQUE_IGNORED";
+extern const isc::log::MessageID DHCPSRV_CFGMGR_IP_RESERVATIONS_UNIQUE_DUPLICATES_DETECTED = "DHCPSRV_CFGMGR_IP_RESERVATIONS_UNIQUE_DUPLICATES_DETECTED";
 extern const isc::log::MessageID DHCPSRV_CFGMGR_IP_RESERVATIONS_UNIQUE_DUPLICATES_POSSIBLE = "DHCPSRV_CFGMGR_IP_RESERVATIONS_UNIQUE_DUPLICATES_POSSIBLE";
 extern const isc::log::MessageID DHCPSRV_CFGMGR_NEW_SUBNET4 = "DHCPSRV_CFGMGR_NEW_SUBNET4";
 extern const isc::log::MessageID DHCPSRV_CFGMGR_NEW_SUBNET6 = "DHCPSRV_CFGMGR_NEW_SUBNET6";
@@ -312,6 +313,7 @@ const char* values[] = {
     "DHCPSRV_CFGMGR_FLQ_POPULATE_FREE_PREFIX_LEASES_DONE", "populated %1 free prefix leases for the FLQ allocator in subnet %2 completed in %3",
     "DHCPSRV_CFGMGR_IPV4_RESERVATIONS_NON_UNIQUE_IGNORED", "ignoring \"ip-reservations-unique\" setting because at least one of the host database backends does not support non-unique IP reservations in a subnet",
     "DHCPSRV_CFGMGR_IPV6_RESERVATIONS_NON_UNIQUE_IGNORED", "ignoring \"ip-reservations-unique\" setting because at least one of the host database backends does not support non unique IP reservations in a subnet",
+    "DHCPSRV_CFGMGR_IP_RESERVATIONS_UNIQUE_DUPLICATES_DETECTED", "the \"ip-reservations-unique\" flag is set to false and multiple reservations for the IP address: %1 in subnet: %2 are not allowed causing error: %3",
     "DHCPSRV_CFGMGR_IP_RESERVATIONS_UNIQUE_DUPLICATES_POSSIBLE", "setting \"ip-reservations-unique\" from false to true poses a risk that some host backends may still contain multiple reservations for the same IP address",
     "DHCPSRV_CFGMGR_NEW_SUBNET4", "a new subnet has been added to configuration: %1",
     "DHCPSRV_CFGMGR_NEW_SUBNET6", "a new subnet has been added to configuration: %1",
index a243c10209a29394be6da7c80e44ae0ab25d634a..be10d79340c159d71b657dc167c4c7a09f00127d 100644 (file)
@@ -27,6 +27,7 @@ extern const isc::log::MessageID DHCPSRV_CFGMGR_FLQ_POPULATE_FREE_PREFIX_LEASES;
 extern const isc::log::MessageID DHCPSRV_CFGMGR_FLQ_POPULATE_FREE_PREFIX_LEASES_DONE;
 extern const isc::log::MessageID DHCPSRV_CFGMGR_IPV4_RESERVATIONS_NON_UNIQUE_IGNORED;
 extern const isc::log::MessageID DHCPSRV_CFGMGR_IPV6_RESERVATIONS_NON_UNIQUE_IGNORED;
+extern const isc::log::MessageID DHCPSRV_CFGMGR_IP_RESERVATIONS_UNIQUE_DUPLICATES_DETECTED;
 extern const isc::log::MessageID DHCPSRV_CFGMGR_IP_RESERVATIONS_UNIQUE_DUPLICATES_POSSIBLE;
 extern const isc::log::MessageID DHCPSRV_CFGMGR_NEW_SUBNET4;
 extern const isc::log::MessageID DHCPSRV_CFGMGR_NEW_SUBNET6;
index 9d689cd3992038436d4aa7776fbc436328513d34..f032b186529370d11d39ddcf62655911f5027bc7 100644 (file)
@@ -128,6 +128,13 @@ backends may still contain multiple reservations for the same IP addresses
 causing problems with lease allocation for certain addresses. Please ensure
 that all such duplicates are removed.
 
+% DHCPSRV_CFGMGR_IP_RESERVATIONS_UNIQUE_DUPLICATES_DETECTED the "ip-reservations-unique" flag is set to false and multiple reservations for the IP address: %1 in subnet: %2 are not allowed causing error: %3
+This warning message is issued when the DHCP server is configured to not allow
+multiple reservations for the same IP address. However, the host database
+backends contains multiple reservations for the IP addresses which logged as
+the first argument, in the subnet logged as second argument, causing problems
+with lease allocation logged as third argument.
+
 % DHCPSRV_CFGMGR_NEW_SUBNET4 a new subnet has been added to configuration: %1
 This is an informational message reporting that the configuration has
 been extended to include the specified IPv4 subnet.