2 PowerDNS Versatile Database Driven Nameserver
3 Copyright (C) 2002 PowerDNS.COM BV
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
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.
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
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef UEBERBACKEND_HH
20 #define UEBERBACKEND_HH
27 #include <semaphore.h>
33 #include <sys/socket.h>
34 #include <netinet/in.h>
40 #include "dnspacket.hh"
41 #include "dnsbackend.hh"
45 class BackendReporter;
47 /** This is a very magic backend that allows us to load modules dynamically,
48 and query them in order. This is persistent over all UeberBackend instantiations
49 across multiple threads. Very magic */
51 class UeberBackend : public DNSBackend
55 UeberBackend(const string &);
57 typedef DNSBackend *BackendMaker(); //!< typedef for functions returning pointers to new backends
59 bool superMasterBackend(const string &ip, const string &domain, const vector<DNSResourceRecord>&nsset, string *account, DNSBackend **db);
61 /** contains BackendReporter objects, which contain maker functions and information about
62 weather a module has already been reported to existing instances of the UeberBackend
64 static vector<BackendReporter>backendmakers;
66 /** Tracks all created UeberBackend instances for us. We use this vector to notify
67 existing threads of new modules
69 static vector<UeberBackend *>instances;
70 static pthread_mutex_t instances_lock;
72 static bool loadmodule(const string &name);
74 /** Thread function that listens on our unix domain socket for commands, for example
75 instructions to load new modules */
76 static void *DynListener(void *);
80 /** This contains all registered backends. The DynListener modifies this list for us when
81 new modules are loaded */
82 vector<DNSBackend*>backends;
87 //! the very magic handle for UeberBackend questions
91 bool get(DNSResourceRecord &r);
95 //! The UeberBackend class where this handle belongs to
97 //! The current real backend, which is answering questions
98 DNSBackend *d_hinterBackend;
100 //! Index of the current backend within the backends vector
103 //! DNSPacket who asked this question
109 static int instances;
112 void lookup(const QType &, const string &qdomain, DNSPacket *pkt_p=0, int zoneId=-1);
114 bool getSOA(const string &domain, SOAData &sd);
115 bool list(int domain_id);
116 bool get(DNSResourceRecord &r);
118 static DNSBackend *maker(const map<string,string> &);
119 static void closeDynListener();
120 static void UeberBackend::setStatus(const string &st);
121 void getUnfreshSlaveInfos(vector<DomainInfo>* domains);
122 void getUpdatedMasters(vector<DomainInfo>* domains);
123 bool getDomainInfo(const string &domain, DomainInfo &di);
127 DNSResourceRecord lastrr;
138 DNSResourceRecord d_answer;
140 int cacheHas(const Question &q, DNSResourceRecord &rr);
141 void addNegCache(const Question &q);
142 void addOneCache(const Question &q, const DNSResourceRecord &rr);
144 static pthread_mutex_t d_mut;
145 static pthread_cond_t d_cond;
146 static sem_t d_dynserialize;
149 static string s_status;
151 static string programname;
156 /** Class used to report new backends. It stores a maker function, and a flag that indicates that
157 this module has been reported */
158 class BackendReporter
161 BackendReporter(UeberBackend::BackendMaker *p)
166 map<string,string>d_parameters;
167 UeberBackend::BackendMaker *maker; //!< function to make this backend
168 bool reported; //!< if this backend has been reported to running UeberBackend threads