From 03a51d3d22eac26ac22bcbba704e286933f2abb4 Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sat, 6 Mar 2021 16:34:17 +0530 Subject: [PATCH] CacheZone: fixed bug in QueryRecords() which returned CNAME with special dns record RDATA. Updated SetRecords to remove old CNAME only when its RDATA is DnsCNAMERecord. --- DnsServerCore/Dns/Zones/CacheZone.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/DnsServerCore/Dns/Zones/CacheZone.cs b/DnsServerCore/Dns/Zones/CacheZone.cs index 2db2fa5f..b3fd8447 100644 --- a/DnsServerCore/Dns/Zones/CacheZone.cs +++ b/DnsServerCore/Dns/Zones/CacheZone.cs @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; using TechnitiumLibrary.IO; using TechnitiumLibrary.Net.Dns; +using TechnitiumLibrary.Net.Dns.ResourceRecords; namespace DnsServerCore.Dns.Zones { @@ -120,7 +121,15 @@ namespace DnsServerCore.Dns.Zones default: //remove old CNAME entry since current new entry type overlaps any existing CNAME entry in cache //keeping both entries will create issue with serve stale implementation since stale CNAME entry will be always returned - _entries.TryRemove(DnsResourceRecordType.CNAME, out _); + + if (_entries.TryGetValue(DnsResourceRecordType.CNAME, out IReadOnlyList cnameRecords)) + { + if ((cnameRecords.Count > 0) && (cnameRecords[0].RDATA is DnsCNAMERecord)) + { + //delete CNAME entry only when it contains DnsCNAMERecord RDATA and not special cache records + _entries.TryRemove(DnsResourceRecordType.CNAME, out _); + } + } break; } } @@ -170,7 +179,10 @@ namespace DnsServerCore.Dns.Zones { IReadOnlyList filteredRecords = FilterExpiredRecords(type, existingCNAMERecords, serveStale, filterSpecialCacheRecords); if (filteredRecords.Count > 0) - return filteredRecords; + { + if ((type == DnsResourceRecordType.CNAME) || (filteredRecords[0].RDATA is DnsCNAMERecord)) + return filteredRecords; + } } if (_entries.TryGetValue(type, out IReadOnlyList existingRecords))