Browse Source

[3677] Leases that no longer match subnet info are now removed.

Tomek Mrugalski 10 years ago
parent
commit
d5804e99b5
2 changed files with 21 additions and 1 deletions
  1. 7 1
      src/bin/dhcp6/tests/rebind_unittest.cc
  2. 14 0
      src/lib/dhcpsrv/alloc_engine.cc

+ 7 - 1
src/bin/dhcp6/tests/rebind_unittest.cc

@@ -250,15 +250,21 @@ TEST_F(RebindTest, directClientChangingSubnet) {
     configure(REBIND_CONFIGS[1], *client.getServer());
     // Try to rebind, using the address that the client had acquired using
     // previous server configuration.
+
     ASSERT_NO_THROW(client.doRebind());
+
     // We are expecting that the server didn't extend the lease because
     // the address that client is using doesn't match the new subnet.
     // But, the client still has an old lease.
     ASSERT_EQ(1, client.getLeaseNum());
     Lease6 lease_client2 = client.getLease(0);
+
     // The current lease should be exactly the same as old lease,
     // because server shouldn't have extended.
-    EXPECT_TRUE(lease_client == lease_client2);
+    EXPECT_TRUE(lease_client.addr_ == lease_client2.addr_);
+    EXPECT_EQ(0, lease_client2.preferred_lft_);
+    EXPECT_EQ(0, lease_client2.valid_lft_);
+
     // Make sure, that the lease that client has, is matching the lease
     // in the lease database.
     Lease6Ptr lease_server2 = checkLease(lease_client2);

+ 14 - 0
src/lib/dhcpsrv/alloc_engine.cc

@@ -1693,6 +1693,20 @@ AllocEngine::extendLease6(ClientContext6& ctx, Lease6Ptr lease) {
         return;
     }
 
+    // Check if the lease still belongs to the subnet. If it doesn't,
+    // we'll need to remove it.
+    if ((lease->type_ != Lease::TYPE_PD) && !ctx.subnet_->inRange(lease->addr_)) {
+        // Oh dear, the lease is no longer valid. We need to get rid of it.
+
+        // Remove this lease from LeaseMgr
+        LeaseMgrFactory::instance().deleteLease(lease->addr_);
+
+        // Add it to the removed leases list.
+        ctx.old_leases_.push_back(lease);
+
+        return;
+    }
+
     // Keep the old data in case the callout tells us to skip update.
     Lease6 old_data = *lease;