Skip to content

Commit 05159da

Browse files
committed
[#3949] Do not add suffix to qualifed host names
/src/bin/dhcp4/tests/host_unittest.cc /src/bin/dhcp6/tests/host_unittest.cc Updated tests /src/lib/dhcpsrv/d2_client_mgr.cc D2ClientMgr::qualifyName() - don't add suffix to names that end with a dot. /src/lib/dhcpsrv/d2_client_mgr.h D2ClientMgr::adjustDomainName() - strip trailing dots from T::PARTIAL FQDNs before calling qualifyName() /src/lib/dhcpsrv/tests/d2_client_unittest.cc TEST_F(D2ClientMgrParamsTest, qualifyName) - updated
1 parent cc5a3e3 commit 05159da

File tree

6 files changed

+40
-27
lines changed

6 files changed

+40
-27
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[bug] tmark
2+
Avoid adding the qualifying-suffix to fully qualified
3+
host names specified in host reservations.
4+
(Gitlab #3949)

src/bin/dhcp4/tests/host_unittest.cc

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@ const char* CONFIGS[] = {
4141
"{ \"interfaces-config\": {\n"
4242
" \"interfaces\": [ \"*\" ]\n"
4343
"},\n"
44+
"\"ddns-qualifying-suffix\": \"example.org.\",\n"
4445
"\"host-reservation-identifiers\": [ \"circuit-id\", \"hw-address\",\n"
4546
" \"duid\", \"client-id\" ],\n"
4647
"\"reservations\": [ \n"
4748
"{\n"
4849
" \"hw-address\": \"aa:bb:cc:dd:ee:ff\",\n"
49-
" \"hostname\": \"hw-host-dynamic\"\n"
50+
" \"hostname\": \"hw-host-dynamic.already.com.\"\n"
5051
"},\n"
5152
"{\n"
5253
" \"hw-address\": \"01:02:03:04:05:06\",\n"
@@ -55,12 +56,12 @@ const char* CONFIGS[] = {
5556
"},\n"
5657
"{\n"
5758
" \"hw-address\": \"02:02:03:04:05:06\",\n"
58-
" \"hostname\": \"hw-host-fixed-in-range\",\n"
59+
" \"hostname\": \"hw-host-fixed-in-range.example.org.\",\n"
5960
" \"ip-address\": \"10.0.0.77\"\n"
6061
"},\n"
6162
"{\n"
6263
" \"duid\": \"01:02:03:04:05\",\n"
63-
" \"hostname\": \"duid-host\"\n"
64+
" \"hostname\": \"duid-host.\"\n"
6465
"},\n"
6566
"{\n"
6667
" \"circuit-id\": \"'charter950'\",\n"
@@ -590,7 +591,7 @@ TEST_F(HostTest, globalHardwareDynamicAddress) {
590591
Dhcp4Client client(srv_, Dhcp4Client::SELECTING);
591592

592593
client.setHWAddress("aa:bb:cc:dd:ee:ff");
593-
runDoraTest(CONFIGS[0], client, "hw-host-dynamic", "10.0.0.10");
594+
runDoraTest(CONFIGS[0], client, "hw-host-dynamic.already.com", "10.0.0.10");
594595
}
595596

596597
// Verifies that a client matched to a global in-subnet address reservation
@@ -600,7 +601,7 @@ TEST_F(HostTest, globalHardwareFixedAddressInRange) {
600601
Dhcp4Client client(srv_, Dhcp4Client::SELECTING);
601602

602603
client.setHWAddress("02:02:03:04:05:06");
603-
runDoraTest(CONFIGS[0], client, "hw-host-fixed-in-range", "10.0.0.77");
604+
runDoraTest(CONFIGS[0], client, "hw-host-fixed-in-range.example.org", "10.0.0.77");
604605
}
605606

606607
// Verifies that a client matched to a global out-of-range address reservation
@@ -610,7 +611,7 @@ TEST_F(HostTest, globalHardwareFixedAddressOutOfRange) {
610611
Dhcp4Client client(srv_, Dhcp4Client::SELECTING);
611612

612613
client.setHWAddress("01:02:03:04:05:06");
613-
runDoraTest(CONFIGS[0], client, "hw-host-fixed-out-of-range", "10.0.0.10");
614+
runDoraTest(CONFIGS[0], client, "hw-host-fixed-out-of-range.example.org", "10.0.0.10");
614615
}
615616

616617
// Verifies that a client can be matched to a global reservation by DUID
@@ -641,7 +642,7 @@ TEST_F(HostTest, globalCircuitId) {
641642
// Set the circuit id
642643
client.setCircuitId("charter950");
643644

644-
runDoraTest(CONFIGS[0], client, "circuit-id-host", "10.0.0.10");
645+
runDoraTest(CONFIGS[0], client, "circuit-id-host.example.org", "10.0.0.10");
645646
}
646647

647648
// Verifies that a client can be matched to a global reservation by client-id
@@ -655,7 +656,7 @@ TEST_F(HostTest, globalClientID) {
655656
// - 11:22:33:44:55:66 - is an actual DUID for which there is a
656657
client.includeClientId("01:11:22:33:44:55:66");
657658

658-
runDoraTest(CONFIGS[0], client, "client-id-host", "10.0.0.10");
659+
runDoraTest(CONFIGS[0], client, "client-id-host.example.org", "10.0.0.10");
659660
}
660661

661662
// Verifies that even when a matching global reservation exists,

src/bin/dhcp6/tests/host_unittest.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ const char* CONFIGS[] = {
6868
"\"preferred-lifetime\": 3000,"
6969
"\"rebind-timer\": 2000, "
7070
"\"renew-timer\": 1000, "
71+
"\"ddns-qualifying-suffix\":\"example.org.\", "
7172
"\"subnet6\": [ "
7273
" { "
7374
" \"id\": 1, "
@@ -82,7 +83,8 @@ const char* CONFIGS[] = {
8283
" },"
8384
" {"
8485
" \"duid\": \"01:02:03:05\","
85-
" \"ip-addresses\": [ \"2001:db8:1:1::babf\" ]"
86+
" \"ip-addresses\": [ \"2001:db8:1:1::babf\" ],"
87+
" \"hostname\": \"hare.mad-hatter.com.\""
8688
" } ]"
8789
" } ]"
8890
"}",
@@ -1551,7 +1553,7 @@ TEST_F(HostTest, basicSarrs) {
15511553
// and lease has reserved hostname
15521554
Lease6Ptr lease_server = checkLease(lease_client);
15531555
ASSERT_TRUE(lease_server);
1554-
EXPECT_EQ("alice", lease_server->hostname_);
1556+
EXPECT_EQ("alice.example.org", lease_server->hostname_);
15551557

15561558
// Now redo the client, adding one to the DUID
15571559
client.clearConfig();
@@ -1569,7 +1571,7 @@ TEST_F(HostTest, basicSarrs) {
15691571
// and that the server lease has NO hostname
15701572
lease_server = checkLease(lease_client);
15711573
ASSERT_TRUE(lease_server);
1572-
EXPECT_EQ("", lease_server->hostname_);
1574+
EXPECT_EQ("hare.mad-hatter.com", lease_server->hostname_);
15731575

15741576
// Now redo the client with yet another DUID and verify that
15751577
// we get a dynamic address.

src/lib/dhcpsrv/d2_client_mgr.cc

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,22 +187,17 @@ D2ClientMgr::qualifyName(const std::string& partial_name,
187187
const DdnsParams& ddns_params,
188188
const bool trailing_dot) const {
189189
std::ostringstream gen_name;
190-
191190
gen_name << partial_name;
192191
std::string suffix = ddns_params.getQualifyingSuffix();
193-
bool suffix_present = true;
194-
if (!suffix.empty()) {
192+
if (!suffix.empty() && partial_name.back() != '.') {
193+
bool suffix_present = true;
195194
std::string str = gen_name.str();
196195
auto suffix_rit = suffix.rbegin();
197196
if (*suffix_rit == '.') {
198197
++suffix_rit;
199198
}
200199

201200
auto gen_rit = str.rbegin();
202-
if (*gen_rit == '.') {
203-
++gen_rit;
204-
}
205-
206201
while (suffix_rit != suffix.rend()) {
207202
if ((gen_rit == str.rend()) || (*suffix_rit != *gen_rit)) {
208203
// They don't match.

src/lib/dhcpsrv/d2_client_mgr.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,6 @@ D2ClientMgr::adjustDomainName(const T& fqdn, T& fqdn_resp, const DdnsParams& ddn
491491
} else {
492492
// Sanitize the name the client sent us, if we're configured to do so.
493493
std::string client_name = fqdn.getDomainName();
494-
495494
isc::util::str::StringSanitizerPtr sanitizer = ddns_params.getHostnameSanitizer();
496495
if (sanitizer) {
497496
// We need the raw text form, so we can replace escaped chars
@@ -521,6 +520,12 @@ D2ClientMgr::adjustDomainName(const T& fqdn, T& fqdn_resp, const DdnsParams& ddn
521520

522521
// If the supplied name is partial, qualify it by adding the suffix.
523522
if (fqdn.getDomainNameType() == T::PARTIAL) {
523+
if (client_name.back() == '.') {
524+
// By definition a partial cannot end in a dot, sanitizing above
525+
// may have added one. Strip it, so we'll add the suffix (if one).
526+
client_name.pop_back();
527+
}
528+
524529
fqdn_resp.setDomainName(qualifyName(client_name, ddns_params, true), T::FULL);
525530
} else {
526531
fqdn_resp.setDomainName(client_name, T::FULL);

src/lib/dhcpsrv/tests/d2_client_unittest.cc

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -639,13 +639,8 @@ TEST_F(D2ClientMgrParamsTest, qualifyName) {
639639
qualified_name = mgr.qualifyName(partial_name, *ddns_params_, do_dot);
640640
EXPECT_EQ("somehost.hasdot.com.", qualified_name);
641641

642-
// Verify that the qualifying suffix gets appended without an
643-
// extraneous dot when partial_name ends with a "."
644-
qualified_name = mgr.qualifyName("somehost.", *ddns_params_, do_dot);
645-
EXPECT_EQ("somehost.hasdot.com.", qualified_name);
646-
647-
// Verify that a name with a trailing dot does not get an extraneous
648-
// dot when the suffix is blank
642+
// Verify that the qualifying suffix does not get appended nor an
643+
// extraneous dot added to a name with a trailing dot.
649644
subnet_->setDdnsQualifyingSuffix("");
650645
qualified_name = mgr.qualifyName("somehost.", *ddns_params_, do_dot);
651646
EXPECT_EQ("somehost.", qualified_name);
@@ -664,7 +659,6 @@ TEST_F(D2ClientMgrParamsTest, qualifyName) {
664659
// suffix is blank and trailing dot is false
665660
qualified_name = mgr.qualifyName("somehost.", *ddns_params_, do_not_dot);
666661
EXPECT_EQ("somehost", qualified_name);
667-
668662
}
669663

670664
/// @brief Tests the qualifyName method's ability to avoid duplicating
@@ -802,6 +796,12 @@ TEST_F(D2ClientMgrParamsTest, adjustDomainNameV4) {
802796
"myhost.example.com.", Option4ClientFqdn::FULL,
803797
"myhost.example.com.", Option4ClientFqdn::FULL
804798
},
799+
{
800+
"RCM_NEVER #4, partial client name with traling .",
801+
D2ClientConfig::RCM_NEVER,
802+
"myhost.", Option4ClientFqdn::PARTIAL,
803+
"myhost.suffix.com.", Option4ClientFqdn::FULL
804+
},
805805
{
806806
"RCM_ALWAYS #1, empty client name",
807807
D2ClientConfig::RCM_ALWAYS,
@@ -917,6 +917,12 @@ TEST_F(D2ClientMgrParamsTest, adjustDomainNameV6) {
917917
"myhost.example.com.", Option6ClientFqdn::FULL,
918918
"myhost.example.com.", Option6ClientFqdn::FULL
919919
},
920+
{
921+
"RCM_NEVER #4, partial client name with trailing .",
922+
D2ClientConfig::RCM_NEVER,
923+
"myhost.", Option6ClientFqdn::PARTIAL,
924+
"myhost.suffix.com.", Option6ClientFqdn::FULL
925+
},
920926
{
921927
"RCM_ALWAYS #1, empty client name",
922928
D2ClientConfig::RCM_ALWAYS,

0 commit comments

Comments
 (0)