d2_update_message.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // Copyright (C) 2013 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 D2_UPDATE_MESSAGE_H
  15. #define D2_UPDATE_MESSAGE_H
  16. #include <d2/d2_zone.h>
  17. #include <dns/message.h>
  18. #include <dns/name.h>
  19. #include <dns/rcode.h>
  20. #include <dns/rrclass.h>
  21. #include <dns/rrset.h>
  22. #include <map>
  23. namespace isc {
  24. namespace d2 {
  25. /// @brief Exception indicating that Zone section contains invalid content.
  26. ///
  27. /// This exception is thrown when ZONE section of the DNS Update message
  28. /// is invalid. According to RFC2136, section 2.3, the zone section is
  29. /// allowed to contain exactly one record. When Request message contains
  30. /// more records or is empty, this exception is thrown.
  31. class InvalidZoneSection : public Exception {
  32. public:
  33. InvalidZoneSection(const char* file, size_t line, const char* what) :
  34. isc::Exception(file, line, what) {}
  35. };
  36. /// @brief The @c D2UpdateMessage encapsulates a DNS Update message.
  37. ///
  38. /// This class represents the DNS Update message. Functions exposed by this
  39. /// class allow to specify the data sections carried by the message and create
  40. /// an on-wire format of this message. This class is also used to decode
  41. /// messages received from the DNS server from the on-wire format.
  42. ///
  43. /// <b>Design choice:</b> A dedicated class has been created to encapsulate
  44. /// DNS Update message because existing @c isc::dns::Message is designed to
  45. /// support regular DNS messages described in RFC 1035 only. Altough DNS Update
  46. /// has the same format, particular sections serve different purposes. In order
  47. /// to avoid rewrite of significant portions of @c isc::dns::Message class, this
  48. /// class is implemented in-terms-of @c Message class to reuse its functionality
  49. /// wherever possible.
  50. class D2UpdateMessage {
  51. public:
  52. enum QRFlag {
  53. REQUEST,
  54. RESPONSE
  55. };
  56. enum UpdateMsgSection {
  57. SECTION_ZONE,
  58. SECTION_PREREQUISITE,
  59. SECTION_UPDATE,
  60. SECTION_ADDITIONAL
  61. };
  62. public:
  63. D2UpdateMessage(const bool parse = false);
  64. private:
  65. D2UpdateMessage(const D2UpdateMessage& source);
  66. D2UpdateMessage& operator=(const D2UpdateMessage& source);
  67. public:
  68. QRFlag getQRFlag() const;
  69. void setQRFlag(const QRFlag flag);
  70. uint16_t getQid() const;
  71. void setQid(const uint16_t qid);
  72. const dns::Rcode& getRcode() const;
  73. void setRcode(const dns::Rcode& rcode);
  74. unsigned int getRRCount(const UpdateMsgSection section) const;
  75. const dns::RRsetIterator beginSection(const UpdateMsgSection section) const;
  76. const dns::RRsetIterator endSection(const UpdateMsgSection section) const;
  77. void setZone(const dns::Name& zone, const dns::RRClass& rrclass);
  78. D2ZonePtr getZone() const;
  79. void addRRset(const UpdateMsgSection section, const dns::RRsetPtr& rrset);
  80. bool hasRRset(const UpdateMsgSection section, const dns::Name& name,
  81. const dns::RRClass& rrclass, const dns::RRType& rrtype);
  82. bool hasRRset(const UpdateMsgSection section, const dns::RRsetPtr &rrset);
  83. void clearSection(const UpdateMsgSection section);
  84. void clear(const bool parse_mode);
  85. void toWire(dns::AbstractMessageRenderer& renderer);
  86. void fromWire(isc::util::InputBuffer& buffer);
  87. private:
  88. static dns::Message::Section ddnsToDnsSection(const UpdateMsgSection section);
  89. dns::Message message_;
  90. D2ZonePtr zone_;
  91. };
  92. } // namespace d2
  93. } // namespace isc
  94. #endif // D2_UPDATE_MESSAGE_H