Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Kea
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
426
Issues
426
List
Boards
Labels
Service Desk
Milestones
Merge Requests
66
Merge Requests
66
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
ISC Open Source Projects
Kea
Commits
a26a75c9
Commit
a26a75c9
authored
Sep 18, 2013
by
Tomek Mrugalski
🛰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[3149] Lease6::LeaseType and Pool::PoolType unified.
parent
17021645
Changes
29
Hide whitespace changes
Inline
Side-by-side
Showing
29 changed files
with
946 additions
and
832 deletions
+946
-832
src/bin/dhcp6/config_parser.cc
src/bin/dhcp6/config_parser.cc
+2
-2
src/bin/dhcp6/dhcp6_srv.cc
src/bin/dhcp6/dhcp6_srv.cc
+3
-3
src/bin/dhcp6/tests/dhcp6_srv_unittest.cc
src/bin/dhcp6/tests/dhcp6_srv_unittest.cc
+16
-16
src/bin/dhcp6/tests/dhcp6_test_utils.h
src/bin/dhcp6/tests/dhcp6_test_utils.h
+2
-2
src/bin/dhcp6/tests/hooks_unittest.cc
src/bin/dhcp6/tests/hooks_unittest.cc
+15
-15
src/lib/dhcpsrv/Makefile.am
src/lib/dhcpsrv/Makefile.am
+1
-0
src/lib/dhcpsrv/alloc_engine.cc
src/lib/dhcpsrv/alloc_engine.cc
+17
-15
src/lib/dhcpsrv/alloc_engine.h
src/lib/dhcpsrv/alloc_engine.h
+12
-8
src/lib/dhcpsrv/lease.cc
src/lib/dhcpsrv/lease.cc
+216
-0
src/lib/dhcpsrv/lease.h
src/lib/dhcpsrv/lease.h
+353
-0
src/lib/dhcpsrv/lease_mgr.cc
src/lib/dhcpsrv/lease_mgr.cc
+1
-188
src/lib/dhcpsrv/lease_mgr.h
src/lib/dhcpsrv/lease_mgr.h
+6
-318
src/lib/dhcpsrv/memfile_lease_mgr.cc
src/lib/dhcpsrv/memfile_lease_mgr.cc
+3
-3
src/lib/dhcpsrv/memfile_lease_mgr.h
src/lib/dhcpsrv/memfile_lease_mgr.h
+3
-3
src/lib/dhcpsrv/mysql_lease_mgr.cc
src/lib/dhcpsrv/mysql_lease_mgr.cc
+10
-10
src/lib/dhcpsrv/mysql_lease_mgr.h
src/lib/dhcpsrv/mysql_lease_mgr.h
+3
-3
src/lib/dhcpsrv/pool.cc
src/lib/dhcpsrv/pool.cc
+11
-9
src/lib/dhcpsrv/pool.h
src/lib/dhcpsrv/pool.h
+9
-26
src/lib/dhcpsrv/subnet.cc
src/lib/dhcpsrv/subnet.cc
+32
-31
src/lib/dhcpsrv/subnet.h
src/lib/dhcpsrv/subnet.h
+9
-9
src/lib/dhcpsrv/tests/alloc_engine_unittest.cc
src/lib/dhcpsrv/tests/alloc_engine_unittest.cc
+41
-40
src/lib/dhcpsrv/tests/lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/lease_mgr_unittest.cc
+13
-13
src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
+9
-9
src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc
+5
-5
src/lib/dhcpsrv/tests/pool_unittest.cc
src/lib/dhcpsrv/tests/pool_unittest.cc
+26
-26
src/lib/dhcpsrv/tests/subnet_unittest.cc
src/lib/dhcpsrv/tests/subnet_unittest.cc
+73
-73
src/lib/dhcpsrv/tests/test_libraries.h
src/lib/dhcpsrv/tests/test_libraries.h
+51
-0
src/lib/dhcpsrv/tests/test_utils.cc
src/lib/dhcpsrv/tests/test_utils.cc
+3
-4
src/lib/dhcpsrv/tests/test_utils.h
src/lib/dhcpsrv/tests/test_utils.h
+1
-1
No files found.
src/bin/dhcp6/config_parser.cc
View file @
a26a75c9
...
...
@@ -147,7 +147,7 @@ protected:
/// @return returns a PoolPtr to the new Pool4 object.
PoolPtr
poolMaker
(
IOAddress
&
addr
,
uint32_t
len
,
int32_t
ptype
)
{
return
(
PoolPtr
(
new
Pool6
(
static_cast
<
isc
::
dhcp
::
Pool
::
Pool
Type
>
return
(
PoolPtr
(
new
Pool6
(
static_cast
<
isc
::
dhcp
::
Lease
::
Type
>
(
ptype
),
addr
,
len
)));
}
...
...
@@ -161,7 +161,7 @@ protected:
/// @return returns a PoolPtr to the new Pool4 object.
PoolPtr
poolMaker
(
IOAddress
&
min
,
IOAddress
&
max
,
int32_t
ptype
)
{
return
(
PoolPtr
(
new
Pool6
(
static_cast
<
isc
::
dhcp
::
Pool
::
Pool
Type
>
return
(
PoolPtr
(
new
Pool6
(
static_cast
<
isc
::
dhcp
::
Lease
::
Type
>
(
ptype
),
min
,
max
)));
}
};
...
...
src/bin/dhcp6/dhcp6_srv.cc
View file @
a26a75c9
...
...
@@ -1225,7 +1225,7 @@ Dhcpv6Srv::assignIA_NA(const Subnet6Ptr& subnet, const DuidPtr& duid,
// be inserted into the LeaseMgr as well.
Lease6Collection
leases
=
alloc_engine_
->
allocateAddress6
(
subnet
,
duid
,
ia
->
getIAID
(),
hint
,
hint
,
Lease
::
TYPE_NA
,
do_fwd
,
do_rev
,
hostname
,
fake_allocation
,
...
...
@@ -1321,7 +1321,7 @@ Dhcpv6Srv::renewIA_NA(const Subnet6Ptr& subnet, const DuidPtr& duid,
return
(
ia_rsp
);
}
Lease6Ptr
lease
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
6
::
LEASE_IA
_NA
,
Lease6Ptr
lease
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
::
TYPE
_NA
,
*
duid
,
ia
->
getIAID
(),
subnet
->
getID
());
...
...
@@ -1585,7 +1585,7 @@ Dhcpv6Srv::releaseIA_NA(const DuidPtr& duid, const Pkt6Ptr& query,
return
(
ia_rsp
);
}
Lease6Ptr
lease
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
6
::
LEASE_IA
_NA
,
Lease6Ptr
lease
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
::
TYPE
_NA
,
release_addr
->
getAddress
());
if
(
!
lease
)
{
...
...
src/bin/dhcp6/tests/dhcp6_srv_unittest.cc
View file @
a26a75c9
...
...
@@ -67,7 +67,7 @@ public:
:
Dhcpv6SrvTest
()
{
// generateClientId assigns DUID to duid_.
generateClientId
();
lease_
.
reset
(
new
Lease6
(
Lease
6
::
LEASE_IA
_NA
,
IOAddress
(
"2001:db8:1::1"
),
lease_
.
reset
(
new
Lease6
(
Lease
::
TYPE
_NA
,
IOAddress
(
"2001:db8:1::1"
),
duid_
,
1234
,
501
,
502
,
503
,
504
,
1
,
0
));
...
...
@@ -1018,13 +1018,13 @@ TEST_F(Dhcpv6SrvTest, RenewBasic) {
// Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid
// value on purpose. They should be updated during RENEW.
Lease6Ptr
lease
(
new
Lease6
(
Lease
6
::
LEASE_IA
_NA
,
addr
,
duid_
,
iaid
,
Lease6Ptr
lease
(
new
Lease6
(
Lease
::
TYPE
_NA
,
addr
,
duid_
,
iaid
,
501
,
502
,
503
,
504
,
subnet_
->
getID
(),
0
));
lease
->
cltt_
=
1234
;
ASSERT_TRUE
(
LeaseMgrFactory
::
instance
().
addLease
(
lease
));
// Check that the lease is really in the database
Lease6Ptr
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
6
::
LEASE_IA
_NA
,
Lease6Ptr
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
::
TYPE
_NA
,
addr
);
ASSERT_TRUE
(
l
);
...
...
@@ -1117,7 +1117,7 @@ TEST_F(Dhcpv6SrvTest, RenewReject) {
OptionPtr
clientid
=
generateClientId
();
// Check that the lease is NOT in the database
Lease6Ptr
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
6
::
LEASE_IA
_NA
,
Lease6Ptr
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
::
TYPE
_NA
,
addr
);
ASSERT_FALSE
(
l
);
...
...
@@ -1149,14 +1149,14 @@ TEST_F(Dhcpv6SrvTest, RenewReject) {
checkIA_NAStatusCode
(
ia
,
STATUS_NoBinding
);
// Check that there is no lease added
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
6
::
LEASE_IA
_NA
,
addr
);
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
::
TYPE
_NA
,
addr
);
ASSERT_FALSE
(
l
);
// CASE 2: Lease is known and belongs to this client, but to a different IAID
// Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid
// value on purpose. They should be updated during RENEW.
Lease6Ptr
lease
(
new
Lease6
(
Lease
6
::
LEASE_IA
_NA
,
addr
,
duid_
,
valid_iaid
,
Lease6Ptr
lease
(
new
Lease6
(
Lease
::
TYPE
_NA
,
addr
,
duid_
,
valid_iaid
,
501
,
502
,
503
,
504
,
subnet_
->
getID
(),
0
));
lease
->
cltt_
=
123
;
// Let's use it as an indicator that the lease
// was NOT updated.
...
...
@@ -1191,7 +1191,7 @@ TEST_F(Dhcpv6SrvTest, RenewReject) {
ASSERT_TRUE
(
ia
);
checkIA_NAStatusCode
(
ia
,
STATUS_NoBinding
);
lease
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
6
::
LEASE_IA
_NA
,
addr
);
lease
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
::
TYPE
_NA
,
addr
);
ASSERT_TRUE
(
lease
);
// Verify that the lease was not updated.
EXPECT_EQ
(
123
,
lease
->
cltt_
);
...
...
@@ -1222,13 +1222,13 @@ TEST_F(Dhcpv6SrvTest, ReleaseBasic) {
// Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid
// value on purpose. They should be updated during RENEW.
Lease6Ptr
lease
(
new
Lease6
(
Lease
6
::
LEASE_IA
_NA
,
addr
,
duid_
,
iaid
,
Lease6Ptr
lease
(
new
Lease6
(
Lease
::
TYPE
_NA
,
addr
,
duid_
,
iaid
,
501
,
502
,
503
,
504
,
subnet_
->
getID
(),
0
));
lease
->
cltt_
=
1234
;
ASSERT_TRUE
(
LeaseMgrFactory
::
instance
().
addLease
(
lease
));
// Check that the lease is really in the database
Lease6Ptr
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
6
::
LEASE_IA
_NA
,
Lease6Ptr
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
::
TYPE
_NA
,
addr
);
ASSERT_TRUE
(
l
);
...
...
@@ -1268,11 +1268,11 @@ TEST_F(Dhcpv6SrvTest, ReleaseBasic) {
// Check that the lease is really gone in the database
// get lease by address
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
6
::
LEASE_IA
_NA
,
addr
);
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
::
TYPE
_NA
,
addr
);
ASSERT_FALSE
(
l
);
// get lease by subnetid/duid/iaid combination
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
6
::
LEASE_IA
_NA
,
*
duid_
,
iaid
,
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
::
TYPE
_NA
,
*
duid_
,
iaid
,
subnet_
->
getID
());
ASSERT_FALSE
(
l
);
}
...
...
@@ -1305,7 +1305,7 @@ TEST_F(Dhcpv6SrvTest, ReleaseReject) {
OptionPtr
clientid
=
generateClientId
();
// Check that the lease is NOT in the database
Lease6Ptr
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
6
::
LEASE_IA
_NA
,
Lease6Ptr
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
::
TYPE
_NA
,
addr
);
ASSERT_FALSE
(
l
);
...
...
@@ -1339,13 +1339,13 @@ TEST_F(Dhcpv6SrvTest, ReleaseReject) {
checkMsgStatusCode
(
reply
,
STATUS_NoBinding
);
// Check that the lease is not there
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
6
::
LEASE_IA
_NA
,
addr
);
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
::
TYPE
_NA
,
addr
);
ASSERT_FALSE
(
l
);
// CASE 2: Lease is known and belongs to this client, but to a different IAID
SCOPED_TRACE
(
"CASE 2: Lease is known and belongs to this client, but to a different IAID"
);
Lease6Ptr
lease
(
new
Lease6
(
Lease
6
::
LEASE_IA
_NA
,
addr
,
duid_
,
valid_iaid
,
Lease6Ptr
lease
(
new
Lease6
(
Lease
::
TYPE
_NA
,
addr
,
duid_
,
valid_iaid
,
501
,
502
,
503
,
504
,
subnet_
->
getID
(),
0
));
ASSERT_TRUE
(
LeaseMgrFactory
::
instance
().
addLease
(
lease
));
...
...
@@ -1361,7 +1361,7 @@ TEST_F(Dhcpv6SrvTest, ReleaseReject) {
checkMsgStatusCode
(
reply
,
STATUS_NoBinding
);
// Check that the lease is still there
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
6
::
LEASE_IA
_NA
,
addr
);
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
::
TYPE
_NA
,
addr
);
ASSERT_TRUE
(
l
);
// CASE 3: Lease belongs to a client with different client-id
...
...
@@ -1384,7 +1384,7 @@ TEST_F(Dhcpv6SrvTest, ReleaseReject) {
checkMsgStatusCode
(
reply
,
STATUS_NoBinding
);
// Check that the lease is still there
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
6
::
LEASE_IA
_NA
,
addr
);
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
::
TYPE
_NA
,
addr
);
ASSERT_TRUE
(
l
);
// Finally, let's cleanup the database
...
...
src/bin/dhcp6/tests/dhcp6_test_utils.h
View file @
a26a75c9
...
...
@@ -321,7 +321,7 @@ public:
Dhcpv6SrvTest
()
{
subnet_
=
Subnet6Ptr
(
new
Subnet6
(
IOAddress
(
"2001:db8:1::"
),
48
,
1000
,
2000
,
3000
,
4000
));
pool_
=
Pool6Ptr
(
new
Pool6
(
Pool6
::
TYPE_I
A
,
IOAddress
(
"2001:db8:1:1::"
),
64
));
pool_
=
Pool6Ptr
(
new
Pool6
(
Lease
::
TYPE_N
A
,
IOAddress
(
"2001:db8:1:1::"
),
64
));
subnet_
->
addPool
(
pool_
);
CfgMgr
::
instance
().
deleteSubnets6
();
...
...
@@ -377,7 +377,7 @@ public:
boost
::
shared_ptr
<
Option6IAAddr
>
addr
)
{
boost
::
shared_ptr
<
Option6IA
>
ia
=
boost
::
dynamic_pointer_cast
<
Option6IA
>
(
ia_na
);
Lease6Ptr
lease
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
6
::
LEASE_IA
_NA
,
Lease6Ptr
lease
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
::
TYPE
_NA
,
addr
->
getAddress
());
if
(
!
lease
)
{
std
::
cout
<<
"Lease for "
<<
addr
->
getAddress
().
toText
()
...
...
src/bin/dhcp6/tests/hooks_unittest.cc
View file @
a26a75c9
...
...
@@ -1070,13 +1070,13 @@ TEST_F(HooksDhcpv6SrvTest, basic_lease6_renew) {
// Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid
// value on purpose. They should be updated during RENEW.
Lease6Ptr
lease
(
new
Lease6
(
Lease
6
::
LEASE_IA
_NA
,
addr
,
duid_
,
iaid
,
Lease6Ptr
lease
(
new
Lease6
(
Lease
::
TYPE
_NA
,
addr
,
duid_
,
iaid
,
501
,
502
,
503
,
504
,
subnet_
->
getID
(),
0
));
lease
->
cltt_
=
1234
;
ASSERT_TRUE
(
LeaseMgrFactory
::
instance
().
addLease
(
lease
));
// Check that the lease is really in the database
Lease6Ptr
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
6
::
LEASE_IA
_NA
,
Lease6Ptr
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
::
TYPE
_NA
,
addr
);
ASSERT_TRUE
(
l
);
...
...
@@ -1167,13 +1167,13 @@ TEST_F(HooksDhcpv6SrvTest, leaseUpdate_lease6_renew) {
// Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid
// value on purpose. They should be updated during RENEW.
Lease6Ptr
lease
(
new
Lease6
(
Lease
6
::
LEASE_IA
_NA
,
addr
,
duid_
,
iaid
,
Lease6Ptr
lease
(
new
Lease6
(
Lease
::
TYPE
_NA
,
addr
,
duid_
,
iaid
,
501
,
502
,
503
,
504
,
subnet_
->
getID
(),
0
));
lease
->
cltt_
=
1234
;
ASSERT_TRUE
(
LeaseMgrFactory
::
instance
().
addLease
(
lease
));
// Check that the lease is really in the database
Lease6Ptr
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
6
::
LEASE_IA
_NA
,
Lease6Ptr
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
::
TYPE
_NA
,
addr
);
ASSERT_TRUE
(
l
);
...
...
@@ -1258,13 +1258,13 @@ TEST_F(HooksDhcpv6SrvTest, skip_lease6_renew) {
// Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid
// value on purpose. They should be updated during RENEW.
Lease6Ptr
lease
(
new
Lease6
(
Lease
6
::
LEASE_IA
_NA
,
addr
,
duid_
,
iaid
,
Lease6Ptr
lease
(
new
Lease6
(
Lease
::
TYPE
_NA
,
addr
,
duid_
,
iaid
,
501
,
502
,
503
,
504
,
subnet_
->
getID
(),
0
));
lease
->
cltt_
=
1234
;
ASSERT_TRUE
(
LeaseMgrFactory
::
instance
().
addLease
(
lease
));
// Check that the lease is really in the database
Lease6Ptr
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
6
::
LEASE_IA
_NA
,
Lease6Ptr
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
::
TYPE
_NA
,
addr
);
ASSERT_TRUE
(
l
);
...
...
@@ -1296,7 +1296,7 @@ TEST_F(HooksDhcpv6SrvTest, skip_lease6_renew) {
// Check that our callback was called
EXPECT_EQ
(
"lease6_renew"
,
callback_name_
);
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
6
::
LEASE_IA
_NA
,
addr
);
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
::
TYPE
_NA
,
addr
);
// Check that the old values are still there and they were not
// updated by the renewal
...
...
@@ -1334,13 +1334,13 @@ TEST_F(HooksDhcpv6SrvTest, basic_lease6_release) {
// Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid
// value on purpose. They should be updated during RENEW.
Lease6Ptr
lease
(
new
Lease6
(
Lease
6
::
LEASE_IA
_NA
,
addr
,
duid_
,
iaid
,
Lease6Ptr
lease
(
new
Lease6
(
Lease
::
TYPE
_NA
,
addr
,
duid_
,
iaid
,
501
,
502
,
503
,
504
,
subnet_
->
getID
(),
0
));
lease
->
cltt_
=
1234
;
ASSERT_TRUE
(
LeaseMgrFactory
::
instance
().
addLease
(
lease
));
// Check that the lease is really in the database
Lease6Ptr
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
6
::
LEASE_IA
_NA
,
Lease6Ptr
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
::
TYPE
_NA
,
addr
);
ASSERT_TRUE
(
l
);
...
...
@@ -1379,11 +1379,11 @@ TEST_F(HooksDhcpv6SrvTest, basic_lease6_release) {
// Check that the lease is really gone in the database
// get lease by address
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
6
::
LEASE_IA
_NA
,
addr
);
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
::
TYPE
_NA
,
addr
);
ASSERT_FALSE
(
l
);
// Get lease by subnetid/duid/iaid combination
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
6
::
LEASE_IA
_NA
,
*
duid_
,
iaid
,
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
::
TYPE
_NA
,
*
duid_
,
iaid
,
subnet_
->
getID
());
ASSERT_FALSE
(
l
);
}
...
...
@@ -1415,13 +1415,13 @@ TEST_F(HooksDhcpv6SrvTest, skip_lease6_release) {
// Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid
// value on purpose. They should be updated during RENEW.
Lease6Ptr
lease
(
new
Lease6
(
Lease
6
::
LEASE_IA
_NA
,
addr
,
duid_
,
iaid
,
Lease6Ptr
lease
(
new
Lease6
(
Lease
::
TYPE
_NA
,
addr
,
duid_
,
iaid
,
501
,
502
,
503
,
504
,
subnet_
->
getID
(),
0
));
lease
->
cltt_
=
1234
;
ASSERT_TRUE
(
LeaseMgrFactory
::
instance
().
addLease
(
lease
));
// Check that the lease is really in the database
Lease6Ptr
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
6
::
LEASE_IA
_NA
,
Lease6Ptr
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
::
TYPE
_NA
,
addr
);
ASSERT_TRUE
(
l
);
...
...
@@ -1448,12 +1448,12 @@ TEST_F(HooksDhcpv6SrvTest, skip_lease6_release) {
// Check that the lease is still there
// get lease by address
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
6
::
LEASE_IA
_NA
,
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
::
TYPE
_NA
,
addr
);
ASSERT_TRUE
(
l
);
// Get lease by subnetid/duid/iaid combination
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
6
::
LEASE_IA
_NA
,
*
duid_
,
iaid
,
l
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
::
TYPE
_NA
,
*
duid_
,
iaid
,
subnet_
->
getID
());
ASSERT_TRUE
(
l
);
}
...
...
src/lib/dhcpsrv/Makefile.am
View file @
a26a75c9
...
...
@@ -42,6 +42,7 @@ libb10_dhcpsrv_la_SOURCES += cfgmgr.cc cfgmgr.h
libb10_dhcpsrv_la_SOURCES
+=
dhcp_config_parser.h
libb10_dhcpsrv_la_SOURCES
+=
dhcp_parsers.cc dhcp_parsers.h
libb10_dhcpsrv_la_SOURCES
+=
key_from_key.h
libb10_dhcpsrv_la_SOURCES
+=
lease.cc lease.h
libb10_dhcpsrv_la_SOURCES
+=
lease_mgr.cc lease_mgr.h
libb10_dhcpsrv_la_SOURCES
+=
lease_mgr_factory.cc lease_mgr_factory.h
libb10_dhcpsrv_la_SOURCES
+=
memfile_lease_mgr.cc memfile_lease_mgr.h
...
...
src/lib/dhcpsrv/alloc_engine.cc
View file @
a26a75c9
...
...
@@ -53,7 +53,7 @@ AllocEngineHooks Hooks;
namespace
isc
{
namespace
dhcp
{
AllocEngine
::
IterativeAllocator
::
IterativeAllocator
(
Pool
::
Pool
Type
lease_type
)
AllocEngine
::
IterativeAllocator
::
IterativeAllocator
(
Lease
::
Type
lease_type
)
:
Allocator
(
lease_type
)
{
}
...
...
@@ -146,7 +146,7 @@ AllocEngine::IterativeAllocator::pickAddress(const SubnetPtr& subnet,
return
(
next
);
}
AllocEngine
::
HashedAllocator
::
HashedAllocator
(
Pool
::
Pool
Type
lease_type
)
AllocEngine
::
HashedAllocator
::
HashedAllocator
(
Lease
::
Type
lease_type
)
:
Allocator
(
lease_type
)
{
isc_throw
(
NotImplemented
,
"Hashed allocator is not implemented"
);
}
...
...
@@ -159,7 +159,7 @@ AllocEngine::HashedAllocator::pickAddress(const SubnetPtr&,
isc_throw
(
NotImplemented
,
"Hashed allocator is not implemented"
);
}
AllocEngine
::
RandomAllocator
::
RandomAllocator
(
Pool
::
Pool
Type
lease_type
)
AllocEngine
::
RandomAllocator
::
RandomAllocator
(
Lease
::
Type
lease_type
)
:
Allocator
(
lease_type
)
{
isc_throw
(
NotImplemented
,
"Random allocator is not implemented"
);
}
...
...
@@ -204,6 +204,7 @@ AllocEngine::allocateAddress6(const Subnet6Ptr& subnet,
const
DuidPtr
&
duid
,
uint32_t
iaid
,
const
IOAddress
&
hint
,
Lease
::
Type
type
,
const
bool
fwd_dns_update
,
const
bool
rev_dns_update
,
const
std
::
string
&
hostname
,
...
...
@@ -227,8 +228,8 @@ AllocEngine::allocateAddress6(const Subnet6Ptr& subnet,
// check if there's existing lease for that subnet/duid/iaid combination.
/// @todo: Make this generic (cover temp. addrs and prefixes)
Lease6Collection
existing
=
LeaseMgrFactory
::
instance
().
getLeases6
(
Lease6
::
LEASE_IA_NA
,
*
duid
,
iaid
,
subnet
->
getID
());
Lease6Collection
existing
=
LeaseMgrFactory
::
instance
().
getLeases6
(
type
,
*
duid
,
iaid
,
subnet
->
getID
());
if
(
!
existing
.
empty
())
{
// we have at least one lease already. This is a returning client,
...
...
@@ -240,15 +241,14 @@ AllocEngine::allocateAddress6(const Subnet6Ptr& subnet,
if
(
subnet
->
inPool
(
hint
))
{
/// @todo: We support only one hint for now
Lease6Ptr
lease
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease6
::
LEASE_IA_NA
,
hint
);
Lease6Ptr
lease
=
LeaseMgrFactory
::
instance
().
getLease6
(
type
,
hint
);
if
(
!
lease
)
{
/// @todo: check if the hint is reserved once we have host support
/// implemented
// the hint is valid and not currently used, let's create a lease for it
/// @todo: We support only one lease per ia for now
lease
=
createLease6
(
subnet
,
duid
,
iaid
,
hint
,
fwd_dns_update
,
lease
=
createLease6
(
subnet
,
duid
,
iaid
,
hint
,
type
,
fwd_dns_update
,
rev_dns_update
,
hostname
,
callout_handle
,
fake_allocation
);
...
...
@@ -264,11 +264,12 @@ AllocEngine::allocateAddress6(const Subnet6Ptr& subnet,
}
else
{
if
(
lease
->
expired
())
{
/// 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
,
hostname
,
callout_handle
,
fake_allocation
);
/// @todo: We support only one lease per ia for now
Lease6Collection
collection
;
collection
.
push_back
(
lease
);
return
(
collection
);
...
...
@@ -300,14 +301,14 @@ AllocEngine::allocateAddress6(const Subnet6Ptr& subnet,
/// @todo: check if the address is reserved once we have host support
/// implemented
Lease6Ptr
existing
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease6
::
LEASE_IA_NA
,
candidate
);
Lease6Ptr
existing
=
LeaseMgrFactory
::
instance
().
getLease6
(
type
,
candidate
);
if
(
!
existing
)
{
// there's no existing lease for selected candidate, so it is
// free. Let's allocate it.
Lease6Ptr
lease
=
createLease6
(
subnet
,
duid
,
iaid
,
candidate
,
fwd_dns_update
,
rev
_dns_update
,
hostname
,
type
,
fwd
_dns_update
,
rev_dns_update
,
hostname
,
callout_handle
,
fake_allocation
);
if
(
lease
)
{
Lease6Collection
collection
;
...
...
@@ -752,13 +753,14 @@ Lease6Ptr AllocEngine::createLease6(const Subnet6Ptr& subnet,
const
DuidPtr
&
duid
,
uint32_t
iaid
,
const
IOAddress
&
addr
,
Lease
::
Type
type
,
const
bool
fwd_dns_update
,
const
bool
rev_dns_update
,
const
std
::
string
&
hostname
,
const
isc
::
hooks
::
CalloutHandlePtr
&
callout_handle
,
bool
fake_allocation
/*= false */
)
{
Lease6Ptr
lease
(
new
Lease6
(
Lease6
::
LEASE_IA_NA
,
addr
,
duid
,
iaid
,
Lease6Ptr
lease
(
new
Lease6
(
type
,
addr
,
duid
,
iaid
,
subnet
->
getPreferred
(),
subnet
->
getValid
(),
subnet
->
getT1
(),
subnet
->
getT2
(),
subnet
->
getID
()));
...
...
@@ -818,7 +820,7 @@ Lease6Ptr AllocEngine::createLease6(const Subnet6Ptr& subnet,
// It is for advertise only. We should not insert the lease into LeaseMgr,
// but rather check that we could have inserted it.
Lease6Ptr
existing
=
LeaseMgrFactory
::
instance
().
getLease6
(
Lease
6
::
LEASE_IA
_NA
,
addr
);
Lease
::
TYPE
_NA
,
addr
);
if
(
!
existing
)
{
return
(
lease
);
}
else
{
...
...
src/lib/dhcpsrv/alloc_engine.h
View file @
a26a75c9
...
...
@@ -81,7 +81,7 @@ protected:
///
/// Specifies which type of leases this allocator will assign
/// @param pool_type specifies pool type (addresses, temp. addr or prefixes)
Allocator
(
Pool
::
Pool
Type
pool_type
)
Allocator
(
Lease
::
Type
pool_type
)
:
pool_type_
(
pool_type
)
{
}
...
...
@@ -90,8 +90,8 @@ protected:
}
protected:
/// @brief defines
lease
type allocation
Pool
::
Pool
Type
pool_type_
;
/// @brief defines
pool
type allocation
Lease
::
Type
pool_type_
;
};
/// @brief Address/prefix allocator that iterates over all addresses
...
...
@@ -107,7 +107,7 @@ protected:
///
/// Does not do anything
/// @param type - specifies allocation type
IterativeAllocator
(
Pool
::
Pool
Type
type
);
IterativeAllocator
(
Lease
::
Type
type
);
/// @brief returns the next address from pools in a subnet
///
...
...
@@ -136,7 +136,7 @@ protected:
/// @brief default constructor (does nothing)
/// @param type - specifies allocation type
HashedAllocator
(
Pool
::
Pool
Type
type
);
HashedAllocator
(
Lease
::
Type
type
);
/// @brief returns an address based on hash calculated from client's DUID.
///
...
...
@@ -159,7 +159,7 @@ protected:
/// @brief default constructor (does nothing)
/// @param type - specifies allocation type
RandomAllocator
(
Pool
::
Pool
Type
type
);
RandomAllocator
(
Lease
::
Type
type
);
/// @brief returns an random address from pool of specified subnet
///
...
...
@@ -298,6 +298,7 @@ protected:
/// @param duid Client's DUID
/// @param iaid iaid field from the IA_NA container that client sent
/// @param hint a hint that the client provided
/// @param type lease type (IA, TA or PD)
/// @param fwd_dns_update A boolean value which indicates that server takes
/// responsibility for the forward DNS Update for this lease
/// (if true).
...
...
@@ -316,6 +317,7 @@ protected:
const
DuidPtr
&
duid
,
uint32_t
iaid
,
const
isc
::
asiolink
::
IOAddress
&
hint
,
Lease
::
Type
type
,
const
bool
fwd_dns_update
,
const
bool
rev_dns_update
,
const
std
::
string
&
hostname
,
...
...
@@ -367,7 +369,8 @@ private:
/// @param duid client's DUID
/// @param iaid IAID from the IA_NA container the client sent to us
/// @param addr an address that was selected and is confirmed to be
/// available
/// available
/// @param type lease type (IA, TA or PD)
/// @param fwd_dns_update A boolean value which indicates that server takes
/// responsibility for the forward DNS Update for this lease
/// (if true).
...
...
@@ -384,7 +387,8 @@ private:
/// became unavailable)
Lease6Ptr
createLease6
(
const
Subnet6Ptr
&
subnet
,
const
DuidPtr
&
duid
,
uint32_t
iaid
,
const
isc
::
asiolink
::
IOAddress
&
addr
,
const
bool
fwd_dns_update
,
const
bool
rev_dns_update
,
Lease
::
Type
type
,
const
bool
fwd_dns_update
,
const
bool
rev_dns_update
,
const
std
::
string
&
hostname
,
const
isc
::
hooks
::
CalloutHandlePtr
&
callout_handle
,
bool
fake_allocation
=
false
);
...
...
src/lib/dhcpsrv/lease.cc
0 → 100644
View file @
a26a75c9
// Copyright (C) 2012-2013 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#include <dhcpsrv/lease.h>
#include <sstream>
using
namespace
std
;
namespace
isc
{
namespace
dhcp
{
Lease
::
Lease
(
const
isc
::
asiolink
::
IOAddress
&
addr
,
uint32_t
t1
,
uint32_t
t2
,
uint32_t
valid_lft
,
SubnetID
subnet_id
,
time_t
cltt
,
const
bool
fqdn_fwd
,
const
bool
fqdn_rev
,
const
std
::
string
&
hostname
)
:
addr_
(
addr
),
t1_
(
t1
),
t2_
(
t2
),
valid_lft_
(
valid_lft
),
cltt_
(
cltt
),
subnet_id_
(
subnet_id
),
fixed_
(
false
),
hostname_
(
hostname
),
fqdn_fwd_
(
fqdn_fwd
),
fqdn_rev_
(
fqdn_rev
)
{
}
std
::
string
Lease
::
typeToText
(
Lease
::
Type
type
)
{
switch
(
type
)
{
case
Lease
::
TYPE_NA
:
return
string
(
"IA_NA"
);
case
Lease
::
TYPE_TA
:
return
string
(
"IA_TA"
);
case
Lease
::
TYPE_PD
:
return
string
(
"IA_PD"
);
break
;
default:
{
stringstream
tmp
;
tmp
<<
"unknown ("
<<
type
<<
")"
;
return
(
tmp
.
str
());
}
}
}
bool
Lease
::
expired
()
const
{
// Let's use int64 to avoid problems with negative/large uint32 values
int64_t
expire_time
=
cltt_
+
valid_lft_
;
return
(
expire_time
<
time
(
NULL
));
}
Lease4
::
Lease4
(
const
Lease4
&
other
)
:
Lease
(
other
.
addr_
,
other
.
t1_
,
other
.
t2_
,
other
.
valid_lft_
,
other
.
subnet_id_
,
other
.
cltt_
,
other
.
fqdn_fwd_
,
other
.
fqdn_rev_
,
other
.
hostname_
),
ext_
(
other
.
ext_
),
hwaddr_
(
other
.
hwaddr_
)
{
fixed_
=
other
.
fixed_
;
comments_
=
other
.
comments_
;
if
(
other
.
client_id_
)
{
client_id_
.
reset
(
new
ClientId
(
other
.
client_id_
->
getClientId
()));
}
else
{
client_id_
.
reset
();
}
}
Lease4
&
Lease4
::
operator
=
(
const
Lease4
&
other
)
{
if
(
this
!=
&
other
)
{
addr_
=
other
.
addr_
;
t1_
=
other
.
t1_
;
t2_
=
other
.
t2_
;
valid_lft_
=
other
.
valid_lft_
;
cltt_
=
other
.
cltt_
;
subnet_id_
=
other
.
subnet_id_
;
fixed_
=
other
.
fixed_
;
hostname_
=
other
.
hostname_
;
fqdn_fwd_
=
other
.
fqdn_fwd_
;
fqdn_rev_
=
other
.
fqdn_rev_
;
comments_
=
other
.
comments_
;
ext_
=
other
.
ext_
;
hwaddr_
=
other
.
hwaddr_
;
if
(
other
.
client_id_
)
{
client_id_
.
reset
(
new
ClientId
(
other
.
client_id_
->
getClientId
()));
}
else
{
client_id_
.
reset
();
}
}
return
(
*
this
);
}
Lease6
::
Lease6
(
Type
type
,
const
isc
::
asiolink
::
IOAddress
&
addr
,
DuidPtr
duid
,
uint32_t
iaid
,
uint32_t
preferred
,
uint32_t
valid
,
uint32_t
t1
,
uint32_t
t2
,
SubnetID
subnet_id
,
uint8_t
prefixlen
)
:
Lease
(
addr
,
t1
,
t2
,
valid
,
subnet_id
,
0
/*cltt*/
,
false
,
false
,
""
),
type_
(
type
),
prefixlen_
(
prefixlen
),
iaid_
(
iaid
),
duid_
(
duid
),