Browse Source

[3295] Function which creates Name Change Request takes FQDN from message.

Marcin Siodelski 11 years ago
parent
commit
7bac6cc149
3 changed files with 24 additions and 26 deletions
  1. 11 12
      src/bin/dhcp6/dhcp6_srv.cc
  2. 1 2
      src/bin/dhcp6/dhcp6_srv.h
  3. 12 12
      src/bin/dhcp6/tests/fqdn_unittest.cc

+ 11 - 12
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);
 }

+ 1 - 2
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.

+ 12 - 12
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