From: Marcin Siodelski Date: Wed, 28 Feb 2018 10:24:51 +0000 (+0100) Subject: [5437] Optimize lease searches for a DHCPv6 client. X-Git-Tag: ha_checkpoints12~10^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=53713e352dd6efaefbd6fa382b4f531e7c657889;p=thirdparty%2Fkea.git [5437] Optimize lease searches for a DHCPv6 client. --- 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_); }