Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
ISC Open Source Projects
Kea
Commits
91bfb283
Commit
91bfb283
authored
Aug 20, 2015
by
Tomek Mrugalski
🛰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[3983] Support for 'decline-probation-period' implemented.
parent
e9c58e3d
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
194 additions
and
6 deletions
+194
-6
src/bin/dhcp4/json_config_parser.cc
src/bin/dhcp4/json_config_parser.cc
+21
-3
src/bin/dhcp4/tests/config_parser_unittest.cc
src/bin/dhcp4/tests/config_parser_unittest.cc
+46
-0
src/bin/dhcp6/json_config_parser.cc
src/bin/dhcp6/json_config_parser.cc
+24
-1
src/bin/dhcp6/tests/config_parser_unittest.cc
src/bin/dhcp6/tests/config_parser_unittest.cc
+46
-0
src/lib/dhcpsrv/Makefile.am
src/lib/dhcpsrv/Makefile.am
+1
-0
src/lib/dhcpsrv/defaults.h
src/lib/dhcpsrv/defaults.h
+38
-0
src/lib/dhcpsrv/srv_config.cc
src/lib/dhcpsrv/srv_config.cc
+4
-2
src/lib/dhcpsrv/srv_config.h
src/lib/dhcpsrv/srv_config.h
+14
-0
No files found.
src/bin/dhcp4/json_config_parser.cc
View file @
91bfb283
...
@@ -21,6 +21,7 @@
...
@@ -21,6 +21,7 @@
#include <dhcpsrv/cfg_option.h>
#include <dhcpsrv/cfg_option.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcp4/json_config_parser.h>
#include <dhcp4/json_config_parser.h>
#include <dhcpsrv/defaults.h>
#include <dhcpsrv/option_space_container.h>
#include <dhcpsrv/option_space_container.h>
#include <dhcpsrv/parsers/dbaccess_parser.h>
#include <dhcpsrv/parsers/dbaccess_parser.h>
#include <dhcpsrv/parsers/dhcp_parsers.h>
#include <dhcpsrv/parsers/dhcp_parsers.h>
...
@@ -375,7 +376,8 @@ namespace dhcp {
...
@@ -375,7 +376,8 @@ namespace dhcp {
DhcpConfigParser
*
parser
=
NULL
;
DhcpConfigParser
*
parser
=
NULL
;
if
((
config_id
.
compare
(
"valid-lifetime"
)
==
0
)
||
if
((
config_id
.
compare
(
"valid-lifetime"
)
==
0
)
||
(
config_id
.
compare
(
"renew-timer"
)
==
0
)
||
(
config_id
.
compare
(
"renew-timer"
)
==
0
)
||
(
config_id
.
compare
(
"rebind-timer"
)
==
0
))
{
(
config_id
.
compare
(
"rebind-timer"
)
==
0
)
||
(
config_id
.
compare
(
"decline-probation-period"
)
==
0
)
)
{
parser
=
new
Uint32Parser
(
config_id
,
parser
=
new
Uint32Parser
(
config_id
,
globalContext
()
->
uint32_values_
);
globalContext
()
->
uint32_values_
);
}
else
if
(
config_id
.
compare
(
"interfaces-config"
)
==
0
)
{
}
else
if
(
config_id
.
compare
(
"interfaces-config"
)
==
0
)
{
...
@@ -411,7 +413,13 @@ namespace dhcp {
...
@@ -411,7 +413,13 @@ namespace dhcp {
return
(
parser
);
return
(
parser
);
}
}
void
commitGlobalOptions
()
{
/// @brief Commits global parameters
///
/// Currently this method sets the following global parameters:
///
/// - echo-client-id
/// - decline-probation-period
void
commitGlobalParameters4
()
{
// Although the function is modest for now, it is certain that the number
// Although the function is modest for now, it is certain that the number
// of global switches will increase over time, hence the name.
// of global switches will increase over time, hence the name.
...
@@ -423,6 +431,16 @@ void commitGlobalOptions() {
...
@@ -423,6 +431,16 @@ void commitGlobalOptions() {
}
catch
(...)
{
}
catch
(...)
{
// Ignore errors. This flag is optional
// Ignore errors. This flag is optional
}
}
// Set the probation period for decline handling.
try
{
uint32_t
probation_period
=
globalContext
()
->
uint32_values_
->
getOptionalParam
(
"decline-probation-period"
,
DEFAULT_DECLINE_PROBATION_PERIOD
);
CfgMgr
::
instance
().
getStagingCfg
()
->
setDeclinePeriod
(
probation_period
);
}
catch
(...)
{
// That's not really needed.
}
}
}
isc
::
data
::
ConstElementPtr
isc
::
data
::
ConstElementPtr
...
@@ -592,7 +610,7 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
...
@@ -592,7 +610,7 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
// CfgMgr::commit() function.
// CfgMgr::commit() function.
// Apply global options
// Apply global options
commitGlobal
Options
();
commitGlobal
Parameters4
();
// This occurs last as if it succeeds, there is no easy way
// This occurs last as if it succeeds, there is no easy way
// revert it. As a result, the failure to commit a subsequent
// revert it. As a result, the failure to commit a subsequent
...
...
src/bin/dhcp4/tests/config_parser_unittest.cc
View file @
91bfb283
...
@@ -32,6 +32,7 @@
...
@@ -32,6 +32,7 @@
#include <dhcpsrv/cfg_hosts.h>
#include <dhcpsrv/cfg_hosts.h>
#include <dhcpsrv/cfg_subnets4.h>
#include <dhcpsrv/cfg_subnets4.h>
#include <dhcpsrv/testutils/config_result_check.h>
#include <dhcpsrv/testutils/config_result_check.h>
#include <dhcpsrv/defaults.h>
#include <hooks/hooks_manager.h>
#include <hooks/hooks_manager.h>
#include "marker_file.h"
#include "marker_file.h"
...
@@ -3647,4 +3648,49 @@ TEST_F(Dhcp4ParserTest, hostReservationPerSubnet) {
...
@@ -3647,4 +3648,49 @@ TEST_F(Dhcp4ParserTest, hostReservationPerSubnet) {
EXPECT_EQ
(
Subnet
::
HR_ALL
,
subnet
->
getHostReservationMode
());
EXPECT_EQ
(
Subnet
::
HR_ALL
,
subnet
->
getHostReservationMode
());
}
}
/// Check that the decline-probation-period has a default value when not
/// specified.
TEST_F
(
Dhcp4ParserTest
,
declineTimerDefault
)
{
ConstElementPtr
status
;
string
config
=
"{ "
+
genIfaceConfig
()
+
","
+
"
\"
subnet4
\"
: [ ]"
"}"
;
ElementPtr
json
=
Element
::
fromJSON
(
config
);
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
// returned value should be 0 (success)
checkResult
(
status
,
0
);
// The value of decline-probation-perion must be equal to the
// default value.
EXPECT_EQ
(
DEFAULT_DECLINE_PROBATION_PERIOD
,
CfgMgr
::
instance
().
getStagingCfg
()
->
getDeclinePeriod
());
}
/// Check that the decline-probation-period value can be set properly.
TEST_F
(
Dhcp4ParserTest
,
declineTimer
)
{
ConstElementPtr
status
;
string
config
=
"{ "
+
genIfaceConfig
()
+
","
+
"
\"
decline-probation-period
\"
: 12345,"
"
\"
subnet4
\"
: [ ]"
"}"
;
ElementPtr
json
=
Element
::
fromJSON
(
config
);
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
// returned value should be 0 (success)
checkResult
(
status
,
0
);
// The value of decline-probation-perion must be equal to the
// value specified.
EXPECT_EQ
(
12345
,
CfgMgr
::
instance
().
getStagingCfg
()
->
getDeclinePeriod
());
}
}
}
src/bin/dhcp6/json_config_parser.cc
View file @
91bfb283
...
@@ -27,6 +27,7 @@
...
@@ -27,6 +27,7 @@
#include <dhcpsrv/pool.h>
#include <dhcpsrv/pool.h>
#include <dhcpsrv/subnet.h>
#include <dhcpsrv/subnet.h>
#include <dhcpsrv/triplet.h>
#include <dhcpsrv/triplet.h>
#include <dhcpsrv/defaults.h>
#include <dhcpsrv/parsers/dbaccess_parser.h>
#include <dhcpsrv/parsers/dbaccess_parser.h>
#include <dhcpsrv/parsers/dhcp_config_parser.h>
#include <dhcpsrv/parsers/dhcp_config_parser.h>
#include <dhcpsrv/parsers/dhcp_parsers.h>
#include <dhcpsrv/parsers/dhcp_parsers.h>
...
@@ -666,7 +667,8 @@ namespace dhcp {
...
@@ -666,7 +667,8 @@ namespace dhcp {
if
((
config_id
.
compare
(
"preferred-lifetime"
)
==
0
)
||
if
((
config_id
.
compare
(
"preferred-lifetime"
)
==
0
)
||
(
config_id
.
compare
(
"valid-lifetime"
)
==
0
)
||
(
config_id
.
compare
(
"valid-lifetime"
)
==
0
)
||
(
config_id
.
compare
(
"renew-timer"
)
==
0
)
||
(
config_id
.
compare
(
"renew-timer"
)
==
0
)
||
(
config_id
.
compare
(
"rebind-timer"
)
==
0
))
{
(
config_id
.
compare
(
"rebind-timer"
)
==
0
)
||
(
config_id
.
compare
(
"decline-probation-period"
)
==
0
)
)
{
parser
=
new
Uint32Parser
(
config_id
,
parser
=
new
Uint32Parser
(
config_id
,
globalContext
()
->
uint32_values_
);
globalContext
()
->
uint32_values_
);
}
else
if
(
config_id
.
compare
(
"interfaces-config"
)
==
0
)
{
}
else
if
(
config_id
.
compare
(
"interfaces-config"
)
==
0
)
{
...
@@ -702,6 +704,24 @@ namespace dhcp {
...
@@ -702,6 +704,24 @@ namespace dhcp {
return
(
parser
);
return
(
parser
);
}
}
/// @brief Commits global parameters
///
/// Currently this method sets the following global parameters:
///
/// - decline-probation-period
void
commitGlobalParameters6
()
{
// Set the probation period for decline handling.
try
{
uint32_t
probation_period
=
globalContext
()
->
uint32_values_
->
getOptionalParam
(
"decline-probation-period"
,
DEFAULT_DECLINE_PROBATION_PERIOD
);
CfgMgr
::
instance
().
getStagingCfg
()
->
setDeclinePeriod
(
probation_period
);
}
catch
(...)
{
// That's not really needed.
}
}
isc
::
data
::
ConstElementPtr
isc
::
data
::
ConstElementPtr
configureDhcp6Server
(
Dhcpv6Srv
&
,
isc
::
data
::
ConstElementPtr
config_set
)
{
configureDhcp6Server
(
Dhcpv6Srv
&
,
isc
::
data
::
ConstElementPtr
config_set
)
{
if
(
!
config_set
)
{
if
(
!
config_set
)
{
...
@@ -870,6 +890,9 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) {
...
@@ -870,6 +890,9 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) {
subnet_parser
->
commit
();
subnet_parser
->
commit
();
}
}
// Commit global options
commitGlobalParameters6
();
// No need to commit interface names as this is handled by the
// No need to commit interface names as this is handled by the
// CfgMgr::commit() function.
// CfgMgr::commit() function.
...
...
src/bin/dhcp6/tests/config_parser_unittest.cc
View file @
91bfb283
...
@@ -27,6 +27,7 @@
...
@@ -27,6 +27,7 @@
#include <dhcpsrv/addr_utilities.h>
#include <dhcpsrv/addr_utilities.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/cfg_hosts.h>
#include <dhcpsrv/cfg_hosts.h>
#include <dhcpsrv/defaults.h>
#include <dhcpsrv/subnet.h>
#include <dhcpsrv/subnet.h>
#include <dhcpsrv/subnet_selector.h>
#include <dhcpsrv/subnet_selector.h>
#include <dhcpsrv/testutils/config_result_check.h>
#include <dhcpsrv/testutils/config_result_check.h>
...
@@ -3982,4 +3983,49 @@ TEST_F(Dhcp6ParserTest, rsooBogusName) {
...
@@ -3982,4 +3983,49 @@ TEST_F(Dhcp6ParserTest, rsooBogusName) {
EXPECT_TRUE
(
errorContainsPosition
(
status
,
"<string>"
));
EXPECT_TRUE
(
errorContainsPosition
(
status
,
"<string>"
));
}
}
/// Check that the decline-probation-period value can be set properly.
TEST_F
(
Dhcp6ParserTest
,
declineTimerDefault
)
{
ConstElementPtr
status
;
string
config_txt
=
"{ "
+
genIfaceConfig
()
+
","
"
\"
subnet6
\"
: [ ] "
"}"
;
ElementPtr
config
=
Element
::
fromJSON
(
config_txt
);
EXPECT_NO_THROW
(
status
=
configureDhcp6Server
(
srv_
,
config
));
// returned value should be 0 (success)
checkResult
(
status
,
0
);
// The value of decline-probation-perion must be equal to the
// default value.
EXPECT_EQ
(
DEFAULT_DECLINE_PROBATION_PERIOD
,
CfgMgr
::
instance
().
getStagingCfg
()
->
getDeclinePeriod
());
}
/// Check that the decline-probation-period value can be set properly.
TEST_F
(
Dhcp6ParserTest
,
declineTimer
)
{
ConstElementPtr
status
;
string
config
=
"{ "
+
genIfaceConfig
()
+
","
+
"
\"
decline-probation-period
\"
: 12345,"
"
\"
subnet6
\"
: [ ]"
"}"
;
ElementPtr
json
=
Element
::
fromJSON
(
config
);
EXPECT_NO_THROW
(
status
=
configureDhcp6Server
(
srv_
,
json
));
// returned value should be 0 (success)
checkResult
(
status
,
0
);
// The value of decline-probation-perion must be equal to the
// value specified.
EXPECT_EQ
(
12345
,
CfgMgr
::
instance
().
getStagingCfg
()
->
getDeclinePeriod
());
}
};
};
src/lib/dhcpsrv/Makefile.am
View file @
91bfb283
...
@@ -92,6 +92,7 @@ libkea_dhcpsrv_la_SOURCES += csv_lease_file6.cc csv_lease_file6.h
...
@@ -92,6 +92,7 @@ libkea_dhcpsrv_la_SOURCES += csv_lease_file6.cc csv_lease_file6.h
libkea_dhcpsrv_la_SOURCES
+=
d2_client_cfg.cc d2_client_cfg.h
libkea_dhcpsrv_la_SOURCES
+=
d2_client_cfg.cc d2_client_cfg.h
libkea_dhcpsrv_la_SOURCES
+=
d2_client_mgr.cc d2_client_mgr.h
libkea_dhcpsrv_la_SOURCES
+=
d2_client_mgr.cc d2_client_mgr.h
libkea_dhcpsrv_la_SOURCES
+=
daemon.cc daemon.h
libkea_dhcpsrv_la_SOURCES
+=
daemon.cc daemon.h
libkea_dhcpsrv_la_SOURCES
+=
defaults.h
libkea_dhcpsrv_la_SOURCES
+=
dhcpsrv_log.cc dhcpsrv_log.h
libkea_dhcpsrv_la_SOURCES
+=
dhcpsrv_log.cc dhcpsrv_log.h
libkea_dhcpsrv_la_SOURCES
+=
host.cc host.h
libkea_dhcpsrv_la_SOURCES
+=
host.cc host.h
libkea_dhcpsrv_la_SOURCES
+=
host_container.h
libkea_dhcpsrv_la_SOURCES
+=
host_container.h
...
...
src/lib/dhcpsrv/defaults.h
0 → 100644
View file @
91bfb283
// Copyright (C) 2015 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.
/// @file defaults.h
///
/// @brief Contains the default values of the server.
#ifndef DEFAULTS_H
#define DEFAULTS_H
#include <stdint.h>
namespace
isc
{
namespace
dhcp
{
/// @brief Number of seconds after declined lease recovers
///
/// This define specifies the default value for decline probation period.
/// Once a lease is declined, it will spend this amount of seconds as
/// being unavailable. This is only the default value. Specific value may
/// be defined in the configuration file. The default is 1 day.
static
const
uint32_t
DEFAULT_DECLINE_PROBATION_PERIOD
=
24
*
3600
;
};
};
#endif
src/lib/dhcpsrv/srv_config.cc
View file @
91bfb283
...
@@ -30,14 +30,16 @@ SrvConfig::SrvConfig()
...
@@ -30,14 +30,16 @@ SrvConfig::SrvConfig()
:
sequence_
(
0
),
cfg_iface_
(
new
CfgIface
()),
:
sequence_
(
0
),
cfg_iface_
(
new
CfgIface
()),
cfg_option_def_
(
new
CfgOptionDef
()),
cfg_option_
(
new
CfgOption
()),
cfg_option_def_
(
new
CfgOptionDef
()),
cfg_option_
(
new
CfgOption
()),
cfg_subnets4_
(
new
CfgSubnets4
()),
cfg_subnets6_
(
new
CfgSubnets6
()),
cfg_subnets4_
(
new
CfgSubnets4
()),
cfg_subnets6_
(
new
CfgSubnets6
()),
cfg_hosts_
(
new
CfgHosts
()),
cfg_rsoo_
(
new
CfgRSOO
())
{
cfg_hosts_
(
new
CfgHosts
()),
cfg_rsoo_
(
new
CfgRSOO
()),
decline_timer_
(
0
)
{
}
}
SrvConfig
::
SrvConfig
(
const
uint32_t
sequence
)
SrvConfig
::
SrvConfig
(
const
uint32_t
sequence
)
:
sequence_
(
sequence
),
cfg_iface_
(
new
CfgIface
()),
:
sequence_
(
sequence
),
cfg_iface_
(
new
CfgIface
()),
cfg_option_def_
(
new
CfgOptionDef
()),
cfg_option_
(
new
CfgOption
()),
cfg_option_def_
(
new
CfgOptionDef
()),
cfg_option_
(
new
CfgOption
()),
cfg_subnets4_
(
new
CfgSubnets4
()),
cfg_subnets6_
(
new
CfgSubnets6
()),
cfg_subnets4_
(
new
CfgSubnets4
()),
cfg_subnets6_
(
new
CfgSubnets6
()),
cfg_hosts_
(
new
CfgHosts
()),
cfg_rsoo_
(
new
CfgRSOO
())
{
cfg_hosts_
(
new
CfgHosts
()),
cfg_rsoo_
(
new
CfgRSOO
()),
decline_timer_
(
0
)
{
}
}
std
::
string
std
::
string
...
...
src/lib/dhcpsrv/srv_config.h
View file @
91bfb283
...
@@ -376,6 +376,17 @@ public:
...
@@ -376,6 +376,17 @@ public:
/// @ref CfgSubnets6::removeStatistics for details.
/// @ref CfgSubnets6::removeStatistics for details.
void
removeStatistics
();
void
removeStatistics
();
/// @brief Sets decline probation-period
/// @param decline_timer number of seconds after declined lease is restored
void
setDeclinePeriod
(
uint32_t
decline_timer
)
{
decline_timer_
=
decline_timer
;
}
/// @brief
uint32_t
getDeclinePeriod
()
const
{
return
(
decline_timer_
);
}
private:
private:
/// @brief Sequence number identifying the configuration.
/// @brief Sequence number identifying the configuration.
...
@@ -425,6 +436,9 @@ private:
...
@@ -425,6 +436,9 @@ private:
/// @brief Pointer to the control-socket information
/// @brief Pointer to the control-socket information
isc
::
data
::
ConstElementPtr
control_socket_
;
isc
::
data
::
ConstElementPtr
control_socket_
;
/// @brief Decline Period time
uint32_t
decline_timer_
;
};
};
/// @name Pointers to the @c SrvConfig object.
/// @name Pointers to the @c SrvConfig object.
...
...
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