Commit 733a15db authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[master] Merge branch 'trac3146' (Abstract LeaseMgr support for PD)

Conflicts:
	ChangeLog
parents 27e895a6 05a05d81
674. [func] tomek
Preparatory work for prefix delegation in LeaseMgr. getLease6()
renamed to getLeases6(). It now can return more than one lease.
(Trac #3146, git 05a05d810be754e7a4d8ca181550867febf6dcc6)
673. [func] tomek 673. [func] tomek
libdhcp: Added support for IA_PD and IAPREFIX options. New class libdhcp: Added support for IA_PD and IAPREFIX options. New class
for IAPREFIX (Option6_IAPrefix) has been added. for IAPREFIX (Option6_IAPrefix) has been added.
......
...@@ -1223,13 +1223,18 @@ Dhcpv6Srv::assignIA_NA(const Subnet6Ptr& subnet, const DuidPtr& duid, ...@@ -1223,13 +1223,18 @@ Dhcpv6Srv::assignIA_NA(const Subnet6Ptr& subnet, const DuidPtr& duid,
// will try to honour the hint, but it is just a hint - some other address // will try to honour the hint, but it is just a hint - some other address
// may be used instead. If fake_allocation is set to false, the lease will // may be used instead. If fake_allocation is set to false, the lease will
// be inserted into the LeaseMgr as well. // be inserted into the LeaseMgr as well.
Lease6Ptr lease = alloc_engine_->allocateAddress6(subnet, duid, Lease6Collection leases = alloc_engine_->allocateAddress6(subnet, duid,
ia->getIAID(), ia->getIAID(),
hint, hint,
do_fwd, do_rev, do_fwd, do_rev,
hostname, hostname,
fake_allocation, fake_allocation,
callout_handle); callout_handle);
/// @todo: Handle more than one lease
Lease6Ptr lease;
if (!leases.empty()) {
lease = *leases.begin();
}
// Create IA_NA that we will put in the response. // Create IA_NA that we will put in the response.
// Do not use OptionDefinition to create option's instance so // Do not use OptionDefinition to create option's instance so
...@@ -1316,7 +1321,8 @@ Dhcpv6Srv::renewIA_NA(const Subnet6Ptr& subnet, const DuidPtr& duid, ...@@ -1316,7 +1321,8 @@ Dhcpv6Srv::renewIA_NA(const Subnet6Ptr& subnet, const DuidPtr& duid,
return (ia_rsp); return (ia_rsp);
} }
Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(*duid, ia->getIAID(), Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease6::LEASE_IA_NA,
*duid, ia->getIAID(),
subnet->getID()); subnet->getID());
if (!lease) { if (!lease) {
...@@ -1579,7 +1585,8 @@ Dhcpv6Srv::releaseIA_NA(const DuidPtr& duid, const Pkt6Ptr& query, ...@@ -1579,7 +1585,8 @@ Dhcpv6Srv::releaseIA_NA(const DuidPtr& duid, const Pkt6Ptr& query,
return (ia_rsp); return (ia_rsp);
} }
Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(release_addr->getAddress()); Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease6::LEASE_IA_NA,
release_addr->getAddress());
if (!lease) { if (!lease) {
// client releasing a lease that we don't know about. // client releasing a lease that we don't know about.
......
...@@ -1024,7 +1024,8 @@ TEST_F(Dhcpv6SrvTest, RenewBasic) { ...@@ -1024,7 +1024,8 @@ TEST_F(Dhcpv6SrvTest, RenewBasic) {
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
// Check that the lease is really in the database // Check that the lease is really in the database
Lease6Ptr l = LeaseMgrFactory::instance().getLease6(addr); Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease6::LEASE_IA_NA,
addr);
ASSERT_TRUE(l); ASSERT_TRUE(l);
// Check that T1, T2, preferred, valid and cltt really set and not using // Check that T1, T2, preferred, valid and cltt really set and not using
...@@ -1116,7 +1117,8 @@ TEST_F(Dhcpv6SrvTest, RenewReject) { ...@@ -1116,7 +1117,8 @@ TEST_F(Dhcpv6SrvTest, RenewReject) {
OptionPtr clientid = generateClientId(); OptionPtr clientid = generateClientId();
// Check that the lease is NOT in the database // Check that the lease is NOT in the database
Lease6Ptr l = LeaseMgrFactory::instance().getLease6(addr); Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease6::LEASE_IA_NA,
addr);
ASSERT_FALSE(l); ASSERT_FALSE(l);
// Let's create a RENEW // Let's create a RENEW
...@@ -1147,7 +1149,7 @@ TEST_F(Dhcpv6SrvTest, RenewReject) { ...@@ -1147,7 +1149,7 @@ TEST_F(Dhcpv6SrvTest, RenewReject) {
checkIA_NAStatusCode(ia, STATUS_NoBinding); checkIA_NAStatusCode(ia, STATUS_NoBinding);
// Check that there is no lease added // Check that there is no lease added
l = LeaseMgrFactory::instance().getLease6(addr); l = LeaseMgrFactory::instance().getLease6(Lease6::LEASE_IA_NA, addr);
ASSERT_FALSE(l); ASSERT_FALSE(l);
// CASE 2: Lease is known and belongs to this client, but to a different IAID // CASE 2: Lease is known and belongs to this client, but to a different IAID
...@@ -1189,7 +1191,7 @@ TEST_F(Dhcpv6SrvTest, RenewReject) { ...@@ -1189,7 +1191,7 @@ TEST_F(Dhcpv6SrvTest, RenewReject) {
ASSERT_TRUE(ia); ASSERT_TRUE(ia);
checkIA_NAStatusCode(ia, STATUS_NoBinding); checkIA_NAStatusCode(ia, STATUS_NoBinding);
lease = LeaseMgrFactory::instance().getLease6(addr); lease = LeaseMgrFactory::instance().getLease6(Lease6::LEASE_IA_NA, addr);
ASSERT_TRUE(lease); ASSERT_TRUE(lease);
// Verify that the lease was not updated. // Verify that the lease was not updated.
EXPECT_EQ(123, lease->cltt_); EXPECT_EQ(123, lease->cltt_);
...@@ -1226,7 +1228,8 @@ TEST_F(Dhcpv6SrvTest, ReleaseBasic) { ...@@ -1226,7 +1228,8 @@ TEST_F(Dhcpv6SrvTest, ReleaseBasic) {
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
// Check that the lease is really in the database // Check that the lease is really in the database
Lease6Ptr l = LeaseMgrFactory::instance().getLease6(addr); Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease6::LEASE_IA_NA,
addr);
ASSERT_TRUE(l); ASSERT_TRUE(l);
// Let's create a RELEASE // Let's create a RELEASE
...@@ -1265,11 +1268,12 @@ TEST_F(Dhcpv6SrvTest, ReleaseBasic) { ...@@ -1265,11 +1268,12 @@ TEST_F(Dhcpv6SrvTest, ReleaseBasic) {
// Check that the lease is really gone in the database // Check that the lease is really gone in the database
// get lease by address // get lease by address
l = LeaseMgrFactory::instance().getLease6(addr); l = LeaseMgrFactory::instance().getLease6(Lease6::LEASE_IA_NA, addr);
ASSERT_FALSE(l); ASSERT_FALSE(l);
// get lease by subnetid/duid/iaid combination // get lease by subnetid/duid/iaid combination
l = LeaseMgrFactory::instance().getLease6(*duid_, iaid, subnet_->getID()); l = LeaseMgrFactory::instance().getLease6(Lease6::LEASE_IA_NA, *duid_, iaid,
subnet_->getID());
ASSERT_FALSE(l); ASSERT_FALSE(l);
} }
...@@ -1301,7 +1305,8 @@ TEST_F(Dhcpv6SrvTest, ReleaseReject) { ...@@ -1301,7 +1305,8 @@ TEST_F(Dhcpv6SrvTest, ReleaseReject) {
OptionPtr clientid = generateClientId(); OptionPtr clientid = generateClientId();
// Check that the lease is NOT in the database // Check that the lease is NOT in the database
Lease6Ptr l = LeaseMgrFactory::instance().getLease6(addr); Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease6::LEASE_IA_NA,
addr);
ASSERT_FALSE(l); ASSERT_FALSE(l);
// Let's create a RELEASE // Let's create a RELEASE
...@@ -1334,7 +1339,7 @@ TEST_F(Dhcpv6SrvTest, ReleaseReject) { ...@@ -1334,7 +1339,7 @@ TEST_F(Dhcpv6SrvTest, ReleaseReject) {
checkMsgStatusCode(reply, STATUS_NoBinding); checkMsgStatusCode(reply, STATUS_NoBinding);
// Check that the lease is not there // Check that the lease is not there
l = LeaseMgrFactory::instance().getLease6(addr); l = LeaseMgrFactory::instance().getLease6(Lease6::LEASE_IA_NA, addr);
ASSERT_FALSE(l); ASSERT_FALSE(l);
// CASE 2: Lease is known and belongs to this client, but to a different IAID // CASE 2: Lease is known and belongs to this client, but to a different IAID
...@@ -1356,7 +1361,7 @@ TEST_F(Dhcpv6SrvTest, ReleaseReject) { ...@@ -1356,7 +1361,7 @@ TEST_F(Dhcpv6SrvTest, ReleaseReject) {
checkMsgStatusCode(reply, STATUS_NoBinding); checkMsgStatusCode(reply, STATUS_NoBinding);
// Check that the lease is still there // Check that the lease is still there
l = LeaseMgrFactory::instance().getLease6(addr); l = LeaseMgrFactory::instance().getLease6(Lease6::LEASE_IA_NA, addr);
ASSERT_TRUE(l); ASSERT_TRUE(l);
// CASE 3: Lease belongs to a client with different client-id // CASE 3: Lease belongs to a client with different client-id
...@@ -1379,7 +1384,7 @@ TEST_F(Dhcpv6SrvTest, ReleaseReject) { ...@@ -1379,7 +1384,7 @@ TEST_F(Dhcpv6SrvTest, ReleaseReject) {
checkMsgStatusCode(reply, STATUS_NoBinding); checkMsgStatusCode(reply, STATUS_NoBinding);
// Check that the lease is still there // Check that the lease is still there
l = LeaseMgrFactory::instance().getLease6(addr); l = LeaseMgrFactory::instance().getLease6(Lease6::LEASE_IA_NA, addr);
ASSERT_TRUE(l); ASSERT_TRUE(l);
// Finally, let's cleanup the database // Finally, let's cleanup the database
......
...@@ -377,7 +377,8 @@ public: ...@@ -377,7 +377,8 @@ public:
boost::shared_ptr<Option6IAAddr> addr) { boost::shared_ptr<Option6IAAddr> addr) {
boost::shared_ptr<Option6IA> ia = boost::dynamic_pointer_cast<Option6IA>(ia_na); boost::shared_ptr<Option6IA> ia = boost::dynamic_pointer_cast<Option6IA>(ia_na);
Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(addr->getAddress()); Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease6::LEASE_IA_NA,
addr->getAddress());
if (!lease) { if (!lease) {
std::cout << "Lease for " << addr->getAddress().toText() std::cout << "Lease for " << addr->getAddress().toText()
<< " not found in the database backend."; << " not found in the database backend.";
......
...@@ -1076,7 +1076,8 @@ TEST_F(HooksDhcpv6SrvTest, basic_lease6_renew) { ...@@ -1076,7 +1076,8 @@ TEST_F(HooksDhcpv6SrvTest, basic_lease6_renew) {
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
// Check that the lease is really in the database // Check that the lease is really in the database
Lease6Ptr l = LeaseMgrFactory::instance().getLease6(addr); Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease6::LEASE_IA_NA,
addr);
ASSERT_TRUE(l); ASSERT_TRUE(l);
// Check that T1, T2, preferred, valid and cltt really set and not using // Check that T1, T2, preferred, valid and cltt really set and not using
...@@ -1172,7 +1173,8 @@ TEST_F(HooksDhcpv6SrvTest, leaseUpdate_lease6_renew) { ...@@ -1172,7 +1173,8 @@ TEST_F(HooksDhcpv6SrvTest, leaseUpdate_lease6_renew) {
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
// Check that the lease is really in the database // Check that the lease is really in the database
Lease6Ptr l = LeaseMgrFactory::instance().getLease6(addr); Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease6::LEASE_IA_NA,
addr);
ASSERT_TRUE(l); ASSERT_TRUE(l);
// Check that T1, T2, preferred, valid and cltt really set and not using // Check that T1, T2, preferred, valid and cltt really set and not using
...@@ -1262,7 +1264,8 @@ TEST_F(HooksDhcpv6SrvTest, skip_lease6_renew) { ...@@ -1262,7 +1264,8 @@ TEST_F(HooksDhcpv6SrvTest, skip_lease6_renew) {
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
// Check that the lease is really in the database // Check that the lease is really in the database
Lease6Ptr l = LeaseMgrFactory::instance().getLease6(addr); Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease6::LEASE_IA_NA,
addr);
ASSERT_TRUE(l); ASSERT_TRUE(l);
// Check that T1, T2, preferred, valid and cltt really set and not using // Check that T1, T2, preferred, valid and cltt really set and not using
...@@ -1293,7 +1296,7 @@ TEST_F(HooksDhcpv6SrvTest, skip_lease6_renew) { ...@@ -1293,7 +1296,7 @@ TEST_F(HooksDhcpv6SrvTest, skip_lease6_renew) {
// Check that our callback was called // Check that our callback was called
EXPECT_EQ("lease6_renew", callback_name_); EXPECT_EQ("lease6_renew", callback_name_);
l = LeaseMgrFactory::instance().getLease6(addr); l = LeaseMgrFactory::instance().getLease6(Lease6::LEASE_IA_NA, addr);
// Check that the old values are still there and they were not // Check that the old values are still there and they were not
// updated by the renewal // updated by the renewal
...@@ -1337,7 +1340,8 @@ TEST_F(HooksDhcpv6SrvTest, basic_lease6_release) { ...@@ -1337,7 +1340,8 @@ TEST_F(HooksDhcpv6SrvTest, basic_lease6_release) {
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
// Check that the lease is really in the database // Check that the lease is really in the database
Lease6Ptr l = LeaseMgrFactory::instance().getLease6(addr); Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease6::LEASE_IA_NA,
addr);
ASSERT_TRUE(l); ASSERT_TRUE(l);
// Let's create a RELEASE // Let's create a RELEASE
...@@ -1375,11 +1379,12 @@ TEST_F(HooksDhcpv6SrvTest, basic_lease6_release) { ...@@ -1375,11 +1379,12 @@ TEST_F(HooksDhcpv6SrvTest, basic_lease6_release) {
// Check that the lease is really gone in the database // Check that the lease is really gone in the database
// get lease by address // get lease by address
l = LeaseMgrFactory::instance().getLease6(addr); l = LeaseMgrFactory::instance().getLease6(Lease6::LEASE_IA_NA, addr);
ASSERT_FALSE(l); ASSERT_FALSE(l);
// Get lease by subnetid/duid/iaid combination // Get lease by subnetid/duid/iaid combination
l = LeaseMgrFactory::instance().getLease6(*duid_, iaid, subnet_->getID()); l = LeaseMgrFactory::instance().getLease6(Lease6::LEASE_IA_NA, *duid_, iaid,
subnet_->getID());
ASSERT_FALSE(l); ASSERT_FALSE(l);
} }
...@@ -1416,7 +1421,8 @@ TEST_F(HooksDhcpv6SrvTest, skip_lease6_release) { ...@@ -1416,7 +1421,8 @@ TEST_F(HooksDhcpv6SrvTest, skip_lease6_release) {
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
// Check that the lease is really in the database // Check that the lease is really in the database
Lease6Ptr l = LeaseMgrFactory::instance().getLease6(addr); Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease6::LEASE_IA_NA,
addr);
ASSERT_TRUE(l); ASSERT_TRUE(l);
// Let's create a RELEASE // Let's create a RELEASE
...@@ -1442,11 +1448,13 @@ TEST_F(HooksDhcpv6SrvTest, skip_lease6_release) { ...@@ -1442,11 +1448,13 @@ TEST_F(HooksDhcpv6SrvTest, skip_lease6_release) {
// Check that the lease is still there // Check that the lease is still there
// get lease by address // get lease by address
l = LeaseMgrFactory::instance().getLease6(addr); l = LeaseMgrFactory::instance().getLease6(Lease6::LEASE_IA_NA,
addr);
ASSERT_TRUE(l); ASSERT_TRUE(l);
// Get lease by subnetid/duid/iaid combination // Get lease by subnetid/duid/iaid combination
l = LeaseMgrFactory::instance().getLease6(*duid_, iaid, subnet_->getID()); l = LeaseMgrFactory::instance().getLease6(Lease6::LEASE_IA_NA, *duid_, iaid,
subnet_->getID());
ASSERT_TRUE(l); ASSERT_TRUE(l);
} }
......
...@@ -195,7 +195,7 @@ AllocEngine::AllocEngine(AllocType engine_type, unsigned int attempts) ...@@ -195,7 +195,7 @@ AllocEngine::AllocEngine(AllocType engine_type, unsigned int attempts)
hook_index_lease6_select_ = Hooks.hook_index_lease6_select_; hook_index_lease6_select_ = Hooks.hook_index_lease6_select_;
} }
Lease6Ptr Lease6Collection
AllocEngine::allocateAddress6(const Subnet6Ptr& subnet, AllocEngine::allocateAddress6(const Subnet6Ptr& subnet,
const DuidPtr& duid, const DuidPtr& duid,
uint32_t iaid, uint32_t iaid,
...@@ -222,40 +222,52 @@ AllocEngine::allocateAddress6(const Subnet6Ptr& subnet, ...@@ -222,40 +222,52 @@ AllocEngine::allocateAddress6(const Subnet6Ptr& subnet,
} }
// check if there's existing lease for that subnet/duid/iaid combination. // check if there's existing lease for that subnet/duid/iaid combination.
Lease6Ptr existing = LeaseMgrFactory::instance().getLease6(*duid, iaid, subnet->getID()); /// @todo: Make this generic (cover temp. addrs and prefixes)
if (existing) { Lease6Collection existing = LeaseMgrFactory::instance().getLeases6(
// we have a lease already. This is a returning client, probably after Lease6::LEASE_IA_NA, *duid, iaid, subnet->getID());
// his reboot.
if (!existing.empty()) {
// we have at least one lease already. This is a returning client,
// probably after his reboot.
return (existing); return (existing);
} }
// check if the hint is in pool and is available // check if the hint is in pool and is available
if (subnet->inPool(hint)) { if (subnet->inPool(hint)) {
existing = LeaseMgrFactory::instance().getLease6(hint);
if (!existing) { /// @todo: We support only one hint for now
Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(
Lease6::LEASE_IA_NA, hint);
if (!lease) {
/// @todo: check if the hint is reserved once we have host support /// @todo: check if the hint is reserved once we have host support
/// implemented /// implemented
// the hint is valid and not currently used, let's create a lease for it // the hint is valid and not currently used, let's create a lease for it
Lease6Ptr lease = createLease6(subnet, duid, iaid, /// @todo: We support only one lease per ia for now
hint, lease = createLease6(subnet, duid, iaid, hint, fwd_dns_update,
fwd_dns_update, rev_dns_update, hostname, callout_handle,
rev_dns_update, hostname, fake_allocation);
callout_handle,
fake_allocation);
// It can happen that the lease allocation failed (we could have lost // 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 // the race condition. That means that the hint is lo longer usable and
// we need to continue the regular allocation path. // we need to continue the regular allocation path.
if (lease) { if (lease) {
return (lease); /// @todo: We support only one lease per ia for now
Lease6Collection collection;
collection.push_back(lease);
return (collection);
} }
} else { } else {
if (existing->expired()) { if (lease->expired()) {
return (reuseExpiredLease(existing, subnet, duid, iaid, /// We found a lease and it is expired, so we can reuse it
/// @todo: We support only one lease per ia for now
lease = reuseExpiredLease(lease, subnet, duid, iaid,
fwd_dns_update, rev_dns_update, fwd_dns_update, rev_dns_update,
hostname, callout_handle, hostname, callout_handle,
fake_allocation)); fake_allocation);
Lease6Collection collection;
collection.push_back(lease);
return (collection);
} }
} }
...@@ -284,7 +296,8 @@ AllocEngine::allocateAddress6(const Subnet6Ptr& subnet, ...@@ -284,7 +296,8 @@ AllocEngine::allocateAddress6(const Subnet6Ptr& subnet,
/// @todo: check if the address is reserved once we have host support /// @todo: check if the address is reserved once we have host support
/// implemented /// implemented
Lease6Ptr existing = LeaseMgrFactory::instance().getLease6(candidate); Lease6Ptr existing = LeaseMgrFactory::instance().getLease6(
Lease6::LEASE_IA_NA, candidate);
if (!existing) { if (!existing) {
// there's no existing lease for selected candidate, so it is // there's no existing lease for selected candidate, so it is
// free. Let's allocate it. // free. Let's allocate it.
...@@ -293,7 +306,9 @@ AllocEngine::allocateAddress6(const Subnet6Ptr& subnet, ...@@ -293,7 +306,9 @@ AllocEngine::allocateAddress6(const Subnet6Ptr& subnet,
hostname, hostname,
callout_handle, fake_allocation); callout_handle, fake_allocation);
if (lease) { if (lease) {
return (lease); Lease6Collection collection;
collection.push_back(lease);
return (collection);
} }
// Although the address was free just microseconds ago, it may have // Although the address was free just microseconds ago, it may have
...@@ -301,10 +316,13 @@ AllocEngine::allocateAddress6(const Subnet6Ptr& subnet, ...@@ -301,10 +316,13 @@ AllocEngine::allocateAddress6(const Subnet6Ptr& subnet,
// allocation attempts. // allocation attempts.
} else { } else {
if (existing->expired()) { if (existing->expired()) {
return (reuseExpiredLease(existing, subnet, duid, iaid, existing = reuseExpiredLease(existing, subnet, duid, iaid,
fwd_dns_update, rev_dns_update, fwd_dns_update, rev_dns_update,
hostname, callout_handle, hostname, callout_handle,
fake_allocation)); fake_allocation);
Lease6Collection collection;
collection.push_back(existing);
return (collection);
} }
} }
...@@ -322,7 +340,7 @@ AllocEngine::allocateAddress6(const Subnet6Ptr& subnet, ...@@ -322,7 +340,7 @@ AllocEngine::allocateAddress6(const Subnet6Ptr& subnet,
LOG_ERROR(dhcpsrv_logger, DHCPSRV_ADDRESS6_ALLOC_ERROR).arg(e.what()); LOG_ERROR(dhcpsrv_logger, DHCPSRV_ADDRESS6_ALLOC_ERROR).arg(e.what());
} }
return (Lease6Ptr()); return (Lease6Collection());
} }
Lease4Ptr Lease4Ptr
...@@ -795,7 +813,8 @@ Lease6Ptr AllocEngine::createLease6(const Subnet6Ptr& subnet, ...@@ -795,7 +813,8 @@ Lease6Ptr AllocEngine::createLease6(const Subnet6Ptr& subnet,
// It is for advertise only. We should not insert the lease into LeaseMgr, // It is for advertise only. We should not insert the lease into LeaseMgr,
// but rather check that we could have inserted it. // but rather check that we could have inserted it.
Lease6Ptr existing = LeaseMgrFactory::instance().getLease6(addr); Lease6Ptr existing = LeaseMgrFactory::instance().getLease6(
Lease6::LEASE_IA_NA, addr);
if (!existing) { if (!existing) {
return (lease); return (lease);
} else { } else {
......
...@@ -295,8 +295,8 @@ protected: ...@@ -295,8 +295,8 @@ protected:
/// @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. /// will be executed if this parameter is passed.
/// ///
/// @return Allocated IPv6 lease (or NULL if allocation failed) /// @return Allocated IPv6 leases (may be empty if allocation failed)
Lease6Ptr Lease6Collection
allocateAddress6(const Subnet6Ptr& subnet, allocateAddress6(const Subnet6Ptr& subnet,
const DuidPtr& duid, const DuidPtr& duid,
uint32_t iaid, uint32_t iaid,
......
...@@ -76,7 +76,9 @@ CREATE INDEX lease6_by_iaid_subnet_id_duid ON lease6 (iaid, subnet_id, duid); ...@@ -76,7 +76,9 @@ CREATE INDEX lease6_by_iaid_subnet_id_duid ON lease6 (iaid, subnet_id, duid);
# ... and a definition of lease6 types. This table is a convenience for # ... and a definition of lease6 types. This table is a convenience for
# users of the database - if they want to view the lease table and use the # users of the database - if they want to view the lease table and use the
# type names, they can join this table with the lease6 table # type names, they can join this table with the lease6 table.
# Make sure those values match Lease6::LeaseType enum (see src/bin/dhcpsrv/
# lease_mgr.h)
CREATE TABLE lease6_types ( CREATE TABLE lease6_types (
lease_type TINYINT PRIMARY KEY NOT NULL, # Lease type code. lease_type TINYINT PRIMARY KEY NOT NULL, # Lease type code.
name VARCHAR(5) # Name of the lease type name VARCHAR(5) # Name of the lease type
......
...@@ -130,6 +130,23 @@ std::string LeaseMgr::getParameter(const std::string& name) const { ...@@ -130,6 +130,23 @@ std::string LeaseMgr::getParameter(const std::string& name) const {
return (param->second); return (param->second);
} }
Lease6Ptr
LeaseMgr::getLease6(Lease6::LeaseType type, const DUID& duid,
uint32_t iaid, SubnetID subnet_id) const {
Lease6Collection col = getLeases6(type, duid, iaid, subnet_id);
if (col.size() > 1) {
isc_throw(MultipleRecords, "More than one lease found for type "
<< static_cast<int>(type) << ", duid "
<< duid.toText() << ", iaid " << iaid
<< " and subnet-id " << subnet_id);
}
if (col.empty()) {
return (Lease6Ptr());
}
return (*col.begin());
}
std::string std::string
Lease6::toText() const { Lease6::toText() const {
ostringstream stream; ostringstream stream;
......
...@@ -318,9 +318,9 @@ struct Lease6 : public Lease { ...@@ -318,9 +318,9 @@ struct Lease6 : public Lease {
/// @brief Type of lease contents /// @brief Type of lease contents