zone_finder_context.cc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. #include <dns/rdata.h>
  15. #include <dns/rrset.h>
  16. #include <dns/rrtype.h>
  17. #include <dns/rdataclass.h>
  18. #include <datasrc/zone.h>
  19. #include <boost/foreach.hpp>
  20. #include <vector>
  21. using namespace std;
  22. using namespace isc::dns;
  23. using namespace isc::dns::rdata;
  24. namespace isc {
  25. namespace datasrc {
  26. namespace {
  27. void
  28. getAdditionalAddrs(ZoneFinder& finder, const Name& name,
  29. const vector<RRType>& requested_types,
  30. vector<ConstRRsetPtr>& result_rrsets,
  31. ZoneFinder::FindOptions options)
  32. {
  33. // Ignore out-of-zone names
  34. const NameComparisonResult cmp = finder.getOrigin().compare(name);
  35. if ((cmp.getRelation() != NameComparisonResult::SUPERDOMAIN) &&
  36. (cmp.getRelation() != NameComparisonResult::EQUAL)) {
  37. return;
  38. }
  39. BOOST_FOREACH(RRType rrtype, requested_types) {
  40. ConstZoneFinderContextPtr ctx = finder.find(name, rrtype, options);
  41. if (ctx->code == ZoneFinder::SUCCESS) {
  42. result_rrsets.push_back(ctx->rrset);
  43. }
  44. }
  45. }
  46. void
  47. getAdditionalForRRset(ZoneFinder& finder, const AbstractRRset& rrset,
  48. const vector<RRType>& requested_types,
  49. vector<ConstRRsetPtr>& result,
  50. ZoneFinder::FindOptions orig_options)
  51. {
  52. RdataIteratorPtr rdata_iterator(rrset.getRdataIterator());
  53. ZoneFinder::FindOptions options = ZoneFinder::FIND_DEFAULT;
  54. if ((orig_options & ZoneFinder::FIND_DNSSEC) != 0) {
  55. options = options | ZoneFinder::FIND_DNSSEC;
  56. }
  57. for (; !rdata_iterator->isLast(); rdata_iterator->next()) {
  58. const Rdata& rdata(rdata_iterator->getCurrent());
  59. if (rrset.getType() == RRType::NS()) {
  60. // Need to perform the search in the "GLUE OK" mode.
  61. const generic::NS& ns = dynamic_cast<const generic::NS&>(rdata);
  62. getAdditionalAddrs(finder, ns.getNSName(), requested_types,
  63. result, options | ZoneFinder::FIND_GLUE_OK);
  64. } else if (rrset.getType() == RRType::MX()) {
  65. const generic::MX& mx = dynamic_cast<const generic::MX&>(rdata);
  66. getAdditionalAddrs(finder, mx.getMXName(), requested_types,
  67. result, options);
  68. }
  69. }
  70. }
  71. }
  72. void
  73. ZoneFinder::Context::getAdditionalImpl(const vector<RRType>& requested_types,
  74. vector<ConstRRsetPtr>& result)
  75. {
  76. // If rrset is non NULL, it should have been SUCCESS/DELEGATION; otherwise
  77. // we should have responded to type ANY query.
  78. if (rrset) {
  79. getAdditionalForRRset(finder_, *rrset, requested_types, result,
  80. options_);
  81. return;
  82. }
  83. BOOST_FOREACH(ConstRRsetPtr rrset_in_set, all_set_) {
  84. getAdditionalForRRset(finder_, *rrset_in_set, requested_types, result,
  85. options_);
  86. }
  87. }
  88. } // namespace datasrc
  89. } // datasrc isc