From 228931451942fd48177651d535253a1b8203cc07 Mon Sep 17 00:00:00 2001 From: Christian Hofstaedtler Date: Thu, 19 Mar 2015 23:05:36 +0100 Subject: [PATCH] Optimize AXFR disabled case When disable-axfr=yes or client ACLs don't allow the AXFR to go through, skip all backend launching activities (possibly expensive for pipe- and remotebackend users). Same for IXFR. --- pdns/tcpreceiver.cc | 95 +++++++++++++++++++++++---------------------- 1 file changed, 49 insertions(+), 46 deletions(-) diff --git a/pdns/tcpreceiver.cc b/pdns/tcpreceiver.cc index de2e8c1280..95dbcd7b84 100644 --- a/pdns/tcpreceiver.cc +++ b/pdns/tcpreceiver.cc @@ -521,38 +521,13 @@ namespace { /** do the actual zone transfer. Return 0 in case of error, 1 in case of success */ int TCPNameserver::doAXFR(const string &target, shared_ptr q, int outsock) { - bool noAXFRBecauseOfNSEC3Narrow=false; - NSEC3PARAMRecordContent ns3pr; - bool narrow; - bool NSEC3Zone=false; - - DNSSECKeeper dk; - dk.clearCaches(target); - bool securedZone = dk.isSecuredZone(target); - bool presignedZone = dk.isPresigned(target); - - if(dk.getNSEC3PARAM(target, &ns3pr, &narrow)) { - NSEC3Zone=true; - if(narrow) { - L<getRemote()< outpacket= getFreshAXFRPacket(q); if(q->d_dnssecOk) outpacket->d_dnssecOk=true; // RFC 5936, 2.2.5 'SHOULD' - - if(noAXFRBecauseOfNSEC3Narrow) { - L<getRemote()<setRcode(RCode::Refused); - // FIXME: should actually figure out if we are auth over a zone, and send out 9 if we aren't - sendPacket(outpacket,outsock); - return 0; - } - + L<getRemote()< q, int out s_P=new PacketHandler; } - if(!s_P->getBackend()->getSOAUncached(target, sd) || !canDoAXFR(q)) { + // canDoAXFR does all the ACL checks, and has the if(disable-axfr) shortcut, call it first. + if(!canDoAXFR(q) || !s_P->getBackend()->getSOAUncached(target, sd)) { L<setRcode(9); // 'NOTAUTH' sendPacket(outpacket,outsock); return 0; } } - + UeberBackend db; if(!db.getSOAUncached(target, sd)) { L< q, int out return 0; } + DNSSECKeeper dk; + dk.clearCaches(target); + bool securedZone = dk.isSecuredZone(target); + bool presignedZone = dk.isPresigned(target); + + bool noAXFRBecauseOfNSEC3Narrow=false; + NSEC3PARAMRecordContent ns3pr; + bool narrow; + bool NSEC3Zone=false; + if(dk.getNSEC3PARAM(target, &ns3pr, &narrow)) { + NSEC3Zone=true; + if(narrow) { + L<getRemote()<getRemote()<setRcode(RCode::Refused); + // FIXME: should actually figure out if we are auth over a zone, and send out 9 if we aren't + sendPacket(outpacket,outsock); + return 0; + } + TSIGRecordContent trc; string tsigkeyname, tsigsecret; @@ -932,22 +933,6 @@ int TCPNameserver::doIXFR(shared_ptr q, int outsock) if(q->d_dnssecOk) outpacket->d_dnssecOk=true; // RFC 5936, 2.2.5 'SHOULD' - DNSSECKeeper dk; - NSEC3PARAMRecordContent ns3pr; - bool narrow; - - dk.clearCaches(q->qdomain); - bool securedZone = dk.isSecuredZone(q->qdomain); - if(dk.getNSEC3PARAM(q->qdomain, &ns3pr, &narrow)) { - if(narrow) { - L<qdomain<<"' denied to "<getRemote()<setRcode(RCode::Refused); - sendPacket(outpacket,outsock); - return 0; - } - } - uint32_t serial = 0; MOADNSParser mdp(q->getString()); for(MOADNSParser::answers_t::const_iterator i=mdp.d_answers.begin(); i != mdp.d_answers.end(); ++i) { @@ -973,6 +958,7 @@ int TCPNameserver::doIXFR(shared_ptr q, int outsock) L<qdomain<<"' initiated by "<getRemote()<<" with serial "< q, int outsock) s_P=new PacketHandler; } - if(!s_P->getBackend()->getSOAUncached(q->qdomain, sd) || !canDoAXFR(q)) { + // canDoAXFR does all the ACL checks, and has the if(disable-axfr) shortcut, call it first. + if(!canDoAXFR(q) || !s_P->getBackend()->getSOAUncached(q->qdomain, sd)) { L<qdomain<<"' failed: not authoritative"<setRcode(9); // 'NOTAUTH' sendPacket(outpacket,outsock); @@ -990,6 +977,22 @@ int TCPNameserver::doIXFR(shared_ptr q, int outsock) } } + DNSSECKeeper dk; + NSEC3PARAMRecordContent ns3pr; + bool narrow; + + dk.clearCaches(q->qdomain); + bool securedZone = dk.isSecuredZone(q->qdomain); + if(dk.getNSEC3PARAM(q->qdomain, &ns3pr, &narrow)) { + if(narrow) { + L<qdomain<<"' denied to "<getRemote()<setRcode(RCode::Refused); + sendPacket(outpacket,outsock); + return 0; + } + } + string target = q->qdomain; UeberBackend db; -- 2.47.2