summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Markwalder <tmark@isc.org>2023-03-24 15:37:16 +0100
committerThomas Markwalder <tmark@isc.org>2023-03-24 17:50:00 +0100
commit962ce5f31f72bac273da46a180b7bd16fa6a9f15 (patch)
tree0ba3a0d0ae872fe373640ed3010979f1ce8f1a9f
parent[#225] Adding a UT (diff)
downloadkea-962ce5f31f72bac273da46a180b7bd16fa6a9f15.tar.xz
kea-962ce5f31f72bac273da46a180b7bd16fa6a9f15.zip
[#225] Fixed parsers, added UTs
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
-rw-r--r--src/bin/dhcp4/dhcp4_lexer.cc2
-rw-r--r--src/bin/dhcp4/dhcp4_lexer.ll2
-rw-r--r--src/bin/dhcp4/tests/fqdn_unittest.cc64
-rw-r--r--src/bin/dhcp6/dhcp6_lexer.cc2
-rw-r--r--src/bin/dhcp6/dhcp6_lexer.ll2
5 files changed, 66 insertions, 6 deletions
diff --git a/src/bin/dhcp4/dhcp4_lexer.cc b/src/bin/dhcp4/dhcp4_lexer.cc
index f0551d7c5d..8f729733e8 100644
--- a/src/bin/dhcp4/dhcp4_lexer.cc
+++ b/src/bin/dhcp4/dhcp4_lexer.cc
@@ -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
diff --git a/src/bin/dhcp4/dhcp4_lexer.ll b/src/bin/dhcp4/dhcp4_lexer.ll
index 92a719e678..ebf8f03dd4 100644
--- a/src/bin/dhcp4/dhcp4_lexer.ll
+++ b/src/bin/dhcp4/dhcp4_lexer.ll
@@ -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_);
}
}
diff --git a/src/bin/dhcp4/tests/fqdn_unittest.cc b/src/bin/dhcp4/tests/fqdn_unittest.cc
index 46b8973d79..8256555b9c 100644
--- a/src/bin/dhcp4/tests/fqdn_unittest.cc
+++ b/src/bin/dhcp4/tests/fqdn_unittest.cc
@@ -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
diff --git a/src/bin/dhcp6/dhcp6_lexer.cc b/src/bin/dhcp6/dhcp6_lexer.cc
index 231edd2e7e..3fb38c9bba 100644
--- a/src/bin/dhcp6/dhcp6_lexer.cc
+++ b/src/bin/dhcp6/dhcp6_lexer.cc
@@ -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
diff --git a/src/bin/dhcp6/dhcp6_lexer.ll b/src/bin/dhcp6/dhcp6_lexer.ll
index d9821fa7b1..395cac2d46 100644
--- a/src/bin/dhcp6/dhcp6_lexer.ll
+++ b/src/bin/dhcp6/dhcp6_lexer.ll
@@ -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_);
}
}