zone.h 52 KB

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