From: Marcin Siodelski Date: Tue, 10 Feb 2015 18:20:00 +0000 (+0100) Subject: [master] Merge branch 'trac3690' X-Git-Tag: trac3712_base~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1afa4e24b0fcdd6d3a2e596663ce1102ffe2340d;p=thirdparty%2Fkea.git [master] Merge branch 'trac3690' Conflicts: src/lib/dhcpsrv/tests/alloc_engine_unittest.cc --- 1afa4e24b0fcdd6d3a2e596663ce1102ffe2340d diff --cc src/lib/dhcpsrv/tests/alloc_engine_unittest.cc index 241cea224d,2ac499f2b5..eba3ccf16b --- a/src/lib/dhcpsrv/tests/alloc_engine_unittest.cc +++ b/src/lib/dhcpsrv/tests/alloc_engine_unittest.cc @@@ -2780,44 -2263,42 +2780,80 @@@ TEST_F(AllocEngine4Test, reservedAddres EXPECT_NE(allocated_lease->addr_.toText(), "192.0.2.100"); } + // This test checks that the client requesting an address which is + // reserved for another client will get no lease or a different + // address will be assigned if the client is sending a DHCPDISCOVER. + TEST_F(AllocEngine4Test, reservedAddressHintUsedByOtherClient) { + // Create a reservation for the client. + HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr_->hwaddr_.size(), + Host::IDENT_HWADDR, subnet_->getID(), + SubnetID(0), IOAddress("192.0.2.100"))); + CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); + CfgMgr::instance().commit(); + + AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 100, false); + + // Different client is requesting this address. + Lease4Ptr allocated_lease = engine.allocateLease4(subnet_, ClientIdPtr(), + hwaddr_, + IOAddress("192.0.2.100"), + false, false, "", false, + CalloutHandlePtr(), + old_lease_); + // The client should get no lease (DHCPNAK). + ASSERT_FALSE(allocated_lease); + + // The same client should get a different lease than requested if + // if is sending a DHCPDISCOVER (fake allocation is true). + allocated_lease = engine.allocateLease4(subnet_, ClientIdPtr(), + hwaddr_, + IOAddress("192.0.2.100"), + false, false, "", true, + CalloutHandlePtr(), + old_lease_); + ASSERT_TRUE(allocated_lease); + // Make sure the lease obtained is for a different address. + EXPECT_NE(allocated_lease->addr_.toText(), "192.0.2.100"); + } + +// This test checks that the allocation engine refuses to allocate an +// address when the pool is exhausted, and the only one available +// address is reserved for a different client. +TEST_F(AllocEngine4Test, reservedAddressShortPool) { + AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 100, false); + + // Create short pool with only one address. + initSubnet(IOAddress("192.0.2.100"), IOAddress("192.0.2.100")); + // Reserve the address for a different client. + HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr_->hwaddr_.size(), + Host::IDENT_HWADDR, subnet_->getID(), + SubnetID(0), IOAddress("192.0.2.100"))); + CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); + CfgMgr::instance().commit(); + + // Allocation engine should determine that the available address is + // reserved for someone else and not allocate it. + Lease4Ptr allocated_lease = engine.allocateLease4(subnet_, ClientIdPtr(), + hwaddr_, + IOAddress("0.0.0.0"), + false, false, "", false, + CalloutHandlePtr(), + old_lease_); + EXPECT_FALSE(allocated_lease); + + // Now, let's remove the reservation. + initSubnet(IOAddress("192.0.2.100"), IOAddress("192.0.2.100")); + CfgMgr::instance().commit(); + + // Address should be successfully allocated. + allocated_lease = engine.allocateLease4(subnet_, ClientIdPtr(), hwaddr_, + IOAddress("0.0.0.0"), false, false, + "", false, CalloutHandlePtr(), + old_lease_); + ASSERT_TRUE(allocated_lease); + EXPECT_EQ("192.0.2.100", allocated_lease->addr_.toText()); +} + /// @brief helper class used in Hooks testing in AllocEngine6 /// /// It features a couple of callout functions and buffers to store