]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/packethandler.hh
PowerDNS Forward-Notify Patch:
[thirdparty/pdns.git] / pdns / packethandler.hh
1 /*
2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * In addition, for the avoidance of any doubt, permission is granted to
10 * link this program with OpenSSL and to (re)distribute the binaries
11 * produced as the result of such linking.
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
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22 #ifndef PACKETHANDLER_HH
23 #define PACKETHANDLER_HH
24
25 #include <sys/socket.h>
26 #include <netinet/in.h>
27 #include <arpa/inet.h>
28 #include "ueberbackend.hh"
29 #include "dnspacket.hh"
30 #include "packetcache.hh"
31 #include "dnsseckeeper.hh"
32 #include "lua-auth.hh"
33 #include "lua-auth4.hh"
34 #include "gss_context.hh"
35
36 #include "namespaces.hh"
37
38 // silly Solaris people define PC
39 #undef PC
40
41 /** Central DNS logic according to RFC1034. Ask this class a question in the form of a DNSPacket
42 and it will return, synchronously, a DNSPacket answer, suitable for
43 sending out over the network.
44
45 The PacketHandler gives your question to the PacketCache for possible inclusion
46 in the cache.
47
48 In order to do so, the PacketHandler contains a reference to the global extern PacketCache PC
49
50 It also contains an UeberBackend instance for answering the subqueries needed to generate
51 a complete reply.
52
53 */
54 class NSEC3PARAMRecordContent;
55
56 class PacketHandler
57 {
58 public:
59 DNSPacket *doQuestion(DNSPacket *); //!< hand us a DNS packet with a question, we give you an answer
60 DNSPacket *question(DNSPacket *); //!< hand us a DNS packet with a question, we give you an answer
61 PacketHandler();
62 ~PacketHandler(); // defined in packethandler.cc, and does --count
63 static int numRunning(){return s_count;}; //!< Returns the number of running PacketHandlers. Called by Distributor
64
65 UeberBackend *getBackend();
66
67 int trySuperMasterSynchronous(DNSPacket *p, const DNSName& tsigkeyname);
68 static NetmaskGroup s_allowNotifyFrom;
69 static set<string> s_forwardNotify;
70
71 private:
72 int trySuperMaster(DNSPacket *p, const DNSName& tsigkeyname);
73 int processNotify(DNSPacket *);
74 void addRootReferral(DNSPacket *r);
75 int doChaosRequest(DNSPacket *p, DNSPacket *r, DNSName &target);
76 bool addDNSKEY(DNSPacket *p, DNSPacket *r, const SOAData& sd);
77 bool addCDNSKEY(DNSPacket *p, DNSPacket *r, const SOAData& sd);
78 bool addCDS(DNSPacket *p, DNSPacket *r, const SOAData& sd);
79 bool addNSEC3PARAM(DNSPacket *p, DNSPacket *r, const SOAData& sd);
80 int doAdditionalProcessingAndDropAA(DNSPacket *p, DNSPacket *r, const SOAData& sd, bool retargeted);
81 void addNSECX(DNSPacket *p, DNSPacket* r, const DNSName &target, const DNSName &wildcard, const DNSName &auth, int mode);
82 void addNSEC(DNSPacket *p, DNSPacket* r, const DNSName &target, const DNSName &wildcard, const DNSName& auth, int mode);
83 void addNSEC3(DNSPacket *p, DNSPacket* r, const DNSName &target, const DNSName &wildcard, const DNSName& auth, const NSEC3PARAMRecordContent& nsec3param, bool narrow, int mode);
84 void emitNSEC(DNSPacket *r, const SOAData& sd, const DNSName& name, const DNSName& next, int mode);
85 void emitNSEC3(DNSPacket *r, const SOAData& sd, const NSEC3PARAMRecordContent &ns3rc, const DNSName& unhashed, const string& begin, const string& end, int mode);
86 int processUpdate(DNSPacket *p);
87 int forwardPacket(const string &msgPrefix, DNSPacket *p, DomainInfo *di);
88 uint performUpdate(const string &msgPrefix, const DNSRecord *rr, DomainInfo *di, bool isPresigned, bool* narrow, bool* haveNSEC3, NSEC3PARAMRecordContent *ns3pr, bool *updatedSerial);
89 int checkUpdatePrescan(const DNSRecord *rr);
90 int checkUpdatePrerequisites(const DNSRecord *rr, DomainInfo *di);
91 void increaseSerial(const string &msgPrefix, const DomainInfo *di, bool haveNSEC3, bool narrow, const NSEC3PARAMRecordContent *ns3pr);
92
93 void makeNXDomain(DNSPacket* p, DNSPacket* r, const DNSName& target, const DNSName& wildcard, SOAData& sd);
94 void makeNOError(DNSPacket* p, DNSPacket* r, const DNSName& target, const DNSName& wildcard, SOAData& sd, int mode);
95 vector<DNSZoneRecord> getBestReferralNS(DNSPacket *p, SOAData& sd, const DNSName &target);
96 vector<DNSZoneRecord> getBestDNAMESynth(DNSPacket *p, SOAData& sd, DNSName &target);
97 bool tryDNAME(DNSPacket *p, DNSPacket*r, SOAData& sd, DNSName &target);
98 bool tryReferral(DNSPacket *p, DNSPacket*r, SOAData& sd, const DNSName &target, bool retargeted);
99
100 bool getBestWildcard(DNSPacket *p, SOAData& sd, const DNSName &target, DNSName &wildcard, vector<DNSZoneRecord>* ret);
101 bool tryWildcard(DNSPacket *p, DNSPacket*r, SOAData& sd, DNSName &target, DNSName &wildcard, bool& retargeted, bool& nodata);
102 bool addDSforNS(DNSPacket* p, DNSPacket* r, SOAData& sd, const DNSName& dsname);
103 void completeANYRecords(DNSPacket *p, DNSPacket*r, SOAData& sd, const DNSName &target);
104
105 void tkeyHandler(DNSPacket *p, DNSPacket *r); //<! process TKEY record, and adds TKEY record to (r)eply, or error code.
106
107 static AtomicCounter s_count;
108 static pthread_mutex_t s_rfc2136lock;
109 bool d_logDNSDetails;
110 bool d_doIPv6AdditionalProcessing;
111 bool d_doDNAME;
112 bool d_doExpandALIAS;
113 std::unique_ptr<AuthLua> d_pdl;
114 std::unique_ptr<AuthLua4> d_update_policy_lua;
115
116 UeberBackend B; // every thread an own instance
117 DNSSECKeeper d_dk; // B is shared with DNSSECKeeper
118 };
119 bool getNSEC3Hashes(bool narrow, DNSBackend* db, int id, const std::string& hashed, bool decrement, DNSName& unhashed, string& before, string& after, int mode=0);
120 std::shared_ptr<DNSRecordContent> makeSOAContent(const SOAData& sd);
121 #endif /* PACKETHANDLER */