123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- #include <config.h>
- #include <cassert>
- #include <dns/name.h>
- #include <dns/rdataclass.h>
- #include <dns/rrclass.h>
- #include <dns/rrset.h>
- #include <dns/rrsetlist.h>
- #include <dns/rrtype.h>
- #include <dns/rrttl.h>
- #include <datasrc/data_source.h>
- #include <datasrc/static_datasrc.h>
- using namespace std;
- using namespace isc::dns;
- using namespace isc::dns::rdata;
- namespace isc {
- namespace datasrc {
- struct StaticDataSrcImpl {
- public:
- StaticDataSrcImpl();
- const Name authors_name;
- const Name version_name;
-
-
-
- RRsetPtr authors;
- RRsetPtr authors_ns;
- RRsetPtr authors_soa;
- RRsetPtr version;
- RRsetPtr version_ns;
- RRsetPtr version_soa;
- };
- StaticDataSrcImpl::StaticDataSrcImpl() :
- authors_name("authors.bind"), version_name("version.bind")
- {
- authors = RRsetPtr(new RRset(authors_name, RRClass::CH(),
- RRType::TXT(), RRTTL(0)));
- authors->addRdata(generic::TXT("Chen Zhengzhang"));
- authors->addRdata(generic::TXT("Evan Hunt"));
- authors->addRdata(generic::TXT("Han Feng"));
- authors->addRdata(generic::TXT("Jelte Jansen"));
- authors->addRdata(generic::TXT("Jeremy C. Reed"));
- authors->addRdata(generic::TXT("Jin Jian"));
- authors->addRdata(generic::TXT("JINMEI Tatuya"));
- authors->addRdata(generic::TXT("Kazunori Fujiwara"));
- authors->addRdata(generic::TXT("Michael Graff"));
- authors->addRdata(generic::TXT("Naoki Kambe"));
- authors->addRdata(generic::TXT("Shane Kerr"));
- authors->addRdata(generic::TXT("Shen Tingting"));
- authors->addRdata(generic::TXT("Stephen Morris"));
- authors->addRdata(generic::TXT("Zhang Likun"));
- authors_ns = RRsetPtr(new RRset(authors_name, RRClass::CH(),
- RRType::NS(), RRTTL(0)));
- authors_ns->addRdata(generic::NS(authors_name));
- authors_soa = RRsetPtr(new RRset(authors_name, RRClass::CH(),
- RRType::SOA(), RRTTL(0)));
- authors_soa->addRdata(generic::SOA(
- "authors.bind. hostmaster.authors.bind. "
- "0 28800 7200 604800 86400"));
- version = RRsetPtr(new RRset(version_name, RRClass::CH(),
- RRType::TXT(), RRTTL(0)));
- version->addRdata(generic::TXT(PACKAGE_STRING));
- version_ns = RRsetPtr(new RRset(version_name, RRClass::CH(),
- RRType::NS(), RRTTL(0)));
- version_ns->addRdata(generic::NS(version_name));
- version_soa = RRsetPtr(new RRset(version_name, RRClass::CH(),
- RRType::SOA(), RRTTL(0)));
- version_soa->addRdata(generic::SOA(
- "version.bind. hostmaster.version.bind. "
- "0 28800 7200 604800 86400"));
- }
- StaticDataSrc::StaticDataSrc()
- {
- setClass(RRClass::CH());
- impl_ = new StaticDataSrcImpl;
- }
- StaticDataSrc::~StaticDataSrc()
- {
- delete impl_;
- }
- namespace {
- bool
- isSubdomain(const Name& qname, const Name& zone) {
- const NameComparisonResult::NameRelation cmp =
- qname.compare(zone).getRelation();
- return (cmp == NameComparisonResult::EQUAL ||
- cmp == NameComparisonResult::SUBDOMAIN);
- }
- }
- void
- StaticDataSrc::findClosestEnclosure(DataSrcMatch& match) const {
- const Name& qname = match.getName();
- if (match.getClass() != getClass() && match.getClass() != RRClass::ANY()) {
- return;
- }
- if (isSubdomain(qname, impl_->version_name)) {
- match.update(*this, impl_->version_name);
- return;
- }
- if (isSubdomain(qname, impl_->authors_name)) {
- match.update(*this, impl_->authors_name);
- return;
- }
- }
- DataSrc::Result
- StaticDataSrc::findRRset(const Name& qname,
- const RRClass& qclass, const RRType& qtype,
- RRsetList& target, uint32_t& flags,
- const Name* const zonename) const
- {
- flags = 0;
- if (qclass != getClass() && qclass != RRClass::ANY()) {
- return (ERROR);
- }
-
- bool is_versionname = false, is_authorsname = false;
- if (zonename != NULL) {
- if (*zonename == impl_->version_name &&
- isSubdomain(qname, impl_->version_name)) {
- is_versionname = true;
- } else if (*zonename == impl_->authors_name &&
- isSubdomain(qname, impl_->authors_name)) {
- is_authorsname = true;
- } else {
- flags = NO_SUCH_ZONE;
- return (SUCCESS);
- }
- } else {
- if (isSubdomain(qname, impl_->version_name)) {
- is_versionname = true;
- } else if (isSubdomain(qname, impl_->authors_name)) {
- is_authorsname = true;
- } else {
- flags = NO_SUCH_ZONE;
- return (SUCCESS);
- }
- }
- const bool any = (qtype == RRType::ANY());
- if (is_versionname) {
- if (qname == impl_->version_name) {
- if (qtype == RRType::TXT() || any) {
- target.addRRset(impl_->version);
- }
- if (qtype == RRType::NS() || any) {
- target.addRRset(impl_->version_ns);
- }
- if (qtype == RRType::SOA() || any) {
- target.addRRset(impl_->version_soa);
- }
- if (target.size() == 0) {
- flags = TYPE_NOT_FOUND;
- }
- } else {
- flags = NAME_NOT_FOUND;
- }
- } else {
- assert(is_authorsname);
- if (qname == impl_->authors_name) {
- if (qtype == RRType::TXT() || any) {
- target.addRRset(impl_->authors);
- }
- if (qtype == RRType::NS() || any) {
- target.addRRset(impl_->authors_ns);
- }
- if (qtype == RRType::SOA() || any) {
- target.addRRset(impl_->authors_soa);
- }
- if (target.size() == 0 ) {
- flags = TYPE_NOT_FOUND;
- }
- } else {
- flags = NAME_NOT_FOUND;
- }
- }
- return (SUCCESS);
- }
- DataSrc::Result
- StaticDataSrc::findExactRRset(const Name& qname,
- const RRClass& qclass, const RRType& qtype,
- RRsetList& target, uint32_t& flags,
- const Name* zonename) const
- {
- return (findRRset(qname, qclass, qtype, target, flags, zonename));
- }
- DataSrc::Result
- StaticDataSrc::findPreviousName(const Name& qname UNUSED_PARAM,
- Name& target UNUSED_PARAM,
- const Name* zonename UNUSED_PARAM) const
- {
- return (NOT_IMPLEMENTED);
- }
- DataSrc::Result
- StaticDataSrc::findCoveringNSEC3(const Name& zonename UNUSED_PARAM,
- string& hash UNUSED_PARAM,
- RRsetList& target UNUSED_PARAM) const
- {
- return (NOT_IMPLEMENTED);
- }
- DataSrc::Result
- StaticDataSrc::init() {
- return (SUCCESS);
- }
- DataSrc::Result
- StaticDataSrc::init(isc::data::ConstElementPtr config UNUSED_PARAM) {
- return (init());
- }
- DataSrc::Result
- StaticDataSrc::close() {
- return (SUCCESS);
- }
- }
- }
|