From: Tomek Mrugalski Date: Fri, 6 Feb 2015 17:14:10 +0000 (+0100) Subject: [3677] Leases that no longer match subnet info are now removed. X-Git-Tag: trac3712_base~7^2~10 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d5804e99b5d3abbfa008ec6a16b593952e656f72;p=thirdparty%2Fkea.git [3677] Leases that no longer match subnet info are now removed. --- diff --git a/src/bin/dhcp6/tests/rebind_unittest.cc b/src/bin/dhcp6/tests/rebind_unittest.cc index 5a47c3972b..3a7df87579 100644 --- a/src/bin/dhcp6/tests/rebind_unittest.cc +++ b/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); diff --git a/src/lib/dhcpsrv/alloc_engine.cc b/src/lib/dhcpsrv/alloc_engine.cc index 1afd0119e9..43a52dfcd3 100644 --- a/src/lib/dhcpsrv/alloc_engine.cc +++ b/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;