mirror of
https://github.com/fergalmoran/DnsServer.git
synced 2026-02-24 00:37:08 +00:00
DnsServer: updated code to implement AuthZoneManager, CacheZoneManager and BlockListZoneManager. Implemented new recursive resolver code using wait handles to fix thread contention issues. Removed doh-servers-associated json response support. Changed zone processing sequence to auth, allowed, blocked, blocklist, and finally recursive. Implemented CNAME cloaking checks. Code refactoring done.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
Technitium DNS Server
|
||||
Copyright (C) 2019 Shreyas Zare (shreyas@technitium.com)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using TechnitiumLibrary.Net.Dns;
|
||||
|
||||
namespace DnsServerCore.Dns
|
||||
{
|
||||
class ResolverDnsCache : DnsCache
|
||||
{
|
||||
#region variables
|
||||
|
||||
const uint NEGATIVE_RECORD_TTL = 300u;
|
||||
const uint MINIMUM_RECORD_TTL = 10u;
|
||||
const uint SERVE_STALE_TTL = 7 * 24 * 60 * 60; //7 days serve stale ttl as per draft-ietf-dnsop-serve-stale-04
|
||||
|
||||
readonly protected Zone _cacheZoneRoot;
|
||||
|
||||
#endregion
|
||||
|
||||
#region constructor
|
||||
|
||||
public ResolverDnsCache(Zone cacheZoneRoot)
|
||||
: base(NEGATIVE_RECORD_TTL, MINIMUM_RECORD_TTL, SERVE_STALE_TTL)
|
||||
{
|
||||
_cacheZoneRoot = cacheZoneRoot;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public
|
||||
|
||||
public override DnsDatagram Query(DnsDatagram request)
|
||||
{
|
||||
return _cacheZoneRoot.Query(request);
|
||||
}
|
||||
|
||||
protected override void CacheRecords(ICollection<DnsResourceRecord> resourceRecords)
|
||||
{
|
||||
_cacheZoneRoot.SetRecords(resourceRecords);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Technitium DNS Server
|
||||
Copyright (C) 2019 Shreyas Zare (shreyas@technitium.com)
|
||||
Copyright (C) 2020 Shreyas Zare (shreyas@technitium.com)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -17,23 +17,25 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
using DnsServerCore.Dns.Zones;
|
||||
using TechnitiumLibrary.Net.Dns;
|
||||
|
||||
namespace DnsServerCore.Dns
|
||||
{
|
||||
class ResolverPrefetchDnsCache : ResolverDnsCache
|
||||
class ResolverPrefetchDnsCache : IDnsCache
|
||||
{
|
||||
#region variables
|
||||
|
||||
readonly CacheZoneManager _cacheZoneManager;
|
||||
readonly DnsQuestionRecord _prefetchQuery;
|
||||
|
||||
#endregion
|
||||
|
||||
#region constructor
|
||||
|
||||
public ResolverPrefetchDnsCache(Zone cacheZoneRoot, DnsQuestionRecord prefetchQuery)
|
||||
: base(cacheZoneRoot)
|
||||
public ResolverPrefetchDnsCache(CacheZoneManager cacheZoneManager, DnsQuestionRecord prefetchQuery)
|
||||
{
|
||||
_cacheZoneManager = cacheZoneManager;
|
||||
_prefetchQuery = prefetchQuery;
|
||||
}
|
||||
|
||||
@@ -41,12 +43,20 @@ namespace DnsServerCore.Dns
|
||||
|
||||
#region public
|
||||
|
||||
public override DnsDatagram Query(DnsDatagram request)
|
||||
public DnsDatagram Query(DnsDatagram request, bool serveStale = false)
|
||||
{
|
||||
if (_prefetchQuery.Equals(request.Question[0]))
|
||||
return _cacheZoneRoot.QueryCacheGetClosestNameServers(request); //return closest name servers so that the recursive resolver queries them to refreshes cache instead of returning response from cache
|
||||
{
|
||||
//return closest name servers so that the recursive resolver queries them to refreshes cache instead of returning response from cache
|
||||
return _cacheZoneManager.QueryClosestDelegation(request);
|
||||
}
|
||||
|
||||
return _cacheZoneRoot.Query(request);
|
||||
return _cacheZoneManager.Query(request, serveStale);
|
||||
}
|
||||
|
||||
public void CacheResponse(DnsDatagram response)
|
||||
{
|
||||
_cacheZoneManager.CacheResponse(response);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Technitium DNS Server
|
||||
Copyright (C) 2019 Shreyas Zare (shreyas@technitium.com)
|
||||
Copyright (C) 2020 Shreyas Zare (shreyas@technitium.com)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -17,39 +17,33 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
using System.Threading;
|
||||
using TechnitiumLibrary.Net.Dns;
|
||||
|
||||
namespace DnsServerCore.Dns
|
||||
{
|
||||
class RecursiveQueryLock
|
||||
class ResolverQueryHandle
|
||||
{
|
||||
#region variables
|
||||
|
||||
bool _complete;
|
||||
DnsDatagram _response;
|
||||
readonly EventWaitHandle _waitHandle = new ManualResetEvent(false);
|
||||
|
||||
#endregion
|
||||
|
||||
#region public
|
||||
|
||||
public void SetComplete(DnsDatagram response)
|
||||
public void Set(DnsDatagram response)
|
||||
{
|
||||
if (!_complete)
|
||||
{
|
||||
_complete = true;
|
||||
_response = response;
|
||||
}
|
||||
_response = response;
|
||||
_waitHandle.Set();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region properties
|
||||
|
||||
public bool Complete
|
||||
{ get { return _complete; } }
|
||||
|
||||
public DnsDatagram Response
|
||||
{ get { return _response; } }
|
||||
public DnsDatagram WaitForResponse(int timeout)
|
||||
{
|
||||
_waitHandle.WaitOne(timeout);
|
||||
return _response;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user