]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#225] Fixed parsers, added UTs
authorThomas Markwalder <tmark@isc.org>
Fri, 24 Mar 2023 14:37:16 +0000 (10:37 -0400)
committerThomas Markwalder <tmark@isc.org>
Fri, 24 Mar 2023 16:50:00 +0000 (12:50 -0400)
modified:   src/bin/dhcp4/dhcp4_lexer.cc
modified:   src/bin/dhcp4/dhcp4_lexer.ll
modified:   src/bin/dhcp4/tests/fqdn_unittest.cc
modified:   src/bin/dhcp6/dhcp6_lexer.cc
modified:   src/bin/dhcp6/dhcp6_lexer.ll

src/bin/dhcp4/dhcp4_lexer.cc
src/bin/dhcp4/dhcp4_lexer.ll
src/bin/dhcp4/tests/fqdn_unittest.cc
src/bin/dhcp6/dhcp6_lexer.cc
src/bin/dhcp6/dhcp6_lexer.ll

index f0551d7c5d40a24ff02a7e75068deb0b3417e8bc..8f729733e89c4f76cd75268a4adb7f492f829cd2 100644 (file)
@@ -3588,7 +3588,7 @@ YY_RULE_SETUP
     case isc::dhcp::Parser4Context::SHARED_NETWORK:
         return isc::dhcp::Dhcp4Parser::make_DDNS_TTL_PERCENT(driver.loc_);
     default:
-        return isc::dhcp::Dhcp4Parser::make_STRING("ddns_ttl-percent", driver.loc_);
+        return isc::dhcp::Dhcp4Parser::make_STRING("ddns-ttl-percent", driver.loc_);
     }
 }
        YY_BREAK
index 92a719e678cffcde18e3af76ee490f99cbbab06d..ebf8f03dd4600c99535879092647b8b25db77485 100644 (file)
@@ -865,7 +865,7 @@ ControlCharacterFill            [^"\\]|\\["\\/bfnrtu]
     case isc::dhcp::Parser4Context::SHARED_NETWORK:
         return isc::dhcp::Dhcp4Parser::make_DDNS_TTL_PERCENT(driver.loc_);
     default:
-        return isc::dhcp::Dhcp4Parser::make_STRING("ddns_ttl-percent", driver.loc_);
+        return isc::dhcp::Dhcp4Parser::make_STRING("ddns-ttl-percent", driver.loc_);
     }
 }
 
index 46b8973d790852e52e9e2f62460f31d55ebe8e09..8256555b9c51b339fd0db422110d2e64a97506ab 100644 (file)
@@ -19,6 +19,7 @@
 #include <dhcpsrv/ncr_generator.h>
 #include <stats/stats_mgr.h>
 #include <testutils/gtest_utils.h>
+#include <util/optional.h>
 
 #include <gtest/gtest.h>
 #include <boost/scoped_ptr.hpp>
@@ -29,6 +30,7 @@ using namespace isc::dhcp;
 using namespace isc::dhcp::test;
 using namespace isc::dhcp_ddns;
 using namespace isc::stats;
