zone_data.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. }
  30. }
  31. }
  32. namespace datasrc {
  33. namespace memory {
  34. typedef DomainTree<RdataSet> ZoneTree;
  35. typedef DomainTreeNode<RdataSet> ZoneNode;
  36. class NSEC3Data : boost::noncopyable {
  37. public:
  38. static NSEC3Data* create(util::MemorySegment& mem_sgmt,
  39. const dns::rdata::generic::NSEC3PARAM& rdata);
  40. static NSEC3Data* create(util::MemorySegment& mem_sgmt,
  41. const dns::rdata::generic::NSEC3& rdata);
  42. static void destroy(util::MemorySegment& mem_sgmt, NSEC3Data* data,
  43. dns::RRClass nsec3_class);
  44. const boost::interprocess::offset_ptr<ZoneTree> nsec3_tree_;
  45. public:
  46. const uint8_t hashalg;
  47. const uint8_t flags;
  48. const uint16_t iterations;
  49. // For 64-bit machines there'll be a padding space here, but since
  50. // only at most one (or a few in very rare cases) instance will be
  51. // created per zone, the overhead should be acceptable.
  52. const ZoneTree* getNSEC3Tree() const { return (nsec3_tree_.get()); }
  53. size_t getSaltLen() const { return (*getSaltBuf()); }
  54. const uint8_t* getSaltData() const { return (getSaltBuf() + 1); }
  55. void insertName(util::MemorySegment& mem_sgmt, const dns::Name& name,
  56. ZoneNode** node);
  57. private:
  58. // Common subroutine for the public versions of create().
  59. static NSEC3Data* create(util::MemorySegment& mem_sgmt, uint8_t hashalg,
  60. uint8_t flags, uint16_t iterations,
  61. const std::vector<uint8_t>& salt);
  62. NSEC3Data(ZoneTree* nsec3_tree_param, uint8_t hashalg_param,
  63. uint8_t flags_param, uint16_t iterations_param) :
  64. nsec3_tree_(nsec3_tree_param), hashalg(hashalg_param),
  65. flags(flags_param), iterations(iterations_param)
  66. {}
  67. const uint8_t* getSaltBuf() const {
  68. return (reinterpret_cast<const uint8_t*>(this + 1));
  69. }
  70. uint8_t* getSaltBuf() {
  71. return (reinterpret_cast<uint8_t*>(this + 1));
  72. }
  73. };
  74. class ZoneData : boost::noncopyable {
  75. public:
  76. private:
  77. ZoneData(ZoneTree* zone_tree, ZoneNode* origin_node) :
  78. zone_tree_(zone_tree), origin_node_(origin_node)
  79. {}
  80. public:
  81. static ZoneData* create(util::MemorySegment& mem_sgmt,
  82. const dns::Name& zone_name);
  83. static void destroy(util::MemorySegment& mem_sgmt, dns::RRClass zone_class,
  84. ZoneData* zone_data);
  85. void insertName(util::MemorySegment& mem_sgmt, const dns::Name& name,
  86. ZoneNode** node);
  87. // This is a shortcut.
  88. const ZoneNode* getOriginNode() const {
  89. return (origin_node_.get());
  90. }
  91. const ZoneTree* getZoneTree() const { return (zone_tree_.get()); }
  92. private:
  93. const boost::interprocess::offset_ptr<ZoneTree> zone_tree_;
  94. const boost::interprocess::offset_ptr<ZoneNode> origin_node_;
  95. };
  96. } // namespace memory
  97. } // namespace datasrc
  98. } // namespace isc
  99. #endif // DATASRC_MEMORY_ZONE_DATA_H
  100. // Local Variables:
  101. // mode: c++
  102. // End: