Skip to content

Commit f12fcf7

Browse files
committed
Add and hook tkeyHandler
1 parent cd3f21c commit f12fcf7

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

pdns/packethandler.cc

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,12 @@ DNSPacket *PacketHandler::questionOrRecurse(DNSPacket *p, bool *shouldRecurse)
10141014
}
10151015

10161016
r=p->replyPacket(); // generate an empty reply packet, possibly with TSIG details inside
1017-
1017+
1018+
if (p->qtype == QType::TKEY) {
1019+
this->tkeyHandler(p, r);
1020+
return r;
1021+
}
1022+
10181023
try {
10191024

10201025
// XXX FIXME do this in DNSPacket::parse ?
@@ -1346,3 +1351,62 @@ DNSPacket *PacketHandler::questionOrRecurse(DNSPacket *p, bool *shouldRecurse)
13461351

13471352
}
13481353

1354+
void PacketHandler::tkeyHandler(DNSPacket *p, DNSPacket *r) {
1355+
TKEYRecordContent tkey_in;
1356+
boost::shared_ptr<TKEYRecordContent> tkey_out(new TKEYRecordContent());
1357+
string label, lcLabel;
1358+
1359+
if (!p->getTKEYRecord(&tkey_in, &label)) {
1360+
L<<Logger::Error<<"TKEY request but no TKEY RR found"<<endl;
1361+
r->setRcode(RCode::FormErr);
1362+
return;
1363+
}
1364+
1365+
// retain original label for response
1366+
lcLabel = toLowerCanonic(label);
1367+
1368+
tkey_out->d_error = 0;
1369+
tkey_out->d_mode = tkey_in.d_mode;
1370+
tkey_out->d_algo = tkey_in.d_algo;
1371+
tkey_out->d_inception = time((time_t*)NULL);
1372+
tkey_out->d_expiration = tkey_out->d_inception+15;
1373+
1374+
if (tkey_in.d_mode == 3) {
1375+
tkey_out->d_error = 19; // BADMODE
1376+
} else if (tkey_in.d_mode == 5) {
1377+
if (p->d_havetsig == false) { // unauthenticated
1378+
if (p->d.opcode == Opcode::Update)
1379+
r->setRcode(RCode::Refused);
1380+
else
1381+
r->setRcode(RCode::NotAuth);
1382+
return;
1383+
}
1384+
tkey_out->d_error = 20; // BADNAME (because we have no support for anything here)
1385+
} else {
1386+
if (p->d_havetsig == false && tkey_in.d_mode != 2) { // unauthenticated
1387+
if (p->d.opcode == Opcode::Update)
1388+
r->setRcode(RCode::Refused);
1389+
else
1390+
r->setRcode(RCode::NotAuth);
1391+
return;
1392+
}
1393+
tkey_out->d_error = 19; // BADMODE
1394+
}
1395+
1396+
tkey_out->d_keysize = tkey_out->d_key.size();
1397+
tkey_out->d_othersize = tkey_out->d_other.size();
1398+
1399+
DNSRecord rec;
1400+
rec.d_label = label;
1401+
rec.d_ttl = 0;
1402+
rec.d_type = QType::TKEY;
1403+
rec.d_class = QClass::ANY;
1404+
rec.d_content = tkey_out;
1405+
1406+
DNSResourceRecord rr(rec);
1407+
rr.qclass = QClass::ANY;
1408+
rr.qtype = QType::TKEY;
1409+
rr.d_place = DNSResourceRecord::ANSWER;
1410+
r->addRecord(rr);
1411+
r->commitD();
1412+
}

pdns/packethandler.hh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ private:
101101
bool tryWildcard(DNSPacket *p, DNSPacket*r, SOAData& sd, string &target, string &wildcard, bool& retargeted, bool& nodata);
102102
bool addDSforNS(DNSPacket* p, DNSPacket* r, SOAData& sd, const string& dsname);
103103
void completeANYRecords(DNSPacket *p, DNSPacket*r, SOAData& sd, const string &target);
104-
104+
105+
void tkeyHandler(DNSPacket *p, DNSPacket *r);
106+
105107
static AtomicCounter s_count;
106108
static pthread_mutex_t s_rfc2136lock;
107109
bool d_doRecursion;

0 commit comments

Comments
 (0)