zone.h 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  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 <utility>
  17. #include <vector>
  18. #include <dns/rrset.h>
  19. #include <dns/rrsetlist.h>
  20. #include <datasrc/result.h>
  21. namespace isc {
  22. namespace datasrc {
  23. /// \brief The base class to search a zone for RRsets
  24. ///
  25. /// The \c ZoneFinder class is an abstract base class for representing
  26. /// an object that performs DNS lookups in a specific zone accessible via
  27. /// a data source. In general, different types of data sources (in-memory,
  28. /// database-based, etc) define their own derived classes of \c ZoneFinder,
  29. /// implementing ways to retrieve the required data through the common
  30. /// interfaces declared in the base class. Each concrete \c ZoneFinder
  31. /// object is therefore (conceptually) associated with a specific zone
  32. /// of one specific data source instance.
  33. ///
  34. /// The origin name and the RR class of the associated zone are available
  35. /// via the \c getOrigin() and \c getClass() methods, respectively.
  36. ///
  37. /// The most important method of this class is \c find(), which performs
  38. /// the lookup for a given domain and type. See the description of the
  39. /// method for details.
  40. ///
  41. /// \note It's not clear whether we should request that a zone finder form a
  42. /// "transaction", that is, whether to ensure the finder is not susceptible
  43. /// to changes made by someone else than the creator of the finder. If we
  44. /// don't request that, for example, two different lookup results for the
  45. /// same name and type can be different if other threads or programs make
  46. /// updates to the zone between the lookups. We should revisit this point
  47. /// as we gain more experiences.
  48. class ZoneFinder {
  49. public:
  50. /// Result codes of the \c find() method.
  51. ///
  52. /// Note: the codes are tentative. We may need more, or we may find
  53. /// some of them unnecessary as we implement more details.
  54. ///
  55. /// Some are synonyms of others in terms of RCODE returned to user.
  56. /// But they help the logic to decide if it should ask for a NSEC
  57. /// that covers something or not (for example, in case of NXRRSET,
  58. /// the directly returned NSEC is sufficient, but with wildcard one,
  59. /// we need to add one proving there's no exact match and this is
  60. /// actually the best wildcard we have). Data sources that don't
  61. /// support DNSSEC don't need to distinguish them.
  62. ///
  63. /// In case of CNAME, if the CNAME is a wildcard (i.e., its owner name
  64. /// starts with the label "*"), WILDCARD_CNAME will be returned instead
  65. /// of CNAME.
  66. ///
  67. /// In case of NXDOMAIN, the returned NSEC covers the queried domain
  68. /// that proves that the query name does not exist in the zone. Note that
  69. /// this does not necessarily prove it doesn't even match a wildcard
  70. /// (even if the result of NXDOMAIN can only happen when there's no
  71. /// matching wildcard either). It is caller's responsibility to provide
  72. /// a proof that there is no matching wildcard if that proof is necessary.
  73. ///
  74. /// Various variants of "no data" cases are complicated, when involves
  75. /// DNSSEC and wildcard processing. Referring to Section 3.1.3 of
  76. /// RFC4035, we need to consider the following cases:
  77. /// -# (Normal) no data: there is a matching non-wildcard name with a
  78. /// different RR type. This is the "No Data" case of the RFC.
  79. /// -# (Normal) empty non terminal: there is no matching (exact or
  80. /// wildcard) name, but there is a subdomain with an RR of the query
  81. /// name. This is one case of "Name Error" of the RFC.
  82. /// -# Wildcard empty non terminal: similar to 2a, but the empty name
  83. /// is a wildcard, and matches the query name by wildcard expansion.
  84. /// This is a special case of "Name Error" of the RFC.
  85. /// -# Wildcard no data: there is no exact match name, but there is a
  86. /// wildcard name that matches the query name with a different type
  87. /// of RR. This is the "Wildcard No Data" case of the RFC.
  88. ///
  89. /// In any case, \c find() will result in \c NXRRSET with no RRset
  90. /// unless the \c FIND_DNSSEC option is specified. The rest of the
  91. /// discussion only applies to the case where this option is specified.
  92. ///
  93. /// In case 1, \c find() will result in NXRRSET, and return NSEC of the
  94. /// matching name.
  95. ///
  96. /// In case 2, \c find() will result in NXRRSET, and return NSEC for the
  97. /// interval where the empty nonterminal lives. The end of the interval
  98. /// is the subdomain causing existence of the empty nonterminal (if
  99. /// there's sub.x.example.com, and no record in x.example.com, then
  100. /// x.example.com exists implicitly - is the empty nonterminal and
  101. /// sub.x.example.com is the subdomain causing it). Note that this NSEC
  102. /// proves not only the existence of empty non terminal name but also
  103. /// the non existence of possibly matching wildcard name, because
  104. /// there can be no better wildcard match than the exact matching empty
  105. /// name.
  106. ///
  107. /// In case 3, \c find() will result in WILDCARD_NXRRSET, and return NSEC
  108. /// for the interval where the wildcard empty nonterminal lives.
  109. /// Cases 2 and 3 are especially complicated and confusing. See the
  110. /// examples below.
  111. ///
  112. /// In case 4, \c find() will result in WILDCARD_NXRRSET, and return
  113. /// NSEC of the matching wildcard name.
  114. ///
  115. /// Examples: if zone "example.com" has the following record:
  116. /// \code
  117. /// a.example.com. NSEC a.b.example.com.
  118. /// \endcode
  119. /// a call to \c find() for "b.example.com." with the FIND_DNSSEC option
  120. /// will result in NXRRSET, and this NSEC will be returned.
  121. /// Likewise, if zone "example.org" has the following record,
  122. /// \code
  123. /// a.example.org. NSEC x.*.b.example.org.
  124. /// \endcode
  125. /// a call to \c find() for "y.b.example.org" with FIND_DNSSEC will
  126. /// result in NXRRSET_NXRRSET, and this NSEC will be returned.
  127. enum Result {
  128. SUCCESS, ///< An exact match is found.
  129. DELEGATION, ///< The search encounters a zone cut.
  130. NXDOMAIN, ///< There is no domain name that matches the search name
  131. NXRRSET, ///< There is a matching name but no RRset of the search type
  132. CNAME, ///< The search encounters and returns a CNAME RR
  133. DNAME, ///< The search encounters and returns a DNAME RR
  134. WILDCARD, ///< Succes by wildcard match, for DNSSEC
  135. WILDCARD_CNAME, ///< CNAME on wildcard, search returns CNAME, for DNSSEC
  136. WILDCARD_NXRRSET ///< NXRRSET on wildcard, for DNSSEC
  137. };
  138. /// Special attribute flags on the result of the \c find() method
  139. ///
  140. /// The flag values defined here are intended to signal to the caller
  141. /// that it may need special handling on the result. This is particularly
  142. /// of concern when DNSSEC is requested. For example, for negative
  143. /// responses the caller would want to know whether the zone is signed
  144. /// with NSEC or NSEC3 so that it can subsequently provide necessary
  145. /// proof of the result.
  146. ///
  147. /// The caller is generally expected to get access to the information
  148. /// via read-only getter methods of \c FindResult so that it won't rely
  149. /// on specific details of the representation of the flags. So these
  150. /// definitions are basically only meaningful for data source
  151. /// implementations.
  152. enum FindResultFlags {
  153. RESULT_DEFAULT = 0, ///< The default flags
  154. RESULT_WILDCARD = 1, ///< find() resulted in a wildcard match
  155. RESULT_NSEC_SIGNED = 2, ///< The zone is signed with NSEC RRs
  156. RESULT_NSEC3_SIGNED = 4 ///< The zone is signed with NSEC3 RRs
  157. };
  158. /// A helper structure to represent the search result of \c find().
  159. ///
  160. /// This is a straightforward tuple of the result code and a pointer
  161. /// (and optionally special flags) to the found RRset to represent the
  162. /// result of \c find() (there will be more members in the future -
  163. /// see the class description).
  164. /// We use this in order to avoid overloading the return value for both
  165. /// the result code ("success" or "not found") and the found object,
  166. /// i.e., avoid using \c NULL to mean "not found", etc.
  167. ///
  168. /// This is a simple value class whose internal state never changes,
  169. /// so for convenience we allow the applications to refer to some of the
  170. /// members directly. For others we provide read-only accessor methods
  171. /// to hide specific representation.
  172. ///
  173. /// Note: we should eventually include a notion of "zone node", which
  174. /// corresponds to a particular domain name of the zone, so that we can
  175. /// find RRsets of a different RR type for that name (e.g. for type ANY
  176. /// query or to include DS RRs with delegation).
  177. ///
  178. /// Note: we may also want to include the closest enclosure "node" to
  179. /// optimize including the NSEC for no-wildcard proof (FWIW NSD does that).
  180. struct FindResult {
  181. FindResult(Result param_code,
  182. const isc::dns::ConstRRsetPtr param_rrset,
  183. FindResultFlags param_flags = RESULT_DEFAULT) :
  184. code(param_code), rrset(param_rrset), flags(param_flags)
  185. {}
  186. const Result code;
  187. const isc::dns::ConstRRsetPtr rrset;
  188. /// Return true iff find() results in a wildcard match.
  189. bool isWildcard() const { return ((flags & RESULT_WILDCARD) != 0); }
  190. /// Return true when the underlying zone is signed with NSEC.
  191. ///
  192. /// The \c find() implementation allow this to return false if
  193. /// \c FIND_DNSSEC isn't specified regardless of whether the zone
  194. /// is signed or which of NSEC/NSEC3 is used.
  195. ///
  196. /// When this is returned, the implementation of find() must ensure
  197. /// that \c rrset be a valid NSEC RRset as described in \c find()
  198. /// documentation.
  199. bool isNSECSigned() const {
  200. return ((flags & RESULT_NSEC_SIGNED) != 0);
  201. }
  202. /// Return true when the underlying zone is signed with NSEC3.
  203. ///
  204. /// The \c find() implementation allow this to return false if
  205. /// \c FIND_DNSSEC isn't specified regardless of whether the zone
  206. /// is signed or which of NSEC/NSEC3 is used.
  207. bool isNSEC3Signed() const {
  208. return ((flags & RESULT_NSEC3_SIGNED) != 0);
  209. }
  210. private:
  211. FindResultFlags flags;
  212. };
  213. /// Find options.
  214. ///
  215. /// The option values are used as a parameter for \c find().
  216. /// These are values of a bitmask type. Bitwise operations can be
  217. /// performed on these values to express compound options.
  218. enum FindOptions {
  219. FIND_DEFAULT = 0, ///< The default options
  220. FIND_GLUE_OK = 1, ///< Allow search under a zone cut
  221. FIND_DNSSEC = 2, ///< Require DNSSEC data in the answer
  222. ///< (RRSIG, NSEC, etc.). The implementation
  223. ///< is allowed to include it even if it is
  224. ///< not set.
  225. NO_WILDCARD = 4 ///< Do not try wildcard matching.
  226. };
  227. ///
  228. /// \name Constructors and Destructor.
  229. ///
  230. //@{
  231. protected:
  232. /// The default constructor.
  233. ///
  234. /// This is intentionally defined as \c protected as this base class should
  235. /// never be instantiated (except as part of a derived class).
  236. ZoneFinder() {}
  237. public:
  238. /// The destructor.
  239. virtual ~ZoneFinder() {}
  240. //@}
  241. ///
  242. /// \name Getter Methods
  243. ///
  244. /// These methods should never throw an exception.
  245. //@{
  246. /// Return the origin name of the zone.
  247. virtual isc::dns::Name getOrigin() const = 0;
  248. /// Return the RR class of the zone.
  249. virtual isc::dns::RRClass getClass() const = 0;
  250. //@}
  251. ///
  252. /// \name Search Methods
  253. ///
  254. //@{
  255. /// Search the zone for a given pair of domain name and RR type.
  256. ///
  257. /// Each derived version of this method searches the underlying backend
  258. /// for the data that best matches the given name and type.
  259. /// This method is expected to be "intelligent", and identifies the
  260. /// best possible answer for the search key. Specifically,
  261. ///
  262. /// - If the search name belongs under a zone cut, it returns the code
  263. /// of \c DELEGATION and the NS RRset at the zone cut.
  264. /// - If there is no matching name, it returns the code of \c NXDOMAIN,
  265. /// and, if DNSSEC is requested, the NSEC RRset that proves the
  266. /// non-existence if the zone is signed with NSEC; if it's signed with
  267. /// NSEC3, an empty NSEC3 RRset (an RRset that doesn't have RDATA)
  268. /// whose name is the closest encloser of the given name.
  269. /// - If there is a matching name but no RRset of the search type, it
  270. /// returns the code of \c NXRRSET, and, if DNSSEC is required,
  271. /// the NSEC RRset for that name if the zone is signed with NSEC;
  272. /// if it's signed with NSEC3, an empty NSEC3 RRset whose name is the
  273. /// given name.
  274. /// - If there is no matching name but there is a matching wild card name,
  275. /// but it doesn't have a requested type of RR, and if DNSSEC is
  276. /// required, then it returns the code of \c WILDCARD_NXRRSET.
  277. /// If the zone is signed with NSEC, it returns corresponding NSEC
  278. /// (see the description of \c Result); if it's signed with NSEC3,
  279. /// it returns an empty NSEC3 RRset whose name is the matching wildcard.
  280. /// - If there is a CNAME RR of the searched name but there is no
  281. /// RR of the searched type of the name (so this type is different from
  282. /// CNAME), it returns the code of \c CNAME and that CNAME RR.
  283. /// Note that if the searched RR type is CNAME, it is considered
  284. /// a successful match, and the code of \c SUCCESS will be returned.
  285. /// - If the search name matches a delegation point of DNAME, it returns
  286. /// the code of \c DNAME and that DNAME RR.
  287. ///
  288. /// The \c options parameter specifies customized behavior of the search.
  289. /// Their semantics is as follows (they are or bit-field):
  290. ///
  291. /// - \c FIND_GLUE_OK Allow search under a zone cut. By default the search
  292. /// will stop once it encounters a zone cut. If this option is specified
  293. /// it remembers information about the highest zone cut and continues
  294. /// the search until it finds an exact match for the given name or it
  295. /// detects there is no exact match. If an exact match is found,
  296. /// RRsets for that name are searched just like the normal case;
  297. /// otherwise, if the search has encountered a zone cut, \c DELEGATION
  298. /// with the information of the highest zone cut will be returned.
  299. /// - \c FIND_DNSSEC Request that DNSSEC data (like NSEC, RRSIGs) are
  300. /// returned with the answer. It is allowed for the data source to
  301. /// include them even when not requested.
  302. /// - \c NO_WILDCARD Do not try wildcard matching. This option is of no
  303. /// use for normal lookups; it's intended to be used to get a DNSSEC
  304. /// proof of the non existence of any matching wildcard or non existence
  305. /// of an exact match when a wildcard match is found.
  306. ///
  307. /// In general, \c name is expected to be included in the zone, that is,
  308. /// it should be equal to or a subdomain of the zone origin. Otherwise
  309. /// this method will return \c NXDOMAIN with an empty RRset. But such a
  310. /// case should rather be considered a caller's bug.
  311. ///
  312. /// \note For this reason it's probably better to throw an exception
  313. /// than returning \c NXDOMAIN. This point should be revisited in a near
  314. /// future version. In any case applications shouldn't call this method
  315. /// for an out-of-zone name.
  316. ///
  317. /// \exception std::bad_alloc Memory allocation such as for constructing
  318. /// the resulting RRset fails
  319. /// \exception DataSourceError Derived class specific exception, e.g.
  320. /// when encountering a bad zone configuration or database connection
  321. /// failure. Although these are considered rare, exceptional events,
  322. /// it can happen under relatively usual conditions (unlike memory
  323. /// allocation failure). So, in general, the application is expected
  324. /// to catch this exception, either specifically or as a result of
  325. /// catching a base exception class, and handle it gracefully.
  326. ///
  327. /// \param name The domain name to be searched for.
  328. /// \param type The RR type to be searched for.
  329. /// \param options The search options.
  330. /// \return A \c FindResult object enclosing the search result (see above).
  331. virtual FindResult find(const isc::dns::Name& name,
  332. const isc::dns::RRType& type,
  333. const FindOptions options
  334. = FIND_DEFAULT) = 0;
  335. ///
  336. /// \brief Finds all RRsets in the given name.
  337. ///
  338. /// This function works almost exactly in the same way as the find one. The
  339. /// only difference is, when the lookup is successful (eg. the code is
  340. /// SUCCESS or WILDCARD), all the RRsets residing in the named node are
  341. /// copied into the \c target parameter and the rrset member of the result
  342. /// is NULL. All the other (unsuccessful) cases are handled the same,
  343. /// including returning delegations, NSEC/NSEC3 proofs, etc. The options
  344. /// parameter works the same way and it should conform to the same exception
  345. /// restrictions.
  346. ///
  347. /// \param name \see find, parameter name
  348. /// \param target the successfull result is returned through this
  349. /// \param options \see find, parameter options
  350. /// \return \see find and it's result
  351. virtual FindResult findAll(const isc::dns::Name& name,
  352. std::vector<isc::dns::ConstRRsetPtr> &target,
  353. const FindOptions options = FIND_DEFAULT) = 0;
  354. /// A helper structure to represent the search result of \c findNSEC3().
  355. ///
  356. /// The idea is similar to that of \c FindResult, but \c findNSEC3() has
  357. /// special interface and semantics, we use a different structure to
  358. /// represent the result.
  359. struct FindNSEC3Result {
  360. FindNSEC3Result(bool param_matched,
  361. isc::dns::ConstRRsetPtr param_closest_proof,
  362. isc::dns::ConstRRsetPtr param_next_proof) :
  363. matched(param_matched), closest_proof(param_closest_proof),
  364. next_proof(param_next_proof)
  365. {}
  366. /// true iff closest_proof is a matching NSEC3
  367. const bool matched;
  368. /// Either the NSEC3 for the closest provable encloser of the given
  369. /// name or NSEC3 that covers the name
  370. const isc::dns::ConstRRsetPtr closest_proof;
  371. /// When non NULL, NSEC3 for the next closer name.
  372. const isc::dns::ConstRRsetPtr next_proof;
  373. };
  374. /// Search the zone for the NSEC3 RR(s) that prove existence or non
  375. /// existence of a give name.
  376. ///
  377. /// It searches the NSEC3 namespace of the zone (how that namespace is
  378. /// implemented can vary in specific data source implementation) for NSEC3
  379. /// RRs that match or cover the NSEC3 hash value for the given name.
  380. ///
  381. /// If \c recursive is false, it will first look for the NSEC3 that has
  382. /// a matching hash. If it doesn't exist, it identifies the covering NSEC3
  383. /// for the hash. In either case the search stops at that point and the
  384. /// found NSEC3 RR(set) will be returned in the closest_proof member of
  385. /// \c FindNSEC3Result. \c matched is true or false depending on
  386. /// the found NSEC3 is a matched one or covering one. \c next_proof
  387. /// is always NULL.
  388. ///
  389. /// If \c recursive is true, it will continue the search toward the zone
  390. /// apex (origin name) until it finds a provable encloser, that is,
  391. /// an ancestor of \c name that has a matching NSEC3. This is the closest
  392. /// provable encloser of \c name as defined in RFC5155. In this case,
  393. /// if the found encloser is not equal to \c name, the search should
  394. /// have seen a covering NSEC3 for the immediate child of the found
  395. /// encloser. That child name is the next closer name as defined in
  396. /// RFC5155. In this case, this method returns the NSEC3 for the
  397. /// closest encloser in \c closest_proof, and the NSEC3 for the next
  398. /// closer name in \c next_proof of \c FindNSEC3Result. This set of
  399. /// NSEC3 RRs provide the closest encloser proof as defined in RFC5155.
  400. /// If, on the other hand, the found closest name is equal to \c name,
  401. /// this method simply returns it in \c closest_proof. \c next_proof
  402. /// is set to NULL. In all cases \c matched is set to true.
  403. ///
  404. /// When looking for NSEC3, this method retrieves NSEC3 parameters from
  405. /// the corresponding zone to calculate hash values. Actual implementation
  406. /// of how to do this will differ in different data sources. If the
  407. /// NSEC3 parameters are not available \c DataSourceError exception
  408. /// will be thrown.
  409. ///
  410. /// \note This implicitly means this method assumes the zone does not
  411. /// have more than one set of parameters. This assumption should be
  412. /// reasonable in actual deployment and will help simplify the interface
  413. /// and implementation. But if there's a real need for supporting
  414. /// multiple sets of parameters in a single zone, we will have to
  415. /// extend this method so that, e.g., the caller can specify the parameter
  416. /// set.
  417. ///
  418. /// In general, this method expects the zone is properly signed with NSEC3
  419. /// RRs. Specifically, it assumes at least the apex node has a matching
  420. /// NSEC3 RR (so the search in the recursive mode must always succeed);
  421. /// it also assumes that it can retrieve NSEC parameters (iterations,
  422. /// algorithm, and salt) from the zone as noted above. If these
  423. /// assumptions aren't met, \c DataSourceError exception will be thrown.
  424. ///
  425. /// \exception InvalidParameter name is not a subdomain of the zone origin
  426. /// \exception DataSourceError Low-level or internal datasource errors
  427. /// happened, or the zone isn't properly signed with NSEC3
  428. /// (NSEC3 parameters cannot be found, no NSEC3s are available, etc).
  429. /// \exception std::bad_alloc The underlying implementation involves
  430. /// memory allocation and it fails
  431. ///
  432. /// \param name The name for which NSEC3 RRs are to be found. It must
  433. /// be a subdomain of the zone.
  434. /// \param recursive Whether or not search should continue until it finds
  435. /// a provable encloser (see above).
  436. ///
  437. /// \return The search result and whether or not the closest_proof is
  438. /// a matching NSEC3, in the form of \c FindNSEC3Result object.
  439. virtual FindNSEC3Result
  440. findNSEC3(const isc::dns::Name& name, bool recursive) = 0;
  441. /// \brief Get previous name in the zone
  442. ///
  443. /// Gets the previous name in the DNSSEC order. This can be used
  444. /// to find the correct NSEC records for proving nonexistence
  445. /// of domains.
  446. ///
  447. /// The concrete implementation might throw anything it thinks appropriate,
  448. /// however it is recommended to stick to the ones listed here. The user
  449. /// of this method should be able to handle any exceptions.
  450. ///
  451. /// This method does not include under-zone-cut data (glue data).
  452. ///
  453. /// \param query The name for which one we look for a previous one. The
  454. /// queried name doesn't have to exist in the zone.
  455. /// \return The preceding name
  456. ///
  457. /// \throw NotImplemented in case the data source backend doesn't support
  458. /// DNSSEC or there is no previous in the zone (NSEC records might be
  459. /// missing in the DB, the queried name is less or equal to the apex).
  460. /// \throw DataSourceError for low-level or internal datasource errors
  461. /// (like broken connection to database, wrong data living there).
  462. /// \throw std::bad_alloc For allocation errors.
  463. virtual isc::dns::Name findPreviousName(const isc::dns::Name& query)
  464. const = 0;
  465. //@}
  466. };
  467. /// \brief Operator to combine FindOptions
  468. ///
  469. /// We would need to manually static-cast the options if we put or
  470. /// between them, which is undesired with bit-flag options. Therefore
  471. /// we hide the cast here, which is the simplest solution and it still
  472. /// provides reasonable level of type safety.
  473. inline ZoneFinder::FindOptions operator |(ZoneFinder::FindOptions a,
  474. ZoneFinder::FindOptions b)
  475. {
  476. return (static_cast<ZoneFinder::FindOptions>(static_cast<unsigned>(a) |
  477. static_cast<unsigned>(b)));
  478. }
  479. /// \brief Operator to combine FindResultFlags
  480. ///
  481. /// Similar to the same operator for \c FindOptions. Refer to the description
  482. /// of that function.
  483. inline ZoneFinder::FindResultFlags operator |(
  484. ZoneFinder::FindResultFlags a,
  485. ZoneFinder::FindResultFlags b)
  486. {
  487. return (static_cast<ZoneFinder::FindResultFlags>(
  488. static_cast<unsigned>(a) | static_cast<unsigned>(b)));
  489. }
  490. /// \brief A pointer-like type pointing to a \c ZoneFinder object.
  491. typedef boost::shared_ptr<ZoneFinder> ZoneFinderPtr;
  492. /// \brief A pointer-like type pointing to a \c ZoneFinder object.
  493. typedef boost::shared_ptr<const ZoneFinder> ConstZoneFinderPtr;
  494. /// The base class to make updates to a single zone.
  495. ///
  496. /// On construction, each derived class object will start a "transaction"
  497. /// for making updates to a specific zone (this means a constructor of
  498. /// a derived class would normally take parameters to identify the zone
  499. /// to be updated). The underlying realization of a "transaction" will differ
  500. /// for different derived classes; if it uses a general purpose database
  501. /// as a backend, it will involve performing some form of "begin transaction"
  502. /// statement for the database.
  503. ///
  504. /// Updates (adding or deleting RRs) are made via \c addRRset() and
  505. /// \c deleteRRset() methods. Until the \c commit() method is called the
  506. /// changes are local to the updater object. For example, they won't be
  507. /// visible via a \c ZoneFinder object except the one returned by the
  508. /// updater's own \c getFinder() method. The \c commit() completes the
  509. /// transaction and makes the changes visible to others.
  510. ///
  511. /// This class does not provide an explicit "rollback" interface. If
  512. /// something wrong or unexpected happens during the updates and the
  513. /// caller wants to cancel the intermediate updates, the caller should
  514. /// simply destruct the updater object without calling \c commit().
  515. /// The destructor is supposed to perform the "rollback" operation,
  516. /// depending on the internal details of the derived class.
  517. ///
  518. /// \note This initial implementation provides a quite simple interface of
  519. /// adding and deleting RRs (see the description of the related methods).
  520. /// It may be revisited as we gain more experiences.
  521. class ZoneUpdater {
  522. protected:
  523. /// The default constructor.
  524. ///
  525. /// This is intentionally defined as protected to ensure that this base
  526. /// class is never instantiated directly.
  527. ZoneUpdater() {}
  528. public:
  529. /// The destructor
  530. ///
  531. /// Each derived class implementation must ensure that if \c commit()
  532. /// has not been performed by the time of the call to it, then it
  533. /// "rollbacks" the updates made via the updater so far.
  534. virtual ~ZoneUpdater() {}
  535. /// Return a finder for the zone being updated.
  536. ///
  537. /// The returned finder provides the functionalities of \c ZoneFinder
  538. /// for the zone as updates are made via the updater. That is, before
  539. /// making any update, the finder will be able to find all RRsets that
  540. /// exist in the zone at the time the updater is created. If RRsets
  541. /// are added or deleted via \c addRRset() or \c deleteRRset(),
  542. /// this finder will find the added ones or miss the deleted ones
  543. /// respectively.
  544. ///
  545. /// The finder returned by this method is effective only while the updates
  546. /// are performed, i.e., from the construction of the corresponding
  547. /// updater until \c commit() is performed or the updater is destructed
  548. /// without commit. The result of a subsequent call to this method (or
  549. /// the use of the result) after that is undefined.
  550. ///
  551. /// \return A reference to a \c ZoneFinder for the updated zone
  552. virtual ZoneFinder& getFinder() = 0;
  553. /// Add an RRset to a zone via the updater
  554. ///
  555. /// This may be revisited in a future version, but right now the intended
  556. /// behavior of this method is simple: It "naively" adds the specified
  557. /// RRset to the zone specified on creation of the updater.
  558. /// It performs minimum level of validation on the specified RRset:
  559. /// - Whether the RR class is identical to that for the zone to be updated
  560. /// - Whether the RRset is not empty, i.e., it has at least one RDATA
  561. /// - Whether the RRset is not associated with an RRSIG, i.e.,
  562. /// whether \c getRRsig() on the RRset returns a NULL pointer.
  563. ///
  564. /// and otherwise does not check any oddity. For example, it doesn't
  565. /// check whether the owner name of the specified RRset is a subdomain
  566. /// of the zone's origin; it doesn't care whether or not there is already
  567. /// an RRset of the same name and RR type in the zone, and if there is,
  568. /// whether any of the existing RRs have duplicate RDATA with the added
  569. /// ones. If these conditions matter the calling application must examine
  570. /// the existing data beforehand using the \c ZoneFinder returned by
  571. /// \c getFinder().
  572. ///
  573. /// The validation requirement on the associated RRSIG is temporary.
  574. /// If we find it more reasonable and useful to allow adding a pair of
  575. /// RRset and its RRSIG RRset as we gain experiences with the interface,
  576. /// we may remove this restriction. Until then we explicitly check it
  577. /// to prevent accidental misuse.
  578. ///
  579. /// Conceptually, on successful call to this method, the zone will have
  580. /// the specified RRset, and if there is already an RRset of the same
  581. /// name and RR type, these two sets will be "merged". "Merged" means
  582. /// that a subsequent call to \c ZoneFinder::find() for the name and type
  583. /// will result in success and the returned RRset will contain all
  584. /// previously existing and newly added RDATAs with the TTL being the
  585. /// minimum of the two RRsets. The underlying representation of the
  586. /// "merged" RRsets may vary depending on the characteristic of the
  587. /// underlying data source. For example, if it uses a general purpose
  588. /// database that stores each RR of the same RRset separately, it may
  589. /// simply be a larger sets of RRs based on both the existing and added
  590. /// RRsets; the TTLs of the RRs may be different within the database, and
  591. /// there may even be duplicate RRs in different database rows. As long
  592. /// as the RRset returned via \c ZoneFinder::find() conforms to the
  593. /// concept of "merge", the actual internal representation is up to the
  594. /// implementation.
  595. ///
  596. /// This method must not be called once commit() is performed. If it
  597. /// calls after \c commit() the implementation must throw a
  598. /// \c DataSourceError exception.
  599. ///
  600. /// If journaling was requested when getting this updater, it will reject
  601. /// to add the RRset if the squence doesn't look like and IXFR (see
  602. /// DataSourceClient::getUpdater). In such case isc::BadValue is thrown.
  603. ///
  604. /// \todo As noted above we may have to revisit the design details as we
  605. /// gain experiences:
  606. ///
  607. /// - we may want to check (and maybe reject) if there is already a
  608. /// duplicate RR (that has the same RDATA).
  609. /// - we may want to check (and maybe reject) if there is already an
  610. /// RRset of the same name and RR type with different TTL
  611. /// - we may even want to check if there is already any RRset of the
  612. /// same name and RR type.
  613. /// - we may want to add an "options" parameter that can control the
  614. /// above points
  615. /// - we may want to have this method return a value containing the
  616. /// information on whether there's a duplicate, etc.
  617. ///
  618. /// \exception DataSourceError Called after \c commit(), RRset is invalid
  619. /// (see above), internal data source error
  620. /// \exception isc::BadValue Journaling is enabled and the current RRset
  621. /// doesn't fit into the IXFR sequence (see above).
  622. /// \exception std::bad_alloc Resource allocation failure
  623. ///
  624. /// \param rrset The RRset to be added
  625. virtual void addRRset(const isc::dns::RRset& rrset) = 0;
  626. /// Delete an RRset from a zone via the updater
  627. ///
  628. /// Like \c addRRset(), the detailed semantics and behavior of this method
  629. /// may have to be revisited in a future version. The following are
  630. /// based on the initial implementation decisions.
  631. ///
  632. /// On successful completion of this method, it will remove from the zone
  633. /// the RRs of the specified owner name and RR type that match one of
  634. /// the RDATAs of the specified RRset. There are several points to be
  635. /// noted:
  636. /// - Existing RRs that don't match any of the specified RDATAs will
  637. /// remain in the zone.
  638. /// - Any RRs of the specified RRset that doesn't exist in the zone will
  639. /// simply be ignored; the implementation of this method is not supposed
  640. /// to check that condition.
  641. /// - The TTL of the RRset is ignored; matching is only performed by
  642. /// the owner name, RR type and RDATA
  643. ///
  644. /// Ignoring the TTL may not look sensible, but it's based on the
  645. /// observation that it will result in more intuitive result, especially
  646. /// when the underlying data source is a general purpose database.
  647. /// See also \c DatabaseAccessor::deleteRecordInZone() on this point.
  648. /// It also matches the dynamic update protocol (RFC2136), where TTLs
  649. /// are ignored when deleting RRs.
  650. ///
  651. /// \note Since the TTL is ignored, this method could take the RRset
  652. /// to be deleted as a tuple of name, RR type, and a list of RDATAs.
  653. /// But in practice, it's quite likely that the caller has the RRset
  654. /// in the form of the \c RRset object (e.g., extracted from a dynamic
  655. /// update request message), so this interface would rather be more
  656. /// convenient. If it turns out not to be true we can change or extend
  657. /// the method signature.
  658. ///
  659. /// This method performs minimum level of validation on the specified
  660. /// RRset:
  661. /// - Whether the RR class is identical to that for the zone to be updated
  662. /// - Whether the RRset is not empty, i.e., it has at least one RDATA
  663. /// - Whether the RRset is not associated with an RRSIG, i.e.,
  664. /// whether \c getRRsig() on the RRset returns a NULL pointer.
  665. ///
  666. /// This method must not be called once commit() is performed. If it
  667. /// calls after \c commit() the implementation must throw a
  668. /// \c DataSourceError exception.
  669. ///
  670. /// If journaling was requested when getting this updater, it will reject
  671. /// to add the RRset if the squence doesn't look like and IXFR (see
  672. /// DataSourceClient::getUpdater). In such case isc::BadValue is thrown.
  673. ///
  674. /// \todo As noted above we may have to revisit the design details as we
  675. /// gain experiences:
  676. ///
  677. /// - we may want to check (and maybe reject) if some or all of the RRs
  678. /// for the specified RRset don't exist in the zone
  679. /// - we may want to allow an option to "delete everything" for specified
  680. /// name and/or specified name + RR type.
  681. /// - as mentioned above, we may want to include the TTL in matching the
  682. /// deleted RRs
  683. /// - we may want to add an "options" parameter that can control the
  684. /// above points
  685. /// - we may want to have this method return a value containing the
  686. /// information on whether there's any RRs that are specified but don't
  687. /// exit, the number of actually deleted RRs, etc.
  688. ///
  689. /// \exception DataSourceError Called after \c commit(), RRset is invalid
  690. /// (see above), internal data source error
  691. /// \exception isc::BadValue Journaling is enabled and the current RRset
  692. /// doesn't fit into the IXFR sequence (see above).
  693. /// \exception std::bad_alloc Resource allocation failure
  694. ///
  695. /// \param rrset The RRset to be deleted
  696. virtual void deleteRRset(const isc::dns::RRset& rrset) = 0;
  697. /// Commit the updates made in the updater to the zone
  698. ///
  699. /// This method completes the "transaction" started at the creation
  700. /// of the updater. After successful completion of this method, the
  701. /// updates will be visible outside the scope of the updater.
  702. /// The actual internal behavior will defer for different derived classes.
  703. /// For a derived class with a general purpose database as a backend,
  704. /// for example, this method would perform a "commit" statement for the
  705. /// database.
  706. ///
  707. /// This operation can only be performed at most once. A duplicate call
  708. /// must result in a DatasourceError exception.
  709. ///
  710. /// \exception DataSourceError Duplicate call of the method,
  711. /// internal data source error
  712. /// \exception isc::BadValue Journaling is enabled and the update is not
  713. /// complete IXFR sequence.
  714. virtual void commit() = 0;
  715. };
  716. /// \brief A pointer-like type pointing to a \c ZoneUpdater object.
  717. typedef boost::shared_ptr<ZoneUpdater> ZoneUpdaterPtr;
  718. /// The base class for retrieving differences between two versions of a zone.
  719. ///
  720. /// On construction, each derived class object will internally set up
  721. /// retrieving sequences of differences between two specific version of
  722. /// a specific zone managed in a particular data source. So the constructor
  723. /// of a derived class would normally take parameters to identify the zone
  724. /// and the two versions for which the differences should be retrieved.
  725. /// See \c DataSourceClient::getJournalReader for more concrete details
  726. /// used in this API.
  727. ///
  728. /// Once constructed, an object of this class will act like an iterator
  729. /// over the sequences. Every time the \c getNextDiff() method is called
  730. /// it returns one element of the differences in the form of an \c RRset
  731. /// until it reaches the end of the entire sequences.
  732. class ZoneJournalReader {
  733. public:
  734. /// Result codes used by a factory method for \c ZoneJournalReader
  735. enum Result {
  736. SUCCESS, ///< A \c ZoneJournalReader object successfully created
  737. NO_SUCH_ZONE, ///< Specified zone does not exist in the data source
  738. NO_SUCH_VERSION ///< Specified versions do not exist in the diff storage
  739. };
  740. protected:
  741. /// The default constructor.
  742. ///
  743. /// This is intentionally defined as protected to ensure that this base
  744. /// class is never instantiated directly.
  745. ZoneJournalReader() {}
  746. public:
  747. /// The destructor
  748. virtual ~ZoneJournalReader() {}
  749. /// Return the next difference RR of difference sequences.
  750. ///
  751. /// In this API, the difference between two versions of a zone is
  752. /// conceptually represented as IXFR-style difference sequences:
  753. /// Each difference sequence is a sequence of RRs: an older version of
  754. /// SOA (to be deleted), zero or more other deleted RRs, the
  755. /// post-transaction SOA (to be added), and zero or more other
  756. /// added RRs. (Note, however, that the underlying data source
  757. /// implementation may or may not represent the difference in
  758. /// straightforward realization of this concept. The mapping between
  759. /// the conceptual difference and the actual implementation is hidden
  760. /// in each derived class).
  761. ///
  762. /// This method provides an application with a higher level interface
  763. /// to retrieve the difference along with the conceptual model: the
  764. /// \c ZoneJournalReader object iterates over the entire sequences
  765. /// from the beginning SOA (which is to be deleted) to one of the
  766. /// added RR of with the ending SOA, and each call to this method returns
  767. /// one RR in the form of an \c RRset that contains exactly one RDATA
  768. /// in the order of the sequences.
  769. ///
  770. /// Note that the ordering of the sequences specifies the semantics of
  771. /// each difference: add or delete. For example, the first RR is to
  772. /// be deleted, and the last RR is to be added. So the return value
  773. /// of this method does not explicitly indicate whether the RR is to be
  774. /// added or deleted.
  775. ///
  776. /// This method ensures the returned \c RRset represents an RR, that is,
  777. /// it contains exactly one RDATA. However, it does not necessarily
  778. /// ensure that the resulting sequences are in the form of IXFR-style.
  779. /// For example, the first RR is supposed to be an SOA, and it should
  780. /// normally be the case, but this interface does not necessarily require
  781. /// the derived class implementation ensure this. Normally the
  782. /// differences are expected to be stored using this API (via a
  783. /// \c ZoneUpdater object), and as long as that is the case and the
  784. /// underlying implementation follows the requirement of the API, the
  785. /// result of this method should be a valid IXFR-style sequences.
  786. /// So this API does not mandate the almost redundant check as part of
  787. /// the interface. If the application needs to make it sure 100%, it
  788. /// must check the resulting sequence itself.
  789. ///
  790. /// Once the object reaches the end of the sequences, this method returns
  791. /// \c Null. Any subsequent call will result in an exception of
  792. /// class \c InvalidOperation.
  793. ///
  794. /// \exception InvalidOperation The method is called beyond the end of
  795. /// the difference sequences.
  796. /// \exception DataSourceError Underlying data is broken and the RR
  797. /// cannot be created or other low level data source error.
  798. ///
  799. /// \return An \c RRset that contains one RDATA corresponding to the
  800. /// next difference in the sequences.
  801. virtual isc::dns::ConstRRsetPtr getNextDiff() = 0;
  802. };
  803. /// \brief A pointer-like type pointing to a \c ZoneUpdater object.
  804. typedef boost::shared_ptr<ZoneJournalReader> ZoneJournalReaderPtr;
  805. } // end of datasrc
  806. } // end of isc
  807. #endif // __ZONE_H
  808. // Local Variables:
  809. // mode: c++
  810. // End: