int diff;
bool logDNSQueries = ::arg().mustDo("log-dns-queries");
- bool doRecursion = ::arg().mustDo("recursor");
UDPNameserver *NS = N;
// If we have SO_REUSEPORT then create a new port for all receiver threads
}
if((P->d.opcode != Opcode::Notify && P->d.opcode != Opcode::Update) && P->couldBeCached()) {
- bool haveSomething = false;
- if (!P->d.rd || !DP->recurseFor(P))
- haveSomething=PC.get(P, &cached); // does the PacketCache recognize this question?
+ bool haveSomething=PC.get(P, &cached); // does the PacketCache recognize this question?
if (haveSomething) {
if(logDNSQueries)
L<<"packetcache HIT"<<endl;
{
++s_count;
d_doDNAME=::arg().mustDo("dname-processing");
- d_doRecursion= ::arg().mustDo("recursor");
d_logDNSDetails= ::arg().mustDo("log-dns-details");
d_doIPv6AdditionalProcessing = ::arg().mustDo("do-ipv6-additional-processing");
string fname= ::arg()["lua-prequery-script"];
return ret;
}
- bool shouldRecurse=false;
- ret=questionOrRecurse(p, &shouldRecurse);
- if(shouldRecurse) {
- DP->sendPacket(p);
- }
+ ret=doQuestion(p);
+
if(LPE) {
policyres = LPE->police(p, ret);
if(policyres == PolicyDecision::DROP) {
}
//! Called by the Distributor to ask a question. Returns 0 in case of an error
-DNSPacket *PacketHandler::questionOrRecurse(DNSPacket *p, bool *shouldRecurse)
+DNSPacket *PacketHandler::doQuestion(DNSPacket *p)
{
- *shouldRecurse=false;
DNSZoneRecord rr;
SOAData sd;
// L<<Logger::Warning<<"Query for '"<<p->qdomain<<"' "<<p->qtype.getName()<<" from "<<p->getRemote()<< " (tcp="<<p->d_tcp<<")"<<endl;
- r->d.ra = (p->d.rd && d_doRecursion && DP->recurseFor(p)); // make sure we set ra if rd was set, and we'll do it
-
if(p->qtype.getCode()==QType::IXFR) {
r->setRcode(RCode::NotImp);
return r;
if(!B.getAuth(p, &sd, target)) {
DLOG(L<<Logger::Error<<"We have no authority over zone '"<<target<<"'"<<endl);
- if(r->d.ra) {
- DLOG(L<<Logger::Error<<"Recursion is available for this remote, doing that"<<endl);
- *shouldRecurse=true;
- delete r;
- return 0;
- }
-
if(!retargetcount) {
r->setA(false); // drop AA if we never had a SOA in the first place
r->setRcode(RCode::Refused); // send REFUSED - but only on empty 'no idea'
throw NetworkError("Error reading DNS data from TCP client "+remote.toString()+": "+ae.what());
}
-static void proxyQuestion(shared_ptr<DNSPacket> packet, unsigned int idleTimeout)
-{
- int sock=socket(AF_INET, SOCK_STREAM, 0);
-
- setCloseOnExec(sock);
- if(sock < 0)
- throw NetworkError("Error making TCP connection socket to recursor: "+stringerror());
-
- setNonBlocking(sock);
- ServiceTuple st;
- st.port=53;
- parseService(::arg()["recursor"],st);
-
- try {
- ComboAddress recursor(st.host, st.port);
- connectWithTimeout(sock, (struct sockaddr*)&recursor, recursor.getSocklen());
- const string &buffer=packet->getString();
-
- uint16_t len=htons(buffer.length()), slen;
-
- writenWithTimeout(sock, &len, 2, idleTimeout);
- writenWithTimeout(sock, buffer.c_str(), buffer.length(), idleTimeout);
-
- readnWithTimeout(sock, &len, 2, idleTimeout);
- len=ntohs(len);
-
- char answer[len];
- readnWithTimeout(sock, answer, len, idleTimeout);
-
- slen=htons(len);
- writenWithTimeout(packet->getSocket(), &slen, 2, idleTimeout);
-
- writenWithTimeout(packet->getSocket(), answer, len, idleTimeout);
- }
- catch(NetworkError& ae) {
- close(sock);
- throw NetworkError("While proxying a question to recursor "+st.host+": " +ae.what());
- }
- close(sock);
- return;
-}
-
-
static void incTCPAnswerCount(const ComboAddress& remote)
{
S.inc("tcp-answers");
}
- if(!packet->d.rd && packet->couldBeCached() && PC.get(packet.get(), cached.get())) { // short circuit - does the PacketCache recognize this question?
+ if(packet->couldBeCached() && PC.get(packet.get(), cached.get())) { // short circuit - does the PacketCache recognize this question?
if(logDNSQueries)
L<<"packetcache HIT"<<endl;
cached->setRemote(&packet->d_remote);
L<<Logger::Error<<"TCP server is without backend connections, launching"<<endl;
s_P=new PacketHandler;
}
- bool shouldRecurse;
- reply=shared_ptr<DNSPacket>(s_P->questionOrRecurse(packet.get(), &shouldRecurse)); // we really need to ask the backend :-)
+ reply=shared_ptr<DNSPacket>(s_P->doQuestion(packet.get())); // we really need to ask the backend :-)
if(LPE) LPE->police(&(*packet), &(*reply), true);
-
- if(shouldRecurse) {
- proxyQuestion(packet, d_idleTimeout);
- continue;
- }
}
if(!reply) // unable to write an answer?