message_utility.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. // $Id$
  15. #ifndef MESSAGE_UTILITY_H
  16. #define MESSAGE_UTILITY_H
  17. #include <dns/message.h>
  18. namespace isc {
  19. namespace cache {
  20. /// \brief Some utility functions to extract info from message
  21. ///
  22. /// We need to check the message before cache it, for example, if no SOA
  23. /// record is found in the Authority section of NXDOMAIN response, the
  24. /// message cannot be cached
  25. namespace MessageUtility{
  26. /// \brief Check whether there is some type of record in
  27. /// Authority section
  28. ///
  29. /// \param msg The response message to be checked
  30. /// \param type The RR type that need to check
  31. bool hasTheRecordInAuthoritySection(const isc::dns::Message& msg,
  32. const isc::dns::RRType& type);
  33. /// \brief Check whetehr the message is a negative response
  34. /// (NXDOMAIN or NOERROR_NODATA)
  35. ///
  36. /// \param msg The response message
  37. bool isNegativeResponse(const isc::dns::Message& msg);
  38. /// \brief Check whether the message can be cached
  39. /// Negative responses without SOA records SHOULD NOT be cached as there
  40. /// is no way to prevent the negative responses looping forever between a
  41. /// pair of servers even with a short TTL.
  42. /// Despite the DNS forming a tree of servers, with various mis-
  43. /// configurations it is possible to form a loop in the query graph, e.g.
  44. /// two servers listing each other as forwarders, various lame server
  45. /// configurations. Without a TTL count down a cache negative response
  46. /// when received by the next server would have its TTL reset. This
  47. /// negative indication could then live forever circulating between the
  48. /// servers involved. (Sec 5, RFC2308)
  49. ///
  50. /// \param msg The response message
  51. bool canMessageBeCached(const isc::dns::Message& msg);
  52. } // namespace MessageUtility
  53. } // namespace cache
  54. } // namespace isc
  55. #endif//MESSAGE_UTILITY_H