Parcourir la source

[3295] Do not generate NameChangeRequests for Solicit.

Marcin Siodelski il y a 11 ans
Parent
commit
c50566742f

+ 1 - 1
src/bin/dhcp6/dhcp6_srv.cc

@@ -1322,7 +1322,7 @@ Dhcpv6Srv::assignIA_NA(const Subnet6Ptr& subnet, const DuidPtr& duid,
         // have to check that the FQDN settings we provided are the same
         // that were set. If they aren't, we will have to remove existing
         // DNS records and update the lease with the new settings.
-        if (old_lease &&
+        if (!fake_allocation && old_lease &&
             ((lease->hostname_ != old_lease->hostname_) ||
              (lease->fqdn_fwd_ != old_lease->fqdn_fwd_) ||
              (lease->fqdn_rev_ != old_lease->fqdn_rev_))) {

+ 30 - 0
src/bin/dhcp6/tests/fqdn_unittest.cc

@@ -684,6 +684,36 @@ TEST_F(FqdnDhcpv6SrvTest, processTwoRequests) {
 
 }
 
+// Test that NameChangeRequest is not generated when Solicit message is sent.
+// The Solicit is here sent after a lease has been allocated for a client.
+// The Solicit conveys a different hostname which would trigger updates to
+// DNS if the Request was sent instead of Soicit. The code should differentiate
+// behavior depending whether Solicit or Request is sent.
+TEST_F(FqdnDhcpv6SrvTest, processRequestSolicit) {
+    NakedDhcpv6Srv srv(0);
+
+    // Create a Request message with FQDN option and generate server's
+    // response using processRequest function. This will result in the
+    // creation of a new lease and the appropriate NameChangeRequest
+    // to add both reverse and forward mapping to DNS.
+    testProcessMessage(DHCPV6_REQUEST, "myhost.example.com", srv);
+    ASSERT_EQ(1, srv.name_change_reqs_.size());
+    verifyNameChangeRequest(srv, isc::dhcp_ddns::CHG_ADD, true, true,
+                            "2001:db8:1:1::dead:beef",
+                            "000201415AA33D1187D148275136FA30300478"
+                            "FAAAA3EBD29826B5C907B2C9268A6F52",
+                            0, 4000);
+
+    // When the returning client sends Solicit the code should never generate
+    // NameChangeRequest and preserve existing DNS entries for the client.
+    // The NameChangeRequest should only be generated when a client sends
+    // Request or Renew.
+    testProcessMessage(DHCPV6_SOLICIT, "otherhost.example.com", srv);
+    ASSERT_TRUE(srv.name_change_reqs_.empty());
+
+}
+
+
 // Test that client may send Request followed by the Renew, both holding
 // FQDN options, but each option holding different domain-name. The Renew
 // should result in generation of the two NameChangeRequests, one to remove

+ 5 - 1
src/lib/dhcpsrv/alloc_engine.cc

@@ -432,6 +432,10 @@ AllocEngine::allocateLeases6(const Subnet6Ptr& subnet, const DuidPtr& duid,
                                                rev_dns_update, hostname,
                                                callout_handle, fake_allocation);
                 if (lease) {
+                    // We are allocating a new lease (not renewing). So, the
+                    // old lease should be NULL.
+                    old_leases.push_back(Lease6Ptr());
+
                     Lease6Collection collection;
                     collection.push_back(lease);
                     return (collection);
@@ -444,7 +448,7 @@ AllocEngine::allocateLeases6(const Subnet6Ptr& subnet, const DuidPtr& duid,
                 if (existing->expired()) {
                     // Copy an existing, expired lease so as it can be returned
                     // to the caller.
-                    Lease6Ptr old_lease(new Lease6(*lease));
+                    Lease6Ptr old_lease(new Lease6(*existing));
                     old_leases.push_back(old_lease);
 
                     existing = reuseExpiredLease(existing, subnet, duid, iaid,