zone.h 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146
  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 <dns/name.h>
  17. #include <dns/rrset.h>
  18. #include <dns/rrtype.h>
  19. #include <datasrc/exceptions.h>
  20. #include <datasrc/result.h>
  21. #include <datasrc/rrset_collection_base.h>
  22. #include <utility>
  23. #include <vector>
  24. namespace isc {
  25. namespace datasrc {
  26. /// \brief Out of zone exception
  27. ///
  28. /// This is thrown when a method is called for a name or RRset which
  29. /// is not in or below the zone.
  30. class OutOfZone : public ZoneException {
  31. public:
  32. OutOfZone(const char* file, size_t line, const char* what) :
  33. ZoneException(file, line, what) {}
  34. };
  35. /// \brief The base class to search a zone for RRsets
  36. ///
  37. /// The \c ZoneFinder class is an abstract base class for representing
  38. /// an object that performs DNS lookups in a specific zone accessible via
  39. /// a data source. In general, different types of data sources (in-memory,
  40. /// database-based, etc) define their own derived classes of \c ZoneFinder,
  41. /// implementing ways to retrieve the required data through the common
  42. /// interfaces declared in the base class. Each concrete \c ZoneFinder
  43. /// object is therefore (conceptually) associated with a specific zone
  44. /// of one specific data source instance.
  45. ///
  46. /// The origin name and the RR class of the associated zone are available
  47. /// via the \c getOrigin() and \c getClass() methods, respectively.
  48. ///
  49. /// The most important method of this class is \c find(), which performs
  50. /// the lookup for a given domain and type. See the description of the
  51. /// method for details.
  52. ///
  53. /// \note It's not clear whether we should request that a zone finder form a
  54. /// "transaction", that is, whether to ensure the finder is not susceptible
  55. /// to changes made by someone else than the creator of the finder. If we
  56. /// don't request that, for example, two different lookup results for the
  57. /// same name and type can be different if other threads or programs make
  58. /// updates to the zone between the lookups. We should revisit this point
  59. /// as we gain more experiences.
  60. class ZoneFinder {
  61. public:
  62. /// Result codes of the \c find() method.
  63. ///
  64. /// Note: the codes are tentative. We may need more, or we may find
  65. /// some of them unnecessary as we implement more details.
  66. ///
  67. /// See the description of \c find() for further details of how
  68. /// these results should be interpreted.
  69. enum Result {
  70. SUCCESS, ///< An exact match is found.
  71. DELEGATION, ///< The search encounters a zone cut.
  72. NXDOMAIN, ///< There is no domain name that matches the search name
  73. NXRRSET, ///< There is a matching name but no RRset of the search type
  74. CNAME, ///< The search encounters and returns a CNAME RR
  75. DNAME ///< The search encounters and returns a DNAME RR
  76. };
  77. /// Special attribute flags on the result of the \c find() method
  78. ///
  79. /// The flag values defined here are intended to signal to the caller
  80. /// that it may need special handling on the result. This is particularly
  81. /// of concern when DNSSEC is requested. For example, for negative
  82. /// responses the caller would want to know whether the zone is signed
  83. /// with NSEC or NSEC3 so that it can subsequently provide necessary
  84. /// proof of the result.
  85. ///
  86. /// The caller is generally expected to get access to the information
  87. /// via read-only getter methods of \c FindContext so that it won't rely
  88. /// on specific details of the representation of the flags. So these
  89. /// definitions are basically only meaningful for data source
  90. /// implementations.
  91. enum FindResultFlags {
  92. RESULT_DEFAULT = 0, ///< The default flags
  93. RESULT_WILDCARD = 1, ///< find() resulted in a wildcard match
  94. RESULT_NSEC_SIGNED = 2, ///< The zone is signed with NSEC RRs
  95. RESULT_NSEC3_SIGNED = 4 ///< The zone is signed with NSEC3 RRs
  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. FIND_DNSSEC = 2, ///< Require DNSSEC data in the answer
  106. ///< (RRSIG, NSEC, etc.). The implementation
  107. ///< is allowed to include it even if it is
  108. ///< not set.
  109. NO_WILDCARD = 4 ///< Do not try wildcard matching.
  110. };
  111. protected:
  112. /// \brief A convenient tuple representing a set of find() results.
  113. ///
  114. /// This helper structure is specifically expected to be used as an input
  115. /// for the construct of the \c Context class object used by derived
  116. /// ZoneFinder implementations. This is therefore defined as protected.
  117. struct ResultContext {
  118. ResultContext(Result code_param,
  119. isc::dns::ConstRRsetPtr rrset_param,
  120. FindResultFlags flags_param = RESULT_DEFAULT) :
  121. code(code_param), rrset(rrset_param), flags(flags_param)
  122. {}
  123. const Result code;
  124. const isc::dns::ConstRRsetPtr rrset;
  125. const FindResultFlags flags;
  126. };
  127. public:
  128. /// \brief A helper function to strip RRSIGs when FIND_DNSSEC is not
  129. /// requested.
  130. static isc::dns::ConstRRsetPtr
  131. stripRRsigs(isc::dns::ConstRRsetPtr rp, const FindOptions options);
  132. /// \brief Context of the result of a find() call.
  133. ///
  134. /// This class encapsulates results and (possibly) associated context
  135. /// of a call to the \c find() method. The public member variables of
  136. /// this class represent the result of the call. They are a
  137. /// straightforward tuple of the result code and a pointer (and
  138. /// optionally special flags) to the found RRset.
  139. ///
  140. /// These member variables will be initialized on construction and never
  141. /// change, so for convenience we allow the applications to refer to some
  142. /// of the members directly. For some others we provide read-only accessor
  143. /// methods to hide specific representation.
  144. ///
  145. /// Another role of this class is to provide the interface to some common
  146. /// processing logic that may be necessary using the result of \c find().
  147. /// Specifically, it's expected to be used in the context of DNS query
  148. /// handling, where the caller would need to look into the data source
  149. /// again based on the \c find() result. For example, it would need to
  150. /// get A and/or AAAA records for some of the answer or authority RRs.
  151. ///
  152. /// This class defines (a set of) method(s) that can be commonly used
  153. /// for such purposes for any type of data source (as long as it conforms
  154. /// to the public \c find() interface). In some cases, a specific data
  155. /// source implementation may want to (and can) optimize the processing
  156. /// exploiting its internal data structure and the knowledge of the context
  157. /// of the precedent \c find() call. Such a data source implementation
  158. /// can define a derived class of the base Context and override the
  159. /// specific virtual method.
  160. ///
  161. /// This base class defines these common protected methods along with
  162. /// some helper pure virtual methods that would be necessary for the
  163. /// common methods. If a derived class wants to use the common version
  164. /// of the protected method, it needs to provide expected result through
  165. /// their implementation of the pure virtual methods.
  166. ///
  167. /// This class object is generally expected to be associated with the
  168. /// ZoneFinder that originally performed the \c find() call, and expects
  169. /// the finder is valid throughout the lifetime of this object. It's
  170. /// caller's responsibility to ensure that assumption.
  171. class Context {
  172. public:
  173. /// \brief The constructor.
  174. ///
  175. /// \param options The find options specified for the find() call.
  176. /// \param result The result of the find() call.
  177. Context(FindOptions options, const ResultContext& result) :
  178. code(result.code), rrset(result.rrset),
  179. flags_(result.flags), options_(options)
  180. {}
  181. /// \brief The destructor.
  182. virtual ~Context() {}
  183. const Result code;
  184. const isc::dns::ConstRRsetPtr rrset;
  185. /// Return true iff find() results in a wildcard match.
  186. bool isWildcard() const { return ((flags_ & RESULT_WILDCARD) != 0); }
  187. /// Return true when the underlying zone is signed with NSEC.
  188. ///
  189. /// The \c find() implementation allows this to return false if
  190. /// \c FIND_DNSSEC isn't specified regardless of whether the zone
  191. /// is signed or which of NSEC/NSEC3 is used.
  192. ///
  193. /// When this is returned, the implementation of find() must ensure
  194. /// that \c rrset be a valid NSEC RRset as described in \c find()
  195. /// documentation.
  196. bool isNSECSigned() const {
  197. return ((flags_ & RESULT_NSEC_SIGNED) != 0);
  198. }
  199. /// Return true when the underlying zone is signed with NSEC3.
  200. ///
  201. /// The \c find() implementation allows this to return false if
  202. /// \c FIND_DNSSEC isn't specified regardless of whether the zone
  203. /// is signed or which of NSEC/NSEC3 is used.
  204. bool isNSEC3Signed() const {
  205. return ((flags_ & RESULT_NSEC3_SIGNED) != 0);
  206. }
  207. /// \brief Find and return additional RRsets corresponding to the
  208. /// result of \c find().
  209. ///
  210. /// If this context is based on a normal find() call that resulted
  211. /// in SUCCESS or DELEGATION, it examines the returned RRset (in many
  212. /// cases NS, sometimes MX or others), searches the data source for
  213. /// specified type of additional RRs for each RDATA of the RRset
  214. /// (e.g., A or AAAA for the name server addresses), and stores the
  215. /// result in the given vector. The vector may not be empty; this
  216. /// method appends any found RRsets to it, without touching existing
  217. /// elements.
  218. ///
  219. /// If this context is based on a findAll() call that resulted in
  220. /// SUCCESS, it performs the same process for each RRset returned in
  221. /// the \c findAll() call.
  222. ///
  223. /// The caller specifies desired RR types of the additional RRsets
  224. /// in \c requested_types. Normally it consists of A and/or AAAA
  225. /// types, but other types can be specified.
  226. ///
  227. /// This method is meaningful only when the precedent find()/findAll()
  228. /// call resulted in SUCCESS or DELEGATION. Otherwise this method
  229. /// does nothing.
  230. ///
  231. /// \note The additional RRsets returned via method are limited to
  232. /// ones contained in the zone which the corresponding find/findAll
  233. /// call searched (possibly including glues under a zone cut where
  234. /// they are applicable). If the caller needs to get out-of-zone
  235. /// additional RRsets, it needs to explicitly finds them by
  236. /// identifying the corresponding zone and calls \c find() for it.
  237. ///
  238. /// \param requested_types A vector of RR types for desired additional
  239. /// RRsets.
  240. /// \param result A vector to which any found additional RRsets are
  241. /// to be inserted.
  242. void getAdditional(
  243. const std::vector<isc::dns::RRType>& requested_types,
  244. std::vector<isc::dns::ConstRRsetPtr>& result)
  245. {
  246. // Perform common checks, and delegate the process to the default
  247. // or specialized implementation.
  248. if (code != SUCCESS && code != DELEGATION) {
  249. return;
  250. }
  251. getAdditionalImpl(requested_types, result);
  252. }
  253. protected:
  254. /// \brief Return the \c ZoneFinder that created this \c Context.
  255. ///
  256. /// A derived class implementation can return NULL if it defines
  257. /// other protected methods that require a non NULL result from
  258. /// this method. Otherwise it must return a valid, non NULL pointer
  259. /// to the \c ZoneFinder object.
  260. ///
  261. /// When returning non NULL, the ownership of the pointed object
  262. /// was not transferred to the caller; it cannot be assumed to be
  263. /// valid after the originating \c Context object is destroyed.
  264. /// Also, the caller must not try to delete the returned object.
  265. virtual ZoneFinder* getFinder() = 0;
  266. /// \brief Return a vector of RRsets corresponding to findAll() result.
  267. ///
  268. /// This method returns a set of RRsets that correspond to the
  269. /// returned RRsets to a prior \c findAll() call.
  270. ///
  271. /// A derived class implementation can return NULL if it defines
  272. /// other protected methods that require a non NULL result from
  273. /// this method. Otherwise it must return a valid, non NULL pointer
  274. /// to a vector that correspond to the expected set of RRsets.
  275. ///
  276. /// When returning non NULL, the ownership of the pointed object
  277. /// was not transferred to the caller; it cannot be assumed to be
  278. /// valid after the originating \c Context object is destroyed.
  279. /// Also, the caller must not try to delete the returned object.
  280. virtual const std::vector<isc::dns::ConstRRsetPtr>*
  281. getAllRRsets() const = 0;
  282. /// \brief Actual implementation of getAdditional().
  283. ///
  284. /// This base class defines a default implementation that can be
  285. /// used for any type of data sources. A data source implementation
  286. /// can override it.
  287. ///
  288. /// The default version of this implementation requires both
  289. /// \c getFinder() and \c getAllRRsets() return valid results.
  290. virtual void getAdditionalImpl(
  291. const std::vector<isc::dns::RRType>& requested_types,
  292. std::vector<isc::dns::ConstRRsetPtr>& result);
  293. private:
  294. const FindResultFlags flags_;
  295. protected:
  296. const FindOptions options_;
  297. };
  298. /// \brief Generic ZoneFinder context that works for all implementations.
  299. ///
  300. /// This is a concrete derived class of \c ZoneFinder::Context that
  301. /// only use the generic (default) versions of the protected methods
  302. /// and therefore work for any data source implementation.
  303. ///
  304. /// A data source implementation can use this class to create a
  305. /// \c Context object as a return value of \c find() or \c findAll()
  306. /// method if it doesn't have to optimize specific protected methods.
  307. class GenericContext : public Context {
  308. public:
  309. /// \brief The constructor for the normal find call.
  310. ///
  311. /// This constructor is expected to be called from the \c find()
  312. /// method when it constructs the return value.
  313. ///
  314. /// \param finder The ZoneFinder on which find() is called.
  315. /// \param options See the \c Context class.
  316. /// \param result See the \c Context class.
  317. GenericContext(ZoneFinder& finder, FindOptions options,
  318. const ResultContext& result) :
  319. Context(options, result), finder_(finder)
  320. {}
  321. /// \brief The constructor for the normal findAll call.
  322. ///
  323. /// This constructor is expected to be called from the \c findAll()
  324. /// method when it constructs the return value.
  325. ///
  326. /// It copies the vector that is to be returned to the caller of
  327. /// \c findAll() for possible subsequent use. Note that it cannot
  328. /// simply hold a reference to the vector because the caller may
  329. /// alter it after the \c findAll() call.
  330. ///
  331. /// \param finder The ZoneFinder on which findAll() is called.
  332. /// \param options See the \c Context class.
  333. /// \param result See the \c Context class.
  334. /// \param all_set Reference to the vector given by the caller of
  335. /// \c findAll(), storing the RRsets to be returned.
  336. GenericContext(ZoneFinder& finder, FindOptions options,
  337. const ResultContext& result,
  338. const std::vector<isc::dns::ConstRRsetPtr>& all_set) :
  339. Context(options, result), finder_(finder), all_set_(all_set)
  340. {}
  341. protected:
  342. virtual ZoneFinder* getFinder() { return (&finder_); }
  343. virtual const std::vector<isc::dns::ConstRRsetPtr>*
  344. getAllRRsets() const {
  345. return (&all_set_);
  346. }
  347. private:
  348. ZoneFinder& finder_;
  349. std::vector<isc::dns::ConstRRsetPtr> all_set_;
  350. };
  351. ///
  352. /// \name Constructors and Destructor.
  353. ///
  354. //@{
  355. protected:
  356. /// The default constructor.
  357. ///
  358. /// This is intentionally defined as \c protected as this base class should
  359. /// never be instantiated (except as part of a derived class).
  360. ZoneFinder() {}
  361. public:
  362. /// The destructor.
  363. virtual ~ZoneFinder() {}
  364. //@}
  365. ///
  366. /// \name Getter Methods
  367. ///
  368. /// These methods should never throw an exception.
  369. //@{
  370. /// Return the origin name of the zone.
  371. virtual isc::dns::Name getOrigin() const = 0;
  372. /// Return the RR class of the zone.
  373. virtual isc::dns::RRClass getClass() const = 0;
  374. //@}
  375. ///
  376. /// \name Search Methods
  377. ///
  378. //@{
  379. /// Search the zone for a given pair of domain name and RR type.
  380. ///
  381. /// Each derived version of this method searches the underlying backend
  382. /// for the data that best matches the given name and type.
  383. /// This method is expected to be "intelligent", and identifies the
  384. /// best possible answer for the search key. Specifically,
  385. ///
  386. /// - If the search name belongs under a zone cut, it returns the code
  387. /// of \c DELEGATION and the NS RRset at the zone cut.
  388. /// - If there is no matching name, it returns the code of \c NXDOMAIN.
  389. /// - If there is a matching name but no RRset of the search type, it
  390. /// returns the code of \c NXRRSET. This case includes the search name
  391. /// matches an empty node of the zone.
  392. /// - If there is a CNAME RR of the searched name but there is no
  393. /// RR of the searched type of the name (so this type is different from
  394. /// CNAME), it returns the code of \c CNAME and that CNAME RR.
  395. /// Note that if the searched RR type is CNAME, it is considered
  396. /// a successful match, and the code of \c SUCCESS will be returned.
  397. /// - If the search name matches a delegation point of DNAME, it returns
  398. /// the code of \c DNAME and that DNAME RR.
  399. ///
  400. /// No RRset will be returned in the \c NXDOMAIN and \c NXRRSET cases
  401. /// (\c rrset member of \c FindContext will be NULL), unless DNSSEC data
  402. /// are required. See below for the cases with DNSSEC.
  403. ///
  404. /// The returned \c FindContext object can also provide supplemental
  405. /// information about the search result via its methods returning a
  406. /// boolean value. Such information may be useful for the caller if
  407. /// the caller wants to collect additional DNSSEC proofs based on the
  408. /// search result.
  409. ///
  410. /// The \c options parameter specifies customized behavior of the search.
  411. /// Their semantics is as follows (they are or bit-field):
  412. ///
  413. /// - \c FIND_GLUE_OK Allow search under a zone cut. By default the search
  414. /// will stop once it encounters a zone cut. If this option is specified
  415. /// it remembers information about the highest zone cut and continues
  416. /// the search until it finds an exact match for the given name or it
  417. /// detects there is no exact match. If an exact match is found,
  418. /// RRsets for that name are searched just like the normal case;
  419. /// otherwise, if the search has encountered a zone cut, \c DELEGATION
  420. /// with the information of the highest zone cut will be returned.
  421. /// Note: the term "glue" in the DNS protocol standard may sometimes
  422. /// cause confusion: some people use this term strictly for an address
  423. /// record (type AAAA or A) for the name used in the RDATA of an NS RR;
  424. /// some others seem to give it broader flexibility. Nevertheless,
  425. /// in this API the "GLUE OK" simply means the search by find() can
  426. /// continue beyond a zone cut; the derived class implementation does
  427. /// not have to, and should not, check whether the type is an address
  428. /// record or whether the query name is pointed by some NS RR.
  429. /// It's up to the caller with which definition of "glue" the search
  430. /// result with this option should be used.
  431. /// - \c FIND_DNSSEC Request that DNSSEC data (like NSEC, RRSIGs) are
  432. /// returned with the answer. It is allowed for the data source to
  433. /// include them even when not requested.
  434. /// - \c NO_WILDCARD Do not try wildcard matching. This option is of no
  435. /// use for normal lookups; it's intended to be used to get a DNSSEC
  436. /// proof of the non existence of any matching wildcard or non existence
  437. /// of an exact match when a wildcard match is found.
  438. ///
  439. /// In general, \c name is expected to be included in the zone, that is,
  440. /// it should be equal to or a subdomain of the zone origin. Otherwise
  441. /// this method will return \c NXDOMAIN with an empty RRset. But such a
  442. /// case should rather be considered a caller's bug.
  443. ///
  444. /// \note For this reason it's probably better to throw an exception
  445. /// than returning \c NXDOMAIN. This point should be revisited in a near
  446. /// future version. In any case applications shouldn't call this method
  447. /// for an out-of-zone name.
  448. ///
  449. /// <b>DNSSEC considerations:</b>
  450. /// The result when DNSSEC data are required can be very complicated,
  451. /// especially if it involves negative result or wildcard match.
  452. /// Specifically, if an application calls this method for DNS query
  453. /// processing with DNSSEC data, and if the search result code is
  454. /// either \c NXDOMAIN or \c NXRRRSET, and/or \c isWildcard() returns
  455. /// true, then the application will need to find additional NSEC or
  456. /// NSEC3 records for supplemental proofs. This method helps the
  457. /// application for such post search processing.
  458. ///
  459. /// First, it tells the application whether the zone is signed with
  460. /// NSEC or NSEC3 via the \c isNSEC(3)Signed() method. Any sanely signed
  461. /// zone should be signed with either (and only one) of these two types
  462. /// of RRs; however, the application should expect that the zone could
  463. /// be broken and these methods could both return false. But this method
  464. /// should ensure that not both of these methods return true.
  465. ///
  466. /// In case it's signed with NSEC3, there is no further information
  467. /// returned from this method.
  468. ///
  469. /// In case it's signed with NSEC, this method will possibly return
  470. /// a related NSEC RRset in the \c rrset member of \c FindContext.
  471. /// What kind of NSEC is returned depends on the result code
  472. /// (\c NXDOMAIN or \c NXRRSET) and on whether it's a wildcard match:
  473. ///
  474. /// - In case of NXDOMAIN, the returned NSEC covers the queried domain
  475. /// that proves that the query name does not exist in the zone. Note
  476. /// that this does not necessarily prove it doesn't even match a
  477. /// wildcard (even if the result of NXDOMAIN can only happen when
  478. /// there's no matching wildcard either). It is caller's
  479. /// responsibility to provide a proof that there is no matching
  480. /// wildcard if that proof is necessary.
  481. /// - In case of NXRRSET, we need to consider the following cases
  482. /// referring to Section 3.1.3 of RFC4035:
  483. ///
  484. /// -# (Normal) no data: there is a matching non-wildcard name with a
  485. /// different RR type. This is the "No Data" case of the RFC.
  486. /// -# (Normal) empty non terminal: there is no matching (exact or
  487. /// wildcard) name, but there is a subdomain with an RR of the query
  488. /// name. This is one case of "Name Error" of the RFC.
  489. /// -# Wildcard empty non terminal: similar to 2a, but the empty name
  490. /// is a wildcard, and matches the query name by wildcard expansion.
  491. /// This is a special case of "Name Error" of the RFC.
  492. /// -# Wildcard no data: there is no exact match name, but there is a
  493. /// wildcard name that matches the query name with a different type
  494. /// of RR. This is the "Wildcard No Data" case of the RFC.
  495. ///
  496. /// In case 1, \c find() returns NSEC of the matching name.
  497. ///
  498. /// In case 2, \c find() will return NSEC for the interval where the
  499. /// empty nonterminal lives. The end of the interval is the subdomain
  500. /// causing existence of the empty nonterminal (if there's
  501. /// sub.x.example.com, and no record in x.example.com, then
  502. /// x.example.com exists implicitly - is the empty nonterminal and
  503. /// sub.x.example.com is the subdomain causing it). Note that this NSEC
  504. /// proves not only the existence of empty non terminal name but also
  505. /// the non existence of possibly matching wildcard name, because
  506. /// there can be no better wildcard match than the exact matching empty
  507. /// name.
  508. ///
  509. /// In case 3, \c find() will return NSEC for the interval where the
  510. /// wildcard empty nonterminal lives. Cases 2 and 3 are especially
  511. /// complicated and confusing. See the examples below.
  512. ///
  513. /// In case 4, \c find() will return NSEC of the matching wildcard name.
  514. ///
  515. /// Examples: if zone "example.com" has the following record:
  516. /// \code
  517. /// a.example.com. NSEC a.b.example.com.
  518. /// \endcode
  519. /// a call to \c find() for "b.example.com." with the FIND_DNSSEC option
  520. /// will result in NXRRSET, and this NSEC will be returned.
  521. /// Likewise, if zone "example.org" has the following record,
  522. /// \code
  523. /// a.example.org. NSEC x.*.b.example.org.
  524. /// \endcode
  525. /// a call to \c find() for "y.b.example.org" with FIND_DNSSEC will
  526. /// result in NXRRSET and this NSEC; \c isWildcard() on the returned
  527. /// \c FindContext object will return true.
  528. ///
  529. /// \exception std::bad_alloc Memory allocation such as for constructing
  530. /// the resulting RRset fails
  531. /// \throw OutOfZone The Name \c name is outside of the origin of the
  532. /// zone of this ZoneFinder.
  533. /// \exception DataSourceError Derived class specific exception, e.g.
  534. /// when encountering a bad zone configuration or database connection
  535. /// failure. Although these are considered rare, exceptional events,
  536. /// it can happen under relatively usual conditions (unlike memory
  537. /// allocation failure). So, in general, the application is expected
  538. /// to catch this exception, either specifically or as a result of
  539. /// catching a base exception class, and handle it gracefully.
  540. ///
  541. /// \param name The domain name to be searched for.
  542. /// \param type The RR type to be searched for.
  543. /// \param options The search options.
  544. /// \return A \c FindContext object enclosing the search result
  545. /// (see above).
  546. virtual boost::shared_ptr<Context> find(const isc::dns::Name& name,
  547. const isc::dns::RRType& type,
  548. const FindOptions options
  549. = FIND_DEFAULT) = 0;
  550. ///
  551. /// \brief Finds all RRsets in the given name.
  552. ///
  553. /// This function works almost exactly in the same way as the find one. The
  554. /// only difference is, when the lookup is successful (eg. the code is
  555. /// SUCCESS), all the RRsets residing in the named node are
  556. /// copied into the \c target parameter and the rrset member of the result
  557. /// is NULL. All the other (unsuccessful) cases are handled the same,
  558. /// including returning delegations, NSEC/NSEC3 availability and NSEC
  559. /// proofs, wildcard information etc. The options parameter works the
  560. /// same way and it should conform to the same exception restrictions.
  561. ///
  562. /// \param name \see find, parameter name
  563. /// \param target the successfull result is returned through this
  564. /// \param options \see find, parameter options
  565. /// \return \see find and it's result
  566. virtual boost::shared_ptr<Context> findAll(
  567. const isc::dns::Name& name,
  568. std::vector<isc::dns::ConstRRsetPtr> &target,
  569. const FindOptions options = FIND_DEFAULT) = 0;
  570. /// A helper structure to represent the search result of \c findNSEC3().
  571. ///
  572. /// The idea is similar to that of \c FindContext, but \c findNSEC3() has
  573. /// special interface and semantics, we use a different structure to
  574. /// represent the result.
  575. struct FindNSEC3Result {
  576. FindNSEC3Result(bool param_matched, uint8_t param_closest_labels,
  577. isc::dns::ConstRRsetPtr param_closest_proof,
  578. isc::dns::ConstRRsetPtr param_next_proof) :
  579. matched(param_matched), closest_labels(param_closest_labels),
  580. closest_proof(param_closest_proof),
  581. next_proof(param_next_proof)
  582. {}
  583. /// true iff closest_proof is a matching NSEC3
  584. const bool matched;
  585. /// The number of labels of the identified closest encloser.
  586. const uint8_t closest_labels;
  587. /// Either the NSEC3 for the closest provable encloser of the given
  588. /// name or NSEC3 that covers the name
  589. const isc::dns::ConstRRsetPtr closest_proof;
  590. /// When non NULL, NSEC3 for the next closer name.
  591. const isc::dns::ConstRRsetPtr next_proof;
  592. };
  593. /// Search the zone for the NSEC3 RR(s) that prove existence or non
  594. /// existence of a give name.
  595. ///
  596. /// It searches the NSEC3 namespace of the zone (how that namespace is
  597. /// implemented can vary in specific data source implementation) for NSEC3
  598. /// RRs that match or cover the NSEC3 hash value for the given name.
  599. ///
  600. /// If \c recursive is false, it will first look for the NSEC3 that has
  601. /// a matching hash. If it doesn't exist, it identifies the covering NSEC3
  602. /// for the hash. In either case the search stops at that point and the
  603. /// found NSEC3 RR(set) will be returned in the closest_proof member of
  604. /// \c FindNSEC3Result. \c matched is true or false depending on
  605. /// the found NSEC3 is a matched one or covering one. \c next_proof
  606. /// is always NULL. closest_labels must be equal to the number of
  607. /// labels of \c name (and therefore meaningless).
  608. ///
  609. /// If \c recursive is true, it will continue the search toward the zone
  610. /// apex (origin name) until it finds a provable encloser, that is,
  611. /// an ancestor of \c name that has a matching NSEC3. This is the closest
  612. /// provable encloser of \c name as defined in RFC5155. In this case,
  613. /// if the found encloser is not equal to \c name, the search should
  614. /// have seen a covering NSEC3 for the immediate child of the found
  615. /// encloser. That child name is the next closer name as defined in
  616. /// RFC5155. In this case, this method returns the NSEC3 for the
  617. /// closest encloser in \c closest_proof, and the NSEC3 for the next
  618. /// closer name in \c next_proof of \c FindNSEC3Result. This set of
  619. /// NSEC3 RRs provide the closest encloser proof as defined in RFC5155.
  620. /// closest_labels will be set to the number of labels of the identified
  621. /// closest encloser. This will be useful when the caller needs to
  622. /// construct the closest encloser name from the original \c name.
  623. /// If, on the other hand, the found closest name is equal to \c name,
  624. /// this method simply returns it in \c closest_proof. \c next_proof
  625. /// is set to NULL. In all cases \c matched is set to true.
  626. /// closest_labels will be set to the number of labels of \c name.
  627. ///
  628. /// When looking for NSEC3, this method retrieves NSEC3 parameters from
  629. /// the corresponding zone to calculate hash values. Actual implementation
  630. /// of how to do this will differ in different data sources. If the
  631. /// NSEC3 parameters are not available \c DataSourceError exception
  632. /// will be thrown.
  633. ///
  634. /// \note This implicitly means this method assumes the zone does not
  635. /// have more than one set of parameters. This assumption should be
  636. /// reasonable in actual deployment and will help simplify the interface
  637. /// and implementation. But if there's a real need for supporting
  638. /// multiple sets of parameters in a single zone, we will have to
  639. /// extend this method so that, e.g., the caller can specify the parameter
  640. /// set.
  641. ///
  642. /// In general, this method expects the zone is properly signed with NSEC3
  643. /// RRs. Specifically, it assumes at least the apex node has a matching
  644. /// NSEC3 RR (so the search in the recursive mode must always succeed);
  645. /// it also assumes that it can retrieve NSEC parameters (iterations,
  646. /// algorithm, and salt) from the zone as noted above. If these
  647. /// assumptions aren't met, \c DataSourceError exception will be thrown.
  648. ///
  649. /// \exception OutOfZone name is not a subdomain of the zone origin
  650. /// \exception DataSourceError Low-level or internal datasource errors
  651. /// happened, or the zone isn't properly signed with NSEC3
  652. /// (NSEC3 parameters cannot be found, no NSEC3s are available, etc).
  653. /// \exception std::bad_alloc The underlying implementation involves
  654. /// memory allocation and it fails
  655. ///
  656. /// \param name The name for which NSEC3 RRs are to be found. It must
  657. /// be a subdomain of the zone.
  658. /// \param recursive Whether or not search should continue until it finds
  659. /// a provable encloser (see above).
  660. ///
  661. /// \return The search result and whether or not the closest_proof is
  662. /// a matching NSEC3, in the form of \c FindNSEC3Result object.
  663. virtual FindNSEC3Result
  664. findNSEC3(const isc::dns::Name& name, bool recursive) = 0;
  665. //@}
  666. };
  667. /// \brief Operator to combine FindOptions
  668. ///
  669. /// We would need to manually static-cast the options if we put or
  670. /// between them, which is undesired with bit-flag options. Therefore
  671. /// we hide the cast here, which is the simplest solution and it still
  672. /// provides reasonable level of type safety.
  673. inline ZoneFinder::FindOptions operator |(ZoneFinder::FindOptions a,
  674. ZoneFinder::FindOptions b)
  675. {
  676. return (static_cast<ZoneFinder::FindOptions>(static_cast<unsigned>(a) |
  677. static_cast<unsigned>(b)));
  678. }
  679. /// \brief Operator to combine FindResultFlags
  680. ///
  681. /// Similar to the same operator for \c FindOptions. Refer to the description
  682. /// of that function.
  683. inline ZoneFinder::FindResultFlags operator |(
  684. ZoneFinder::FindResultFlags a,
  685. ZoneFinder::FindResultFlags b)
  686. {
  687. return (static_cast<ZoneFinder::FindResultFlags>(
  688. static_cast<unsigned>(a) | static_cast<unsigned>(b)));
  689. }
  690. /// \brief A pointer-like type pointing to a \c ZoneFinder object.
  691. typedef boost::shared_ptr<ZoneFinder> ZoneFinderPtr;
  692. /// \brief A pointer-like type pointing to an immutable \c ZoneFinder object.
  693. typedef boost::shared_ptr<const ZoneFinder> ConstZoneFinderPtr;
  694. /// \brief A pointer-like type pointing to a \c ZoneFinder::Context object.
  695. typedef boost::shared_ptr<ZoneFinder::Context> ZoneFinderContextPtr;
  696. /// \brief A pointer-like type pointing to an immutable
  697. /// \c ZoneFinder::Context object.
  698. typedef boost::shared_ptr<ZoneFinder::Context> ConstZoneFinderContextPtr;
  699. /// \brief A forward declaration
  700. class RRsetCollectionBase;
  701. /// The base class to make updates to a single zone.
  702. ///
  703. /// On construction, each derived class object will start a "transaction"
  704. /// for making updates to a specific zone (this means a constructor of
  705. /// a derived class would normally take parameters to identify the zone
  706. /// to be updated). The underlying realization of a "transaction" will differ
  707. /// for different derived classes; if it uses a general purpose database
  708. /// as a backend, it will involve performing some form of "begin transaction"
  709. /// statement for the database.
  710. ///
  711. /// Updates (adding or deleting RRs) are made via \c addRRset() and
  712. /// \c deleteRRset() methods. Until the \c commit() method is called the
  713. /// changes are local to the updater object. For example, they won't be
  714. /// visible via a \c ZoneFinder object except the one returned by the
  715. /// updater's own \c getFinder() method. The \c commit() completes the
  716. /// transaction and makes the changes visible to others.
  717. ///
  718. /// This class does not provide an explicit "rollback" interface. If
  719. /// something wrong or unexpected happens during the updates and the
  720. /// caller wants to cancel the intermediate updates, the caller should
  721. /// simply destruct the updater object without calling \c commit().
  722. /// The destructor is supposed to perform the "rollback" operation,
  723. /// depending on the internal details of the derived class.
  724. ///
  725. /// \note This initial implementation provides a quite simple interface of
  726. /// adding and deleting RRs (see the description of the related methods).
  727. /// It may be revisited as we gain more experiences.
  728. class ZoneUpdater {
  729. protected:
  730. /// The default constructor.
  731. ///
  732. /// This is intentionally defined as protected to ensure that this base
  733. /// class is never instantiated directly.
  734. ZoneUpdater() {}
  735. public:
  736. /// The destructor
  737. ///
  738. /// Each derived class implementation must ensure that if \c commit()
  739. /// has not been performed by the time of the call to it, then it
  740. /// "rollbacks" the updates made via the updater so far.
  741. virtual ~ZoneUpdater() {}
  742. /// Return a finder for the zone being updated.
  743. ///
  744. /// The returned finder provides the functionalities of \c ZoneFinder
  745. /// for the zone as updates are made via the updater. That is, before
  746. /// making any update, the finder will be able to find all RRsets that
  747. /// exist in the zone at the time the updater is created. If RRsets
  748. /// are added or deleted via \c addRRset() or \c deleteRRset(),
  749. /// this finder will find the added ones or miss the deleted ones
  750. /// respectively.
  751. ///
  752. /// The finder returned by this method is effective only while the updates
  753. /// are performed, i.e., from the construction of the corresponding
  754. /// updater until \c commit() is performed or the updater is destructed
  755. /// without commit. The result of a subsequent call to this method (or
  756. /// the use of the result) after that is undefined.
  757. ///
  758. /// \return A reference to a \c ZoneFinder for the updated zone
  759. virtual ZoneFinder& getFinder() = 0;
  760. /// Return an RRsetCollection for the updater.
  761. ///
  762. /// This method returns an \c RRsetCollection for the updater,
  763. /// implementing the \c isc::datasrc::RRsetCollectionBase
  764. /// interface. Typically, the returned \c RRsetCollection is a
  765. /// singleton for its \c ZoneUpdater. The returned RRsetCollection
  766. /// object must not be used after its corresponding \c ZoneUpdater
  767. /// has been destroyed. The returned RRsetCollection object may be
  768. /// used to search RRsets from the ZoneUpdater. The actual
  769. /// \c RRsetCollection returned has a behavior dependent on the
  770. /// \c ZoneUpdater implementation.
  771. ///
  772. /// The behavior of the RRsetCollection is similar to the behavior
  773. /// of the \c Zonefinder returned by \c getFinder(). In fact, it's
  774. /// redundant in a sense because one can implement the
  775. /// \c dns::RRsetCollectionBase interface using an updater and
  776. /// \c getFinder() interface (unless it's expected to support zone
  777. /// iteration, and the initial implementation of the `RRsetCollection`
  778. /// returned by this method doesn't support it). We still provide it
  779. /// as an updater's method so it will be easier for an updater
  780. /// implementation to customize the `RRsetCollection` implementation,
  781. /// and also for making it easy to impose restrictions described below.
  782. ///
  783. /// Specific data sources may have special restrictions. That's
  784. /// especially the case for database-based data sources. Such
  785. /// restrictions may also result in limiting the usage of the
  786. /// `RRsetCollection` as described in the following paragraphs. A
  787. /// specific updater implementation may provide more flexible
  788. /// behavior, but applications using this interface must assume
  789. /// the most restricted case unless it knows it uses a particular
  790. /// specialized updater implementation that loosens specific restrictions.
  791. ///
  792. /// To summarize the restrictions:
  793. /// - An application must not add or delete RRsets after
  794. /// \c getRRsetCollection() is called.
  795. /// - An application must not use the returned collection from
  796. /// \c getRRsetCollection() once \c commit() is called on the updater
  797. /// that generates the collection.
  798. ///
  799. /// Implementations of \c ZoneUpdater may not allow adding or
  800. /// deleting RRsets after \c getRRsetCollection() is called. This is
  801. /// because if an iterator of the collection is being used at that time
  802. /// the modification to the zone may break an internal assumption of the
  803. /// iterator and may result in unexpected behavior. Also, the iterator
  804. /// may conceptually hold a "reader lock" of the zone (in an implementation
  805. /// dependent manner), which would prevent the addition or deletion,
  806. /// surprising the caller (who would normally expect it to succeed).
  807. ///
  808. /// Implementations of \c ZoneUpdater may disable a previously returned
  809. /// \c RRsetCollection after \c commit() is called. This is because
  810. /// the returned \c RRsetCollection may internally rely on the conceptual
  811. /// transaction of the updater that generates the collection (which would
  812. /// be literally the case for database-based data sources), and once
  813. /// the transaction is committed anything that relies on it won't be valid.
  814. /// If an \c RRsetCollection is disabled, using methods such as \c find()
  815. /// and using its iterator would cause an exception to be thrown. See
  816. /// \c isc::datasrc::RRsetCollectionBase for details.
  817. virtual isc::datasrc::RRsetCollectionBase& getRRsetCollection() = 0;
  818. /// Add an RRset to a zone via the updater
  819. ///
  820. /// This may be revisited in a future version, but right now the intended
  821. /// behavior of this method is simple: It "naively" adds the specified
  822. /// RRset to the zone specified on creation of the updater.
  823. /// It performs minimum level of validation on the specified RRset:
  824. /// - Whether the RR class is identical to that for the zone to be updated
  825. /// - Whether the RRset is not empty, i.e., it has at least one RDATA
  826. /// - Whether the RRset is not associated with an RRSIG, i.e.,
  827. /// whether \c getRRsig() on the RRset returns a NULL pointer.
  828. ///
  829. /// and otherwise does not check any oddity. For example, it doesn't
  830. /// check whether the owner name of the specified RRset is a subdomain
  831. /// of the zone's origin; it doesn't care whether or not there is already
  832. /// an RRset of the same name and RR type in the zone, and if there is,
  833. /// whether any of the existing RRs have duplicate RDATA with the added
  834. /// ones. If these conditions matter the calling application must examine
  835. /// the existing data beforehand using the \c ZoneFinder returned by
  836. /// \c getFinder().
  837. ///
  838. /// The validation requirement on the associated RRSIG is temporary.
  839. /// If we find it more reasonable and useful to allow adding a pair of
  840. /// RRset and its RRSIG RRset as we gain experiences with the interface,
  841. /// we may remove this restriction. Until then we explicitly check it
  842. /// to prevent accidental misuse.
  843. ///
  844. /// Conceptually, on successful call to this method, the zone will have
  845. /// the specified RRset, and if there is already an RRset of the same
  846. /// name and RR type, these two sets will be "merged". "Merged" means
  847. /// that a subsequent call to \c ZoneFinder::find() for the name and type
  848. /// will result in success and the returned RRset will contain all
  849. /// previously existing and newly added RDATAs with the TTL being the
  850. /// minimum of the two RRsets. The underlying representation of the
  851. /// "merged" RRsets may vary depending on the characteristic of the
  852. /// underlying data source. For example, if it uses a general purpose
  853. /// database that stores each RR of the same RRset separately, it may
  854. /// simply be a larger sets of RRs based on both the existing and added
  855. /// RRsets; the TTLs of the RRs may be different within the database, and
  856. /// there may even be duplicate RRs in different database rows. As long
  857. /// as the RRset returned via \c ZoneFinder::find() conforms to the
  858. /// concept of "merge", the actual internal representation is up to the
  859. /// implementation.
  860. ///
  861. /// This method must not be called once commit() is performed. If it
  862. /// calls after \c commit() the implementation must throw a
  863. /// \c DataSourceError exception.
  864. ///
  865. /// Implementations of \c ZoneUpdater may not allow adding or
  866. /// deleting RRsets after \c getRRsetCollection() is called (see
  867. /// the description of \c getRRsetCollection()). In this case,
  868. /// implementations throw an \c InvalidOperation exception.
  869. ///
  870. /// If journaling was requested when getting this updater, it will reject
  871. /// to add the RRset if the squence doesn't look like and IXFR (see
  872. /// DataSourceClient::getUpdater). In such case isc::BadValue is thrown.
  873. ///
  874. /// \todo As noted above we may have to revisit the design details as we
  875. /// gain experiences:
  876. ///
  877. /// - we may want to check (and maybe reject) if there is already a
  878. /// duplicate RR (that has the same RDATA).
  879. /// - we may want to check (and maybe reject) if there is already an
  880. /// RRset of the same name and RR type with different TTL
  881. /// - we may even want to check if there is already any RRset of the
  882. /// same name and RR type.
  883. /// - we may want to add an "options" parameter that can control the
  884. /// above points
  885. /// - we may want to have this method return a value containing the
  886. /// information on whether there's a duplicate, etc.
  887. ///
  888. /// \exception DataSourceError Called after \c commit(), RRset is invalid
  889. /// (see above), internal data source error
  890. /// \exception isc::BadValue Journaling is enabled and the current RRset
  891. /// doesn't fit into the IXFR sequence (see above).
  892. /// \exception std::bad_alloc Resource allocation failure
  893. ///
  894. /// \param rrset The RRset to be added
  895. virtual void addRRset(const isc::dns::AbstractRRset& rrset) = 0;
  896. /// Delete an RRset from a zone via the updater
  897. ///
  898. /// Like \c addRRset(), the detailed semantics and behavior of this method
  899. /// may have to be revisited in a future version. The following are
  900. /// based on the initial implementation decisions.
  901. ///
  902. /// On successful completion of this method, it will remove from the zone
  903. /// the RRs of the specified owner name and RR type that match one of
  904. /// the RDATAs of the specified RRset. There are several points to be
  905. /// noted:
  906. /// - Existing RRs that don't match any of the specified RDATAs will
  907. /// remain in the zone.
  908. /// - Any RRs of the specified RRset that doesn't exist in the zone will
  909. /// simply be ignored; the implementation of this method is not supposed
  910. /// to check that condition.
  911. /// - The TTL of the RRset is ignored; matching is only performed by
  912. /// the owner name, RR type and RDATA
  913. ///
  914. /// Ignoring the TTL may not look sensible, but it's based on the
  915. /// observation that it will result in more intuitive result, especially
  916. /// when the underlying data source is a general purpose database.
  917. /// See also \c DatabaseAccessor::deleteRecordInZone() on this point.
  918. /// It also matches the dynamic update protocol (RFC2136), where TTLs
  919. /// are ignored when deleting RRs.
  920. ///
  921. /// \note Since the TTL is ignored, this method could take the RRset
  922. /// to be deleted as a tuple of name, RR type, and a list of RDATAs.
  923. /// But in practice, it's quite likely that the caller has the RRset
  924. /// in the form of the \c RRset object (e.g., extracted from a dynamic
  925. /// update request message), so this interface would rather be more
  926. /// convenient. If it turns out not to be true we can change or extend
  927. /// the method signature.
  928. ///
  929. /// This method performs minimum level of validation on the specified
  930. /// RRset:
  931. /// - Whether the RR class is identical to that for the zone to be updated
  932. /// - Whether the RRset is not empty, i.e., it has at least one RDATA
  933. /// - Whether the RRset is not associated with an RRSIG, i.e.,
  934. /// whether \c getRRsig() on the RRset returns a NULL pointer.
  935. ///
  936. /// This method must not be called once commit() is performed. If it
  937. /// calls after \c commit() the implementation must throw a
  938. /// \c DataSourceError exception.
  939. ///
  940. /// Implementations of \c ZoneUpdater may not allow adding or
  941. /// deleting RRsets after \c getRRsetCollection() is called (see
  942. /// the description of \c getRRsetCollection()). In this case,
  943. /// implementations throw an \c InvalidOperation exception.
  944. ///
  945. /// If journaling was requested when getting this updater, it will reject
  946. /// to add the RRset if the squence doesn't look like and IXFR (see
  947. /// DataSourceClient::getUpdater). In such case isc::BadValue is thrown.
  948. ///
  949. /// \todo As noted above we may have to revisit the design details as we
  950. /// gain experiences:
  951. ///
  952. /// - we may want to check (and maybe reject) if some or all of the RRs
  953. /// for the specified RRset don't exist in the zone
  954. /// - we may want to allow an option to "delete everything" for specified
  955. /// name and/or specified name + RR type.
  956. /// - as mentioned above, we may want to include the TTL in matching the
  957. /// deleted RRs
  958. /// - we may want to add an "options" parameter that can control the
  959. /// above points
  960. /// - we may want to have this method return a value containing the
  961. /// information on whether there's any RRs that are specified but don't
  962. /// exit, the number of actually deleted RRs, etc.
  963. ///
  964. /// \exception DataSourceError Called after \c commit(), RRset is invalid
  965. /// (see above), internal data source error
  966. /// \exception isc::BadValue Journaling is enabled and the current RRset
  967. /// doesn't fit into the IXFR sequence (see above).
  968. /// \exception std::bad_alloc Resource allocation failure
  969. ///
  970. /// \param rrset The RRset to be deleted
  971. virtual void deleteRRset(const isc::dns::AbstractRRset& rrset) = 0;
  972. /// Commit the updates made in the updater to the zone
  973. ///
  974. /// This method completes the "transaction" started at the creation
  975. /// of the updater. After successful completion of this method, the
  976. /// updates will be visible outside the scope of the updater.
  977. /// The actual internal behavior will defer for different derived classes.
  978. /// For a derived class with a general purpose database as a backend,
  979. /// for example, this method would perform a "commit" statement for the
  980. /// database.
  981. ///
  982. /// This operation can only be performed at most once. A duplicate call
  983. /// must result in a DatasourceError exception.
  984. ///
  985. /// \exception DataSourceError Duplicate call of the method,
  986. /// internal data source error
  987. /// \exception isc::BadValue Journaling is enabled and the update is not
  988. /// complete IXFR sequence.
  989. virtual void commit() = 0;
  990. };
  991. /// \brief A pointer-like type pointing to a \c ZoneUpdater object.
  992. typedef boost::shared_ptr<ZoneUpdater> ZoneUpdaterPtr;
  993. /// The base class for retrieving differences between two versions of a zone.
  994. ///
  995. /// On construction, each derived class object will internally set up
  996. /// retrieving sequences of differences between two specific version of
  997. /// a specific zone managed in a particular data source. So the constructor
  998. /// of a derived class would normally take parameters to identify the zone
  999. /// and the two versions for which the differences should be retrieved.
  1000. /// See \c DataSourceClient::getJournalReader for more concrete details
  1001. /// used in this API.
  1002. ///
  1003. /// Once constructed, an object of this class will act like an iterator
  1004. /// over the sequences. Every time the \c getNextDiff() method is called
  1005. /// it returns one element of the differences in the form of an \c RRset
  1006. /// until it reaches the end of the entire sequences.
  1007. class ZoneJournalReader {
  1008. public:
  1009. /// Result codes used by a factory method for \c ZoneJournalReader
  1010. enum Result {
  1011. SUCCESS, ///< A \c ZoneJournalReader object successfully created
  1012. NO_SUCH_ZONE, ///< Specified zone does not exist in the data source
  1013. NO_SUCH_VERSION ///< Specified versions do not exist in the diff storage
  1014. };
  1015. protected:
  1016. /// The default constructor.
  1017. ///
  1018. /// This is intentionally defined as protected to ensure that this base
  1019. /// class is never instantiated directly.
  1020. ZoneJournalReader() {}
  1021. public:
  1022. /// The destructor
  1023. virtual ~ZoneJournalReader() {}
  1024. /// Return the next difference RR of difference sequences.
  1025. ///
  1026. /// In this API, the difference between two versions of a zone is
  1027. /// conceptually represented as IXFR-style difference sequences:
  1028. /// Each difference sequence is a sequence of RRs: an older version of
  1029. /// SOA (to be deleted), zero or more other deleted RRs, the
  1030. /// post-transaction SOA (to be added), and zero or more other
  1031. /// added RRs. (Note, however, that the underlying data source
  1032. /// implementation may or may not represent the difference in
  1033. /// straightforward realization of this concept. The mapping between
  1034. /// the conceptual difference and the actual implementation is hidden
  1035. /// in each derived class).
  1036. ///
  1037. /// This method provides an application with a higher level interface
  1038. /// to retrieve the difference along with the conceptual model: the
  1039. /// \c ZoneJournalReader object iterates over the entire sequences
  1040. /// from the beginning SOA (which is to be deleted) to one of the
  1041. /// added RR of with the ending SOA, and each call to this method returns
  1042. /// one RR in the form of an \c RRset that contains exactly one RDATA
  1043. /// in the order of the sequences.
  1044. ///
  1045. /// Note that the ordering of the sequences specifies the semantics of
  1046. /// each difference: add or delete. For example, the first RR is to
  1047. /// be deleted, and the last RR is to be added. So the return value
  1048. /// of this method does not explicitly indicate whether the RR is to be
  1049. /// added or deleted.
  1050. ///
  1051. /// This method ensures the returned \c RRset represents an RR, that is,
  1052. /// it contains exactly one RDATA. However, it does not necessarily
  1053. /// ensure that the resulting sequences are in the form of IXFR-style.
  1054. /// For example, the first RR is supposed to be an SOA, and it should
  1055. /// normally be the case, but this interface does not necessarily require
  1056. /// the derived class implementation ensure this. Normally the
  1057. /// differences are expected to be stored using this API (via a
  1058. /// \c ZoneUpdater object), and as long as that is the case and the
  1059. /// underlying implementation follows the requirement of the API, the
  1060. /// result of this method should be a valid IXFR-style sequences.
  1061. /// So this API does not mandate the almost redundant check as part of
  1062. /// the interface. If the application needs to make it sure 100%, it
  1063. /// must check the resulting sequence itself.
  1064. ///
  1065. /// Once the object reaches the end of the sequences, this method returns
  1066. /// \c Null. Any subsequent call will result in an exception of
  1067. /// class \c InvalidOperation.
  1068. ///
  1069. /// \exception InvalidOperation The method is called beyond the end of
  1070. /// the difference sequences.
  1071. /// \exception DataSourceError Underlying data is broken and the RR
  1072. /// cannot be created or other low level data source error.
  1073. ///
  1074. /// \return An \c RRset that contains one RDATA corresponding to the
  1075. /// next difference in the sequences.
  1076. virtual isc::dns::ConstRRsetPtr getNextDiff() = 0;
  1077. };
  1078. /// \brief A pointer-like type pointing to a \c ZoneUpdater object.
  1079. typedef boost::shared_ptr<ZoneJournalReader> ZoneJournalReaderPtr;
  1080. } // end of datasrc
  1081. } // end of isc
  1082. #endif // ZONE_H
  1083. // Local Variables:
  1084. // mode: c++
  1085. // End: