2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * In addition, for the avoidance of any doubt, permission is granted to
10 * link this program with OpenSSL and to (re)distribute the binaries
11 * produced as the result of such linking.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #ifndef UEBERBACKEND_HH
23 #define UEBERBACKEND_HH
30 #include <semaphore.h>
36 #include <boost/utility.hpp>
37 #include "dnspacket.hh"
38 #include "dnsbackend.hh"
40 #include "namespaces.hh"
42 /** This is a very magic backend that allows us to load modules dynamically,
43 and query them in order. This is persistent over all UeberBackend instantiations
44 across multiple threads.
46 The UeberBackend is transparent for exceptions, which should fall straight through.
49 class UeberBackend : public boost::noncopyable
52 UeberBackend(const string &pname="default");
55 bool superMasterBackend(const string &ip, const DNSName &domain, const vector<DNSResourceRecord>&nsset, string *nameserver, string *account, DNSBackend **db);
57 /** Tracks all created UeberBackend instances for us. We use this vector to notify
58 existing threads of new modules
60 static vector<UeberBackend *>instances;
61 static pthread_mutex_t instances_lock;
63 static bool loadmodule(const string &name);
67 /** This contains all registered backends. The DynListener modifies this list for us when
68 new modules are loaded */
69 vector<DNSBackend*> backends;
73 //! the very magic handle for UeberBackend questions
77 bool get(DNSZoneRecord &dr);
81 //! The UeberBackend class where this handle belongs to
83 //! The current real backend, which is answering questions
84 DNSBackend *d_hinterBackend;
86 //! DNSPacket who asked this question
90 //! Index of the current backend within the backends vector
96 static AtomicCounter instances;
99 void lookup(const QType &, const DNSName &qdomain, DNSPacket *pkt_p=0, int zoneId=-1);
101 /** Determines if we are authoritative for a zone, and at what level */
102 bool getAuth(const DNSName &target, const QType &qtype, SOAData* sd, bool cachedOk=true);
103 bool getSOA(const DNSName &domain, SOAData &sd);
104 bool getSOAUncached(const DNSName &domain, SOAData &sd); // same, but ignores cache
105 bool get(DNSZoneRecord &r);
106 void getAllDomains(vector<DomainInfo> *domains, bool include_disabled=false);
108 void getUnfreshSlaveInfos(vector<DomainInfo>* domains);
109 void getUpdatedMasters(vector<DomainInfo>* domains);
110 bool getDomainInfo(const DNSName &domain, DomainInfo &di);
111 bool createDomain(const DNSName &domain);
114 bool addDomainKey(const DNSName& name, const DNSBackend::KeyData& key, int64_t& id);
115 bool getDomainKeys(const DNSName& name, std::vector<DNSBackend::KeyData>& keys);
116 bool getAllDomainMetadata(const DNSName& name, std::map<std::string, std::vector<std::string> >& meta);
117 bool getDomainMetadata(const DNSName& name, const std::string& kind, std::vector<std::string>& meta);
118 bool setDomainMetadata(const DNSName& name, const std::string& kind, const std::vector<std::string>& meta);
120 bool removeDomainKey(const DNSName& name, unsigned int id);
121 bool activateDomainKey(const DNSName& name, unsigned int id);
122 bool deactivateDomainKey(const DNSName& name, unsigned int id);
124 bool getTSIGKey(const DNSName& name, DNSName* algorithm, string* content);
125 bool setTSIGKey(const DNSName& name, const DNSName& algorithm, const string& content);
126 bool deleteTSIGKey(const DNSName& name);
127 bool getTSIGKeys(std::vector< struct TSIGKey > &keys);
129 void alsoNotifies(const DNSName &domain, set<string> *ips);
130 void rediscover(string* status=0);
132 bool searchRecords(const string &pattern, int maxResults, vector<DNSResourceRecord>& result);
133 bool searchComments(const string &pattern, int maxResults, vector<Comment>& result);
137 vector<DNSZoneRecord> d_answers;
138 vector<DNSZoneRecord>::const_iterator d_cachehandleiter;
140 static pthread_mutex_t d_mut;
141 static pthread_cond_t d_cond;
150 unsigned int d_cache_ttl, d_negcache_ttl;
159 int cacheHas(const Question &q, vector<DNSZoneRecord> &rrs);
160 void addNegCache(const Question &q);
161 void addCache(const Question &q, const vector<DNSZoneRecord> &rrs);