]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/packethandler.hh
Initial revision
[thirdparty/pdns.git] / pdns / packethandler.hh
1 /*
2 PowerDNS Versatile Database Driven Nameserver
3 Copyright (C) 2002 PowerDNS.COM BV
4
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.
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
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 #ifndef PACKETHANDLER_HH
20 #define PACKETHANDLER_HH
21
22 #ifndef WIN32
23 # include <sys/socket.h>
24 # include <netinet/in.h>
25 # include <arpa/inet.h>
26 #endif // WIN32
27
28 #include "ueberbackend.hh"
29 #include "dnspacket.hh"
30 #include "packetcache.hh"
31
32 using namespace std;
33
34 /** Central DNS logic according to RFC1034. Ask this class a question in the form of a DNSPacket
35 and it will return, synchronously, a DNSPacket answer, suitable for
36 sending out over the network.
37
38 The PacketHandler gives your question to the PacketCache for possible inclusion
39 in the cache.
40
41 In order to do so, the PacketHandler contains a reference to the global extern PacketCache PC
42
43 It also contains an UeberBackend instance for answering the subqueries needed to generate
44 a complete reply.
45
46 */
47
48 class PacketHandler
49 {
50 public:
51 template<class T> class Guard
52 {
53 public:
54 Guard(T **guard)
55 {
56 d_guard=guard;
57 }
58
59 ~Guard()
60 {
61 if(*d_guard)
62 delete *d_guard;
63 }
64
65 private:
66 T **d_guard;
67 };
68
69
70 DNSPacket *question(DNSPacket *); //!< hand us a DNS packet with a question, we give you an answer
71 PacketHandler();
72 ~PacketHandler(); // defined in packethandler.cc, and does --count
73 static int numRunning(){return s_count;}; //!< Returns the number of running PacketHandlers
74
75 void soaMagic(DNSResourceRecord *rr);
76 DNSBackend *getBackend();
77 class DBException{};
78
79 private:
80 int doNotify(DNSPacket *);
81 int PacketHandler::trySuperMaster(DNSPacket *p);
82 int makeCanonic(DNSPacket *p, DNSPacket *r, string &target);
83 int doWildcardRecords(DNSPacket *p, DNSPacket *r, string &target);
84 int findMboxFW(DNSPacket *p, DNSPacket *r, string &target);
85 int findUrl(DNSPacket *p, DNSPacket *r, string &target);
86 int doFancyRecords(DNSPacket *p, DNSPacket *r, string &target);
87 int doDNSCheckRequest(DNSPacket *p, DNSPacket *r, string &target);
88 int doVersionRequest(DNSPacket *p, DNSPacket *r, string &target);
89 bool getAuth(DNSPacket *p, SOAData *sd, const string &target, int *zoneId);
90 bool getTLDAuth(DNSPacket *p, SOAData *sd, const string &target, int *zoneId);
91 int doAdditionalProcessing(DNSPacket *p, DNSPacket *r, bool &dangling);
92
93
94 static int s_count;
95 bool d_doFancyRecords;
96 bool d_doRecursion;
97 bool d_doLazyRecursion;
98 bool d_doWildcards;
99 bool d_doCNAME;
100 bool d_logDNSDetails;
101
102 UeberBackend B; // every thread an own instance
103 };
104
105 #endif /* PACKETHANDLER */