Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auth: refactor doQuestion [Experiment] #14600

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .not-formatted
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@
./pdns/test-ueberbackend_cc.cc
./pdns/test-zoneparser_tng_cc.cc
./pdns/threadname.cc
./pdns/tkey.cc
./pdns/trusted-notification-proxy.cc
./pdns/trusted-notification-proxy.hh
./pdns/tsig-tests.cc
Expand Down
1 change: 0 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,6 @@ common_sources += files(
src_dir / 'tcpreceiver.hh',
src_dir / 'threadname.cc',
src_dir / 'threadname.hh',
src_dir / 'tkey.cc',
src_dir / 'trusted-notification-proxy.cc',
src_dir / 'trusted-notification-proxy.hh',
src_dir / 'tsigutils.cc',
Expand Down
1 change: 0 additions & 1 deletion pdns/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ pdns_server_SOURCES = \
svc-records.cc svc-records.hh \
tcpreceiver.cc tcpreceiver.hh \
threadname.hh threadname.cc \
tkey.cc \
trusted-notification-proxy.hh trusted-notification-proxy.cc \
tsigutils.hh tsigutils.cc \
tsigverifier.cc tsigverifier.hh \
Expand Down
36 changes: 14 additions & 22 deletions pdns/distributor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ template<class Answer, class Question, class Backend>void MultiThreadDistributor
}
--d_queued;
auto questionData = std::move(*tempQD);
std::unique_ptr<Answer> a = nullptr;
std::unique_ptr<Answer> answer = nullptr;
if (queuetimeout && questionData->Q.d_dt.udiff() > queuetimeout * 1000) {
S.inc("timedout-packets");
continue;
Expand All @@ -213,15 +213,13 @@ retry:
allowRetry = false;
b = make_unique<Backend>();
}
a = b->question(questionData->Q);
answer = b->question(questionData->Q);
}
catch (const PDNSException &e) {
b.reset();
if (!allowRetry) {
g_log<<Logger::Error<<"Backend error: "<<e.reason<<endl;
a = questionData->Q.replyPacket();

a->setRcode(RCode::ServFail);
answer = questionData->Q.replyPacket(RCode::ServFail);
S.inc("servfail-packets");
S.ringAccount("servfail-queries", questionData->Q.qdomain, questionData->Q.qtype);
} else {
Expand All @@ -233,9 +231,7 @@ retry:
b.reset();
if (!allowRetry) {
g_log<<Logger::Error<<"Caught unknown exception in Distributor thread "<<std::this_thread::get_id()<<endl;
a = questionData->Q.replyPacket();

a->setRcode(RCode::ServFail);
answer = questionData->Q.replyPacket(RCode::ServFail);
S.inc("servfail-packets");
S.ringAccount("servfail-queries", questionData->Q.qdomain, questionData->Q.qtype);
} else {
Expand All @@ -244,10 +240,10 @@ retry:
}
}

questionData->callback(a, questionData->start);
questionData->callback(answer, questionData->start);
#ifdef ENABLE_GSS_TSIG
if (g_doGssTSIG && a != nullptr) {
questionData->Q.cleanupGSS(a->d.rcode);
if (g_doGssTSIG && answer != nullptr) {
questionData->Q.cleanupGSS(answer->d.rcode);
}
#endif
questionData.reset();
Expand All @@ -272,23 +268,21 @@ retry:
template<class Answer, class Question, class Backend>int SingleThreadDistributor<Answer,Question,Backend>::question(Question& q, callback_t callback)
{
int start = q.d_dt.udiff();
std::unique_ptr<Answer> a = nullptr;
std::unique_ptr<Answer> answer = nullptr;
bool allowRetry=true;
retry:
try {
if (!b) {
allowRetry=false;
b=make_unique<Backend>();
}
a=b->question(q); // a can be NULL!
answer = b->question(q); // answer can be NULL!
}
catch(const PDNSException &e) {
b.reset();
if (!allowRetry) {
g_log<<Logger::Error<<"Backend error: "<<e.reason<<endl;
a=q.replyPacket();

a->setRcode(RCode::ServFail);
answer = q.replyPacket(RCode::ServFail);
S.inc("servfail-packets");
S.ringAccount("servfail-queries", q.qdomain, q.qtype);
} else {
Expand All @@ -300,20 +294,18 @@ retry:
b.reset();
if (!allowRetry) {
g_log<<Logger::Error<<"Caught unknown exception in Distributor thread "<<std::this_thread::get_id()<<endl;
a=q.replyPacket();

a->setRcode(RCode::ServFail);
answer = q.replyPacket(RCode::ServFail);
S.inc("servfail-packets");
S.ringAccount("servfail-queries", q.qdomain, q.qtype);
} else {
g_log<<Logger::Warning<<"Caught unknown exception in Distributor thread "<<std::this_thread::get_id()<<" (retry once)"<<endl;
goto retry;
}
}
callback(a, start);
callback(answer, start);
#ifdef ENABLE_GSS_TSIG
if (g_doGssTSIG && a != nullptr) {
q.cleanupGSS(a->d.rcode);
if (g_doGssTSIG && answer != nullptr) {
q.cleanupGSS(answer->d.rcode);
}
#endif
return 0;
Expand Down
4 changes: 3 additions & 1 deletion pdns/dnspacket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ void DNSPacket::setQuestion(int op, const DNSName &qd, int newqtype)
}

/** convenience function for creating a reply packet from a question packet. */
std::unique_ptr<DNSPacket> DNSPacket::replyPacket() const
std::unique_ptr<DNSPacket> DNSPacket::replyPacket(int rcode, uint16_t extRCode) const
{
auto r=make_unique<DNSPacket>(false);
r->setSocket(d_socket);
Expand All @@ -434,6 +434,8 @@ std::unique_ptr<DNSPacket> DNSPacket::replyPacket() const
r->setRD(d.rd); // if you wanted to recurse, answer will say you wanted it
r->setID(d.id);
r->setOpcode(d.opcode);
r->setRcode(rcode);
r->setEDNSRcode(extRCode);

r->d_dt=d_dt;
r->d.qdcount=1;
Expand Down
2 changes: 1 addition & 1 deletion pdns/dnspacket.hh
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public:
vector<DNSZoneRecord*> getServiceRecords(); //!< Get a vector with all Service-style (SVCB) records
void setCompress(bool compress);

std::unique_ptr<DNSPacket> replyPacket() const; //!< convenience function that creates a virgin answer packet to this question
std::unique_ptr<DNSPacket> replyPacket(int rcode = RCode::NoError, uint16_t extRCode = 0) const; //!< convenience function that creates a virgin answer packet to this question

void commitD(); //!< copies 'd' into the stringbuffer
unsigned int getMaxReplyLen(); //!< retrieve the maximum length of the packet we should send in response
Expand Down
Loading
Loading