]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1405] checking out of pool reservations should be done only if in subnet is true
authorRazvan Becheriu <razvan@isc.org>
Tue, 17 Nov 2020 08:48:00 +0000 (10:48 +0200)
committerRazvan Becheriu <razvan@isc.org>
Wed, 18 Nov 2020 13:55:24 +0000 (15:55 +0200)
src/lib/dhcpsrv/alloc_engine.cc

index f869a3d4b951782bc3bf8f4d19e3e28dc3284239..0c0425cc03345f7ced794bf95fbd0dbb371cfe73 100644 (file)
@@ -621,7 +621,7 @@ AllocEngine::findReservation(ClientContext6& ctx) {
         (network->getAllSubnets()->size() > ctx.host_identifiers_.size());
 
     if (use_single_query) {
-        for (auto id_pair : ctx.host_identifiers_) {
+        for (const auto id_pair : ctx.host_identifiers_) {
             ConstHostCollection hosts = HostMgr::instance().getAll(id_pair.first,
                                                                    &id_pair.second[0],
                                                                    id_pair.second.size());
@@ -645,7 +645,7 @@ AllocEngine::findReservation(ClientContext6& ctx) {
             subnet->getReservationsInSubnet()) {
             // Iterate over configured identifiers in the order of preference
             // and try to use each of them to search for the reservations.
-            for (auto id_pair : ctx.host_identifiers_) {
+            for (const auto id_pair : ctx.host_identifiers_) {
                 if (use_single_query) {
                     if (host_map.count(subnet->getID()) > 0) {
                         ctx.hosts_[subnet->getID()] = host_map[subnet->getID()];
@@ -931,8 +931,8 @@ AllocEngine::allocateUnreservedLeases6(ClientContext6& ctx) {
             // The out-of-pool flag indicates that no client should be assigned reservations
             // from within the dynamic pool, and for that reason we only look at reservations that
             // are outside the pools, hence the inPool check.
-            if ((in_subnet && !out_of_pool) ||
-                (out_of_pool && (!ctx.subnet_->inPool(ctx.currentIA().type_, hint)))) {
+            if (in_subnet && (!out_of_pool ||
+                !ctx.subnet_->inPool(ctx.currentIA().type_, hint))) {
                 hosts = getIPv6Resrv(subnet->getID(), hint);
             }
 
@@ -969,8 +969,8 @@ AllocEngine::allocateUnreservedLeases6(ClientContext6& ctx) {
             // The out-of-pool flag indicates that no client should be assigned reservations
             // from within the dynamic pool, and for that reason we only look at reservations that
             // are outside the pools, hence the inPool check.
-            if ((in_subnet && !out_of_pool) ||
-                (out_of_pool && (!ctx.subnet_->inPool(ctx.currentIA().type_, hint)))) {
+            if (in_subnet && (!out_of_pool ||
+                !ctx.subnet_->inPool(ctx.currentIA().type_, hint))) {
                 hosts = getIPv6Resrv(subnet->getID(), hint);
             }
 
@@ -1277,8 +1277,8 @@ AllocEngine::allocateReservedLeases6(ClientContext6& ctx,
             // The out-of-pool flag indicates that no client should be assigned reservations
             // from within the dynamic pool, and for that reason we only look at reservations that
             // are outside the pools, hence the inPool check.
-            if ((in_subnet && !out_of_pool) ||
-                (out_of_pool && (!subnet->inPool(ctx.currentIA().type_, addr)))) {
+            if (in_subnet && (!out_of_pool ||
+                !subnet->inPool(ctx.currentIA().type_, addr))) {
             } else {
                 continue;
             }
@@ -1480,8 +1480,8 @@ AllocEngine::removeNonmatchingReservedLeases6(ClientContext6& ctx,
     }
     // If host reservation is disabled (so there are no reserved leases)
     // use the simplified version.
-    if (!ctx.subnet_->getReservationsGlobal() &&
-        !ctx.subnet_->getReservationsInSubnet()) {
+    if (!ctx.subnet_->getReservationsInSubnet() &&
+        !ctx.subnet_->getReservationsGlobal()) {
         removeNonmatchingReservedNoHostLeases6(ctx, existing_leases);
         return;
     }
@@ -2974,8 +2974,8 @@ addressReserved(const IOAddress& address, const AllocEngine::ClientContext4& ctx
     // The out-of-pool flag indicates that no client should be assigned reservations
     // from within the dynamic pool, and for that reason we only look at reservations that
     // are outside the pools, hence the inPool check.
-    if ((in_subnet && !out_of_pool) ||
-        (out_of_pool && (!ctx.subnet_->inPool(Lease::TYPE_V4, address)))) {
+    if (in_subnet && (!out_of_pool ||
+        !ctx.subnet_->inPool(Lease::TYPE_V4, address))) {
         // The global parameter ip-reservations-unique controls whether it is allowed
         // to specify multiple reservations for the same IP address or delegated prefix
         // or IP reservations must be unique. Some host backends do not support the
@@ -2997,7 +2997,7 @@ addressReserved(const IOAddress& address, const AllocEngine::ClientContext4& ctx
         }
 
         for (auto host : hosts) {
-            for (auto id : ctx.host_identifiers_) {
+            for (const auto id : ctx.host_identifiers_) {
                 // If we find the matching host we know that this address is reserved
                 // for us and we can return immediately.
                 if (id.first == host->getIdentifierType() &&
@@ -3061,8 +3061,8 @@ hasAddressReservation(AllocEngine::ClientContext4& ctx) {
         if (host != ctx.hosts_.end()) {
             auto reservation = host->second->getIPv4Reservation();
             if (!reservation.isV4Zero() &&
-                ((in_subnet && !out_of_pool) ||
-                 (out_of_pool && !subnet->inPool(Lease::TYPE_V4, reservation)))) {
+                in_subnet && (!out_of_pool ||
+                !subnet->inPool(Lease::TYPE_V4, reservation))) {
                 ctx.subnet_ = subnet;
                 return (true);
             }
@@ -3362,12 +3362,10 @@ AllocEngine::findReservation(ClientContext4& ctx) {
         (network->getAllSubnets()->size() > ctx.host_identifiers_.size());
 
     if (use_single_query) {
-        for (auto id_pair = ctx.host_identifiers_.begin();
-             id_pair != ctx.host_identifiers_.end();
-             ++id_pair) {
-            ConstHostCollection hosts = HostMgr::instance().getAll(id_pair->first,
-                                                                   &id_pair->second[0],
-                                                                   id_pair->second.size());
+        for (const auto id_pair : ctx.host_identifiers_) {
+            ConstHostCollection hosts = HostMgr::instance().getAll(id_pair.first,
+                                                                   &id_pair.second[0],
+                                                                   id_pair.second.size());
             // 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.
@@ -3388,7 +3386,7 @@ AllocEngine::findReservation(ClientContext4& ctx) {
             subnet->getReservationsInSubnet()) {
             // Iterate over configured identifiers in the order of preference
             // and try to use each of them to search for the reservations.
-            BOOST_FOREACH(const IdentifierPair& id_pair, ctx.host_identifiers_) {
+            for (const IdentifierPair& id_pair : ctx.host_identifiers_) {
                 if (use_single_query) {
                     if (host_map.count(subnet->getID()) > 0) {
                         ctx.hosts_[subnet->getID()] = host_map[subnet->getID()];
@@ -3420,7 +3418,7 @@ AllocEngine::findReservation(ClientContext4& ctx) {
 ConstHostPtr
 AllocEngine::findGlobalReservation(ClientContext4& ctx) {
     ConstHostPtr host;
-    BOOST_FOREACH(const IdentifierPair& id_pair, ctx.host_identifiers_) {
+    for (const IdentifierPair& id_pair : ctx.host_identifiers_) {
         // Attempt to find a host using a specified identifier.
         host = HostMgr::instance().get4(SUBNET_ID_GLOBAL, id_pair.first,
                                         &id_pair.second[0], id_pair.second.size());