]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#413,!288] kea-dhcp6 now uses options from config backends
authorThomas Markwalder <tmark@isc.org>
Fri, 29 Mar 2019 14:41:45 +0000 (10:41 -0400)
committerThomas Markwalder <tmark@isc.org>
Wed, 10 Apr 2019 17:36:13 +0000 (13:36 -0400)
src/bin/dhcp6/tests/config_backend_unittest.cc
    TEST_F(Dhcp6CBTest, mergeOptions) - enabled and
    revamped.

src/lib/dhcpsrv/tests/cfg_option_unittest.cc
    TEST_F(CfgOptionTest, createDescriptorOptionValid) - added test
    of a standard V6 option

src/lib/dhcpsrv/srv_config.cc
    SrvConfig::merge6(SrvConfig& other) - now merges
    options

src/bin/dhcp6/tests/config_backend_unittest.cc
src/lib/dhcpsrv/srv_config.cc
src/lib/dhcpsrv/tests/cfg_option_unittest.cc

index a7add189c3c1618482ee97324948ac69a3040b50..799de93b4fc4059ef523b428b3de2dd4433b11cb 100644 (file)
@@ -10,6 +10,7 @@
 #include <gtest/gtest.h>
 
 #include <database/backend_selector.h>
+#include <dhcp/option_int.h>
 #include <dhcp/option_string.h>
 #include <dhcp/tests/iface_mgr_test_config.h>
 #include <dhcp6/dhcp6_srv.h>
@@ -299,17 +300,15 @@ TEST_F(Dhcp6CBTest, mergeOptionDefs) {
 
 // This test verifies that externally configured options
 // merged correctly into staging configuration.
-TEST_F(Dhcp6CBTest, DISABLED_mergeOptions) {
+TEST_F(Dhcp6CBTest, mergeOptions) {
     string base_config =
         "{ \n"
         "    \"option-data\": [ { \n"
-        "        \"name\": \"dhcp-message\", \n"
-        "        \"data\": \"0A0B0C0D\", \n"
-        "        \"csv-format\": false \n"
+        "        \"name\": \"solmax-rt\", \n"
+        "        \"data\": \"500\" \n"
         "     },{ \n"
-        "        \"name\": \"host-name\", \n"
-        "        \"data\": \"old.example.com\", \n"
-        "        \"csv-format\": true \n"
+        "        \"name\": \"bootfile-url\", \n"
+        "        \"data\": \"orig-boot-file\" \n"
         "     } \n"
         "    ], \n"
         "    \"config-control\": { \n"
@@ -324,55 +323,43 @@ TEST_F(Dhcp6CBTest, DISABLED_mergeOptions) {
         "   } \n"
         "} \n";
 
-    extractConfig(base_config);
 
     OptionDescriptorPtr opt;
-
-    // Add host-name to the first backend.
-    opt.reset(new OptionDescriptor(
-              createOption<OptionString>(Option::V6, DHO_HOST_NAME,
-                                         true, false, "new.example.com")));
-    opt->space_name_ = DHCP6_OPTION_SPACE;
-    db1_->createUpdateOption6(ServerSelector::ALL(), opt);
-
-    // Add boot-file-name to the first backend.
+    // Add solmax-rt to the first backend.
     opt.reset(new OptionDescriptor(
-              createOption<OptionString>(Option::V6, DHO_BOOT_FILE_NAME,
-                                         true, false, "my-boot-file")));
+              createOption<OptionString>(Option::V6, D6O_BOOTFILE_URL,
+                                         true, false, "updated-boot-file")));
     opt->space_name_ = DHCP6_OPTION_SPACE;
     db1_->createUpdateOption6(ServerSelector::ALL(), opt);
 
-    // Add boot-file-name to the second backend.
+    // Add solmax-rt to the second backend.
     opt.reset(new OptionDescriptor(
-              createOption<OptionString>(Option::V6, DHO_BOOT_FILE_NAME,
-                                         true, false, "your-boot-file")));
+              createOption<OptionUint32>(Option::V6, D6O_SOL_MAX_RT,
+                                         false, true, 700)));
     opt->space_name_ = DHCP6_OPTION_SPACE;
     db2_->createUpdateOption6(ServerSelector::ALL(), opt);
 
     // Should parse and merge without error.
     ASSERT_NO_FATAL_FAILURE(configure(base_config, CONTROL_RESULT_SUCCESS, ""));
 
-    // Verify the composite staging is correct.
+    //  Now let's verify that composite staging options are correct.
     SrvConfigPtr staging_cfg = CfgMgr::instance().getStagingCfg();
-
-    // Option definition from JSON should be there.
     CfgOptionPtr options = staging_cfg->getCfgOption();
 
