diff options
Diffstat (limited to 'src/lib/dhcpsrv/alloc_engine.cc')
-rw-r--r-- | src/lib/dhcpsrv/alloc_engine.cc | 84 |
1 files changed, 41 insertions, 43 deletions
diff --git a/src/lib/dhcpsrv/alloc_engine.cc b/src/lib/dhcpsrv/alloc_engine.cc index 111a3a9347..810409fe4b 100644 --- a/src/lib/dhcpsrv/alloc_engine.cc +++ b/src/lib/dhcpsrv/alloc_engine.cc @@ -388,9 +388,9 @@ AllocEngine::findReservation(ClientContext6& ctx) { // Store the hosts in the temporary map, because some hosts may // belong to subnets outside of the shared network. We'll need // to eliminate them. - for (auto host = hosts.begin(); host != hosts.end(); ++host) { - if ((*host)->getIPv6SubnetID() != SUBNET_ID_GLOBAL) { - host_map[(*host)->getIPv6SubnetID()] = *host; + for (auto const& host : hosts) { + if (host->getIPv6SubnetID() != SUBNET_ID_GLOBAL) { + host_map[host->getIPv6SubnetID()] = host; } } } @@ -621,7 +621,7 @@ AllocEngine::allocateLeases6(ClientContext6& ctx) { // If there are any leases allocated, let's store in them in the // IA context so as they are available when we process subsequent // IAs. - BOOST_FOREACH(Lease6Ptr lease, leases) { + for (auto const& lease : leases) { ctx.addAllocatedResource(lease->addr_, lease->prefixlen_); ctx.new_leases_.push_back(lease); } @@ -1148,7 +1148,7 @@ AllocEngine::allocateReservedLeases6(ClientContext6& ctx, // We want to avoid allocating new lease for an IA if there is already // a valid lease for which client has reservation. So, we first check if // we already have a lease for a reserved address or prefix. - BOOST_FOREACH(const Lease6Ptr& lease, existing_leases) { + for (auto const& lease : existing_leases) { if ((lease->valid_lft_ != 0)) { if ((ctx.hosts_.count(lease->subnet_id_) > 0) && ctx.hosts_[lease->subnet_id_]->hasReservation(makeIPv6Resrv(*lease))) { @@ -1218,7 +1218,7 @@ AllocEngine::allocateReservedLeases6(ClientContext6& ctx, // Get the IPv6 reservations of specified type. const IPv6ResrvRange& reservs = host->getIPv6Reservations(type); - BOOST_FOREACH(IPv6ResrvTuple type_lease_tuple, reservs) { + BOOST_FOREACH(auto const& type_lease_tuple, reservs) { // We do have a reservation for address or prefix. const IOAddress& addr = type_lease_tuple.second.getPrefix(); uint8_t prefix_len = type_lease_tuple.second.getPrefixLen(); @@ -1318,7 +1318,7 @@ AllocEngine::allocateGlobalReservedLeases6(ClientContext6& ctx, // We want to avoid allocating a new lease for an IA if there is already // a valid lease for which client has reservation. So, we first check if // we already have a lease for a reserved address or prefix. - BOOST_FOREACH(const Lease6Ptr& lease, existing_leases) { + for (auto const& lease : existing_leases) { if ((lease->valid_lft_ != 0) && (ghost->hasReservation(makeIPv6Resrv(*lease)))) { // We found existing lease for a reserved address or prefix. @@ -1357,7 +1357,7 @@ AllocEngine::allocateGlobalReservedLeases6(ClientContext6& ctx, IPv6Resrv::TYPE_NA : IPv6Resrv::TYPE_PD; const IPv6ResrvRange& reservs = ghost->getIPv6Reservations(type); - BOOST_FOREACH(IPv6ResrvTuple type_lease_tuple, reservs) { + BOOST_FOREACH(auto const& type_lease_tuple, reservs) { // We do have a reservation for address or prefix. const IOAddress& addr = type_lease_tuple.second.getPrefix(); uint8_t prefix_len = type_lease_tuple.second.getPrefixLen(); @@ -1468,7 +1468,7 @@ AllocEngine::removeNonmatchingReservedLeases6(ClientContext6& ctx, // so the operation shouldn't be that expensive. Lease6Collection copy = existing_leases; - BOOST_FOREACH(const Lease6Ptr& candidate, copy) { + for (auto const& candidate : copy) { // If we have reservation we should check if the reservation is for // the candidate lease. If so, we simply accept the lease. IPv6Resrv resv = makeIPv6Resrv(*candidate); @@ -1576,7 +1576,7 @@ AllocEngine::removeNonmatchingReservedNoHostLeases6(ClientContext6& ctx, // so the operation shouldn't be that expensive. Lease6Collection copy = existing_leases; - BOOST_FOREACH(const Lease6Ptr& candidate, copy) { + for (auto const& candidate : copy) { // Lease can be allocated to us from a dynamic pool, but we must // check if this lease belongs to any allowed pool. If it does, // we can proceed to checking the next lease. @@ -1657,7 +1657,7 @@ AllocEngine::removeNonreservedLeases6(ClientContext6& ctx, lease != existing_leases.end(); ++lease) { // If there is reservation for this keep it. - IPv6Resrv resv = makeIPv6Resrv(*(*lease)); + IPv6Resrv resv = makeIPv6Resrv(**lease); if (ctx.hasGlobalReservation(resv) || ((ctx.hosts_.count((*lease)->subnet_id_) > 0) && (ctx.hosts_[(*lease)->subnet_id_]->hasReservation(resv)))) { @@ -1883,9 +1883,8 @@ AllocEngine::getLifetimes6(ClientContext6& ctx, uint32_t& preferred, uint32_t& v // Iterate over the assigned class definitions. int have_both = 0; - for (auto name = classes.cbegin(); - name != classes.cend() && have_both < 2; ++name) { - ClientClassDefPtr cl = dict->findClass(*name); + for (auto const& name : classes) { + ClientClassDefPtr cl = dict->findClass(name); if (candidate_preferred.unspecified() && (cl && (!cl->getPreferred().unspecified()))) { candidate_preferred = cl->getPreferred(); @@ -1897,6 +1896,9 @@ AllocEngine::getLifetimes6(ClientContext6& ctx, uint32_t& preferred, uint32_t& v candidate_valid = cl->getValid(); ++have_both; } + if (have_both == 2) { + break; + } } } @@ -2139,25 +2141,25 @@ AllocEngine::renewLeases6(ClientContext6& ctx) { } // Extend all existing leases that passed all checks. - for (Lease6Collection::iterator l = leases.begin(); l != leases.end(); ++l) { - if (ctx.currentIA().isNewResource((*l)->addr_, - (*l)->prefixlen_)) { + for (auto const& l : leases) { + if (ctx.currentIA().isNewResource(l->addr_, + l->prefixlen_)) { // This lease was just created so is already extended. continue; } LOG_DEBUG(alloc_engine_logger, ALLOC_ENGINE_DBG_TRACE_DETAIL, ALLOC_ENGINE_V6_EXTEND_LEASE) .arg(ctx.query_->getLabel()) - .arg((*l)->typeToText((*l)->type_)) - .arg((*l)->addr_); - extendLease6(ctx, *l); + .arg(l->typeToText(l->type_)) + .arg(l->addr_); + extendLease6(ctx, l); } if (!leases.empty()) { // If there are any leases allocated, let's store in them in the // IA context so as they are available when we process subsequent // IAs. - BOOST_FOREACH(Lease6Ptr lease, leases) { + for (auto const& lease : leases) { ctx.addAllocatedResource(lease->addr_, lease->prefixlen_); ctx.new_leases_.push_back(lease); } @@ -2418,9 +2420,8 @@ AllocEngine::extendLease6(ClientContext6& ctx, Lease6Ptr lease) { Lease6Collection AllocEngine::updateLeaseData(ClientContext6& ctx, const Lease6Collection& leases) { Lease6Collection updated_leases; - for (Lease6Collection::const_iterator lease_it = leases.begin(); - lease_it != leases.end(); ++lease_it) { - Lease6Ptr lease(new Lease6(**lease_it)); + for (auto const& lease_it : leases) { + Lease6Ptr lease(new Lease6(*lease_it)); if (ctx.currentIA().isNewResource(lease->addr_, lease->prefixlen_)) { // This lease was just created so is already up to date. updated_leases.push_back(lease); @@ -2452,14 +2453,14 @@ AllocEngine::updateLeaseData(ClientContext6& ctx, const Lease6Collection& leases } bool fqdn_changed = ((lease->type_ != Lease::TYPE_PD) && - !(lease->hasIdenticalFqdn(**lease_it))); + !(lease->hasIdenticalFqdn(*lease_it))); lease->cltt_ = time(NULL); if (!fqdn_changed) { setLeaseReusable(lease, current_preferred_lft, ctx); } if (lease->reuseable_valid_lft_ == 0) { - ctx.currentIA().changed_leases_.push_back(*lease_it); + ctx.currentIA().changed_leases_.push_back(lease_it); LeaseMgrFactory::instance().updateLease6(lease); } @@ -2575,7 +2576,7 @@ AllocEngine::reclaimExpiredLeases6Internal(const size_t max_leases, } size_t leases_processed = 0; - BOOST_FOREACH(Lease6Ptr lease, leases) { + for (auto const& lease : leases) { try { // Reclaim the lease. @@ -2738,7 +2739,7 @@ AllocEngine::reclaimExpiredLeases4Internal(const size_t max_leases, } size_t leases_processed = 0; - BOOST_FOREACH(Lease4Ptr lease, leases) { + for (auto const& lease : leases) { try { // Reclaim the lease. @@ -3502,10 +3503,10 @@ void findClientLease(AllocEngine::ClientContext4& ctx, Lease4Ptr& client_lease) // explicitly configured to ignore client identifiers for this subnet // check if there is a lease within this subnet. if (subnet->getMatchClientId()) { - for (auto l = leases_client_id.begin(); l != leases_client_id.end(); ++l) { - if ((*l)->subnet_id_ == subnet->getID()) { + for (auto const& l : leases_client_id) { + if (l->subnet_id_ == subnet->getID()) { // Lease found, so stick to this lease. - client_lease = (*l); + client_lease = l; ctx.subnet_ = subnet; return; } @@ -3530,9 +3531,8 @@ void findClientLease(AllocEngine::ClientContext4& ctx, Lease4Ptr& client_lease) // Try to find the lease that matches current subnet and belongs to // this client, so both HW address and client identifier match. - for (Lease4Collection::const_iterator client_lease_it = leases_hw_address.begin(); - client_lease_it != leases_hw_address.end(); ++client_lease_it) { - Lease4Ptr existing_lease = *client_lease_it; + for (auto const& client_lease_it : leases_hw_address) { + Lease4Ptr existing_lease = client_lease_it; if ((existing_lease->subnet_id_ == subnet->getID()) && existing_lease->belongsToClient(ctx.hwaddr_, client_id)) { // Found the lease of this client, so return it. @@ -3760,9 +3760,9 @@ AllocEngine::findReservation(ClientContext4& ctx) { // Store the hosts in the temporary map, because some hosts may // belong to subnets outside of the shared network. We'll need // to eliminate them. - for (auto host = hosts.begin(); host != hosts.end(); ++host) { - if ((*host)->getIPv4SubnetID() != SUBNET_ID_GLOBAL) { - host_map[(*host)->getIPv4SubnetID()] = *host; + for (auto const& host : hosts) { + if (host->getIPv4SubnetID() != SUBNET_ID_GLOBAL) { + host_map[host->getIPv4SubnetID()] = host; } } } @@ -4172,9 +4172,8 @@ AllocEngine::getOfferLft(const ClientContext4& ctx) { CfgMgr::instance().getCurrentCfg()->getClientClassDictionary(); // Iterate over the assigned class definitions. - for (ClientClasses::const_iterator name = classes.cbegin(); - name != classes.cend(); ++name) { - ClientClassDefPtr cl = dict->findClass(*name); + for (auto const& name : classes) { + ClientClassDefPtr cl = dict->findClass(name); if (cl && (!cl->getOfferLft().unspecified())) { offer_lft = cl->getOfferLft(); break; @@ -4217,9 +4216,8 @@ AllocEngine::getValidLft(const ClientContext4& ctx) { CfgMgr::instance().getCurrentCfg()->getClientClassDictionary(); // Iterate over the assigned class definitions. - for (ClientClasses::const_iterator name = classes.cbegin(); - name != classes.cend(); ++name) { - ClientClassDefPtr cl = dict->findClass(*name); + for (auto const& name : classes) { + ClientClassDefPtr cl = dict->findClass(name); if (cl && (!cl->getValid().unspecified())) { candidate_lft = cl->getValid(); break; |