data_source.cc 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350
  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 <config.h>
  15. #include <cassert>
  16. #include <iomanip>
  17. #include <iostream>
  18. #include <vector>
  19. #include <boost/shared_ptr.hpp>
  20. #include <boost/foreach.hpp>
  21. #include <datasrc/cache.h>
  22. #include <datasrc/data_source.h>
  23. #include <datasrc/query.h>
  24. #include <dns/util/base32hex.h>
  25. #include <dns/buffer.h>
  26. #include <dns/message.h>
  27. #include <dns/name.h>
  28. #include <dns/rcode.h>
  29. #include <dns/rdataclass.h>
  30. #include <dns/rrset.h>
  31. #include <dns/rrsetlist.h>
  32. #include <dns/util/sha1.h>
  33. #include <cc/data.h>
  34. #define RETERR(x) do { \
  35. DataSrc::Result r = (x); \
  36. if (r != DataSrc::SUCCESS) \
  37. return (r); \
  38. } while (0)
  39. using namespace std;
  40. using namespace isc::dns;
  41. using namespace isc::dns::rdata;
  42. namespace {
  43. struct MatchRRsetForType {
  44. MatchRRsetForType(const RRType rrtype) : rrtype_(rrtype) {}
  45. bool operator()(RRsetPtr rrset) {
  46. return (rrset->getType() == rrtype_);
  47. }
  48. const RRType rrtype_;
  49. };
  50. // This is a helper to retrieve a specified RR type of RRset from RRsetList.
  51. // In our case the data source search logic should ensure that the class is
  52. // valid. We use this find logic of our own so that we can support both
  53. // specific RR class queries (normal case) and class ANY queries.
  54. RRsetPtr
  55. findRRsetFromList(RRsetList& list, const RRType rrtype) {
  56. RRsetList::iterator it(find_if(list.begin(), list.end(),
  57. MatchRRsetForType(rrtype)));
  58. return (it != list.end() ? *it : RRsetPtr());
  59. }
  60. }
  61. namespace isc {
  62. namespace datasrc {
  63. typedef boost::shared_ptr<const Nsec3Param> ConstNsec3ParamPtr;
  64. class ZoneInfo {
  65. public:
  66. ZoneInfo(DataSrc* ts,
  67. const isc::dns::Name& n,
  68. const isc::dns::RRClass& c,
  69. const isc::dns::RRType& t = isc::dns::RRType::ANY()) :
  70. top_source_(ts),
  71. dsm_(((t == RRType::DS() && n.getLabelCount() != 1)
  72. ? n.split(1, n.getLabelCount() - 1) : n),
  73. c)
  74. {}
  75. const Name* getEnclosingZone() {
  76. if (dsm_.getEnclosingZone() == NULL) {
  77. top_source_->findClosestEnclosure(dsm_);
  78. }
  79. return (dsm_.getEnclosingZone());
  80. }
  81. const DataSrc* getDataSource() {
  82. if (dsm_.getDataSource() == NULL) {
  83. top_source_->findClosestEnclosure(dsm_);
  84. }
  85. return (dsm_.getDataSource());
  86. }
  87. private:
  88. const DataSrc* top_source_;
  89. DataSrcMatch dsm_;
  90. };
  91. // Add a task to the query task queue to look up additional data
  92. // (i.e., address records for the names included in NS or MX records)
  93. void
  94. getAdditional(Query& q, ConstRRsetPtr rrset) {
  95. if (!q.wantAdditional()) {
  96. return;
  97. }
  98. RdataIteratorPtr it = rrset->getRdataIterator();
  99. for (; !it->isLast(); it->next()) {
  100. const Rdata& rd(it->getCurrent());
  101. if (rrset->getType() == RRType::NS()) {
  102. const generic::NS& ns = dynamic_cast<const generic::NS&>(rd);
  103. q.tasks().push(QueryTaskPtr(
  104. new QueryTask(q, ns.getNSName(),
  105. Message::SECTION_ADDITIONAL,
  106. QueryTask::GLUE_QUERY,
  107. QueryTask::GETADDITIONAL)));
  108. } else if (rrset->getType() == RRType::MX()) {
  109. const generic::MX& mx = dynamic_cast<const generic::MX&>(rd);
  110. q.tasks().push(QueryTaskPtr(
  111. new QueryTask(q, mx.getMXName(),
  112. Message::SECTION_ADDITIONAL,
  113. QueryTask::NOGLUE_QUERY,
  114. QueryTask::GETADDITIONAL)));
  115. }
  116. }
  117. }
  118. // Synthesize a CNAME answer, for the benefit of clients that don't
  119. // understand DNAME
  120. void
  121. synthesizeCname(QueryTaskPtr task, RRsetPtr rrset, RRsetList& target) {
  122. RdataIteratorPtr it = rrset->getRdataIterator();
  123. // More than one DNAME RR in the RRset is illegal, so we only have
  124. // to process the first one.
  125. if (it->isLast()) {
  126. return;
  127. }
  128. const Rdata& rd(it->getCurrent());
  129. const generic::DNAME& dname = dynamic_cast<const generic::DNAME&>(rd);
  130. const Name& dname_target(dname.getDname());
  131. RRsetPtr cname(new RRset(task->qname, rrset->getClass(), RRType::CNAME(),
  132. rrset->getTTL()));
  133. const int qnlen = task->qname.getLabelCount();
  134. const int dnlen = rrset->getName().getLabelCount();
  135. assert(qnlen > dnlen);
  136. const Name& prefix(task->qname.split(0, qnlen - dnlen));
  137. cname->addRdata(generic::CNAME(prefix.concatenate(dname_target)));
  138. target.addRRset(cname);
  139. }
  140. // Add a task to the query task queue to look up the data pointed
  141. // to by a CNAME record
  142. void
  143. chaseCname(Query& q, QueryTaskPtr task, RRsetPtr rrset) {
  144. RdataIteratorPtr it = rrset->getRdataIterator();
  145. // More than one CNAME RR in the RRset is illegal, so we only have
  146. // to process the first one.
  147. if (it->isLast()) {
  148. return;
  149. }
  150. // Stop chasing CNAMES after 16 lookups, to prevent loops
  151. if (q.tooMany()) {
  152. return;
  153. }
  154. q.tasks().push(QueryTaskPtr(
  155. new QueryTask(q, dynamic_cast<const generic::CNAME&>
  156. (it->getCurrent()).getCname(),
  157. task->qtype, Message::SECTION_ANSWER,
  158. QueryTask::FOLLOWCNAME)));
  159. }
  160. // Check the cache for data which can answer the current query task.
  161. bool
  162. checkCache(QueryTask& task, RRsetList& target) {
  163. HotCache& cache = task.q.getCache();
  164. RRsetList rrsets;
  165. RRsetPtr rrset;
  166. int count = 0;
  167. uint32_t flags = 0, cflags = 0;
  168. bool hit = false, found = false;
  169. switch (task.op) {
  170. case QueryTask::SIMPLE_QUERY: // Find exact RRset
  171. // ANY queries must be handled by the low-level data source,
  172. // or the results won't be guaranteed to be complete
  173. if (task.qtype == RRType::ANY() || task.qclass == RRClass::ANY()) {
  174. break;
  175. }
  176. hit = cache.retrieve(task.qname, task.qclass, task.qtype, rrset, flags);
  177. if (hit) {
  178. if (rrset) {
  179. rrsets.addRRset(rrset);
  180. target.append(rrsets);
  181. }
  182. // Reset the referral flag and treat CNAME as "not found".
  183. // This emulates the behavior of the sqlite3 data source.
  184. // XXX: this is not ideal in that the responsibility for handling
  185. // operation specific cases is spread over various classes at
  186. // different abstraction levels. For longer terms we should
  187. // revisit the whole datasource/query design, and clarify this
  188. // point better.
  189. flags &= ~DataSrc::REFERRAL;
  190. if ((flags & DataSrc::CNAME_FOUND) != 0) {
  191. flags &= ~DataSrc::CNAME_FOUND;
  192. flags |= DataSrc::TYPE_NOT_FOUND;
  193. }
  194. task.flags = flags;
  195. return (true);
  196. }
  197. break;
  198. case QueryTask::AUTH_QUERY: // Find exact RRset or CNAME
  199. if (task.qtype == RRType::ANY() || task.qclass == RRClass::ANY()) {
  200. break;
  201. }
  202. hit = cache.retrieve(task.qname, task.qclass, task.qtype, rrset, flags);
  203. if (!hit || !rrset || (flags & DataSrc::CNAME_FOUND) != 0) {
  204. hit = cache.retrieve(task.qname, task.qclass, RRType::CNAME(),
  205. rrset, flags);
  206. if (!rrset) {
  207. // If we don't have a positive cache, forget it; otherwise the
  208. // intermediate result may confuse the subsequent processing.
  209. hit = false;
  210. }
  211. }
  212. if (hit) {
  213. if (rrset) {
  214. rrsets.addRRset(rrset);
  215. target.append(rrsets);
  216. }
  217. task.flags = flags;
  218. return (true);
  219. }
  220. break;
  221. case QueryTask::GLUE_QUERY: // Find addresses
  222. case QueryTask::NOGLUE_QUERY:
  223. // (XXX: need to figure out how to deal with noglue case)
  224. flags = 0;
  225. hit = cache.retrieve(task.qname, task.qclass, RRType::A(),
  226. rrset, cflags);
  227. if (hit) {
  228. flags |= cflags;
  229. ++count;
  230. if (rrset) {
  231. rrsets.addRRset(rrset);
  232. found = true;
  233. }
  234. }
  235. hit = cache.retrieve(task.qname, task.qclass, RRType::AAAA(),
  236. rrset, flags);
  237. if (hit) {
  238. flags |= cflags;
  239. ++count;
  240. if (rrset) {
  241. rrsets.addRRset(rrset);
  242. found = true;
  243. }
  244. }
  245. if (count == 2) {
  246. if (found) {
  247. flags &= ~DataSrc::TYPE_NOT_FOUND;
  248. target.append(rrsets);
  249. }
  250. task.flags = flags;
  251. return (true);
  252. }
  253. break;
  254. case QueryTask::REF_QUERY: // Find NS, DS and/or DNAME
  255. flags = count = 0;
  256. hit = cache.retrieve(task.qname, task.qclass, RRType::NS(),
  257. rrset, cflags);
  258. if (hit) {
  259. flags |= cflags;
  260. ++count;
  261. if (rrset) {
  262. rrsets.addRRset(rrset);
  263. found = true;
  264. }
  265. }
  266. hit = cache.retrieve(task.qname, task.qclass, RRType::DS(),
  267. rrset, flags);
  268. if (hit) {
  269. flags |= cflags;
  270. ++count;
  271. if (rrset) {
  272. rrsets.addRRset(rrset);
  273. found = true;
  274. }
  275. }
  276. hit = cache.retrieve(task.qname, task.qclass, RRType::DNAME(),
  277. rrset, flags);
  278. if (hit) {
  279. flags |= cflags;
  280. ++count;
  281. if (rrset) {
  282. rrsets.addRRset(rrset);
  283. found = true;
  284. }
  285. }
  286. if (count == 3) {
  287. if (found) {
  288. flags &= ~DataSrc::TYPE_NOT_FOUND;
  289. flags &= DataSrc::REFERRAL;
  290. target.append(rrsets);
  291. }
  292. task.flags = flags;
  293. return (true);
  294. }
  295. break;
  296. }
  297. return (false);
  298. }
  299. // Carry out the query specified in a QueryTask object
  300. DataSrc::Result
  301. doQueryTask(QueryTask& task, ZoneInfo& zoneinfo, RRsetList& target) {
  302. HotCache& cache = task.q.getCache();
  303. RRsetPtr rrset;
  304. // First, check the cache for matching data
  305. if (checkCache(task, target)) {
  306. return (DataSrc::SUCCESS);
  307. }
  308. // Requested data weren't in the cache (or were, but had expired),
  309. // so now we proceed with the low-level data source lookup, and cache
  310. // whatever we find.
  311. const DataSrc* ds = zoneinfo.getDataSource();
  312. const Name* const zonename = zoneinfo.getEnclosingZone();
  313. if (ds == NULL) {
  314. task.flags |= DataSrc::NO_SUCH_ZONE;
  315. return (DataSrc::SUCCESS);
  316. }
  317. DataSrc::Result result;
  318. switch (task.op) {
  319. case QueryTask::SIMPLE_QUERY:
  320. result = ds->findExactRRset(task.qname, task.qclass, task.qtype,
  321. target, task.flags, zonename);
  322. if (result != DataSrc::SUCCESS) {
  323. return (result);
  324. }
  325. if (task.qclass == RRClass::ANY()) {
  326. // XXX: Currently, RRsetList::findRRset() doesn't handle
  327. // ANY queries, and without that we can't cache the results,
  328. // so we just return in that case.
  329. return (result);
  330. }
  331. if (task.flags == 0) {
  332. rrset = target.findRRset(task.qtype, task.qclass);
  333. assert(rrset);
  334. cache.addPositive(rrset, task.flags);
  335. } else {
  336. cache.addNegative(task.qname, task.qclass, task.qtype, task.flags);
  337. }
  338. return (result);
  339. case QueryTask::AUTH_QUERY:
  340. result = ds->findRRset(task.qname, task.qclass, task.qtype,
  341. target, task.flags, zonename);
  342. if (result != DataSrc::SUCCESS) {
  343. return (result);
  344. }
  345. if (task.qclass == RRClass::ANY()) {
  346. return (result);
  347. }
  348. if (task.qtype == RRType::ANY()) {
  349. BOOST_FOREACH(RRsetPtr rr, target) {
  350. cache.addPositive(rr, task.flags);
  351. }
  352. } else if ((task.flags & DataSrc::CNAME_FOUND) != 0) {
  353. cache.addNegative(task.qname, task.qclass, task.qtype, task.flags);
  354. rrset = target.findRRset(RRType::CNAME(), task.qclass);
  355. assert(rrset);
  356. cache.addPositive(rrset, task.flags);
  357. } else if ((task.flags & DataSrc::DATA_NOT_FOUND) == 0) {
  358. if (task.qtype != RRType::CNAME()) {
  359. cache.addNegative(task.qname, task.qclass, RRType::CNAME(),
  360. task.flags);
  361. }
  362. rrset = target.findRRset(task.qtype, task.qclass);
  363. assert(rrset);
  364. cache.addPositive(rrset, task.flags);
  365. } else {
  366. cache.addNegative(task.qname, task.qclass, task.qtype, task.flags);
  367. }
  368. return (result);
  369. case QueryTask::GLUE_QUERY:
  370. case QueryTask::NOGLUE_QUERY:
  371. result = ds->findAddrs(task.qname, task.qclass, target,
  372. task.flags, zonename);
  373. if (result != DataSrc::SUCCESS) {
  374. return (result);
  375. }
  376. if (task.qclass == RRClass::ANY()) {
  377. return (result);
  378. }
  379. rrset = target.findRRset(RRType::A(), task.qclass);
  380. if (rrset) {
  381. cache.addPositive(rrset, task.flags);
  382. } else {
  383. cache.addNegative(task.qname, task.qclass, RRType::A(), task.flags);
  384. }
  385. rrset = target.findRRset(RRType::AAAA(), task.qclass);
  386. if (rrset) {
  387. cache.addPositive(rrset, task.flags);
  388. } else {
  389. cache.addNegative(task.qname, task.qclass, RRType::AAAA(),
  390. task.flags);
  391. }
  392. return (result);
  393. case QueryTask::REF_QUERY:
  394. result = ds->findReferral(task.qname, task.qclass, target,
  395. task.flags, zonename);
  396. if (result != DataSrc::SUCCESS) {
  397. return (result);
  398. }
  399. if (task.qclass == RRClass::ANY()) {
  400. return (result);
  401. }
  402. rrset = target.findRRset(RRType::NS(), task.qclass);
  403. if (rrset) {
  404. cache.addPositive(rrset, task.flags);
  405. } else {
  406. cache.addNegative(task.qname, task.qclass, RRType::NS(),
  407. task.flags);
  408. }
  409. rrset = target.findRRset(RRType::DS(), task.qclass);
  410. if (rrset) {
  411. cache.addPositive(rrset, task.flags);
  412. } else {
  413. cache.addNegative(task.qname, task.qclass, RRType::DS(),
  414. task.flags);
  415. }
  416. rrset = target.findRRset(RRType::DNAME(), task.qclass);
  417. if (rrset) {
  418. cache.addPositive(rrset, task.flags);
  419. } else {
  420. cache.addNegative(task.qname, task.qclass, RRType::DNAME(),
  421. task.flags);
  422. }
  423. return (result);
  424. }
  425. // Not reached
  426. return (DataSrc::ERROR);
  427. }
  428. // Add an RRset (and its associated RRSIG) to a message section,
  429. // checking first to ensure that there isn't already an RRset with
  430. // the same name and type.
  431. inline void
  432. addToMessage(Query& q, const Message::Section sect, RRsetPtr rrset,
  433. bool no_dnssec = false)
  434. {
  435. Message& m = q.message();
  436. if (no_dnssec) {
  437. if (rrset->getType() == RRType::RRSIG() ||
  438. !m.hasRRset(sect, rrset->getName(), rrset->getClass(),
  439. rrset->getType())) {
  440. m.addRRset(sect, rrset, false);
  441. }
  442. } else {
  443. if (!m.hasRRset(sect, rrset->getName(), rrset->getClass(),
  444. rrset->getType())) {
  445. m.addRRset(sect, rrset, q.wantDnssec());
  446. }
  447. }
  448. }
  449. // Copy referral information into the authority section of a message
  450. inline void
  451. copyAuth(Query& q, RRsetList& auth) {
  452. BOOST_FOREACH(RRsetPtr rrset, auth) {
  453. if (rrset->getType() == RRType::DNAME()) {
  454. continue;
  455. }
  456. if (rrset->getType() == RRType::DS() && !q.wantDnssec()) {
  457. continue;
  458. }
  459. addToMessage(q, Message::SECTION_AUTHORITY, rrset);
  460. getAdditional(q, rrset);
  461. }
  462. }
  463. // Query for referrals (i.e., NS/DS or DNAME) at a given name
  464. inline bool
  465. refQuery(const Query& q, const Name& name, ZoneInfo& zoneinfo,
  466. RRsetList& target)
  467. {
  468. QueryTask newtask(q, name, QueryTask::REF_QUERY);
  469. if (doQueryTask(newtask, zoneinfo, target) != DataSrc::SUCCESS) {
  470. // Lookup failed
  471. return (false);
  472. }
  473. // Referral bit is expected, so clear it when checking flags
  474. if ((newtask.flags & ~DataSrc::REFERRAL) != 0) {
  475. return (false);
  476. }
  477. return (true);
  478. }
  479. // Match downward, from the zone apex to the query name, looking for
  480. // referrals. Note that we exclude the apex name and query name themselves;
  481. // they'll be handled in a normal lookup in the zone.
  482. inline bool
  483. hasDelegation(Query& q, QueryTaskPtr task, ZoneInfo& zoneinfo) {
  484. const Name* const zonename = zoneinfo.getEnclosingZone();
  485. if (zonename == NULL) {
  486. if (task->state == QueryTask::GETANSWER) {
  487. q.message().setRcode(Rcode::REFUSED());
  488. }
  489. return (false);
  490. }
  491. const int diff = task->qname.getLabelCount() - zonename->getLabelCount();
  492. if (diff > 1) {
  493. bool found = false;
  494. RRsetList ref;
  495. for (int i = diff - 1; i > 0; --i) {
  496. const Name sub(task->qname.split(i));
  497. if (refQuery(q, sub, zoneinfo, ref)) {
  498. found = true;
  499. break;
  500. }
  501. }
  502. // Found a referral while getting additional data
  503. // for something other than NS; we skip it.
  504. if (found && task->op == QueryTask::NOGLUE_QUERY) {
  505. return (true);
  506. }
  507. // Found a referral while getting answer data;
  508. // send a delegation.
  509. if (found) {
  510. RRsetPtr r = findRRsetFromList(ref, RRType::DNAME());
  511. if (r != NULL) {
  512. RRsetList syn;
  513. addToMessage(q, Message::SECTION_ANSWER, r);
  514. q.message().setHeaderFlag(Message::HEADERFLAG_AA);
  515. synthesizeCname(task, r, syn);
  516. if (syn.size() == 1) {
  517. RRsetPtr cname_rrset = findRRsetFromList(syn,
  518. RRType::CNAME());
  519. addToMessage(q, Message::SECTION_ANSWER, cname_rrset);
  520. chaseCname(q, task, cname_rrset);
  521. return (true);
  522. }
  523. }
  524. copyAuth(q, ref);
  525. return (true);
  526. }
  527. }
  528. // We appear to have authoritative data; set the header
  529. // flag. (We may clear it later if we find a referral
  530. // at the actual qname node.)
  531. if (task->op == QueryTask::AUTH_QUERY &&
  532. task->state == QueryTask::GETANSWER) {
  533. q.message().setHeaderFlag(Message::HEADERFLAG_AA);
  534. }
  535. return (false);
  536. }
  537. inline DataSrc::Result
  538. addSOA(Query& q, ZoneInfo& zoneinfo) {
  539. RRsetList soa;
  540. const Name* const zonename = zoneinfo.getEnclosingZone();
  541. QueryTask newtask(q, *zonename, RRType::SOA(), QueryTask::SIMPLE_QUERY);
  542. RETERR(doQueryTask(newtask, zoneinfo, soa));
  543. if (newtask.flags != 0) {
  544. return (DataSrc::ERROR);
  545. }
  546. addToMessage(q, Message::SECTION_AUTHORITY,
  547. findRRsetFromList(soa, RRType::SOA()));
  548. return (DataSrc::SUCCESS);
  549. }
  550. inline DataSrc::Result
  551. addNSEC(Query& q, const Name& name, ZoneInfo& zoneinfo) {
  552. RRsetList nsec;
  553. QueryTask newtask(q, name, RRType::NSEC(), QueryTask::SIMPLE_QUERY);
  554. RETERR(doQueryTask(newtask, zoneinfo, nsec));
  555. if (newtask.flags == 0) {
  556. addToMessage(q, Message::SECTION_AUTHORITY,
  557. findRRsetFromList(nsec, RRType::NSEC()));
  558. }
  559. return (DataSrc::SUCCESS);
  560. }
  561. inline DataSrc::Result
  562. getNsec3(Query& q, ZoneInfo& zoneinfo, string& hash, RRsetPtr& target) {
  563. const DataSrc* ds = zoneinfo.getDataSource();
  564. const Name* const zonename = zoneinfo.getEnclosingZone();
  565. if (ds == NULL) {
  566. q.message().setRcode(Rcode::SERVFAIL());
  567. return (DataSrc::ERROR);
  568. }
  569. RRsetList rl;
  570. RETERR(ds->findCoveringNSEC3(*zonename, hash, rl));
  571. target = rl.findRRset(RRType::NSEC3(), q.qclass());
  572. return (DataSrc::SUCCESS);
  573. }
  574. ConstNsec3ParamPtr
  575. getNsec3Param(Query& q, ZoneInfo& zoneinfo) {
  576. DataSrc::Result result;
  577. RRsetList nsec3param;
  578. const Name* const zonename = zoneinfo.getEnclosingZone();
  579. QueryTask newtask(q, *zonename, RRType::NSEC3PARAM(),
  580. QueryTask::SIMPLE_QUERY);
  581. result = doQueryTask(newtask, zoneinfo, nsec3param);
  582. newtask.flags &= ~DataSrc::REFERRAL;
  583. if (result != DataSrc::SUCCESS || newtask.flags != 0) {
  584. return (ConstNsec3ParamPtr());
  585. }
  586. RRsetPtr rrset = nsec3param.findRRset(RRType::NSEC3PARAM(), q.qclass());
  587. if (!rrset) {
  588. return (ConstNsec3ParamPtr());
  589. }
  590. // XXX: currently only one NSEC3 chain per zone is supported;
  591. // we will need to revisit this.
  592. RdataIteratorPtr it = rrset->getRdataIterator();
  593. if (it->isLast()) {
  594. return (ConstNsec3ParamPtr());
  595. }
  596. const generic::NSEC3PARAM& np =
  597. dynamic_cast<const generic::NSEC3PARAM&>(it->getCurrent());
  598. return (ConstNsec3ParamPtr(new Nsec3Param(np.getHashalg(), np.getFlags(),
  599. np.getIterations(),
  600. np.getSalt())));
  601. }
  602. inline DataSrc::Result
  603. proveNX(Query& q, QueryTaskPtr task, ZoneInfo& zoneinfo, const bool wildcard) {
  604. Message& m = q.message();
  605. const Name* const zonename = zoneinfo.getEnclosingZone();
  606. ConstNsec3ParamPtr nsec3 = getNsec3Param(q, zoneinfo);
  607. if (nsec3 != NULL) {
  608. // Attach the NSEC3 record covering the QNAME
  609. RRsetPtr rrset;
  610. string hash1(nsec3->getHash(task->qname));
  611. RETERR(getNsec3(q, zoneinfo, hash1, rrset));
  612. addToMessage(q, Message::SECTION_AUTHORITY, rrset);
  613. // If this is an NXRRSET or NOERROR/NODATA, we're done
  614. if ((task->flags & DataSrc::TYPE_NOT_FOUND) != 0) {
  615. return (DataSrc::SUCCESS);
  616. }
  617. // Find the closest provable enclosing name for QNAME
  618. Name enclosure(*zonename);
  619. const int diff = task->qname.getLabelCount() -
  620. enclosure.getLabelCount();
  621. string hash2;
  622. for (int i = 1; i <= diff; ++i) {
  623. enclosure = task->qname.split(i);
  624. string nodehash(nsec3->getHash(enclosure));
  625. if (nodehash == hash1) {
  626. break;
  627. }
  628. hash2 = nodehash;
  629. RRsetList rl;
  630. // hash2 will be overwritten with the actual hash found;
  631. // we don't want to use one until we find an exact match
  632. RETERR(getNsec3(q, zoneinfo, hash2, rrset));
  633. if (hash2 == nodehash) {
  634. addToMessage(q, Message::SECTION_AUTHORITY, rrset);
  635. break;
  636. }
  637. }
  638. // If we are processing a wildcard answer, we're done.
  639. if (wildcard) {
  640. return (DataSrc::SUCCESS);
  641. }
  642. // Otherwise, there is no wildcard record, so we must add a
  643. // covering NSEC3 to prove that it doesn't exist.
  644. string hash3(nsec3->getHash(Name("*").concatenate(enclosure)));
  645. RETERR(getNsec3(q, zoneinfo, hash3, rrset));
  646. if (hash3 != hash1 && hash3 != hash2) {
  647. addToMessage(q, Message::SECTION_AUTHORITY, rrset);
  648. }
  649. } else {
  650. Name nsecname(task->qname);
  651. if ((task->flags & DataSrc::NAME_NOT_FOUND) != 0 || wildcard) {
  652. const DataSrc* ds = zoneinfo.getDataSource();
  653. if (ds == NULL) {
  654. m.setRcode(Rcode::SERVFAIL());
  655. return (DataSrc::ERROR);
  656. }
  657. ds->findPreviousName(task->qname, nsecname, zonename);
  658. }
  659. RETERR(addNSEC(q, nsecname, zoneinfo));
  660. if ((task->flags & DataSrc::TYPE_NOT_FOUND) != 0 ||
  661. nsecname == *zonename)
  662. {
  663. return (DataSrc::SUCCESS);
  664. }
  665. // If we are processing a wildcard answer, we're done.
  666. if (wildcard) {
  667. return (DataSrc::SUCCESS);
  668. }
  669. // Otherwise, there is no wildcard record, so we must add an
  670. // NSEC for the zone to prove the wildcard doesn't exist.
  671. RETERR(addNSEC(q, *zonename, zoneinfo));
  672. }
  673. return (DataSrc::SUCCESS);
  674. }
  675. // Attempt a wildcard lookup
  676. inline DataSrc::Result
  677. tryWildcard(Query& q, QueryTaskPtr task, ZoneInfo& zoneinfo, bool& found) {
  678. Message& m = q.message();
  679. DataSrc::Result result;
  680. found = false;
  681. if ((task->flags & DataSrc::NAME_NOT_FOUND) == 0 ||
  682. (task->state != QueryTask::GETANSWER &&
  683. task->state != QueryTask::FOLLOWCNAME)) {
  684. return (DataSrc::SUCCESS);
  685. }
  686. const Name* const zonename = zoneinfo.getEnclosingZone();
  687. const int diff = task->qname.getLabelCount() - zonename->getLabelCount();
  688. if (diff < 1) {
  689. return (DataSrc::SUCCESS);
  690. }
  691. RRsetList wild;
  692. const Name star("*");
  693. bool cname = false;
  694. for (int i = 1; i <= diff; ++i) {
  695. const Name& wname(star.concatenate(task->qname.split(i)));
  696. QueryTask newtask(q, wname, task->qtype, Message::SECTION_ANSWER,
  697. QueryTask::AUTH_QUERY);
  698. result = doQueryTask(newtask, zoneinfo, wild);
  699. if (result == DataSrc::SUCCESS) {
  700. if (newtask.flags == 0) {
  701. task->flags &= ~DataSrc::NAME_NOT_FOUND;
  702. task->flags &= ~DataSrc::TYPE_NOT_FOUND;
  703. found = true;
  704. break;
  705. } else if ((newtask.flags & DataSrc::CNAME_FOUND) != 0) {
  706. task->flags &= ~DataSrc::NAME_NOT_FOUND;
  707. task->flags &= ~DataSrc::TYPE_NOT_FOUND;
  708. task->flags |= DataSrc::CNAME_FOUND;
  709. found = true;
  710. cname = true;
  711. break;
  712. } else if ((newtask.flags & DataSrc::TYPE_NOT_FOUND) != 0) {
  713. task->flags &= ~DataSrc::NAME_NOT_FOUND;
  714. task->flags |= DataSrc::TYPE_NOT_FOUND;
  715. break;
  716. }
  717. }
  718. }
  719. // A wildcard was found.
  720. if (found) {
  721. // Prove the nonexistence of the name we were looking for
  722. if (q.wantDnssec()) {
  723. result = proveNX(q, task, zoneinfo, true);
  724. if (result != DataSrc::SUCCESS) {
  725. m.setRcode(Rcode::SERVFAIL());
  726. return (DataSrc::ERROR);
  727. }
  728. }
  729. // Add the data to the answer section (but with the name changed to
  730. // match the qname), and then continue as if this were a normal
  731. // answer: if a CNAME, chase the target, otherwise add authority.
  732. if (cname) {
  733. RRsetPtr rrset = findRRsetFromList(wild, RRType::CNAME());
  734. if (rrset != NULL) {
  735. rrset->setName(task->qname);
  736. addToMessage(q, Message::SECTION_ANSWER, rrset);
  737. chaseCname(q, task, rrset);
  738. }
  739. } else {
  740. BOOST_FOREACH (RRsetPtr rrset, wild) {
  741. rrset->setName(task->qname);
  742. addToMessage(q, Message::SECTION_ANSWER, rrset);
  743. }
  744. RRsetList auth;
  745. if (!refQuery(q, *zonename, zoneinfo, auth)) {
  746. return (DataSrc::ERROR);
  747. }
  748. copyAuth(q, auth);
  749. }
  750. }
  751. return (DataSrc::SUCCESS);
  752. }
  753. //
  754. // doQuery: Processes a query.
  755. //
  756. void
  757. DataSrc::doQuery(Query& q) {
  758. Message& m = q.message();
  759. vector<RRsetPtr> additional;
  760. // Record the fact that the query is being processed by the
  761. // current data source.
  762. q.setDatasrc(this);
  763. // Process the query task queue. (The queue is initialized
  764. // and the first task placed on it by the Query constructor.)
  765. m.setHeaderFlag(Message::HEADERFLAG_AA, false);
  766. while (!q.tasks().empty()) {
  767. QueryTaskPtr task = q.tasks().front();
  768. q.tasks().pop();
  769. // Can't query directly for RRSIG.
  770. if (task->qtype == RRType::RRSIG()) {
  771. m.setRcode(Rcode::REFUSED());
  772. return;
  773. }
  774. // These task types should never be on the task queue.
  775. if (task->op == QueryTask::SIMPLE_QUERY ||
  776. task->op == QueryTask::REF_QUERY) {
  777. m.setRcode(Rcode::SERVFAIL());
  778. return;
  779. }
  780. ZoneInfo zoneinfo(this, task->qname, task->qclass, task->qtype);
  781. RRsetList data;
  782. Result result = SUCCESS;
  783. // For these query task types, if there is more than
  784. // one level between the zone name and qname, we need to
  785. // check the intermediate nodes for referrals.
  786. if ((task->op == QueryTask::AUTH_QUERY ||
  787. task->op == QueryTask::NOGLUE_QUERY) &&
  788. hasDelegation(q, task, zoneinfo)) {
  789. continue;
  790. }
  791. result = doQueryTask(*task, zoneinfo, data);
  792. if (result != SUCCESS) {
  793. m.setRcode(Rcode::SERVFAIL());
  794. return;
  795. }
  796. // No such zone. If we're chasing cnames or adding additional
  797. // data, that's okay, but if doing an original query, return
  798. // REFUSED.
  799. if (task->flags == NO_SUCH_ZONE) {
  800. if (task->state == QueryTask::GETANSWER) {
  801. m.setRcode(Rcode::REFUSED());
  802. return;
  803. }
  804. continue;
  805. }
  806. // Query found a referral; let's find out if that was expected--
  807. // i.e., if an NS was at the zone apex, or if we were querying
  808. // specifically for, and found, a DS, NSEC, or DNAME record.
  809. const Name* const zonename = zoneinfo.getEnclosingZone();
  810. if ((task->flags & REFERRAL) != 0 &&
  811. (zonename->getLabelCount() == task->qname.getLabelCount() ||
  812. ((task->qtype == RRType::NSEC() ||
  813. task->qtype == RRType::DS() ||
  814. task->qtype == RRType::DNAME()) &&
  815. findRRsetFromList(data, task->qtype)))) {
  816. task->flags &= ~REFERRAL;
  817. }
  818. if (result == SUCCESS && task->flags == 0) {
  819. bool have_ns = false, need_auth = false;
  820. switch (task->state) {
  821. case QueryTask::GETANSWER:
  822. case QueryTask::FOLLOWCNAME:
  823. BOOST_FOREACH(RRsetPtr rrset, data) {
  824. addToMessage(q, task->section, rrset);
  825. if (q.tasks().empty()) {
  826. need_auth = true;
  827. }
  828. getAdditional(q, rrset);
  829. if (rrset->getType() == RRType::NS()) {
  830. have_ns = true;
  831. }
  832. }
  833. q.setStatus(Query::ANSWERED);
  834. if (need_auth && !have_ns) {
  835. // Data found, no additional processing needed.
  836. // Add the NS records for the enclosing zone to
  837. // the authority section.
  838. RRsetList auth;
  839. if (!refQuery(q, Name(*zonename), zoneinfo, auth) ||
  840. !findRRsetFromList(auth, RRType::NS())) {
  841. isc_throw(DataSourceError,
  842. "NS RR not found in " << *zonename << "/" <<
  843. q.qclass());
  844. }
  845. copyAuth(q, auth);
  846. }
  847. continue;
  848. case QueryTask::GETADDITIONAL:
  849. // Got additional data. Do not add it to the message
  850. // yet; instead store it and copy it in at the end
  851. // (this allow RRSIGs to be omitted if necessary).
  852. BOOST_FOREACH(RRsetPtr rrset, data) {
  853. if (q.status() == Query::ANSWERED &&
  854. rrset->getName() == q.qname() &&
  855. rrset->getType() == q.qtype()) {
  856. continue;
  857. }
  858. additional.push_back(rrset);
  859. }
  860. continue;
  861. default:
  862. isc_throw (Unexpected, "unexpected query state");
  863. }
  864. } else if (result == ERROR || result == NOT_IMPLEMENTED) {
  865. m.setRcode(Rcode::SERVFAIL());
  866. return;
  867. } else if ((task->flags & CNAME_FOUND) != 0) {
  868. // The qname node contains a CNAME. Add a new task to the
  869. // queue to look up its target.
  870. RRsetPtr rrset = findRRsetFromList(data, RRType::CNAME());
  871. if (rrset != NULL) {
  872. addToMessage(q, task->section, rrset);
  873. chaseCname(q, task, rrset);
  874. }
  875. continue;
  876. } else if ((task->flags & REFERRAL) != 0) {
  877. // The qname node contains an out-of-zone referral.
  878. if (task->state == QueryTask::GETANSWER) {
  879. RRsetList auth;
  880. m.setHeaderFlag(Message::HEADERFLAG_AA, false);
  881. if (!refQuery(q, task->qname, zoneinfo, auth)) {
  882. m.setRcode(Rcode::SERVFAIL());
  883. return;
  884. }
  885. BOOST_FOREACH (RRsetPtr rrset, auth) {
  886. if (rrset->getType() == RRType::NS()) {
  887. addToMessage(q, Message::SECTION_AUTHORITY, rrset);
  888. } else if (rrset->getType() == task->qtype) {
  889. addToMessage(q, Message::SECTION_ANSWER, rrset);
  890. } else if (rrset->getType() == RRType::DS() &&
  891. q.wantDnssec()) {
  892. addToMessage(q, Message::SECTION_AUTHORITY, rrset);
  893. }
  894. getAdditional(q, rrset);
  895. }
  896. }
  897. continue;
  898. } else if ((task->flags & (NAME_NOT_FOUND|TYPE_NOT_FOUND)) != 0) {
  899. // No data found at this qname/qtype.
  900. // If we were looking for additional data, we should simply
  901. // ignore this result.
  902. if (task->state == QueryTask::GETADDITIONAL) {
  903. continue;
  904. }
  905. // If we were looking for answer data, not additional,
  906. // and the name was not found, we need to find out whether
  907. // there are any relevant wildcards.
  908. bool wildcard_found = false;
  909. result = tryWildcard(q, task, zoneinfo, wildcard_found);
  910. if (result != SUCCESS) {
  911. m.setRcode(Rcode::SERVFAIL());
  912. return;
  913. }
  914. if (wildcard_found) {
  915. continue;
  916. }
  917. // If we've reached this point, there is definitely no answer.
  918. // If we were chasing cnames or adding additional data, that's
  919. // okay, but if we were doing an original query, reply with the
  920. // SOA in the authority section. For NAME_NOT_FOUND, set
  921. // NXDOMAIN, and also add the previous NSEC to the authority
  922. // section. For TYPE_NOT_FOUND, do not set an error rcode,
  923. // and send the current NSEC in the authority section.
  924. if (task->state == QueryTask::GETANSWER) {
  925. if ((task->flags & NAME_NOT_FOUND) != 0) {
  926. m.setRcode(Rcode::NXDOMAIN());
  927. }
  928. result = addSOA(q, zoneinfo);
  929. if (result != SUCCESS) {
  930. isc_throw(DataSourceError,
  931. "SOA RR not found in " << *zonename <<
  932. "/" << q.qclass());
  933. }
  934. }
  935. Name nsecname(task->qname);
  936. if ((task->flags & NAME_NOT_FOUND) != 0) {
  937. const DataSrc* ds = zoneinfo.getDataSource();
  938. ds->findPreviousName(task->qname, nsecname, zonename);
  939. }
  940. if (q.wantDnssec()) {
  941. result = proveNX(q, task, zoneinfo, false);
  942. if (result != DataSrc::SUCCESS) {
  943. m.setRcode(Rcode::SERVFAIL());
  944. return;
  945. }
  946. }
  947. return;
  948. } else {
  949. // Should never be reached!
  950. m.setRcode(Rcode::SERVFAIL());
  951. return;
  952. }
  953. }
  954. // We're done, so now copy in the additional data:
  955. // data first, then signatures. (If we run out of
  956. // space, signatures in additional section are
  957. // optional.)
  958. BOOST_FOREACH(RRsetPtr rrset, additional) {
  959. addToMessage(q, Message::SECTION_ADDITIONAL, rrset, true);
  960. }
  961. if (q.wantDnssec()) {
  962. BOOST_FOREACH(RRsetPtr rrset, additional) {
  963. if (rrset->getRRsig()) {
  964. addToMessage(q, Message::SECTION_ADDITIONAL, rrset->getRRsig(),
  965. true);
  966. }
  967. }
  968. }
  969. }
  970. DataSrc::Result
  971. DataSrc::findAddrs(const Name& qname, const RRClass& qclass,
  972. RRsetList& target, uint32_t& flags,
  973. const Name* zonename) const
  974. {
  975. Result r;
  976. bool a = false, aaaa = false;
  977. flags = 0;
  978. r = findExactRRset(qname, qclass, RRType::A(), target, flags, zonename);
  979. if (r == SUCCESS && flags == 0) {
  980. a = true;
  981. }
  982. flags = 0;
  983. r = findExactRRset(qname, qclass, RRType::AAAA(), target, flags,
  984. zonename);
  985. if (r == SUCCESS && flags == 0) {
  986. aaaa = true;
  987. }
  988. if (!a && !aaaa) {
  989. flags = TYPE_NOT_FOUND;
  990. } else {
  991. flags = 0;
  992. }
  993. return (SUCCESS);
  994. }
  995. DataSrc::Result
  996. DataSrc::findReferral(const Name& qname, const RRClass& qclass,
  997. RRsetList& target, uint32_t& flags,
  998. const Name* zonename) const
  999. {
  1000. Result r;
  1001. bool ns = false, ds = false, dname = false;
  1002. flags = 0;
  1003. r = findExactRRset(qname, qclass, RRType::NS(), target, flags, zonename);
  1004. if (r == SUCCESS && flags == 0) {
  1005. ns = true;
  1006. } else if ((flags & (NO_SUCH_ZONE|NAME_NOT_FOUND))) {
  1007. return (SUCCESS);
  1008. }
  1009. flags = 0;
  1010. r = findExactRRset(qname, qclass, RRType::DS(), target, flags, zonename);
  1011. if (r == SUCCESS && flags == 0) {
  1012. ds = true;
  1013. } else if ((flags & (NO_SUCH_ZONE|NAME_NOT_FOUND))) {
  1014. return (SUCCESS);
  1015. }
  1016. flags = 0;
  1017. r = findExactRRset(qname, qclass, RRType::DNAME(), target, flags, zonename);
  1018. if (r == SUCCESS && flags == 0) {
  1019. dname = true;
  1020. } else if ((flags & (NO_SUCH_ZONE|NAME_NOT_FOUND))) {
  1021. return (SUCCESS);
  1022. }
  1023. if (!ns && !dname && !ds) {
  1024. flags = TYPE_NOT_FOUND;
  1025. } else {
  1026. flags = 0;
  1027. }
  1028. return (SUCCESS);
  1029. }
  1030. void
  1031. MetaDataSrc::addDataSrc(ConstDataSrcPtr data_src) {
  1032. if (getClass() != RRClass::ANY() && data_src->getClass() != getClass()) {
  1033. isc_throw(Unexpected, "class mismatch");
  1034. }
  1035. data_sources.push_back(data_src);
  1036. }
  1037. void
  1038. MetaDataSrc::removeDataSrc(ConstDataSrcPtr data_src) {
  1039. std::vector<ConstDataSrcPtr>::iterator it, itr;
  1040. for (it = data_sources.begin(); it != data_sources.end(); ++it) {
  1041. if (*it == data_src) {
  1042. itr = it;
  1043. }
  1044. }
  1045. data_sources.erase(itr);
  1046. }
  1047. void
  1048. MetaDataSrc::findClosestEnclosure(DataSrcMatch& match) const {
  1049. if (getClass() != match.getClass() &&
  1050. getClass() != RRClass::ANY() && match.getClass() != RRClass::ANY()) {
  1051. return;
  1052. }
  1053. BOOST_FOREACH (ConstDataSrcPtr data_src, data_sources) {
  1054. data_src->findClosestEnclosure(match);
  1055. }
  1056. }
  1057. DataSrcMatch::~DataSrcMatch() {
  1058. delete closest_name_;
  1059. }
  1060. void
  1061. DataSrcMatch::update(const DataSrc& new_source, const Name& container) {
  1062. if (getClass() != new_source.getClass() && getClass() != RRClass::ANY() &&
  1063. new_source.getClass() != RRClass::ANY())
  1064. {
  1065. return;
  1066. }
  1067. if (closest_name_ == NULL) {
  1068. const NameComparisonResult::NameRelation cmp =
  1069. getName().compare(container).getRelation();
  1070. if (cmp != NameComparisonResult::EQUAL &&
  1071. cmp != NameComparisonResult::SUBDOMAIN)
  1072. {
  1073. return;
  1074. }
  1075. closest_name_ = new Name(container);
  1076. best_source_ = &new_source;
  1077. return;
  1078. }
  1079. if (container.compare(*closest_name_).getRelation() ==
  1080. NameComparisonResult::SUBDOMAIN) {
  1081. Name* newname = new Name(container);
  1082. delete closest_name_;
  1083. closest_name_ = newname;
  1084. best_source_ = &new_source;
  1085. }
  1086. }
  1087. Nsec3Param::Nsec3Param(const uint8_t a, const uint8_t f, const uint16_t i,
  1088. const std::vector<uint8_t>& s) :
  1089. algorithm_(a), flags_(f), iterations_(i), salt_(s)
  1090. {}
  1091. string
  1092. Nsec3Param::getHash(const Name& name) const {
  1093. OutputBuffer buf(0);
  1094. name.toWire(buf);
  1095. uint8_t digest[SHA1_HASHSIZE];
  1096. const uint8_t* input = static_cast<const uint8_t*>(buf.getData());
  1097. size_t inlength = buf.getLength();
  1098. const uint8_t saltlen = salt_.size();
  1099. int n = 0;
  1100. SHA1Context sha;
  1101. do {
  1102. SHA1Reset(&sha);
  1103. SHA1Input(&sha, input, inlength);
  1104. SHA1Input(&sha, &salt_[0], saltlen);
  1105. SHA1Result(&sha, digest);
  1106. input = digest;
  1107. inlength = SHA1_HASHSIZE;
  1108. } while (n++ < iterations_);
  1109. return (encodeBase32Hex(vector<uint8_t>(digest, digest + SHA1_HASHSIZE)));
  1110. }
  1111. DataSrc::Result
  1112. DataSrc::init(isc::data::ConstElementPtr) {
  1113. return (NOT_IMPLEMENTED);
  1114. }
  1115. DataSrc::Result
  1116. MetaDataSrc::findRRset(const isc::dns::Name&,
  1117. const isc::dns::RRClass&,
  1118. const isc::dns::RRType&,
  1119. isc::dns::RRsetList&,
  1120. uint32_t&,
  1121. const isc::dns::Name*) const
  1122. {
  1123. return (NOT_IMPLEMENTED);
  1124. }
  1125. DataSrc::Result
  1126. MetaDataSrc::findExactRRset(const isc::dns::Name&,
  1127. const isc::dns::RRClass&,
  1128. const isc::dns::RRType&,
  1129. isc::dns::RRsetList&,
  1130. uint32_t&,
  1131. const isc::dns::Name*) const
  1132. {
  1133. return (NOT_IMPLEMENTED);
  1134. }
  1135. DataSrc::Result
  1136. MetaDataSrc::findAddrs(const isc::dns::Name&,
  1137. const isc::dns::RRClass&,
  1138. isc::dns::RRsetList&,
  1139. uint32_t&,
  1140. const isc::dns::Name*) const
  1141. {
  1142. return (NOT_IMPLEMENTED);
  1143. }
  1144. DataSrc::Result
  1145. MetaDataSrc::findReferral(const isc::dns::Name&,
  1146. const isc::dns::RRClass&,
  1147. isc::dns::RRsetList&,
  1148. uint32_t&,
  1149. const isc::dns::Name*) const
  1150. {
  1151. return (NOT_IMPLEMENTED);
  1152. }
  1153. DataSrc::Result
  1154. MetaDataSrc::findPreviousName(const isc::dns::Name&,
  1155. isc::dns::Name&,
  1156. const isc::dns::Name*) const
  1157. {
  1158. return (NOT_IMPLEMENTED);
  1159. }
  1160. DataSrc::Result
  1161. MetaDataSrc::findCoveringNSEC3(const isc::dns::Name&,
  1162. std::string&,
  1163. isc::dns::RRsetList&) const
  1164. {
  1165. return (NOT_IMPLEMENTED);
  1166. }
  1167. }
  1168. }