zone.h 33 KB

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