]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[master] Merge branch 'trac3690'
authorMarcin Siodelski <marcin@isc.org>
Tue, 10 Feb 2015 18:20:00 +0000 (19:20 +0100)
committerMarcin Siodelski <marcin@isc.org>
Tue, 10 Feb 2015 18:20:00 +0000 (19:20 +0100)
Conflicts:
src/lib/dhcpsrv/tests/alloc_engine_unittest.cc

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

Simple merge
index 241cea224dd9012f8ebc3218436d0b5b1b102dca,2ac499f2b5c2e061ed1ecdc08da4b4bbb3671b3f..eba3ccf16bcd1522da9c69555253328d110c1e93
@@@ -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