query.cc 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. #include <dns/message.h>
  15. #include <dns/rcode.h>
  16. #include <datasrc/memory_datasrc.h>
  17. #include <auth/query.h>
  18. using namespace isc::dns;
  19. using namespace isc::datasrc;
  20. namespace isc {
  21. namespace auth {
  22. struct Query::QueryImpl {
  23. QueryImpl(const MemoryDataSrc& memory_datasrc, const Name& qname,
  24. const RRType& qtype, Message& response) :
  25. memory_datasrc_(memory_datasrc), qname_(qname), qtype_(qtype),
  26. response_(response)
  27. {}
  28. const MemoryDataSrc& memory_datasrc_;
  29. const Name& qname_;
  30. const RRType& qtype_;
  31. Message& response_;
  32. };
  33. Query::Query(const MemoryDataSrc& memory_datasrc, const Name& qname,
  34. const RRType& qtype, Message& response) :
  35. impl_(new QueryImpl(memory_datasrc, qname, qtype, response))
  36. {}
  37. Query::~Query() {
  38. delete impl_;
  39. }
  40. void
  41. Query::process() const {
  42. const MemoryDataSrc::FindResult result =
  43. impl_->memory_datasrc_.findZone(impl_->qname_);
  44. bool keep_doing = true;
  45. if (result.code != result::SUCCESS &&
  46. result.code != result::PARTIALMATCH) {
  47. impl_->response_.setRcode(Rcode::SERVFAIL());
  48. return;
  49. }
  50. while (keep_doing) {
  51. keep_doing = false;
  52. Zone::FindResult db_result = result.zone->find(impl_->qname_,
  53. impl_->qtype_);
  54. switch (db_result.code) {
  55. case Zone::SUCCESS:
  56. impl_->response_.setRcode(Rcode::NOERROR());
  57. impl_->response_.addRRset(Message::SECTION_ANSWER,
  58. boost::const_pointer_cast<RRset>(db_result.rrset));
  59. // fill in authority and addtional sections.
  60. break;
  61. case Zone::DELEGATION:
  62. // add NS to authority section, fill in additional section.
  63. break;
  64. case Zone::NXDOMAIN:
  65. impl_->response_.setRcode(Rcode::NXDOMAIN());
  66. // add SOA to authority section
  67. break;
  68. case Zone::NXRRSET:
  69. impl_->response_.setRcode(Rcode::NXRRSET());
  70. // add SOA to authority section
  71. break;
  72. case Zone::CNAME:
  73. case Zone::DNAME:
  74. // replace qname, continue lookup
  75. keep_doing = true;
  76. break;
  77. // should not happen, catch programming error here.
  78. default:
  79. break;
  80. isc_throw(Unexpected,
  81. "Zone::find return unexpected result.");
  82. }
  83. }
  84. }
  85. }
  86. }