zone_data.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. // Copyright (C) 2012 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 DATASRC_MEMORY_ZONE_DATA_H
  15. #define DATASRC_MEMORY_ZONE_DATA_H 1
  16. #include <util/memory_segment.h>
  17. #include <dns/name.h>
  18. #include <dns/rrclass.h>
  19. #include <datasrc/memory/domaintree.h>
  20. #include <datasrc/memory/rdataset.h>
  21. #include <boost/interprocess/offset_ptr.hpp>
  22. #include <boost/noncopyable.hpp>
  23. #include <vector>
  24. namespace isc {
  25. namespace dns {
  26. namespace rdata {
  27. namespace generic {
  28. class NSEC3PARAM;
  29. class NSEC3;
  30. }
  31. }
  32. }
  33. namespace datasrc {
  34. namespace memory {
  35. typedef DomainTree<RdataSet> ZoneTree;
  36. typedef DomainTreeNode<RdataSet> ZoneNode;
  37. /// \brief NSEC3 data for a DNS zone.
  38. ///
  39. /// This class encapsulates a set of NSEC3 related data for a zone
  40. /// that is signed with NSEC3 RRs. Specifically, it contains hash
  41. /// parameters as given in an NSEC3PARAM RDATA and all NSEC3 RRs of the zone.
  42. ///
  43. /// The main concept of the class is generally the same as that of
  44. /// \c ZoneData (see its description for details), but the related data
  45. //// are encapsulated in a more straightforward way in this class.
  46. ///
  47. /// The NSEC3 RRs (which should normally have RRSIGs) are stored in a
  48. /// \c DomainTree object whose data type is (a list of) \c RdataSet.
  49. /// This tree is expected to store NSEC3 RRs only, so the RR type of
  50. /// \c RdataSet should be NSEC3. But this class itself doesn't guarantee
  51. /// this condition. It's the caller's responsibility.
  52. ///
  53. /// Read-only access to the tree is possible via the \c getNSEC3Tree() method.
  54. /// Modifying the tree must be done by a specific method (in the initial
  55. /// implementation, it's \c insertName(). There may be some more as we
  56. /// see the need); the application cannot directly change the content of the
  57. /// tree in an arbitrary way. This class does not have a strong reason to be
  58. /// that strict, but is defined this way mainly to be consistent with the
  59. /// \c ZoneData class.
  60. ///
  61. /// Most of the hash parameters are maintained in the form of straightforward
  62. /// member variables, which can be directly referenced by the application.
  63. /// The exception is the salt, which is encapsulated as opaque data
  64. /// immediately following the main class object, and should be accessible
  65. /// via the \c getSaltLen() and \c getSaltData() method.
  66. ///
  67. /// \note The fact that the this class couples one set of hash parameters
  68. /// and the set of NSEC3 RRs implicitly means a zone is assumed to have
  69. /// only one set of NSEC3 parameters. When we support multiple sets of
  70. /// parameters the design should be revised accordingly.
  71. class NSEC3Data : boost::noncopyable {
  72. public:
  73. /// \brief Allocate and construct \c NSEC3Data from NSEC3PARAM Rdata.
  74. ///
  75. /// The NSEC3 parameters are extracted and stored within the created
  76. /// \c NSEC3Data object.
  77. ///
  78. /// \throw std::bad_alloc Memory allocation fails.
  79. ///
  80. /// \param mem_sgmt A \c MemorySegment from which memory for the new
  81. /// \c NSEC3Data is allocated.
  82. /// \param rdata An NSEC3PARAM RDATA that specifies the NSEC3 parameters
  83. /// to be stored.
  84. static NSEC3Data* create(util::MemorySegment& mem_sgmt,
  85. const dns::rdata::generic::NSEC3PARAM& rdata);
  86. /// \brief Allocate and construct \c NSEC3Data from NSEC3 Rdata.
  87. ///
  88. /// The NSEC3 hash parameters are extracted and stored within the created
  89. /// \c NSEC3Data object.
  90. ///
  91. /// \throw std::bad_alloc Memory allocation fails.
  92. ///
  93. /// \param mem_sgmt A \c MemorySegment from which memory for the new
  94. /// \c NSEC3Data is allocated.
  95. /// \param rdata An NSEC3 RDATA that specifies the NSEC3 parameters
  96. /// to be stored.
  97. static NSEC3Data* create(util::MemorySegment& mem_sgmt,
  98. const dns::rdata::generic::NSEC3& rdata);
  99. /// \brief Destruct and deallocate \c NSEC3Data.
  100. ///
  101. /// It releases all resources allocated for the internal NSEC3 name space
  102. /// including NSEC3 RdataSet. It assumes \c RdataSets objects stored
  103. /// in the space were allocated using the same memory segment as
  104. /// \c mem_sgmt. The caller must ensure this assumption.
  105. ///
  106. /// Note that an \c RRClass object must be passed to this method.
  107. /// It's necessary to destroy the stored \c RdataSet objects
  108. /// (see its class description). This class doesn't hold this information;
  109. /// it's the caller's responsibility to associate an \c NSEC3Data
  110. /// class object with its expected RR class, and pass it to
  111. /// \c destroy(). (In practice, it will be passed via
  112. /// \c ZoneData::destroy().)
  113. ///
  114. /// \throw none
  115. ///
  116. /// \param mem_sgmt The \c MemorySegment that allocated memory for
  117. /// \c data.
  118. /// \param data A non-NULL pointer to a valid NSEC3Data object
  119. /// that was originally created by the \c create() method (the behavior
  120. /// is undefined if this condition isn't met).
  121. /// \param nsec3_class The RR class of the \c RdataSet stored in the NSEC3
  122. /// name space to be destroyed.
  123. static void destroy(util::MemorySegment& mem_sgmt, NSEC3Data* data,
  124. dns::RRClass nsec3_class);
  125. private:
  126. // Domain tree for the Internal NSEC3 name space. Access to it is
  127. // limited only via public methods.
  128. const boost::interprocess::offset_ptr<ZoneTree> nsec3_tree_;
  129. public:
  130. const uint8_t hashalg; ///< Hash algorithm
  131. const uint8_t flags; ///< NSEC3 parameter flags
  132. const uint16_t iterations; ///< Hash iterations
  133. // For 64-bit machines there'll be padding space here, but since
  134. // only at most one instance (or a few in very rare cases) will be
  135. // created per zone, the overhead should be acceptable.
  136. /// \brief Return \c ZoneTree for the NSEC3 name space.
  137. ///
  138. /// \throw none
  139. const ZoneTree& getNSEC3Tree() const { return (*nsec3_tree_); }
  140. /// \brief Return the size of NSEC3 salt.
  141. ///
  142. /// \throw none
  143. ///
  144. /// The return value must be in the range between 0 and 255 (inclusive).
  145. size_t getSaltLen() const { return (*getSaltBuf()); }
  146. /// \brief Return a pointer to the salt data.
  147. ///
  148. /// \throw none
  149. ///
  150. /// The valid range is up to the \c getSaltLen() bytes from the
  151. /// returned value. If \c getSaltLen() returns 0, the return value
  152. /// of this method is invalid and must not be used.
  153. const uint8_t* getSaltData() const { return (getSaltBuf() + 1); }
  154. /// \brief Insert a name to the NSEC3 name space.
  155. ///
  156. /// It allocates resource for the given name in the internal NSEC3 name
  157. /// space, and returns an access point to it in the form of \c ZoneNode
  158. /// pointer via the given \c node variable. If the name already exists
  159. /// in the name space, it returns a pointer to the existing node.
  160. ///
  161. /// This method does not perform any semantics check on the given name
  162. /// (e.g., whether the first label is a valid encoded string for an NSEC3
  163. /// owner name).
  164. ///
  165. /// \throw std::bad_alloc Memory allocation fails
  166. ///
  167. /// \param mem_sgmt Memory segment in which resource for the new memory
  168. /// is to be allocated.
  169. /// \param name The name to be inserted.
  170. /// \param node A pointer to \c ZoneNode pointer in which the created or
  171. /// found node for the name is stored. Must not be NULL (the method does
  172. /// not check that condition).
  173. void insertName(util::MemorySegment& mem_sgmt, const dns::Name& name,
  174. ZoneNode** node);
  175. private:
  176. // Common subroutine for the public versions of create().
  177. static NSEC3Data* create(util::MemorySegment& mem_sgmt, uint8_t hashalg,
  178. uint8_t flags, uint16_t iterations,
  179. const std::vector<uint8_t>& salt);
  180. /// \brief The constructor.
  181. ///
  182. /// An object of this class is always expected to be created by the
  183. /// allocator (\c create()), so the constructor is hidden as private.
  184. ///
  185. /// It never throws an exception.
  186. NSEC3Data(ZoneTree* nsec3_tree_param, uint8_t hashalg_param,
  187. uint8_t flags_param, uint16_t iterations_param) :
  188. nsec3_tree_(nsec3_tree_param), hashalg(hashalg_param),
  189. flags(flags_param), iterations(iterations_param)
  190. {}
  191. const uint8_t* getSaltBuf() const {
  192. return (reinterpret_cast<const uint8_t*>(this + 1));
  193. }
  194. uint8_t* getSaltBuf() {
  195. return (reinterpret_cast<uint8_t*>(this + 1));
  196. }
  197. };
  198. /// \brief DNS zone data.
  199. ///
  200. /// This class encapsulates the content of a DNS zone (which is essentially a
  201. /// set of RRs) in a memory efficient way and provides accessor interfaces
  202. /// to it.
  203. ///
  204. /// The primary goal of this class is to provide a packed structure of the
  205. /// data for memory efficiency. Basically, this class should be considered
  206. /// a private part of some other classes within this module and should not
  207. /// be used directly from normal applications. So it's not intended to hide
  208. /// much of the underlying implementation details; rather, it tries
  209. /// to keep the representation simple.
  210. ///
  211. /// The RRs are stored in a \c DomainTree object whose data type is
  212. /// (a list of) \c RdataSet. The tree nodes correspond to owner names,
  213. /// and the \c RdataSet objects (forming a linked list) set in the node
  214. /// represent the rest of the RR parameters except the RR class: type,
  215. /// TTL, and RDATA. This class does not have any knowledge of the RR class
  216. /// of the zone; since it's quite likely that the application maintains
  217. /// a set of zones of the same RR class, and the number of such zones can be
  218. /// huge, it makes more sense to have the application maintain the class value
  219. /// in a unified way to minimize memory footprint.
  220. ///
  221. /// The \c DomainTree object in this class is not expected to hold NSEC3
  222. /// RRs when the zone is signed with NSEC3; they should be maintained
  223. /// in an associated \c NSEC3Data object. But this class does not prevent
  224. /// the unexpected usage of adding an NSEC3 RdataSet directly in the tree.
  225. /// It's the caller's responsibility to ensure this assumption.
  226. ///
  227. /// This class maintains some other meta data and additional zone related
  228. /// content. First, it automatically creates a \c DomainTree node for the
  229. /// zone's origin name on initialization and keeps a reference to it
  230. /// throughout its lifetime. This is the case even if the zone doesn't have
  231. /// any RRs (such as in the case before initial loading). Any valid zone
  232. /// to be served should have an RR at the origin node (at least SOA, for
  233. /// example), so this assumption should be reasonable. But the application
  234. /// must ensure that any \c ZoneData object in actual use should have an
  235. /// RR at the origin; otherwise the inconsistency between the internal state
  236. /// and the actual zone content could lead to unexpected disruption.
  237. /// In particular, it must be careful when it supports dynamic updates
  238. /// to an existing zone so an update attempt doesn't result in deleting
  239. /// the origin node.
  240. ///
  241. /// To ensure integrity regarding the reference to the origin, write
  242. /// access to the tree node can be done only by public methods; the member
  243. /// variable for the tree is hidden as private. On the other hand, read-only
  244. /// access to the tree is allowed via the const version of \c getZoneTree()
  245. /// method for the convenience of the application. So, it's intentional
  246. /// that there's no non-const version of this method. Do not add one
  247. /// when this class is to be extended.
  248. ///
  249. /// Another type of meta data is parameters and records of NSEC3 RRs
  250. /// when the zone is signed with NSEC3. It's represented in the form of
  251. /// an \c NSEC3Data object, and a \c ZoneData object may be associated with
  252. /// 0 or 1 \c NSEC3Data objects using the \c setNSEC3Data() method, which
  253. /// can be retrieved by the \c getNSEC3Data() method. If the \c ZoneData
  254. /// object is not associated with an \c NSEC3Data object, it's considered not
  255. /// signed with NSEC3 RRs; otherwise it's considered to be signed with
  256. /// NSEC3 RRs and with the parameters stored in the \c NSEC3Data object.
  257. ///
  258. /// \note This interpretation may change in the future when we support migration
  259. /// from NSEC to NSEC3 or vice versa, support incremental signing, or support
  260. /// multiple sets of NSEC3 parameters.
  261. ///
  262. /// One last type of meta data is the status of the zone in terms of DNSSEC
  263. /// signing. This class supports the following concepts:
  264. /// - Whether the zone is signed or not, either with NSEC records or NSEC3
  265. /// records.
  266. /// - Whether the zone has a complete set of NSEC3 records.
  267. ///
  268. /// The former status can be accessed via the \c isSigned() and \c setSigned()
  269. /// methods; the latter can be retrieved via the \c isNSEC3Signed() method.
  270. ///
  271. /// This class does not actually relate the status of signed-or-not to
  272. /// any of its other attributes; it's up to the application how to set or
  273. /// use this status and maintain it in a reasonable way. One possible
  274. /// definition is to set this status if and only if the zone has a
  275. /// DNSKEY RR at the zone origin (which is BIND 9's definition of signed
  276. /// zone). When the application adopts this definition, it's the
  277. /// application's responsibility to keep the status consistent with the
  278. /// actual existence or non-existence of a DNSKEY RR.
  279. ///
  280. /// In the current implementation, a zone is considered to have a complete
  281. /// set of NSEC3 records if and only if it's associated with an \c NSEC3Data
  282. /// object (as noted above, these concepts may be separated in future).
  283. /// For this reason there is no "set" method for the latter; setting
  284. /// an \c NSEC3Data effectively enables the latter status. \c isNSEC3Signed()
  285. /// method is still provided (even though it's a kind of trivial wrapper to
  286. /// \c getNSEC3Data()) partly for a more intuitive shortcut, and partly
  287. /// because we won't have to change the application code when we implement
  288. /// the future separation.
  289. ///
  290. /// The intended usage of these two status concepts is to implement the
  291. /// \c ZoneFinder::Context::isNSECSigned() and
  292. /// \c ZoneFinder::Context::isNSEC3Signed() methods. A possible implementation
  293. /// is as follows:
  294. /// - \c ZoneFinder::Context::isNSECSigned() returns true iff \c isSigned()
  295. /// is true and \c isNSEC3Signed() is false.
  296. /// - \c ZoneFinder::Context::isNSEC3Signed() returns true iff \c isSigned()
  297. /// is true and \c isNSEC3Signed() is true.
  298. ///
  299. /// Note that even though \c isNSEC3Signed() being true should indicate
  300. /// \c isSigned() is true too in practice, the interfaces do not
  301. /// automatically ensure that, so we'd need to check both conditions
  302. /// explicitly. And, in fact, if we adopt the above definition of
  303. /// \c isSigned(), it's possible that a zone has a complete set of NSEC3
  304. /// RRs but no DNSKEY (although it's effectively a broken zone unless we
  305. /// support incremental signing).
  306. ///
  307. /// This class is designed so an instance can be stored in a shared
  308. /// memory region. So the pointer member variables (the initial
  309. /// implementation only contains pointer member variables) are defined
  310. /// as offset pointers. When this class is extended these properties must
  311. /// be preserved, and must also meet other requirements so it can be stored
  312. /// in a shared memory region (see, for example, \c RdataSet description).
  313. /// Future extensions must also be conscious of placing the member variables
  314. /// so that they will not accidentally cause padding and increase memory
  315. /// footprint.
  316. class ZoneData : boost::noncopyable {
  317. private:
  318. /// \brief The constructor.
  319. ///
  320. /// An object of this class is always expected to be created by the
  321. /// allocator (\c create()), so the constructor is hidden as private.
  322. ///
  323. /// It never throws an exception.
  324. ZoneData(ZoneTree* zone_tree, ZoneNode* origin_node) :
  325. zone_tree_(zone_tree), origin_node_(origin_node)
  326. {}
  327. // Zone node flags.
  328. private:
  329. // Set in the origin node (which always exists at the same address)
  330. // to indicate whether the zone is signed or not. Internal use,
  331. // so defined as private.
  332. static const ZoneNode::Flags DNSSEC_SIGNED = ZoneNode::FLAG_USER1;
  333. public:
  334. /// \brief Node flag indicating it is at a "wildcard level"
  335. ///
  336. /// This means one of the node's immediate children is a wildcard.
  337. static const ZoneNode::Flags WILDCARD_NODE = ZoneNode::FLAG_USER2;
  338. public:
  339. /// \brief Allocate and construct \c ZoneData.
  340. ///
  341. /// \throw std::bad_alloc Memory allocation fails.
  342. ///
  343. /// \param mem_sgmt A \c MemorySegment from which memory for the new
  344. /// \c ZoneData is allocated.
  345. /// \param name The zone name.
  346. static ZoneData* create(util::MemorySegment& mem_sgmt,
  347. const dns::Name& zone_name);
  348. /// \brief Destruct and deallocate \c ZoneData.
  349. ///
  350. /// It releases all resource allocated in the internal storage NSEC3 for
  351. /// zone names and RdataSet objects, and if associated, the \c NSEC3Data.
  352. /// It assumes \c RdataSets objects stored in the space and the
  353. /// associated \c NSEC3Data object were allocated using the same memory
  354. /// segment as \c mem_sgmt. The caller must ensure this assumption.
  355. ///
  356. /// Note that an \c RRClass object must be passed to this method.
  357. /// It's used to destroy the stored \c RdataSet objects
  358. /// (see its class description). This class doesn't hold this information;
  359. /// it's the caller's responsibility to associate a \c ZoneData class
  360. /// object with its expected RR class, and pass it to \c destroy().
  361. ///
  362. /// \throw none
  363. ///
  364. /// \param mem_sgmt The \c MemorySegment that allocated memory for
  365. /// \c zone_data.
  366. /// \param zone_data A non-NULL pointer to a valid ZoneData object
  367. /// that was originally created by the \c create() method (the behavior
  368. /// is undefined if this condition isn't met).
  369. /// \param zone_class The RR class of the \c RdataSet stored in the
  370. /// internal tree.
  371. static void destroy(util::MemorySegment& mem_sgmt, ZoneData* zone_data,
  372. dns::RRClass zone_class);
  373. ///
  374. /// \name Getter methods
  375. ///
  376. //@{
  377. /// \brief Return zone's origin node.
  378. ///
  379. /// This is a convenience and efficient short cut to get access to the
  380. /// zone origin in the form of \c ZoneNode object.
  381. ///
  382. /// The class encapsulation ensures that the origin node always exists at
  383. /// the same address, so this method always returns a non-NULL valid
  384. /// valid pointer.
  385. ///
  386. /// \throw none
  387. const ZoneNode* getOriginNode() const {
  388. return (origin_node_.get());
  389. }
  390. /// \brief Return the zone's name space in the form of \c ZoneTree
  391. ///
  392. /// \note It's intentional that non-const version of this method
  393. /// isn't provided. See the class description.
  394. ///
  395. /// \throw none
  396. const ZoneTree& getZoneTree() const { return (*zone_tree_); }
  397. /// \brief Return whether or not the zone is signed in terms of DNSSEC.
  398. ///
  399. /// Note that this class does not care about what "signed" means.
  400. /// This method simply returns the last value set by \c setSigned()
  401. /// (or the default, which is \c false). The caller is expected to
  402. /// use this method and \c setSigned() in a reasonable, consistent way.
  403. ///
  404. /// \throw none
  405. bool isSigned() const { return (origin_node_->getFlag(DNSSEC_SIGNED)); }
  406. /// \brief Return whether or not the zone is signed with NSEC3 RRs.
  407. ///
  408. /// In the current implementation, the zone is considered signed with
  409. /// NSEC3 if and only if it has non-NULL NSEC3 data.
  410. ///
  411. /// This also means it's not considered NSEC3 signed by default.
  412. ///
  413. /// \throw none
  414. bool isNSEC3Signed() const { return (nsec3_data_); }
  415. /// \brief Return NSEC3Data of the zone.
  416. ///
  417. /// This method returns non-NULL valid pointer to \c NSEC3Data object
  418. /// associated to the \c ZoneData if it was set by \c setNSEC3Data();
  419. /// otherwise it returns NULL.
  420. ///
  421. /// \throw none
  422. const NSEC3Data* getNSEC3Data() const { return (nsec3_data_.get()); }
  423. //@}
  424. ///
  425. /// \name Methods for modifying the tree
  426. ///
  427. //@{
  428. /// \brief Insert a name to the zone.
  429. ///
  430. /// It allocates resource for the given name in the internal storage
  431. /// for zone data, and returns an access point to it in the form of
  432. /// \c ZoneNode pointer via the given \c node variable. If the name
  433. /// already exists in the name space, it returns a pointer to the existing
  434. /// node.
  435. ///
  436. /// The name to be inserted by this method is expected to belong to
  437. /// zone's "normal" (i.e., non-NSEÇ3) name space. If it's a name for
  438. /// an NSEC3 RR, it must be set in the corresponding \c NSEC3Data for
  439. /// this zone data (if it doesn't exist it must be created and set
  440. /// by \c setNSEC3Data()).
  441. ///
  442. /// The name is also expected to be a subdomain of, or equal to the
  443. /// zone's origin name (specified on creation in \c create()), but
  444. /// this method does not check that condition. The caller is responsible
  445. /// for ensuring this assumption.
  446. ///
  447. /// Since this method doesn't perform any semantics check, it always
  448. /// succeeds (except for the rare case where memory allocation
  449. /// fails) and \c node will be set to a valid pointer.
  450. ///
  451. /// \note We may want to differentiate between the case where the name is
  452. /// newly created and the case where it already existed. Right now it's
  453. /// unclear, so it doesn't return this information. If we see the need
  454. /// for it, this method can be extended that way.
  455. ///
  456. /// \throw std::bad_alloc Memory allocation fails
  457. ///
  458. /// \param mem_sgmt Memory segment in which resource for the new memory
  459. /// is to be allocated.
  460. /// \param name The name to be inserted.
  461. /// \param node A pointer to \c ZoneNode pointer in which the created or
  462. /// found node for the name is stored. Must not be NULL (the method does
  463. /// not check that condition).
  464. void insertName(util::MemorySegment& mem_sgmt, const dns::Name& name,
  465. ZoneNode** node);
  466. /// \brief Specify whether or not the zone is signed in terms of DNSSEC.
  467. ///
  468. /// The zone will be considered "signed" (in that subsequent calls to
  469. /// \c isSigned() will return \c true) iff the parameter \c on is \c true.
  470. ///
  471. /// This class does not care what "signed" actually means; it does not
  472. /// check any zone RRs to verify if the given state makes sense (e.g.
  473. /// whether the zone has a DNSKEY RR at the origin). The caller is
  474. /// expected to use this method and \c isSigned() in a reasonable,
  475. /// consistent way.
  476. ///
  477. /// \throw none
  478. void setSigned(bool on) {
  479. origin_node_->setFlag(DNSSEC_SIGNED, on);
  480. }
  481. /// \brief Return NSEC3Data of the zone, non-const version.
  482. ///
  483. /// This is similar to the const version, but return a non-const pointer
  484. /// so the caller can modify the content.
  485. ///
  486. /// \throw none
  487. NSEC3Data* getNSEC3Data() { return (nsec3_data_.get()); }
  488. /// \brief Associate \c NSEC3Data to the zone.
  489. ///
  490. /// This method associates the given \c NSEC3Data object with the zone
  491. /// data. If there was already associated \c NSEC3Data object, it will
  492. /// be returned. If no \c NSEC3Data object was associated before,
  493. /// a NULL pointer will be returned. \c nsec3_data can be NULL, in which
  494. /// case the zone will be disassociated with a \c NSEC3Data.
  495. ///
  496. /// In general, if a non-NULL pointer is passed, it's assumed that
  497. /// the \c NSEC3Data object was allocated in the same \c MemorySegment
  498. /// as that for the zone data, so the \c destroy() method can destroy
  499. /// both with the same memory segment. If this condition is not met,
  500. /// the caller must extract the associated \c NSEC3Data by calling
  501. /// this method with NULL and release any resource for it by itself
  502. /// before destroying this zone data.
  503. ///
  504. /// \throw none
  505. ///
  506. /// \param nsec3_data A pointer to \c NSEC3Data object to be associated
  507. /// with the zone. Can be NULL.
  508. /// \return Previously associated \c NSEC3Data object in the zone. This
  509. /// can be NULL.
  510. NSEC3Data* setNSEC3Data(NSEC3Data* nsec3_data) {
  511. NSEC3Data* old = nsec3_data_.get();
  512. nsec3_data_ = nsec3_data;
  513. return (old);
  514. }
  515. //@}
  516. private:
  517. const boost::interprocess::offset_ptr<ZoneTree> zone_tree_;
  518. const boost::interprocess::offset_ptr<ZoneNode> origin_node_;
  519. boost::interprocess::offset_ptr<NSEC3Data> nsec3_data_;
  520. };
  521. } // namespace memory
  522. } // namespace datasrc
  523. } // namespace isc
  524. #endif // DATASRC_MEMORY_ZONE_DATA_H
  525. // Local Variables:
  526. // mode: c++
  527. // End: