]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#505] addressed review
authorRazvan Becheriu <razvan@isc.org>
Thu, 20 Aug 2020 18:42:20 +0000 (21:42 +0300)
committerRazvan Becheriu <razvan@isc.org>
Fri, 21 Aug 2020 10:04:30 +0000 (10:04 +0000)
src/lib/dhcpsrv/parsers/base_network_parser.cc
src/lib/dhcpsrv/parsers/dhcp_parsers.cc
src/lib/dhcpsrv/tests/shared_network_parser_unittest.cc

index 89ebfe9df885898fae191dddc35f73a6e8064b2a..4bcd1788901956b68f92df3662b958ae07f9ee55 100644 (file)
@@ -125,7 +125,7 @@ BaseNetworkParser::parseCommon(const ConstElementPtr& network_data,
 
     if (has_renew && has_rebind && (renew > rebind)) {
         isc_throw(DhcpConfigError, "the value of renew-timer" << " (" << renew
-                  << ") is not less than rebind-timer" << " (" << rebind << ")");
+                  << ") is greater than rebind-timer" << " (" << rebind << ")");
     }
 
     network->setValid(parseLifetime(network_data, "valid-lifetime"));
index 11265f5999c3207f27dafffbd9e7c63cea89715d..9f339d69b448f7761837baed1ed078a9d5c62c04 100644 (file)
@@ -760,14 +760,14 @@ Subnet4ConfigParser::initSubnet(data::ConstElementPtr params,
         renew = subnet4->getT1().get();
         output << "t1=" << renew << ", ";
     }
-    if (rebind) {
+    if (has_rebind) {
         rebind = subnet4->getT2().get();
         output << "t2=" << rebind << ", ";
     }
 
     if (has_renew && has_rebind && (renew > rebind)) {
         isc_throw(DhcpConfigError, "the value of renew-timer" << " (" << renew
-                  << ") is not less than rebind-timer" << " (" << rebind << ")");
+                  << ") is greater than rebind-timer" << " (" << rebind << ")");
     }
 
     if (!subnet4->getValid().unspecified()) {
@@ -1262,7 +1262,7 @@ Subnet6ConfigParser::initSubnet(data::ConstElementPtr params,
 
     if (has_renew && has_rebind && (renew > rebind)) {
         isc_throw(DhcpConfigError, "the value of renew-timer" << " (" << renew
-                  << ") is not less than rebind-timer" << " (" << rebind << ")");
+                  << ") is greater than rebind-timer" << " (" << rebind << ")");
     }
 
     if (!subnet6->getPreferred().unspecified()) {
index 6b3db1c9c3ccae589433ad3e81b0bb9c3d0b09e1..b63017c6ba6f7f112e672e261eb345f56a706fcb 100644 (file)
@@ -474,14 +474,14 @@ TEST_F(SharedNetwork4ParserTest, iface) {
 TEST_F(SharedNetwork4ParserTest, parseWithInvalidRenewRebind) {
     IfaceMgrTestConfig ifmgr(true);
 
-    // Basic configuration for shared network. A bunch of parameters
-    // have to be specified for subnets because subnet parsers expect
-    // that default and global values are set.
+    // Basic configuration for shared network.
     std::string config = getWorkingConfig();
     ElementPtr config_element = Element::fromJSON(config);
-    ConstElementPtr valid_element = config_element->get("renew-timer");
-    ElementPtr invalid_element = boost::const_pointer_cast<Element>(valid_element);
-    invalid_element->setValue(200);
+    ConstElementPtr valid_element = config_element->get("rebind-timer");
+    int64_t value = valid_element->intValue();
+    valid_element = config_element->get("renew-timer");
+    ElementPtr mutable_element = boost::const_pointer_cast<Element>(valid_element);
+    mutable_element->setValue(value + 1);
 
     // Parse configuration specified above.
     SharedNetwork4Parser parser;
@@ -491,6 +491,28 @@ TEST_F(SharedNetwork4ParserTest, parseWithInvalidRenewRebind) {
     ASSERT_FALSE(network);
 }
 
+// This test verifies that shared network parser for IPv4 works properly
+// when renew and rebind timers are equal.
+TEST_F(SharedNetwork4ParserTest, parseValidWithEqualRenewRebind) {
+    IfaceMgrTestConfig ifmgr(true);
+
+    // Basic configuration for shared network.
+    std::string config = getWorkingConfig();
+    ElementPtr config_element = Element::fromJSON(config);
+    ConstElementPtr valid_element = config_element->get("rebind-timer");
+    int64_t value = valid_element->intValue();
+    valid_element = config_element->get("renew-timer");
+    ElementPtr mutable_element = boost::const_pointer_cast<Element>(valid_element);
+    mutable_element->setValue(value);
+
+    // Parse configuration specified above.
+    SharedNetwork4Parser parser;
+    SharedNetwork4Ptr network;
+
+    ASSERT_NO_THROW(network = parser.parse(config_element));
+    ASSERT_TRUE(network);
+}
+
 /// @brief Test fixture class for SharedNetwork6Parser class.
 class SharedNetwork6ParserTest : public SharedNetworkParserTest {
 public: