Browse Source

[3400] Config file now may contain components other than Dhcp6

Tomek Mrugalski 11 years ago
parent
commit
7a296c1f10

+ 5 - 0
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"  } ]
 }
+
+}
+

+ 19 - 1
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());

+ 6 - 4
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