SecondaryForwarderZone.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. Technitium DNS Server
  3. Copyright (C) 2024 Shreyas Zare (shreyas@technitium.com)
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. using DnsServerCore.Dns.ResourceRecords;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Threading.Tasks;
  19. using TechnitiumLibrary.Net.Dns;
  20. using TechnitiumLibrary.Net.Dns.ResourceRecords;
  21. namespace DnsServerCore.Dns.Zones
  22. {
  23. class SecondaryForwarderZone : SecondaryZone
  24. {
  25. #region constructor
  26. public SecondaryForwarderZone(DnsServer dnsServer, AuthZoneInfo zoneInfo)
  27. : base(dnsServer, zoneInfo)
  28. { }
  29. public SecondaryForwarderZone(DnsServer dnsServer, string name, IReadOnlyList<NameServerAddress> primaryNameServerAddresses, DnsTransportProtocol primaryZoneTransferProtocol = DnsTransportProtocol.Tcp, string primaryZoneTransferTsigKeyName = null)
  30. : base(dnsServer, name, primaryNameServerAddresses, primaryZoneTransferProtocol, primaryZoneTransferTsigKeyName, false)
  31. {
  32. InitZone();
  33. }
  34. #endregion
  35. #region protected
  36. protected virtual void InitZone()
  37. {
  38. //init secondary forwarder zone with dummy SOA record
  39. DnsSOARecordData soa = new DnsSOARecordData(_dnsServer.ServerDomain, "invalid", 0, 900, 300, 604800, 900);
  40. DnsResourceRecord soaRecord = new DnsResourceRecord(_name, DnsResourceRecordType.SOA, DnsClass.IN, 0, soa);
  41. soaRecord.GetAuthGenericRecordInfo().LastModified = DateTime.UtcNow;
  42. _entries[DnsResourceRecordType.SOA] = [soaRecord];
  43. }
  44. protected override Task FinalizeZoneTransferAsync()
  45. {
  46. //secondary forwarder does not maintain zone history; no need to call base method
  47. return Task.CompletedTask;
  48. }
  49. protected override Task FinalizeIncrementalZoneTransferAsync(IReadOnlyList<DnsResourceRecord> historyRecords)
  50. {
  51. //secondary forwarder does not maintain zone history; no need to call base method
  52. return Task.CompletedTask;
  53. }
  54. #endregion
  55. #region public
  56. public override string GetZoneTypeName()
  57. {
  58. return "Secondary Forwarder";
  59. }
  60. public override IReadOnlyList<DnsResourceRecord> QueryRecords(DnsResourceRecordType type, bool dnssecOk)
  61. {
  62. if (type == DnsResourceRecordType.SOA)
  63. return []; //secondary forwarder zone is not authoritative and contains dummy SOA record
  64. return base.QueryRecords(type, dnssecOk);
  65. }
  66. #endregion
  67. #region properties
  68. public override bool OverrideCatalogZoneTransfer
  69. {
  70. get { throw new InvalidOperationException(); }
  71. set { throw new InvalidOperationException(); }
  72. }
  73. public override bool OverrideCatalogPrimaryNameServers
  74. {
  75. get { throw new InvalidOperationException(); }
  76. set { throw new InvalidOperationException(); }
  77. }
  78. public override AuthZoneQueryAccess QueryAccess
  79. {
  80. get { return base.QueryAccess; }
  81. set
  82. {
  83. switch (value)
  84. {
  85. case AuthZoneQueryAccess.AllowOnlyZoneNameServers:
  86. case AuthZoneQueryAccess.AllowZoneNameServersAndUseSpecifiedNetworkACL:
  87. throw new ArgumentException("The Query Access option is invalid for Secondary Conditional Forwarder zones: " + value.ToString(), nameof(QueryAccess));
  88. }
  89. base.QueryAccess = value;
  90. }
  91. }
  92. public override AuthZoneTransfer ZoneTransfer
  93. {
  94. get { return base.ZoneTransfer; }
  95. set { throw new InvalidOperationException(); }
  96. }
  97. public override AuthZoneNotify Notify
  98. {
  99. get { return base.Notify; }
  100. set { throw new InvalidOperationException(); }
  101. }
  102. public override AuthZoneUpdate Update
  103. {
  104. get { return base.Update; }
  105. set
  106. {
  107. switch (value)
  108. {
  109. case AuthZoneUpdate.AllowOnlyZoneNameServers:
  110. case AuthZoneUpdate.AllowZoneNameServersAndUseSpecifiedNetworkACL:
  111. throw new ArgumentException("The Dynamic Updates option is invalid for Secondary Conditional Forwarder zones: " + value.ToString(), nameof(Update));
  112. }
  113. base.Update = value;
  114. }
  115. }
  116. public override IReadOnlyList<NameServerAddress> PrimaryNameServerAddresses
  117. {
  118. get { return base.PrimaryNameServerAddresses; }
  119. set
  120. {
  121. if ((value is null) || (value.Count == 0))
  122. throw new ArgumentException("At least one primary name server address must be specified for " + GetZoneTypeName() + " zone.", nameof(PrimaryNameServerAddresses));
  123. base.PrimaryNameServerAddresses = value;
  124. }
  125. }
  126. public override bool ValidateZone
  127. {
  128. get { return base.ValidateZone; }
  129. set { throw new InvalidOperationException(); }
  130. }
  131. #endregion
  132. }
  133. }