]>
Commit | Line | Data |
---|---|---|
12c86877 BH |
1 | /* |
2 | PowerDNS Versatile Database Driven Nameserver | |
51a3a4d4 | 3 | Copyright (C) 2002 - 2011 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 | |
f782fe38 MH |
8 | |
9 | Additionally, the license of this program contains a special | |
10 | exception which allows to distribute the program in binary form when | |
11 | it is linked against OpenSSL. | |
12c86877 BH |
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 | |
06bd9ccf | 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
12c86877 BH |
21 | */ |
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 BH |
32 | #include <sys/un.h> |
33 | #include <dlfcn.h> | |
34 | #include <unistd.h> | |
35 | #include <sys/socket.h> | |
36 | #include <netinet/in.h> | |
37 | #include <sys/stat.h> | |
38 | #include <fcntl.h> | |
39 | #include <unistd.h> | |
6a010475 | 40 | #include <boost/utility.hpp> |
12c86877 BH |
41 | #include "dnspacket.hh" |
42 | #include "dnsbackend.hh" | |
43 | ||
10f4eea8 | 44 | #include "namespaces.hh" |
12c86877 | 45 | |
12c86877 BH |
46 | /** This is a very magic backend that allows us to load modules dynamically, |
47 | and query them in order. This is persistent over all UeberBackend instantiations | |
bdc9f8d2 BH |
48 | across multiple threads. |
49 | ||
50 | The UeberBackend is transparent for exceptions, which should fall straight through. | |
51 | */ | |
12c86877 | 52 | |
3971cf53 | 53 | class UeberBackend : public boost::noncopyable |
12c86877 BH |
54 | { |
55 | public: | |
6a010475 | 56 | UeberBackend(const string &pname="default"); |
12c86877 BH |
57 | ~UeberBackend(); |
58 | typedef DNSBackend *BackendMaker(); //!< typedef for functions returning pointers to new backends | |
59 | ||
719f9024 | 60 | bool superMasterBackend(const string &ip, const string &domain, const vector<DNSResourceRecord>&nsset, string *nameserver, string *account, DNSBackend **db); |
12c86877 | 61 | |
12c86877 BH |
62 | /** Tracks all created UeberBackend instances for us. We use this vector to notify |
63 | existing threads of new modules | |
64 | */ | |
65 | static vector<UeberBackend *>instances; | |
66 | static pthread_mutex_t instances_lock; | |
67 | ||
68 | static bool loadmodule(const string &name); | |
69 | ||
12c86877 BH |
70 | static void go(void); |
71 | ||
12c86877 BH |
72 | /** This contains all registered backends. The DynListener modifies this list for us when |
73 | new modules are loaded */ | |
6a010475 | 74 | vector<DNSBackend*> backends; |
12c86877 | 75 | |
12c86877 BH |
76 | void cleanup(); |
77 | ||
78 | //! the very magic handle for UeberBackend questions | |
79 | class handle | |
80 | { | |
81 | public: | |
82 | bool get(DNSResourceRecord &r); | |
83 | handle(); | |
84 | ~handle(); | |
85 | ||
86 | //! The UeberBackend class where this handle belongs to | |
87 | UeberBackend *parent; | |
88 | //! The current real backend, which is answering questions | |
89 | DNSBackend *d_hinterBackend; | |
90 | ||
91 | //! Index of the current backend within the backends vector | |
92 | unsigned int i; | |
93 | ||
94 | //! DNSPacket who asked this question | |
95 | DNSPacket *pkt_p; | |
96 | string qname; | |
97 | QType qtype; | |
98 | private: | |
99 | ||
16f7d28d | 100 | static AtomicCounter instances; |
12c86877 BH |
101 | }; |
102 | ||
103 | void lookup(const QType &, const string &qdomain, DNSPacket *pkt_p=0, int zoneId=-1); | |
104 | ||
81c486ad | 105 | bool getAuth(DNSPacket *p, SOAData *sd, const string &target); |
35933370 | 106 | bool getSOA(const string &domain, SOAData &sd, DNSPacket *p=0); |
79ba7763 | 107 | bool getSOAUncached(const string &domain, SOAData &sd, DNSPacket *p=0); // same, but ignores cache |
cea26350 | 108 | bool list(const string &target, int domain_id, bool include_disabled=false); |
12c86877 | 109 | bool get(DNSResourceRecord &r); |
cea26350 | 110 | void getAllDomains(vector<DomainInfo> *domains, bool include_disabled=false); |
12c86877 BH |
111 | |
112 | static DNSBackend *maker(const map<string,string> &); | |
12c86877 BH |
113 | void getUnfreshSlaveInfos(vector<DomainInfo>* domains); |
114 | void getUpdatedMasters(vector<DomainInfo>* domains); | |
115 | bool getDomainInfo(const string &domain, DomainInfo &di); | |
4d73ea84 | 116 | bool createDomain(const string &domain); |
c0273500 | 117 | |
3971cf53 CH |
118 | int addDomainKey(const string& name, const DNSBackend::KeyData& key); |
119 | bool getDomainKeys(const string& name, unsigned int kind, std::vector<DNSBackend::KeyData>& keys); | |
ac993e0a | 120 | bool getAllDomainMetadata(const string& name, std::map<std::string, std::vector<std::string> >& meta); |
c0273500 BH |
121 | bool getDomainMetadata(const string& name, const std::string& kind, std::vector<std::string>& meta); |
122 | bool setDomainMetadata(const string& name, const std::string& kind, const std::vector<std::string>& meta); | |
4496f66f BH |
123 | |
124 | bool removeDomainKey(const string& name, unsigned int id); | |
125 | bool activateDomainKey(const string& name, unsigned int id); | |
126 | bool deactivateDomainKey(const string& name, unsigned int id); | |
78bcb858 | 127 | |
996df946 | 128 | bool getDirectNSECx(uint32_t id, const string &hashed, const QType &qtype, string &before, DNSResourceRecord &rr); |
461a0401 | 129 | bool getDirectRRSIGs(const string &signer, const string &qname, const QType &qtype, vector<DNSResourceRecord> &rrsigs); |
d88babea | 130 | |
78bcb858 | 131 | bool getTSIGKey(const string& name, string* algorithm, string* content); |
6f872b78 AT |
132 | bool setTSIGKey(const string& name, const string& algorithm, const string& content); |
133 | bool deleteTSIGKey(const string& name); | |
134 | bool getTSIGKeys(std::vector< struct TSIGKey > &keys); | |
135 | ||
27d94a79 | 136 | void alsoNotifies(const string &domain, set<string> *ips); |
973ad2b5 | 137 | void rediscover(string* status=0); |
12c86877 BH |
138 | void reload(); |
139 | private: | |
f1d64762 MZ |
140 | unsigned int d_cache_ttl, d_negcache_ttl; |
141 | ||
12c86877 BH |
142 | pthread_t tid; |
143 | handle d_handle; | |
144 | bool d_negcached; | |
145 | bool d_cached; | |
146 | struct Question | |
147 | { | |
148 | QType qtype; | |
149 | string qname; | |
150 | int zoneId; | |
151 | }d_question; | |
cb433f9c BH |
152 | vector<DNSResourceRecord> d_answers; |
153 | vector<DNSResourceRecord>::const_iterator d_cachehandleiter; | |
12c86877 | 154 | |
cb433f9c | 155 | int cacheHas(const Question &q, vector<DNSResourceRecord> &rrs); |
12c86877 | 156 | void addNegCache(const Question &q); |
cb433f9c | 157 | void addCache(const Question &q, const vector<DNSResourceRecord> &rrs); |
12c86877 BH |
158 | |
159 | static pthread_mutex_t d_mut; | |
160 | static pthread_cond_t d_cond; | |
161 | static sem_t d_dynserialize; | |
162 | static bool d_go; | |
12c86877 | 163 | int d_ancount; |
e0d84497 | 164 | |
12c86877 | 165 | bool stale; |
c27c8d96 | 166 | int domain_id; |
12c86877 BH |
167 | }; |
168 | ||
12c86877 | 169 | #endif |