mirror of
https://github.com/fergalmoran/DnsServer.git
synced 2026-03-25 15:00:02 +00:00
StubZone: using GetAllNameServerAddresses() for getting all name server addresses.
This commit is contained in:
@@ -20,7 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
using DnsServerCore.Dns.ResourceRecords;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using TechnitiumLibrary.Net.Dns;
|
||||
using TechnitiumLibrary.Net.Dns.ResourceRecords;
|
||||
@@ -155,56 +154,7 @@ namespace DnsServerCore.Dns.Zones
|
||||
_isExpired = DateTime.UtcNow > _expiry;
|
||||
|
||||
//get all name server addresses
|
||||
List<NameServerAddress> nameServers = new List<NameServerAddress>();
|
||||
|
||||
IReadOnlyList<DnsResourceRecord> nsRecords = _entries[DnsResourceRecordType.NS];
|
||||
|
||||
foreach (DnsResourceRecord nsRecord in nsRecords)
|
||||
{
|
||||
string nsDomain = (nsRecord.RDATA as DnsNSRecord).NameServer;
|
||||
|
||||
IReadOnlyList<DnsResourceRecord> glueRecords = nsRecord.GetGlueRecords();
|
||||
if (glueRecords.Count > 0)
|
||||
{
|
||||
foreach (DnsResourceRecord glueRecord in glueRecords)
|
||||
{
|
||||
switch (glueRecord.Type)
|
||||
{
|
||||
case DnsResourceRecordType.A:
|
||||
nameServers.Add(new NameServerAddress(nsDomain, (glueRecord.RDATA as DnsARecord).Address));
|
||||
break;
|
||||
|
||||
case DnsResourceRecordType.AAAA:
|
||||
if (_dnsServer.PreferIPv6)
|
||||
nameServers.Add(new NameServerAddress(nsDomain, (glueRecord.RDATA as DnsAAAARecord).Address));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//resolve addresses
|
||||
DnsDatagram response = _dnsServer.DirectQuery(new DnsQuestionRecord(nsDomain, DnsResourceRecordType.A, DnsClass.IN));
|
||||
if (response != null)
|
||||
{
|
||||
IReadOnlyList<IPAddress> addresses = DnsClient.ParseResponseA(response);
|
||||
foreach (IPAddress address in addresses)
|
||||
nameServers.Add(new NameServerAddress(nsDomain, address));
|
||||
}
|
||||
|
||||
if (_dnsServer.PreferIPv6)
|
||||
{
|
||||
response = _dnsServer.DirectQuery(new DnsQuestionRecord(nsDomain, DnsResourceRecordType.AAAA, DnsClass.IN));
|
||||
if (response != null)
|
||||
{
|
||||
IReadOnlyList<IPAddress> addresses = DnsClient.ParseResponseAAAA(response);
|
||||
foreach (IPAddress address in addresses)
|
||||
nameServers.Add(new NameServerAddress(nsDomain, address));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
IReadOnlyList<NameServerAddress> nameServers = GetAllNameServerAddresses(_dnsServer, false);
|
||||
|
||||
if (nameServers.Count == 0)
|
||||
{
|
||||
@@ -285,7 +235,7 @@ namespace DnsServerCore.Dns.Zones
|
||||
{
|
||||
LogManager log = _dnsServer.LogManager;
|
||||
if (log != null)
|
||||
log.Write("DNS Server successfully refreshed '" + _name + "' stub zone from: " + soaResponse.Metadata.NameServerAddress.ToString());
|
||||
log.Write("DNS Server successfully checked for update to '" + _name + "' stub zone from: " + soaResponse.Metadata.NameServerAddress.ToString());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user