Skip to content

Commit fb30624

Browse files
committed
auth: undent opcode dispatch
1 parent 35056a1 commit fb30624

File tree

2 files changed

+31
-38
lines changed

2 files changed

+31
-38
lines changed

pdns/packethandler.cc

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ bool PacketHandler::s_SVCAutohints{false};
6060

6161
extern string g_programname;
6262

63+
[[nodiscard]] static std::unique_ptr<DNSPacket> tkeyHandler(const DNSPacket& p);
64+
6365
// See https://www.rfc-editor.org/rfc/rfc8078.txt and https://www.rfc-editor.org/errata/eid5049 for details
6466
const std::shared_ptr<CDNSKEYRecordContent> PacketHandler::s_deleteCDNSKEYContent = std::make_shared<CDNSKEYRecordContent>("0 3 0 AA==");
6567
const std::shared_ptr<CDSRecordContent> PacketHandler::s_deleteCDSContent = std::make_shared<CDSRecordContent>("0 0 0 00");
@@ -1407,9 +1409,7 @@ std::unique_ptr<DNSPacket> PacketHandler::doQuestion(DNSPacket& p)
14071409
}
14081410

14091411
if (p.qtype == QType::TKEY) {
1410-
auto reply = p.replyPacket();
1411-
this->tkeyHandler(p, reply);
1412-
return reply;
1412+
return tkeyHandler(p);
14131413
}
14141414

14151415
try {
@@ -1424,29 +1424,29 @@ std::unique_ptr<DNSPacket> PacketHandler::doQuestion(DNSPacket& p)
14241424
S.inc("servfail-packets");
14251425
return p.replyPacket(RCode::ServFail);
14261426
}
1427-
if(p.d.opcode) { // non-zero opcode (again thanks RA!)
1428-
if(p.d.opcode==Opcode::Update) {
1429-
S.inc("dnsupdate-queries");
1430-
int res = processUpdate(p);
1431-
if (res == RCode::Refused)
1432-
S.inc("dnsupdate-refused");
1433-
else if (res != RCode::ServFail)
1434-
S.inc("dnsupdate-answers");
1435-
return p.replyPacket(res);
1436-
}
1437-
else if(p.d.opcode==Opcode::Notify) {
1438-
S.inc("incoming-notifications");
1439-
return p.replyPacket(processNotify(p));
1440-
}
14411427

1428+
if (p.d.opcode == Opcode::Update) {
1429+
S.inc("dnsupdate-queries");
1430+
int res = processUpdate(p);
1431+
if (res == RCode::Refused)
1432+
S.inc("dnsupdate-refused");
1433+
else if (res != RCode::ServFail)
1434+
S.inc("dnsupdate-answers");
1435+
return p.replyPacket(res);
1436+
}
1437+
else if (p.d.opcode == Opcode::Notify) {
1438+
S.inc("incoming-notifications");
1439+
return p.replyPacket(processNotify(p));
1440+
}
1441+
else if (p.d.opcode != Opcode::Query) {
14421442
g_log<<Logger::Error<<"Received an unknown opcode "<<p.d.opcode<<" from "<<p.getRemoteString()<<" for "<<p.qdomain<<endl;
1443-
14441443
return p.replyPacket(RCode::NotImp);
14451444
}
14461445

1446+
// From here on, we are handling a *Query* packet.
14471447
// g_log<<Logger::Warning<<"Query for '"<<p.qdomain<<"' "<<p.qtype.toString()<<" from "<<p.getRemoteString()<< " (tcp="<<p.d_tcp<<")"<<endl;
14481448

1449-
if(p.qtype.getCode()==QType::IXFR) {
1449+
if (p.qtype == QType::IXFR) {
14501450
return p.replyPacket(RCode::Refused);
14511451
}
14521452

@@ -1812,7 +1812,9 @@ std::unique_ptr<DNSPacket> PacketHandler::doQuestion(DNSPacket& p)
18121812
}
18131813
}
18141814

