Commit 18dc9853 authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[3083] Extended Allocation Engine API to pass the FQDN data.

parent 231fed6c
......@@ -328,6 +328,9 @@ AllocEngine::allocateAddress4(const SubnetPtr& subnet,
const ClientIdPtr& clientid,
const HWAddrPtr& hwaddr,
const IOAddress& hint,
const bool fwd_dns_update,
const bool rev_dns_update,
const std::string& hostname,
bool fake_allocation,
const isc::hooks::CalloutHandlePtr& callout_handle,
Lease4Ptr& old_lease) {
......@@ -359,7 +362,9 @@ AllocEngine::allocateAddress4(const SubnetPtr& subnet,
old_lease.reset(new Lease4(*existing));
// We have a lease already. This is a returning client, probably after
// its reboot.
existing = renewLease4(subnet, clientid, hwaddr, existing, fake_allocation);
existing = renewLease4(subnet, clientid, hwaddr,
fwd_dns_update, rev_dns_update, hostname,
existing, fake_allocation);
if (existing) {
return (existing);
}
......@@ -375,7 +380,9 @@ AllocEngine::allocateAddress4(const SubnetPtr& subnet,
old_lease.reset(new Lease4(*existing));
// we have a lease already. This is a returning client, probably after
// its reboot.
existing = renewLease4(subnet, clientid, hwaddr, existing, fake_allocation);
existing = renewLease4(subnet, clientid, hwaddr,
fwd_dns_update, rev_dns_update,
hostname, existing, fake_allocation);
// @todo: produce a warning. We haven't found him using MAC address, but
// we found him using client-id
if (existing) {
......@@ -393,7 +400,9 @@ AllocEngine::allocateAddress4(const SubnetPtr& subnet,
// The hint is valid and not currently used, let's create a lease for it
Lease4Ptr lease = createLease4(subnet, clientid, hwaddr, hint,
callout_handle, fake_allocation);
fwd_dns_update, rev_dns_update,
hostname, callout_handle,
fake_allocation);
// It can happen that the lease allocation failed (we could have lost
// the race condition. That means that the hint is lo longer usable and
......@@ -406,7 +415,9 @@ AllocEngine::allocateAddress4(const SubnetPtr& subnet,
// Save the old lease, before reusing it.
old_lease.reset(new Lease4(*existing));
return (reuseExpiredLease(existing, subnet, clientid, hwaddr,
callout_handle, fake_allocation));
fwd_dns_update, rev_dns_update,
hostname, callout_handle,
fake_allocation));
}
}
......@@ -439,7 +450,9 @@ AllocEngine::allocateAddress4(const SubnetPtr& subnet,
if (!existing) {
// there's no existing lease for selected candidate, so it is
// free. Let's allocate it.
Lease4Ptr lease = createLease4(subnet, clientid, hwaddr, candidate,
Lease4Ptr lease = createLease4(subnet, clientid, hwaddr,
candidate, fwd_dns_update,
rev_dns_update, hostname,
callout_handle, fake_allocation);
if (lease) {
return (lease);
......@@ -453,7 +466,9 @@ AllocEngine::allocateAddress4(const SubnetPtr& subnet,
// Save old lease before reusing it.
old_lease.reset(new Lease4(*existing));
return (reuseExpiredLease(existing, subnet, clientid, hwaddr,
callout_handle, fake_allocation));
fwd_dns_update, rev_dns_update,
hostname, callout_handle,
fake_allocation));
}
}
......@@ -476,6 +491,9 @@ AllocEngine::allocateAddress4(const SubnetPtr& subnet,
Lease4Ptr AllocEngine::renewLease4(const SubnetPtr& subnet,
const ClientIdPtr& clientid,
const HWAddrPtr& hwaddr,
const bool fwd_dns_update,
const bool rev_dns_update,
const std::string& hostname,
const Lease4Ptr& lease,
bool fake_allocation /* = false */) {
......@@ -486,6 +504,9 @@ Lease4Ptr AllocEngine::renewLease4(const SubnetPtr& subnet,
lease->t1_ = subnet->getT1();
lease->t2_ = subnet->getT2();
lease->valid_lft_ = subnet->getValid();
lease->fqdn_fwd_ = fwd_dns_update;
lease->fqdn_rev_ = rev_dns_update;
lease->hostname_ = hostname;
if (!fake_allocation) {
// for REQUEST we do update the lease
......@@ -576,6 +597,9 @@ Lease4Ptr AllocEngine::reuseExpiredLease(Lease4Ptr& expired,
const SubnetPtr& subnet,
const ClientIdPtr& clientid,
const HWAddrPtr& hwaddr,
const bool fwd_dns_update,
const bool rev_dns_update,
const std::string& hostname,
const isc::hooks::CalloutHandlePtr& callout_handle,
bool fake_allocation /*= false */ ) {
......@@ -592,9 +616,9 @@ Lease4Ptr AllocEngine::reuseExpiredLease(Lease4Ptr& expired,
expired->cltt_ = time(NULL);
expired->subnet_id_ = subnet->getID();
expired->fixed_ = false;
expired->hostname_ = std::string("");
expired->fqdn_fwd_ = false;
expired->fqdn_rev_ = false;
expired->hostname_ = hostname;
expired->fqdn_fwd_ = fwd_dns_update;
expired->fqdn_rev_ = rev_dns_update;
/// @todo: log here that the lease was reused (there's ticket #2524 for
/// logging in libdhcpsrv)
......@@ -732,6 +756,9 @@ Lease4Ptr AllocEngine::createLease4(const SubnetPtr& subnet,
const DuidPtr& clientid,
const HWAddrPtr& hwaddr,
const IOAddress& addr,
const bool fwd_dns_update,
const bool rev_dns_update,
const std::string& hostname,
const isc::hooks::CalloutHandlePtr& callout_handle,
bool fake_allocation /*= false */ ) {
if (!hwaddr) {
......@@ -750,6 +777,11 @@ Lease4Ptr AllocEngine::createLease4(const SubnetPtr& subnet,
subnet->getT1(), subnet->getT2(), now,
subnet->getID()));
// Set FQDN specific lease parameters.
lease->fqdn_fwd_ = fwd_dns_update;
lease->fqdn_rev_ = rev_dns_update;
lease->hostname_ = hostname;
// Let's execute all callouts registered for lease4_select
if (callout_handle &&
HooksManager::getHooksManager().calloutsPresent(hook_index_lease4_select_)) {
......
......@@ -212,11 +212,16 @@ protected:
///
/// @param subnet subnet the allocation should come from
/// @param clientid Client identifier
/// @param hwaddr client's hardware address info
/// @param hint a hint that the client provided
/// @param fake_allocation is this real i.e. REQUEST (false) or just picking
/// @param hwaddr Client's hardware address info
/// @param hint A hint that the client provided
/// @param fwd_dns_update Indicates whether forward DNS update will be
/// performed for the client (true) or not (false).
/// @param rev_dns_update Indicates whether reverse DNS update will be
/// performed for the client (true) or not (false).
/// @param hostname A string carrying hostname to be used for DNS updates.
/// @param fake_allocation Is this real i.e. REQUEST (false) or just picking
/// an address for DISCOVER that is not really allocated (true)
/// @param callout_handle a callout handle (used in hooks). A lease callouts
/// @param callout_handle A callout handle (used in hooks). A lease callouts
/// will be executed if this parameter is passed.
/// @param [out] old_lease Holds the pointer to a previous instance of a
/// lease. The NULL pointer indicates that lease didn't exist prior
......@@ -228,6 +233,9 @@ protected:
const ClientIdPtr& clientid,
const HWAddrPtr& hwaddr,
const isc::asiolink::IOAddress& hint,
const bool fwd_dns_update,
const bool rev_dns_update,
const std::string& hostname,
bool fake_allocation,
const isc::hooks::CalloutHandlePtr& callout_handle,
Lease4Ptr& old_lease);
......@@ -241,16 +249,24 @@ protected:
/// to get a new lease. It thinks that it gets a new lease, but in fact
/// we are only renewing the still valid lease for that client.
///
/// @param subnet subnet the client is attached to
/// @param clientid client identifier
/// @param hwaddr client's hardware address
/// @param lease lease to be renewed
/// @param fake_allocation is this real i.e. REQUEST (false) or just picking
/// @param subnet A subnet the client is attached to
/// @param clientid Client identifier
/// @param hwaddr Client's hardware address
/// @param fwd_dns_update Indicates whether forward DNS update will be
/// performed for the client (true) or not (false).
/// @param rev_dns_update Indicates whether reverse DNS update will be
/// performed for the client (true) or not (false).
/// @param hostname A string carrying hostname to be used for DNS updates.
/// @param lease A lease to be renewed
/// @param fake_allocation Is this real i.e. REQUEST (false) or just picking
/// an address for DISCOVER that is not really allocated (true)
Lease4Ptr
renewLease4(const SubnetPtr& subnet,
const ClientIdPtr& clientid,
const HWAddrPtr& hwaddr,
const bool fwd_dns_update,
const bool rev_dns_update,
const std::string& hostname,
const Lease4Ptr& lease,
bool fake_allocation /* = false */);
......@@ -296,20 +312,28 @@ private:
/// into the database. That may fail in some cases, e.g. when there is another
/// allocation process and we lost a race to a specific lease.
///
/// @param subnet subnet the lease is allocated from
/// @param clientid client identifier
/// @param hwaddr client's hardware address
/// @param addr an address that was selected and is confirmed to be available
/// @param subnet Subnet the lease is allocated from
/// @param clientid Client identifier
/// @param hwaddr Client's hardware address
/// @param addr An address that was selected and is confirmed to be available
/// @param fwd_dns_update Indicates whether forward DNS update will be
/// performed for the client (true) or not (false).
/// @param rev_dns_update Indicates whether reverse DNS update will be
/// performed for the client (true) or not (false).
/// @param hostname A string carrying hostname to be used for DNS updates.
/// @param callout_handle a callout handle (used in hooks). A lease callouts
/// will be executed if this parameter is passed (and there are callouts
/// registered)
/// @param fake_allocation is this real i.e. REQUEST (false) or just picking
/// @param fake_allocation Is this real i.e. REQUEST (false) or just picking
/// an address for DISCOVER that is not really allocated (true)
/// @return allocated lease (or NULL in the unlikely case of the lease just
/// becomed unavailable)
Lease4Ptr createLease4(const SubnetPtr& subnet, const DuidPtr& clientid,
const HWAddrPtr& hwaddr,
const isc::asiolink::IOAddress& addr,
const bool fwd_dns_update,
const bool rev_dns_update,
const std::string& hostname,
const isc::hooks::CalloutHandlePtr& callout_handle,
bool fake_allocation = false);
......@@ -349,13 +373,18 @@ private:
/// is updated if this is real (i.e. REQUEST, fake_allocation = false), not
/// dummy allocation request (i.e. DISCOVER, fake_allocation = true).
///
/// @param expired old, expired lease
/// @param subnet subnet the lease is allocated from
/// @param clientid client identifier
/// @param hwaddr client's hardware address
/// @param callout_handle a callout handle (used in hooks). A lease callouts
/// @param expired Old, expired lease
/// @param subnet Subnet the lease is allocated from
/// @param clientid Client identifier
/// @param hwaddr Client's hardware address
/// @param fwd_dns_update Indicates whether forward DNS update will be
/// performed for the client (true) or not (false).
/// @param rev_dns_update Indicates whether reverse DNS update will be
/// performed for the client (true) or not (false).
/// @param hostname A string carrying hostname to be used for DNS updates.
/// @param callout_handle A callout handle (used in hooks). A lease callouts
/// will be executed if this parameter is passed.
/// @param fake_allocation is this real i.e. REQUEST (false) or just picking
/// @param fake_allocation Is this real i.e. REQUEST (false) or just picking
/// an address for DISCOVER that is not really allocated (true)
/// @return refreshed lease
/// @throw BadValue if trying to recycle lease that is still valid
......@@ -363,6 +392,9 @@ private:
const SubnetPtr& subnet,
const ClientIdPtr& clientid,
const HWAddrPtr& hwaddr,
const bool fwd_dns_update,
const bool rev_dns_update,
const std::string& hostname,
const isc::hooks::CalloutHandlePtr& callout_handle,
bool fake_allocation = false);
......
......@@ -613,8 +613,9 @@ TEST_F(AllocEngine4Test, simpleAlloc4) {
ASSERT_TRUE(engine);
Lease4Ptr lease = engine->allocateAddress4(subnet_, clientid_, hwaddr_,
IOAddress("0.0.0.0"), false,
CalloutHandlePtr(),
IOAddress("0.0.0.0"),
false, false, "",
false, CalloutHandlePtr(),
old_lease_);
// The new lease has been allocated, so the old lease should not exist.
EXPECT_FALSE(old_lease_);
......@@ -640,8 +641,9 @@ TEST_F(AllocEngine4Test, fakeAlloc4) {
ASSERT_TRUE(engine);
Lease4Ptr lease = engine->allocateAddress4(subnet_, clientid_, hwaddr_,
IOAddress("0.0.0.0"), true,
CalloutHandlePtr(),
IOAddress("0.0.0.0"),
false, false, "",
true, CalloutHandlePtr(),
old_lease_);
// The new lease has been allocated, so the old lease should not exist.
......@@ -668,6 +670,7 @@ TEST_F(AllocEngine4Test, allocWithValidHint4) {
Lease4Ptr lease = engine->allocateAddress4(subnet_, clientid_, hwaddr_,
IOAddress("192.0.2.105"),
false, false, "",
false, CalloutHandlePtr(),
old_lease_);
// Check that we got a lease
......@@ -711,6 +714,7 @@ TEST_F(AllocEngine4Test, allocWithUsedHint4) {
// twice.
Lease4Ptr lease = engine->allocateAddress4(subnet_, clientid_, hwaddr_,
IOAddress("192.0.2.106"),
false, false, "",
false, CalloutHandlePtr(),
old_lease_);
......@@ -750,6 +754,7 @@ TEST_F(AllocEngine4Test, allocBogusHint4) {
// with the normal allocation
Lease4Ptr lease = engine->allocateAddress4(subnet_, clientid_, hwaddr_,
IOAddress("10.1.1.1"),
false, false, "",
false, CalloutHandlePtr(),
old_lease_);
// Check that we got a lease
......@@ -781,14 +786,17 @@ TEST_F(AllocEngine4Test, allocateAddress4Nulls) {
// Allocations without subnet are not allowed
Lease4Ptr lease = engine->allocateAddress4(SubnetPtr(), clientid_, hwaddr_,
IOAddress("0.0.0.0"), false,
CalloutHandlePtr(), old_lease_);
IOAddress("0.0.0.0"),
false, false, "",
false, CalloutHandlePtr(),
old_lease_);
EXPECT_FALSE(lease);
// Allocations without HW address are not allowed
lease = engine->allocateAddress4(subnet_, clientid_, HWAddrPtr(),
IOAddress("0.0.0.0"), false,
CalloutHandlePtr(),
IOAddress("0.0.0.0"),
false, false, "",
false, CalloutHandlePtr(),
old_lease_);
EXPECT_FALSE(lease);
EXPECT_FALSE(old_lease_);
......@@ -796,8 +804,9 @@ TEST_F(AllocEngine4Test, allocateAddress4Nulls) {
// Allocations without client-id are allowed
clientid_ = ClientIdPtr();
lease = engine->allocateAddress4(subnet_, ClientIdPtr(), hwaddr_,
IOAddress("0.0.0.0"), false,
CalloutHandlePtr(),
IOAddress("0.0.0.0"),
false, false, "",
false, CalloutHandlePtr(),
old_lease_);
// Check that we got a lease
ASSERT_TRUE(lease);
......@@ -903,7 +912,9 @@ TEST_F(AllocEngine4Test, smallPool4) {
subnet_->addPool(pool_);
cfg_mgr.addSubnet4(subnet_);
Lease4Ptr lease = engine->allocateAddress4(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"),
Lease4Ptr lease = engine->allocateAddress4(subnet_, clientid_, hwaddr_,
IOAddress("0.0.0.0"),
false, false, "",
false, CalloutHandlePtr(),
old_lease_);
......@@ -947,8 +958,9 @@ TEST_F(AllocEngine4Test, outOfAddresses4) {
uint8_t hwaddr2[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe};
uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 };
time_t now = time(NULL);
Lease4Ptr lease(new Lease4(addr, hwaddr2, sizeof(hwaddr2), clientid2, sizeof(clientid2),
501, 502, 503, now, subnet_->getID()));
Lease4Ptr lease(new Lease4(addr, hwaddr2, sizeof(hwaddr2), clientid2,
sizeof(clientid2), 501, 502, 503, now,
subnet_->getID()));
lease->cltt_ = time(NULL) - 10; // Allocated 10 seconds ago
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
......@@ -956,8 +968,9 @@ TEST_F(AllocEngine4Test, outOfAddresses4) {
// else, so the allocation should fail
Lease4Ptr lease2 = engine->allocateAddress4(subnet_, clientid_, hwaddr_,
IOAddress("0.0.0.0"), false,
CalloutHandlePtr(),
IOAddress("0.0.0.0"),
false, false, "",
false, CalloutHandlePtr(),
old_lease_);
EXPECT_FALSE(lease2);
EXPECT_FALSE(old_lease_);
......@@ -998,6 +1011,7 @@ TEST_F(AllocEngine4Test, discoverReuseExpiredLease4) {
// CASE 1: Asking for any address
lease = engine->allocateAddress4(subnet_, clientid_, hwaddr_,
IOAddress("0.0.0.0"),
false, false, "",
true, CalloutHandlePtr(),
old_lease_);
// Check that we got that single lease
......@@ -1014,7 +1028,9 @@ TEST_F(AllocEngine4Test, discoverReuseExpiredLease4) {
checkLease4(lease);
// CASE 2: Asking specifically for this address
lease = engine->allocateAddress4(subnet_, clientid_, hwaddr_, IOAddress(addr.toText()),
lease = engine->allocateAddress4(subnet_, clientid_, hwaddr_,
IOAddress(addr.toText()),
false, false, "",
true, CalloutHandlePtr(),
old_lease_);
// Check that we got that single lease
......@@ -1053,8 +1069,9 @@ TEST_F(AllocEngine4Test, requestReuseExpiredLease4) {
// A client comes along, asking specifically for this address
lease = engine->allocateAddress4(subnet_, clientid_, hwaddr_,
IOAddress(addr.toText()), false,
CalloutHandlePtr(),
IOAddress(addr.toText()),
false, false, "",
false, CalloutHandlePtr(),
old_lease_);
// Check that he got that single lease
......@@ -1100,7 +1117,8 @@ TEST_F(AllocEngine4Test, renewLease4) {
// Lease was assigned 45 seconds ago and is valid for 100 seconds. Let's
// renew it.
ASSERT_FALSE(lease->expired());
lease = engine->renewLease4(subnet_, clientid_, hwaddr_, lease, false);
lease = engine->renewLease4(subnet_, clientid_, hwaddr_, false,
false, "", lease, false);
// Check that he got that single lease
ASSERT_TRUE(lease);
EXPECT_EQ(addr.toText(), lease->addr_.toText());
......@@ -1462,6 +1480,7 @@ TEST_F(HookAllocEngine4Test, lease4_select) {
Lease4Ptr lease = engine->allocateAddress4(subnet_, clientid_, hwaddr_,
IOAddress("0.0.0.0"),
false, false, "",
false, callout_handle,
old_lease_);
// Check that we got a lease
......@@ -1525,7 +1544,9 @@ TEST_F(HookAllocEngine4Test, change_lease4_select) {
CalloutHandlePtr callout_handle = HooksManager::createCalloutHandle();
// Call allocateAddress4. Callouts should be triggered here.
Lease4Ptr lease = engine->allocateAddress4(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"),
Lease4Ptr lease = engine->allocateAddress4(subnet_, clientid_, hwaddr_,
IOAddress("0.0.0.0"),
false, false, "",
false, callout_handle,
old_lease_);
// Check that we got a lease
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment