test_datasrc.cc 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  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. // $Id$
  15. #include "config.h"
  16. #include <cassert>
  17. #include <algorithm>
  18. #include <dns/tests/unittest_util.h>
  19. #include "test_datasrc.h"
  20. #include <datasrc/data_source.h>
  21. #include <dns/buffer.h>
  22. #include <dns/messagerenderer.h>
  23. #include <dns/name.h>
  24. #include <dns/rdata.h>
  25. #include <dns/rdataclass.h>
  26. #include <dns/rrclass.h>
  27. #include <dns/rrset.h>
  28. #include <dns/rrsetlist.h>
  29. #include <dns/rrtype.h>
  30. #include <dns/rrttl.h>
  31. #include <iostream>
  32. using isc::UnitTestUtil;
  33. using namespace std;
  34. using namespace isc::dns;
  35. using namespace isc::dns::rdata;
  36. namespace isc {
  37. namespace datasrc {
  38. namespace {
  39. // This is a mock data source for testing. It can contain multiple zones.
  40. // The content of each zone should be configured in the form of RRData{}.
  41. // Each RRData element is a tuple of char strings, representing
  42. // "name, RRtype, RDATA". For simplicity we use the same single TTL for
  43. // RRs (TEST_TTL) defined below.
  44. // Multiple RRs of the same pair of (name, RRtype) can be defined, but
  45. // they must not be interleaved with other types of pair. For example,
  46. // This is okay:
  47. // {"example.com", "AAAA", "2001:db8::1"},
  48. // {"example.com", "AAAA", "2001:db8::2"},
  49. // ...
  50. // but this is invalid:
  51. // {"example.com", "AAAA", "2001:db8::1"},
  52. // {"example.com", "A", "192.0.2.1"},
  53. // {"example.com", "AAAA", "2001:db8::2"},
  54. // ...
  55. // If an RRset is associated with an RRSIG, the RRSIG must immediately follow
  56. // the RRset to be signed. Currently, only one (or zero) RRSIG can be
  57. // specified per RRset.
  58. //
  59. // Names are sorted internally, and don't have to be sorted in the data.
  60. //
  61. // A zone is defined in the form of ZoneData{}, which contains:
  62. // zone name (character string)
  63. // RRclass (character string)
  64. // A pointer to in-zone RRs in the form of RRData{}
  65. // A pointer to glue RRs in the form of RRData{}
  66. // Glues can be omitted, in which case a convenient constant "empty_records"
  67. // can be specified.
  68. // For simplicity we use the same single TTL for all test RRs.
  69. const uint32_t TEST_TTL = 3600;
  70. struct RRData {
  71. const char* const name;
  72. const char* const rrtype;
  73. const char* const rdata;
  74. };
  75. struct ZoneData {
  76. const char* const zone_name;
  77. const char* const rrclass;
  78. const struct RRData* records;
  79. const struct RRData* glue_records;
  80. };
  81. //
  82. // zone data for example.com
  83. //
  84. const struct RRData example_com_records[] = {
  85. // example.com
  86. {"example.com", "NS", "dns01.example.com"},
  87. {"example.com", "NS", "dns02.example.com"},
  88. {"example.com", "NS", "dns03.example.com"},
  89. {"example.com", "RRSIG", "NS 5 2 3600 20100322084538 20100220084538 33495 example.com. ClcrfjkQZUY5L6ZlCkU3cJHzcrEGrofKSVeeoeZ+w6yeEowFNVXs2YBo3tom53DiCrdD9rs3feVSLGW5rjsz/O6lDuomgQG+EVSnWa7GTIPBXj1BmDXXp3XxeldYmhf4UzaN5BA+RUA5E8NChNKuNNof76j2S9tilfN/kvpy4fw="},
  90. {"example.com", "SOA", "master.example.com. admin.example.com. 1234 3600 1800 2419200 7200"},
  91. {"example.com", "RRSIG", "SOA 5 2 3600 20100322084538 20100220084538 33495 example.com. KUun66Qaw36osk2BJS6U1fAy3PPDkNo2QK4meGNbDBY8q8b+f2o+IXJ14YCvssGl1ORW0CcLnDRxssnk8V/Svmj5iFhO+8HC2hnVBdi2zewvdVtwRb+lWwKN7pkXXwuy6g1t9WCd/j5FCc/wgxqtZUTPb6XgZcnHrORDMOTqLs4="},
  92. {"example.com", "NSEC", "cname-ext.example.com. NS SOA MX RRSIG NSEC DNSKEY"},
  93. {"example.com", "RRSIG", "NSEC 5 2 7200 20100322084538 20100220084538 33495 example.com. KxuVaPPKNPJzr/q+cJPiNlkHVTQK0LVsgTbSqruXQc25lAd0wn5oKUtxL1bEAchHkfA8eLzcYCj2ZqqAv9OJubw53mfskTad7UHs4Uj2RTrIsNGMCiZGgOpvNb9JcWpQtoyXVT1uNse+Qsbeir0eyeYIufUynFU041jtNrlJMio="},
  94. // dns01.example.com
  95. {"dns01.example.com", "A", "192.0.2.1"},
  96. {"dns01.example.com", "RRSIG", "A 5 3 3600 20100322084538 20100220084538 33495 example.com. NIawlZLk8WZAjNux7oQM2mslfW52OZFFkWt++7FHu2SU98XqEeKfCMnpgtWe5T8Nr9cS8df901iEOJoWQzGTEaHYUBtEhsSjBVn7mKp3fz6473a2xxy75SUKZ0rxjNXSZ8Q5rnFmkX0HTH2Sg51mtjH6aC2pfheQnA2t193BnSg="},
  97. {"dns01.example.com", "NSEC", "dns02.example.com. A RRSIG NSEC"},
  98. {"dns01.example.com", "RRSIG", "NSEC 5 3 7200 20100322084538 20100220084538 33495 example.com. EkyeshmMNP9xiAz6mDFDIwksTdmkF9zsFzLuVKAgK6eUk7St6tp5PSvjA8nWol0vdvvz4LK85a4ffTFEiNRyvWeYP2vOhEkyDcrwuCd8Vc3jh/8Sm1Js+nX7hJStrZGFvp2TWPpt9nKH5p3MxXvTb/YVurnue0xSeFAE17O3+I0="},
  99. // dns02.example.com
  100. {"dns02.example.com", "A", "192.0.2.2"},
  101. {"dns02.example.com", "RRSIG", "A 5 3 3600 20100322084538 20100220084538 33495 example.com. XJtVMbUIRE0mk6Hn/Nx6k36jaxaBDPK2/IYB6vCQjJETz6gW4T6q/H/eY9/Lsw5iYPFhoBRDxT4XFj575t98kELXnJe1WhuMbRPlOhyOjxkLECaUne/sbFPOtbGFx9ohuojI0RgxxZiCFaO8wJuv6nfPuzmlLajWS6z9NZeOMIk="},
  102. {"dns02.example.com", "NSEC", "dns03.example.com. A RRSIG NSEC"},
  103. {"dns02.example.com", "RRSIG", "NSEC 5 3 7200 20100322084538 20100220084538 33495 example.com. imBNTMB3sPU4kblcaAH6V7lCVt5xgtAybi3DA/SbLEulLaV2NE6vcoEn/AieaM4mOJicQnUDj/H+1hSEhzxU2tRM8zfVlvztxQWn6eh7ZR4mKfNDSvRUGU9ykhpwMyC7wjOt1j5bcSA/OTnLRAilslnJyOM4bSaxVEFo8YPjncY="},
  104. // dns03.example.com
  105. {"dns03.example.com", "A", "192.0.2.3"},
  106. {"dns03.example.com", "RRSIG", "A 5 3 3600 20100322084538 20100220084538 33495 example.com. Ubrcm1H+F6m8khle7P9zU8eO+Jtuj+1Vx1MM5KAkmZPJwQe9uTcoCpQa6DXOGG9kajDTnNN1Be1gkZuJDTZJG4SmJLXLbNY3RDnxpGmWta3qs/VgDq78/YM8ropt1/s7YKyrCfGE2ff+FUB0mLObiG01ZV2gu5HJzgE7SEWLEiI="},
  107. {"dns03.example.com", "NSEC", "foo.example.com. A RRSIG NSEC"},
  108. {"dns03.example.com", "RRSIG", "NSEC 5 3 7200 20100322084538 20100220084538 33495 example.com. nn829Xw5CJFnPHwI9WHeT5epQv+odtCkHnjlPFGoPTLOyiks+041UmMqtq3uiSp4d2meMSe9UuDvoROT0L6NTtQQvVqiDhTn0irTFw1uw7fO8ZTG7eyu6Ypfz0+HvfbNvd4kMoD2OTgADRXPVsCTwK+PBOIIG9YTEQfl8pCqW5g="},
  109. // www.example.com
  110. {"www.example.com", "A", "192.0.2.1"},
  111. {"www.example.com", "RRSIG", "A 5 3 3600 20100322084538 20100220084538 33495 example.com. qyFyyV/mE8x4pdhudr5iycwhDsva31MzwO1kBR+bDKvzJg8mN8KxlPZrOlNNUhd3YRXQVwieMyxOTWRPXoxrNEDkNwimXkfe3rrHY7ibV9eNS4OIBUjb44VjCNr9CmQSzfuQ2yxO2r+YIuPYHRCjieD4xh6t9ay4IaCN/tDAJ+Q="},
  112. {"www.example.com", "NSEC", "example.com. A RRSIG NSEC"},
  113. {"www.example.com", "RRSIG", "NSEC 5 3 7200 20100322084538 20100220084538 33495 example.com. ZLZlSVBa2oe4U+7SZASnypP2VkI5gg1/1cVGqYUvfYNIUkcVMWDgn7DZCfpmo+2vdlV/4VhAc+sjDd+X+e57XGnW8+lqZHvG6NMMhmSGmeATD3D+8lEJJGo0dxoN4rHJQyp/eT2S4nChz+D/ze+YRagYxGF7pXm9zcrw3kKZGTs="},
  114. // *.wild.example.com
  115. {"*.wild.example.com", "A", "192.0.2.2"},
  116. {"*.wild.example.com", "RRSIG", "A 5 3 3600 20100322084538 20100220084538 33495 example.com. FdO+UWONgtLKFxUzzygGunw67F9y8SzsP7yOLEYVJclRR8X3Ii62L0gtQHq2y0TcKsXttRsD6XY+tM5P/pgXlTNi7Bk4Fgb0PIDPjOsfT4DrS80kWn0YbinM/4/FA1j5ru5sTTboOY5UGhvDnoA9ogNuQQYb2/3wkoH0PrA2Q/0="},
  117. {"*.wild.example.com", "NSEC", "*.wild2.example.com. A RRSIG NSEC"},
  118. {"*.wild.example.com", "RRSIG", "NSEC 5 3 7200 20100322084538 20100220084538 33495 example.com. OoGYslRj4xjZnBuzgOqsrvkDAHWycmQzbUxCRmgWnCbXiobJK7/ynONH3jm8G3vGlU0lwpHkhNs6cUK+6Nu8W49X3MT0Xksl/brroLcXYLi3vfxnYUNMMpXdeFl6WNNfoJRo90F/f/TWXAClRrDS29qiG3G1PEJZikIxZsZ0tyM="},
  119. // *.wild2.example.com
  120. {"*.wild2.example.com", "CNAME", "www.example.com"},
  121. {"*.wild2.example.com", "RRSIG", "CNAME 5 3 3600 20100410212307 20100311212307 33495 example.com. pGHtGdRBi4GKFSKszi6SsKvuBLDX8dFhZubU0tMojQ9SJuiFNF+WtxvdAYuUaoWP/9VLUaYmiw5u7JnzmR84DiXZPEs6DtD+UJdOZhaS7V7RTpE+tMOfVQBLpUnRWYtlTTmiBpFquzf3DdIxgUFhEPEuJJyp3LFRxJObCaq9 nvI="},
  122. {"*.wild2.example.com", "NSEC", "*.wild3.example.com. CNAME RRSIG NSEC"},
  123. {"*.wild2.example.com", "RRSIG", "NSEC 5 3 7200 20100410212307 20100311212307 33495 example.com. EuSzh6or8mbvwru2H7fyYeMpW6J8YZ528rabU38V/lMN0TdamghIuCneAvSNaZgwk2MSN1bWpZqB2kAipaM/ZI9/piLlTvVjjOQ8pjk0auwCEqT7Z7Qng3E92O9yVzO+WHT9QZn/fR6t60392In4IvcBGjZyjzQk8njIwbui xGA="},
  124. // *.wild3.example.com -- a wildcard record with a lame CNAME
  125. {"*.wild3.example.com", "CNAME", "spork.example.com"},
  126. {"*.wild3.example.com", "RRSIG", "CNAME 5 3 3600 20100410212307 20100311212307 33495 example.com. pGHtGdRBi4GKFSKszi6SsKvuBLDX8dFhZubU0tMojQ9SJuiFNF+WtxvdAYuUaoWP/9VLUaYmiw5u7JnzmR84DiXZPEs6DtD+UJdOZhaS7V7RTpE+tMOfVQBLpUnRWYtlTTmiBpFquzf3DdIxgUFhEPEuJJyp3LFRxJObCaq9 nvI="},
  127. {"*.wild3.example.com", "NSEC", "www.example.com. CNAME RRSIG NSEC"},
  128. {"*.wild3.example.com", "RRSIG", "NSEC 5 3 7200 20100410212307 20100311212307 33495 example.com. EuSzh6or8mbvwru2H7fyYeMpW6J8YZ528rabU38V/lMN0TdamghIuCneAvSNaZgwk2MSN1bWpZqB2kAipaM/ZI9/piLlTvVjjOQ8pjk0auwCEqT7Z7Qng3E92O9yVzO+WHT9QZn/fR6t60392In4IvcBGjZyjzQk8njIwbui xGA="},
  129. // foo.example.com
  130. {"foo.example.com", "CNAME", "cnametest.flame.org"},
  131. {"foo.example.com", "RRSIG", "CNAME 5 3 3600 20100322084538 20100220084538 33495 example.com. DSqkLnsh0gCeCPVW/Q8viy9GNP+KHmFGfWqyVG1S6koBtGN/VQQ16M4PHZ9Zssmf/JcDVJNIhAChHPE2WJiaPCNGTprsaUshf1Q2vMPVnkrJKgDY8SVRYMptmT8eaT0gGri4KhqRoFpMT5OYfesybwDgfhFSQQAh6ps3bIUsy4o="},
  132. {"foo.example.com", "NSEC", "mail.example.com. CNAME RRSIG NSEC"},
  133. {"foo.example.com", "RRSIG", "NSEC 5 3 7200 20100322084538 20100220084538 33495 example.com. RTQwlSqui6StUYye1KCSOEr1d3irndWFqHBpwP7g7n+w8EDXJ8I7lYgwzHvlQt6BLAxe5fUDi7ct8M5hXvsm7FoWPZ5wXH+2/eJUCYxIw4vezKMkMwBP6M/YkJ2CMqY8DppYf60QaLDONQAr7AcK/naSyioeI5h6eaoVitUDMso="},
  134. // cname-int.example.com
  135. {"cname-int.example.com", "CNAME", "www.example.com."},
  136. {"cname-int.example.com", "RRSIG", "CNAME 5 3 3600 20100322084538 20100220084538 33495 example.com. U1wjt0XY9xjTwvUmWSUcfLGMhCjfX2ylWfHrycy50x2oxcK9z94E1ejen9wDTIEBSGYgi6wpZ8RK0+02N1DWTGpDqNXd7aFRfDrWQJ/q/XJHDx0vlcmhkWhrT82LBfKxkrptOzchuSo/c0mpK+mpiIMc1VOwY+yuQ2ALfcD6EHw="},
  137. {"cname-int.example.com", "NSEC", "dname.example.com. CNAME RRSIG NSEC"},
  138. {"cname-int.example.com", "RRSIG", "NSEC 5 3 7200 20100322084538 20100220084538 33495 example.com. rbV+gaxfrsoha59NOLF4EFyWQ+GuFCVK/8D77x1atan3HNlXBlZ1smgudKTaJ3CtlobIDt0MEdPxY1yn2Tskw/5mlP1PWf8oaP3BwGSQdn4gLI8+sMpNOPFEdXpxqxngm2F6/7fqniL1QuSAQBEdO+5UiCAgnncPmAsSJg3u1zg="},
  139. // cname-ext.example.com
  140. {"cname-ext.example.com", "CNAME", "www.sql1.example.com"},
  141. {"cname-ext.example.com", "RRSIG", "CNAME 5 3 3600 20100322084538 20100220084538 33495 example.com. bGPIuZilyygvTThK4BrdECuaBcnZUgW/0d09iN2CrNjckchQl3dtbnMNirFsVs9hShDSldRNlQpiAVMpnPgXHhReNum7jmX6yqIH6s8GKIo91zr3VL/ramlezie5w4MilDHrxXLK2pb8IHmP+ZHivQ2EtdYQZgETWBWxr5FDfwk="},
  142. {"cname-ext.example.com", "NSEC", "cname-int.example.com. CNAME RRSIG NSEC"},
  143. {"cname-ext.example.com", "RRSIG", "NSEC 5 3 7200 20100322084538 20100220084538 33495 example.com. inWsFwSDWG7TakjwbUTzTRpXz0WifelA5Kn3ABk6BVirIPmd+yQoNj2QZBDFAQwhnLPlNws2Oo4vgMsBMyx1Fv5eHgMUuCN3DUDaLlzlPtUb42CjOUa+jZBeTV/Hd7WZrirluASE1QFDprLdSSqoPPfAKvN3pORtW7y580dMOIM="},
  144. // dname.example.com
  145. {"dname.example.com", "DNAME", "sql1.example.com."},
  146. {"dname.example.com", "RRSIG", "DNAME 5 3 3600 20100322084538 20100220084538 33495 example.com. ae8U47oaiwWdurkSyzcsCAF6DxBqjukizwF7K7U6lQVMtfoUE14oiAqfj1fjH8YLDOO/Hd1twrd/u0vgjnI1Gg32YTi7cYOzwE912SV1u2B/y0awaQKWPBwOW0aI7vxelt1vMUF81xosiQD04gOIdDBTqbHKcDxum87iWbhk4Ug="},
  147. {"dname.example.com", "NSEC", "dns01.example.com. DNAME RRSIG NSEC"},
  148. {"dname.example.com", "RRSIG", "NSEC 5 3 7200 20100322084538 20100220084538 33495 example.com. c21Fff2D8vBrLzohBnUeflkaRdUAnUxAFGp+UQ0miACDCMOFBlCS9v9g/2+orOnKfd3l4vyz55C310t8JXgXb119ofaZWj2zkdUe+X8Bax+sMS0Y5K/sUhSNvbJbozr9UYPdvjSVBiWgh3s9fsb+etKq9uFukAzGU/FuGYpO0r0="},
  149. // subzone.example.com
  150. {"subzone.example.com", "NS", "ns1.subzone.example.com"},
  151. {"subzone.example.com", "NS", "ns2.subzone.example.com"},
  152. {"subzone.example.com", "NSEC", "*.wild.example.com. NS DS RRSIG NSEC"},
  153. {"subzone.example.com", "RRSIG", "NSEC 5 3 7200 20100322084538 20100220084538 33495 example.com. Oe2kgIhsLtPJ4+lDZDxznV8/vEVoXKOBFN9lwWyebaKa19BaSXlQ+YVejmulmKDDjEucMvEfuItfn6w7bnU+DzOLk5D1lJCjwDlKz8u3xOAx16TiuQn4bgQAOiFtBQygmGGqO3BVpX+jxsmw7eH3emofy8uUqr/C4aopnwuf28g="},
  154. {"subzone.example.com", "DS", "33313 5 1 0FDD7A2C11AA7F55D50FBF9B7EDDA2322C541A8D"},
  155. {"subzone.example.com", "DS", "33313 5 2 00B99B7006F496D135B01AB17EDB469B4BE9E1973884DEA757BC4E3015A8C3AB"},
  156. {"subzone.example.com", "RRSIG", "DS 5 3 3600 20100322084538 20100220084538 33495 example.com. dIqZKvpkJN1l92SOiWgJh3KbjErIN+EfojMsm4pEdV5xQdZwj6DNNEu6Kw4rRwdvrZIu0TyqPr3jSJb7o6R7vZgZzmLfVV/ojQah7rwuYHCFcfyZ4JyK2311fMhRR1QAvMsdcjdyA1XC140Cm6AnL3cH5rh/KUks/0ec3Ca7GNQ="},
  157. // subset of child zone: sql1
  158. {"sql1.example.com", "NS", "dns01.example.com"},
  159. {"sql1.example.com", "NS", "dns02.example.com"},
  160. {"sql1.example.com", "NS", "dns03.example.com"},
  161. {"sql1.example.com", "DS", "33313 5 1 0FDD7A2C11AA7F55D50FBF9B7EDDA2322C541A8D"},
  162. {"sql1.example.com", "DS", "33313 5 2 00B99B7006F496D135B01AB17EDB469B4BE9E1973884DEA757BC4E3015A8C3AB"},
  163. {"sql1.example.com", "RRSIG", "DS 5 3 3600 20100322084538 20100220084538 33495 example.com. dIqZKvpkJN1l92SOiWgJh3KbjErIN+EfojMsm4pEdV5xQdZwj6DNNEu6Kw4rRwdvrZIu0TyqPr3jSJb7o6R7vZgZzmLfVV/ojQah7rwuYHCFcfyZ4JyK2311fMhRR1QAvMsdcjdyA1XC140Cm6AnL3cH5rh/KUks/0ec3Ca7GNQ="},
  164. {"sql1.example.com", "NSEC", "subzone.example.com. NS DS RRSIG NSEC"},
  165. {"sql1.example.com", "RRSIG", "NSEC 5 3 7200 20100322084538 20100220084538 33495 example.com. k9FRdFyk/cPdkmmaoZbGZPpzIzfbFWQ3QCHd2qhJa0xAXaEOT/GBL6aFqx9SlunDu2wgES+To5fWPZGi4NzWpp6c5t27rnATN/oCEQ/UYIJKmWbqrXdst0Ps5boznk7suK2Y+km31KxaIf3fDd/T3kZCVsR0aWKRRRatPb7GfLw="},
  166. {NULL, NULL, NULL}
  167. };
  168. const struct RRData example_com_glue_records[] = {
  169. {"ns1.subzone.example.com", "A", "192.0.2.1"},
  170. {"ns2.subzone.example.com", "A", "192.0.2.2"},
  171. {NULL, NULL, NULL}
  172. };
  173. //
  174. // zone data for sql1.example.com
  175. //
  176. const struct RRData sql1_example_com_records[] = {
  177. {"sql1.example.com", "NS", "dns01.example.com"},
  178. {"sql1.example.com", "NS", "dns02.example.com"},
  179. {"sql1.example.com", "NS", "dns03.example.com"},
  180. {"sql1.example.com", "RRSIG", "NS 5 3 3600 20100322084536 20100220084536 12447 sql1.example.com. 0CL8noy0NSgoWwuKd+Dc6vyIIw2BrAEBx0IJzcSB6GlB25x/zjEd6AJG0be13HN6jOaTX8iWTuCVrEYuXg76V+M4EvTZHjEScj0az74TrDv4Vdo459paGKCX9B8NLJW1mW4fzZrrXQ8jmBEZeS91Q5rJrO+UKJEuUz3LYdTPvao="},
  181. {"sql1.example.com", "SOA", "master.example.com. admin.example.com. 678 3600 1800 2419200 7200"},
  182. {"sql1.example.com", "RRSIG", "SOA 5 3 3600 20100322084536 20100220084536 12447 sql1.example.com. oakulfyljL/RAKgCKXEZ3KsG8BJj5WG4JK4moWFB6c9OKem6jIk8hKP2XlUVXFuOYJlRdIM4KicmR2GAK+5jJp6z5ShssstYTXo3QosVm6oCKumuFeLFHzcjfqP1D+F9NsvHldJIBnS/4ebPkmR5OENyCZXQF5HmN2awIj4CLjE="},
  183. {"sql1.example.com", "NSEC", "www.sql1.example.com. NS SOA RRSIG NSEC DNSKEY"},
  184. {"sql1.example.com", "RRSIG", "NSEC 5 3 7200 20100322084536 20100220084536 12447 sql1.example.com. v71CgdTYccCiTqfRcn6HsvISQa8ruvUfCKtpwym0RW/G27xlZn8otj2IMtWwkLxti8Rqqu+PTViLaOIbeVfHBcqzAd7U59cAOYoq3ODZx6auiE3C23HAKqUavKcP7Esaajm1cbcWy6Kyie4CAZc8M7EeKxgkXMKJGqBQzF+/FOo="},
  185. // www.sql1.example.com
  186. {"www.sql1.example.com", "A", "192.0.2.2"},
  187. {"www.sql1.example.com", "RRSIG", "A 5 4 3600 20100322084536 20100220084536 12447 sql1.example.com. DNdVKxB3oBsB14NPoV9WG14Y/g4zMcIXLYnFjj9vRZRZJpAvbTEipiXlayuhOxnqU827OipETQyeULZmLsqIQ1wK4Fgf+9b5aJ8D85/o4wBka00X4hZ3MwDPRb4mjuogwBTBg5NRpNSzUfbkPGiav08BFwgg+Efm9veSB05arS0="},
  188. {"www.sql1.example.com", "NSEC", "sql1.example.com. A RRSIG NSEC"},
  189. {"www.sql1.example.com", "RRSIG", "NSEC 5 4 7200 20100322084536 20100220084536 12447 sql1.example.com. cJMJhDx/ND7/9j3zhyXe+6eaSsU7ByYpXhJzbe+OhjFgH0VasQXq7o1QB3I293UZ+yhkjgXap+9QtPlraaNaYyTyOMQ42OoxSefJpYz9CME/FI2tsUfyrCnLFxYRNet7sMS0q+hLqxRayuEHDFDp72hHPGLJQ8a7jq4SrIonT50="},
  190. {NULL, NULL, NULL}
  191. };
  192. //
  193. // zone data for loop.example
  194. //
  195. const struct RRData loop_example_records[] = {
  196. {"loop.example", "SOA", "master.loop.example admin.loop.example. "
  197. "1234 3600 1800 2419200 7200"},
  198. {"loop.example", "NS", "ns.loop.example"},
  199. {"one.loop.example", "CNAME", "two.loop.example"},
  200. {"two.loop.example", "CNAME", "one.loop.example"},
  201. {NULL, NULL, NULL}
  202. };
  203. //
  204. // zone data for nons.example
  205. //
  206. const struct RRData nons_example_records[] = {
  207. {"nons.example", "SOA", "master.nons.example admin.nons.example. "
  208. "1234 3600 1800 2419200 7200"},
  209. {"www.nons.example", "A", "192.0.2.1"},
  210. {"ns.nons.example", "A", "192.0.2.2"},
  211. {NULL, NULL, NULL}
  212. };
  213. //
  214. // zone data for nons-dname.example
  215. //
  216. const struct RRData nonsdname_example_records[] = {
  217. {"nons-dname.example", "SOA", "master.nons-dname.example "
  218. "admin.nons-dname.example. 1234 3600 1800 2419200 7200"},
  219. {"nons-dname.example", "DNAME", "example.org"},
  220. {"www.nons-dname.example", "A", "192.0.2.1"},
  221. {"ns.nons-dname.example", "A", "192.0.2.2"},
  222. {NULL, NULL, NULL}
  223. };
  224. //
  225. // zone data for nosoa.example
  226. //
  227. const struct RRData nosoa_example_records[] = {
  228. {"nosoa.example", "NS", "ns.nosoa.example"},
  229. {"www.nosoa.example", "A", "192.0.2.1"},
  230. {"ns.nosoa.example", "A", "192.0.2.2"},
  231. {NULL, NULL, NULL}
  232. };
  233. //
  234. // empty data set, for convenience.
  235. //
  236. const struct RRData empty_records[] = {
  237. {NULL, NULL, NULL}
  238. };
  239. //
  240. // test zones
  241. //
  242. const struct ZoneData zone_data[] = {
  243. { "example.com", "IN", example_com_records, example_com_glue_records },
  244. { "sql1.example.com", "IN", sql1_example_com_records, empty_records },
  245. { "loop.example", "IN", loop_example_records, empty_records },
  246. { "nons.example", "IN", nons_example_records, empty_records },
  247. { "nons-dname.example", "IN", nonsdname_example_records, empty_records },
  248. { "nosoa.example", "IN", nosoa_example_records, empty_records }
  249. };
  250. const size_t NUM_ZONES = sizeof(zone_data) / sizeof(zone_data[0]);
  251. struct Zone {
  252. Zone(const char* const name, const char* const class_txt) :
  253. zone_name(Name(name)), rrclass(class_txt)
  254. {}
  255. Name zone_name;
  256. RRClass rrclass;
  257. vector<Name> names;
  258. vector<RRsetPtr> rrsets;
  259. };
  260. vector<Zone> zones;
  261. }
  262. DataSrc::Result
  263. TestDataSrc::init(const isc::data::ElementPtr config UNUSED_PARAM)
  264. {
  265. return init();
  266. }
  267. void
  268. buildZone(Zone& zone, const RRData* records, const bool is_glue) {
  269. RRsetPtr prev_rrset;
  270. for (int i = 0; records[i].name != NULL; ++i) {
  271. Name name(records[i].name);
  272. RRType rrtype(records[i].rrtype);
  273. RRsetPtr rrset;
  274. bool new_name = false;
  275. if (!prev_rrset || prev_rrset->getName() != name) {
  276. if (!is_glue) {
  277. zone.names.push_back(name);
  278. }
  279. new_name = true;
  280. }
  281. if (new_name || prev_rrset->getType() != rrtype) {
  282. rrset = RRsetPtr(new RRset(name, zone.rrclass, rrtype,
  283. RRTTL(TEST_TTL)));
  284. if (rrtype != RRType::RRSIG()) {
  285. zone.rrsets.push_back(rrset);
  286. }
  287. } else {
  288. rrset = prev_rrset;
  289. }
  290. rrset->addRdata(createRdata(rrtype, zone.rrclass, records[i].rdata));
  291. if (rrtype == RRType::RRSIG()) {
  292. prev_rrset->addRRsig(rrset);
  293. }
  294. prev_rrset = rrset;
  295. }
  296. }
  297. DataSrc::Result
  298. TestDataSrc::init() {
  299. if (initialized) {
  300. return (SUCCESS);
  301. }
  302. if (zones.empty()) {
  303. for (int i = 0; i < NUM_ZONES; ++i) {
  304. Zone zone(zone_data[i].zone_name, zone_data[i].rrclass);
  305. buildZone(zone, zone_data[i].records, false);
  306. buildZone(zone, zone_data[i].glue_records, true);
  307. sort(zone.names.begin(), zone.names.end());
  308. zones.push_back(zone);
  309. }
  310. }
  311. initialized = true;
  312. return (SUCCESS);
  313. }
  314. void
  315. TestDataSrc::findClosestEnclosure(NameMatch& match,
  316. const RRClass& qclass) const
  317. {
  318. const Name& qname = match.qname();
  319. if (qclass != getClass() && qclass != RRClass::ANY()) {
  320. return;
  321. }
  322. vector<Zone>::const_iterator it;
  323. vector<Zone>::const_iterator best_it = zones.end();
  324. unsigned int best_common_labels = 0;
  325. for (it = zones.begin(); it != zones.end(); ++it) {
  326. const NameComparisonResult cmp = qname.compare(it->zone_name);
  327. const NameComparisonResult::NameRelation reln = cmp.getRelation();
  328. if ((reln == NameComparisonResult::EQUAL ||
  329. reln == NameComparisonResult::SUBDOMAIN) &&
  330. cmp.getCommonLabels() > best_common_labels) {
  331. best_it = it;
  332. best_common_labels = cmp.getCommonLabels();
  333. }
  334. }
  335. if (best_it != zones.end()) {
  336. match.update(*this, best_it->zone_name);
  337. }
  338. }
  339. struct ZoneNameMatch : public unary_function<Name, bool> {
  340. ZoneNameMatch(const Name& name) : name_(name) {}
  341. bool operator()(const Zone& zone) const {
  342. return (zone.zone_name == name_);
  343. }
  344. const Name& name_;
  345. };
  346. // XXX: the main data source module can override the returned RRset.
  347. // That's bad and should be fixed (Trac #254), but for now we work around it.
  348. RRsetPtr
  349. copyRRset(RRsetPtr const source) {
  350. RRsetPtr rrset = RRsetPtr(new RRset(source->getName(), source->getClass(),
  351. source->getType(), source->getTTL()));
  352. RdataIteratorPtr it = source->getRdataIterator();
  353. for (it->first(); !it->isLast(); it->next()) {
  354. rrset->addRdata(it->getCurrent());
  355. }
  356. if (source->getRRsig()) {
  357. rrset->addRRsig(copyRRset(source->getRRsig()));
  358. }
  359. return (rrset);
  360. }
  361. class TestDataSrc::RRsetMatch {
  362. public:
  363. struct MatchResult {
  364. MatchResult(const bool name_found, const bool has_delegation) :
  365. name_found_(name_found), has_delegation_(has_delegation)
  366. {}
  367. bool name_found_;
  368. bool has_delegation_;
  369. };
  370. RRsetMatch(const Name& name, const RRType& rrtype, const Mode mode,
  371. RRsetList& target, uint32_t& flags) :
  372. name_(name), rrtype_(rrtype), mode_(mode), target_(target),
  373. flags_(flags), name_found_(false), has_delegation_(false)
  374. {}
  375. void operator()(const RRsetPtr& rrset) {
  376. if (rrset->getName() != name_) {
  377. return;
  378. }
  379. name_found_ = true;
  380. if (rrset->getType() == RRType::NS() ||
  381. rrset->getType() == RRType::DNAME()) {
  382. has_delegation_ = true;
  383. }
  384. if (mode_ == DELEGATION) {
  385. if (rrset->getType() == RRType::NS() ||
  386. rrset->getType() == RRType::DNAME() ||
  387. rrset->getType() == RRType::DS()) {
  388. target_.addRRset(copyRRset(rrset));
  389. }
  390. } else if (mode_ == ADDRESS) {
  391. if (rrset->getType() == RRType::A() ||
  392. rrset->getType() == RRType::AAAA()) {
  393. target_.addRRset(copyRRset(rrset));
  394. }
  395. } else {
  396. if (rrtype_ == RRType::NSEC() &&
  397. rrset->getType() == RRType::CNAME()) {
  398. // XXX: ignore CNAME if the qtype is NSEC.
  399. // tricky, but necessary.
  400. return;
  401. }
  402. if (rrtype_ == RRType::ANY() || rrtype_ == rrset->getType() ||
  403. rrset->getType() == RRType::CNAME() ||
  404. rrset->getType() == RRType::DNAME()) {
  405. target_.addRRset(copyRRset(rrset));
  406. if (rrset->getType() == RRType::CNAME()) {
  407. flags_ |= CNAME_FOUND;
  408. }
  409. if (rrset->getType() == RRType::DNAME()) {
  410. flags_ |= REFERRAL;
  411. }
  412. }
  413. }
  414. }
  415. MatchResult getResult() { return (MatchResult(name_found_,
  416. has_delegation_)); }
  417. const Name& name_;
  418. const RRType& rrtype_;
  419. const Mode mode_;
  420. RRsetList& target_;
  421. uint32_t& flags_;
  422. bool name_found_;
  423. bool has_delegation_;
  424. };
  425. void
  426. TestDataSrc::findRecords(const Name& name, const RRType& rdtype,
  427. RRsetList& target, const Name* zonename,
  428. const Mode mode, uint32_t& flags) const
  429. {
  430. flags = 0;
  431. assert(zonename != NULL);
  432. vector<Zone>::const_iterator zone = find_if(zones.begin(), zones.end(),
  433. ZoneNameMatch(*zonename));
  434. if (zone == zones.end()) {
  435. return;
  436. }
  437. const RRsetMatch::MatchResult match_result =
  438. for_each(zone->rrsets.begin(), zone->rrsets.end(),
  439. RRsetMatch(name, rdtype, mode, target, flags)).getResult();
  440. if (match_result.has_delegation_) {
  441. flags |= REFERRAL;
  442. }
  443. if (target.size() == 0) {
  444. if (match_result.name_found_) {
  445. flags |= TYPE_NOT_FOUND;
  446. } else {
  447. flags |= NAME_NOT_FOUND;
  448. }
  449. }
  450. }
  451. DataSrc::Result
  452. TestDataSrc::findRRset(const Name& qname,
  453. const RRClass& qclass UNUSED_PARAM,
  454. const RRType& qtype,
  455. RRsetList& target,
  456. uint32_t& flags,
  457. const Name* zonename) const
  458. {
  459. if (qclass != getClass() && qclass != RRClass::ANY()) {
  460. return (ERROR);
  461. }
  462. findRecords(qname, qtype, target, zonename, NORMAL, flags);
  463. return (SUCCESS);
  464. }
  465. DataSrc::Result
  466. TestDataSrc::findExactRRset(const Name& qname,
  467. const RRClass& qclass UNUSED_PARAM,
  468. const RRType& qtype,
  469. RRsetList& target,
  470. uint32_t& flags,
  471. const Name* zonename) const
  472. {
  473. if (qclass != getClass() && qclass != RRClass::ANY()) {
  474. return (ERROR);
  475. }
  476. findRecords(qname, qtype, target, zonename, NORMAL, flags);
  477. // Ignore referrals in this case
  478. flags &= ~REFERRAL;
  479. // CNAMEs don't count in this case
  480. if ((flags & CNAME_FOUND) != 0) {
  481. flags &= ~CNAME_FOUND;
  482. flags |= TYPE_NOT_FOUND;
  483. }
  484. return (SUCCESS);
  485. }
  486. DataSrc::Result
  487. TestDataSrc::findAddrs(const Name& qname,
  488. const RRClass& qclass UNUSED_PARAM,
  489. RRsetList& target,
  490. uint32_t& flags,
  491. const Name* zonename) const
  492. {
  493. if (qclass != getClass() && qclass != RRClass::ANY()) {
  494. return (ERROR);
  495. }
  496. findRecords(qname, RRType::ANY(), target, zonename, ADDRESS, flags);
  497. return (SUCCESS);
  498. }
  499. DataSrc::Result
  500. TestDataSrc::findReferral(const Name& qname,
  501. const RRClass& qclass UNUSED_PARAM,
  502. RRsetList& target,
  503. uint32_t& flags,
  504. const Name* zonename) const
  505. {
  506. if (qclass != getClass() && qclass != RRClass::ANY()) {
  507. return (ERROR);
  508. }
  509. findRecords(qname, RRType::ANY(), target, zonename, DELEGATION, flags);
  510. return (SUCCESS);
  511. }
  512. DataSrc::Result
  513. TestDataSrc::findPreviousName(const Name& qname,
  514. Name& target,
  515. const Name* zonename) const
  516. {
  517. assert(zonename != NULL);
  518. vector<Zone>::const_iterator zone = find_if(zones.begin(), zones.end(),
  519. ZoneNameMatch(*zonename));
  520. if (zone == zones.end()) {
  521. return (ERROR);
  522. }
  523. if (zone->names.empty()) {
  524. return (ERROR);
  525. }
  526. // if found, next_name >= qname.
  527. vector<Name>::const_iterator next_name =
  528. lower_bound(zone->names.begin(), zone->names.end(), qname);
  529. if (next_name == zone->names.end()) {
  530. // if no such name was found, the previous name is the last name.
  531. target = zone->names.back();
  532. } else if (*next_name == qname) {
  533. target = *next_name;
  534. } else if (next_name == zone->names.begin()) {
  535. // if qname < first_name, the "previous name" is the last name.
  536. target = zone->names.back();
  537. } else {
  538. // otherwise, qname and next_name share the same previous name.
  539. target = *(next_name - 1);
  540. }
  541. return (SUCCESS);
  542. }
  543. DataSrc::Result
  544. TestDataSrc::findCoveringNSEC3(const Name& zonename UNUSED_PARAM,
  545. string& hash UNUSED_PARAM,
  546. RRsetList& target UNUSED_PARAM) const
  547. {
  548. return (NOT_IMPLEMENTED);
  549. }
  550. }
  551. }