From 216695a3cd637262641b82c1a6dfd568fc20b3f1 Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sun, 23 Apr 2023 16:15:12 +0530 Subject: [PATCH] CacheZone: added support for conditional forwarding client subnet. --- DnsServerCore/Dns/Zones/CacheZone.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/DnsServerCore/Dns/Zones/CacheZone.cs b/DnsServerCore/Dns/Zones/CacheZone.cs index 417836f0..367c60d9 100644 --- a/DnsServerCore/Dns/Zones/CacheZone.cs +++ b/DnsServerCore/Dns/Zones/CacheZone.cs @@ -199,8 +199,10 @@ namespace DnsServerCore.Dns.Zones ConcurrentDictionary> entries; - NetworkAddress eDnsClientSubnet = records[0].GetCacheRecordInfo().EDnsClientSubnet; - if ((eDnsClientSubnet is null) || !IsTypeSupportedForEDnsClientSubnet(type)) + CacheRecordInfo cacheRecordInfo = records[0].GetCacheRecordInfo(); + NetworkAddress eDnsClientSubnet = cacheRecordInfo.EDnsClientSubnet; + + if ((eDnsClientSubnet is null) || (!cacheRecordInfo.ConditionalForwardingClientSubnet && !IsTypeSupportedForEDnsClientSubnet(type))) { entries = _entries; } @@ -385,11 +387,11 @@ namespace DnsServerCore.Dns.Zones return count; } - public IReadOnlyList QueryRecords(DnsResourceRecordType type, bool serveStale, bool skipSpecialCacheRecord, NetworkAddress eDnsClientSubnet) + public IReadOnlyList QueryRecords(DnsResourceRecordType type, bool serveStale, bool skipSpecialCacheRecord, NetworkAddress eDnsClientSubnet, bool conditionalForwardingClientSubnet) { ConcurrentDictionary> entries; - if ((eDnsClientSubnet is null) || !IsTypeSupportedForEDnsClientSubnet(type)) + if ((eDnsClientSubnet is null) || (!conditionalForwardingClientSubnet && !IsTypeSupportedForEDnsClientSubnet(type))) { entries = _entries; } @@ -408,7 +410,7 @@ namespace DnsServerCore.Dns.Zones if (cacheSubnet.PrefixLength > eDnsClientSubnet.PrefixLength) continue; - if (cacheSubnet.Equals(eDnsClientSubnet) || cacheSubnet.Contains(eDnsClientSubnet.Address)) + if (cacheSubnet.Equals(eDnsClientSubnet) || (!conditionalForwardingClientSubnet && cacheSubnet.Contains(eDnsClientSubnet.Address))) { if ((selectedNetwork is null) || (cacheSubnet.PrefixLength > selectedNetwork.PrefixLength)) {