ResolverPrefetchDnsCache.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 TechnitiumLibrary.Net.Dns;
  16. namespace DnsServerCore.Dns
  17. {
  18. class ResolverPrefetchDnsCache : ResolverDnsCache
  19. {
  20. #region variables
  21. readonly DnsQuestionRecord _prefetchQuestion;
  22. #endregion
  23. #region constructor
  24. public ResolverPrefetchDnsCache(DnsServer dnsServer, bool skipDnsAppAuthoritativeRequestHandlers, DnsQuestionRecord prefetchQuestion)
  25. : base(dnsServer, skipDnsAppAuthoritativeRequestHandlers)
  26. {
  27. _prefetchQuestion = prefetchQuestion;
  28. }
  29. #endregion
  30. #region public
  31. public override DnsDatagram Query(DnsDatagram request, bool serveStale = false, bool findClosestNameServers = false, bool resetExpiry = false)
  32. {
  33. if (_prefetchQuestion.Equals(request.Question[0]))
  34. {
  35. //request is for prefetch question
  36. if (!findClosestNameServers)
  37. return null; //dont give answer from cache for prefetch question
  38. //return closest name servers so that the recursive resolver queries them to refreshes cache instead of returning response from cache
  39. return QueryClosestDelegation(request);
  40. }
  41. return base.Query(request, serveStale, findClosestNameServers, resetExpiry);
  42. }
  43. #endregion
  44. }
  45. }