zone_data_updater.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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_ZONE_DATA_UPDATER_H
  15. #define DATASRC_ZONE_DATA_UPDATER_H 1
  16. #include <datasrc/memory/zone_data.h>
  17. #include <datasrc/memory/rdata_serialization.h>
  18. #include <dns/name.h>
  19. #include <dns/rrclass.h>
  20. #include <dns/rrset.h>
  21. #include <dns/nsec3hash.h>
  22. #include <util/memory_segment.h>
  23. #include <boost/noncopyable.hpp>
  24. namespace isc {
  25. namespace datasrc {
  26. namespace memory {
  27. class ZoneDataUpdater : boost::noncopyable {
  28. public:
  29. ZoneDataUpdater(util::MemorySegment& mem_sgmt,
  30. isc::dns::RRClass rrclass,
  31. const isc::dns::Name& zone_name,
  32. ZoneData& zone_data) :
  33. mem_sgmt_(mem_sgmt),
  34. rrclass_(rrclass),
  35. zone_name_(zone_name),
  36. zone_data_(zone_data),
  37. hash_(NULL)
  38. {}
  39. /// The destructor.
  40. ~ZoneDataUpdater() {
  41. delete hash_;
  42. }
  43. //@}
  44. /// This is thrown if the provided RRset parameter is NULL.
  45. struct NullRRset : public InvalidParameter {
  46. NullRRset(const char* file, size_t line, const char* what) :
  47. InvalidParameter(file, line, what)
  48. {}
  49. };
  50. /// \brief Zone is empty exception.
  51. ///
  52. /// This is thrown if we have an empty zone created as a result of
  53. /// load().
  54. struct EmptyZone : public InvalidParameter {
  55. EmptyZone(const char* file, size_t line, const char* what) :
  56. InvalidParameter(file, line, what)
  57. {}
  58. };
  59. /// \brief General failure exception for \c add().
  60. ///
  61. /// This is thrown against general error cases in adding an RRset
  62. /// to the zone.
  63. ///
  64. /// Note: this exception would cover cases for \c OutOfZone or
  65. /// \c NullRRset. We'll need to clarify and unify the granularity
  66. /// of exceptions eventually. For now, exceptions are added as
  67. /// developers see the need for it.
  68. struct AddError : public InvalidParameter {
  69. AddError(const char* file, size_t line, const char* what) :
  70. InvalidParameter(file, line, what)
  71. {}
  72. };
  73. void add(const isc::dns::ConstRRsetPtr& rrset,
  74. const isc::dns::ConstRRsetPtr& sig_rrset);
  75. private:
  76. // Add the necessary magic for any wildcard contained in 'name'
  77. // (including itself) to be found in the zone.
  78. //
  79. // In order for wildcard matching to work correctly in the zone finder,
  80. // we must ensure that a node for the wildcarding level exists in the
  81. // backend ZoneTree.
  82. // E.g. if the wildcard name is "*.sub.example." then we must ensure
  83. // that "sub.example." exists and is marked as a wildcard level.
  84. // Note: the "wildcarding level" is for the parent name of the wildcard
  85. // name (such as "sub.example.").
  86. //
  87. // We also perform the same trick for empty wild card names possibly
  88. // contained in 'name' (e.g., '*.foo.example' in 'bar.*.foo.example').
  89. void addWildcards(const isc::dns::Name& name);
  90. // Does some checks in context of the data that are already in the
  91. // zone. Currently checks for forbidden combinations of RRsets in
  92. // the same domain (CNAME+anything, DNAME+NS). If such condition is
  93. // found, it throws AddError.
  94. void contextCheck(const isc::dns::AbstractRRset& rrset,
  95. const RdataSet* set) const;
  96. // Validate rrset before adding it to the zone. If something is wrong
  97. // it throws an exception. It doesn't modify the zone, and provides
  98. // the strong exception guarantee.
  99. void validate(const isc::dns::ConstRRsetPtr rrset) const;
  100. const isc::dns::NSEC3Hash* getNSEC3Hash();
  101. template <typename T>
  102. void setupNSEC3(const isc::dns::ConstRRsetPtr rrset);
  103. void addNSEC3(const isc::dns::ConstRRsetPtr rrset,
  104. const isc::dns::ConstRRsetPtr rrsig);
  105. void addRdataSet(const isc::dns::ConstRRsetPtr rrset,
  106. const isc::dns::ConstRRsetPtr rrsig);
  107. util::MemorySegment& mem_sgmt_;
  108. const isc::dns::RRClass rrclass_;
  109. const isc::dns::Name& zone_name_;
  110. ZoneData& zone_data_;
  111. RdataEncoder encoder_;
  112. isc::dns::NSEC3Hash* hash_;
  113. };
  114. } // namespace memory
  115. } // namespace datasrc
  116. } // namespace isc
  117. #endif // DATASRC_ZONE_DATA_UPDATER_H
  118. // Local Variables:
  119. // mode: c++
  120. // End: