memory_datasrc.cc 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  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 <map>
  15. #include <cassert>
  16. #include <boost/shared_ptr.hpp>
  17. #include <boost/bind.hpp>
  18. #include <dns/name.h>
  19. #include <dns/rrclass.h>
  20. #include <dns/rrsetlist.h>
  21. #include <dns/masterload.h>
  22. #include <datasrc/memory_datasrc.h>
  23. #include <datasrc/rbtree.h>
  24. using namespace std;
  25. using namespace isc::dns;
  26. namespace isc {
  27. namespace datasrc {
  28. // Private data and hidden methods of MemoryZone
  29. struct MemoryZone::MemoryZoneImpl {
  30. // Constructor
  31. MemoryZoneImpl(const RRClass& zone_class, const Name& origin) :
  32. zone_class_(zone_class), origin_(origin), origin_data_(NULL),
  33. domains_(true)
  34. {
  35. // We create the node for origin (it needs to exist anyway in future)
  36. domains_.insert(origin, &origin_data_);
  37. DomainPtr origin_domain(new Domain);
  38. origin_data_->setData(origin_domain);
  39. }
  40. // Some type aliases
  41. /*
  42. * Each domain consists of some RRsets. They will be looked up by the
  43. * RRType.
  44. *
  45. * The use of map is questionable with regard to performance - there'll
  46. * be usually only few RRsets in the domain, so the log n benefit isn't
  47. * much and a vector/array might be faster due to its simplicity and
  48. * continuous memory location. But this is unlikely to be a performance
  49. * critical place and map has better interface for the lookups, so we use
  50. * that.
  51. */
  52. typedef map<RRType, ConstRRsetPtr> Domain;
  53. typedef Domain::value_type DomainPair;
  54. typedef boost::shared_ptr<Domain> DomainPtr;
  55. // The tree stores domains
  56. typedef RBTree<Domain> DomainTree;
  57. typedef RBNode<Domain> DomainNode;
  58. static const DomainNode::Flags DOMAINFLAG_WILD = DomainNode::FLAG_USER1;
  59. // Information about the zone
  60. RRClass zone_class_;
  61. Name origin_;
  62. DomainNode* origin_data_;
  63. string file_name_;
  64. // The actual zone data
  65. DomainTree domains_;
  66. // Add the necessary magic for any wildcard contained in 'name'
  67. // (including itself) to be found in the zone.
  68. //
  69. // In order for wildcard matching to work correctly in find(),
  70. // we must ensure that a node for the wildcarding level exists in the
  71. // backend RBTree.
  72. // E.g. if the wildcard name is "*.sub.example." then we must ensure
  73. // that "sub.example." exists and is marked as a wildcard level.
  74. // Note: the "wildcarding level" is for the parent name of the wildcard
  75. // name (such as "sub.example.").
  76. //
  77. // We also perform the same trick for empty wild card names possibly
  78. // contained in 'name' (e.g., '*.foo.example' in 'bar.*.foo.example').
  79. void addWildcards(DomainTree& domains, const Name& name) {
  80. Name wname(name);
  81. const unsigned int labels(wname.getLabelCount());
  82. const unsigned int origin_labels(origin_.getLabelCount());
  83. for (unsigned int l = labels;
  84. l > origin_labels;
  85. --l, wname = wname.split(1)) {
  86. if (wname.isWildcard()) {
  87. // Ensure a separate level exists for the "wildcarding" name,
  88. // and mark the node as "wild".
  89. DomainNode* node;
  90. DomainTree::Result result(domains.insert(wname.split(1),
  91. &node));
  92. assert(result == DomainTree::SUCCESS ||
  93. result == DomainTree::ALREADYEXISTS);
  94. node->setFlag(DOMAINFLAG_WILD);
  95. // Ensure a separate level exists for the wildcard name.
  96. // Note: for 'name' itself we do this later anyway, but the
  97. // overhead should be marginal because wildcard names should
  98. // be rare.
  99. result = domains.insert(wname, &node);
  100. assert(result == DomainTree::SUCCESS ||
  101. result == DomainTree::ALREADYEXISTS);
  102. }
  103. }
  104. }
  105. /*
  106. * Does some checks in context of the data that are already in the zone.
  107. * Currently checks for forbidden combinations of RRsets in the same
  108. * domain (CNAME+anything, DNAME+NS).
  109. *
  110. * If such condition is found, it throws AddError.
  111. */
  112. void contextCheck(const ConstRRsetPtr& rrset,
  113. const DomainPtr& domain) const {
  114. // Ensure CNAME and other type of RR don't coexist for the same
  115. // owner name.
  116. if (rrset->getType() == RRType::CNAME()) {
  117. // XXX: this check will become incorrect when we support DNSSEC
  118. // (depending on how we support DNSSEC). We should revisit it
  119. // at that point.
  120. if (!domain->empty()) {
  121. isc_throw(AddError, "CNAME can't be added with other data for "
  122. << rrset->getName());
  123. }
  124. } else if (domain->find(RRType::CNAME()) != domain->end()) {
  125. isc_throw(AddError, "CNAME and " << rrset->getType() <<
  126. " can't coexist for " << rrset->getName());
  127. }
  128. /*
  129. * Similar with DNAME, but it must not coexist only with NS and only in
  130. * non-apex domains.
  131. * RFC 2672 section 3 mentions that it is implied from it and RFC 2181
  132. */
  133. if (rrset->getName() != origin_ &&
  134. // Adding DNAME, NS already there
  135. ((rrset->getType() == RRType::DNAME() &&
  136. domain->find(RRType::NS()) != domain->end()) ||
  137. // Adding NS, DNAME already there
  138. (rrset->getType() == RRType::NS() &&
  139. domain->find(RRType::DNAME()) != domain->end())))
  140. {
  141. isc_throw(AddError, "DNAME can't coexist with NS in non-apex "
  142. "domain " << rrset->getName());
  143. }
  144. }
  145. // Validate rrset before adding it to the zone. If something is wrong
  146. // it throws an exception. It doesn't modify the zone, and provides
  147. // the strong exception guarantee.
  148. void addValidation(const ConstRRsetPtr rrset) {
  149. if (!rrset) {
  150. isc_throw(NullRRset, "The rrset provided is NULL");
  151. }
  152. // Check for singleton RRs. It should probably handled at a different
  153. // in future.
  154. if ((rrset->getType() == RRType::CNAME() ||
  155. rrset->getType() == RRType::DNAME()) &&
  156. rrset->getRdataCount() > 1)
  157. {
  158. // XXX: this is not only for CNAME or DNAME. We should generalize
  159. // this code for all other "singleton RR types" (such as SOA) in a
  160. // separate task.
  161. isc_throw(AddError, "multiple RRs of singleton type for "
  162. << rrset->getName());
  163. }
  164. NameComparisonResult compare(origin_.compare(rrset->getName()));
  165. if (compare.getRelation() != NameComparisonResult::SUPERDOMAIN &&
  166. compare.getRelation() != NameComparisonResult::EQUAL)
  167. {
  168. isc_throw(OutOfZone, "The name " << rrset->getName() <<
  169. " is not contained in zone " << origin_);
  170. }
  171. // Some RR types do not really work well with a wildcard.
  172. // Even though the protocol specifically doesn't completely ban such
  173. // usage, we refuse to load a zone containing such RR in order to
  174. // keep the lookup logic simpler and more predictable.
  175. // See RFC4592 and (for DNAME) draft-ietf-dnsext-rfc2672bis-dname
  176. // for more technical background. Note also that BIND 9 refuses
  177. // NS at a wildcard, so in that sense we simply provide compatible
  178. // behavior.
  179. if (rrset->getName().isWildcard()) {
  180. if (rrset->getType() == RRType::NS()) {
  181. isc_throw(AddError, "Invalid NS owner name (wildcard): " <<
  182. rrset->getName());
  183. }
  184. if (rrset->getType() == RRType::DNAME()) {
  185. isc_throw(AddError, "Invalid DNAME owner name (wildcard): " <<
  186. rrset->getName());
  187. }
  188. }
  189. }
  190. /*
  191. * Implementation of longer methods. We put them here, because the
  192. * access is without the impl_-> and it will get inlined anyway.
  193. */
  194. // Implementation of MemoryZone::add
  195. result::Result add(const ConstRRsetPtr& rrset, DomainTree* domains) {
  196. // Sanitize input
  197. addValidation(rrset);
  198. // Add wildcards possibly contained in the owner name to the domain
  199. // tree.
  200. // Note: this can throw an exception, breaking strong exception
  201. // guarantee. (see also the note for contextCheck() below).
  202. addWildcards(*domains, rrset->getName());
  203. // Get the node
  204. DomainNode* node;
  205. DomainTree::Result result = domains->insert(rrset->getName(), &node);
  206. // Just check it returns reasonable results
  207. assert((result == DomainTree::SUCCESS ||
  208. result == DomainTree::ALREADYEXISTS) && node!= NULL);
  209. // Now get the domain
  210. DomainPtr domain;
  211. // It didn't exist yet, create it
  212. if (node->isEmpty()) {
  213. domain.reset(new Domain);
  214. node->setData(domain);
  215. } else { // Get existing one
  216. domain = node->getData();
  217. }
  218. // Checks related to the surrounding data.
  219. // Note: when the check fails and the exception is thrown, it may
  220. // break strong exception guarantee. At the moment we prefer
  221. // code simplicity and don't bother to introduce complicated
  222. // recovery code.
  223. contextCheck(rrset, domain);
  224. // Try inserting the rrset there
  225. if (domain->insert(DomainPair(rrset->getType(), rrset)).second) {
  226. // Ok, we just put it in
  227. // If this RRset creates a zone cut at this node, mark the node
  228. // indicating the need for callback in find().
  229. if (rrset->getType() == RRType::NS() &&
  230. rrset->getName() != origin_) {
  231. node->setFlag(DomainNode::FLAG_CALLBACK);
  232. // If it is DNAME, we have a callback as well here
  233. } else if (rrset->getType() == RRType::DNAME()) {
  234. node->setFlag(DomainNode::FLAG_CALLBACK);
  235. }
  236. return (result::SUCCESS);
  237. } else {
  238. // The RRSet of given type was already there
  239. return (result::EXIST);
  240. }
  241. }
  242. /*
  243. * Same as above, but it checks the return value and if it already exists,
  244. * it throws.
  245. */
  246. void addFromLoad(const ConstRRsetPtr& set, DomainTree* domains) {
  247. switch (add(set, domains)) {
  248. case result::EXIST:
  249. isc_throw(dns::MasterLoadError, "Duplicate rrset: " <<
  250. set->toText());
  251. case result::SUCCESS:
  252. return;
  253. default:
  254. assert(0);
  255. }
  256. }
  257. // Maintain intermediate data specific to the search context used in
  258. /// \c find().
  259. ///
  260. /// It will be passed to \c zonecutCallback() and record a possible
  261. /// zone cut node and related RRset (normally NS or DNAME).
  262. struct FindState {
  263. FindState(FindOptions options) :
  264. zonecut_node_(NULL),
  265. dname_node_(NULL),
  266. options_(options)
  267. {}
  268. const DomainNode* zonecut_node_;
  269. const DomainNode* dname_node_;
  270. ConstRRsetPtr rrset_;
  271. const FindOptions options_;
  272. };
  273. // A callback called from possible zone cut nodes and nodes with DNAME.
  274. // This will be passed from the \c find() method to \c RBTree::find().
  275. static bool cutCallback(const DomainNode& node, FindState* state) {
  276. // We need to look for DNAME first, there's allowed case where
  277. // DNAME and NS coexist in the apex. DNAME is the one to notice,
  278. // the NS is authoritative, not delegation (corner case explicitly
  279. // allowed by section 3 of 2672)
  280. const Domain::const_iterator foundDNAME(node.getData()->find(
  281. RRType::DNAME()));
  282. if (foundDNAME != node.getData()->end()) {
  283. state->dname_node_ = &node;
  284. state->rrset_ = foundDNAME->second;
  285. // No more processing below the DNAME (RFC 2672, section 3
  286. // forbids anything to exist below it, so there's no need
  287. // to actually search for it). This is strictly speaking
  288. // a different way than described in 4.1 of that RFC,
  289. // but because of the assumption in section 3, it has the
  290. // same behaviour.
  291. return (true);
  292. }
  293. // Look for NS
  294. const Domain::const_iterator foundNS(node.getData()->find(
  295. RRType::NS()));
  296. if (foundNS != node.getData()->end()) {
  297. // We perform callback check only for the highest zone cut in the
  298. // rare case of nested zone cuts.
  299. if (state->zonecut_node_ != NULL) {
  300. return (false);
  301. }
  302. // BIND 9 checks if this node is not the origin. That's probably
  303. // because it can support multiple versions for dynamic updates
  304. // and IXFR, and it's possible that the callback is called at
  305. // the apex and the DNAME doesn't exist for a particular version.
  306. // It cannot happen for us (at least for now), so we don't do
  307. // that check.
  308. state->zonecut_node_ = &node;
  309. state->rrset_ = foundNS->second;
  310. // Unless glue is allowed the search stops here, so we return
  311. // false; otherwise return true to continue the search.
  312. return ((state->options_ & FIND_GLUE_OK) == 0);
  313. }
  314. // This case should not happen because we enable callback only
  315. // when we add an RR searched for above.
  316. assert(0);
  317. // This is here to avoid warning (therefore compilation error)
  318. // in case assert is turned off. Otherwise we could get "Control
  319. // reached end of non-void function".
  320. return (false);
  321. }
  322. /*
  323. * Prepares a rrset to be return as a result.
  324. *
  325. * If rename is false, it returns the one provided. If it is true, it
  326. * creates a new rrset with the same data but with provided name.
  327. * It is designed for wildcard case, where we create the rrsets
  328. * dynamically.
  329. */
  330. static ConstRRsetPtr prepareRRset(const Name& name, const ConstRRsetPtr&
  331. rrset, bool rename)
  332. {
  333. if (rename) {
  334. /*
  335. * We lose a signature here. But it would be wrong anyway, because
  336. * the name changed. This might turn out to be unimportant in
  337. * future, because wildcards will probably be handled somehow
  338. * by DNSSEC.
  339. */
  340. RRsetPtr result(new RRset(name, rrset->getClass(),
  341. rrset->getType(), rrset->getTTL()));
  342. for (RdataIteratorPtr i(rrset->getRdataIterator()); !i->isLast();
  343. i->next()) {
  344. result->addRdata(i->getCurrent());
  345. }
  346. return (result);
  347. } else {
  348. return (rrset);
  349. }
  350. }
  351. // Implementation of MemoryZone::find
  352. FindResult find(const Name& name, RRType type,
  353. RRsetList* target, const FindOptions options) const
  354. {
  355. // Get the node
  356. DomainNode* node(NULL);
  357. FindState state(options);
  358. RBTreeNodeChain<Domain> node_path;
  359. bool rename(false);
  360. switch (domains_.find(name, &node, node_path, cutCallback, &state)) {
  361. case DomainTree::PARTIALMATCH:
  362. /*
  363. * In fact, we could use a single variable instead of
  364. * dname_node_ and zonecut_node_. But then we would need
  365. * to distinquish these two cases by something else and
  366. * it seemed little more confusing to me when I wrote it.
  367. *
  368. * Usually at most one of them will be something else than
  369. * NULL (it might happen both are NULL, in which case we
  370. * consider it NOT FOUND). There's one corner case when
  371. * both might be something else than NULL and it is in case
  372. * there's a DNAME under a zone cut and we search in
  373. * glue OK mode ‒ in that case we don't stop on the domain
  374. * with NS and ignore it for the answer, but it gets set
  375. * anyway. Then we find the DNAME and we need to act by it,
  376. * therefore we first check for DNAME and then for NS. In
  377. * all other cases it doesn't matter, as at least one of them
  378. * is NULL.
  379. */
  380. if (state.dname_node_ != NULL) {
  381. // We were traversing a DNAME node (and wanted to go
  382. // lower below it), so return the DNAME
  383. return (FindResult(DNAME, prepareRRset(name, state.rrset_,
  384. rename)));
  385. }
  386. if (state.zonecut_node_ != NULL) {
  387. return (FindResult(DELEGATION, prepareRRset(name,
  388. state.rrset_, rename)));
  389. }
  390. // If the RBTree search stopped at a node for a super domain
  391. // of the search name, it means the search name exists in
  392. // the zone but is empty. Treat it as NXRRSET.
  393. if (node_path.getLastComparisonResult().getRelation() ==
  394. NameComparisonResult::SUPERDOMAIN) {
  395. return (FindResult(NXRRSET, ConstRRsetPtr()));
  396. }
  397. /*
  398. * No redirection anywhere. Let's try if it is a wildcard.
  399. *
  400. * The wildcard is checked after the empty non-terminal domain
  401. * case above, because if that one triggers, it means we should
  402. * not match according to 4.3.3 of RFC 1034 (the query name
  403. * is known to exist).
  404. */
  405. if (node->getFlag(DOMAINFLAG_WILD)) {
  406. /* Should we cancel this match?
  407. *
  408. * If we compare with some node and get a common ancestor,
  409. * it might mean we are comparing with a non-wildcard node.
  410. * In that case, we check which part is common. If we have
  411. * something in common that lives below the node we got
  412. * (the one above *), then we should cancel the match
  413. * according to section 4.3.3 of RFC 1034 (as the name
  414. * between the wildcard domain and the query name is known
  415. * to exist).
  416. *
  417. * Because the way the tree stores relative names, we will
  418. * have exactly one common label (the ".") in case we have
  419. * nothing common under the node we got and we will get
  420. * more common labels otherwise (yes, this relies on the
  421. * internal RBTree structure, which leaks out through this
  422. * little bit).
  423. *
  424. * If the empty non-terminal node actually exists in the
  425. * tree, then this cancellation is not needed, because we
  426. * will not get here at all.
  427. */
  428. if (node_path.getLastComparisonResult().getRelation() ==
  429. NameComparisonResult::COMMONANCESTOR && node_path.
  430. getLastComparisonResult().getCommonLabels() > 1) {
  431. return (FindResult(NXDOMAIN, ConstRRsetPtr()));
  432. }
  433. Name wildcard(Name("*").concatenate(
  434. node_path.getAbsoluteName()));
  435. DomainTree::Result result(domains_.find(wildcard, &node));
  436. /*
  437. * Otherwise, why would the DOMAINFLAG_WILD be there if
  438. * there was no wildcard under it?
  439. */
  440. assert(result == DomainTree::EXACTMATCH);
  441. /*
  442. * We have the wildcard node now. Jump below the switch,
  443. * where handling of the common (exact-match) case is.
  444. *
  445. * However, rename it to the searched name.
  446. */
  447. rename = true;
  448. break;
  449. }
  450. // fall through
  451. case DomainTree::NOTFOUND:
  452. return (FindResult(NXDOMAIN, ConstRRsetPtr()));
  453. case DomainTree::EXACTMATCH: // This one is OK, handle it
  454. break;
  455. default:
  456. assert(0);
  457. }
  458. assert(node != NULL);
  459. // If there is an exact match but the node is empty, it's equivalent
  460. // to NXRRSET.
  461. if (node->isEmpty()) {
  462. return (FindResult(NXRRSET, ConstRRsetPtr()));
  463. }
  464. Domain::const_iterator found;
  465. // If the node callback is enabled, this may be a zone cut. If it
  466. // has a NS RR, we should return a delegation, but not in the apex.
  467. if (node->getFlag(DomainNode::FLAG_CALLBACK) && node != origin_data_) {
  468. found = node->getData()->find(RRType::NS());
  469. if (found != node->getData()->end()) {
  470. return (FindResult(DELEGATION, prepareRRset(name,
  471. found->second, rename)));
  472. }
  473. }
  474. // handle type any query
  475. if (target != NULL && !node->getData()->empty()) {
  476. // Empty domain will be handled as NXRRSET by normal processing
  477. for (found = node->getData()->begin();
  478. found != node->getData()->end(); ++found)
  479. {
  480. target->addRRset(
  481. boost::const_pointer_cast<RRset>(prepareRRset(name,
  482. found->second, rename)));
  483. }
  484. return (FindResult(SUCCESS, ConstRRsetPtr()));
  485. }
  486. found = node->getData()->find(type);
  487. if (found != node->getData()->end()) {
  488. // Good, it is here
  489. return (FindResult(SUCCESS, prepareRRset(name, found->second,
  490. rename)));
  491. } else {
  492. // Next, try CNAME.
  493. found = node->getData()->find(RRType::CNAME());
  494. if (found != node->getData()->end()) {
  495. return (FindResult(CNAME, prepareRRset(name, found->second,
  496. rename)));
  497. }
  498. }
  499. // No exact match or CNAME. Return NXRRSET.
  500. return (FindResult(NXRRSET, ConstRRsetPtr()));
  501. }
  502. };
  503. MemoryZone::MemoryZone(const RRClass& zone_class, const Name& origin) :
  504. impl_(new MemoryZoneImpl(zone_class, origin))
  505. {
  506. }
  507. MemoryZone::~MemoryZone() {
  508. delete impl_;
  509. }
  510. const Name&
  511. MemoryZone::getOrigin() const {
  512. return (impl_->origin_);
  513. }
  514. const RRClass&
  515. MemoryZone::getClass() const {
  516. return (impl_->zone_class_);
  517. }
  518. Zone::FindResult
  519. MemoryZone::find(const Name& name, const RRType& type,
  520. RRsetList* target, const FindOptions options) const
  521. {
  522. return (impl_->find(name, type, target, options));
  523. }
  524. result::Result
  525. MemoryZone::add(const ConstRRsetPtr& rrset) {
  526. return (impl_->add(rrset, &impl_->domains_));
  527. }
  528. void
  529. MemoryZone::load(const string& filename) {
  530. // Load it into a temporary tree
  531. MemoryZoneImpl::DomainTree tmp;
  532. masterLoad(filename.c_str(), getOrigin(), getClass(),
  533. boost::bind(&MemoryZoneImpl::addFromLoad, impl_, _1, &tmp));
  534. // If it went well, put it inside
  535. impl_->file_name_ = filename;
  536. tmp.swap(impl_->domains_);
  537. // And let the old data die with tmp
  538. }
  539. void
  540. MemoryZone::swap(MemoryZone& zone) {
  541. std::swap(impl_, zone.impl_);
  542. }
  543. const string
  544. MemoryZone::getFileName() const {
  545. return (impl_->file_name_);
  546. }
  547. /// Implementation details for \c MemoryDataSrc hidden from the public
  548. /// interface.
  549. ///
  550. /// For now, \c MemoryDataSrc only contains a \c ZoneTable object, which
  551. /// consists of (pointers to) \c MemoryZone objects, we may add more
  552. /// member variables later for new features.
  553. class MemoryDataSrc::MemoryDataSrcImpl {
  554. public:
  555. MemoryDataSrcImpl() : zone_count(0) {}
  556. unsigned int zone_count;
  557. ZoneTable zone_table;
  558. };
  559. MemoryDataSrc::MemoryDataSrc() : impl_(new MemoryDataSrcImpl)
  560. {}
  561. MemoryDataSrc::~MemoryDataSrc() {
  562. delete impl_;
  563. }
  564. unsigned int
  565. MemoryDataSrc::getZoneCount() const {
  566. return (impl_->zone_count);
  567. }
  568. result::Result
  569. MemoryDataSrc::addZone(ZonePtr zone) {
  570. if (!zone) {
  571. isc_throw(InvalidParameter,
  572. "Null pointer is passed to MemoryDataSrc::addZone()");
  573. }
  574. const result::Result result = impl_->zone_table.addZone(zone);
  575. if (result == result::SUCCESS) {
  576. ++impl_->zone_count;
  577. }
  578. return (result);
  579. }
  580. MemoryDataSrc::FindResult
  581. MemoryDataSrc::findZone(const isc::dns::Name& name) const {
  582. return (FindResult(impl_->zone_table.findZone(name).code,
  583. impl_->zone_table.findZone(name).zone));
  584. }
  585. } // end of namespace datasrc
  586. } // end of namespace dns