Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
Kea
Commits
cb0fd5fa
Commit
cb0fd5fa
authored
Apr 10, 2018
by
Tomek Mrugalski
🛰
Browse files
[5543] leaseX-wipe now allows deleting leases from all subnets.
parent
c8ddecea
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/hooks/dhcp/lease_cmds/lease_cmds.cc
View file @
cb0fd5fa
...
...
@@ -767,10 +767,28 @@ LeaseCmdsImpl::lease4WipeHandler(CalloutHandle& handle) {
SimpleParser
parser
;
SubnetID
id
=
parser
.
getUint32
(
cmd_args_
,
"subnet-id"
);
size_t
num
=
LeaseMgrFactory
::
instance
().
wipeLeases4
(
id
);
size_t
num
=
0
;
// number of leases deleted
stringstream
ids
;
// a text with subnet-ids being wiped
if
(
id
)
{
// Wipe a single subnet
num
=
LeaseMgrFactory
::
instance
().
wipeLeases4
(
id
);
ids
<<
id
;
}
else
{
// Wipe them all!
ConstSrvConfigPtr
config
=
CfgMgr
::
instance
().
getCurrentCfg
();
ConstCfgSubnets4Ptr
subnets
=
config
->
getCfgSubnets4
();
const
Subnet4Collection
*
subs
=
subnets
->
getAll
();
// Go over all subnets and wipe leases in each of them.
for
(
auto
sub
:
*
subs
)
{
num
+=
LeaseMgrFactory
::
instance
().
wipeLeases4
(
sub
->
getID
());
ids
<<
sub
->
getID
()
<<
" "
;
}
}
stringstream
tmp
;
tmp
<<
"Deleted "
<<
num
<<
" IPv4 lease(s)
."
;
tmp
<<
"Deleted "
<<
num
<<
" IPv4 lease(s)
from subnet(s) "
<<
ids
.
str
()
;
ConstElementPtr
response
=
createAnswer
(
num
?
CONTROL_RESULT_SUCCESS
:
CONTROL_RESULT_EMPTY
,
tmp
.
str
());
setResponse
(
handle
,
response
);
...
...
@@ -795,10 +813,28 @@ LeaseCmdsImpl::lease6WipeHandler(CalloutHandle& handle) {
SimpleParser
parser
;
SubnetID
id
=
parser
.
getUint32
(
cmd_args_
,
"subnet-id"
);
size_t
num
=
LeaseMgrFactory
::
instance
().
wipeLeases6
(
id
);
size_t
num
=
0
;
// number of leases deleted
stringstream
ids
;
// a text with subnet-ids being wiped
if
(
id
)
{
// Wipe a single subnet.
num
=
LeaseMgrFactory
::
instance
().
wipeLeases6
(
id
);
ids
<<
id
;
}
else
{
// Wipe them all!
ConstSrvConfigPtr
config
=
CfgMgr
::
instance
().
getCurrentCfg
();
ConstCfgSubnets6Ptr
subnets
=
config
->
getCfgSubnets6
();
const
Subnet6Collection
*
subs
=
subnets
->
getAll
();
// Go over all subnets and wipe leases in each of them.
for
(
auto
sub
:
*
subs
)
{
num
+=
LeaseMgrFactory
::
instance
().
wipeLeases6
(
sub
->
getID
());
ids
<<
sub
->
getID
()
<<
" "
;
}
}
stringstream
tmp
;
tmp
<<
"Deleted "
<<
num
<<
" IPv6 lease(s)
."
;
tmp
<<
"Deleted "
<<
num
<<
" IPv6 lease(s)
from subnet(s) "
<<
ids
.
str
()
;
ConstElementPtr
response
=
createAnswer
(
num
?
CONTROL_RESULT_SUCCESS
:
CONTROL_RESULT_EMPTY
,
tmp
.
str
());
setResponse
(
handle
,
response
);
...
...
src/hooks/dhcp/lease_cmds/tests/lease_cmds_unittest.cc
View file @
cb0fd5fa
...
...
@@ -2679,11 +2679,43 @@ TEST_F(LeaseCmdsTest, Lease4Wipe) {
"
\"
subnet-id
\"
: 44"
" }
\n
"
"}"
;
string
exp_rsp
=
"Deleted 2 IPv4 lease(s)
.
"
;
string
exp_rsp
=
"Deleted 2 IPv4 lease(s)
from subnet(s) 44
"
;
testCommand
(
cmd
,
CONTROL_RESULT_SUCCESS
,
exp_rsp
);
// Make sure the lease i
s
really gone.
// Make sure the lease
s
i
n subnet 44 are
really gone.
EXPECT_FALSE
(
lmptr_
->
getLease4
(
IOAddress
(
"192.0.2.1"
)));
EXPECT_FALSE
(
lmptr_
->
getLease4
(
IOAddress
(
"192.0.2.2"
)));
// Make sure the leases from subnet 88 are still there.
EXPECT_TRUE
(
lmptr_
->
getLease4
(
IOAddress
(
"192.0.3.1"
)));
EXPECT_TRUE
(
lmptr_
->
getLease4
(
IOAddress
(
"192.0.3.2"
)));
}
// Checks that lease4-wipe can remove leases from all subnets
// at once.
TEST_F
(
LeaseCmdsTest
,
Lease4WipeAll
)
{
// Initialize lease manager (false = v4, true = add a lease)
initLeaseMgr
(
false
,
true
);
// Query for valid, existing lease.
string
cmd
=
"{
\n
"
"
\"
command
\"
:
\"
lease4-wipe
\"
,
\n
"
"
\"
arguments
\"
: {"
"
\"
subnet-id
\"
: 0"
" }
\n
"
"}"
;
string
exp_rsp
=
"Deleted 4 IPv4 lease(s) from subnet(s) 44 88 "
;
testCommand
(
cmd
,
CONTROL_RESULT_SUCCESS
,
exp_rsp
);
// Make sure the leases in subnet 44 are really gone.
EXPECT_FALSE
(
lmptr_
->
getLease4
(
IOAddress
(
"192.0.2.1"
)));
EXPECT_FALSE
(
lmptr_
->
getLease4
(
IOAddress
(
"192.0.2.2"
)));
// Make sure the leases from subnet 88 are gone, too.
EXPECT_FALSE
(
lmptr_
->
getLease4
(
IOAddress
(
"192.0.3.1"
)));
EXPECT_FALSE
(
lmptr_
->
getLease4
(
IOAddress
(
"192.0.3.2"
)));
}
// Checks that lease4-wipe properly reports when no leases were deleted.
...
...
@@ -2700,7 +2732,25 @@ TEST_F(LeaseCmdsTest, Lease4WipeNoLeases) {
"
\"
subnet-id
\"
: 44"
" }
\n
"
"}"
;
string
exp_rsp
=
"Deleted 0 IPv4 lease(s)."
;
string
exp_rsp
=
"Deleted 0 IPv4 lease(s) from subnet(s) 44"
;
testCommand
(
cmd
,
CONTROL_RESULT_EMPTY
,
exp_rsp
);
}
// Checks that lease4-wipe properly reports when no leases were deleted.
TEST_F
(
LeaseCmdsTest
,
Lease4WipeNoLeasesAll
)
{
// Initialize lease manager (false = v4, false = no leases)
initLeaseMgr
(
false
,
false
);
// Query for valid, existing lease.
string
cmd
=
"{
\n
"
"
\"
command
\"
:
\"
lease4-wipe
\"
,
\n
"
"
\"
arguments
\"
: {"
"
\"
subnet-id
\"
: 0"
" }
\n
"
"}"
;
string
exp_rsp
=
"Deleted 0 IPv4 lease(s) from subnet(s) 44 88 "
;
testCommand
(
cmd
,
CONTROL_RESULT_EMPTY
,
exp_rsp
);
}
...
...
@@ -2734,13 +2784,45 @@ TEST_F(LeaseCmdsTest, Lease6Wipe) {
"
\"
subnet-id
\"
: 66
\n
"
" }
\n
"
"}"
;
string
exp_rsp
=
"Deleted 2 IPv6 lease(s)
.
"
;
string
exp_rsp
=
"Deleted 2 IPv6 lease(s)
from subnet(s) 66
"
;
// The status expected is success. The lease should be deleted.
testCommand
(
cmd
,
CONTROL_RESULT_SUCCESS
,
exp_rsp
);
// Make sure the lease i
s
really gone.
// Make sure the lease
s
i
n subnet 44 are
really gone.
EXPECT_FALSE
(
lmptr_
->
getLease6
(
Lease
::
TYPE_NA
,
IOAddress
(
"2001:db8:1::1"
)));
EXPECT_FALSE
(
lmptr_
->
getLease6
(
Lease
::
TYPE_NA
,
IOAddress
(
"2001:db8:1::2"
)));
// The leases in subnet 88 are supposed to be still there.
EXPECT_TRUE
(
lmptr_
->
getLease6
(
Lease
::
TYPE_NA
,
IOAddress
(
"2001:db8:2::1"
)));
EXPECT_TRUE
(
lmptr_
->
getLease6
(
Lease
::
TYPE_NA
,
IOAddress
(
"2001:db8:2::2"
)));
}
// Checks that lease4-wipe can remove leases from all subnets
TEST_F
(
LeaseCmdsTest
,
Lease6WipeAll
)
{
initLeaseMgr
(
true
,
true
);
// (true = v6, true = create a lease)
// Now send the command.
string
cmd
=
"{
\n
"
"
\"
command
\"
:
\"
lease6-wipe
\"
,
\n
"
"
\"
arguments
\"
: {"
"
\"
subnet-id
\"
: 0
\n
"
" }
\n
"
"}"
;
string
exp_rsp
=
"Deleted 4 IPv6 lease(s) from subnet(s) 66 99 "
;
// The status expected is success. The lease should be deleted.
testCommand
(
cmd
,
CONTROL_RESULT_SUCCESS
,
exp_rsp
);
// Make sure the leases in subnet 44 are really gone.
EXPECT_FALSE
(
lmptr_
->
getLease6
(
Lease
::
TYPE_NA
,
IOAddress
(
"2001:db8:1::1"
)));
EXPECT_FALSE
(
lmptr_
->
getLease6
(
Lease
::
TYPE_NA
,
IOAddress
(
"2001:db8:1::2"
)));
// The leases in subnet 88 are supposed to be still there.
EXPECT_FALSE
(
lmptr_
->
getLease6
(
Lease
::
TYPE_NA
,
IOAddress
(
"2001:db8:2::1"
)));
EXPECT_FALSE
(
lmptr_
->
getLease6
(
Lease
::
TYPE_NA
,
IOAddress
(
"2001:db8:2::2"
)));
}
// Checks that lease4-wipe properly reports when no leases were deleted.
...
...
@@ -2757,7 +2839,25 @@ TEST_F(LeaseCmdsTest, Lease6WipeNoLeases) {
"
\"
subnet-id
\"
: 66"
" }
\n
"
"}"
;
string
exp_rsp
=
"Deleted 0 IPv6 lease(s)."
;
string
exp_rsp
=
"Deleted 0 IPv6 lease(s) from subnet(s) 66"
;
testCommand
(
cmd
,
CONTROL_RESULT_EMPTY
,
exp_rsp
);
}
// Checks that lease4-wipe properly reports when no leases were deleted.
TEST_F
(
LeaseCmdsTest
,
Lease6WipeNoLeasesAll
)
{
// Initialize lease manager (false = v4, false = no leases)
initLeaseMgr
(
true
,
false
);
// Query for valid, existing lease.
string
cmd
=
"{
\n
"
"
\"
command
\"
:
\"
lease6-wipe
\"
,
\n
"
"
\"
arguments
\"
: {"
"
\"
subnet-id
\"
: 0"
" }
\n
"
"}"
;
string
exp_rsp
=
"Deleted 0 IPv6 lease(s) from subnet(s) 66 99 "
;
testCommand
(
cmd
,
CONTROL_RESULT_EMPTY
,
exp_rsp
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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