]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5437] Optimize lease searches for a DHCPv6 client.
authorMarcin Siodelski <marcin@isc.org>
Wed, 28 Feb 2018 10:24:51 +0000 (11:24 +0100)
committerMarcin Siodelski <marcin@isc.org>
Wed, 28 Feb 2018 10:24:51 +0000 (11:24 +0100)
src/lib/dhcpsrv/alloc_engine.cc

index 67c33cabf5963f2c9ba4b254b0a811df2086d778..a66a8c16f6bd1e4973aed74aa3dc2f8b3d7c3eec 100644 (file)
@@ -584,14 +584,20 @@ AllocEngine::allocateLeases6(ClientContext6& ctx) {
         // Check if there are existing leases for that shared network and
         // DUID/IAID.
         Subnet6Ptr subnet = ctx.subnet_;
+        Lease6Collection all_leases =
+            LeaseMgrFactory::instance().getLeases6(ctx.currentIA().type_,
+                                                   *ctx.duid_,
+                                                   ctx.currentIA().iaid_);
+
+        // Iterate over the leases and eliminate those that are outside of
+        // our shared network.
         Lease6Collection leases;
         while (subnet) {
-            Lease6Collection leases_subnet =
-                LeaseMgrFactory::instance().getLeases6(ctx.currentIA().type_,
-                                                       *ctx.duid_,
-                                                       ctx.currentIA().iaid_,
-                                                       subnet->getID());
-            leases.insert(leases.end(), leases_subnet.begin(), leases_subnet.end());
+            for (auto l = all_leases.begin(); l != all_leases.end(); ++l) {
+                if ((*l)->subnet_id_ == subnet->getID()) {
+                    leases.push_back(*l);
+                }
+            }
 
             subnet = subnet->getNextSubnet(ctx.subnet_);
         }