fbf736
From f6eee0760ca32e8ce090d73135ffbeb483f2bc5a Mon Sep 17 00:00:00 2001
fbf736
From: Stephen Baynes <sbaynes@mail.com>
fbf736
Date: Thu, 1 Dec 2016 12:20:39 +1300
fbf736
Subject: [PATCH] Bug 4007: Hang on DNS query with dead-end CNAME
fbf736
fbf736
DNS lookup recursion no longer occurs. ipcacheParse() return values are no
fbf736
longer useful.
fbf736
fbf736
Also, cleanup the debugging output.
fbf736
---
fbf736
 src/ipcache.cc | 40 ++++++++++++++++------------------------
fbf736
 1 file changed, 16 insertions(+), 24 deletions(-)
fbf736
fbf736
diff --git a/src/ipcache.cc b/src/ipcache.cc
fbf736
index 0eaab11241..d2a883e29b 100644
fbf736
--- a/src/ipcache.cc
fbf736
+++ b/src/ipcache.cc
fbf736
@@ -123,7 +123,6 @@ static void stat_ipcache_get(StoreEntry *);
fbf736
 static FREE ipcacheFreeEntry;
fbf736
 static IDNSCB ipcacheHandleReply;
fbf736
 static int ipcacheExpiredEntry(ipcache_entry *);
fbf736
-static int ipcacheParse(ipcache_entry *, const rfc1035_rr *, int, const char *error);
fbf736
 static ipcache_entry *ipcache_get(const char *);
fbf736
 static void ipcacheLockEntry(ipcache_entry *);
fbf736
 static void ipcacheStatPrint(ipcache_entry *, StoreEntry *);
fbf736
@@ -328,8 +327,7 @@ ipcacheCallback(ipcache_entry *i, int wait)
fbf736
     ipcacheUnlockEntry(i);
fbf736
 }
fbf736
 
fbf736
-/// \ingroup IPCacheAPI
fbf736
-static int
fbf736
+static void
fbf736
 ipcacheParse(ipcache_entry *i, const rfc1035_rr * answers, int nr, const char *error_message)
fbf736
 {
fbf736
     int k;
fbf736
@@ -350,25 +348,25 @@ ipcacheParse(ipcache_entry *i, const rfc1035_rr * answers, int nr, const char *e
fbf736
     i->addrs.count = 0;
fbf736
 
fbf736
     if (nr < 0) {
fbf736
-        debugs(14, 3, "ipcacheParse: Lookup failed '" << error_message << "' for '" << (const char *)i->hash.key << "'");
fbf736
+        debugs(14, 3, "Lookup failed '" << error_message << "' for '" << (const char *)i->hash.key << "'");
fbf736
         i->error_message = xstrdup(error_message);
fbf736
-        return -1;
fbf736
+        return;
fbf736
     }
fbf736
 
fbf736
     if (nr == 0) {
fbf736
-        debugs(14, 3, "ipcacheParse: No DNS records in response to '" << name << "'");
fbf736
+        debugs(14, 3, "No DNS records in response to '" << name << "'");
fbf736
         i->error_message = xstrdup("No DNS records");
fbf736
-        return -1;
fbf736
+        return;
fbf736
     }
fbf736
 
fbf736
-    debugs(14, 3, "ipcacheParse: " << nr << " answers for '" << name << "'");
fbf736
+    debugs(14, 3, nr << " answers for '" << name << "'");
fbf736
     assert(answers);
fbf736
 
fbf736
     for (k = 0; k < nr; ++k) {
fbf736
 
fbf736
         if (Ip::EnableIpv6 && answers[k].type == RFC1035_TYPE_AAAA) {
fbf736
             if (answers[k].rdlength != sizeof(struct in6_addr)) {
fbf736
-                debugs(14, DBG_IMPORTANT, "ipcacheParse: Invalid IPv6 address in response to '" << name << "'");
fbf736
+                debugs(14, DBG_IMPORTANT, MYNAME << "Invalid IPv6 address in response to '" << name << "'");
fbf736
                 continue;
fbf736
             }
fbf736
             ++na;
fbf736
@@ -378,7 +376,7 @@ ipcacheParse(ipcache_entry *i, const rfc1035_rr * answers, int nr, const char *e
fbf736
 
fbf736
         if (answers[k].type == RFC1035_TYPE_A) {
fbf736
             if (answers[k].rdlength != sizeof(struct in_addr)) {
fbf736
-                debugs(14, DBG_IMPORTANT, "ipcacheParse: Invalid IPv4 address in response to '" << name << "'");
fbf736
+                debugs(14, DBG_IMPORTANT, MYNAME << "Invalid IPv4 address in response to '" << name << "'");
fbf736
                 continue;
fbf736
             }
fbf736
             ++na;
fbf736
@@ -394,14 +392,14 @@ ipcacheParse(ipcache_entry *i, const rfc1035_rr * answers, int nr, const char *e
fbf736
         }
fbf736
 
fbf736
         // otherwise its an unknown RR. debug at level 9 since we usually want to ignore these and they are common.
fbf736
-        debugs(14, 9, HERE << "Unknown RR type received: type=" << answers[k].type << " starting at " << &(answers[k]) );
fbf736
+        debugs(14, 9, "Unknown RR type received: type=" << answers[k].type << " starting at " << &(answers[k]) );
fbf736
     }
fbf736
     if (na == 0) {
fbf736
-        debugs(14, DBG_IMPORTANT, "ipcacheParse: No Address records in response to '" << name << "'");
fbf736
+        debugs(14, DBG_IMPORTANT, MYNAME << "No Address records in response to '" << name << "'");
fbf736
         i->error_message = xstrdup("No Address records");
fbf736
         if (cname_found)
fbf736
             ++IpcacheStats.cname_only;
fbf736
-        return 0;
fbf736
+        return;
fbf736
     }
fbf736
 
fbf736
     i->addrs.in_addrs = static_cast<Ip::Address *>(xcalloc(na, sizeof(Ip::Address)));
fbf736
@@ -419,7 +417,7 @@ ipcacheParse(ipcache_entry *i, const rfc1035_rr * answers, int nr, const char *e
fbf736
             memcpy(&temp, answers[k].rdata, sizeof(struct in_addr));
fbf736
             i->addrs.in_addrs[j] = temp;
fbf736
 
fbf736
-            debugs(14, 3, "ipcacheParse: " << name << " #" << j << " " << i->addrs.in_addrs[j]);
fbf736
+            debugs(14, 3, name << " #" << j << " " << i->addrs.in_addrs[j]);
fbf736
             ++j;
fbf736
 
fbf736
         } else if (Ip::EnableIpv6 && answers[k].type == RFC1035_TYPE_AAAA) {
fbf736
@@ -430,7 +428,7 @@ ipcacheParse(ipcache_entry *i, const rfc1035_rr * answers, int nr, const char *e
fbf736
             memcpy(&temp, answers[k].rdata, sizeof(struct in6_addr));
fbf736
             i->addrs.in_addrs[j] = temp;
fbf736
 
fbf736
-            debugs(14, 3, "ipcacheParse: " << name << " #" << j << " " << i->addrs.in_addrs[j] );
fbf736
+            debugs(14, 3, name << " #" << j << " " << i->addrs.in_addrs[j] );
fbf736
             ++j;
fbf736
         }
fbf736
         if (ttl == 0 || (int) answers[k].ttl < ttl)
fbf736
@@ -453,8 +451,6 @@ ipcacheParse(ipcache_entry *i, const rfc1035_rr * answers, int nr, const char *e
fbf736
     i->expires = squid_curtime + ttl;
fbf736
 
fbf736
     i->flags.negcached = false;
fbf736
-
fbf736
-    return i->addrs.count;
fbf736
 }
fbf736
 
fbf736
 /// \ingroup IPCacheInternal
fbf736
@@ -467,13 +463,9 @@ ipcacheHandleReply(void *data, const rfc1035_rr * answers, int na, const char *e
fbf736
     const int age = i->age();
fbf736
     statCounter.dns.svcTime.count(age);
fbf736
 
fbf736
-    int done = ipcacheParse(i, answers, na, error_message);
fbf736
-
fbf736
-    /* If we have not produced either IPs or Error immediately, wait for recursion to finish. */
fbf736
-    if (done != 0 || error_message != NULL) {
fbf736
-        ipcacheAddEntry(i);
fbf736
-        ipcacheCallback(i, age);
fbf736
-    }
fbf736
+    ipcacheParse(i, answers, na, error_message);
fbf736
+    ipcacheAddEntry(i);
fbf736
+    ipcacheCallback(i, age);
fbf736
 }
fbf736
 
fbf736
 /**