From 573d6cf1d2e03e96ae175d6926a12cdf7f95be10 Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sat, 6 Jun 2020 16:18:13 +0530 Subject: [PATCH] AuthZoneInfo: updated code to support forwarder zone and included LastRefreshed and IsExpired for secondary and stub zones. --- DnsServerCore/Dns/Zones/AuthZoneInfo.cs | 64 ++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/DnsServerCore/Dns/Zones/AuthZoneInfo.cs b/DnsServerCore/Dns/Zones/AuthZoneInfo.cs index c4cd0a43..01efbc5c 100644 --- a/DnsServerCore/Dns/Zones/AuthZoneInfo.cs +++ b/DnsServerCore/Dns/Zones/AuthZoneInfo.cs @@ -30,7 +30,8 @@ namespace DnsServerCore.Dns.Zones Unknown = 0, Primary = 1, Secondary = 2, - Stub = 3 + Stub = 3, + Forwarder = 4 } public class AuthZoneInfo : IComparable @@ -41,6 +42,8 @@ namespace DnsServerCore.Dns.Zones readonly AuthZoneType _type; readonly bool _disabled; + readonly DateTime _lastRefreshed; + readonly AuthZone _zone; #endregion @@ -62,6 +65,18 @@ namespace DnsServerCore.Dns.Zones _name = bR.ReadShortString(); _type = (AuthZoneType)bR.ReadByte(); _disabled = bR.ReadBoolean(); + + switch (_type) + { + case AuthZoneType.Secondary: + _lastRefreshed = bR.ReadDate(); + break; + + case AuthZoneType.Stub: + _lastRefreshed = bR.ReadDate(); + break; + } + break; default: @@ -79,11 +94,24 @@ namespace DnsServerCore.Dns.Zones _type = AuthZoneType.Secondary; else if (zone is StubZone) _type = AuthZoneType.Stub; + else if (zone is ForwarderZone) + _type = AuthZoneType.Forwarder; else _type = AuthZoneType.Unknown; _disabled = zone.Disabled; + switch (_type) + { + case AuthZoneType.Secondary: + _lastRefreshed = (_zone as SecondaryZone).LastRefreshed; + break; + + case AuthZoneType.Stub: + _lastRefreshed = (_zone as StubZone).LastRefreshed; + break; + } + _zone = zone; } @@ -101,11 +129,25 @@ namespace DnsServerCore.Dns.Zones public void WriteTo(BinaryWriter bW) { + if (_zone == null) + throw new InvalidOperationException(); + bW.Write((byte)1); //version bW.WriteShortString(_name); bW.Write((byte)_type); bW.Write(_disabled); + + switch (_type) + { + case AuthZoneType.Secondary: + bW.Write(_lastRefreshed); + break; + + case AuthZoneType.Stub: + bW.Write(_lastRefreshed); + break; + } } public int CompareTo(AuthZoneInfo other) @@ -140,6 +182,26 @@ namespace DnsServerCore.Dns.Zones } } + public DateTime LastRefreshed + { get { return _lastRefreshed; } } + + public bool IsExpired + { + get + { + if (_zone == null) + throw new InvalidOperationException(); + + if (_zone is SecondaryZone) + return (_zone as SecondaryZone).IsExpired; + + if (_zone is StubZone) + return (_zone as StubZone).IsExpired; + + return false; + } + } + public bool Internal { get