]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1040] handle update and delete
authorRazvan Becheriu <razvan@isc.org>
Thu, 23 Jan 2020 17:50:54 +0000 (19:50 +0200)
committerRazvan Becheriu <razvan@isc.org>
Fri, 24 Jan 2020 12:27:09 +0000 (12:27 +0000)
src/bin/dhcp4/dhcp4_srv.cc
src/bin/dhcp6/dhcp6_srv.cc
src/lib/dhcpsrv/alloc_engine.cc

index 01773340e82e336783e081e4d5e9cf62c133898b..74f1f01952c16b127785e0f453d560d20f348fd7 100644 (file)
@@ -3039,10 +3039,6 @@ Dhcpv4Srv::declineLease(const Lease4Ptr& lease, const Pkt4Ptr& decline,
         }
     }
 
-    // Remove existing DNS entries for the lease, if any.
-    // queueNCR will do the necessary checks and will skip the update, if not needed.
-    queueNCR(CHG_REMOVE, lease);
-
     // @todo: Call hooks.
 
     // We need to disassociate the lease from the client. Once we move a lease
@@ -3052,6 +3048,10 @@ Dhcpv4Srv::declineLease(const Lease4Ptr& lease, const Pkt4Ptr& decline,
 
     LeaseMgrFactory::instance().updateLease4(lease);
 
+    // Remove existing DNS entries for the lease, if any.
+    // queueNCR will do the necessary checks and will skip the update, if not needed.
+    queueNCR(CHG_REMOVE, lease);
+
     // Bump up the statistics.
 
     // Per subnet declined addresses counter.
index 9f6f9e192cf3596d69524691e414f31829a76664..68586a7ebdfb9291ebc44fd125c79b1191169f96 100644 (file)
@@ -3395,11 +3395,6 @@ Dhcpv6Srv::declineLease(const Pkt6Ptr& decline, const Lease6Ptr lease,
         }
     }
 
-    // Check if a lease has flags indicating that the FQDN update has
-    // been performed. If so, create NameChangeRequest which removes
-    // the entries. This method does all necessary checks.
-    queueNCR(CHG_REMOVE, lease);
-
     // @todo: Call hooks.
 
     // We need to disassociate the lease from the client. Once we move a lease
@@ -3409,6 +3404,11 @@ Dhcpv6Srv::declineLease(const Pkt6Ptr& decline, const Lease6Ptr lease,
 
     LeaseMgrFactory::instance().updateLease6(lease);
 
+    // Check if a lease has flags indicating that the FQDN update has
+    // been performed. If so, create NameChangeRequest which removes
+    // the entries. This method does all necessary checks.
+    queueNCR(CHG_REMOVE, lease);
+
     // Bump up the subnet-specific statistic.
     StatsMgr::instance().addValue(
         StatsMgr::generateName("subnet", lease->subnet_id_, "declined-addresses"),
@@ -3774,9 +3774,9 @@ Dhcpv6Srv::generateFqdn(const Pkt6Ptr& answer,
         // Set the generated FQDN in the Client FQDN option.
         fqdn->setDomainName(generated_name, Option6ClientFqdn::FULL);
 
-       answer->delOption(D6O_CLIENT_FQDN);
-       answer->addOption(fqdn);
-       ctx.hostname_ = generated_name;
+        answer->delOption(D6O_CLIENT_FQDN);
+        answer->addOption(fqdn);
+        ctx.hostname_ = generated_name;
     } catch (const Exception& ex) {
         LOG_ERROR(ddns6_logger, DHCP6_DDNS_GENERATED_FQDN_UPDATE_FAIL)
             .arg(answer->getLabel())
index fe4a6c6d713fd40e5258d6753de99edf6d9f3801..8f49fa6c81343bb0b1f77b1fd975baebc8bcbc1e 100644 (file)
@@ -1474,7 +1474,11 @@ AllocEngine::removeNonmatchingReservedLeases6(ClientContext6& ctx,
 
         // Remove this lease from LeaseMgr as it is reserved to someone
         // else or doesn't belong to a pool.
-        LeaseMgrFactory::instance().deleteLease(candidate);
+        bool success = LeaseMgrFactory::instance().deleteLease(candidate);
+
+        if (!success) {
+            continue;
+        }
 
         // Update DNS if needed.
         queueNCR(CHG_REMOVE, candidate);
@@ -1517,7 +1521,11 @@ AllocEngine::removeNonmatchingReservedNoHostLeases6(ClientContext6& ctx,
         }
 
         // Remove this lease from LeaseMgr as it doesn't belong to a pool.
-        LeaseMgrFactory::instance().deleteLease(candidate);
+        bool success = LeaseMgrFactory::instance().deleteLease(candidate);
+
+        if (!success) {
+            continue;
+        }
 
         // Update DNS if needed.
         queueNCR(CHG_REMOVE, candidate);
@@ -1584,7 +1592,11 @@ AllocEngine::removeNonreservedLeases6(ClientContext6& ctx,
         // simply remove it from the list.
         // We have reservations, but not for this lease. Release it.
         // Remove this lease from LeaseMgr
-        LeaseMgrFactory::instance().deleteLease(*lease);
+        bool success = LeaseMgrFactory::instance().deleteLease(*lease);
+
+        if (!success) {
+            continue;
+        }
 
         // Update DNS if required.
         queueNCR(CHG_REMOVE, *lease);
@@ -1984,7 +1996,11 @@ AllocEngine::extendLease6(ClientContext6& ctx, Lease6Ptr lease) {
         // Oh dear, the lease is no longer valid. We need to get rid of it.
 
         // Remove this lease from LeaseMgr
-        LeaseMgrFactory::instance().deleteLease(lease);
+        bool success = LeaseMgrFactory::instance().deleteLease(lease);
+
+        if (!success) {
+            return;
+        }
 
         // Updated DNS if required.
         queueNCR(CHG_REMOVE, lease);
@@ -3523,12 +3539,15 @@ AllocEngine::requestLease4(AllocEngine::ClientContext4& ctx) {
             .arg(ctx.query_->getLabel())
             .arg(client_lease->addr_.toText());
 
-        lease_mgr.deleteLease(client_lease);
+        bool success = lease_mgr.deleteLease(client_lease);
 
-        // Need to decrease statistic for assigned addresses.
-        StatsMgr::instance().addValue(
-            StatsMgr::generateName("subnet", client_lease->subnet_id_, "assigned-addresses"),
-            static_cast<int64_t>(-1));
+        if (success) {
+            // Need to decrease statistic for assigned addresses.
+            StatsMgr::instance().addValue(
+                StatsMgr::generateName("subnet", client_lease->subnet_id_,
+                                       "assigned-addresses"),
+                static_cast<int64_t>(-1));
+        }
     }
 
     // Return the allocated lease or NULL pointer if allocation was