]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
core_dns Set the TTL of the cache entry to the lowest TTL in a set of ResourceRecords
authorAttila Molnar <attilamolnar@hush.com>
Tue, 12 May 2015 22:56:35 +0000 (00:56 +0200)
committerAttila Molnar <attilamolnar@hush.com>
Tue, 12 May 2015 22:56:35 +0000 (00:56 +0200)
src/coremods/core_dns.cpp

index 6652841d02a9a07e0b0d4884a7037f7249d5ed6e..e1494b7f314a39fdb0f3a72cc8b1d7a7b6798f8f 100644 (file)
@@ -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;
        }