root/trunk/pdns/pdns/packethandler.hh @ 1561

Revision 1561, 4.3 KB (checked in by ahu, 3 years ago)

rip out old, but efficient and highly tuned but scary packethandler code, replace by much cleaner variant with dnssec guts
un-ifdef up the actual signing stuff in dnspacket.cc. crashes violently on the first DNSSEC query now!

  • Property svn:eol-style set to native
  • Property svn:keywords set to author date id revision
Line 
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 version 2
7    as published by the Free Software Foundation
8   
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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  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
32using namespace std;
33
34// silly Solaris people define PC
35#undef PC
36
37/** Central DNS logic according to RFC1034. Ask this class a question in the form of a DNSPacket
38    and it will return, synchronously, a DNSPacket answer, suitable for
39    sending out over the network.
40
41    The PacketHandler gives your question to the PacketCache for possible inclusion
42    in the cache.
43
44    In order to do so, the PacketHandler contains a reference to the global extern PacketCache PC
45
46    It also contains an UeberBackend instance for answering the subqueries needed to generate
47    a complete reply.
48
49*/
50
51class PacketHandler
52{
53public:
54  template<class T> class Guard
55  {
56  public:
57    Guard(T **guard)
58    {
59      d_guard=guard;
60    }
61   
62    ~Guard()
63    {
64      if(*d_guard)
65        delete *d_guard;
66    }
67   
68  private:
69    T **d_guard;
70  };
71
72  DNSPacket *questionOrRecurse(DNSPacket *, bool* shouldRecurse); //!< hand us a DNS packet with a question, we'll tell you answer, or that you should recurse
73  DNSPacket *question(DNSPacket *); //!< hand us a DNS packet with a question, we give you an answer
74  PacketHandler(); 
75  ~PacketHandler(); // defined in packethandler.cc, and does --count
76  static int numRunning(){return s_count;}; //!< Returns the number of running PacketHandlers. Called by Distributor
77 
78  void soaMagic(DNSResourceRecord *rr);
79  DNSBackend *getBackend();
80
81
82private:
83  int processNotify(DNSPacket *);
84  void addRootReferral(DNSPacket *r);
85  int trySuperMaster(DNSPacket *p);
86  int makeCanonic(DNSPacket *p, DNSPacket *r, string &target);
87  int doWildcardRecords(DNSPacket *p, DNSPacket *r, string &target);
88  int findMboxFW(DNSPacket *p, DNSPacket *r, string &target);
89  int findUrl(DNSPacket *p, DNSPacket *r, string &target);
90  int doFancyRecords(DNSPacket *p, DNSPacket *r, string &target);
91  int doVersionRequest(DNSPacket *p, DNSPacket *r, string &target);
92  int doDNSKEYRequest(DNSPacket *p, DNSPacket *r);
93  bool getAuth(DNSPacket *p, SOAData *sd, const string &target, int *zoneId);
94  bool getTLDAuth(DNSPacket *p, SOAData *sd, const string &target, int *zoneId);
95  int doAdditionalProcessingAndDropAA(DNSPacket *p, DNSPacket *r);
96  bool doDNSSECProcessing(DNSPacket* p, DNSPacket *r);
97  void addNSEC(DNSPacket *p, DNSPacket* r, const string &target, const std::string& auth, int mode);
98  void emitNSEC(const std::string& before, const std::string& after, const std::string& toNSEC, DNSPacket *r, int mode);
99  void synthesiseRRSIGs(DNSPacket* p, DNSPacket* r);
100  void makeNXDomain(DNSPacket* p, DNSPacket* r, const std::string& target, SOAData& sd);
101  void makeNOError(DNSPacket* p, DNSPacket* r, const std::string& target, SOAData& sd);
102  vector<DNSResourceRecord> getBestReferralNS(DNSPacket *p, SOAData& sd, const string &target);
103  bool tryReferral(DNSPacket *p, DNSPacket*r, SOAData& sd, const string &target);
104
105  vector<DNSResourceRecord> getBestWildcard(DNSPacket *p, SOAData& sd, const string &target);
106  bool tryWildcard(DNSPacket *p, DNSPacket*r, SOAData& sd, string &target, bool& retargeted);
107  bool addDSforNS(DNSPacket* p, DNSPacket* r, SOAData& sd, const string& dsname);
108  void completeANYRecords(DNSPacket *p, DNSPacket*r, SOAData& sd, const string &target);
109 
110  static int s_count;
111  bool d_doFancyRecords;
112  bool d_doRecursion;
113  bool d_doWildcards;
114  bool d_doCNAME;
115  bool d_logDNSDetails;
116  bool d_doIPv6AdditionalProcessing;
117
118  UeberBackend B; // every thread an own instance
119};
120
121#endif /* PACKETHANDLER */
Note: See TracBrowser for help on using the browser.