From: Marcin Siodelski Date: Mon, 18 Aug 2014 12:55:49 +0000 (+0200) Subject: [3477] Return status of DDNS updates in the configuration summary. X-Git-Tag: trac3482_base~29^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d5ccd277c8747242b4d8a3aa3e8fdbf21a763e67;p=thirdparty%2Fkea.git [3477] Return status of DDNS updates in the configuration summary. --- diff --git a/src/lib/dhcpsrv/configuration.cc b/src/lib/dhcpsrv/configuration.cc index 92b2c9cf25..80289e6ac3 100644 --- a/src/lib/dhcpsrv/configuration.cc +++ b/src/lib/dhcpsrv/configuration.cc @@ -43,6 +43,11 @@ Configuration::getConfigSummary(const uint32_t selection) const { s << "; "; } + if ((selection & CFGSEL_DDNS) == CFGSEL_DDNS) { + bool ddns_enabled = CfgMgr::instance().ddnsEnabled(); + s << "DDNS: " << (ddns_enabled ? "enabled" : "disabled") << "; "; + } + if (s.tellp() == 0) { s << "no config details available"; } diff --git a/src/lib/dhcpsrv/configuration.h b/src/lib/dhcpsrv/configuration.h index 4294129165..514875664e 100644 --- a/src/lib/dhcpsrv/configuration.h +++ b/src/lib/dhcpsrv/configuration.h @@ -84,12 +84,14 @@ typedef std::vector LoggingInfoStorage; /// @todo Migrate all other configuration parameters from cfgmgr.h here struct Configuration { - static const uint16_t CFGSEL_NONE = 0x00000000; - static const uint16_t CFGSEL_SUBNET4 = 0x00000001; - static const uint16_t CFGSEL_SUBNET6 = 0x00000002; - static const uint16_t CFGSEL_ALL4 = 0x00000001; - static const uint16_t CFGSEL_ALL6 = 0x00000002; - static const uint16_t CFGSEL_ALL = 0x00000003; + static const uint16_t CFGSEL_NONE = 0x0000; + static const uint16_t CFGSEL_SUBNET4 = 0x0001; + static const uint16_t CFGSEL_SUBNET6 = 0x0002; + static const uint16_t CFGSEL_SUBNET = 0x0003; + static const uint16_t CFGSEL_ALL4 = 0x0001; + static const uint16_t CFGSEL_ALL6 = 0x0002; + static const uint16_t CFGSEL_DDNS = 0x0004; + static const uint16_t CFGSEL_ALL = 0xFFFF; /// @brief logging specific information LoggingInfoStorage logging_info_; diff --git a/src/lib/dhcpsrv/tests/configuration_unittest.cc b/src/lib/dhcpsrv/tests/configuration_unittest.cc index 6770595c67..a917bb8d8d 100644 --- a/src/lib/dhcpsrv/tests/configuration_unittest.cc +++ b/src/lib/dhcpsrv/tests/configuration_unittest.cc @@ -108,6 +108,12 @@ public: /// from @c CfgMgr to @c Configuration. void clearSubnets(); + /// @brief Enable/disable DDNS. + /// + /// @param enable A boolean value indicating if the DDNS should be + /// enabled (true) or disabled (false). + void enableDDNS(const bool enable); + /// @brief Stores configuration. Configuration conf_; /// @brief A collection of IPv4 subnets used by unit tests. @@ -141,6 +147,11 @@ ConfigurationTest::clearSubnets() { CfgMgr::instance().deleteSubnets6(); } +void +ConfigurationTest::enableDDNS(const bool enable) { + CfgMgr::instance().getD2ClientConfig()->enableUpdates(enable); +} + // Check that by default there are no logging entries TEST_F(ConfigurationTest, basic) { EXPECT_TRUE(conf_.logging_info_.empty()); @@ -171,6 +182,21 @@ TEST_F(ConfigurationTest, loggingInfo) { EXPECT_EQ(2097152, conf_.logging_info_[0].destinations_[0].maxsize_); } +// Check that the configuration summary including information about the status +// of DDNS is returned. +TEST_F(ConfigurationTest, summaryDDNS) { + EXPECT_EQ("DDNS: disabled", + conf_.getConfigSummary(Configuration::CFGSEL_DDNS)); + + enableDDNS(true); + EXPECT_EQ("DDNS: enabled", + conf_.getConfigSummary(Configuration::CFGSEL_DDNS)); + + enableDDNS(false); + EXPECT_EQ("no IPv4 subnets!; no IPv6 subnets!; DDNS: disabled", + conf_.getConfigSummary(Configuration::CFGSEL_ALL)); +} + // Check that the configuration summary including information about added // subnets is returned. TEST_F(ConfigurationTest, summarySubnets) { @@ -180,49 +206,49 @@ TEST_F(ConfigurationTest, summarySubnets) { // Initially, there are no subnets added but it should be explicitly // reported when we query for information about the subnets. EXPECT_EQ("no IPv4 subnets!; no IPv6 subnets!", - conf_.getConfigSummary(Configuration::CFGSEL_ALL)); + conf_.getConfigSummary(Configuration::CFGSEL_SUBNET)); // If we just want information about IPv4 subnets, there should be no // mention of IPv6 subnets, even though there are none added. EXPECT_EQ("no IPv4 subnets!", - conf_.getConfigSummary(Configuration::CFGSEL_ALL4)); + conf_.getConfigSummary(Configuration::CFGSEL_SUBNET4)); // If we just want information about IPv6 subnets, there should be no // mention of IPv4 subnets, even though there are none added. EXPECT_EQ("no IPv6 subnets!", - conf_.getConfigSummary(Configuration::CFGSEL_ALL6)); + conf_.getConfigSummary(Configuration::CFGSEL_SUBNET6)); // Add IPv4 subnet and make sure it is reported. addSubnet4(0); EXPECT_EQ("added IPv4 subnets: 1", - conf_.getConfigSummary(Configuration::CFGSEL_ALL4)); + conf_.getConfigSummary(Configuration::CFGSEL_SUBNET4)); EXPECT_EQ("added IPv4 subnets: 1; no IPv6 subnets!", - conf_.getConfigSummary(Configuration::CFGSEL_ALL)); + conf_.getConfigSummary(Configuration::CFGSEL_SUBNET)); // Add IPv6 subnet and make sure it is reported. addSubnet6(0); EXPECT_EQ("added IPv6 subnets: 1", - conf_.getConfigSummary(Configuration::CFGSEL_ALL6)); + conf_.getConfigSummary(Configuration::CFGSEL_SUBNET6)); EXPECT_EQ("added IPv4 subnets: 1; added IPv6 subnets: 1", - conf_.getConfigSummary(Configuration::CFGSEL_ALL)); + conf_.getConfigSummary(Configuration::CFGSEL_SUBNET)); // Add one more subnet and make sure the bumped value is only // for IPv4, but not for IPv6. addSubnet4(1); EXPECT_EQ("added IPv4 subnets: 2; added IPv6 subnets: 1", - conf_.getConfigSummary(Configuration::CFGSEL_ALL)); + conf_.getConfigSummary(Configuration::CFGSEL_SUBNET)); EXPECT_EQ("added IPv4 subnets: 2", - conf_.getConfigSummary(Configuration::CFGSEL_ALL4)); + conf_.getConfigSummary(Configuration::CFGSEL_SUBNET4)); addSubnet6(1); EXPECT_EQ("added IPv4 subnets: 2; added IPv6 subnets: 2", - conf_.getConfigSummary(Configuration::CFGSEL_ALL)); + conf_.getConfigSummary(Configuration::CFGSEL_SUBNET)); // Remove all subnets and make sure that there are no reported subnets // back again. clearSubnets(); EXPECT_EQ("no IPv4 subnets!; no IPv6 subnets!", - conf_.getConfigSummary(Configuration::CFGSEL_ALL)); + conf_.getConfigSummary(Configuration::CFGSEL_SUBNET)); } } // end of anonymous namespace