]> git.ipfire.org Git - thirdparty/pdns.git/blame - pdns/dnsbackend.hh
Add rfc2136handler to handle rfc2136 operation
[thirdparty/pdns.git] / pdns / dnsbackend.hh
CommitLineData
12c86877
BH
1/*
2 PowerDNS Versatile Database Driven Nameserver
66dba9d7 3 Copyright (C) 2002-2010 PowerDNS.COM BV
12c86877
BH
4
5 This program is free software; you can redistribute it and/or modify
22dc646a
BH
6 it under the terms of the GNU General Public License version 2
7 as published by the Free Software Foundation
8
12c86877
BH
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
06bd9ccf 17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12c86877 18*/
12c86877
BH
19#ifndef DNSBACKEND_HH
20#define DNSBACKEND_HH
21
973ad2b5
BH
22class DNSPacket;
23
12c86877
BH
24#include "utility.hh"
25#include <string>
26#include <vector>
27#include <map>
28#include <sys/types.h>
cc3afe25 29#include "ahuexception.hh"
973ad2b5 30#include <set>
702b226d 31#include <iostream>
973ad2b5
BH
32
33#ifndef WIN32
34# include <sys/socket.h>
35# include <dirent.h>
36#endif // WIN32
12c86877
BH
37
38#include "qtype.hh"
39#include "dns.hh"
e5b11b2f 40#include <vector>
10f4eea8 41#include "namespaces.hh"
12c86877
BH
42
43class DNSBackend;
44struct DomainInfo
45{
90c9a70e 46 DomainInfo() : backend(0) {}
092f210a 47 uint32_t id;
12c86877 48 string zone;
e5b11b2f 49 vector<string> masters;
092f210a
BH
50 uint32_t notified_serial;
51 uint32_t serial;
12c86877
BH
52 time_t last_check;
53 enum {Master,Slave,Native} kind;
54 DNSBackend *backend;
7f3d870e
BH
55
56 bool operator<(const DomainInfo& rhs) const
57 {
58 return zone < rhs.zone;
59 }
12c86877
BH
60};
61
62class DNSPacket;
bdc9f8d2
BH
63
64
65//! This virtual base class defines the interface for backends for the ahudns.
66/** To create a backend, inherit from this class and implement functions for all virtual methods.
67 Methods should not throw an exception if they are sure they did not find the requested data. However,
68 if an error occurred which prevented them temporarily from performing a lockup, they should throw a DBException,
69 which will cause the nameserver to send out a ServFail or take other evasive action. Probably only locking
70 issues should lead to DBExceptions.
71
72 More serious errors, which may indicate that the database connection is hosed, or a configuration error occurred, should
73 lead to the throwing of an AhuException. This exception will fall straight through the UeberBackend and the PacketHandler
74 and be caught by the Distributor, which will delete your DNSBackend instance and spawn a new one.
75*/
12c86877
BH
76class DNSBackend
77{
78public:
bdc9f8d2 79 //! lookup() initiates a lookup. A lookup without results should not throw!
12c86877 80 virtual void lookup(const QType &qtype, const string &qdomain, DNSPacket *pkt_p=0, int zoneId=-1)=0;
bdc9f8d2 81 virtual bool get(DNSResourceRecord &)=0; //!< retrieves one DNSResource record, returns false if no more were available
702b226d 82
5c3bf2db 83
bdc9f8d2
BH
84 //! Initiates a list of the specified domain
85 /** Once initiated, DNSResourceRecord objects can be retrieved using get(). Should return false
86 if the backend does not consider itself responsible for the id passed.
87 \param domain_id ID of which a list is requested
88 */
88def049 89 virtual bool list(const string &target, int domain_id)=0;
12c86877
BH
90
91 virtual ~DNSBackend(){};
92
bdc9f8d2 93 //! fills the soadata struct with the SOA details. Returns false if there is no SOA.
35933370 94 virtual bool getSOA(const string &name, SOAData &soadata, DNSPacket *p=0);
12c86877 95
d07fc616
PD
96 //! Calculates a SOA serial for the zone and stores it in the third argument.
97 virtual bool calculateSOASerial(const string& domain, const SOAData& sd, time_t& serial);
98
8bbb6f36
BH
99 virtual bool replaceRRSet(uint32_t domain_id, const string& qname, const QType& qt, const vector<DNSResourceRecord>& rrset)
100 {
101 return false;
102 }
103
4aafcb39 104 // the DNSSEC related (getDomainMetadata has broader uses too)
8ab63616
BH
105 virtual bool getDomainMetadata(const string& name, const std::string& kind, std::vector<std::string>& meta) { return false; }
106 virtual bool setDomainMetadata(const string& name, const std::string& kind, const std::vector<std::string>& meta) {return false;}
4aafcb39 107
1325e8a2
PD
108 virtual void getAllDomains(vector<DomainInfo> *domains) { }
109
4aafcb39
BH
110 struct KeyData {
111 unsigned int id;
112 unsigned int flags;
113 bool active;
114 std::string content;
115 };
116
8ab63616
BH
117 virtual bool getDomainKeys(const string& name, unsigned int kind, std::vector<KeyData>& keys) { return false;}
118 virtual bool removeDomainKey(const string& name, unsigned int id) { return false; }
119 virtual int addDomainKey(const string& name, const KeyData& key){ return -1; }
120 virtual bool activateDomainKey(const string& name, unsigned int id) { return false; }
121 virtual bool deactivateDomainKey(const string& name, unsigned int id) { return false; }
122
78bcb858
BH
123 virtual bool getTSIGKey(const string& name, string* algorithm, string* content) { return false; }
124
4aafcb39
BH
125 virtual bool getBeforeAndAfterNamesAbsolute(uint32_t id, const std::string& qname, std::string& unhashed, std::string& before, std::string& after)
126 {
127 std::cerr<<"Default beforeAndAfterAbsolute called!"<<std::endl;
128 abort();
129 return false;
130 }
131
132 bool getBeforeAndAfterNames(uint32_t id, const std::string& zonename, const std::string& qname, std::string& before, std::string& after);
133
134 virtual bool updateDNSSECOrderAndAuth(uint32_t domain_id, const std::string& zonename, const std::string& qname, bool auth)
135 {
136 return false;
137 }
138
139 virtual bool updateDNSSECOrderAndAuthAbsolute(uint32_t domain_id, const std::string& qname, const std::string& ordername, bool auth)
140 {
141 return false;
142 }
143
b5baefaf
PD
144 virtual bool updateEmptyNonTerminals(uint32_t domain_id, const std::string& zonename, set<string>& insert, set<string>& erase, bool remove)
145 {
146 return false;
147 }
148
c2df797e 149 virtual bool nullifyDNSSECOrderNameAndUpdateAuth(uint32_t domain_id, const std::string& qname, bool auth)
b5baefaf
PD
150 {
151 return false;
152 }
153
27045410
PD
154 virtual bool nullifyDNSSECOrderNameAndAuth(uint32_t domain_id, const std::string& qname, const std::string& type)
155 {
156 return false;
157 }
158
c2df797e
PD
159 virtual bool setDNSSECAuthOnDsRecord(uint32_t domain_id, const std::string& qname)
160 {
161 return false;
162 }
163
ece45ffb
PD
164 virtual bool doesDNSSEC()
165 {
166 return false;
167 }
168
4aafcb39
BH
169 // end DNSSEC
170
bdc9f8d2 171 //! returns true if master ip is master for domain name.
12c86877
BH
172 virtual bool isMaster(const string &name, const string &ip)
173 {
174 return false;
175 }
176
bdc9f8d2 177 //! starts the transaction for updating domain qname (FIXME: what is id?)
12c86877
BH
178 virtual bool startTransaction(const string &qname, int id=-1)
179 {
180 return false;
181 }
182
bdc9f8d2 183 //! commits the transaction started by startTransaction
12c86877
BH
184 virtual bool commitTransaction()
185 {
186 return false;
187 }
188
bdc9f8d2 189 //! aborts the transaction started by strartTransaction, should leave state unaltered
12c86877
BH
190 virtual bool abortTransaction()
191 {
192 return false;
193 }
194
195 virtual void reload()
196 {
197 }
198
973ad2b5 199 virtual void rediscover(string* status=0)
12c86877
BH
200 {
201 }
202
bdc9f8d2 203 //! feeds a record to a zone, needs a call to startTransaction first
f9cf6d92 204 virtual bool feedRecord(const DNSResourceRecord &rr, string *ordername=0)
12c86877
BH
205 {
206 return false; // no problem!
207 }
f9cf6d92
KM
208 virtual bool feedEnts(int domain_id, set<string> &nonterm)
209 {
210 return false;
211 }
212 virtual bool feedEnts3(int domain_id, const string &domain, set<string> &nonterm, unsigned int times, const string &salt, bool narrow)
213 {
214 return false;
215 }
216
bdc9f8d2 217 //! if this returns true, DomainInfo di contains information about the domain
12c86877
BH
218 virtual bool getDomainInfo(const string &domain, DomainInfo &di)
219 {
220 return false;
221 }
bdc9f8d2 222 //! slave capable backends should return a list of slaves that should be rechecked for staleness
12c86877
BH
223 virtual void getUnfreshSlaveInfos(vector<DomainInfo>* domains)
224 {
225 }
226
bdc9f8d2 227 //! get a list of IP addresses that should also be notified for a domain
12c86877
BH
228 virtual void alsoNotifies(const string &domain, set<string> *ips)
229 {
230 }
bdc9f8d2
BH
231
232 //! get list of domains that have been changed since their last notification to slaves
12c86877
BH
233 virtual void getUpdatedMasters(vector<DomainInfo>* domains)
234 {
235 }
bdc9f8d2
BH
236
237 //! Called by PowerDNS to inform a backend that a domain has been checked for freshness
092f210a 238 virtual void setFresh(uint32_t domain_id)
12c86877
BH
239 {
240
241 }
bdc9f8d2 242 //! Called by PowerDNS to inform a backend that the changes in the domain have been reported to slaves
092f210a 243 virtual void setNotified(uint32_t id, uint32_t serial)
12c86877
BH
244 {
245 }
246
bdc9f8d2 247 //! Can be called to seed the getArg() function with a prefix
12c86877 248 void setArgPrefix(const string &prefix);
bdc9f8d2
BH
249
250 //! determine if ip is a supermaster or a domain
12c86877
BH
251 virtual bool superMasterBackend(const string &ip, const string &domain, const vector<DNSResourceRecord>&nsset, string *account, DNSBackend **db)
252 {
253 return false;
254 }
bdc9f8d2
BH
255
256 //! called by PowerDNS to create a slave record for a superMaster
12c86877
BH
257 virtual bool createSlaveDomain(const string &ip, const string &domain, const string &account)
258 {
259 return false;
260 }
261
262protected:
263 bool mustDo(const string &key);
264 const string &getArg(const string &key);
265 int getArgAsNum(const string &key);
266 string getRemote(DNSPacket *p);
267 bool getRemote(DNSPacket *p, struct sockaddr *in, Utility::socklen_t *len);
268
269private:
270 string d_prefix;
271};
272
273class BackendFactory
274{
275public:
276 BackendFactory(const string &name) : d_name(name) {}
277 virtual ~BackendFactory(){}
278 virtual DNSBackend *make(const string &suffix)=0;
2717b8b3
BH
279 virtual DNSBackend *makeMetadataOnly(const string &suffix)
280 {
281 return this->make(suffix);
282 }
12c86877
BH
283 virtual void declareArguments(const string &suffix=""){}
284 const string &getName() const;
285
286protected:
287 void declare(const string &suffix, const string &param, const string &explanation, const string &value);
288
289private:
290 const string d_name;
291};
292
293class BackendMakerClass
294{
295public:
296 void report(BackendFactory *bf);
297 void launch(const string &instr);
e0d84497 298 vector<DNSBackend *>all(bool skipBIND=false);
12c86877
BH
299 void load(const string &module);
300 int numLauncheable();
301 vector<string> getModules();
302
303private:
304 void load_all();
305 typedef map<string,BackendFactory *>d_repository_t;
306 d_repository_t d_repository;
307 vector<pair<string,string> >d_instances;
308};
309
310extern BackendMakerClass &BackendMakers();
311
bdc9f8d2 312//! Exception that can be thrown by a DNSBackend to indicate a failure
cc3afe25
BH
313class DBException : public AhuException
314{
315public:
316 DBException(const string &reason) : AhuException(reason){}
317};
318
12c86877
BH
319
320#endif