summaryrefslogtreecommitdiff
path: root/src/coremods/core_dns.cpp
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2015-05-13 00:56:35 +0200
committerAttila Molnar <attilamolnar@hush.com>2015-05-13 00:56:35 +0200
commitcc007f8a3baa92ac46f17457a9a321e9b6530ded (patch)
treeb4b3b295aa29cf3f5d9a9c19cf661b3abe241ae9 /src/coremods/core_dns.cpp
parent17787004f196f92ea8e5e47ef5852a906491ee1d (diff)
core_dns Set the TTL of the cache entry to the lowest TTL in a set of ResourceRecords
Diffstat (limited to 'src/coremods/core_dns.cpp')
-rw-r--r--src/coremods/core_dns.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/coremods/core_dns.cpp b/src/coremods/core_dns.cpp
index 6652841d0..e1494b7f3 100644
--- a/src/coremods/core_dns.cpp
+++ b/src/coremods/core_dns.cpp
@@ -374,7 +374,18 @@ class MyManager : public Manager, public Timer, public EventHandler
*/
void AddCache(Query& r)
{
- const ResourceRecord& rr = r.answers[0];
+ // Determine the lowest TTL value and use that as the TTL of the cache entry
+ unsigned int cachettl = UINT_MAX;
+ for (std::vector<ResourceRecord>::const_iterator i = r.answers.begin(); i != r.answers.end(); ++i)
+ {
+ const ResourceRecord& rr = *i;
+ if (rr.ttl < cachettl)
+ cachettl = rr.ttl;
+ }
+
+ ResourceRecord& rr = r.answers.front();
+ // Set TTL to what we've determined to be the lowest
+ rr.ttl = cachettl;
ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "cache: added cache for " + rr.name + " -> " + rr.rdata + " ttl: " + ConvToStr(rr.ttl));
this->cache[r.question] = r;
}