-    // dhcp-message should come from the original config.
-    OptionDescriptor found_opt = options->get("dhcp6", DHO_DHCP_MESSAGE);
-    ASSERT_TRUE(found_opt.option_);
-    EXPECT_EQ("0x0A0B0C0D", found_opt.option_->toHexString());
-
-    // host-name should come from the first back end,
+    // bootfile-url should come from the first config back end.
     // (overwriting the original).
-    found_opt = options->get("dhcp6", DHO_HOST_NAME);
+    OptionDescriptor found_opt = options->get("dhcp6", D6O_BOOTFILE_URL);
     ASSERT_TRUE(found_opt.option_);
-    EXPECT_EQ("new.example.com", found_opt.option_->toString());
+    OptionStringPtr opstr = boost::dynamic_pointer_cast<OptionString>(found_opt.option_);
+    ASSERT_TRUE(opstr);
+    EXPECT_EQ("updated-boot-file", opstr->getValue());
 
-    // booth-file-name should come from the first back end.
-    found_opt = options->get("dhcp6", DHO_BOOT_FILE_NAME);
+    // sol-maxt-rt should come from the original config
+    found_opt = options->get("dhcp6", D6O_SOL_MAX_RT);
     ASSERT_TRUE(found_opt.option_);
-    EXPECT_EQ("my-boot-file", found_opt.option_->toString());
+    OptionUint32Ptr opint = boost::dynamic_pointer_cast<OptionUint32>(found_opt.option_);
+    ASSERT_TRUE(opint);
+    EXPECT_EQ(500, opint->getValue());
 }
 
 // This test verifies that externally configured shared-networks are
index 05a67bc3ee77ddc72315d01b48ff3a9c2862cb3b..e42ae4c78a14815ff3c95af36e3b8d247f6bbf49 100644 (file)
@@ -212,10 +212,10 @@ SrvConfig::merge6(SrvConfig& other) {
     // definitions.
     cfg_option_def_->merge((*other.getCfgOptionDef()));
 
-#if 0
     // Merge options.
     cfg_option_->merge(cfg_option_def_, (*other.getCfgOption()));
 
+#if 0
     // Merge shared networks.
     cfg_shared_networks6_->merge(cfg_option_def_, *(other.getCfgSharedNetworks6()));
 
index cc77262c4b5e9665fceec74f2292617f3bedeb17..52660d6faabfebcfebb54b8c8f81b3f5ef007910 100644 (file)
@@ -7,6 +7,7 @@
 #include <config.h>
 #include <dhcp/dhcp6.h>
 #include <dhcp/option.h>
+#include <dhcp/option_custom.h>
 #include <dhcp/option_int.h>
 #include <dhcp/option_int_array.h>
 #include <dhcp/option_space.h>
@@ -547,10 +548,10 @@ TEST_F(CfgOptionTest, createDescriptorOptionValid) {
     defs->add((OptionDefinitionPtr(new OptionDefinition("one", 1, "uint8"))), "isc");
     defs->add((OptionDefinitionPtr(new OptionDefinition("two", 2, "uint8", true))), "isc");
 
-    // We'll try a standard option first.
+    // We'll try a standard V4 option first.
     std::string space = "dhcp4";
-    std::string value("example.org");
-    OptionPtr option(new Option(Option::V4, DHO_HOST_NAME));
+    std::string value = "v4.example.com";
+    OptionPtr option(new Option(Option::V6, DHO_HOST_NAME));
     option->setData(value.begin(), value.end());
     OptionDescriptorPtr desc(new OptionDescriptor(option, false));
 
@@ -559,7 +560,21 @@ TEST_F(CfgOptionTest, createDescriptorOptionValid) {
     ASSERT_TRUE(updated);
     OptionStringPtr opstr = boost::dynamic_pointer_cast<OptionString>(desc->option_);
     ASSERT_TRUE(opstr);
-    EXPECT_EQ("example.org", opstr->getValue());
+    EXPECT_EQ("v4.example.com", opstr->getValue());
+
+    // Next we'll try a standard V6 option.
+    space = "dhcp6";
+    std::vector<uint8_t> fqdn =
+        { 2, 'v', '6', 7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 3, 'c', 'o', 'm', 0 };
+    option.reset(new Option(Option::V6, D6O_AFTR_NAME));
+    option->setData(fqdn.begin(), fqdn.end());
+    desc.reset(new OptionDescriptor(option, false));
+
+    ASSERT_NO_THROW(updated = CfgOption::createDescriptorOption(defs, space, *desc));
+    ASSERT_TRUE(updated);
+    OptionCustomPtr opcustom = boost::dynamic_pointer_cast<OptionCustom>(desc->option_);
+    ASSERT_TRUE(opcustom);
+    EXPECT_EQ("v6.example.com.", opcustom->readFqdn());
 
     // Next we'll try a vendor option with a formatted value
     space = "vendor-4491";