Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sebastian Schrader
Kea
Commits
c8837f49
Commit
c8837f49
authored
Sep 08, 2015
by
Marcin Siodelski
Browse files
[3973] Implemented first version of the lease reclamation routine.
parent
13fed2c9
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
src/lib/dhcpsrv/alloc_engine.cc
View file @
c8837f49
...
...
@@ -14,8 +14,12 @@
#include <config.h>
#include <dhcp/option_data_types.h>
#include <dhcp_ddns/ncr_msg.h>
#include <dhcpsrv/alloc_engine.h>
#include <dhcpsrv/alloc_engine_log.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/d2_client_mgr.h>
#include <dhcpsrv/dhcpsrv_log.h>
#include <dhcpsrv/host_mgr.h>
#include <dhcpsrv/host.h>
...
...
@@ -34,6 +38,7 @@
using
namespace
isc
::
asiolink
;
using
namespace
isc
::
dhcp
;
using
namespace
isc
::
dhcp_ddns
;
using
namespace
isc
::
hooks
;
using
namespace
isc
::
stats
;
...
...
@@ -1272,6 +1277,66 @@ AllocEngine::updateLeaseData(ClientContext6& ctx, const Lease6Collection& leases
return
(
updated_leases
);
}
void
AllocEngine
::
reclaimExpiredLeases6
(
const
size_t
max_leases
,
const
uint16_t
timeout
,
const
bool
remove_lease
)
{
LeaseMgr
&
lease_mgr
=
LeaseMgrFactory
::
instance
();
Lease6Collection
leases
;
lease_mgr
.
getExpiredLeases6
(
leases
,
max_leases
);
for
(
Lease6Collection
::
const_iterator
lease_it
=
leases
.
begin
();
lease_it
!=
leases
.
end
();
++
lease_it
)
{
/// @todo execute a lease6_expire hook here
/// @todo perform DNS update here
queueNameChangeRequest
(
*
lease_it
,
*
(
*
lease_it
)
->
duid_
);
// Reclaim the lease - depending on the configuration, set the
// expired-reclaimed state or simply remove it.
if
(
remove_lease
)
{
LeaseMgrFactory
::
instance
().
deleteLease
((
*
lease_it
)
->
addr_
);
}
else
{
(
*
lease_it
)
->
state_
=
Lease
::
STATE_EXPIRED_RECLAIMED
;
LeaseMgrFactory
::
instance
().
updateLease6
(
*
lease_it
);
}
}
}
template
<
typename
LeasePtrType
,
typename
IdentifierType
>
void
AllocEngine
::
queueNameChangeRequest
(
const
LeasePtrType
&
lease
,
const
IdentifierType
&
identifier
)
const
{
if
(
lease
->
hostname_
.
empty
()
||
!
lease
->
fqdn_fwd_
||
!
lease
->
fqdn_rev_
)
{
return
;
}
if
(
!
CfgMgr
::
instance
().
getD2ClientMgr
().
ddnsEnabled
())
{
return
;
}
std
::
vector
<
uint8_t
>
hostname_wire
;
try
{
OptionDataTypeUtil
::
writeFqdn
(
lease
->
hostname_
,
hostname_wire
,
true
);
}
catch
(
const
std
::
exception
&
ex
)
{
}
isc
::
dhcp_ddns
::
D2Dhcid
dhcid
(
identifier
,
hostname_wire
);
NameChangeRequestPtr
ncr
;
ncr
.
reset
(
new
NameChangeRequest
(
isc
::
dhcp_ddns
::
CHG_REMOVE
,
lease
->
fqdn_fwd_
,
lease
->
fqdn_rev_
,
lease
->
hostname_
,
lease
->
addr_
.
toText
(),
dhcid
,
0
,
lease
->
valid_lft_
));
CfgMgr
::
instance
().
getD2ClientMgr
().
sendRequest
(
ncr
);
}
}
// end of isc::dhcp namespace
}
// end of isc namespace
...
...
src/lib/dhcpsrv/alloc_engine.h
View file @
c8837f49
...
...
@@ -490,6 +490,21 @@ public:
/// @return Returns renewed lease.
Lease6Collection
renewLeases6
(
ClientContext6
&
ctx
);
/// @brief Reclaims expired leases.
///
/// This method retrieves a collection of expired leases and reclaims them.
/// See http://kea.isc.org/wiki/LeaseExpirationDesign#LeasesReclamationRoutine
/// for the details.
///
/// @param max_leases Maximum number of leases to be reclaimed.
/// @param timeout Maximum amount of time that the reclaimation routine
/// may be processing expired leases, expressed in seconds.
/// @param remove_lease A boolean value indicating if the lease should
/// be removed when it is reclaimed (if true) or it should be left in the
/// database in the "expired-reclaimed" state (if false).
void
reclaimExpiredLeases6
(
const
size_t
max_leases
,
const
uint16_t
timeout
,
const
bool
remove_lease
);
/// @brief Attempts to find appropriate host reservation.
///
/// Attempts to find appropriate host reservation in HostMgr. If found, it
...
...
@@ -663,6 +678,10 @@ private:
/// @param lease IPv6 lease to be extended.
void
extendLease6
(
ClientContext6
&
ctx
,
Lease6Ptr
lease
);
template
<
typename
LeasePtrType
,
typename
IdentifierType
>
void
queueNameChangeRequest
(
const
LeasePtrType
&
lease
,
const
IdentifierType
&
identifier
)
const
;
public:
/// @brief Context information for the DHCPv4 lease allocation.
...
...
src/lib/dhcpsrv/tests/Makefile.am
View file @
c8837f49
...
...
@@ -56,6 +56,7 @@ TESTS += libdhcpsrv_unittests
libdhcpsrv_unittests_SOURCES
=
run_unittests.cc
libdhcpsrv_unittests_SOURCES
+=
addr_utilities_unittest.cc
libdhcpsrv_unittests_SOURCES
+=
alloc_engine_utils.cc alloc_engine_utils.h
libdhcpsrv_unittests_SOURCES
+=
alloc_engine_expiration_unittest.cc
libdhcpsrv_unittests_SOURCES
+=
alloc_engine_hooks_unittest.cc
libdhcpsrv_unittests_SOURCES
+=
alloc_engine4_unittest.cc
libdhcpsrv_unittests_SOURCES
+=
alloc_engine6_unittest.cc
...
...
src/lib/dhcpsrv/tests/alloc_engine_expiration_unittest.cc
0 → 100644
View file @
c8837f49
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment