From: Aki Tuomi Date: Wed, 17 Jun 2015 07:56:26 +0000 (+0300) Subject: Use DNSName in GeoIP backend X-Git-Tag: dnsdist-1.0.0-alpha1~248^2~58^2~21^2~5^2~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cac80fee54754ee5fe1ab4b106861ef745e056b9;p=thirdparty%2Fpdns.git Use DNSName in GeoIP backend --- diff --git a/modules/geoipbackend/geoipbackend.cc b/modules/geoipbackend/geoipbackend.cc index e83b368322..2e7d2acc72 100644 --- a/modules/geoipbackend/geoipbackend.cc +++ b/modules/geoipbackend/geoipbackend.cc @@ -11,10 +11,10 @@ pthread_rwlock_t GeoIPBackend::s_state_lock=PTHREAD_RWLOCK_INITIALIZER; class GeoIPDomain { public: int id; - string domain; + DNSName domain; int ttl; - map services; - map > records; + map services; + map > records; }; static vector s_domains; @@ -85,12 +85,10 @@ void GeoIPBackend::initialize() { GeoIPDomain dom; dom.id = s_domains.size(); dom.domain = domain["domain"].as(); - std::transform(dom.domain.begin(), dom.domain.end(), dom.domain.begin(), dns_tolower); dom.ttl = domain["ttl"].as(); for(YAML::const_iterator recs = domain["records"].begin(); recs != domain["records"].end(); recs++) { - string qname = recs->first.as(); - std::transform(qname.begin(), qname.end(), qname.begin(), dns_tolower); + DNSName qname = DNSName(recs->first.as()); vector rrs; BOOST_FOREACH(YAML::Node item, recs->second) { @@ -120,7 +118,7 @@ void GeoIPBackend::initialize() { } for(YAML::const_iterator service = domain["services"].begin(); service != domain["services"].end(); service++) { - dom.services[service->first.as()] = service->second.as(); + dom.services[DNSName(service->first.as())] = service->second.as(); } tmp_domains.push_back(dom); @@ -144,7 +142,7 @@ GeoIPBackend::~GeoIPBackend() { } } -void GeoIPBackend::lookup(const QType &qtype, const string &qdomain, DNSPacket *pkt_p, int zoneId) { +void GeoIPBackend::lookup(const QType &qtype, const DNSName& qdomain, DNSPacket *pkt_p, int zoneId) { ReadLock rl(&s_state_lock); GeoIPDomain dom; bool found = false; @@ -154,8 +152,7 @@ void GeoIPBackend::lookup(const QType &qtype, const string &qdomain, DNSPacket * if (d_result.size()>0) throw PDNSException("Cannot perform lookup while another is running"); - string search = qdomain; - std::transform(search.begin(), search.end(), search.begin(), dns_tolower); + DNSName search = qdomain; d_result.clear(); @@ -163,8 +160,8 @@ void GeoIPBackend::lookup(const QType &qtype, const string &qdomain, DNSPacket * dom = s_domains[zoneId]; else { BOOST_FOREACH(GeoIPDomain i, s_domains) { - if (endsOn(search, dom.domain)) { - dom = i; + if (search.isPartOf(i.domain)) { + dom = i; found = true; break; } @@ -173,7 +170,7 @@ void GeoIPBackend::lookup(const QType &qtype, const string &qdomain, DNSPacket * } if (dom.records.count(search)) { // return static value - map >::iterator i = dom.records.find(search); + map >::iterator i = dom.records.find(search); BOOST_FOREACH(DNSResourceRecord rr, i->second) { if (qtype == QType::ANY || rr.qtype == qtype) { d_result.push_back(rr); @@ -193,7 +190,7 @@ void GeoIPBackend::lookup(const QType &qtype, const string &qdomain, DNSPacket * } if (dom.services.count(search) == 0) return; // no hit - map::const_iterator target = dom.services.find(search); + map::const_iterator target = dom.services.find(search); string format = target->second; format = format2str(format, ip, v6); @@ -377,12 +374,11 @@ void GeoIPBackend::rediscover(string* status) { reload(); } -bool GeoIPBackend::getDomainInfo(const string &domain, DomainInfo &di) { +bool GeoIPBackend::getDomainInfo(const DNSName& domain, DomainInfo &di) { ReadLock rl(&s_state_lock); - cerr << "looking for " << domain << endl; BOOST_FOREACH(GeoIPDomain dom, s_domains) { - if (pdns_iequals(dom.domain, domain)) { + if (dom.domain == domain) { SOAData sd; this->getSOA(domain, sd); di.id = dom.id; @@ -396,7 +392,7 @@ bool GeoIPBackend::getDomainInfo(const string &domain, DomainInfo &di) { return false; } -bool GeoIPBackend::getAllDomainMetadata(const string& name, std::map >& meta) { +bool GeoIPBackend::getAllDomainMetadata(const DNSName& name, std::map >& meta) { if (!d_dnssec) return false; ReadLock rl(&s_state_lock); @@ -412,7 +408,7 @@ bool GeoIPBackend::getAllDomainMetadata(const string& name, std::map& meta) { +bool GeoIPBackend::getDomainMetadata(const DNSName& name, const std::string& kind, std::vector& meta) { if (!d_dnssec) return false; ReadLock rl(&s_state_lock); @@ -430,7 +426,7 @@ bool GeoIPBackend::getDomainMetadata(const std::string& name, const std::string& return false; } -bool GeoIPBackend::getDomainKeys(const std::string& name, unsigned int kind, std::vector& keys) { +bool GeoIPBackend::getDomainKeys(const DNSName& name, unsigned int kind, std::vector& keys) { if (!d_dnssec) return false; ReadLock rl(&s_state_lock); BOOST_FOREACH(GeoIPDomain dom, s_domains) { @@ -439,7 +435,7 @@ bool GeoIPBackend::getDomainKeys(const std::string& name, unsigned int kind, std regmatch_t regm[5]; regcomp(®, "(.*)[.]([0-9]+)[.]([0-9]+)[.]([01])[.]key$", REG_ICASE|REG_EXTENDED); ostringstream pathname; - pathname << getArg("dnssec-keydir") << "/" << dom.domain << "*.key"; + pathname << getArg("dnssec-keydir") << "/" << dom.domain.toStringNoDot() << "*.key"; glob_t glob_result; if (glob(pathname.str().c_str(),GLOB_ERR,NULL,&glob_result) == 0) { for(size_t i=0;i >& meta); - virtual bool getDomainMetadata(const std::string& name, const std::string& kind, std::vector& meta); - virtual bool getDomainKeys(const std::string& name, unsigned int kind, std::vector& keys); - virtual bool removeDomainKey(const string& name, unsigned int id); - virtual int addDomainKey(const string& name, const KeyData& key); - virtual bool activateDomainKey(const string& name, unsigned int id); - virtual bool deactivateDomainKey(const string& name, unsigned int id); + virtual bool getAllDomainMetadata(const DNSName& name, std::map >& meta); + virtual bool getDomainMetadata(const DNSName& name, const std::string& kind, std::vector& meta); + virtual bool getDomainKeys(const DNSName& name, unsigned int kind, std::vector& keys); + virtual bool removeDomainKey(const DNSName& name, unsigned int id); + virtual int addDomainKey(const DNSName& name, const KeyData& key); + virtual bool activateDomainKey(const DNSName& name, unsigned int id); + virtual bool deactivateDomainKey(const DNSName& name, unsigned int id); enum GeoIPQueryAttribute { Afi, @@ -62,7 +62,7 @@ private: string format2str(string format, const string& ip, bool v6); int d_dbmode; bool d_dnssec; - bool hasDNSSECkey(const string &domain); + bool hasDNSSECkey(const DNSName& name); vector d_result; };