Skip to content

Instantly share code, notes, and snippets.

@Habbie
Last active March 17, 2021 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Habbie/5e8a2ea5187cfe02ec74be8590db538e to your computer and use it in GitHub Desktop.
Save Habbie/5e8a2ea5187cfe02ec74be8590db538e to your computer and use it in GitHub Desktop.
diff --git a/pdns/dnsparser.hh b/pdns/dnsparser.hh
index c6954e495..d728172c1 100644
--- a/pdns/dnsparser.hh
+++ b/pdns/dnsparser.hh
@@ -513,7 +513,9 @@ public:
uint32_t tmp;
memcpy(&tmp, (void*) p, sizeof(tmp));
tmp = ntohl(tmp);
+ cerr<<"decreaseAndSkip32BitInt tmp="<<tmp<<" decrease="<<decrease;
tmp-=decrease;
+ cerr<<" tmp="<<tmp<<endl;
tmp = htonl(tmp);
memcpy(d_packet + d_offset-4, (const char*)&tmp, sizeof(tmp));
}
diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc
index aadd7a2e7..76847d522 100644
--- a/pdns/pdns_recursor.cc
+++ b/pdns/pdns_recursor.cc
@@ -2125,12 +2125,18 @@ static void startDoResolve(void *p)
g_stats.variableResponses++;
}
if (!SyncRes::s_nopacketcache && !variableAnswer && !sr.wasVariable()) {
+ cerr<<"before insertResponsePacket, ";
+ cerr<<"minTTL="<<minTTL;
+ cerr<<endl;
+
+ if (pw.getHeader()->rcode == RCode::ServFail) minTTL = min(minTTL, SyncRes::s_packetcacheservfailttl);
+ minTTL = min(minTTL, SyncRes::s_packetcachettl);
+
t_packetCache->insertResponsePacket(dc->d_tag, dc->d_qhash, std::move(dc->d_query), dc->d_mdp.d_qname,
dc->d_mdp.d_qtype, dc->d_mdp.d_qclass,
string((const char*)&*packet.begin(), packet.size()),
g_now.tv_sec,
- pw.getHeader()->rcode == RCode::ServFail ? SyncRes::s_packetcacheservfailttl :
- min(minTTL,SyncRes::s_packetcachettl),
+ minTTL,
dq.validationState,
std::move(pbDataForCache), dc->d_tcp);
}
diff --git a/pdns/recpacketcache.cc b/pdns/recpacketcache.cc
index 048541982..c9cdb36c5 100644
--- a/pdns/recpacketcache.cc
+++ b/pdns/recpacketcache.cc
@@ -61,8 +61,10 @@ bool RecursorPacketCache::checkResponseMatches(std::pair<packetCache_t::index<Ha
continue;
}
+ cerr<<"now="<<now<<" iter->d_ttd="<<(iter->d_ttd)<<endl;
if (now < iter->d_ttd) { // it is right, it is fresh!
*age = static_cast<uint32_t>(now - iter->d_creation);
+ cerr<<"age="<<*age<<endl;
// we know ttl is > 0
uint32_t ttl = static_cast<uint32_t>(iter->d_ttd - now);
if (s_refresh_ttlperc > 0 && !iter->d_submitted) {
@@ -160,6 +162,8 @@ void RecursorPacketCache::insertResponsePacket(unsigned int tag, uint32_t qhash,
auto range = idx.equal_range(tie(tag, qhash, tcp));
auto iter = range.first;
+ cerr<<"insert got ttl="<<ttl<<endl;
+
for( ; iter != range.second ; ++iter) {
if (iter->d_type != qtype || iter->d_class != qclass || iter->d_name != qname ) {
continue;
@@ -176,6 +180,8 @@ void RecursorPacketCache::insertResponsePacket(unsigned int tag, uint32_t qhash,
iter->d_pbdata = std::move(*pbdata);
}
+ cerr<<"insert refresh now="<<now<<" ttl="<<ttl<<" ttd="<<iter->d_ttd<<endl;
+
break;
}
@@ -191,6 +197,7 @@ void RecursorPacketCache::insertResponsePacket(unsigned int tag, uint32_t qhash,
if (pbdata) {
e.d_pbdata = std::move(*pbdata);
}
+ cerr<<"insert insert now="<<now<<" ttl="<<ttl<<" ttd="<<e.d_ttd<<endl;
d_packetCache.insert(e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment