From: Marcin Siodelski Date: Thu, 11 Dec 2014 21:19:10 +0000 (+0100) Subject: [3564] Fix failing unit tests after the updates to the allocation engine. X-Git-Tag: trac3504_base~25^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dd8b2fdc1bf09ebcf431363a8fe498119bf7b696;p=thirdparty%2Fkea.git [3564] Fix failing unit tests after the updates to the allocation engine. --- diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc index 41fcc1c916..388237b6e1 100644 --- a/src/bin/dhcp4/dhcp4_srv.cc +++ b/src/bin/dhcp4/dhcp4_srv.cc @@ -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(); diff --git a/src/bin/dhcp4/tests/dhcp4_test_utils.cc b/src/bin/dhcp4/tests/dhcp4_test_utils.cc index 62c2647a28..be9c64a09e 100644 --- a/src/bin/dhcp4/tests/dhcp4_test_utils.cc +++ b/src/bin/dhcp4/tests/dhcp4_test_utils.cc @@ -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(rsp->getType())); EXPECT_EQ(expected_transid, rsp->getTransid()); } diff --git a/src/bin/dhcp4/tests/dhcp4_test_utils.h b/src/bin/dhcp4/tests/dhcp4_test_utils.h index d24ed33099..e4426c5d9e 100644 --- a/src/bin/dhcp4/tests/dhcp4_test_utils.h +++ b/src/bin/dhcp4/tests/dhcp4_test_utils.h @@ -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 diff --git a/src/lib/dhcpsrv/alloc_engine.cc b/src/lib/dhcpsrv/alloc_engine.cc index 18fdf3218b..da01823af6 100644 --- a/src/lib/dhcpsrv/alloc_engine.cc +++ b/src/lib/dhcpsrv/alloc_engine.cc @@ -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);