mirror of
https://github.com/fergalmoran/DnsServer.git
synced 2026-02-25 17:27:40 +00:00
DnsResourceRecordExtension: removed get/set type of extension methods.
This commit is contained in:
@@ -23,53 +23,37 @@ using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using TechnitiumLibrary;
|
||||
using TechnitiumLibrary.Net.Dns;
|
||||
using TechnitiumLibrary.Net.Dns.ResourceRecords;
|
||||
|
||||
namespace DnsServerCore.Dns.ResourceRecords
|
||||
{
|
||||
static class DnsResourceRecordExtension
|
||||
{
|
||||
public static void SetGlueRecords(this DnsResourceRecord record, IReadOnlyList<DnsResourceRecord> glueRecords)
|
||||
{
|
||||
if (record.Tag is not DnsResourceRecordInfo rrInfo)
|
||||
{
|
||||
rrInfo = new DnsResourceRecordInfo();
|
||||
record.Tag = rrInfo;
|
||||
}
|
||||
|
||||
rrInfo.GlueRecords = glueRecords;
|
||||
}
|
||||
|
||||
public static void SetGlueRecords(this DnsResourceRecord record, string glueAddresses)
|
||||
{
|
||||
SetGlueRecords(record, glueAddresses.Split(IPAddress.Parse, ','));
|
||||
}
|
||||
|
||||
public static void SetGlueRecords(this DnsResourceRecord record, IReadOnlyList<IPAddress> glueAddresses)
|
||||
{
|
||||
if (record.RDATA is not DnsNSRecordData nsRecord)
|
||||
throw new InvalidOperationException();
|
||||
|
||||
string domain = nsRecord.NameServer;
|
||||
|
||||
DnsResourceRecord[] glueRecords = new DnsResourceRecord[glueAddresses.Count];
|
||||
IReadOnlyList<IPAddress> glueAddressesList = glueAddresses.Split(IPAddress.Parse, ',');
|
||||
DnsResourceRecord[] glueRecords = new DnsResourceRecord[glueAddressesList.Count];
|
||||
|
||||
for (int i = 0; i < glueRecords.Length; i++)
|
||||
{
|
||||
switch (glueAddresses[i].AddressFamily)
|
||||
switch (glueAddressesList[i].AddressFamily)
|
||||
{
|
||||
case AddressFamily.InterNetwork:
|
||||
glueRecords[i] = new DnsResourceRecord(domain, DnsResourceRecordType.A, DnsClass.IN, record.TTL, new DnsARecordData(glueAddresses[i]));
|
||||
glueRecords[i] = new DnsResourceRecord(domain, DnsResourceRecordType.A, DnsClass.IN, record.TTL, new DnsARecordData(glueAddressesList[i]));
|
||||
break;
|
||||
|
||||
case AddressFamily.InterNetworkV6:
|
||||
glueRecords[i] = new DnsResourceRecord(domain, DnsResourceRecordType.AAAA, DnsClass.IN, record.TTL, new DnsAAAARecordData(glueAddresses[i]));
|
||||
glueRecords[i] = new DnsResourceRecord(domain, DnsResourceRecordType.AAAA, DnsClass.IN, record.TTL, new DnsAAAARecordData(glueAddressesList[i]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SetGlueRecords(record, glueRecords);
|
||||
record.GetAuthRecordInfo().GlueRecords = glueRecords;
|
||||
}
|
||||
|
||||
public static void SyncGlueRecords(this DnsResourceRecord record, IReadOnlyList<DnsResourceRecord> allGlueRecords)
|
||||
@@ -94,10 +78,7 @@ namespace DnsServerCore.Dns.ResourceRecords
|
||||
}
|
||||
}
|
||||
|
||||
if (foundGlueRecords.Count > 0)
|
||||
SetGlueRecords(record, foundGlueRecords);
|
||||
else
|
||||
SetGlueRecords(record, Array.Empty<DnsResourceRecord>());
|
||||
record.GetAuthRecordInfo().GlueRecords = foundGlueRecords;
|
||||
}
|
||||
|
||||
public static void SyncGlueRecords(this DnsResourceRecord record, IReadOnlyCollection<DnsResourceRecord> deletedGlueRecords, IReadOnlyCollection<DnsResourceRecord> addedGlueRecords)
|
||||
@@ -108,14 +89,16 @@ namespace DnsServerCore.Dns.ResourceRecords
|
||||
bool updated = false;
|
||||
|
||||
List<DnsResourceRecord> updatedGlueRecords = new List<DnsResourceRecord>();
|
||||
IReadOnlyList<DnsResourceRecord> existingGlueRecords = GetGlueRecords(record);
|
||||
|
||||
foreach (DnsResourceRecord existingGlueRecord in existingGlueRecords)
|
||||
IReadOnlyList<DnsResourceRecord> existingGlueRecords = record.GetAuthRecordInfo().GlueRecords;
|
||||
if (existingGlueRecords is not null)
|
||||
{
|
||||
if (deletedGlueRecords.Contains(existingGlueRecord))
|
||||
updated = true; //skipped to delete existing glue record
|
||||
else
|
||||
updatedGlueRecords.Add(existingGlueRecord);
|
||||
foreach (DnsResourceRecord existingGlueRecord in existingGlueRecords)
|
||||
{
|
||||
if (deletedGlueRecords.Contains(existingGlueRecord))
|
||||
updated = true; //skipped to delete existing glue record
|
||||
else
|
||||
updatedGlueRecords.Add(existingGlueRecord);
|
||||
}
|
||||
}
|
||||
|
||||
string domain = nsRecord.NameServer;
|
||||
@@ -136,121 +119,25 @@ namespace DnsServerCore.Dns.ResourceRecords
|
||||
}
|
||||
|
||||
if (updated)
|
||||
SetGlueRecords(record, updatedGlueRecords);
|
||||
record.GetAuthRecordInfo().GlueRecords = updatedGlueRecords;
|
||||
}
|
||||
|
||||
public static IReadOnlyList<DnsResourceRecord> GetGlueRecords(this DnsResourceRecord record)
|
||||
public static AuthRecordInfo GetAuthRecordInfo(this DnsResourceRecord record)
|
||||
{
|
||||
if (record.Tag is DnsResourceRecordInfo rrInfo)
|
||||
if (record.Tag is not AuthRecordInfo rrInfo)
|
||||
{
|
||||
IReadOnlyList<DnsResourceRecord> glueRecords = rrInfo.GlueRecords;
|
||||
if (glueRecords is null)
|
||||
return Array.Empty<DnsResourceRecord>();
|
||||
|
||||
return glueRecords;
|
||||
}
|
||||
|
||||
return Array.Empty<DnsResourceRecord>();
|
||||
}
|
||||
|
||||
public static bool IsDisabled(this DnsResourceRecord record)
|
||||
{
|
||||
if (record.Tag is DnsResourceRecordInfo rrInfo)
|
||||
return rrInfo.Disabled;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void Disable(this DnsResourceRecord record)
|
||||
{
|
||||
if (record.Tag is not DnsResourceRecordInfo rrInfo)
|
||||
{
|
||||
rrInfo = new DnsResourceRecordInfo();
|
||||
rrInfo = new AuthRecordInfo();
|
||||
record.Tag = rrInfo;
|
||||
}
|
||||
|
||||
rrInfo.Disabled = true;
|
||||
return rrInfo;
|
||||
}
|
||||
|
||||
public static void Enable(this DnsResourceRecord record)
|
||||
public static CacheRecordInfo GetCacheRecordInfo(this DnsResourceRecord record)
|
||||
{
|
||||
if (record.Tag is DnsResourceRecordInfo rrInfo)
|
||||
rrInfo.Disabled = false;
|
||||
}
|
||||
|
||||
public static string GetComments(this DnsResourceRecord record)
|
||||
{
|
||||
if (record.Tag is DnsResourceRecordInfo rrInfo)
|
||||
return rrInfo.Comments;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void SetComments(this DnsResourceRecord record, string value)
|
||||
{
|
||||
if (record.Tag is not DnsResourceRecordInfo rrInfo)
|
||||
if (record.Tag is not CacheRecordInfo rrInfo)
|
||||
{
|
||||
rrInfo = new DnsResourceRecordInfo();
|
||||
record.Tag = rrInfo;
|
||||
}
|
||||
|
||||
rrInfo.Comments = value;
|
||||
}
|
||||
|
||||
public static DateTime GetDeletedOn(this DnsResourceRecord record)
|
||||
{
|
||||
if (record.Tag is DnsResourceRecordInfo rrInfo)
|
||||
return rrInfo.DeletedOn;
|
||||
|
||||
return DateTime.MinValue;
|
||||
}
|
||||
|
||||
public static void SetDeletedOn(this DnsResourceRecord record, DateTime value)
|
||||
{
|
||||
if (record.Tag is not DnsResourceRecordInfo rrInfo)
|
||||
{
|
||||
rrInfo = new DnsResourceRecordInfo();
|
||||
record.Tag = rrInfo;
|
||||
}
|
||||
|
||||
rrInfo.DeletedOn = value;
|
||||
}
|
||||
|
||||
public static void SetPrimaryNameServers(this DnsResourceRecord record, IReadOnlyList<NameServerAddress> primaryNameServers)
|
||||
{
|
||||
if (record.Tag is not DnsResourceRecordInfo rrInfo)
|
||||
{
|
||||
rrInfo = new DnsResourceRecordInfo();
|
||||
record.Tag = rrInfo;
|
||||
}
|
||||
|
||||
rrInfo.PrimaryNameServers = primaryNameServers;
|
||||
}
|
||||
|
||||
public static void SetPrimaryNameServers(this DnsResourceRecord record, string primaryNameServers)
|
||||
{
|
||||
SetPrimaryNameServers(record, primaryNameServers.Split(NameServerAddress.Parse, ','));
|
||||
}
|
||||
|
||||
public static IReadOnlyList<NameServerAddress> GetPrimaryNameServers(this DnsResourceRecord record)
|
||||
{
|
||||
if (record.Tag is DnsResourceRecordInfo rrInfo)
|
||||
{
|
||||
IReadOnlyList<NameServerAddress> primaryNameServers = rrInfo.PrimaryNameServers;
|
||||
if (primaryNameServers is null)
|
||||
return Array.Empty<NameServerAddress>();
|
||||
|
||||
return primaryNameServers;
|
||||
}
|
||||
|
||||
return Array.Empty<NameServerAddress>();
|
||||
}
|
||||
|
||||
public static DnsResourceRecordInfo GetRecordInfo(this DnsResourceRecord record)
|
||||
{
|
||||
if (record.Tag is not DnsResourceRecordInfo rrInfo)
|
||||
{
|
||||
rrInfo = new DnsResourceRecordInfo();
|
||||
rrInfo = new CacheRecordInfo();
|
||||
record.Tag = rrInfo;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user