dns.h 5.3 KB

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