]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3564] Fix failing unit tests after the updates to the allocation engine.
authorMarcin Siodelski <marcin@isc.org>
Thu, 11 Dec 2014 21:19:10 +0000 (22:19 +0100)
committerMarcin Siodelski <marcin@isc.org>
Thu, 11 Dec 2014 21:19:10 +0000 (22:19 +0100)
src/bin/dhcp4/dhcp4_srv.cc
src/bin/dhcp4/tests/dhcp4_test_utils.cc
src/bin/dhcp4/tests/dhcp4_test_utils.h
src/lib/dhcpsrv/alloc_engine.cc

index 41fcc1c9161feae092d9efd80b0b4aca65c45813..388237b6e15402aa6d145e925805a505ab7de6fa 100644 (file)
@@ -957,14 +957,17 @@ Dhcpv4Srv::assignLease(const Pkt4Ptr& question, Pkt4Ptr& answer) {
     OptionCustomPtr opt_serverid = boost::dynamic_pointer_cast<
         OptionCustom>(question->getOption(DHO_DHCP_SERVER_IDENTIFIER));
 
-    // Try to get the Requested IP Address option and use the address as a hint
-    // for the allocation engine. If the server doesn't already have a lease
-    // for this client it will try to allocate the one requested.
+    // Check if the client has sent a requested IP address option or
+    // ciaddr.
     OptionCustomPtr opt_requested_address = boost::dynamic_pointer_cast<
         OptionCustom>(question->getOption(DHO_DHCP_REQUESTED_ADDRESS));
     IOAddress hint("0.0.0.0");
     if (opt_requested_address) {
         hint = opt_requested_address->readAddress();
+
+    } else if (question->getCiaddr() != IOAddress("0.0.0.0")) {
+        hint = question->getCiaddr();
+
     }
 
     HWAddrPtr hwaddr = question->getHWAddr();
index 62c2647a2877f28fe404d86188c3b128779c407f..be9c64a09e8a88ab77f39a080bc71e8e65ec508b 100644 (file)
@@ -283,10 +283,11 @@ void Dhcpv4SrvTest::checkAddressParams(const Pkt4Ptr& rsp,
     }
 }
 
-void Dhcpv4SrvTest::checkResponse(const Pkt4Ptr& rsp, uint8_t expected_message_type,
+void Dhcpv4SrvTest::checkResponse(const Pkt4Ptr& rsp, int expected_message_type,
                                   uint32_t expected_transid) {
     ASSERT_TRUE(rsp);
-    EXPECT_EQ(expected_message_type, rsp->getType());
+    EXPECT_EQ(expected_message_type,
+              static_cast<int>(rsp->getType()));
     EXPECT_EQ(expected_transid, rsp->getTransid());
 }
 
index d24ed330995737775d6059d4e1aa0ae8a669d1ec..e4426c5d9e2dc41ebae0f21b14df514b16c01dad 100644 (file)
@@ -307,7 +307,7 @@ public:
     /// @param rsp response packet to be validated
     /// @param expected_message_type expected message type
     /// @param expected_transid expected transaction-id
-    void checkResponse(const Pkt4Ptr& rsp, uint8_t expected_message_type,
+    void checkResponse(const Pkt4Ptr& rsp, int expected_message_type,
                        uint32_t expected_transid);
 
     /// @brief Checks if the lease sent to client is present in the database
index 18fdf3218bd4b24e413e760902aa81b6a9f447d0..da01823af664524933e7e4d94535fb3b053350f2 100644 (file)
@@ -1027,8 +1027,17 @@ AllocEngine::reallocateClientLease(Lease4Ptr& lease,
     // Save the old lease, before renewal.
     ctx.old_lease_.reset(new Lease4(*lease));
 
+    /// The client's address will need to be modified in case if:
+    /// - There is a reservation for the client (likely new one) and
+    ///   the currently used address is different.
+    /// - Client requested some IP address and the requested address
+    ///   is different than the currently used one. Note that if this
+    ///   is a DHCPDISCOVER the requested IP address is ignored when
+    ///   it doesn't match the one in use.
     if ((ctx.host_ && (ctx.host_->getIPv4Reservation() != lease->addr_)) ||
-        (lease->addr_ != ctx.requested_address_)) {
+        (!ctx.fake_allocation_ &&
+         (ctx.requested_address_ != IOAddress("0.0.0.0")) &&
+         (lease->addr_ != ctx.requested_address_))) {
         lease = replaceClientLease(lease, ctx);
         return (lease);