CacheZone: updated SetRecords() to set ParentSideTtl values for new NS records from existing NS records for use with NS revalidation. Updated QueryRecords() to remove DS from ANY response.

This commit is contained in:
Shreyas Zare
2022-05-08 15:30:00 +05:30
parent df02416e30
commit 2be4a3ed5d

View File

@@ -76,14 +76,37 @@ namespace DnsServerCore.Dns.Zones
public bool SetRecords(DnsResourceRecordType type, IReadOnlyList<DnsResourceRecord> records, bool serveStale)
{
bool isFailureRecord = (records.Count > 0) && records[0].RDATA is DnsCache.DnsSpecialCacheRecord splRecord && splRecord.IsFailureOrBadCache;
if (isFailureRecord)
bool isFailureRecord = false;
if (records.Count > 0)
{
//call trying to cache failure record
if (_entries.TryGetValue(type, out IReadOnlyList<DnsResourceRecord> existingRecords))
if (records[0].RDATA is DnsCache.DnsSpecialCacheRecord splRecord)
{
if ((existingRecords.Count > 0) && !(existingRecords[0].RDATA is DnsCache.DnsSpecialCacheRecord existingSplRecord && existingSplRecord.IsFailureOrBadCache) && !DnsResourceRecord.IsRRSetExpired(existingRecords, serveStale))
return false; //skip to avoid overwriting a useful record with a failure record
if (splRecord.IsFailureOrBadCache)
{
//call trying to cache failure record
isFailureRecord = true;
if (_entries.TryGetValue(type, out IReadOnlyList<DnsResourceRecord> existingRecords))
{
if ((existingRecords.Count > 0) && !(existingRecords[0].RDATA is DnsCache.DnsSpecialCacheRecord existingSplRecord && existingSplRecord.IsFailureOrBadCache) && !DnsResourceRecord.IsRRSetExpired(existingRecords, serveStale))
return false; //skip to avoid overwriting a useful record with a failure record
}
}
}
else if ((type == DnsResourceRecordType.NS) && (records[0].RDATA is DnsNSRecordData ns) && !ns.IsParentSideTtlSet)
{
//for ns revalidation
if (_entries.TryGetValue(DnsResourceRecordType.NS, out IReadOnlyList<DnsResourceRecord> existingNSRecords))
{
if ((existingNSRecords.Count > 0) && (existingNSRecords[0].RDATA is DnsNSRecordData existingNS) && existingNS.IsParentSideTtlSet)
{
uint parentSideTtl = existingNS.ParentSideTtl;
foreach (DnsResourceRecord record in records)
(record.RDATA as DnsNSRecordData).ParentSideTtl = parentSideTtl;
}
}
}
}
@@ -201,7 +224,12 @@ namespace DnsServerCore.Dns.Zones
List<DnsResourceRecord> anyRecords = new List<DnsResourceRecord>(_entries.Count * 2);
foreach (KeyValuePair<DnsResourceRecordType, IReadOnlyList<DnsResourceRecord>> entry in _entries)
{
if (entry.Key == DnsResourceRecordType.DS)
continue;
anyRecords.AddRange(ValidateRRSet(type, entry.Value, serveStale, true));
}
return anyRecords;