SOARecordInfo.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 System.Collections.Generic;
  16. using System.IO;
  17. using TechnitiumLibrary.IO;
  18. using TechnitiumLibrary.Net.Dns;
  19. namespace DnsServerCore.Dns.ResourceRecords
  20. {
  21. class SOARecordInfo : GenericRecordInfo
  22. {
  23. #region variables
  24. byte _version;
  25. bool _useSoaSerialDateScheme;
  26. IReadOnlyList<NameServerAddress> _primaryNameServers; //depricated
  27. DnsTransportProtocol _zoneTransferProtocol; //depricated
  28. string _tsigKeyName = string.Empty; //depricated
  29. #endregion
  30. #region constructor
  31. public SOARecordInfo()
  32. { }
  33. public SOARecordInfo(BinaryReader bR)
  34. : base(bR)
  35. { }
  36. #endregion
  37. #region protected
  38. protected override void ReadExtendedRecordInfoFrom(BinaryReader bR)
  39. {
  40. _version = bR.ReadByte();
  41. switch (_version)
  42. {
  43. case 0: //no extended info
  44. break;
  45. case 1:
  46. int count = bR.ReadByte();
  47. if (count > 0)
  48. {
  49. NameServerAddress[] primaryNameServers = new NameServerAddress[count];
  50. for (int i = 0; i < primaryNameServers.Length; i++)
  51. primaryNameServers[i] = new NameServerAddress(bR);
  52. _primaryNameServers = primaryNameServers;
  53. }
  54. _zoneTransferProtocol = (DnsTransportProtocol)bR.ReadByte();
  55. _tsigKeyName = bR.ReadShortString();
  56. _useSoaSerialDateScheme = bR.ReadBoolean();
  57. break;
  58. case 2:
  59. _useSoaSerialDateScheme = bR.ReadBoolean();
  60. break;
  61. default:
  62. throw new InvalidDataException("SOARecordInfo format version not supported.");
  63. }
  64. }
  65. protected override void WriteExtendedRecordInfoTo(BinaryWriter bW)
  66. {
  67. bW.Write((byte)2); //version
  68. bW.Write(_useSoaSerialDateScheme);
  69. }
  70. #endregion
  71. #region properties
  72. public override bool Disabled
  73. {
  74. get { return base.Disabled; }
  75. set
  76. {
  77. //cannot disable SOA
  78. }
  79. }
  80. public override uint ExpiryTtl
  81. {
  82. get { return base.ExpiryTtl; }
  83. set
  84. {
  85. //cannot expire SOA
  86. }
  87. }
  88. public byte Version
  89. { get { return _version; } }
  90. public bool UseSoaSerialDateScheme
  91. {
  92. get { return _useSoaSerialDateScheme; }
  93. set { _useSoaSerialDateScheme = value; }
  94. }
  95. public IReadOnlyList<NameServerAddress> PrimaryNameServers
  96. {
  97. get { return _primaryNameServers; }
  98. set { _primaryNameServers = value; }
  99. }
  100. public DnsTransportProtocol ZoneTransferProtocol
  101. {
  102. get { return _zoneTransferProtocol; }
  103. set { _zoneTransferProtocol = value; }
  104. }
  105. public string TsigKeyName
  106. {
  107. get { return _tsigKeyName; }
  108. set { _tsigKeyName = value; }
  109. }
  110. #endregion
  111. }
  112. }