Browse Source

[5029] Allocation engine allows for multiple leases w/ the same HW addr.

Marcin Siodelski 8 years ago
parent
commit
c5d28bf76b
1 changed files with 15 additions and 7 deletions
  1. 15 7
      src/lib/dhcpsrv/alloc_engine.cc

+ 15 - 7
src/lib/dhcpsrv/alloc_engine.cc

@@ -2149,13 +2149,21 @@ void findClientLease(const AllocEngine::ClientContext4& ctx, Lease4Ptr& client_l
     // If no lease found using the client identifier, try the lookup using
     // If no lease found using the client identifier, try the lookup using
     // the HW address.
     // the HW address.
     if (!client_lease && ctx.hwaddr_) {
     if (!client_lease && ctx.hwaddr_) {
-        client_lease = lease_mgr.getLease4(*ctx.hwaddr_, ctx.subnet_->getID());
+
-        // This lookup may return the lease which has conflicting client
+        // There may be cases when there is a lease for the same MAC address
-        // identifier and thus is considered to belong to someone else.
+        // (even within the same subnet). Such situation may occur for PXE
-        // If this is the case, we need to toss the result and force the
+        // boot clients using the same MAC address but different client
-        // Allocation Engine to allocate another lease.
+        // identifiers.
-        if (client_lease && !client_lease->belongsToClient(ctx.hwaddr_, ctx.clientid_)) {
+        Lease4Collection client_leases = lease_mgr.getLease4(*ctx.hwaddr_);
-            client_lease.reset();
+        for (Lease4Collection::const_iterator client_lease_it = client_leases.begin();
+             client_lease_it != client_leases.end(); ++client_lease_it) {
+            Lease4Ptr existing_lease = *client_lease_it;
+            if ((existing_lease->subnet_id_ == ctx.subnet_->getID()) &&
+                existing_lease->belongsToClient(ctx.hwaddr_, ctx.clientid_)) {
+                // Found the lease of this client, so return it.
+                client_lease = existing_lease;
+                break;
+            }
         }
         }
     }
     }
 }
 }