--------------------- PatchSet 4767 Date: 2007/06/21 12:29:39 Author: amosjeffries Branch: squid3-ipv6 Tag: (none) Log: Fix logic bug which caused DNS failover to always lookup A records. Members: lib/IPAddress.cc:1.1.2.47->1.1.2.48 src/PeerDigest.h:1.1.12.4->1.1.12.5 src/dns_internal.cc:1.15.6.24->1.15.6.25 Index: squid3/lib/IPAddress.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/lib/Attic/IPAddress.cc,v retrieving revision 1.1.2.47 retrieving revision 1.1.2.48 diff -u -r1.1.2.47 -r1.1.2.48 --- squid3/lib/IPAddress.cc 10 Jun 2007 10:53:27 -0000 1.1.2.47 +++ squid3/lib/IPAddress.cc 21 Jun 2007 12:29:39 -0000 1.1.2.48 @@ -1,6 +1,6 @@ /* - * $Id: IPAddress.cc,v 1.1.2.47 2007/06/10 10:53:27 amosjeffries Exp $ + * $Id: IPAddress.cc,v 1.1.2.48 2007/06/21 12:29:39 amosjeffries Exp $ * * DEBUG: section 14 IP Storage and Handling * AUTHOR: Amos Jeffries @@ -899,7 +899,10 @@ #endif } else { - assert(false); + debugs(14,0,"WARNING: Corrupt IP Address details found!"); + fprintf(stderr,"WARNING: Corrupt IP Address details found!"); + memcpy(buf,"dead:beef::",12); +// assert(false); } return buf; Index: squid3/src/PeerDigest.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/PeerDigest.h,v retrieving revision 1.1.12.4 retrieving revision 1.1.12.5 diff -u -r1.1.12.4 -r1.1.12.5 --- squid3/src/PeerDigest.h 30 May 2007 05:06:07 -0000 1.1.12.4 +++ squid3/src/PeerDigest.h 21 Jun 2007 12:29:39 -0000 1.1.12.5 @@ -1,6 +1,6 @@ /* - * $Id: PeerDigest.h,v 1.1.12.4 2007/05/30 05:06:07 amosjeffries Exp $ + * $Id: PeerDigest.h,v 1.1.12.5 2007/06/21 12:29:39 amosjeffries Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -95,7 +95,7 @@ void *operator new (size_t); void operator delete(void *); - struct _peer *peer; /* pointer back to peer structure, argh */ + struct _peer *peer; /* pointer back to peer structure, argh */ CacheDigest *cd; /* actual digest structure */ String host; /* copy of peer->host */ const char *req_result; /* text status of the last request */ Index: squid3/src/dns_internal.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/dns_internal.cc,v retrieving revision 1.15.6.24 retrieving revision 1.15.6.25 diff -u -r1.15.6.24 -r1.15.6.25 --- squid3/src/dns_internal.cc 10 Jun 2007 11:01:24 -0000 1.15.6.24 +++ squid3/src/dns_internal.cc 21 Jun 2007 12:29:39 -0000 1.15.6.25 @@ -1,6 +1,6 @@ /* - * $Id: dns_internal.cc,v 1.15.6.24 2007/06/10 11:01:24 amosjeffries Exp $ + * $Id: dns_internal.cc,v 1.15.6.25 2007/06/21 12:29:39 amosjeffries Exp $ * * DEBUG: section 78 DNS lookups; interacts with lib/rfc1035.c * AUTHOR: Duane Wessels @@ -896,7 +896,7 @@ return; } - debugs(78, 3, "idnsGrokReply: ID 0x" << std::hex << message->id << ", " << std::dec << n << "answers"); + debugs(78, 3, "idnsGrokReply: ID 0x" << std::hex << message->id << ", " << std::dec << n << " answers"); q = idnsFindQuery(message->id); @@ -993,19 +993,33 @@ return; } } + #if USE_IPV6 - else if(q->need_A) { - /* have tried and failed to find AAAA. Now try for A. */ - debugs(78, 3, "idnsGrokReply: AAAA Query failed. Trying A now instead."); - rfc1035MessageDestroy(message); - q->start_t = current_time; - q->id = idnsQueryID(); - rfc1035SetQueryID(q->buf, q->id); - q->sz = rfc3596BuildAQuery(q->name, q->buf, sizeof(q->buf), q->id, &q->query); - q->need_A = false; - idnsCacheQuery(q); - idnsSendQuery(q); - return; + if(n <= 0 && q->need_A) + { + /* ERROR or NO AAA exist. Failover to A records. */ + if(n == 0) + debugs(78, 3, "idnsGrokReply: " << q->name << " has no AAAA records. Looking up A record instead."); + else + debugs(78, 3, "idnsGrokReply: " << q->name << " AAAA query failed. Trying A now instead."); + + rfc1035MessageDestroy(message); + + /* BUG 1968: Unlink previously linked q->hash */ + /* previously susceptable to infinite loop testing dead hash entries */ + if (q->hash.key) { + hash_remove_link(idns_lookup_hash, &q->hash); + q->hash.key = NULL; + } + + q->start_t = current_time; + q->id = idnsQueryID(); + rfc1035SetQueryID(q->buf, q->id); + q->sz = rfc3596BuildAQuery(q->name, q->buf, sizeof(q->buf), q->id, &q->query); + q->need_A = false; + idnsCacheQuery(q); + idnsSendQuery(q); + return; } #endif