From: Marcin Siodelski Date: Fri, 13 Oct 2017 11:22:08 +0000 (+0200) Subject: [5388] Corrected bug in allocation engine. X-Git-Tag: trac5297_base~4^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=db7182c1c305dcc3b2e5dd54b8c1797edc81e843;p=thirdparty%2Fkea.git [5388] Corrected bug in allocation engine. The bug was manifesting itself in inability to find an existing lease within shared network when client performed DORA without a hint. --- diff --git a/src/bin/dhcp4/tests/shared_network_unittest.cc b/src/bin/dhcp4/tests/shared_network_unittest.cc index 39901d86cd..0326630015 100644 --- a/src/bin/dhcp4/tests/shared_network_unittest.cc +++ b/src/bin/dhcp4/tests/shared_network_unittest.cc @@ -1062,6 +1062,31 @@ TEST_F(Dhcpv4SharedNetworkTest, poolInSharedNetworkShortage) { }); } +// Returning client sends 4-way exchange. +TEST_F(Dhcpv4SharedNetworkTest, returningClientStartsOver) { + // Create client. + Dhcp4Client client(Dhcp4Client::SELECTING); + client.setIfaceName("eth1"); + client.includeClientId("01:02:03:04"); + + // Configure the server with one shared network including two subnets and + // one subnet outside of the shared network. + configure(NETWORKS_CONFIG[0], *client.getServer()); + + // Client requests an address in first subnet within a shared network. + // We'll send a hint of 192.0.2.63 and expect to get it. + testAssigned([this, &client]() { + doDORA(client, "192.0.2.63", "192.0.2.63"); + }); + + + // The client reboots and performs 4-way exchange again without a hint. + // It should be assigned the same (existing) lease. + testAssigned([this, &client]() { + doDORA(client, "192.0.2.63"); + }); +} + // Shared network is selected based on giaddr value (relay specified // on shared network level) TEST_F(Dhcpv4SharedNetworkTest, sharedNetworkSelectedByRelay1) { diff --git a/src/lib/dhcpsrv/alloc_engine.cc b/src/lib/dhcpsrv/alloc_engine.cc index f75f7954a8..55effd88a0 100644 --- a/src/lib/dhcpsrv/alloc_engine.cc +++ b/src/lib/dhcpsrv/alloc_engine.cc @@ -2443,6 +2443,10 @@ void findClientLease(AllocEngine::ClientContext4& ctx, Lease4Ptr& client_lease) // configured to ignore client identifier). if (client_id) { client_lease = lease_mgr.getLease4(*client_id, subnet->getID()); + if (client_lease) { + ctx.subnet_ = subnet; + return; + } } // If no lease found using the client identifier, try the lookup using