]> git.ipfire.org Git - thirdparty/pdns.git/blame - pdns/packethandler.hh
Merge pull request #9099 from PowerDNS/omoerbeek-patch-1
[thirdparty/pdns.git] / pdns / packethandler.hh
CommitLineData
12c86877 1/*
12471842
PL
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 */
e8c59f2d 22#pragma once
76473b92
KM
23#include <sys/socket.h>
24#include <netinet/in.h>
25#include <arpa/inet.h>
12c86877
BH
26#include "ueberbackend.hh"
27#include "dnspacket.hh"
28#include "packetcache.hh"
e0d84497 29#include "dnsseckeeper.hh"
0ecc1158 30#include "lua-auth4.hh"
7f9ac49b 31#include "gss_context.hh"
12c86877 32
10f4eea8 33#include "namespaces.hh"
12c86877 34
88def049
BH
35// silly Solaris people define PC
36#undef PC
37
12c86877
BH
38/** Central DNS logic according to RFC1034. Ask this class a question in the form of a DNSPacket
39 and it will return, synchronously, a DNSPacket answer, suitable for
40 sending out over the network.
41
42 The PacketHandler gives your question to the PacketCache for possible inclusion
43 in the cache.
44
45 In order to do so, the PacketHandler contains a reference to the global extern PacketCache PC
46
47 It also contains an UeberBackend instance for answering the subqueries needed to generate
48 a complete reply.
49
50*/
5c3bf2db 51class NSEC3PARAMRecordContent;
12c86877
BH
52
53class PacketHandler
54{
55public:
c2826d2e
RG
56 std::unique_ptr<DNSPacket> doQuestion(DNSPacket&); //!< hand us a DNS packet with a question, we give you an answer
57 std::unique_ptr<DNSPacket> question(DNSPacket&); //!< hand us a DNS packet with a question, we give you an answer
12c86877
BH
58 PacketHandler();
59 ~PacketHandler(); // defined in packethandler.cc, and does --count
bdc9f8d2 60 static int numRunning(){return s_count;}; //!< Returns the number of running PacketHandlers. Called by Distributor
12c86877 61
3971cf53 62 UeberBackend *getBackend();
cc3afe25 63
c2826d2e 64 int trySuperMasterSynchronous(const DNSPacket& p, const DNSName& tsigkeyname);
d207ad63 65 static NetmaskGroup s_allowNotifyFrom;
dad0736b 66 static set<string> s_forwardNotify;
12c86877
BH
67
68private:
c2826d2e
RG
69 int trySuperMaster(const DNSPacket& p, const DNSName& tsigkeyname);
70 int processNotify(const DNSPacket& );
71 void addRootReferral(DNSPacket& r);
72 int doChaosRequest(const DNSPacket& p, std::unique_ptr<DNSPacket>& r, DNSName &target) const;
73 bool addDNSKEY(DNSPacket& p, std::unique_ptr<DNSPacket>& r, const SOAData& sd);
74 bool addCDNSKEY(DNSPacket& p, std::unique_ptr<DNSPacket>& r, const SOAData& sd);
75 bool addCDS(DNSPacket& p, std::unique_ptr<DNSPacket>& r, const SOAData& sd);
76 bool addNSEC3PARAM(const DNSPacket& p, std::unique_ptr<DNSPacket>& r, const SOAData& sd);
77 int doAdditionalProcessingAndDropAA(DNSPacket& p, std::unique_ptr<DNSPacket>& r, const SOAData& sd, bool retargeted);
78 void addNSECX(DNSPacket& p, std::unique_ptr<DNSPacket>& r, const DNSName &target, const DNSName &wildcard, const DNSName &auth, int mode);
79 void addNSEC(DNSPacket& p, std::unique_ptr<DNSPacket>& r, const DNSName &target, const DNSName &wildcard, const DNSName& auth, int mode);
80 void addNSEC3(DNSPacket& p, std::unique_ptr<DNSPacket>& r, const DNSName &target, const DNSName &wildcard, const DNSName& auth, const NSEC3PARAMRecordContent& nsec3param, bool narrow, int mode);
81 void emitNSEC(std::unique_ptr<DNSPacket>& r, const SOAData& sd, const DNSName& name, const DNSName& next, int mode);
82 void emitNSEC3(std::unique_ptr<DNSPacket>& r, const SOAData& sd, const NSEC3PARAMRecordContent &ns3rc, const DNSName& unhashed, const string& begin, const string& end, int mode);
83 int processUpdate(DNSPacket& p);
84 int forwardPacket(const string &msgPrefix, const DNSPacket& p, const DomainInfo& di);
d0d273cf 85 uint performUpdate(const string &msgPrefix, const DNSRecord *rr, DomainInfo *di, bool isPresigned, bool* narrow, bool* haveNSEC3, NSEC3PARAMRecordContent *ns3pr, bool *updatedSerial);
f7a69a4c
RA
86 int checkUpdatePrescan(const DNSRecord *rr);
87 int checkUpdatePrerequisites(const DNSRecord *rr, DomainInfo *di);
166ac305 88 void increaseSerial(const string &msgPrefix, const DomainInfo *di, bool haveNSEC3, bool narrow, const NSEC3PARAMRecordContent *ns3pr);
5c3bf2db 89
c2826d2e
RG
90 void makeNXDomain(DNSPacket& p, std::unique_ptr<DNSPacket>& r, const DNSName& target, const DNSName& wildcard, const SOAData& sd);
91 void makeNOError(DNSPacket& p, std::unique_ptr<DNSPacket>& r, const DNSName& target, const DNSName& wildcard, const SOAData& sd, int mode);
92 vector<DNSZoneRecord> getBestReferralNS(DNSPacket& p, const SOAData& sd, const DNSName &target);
93 vector<DNSZoneRecord> getBestDNAMESynth(DNSPacket& p, const SOAData& sd, DNSName &target);
94 bool tryDNAME(DNSPacket& p, std::unique_ptr<DNSPacket>& r, const SOAData& sd, DNSName &target);
95 bool tryReferral(DNSPacket& p, std::unique_ptr<DNSPacket>& r, const SOAData& sd, const DNSName &target, bool retargeted);
675fa24c 96
c2826d2e
RG
97 bool getBestWildcard(DNSPacket& p, const SOAData& sd, const DNSName &target, DNSName &wildcard, vector<DNSZoneRecord>* ret);
98 bool tryWildcard(DNSPacket& p, std::unique_ptr<DNSPacket>& r, const SOAData& sd, DNSName &target, DNSName &wildcard, bool& retargeted, bool& nodata);
99 bool addDSforNS(DNSPacket& p, std::unique_ptr<DNSPacket>& r, const SOAData& sd, const DNSName& dsname);
100 void completeANYRecords(DNSPacket& p, std::unique_ptr<DNSPacket>& r, const SOAData& sd, const DNSName &target);
c00d7891 101
c2826d2e 102 void tkeyHandler(const DNSPacket& p, std::unique_ptr<DNSPacket>& r); //<! process TKEY record, and adds TKEY record to (r)eply, or error code.
c00d7891 103
16f7d28d 104 static AtomicCounter s_count;
0ddde5fb 105 static std::mutex s_rfc2136lock;
12c86877 106 bool d_logDNSDetails;
fd8bc993 107 bool d_doIPv6AdditionalProcessing;
8dee0750 108 bool d_doDNAME;
389b7a05 109 bool d_doExpandALIAS;
6dbf337f 110 bool d_dnssec;
7c99293d 111 std::unique_ptr<AuthLua4> d_pdl;
3ce6361c 112 std::unique_ptr<AuthLua4> d_update_policy_lua;
12c86877
BH
113
114 UeberBackend B; // every thread an own instance
e59b5787 115 DNSSECKeeper d_dk; // B is shared with DNSSECKeeper
12c86877 116};
c2826d2e 117