From 7bc6ff9e705c44823c9e90b8dc8bf4428b4f2f8e Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sun, 6 Mar 2022 15:50:24 +0530 Subject: [PATCH] CacheZoneManager: Updated Query() to use FindZone call only when its required to find closest name servers else it will use TryGet to directly get the value from tree. --- .../Dns/ZoneManagers/CacheZoneManager.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/DnsServerCore/Dns/ZoneManagers/CacheZoneManager.cs b/DnsServerCore/Dns/ZoneManagers/CacheZoneManager.cs index 6f1ee632..94c60af9 100644 --- a/DnsServerCore/Dns/ZoneManagers/CacheZoneManager.cs +++ b/DnsServerCore/Dns/ZoneManagers/CacheZoneManager.cs @@ -341,7 +341,20 @@ namespace DnsServerCore.Dns.ZoneManagers { DnsQuestionRecord question = request.Question[0]; - CacheZone zone = _root.FindZone(question.Name, out CacheZone closest, out CacheZone delegation); + CacheZone zone; + CacheZone closest = null; + CacheZone delegation = null; + + if (findClosestNameServers) + { + zone = _root.FindZone(question.Name, out closest, out delegation); + } + else + { + if (!_root.TryGet(question.Name, out zone)) + _ = _root.FindZone(question.Name, out closest, out _); //zone not found; attempt to find closest + } + if (zone is not null) { //zone found