]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3692] Address review comments.
authorMarcin Siodelski <marcin@isc.org>
Tue, 3 Feb 2015 15:42:29 +0000 (16:42 +0100)
committerMarcin Siodelski <marcin@isc.org>
Tue, 3 Feb 2015 15:42:29 +0000 (16:42 +0100)
Replaced the do-while loop with the for loop in the allocateLease4. Also,
updated the copyright date.

src/lib/dhcpsrv/alloc_engine.cc
src/lib/dhcpsrv/tests/alloc_engine_unittest.cc

index ebc37256f880dd3ac5eda6615bc4f40415b5586b..38eb92bb30fdd6840c716de3ed37b2b2dc322131 100644 (file)
@@ -21,6 +21,7 @@
 #include <hooks/hooks_manager.h>
 
 #include <cstring>
+#include <limits>
 #include <vector>
 #include <string.h>
 
@@ -405,8 +406,13 @@ AllocEngine::allocateLeases6(const Subnet6Ptr& subnet, const DuidPtr& duid,
         // left), but this has one major problem. We exactly control allocation
         // moment, but we currently do not control expiration time at all
 
-        unsigned int i = attempts_;
-        do {
+        // Initialize the maximum number of attempts to pick and allocate an
+        // address. The value of 0 means "infinite", which is maximum uint32_t
+        // value.
+        uint32_t max_attempts = (attempts_ == 0) ?
+            std::numeric_limits<uint32_t>::max() : attempts_;
+
+        for (uint32_t i = 0; i < max_attempts; ++i) {
             IOAddress candidate = allocator->pickAddress(subnet, duid, hint);
 
             /// @todo: check if the address is reserved once we have host support
@@ -461,11 +467,7 @@ AllocEngine::allocateLeases6(const Subnet6Ptr& subnet, const DuidPtr& duid,
                     return (collection);
                 }
             }
-
-            // Continue trying allocation until we run out of attempts
-            // (or attempts are set to 0, which means infinite)
-            --i;
-        } while ((i > 0) || !attempts_);
+        }
 
         // Unable to allocate an address, return an empty lease.
         LOG_WARN(dhcpsrv_logger, DHCPSRV_ADDRESS6_ALLOC_FAIL).arg(attempts_);
index d2c16611e9a57314fcea81d1a31410336f6cca49..a5d2fac63ced79f2a6daae096f420092cd9d8040 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2012-2014 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2015 Internet Systems Consortium, Inc. ("ISC")
 //
 // Permission to use, copy, modify, and/or distribute this software for any
 // purpose with or without fee is hereby granted, provided that the above