1815-
void PacketHandler::tkeyHandler(const DNSPacket& p, std::unique_ptr<DNSPacket>& r) {
1815+
//<! process TKEY record, and adds TKEY record to (r)eply, or error code.
1816+
[[nodiscard]]
1817+
static std::unique_ptr<DNSPacket> tkeyHandler(const DNSPacket& p) {
18161818
#ifdef ENABLE_GSS_TSIG
18171819
if (g_doGssTSIG) {
18181820
auto [i,a,s] = GssContext::getCounts();
@@ -1829,8 +1831,7 @@ void PacketHandler::tkeyHandler(const DNSPacket& p, std::unique_ptr<DNSPacket>&
18291831

18301832
if (!p.getTKEYRecord(&tkey_in, &name)) {
18311833
g_log<<Logger::Error<<"TKEY request but no TKEY RR found"<<endl;
1832-
r->setRcode(RCode::FormErr);
1833-
return;
1834+
return p.replyPacket(RCode::FormErr);
18341835
}
18351836

18361837
auto inception = time(nullptr);
@@ -1883,11 +1884,7 @@ void PacketHandler::tkeyHandler(const DNSPacket& p, std::unique_ptr<DNSPacket>&
18831884
}
18841885
} else if (tkey_in.d_mode == 5) { // destroy context
18851886
if (p.d_havetsig == false) { // unauthenticated
1886-
if (p.d.opcode == Opcode::Update)
1887-
r->setRcode(RCode::Refused);
1888-
else
1889-
r->setRcode(RCode::NotAuth);
1890-
return;
1887+
return p.replyPacket(p.d.opcode == Opcode::Update ? RCode::Refused : RCode::NotAuth);
18911888
}
18921889
GssContext ctx(name);
18931890
if (ctx.valid()) {
@@ -1898,11 +1895,7 @@ void PacketHandler::tkeyHandler(const DNSPacket& p, std::unique_ptr<DNSPacket>&
18981895
}
18991896
} else {
19001897
if (p.d_havetsig == false && tkey_in.d_mode != 2) { // unauthenticated
1901-
if (p.d.opcode == Opcode::Update)
1902-
r->setRcode(RCode::Refused);
1903-
else
1904-
r->setRcode(RCode::NotAuth);
1905-
return;
1898+
return p.replyPacket(p.d.opcode == Opcode::Update ? RCode::Refused : RCode::NotAuth);
19061899
}
19071900
tkey_out->d_error = 19; // BADMODE
19081901
}
@@ -1918,7 +1911,9 @@ void PacketHandler::tkeyHandler(const DNSPacket& p, std::unique_ptr<DNSPacket>&
19181911
zrr.dr.d_class = QClass::ANY;
19191912
zrr.dr.setContent(std::move(tkey_out));
19201913
zrr.dr.d_place = DNSResourceRecord::ANSWER;
1921-
r->addRecord(std::move(zrr));
1914+
1915+
std::unique_ptr<DNSPacket> reply = p.replyPacket();
1916+
reply->addRecord(std::move(zrr));
19221917

19231918
#ifdef ENABLE_GSS_TSIG
19241919
if (sign)
@@ -1932,9 +1927,10 @@ void PacketHandler::tkeyHandler(const DNSPacket& p, std::unique_ptr<DNSPacket>&
19321927
trc.d_eRcode = 0;
19331928
trc.d_otherData = "";
19341929
// this should cause it to lookup name context
1935-
r->setTSIGDetails(trc, name, name.toStringNoDot(), "", false);
1930+
reply->setTSIGDetails(trc, name, name.toStringNoDot(), "", false);
19361931
}
19371932
#endif
19381933

1939-
r->commitD();
1934+
reply->commitD();
1935+
return reply;
19401936
}

pdns/packethandler.hh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ private:
105105
bool addDSforNS(DNSPacket& p, std::unique_ptr<DNSPacket>& r, const DNSName& dsname);
106106
void completeANYRecords(DNSPacket& p, std::unique_ptr<DNSPacket>& r, const DNSName &target);
107107

108-
void tkeyHandler(const DNSPacket& p, std::unique_ptr<DNSPacket>& r); //<! process TKEY record, and adds TKEY record to (r)eply, or error code.
109-
110108
static AtomicCounter s_count;
111109
static std::mutex s_rfc2136lock;
112110
bool d_logDNSDetails;
@@ -120,4 +118,3 @@ private:
120118
UeberBackend B; // every thread an own instance
121119
DNSSECKeeper d_dk; // B is shared with DNSSECKeeper
122120
};
123-

0 commit comments

Comments
 (0)