dnsproxy: Have a minimum cache TTL
authorArjan van de Ven <arjan@linux.intel.com>
Tue, 10 Jan 2012 00:08:42 +0000 (16:08 -0800)
committerDaniel Wagner <daniel.wagner@bmw-carit.de>
Tue, 10 Jan 2012 12:43:57 +0000 (13:43 +0100)
some DNS servers return an extremely short TTL causing all kinds of fun.
This patch ensures that we just enforce a minimum TTL of 30 seconds.

src/dnsproxy.c

index c373ae1..a30f4c4 100644 (file)
@@ -160,6 +160,10 @@ struct domain_rr {
  * when setting the cache entry life time. The value is in seconds.
  */
 #define MAX_CACHE_TTL (60 * 30)
+/*
+ * Also limit the other end, cache at least for 30 seconds.
+ */
+#define MIN_CACHE_TTL (30)
 
 /*
  * We limit the cache size to some sane value so that cached data does
@@ -1136,6 +1140,9 @@ static int cache_update(struct server_data *srv, unsigned char *msg,
                new_entry = FALSE;
        }
 
+       if (ttl < MIN_CACHE_TTL)
+               ttl = MIN_CACHE_TTL;
+
        data->inserted = current_time;
        data->type = type;
        data->answers = answers;