dns.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. #ifndef ACL_DNS_H
  15. #define ACL_DNS_H 1
  16. #include <string>
  17. #include <vector>
  18. #include <boost/shared_ptr.hpp>
  19. #include <cc/data.h>
  20. #include <acl/ip_check.h>
  21. #include <acl/dnsname_check.h>
  22. #include <acl/loader.h>
  23. namespace isc {
  24. namespace dns {
  25. class TSIGRecord;
  26. }
  27. namespace acl {
  28. namespace dns {
  29. /**
  30. * \brief DNS request to be checked.
  31. *
  32. * This plays the role of Context of the generic template ACLs (in namespace
  33. * isc::acl).
  34. *
  35. * It is a simple structure holding just the bunch of information. Therefore
  36. * the names don't end up with an underscore; there are no methods so they
  37. * can't be confused with local variables.
  38. *
  39. * This structure is generally expected to be ephemeral and read-only: It
  40. * would be constructed immediately before a particular ACL is checked
  41. * and used only for the ACL match purposes. Due to this nature, and since
  42. * ACL processing is often performance sensitive (typically it's performed
  43. * against all incoming packets), the construction is designed to be
  44. * lightweight: it tries to avoid expensive data copies or dynamic memory
  45. * allocation as much as possible. Specifically, the constructor can
  46. * take a pointer or reference to an object and keeps it as a reference
  47. * (not making a local copy). This also means the caller is responsible for
  48. * keeping the passed parameters valid while this structure is used.
  49. * This should generally be reasonable as this structure is expected to be
  50. * used only for a very short period as stated above.
  51. *
  52. * Based on the minimalist philosophy, the initial implementation only
  53. * maintains the remote (source) IP address of the request and (optionally)
  54. * the TSIG record included in the request. We may add more parameters of
  55. * the request as we see the need for them. Possible additional parameters
  56. * are the local (destination) IP address, the remote and local port numbers,
  57. * various fields of the DNS request (e.g. a particular header flag value).
  58. */
  59. struct RequestContext {
  60. /// The constructor
  61. ///
  62. /// This is a trivial constructor that perform straightforward
  63. /// initialization of the member variables from the given parameters.
  64. ///
  65. /// \exception None
  66. ///
  67. /// \param remote_address_param The remote IP address
  68. /// \param tsig_param A valid pointer to the TSIG record included in
  69. /// the request or NULL if the request doesn't contain a TSIG.
  70. RequestContext(const IPAddress& remote_address_param,
  71. const isc::dns::TSIGRecord* tsig_param) :
  72. remote_address(remote_address_param),
  73. tsig(tsig_param)
  74. {}
  75. ///
  76. /// \name Parameter variables
  77. ///
  78. /// These member variables must be immutable so that the integrity of
  79. /// the structure is kept throughout its lifetime. The easiest way is
  80. /// to declare the variable as const. If it's not possible for a
  81. /// particular variable, it must be defined as private and accessible
  82. /// only via an accessor method.
  83. //@{
  84. /// \brief The remote IP address (eg. the client's IP address).
  85. const IPAddress& remote_address;
  86. /// \brief The TSIG record included in the request message, if any.
  87. ///
  88. /// If the request doesn't include a TSIG, this member will be NULL.
  89. const isc::dns::TSIGRecord* const tsig;
  90. //@}
  91. };
  92. /// \brief DNS based check.
  93. typedef acl::Check<RequestContext> RequestCheck;
  94. /// \brief DNS based compound check.
  95. typedef acl::CompoundCheck<RequestContext> CompoundCheck;
  96. /// \brief DNS based ACL.
  97. typedef acl::ACL<RequestContext> RequestACL;
  98. /// \brief DNS based ACL loader.
  99. typedef acl::Loader<RequestContext> RequestLoader;
  100. /**
  101. * \brief Loader singleton access function.
  102. *
  103. * This function returns a loader of ACLs. It is expected applications
  104. * will use this function instead of creating their own loaders, because
  105. * one is enough, this one will have registered default checks and it
  106. * is known one, so any plugins can registrer additional checks as well.
  107. */
  108. RequestLoader& getRequestLoader();
  109. // The following is essentially private to the implementation and could
  110. // be hidden in the implementation file. But it's visible via this header
  111. // file for testing purposes. They are not supposed to be used by normal
  112. // applications directly, and to signal the intent, they are given inside
  113. // a separate namespace.
  114. namespace internal {
  115. // Shortcut typedef
  116. typedef isc::acl::IPCheck<RequestContext> RequestIPCheck;
  117. typedef isc::acl::dns::NameCheck<RequestContext> RequestKeyCheck;
  118. class RequestCheckCreator : public acl::Loader<RequestContext>::CheckCreator {
  119. public:
  120. virtual std::vector<std::string> names() const;
  121. virtual boost::shared_ptr<RequestCheck>
  122. create(const std::string& name, isc::data::ConstElementPtr definition,
  123. const acl::Loader<RequestContext>& loader);
  124. };
  125. } // end of namespace "internal"
  126. } // end of namespace "dns"
  127. } // end of namespace "acl"
  128. } // end of namespace "isc"
  129. #endif
  130. // Local Variables:
  131. // mode: c++
  132. // End: