diff -u -r -N squid-3.1.20/ChangeLog squid-3.1.21/ChangeLog
--- squid-3.1.20/ChangeLog	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/ChangeLog	2012-09-24 02:01:02.000000000 +1200
@@ -1,4 +1,22 @@
-Changes to squid-3.1.20 (08 Jun 2011):
+Changes to squid-3.1.21 (23 Sep 2012):
+
+	- Bug 3622: peerClearRRStart scheduling multiple events
+	- Bug 3615: configure check for default max number of FDs is broken
+	- Bug 3607: --enable-auth documented default action incorrect
+	- Bug 3593: socket failure: Address family not supported by protocol
+	- Bug 3584: Detection of setresuid() is broken
+	- Bug 3568: Consolidate external_acl_type config dumping and add missing %%
+	- Bug 3564: eCAP not supporting CoAP URI schemes
+	- Bug 3484: Docs: sslproxy_cert_error example flawed
+	- Bug 3462: Delay Pools and ICAP
+	- Bug 3133: better fix: Memory leak handling requests for sites that don't exist
+	- Bug 2976: ERR_INVALID_URL for transparently captured requests when reconfiguring
+	- Silence IOS 15.1 unknown capabilities messages.
+	- Account for Store disk client quota when bandwidth-limiting the server.
+	- ... and several documentation fixes
+	- ... and several compile fixes
+
+Changes to squid-3.1.20 (08 Jun 2012):
 
 	- Regression Bug 3545: FreeBSD dnsserver segfaults
 	- Regression Bug 3504: clientside_tos fails to mark traffic
@@ -18,7 +36,7 @@
 	- Support CoAP over HTTP (coap:// and coaps:// URLs)
 	- Support for 3.2 error template codes
 
-Changes to squid-3.1.19 (06 Feb 2011):
+Changes to squid-3.1.19 (06 Feb 2012):
 
 	- Regression Bug 3441: part 2: Prevent further cache size corruption of swap.state
 	- Bug 3473: erase last uses of obsolete auth_user_hash_pointer
diff -u -r -N squid-3.1.20/configure squid-3.1.21/configure
--- squid-3.1.20/configure	2012-06-08 23:25:18.000000000 +1200
+++ squid-3.1.21/configure	2012-09-24 02:02:46.000000000 +1200
@@ -1,7 +1,7 @@
 #! /bin/sh
 # From configure.ac Revision.
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.68 for Squid Web Proxy 3.1.20.
+# Generated by GNU Autoconf 2.68 for Squid Web Proxy 3.1.21.
 #
 # Report bugs to <http://www.squid-cache.org/bugs/>.
 #
@@ -575,8 +575,8 @@
 # Identity of this package.
 PACKAGE_NAME='Squid Web Proxy'
 PACKAGE_TARNAME='squid'
-PACKAGE_VERSION='3.1.20'
-PACKAGE_STRING='Squid Web Proxy 3.1.20'
+PACKAGE_VERSION='3.1.21'
+PACKAGE_STRING='Squid Web Proxy 3.1.21'
 PACKAGE_BUGREPORT='http://www.squid-cache.org/bugs/'
 PACKAGE_URL=''
 
@@ -1540,7 +1540,7 @@
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures Squid Web Proxy 3.1.20 to adapt to many kinds of systems.
+\`configure' configures Squid Web Proxy 3.1.21 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1610,7 +1610,7 @@
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of Squid Web Proxy 3.1.20:";;
+     short | recursive ) echo "Configuration of Squid Web Proxy 3.1.21:";;
    esac
   cat <<\_ACEOF
 
@@ -1741,11 +1741,11 @@
                           hosts_file directive in squid.conf for details
   --enable-auth="list of auth scheme modules"
                           Build support for the list of authentication
-                          schemes. The default is to build support for the
-                          Basic scheme. See src/auth for a list of available
-                          modules, or Programmers Guide section authentication
-                          schemes for details on how to build your custom auth
-                          scheme module
+                          schemes. The default is to auto-detect build support
+                          for all schemes. See src/auth for a list of
+                          available modules, or Programmers Guide section
+                          authentication schemes for details on how to build
+                          your custom auth scheme module
   --enable-basic-auth-helpers="list of helpers"
                           This option selects which basic scheme proxy_auth
                           helpers to build and install as part of the normal
@@ -1941,7 +1941,7 @@
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-Squid Web Proxy configure 3.1.20
+Squid Web Proxy configure 3.1.21
 generated by GNU Autoconf 2.68
 
 Copyright (C) 2010 Free Software Foundation, Inc.
@@ -2952,7 +2952,7 @@
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by Squid Web Proxy $as_me 3.1.20, which was
+It was created by Squid Web Proxy $as_me 3.1.21, which was
 generated by GNU Autoconf 2.68.  Invocation command line was
 
   $ $0 $@
@@ -3771,7 +3771,7 @@
 
 # Define the identity of the package.
  PACKAGE='squid'
- VERSION='3.1.20'
+ VERSION='3.1.21'
 
 
 cat >>confdefs.h <<_ACEOF
@@ -25902,7 +25902,6 @@
 	seteuid \
 	setgroups \
 	setpgrp \
-	setrlimit \
 	setsid \
 	sigaction \
 	snprintf \
@@ -26212,6 +26211,8 @@
 /* end confdefs.h.  */
 
 #include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
   int main(int argc, char **argv) {
     if(setresuid(-1,-1,-1)) {
       perror("setresuid:");
@@ -26644,6 +26645,17 @@
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking Maximum number of filedescriptors we can open" >&5
 $as_echo_n "checking Maximum number of filedescriptors we can open... " >&6; }
+for ac_func in setrlimit
+do :
+  ac_fn_cxx_check_func "$LINENO" "setrlimit" "ac_cv_func_setrlimit"
+if test "x$ac_cv_func_setrlimit" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_SETRLIMIT 1
+_ACEOF
+
+fi
+done
+
 TLDFLAGS="$LDFLAGS"
 if test -n "$squid_filedescriptors_num" ; then
   SQUID_MAXFD=$squid_filedescriptors_num
@@ -28231,7 +28243,7 @@
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by Squid Web Proxy $as_me 3.1.20, which was
+This file was extended by Squid Web Proxy $as_me 3.1.21, which was
 generated by GNU Autoconf 2.68.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -28297,7 +28309,7 @@
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_version="\\
-Squid Web Proxy config.status 3.1.20
+Squid Web Proxy config.status 3.1.21
 configured by $0, generated by GNU Autoconf 2.68,
   with options \\"\$ac_cs_config\\"
 
diff -u -r -N squid-3.1.20/configure.ac squid-3.1.21/configure.ac
--- squid-3.1.20/configure.ac	2012-06-08 23:25:17.000000000 +1200
+++ squid-3.1.21/configure.ac	2012-09-24 02:02:46.000000000 +1200
@@ -2,7 +2,7 @@
 dnl
 dnl  $Id$
 dnl
-AC_INIT([Squid Web Proxy],[3.1.20],[http://www.squid-cache.org/bugs/],[squid])
+AC_INIT([Squid Web Proxy],[3.1.21],[http://www.squid-cache.org/bugs/],[squid])
 AC_PREREQ(2.61)
 AC_CONFIG_HEADERS([include/autoconf.h])
 AC_CONFIG_AUX_DIR(cfgaux)
@@ -1726,7 +1726,7 @@
 dnl Select auth schemes modules to build
 AC_ARG_ENABLE(auth,
   AS_HELP_STRING([--enable-auth="list of auth scheme modules"],[Build support for the list of authentication schemes.
-                  The default is to build support for the Basic scheme.
+                  The default is to auto-detect build support for all schemes.
                   See src/auth for a list of available modules, or
                   Programmers Guide section authentication schemes
                   for details on how to build your custom auth scheme
@@ -3094,7 +3094,6 @@
 	seteuid \
 	setgroups \
 	setpgrp \
-	setrlimit \
 	setsid \
 	sigaction \
 	snprintf \
@@ -3199,6 +3198,8 @@
 AC_CACHE_CHECK(if setresuid is implemented, ac_cv_func_setresuid,
   AC_RUN_IFELSE([AC_LANG_SOURCE([[
 #include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
   int main(int argc, char **argv) {
     if(setresuid(-1,-1,-1)) {
       perror("setresuid:");
@@ -3484,6 +3485,7 @@
 
 dnl Not cached since people are likely to tune this
 AC_MSG_CHECKING(Maximum number of filedescriptors we can open)
+AC_CHECK_FUNCS(setrlimit)
 dnl damn! FreeBSD's pthreads breaks dup2().
 TLDFLAGS="$LDFLAGS"
 if test -n "$squid_filedescriptors_num" ; then
diff -u -r -N squid-3.1.20/CONTRIBUTORS squid-3.1.21/CONTRIBUTORS
--- squid-3.1.20/CONTRIBUTORS	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/CONTRIBUTORS	2012-09-24 02:01:02.000000000 +1200
@@ -9,6 +9,7 @@
     Alexey Veselovsky <alexey.veselovsky@eykontech.com>
     Alin Nastac <mrness@gentoo.org>
     Alter <alter@alter.org.ua>
+    Amos Jeffries <amosjeffries@squid-cache.org>
     Amos Jeffries <squid3@treenet.co.nz>
     Andreas Lamprecht <Andreas.Lamprecht@siemens.at>
     Andres Kroonmaa <andre@ml.ee>
@@ -75,6 +76,7 @@
     Guido Serassio <serassio@squid-cache.org>
     Hasso Tepper <hasso@estpak.ee>
     Henrik Nordstrom <henrik@henriknordstrom.net>
+    Henrik Nordstrom <hno@squid-cache.org>
     Hide Nagaoka <hide@cc.meisei-u.ac.jp>
     Ian Castle <ian.castle@coldcomfortfarm.net>
     Ian Turner <vectro@pipeline.com>
@@ -99,6 +101,7 @@
     Jonathan Larmour <JLarmour@origin-at.co.uk>
     Joshua Root <josh+squid@root.id.au>
     Kieran Whitbread <k.j.whitbread@qmul.ac.uk>
+    Kinkie <kinkie@squid-cache.org>
     Klaubert Herr <klaubert@gmail.com>
     Klaus Singvogel <kssingvo@suse.de>
     Kolics Bertold <bertold@tohotom.vein.hu>
@@ -188,5 +191,7 @@
     Wesha <wesha@iname.com>
     Wojtek Sylwestrzak <W.Sylwestrzak@icm.edu.pl>
     Wolfgang Nothdurft <wolfgang@linogate.de>
+    benno@jeamland.net
     fancyrabbit <fancyrabbit@gmail.com>
+    rousskov
     vollkommen <vollkommen@gmx.net>
diff -u -r -N squid-3.1.20/include/version.h squid-3.1.21/include/version.h
--- squid-3.1.20/include/version.h	2012-06-08 23:25:18.000000000 +1200
+++ squid-3.1.21/include/version.h	2012-09-24 02:02:46.000000000 +1200
@@ -9,7 +9,7 @@
  */
 
 #ifndef SQUID_RELEASE_TIME
-#define SQUID_RELEASE_TIME 1339154416
+#define SQUID_RELEASE_TIME 1348408851
 #endif
 
 #ifndef APP_SHORTNAME
diff -u -r -N squid-3.1.20/RELEASENOTES.html squid-3.1.21/RELEASENOTES.html
--- squid-3.1.20/RELEASENOTES.html	2012-06-09 00:40:45.000000000 +1200
+++ squid-3.1.21/RELEASENOTES.html	2012-09-24 02:25:29.000000000 +1200
@@ -2,10 +2,10 @@
 <HTML>
 <HEAD>
  <META NAME="GENERATOR" CONTENT="LinuxDoc-Tools 0.9.66">
- <TITLE>Squid 3.1.20 release notes</TITLE>
+ <TITLE>Squid 3.1.21 release notes</TITLE>
 </HEAD>
 <BODY>
-<H1>Squid 3.1.20 release notes</H1>
+<H1>Squid 3.1.21 release notes</H1>
 
 <H2>Squid Developers</H2>
 <HR>
@@ -71,7 +71,7 @@
 <HR>
 <H2><A NAME="s1">1.</A> <A HREF="#toc1">Notice</A></H2>
 
-<P>The Squid Team are pleased to announce the release of Squid-3.1.20</P>
+<P>The Squid Team are pleased to announce the release of Squid-3.1.21</P>
 <P>This new release is available for download from 
 <A HREF="http://www.squid-cache.org/Versions/v3/3.1/">http://www.squid-cache.org/Versions/v3/3.1/</A> or the 
 <A HREF="http://www.squid-cache.org/Mirrors/http-mirrors.html">mirrors</A>.</P>
@@ -90,13 +90,15 @@
 <P>
 <UL>
 <LI>The lack of some features available in Squid-2.x series. See the regression sections below for full details.</LI>
+<LI>eCAP library version 0.2.0 and later are not supported. See eCAP section below for details.</LI>
+<LI>CVE-2009-0801 : NAT interception vulnerability to malicious clients. This is fixed in 3.2 series.
+Some attempts have been made to port for 3.1, but the unreliability of NAT handling in 3.1 makes this unsafe.</LI>
 </UL>
 </P>
 
 <P>Currently known issues which only depends on available developer time and may still be resolved in a future 3.1 release are:</P>
 <P>
 <UL>
-<LI>CVE-2009-0801 : NAT interception vulnerability to malicious clients. This is fixed in 3.2 series.</LI>
 <LI>Windows support is still largely missing.</LI>
 <LI>AIX support for building with the IBM compiler is broken.</LI>
 <LI>OpenSSL 1.0.0 support is incomplete.</LI>
@@ -408,6 +410,9 @@
 
 <P>Currently known and available eCAP modules are listed in the wiki feature page on eCAP.</P>
 
+<P><EM>Known Issue:</EM> libecap version 0.0.3 (exactly) is required to build this series
+of Squid. Other versions of libecap contain significant interface differences.</P>
+
 
 <H2><A NAME="ss2.10">2.10</A> <A HREF="#toc2.10">ICAP Bypass and Retry enhancements</A>
 </H2>
@@ -1045,9 +1050,13 @@
         RFC2475, and RFC3260.
 
         The TOS/DSCP byte must be exactly that - octet value 0x00-0xFF.
-        Note that in practice often only values up to 0x3F are usable
-        as the two highest bits have been redefined for use by ECN
-        (RFC3168).
+        Note that in practice often only multiples of 4 is usable as the
+        two rightmost bits have been redefined for use by ECN (RFC 3168
+        section 23.1).
+
+        Note that in practice often only values up to 0xFC are usable,
+        and only in multiple of 4, as the two rightmost bits have been
+        redefined for use by ECN (RFC3168).
 
         This setting is configured by setting the source TOS values:
 
diff -u -r -N squid-3.1.20/src/access_log.cc squid-3.1.21/src/access_log.cc
--- squid-3.1.20/src/access_log.cc	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/access_log.cc	2012-09-24 02:01:02.000000000 +1200
@@ -1778,7 +1778,7 @@
         safe_free(user);
 
     if (!Config.onoff.log_mime_hdrs) {
-        logfilePrintf(logfile, "%9ld.%03d %6d %s %s/%03d %"PRId64" %s %s %s %s%s/%s %s\n",
+        logfilePrintf(logfile, "%9ld.%03d %6d %s %s/%03d %" PRId64 " %s %s %s %s%s/%s %s\n",
                       (long int) current_time.tv_sec,
                       (int) current_time.tv_usec / 1000,
                       al->cache.msec,
@@ -1796,7 +1796,7 @@
     } else {
         char *ereq = log_quote(al->headers.request);
         char *erep = log_quote(al->headers.reply);
-        logfilePrintf(logfile, "%9ld.%03d %6d %s %s/%03d %"PRId64" %s %s %s %s%s/%s %s [%s] [%s]\n",
+        logfilePrintf(logfile, "%9ld.%03d %6d %s %s/%03d %" PRId64 " %s %s %s %s%s/%s %s [%s] [%s]\n",
                       (long int) current_time.tv_sec,
                       (int) current_time.tv_usec / 1000,
                       al->cache.msec,
@@ -1838,7 +1838,7 @@
 
     user2 = accessLogFormatName(al->cache.rfc931);
 
-    logfilePrintf(logfile, "%s %s %s [%s] \"%s %s HTTP/%d.%d\" %d %"PRId64" %s:%s%s",
+    logfilePrintf(logfile, "%s %s %s [%s] \"%s %s HTTP/%d.%d\" %d %" PRId64 " %s:%s%s",
                   client,
                   user2 ? user2 : dash_str,
                   user1 ? user1 : dash_str,
@@ -1900,7 +1900,7 @@
     if (user && !*user)
         safe_free(user);
 
-    logfilePrintf(logfile, "%9ld.%03d %6d %s -/%03d %"PRId64" %s %s %s -/%s -\n",
+    logfilePrintf(logfile, "%9ld.%03d %6d %s -/%03d %" PRId64 " %s %s %s -/%s -\n",
                   (long int) current_time.tv_sec,
                   (int) current_time.tv_usec / 1000,
 
diff -u -r -N squid-3.1.20/src/adaptation/ecap/MessageRep.cc squid-3.1.21/src/adaptation/ecap/MessageRep.cc
--- squid-3.1.20/src/adaptation/ecap/MessageRep.cc	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/adaptation/ecap/MessageRep.cc	2012-09-24 02:01:02.000000000 +1200
@@ -150,6 +150,8 @@
         return protocolInternal;
     case PROTO_ICY:
         return Name();
+    case PROTO_COAP:
+    case PROTO_COAPS: // use 'unknown'/none until libecap supports coap:// and coaps://
     case PROTO_NONE:
         return Name();
 
diff -u -r -N squid-3.1.20/src/BodyPipe.cc squid-3.1.21/src/BodyPipe.cc
--- squid-3.1.20/src/BodyPipe.cc	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/BodyPipe.cc	2012-09-24 02:01:02.000000000 +1200
@@ -423,9 +423,9 @@
 
     outputBuffer.append(" [", 2);
 
-    outputBuffer.Printf("%"PRIu64"<=%"PRIu64, theGetSize, thePutSize);
+    outputBuffer.Printf("%" PRIu64 "<=%" PRIu64, theGetSize, thePutSize);
     if (theBodySize >= 0)
-        outputBuffer.Printf("<=%"PRId64, theBodySize);
+        outputBuffer.Printf("<=%" PRId64, theBodySize);
     else
         outputBuffer.append("<=?", 3);
 
diff -u -r -N squid-3.1.20/src/cache_cf.cc squid-3.1.21/src/cache_cf.cc
--- squid-3.1.20/src/cache_cf.cc	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/cache_cf.cc	2012-09-24 02:01:02.000000000 +1200
@@ -2698,13 +2698,13 @@
 static void
 dump_b_int64_t(StoreEntry * entry, const char *name, int64_t var)
 {
-    storeAppendPrintf(entry, "%s %"PRId64" %s\n", name, var, B_BYTES_STR);
+    storeAppendPrintf(entry, "%s %" PRId64 " %s\n", name, var, B_BYTES_STR);
 }
 
 static void
 dump_kb_int64_t(StoreEntry * entry, const char *name, int64_t var)
 {
-    storeAppendPrintf(entry, "%s %"PRId64" %s\n", name, var, B_KBYTES_STR);
+    storeAppendPrintf(entry, "%s %" PRId64 " %s\n", name, var, B_KBYTES_STR);
 }
 
 static void
@@ -3312,8 +3312,9 @@
     http_port_list *s = create_http_port(portspec);
     // we may need to merge better of the above returns a list with clones
     assert(s->next == NULL);
-    s->next = Config.Sockaddr.http;
-    Config.Sockaddr.http = s;
+    s->next = cbdataReference(Config.Sockaddr.http);
+    cbdataReferenceDone(Config.Sockaddr.http);
+    Config.Sockaddr.http = cbdataReference(s);
 }
 
 http_port_list *
@@ -3385,7 +3386,7 @@
 
     if (Ip::EnableIpv6&IPV6_SPECIAL_SPLITSTACK && s->s.IsAnyAddr()) {
         // clone the port options from *s to *(s->next)
-        s->next = clone_http_port_list(s);
+        s->next = cbdataReference(clone_http_port_list(s));
         s->next->s.SetIPv4();
         debugs(3, 3, "http(s)_port: clone wildcard address for split-stack: " << s->s << " and " << s->next->s);
     }
@@ -3393,7 +3394,7 @@
     while (*head)
         head = &(*head)->next;
 
-    *head = s;
+    *head = cbdataReference(s);
 }
 
 static void
@@ -3531,7 +3532,7 @@
 
     while ((s = *head) != NULL) {
         *head = s->next;
-        delete s;
+        cbdataReferenceDone(s);
     }
 }
 
diff -u -r -N squid-3.1.20/src/cf.data.pre squid-3.1.21/src/cf.data.pre
--- squid-3.1.20/src/cf.data.pre	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/cf.data.pre	2012-09-24 02:01:02.000000000 +1200
@@ -1711,11 +1711,11 @@
 	Use this ACL to bypass server certificate validation errors.
 
 	For example, the following lines will bypass all validation errors
-	when talking to servers located at 172.16.0.0/16. All other
+	when talking to servers for example.com. All other
 	validation errors will result in ERR_SECURE_CONNECT_FAIL error.
 
-		acl BrokenServersAtTrustedIP dst 172.16.0.0/16
-		sslproxy_cert_error allow BrokenServersAtTrustedIP
+		acl BrokenButTrustedServers dstdomain example.com
+		sslproxy_cert_error allow BrokenButTrustedServers
 		sslproxy_cert_error deny all
 
 	This clause only supports fast acl types.
diff -u -r -N squid-3.1.20/src/client_side.cc squid-3.1.21/src/client_side.cc
--- squid-3.1.20/src/client_side.cc	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/client_side.cc	2012-09-24 02:01:02.000000000 +1200
@@ -1950,21 +1950,20 @@
         return; /* already in good shape */
 
     /* BUG: Squid cannot deal with '*' URLs (RFC2616 5.1.2) */
-    // BUG 2976: Squid only accepts intercepted HTTP.
 
     if ((host = mime_get_header(req_hdr, "Host")) != NULL) {
         int url_sz = strlen(url) + 32 + Config.appendDomainLen +
                      strlen(host);
         http->uri = (char *)xcalloc(url_sz, 1);
-        snprintf(http->uri, url_sz, "http://%s%s", /*conn->port->protocol,*/ host, url);
+        snprintf(http->uri, url_sz, "%s://%s%s", conn->port->protocol, host, url);
         debugs(33, 5, "TRANSPARENT HOST REWRITE: '" << http->uri <<"'");
     } else {
         /* Put the local socket IP address as the hostname.  */
         int url_sz = strlen(url) + 32 + Config.appendDomainLen;
         http->uri = (char *)xcalloc(url_sz, 1);
         http->getConn()->me.ToHostname(ipbuf,MAX_IPSTRLEN),
-        snprintf(http->uri, url_sz, "http://%s:%d%s",
-                 // http->getConn()->port->protocol,
+        snprintf(http->uri, url_sz, "%s://%s:%d%s",
+                 http->getConn()->port->protocol,
                  ipbuf, http->getConn()->me.GetPort(), url);
         debugs(33, 5, "TRANSPARENT REWRITE: '" << http->uri << "'");
     }
diff -u -r -N squid-3.1.20/src/client_side_request.cc squid-3.1.21/src/client_side_request.cc
--- squid-3.1.20/src/client_side_request.cc	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/client_side_request.cc	2012-09-24 02:01:02.000000000 +1200
@@ -189,7 +189,7 @@
            EBIT_TEST(request->cache_control->mask, CC_ONLY_IF_CACHED);
 }
 
-/*
+/**
  * This function is designed to serve a fairly specific purpose.
  * Occasionally our vBNS-connected caches can talk to each other, but not
  * the rest of the world.  Here we try to detect frequent failures which
@@ -201,19 +201,25 @@
  *
  * Duane W., Sept 16, 1996
  */
-
-#define FAILURE_MODE_TIME 300
-
 static void
 checkFailureRatio(err_type etype, hier_code hcode)
 {
-    static double magic_factor = 100.0;
-    double n_good;
-    double n_bad;
+    // Can be set at compile time with -D compiler flag
+#ifndef FAILURE_MODE_TIME
+#define FAILURE_MODE_TIME 300
+#endif
 
     if (hcode == HIER_NONE)
         return;
 
+    // don't bother when ICP is disabled.
+    if (Config.Port.icp <= 0)
+        return;
+
+    static double magic_factor = 100.0;
+    double n_good;
+    double n_bad;
+
     n_good = magic_factor / (1.0 + request_failure_ratio);
 
     n_bad = magic_factor - n_good;
@@ -241,10 +247,10 @@
     if (request_failure_ratio < 1.0)
         return;
 
-    debugs(33, 0, "Failure Ratio at "<< std::setw(4)<<
+    debugs(33, DBG_CRITICAL, "WARNING: Failure Ratio at "<< std::setw(4)<<
            std::setprecision(3) << request_failure_ratio);
 
-    debugs(33, 0, "Going into hit-only-mode for " <<
+    debugs(33, DBG_CRITICAL, "WARNING: ICP going into HIT-only mode for " <<
            FAILURE_MODE_TIME / 60 << " minutes...");
 
     hit_only_mode_until = squid_curtime + FAILURE_MODE_TIME;
diff -u -r -N squid-3.1.20/src/DelaySpec.cc squid-3.1.21/src/DelaySpec.cc
--- squid-3.1.20/src/DelaySpec.cc	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/DelaySpec.cc	2012-09-24 02:01:02.000000000 +1200
@@ -57,14 +57,14 @@
     }
 
     storeAppendPrintf(sentry, "\t%s:\n", label);
-    storeAppendPrintf(sentry, "\t\tMax: %"PRId64"\n", max_bytes);
+    storeAppendPrintf(sentry, "\t\tMax: %" PRId64 "\n", max_bytes);
     storeAppendPrintf(sentry, "\t\tRestore: %d\n", restore_bps);
 }
 
 void
 DelaySpec::dump (StoreEntry *entry) const
 {
-    storeAppendPrintf(entry, " %d/%"PRId64"", restore_bps, max_bytes);
+    storeAppendPrintf(entry, " %d/%" PRId64, restore_bps, max_bytes);
 }
 
 void
diff -u -r -N squid-3.1.20/src/DiskIO/DiskDaemon/diskd.cc squid-3.1.21/src/DiskIO/DiskDaemon/diskd.cc
--- squid-3.1.20/src/DiskIO/DiskDaemon/diskd.cc	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/DiskIO/DiskDaemon/diskd.cc	2012-09-24 02:01:02.000000000 +1200
@@ -149,11 +149,11 @@
 
     if (r->offset > -1 && r->offset != fs->offset) {
         DEBUG(2)
-        fprintf(stderr, "seeking to %"PRId64"\n", (int64_t)r->offset);
+        fprintf(stderr, "seeking to %" PRId64 "\n", (int64_t)r->offset);
 
         if (lseek(fs->fd, r->offset, SEEK_SET) < 0) {
             DEBUG(1) {
-                fprintf(stderr, "%d FD %d, offset %"PRId64": ", (int) mypid, fs->fd, (int64_t)r->offset);
+                fprintf(stderr, "%d FD %d, offset %" PRId64 ": ", (int) mypid, fs->fd, (int64_t)r->offset);
                 perror("lseek");
             }
         }
@@ -161,7 +161,7 @@
 
     x = read(fs->fd, buf, readlen);
     DEBUG(2)
-    fprintf(stderr, "%d READ %d,%d,%"PRId64" ret %d\n", (int) mypid,
+    fprintf(stderr, "%d READ %d,%d,%" PRId64 " ret %d\n", (int) mypid,
             fs->fd, readlen, (int64_t)r->offset, x);
 
     if (x < 0) {
@@ -198,14 +198,14 @@
     if (r->offset > -1 && r->offset != fs->offset) {
         if (lseek(fs->fd, r->offset, SEEK_SET) < 0) {
             DEBUG(1) {
-                fprintf(stderr, "%d FD %d, offset %"PRId64": ", (int) mypid, fs->fd, (int64_t)r->offset);
+                fprintf(stderr, "%d FD %d, offset %" PRId64 ": ", (int) mypid, fs->fd, (int64_t)r->offset);
                 perror("lseek");
             }
         }
     }
 
     DEBUG(2)
-    fprintf(stderr, "%d WRITE %d,%d,%"PRId64"\n", (int) mypid,
+    fprintf(stderr, "%d WRITE %d,%d,%" PRId64 "\n", (int) mypid,
             fs->fd, wrtlen, (int64_t)r->offset);
     x = write(fs->fd, buf, wrtlen);
 
diff -u -r -N squid-3.1.20/src/errorpage.cc squid-3.1.21/src/errorpage.cc
--- squid-3.1.20/src/errorpage.cc	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/errorpage.cc	2012-09-24 02:01:02.000000000 +1200
@@ -511,8 +511,7 @@
 #if USE_SSL
     delete err->detail;
 #endif
-    err->dnsError.clean();
-    cbdataFree(err);
+    delete err;
 }
 
 int
diff -u -r -N squid-3.1.20/src/external_acl.cc squid-3.1.21/src/external_acl.cc
--- squid-3.1.20/src/external_acl.cc	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/external_acl.cc	2012-09-24 02:01:02.000000000 +1200
@@ -511,6 +511,11 @@
                 storeAppendPrintf(sentry, " %%%s", #a); \
                 break
 
+#define DUMP_EXT_ACL_TYPE_FMT(a, fmt, ...) \
+            case _external_acl_format::EXT_ACL_##a: \
+                storeAppendPrintf(sentry, fmt, ##__VA_ARGS__); \
+                break
+
                 DUMP_EXT_ACL_TYPE(LOGIN);
 #if USE_IDENT
 
@@ -528,25 +533,14 @@
                 DUMP_EXT_ACL_TYPE(PATH);
                 DUMP_EXT_ACL_TYPE(METHOD);
 #if USE_SSL
-
-            case _external_acl_format::EXT_ACL_USER_CERT_RAW:
-                storeAppendPrintf(sentry, " %%USER_CERT");
-                break;
-
-            case _external_acl_format::EXT_ACL_USER_CERTCHAIN_RAW:
-                storeAppendPrintf(sentry, " %%USER_CERTCHAIN");
-                break;
-
-            case _external_acl_format::EXT_ACL_USER_CERT:
-                storeAppendPrintf(sentry, " %%USER_CERT_%s", format->header);
-                break;
-
-            case _external_acl_format::EXT_ACL_CA_CERT:
-                storeAppendPrintf(sentry, " %%USER_CERT_%s", format->header);
-                break;
+                DUMP_EXT_ACL_TYPE_FMT(USER_CERT_RAW, " %%USER_CERT_RAW");
+                DUMP_EXT_ACL_TYPE_FMT(USER_CERTCHAIN_RAW, " %%USER_CERTCHAIN_RAW");
+                DUMP_EXT_ACL_TYPE_FMT(USER_CERT, " %%USER_CERT_%s", format->header);
+                DUMP_EXT_ACL_TYPE_FMT(CA_CERT, " %%CA_CERT_%s", format->header);
 #endif
 
                 DUMP_EXT_ACL_TYPE(EXT_USER);
+                DUMP_EXT_ACL_TYPE_FMT(PERCENT, " %%%%");
 
             default:
                 fatal("unknown external_acl format error");
diff -u -r -N squid-3.1.20/src/fde.cc squid-3.1.21/src/fde.cc
--- squid-3.1.20/src/fde.cc	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/fde.cc	2012-09-24 02:01:02.000000000 +1200
@@ -56,11 +56,11 @@
 
 #ifdef _SQUID_MSWIN_
 
-    storeAppendPrintf(&dumpEntry, "%4d 0x%-8lX %-6.6s %4d %7"PRId64"%c %7"PRId64"%c %-21s %s\n",
+    storeAppendPrintf(&dumpEntry, "%4d 0x%-8lX %-6.6s %4d %7" PRId64 "%c %7" PRId64 "%c %-21s %s\n",
                       fdNumber,
                       win32.handle,
 #else
-    storeAppendPrintf(&dumpEntry, "%4d %-6.6s %4d %7"PRId64"%c %7"PRId64"%c %-21s %s\n",
+    storeAppendPrintf(&dumpEntry, "%4d %-6.6s %4d %7" PRId64 "%c %7" PRId64 "%c %-21s %s\n",
                       fdNumber,
 #endif
                       fdTypeStr[type],
diff -u -r -N squid-3.1.20/src/fs/coss/store_dir_coss.cc squid-3.1.21/src/fs/coss/store_dir_coss.cc
--- squid-3.1.20/src/fs/coss/store_dir_coss.cc	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/fs/coss/store_dir_coss.cc	2012-09-24 02:01:02.000000000 +1200
@@ -996,8 +996,8 @@
 CossSwapDir::statfs(StoreEntry & sentry) const
 {
     storeAppendPrintf(&sentry, "\n");
-    storeAppendPrintf(&sentry, "Maximum Size: %"PRIu64" KB\n", max_size);
-    storeAppendPrintf(&sentry, "Current Size: %"PRIu64" KB\n", cur_size);
+    storeAppendPrintf(&sentry, "Maximum Size: %" PRIu64 " KB\n", max_size);
+    storeAppendPrintf(&sentry, "Current Size: %" PRIu64 " KB\n", cur_size);
     storeAppendPrintf(&sentry, "Percent Used: %0.2f%%\n",
                       (100.0 * (double)cur_size / (double)max_size) );
     storeAppendPrintf(&sentry, "Number of object collisions: %d\n", (int) numcollisions);
@@ -1095,7 +1095,7 @@
 void
 CossSwapDir::dump(StoreEntry &entry)const
 {
-    storeAppendPrintf(&entry, " %"PRIu64"", (max_size >> 10));
+    storeAppendPrintf(&entry, " %" PRIu64, (max_size >> 10));
     dumpOptions(&entry);
 }
 
diff -u -r -N squid-3.1.20/src/fs/ufs/store_dir_ufs.cc squid-3.1.21/src/fs/ufs/store_dir_ufs.cc
--- squid-3.1.20/src/fs/ufs/store_dir_ufs.cc	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/fs/ufs/store_dir_ufs.cc	2012-09-24 02:01:02.000000000 +1200
@@ -311,8 +311,8 @@
     int x;
     storeAppendPrintf(&sentry, "First level subdirectories: %d\n", l1);
     storeAppendPrintf(&sentry, "Second level subdirectories: %d\n", l2);
-    storeAppendPrintf(&sentry, "Maximum Size: %"PRIu64" KB\n", max_size);
-    storeAppendPrintf(&sentry, "Current Size: %"PRIu64" KB\n", cur_size);
+    storeAppendPrintf(&sentry, "Maximum Size: %" PRIu64 " KB\n", max_size);
+    storeAppendPrintf(&sentry, "Current Size: %" PRIu64 " KB\n", cur_size);
     storeAppendPrintf(&sentry, "Percent Used: %0.2f%%\n",
                       (double)(100.0 * cur_size) / (double)max_size);
     storeAppendPrintf(&sentry, "Filemap bits in use: %d of %d (%d%%)\n",
@@ -1324,7 +1324,7 @@
 void
 UFSSwapDir::dump(StoreEntry & entry) const
 {
-    storeAppendPrintf(&entry, " %"PRIu64" %d %d",
+    storeAppendPrintf(&entry, " %" PRIu64 " %d %d",
                       (max_size >> 10),
                       l1,
                       l2);
diff -u -r -N squid-3.1.20/src/ftp.cc squid-3.1.21/src/ftp.cc
--- squid-3.1.20/src/ftp.cc	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/ftp.cc	2012-09-24 02:01:02.000000000 +1200
@@ -1152,7 +1152,7 @@
         snprintf(icon, 2048, "<IMG border=\"0\" SRC=\"%s\" ALT=\"%-6s\">",
                  mimeGetIconURL(parts->name),
                  "[FILE]");
-        snprintf(size, 2048, " %6"PRId64"k", parts->size);
+        snprintf(size, 2048, " %6" PRId64 "k", parts->size);
         break;
     }
 
@@ -3259,7 +3259,7 @@
 
     debugs(9, 3, HERE);
 
-    snprintf(cbuf, 1024, "REST %"PRId64"\r\n", ftpState->restart_offset);
+    snprintf(cbuf, 1024, "REST %" PRId64 "\r\n", ftpState->restart_offset);
     ftpState->writeCommand(cbuf);
     ftpState->state = SENT_REST;
 }
diff -u -r -N squid-3.1.20/src/HttpHdrContRange.cc squid-3.1.21/src/HttpHdrContRange.cc
--- squid-3.1.20/src/HttpHdrContRange.cc	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/HttpHdrContRange.cc	2012-09-24 02:01:02.000000000 +1200
@@ -129,7 +129,7 @@
     if (!known_spec(spec->offset) || !known_spec(spec->length))
         packerPrintf(p, "*");
     else
-        packerPrintf(p, "bytes %"PRId64"-%"PRId64,
+        packerPrintf(p, "bytes %" PRId64 "-%" PRId64,
                      spec->offset, spec->offset + spec->length - 1);
 }
 
@@ -233,7 +233,7 @@
     if (!known_spec(range->elength))
         packerPrintf(p, "/*");
     else
-        packerPrintf(p, "/%"PRId64, range->elength);
+        packerPrintf(p, "/%" PRId64, range->elength);
 }
 
 void
diff -u -r -N squid-3.1.20/src/HttpHdrRange.cc squid-3.1.21/src/HttpHdrRange.cc
--- squid-3.1.20/src/HttpHdrRange.cc	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/HttpHdrRange.cc	2012-09-24 02:01:02.000000000 +1200
@@ -132,11 +132,11 @@
 HttpHdrRangeSpec::packInto(Packer * packer) const
 {
     if (!known_spec(offset))	/* suffix */
-        packerPrintf(packer, "-%"PRId64,  length);
+        packerPrintf(packer, "-%" PRId64,  length);
     else if (!known_spec(length))		/* trailer */
-        packerPrintf(packer, "%"PRId64"-", offset);
+        packerPrintf(packer, "%" PRId64 "-", offset);
     else			/* range */
-        packerPrintf(packer, "%"PRId64"-%"PRId64,
+        packerPrintf(packer, "%" PRId64 "-%" PRId64,
                      offset, offset + length - 1);
 }
 
diff -u -r -N squid-3.1.20/src/ip/IpAddress.cc squid-3.1.21/src/ip/IpAddress.cc
--- squid-3.1.20/src/ip/IpAddress.cc	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/ip/IpAddress.cc	2012-09-24 02:01:02.000000000 +1200
@@ -592,7 +592,12 @@
     memset(dst, 0, sizeof(struct addrinfo));
 
     // set defaults
+    // Mac OS X does not emit a flag indicating the output is numeric (IP address)
+#if _SQUID_APPLE_
+    dst->ai_flags = 0;
+#else
     dst->ai_flags = AI_NUMERICHOST;
+#endif
 
     if (dst->ai_socktype == 0)
         dst->ai_socktype = SOCK_STREAM;
@@ -605,7 +610,7 @@
             && dst->ai_protocol == 0)
         dst->ai_protocol = IPPROTO_UDP;
 
-    if (force == AF_INET6 || (force == AF_UNSPEC && IsIPv6()) ) {
+    if (force == AF_INET6 || (force == AF_UNSPEC && Ip::EnableIpv6 && IsIPv6()) ) {
         dst->ai_addr = (struct sockaddr*)new sockaddr_in6;
 
         memset(dst->ai_addr,0,sizeof(struct sockaddr_in6));
diff -u -r -N squid-3.1.20/src/MemObject.cc squid-3.1.21/src/MemObject.cc
--- squid-3.1.20/src/MemObject.cc	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/MemObject.cc	2012-09-24 02:01:02.000000000 +1200
@@ -213,13 +213,13 @@
                RequestMethodStr(method), log_url);
     if (vary_headers)
         mb->Printf("\tvary_headers: %s\n", vary_headers);
-    mb->Printf("\tinmem_lo: %"PRId64"\n", inmem_lo);
-    mb->Printf("\tinmem_hi: %"PRId64"\n", data_hdr.endOffset());
-    mb->Printf("\tswapout: %"PRId64" bytes queued\n",
+    mb->Printf("\tinmem_lo: %" PRId64 "\n", inmem_lo);
+    mb->Printf("\tinmem_hi: %" PRId64 "\n", data_hdr.endOffset());
+    mb->Printf("\tswapout: %" PRId64 " bytes queued\n",
                swapout.queue_offset);
 
     if (swapout.sio.getRaw())
-        mb->Printf("\tswapout: %"PRId64" bytes written\n",
+        mb->Printf("\tswapout: %" PRId64 " bytes written\n",
                    (int64_t) swapout.sio->offset());
 
     StoreClientStats statsVisitor(mb);
@@ -376,16 +376,17 @@
 }
 
 int
-MemObject::mostBytesWanted(int max) const
+MemObject::mostBytesWanted(int max, bool ignoreDelayPools) const
 {
 #if DELAY_POOLS
-    /* identify delay id with largest allowance */
-    DelayId largestAllowance = mostBytesAllowed ();
-    return largestAllowance.bytesWanted(0, max);
-#else
+    if (!ignoreDelayPools) {
+        /* identify delay id with largest allowance */
+        DelayId largestAllowance = mostBytesAllowed ();
+        return largestAllowance.bytesWanted(0, max);
+    }
+#endif
 
     return max;
-#endif
 }
 
 void
@@ -437,10 +438,6 @@
 
 #endif
 
-        if (sc->getType() != STORE_MEM_CLIENT)
-            /* reading off disk */
-            continue;
-
         j = sc->delayId.bytesWanted(0, sc->copyInto.length);
 
         if (j > jmax) {
diff -u -r -N squid-3.1.20/src/MemObject.h squid-3.1.21/src/MemObject.h
--- squid-3.1.20/src/MemObject.h	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/MemObject.h	2012-09-24 02:01:02.000000000 +1200
@@ -77,7 +77,7 @@
     void trimSwappable();
     void trimUnSwappable();
     bool isContiguous() const;
-    int mostBytesWanted(int max) const;
+    int mostBytesWanted(int max, bool ignoreDelayPools) const;
     void setNoDelay(bool const newValue);
 #if DELAY_POOLS
 
diff -u -r -N squid-3.1.20/src/neighbors.cc squid-3.1.21/src/neighbors.cc
--- squid-3.1.20/src/neighbors.cc	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/neighbors.cc	2012-09-24 02:01:02.000000000 +1200
@@ -415,9 +415,10 @@
 void
 peerClearRRStart(void)
 {
-    static int event_added = 0;
+    static bool event_added = false;
     if (!event_added) {
         peerClearRRLoop(NULL);
+        event_added=true;
     }
 }
 
diff -u -r -N squid-3.1.20/src/Server.cc squid-3.1.21/src/Server.cc
--- squid-3.1.20/src/Server.cc	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/Server.cc	2012-09-24 02:01:02.000000000 +1200
@@ -721,7 +721,7 @@
     if (!contentSize)
         return; // XXX: bytesWanted asserts on zero-size ranges
 
-    const size_t spaceAvailable = entry->bytesWanted(Range<size_t>(0, contentSize));
+    const size_t spaceAvailable = entry->bytesWanted(Range<size_t>(0, contentSize), true);
 
     if (spaceAvailable < contentSize ) {
         // No or partial body data consuming
diff -u -r -N squid-3.1.20/src/stat.cc squid-3.1.21/src/stat.cc
--- squid-3.1.20/src/stat.cc	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/stat.cc	2012-09-24 02:01:02.000000000 +1200
@@ -1619,7 +1619,7 @@
 
         if (conn != NULL) {
             fd = conn->fd;
-            storeAppendPrintf(s, "\tFD %d, read %"PRId64", wrote %"PRId64"\n", fd,
+            storeAppendPrintf(s, "\tFD %d, read %" PRId64 ", wrote %" PRId64 "\n", fd,
                               fd_table[fd].bytes_read, fd_table[fd].bytes_written);
             storeAppendPrintf(s, "\tFD desc: %s\n", fd_table[fd].desc);
             storeAppendPrintf(s, "\tin: buf %p, offset %ld, size %ld\n",
diff -u -r -N squid-3.1.20/src/store.cc squid-3.1.21/src/store.cc
--- squid-3.1.20/src/store.cc	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/store.cc	2012-09-24 02:01:02.000000000 +1200
@@ -257,7 +257,7 @@
 }
 
 size_t
-StoreEntry::bytesWanted (Range<size_t> const aRange) const
+StoreEntry::bytesWanted (Range<size_t> const aRange, bool ignoreDelayPools) const
 {
     if (mem_obj == NULL)
         return aRange.end;
@@ -268,14 +268,10 @@
 
 #endif
 
-    /* Always read *something* here - we haven't got the header yet */
-    if (EBIT_TEST(flags, ENTRY_FWD_HDR_WAIT))
-        return aRange.end;
-
     if (!mem_obj->readAheadPolicyCanRead())
         return 0;
 
-    return mem_obj->mostBytesWanted(aRange.end);
+    return mem_obj->mostBytesWanted(aRange.end, ignoreDelayPools);
 }
 
 bool
diff -u -r -N squid-3.1.20/src/store_client.cc squid-3.1.21/src/store_client.cc
--- squid-3.1.20/src/store_client.cc	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/store_client.cc	2012-09-24 02:01:02.000000000 +1200
@@ -841,7 +841,7 @@
 
     output->Printf("\tClient #%d, %p\n", clientNumber, _callback.callback_data);
 
-    output->Printf("\t\tcopy_offset: %"PRId64"\n",
+    output->Printf("\t\tcopy_offset: %" PRId64 "\n",
                    copyInto.offset);
 
     output->Printf("\t\tcopy_size: %d\n",
diff -u -r -N squid-3.1.20/src/store_dir.cc squid-3.1.21/src/store_dir.cc
--- squid-3.1.20/src/store_dir.cc	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/store_dir.cc	2012-09-24 02:01:02.000000000 +1200
@@ -360,11 +360,11 @@
     storeAppendPrintf(&output, "Store Directory Statistics:\n");
     storeAppendPrintf(&output, "Store Entries          : %lu\n",
                       (unsigned long int)StoreEntry::inUseCount());
-    storeAppendPrintf(&output, "Maximum Swap Size      : %"PRIu64" KB\n",
+    storeAppendPrintf(&output, "Maximum Swap Size      : %" PRIu64 " KB\n",
                       maxSize());
     storeAppendPrintf(&output, "Current Store Swap Size: %8lu KB\n",
                       store_swap_size);
-    storeAppendPrintf(&output, "Current Capacity       : %"PRId64"%% used, %"PRId64"%% free\n",
+    storeAppendPrintf(&output, "Current Capacity       : %" PRId64 "%% used, %" PRId64 "%% free\n",
                       Math::int64Percent(store_swap_size, maxSize()),
                       Math::int64Percent((maxSize() - store_swap_size), maxSize()));
     /* FIXME Here we should output memory statistics */
diff -u -r -N squid-3.1.20/src/Store.h squid-3.1.21/src/Store.h
--- squid-3.1.20/src/Store.h	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/Store.h	2012-09-24 02:01:02.000000000 +1200
@@ -79,7 +79,7 @@
     virtual void write (StoreIOBuffer);
     virtual _SQUID_INLINE_ bool isEmpty() const;
     virtual bool isAccepting() const;
-    virtual size_t bytesWanted(Range<size_t> const) const;
+    virtual size_t bytesWanted(Range<size_t> const aRange, bool ignoreDelayPool = false) const;
     virtual void complete();
     virtual store_client_t storeClientType() const;
     virtual char const *getSerialisedMetaData();
@@ -224,7 +224,7 @@
 
     bool isEmpty () const {return true;}
 
-    virtual size_t bytesWanted(Range<size_t> const aRange) const { return aRange.end; }
+    virtual size_t bytesWanted(Range<size_t> const aRange, bool ignoreDelayPool = false) const { return aRange.end; }
 
     void operator delete(void *address);
     void complete() {}
diff -u -r -N squid-3.1.20/src/store_log.cc squid-3.1.21/src/store_log.cc
--- squid-3.1.20/src/store_log.cc	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/store_log.cc	2012-09-24 02:01:02.000000000 +1200
@@ -83,7 +83,7 @@
 
         String ctype=(reply->content_type.size() ? reply->content_type.termedBuf() : str_unknown);
 
-        logfilePrintf(storelog, "%9d.%03d %-7s %02d %08X %s %4d %9d %9d %9d " SQUIDSTRINGPH " %"PRId64"/%"PRId64" %s %s\n",
+        logfilePrintf(storelog, "%9d.%03d %-7s %02d %08X %s %4d %9d %9d %9d " SQUIDSTRINGPH " %" PRId64 "/%" PRId64 " %s %s\n",
                       (int) current_time.tv_sec,
                       (int) current_time.tv_usec / 1000,
                       storeLogTags[tag],
diff -u -r -N squid-3.1.20/src/SwapDir.cc squid-3.1.21/src/SwapDir.cc
--- squid-3.1.20/src/SwapDir.cc	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/SwapDir.cc	2012-09-24 02:01:02.000000000 +1200
@@ -258,7 +258,7 @@
 SwapDir::optionMaxSizeDump(StoreEntry * e) const
 {
     if (max_objsize != -1)
-        storeAppendPrintf(e, " max-size=%"PRId64, max_objsize);
+        storeAppendPrintf(e, " max-size=%" PRId64, max_objsize);
 }
 
 /* Swapdirs do not have an index of their own - thus they ask their parent..
diff -u -r -N squid-3.1.20/src/tests/stub_MemObject.cc squid-3.1.21/src/tests/stub_MemObject.cc
--- squid-3.1.20/src/tests/stub_MemObject.cc	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/tests/stub_MemObject.cc	2012-09-24 02:01:02.000000000 +1200
@@ -106,7 +106,7 @@
 }
 
 int
-MemObject::mostBytesWanted(int max) const
+MemObject::mostBytesWanted(int max, bool ignoreDelayPools) const
 {
     fatal ("Not implemented");
     return -1;
diff -u -r -N squid-3.1.20/src/tests/stub_store.cc squid-3.1.21/src/tests/stub_store.cc
--- squid-3.1.20/src/tests/stub_store.cc	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/tests/stub_store.cc	2012-09-24 02:01:02.000000000 +1200
@@ -19,7 +19,7 @@
 HttpReply const *StoreEntry::getReply() const STUB_RETVAL(NULL)
 void StoreEntry::write(StoreIOBuffer) STUB
 bool StoreEntry::isAccepting() const STUB_RETVAL(false)
-size_t StoreEntry::bytesWanted(Range<size_t> const) const STUB_RETVAL(0)
+size_t StoreEntry::bytesWanted(Range<size_t> const, bool) const STUB_RETVAL(0)
 void StoreEntry::complete() STUB
 store_client_t StoreEntry::storeClientType() const STUB_RETVAL(STORE_NON_CLIENT)
 char const *StoreEntry::getSerialisedMetaData() STUB_RETVAL(NULL)
diff -u -r -N squid-3.1.20/src/tools.cc squid-3.1.21/src/tools.cc
--- squid-3.1.20/src/tools.cc	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/tools.cc	2012-09-24 02:01:02.000000000 +1200
@@ -174,7 +174,7 @@
 
     mp = mallinfo();
 
-    fprintf(debug_log, "Memory usage for "APP_SHORTNAME" via mallinfo():\n");
+    fprintf(debug_log, "Memory usage for " APP_SHORTNAME " via mallinfo():\n");
 
     fprintf(debug_log, "\ttotal space in arena:  %6ld KB\n",
             (long)mp.arena >> 10);
diff -u -r -N squid-3.1.20/src/wccp2.cc squid-3.1.21/src/wccp2.cc
--- squid-3.1.20/src/wccp2.cc	2012-06-08 23:20:21.000000000 +1200
+++ squid-3.1.21/src/wccp2.cc	2012-09-24 02:01:02.000000000 +1200
@@ -328,6 +328,8 @@
 #define WCCP2_CAPABILITY_FORWARDING_METHOD	0x01
 #define WCCP2_CAPABILITY_ASSIGNMENT_METHOD	0x02
 #define WCCP2_CAPABILITY_RETURN_METHOD		0x03
+// 0x04 ?? - advertised by a 4507 (ios v15.1) Cisco switch
+// 0x05 ?? - advertised by a 4507 (ios v15.1) Cisco switch
 
 /* capability values */
 #define WCCP2_METHOD_GRE		0x00000001
@@ -1387,6 +1389,10 @@
 
                 break;
 
+            case 4:
+            case 5:
+                break; // ignore silently for now
+
             default:
                 debugs(80, 1, "Unknown capability type in WCCPv2 Packet (" << ntohs(router_capability_element->capability_type) << ").");
             }
