zone.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. // Copyright (C) 2010 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 __ZONE_H
  15. #define __ZONE_H 1
  16. #include <datasrc/result.h>
  17. #include <dns/rrsetlist.h>
  18. namespace isc {
  19. namespace datasrc {
  20. /// \brief The base class for a single authoritative zone
  21. ///
  22. /// The \c Zone class is an abstract base class for representing
  23. /// a DNS zone as part of data source.
  24. ///
  25. /// At the moment this is provided mainly for making the \c ZoneTable class
  26. /// and the authoritative query logic testable, and only provides a minimal
  27. /// set of features.
  28. /// This is why this class is defined in the same header file, but it may
  29. /// have to move to a separate header file when we understand what is
  30. /// necessary for this class for actual operation.
  31. ///
  32. /// The idea is to provide a specific derived zone class for each data
  33. /// source, beginning with in memory one. At that point the derived classes
  34. /// will have more specific features. For example, they will maintain
  35. /// information about the location of a zone file, whether it's loaded in
  36. /// memory, etc.
  37. ///
  38. /// It's not yet clear how the derived zone classes work with various other
  39. /// data sources when we integrate these components, but one possibility is
  40. /// something like this:
  41. /// - If the underlying database such as some variant of SQL doesn't have an
  42. /// explicit representation of zones (as part of public interface), we can
  43. /// probably use a "default" zone class that simply encapsulates the
  44. /// corresponding data source and calls a common "find" like method.
  45. /// - Some data source may want to specialize it by inheritance as an
  46. /// optimization. For example, in the current schema design of the sqlite3
  47. /// data source, its (derived) zone class would contain the information of
  48. /// the "zone ID".
  49. ///
  50. /// <b>Note:</b> Unlike some other abstract base classes we don't name the
  51. /// class beginning with "Abstract". This is because we want to have
  52. /// commonly used definitions such as \c Result and \c ZoneFinderPtr, and we
  53. /// want to make them look more intuitive.
  54. class ZoneFinder {
  55. public:
  56. /// Result codes of the \c find() method.
  57. ///
  58. /// Note: the codes are tentative. We may need more, or we may find
  59. /// some of them unnecessary as we implement more details.
  60. enum Result {
  61. SUCCESS, ///< An exact match is found.
  62. DELEGATION, ///< The search encounters a zone cut.
  63. NXDOMAIN, ///< There is no domain name that matches the search name
  64. NXRRSET, ///< There is a matching name but no RRset of the search type
  65. CNAME, ///< The search encounters and returns a CNAME RR
  66. DNAME ///< The search encounters and returns a DNAME RR
  67. };
  68. /// A helper structure to represent the search result of \c find().
  69. ///
  70. /// This is a straightforward tuple of the result code and a pointer
  71. /// to the found RRset to represent the result of \c find()
  72. /// (there will be more members in the future - see the class
  73. /// description).
  74. /// We use this in order to avoid overloading the return value for both
  75. /// the result code ("success" or "not found") and the found object,
  76. /// i.e., avoid using \c NULL to mean "not found", etc.
  77. ///
  78. /// This is a simple value class whose internal state never changes,
  79. /// so for convenience we allow the applications to refer to the members
  80. /// directly.
  81. ///
  82. /// Note: we should eventually include a notion of "zone node", which
  83. /// corresponds to a particular domain name of the zone, so that we can
  84. /// find RRsets of a different RR type for that name (e.g. for type ANY
  85. /// query or to include DS RRs with delegation).
  86. ///
  87. /// Note: we may also want to include the closest enclosure "node" to
  88. /// optimize including the NSEC for no-wildcard proof (FWIW NSD does that).
  89. struct FindResult {
  90. FindResult(Result param_code,
  91. const isc::dns::ConstRRsetPtr param_rrset) :
  92. code(param_code), rrset(param_rrset)
  93. {}
  94. const Result code;
  95. const isc::dns::ConstRRsetPtr rrset;
  96. };
  97. /// Find options.
  98. ///
  99. /// The option values are used as a parameter for \c find().
  100. /// These are values of a bitmask type. Bitwise operations can be
  101. /// performed on these values to express compound options.
  102. enum FindOptions {
  103. FIND_DEFAULT = 0, ///< The default options
  104. FIND_GLUE_OK = 1 ///< Allow search under a zone cut
  105. };
  106. ///
  107. /// \name Constructors and Destructor.
  108. ///
  109. //@{
  110. protected:
  111. /// The default constructor.
  112. ///
  113. /// This is intentionally defined as \c protected as this base class should
  114. /// never be instantiated (except as part of a derived class).
  115. ZoneFinder() {}
  116. public:
  117. /// The destructor.
  118. virtual ~ZoneFinder() {}
  119. //@}
  120. ///
  121. /// \name Getter Methods
  122. ///
  123. /// These methods should never throw an exception.
  124. //@{
  125. /// Return the origin name of the zone.
  126. virtual isc::dns::Name getOrigin() const = 0;
  127. /// Return the RR class of the zone.
  128. virtual isc::dns::RRClass getClass() const = 0;
  129. //@}
  130. ///
  131. /// \name Search Method
  132. ///
  133. //@{
  134. /// Search the zone for a given pair of domain name and RR type.
  135. ///
  136. /// Each derived version of this method searches the underlying backend
  137. /// for the data that best matches the given name and type.
  138. /// This method is expected to be "intelligent", and identifies the
  139. /// best possible answer for the search key. Specifically,
  140. /// - If the search name belongs under a zone cut, it returns the code
  141. /// of \c DELEGATION and the NS RRset at the zone cut.
  142. /// - If there is no matching name, it returns the code of \c NXDOMAIN,
  143. /// and, if DNSSEC is requested, the NSEC RRset that proves the
  144. /// non-existence.
  145. /// - If there is a matching name but no RRset of the search type, it
  146. /// returns the code of \c NXRRSET, and, if DNSSEC is required,
  147. /// the NSEC RRset for that name.
  148. /// - If there is a CNAME RR of the searched name but there is no
  149. /// RR of the searched type of the name (so this type is different from
  150. /// CNAME), it returns the code of \c CNAME and that CNAME RR.
  151. /// Note that if the searched RR type is CNAME, it is considered
  152. /// a successful match, and the code of \c SUCCESS will be returned.
  153. /// - If the search name matches a delegation point of DNAME, it returns
  154. /// the code of \c DNAME and that DNAME RR.
  155. /// - If the target isn't NULL, all RRsets under the domain are inserted
  156. /// there and SUCCESS (or NXDOMAIN, in case of empty domain) is returned
  157. /// instead of normall processing. This is intended to handle ANY query.
  158. /// \note: this behavior is controversial as we discussed in
  159. /// https://lists.isc.org/pipermail/bind10-dev/2011-January/001918.html
  160. /// We should revisit the interface before we heavily rely on it.
  161. ///
  162. /// The \c options parameter specifies customized behavior of the search.
  163. /// Their semantics is as follows:
  164. /// - \c GLUE_OK Allow search under a zone cut. By default the search
  165. /// will stop once it encounters a zone cut. If this option is specified
  166. /// it remembers information about the highest zone cut and continues
  167. /// the search until it finds an exact match for the given name or it
  168. /// detects there is no exact match. If an exact match is found,
  169. /// RRsets for that name are searched just like the normal case;
  170. /// otherwise, if the search has encountered a zone cut, \c DELEGATION
  171. /// with the information of the highest zone cut will be returned.
  172. ///
  173. /// A derived version of this method may involve internal resource
  174. /// allocation, especially for constructing the resulting RRset, and may
  175. /// throw an exception if it fails.
  176. /// It throws DuplicateRRset exception if there are duplicate rrsets under
  177. /// the same domain.
  178. /// It should not throw other types of exceptions.
  179. ///
  180. /// \param name The domain name to be searched for.
  181. /// \param type The RR type to be searched for.
  182. /// \param target If target is not NULL, insert all RRs under the domain
  183. /// into it.
  184. /// \param options The search options.
  185. /// \return A \c FindResult object enclosing the search result (see above).
  186. virtual FindResult find(const isc::dns::Name& name,
  187. const isc::dns::RRType& type,
  188. isc::dns::RRsetList* target = NULL,
  189. const FindOptions options
  190. = FIND_DEFAULT) const = 0;
  191. //@}
  192. };
  193. /// \brief A pointer-like type pointing to a \c ZoneFinder object.
  194. typedef boost::shared_ptr<ZoneFinder> ZoneFinderPtr;
  195. /// \brief A pointer-like type pointing to a \c ZoneFinder object.
  196. typedef boost::shared_ptr<const ZoneFinder> ConstZoneFinderPtr;
  197. }
  198. }
  199. #endif // __ZONE_H
  200. // Local Variables:
  201. // mode: c++
  202. // End: