]> git.ipfire.org Git - thirdparty/pdns.git/blob - modules/tinydnsbackend/tinydnsbackend.hh
9d65dd1ba3d464b86eabf2a65c6d115ea594f5d3
[thirdparty/pdns.git] / modules / tinydnsbackend / tinydnsbackend.hh
1 #ifndef TINYDNSBACKEND_HH
2 #define TINYDNSBACKEND_HH
3
4 #include "pdns/dnsbackend.hh"
5 #include "pdns/logger.hh"
6 #include "pdns/iputils.hh"
7 #include "pdns/dnspacket.hh"
8 #include <cdb.h>
9 #include <sys/types.h>
10 #include <sys/stat.h>
11 #include <fcntl.h>
12 #include "cdb.hh"
13 #include "pdns/lock.hh"
14 #include <boost/multi_index_container.hpp>
15 #include <boost/multi_index/hashed_index.hpp>
16 #include <boost/multi_index/member.hpp>
17
18 using namespace ::boost;
19 using namespace ::boost::multi_index;
20
21 struct TinyDomainInfo {
22 uint32_t id;
23 uint32_t notified_serial;
24 DNSName zone;
25
26 bool operator<(const TinyDomainInfo& tdi) const
27 {
28 return zone < tdi.zone;
29 }
30 };
31
32 struct TDI_SerialModifier {
33 TDI_SerialModifier (const int newSerial) : d_newSerial(newSerial) {}
34
35 void operator()(TinyDomainInfo& tdi)
36 {
37 tdi.notified_serial = d_newSerial;
38 }
39
40 private:
41 int d_newSerial;
42 };
43
44
45 class TinyDNSBackend : public DNSBackend
46 {
47 public:
48 // Methods for simple operation
49 TinyDNSBackend(const string &suffix);
50 void lookup(const QType &qtype, const DNSName &qdomain, DNSPacket *pkt_p=0, int zoneId=-1);
51 bool list(const DNSName &target, int domain_id, bool include_disabled=false);
52 bool get(DNSResourceRecord &rr);
53 void getAllDomains(vector<DomainInfo> *domains, bool include_disabled=false);
54
55 //Master mode operation
56 void getUpdatedMasters(vector<DomainInfo>* domains);
57 void setNotified(uint32_t id, uint32_t serial);
58 private:
59 vector<string> getLocations();
60
61 //TypeDefs
62 struct tag_zone{};
63 struct tag_domainid{};
64 typedef multi_index_container<
65 TinyDomainInfo,
66 indexed_by<
67 hashed_unique<tag<tag_zone>, member<TinyDomainInfo, DNSName, &TinyDomainInfo::zone> >,
68 hashed_unique<tag<tag_domainid>, member<TinyDomainInfo, uint32_t, &TinyDomainInfo::id> >
69 >
70 > TDI_t;
71 typedef map<string, TDI_t> TDI_suffix_t;
72 typedef TDI_t::index<tag_zone>::type TDIByZone_t;
73 typedef TDI_t::index<tag_domainid>::type TDIById_t;
74
75 //data member variables
76 uint64_t d_taiepoch;
77 QType d_qtype;
78 CDB *d_cdbReader;
79 DNSPacket *d_dnspacket; // used for location and edns-client support.
80 bool d_isWildcardQuery; // Indicate if the query received was a wildcard query.
81 bool d_isAxfr; // Indicate if we received a list() and not a lookup().
82 bool d_locations;
83 bool d_ignorebogus;
84 string d_suffix;
85
86 // Statics
87 static pthread_mutex_t s_domainInfoLock;
88 static TDI_suffix_t s_domainInfo;
89 static uint32_t s_lastId; // used to give a domain an id.
90 };
91
92 #endif // TINYDNSBACKEND_HH