ForwarderZone.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. Technitium DNS Server
  3. Copyright (C) 2023 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 TechnitiumLibrary.Net.Dns;
  19. using TechnitiumLibrary.Net.Dns.ResourceRecords;
  20. using TechnitiumLibrary.Net.Proxy;
  21. namespace DnsServerCore.Dns.Zones
  22. {
  23. class ForwarderZone : ApexZone
  24. {
  25. #region constructor
  26. public ForwarderZone(AuthZoneInfo zoneInfo)
  27. : base(zoneInfo)
  28. { }
  29. public ForwarderZone(string name, DnsTransportProtocol forwarderProtocol, string forwarder, bool dnssecValidation, NetProxyType proxyType, string proxyAddress, ushort proxyPort, string proxyUsername, string proxyPassword, string fwdRecordComments)
  30. : base(name)
  31. {
  32. _zoneTransfer = AuthZoneTransfer.Deny;
  33. _notify = AuthZoneNotify.None;
  34. _update = AuthZoneUpdate.Deny;
  35. DnsResourceRecord fwdRecord = new DnsResourceRecord(name, DnsResourceRecordType.FWD, DnsClass.IN, 0, new DnsForwarderRecordData(forwarderProtocol, forwarder, dnssecValidation, proxyType, proxyAddress, proxyPort, proxyUsername, proxyPassword));
  36. if (!string.IsNullOrEmpty(fwdRecordComments))
  37. fwdRecord.GetAuthRecordInfo().Comments = fwdRecordComments;
  38. _entries[DnsResourceRecordType.FWD] = new DnsResourceRecord[] { fwdRecord };
  39. }
  40. #endregion
  41. #region public
  42. public override void SetRecords(DnsResourceRecordType type, IReadOnlyList<DnsResourceRecord> records)
  43. {
  44. switch (type)
  45. {
  46. case DnsResourceRecordType.CNAME:
  47. throw new InvalidOperationException("Cannot set CNAME record at zone apex.");
  48. case DnsResourceRecordType.SOA:
  49. case DnsResourceRecordType.DS:
  50. throw new DnsServerException("The record type is not supported by forwarder zones.");
  51. default:
  52. base.SetRecords(type, records);
  53. break;
  54. }
  55. }
  56. public override void AddRecord(DnsResourceRecord record)
  57. {
  58. switch (record.Type)
  59. {
  60. case DnsResourceRecordType.DS:
  61. throw new DnsServerException("The record type is not supported by forwarder zones.");
  62. default:
  63. base.AddRecord(record);
  64. break;
  65. }
  66. }
  67. #endregion
  68. #region properties
  69. public override AuthZoneTransfer ZoneTransfer
  70. {
  71. get { return _zoneTransfer; }
  72. set { throw new InvalidOperationException(); }
  73. }
  74. public override AuthZoneNotify Notify
  75. {
  76. get { return _notify; }
  77. set { throw new InvalidOperationException(); }
  78. }
  79. public override AuthZoneUpdate Update
  80. {
  81. get { return _update; }
  82. set { throw new InvalidOperationException(); }
  83. }
  84. #endregion
  85. }
  86. }