From: Thomas Markwalder Date: Fri, 29 Mar 2019 14:41:45 +0000 (-0400) Subject: [#413,!288] kea-dhcp6 now uses options from config backends X-Git-Tag: Kea-1.6.0-beta~270^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=72011040d1a49191b7c935a99dd459cb0463e8da;p=thirdparty%2Fkea.git [#413,!288] kea-dhcp6 now uses options from config backends 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 --- diff --git a/src/bin/dhcp6/tests/config_backend_unittest.cc b/src/bin/dhcp6/tests/config_backend_unittest.cc index a7add189c3..799de93b4f 100644 --- a/src/bin/dhcp6/tests/config_backend_unittest.cc +++ b/src/bin/dhcp6/tests/config_backend_unittest.cc @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -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(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(Option::V6, DHO_BOOT_FILE_NAME, - true, false, "my-boot-file"))); + createOption(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(Option::V6, DHO_BOOT_FILE_NAME, - true, false, "your-boot-file"))); + createOption(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(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(found_opt.option_); + ASSERT_TRUE(opint); + EXPECT_EQ(500, opint->getValue()); } // This test verifies that externally configured shared-networks are diff --git a/src/lib/dhcpsrv/srv_config.cc b/src/lib/dhcpsrv/srv_config.cc index 05a67bc3ee..e42ae4c78a 100644 --- a/src/lib/dhcpsrv/srv_config.cc +++ b/src/lib/dhcpsrv/srv_config.cc @@ -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())); diff --git a/src/lib/dhcpsrv/tests/cfg_option_unittest.cc b/src/lib/dhcpsrv/tests/cfg_option_unittest.cc index cc77262c4b..52660d6faa 100644 --- a/src/lib/dhcpsrv/tests/cfg_option_unittest.cc +++ b/src/lib/dhcpsrv/tests/cfg_option_unittest.cc @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -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(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 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(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";