+using namespace isc::util;
 
 namespace {
 
@@ -320,6 +322,25 @@ const char* CONFIGS[] = {
             "\"enable-updates\": true,\n"
             "\"qualifying-suffix\": \"example.com.\"\n"
         "}\n"
+    "}",
+    // 12
+    // D2 enabled
+    // ddns-ttl-percent specfied
+    "{ \"interfaces-config\": {\n"
+        "      \"interfaces\": [ \"*\" ]\n"
+        "},\n"
+        "\"valid-lifetime\": 3000,\n"
+        "\"subnet4\": [ { \n"
+        "    \"subnet\": \"10.0.0.0/24\", \n"
+        "    \"interface\": \"eth1\",\n"
+        "    \"id\": 1,\n"
+        "    \"pools\": [ { \"pool\": \"10.0.0.10-10.0.0.10\" } ],\n"
+        "    \"ddns-ttl-percent\": .25\n"
+        "} ],\n"
+        "\"dhcp-ddns\": {\n"
+            "\"enable-updates\": true,\n"
+            "\"qualifying-suffix\": \"example.com.\"\n"
+        "}\n"
     "}"
 };
 
@@ -784,7 +805,8 @@ public:
                                  const time_t cltt,
                                  const uint16_t valid_lft,
                                  const bool not_strict_expire_check = false,
-                                 const bool exp_use_cr = true) {
+                                 const bool exp_use_cr = true,
+                                 Optional<double> ttl_percent = Optional<double>()) {
         NameChangeRequestPtr ncr;
         ASSERT_NO_THROW(ncr = d2_mgr_.peekAt(0));
         ASSERT_TRUE(ncr);
@@ -805,7 +827,7 @@ public:
         // current time as cltt but the it may not check the lease expiration
         // time for equality but rather check that the lease expiration time
         // is not greater than the current time + lease lifetime.
-        uint32_t ttl = calculateDdnsTtl(valid_lft);
+        uint32_t ttl = calculateDdnsTtl(valid_lft, ttl_percent);
         if (not_strict_expire_check) {
             EXPECT_GE(cltt + ttl, ncr->getLeaseExpiresOn());
         } else {
@@ -2825,5 +2847,43 @@ TEST_F(NameDhcpv4SrvTest, withOfferLifetime) {
     checkSubnetStat(subnet->getID(), "assigned-addresses", 1);
 }
 
+// Verifies the DNS TTL when ttl percent is specified
+// than zero.
+TEST_F(NameDhcpv4SrvTest, withDdnsTtlPercent) {
+    // Load a configuration with D2 enabled and ddns-ttl-percent
+    ASSERT_NO_FATAL_FAILURE(configure(CONFIGS[12], *srv_));
+    ASSERT_TRUE(CfgMgr::instance().ddnsEnabled());
+
+    // Create a client and get a lease.
+    Dhcp4Client client1(srv_, Dhcp4Client::SELECTING);
+    client1.setIfaceName("eth1");
+    client1.setIfaceIndex(ETH1_INDEX);
+    ASSERT_NO_THROW(client1.includeHostname("client1"));
+
+    // Do the DORA.
+    ASSERT_NO_THROW(client1.doDORA());
+    Pkt4Ptr resp = client1.getContext().response_;
+    ASSERT_TRUE(resp);
+    ASSERT_EQ(DHCPACK, static_cast<int>(resp->getType()));
+
+    // Obtain the Hostname option sent in the response and make sure that the server
+    // has used the hostname reserved for this client.
+    OptionStringPtr hostname;
+    hostname = boost::dynamic_pointer_cast<OptionString>(resp->getOption(DHO_HOST_NAME));
+    ASSERT_TRUE(hostname);
+    EXPECT_EQ("client1.example.com", hostname->getValue());
+
+    // Make sure the lease is in the database and hostname is correct.
+    Lease4Ptr lease = LeaseMgrFactory::instance().getLease4(IOAddress("10.0.0.10"));
+    ASSERT_TRUE(lease);
+    EXPECT_EQ("client1.example.com", lease->hostname_);
+
+    // Verify that an NCR was generated correctly.
+    ASSERT_EQ(1, CfgMgr::instance().getD2ClientMgr().getQueueSize());
+    verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
+                            resp->getYiaddr().toText(),
+                            "client1.example.com.", "",
+                            time(NULL), lease->valid_lft_, true, true, Optional<double>(.25));
+}
 
 } // end of anonymous namespace
index 231edd2e7eb260e4afa3f497a7dfde2c1b08bab3..3fb38c9bbaca0927aae1169a3af62ea4d96ac659 100644 (file)
@@ -3884,7 +3884,7 @@ YY_RULE_SETUP
     case isc::dhcp::Parser6Context::SHARED_NETWORK:
         return isc::dhcp::Dhcp6Parser::make_DDNS_TTL_PERCENT(driver.loc_);
     default:
-        return isc::dhcp::Dhcp6Parser::make_STRING("ddns_ttl-percent", driver.loc_);
+        return isc::dhcp::Dhcp6Parser::make_STRING("ddns-ttl-percent", driver.loc_);
     }
 }
        YY_BREAK
index d9821fa7b1b2743c9845c8ce8ff7e5f711378984..395cac2d46a4b8c5a5ed8322d2fc3b8c04b066e9 100644 (file)
@@ -1110,7 +1110,7 @@ ControlCharacterFill            [^"\\]|\\["\\/bfnrtu]
     case isc::dhcp::Parser6Context::SHARED_NETWORK:
         return isc::dhcp::Dhcp6Parser::make_DDNS_TTL_PERCENT(driver.loc_);
     default:
-        return isc::dhcp::Dhcp6Parser::make_STRING("ddns_ttl-percent", driver.loc_);
+        return isc::dhcp::Dhcp6Parser::make_STRING("ddns-ttl-percent", driver.loc_);
     }
 }