]>
Commit | Line | Data |
---|---|---|
12c86877 | 1 | /* |
12471842 PL |
2 | * This file is part of PowerDNS or dnsdist. |
3 | * Copyright -- PowerDNS.COM B.V. and its contributors | |
4 | * | |
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. | |
8 | * | |
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. | |
12 | * | |
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. | |
17 | * | |
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. | |
21 | */ | |
12c86877 BH |
22 | #ifndef UEBERBACKEND_HH |
23 | #define UEBERBACKEND_HH | |
24 | ||
25 | #include <vector> | |
26 | #include <map> | |
27 | #include <string> | |
28 | #include <algorithm> | |
29 | #include <pthread.h> | |
973ad2b5 BH |
30 | #include <semaphore.h> |
31 | ||
973ad2b5 | 32 | #include <unistd.h> |
973ad2b5 BH |
33 | #include <sys/stat.h> |
34 | #include <fcntl.h> | |
35 | #include <unistd.h> | |
6a010475 | 36 | #include <boost/utility.hpp> |
12c86877 BH |
37 | #include "dnspacket.hh" |
38 | #include "dnsbackend.hh" | |
39 | ||
10f4eea8 | 40 | #include "namespaces.hh" |
12c86877 | 41 | |
12c86877 BH |
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 | |
bdc9f8d2 BH |
44 | across multiple threads. |
45 | ||
46 | The UeberBackend is transparent for exceptions, which should fall straight through. | |
47 | */ | |
12c86877 | 48 | |
3971cf53 | 49 | class UeberBackend : public boost::noncopyable |
12c86877 BH |
50 | { |
51 | public: | |
6a010475 | 52 | UeberBackend(const string &pname="default"); |
12c86877 | 53 | ~UeberBackend(); |
12c86877 | 54 | |
675fa24c | 55 | bool superMasterBackend(const string &ip, const DNSName &domain, const vector<DNSResourceRecord>&nsset, string *nameserver, string *account, DNSBackend **db); |
12c86877 | 56 | |
12c86877 BH |
57 | /** Tracks all created UeberBackend instances for us. We use this vector to notify |
58 | existing threads of new modules | |
59 | */ | |
60 | static vector<UeberBackend *>instances; | |
61 | static pthread_mutex_t instances_lock; | |
62 | ||
63 | static bool loadmodule(const string &name); | |
d4168b30 | 64 | static bool loadModules(const vector<string>& modules, const string& path); |
12c86877 | 65 | |
12c86877 BH |
66 | static void go(void); |
67 | ||
12c86877 BH |
68 | /** This contains all registered backends. The DynListener modifies this list for us when |
69 | new modules are loaded */ | |
6a010475 | 70 | vector<DNSBackend*> backends; |
12c86877 | 71 | |
12c86877 BH |
72 | void cleanup(); |
73 | ||
74 | //! the very magic handle for UeberBackend questions | |
75 | class handle | |
76 | { | |
77 | public: | |
90ba52e0 | 78 | bool get(DNSZoneRecord &dr); |
12c86877 BH |
79 | handle(); |
80 | ~handle(); | |
81 | ||
82 | //! The UeberBackend class where this handle belongs to | |
83 | UeberBackend *parent; | |
84 | //! The current real backend, which is answering questions | |
85 | DNSBackend *d_hinterBackend; | |
86 | ||
12c86877 BH |
87 | //! DNSPacket who asked this question |
88 | DNSPacket *pkt_p; | |
675fa24c | 89 | DNSName qname; |
5b098284 PL |
90 | |
91 | //! Index of the current backend within the backends vector | |
92 | unsigned int i; | |
12c86877 | 93 | QType qtype; |
5b098284 | 94 | |
12c86877 BH |
95 | private: |
96 | ||
16f7d28d | 97 | static AtomicCounter instances; |
12c86877 BH |
98 | }; |
99 | ||
675fa24c | 100 | void lookup(const QType &, const DNSName &qdomain, DNSPacket *pkt_p=0, int zoneId=-1); |
12c86877 | 101 | |
cec52de6 CH |
102 | /** Determines if we are authoritative for a zone, and at what level */ |
103 | bool getAuth(const DNSName &target, const QType &qtype, SOAData* sd, bool cachedOk=true); | |
94bfa5b6 | 104 | bool getSOA(const DNSName &domain, SOAData &sd); |
76e1255a KM |
105 | /** Load SOA info from backends, ignoring the cache.*/ |
106 | bool getSOAUncached(const DNSName &domain, SOAData &sd); | |
90ba52e0 | 107 | bool get(DNSZoneRecord &r); |
cea26350 | 108 | void getAllDomains(vector<DomainInfo> *domains, bool include_disabled=false); |
12c86877 | 109 | |
12c86877 BH |
110 | void getUnfreshSlaveInfos(vector<DomainInfo>* domains); |
111 | void getUpdatedMasters(vector<DomainInfo>* domains); | |
47bddbb7 | 112 | bool getDomainInfo(const DNSName &domain, DomainInfo &di, bool getSerial=true); |
675fa24c | 113 | bool createDomain(const DNSName &domain); |
c0273500 | 114 | |
7fa35c07 | 115 | bool doesDNSSEC(); |
82cc0761 | 116 | bool addDomainKey(const DNSName& name, const DNSBackend::KeyData& key, int64_t& id); |
9c1c5d49 | 117 | bool getDomainKeys(const DNSName& name, std::vector<DNSBackend::KeyData>& keys); |
675fa24c PD |
118 | bool getAllDomainMetadata(const DNSName& name, std::map<std::string, std::vector<std::string> >& meta); |
119 | bool getDomainMetadata(const DNSName& name, const std::string& kind, std::vector<std::string>& meta); | |
120 | bool setDomainMetadata(const DNSName& name, const std::string& kind, const std::vector<std::string>& meta); | |
121 | ||
122 | bool removeDomainKey(const DNSName& name, unsigned int id); | |
123 | bool activateDomainKey(const DNSName& name, unsigned int id); | |
124 | bool deactivateDomainKey(const DNSName& name, unsigned int id); | |
125 | ||
675fa24c PD |
126 | bool getTSIGKey(const DNSName& name, DNSName* algorithm, string* content); |
127 | bool setTSIGKey(const DNSName& name, const DNSName& algorithm, const string& content); | |
128 | bool deleteTSIGKey(const DNSName& name); | |
6f872b78 AT |
129 | bool getTSIGKeys(std::vector< struct TSIGKey > &keys); |
130 | ||
675fa24c | 131 | void alsoNotifies(const DNSName &domain, set<string> *ips); |
973ad2b5 | 132 | void rediscover(string* status=0); |
12c86877 | 133 | void reload(); |
9f8e226e AT |
134 | bool searchRecords(const string &pattern, int maxResults, vector<DNSResourceRecord>& result); |
135 | bool searchComments(const string &pattern, int maxResults, vector<Comment>& result); | |
12c86877 | 136 | private: |
ce4a60ce | 137 | pthread_t d_tid; |
12c86877 | 138 | handle d_handle; |
90ba52e0 | 139 | vector<DNSZoneRecord> d_answers; |
140 | vector<DNSZoneRecord>::const_iterator d_cachehandleiter; | |
c899e9e7 PL |
141 | |
142 | static pthread_mutex_t d_mut; | |
143 | static pthread_cond_t d_cond; | |
c899e9e7 | 144 | |
12c86877 BH |
145 | struct Question |
146 | { | |
675fa24c | 147 | DNSName qname; |
12c86877 | 148 | int zoneId; |
c899e9e7 | 149 | QType qtype; |
12c86877 | 150 | }d_question; |
c899e9e7 PL |
151 | |
152 | unsigned int d_cache_ttl, d_negcache_ttl; | |
ce4a60ce | 153 | int d_domain_id; |
c899e9e7 PL |
154 | int d_ancount; |
155 | ||
156 | bool d_negcached; | |
157 | bool d_cached; | |
158 | static bool d_go; | |
ce4a60ce | 159 | bool d_stale; |
12c86877 | 160 | |
90ba52e0 | 161 | int cacheHas(const Question &q, vector<DNSZoneRecord> &rrs); |
12c86877 | 162 | void addNegCache(const Question &q); |
90ba52e0 | 163 | void addCache(const Question &q, const vector<DNSZoneRecord> &rrs); |
12c86877 | 164 | |
12c86877 BH |
165 | }; |
166 | ||
12c86877 | 167 | #endif |