Browse Source

[4217] HostMgr now uses exactly one identifier in get4() query

 - Includes fix in AllocEngine6Test ctor, provided by Thomas
Tomek Mrugalski 9 years ago
parent
commit
e05819fbce

+ 12 - 2
src/lib/dhcpsrv/host_mgr.cc

@@ -104,7 +104,12 @@ HostMgr::get4(const SubnetID& subnet_id, const HWAddrPtr& hwaddr,
             .arg(subnet_id)
             .arg(subnet_id)
             .arg(hwaddr ? hwaddr->toText() : "(no-hwaddr)")
             .arg(hwaddr ? hwaddr->toText() : "(no-hwaddr)")
             .arg(duid ? duid->toText() : "(duid)");
             .arg(duid ? duid->toText() : "(duid)");
-        host = alternate_source_->get4(subnet_id, hwaddr, duid);
+        if (duid) {
+            host = alternate_source_->get4(subnet_id, HWAddrPtr(), duid);
+        }
+        if (!host && hwaddr) {
+            host = alternate_source_->get4(subnet_id, hwaddr, DuidPtr());
+        }
     }
     }
     return (host);
     return (host);
 }
 }
@@ -134,7 +139,12 @@ HostMgr::get6(const SubnetID& subnet_id, const DuidPtr& duid,
             .arg(subnet_id)
             .arg(subnet_id)
             .arg(duid ? duid->toText() : "(duid)")
             .arg(duid ? duid->toText() : "(duid)")
             .arg(hwaddr ? hwaddr->toText() : "(no-hwaddr)");
             .arg(hwaddr ? hwaddr->toText() : "(no-hwaddr)");
-        host = alternate_source_->get6(subnet_id, duid, hwaddr);
+        if (duid) {
+            host = alternate_source_->get6(subnet_id, duid, HWAddrPtr());
+        }
+        if (!host && hwaddr) {
+            host = alternate_source_->get6(subnet_id, DuidPtr(), hwaddr);
+        }
     }
     }
     return (host);
     return (host);
 }
 }

+ 1 - 1
src/lib/dhcpsrv/mysql_host_data_source.cc

@@ -867,7 +867,7 @@ MySqlHostDataSource::get6(const SubnetID& subnet_id, const DuidPtr& duid,
     inbind[0].buffer = reinterpret_cast<char*>(&subnet_buffer);
     inbind[0].buffer = reinterpret_cast<char*>(&subnet_buffer);
     inbind[0].is_unsigned = MLM_TRUE;
     inbind[0].is_unsigned = MLM_TRUE;
 
 
-    /// @todo: Rethink the logic in BaseHostDataSource::get4(subnet, hwaddr, duid)
+    /// @todo: Rethink the logic in BaseHostDataSource::get6(subnet, hwaddr, duid)
     if (hwaddr && duid) {
     if (hwaddr && duid) {
         isc_throw(BadValue, "MySQL host data source get6() called with both"
         isc_throw(BadValue, "MySQL host data source get6() called with both"
                   " hwaddr and duid, only one of them is allowed");
                   " hwaddr and duid, only one of them is allowed");

+ 3 - 0
src/lib/dhcpsrv/tests/alloc_engine_utils.cc

@@ -134,6 +134,9 @@ AllocEngine6Test::AllocEngine6Test() {
     duid_ = DuidPtr(new DUID(std::vector<uint8_t>(8, 0x42)));
     duid_ = DuidPtr(new DUID(std::vector<uint8_t>(8, 0x42)));
     iaid_ = 42;
     iaid_ = 42;
 
 
+    // Create fresh instance of the HostMgr, and drop any previous HostMgr state.
+    HostMgr::instance().create();
+
     // Let's use odd hardware type to check if there is no Ethernet
     // Let's use odd hardware type to check if there is no Ethernet
     // hardcoded anywhere.
     // hardcoded anywhere.
     const uint8_t mac[] = { 0, 1, 22, 33, 44, 55};
     const uint8_t mac[] = { 0, 1, 22, 33, 44, 55};