From 53713e352dd6efaefbd6fa382b4f531e7c657889 Mon Sep 17 00:00:00 2001 From: Marcin Siodelski Date: Wed, 28 Feb 2018 11:24:51 +0100 Subject: [PATCH] [5437] Optimize lease searches for a DHCPv6 client. --- src/lib/dhcpsrv/alloc_engine.cc | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/lib/dhcpsrv/alloc_engine.cc b/src/lib/dhcpsrv/alloc_engine.cc index 67c33cabf5..a66a8c16f6 100644 --- a/src/lib/dhcpsrv/alloc_engine.cc +++ b/src/lib/dhcpsrv/alloc_engine.cc @@ -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_); } -- 2.47.2