From: Tomek Mrugalski Date: Thu, 8 May 2014 16:41:17 +0000 (+0200) Subject: [3400] Config file now may contain components other than Dhcp6 X-Git-Tag: trac3434_base~32^2~16 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7a296c1f10341d5713e345221eed2f70ee8fc5b1;p=thirdparty%2Fkea.git [3400] Config file now may contain components other than Dhcp6 --- diff --git a/doc/examples/kea6/several-subnets.json b/doc/examples/kea6/several-subnets.json index bafd790744..1fe7254e69 100644 --- a/doc/examples/kea6/several-subnets.json +++ b/doc/examples/kea6/several-subnets.json @@ -2,6 +2,8 @@ # It's a basic scenario with four IPv6 subnets configured. In each # subnet, there's a smaller pool of dynamic addresses. +{ "Dhcp6": + { # Kea is told to listen on eth0 interface only. "interfaces": [ "eth0" ], @@ -29,3 +31,6 @@ { "pool": [ "2001:db8:4::/80" ], "subnet": "2001:db8:4::/64" } ] } + +} + diff --git a/src/bin/dhcp6/jsonfile_backend.cc b/src/bin/dhcp6/jsonfile_backend.cc index a0b85757b0..c393dc473f 100644 --- a/src/bin/dhcp6/jsonfile_backend.cc +++ b/src/bin/dhcp6/jsonfile_backend.cc @@ -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()); diff --git a/src/bin/dhcp6/tests/jsonfile_backend_unittest.cc b/src/bin/dhcp6/tests/jsonfile_backend_unittest.cc index bb09bb2f55..f2ea959b25 100644 --- a/src/bin/dhcp6/tests/jsonfile_backend_unittest.cc +++ b/src/bin/dhcp6/tests/jsonfile_backend_unittest.cc @@ -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