Commit f61aa09c authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[3688] DHCPv4 server appends qualifying suffix to the reserved hostname.

parent 3232c090
...@@ -861,8 +861,9 @@ Dhcpv4Srv::processClientFqdnOption(DHCPv4Exchange& ex) { ...@@ -861,8 +861,9 @@ Dhcpv4Srv::processClientFqdnOption(DHCPv4Exchange& ex) {
fqdn->getFlag(Option4ClientFqdn::FLAG_E)); fqdn->getFlag(Option4ClientFqdn::FLAG_E));
if (ex.getContext()->host_ && !ex.getContext()->host_->getHostname().empty()) { if (ex.getContext()->host_ && !ex.getContext()->host_->getHostname().empty()) {
fqdn_resp->setDomainName(ex.getContext()->host_->getHostname(), D2ClientMgr& d2_mgr = CfgMgr::instance().getD2ClientMgr();
Option4ClientFqdn::FULL); fqdn_resp->setDomainName(d2_mgr.qualifyName(ex.getContext()->host_->getHostname(),
true), Option4ClientFqdn::FULL);
} else { } else {
// Adjust the domain name based on domain name value and type sent by the // Adjust the domain name based on domain name value and type sent by the
...@@ -924,7 +925,8 @@ Dhcpv4Srv::processHostnameOption(DHCPv4Exchange& ex) { ...@@ -924,7 +925,8 @@ Dhcpv4Srv::processHostnameOption(DHCPv4Exchange& ex) {
// If there is a hostname reservation for this client, use it. // If there is a hostname reservation for this client, use it.
if (ex.getContext()->host_ && !ex.getContext()->host_->getHostname().empty()) { 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()) || } else if ((d2_mgr.getD2ClientConfig()->getReplaceClientName()) ||
(label_count < 2)) { (label_count < 2)) {
......
...@@ -61,7 +61,7 @@ const char* CONFIGS[] = { ...@@ -61,7 +61,7 @@ const char* CONFIGS[] = {
" }]," " }],"
"\"dhcp-ddns\": {" "\"dhcp-ddns\": {"
"\"enable-updates\": true," "\"enable-updates\": true,"
"\"qualifying-suffix\": \"fake-suffix.isc.org.\"" "\"qualifying-suffix\": \"\""
"}" "}"
"}", "}",
"{ \"interfaces-config\": {" "{ \"interfaces-config\": {"
...@@ -82,7 +82,7 @@ const char* CONFIGS[] = { ...@@ -82,7 +82,7 @@ const char* CONFIGS[] = {
" \"reservations\": [" " \"reservations\": ["
" {" " {"
" \"hw-address\": \"aa:bb:cc:dd:ee:ff\"," " \"hw-address\": \"aa:bb:cc:dd:ee:ff\","
" \"hostname\": \"foobar.org\"" " \"hostname\": \"foobar\""
" }" " }"
" ]" " ]"
" }]," " }],"
...@@ -1146,15 +1146,20 @@ TEST_F(NameDhcpv4SrvTest, fqdnReservation) { ...@@ -1146,15 +1146,20 @@ TEST_F(NameDhcpv4SrvTest, fqdnReservation) {
ASSERT_TRUE(fqdn); ASSERT_TRUE(fqdn);
EXPECT_EQ("unique-host.example.org.", fqdn->getDomainName()); 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. SCOPED_TRACE("Verify the correctness of the NCR for the"
ASSERT_EQ(1, CfgMgr::instance().getD2ClientMgr().getQueueSize()); "unique-host.example.org");
verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
resp->getYiaddr().toText(), // Because this is a new lease, there should be one NCR which adds the
"unique-host.example.org.", // new DNS entry.
"000001ACB52196C8F3BCC1DF3BA1F40BAC39BF23" ASSERT_EQ(1, CfgMgr::instance().getD2ClientMgr().getQueueSize());
"0D280858B1ED7696E174C4479E3372", verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
time(NULL), subnet_->getValid(), 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. // And that this FQDN has been stored in the lease database.
Lease4Ptr lease = LeaseMgrFactory::instance().getLease4(client.config_.lease_.addr_); Lease4Ptr lease = LeaseMgrFactory::instance().getLease4(client.config_.lease_.addr_);
...@@ -1163,6 +1168,9 @@ TEST_F(NameDhcpv4SrvTest, fqdnReservation) { ...@@ -1163,6 +1168,9 @@ TEST_F(NameDhcpv4SrvTest, fqdnReservation) {
// Reconfigure DHCP server to use a different hostname for the client. // Reconfigure DHCP server to use a different hostname for the client.
configure(CONFIGS[1], *client.getServer()); 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 is in the renewing state.
client.setState(Dhcp4Client::RENEWING); client.setState(Dhcp4Client::RENEWING);
...@@ -1174,29 +1182,40 @@ TEST_F(NameDhcpv4SrvTest, fqdnReservation) { ...@@ -1174,29 +1182,40 @@ TEST_F(NameDhcpv4SrvTest, fqdnReservation) {
// The new FQDN should contain a different name this time. // The new FQDN should contain a different name this time.
fqdn = boost::dynamic_pointer_cast<Option4ClientFqdn>(resp->getOption(DHO_FQDN)); fqdn = boost::dynamic_pointer_cast<Option4ClientFqdn>(resp->getOption(DHO_FQDN));
ASSERT_TRUE(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. // And the lease in the lease database should also contain this new FQDN.
lease = LeaseMgrFactory::instance().getLease4(client.config_.lease_.addr_); lease = LeaseMgrFactory::instance().getLease4(client.config_.lease_.addr_);
ASSERT_TRUE(lease); 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 // 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. // and the one that adds a new entry for the new hostname.
ASSERT_EQ(2, CfgMgr::instance().getD2ClientMgr().getQueueSize()); 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(), SCOPED_TRACE("Verify the correctness of the CHG_REMOVE NCR for the "
"foobar.org.", "unique-host.example.org");
"000001B722C2FB5FAFE25B99178A0BFEC05127B9"
"5DC843E00941D444D53B24C2365337", verifyNameChangeRequest(isc::dhcp_ddns::CHG_REMOVE, true, true,
time(NULL), subnet_->getValid(), 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 // This test verifies that the server sends the Hostname option to the client
...@@ -1247,15 +1266,23 @@ TEST_F(NameDhcpv4SrvTest, hostnameReservation) { ...@@ -1247,15 +1266,23 @@ TEST_F(NameDhcpv4SrvTest, hostnameReservation) {
// Because this is a new lease, there should be one NCR which adds the // Because this is a new lease, there should be one NCR which adds the
// new DNS entry. // new DNS entry.
ASSERT_EQ(1, CfgMgr::instance().getD2ClientMgr().getQueueSize()); ASSERT_EQ(1, CfgMgr::instance().getD2ClientMgr().getQueueSize());
verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true, {
resp->getYiaddr().toText(), SCOPED_TRACE("Verify the correctness of the NCR for the"
"unique-host.example.org.", "unique-host.example.org");
"000001ACB52196C8F3BCC1DF3BA1F40BAC39BF23"
"0D280858B1ED7696E174C4479E3372", verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
time(NULL), subnet_->getValid(), 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. // Reconfigure DHCP server to use a different hostname for the client.
configure(CONFIGS[1], *client.getServer()); 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 is in the renewing state.
client.setState(Dhcp4Client::RENEWING); client.setState(Dhcp4Client::RENEWING);
...@@ -1267,29 +1294,39 @@ TEST_F(NameDhcpv4SrvTest, hostnameReservation) { ...@@ -1267,29 +1294,39 @@ TEST_F(NameDhcpv4SrvTest, hostnameReservation) {
// The new hostname should be different than previously. // The new hostname should be different than previously.
hostname = boost::dynamic_pointer_cast<OptionString>(resp->getOption(DHO_HOST_NAME)); hostname = boost::dynamic_pointer_cast<OptionString>(resp->getOption(DHO_HOST_NAME));
ASSERT_TRUE(hostname); 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. // And the lease in the lease database should also contain this new FQDN.
lease = LeaseMgrFactory::instance().getLease4(client.config_.lease_.addr_); lease = LeaseMgrFactory::instance().getLease4(client.config_.lease_.addr_);
ASSERT_TRUE(lease); 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 // 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. // and the one that adds a new entry for the new hostname.
ASSERT_EQ(2, CfgMgr::instance().getD2ClientMgr().getQueueSize()); ASSERT_EQ(2, CfgMgr::instance().getD2ClientMgr().getQueueSize());
verifyNameChangeRequest(isc::dhcp_ddns::CHG_REMOVE, true, true, {
resp->getYiaddr().toText(), SCOPED_TRACE("Verify the correctness of the CHG_REMOVE NCR for the "
"unique-host.example.org.", "unique-host.example.org");
"000001ACB52196C8F3BCC1DF3BA1F40BAC39BF23"
"0D280858B1ED7696E174C4479E3372", verifyNameChangeRequest(isc::dhcp_ddns::CHG_REMOVE, true, true,
time(NULL), subnet_->getValid(), 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(), SCOPED_TRACE("Verify the correctness of the CHG_ADD NCR for the "
"foobar.org.", "foobar.fake-suffix.isc.org");
"000001B722C2FB5FAFE25B99178A0BFEC05127B9"
"5DC843E00941D444D53B24C2365337", verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
time(NULL), subnet_->getValid(), true); resp->getYiaddr().toText(),
"foobar.fake-suffix.isc.org.",
"0000017C29B3C236344924E448E247F3FD56C7E9"
"167B3397B1305FB664C160B967CE1F",
time(NULL), subnet_->getValid(), true);
}
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment