mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-30 21:45:37 +00:00
[#3463] Addressed review comments
/src/hooks/dhcp/lease_cmds/lease_cmds.cc Add null lease checks /src/lib/dhcpsrv/lease.cc Lease4::decline() - wipe user context /src/lib/dhcpsrv/tests/lease_unittest.cc TEST_F(Lease4Test, decline) - verify user context is wiped
This commit is contained in:
@@ -2794,6 +2794,10 @@ LeaseCmdsImpl::leases4Committed(CalloutHandle& callout_handle,
|
|||||||
callout_handle.getArgument("response4", response);
|
callout_handle.getArgument("response4", response);
|
||||||
callout_handle.getArgument("leases4", leases);
|
callout_handle.getArgument("leases4", leases);
|
||||||
|
|
||||||
|
if (!leases) {
|
||||||
|
isc_throw(Unexpected, "leases4Committed - leases is null");
|
||||||
|
}
|
||||||
|
|
||||||
// In some cases we may have no lease, e.g. DHCPNAK,
|
// In some cases we may have no lease, e.g. DHCPNAK,
|
||||||
// or no response e.g. DHCPRELEASE.
|
// or no response e.g. DHCPRELEASE.
|
||||||
if (leases->empty() || !response || (response->getType() != DHCPACK)) {
|
if (leases->empty() || !response || (response->getType() != DHCPACK)) {
|
||||||
@@ -2802,7 +2806,7 @@ LeaseCmdsImpl::leases4Committed(CalloutHandle& callout_handle,
|
|||||||
|
|
||||||
Lease4Ptr lease = (*leases)[0];
|
Lease4Ptr lease = (*leases)[0];
|
||||||
if (!lease) {
|
if (!lease) {
|
||||||
isc_throw(Unexpected, "leases4Committed - no lease!");
|
isc_throw(Unexpected, "leases4Committed - lease is null");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -2832,6 +2836,10 @@ LeaseCmdsImpl::leases6Committed(CalloutHandle& callout_handle,
|
|||||||
callout_handle.getArgument("response6", response);
|
callout_handle.getArgument("response6", response);
|
||||||
callout_handle.getArgument("leases6", leases);
|
callout_handle.getArgument("leases6", leases);
|
||||||
|
|
||||||
|
if (!leases) {
|
||||||
|
isc_throw(Unexpected, "leases6Committed - leases is null");
|
||||||
|
}
|
||||||
|
|
||||||
// In some cases we may have no active leases or no response.
|
// In some cases we may have no active leases or no response.
|
||||||
if (leases->empty() || !response) {
|
if (leases->empty() || !response) {
|
||||||
return;
|
return;
|
||||||
@@ -2841,6 +2849,10 @@ LeaseCmdsImpl::leases6Committed(CalloutHandle& callout_handle,
|
|||||||
int failed = 0;
|
int failed = 0;
|
||||||
for (auto lease : *leases) {
|
for (auto lease : *leases) {
|
||||||
try {
|
try {
|
||||||
|
if (!lease) {
|
||||||
|
isc_throw(Unexpected, "leases6Committed - lease is null");
|
||||||
|
}
|
||||||
|
|
||||||
/// @todo - Users might want to only update NA or PD leases.
|
/// @todo - Users might want to only update NA or PD leases.
|
||||||
/// This could be done via adding a lease type to the variable.
|
/// This could be done via adding a lease type to the variable.
|
||||||
/// V4 would not use it, for V6 it would restrict a variable
|
/// V4 would not use it, for V6 it would restrict a variable
|
||||||
|
@@ -383,6 +383,7 @@ Lease4::decline(uint32_t probation_period) {
|
|||||||
fqdn_rev_ = false;
|
fqdn_rev_ = false;
|
||||||
state_ = STATE_DECLINED;
|
state_ = STATE_DECLINED;
|
||||||
valid_lft_ = probation_period;
|
valid_lft_ = probation_period;
|
||||||
|
setContext(ElementPtr());
|
||||||
}
|
}
|
||||||
|
|
||||||
isc::data::ElementPtr
|
isc::data::ElementPtr
|
||||||
|
@@ -593,6 +593,9 @@ TEST_F(Lease4Test, decline) {
|
|||||||
lease.fqdn_rev_ = true;
|
lease.fqdn_rev_ = true;
|
||||||
|
|
||||||
time_t now = time(0);
|
time_t now = time(0);
|
||||||
|
ElementPtr context = Element::createMap();
|
||||||
|
context->set("bogus", Element::create("true"));
|
||||||
|
lease.setContext(context);
|
||||||
|
|
||||||
// Move lease to declined state and set its valid-lifetime to 123 seconds
|
// Move lease to declined state and set its valid-lifetime to 123 seconds
|
||||||
lease.decline(123);
|
lease.decline(123);
|
||||||
|
Reference in New Issue
Block a user