From: Thomas Markwalder Date: Fri, 28 Sep 2018 19:36:21 +0000 (-0400) Subject: [#32,!23] SrvConfig::toElement now outputs config-control X-Git-Tag: 153-netconf-control-socket_base~4^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a8e05f99de88138f7667492662af121ea620096e;p=thirdparty%2Fkea.git [#32,!23] SrvConfig::toElement now outputs config-control src/lib/dhcpsrv/srv_config.cc SrvConfig::toElement() - added logic to output config-control src/lib/dhcpsrv/tests/srv_config_unittest.cc TEST_F(SrvConfigTest, unparseConfigControlInfo) - new test --- diff --git a/src/lib/dhcpsrv/srv_config.cc b/src/lib/dhcpsrv/srv_config.cc index 4e4571761e..5e8990711b 100644 --- a/src/lib/dhcpsrv/srv_config.cc +++ b/src/lib/dhcpsrv/srv_config.cc @@ -131,11 +131,12 @@ SrvConfig::copy(SrvConfig& new_config) const { bool SrvConfig::equals(const SrvConfig& other) const { + // Checks common elements: logging & config control if (!ConfigBase::equals(other)) { return (false); } - // Logging information is equal between objects, so check other values. + // Common information is equal between objects, so check other values. if ((*cfg_iface_ != *other.cfg_iface_) || (*cfg_option_def_ != *other.cfg_option_def_) || (*cfg_option_ != *other.cfg_option_) || @@ -382,6 +383,13 @@ SrvConfig::toElement() const { ConstElementPtr cfg_consist = cfg_consist_->toElement(); dhcp->set("sanity-checks", cfg_consist); + // Set config-control (if it exists) + ConstConfigControlInfoPtr info = getConfigControlInfo(); + if (info) { + ConstElementPtr info_elem = info->toElement(); + dhcp->set("config-control", info_elem); + } + return (result); } diff --git a/src/lib/dhcpsrv/srv_config.h b/src/lib/dhcpsrv/srv_config.h index e4fbe2f8ae..f0024e8bfe 100644 --- a/src/lib/dhcpsrv/srv_config.h +++ b/src/lib/dhcpsrv/srv_config.h @@ -62,6 +62,8 @@ public: static const uint32_t CFGSEL_SUBNET = 0x00000003; /// Configured globals static const uint32_t CFGSEL_GLOBALS = 0x00000020; + /// Config control info + static const uint32_t CFGSEL_CFG_CTL = 0x00000040; /// IPv4 related config static const uint32_t CFGSEL_ALL4 = 0x00000035; /// IPv6 related config diff --git a/src/lib/dhcpsrv/tests/srv_config_unittest.cc b/src/lib/dhcpsrv/tests/srv_config_unittest.cc index 0b555bc27b..7df32a422b 100644 --- a/src/lib/dhcpsrv/tests/srv_config_unittest.cc +++ b/src/lib/dhcpsrv/tests/srv_config_unittest.cc @@ -590,7 +590,7 @@ TEST_F(SrvConfigTest, unparseHR) { // Add a v4 global host reservation to the plain subnet HostPtr ghost4(new Host("AA:01:02:03:04:05", "hw-address", - SUBNET_ID_GLOBAL, SUBNET_ID_UNUSED, + SUBNET_ID_GLOBAL, SUBNET_ID_UNUSED, IOAddress("192.0.3.1"))); conf4.getCfgHosts()->add(ghost4); @@ -751,7 +751,7 @@ TEST_F(SrvConfigTest, unparseHR) { conf6.getCfgHosts()->add(phost6); // Add a host reservation to the shared subnet - HostPtr shost6(new Host("f6:e5:d4:c3:b2:a1", "duid", SUBNET_ID_UNUSED, + HostPtr shost6(new Host("f6:e5:d4:c3:b2:a1", "duid", SUBNET_ID_UNUSED, s_id, IOAddress::IPV4_ZERO_ADDRESS(), "bar.example.org")); conf6.getCfgHosts()->add(shost6); @@ -870,4 +870,49 @@ TEST_F(SrvConfigTest, unparseHR) { EXPECT_EQ("bar.example.org", check->stringValue()); } +// Verifies that the toElement method does not miss config control info +TEST_F(SrvConfigTest, unparseConfigControlInfo) { + // DHCPv4 version + CfgMgr::instance().setFamily(AF_INET); + SrvConfig conf4(32); + + // Unparse the config + ConstElementPtr unparsed4 = conf4.toElement(); + ASSERT_TRUE(unparsed4); + ASSERT_EQ(Element::map, unparsed4->getType()); + + // Get Dhcp4 entry + ConstElementPtr dhcp4; + ASSERT_NO_THROW(dhcp4 = unparsed4->get("Dhcp4")); + ASSERT_TRUE(dhcp4); + ASSERT_EQ(Element::map, dhcp4->getType()); + + // Config control should not be present. + ConstElementPtr check; + ASSERT_NO_THROW(check = dhcp4->get("config-control")); + EXPECT_FALSE(check); + + // Now let's create the info and add it to the configuration + ConfigControlInfoPtr info(new ConfigControlInfo()); + ASSERT_NO_THROW(info->addConfigDatabase("type=mysql")); + ASSERT_NO_THROW(conf4.setConfigControlInfo(info)); + + // Unparse the config again + unparsed4 = conf4.toElement(); + ASSERT_NO_THROW(dhcp4 = unparsed4->get("Dhcp4")); + ASSERT_TRUE(dhcp4); + ASSERT_EQ(Element::map, dhcp4->getType()); + + // Config control should be present. + ASSERT_NO_THROW(check = dhcp4->get("config-control")); + ASSERT_TRUE(check); + ASSERT_EQ(Element::map, check->getType()); + + // Unparse the info object and compare its elements to + // that in unparsed config. They should be equal. + ElementPtr info_elem = info->toElement(); + EXPECT_TRUE(info_elem->equals(*check)); +} + + } // end of anonymous namespace