]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1550] addressed comments
authorRazvan Becheriu <razvan@isc.org>
Thu, 19 Nov 2020 13:27:22 +0000 (15:27 +0200)
committerRazvan Becheriu <razvan@isc.org>
Thu, 19 Nov 2020 13:27:22 +0000 (15:27 +0200)
src/lib/dhcpsrv/alloc_engine.cc

index e589b3d44997202a7363865161f67f7e2c370fd7..012a24deb83ca2256cf4f540edb32a25c6069955 100644 (file)
@@ -597,16 +597,17 @@ AllocEngine::findReservation(ClientContext6& ctx) {
     SharedNetwork6Ptr network;
     subnet->getSharedNetwork(network);
 
-    if (ctx.hosts_.find(SUBNET_ID_GLOBAL) == ctx.hosts_.end() &&
-        subnet->getReservationsGlobal()) {
-        // setting null host means there is no host and no need to perform the
-        // search again
-        ctx.hosts_[SUBNET_ID_GLOBAL] = findGlobalReservation(ctx);
-    }
-
-    // If only global reservations are enabled all work is done.
-    if (!subnet->getReservationsInSubnet()) {
-        return;
+    // @todo: This code can be trivially optimized.
+    if (subnet->getReservationsGlobal()) {
+        ConstHostPtr ghost = findGlobalReservation(ctx);
+        if (ghost) {
+            ctx.hosts_[SUBNET_ID_GLOBAL] = ghost;
+
+            // If we had only to fetch global reservations it is done.
+            if (!subnet->getReservationsInSubnet()) {
+                return;
+            }
+        }
     }
 
     // If the subnet belongs to a shared network it is usually going to be
@@ -3344,16 +3345,17 @@ AllocEngine::findReservation(ClientContext4& ctx) {
     SharedNetwork4Ptr network;
     subnet->getSharedNetwork(network);
 
-    if (ctx.hosts_.find(SUBNET_ID_GLOBAL) == ctx.hosts_.end() &&
-        subnet->getReservationsGlobal()) {
-        // setting null host means there is no host and no need to perform the
-        // search again
-        ctx.hosts_[SUBNET_ID_GLOBAL] = findGlobalReservation(ctx);
-    }
+    // @todo: This code can be trivially optimized.
+    if (subnet->getReservationsGlobal()) {
+        ConstHostPtr ghost = findGlobalReservation(ctx);
+        if (ghost) {
+            ctx.hosts_[SUBNET_ID_GLOBAL] = ghost;
 
-    // If only global reservations are enabled all work is done.
-    if (!subnet->getReservationsInSubnet()) {
-        return;
+            // If we had only to fetch global reservations it is done.
+            if (!subnet->getReservationsInSubnet()) {
+                return;
+            }
+        }
     }
 
     // If the subnet belongs to a shared network it is usually going to be