From: Marcin Siodelski Date: Wed, 11 Mar 2015 14:18:20 +0000 (+0100) Subject: [3688] DHCPv4 server appends qualifying suffix to the reserved hostname. X-Git-Tag: trac3764_base~12^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f61aa09ce3da5bd2ecfd413468e6c8730247b685;p=thirdparty%2Fkea.git [3688] DHCPv4 server appends qualifying suffix to the reserved hostname. --- diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc index c731bc4d2f..03fb632e6b 100644 --- a/src/bin/dhcp4/dhcp4_srv.cc +++ b/src/bin/dhcp4/dhcp4_srv.cc @@ -861,8 +861,9 @@ Dhcpv4Srv::processClientFqdnOption(DHCPv4Exchange& ex) { fqdn->getFlag(Option4ClientFqdn::FLAG_E)); if (ex.getContext()->host_ && !ex.getContext()->host_->getHostname().empty()) { - fqdn_resp->setDomainName(ex.getContext()->host_->getHostname(), - Option4ClientFqdn::FULL); + D2ClientMgr& d2_mgr = CfgMgr::instance().getD2ClientMgr(); + fqdn_resp->setDomainName(d2_mgr.qualifyName(ex.getContext()->host_->getHostname(), + true), Option4ClientFqdn::FULL); } else { // Adjust the domain name based on domain name value and type sent by the @@ -924,7 +925,8 @@ Dhcpv4Srv::processHostnameOption(DHCPv4Exchange& ex) { // If there is a hostname reservation for this client, use it. if (ex.getContext()->host_ && !ex.getContext()->host_->getHostname().empty()) { - opt_hostname_resp->setValue(ex.getContext()->host_->getHostname()); + opt_hostname_resp->setValue(d2_mgr.qualifyName(ex.getContext()->host_->getHostname(), + false)); } else if ((d2_mgr.getD2ClientConfig()->getReplaceClientName()) || (label_count < 2)) { diff --git a/src/bin/dhcp4/tests/fqdn_unittest.cc b/src/bin/dhcp4/tests/fqdn_unittest.cc index 280ed3280a..4de0bea3c0 100644 --- a/src/bin/dhcp4/tests/fqdn_unittest.cc +++ b/src/bin/dhcp4/tests/fqdn_unittest.cc @@ -61,7 +61,7 @@ const char* CONFIGS[] = { " }]," "\"dhcp-ddns\": {" "\"enable-updates\": true," - "\"qualifying-suffix\": \"fake-suffix.isc.org.\"" + "\"qualifying-suffix\": \"\"" "}" "}", "{ \"interfaces-config\": {" @@ -82,7 +82,7 @@ const char* CONFIGS[] = { " \"reservations\": [" " {" " \"hw-address\": \"aa:bb:cc:dd:ee:ff\"," - " \"hostname\": \"foobar.org\"" + " \"hostname\": \"foobar\"" " }" " ]" " }]," @@ -1146,15 +1146,20 @@ TEST_F(NameDhcpv4SrvTest, fqdnReservation) { ASSERT_TRUE(fqdn); EXPECT_EQ("unique-host.example.org.", fqdn->getDomainName()); - // Because this is a new lease, there should be one NCR which adds the - // new DNS entry. - ASSERT_EQ(1, CfgMgr::instance().getD2ClientMgr().getQueueSize()); - verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true, - resp->getYiaddr().toText(), - "unique-host.example.org.", - "000001ACB52196C8F3BCC1DF3BA1F40BAC39BF23" - "0D280858B1ED7696E174C4479E3372", - time(NULL), subnet_->getValid(), true); + { + SCOPED_TRACE("Verify the correctness of the NCR for the" + "unique-host.example.org"); + + // Because this is a new lease, there should be one NCR which adds the + // new DNS entry. + ASSERT_EQ(1, CfgMgr::instance().getD2ClientMgr().getQueueSize()); + verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true, + resp->getYiaddr().toText(), + "unique-host.example.org.", + "000001ACB52196C8F3BCC1DF3BA1F40BAC39BF23" + "0D280858B1ED7696E174C4479E3372", + time(NULL), subnet_->getValid(), true); + } // And that this FQDN has been stored in the lease database. Lease4Ptr lease = LeaseMgrFactory::instance().getLease4(client.config_.lease_.addr_); @@ -1163,6 +1168,9 @@ TEST_F(NameDhcpv4SrvTest, fqdnReservation) { // Reconfigure DHCP server to use a different hostname for the client. configure(CONFIGS[1], *client.getServer()); + // Make sure that DDNS is enabled. + ASSERT_TRUE(CfgMgr::instance().ddnsEnabled()); + ASSERT_NO_THROW(client.getServer()->startD2()); // Client is in the renewing state. client.setState(Dhcp4Client::RENEWING); @@ -1174,29 +1182,40 @@ TEST_F(NameDhcpv4SrvTest, fqdnReservation) { // The new FQDN should contain a different name this time. fqdn = boost::dynamic_pointer_cast(resp->getOption(DHO_FQDN)); ASSERT_TRUE(fqdn); - EXPECT_EQ("foobar.org.", fqdn->getDomainName()); + EXPECT_EQ("foobar.fake-suffix.isc.org.", fqdn->getDomainName()); // And the lease in the lease database should also contain this new FQDN. lease = LeaseMgrFactory::instance().getLease4(client.config_.lease_.addr_); ASSERT_TRUE(lease); - EXPECT_EQ("foobar.org.", lease->hostname_); + EXPECT_EQ("foobar.fake-suffix.isc.org.", lease->hostname_); // Now there should be two name NCRs. One that removes the previous entry // and the one that adds a new entry for the new hostname. ASSERT_EQ(2, CfgMgr::instance().getD2ClientMgr().getQueueSize()); - verifyNameChangeRequest(isc::dhcp_ddns::CHG_REMOVE, true, true, - resp->getYiaddr().toText(), - "unique-host.example.org.", - "000001ACB52196C8F3BCC1DF3BA1F40BAC39BF23" - "0D280858B1ED7696E174C4479E3372", - time(NULL), subnet_->getValid(), true); - verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true, - resp->getYiaddr().toText(), - "foobar.org.", - "000001B722C2FB5FAFE25B99178A0BFEC05127B9" - "5DC843E00941D444D53B24C2365337", - time(NULL), subnet_->getValid(), true); + { + SCOPED_TRACE("Verify the correctness of the CHG_REMOVE NCR for the " + "unique-host.example.org"); + + verifyNameChangeRequest(isc::dhcp_ddns::CHG_REMOVE, true, true, + resp->getYiaddr().toText(), + "unique-host.example.org.", + "000001ACB52196C8F3BCC1DF3BA1F40BAC39BF23" + "0D280858B1ED7696E174C4479E3372", + time(NULL), subnet_->getValid(), true); + } + + { + SCOPED_TRACE("Verify the correctness of the CHG_ADD NCR for the " + "foobar.fake-suffix.isc.org"); + + verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true, + resp->getYiaddr().toText(), + "foobar.fake-suffix.isc.org.", + "0000017C29B3C236344924E448E247F3FD56C7E9" + "167B3397B1305FB664C160B967CE1F", + time(NULL), subnet_->getValid(), true); + } } // This test verifies that the server sends the Hostname option to the client @@ -1247,15 +1266,23 @@ TEST_F(NameDhcpv4SrvTest, hostnameReservation) { // Because this is a new lease, there should be one NCR which adds the // new DNS entry. ASSERT_EQ(1, CfgMgr::instance().getD2ClientMgr().getQueueSize()); - verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true, - resp->getYiaddr().toText(), - "unique-host.example.org.", - "000001ACB52196C8F3BCC1DF3BA1F40BAC39BF23" - "0D280858B1ED7696E174C4479E3372", - time(NULL), subnet_->getValid(), true); + { + SCOPED_TRACE("Verify the correctness of the NCR for the" + "unique-host.example.org"); + + verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true, + resp->getYiaddr().toText(), + "unique-host.example.org.", + "000001ACB52196C8F3BCC1DF3BA1F40BAC39BF23" + "0D280858B1ED7696E174C4479E3372", + time(NULL), subnet_->getValid(), true); + } // Reconfigure DHCP server to use a different hostname for the client. configure(CONFIGS[1], *client.getServer()); + // Make sure that DDNS is enabled. + ASSERT_TRUE(CfgMgr::instance().ddnsEnabled()); + ASSERT_NO_THROW(client.getServer()->startD2()); // Client is in the renewing state. client.setState(Dhcp4Client::RENEWING); @@ -1267,29 +1294,39 @@ TEST_F(NameDhcpv4SrvTest, hostnameReservation) { // The new hostname should be different than previously. hostname = boost::dynamic_pointer_cast(resp->getOption(DHO_HOST_NAME)); ASSERT_TRUE(hostname); - EXPECT_EQ("foobar.org", hostname->getValue()); + EXPECT_EQ("foobar.fake-suffix.isc.org", hostname->getValue()); // And the lease in the lease database should also contain this new FQDN. lease = LeaseMgrFactory::instance().getLease4(client.config_.lease_.addr_); ASSERT_TRUE(lease); - EXPECT_EQ("foobar.org", lease->hostname_); + EXPECT_EQ("foobar.fake-suffix.isc.org", lease->hostname_); // Now there should be two name NCRs. One that removes the previous entry // and the one that adds a new entry for the new hostname. ASSERT_EQ(2, CfgMgr::instance().getD2ClientMgr().getQueueSize()); - verifyNameChangeRequest(isc::dhcp_ddns::CHG_REMOVE, true, true, - resp->getYiaddr().toText(), - "unique-host.example.org.", - "000001ACB52196C8F3BCC1DF3BA1F40BAC39BF23" - "0D280858B1ED7696E174C4479E3372", - time(NULL), subnet_->getValid(), true); + { + SCOPED_TRACE("Verify the correctness of the CHG_REMOVE NCR for the " + "unique-host.example.org"); + + verifyNameChangeRequest(isc::dhcp_ddns::CHG_REMOVE, true, true, + resp->getYiaddr().toText(), + "unique-host.example.org.", + "000001ACB52196C8F3BCC1DF3BA1F40BAC39BF23" + "0D280858B1ED7696E174C4479E3372", + time(NULL), subnet_->getValid(), true); + } - verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true, - resp->getYiaddr().toText(), - "foobar.org.", - "000001B722C2FB5FAFE25B99178A0BFEC05127B9" - "5DC843E00941D444D53B24C2365337", - time(NULL), subnet_->getValid(), true); + { + SCOPED_TRACE("Verify the correctness of the CHG_ADD NCR for the " + "foobar.fake-suffix.isc.org"); + + verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true, + resp->getYiaddr().toText(), + "foobar.fake-suffix.isc.org.", + "0000017C29B3C236344924E448E247F3FD56C7E9" + "167B3397B1305FB664C160B967CE1F", + time(NULL), subnet_->getValid(), true); + } }