From: Marcin Siodelski Date: Mon, 20 Jan 2014 15:38:36 +0000 (+0100) Subject: [3295] Function which creates Name Change Request takes FQDN from message. X-Git-Tag: bind10-1.2.0beta1-release~83^2~18 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7bac6cc14920f87a4e15eb5bacc0fff6d43ceaf9;p=thirdparty%2Fkea.git [3295] Function which creates Name Change Request takes FQDN from message. --- diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc index 0eebad1b57..158fa77d01 100644 --- a/src/bin/dhcp6/dhcp6_srv.cc +++ b/src/bin/dhcp6/dhcp6_srv.cc @@ -1046,16 +1046,7 @@ Dhcpv6Srv::processClientFqdn(const Pkt6Ptr& question, const Pkt6Ptr& answer) { } void -Dhcpv6Srv::createNameChangeRequests(const Pkt6Ptr& answer, - const Option6ClientFqdnPtr& opt_fqdn) { - - // It is likely that client haven't included the FQDN option in the message - // and server is not configured to always update DNS. In such cases, - // FQDN option will be NULL. This is valid state, so we simply return. - if (!opt_fqdn) { - return; - } - +Dhcpv6Srv::createNameChangeRequests(const Pkt6Ptr& answer) { // The response message instance is always required. For instance it // holds the Client Identifier. It is a programming error if supplied // message is NULL. @@ -1065,6 +1056,14 @@ Dhcpv6Srv::createNameChangeRequests(const Pkt6Ptr& answer, << " NULL when creating DNS NameChangeRequest"); } + // It is likely that client haven't included the FQDN option. In such case, + // FQDN option will be NULL. This is valid state, so we simply return. + Option6ClientFqdnPtr opt_fqdn = boost::dynamic_pointer_cast< + Option6ClientFqdn>(answer->getOption(D6O_CLIENT_FQDN)); + if (!opt_fqdn) { + return; + } + // Get the Client Id. It is mandatory and a function creating a response // would have thrown an exception if it was missing. Thus throwning // Unexpected if it is missing as it is a programming error. @@ -2162,7 +2161,7 @@ Dhcpv6Srv::processRequest(const Pkt6Ptr& request) { Option6ClientFqdnPtr fqdn = processClientFqdn(request, reply); assignLeases(request, reply); - createNameChangeRequests(reply, fqdn); + createNameChangeRequests(reply); return (reply); } @@ -2180,7 +2179,7 @@ Dhcpv6Srv::processRenew(const Pkt6Ptr& renew) { Option6ClientFqdnPtr fqdn = processClientFqdn(renew, reply); renewLeases(renew, reply, fqdn); - createNameChangeRequests(reply, fqdn); + createNameChangeRequests(reply); return (reply); } diff --git a/src/bin/dhcp6/dhcp6_srv.h b/src/bin/dhcp6/dhcp6_srv.h index 6fe8dc29fd..25e3452670 100644 --- a/src/bin/dhcp6/dhcp6_srv.h +++ b/src/bin/dhcp6/dhcp6_srv.h @@ -400,8 +400,7 @@ protected: /// @param answer A message beging sent to the Client. /// @param fqdn_answer A DHCPv6 Client FQDN %Option which is included in the /// response message sent to a client. - void createNameChangeRequests(const Pkt6Ptr& answer, - const Option6ClientFqdnPtr& fqdn_answer); + void createNameChangeRequests(const Pkt6Ptr& answer); /// @brief Creates a @c isc::dhcp_ddns::NameChangeRequest which requests /// removal of DNS entries for a particular lease. diff --git a/src/bin/dhcp6/tests/fqdn_unittest.cc b/src/bin/dhcp6/tests/fqdn_unittest.cc index 65a32446f4..fe2233863e 100644 --- a/src/bin/dhcp6/tests/fqdn_unittest.cc +++ b/src/bin/dhcp6/tests/fqdn_unittest.cc @@ -436,10 +436,8 @@ TEST_F(FqdnDhcpv6SrvTest, createNameChangeRequestsNoAnswer) { NakedDhcpv6Srv srv(0); Pkt6Ptr answer; - Option6ClientFqdnPtr fqdn = createClientFqdn(Option6ClientFqdn::FLAG_S, - "myhost.example.com", - Option6ClientFqdn::FULL); - EXPECT_THROW(srv.createNameChangeRequests(answer, fqdn), + + EXPECT_THROW(srv.createNameChangeRequests(answer), isc::Unexpected); } @@ -453,22 +451,21 @@ TEST_F(FqdnDhcpv6SrvTest, createNameChangeRequestsNoDUID) { Option6ClientFqdnPtr fqdn = createClientFqdn(Option6ClientFqdn::FLAG_S, "myhost.example.com", Option6ClientFqdn::FULL); + answer->addOption(fqdn); - EXPECT_THROW(srv.createNameChangeRequests(answer, fqdn), - isc::Unexpected); + EXPECT_THROW(srv.createNameChangeRequests(answer), isc::Unexpected); } -// Test no NameChangeRequests are added if FQDN option is NULL. +// Test no NameChangeRequests if Client FQDN is not added to the server's +// response. TEST_F(FqdnDhcpv6SrvTest, createNameChangeRequestsNoFQDN) { NakedDhcpv6Srv srv(0); // Create Reply message with Client Id and Server id. Pkt6Ptr answer = generateMessageWithIds(DHCPV6_REPLY, srv); - // Pass NULL FQDN option. No NameChangeRequests should be created. - Option6ClientFqdnPtr fqdn; - ASSERT_NO_THROW(srv.createNameChangeRequests(answer, fqdn)); + ASSERT_NO_THROW(srv.createNameChangeRequests(answer)); // There should be no new NameChangeRequests. EXPECT_TRUE(srv.name_change_reqs_.empty()); @@ -482,11 +479,13 @@ TEST_F(FqdnDhcpv6SrvTest, createNameChangeRequestsNoAddr) { // Create Reply message with Client Id and Server id. Pkt6Ptr answer = generateMessageWithIds(DHCPV6_REPLY, srv); + // Add Client FQDN option. Option6ClientFqdnPtr fqdn = createClientFqdn(Option6ClientFqdn::FLAG_S, "myhost.example.com", Option6ClientFqdn::FULL); + answer->addOption(fqdn); - ASSERT_NO_THROW(srv.createNameChangeRequests(answer, fqdn)); + ASSERT_NO_THROW(srv.createNameChangeRequests(answer)); // We didn't add any IAs, so there should be no NameChangeRequests in th // queue. @@ -513,10 +512,11 @@ TEST_F(FqdnDhcpv6SrvTest, createNameChangeRequests) { Option6ClientFqdnPtr fqdn = createClientFqdn(Option6ClientFqdn::FLAG_S, "MYHOST.EXAMPLE.COM", Option6ClientFqdn::FULL); + answer->addOption(fqdn); // Create NameChangeRequests. Since we have added 3 IAs, it should // result in generation of 3 distinct NameChangeRequests. - ASSERT_NO_THROW(srv.createNameChangeRequests(answer, fqdn)); + ASSERT_NO_THROW(srv.createNameChangeRequests(answer)); ASSERT_EQ(3, srv.name_change_reqs_.size()); // Verify that NameChangeRequests are correct. Each call to the