zone.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. // Copyright (C) 2010 CZ NIC
  2. // Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC")
  3. //
  4. // Permission to use, copy, modify, and/or distribute this software for any
  5. // purpose with or without fee is hereby granted, provided that the above
  6. // copyright notice and this permission notice appear in all copies.
  7. //
  8. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  9. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  10. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  11. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  12. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  13. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  14. // PERFORMANCE OF THIS SOFTWARE.
  15. #ifndef __ZONE_H
  16. #define __ZONE_H 1
  17. #include <datasrc/result.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 ZonePtr, and we want
  53. /// to make them look more intuitive.
  54. class Zone {
  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. Zone() {}
  116. public:
  117. /// The destructor.
  118. virtual ~Zone() {}
  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 const isc::dns::Name& getOrigin() const = 0;
  127. /// Return the RR class of the zone.
  128. virtual const 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 matching name with CNAME, it returns the code of
  149. /// \c CNAME and that CNAME RR.
  150. /// - If the search name matches a delegation point of DNAME, it returns
  151. /// the code of \c DNAME and that DNAME RR.
  152. ///
  153. /// The \c options parameter specifies customized behavior of the search.
  154. /// Their semantics is as follows:
  155. /// - \c GLUE_OK Allow search under a zone cut. By default the search
  156. /// will stop once it encounters a zone cut. If this option is specified
  157. /// it remembers information about the highest zone cut and continues
  158. /// the search until it finds an exact match for the given name or it
  159. /// detects there is no exact match. If an exact match is found,
  160. /// RRsets for that name are searched just like the normal case;
  161. /// otherwise, if the search has encountered a zone cut, \c DELEGATION
  162. /// with the information of the highest zone cut will be returned.
  163. ///
  164. /// A derived version of this method may involve internal resource
  165. /// allocation, especially for constructing the resulting RRset, and may
  166. /// throw an exception if it fails.
  167. /// It should not throw other types of exceptions.
  168. ///
  169. /// Note: It's quite likely that we'll need to specify search options.
  170. /// For example, we should be able to specify whether to allow returning
  171. /// glue records at or under a zone cut. We leave this interface open
  172. /// at this moment.
  173. ///
  174. /// \param name The domain name to be searched for.
  175. /// \param type The RR type to be searched for.
  176. /// \param options The search options.
  177. /// \return A \c FindResult object enclosing the search result (see above).
  178. virtual FindResult find(const isc::dns::Name& name,
  179. const isc::dns::RRType& type,
  180. const FindOptions options
  181. = FIND_DEFAULT) const = 0;
  182. //@}
  183. };
  184. /// \brief A pointer-like type pointing to a \c Zone object.
  185. typedef boost::shared_ptr<Zone> ZonePtr;
  186. /// \brief A pointer-like type pointing to a \c Zone object.
  187. typedef boost::shared_ptr<const Zone> ConstZonePtr;
  188. }
  189. }
  190. #endif // __ZONE_H
  191. // Local Variables:
  192. // mode: c++
  193. // End: