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
Sebastian Schrader
Kea
Commits
7a296c1f
Commit
7a296c1f
authored
May 08, 2014
by
Tomek Mrugalski
🛰
Browse files
[3400] Config file now may contain components other than Dhcp6
parent
56e20ea0
Changes
3
Hide whitespace changes
Inline
Side-by-side
doc/examples/kea6/several-subnets.json
View file @
7a296c1f
...
...
@@ -2,6 +2,8 @@
#
It's
a
basic
scenario
with
four
IPv
6
subnets
configured.
In
each
#
subnet,
there's
a
smaller
pool
of
dynamic
addresses.
{
"Dhcp6"
:
{
#
Kea
is
told
to
listen
on
eth
0
interface
only.
"interfaces"
:
[
"eth0"
],
...
...
@@ -29,3 +31,6 @@
{
"pool"
:
[
"2001:db8:4::/80"
],
"subnet"
:
"2001:db8:4::/64"
}
]
}
}
src/bin/dhcp6/jsonfile_backend.cc
View file @
7a296c1f
...
...
@@ -48,6 +48,7 @@ ControlledDhcpv6Srv::init(const std::string& file_name) {
// configuration from a JSON file.
isc
::
data
::
ConstElementPtr
json
;
isc
::
data
::
ConstElementPtr
dhcp6
;
isc
::
data
::
ConstElementPtr
result
;
// Basic sanity check: file name must not be empty.
...
...
@@ -59,8 +60,25 @@ ControlledDhcpv6Srv::init(const std::string& file_name) {
// Read contents of the file and parse it as JSON
json
=
Element
::
fromJSONFile
(
file_name
,
true
);
if
(
!
json
)
{
LOG_ERROR
(
dhcp6_logger
,
DHCP6_CONFIG_LOAD_FAIL
)
.
arg
(
"Config file "
+
file_name
+
" missing or empty."
);
isc_throw
(
BadValue
,
"Unable to process JSON configuration file:"
+
file_name
);
}
// Get Dhcp6 component from the config
dhcp6
=
json
->
get
(
"Dhcp6"
);
if
(
!
dhcp6
)
{
LOG_ERROR
(
dhcp6_logger
,
DHCP6_CONFIG_LOAD_FAIL
)
.
arg
(
"Config file "
+
file_name
+
" does not include 'Dhcp6' entry."
);
isc_throw
(
BadValue
,
"Unable to process JSON configuration file:"
+
file_name
);
}
// Use parsed JSON structures to configure the server
result
=
processCommand
(
"config-reload"
,
json
);
result
=
processCommand
(
"config-reload"
,
dhcp6
);
}
catch
(
const
std
::
exception
&
ex
)
{
LOG_ERROR
(
dhcp6_logger
,
DHCP6_CONFIG_LOAD_FAIL
).
arg
(
ex
.
what
());
...
...
src/bin/dhcp6/tests/jsonfile_backend_unittest.cc
View file @
7a296c1f
...
...
@@ -73,7 +73,7 @@ const char* JSONFileBackendTest::TEST_FILE = "test-config.json";
TEST_F
(
JSONFileBackendTest
,
jsonFile
)
{
// Prepare configuration file.
string
config
=
"{
\"
interfaces
\"
: [
\"
*
\"
],"
string
config
=
"{
\"
Dhcp6
\"
: {
\"
interfaces
\"
: [
\"
*
\"
],"
"
\"
preferred-lifetime
\"
: 3000,"
"
\"
rebind-timer
\"
: 2000, "
"
\"
renew-timer
\"
: 1000, "
...
...
@@ -90,7 +90,8 @@ TEST_F(JSONFileBackendTest, jsonFile) {
"
\"
pool
\"
: [
\"
2001:db8:3::/80
\"
],"
"
\"
subnet
\"
:
\"
2001:db8:3::/64
\"
"
" } ],"
"
\"
valid-lifetime
\"
: 4000 }"
;
"
\"
valid-lifetime
\"
: 4000 }"
"}"
;
writeFile
(
TEST_FILE
,
config
);
// Now initialize the server
...
...
@@ -146,7 +147,7 @@ TEST_F(JSONFileBackendTest, comments) {
string
config_hash_comments
=
"# This is a comment. It should be
\n
"
"#ignored. Real config starts in line below
\n
"
"{
\"
interfaces
\"
: [
\"
*
\"
],"
"{
\"
Dhcp6
\"
: {
\"
interfaces
\"
: [
\"
*
\"
],"
"
\"
preferred-lifetime
\"
: 3000,"
"
\"
rebind-timer
\"
: 2000, "
"
\"
renew-timer
\"
: 1000,
\n
"
...
...
@@ -155,7 +156,8 @@ TEST_F(JSONFileBackendTest, comments) {
"
\"
pool
\"
: [
\"
2001:db8:1::/80
\"
],"
"
\"
subnet
\"
:
\"
2001:db8:1::/64
\"
"
" } ],"
"
\"
valid-lifetime
\"
: 4000 }"
;
"
\"
valid-lifetime
\"
: 4000 }"
"}"
;
/// @todo: Implement C++-style (// ...) comments
/// @todo: Implement C-style (/* ... */) comments
...
...
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