]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Replace most USE_IPV6 with run-time support probing
authorAmos Jeffries <amosjeffries@squid-cache.org>
Tue, 27 Jul 2010 13:02:31 +0000 (07:02 -0600)
committerAmos Jeffries <amosjeffries@squid-cache.org>
Tue, 27 Jul 2010 13:02:31 +0000 (07:02 -0600)
This unifies the code built for IPv4-only, dual-stack and split-stack.

 * --disable-ipv6 option remains, however it now prevents the run-time probe

 * Probing previously done in ./configure at build time is now merged and
performed run-time on every startup. IPv6 is enabled or disabled based on
the underlying OS support for sockets and setsockopt operations required.

 * Parsing and other operations which can be performed without specific IPv6
connectivity are enabled.

 * Some DNS logic alterations have had to be made to merge the split-stack
DNS and leverage it for IPv4-only mode. Otherwise the logics are unchanged
from previous dual-stack builds which have been well tested.

49 files changed:
compat/Makefile.am
compat/compat.h
compat/os/freebsd.h
compat/os/macosx.h [new file with mode: 0644]
compat/os/openbsd.h
compat/os/solaris.h
configure.in
lib/getaddrinfo.c
src/Makefile.am
src/acl/Ip.cc
src/cache_cf.cc
src/cf.data.pre
src/client_db.cc
src/client_side.cc
src/comm.cc
src/comm_poll.cc
src/comm_select.cc
src/comm_select_win32.cc
src/dns_internal.cc
src/dnsserver.cc
src/external_acl.cc
src/ftp.cc
src/icmp/Icmp.h
src/icmp/Icmp6.cc
src/icmp/Icmp6.h
src/icmp/IcmpPinger.cc
src/icmp/IcmpSquid.cc
src/icmp/net_db.cc
src/icmp/pinger.cc
src/internal.cc
src/ip/IpAddress.cc
src/ip/IpAddress.h
src/ip/IpIntercept.cc
src/ip/Makefile.am
src/ip/testIpAddress.cc
src/ip/testIpAddress.h
src/ip/tools.cc [new file with mode: 0644]
src/ip/tools.h [new file with mode: 0644]
src/ipcache.cc
src/main.cc
src/multicast.cc
src/snmp_core.cc
src/stub_debug.cc [new file with mode: 0644]
src/tests/testHttpRequest.cc
src/tools.cc
src/url.cc
tools/Makefile.am
tools/cachemgr.cc
tools/squidclient.cc

index 9ff0fc182e4e97d6a1993afc868b6460e5c57f49..1bfccce74a086c84f2189da57b26ef41284fb5c0 100644 (file)
@@ -26,6 +26,7 @@ libcompat_la_SOURCES = \
        os/hpux.h \
        os/linux.h \
        os/mswin.h \
+       os/macosx.h \
        os/next.h \
        os/openbsd.h \
        os/os2.h \
index bacbc5aae2f75d485f401602856dad467c7e9c55..3059cdeff964579ace7a38b995aa3013ff0f2ac0 100644 (file)
@@ -54,6 +54,7 @@
 #include "compat/os/freebsd.h"
 #include "compat/os/hpux.h"
 #include "compat/os/linux.h"
+#include "compat/os/macosx.h"
 #include "compat/os/mswin.h"
 #include "compat/os/next.h"
 #include "compat/os/openbsd.h"
index e4fb395942f488ca602db115c71fc475259c1320..88708ccbddda3e8ccc937a9d445de5cb0aa93068 100644 (file)
 
 #define _etext etext
 
+/*
+ *   This OS has at least one version that defines these as private
+ *   kernel macros commented as being 'non-standard'.
+ *   We need to use them, much nicer than the OS-provided __u*_*[]
+ */
+//#define s6_addr8  __u6_addr.__u6_addr8
+//#define s6_addr16 __u6_addr.__u6_addr16
+#define s6_addr32 __u6_addr.__u6_addr32
+
 #endif /* _SQUID_FREEBSD_ */
 #endif /* SQUID_OS_FREEBSD_H */
diff --git a/compat/os/macosx.h b/compat/os/macosx.h
new file mode 100644 (file)
index 0000000..4490e24
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef SQUID_CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef SQUID_OS_MACOSX_H
+#define SQUID_OS_MACOSX_H
+
+#ifdef _SQUID_APPLE_
+
+/****************************************************************************
+ *--------------------------------------------------------------------------*
+ * DO *NOT* MAKE ANY CHANGES below here unless you know what you're doing...*
+ *--------------------------------------------------------------------------*
+ ****************************************************************************/
+
+/*
+ *   This OS has at least one version that defines these as private
+ *   kernel macros commented as being 'non-standard'.
+ *   We need to use them, much nicer than the OS-provided __u*_*[]
+ */
+//#define s6_addr8  __u6_addr.__u6_addr8
+//#define s6_addr16 __u6_addr.__u6_addr16
+#define s6_addr32 __u6_addr.__u6_addr32
+
+#endif /* _SQUID_APPLE_ */
+#endif /* SQUID_OS_MACOSX_H */
index eae2cdf003bd0042edddce73f60e801d49fe0ded..d11e2affd44455dc8aab05e5079b87d34c95cdbd 100644 (file)
 #endif
 
 
+/*
+ *   This OS has at least one version that defines these as private
+ *   kernel macros commented as being 'non-standard'.
+ *   We need to use them, much nicer than the OS-provided __u*_*[]
+ */
+//#define s6_addr8  __u6_addr.__u6_addr8
+//#define s6_addr16 __u6_addr.__u6_addr16
+#define s6_addr32 __u6_addr.__u6_addr32
+
+/* OpenBSD also hide v6only socket option we need for comm layer. :-( */
+#if !defined(IPV6_V6ONLY)
+#define IPV6_V6ONLY             27 // from OpenBSD 4.3 headers. (NP: does not match non-BSD OS values)
+#endif
+
 #endif /* _SQUID_OPENBSD_ */
 #endif /* SQUID_OS_OPENBSD_H */
index fe1c039ea31f98fd97edea3d605fc548e4d705a0..eb1d1b92e6b8561aa1752fd49c90b22f1e6967bf 100644 (file)
@@ -59,5 +59,10 @@ SQUIDCEXTERN int gethostname(char *, int);
 #define __FUNCTION__ ""
 #endif
 
+/* Bug 2500: Solaris 10/11 require s6_addr* defines. */
+//#define s6_addr8   _S6_un._S6_u8
+//#define s6_addr16  _S6_un._S6_u16
+#define s6_addr32  _S6_un._S6_u32
+
 #endif /* _SQUID_SOLARIS_ */
 #endif /* SQUID_OS_SOALRIS_H */
index b77bedcb0d789715ed2b8de301ad86cfe3c793b3..1d82b2cf564154336a6b9d2c933efb85fd5c5b5f 100644 (file)
@@ -2648,9 +2648,9 @@ esac
 
 dnl Enable IPv6 support
 AC_MSG_CHECKING([whether to enable IPv6])
-use_ipng=auto
+use_ipng=yes
 AC_ARG_ENABLE(ipv6,
-  AS_HELP_STRING([--disable-ipv6],[Disable IPv6 support]),
+  AS_HELP_STRING([--disable-ipv6],[Disable IPv6 support. The default is to probe system capabilities on startup.]),
 [ case $enableval in
   yes|no)
     use_ipng=$enableval
@@ -2662,116 +2662,26 @@ AC_ARG_ENABLE(ipv6,
 AC_MSG_RESULT($use_ipng)
 
 if test "$use_ipng" != "no"; then
-  SAVED_LIBS="$LIBS"
-  dnl Solaris 10/11 requires  -lsocket
-  case "$host" in
-    *-solaris*)
-      LIBS="$LIBS -lsocket"
-      ;;
-    *)
-      ;;
-  esac
-  AC_CACHE_CHECK([if PF_INET6 is available], squid_cv_pf_inet6,
-    AC_RUN_IFELSE([AC_LANG_SOURCE([[ /* PF_INET6 available check */
-#       include <sys/types.h>
-#       include <sys/socket.h>
-        int main(int argc, char **argv) {
-          if (socket(PF_INET6, SOCK_STREAM, 0) < 0)
-            return 1;
-          else
-            return 0;
-        }
-      ]])],[squid_cv_pf_inet6="yes" ; SAVED_LIBS="$LIBS"],[squid_cv_pf_inet6="no"],[])
-   )
-   LIBS="$SAVED_LIBS"
-fi
-
-# NP: semi-silent failure as IPv4-only mode is perfectly usable on this system.
-# unless --enable-ipv6 is explicitly used. in which case it's a hard fail.
-if test "x$use_ipng" = "xyes" && test "x$squid_cv_pf_inet6" = "xno"; then
-       AC_MSG_ERROR([IPv6 cannot be built on this system. Basic kernel definitions are missing.])
-elif test "x$use_ipng" = "xauto" && test "x$squid_cv_pf_inet6" = "xno"; then
-       AC_MSG_WARN([IPv6 cannot be built on this system. Basic kernel definitions are missing.])
-fi
-
-if test "$use_ipng" != "no" && test "$squid_cv_pf_inet6" = "yes" ; then
   AC_DEFINE(USE_IPV6,1,[Enable support for IPv6 ])
-  SET_IPV6_SETTINGS=""
-  use_v4mapped=yes
-
-dnl Check for forced split-stack mode
-  AC_MSG_CHECKING([for IPv6 split-stack requirement])
-  AC_ARG_WITH(ipv6-split-stack,
-    AS_HELP_STRING([--with-ipv6-split-stack],[Force-Enable experimental split-stack support for Windows XP and *BSD. Requires IPv6.]),
-    [ use_v4mapped="no"
-      AC_MSG_RESULT(yes)],
-    [ AC_MSG_RESULT(no) ])
-
-dnl Check for IPv6 v4-mapping availability
-dnl Useful for other OS with hybrid-stack defaults turned OFF
-dnl But only usable if it actually works...
-  if test "$use_v4mapped" = "yes" ; then
-    AC_MSG_CHECKING([for IPv6 v4-mapping ability])
-    AC_RUN_IFELSE([AC_LANG_SOURCE([[ /* IPPROTO_V4MAPPED is usable check */
-#       include <sys/types.h>
-#       include <sys/socket.h>
-#      include <netinet/in.h>
-#if HAVE_NETINET_IN6_H
-#      include <netinet/in6.h>
-#endif
-        int main(int argc, char **argv) {
-          int s = socket(PF_INET6, SOCK_STREAM, 0);
-          int tos = 0;
-          if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &tos, sizeof(int)) < 0)
-            return 1;
-          else
-            return 0;
-        }
-      ]])],[ AC_MSG_RESULT(yes)
-        use_v4mapped=yes
-        AC_DEFINE(IPV6_SPECIAL_V4MAPPED, 1, [Enable v4-mapping through v6 sockets])
-      ],[ AC_MSG_RESULT(no)
-        AC_DEFINE(IPV6_SPECIAL_V4MAPPED, 0, [Enable v4-mapping through v6 sockets])
-        use_v4mapped=no
-      ],[])
-  fi
-
-dnl if we can't defer v4-mapping to the OS we are forced to split-stack the FD table.
-  AC_MSG_CHECKING([for IPv6 stack type/mode])
-  if test "$use_v4mapped" = "yes"; then
-    AC_DEFINE(IPV6_SPECIAL_V4MAPPED, 1, [Enable v4-mapping through v6 sockets. Requires IPv6 hybrid-stack.])
-    AC_DEFINE(IPV6_SPECIAL_SPLITSTACK, 0, [Enable support for IPv6 on split-stack implementations])
-    AC_MSG_RESULT(mapping hybrid)
-  else
-    AC_DEFINE(IPV6_SPECIAL_V4MAPPED, 0, [Enable v4-mapping through v6 sockets. Requires IPv6 hybrid-stack.])
-    AC_DEFINE(IPV6_SPECIAL_SPLITSTACK, 1, [Enable support for IPv6 on split-stack implementations])
-    AC_MSG_RESULT(split-stack or BSD non-mapping dual-stack)
-  fi
+else
+  AC_DEFINE(USE_IPV6,0,[Enable support for IPv6 ])
+fi
 
 dnl Check whether this OS defines sin6_len as a member of sockaddr_in6 as a backup to ss_len
 AC_CACHE_CHECK([for sin6_len field in struct sockaddr_in6],
                 ac_cv_have_sin6_len_in_struct_sai, [
-        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
-                ]], [[ struct sockaddr_in6 s; s.sin6_len = 1; ]])],[ ac_cv_have_sin6_len_in_struct_sai="yes" ],[ ac_cv_have_sin6_len_in_struct_sai="no" 
-        ])
-  ])
-  if test "x$ac_cv_have_sin6_len_in_struct_sai" = "xyes" ; then
-    AC_DEFINE(HAVE_SIN6_LEN_IN_SAI, 1, [Does struct sockaddr_in6 have sin6_len? 1: Yes, 0: No])
-  else
-    AC_DEFINE(HAVE_SIN6_LEN_IN_SAI, 0, [Does struct sockaddr_in6 have sin6_len? 1: Yes, 0: No])
-  fi
-
+              ]], [[ struct sockaddr_in6 s; s.sin6_len = 1; ]])],[ ac_cv_have_sin6_len_in_struct_sai="yes" ],[ ac_cv_have_sin6_len_in_struct_sai="no" 
+      ])
+])
+if test "x$ac_cv_have_sin6_len_in_struct_sai" = "xyes" ; then
+  AC_DEFINE(HAVE_SIN6_LEN_IN_SAI, 1, [Does struct sockaddr_in6 have sin6_len? 1: Yes, 0: No])
 else
-  # IPv6 is not available, but is not explicitly required. Auto-Disable.
-  AC_DEFINE(USE_IPV6,0,[Enable support for IPv6])
-  AC_DEFINE(IPV6_SPECIAL_SPLITSTACK,0,[Enable support for IPv6 on split-stack implementations])
-  AC_DEFINE(IPV6_SPECIAL_V4MAPPED,0,[Enable v4-mapping through v6 sockets])
-  SET_IPV6_SETTINGS="\#IPv6 Not Available: "
+  AC_DEFINE(HAVE_SIN6_LEN_IN_SAI, 0, [Does struct sockaddr_in6 have sin6_len? 1: Yes, 0: No])
 fi
-AC_SUBST(SET_IPV6_SETTINGS)
 
 dnl Check whether this OS defines ss_len as a member of sockaddr_storage
 AC_CACHE_CHECK([for ss_len field in struct sockaddr_storage],
index 25917df2afe1521a9e55cfe85eb9468894507ab8..f9350d4b505efa724e646b5b932b72e6722f43be 100644 (file)
@@ -224,12 +224,10 @@ xgetaddrinfo (const char *nodename, const char *servname,
         if (!(hints->ai_family == PF_UNSPEC || hints->ai_family == PF_INET))
             return EAI_FAMILY;
         break;
-#if USE_IPV6
     case AF_INET6:
         if (!(hints->ai_family == PF_UNSPEC || hints->ai_family == PF_INET6))
             return EAI_FAMILY;
         break;
-#endif
     default:
         return EAI_FAMILY;
     }
@@ -251,7 +249,6 @@ xgetaddrinfo (const char *nodename, const char *servname,
                     *addrs, hp->h_length);
             addrlen = sizeof (struct sockaddr_in);
             break;
-#if USE_IPV6
         case AF_INET6:
 #if SIN6_LEN
             ((struct sockaddr_in6 *) &sa)->sin6_len = hp->h_length;
@@ -261,7 +258,6 @@ xgetaddrinfo (const char *nodename, const char *servname,
                     *addrs, hp->h_length);
             addrlen = sizeof (struct sockaddr_in6);
             break;
-#endif
         default:
             continue;
         }
index 178521fb6db88ae9e3821bb920da4966e97cfa37..0abe1bc9894da02d1765f59d1b46fedf83cf6351 100644 (file)
@@ -780,7 +780,6 @@ cf.data: cf.data.pre Makefile
        -e "s%[@]DEFAULT_CONFIG_DIR[@]%$(DEFAULT_CONFIG_DIR)%g" \
        -e "s%[@]DEFAULT_PREFIX[@]%$(DEFAULT_PREFIX)%g" \
        -e "s%[@]DEFAULT_HOSTS[@]%$(DEFAULT_HOSTS)%g" \
-       -e "s%[@]IPV6_ONLY_SETTING[@]%$(SET_IPV6_SETTINGS)%g" \
        -e "s%[@]SQUID[@]%SQUID\ $(VERSION)%g" \
        < $(srcdir)/cf.data.pre >$@
 
index 982293be4421bfda2c49ddfec6113bbd3d909e4e..14be32b9bbc9d12d5b42d2a6b5b11fdebce55e87 100644 (file)
@@ -36,6 +36,7 @@
 #include "squid.h"
 #include "acl/Ip.h"
 #include "acl/Checklist.h"
+#include "ip/tools.h"
 #include "MemBuf.h"
 #include "wordlist.h"
 
@@ -108,12 +109,8 @@ acl_ip_data::toStr(char *buf, int len) const
     if (!mask.IsNoAddr()) {
         b3[0] = '/';
         rlen++;
-#if USE_IPV6
         int cidr =  mask.GetCIDR() - (addr1.IsIPv4()?96:0);
         snprintf(&(b3[1]), (len-rlen), "%u", (unsigned int)(cidr<0?0:cidr) );
-#else
-        snprintf(&(b3[1]), (len-rlen), "%u", mask.GetCIDR() );
-#endif
     } else
         b3[0] = '\0';
 }
@@ -224,9 +221,7 @@ acl_ip_data::DecodeMask(const char *asc, IpAddress &mask, int ctype)
             /* this will completely crap out with a security fail-open if the admin is playing mask tricks */
             /* however, thats their fault, and we do warn. see bug 2601 for the effects if we don't do this. */
             unsigned int m = mask.GetCIDR();
-#if USE_IPV6
             debugs(28, DBG_CRITICAL, "WARNING: IPv4 netmasks are particularly nasty when used to compare IPv6 to IPv4 ranges.");
-#endif
             debugs(28, DBG_CRITICAL, "WARNING: For now we will assume you meant to write /" << m);
             /* reset the mask completely, and crop to the CIDR boundary back properly. */
             mask.SetNoAddr();
@@ -287,7 +282,6 @@ acl_ip_data::FactoryParse(const char *t)
         return q;
     }
 
-#if USE_IPV6
     /* Special ACL RHS "ipv4" matches IPv4 Internet
      * A nod to IANA; we include the entire class space in case
      * they manage to find a way to recover and use it */
@@ -362,7 +356,6 @@ acl_ip_data::FactoryParse(const char *t)
 
         return r;
     }
-#endif
 
 // IPv4
     if (sscanf(t, SCAN_ACL1_4, addr1, addr2, mask) == 3) {
@@ -421,8 +414,9 @@ acl_ip_data::FactoryParse(const char *t)
             hints.ai_flags |= AI_NUMERICHOST;
         }
 
-#if 0 && USE_IPV6 && !IPV6_SPECIAL_SPLITSTACK
-        hints.ai_flags |= AI_V4MAPPED | AI_ALL;
+#if 0
+        if (Ip::EnableIpv6&IPV6_SPECIAL_V4MAPPING)
+            hints.ai_flags |= AI_V4MAPPED | AI_ALL;
 #endif
 
         int errcode = xgetaddrinfo(addr1,NULL,&hints,&hp);
@@ -473,13 +467,11 @@ acl_ip_data::FactoryParse(const char *t)
         return q;
     }
 
-#if !USE_IPV6
     /* ignore IPv6 addresses when built with IPv4-only */
-    if ( iptype == AF_INET6 ) {
-        debugs(28, 0, "aclIpParseIpData: IPv6 has not been enabled. build with '--enable-ipv6'");
+    if ( iptype == AF_INET6 && !Ip::EnableIpv6) {
+        debugs(28, DBG_IMPORTANT, "aclIpParseIpData: IPv6 has not been enabled.");
         return NULL;
     }
-#endif
 
     /* Decode addr1 */
     if (!*addr1 || !(q->addr1 = addr1)) {
index 29c9dd5b7be6781de25a0d955546c7b1e01074d2..f2863d2521634960922d8f49c5938c2498d9f0d7 100644 (file)
@@ -45,6 +45,7 @@
 #include "acl/MethodData.h"
 #include "acl/Gadgets.h"
 #include "StoreFileSystem.h"
+#include "ip/tools.h"
 #include "Parsing.h"
 #include "rfc1738.h"
 #include "MemBuf.h"
@@ -2825,7 +2826,6 @@ parse_IpAddress_list_token(IpAddress_list ** head, char *token)
     host = NULL;
     port = 0;
 
-#if USE_IPV6
     if (*token == '[') {
         /* [host]:port */
         host = token + 1;
@@ -2836,8 +2836,11 @@ parse_IpAddress_list_token(IpAddress_list ** head, char *token)
         if (*t != ':')
             self_destruct();
         port = xatos(t + 1);
+        if (!Ip::EnableIpv6) {
+            debugs(3, DBG_CRITICAL, "FATAL: IPv6 is not enabled.");
+            self_destruct();
+        }
     } else
-#endif
         if ((t = strchr(token, ':'))) {
             /* host:port */
             host = token;
@@ -2929,7 +2932,6 @@ parse_http_port_specification(http_port_list * s, char *token)
     s->name = xstrdup(token);
     s->connection_auth_disabled = false;
 
-#if USE_IPV6
     if (*token == '[') {
         /* [ipv6]:port */
         host = token + 1;
@@ -2943,23 +2945,25 @@ parse_http_port_specification(http_port_list * s, char *token)
             debugs(3, 0, "http(s)_port: missing Port in: " << token);
             self_destruct();
         }
-        port = xatos(t + 1);
-    } else
-#endif
-        if ((t = strchr(token, ':'))) {
-            /* host:port */
-            /* ipv4:port */
-            host = token;
-            *t = '\0';
-            port = xatos(t + 1);
-
-        } else if ((port = strtol(token, &junk, 10)), !*junk) {
-            /* port */
-            debugs(3, 3, "http(s)_port: found Listen on Port: " << port);
-        } else {
-            debugs(3, 0, "http(s)_port: missing Port: " << token);
+        if (!Ip::EnableIpv6) {
+            debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: IPv6 is not available.");
             self_destruct();
         }
+        port = xatos(t + 1);
+    } else if ((t = strchr(token, ':'))) {
+        /* host:port */
+        /* ipv4:port */
+        host = token;
+        *t = '\0';
+        port = xatos(t + 1);
+
+    } else if ((port = strtol(token, &junk, 10)), !*junk) {
+        /* port */
+        debugs(3, 3, "http(s)_port: found Listen on Port: " << port);
+    } else {
+        debugs(3, 0, "http(s)_port: missing Port: " << token);
+        self_destruct();
+    }
 
     if (port == 0) {
         debugs(3, 0, "http(s)_port: Port cannot be 0: " << token);
@@ -2969,14 +2973,20 @@ parse_http_port_specification(http_port_list * s, char *token)
     if (NULL == host) {
         s->s.SetAnyAddr();
         s->s.SetPort(port);
+        if (!Ip::EnableIpv6)
+            s->s.SetIPv4();
         debugs(3, 3, "http(s)_port: found Listen on wildcard address: *:" << s->s.GetPort() );
     } else if ( s->s = host ) { /* check/parse numeric IPA */
         s->s.SetPort(port);
+        if (!Ip::EnableIpv6)
+            s->s.SetIPv4();
         debugs(3, 3, "http(s)_port: Listen on Host/IP: " << host << " --> " << s->s);
     } else if ( s->s.GetHostByName(host) ) { /* check/parse for FQDN */
         /* dont use ipcache */
         s->defaultsite = xstrdup(host);
         s->s.SetPort(port);
+        if (!Ip::EnableIpv6)
+            s->s.SetIPv4();
         debugs(3, 3, "http(s)_port: found Listen as Host " << s->defaultsite << " on IP: " << s->s);
     } else {
         debugs(3, 0, "http(s)_port: failed to resolve Host/IP: " << host);
@@ -3043,14 +3053,13 @@ parse_http_port_option(http_port_list * s, char *token)
         debugs(3, DBG_IMPORTANT, "Starting Authentication on port " << s->s);
         debugs(3, DBG_IMPORTANT, "Disabling Authentication on port " << s->s << " (interception enabled)");
 
-#if USE_IPV6
         /* INET6: until transparent REDIRECT works on IPv6 SOCKET, force wildcard to IPv4 */
-        debugs(3, DBG_IMPORTANT, "Disabling IPv6 on port " << s->s << " (interception enabled)");
+        if (Ip::EnableIpv6)
+            debugs(3, DBG_IMPORTANT, "Disabling IPv6 on port " << s->s << " (interception enabled)");
         if ( !s->s.SetIPv4() ) {
             debugs(3, DBG_CRITICAL, "http(s)_port: IPv6 addresses cannot be transparent (protocol does not provide NAT)" << s->s );
             self_destruct();
         }
-#endif
     } else if (strcmp(token, "tproxy") == 0) {
         if (s->intercepted || s->accel) {
             debugs(3,DBG_CRITICAL, "http(s)_port: TPROXY option requires its own interception port. It cannot be shared.");
@@ -3068,12 +3077,10 @@ parse_http_port_option(http_port_list * s, char *token)
         }
 
     } else if (strcmp(token, "ipv4") == 0) {
-#if USE_IPV6
         if ( !s->s.SetIPv4() ) {
-            debugs(3, 0, "http(s)_port: IPv6 addresses cannot be used a IPv4-Only." << s->s );
+            debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: IPv6 addresses cannot be used as IPv4-Only. " << s->s );
             self_destruct();
         }
-#endif
     } else if (strcmp(token, "tcpkeepalive") == 0) {
         s->tcp_keepalive.enabled = 1;
     } else if (strncmp(token, "tcpkeepalive=", 13) == 0) {
@@ -3161,7 +3168,6 @@ add_http_port(char *portspec)
     Config.Sockaddr.http = s;
 }
 
-#if IPV6_SPECIAL_SPLITSTACK
 http_port_list *
 clone_http_port_list(http_port_list *a)
 {
@@ -3211,7 +3217,6 @@ clone_http_port_list(http_port_list *a)
 
     return b;
 }
-#endif
 
 static void
 parse_http_port_list(http_port_list ** head)
@@ -3230,14 +3235,12 @@ parse_http_port_list(http_port_list ** head)
         parse_http_port_option(s, token);
     }
 
-#if IPV6_SPECIAL_SPLITSTACK
-    if (s->s.IsAnyAddr()) {
+    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->s.SetIPv4();
         debugs(3, 3, "http(s)_port: clone wildcard address for split-stack: " << s->s << " and " << s->next->s);
     }
-#endif
 
     while (*head)
         head = &(*head)->next;
index f2f033f5459b7a684d24dc0a393ff19646e6fe47..57dba6a57a6384f115bee14ef83d67a82d48303b 100644 (file)
@@ -401,7 +401,7 @@ DOC_START
          protocol=2.5  Compatibility mode for Squid-2.5 external acl helpers
          ipv4 / ipv6   IP-mode used to communicate to this helper.
                        For compatability with older configurations and helpers
-                       the default is 'ipv4'.
+                       the default is currently 'ipv4'.
 
        FORMAT specifications
 
@@ -693,10 +693,8 @@ NOCOMMENT_START
 # Recommended minimum configuration:
 #
 acl manager proto cache_object
-acl localhost src 127.0.0.1/32
-@IPV6_ONLY_SETTING@acl localhost src ::1/128
-acl to_localhost dst 127.0.0.0/8 0.0.0.0/32
-@IPV6_ONLY_SETTING@acl to_localhost dst ::1/128
+acl localhost src 127.0.0.1/32 ::1
+acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1
 
 # Example rule allowing access from your local networks.
 # Adapt to list your (internal) IP networks from where browsing
@@ -704,8 +702,8 @@ acl to_localhost dst 127.0.0.0/8 0.0.0.0/32
 acl localnet src 10.0.0.0/8    # RFC1918 possible internal network
 acl localnet src 172.16.0.0/12 # RFC1918 possible internal network
 acl localnet src 192.168.0.0/16        # RFC1918 possible internal network
-@IPV6_ONLY_SETTING@acl localnet src fc00::/7   # RFC 4193 local private network range
-@IPV6_ONLY_SETTING@acl localnet src fe80::/10  # RFC 4291 link-local (directly plugged) machines
+acl localnet src fc00::/7       # RFC 4193 local private network range
+acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines
 
 acl SSL_ports port 443
 acl Safe_ports port 80         # http
index 77697e2f37be182400dc8d89cf2cdbf9609f25c7..b91c034786d70d982fd68f59798dbd92677edc0c 100644 (file)
@@ -420,12 +420,10 @@ snmp_meshCtblFn(variable_list * Var, snint * ErrP)
     *ErrP = SNMP_ERR_NOERROR;
     MemBuf tmp;
     debugs(49, 6, HERE << "Current : length=" << Var->name_length << ": " << snmpDebugOid(Var->name, Var->name_length, tmp));
-    if (Var->name_length == 16 ) {
+    if (Var->name_length == 16) {
         oid2addr(&(Var->name[12]), keyIp, 4);
-#if USE_IPV6
-    } else if (Var->name_length == 28 ) {
+    } else if (Var->name_length == 28) {
         oid2addr(&(Var->name[12]), keyIp, 16);
-#endif
     } else {
         *ErrP = SNMP_ERR_NOSUCHNAME;
         return NULL;
index a3f4b8d90d79b51abf374b7c7e61e32d766631c1..dc185fea079b5d6a21dab70fe6c49d609305b0fe 100644 (file)
@@ -2990,7 +2990,7 @@ connStateCreate(const IpAddress &peer, const IpAddress &me, int fd, http_port_li
 
     result->peer = peer;
     result->log_addr = peer;
-    result->log_addr.ApplyMask(Config.Addrs.client_netmask.GetCIDR());
+    result->log_addr.ApplyMask(Config.Addrs.client_netmask);
     result->me = me;
     result->fd = fd;
     result->in.buf = (char *)memAllocBuf(CLIENT_REQ_BUF_SZ, &result->in.allocatedSize);
index 4459e85c1c93a1edfa564080697d57d2c8daaae2..4937bb2874abb182d396e545d65a84ee90ef0572 100644 (file)
@@ -49,6 +49,7 @@
 #include "ip/IpAddress.h"
 #include "ip/IpIntercept.h"
 #include "protos.h"
+#include "ip/tools.h"
 
 #if defined(_SQUID_CYGWIN_)
 #include <sys/ioctl.h>
@@ -562,10 +563,8 @@ comm_local_port(int fd)
     if (F->local_addr.GetPort())
         return F->local_addr.GetPort();
 
-#if USE_IPV6
     if (F->sock_family == AF_INET)
         temp.SetIPv4();
-#endif
 
     temp.InitAddrInfo(addr);
 
@@ -722,10 +721,10 @@ comm_openex(int sock_type,
     debugs(50, 3, "comm_openex: Attempt open socket for: " << addr );
 
     new_socket = socket(AI->ai_family, AI->ai_socktype, AI->ai_protocol);
-#if USE_IPV6
+
     /* under IPv6 there is the possibility IPv6 is present but disabled. */
     /* try again as IPv4-native if possible */
-    if ( new_socket < 0 && addr.IsIPv6() && addr.SetIPv4() ) {
+    if ( new_socket < 0 && Ip::EnableIpv6 && addr.IsIPv6() && addr.SetIPv4() ) {
         /* attempt to open this IPv4-only. */
         addr.FreeAddrInfo(AI);
         /* Setup the socket addrinfo details for use */
@@ -736,7 +735,6 @@ comm_openex(int sock_type,
         new_socket = socket(AI->ai_family, AI->ai_socktype, AI->ai_protocol);
         debugs(50, 2, HERE << "attempt open " << note << " socket on: " << addr);
     }
-#endif
 
     if (new_socket < 0) {
         /* Increase the number of reserved fd's if calls to socket()
@@ -763,22 +761,14 @@ comm_openex(int sock_type,
         tos = TOS;
     }
 
-#if IPV6_SPECIAL_SPLITSTACK
-
-    if ( addr.IsIPv6() )
+    if ( Ip::EnableIpv6&IPV6_SPECIAL_SPLITSTACK && addr.IsIPv6() )
         comm_set_v6only(new_socket, 1);
 
-#endif
-
-#if IPV6_SPECIAL_V4MAPPED
-
     /* Windows Vista supports Dual-Sockets. BUT defaults them to V6ONLY. Turn it OFF. */
     /* Other OS may have this administratively disabled for general use. Same deal. */
-    if ( addr.IsIPv6() )
+    if ( Ip::EnableIpv6&IPV6_SPECIAL_V4MAPPING && addr.IsIPv6() )
         comm_set_v6only(new_socket, 0);
 
-#endif
-
     /* update fdstat */
     debugs(5, 5, "comm_open: FD " << new_socket << " is a new socket");
 
@@ -1060,10 +1050,8 @@ ConnectStateData::commResetFD()
     if (F->tos)
         comm_set_tos(fd, F->tos);
 
-#if IPV6_SPECIAL_SPLITSTACK
-    if ( F->local_addr.IsIPv6() )
+    if ( Ip::EnableIpv6&IPV6_SPECIAL_SPLITSTACK && F->local_addr.IsIPv6() )
         comm_set_v6only(fd, 1);
-#endif
 
     copyFDFlags(fd, F);
 
@@ -1441,11 +1429,7 @@ comm_old_accept(int fd, ConnectionDetail &details)
     details.peer.NtoA(F->ipaddr,MAX_IPSTRLEN);
     F->remote_port = details.peer.GetPort();
     F->local_addr.SetPort(details.me.GetPort());
-#if USE_IPV6
-    F->sock_family = details.me.IsIPv4()?AF_INET:AF_INET6;
-#else
-    F->sock_family = AF_INET;
-#endif
+    F->sock_family = details.me.IsIPv6()?AF_INET6:AF_INET;
     details.me.FreeAddrInfo(gai);
 
     commSetNonBlocking(sock);
index 2b9639b0348a8774ebdc355df3e1a27e927fb190..9b00ea363130ab1df6450e13820a77dfd68fa12f 100644 (file)
@@ -580,15 +580,14 @@ comm_poll_dns_incoming(void)
     int nevents;
     dns_io_events = 0;
 
-    if (DnsSocketA < 0)
+    if (DnsSocketA < 0 && DnsSocketB < 0)
         return;
 
-    fds[nfds++] = DnsSocketA;
+    if (DnsSocketA >= 0)
+        fds[nfds++] = DnsSocketA;
 
-#if IPV6_SPECIAL_SPLITSTACK
-    if (DnsSocketB > 0)
+    if (DnsSocketB >= 0)
         fds[nfds++] = DnsSocketB;
-#endif
 
     nevents = comm_check_incoming_poll_handlers(nfds, fds);
 
index 95500c7af36bf734677ef80f70be3f064a84105d..8d1a330db17adaae3cd8a33ab8082541010ba8d8 100644 (file)
@@ -632,15 +632,14 @@ comm_select_dns_incoming(void)
     int nevents;
     dns_io_events = 0;
 
-    if (DnsSocketA < 0)
+    if (DnsSocketA < 0 && DnsSocketB < 0)
         return;
 
-    fds[nfds++] = DnsSocketA;
+    if (DnsSocketA >= 0)
+        fds[nfds++] = DnsSocketA;
 
-#if IPV6_SPECIAL_SPLITSTACK
-    if (DnsSocketB > 0)
+    if (DnsSocketB >= 0)
         fds[nfds++] = DnsSocketB;
-#endif
 
     nevents = comm_check_incoming_select_handlers(nfds, fds);
 
index cdb572589f6fce6fd909fd06f1b704d0e20b6302..edada5c6d15389353ade4cb9c6a57aed11f478ec 100644 (file)
@@ -654,15 +654,14 @@ comm_select_dns_incoming(void)
     int nevents;
     dns_io_events = 0;
 
-    if (DnsSocketA < 0)
+    if (DnsSocketA < 0 && DnsSocketB < 0)
         return;
 
-    fds[nfds++] = DnsSocketA;
+    if (DnsSocketA >= 0)
+        fds[nfds++] = DnsSocketA;
 
-#if IPV6_SPECIAL_SPLITSTACK
-    if (DnsSocketB > 0)
+    if (DnsSocketB >= 0)
         fds[nfds++] = DnsSocketB;
-#endif
 
     nevents = comm_check_incoming_select_handlers(nfds, fds);
 
index f2c4f1e6660dbc5d019ccd636b738eb739a270be..6512b6ce9acd3ba5c80d9a0382175cd3ba5dd496 100644 (file)
@@ -41,6 +41,7 @@
 #include "Store.h"
 #include "comm.h"
 #include "fde.h"
+#include "ip/tools.h"
 #include "MemBuf.h"
 
 #include "wordlist.h"
@@ -814,11 +815,9 @@ idnsSendQuery(idns_query * q)
             idnsSendQueryVC(q, ns);
             x = y = 0;
         } else {
-#if IPV6_SPECIAL_SPLITSTACK
-            if (nameservers[ns].S.IsIPv6() && DnsSocketB > 0)
+            if (DnsSocketB >= 0 && nameservers[ns].S.IsIPv6())
                 y = comm_udp_sendto(DnsSocketB, nameservers[ns].S, q->buf, q->sz);
             else
-#endif
                 x = comm_udp_sendto(DnsSocketA, nameservers[ns].S, q->buf, q->sz);
         }
 
@@ -826,23 +825,17 @@ idnsSendQuery(idns_query * q)
 
         q->queue_t = q->sent_t = current_time;
 
-#if IPV6_SPECIAL_SPLITSTACK
         if (y < 0 && nameservers[ns].S.IsIPv6())
             debugs(50, 1, "idnsSendQuery: FD " << DnsSocketB << ": sendto: " << xstrerror());
         if (x < 0 && nameservers[ns].S.IsIPv4())
-#else
-        if (x < 0)
-#endif
             debugs(50, 1, "idnsSendQuery: FD " << DnsSocketA << ": sendto: " << xstrerror());
 
     } while ( (x<0 && y<0) && q->nsends % nns != 0);
 
-#if IPV6_SPECIAL_SPLITSTACK
     if (y >= 0) {
         fd_bytes(DnsSocketB, y, FD_WRITE);
         commSetSelect(DnsSocketB, COMM_SELECT_READ, idnsRead, NULL, 0);
     }
-#endif
 
     if (x >= 0) {
         fd_bytes(DnsSocketA, x, FD_WRITE);
@@ -1036,13 +1029,10 @@ idnsGrokReply(const char *buf, size_t sz)
             q->start_t = current_time;
             q->id = idnsQueryID();
             rfc1035SetQueryID(q->buf, q->id);
-#if USE_IPV6
-            if (q->query.qtype == RFC1035_TYPE_AAAA) {
+            if (Ip::EnableIpv6 && q->query.qtype == RFC1035_TYPE_AAAA) {
                 debugs(78, 3, "idnsGrokReply: Trying AAAA Query for " << q->name);
                 q->sz = rfc3596BuildAAAAQuery(q->name, q->buf, sizeof(q->buf), q->id, &q->query);
-            } else
-#endif
-            {
+            } else {
                 debugs(78, 3, "idnsGrokReply: Trying A Query for " << q->name);
                 q->sz = rfc3596BuildAQuery(q->name, q->buf, sizeof(q->buf), q->id, &q->query);
             }
@@ -1052,7 +1042,6 @@ idnsGrokReply(const char *buf, size_t sz)
         }
     }
 
-#if USE_IPV6
     if (q->need_A && (Config.onoff.dns_require_A == 1 || n <= 0 ) ) {
         /* ERROR or NO AAAA exist. Failover to A records. */
         /*      Apparently its also a good idea to lookup and store the A records
@@ -1089,7 +1078,6 @@ idnsGrokReply(const char *buf, size_t sz)
         idnsSendQuery(q);
         return;
     }
-#endif
 
     /** If there are two result sets from preceeding AAAA and A lookups merge them with a preference for AAAA */
     if (q->initial_AAAA.count > 0 && n > 0) {
@@ -1172,12 +1160,7 @@ idnsRead(int fd, void *data)
             break;
         }
 
-#if IPV6_SPECIAL_SPLITSTACK
-        if ( from.IsIPv6() )
-            fd_bytes(DnsSocketB, len, FD_READ);
-        else
-#endif
-            fd_bytes(DnsSocketA, len, FD_READ);
+        fd_bytes(fd, len, FD_READ);
 
         assert(N);
         (*N)++;
@@ -1205,12 +1188,7 @@ idnsRead(int fd, void *data)
     }
 
     if (lru_list.head) {
-#if IPV6_SPECIAL_SPLITSTACK
-        if ( from.IsIPv6() )
-            commSetSelect(DnsSocketB, COMM_SELECT_READ, idnsRead, NULL, 0);
-        else
-#endif
-            commSetSelect(DnsSocketA, COMM_SELECT_READ, idnsRead, NULL, 0);
+        commSetSelect(fd, COMM_SELECT_READ, idnsRead, NULL, 0);
     }
 }
 
@@ -1361,42 +1339,33 @@ idnsInit(void)
     if (DnsSocketA < 0 && DnsSocketB < 0) {
         int port;
 
-        IpAddress addr; // since we don't want to alter Config.Addrs.udp_* and dont have one of our own.
+        IpAddress addrA; // since we don't want to alter Config.Addrs.udp_* and dont have one of our own.
 
         if (!Config.Addrs.udp_outgoing.IsNoAddr())
-            addr = Config.Addrs.udp_outgoing;
+            addrA = Config.Addrs.udp_outgoing;
         else
-            addr = Config.Addrs.udp_incoming;
+            addrA = Config.Addrs.udp_incoming;
 
-#if IPV6_SPECIAL_SPLITSTACK
-        IpAddress addr4 = addr;
+        IpAddress addrB = addrA;
+        addrA.SetIPv4();
 
-        if ( addr.IsAnyAddr() || addr.IsIPv6() ) {
-            debugs(78, 2, "idnsInit: attempt open DNS socket to: " << addr);
+        if (Ip::EnableIpv6 && (addrB.IsAnyAddr() || addrB.IsIPv6())) {
+            debugs(78, 2, "idnsInit: attempt open DNS socket to: " << addrB);
             DnsSocketB = comm_open_listener(SOCK_DGRAM,
                                             IPPROTO_UDP,
-                                            addr,
+                                            addrB,
                                             COMM_NONBLOCKING,
-                                            "DNS Socket v6");
+                                            "DNS Socket IPv6");
         }
 
-        if ( addr.IsAnyAddr() || addr.IsIPv4() ) {
-            addr4.SetIPv4();
-            debugs(78, 2, "idnsInit: attempt open DNS socket to: " << addr4);
+        if (addrA.IsAnyAddr() || addrA.IsIPv4()) {
+            debugs(78, 2, "idnsInit: attempt open DNS socket to: " << addrA);
             DnsSocketA = comm_open_listener(SOCK_DGRAM,
                                             IPPROTO_UDP,
-                                            addr4,
+                                            addrA,
                                             COMM_NONBLOCKING,
-                                            "DNS Socket v4");
+                                            "DNS Socket IPv4");
         }
-#else
-        DnsSocketA = comm_open_listener(SOCK_DGRAM,
-                                        IPPROTO_UDP,
-                                        addr,
-                                        COMM_NONBLOCKING,
-                                        "DNS Socket");
-        debugs(78, 2, "idnsInit: attempt open DNS socket to: " << addr);
-#endif
 
         if (DnsSocketA < 0 && DnsSocketB < 0)
             fatal("Could not create a DNS socket");
@@ -1404,19 +1373,13 @@ idnsInit(void)
         /* Ouch... we can't call functions using debug from a debug
          * statement. Doing so messes up the internal Debug::level
          */
-#if IPV6_SPECIAL_SPLITSTACK
         if (DnsSocketB >= 0) {
             port = comm_local_port(DnsSocketB);
-            debugs(78, 1, "DNS Socket created at " << addr << ", FD " << DnsSocketB);
+            debugs(78, 1, "DNS Socket created at " << addrB << ", FD " << DnsSocketB);
         }
-#endif
         if (DnsSocketA >= 0) {
             port = comm_local_port(DnsSocketA);
-#if IPV6_SPECIAL_SPLITSTACK
-            debugs(78, 1, "DNS Socket created at " << addr4 << ", FD " << DnsSocketA);
-#else
-            debugs(78, 1, "DNS Socket created at " << addr << ", FD " << DnsSocketA);
-#endif
+            debugs(78, 1, "DNS Socket created at " << addrA << ", FD " << DnsSocketA);
         }
     }
 
@@ -1470,12 +1433,10 @@ idnsShutdown(void)
         DnsSocketA = -1;
     }
 
-#if IPV6_SPECIAL_SPLITSTACK
-    if (DnsSocketA >= 0 ) {
+    if (DnsSocketB >= 0 ) {
         comm_close(DnsSocketB);
         DnsSocketB = -1;
     }
-#endif
 
     for (int i = 0; i < nns; i++) {
         if (nsvc *vc = nameservers[i].vc) {
@@ -1552,13 +1513,13 @@ idnsALookup(const char *name, IDNSCB * callback, void *data)
         debugs(78, 3, "idnsALookup: searchpath used for " << q->name);
     }
 
-#if USE_IPV6
-    q->sz = rfc3596BuildAAAAQuery(q->name, q->buf, sizeof(q->buf), q->id, &q->query);
-    q->need_A = true;
-#else
-    q->sz = rfc3596BuildAQuery(q->name, q->buf, sizeof(q->buf), q->id, &q->query);
-    q->need_A = false;
-#endif
+    if (Ip::EnableIpv6) {
+        q->sz = rfc3596BuildAAAAQuery(q->name, q->buf, sizeof(q->buf), q->id, &q->query);
+        q->need_A = true;
+    } else {
+        q->sz = rfc3596BuildAQuery(q->name, q->buf, sizeof(q->buf), q->id, &q->query);
+        q->need_A = false;
+    }
 
     if (q->sz < 0) {
         /* problem with query data -- query not sent */
@@ -1594,14 +1555,11 @@ idnsPTRLookup(const IpAddress &addr, IDNSCB * callback, void *data)
 
     q->id = idnsQueryID();
 
-#if USE_IPV6
-    if ( addr.IsIPv6() ) {
+    if (Ip::EnableIpv6 && addr.IsIPv6()) {
         struct in6_addr addr6;
         addr.GetInAddr(addr6);
         q->sz = rfc3596BuildPTRQuery6(addr6, q->buf, sizeof(q->buf), q->id, &q->query);
-    } else
-#endif
-    {
+    } else {
         struct in_addr addr4;
         addr.GetInAddr(addr4);
         q->sz = rfc3596BuildPTRQuery4(addr4, q->buf, sizeof(q->buf), q->id, &q->query);
index 871af9155c7f959f902b83f57982ddbca6193b13..99ffb14337002ec94530d4d4976ce09aa085e915 100644 (file)
@@ -267,11 +267,9 @@ lookup(const char *buf)
                 case AF_INET:
                     xinet_ntop(aiptr->ai_family, &((struct sockaddr_in*)aiptr->ai_addr)->sin_addr, ntoabuf, MAX_IPSTRLEN);
                     break;
-#if USE_IPV6
                 case AF_INET6:
                     xinet_ntop(aiptr->ai_family, &((struct sockaddr_in6*)aiptr->ai_addr)->sin6_addr, ntoabuf, MAX_IPSTRLEN);
                     break;
-#endif
                 default:
                     aiptr = aiptr->ai_next;
                     continue;
index 5bc3c56e27ee8bd891c7fa7cd44cf77ee6355894..def991913a33f64bbd019034763db8489057fa92 100644 (file)
@@ -53,6 +53,7 @@
 #if USE_IDENT
 #include "ident/AclIdent.h"
 #endif
+#include "ip/tools.h"
 #include "client_side.h"
 #include "HttpRequest.h"
 #include "HttpReply.h"
@@ -336,11 +337,9 @@ parse_externalAclHelper(external_acl ** list)
                 debugs(3, 0, "WARNING: Error converting " << a->local_addr << " to IPv4 in " << a->name );
             }
         } else if (strcmp(token, "ipv6") == 0) {
-#if !USE_IPV6
-            debugs(3, 0, "WARNING: --enable-ipv6 required for external ACL helpers to use IPv6: " << a->name );
-#else
-            (void)0;
-#endif
+            if (!Ip::EnableIpv6)
+                debugs(3, 0, "WARNING: --enable-ipv6 required for external ACL helpers to use IPv6: " << a->name );
+            // else nothing to do.
         } else {
             break;
         }
index 745c684489ca4237427b42b7a6c3fa422cc810fc..5b72df2e9ab4565bcf50088c912b2b52a7f4dc90 100644 (file)
@@ -49,6 +49,7 @@
 #include "ConnectionDetail.h"
 #include "forward.h"
 #include "Server.h"
+#include "ip/tools.h"
 #include "MemBuf.h"
 #include "wordlist.h"
 #include "SquidTime.h"
@@ -2470,6 +2471,7 @@ ftpReadEPSV(FtpStateData* ftpState)
         /* server response with list of supported methods   */
         /*   522 Network protocol not supported, use (1)    */
         /*   522 Network protocol not supported, use (1,2)  */
+        /*   522 Network protocol not supported, use (2)  */
         /* TODO: handle the (1,2) case. We might get it back after EPSV ALL
          * which means close data + control without self-destructing and re-open from scratch. */
         debugs(9, 5, HERE << "scanning: " << ftpState->ctrl.last_reply);
@@ -2485,20 +2487,19 @@ ftpReadEPSV(FtpStateData* ftpState)
             ftpState->state = SENT_EPSV_2; /* simulate having sent and failed EPSV 2 */
             ftpSendPassive(ftpState);
         } else if (strcmp(buf, "(2)") == 0) {
-#if USE_IPV6
-            /* If server only supports EPSV 2 and we have already tried that. Go straight to EPRT */
-            if (ftpState->state == SENT_EPSV_2) {
-                ftpSendEPRT(ftpState);
+            if (Ip::EnableIpv6) {
+                /* If server only supports EPSV 2 and we have already tried that. Go straight to EPRT */
+                if (ftpState->state == SENT_EPSV_2) {
+                    ftpSendEPRT(ftpState);
+                } else {
+                    /* or try the next Passive mode down the chain. */
+                    ftpSendPassive(ftpState);
+                }
             } else {
-                /* or try the next Passive mode down the chain. */
+                /* Server only accept EPSV in IPv6 traffic. */
+                ftpState->state = SENT_EPSV_1; /* simulate having sent and failed EPSV 1 */
                 ftpSendPassive(ftpState);
             }
-#else
-            /* We do not support IPv6. Remote server requires it.
-               So we must simulate having failed all EPSV methods. */
-            ftpState->state = SENT_EPSV_1;
-            ftpSendPassive(ftpState);
-#endif
         } else {
             /* handle broken server (RFC 2428 says MUST specify supported protocols in 522) */
             debugs(9, DBG_IMPORTANT, "WARNING: Server at " << fd_table[ftpState->ctrl.fd].ipaddr << " sent unknown protocol negotiation hint: " << buf);
@@ -2671,13 +2672,11 @@ ftpSendPassive(FtpStateData * ftpState)
             /* block other non-EPSV connections being attempted */
             ftpState->flags.epsv_all_sent = true;
         } else {
-#if USE_IPV6
             if (addr.IsIPv6()) {
                 debugs(9, 5, HERE << "FTP Channel (" << addr << "). Sending default EPSV 2");
                 snprintf(cbuf, 1024, "EPSV 2\r\n");
                 ftpState->state = SENT_EPSV_2;
             }
-#endif
             if (addr.IsIPv4()) {
                 debugs(9, 5, HERE << "Channel (" << addr <<"). Sending default EPSV 1");
                 snprintf(cbuf, 1024, "EPSV 1\r\n");
@@ -2954,7 +2953,6 @@ ftpSendPORT(FtpStateData * ftpState)
         return;
     }
 
-#if USE_IPV6
     if ( AI->ai_addrlen != sizeof(struct sockaddr_in) ) {
         ipa.FreeAddrInfo(AI);
         /* IPv6 CANNOT send PORT command.                           */
@@ -2963,7 +2961,6 @@ ftpSendPORT(FtpStateData * ftpState)
         ftpReadPORT(ftpState);
         return;
     }
-#endif
 
     addrptr = (unsigned char *) &((struct sockaddr_in*)AI->ai_addr)->sin_addr;
     portptr = (unsigned char *) &((struct sockaddr_in*)AI->ai_addr)->sin_port;
index d9b9715c04310bb30b53a928966d27a36d8b808a..f30d7f64713a21aaef1ed797d1dadd1012a7e51c 100644 (file)
@@ -39,9 +39,7 @@
 
 #define MAX_PAYLOAD 256 // WAS: SQUIDHOSTNAMELEN
 #define MAX_PKT4_SZ (MAX_PAYLOAD + sizeof(struct timeval) + sizeof (char) + sizeof(struct icmphdr) + 1)
-#if USE_IPV6
 #define MAX_PKT6_SZ (MAX_PAYLOAD + sizeof(struct timeval) + sizeof (char) + sizeof(struct icmp6_hdr) + 1)
-#endif
 
 #if USE_ICMP
 
index 9f0e492ba07941fb5ce676ec9cc3319659de3b92..f37e23766de8fbc3be1cb88330020408fb1f44d7 100644 (file)
@@ -35,7 +35,7 @@
 
 #include "squid.h"
 
-#if USE_ICMP && USE_IPV6
+#if USE_ICMP
 
 #include "SquidTime.h"
 #include "Debug.h"
@@ -338,4 +338,4 @@ Icmp6::Recv(void)
     control.SendResult(preply, (sizeof(pingerReplyData) - PINGER_PAYLOAD_SZ + preply.psize) );
 }
 
-#endif /* USE_ICMP && USE_IPV6 */
+#endif /* USE_ICMP */
index edcc5ddea3534adfb7230f77155ab090d86ae2ce..7b688f1672e55586532123b4a3b2627027c90329 100644 (file)
@@ -34,8 +34,6 @@
 
 #include "config.h"
 
-#if USE_IPV6
-
 #include "Icmp.h"
 
 #if HAVE_NETINET_IN_H
@@ -87,5 +85,4 @@ public:
 SQUIDCEXTERN Icmp6 icmp6;
 
 #endif /* USE_ICMP && SQUID_HELPER */
-#endif /* USE_IPV6 */
 #endif /* _INCLUDE_ICMPV6_H */
index 773f235372bce15d162f47f05ab68b7a0305e5fb..88398b4d542fe44c7288d10f023316bbd36aab78 100644 (file)
@@ -171,9 +171,7 @@ IcmpPinger::Close(void)
 
     /* also shutdown the helper engines */
     icmp4.Close();
-#if USE_IPV6
     icmp6.Close();
-#endif
 }
 
 void
@@ -208,7 +206,6 @@ IcmpPinger::Recv(void)
         return;
     }
 
-#if USE_IPV6
     /* pass request for ICMPv6 handing */
     if (pecho.to.IsIPv6()) {
         debugs(42, 2, HERE << " Pass " << pecho.to << " off to ICMPv6 module.");
@@ -217,7 +214,6 @@ IcmpPinger::Recv(void)
                        pecho.payload,
                        pecho.psize);
     }
-#endif
 
     /* pass the packet for ICMP handling */
     else if (pecho.to.IsIPv4()) {
index ea45720699d6bd6e8410def9652dae68a59a8810..6250a670afe3fd0a940e4c9353b537d4b3d131f4 100644 (file)
@@ -35,6 +35,7 @@
 #include "squid.h"
 #include "icmp/IcmpSquid.h"
 #include "icmp/net_db.h"
+#include "ip/tools.h"
 #include "comm.h"
 #include "SquidTime.h"
 
@@ -253,9 +254,8 @@ IcmpSquid::Open(void)
     debugs(37, 1, HERE << "Pinger socket opened on FD " << icmp_sock);
 
     /* Tests the pinger immediately using localhost */
-#if USE_IPV6
-    SendEcho(localhost, S_ICMP_ECHO, "ip6-localhost");
-#endif
+    if (Ip::EnableIpv6)
+        SendEcho(localhost, S_ICMP_ECHO, "ip6-localhost");
     if (localhost.SetIPv4())
         SendEcho(localhost, S_ICMP_ECHO, "localhost");
 
index 38b1c238e7c483a9016f11af49826289cfc11142..dcaebb612f87fa8ddad9c4623fdf4389d6e0306f 100644 (file)
@@ -344,16 +344,13 @@ networkFromInaddr(const IpAddress &in)
     IpAddress out;
 
     out = in;
-#if USE_IPV6
 
     /* in IPv6 the 'network' should be the routing section. */
-
     if ( in.IsIPv6() ) {
         out.ApplyMask(64, AF_INET6);
         debugs(14, 5, "networkFromInaddr : Masked IPv6 Address to " << in << "/64 routing part.");
         return out;
     }
-#endif
 
 #if USE_CLASSFUL
     struct in_addr b;
index d3380bd7228db0b92d65de51f531f663c7121e77..4837ad59d7a3ce6d84cc96b619cb6f7a55073528 100644 (file)
@@ -109,9 +109,7 @@ Win32__WSAFDIsSet(int fd, fd_set FAR * set)
 // ICMP Engines are declared global here so they can call each other easily.
 IcmpPinger control;
 Icmp4 icmp4;
-#if USE_IPV6
 Icmp6 icmp6;
-#endif
 
 int icmp_pkts_sent = 0;
 
@@ -139,9 +137,7 @@ main(int argc, char *argv[])
      * drop privs
      */
     int icmp4_worker = -1;
-#if USE_IPV6
     int icmp6_worker = -1;
-#endif
     int squid_link = -1;
 
     /** start by initializing the pinger debug cache.log-pinger. */
@@ -160,31 +156,22 @@ main(int argc, char *argv[])
     }
     max_fd = max(max_fd, icmp4_worker);
 
-#if USE_IPV6
     icmp6_worker = icmp6.Open();
     if (icmp6_worker <0 ) {
         debugs(42, 0, "pinger: Unable to start ICMPv6 pinger.");
     }
     max_fd = max(max_fd, icmp6_worker);
-#endif
 
     /** abort if neither worker could open a socket. */
-    if (icmp4_worker == -1) {
-#if USE_IPV6
-        if (icmp6_worker == -1)
-#endif
-        {
-            debugs(42, 0, "FATAL: pinger: Unable to open any ICMP sockets.");
-            exit(1);
-        }
+    if (icmp4_worker < 0 && icmp6_worker < 0) {
+        debugs(42, 0, "FATAL: pinger: Unable to open any ICMP sockets.");
+        exit(1);
     }
 
     if ( (squid_link = control.Open()) < 0) {
         debugs(42, 0, "FATAL: pinger: Unable to setup Pinger control sockets.");
         icmp4.Close();
-#if USE_IPV6
         icmp6.Close();
-#endif
         exit(1); // fatal error if the control channel fails.
     }
     max_fd = max(max_fd, squid_link);
@@ -201,12 +188,10 @@ main(int argc, char *argv[])
         if (icmp4_worker >= 0) {
             FD_SET(icmp4_worker, &R);
         }
-#if USE_IPV6
-
         if (icmp6_worker >= 0) {
             FD_SET(icmp6_worker, &R);
         }
-#endif
+
         FD_SET(squid_link, &R);
         x = select(10, &R, NULL, NULL, &tv);
         getCurrentTime();
@@ -221,12 +206,9 @@ main(int argc, char *argv[])
             control.Recv();
         }
 
-#if USE_IPV6
         if (icmp6_worker >= 0 && FD_ISSET(icmp6_worker, &R)) {
             icmp6.Recv();
         }
-#endif
-
         if (icmp4_worker >= 0 && FD_ISSET(icmp4_worker, &R)) {
             icmp4.Recv();
         }
index f6082d27e10501b0395f552471e879c2172821fe..5b4ccdbe6bf00c95895550de52bfec32add43c61 100644 (file)
@@ -101,25 +101,19 @@ internalRemoteUri(const char *host, u_short port, const char *dir, const char *n
     xstrncpy(lc_host, host, SQUIDHOSTNAMELEN);
     Tolower(lc_host);
 
-#if USE_IPV6
     /* check for an IP address and format appropriately if found */
     IpAddress test = lc_host;
     if ( !test.IsAnyAddr() ) {
         test.ToHostname(lc_host,SQUIDHOSTNAMELEN);
     }
-#endif
 
     /*
      * append the domain in order to mirror the requests with appended
      * domains
      */
 
-#if USE_IPV6
-    /* For IPV6 addresses also check for a colon */
+    /* For IPv6 addresses also check for a colon */
     if (Config.appendDomain && !strchr(lc_host, '.') && !strchr(lc_host, ':'))
-#else
-    if (Config.appendDomain && !strchr(lc_host, '.'))
-#endif
         strncat(lc_host, Config.appendDomain, SQUIDHOSTNAMELEN -
                 strlen(lc_host) - 1);
 
@@ -159,12 +153,8 @@ internalHostname(void)
     LOCAL_ARRAY(char, host, SQUIDHOSTNAMELEN + 1);
     xstrncpy(host, getMyHostname(), SQUIDHOSTNAMELEN);
 
-#if USE_IPV6
-    /* For IPV6 addresses also check for a colon */
+    /* For IPv6 addresses also check for a colon */
     if (Config.appendDomain && !strchr(host, '.') && !strchr(host, ':'))
-#else
-    if (Config.appendDomain && !strchr(host, '.'))
-#endif
         strncat(host, Config.appendDomain, SQUIDHOSTNAMELEN -
                 strlen(host) - 1);
 
index aea1872850e9695e768f8088ca54203fb2ab7450..5614dac2a0857c7ff3fa07ed4f6f8e043b76f64e 100644 (file)
@@ -36,6 +36,7 @@
 
 #include "config.h"
 #include "ip/IpAddress.h"
+#include "ip/tools.h"
 #include "util.h"
 
 
@@ -52,9 +53,6 @@
 #include <arpa/inet.h>  /* inet_ntoa() */
 #endif
 
-#ifdef INET6
-#error "INET6 defined but has been deprecated! Try running bootstrap and configure again."
-#endif
 
 /* We want to use the debug routines when running as module of squid. */
 /* otherwise fallback to printf if those are not available. */
 #    include "../src/Debug.h"
 #endif
 
-#if !USE_IPV6
-//  So there are some places where I will drop to using Macros too.
-//  At least I can restrict them to this file so they don't corrupt the app with C code.
-#  define sin6_addr    sin_addr
-#  define sin6_port    sin_port
-#  define sin6_family  sin_family
-#undef s6_addr
-#  define s6_addr      s_addr
-#endif
-
 /* Debugging only. Dump the address content when a fatal assert is encountered. */
-#if USE_IPV6
 #define IASSERT(a,b)  \
        if(!(b)){       printf("assert \"%s\" at line %d\n", a, __LINE__); \
                printf("IpAddress invalid? with IsIPv4()=%c, IsIPv6()=%c\n",(IsIPv4()?'T':'F'),(IsIPv6()?'T':'F')); \
                        printf(" %x", m_SocketAddr.sin6_addr.s6_addr[i]); \
                } printf("\n"); assert(b); \
        }
-#else
-#define IASSERT(a,b)  \
-       if(!(b)){       printf("assert \"%s\" at line %d\n", a, __LINE__); \
-               printf("IpAddress invalid? with IsIPv4()=%c, IsIPv6()=%c\n",(IsIPv4()?'T':'F'),(IsIPv6()?'T':'F')); \
-               printf("ADDRESS: %x\n", (unsigned int)m_SocketAddr.sin_addr.s_addr); \
-               assert(b); \
-       }
-#endif
 
 IpAddress::IpAddress()
 {
@@ -110,17 +89,12 @@ IpAddress::GetCIDR() const
     uint8_t shift,byte;
     uint8_t bit,caught;
     int len = 0;
-#if USE_IPV6
     const uint8_t *ptr= m_SocketAddr.sin6_addr.s6_addr;
-#else
-    const uint8_t *ptr= (uint8_t *)&m_SocketAddr.sin_addr.s_addr;
-#endif
 
     /* Let's scan all the bits from Most Significant to Least */
     /* Until we find an "0" bit. Then, we return */
     shift=0;
 
-#if USE_IPV6
     /* return IPv4 CIDR for any Mapped address */
     /* Thus only check the mapped bit */
 
@@ -128,8 +102,6 @@ IpAddress::GetCIDR() const
         shift = 12;
     }
 
-#endif
-
     for (; shift<sizeof(m_SocketAddr.sin6_addr) ; shift++) {
         byte= *(ptr+shift);
 
@@ -176,18 +148,6 @@ bool IpAddress::ApplyMask(const unsigned int cidr, int mtype)
     uint8_t clearbits = 0;
     uint8_t* p = NULL;
 
-#if !USE_IPV6
-    IASSERT("mtype != AF_INET6", mtype != AF_INET6); /* using IPv6 in IPv4 is invalid. */
-
-    if (mtype == AF_UNSPEC)
-        mtype = AF_INET;
-
-#else
-    if (mtype == AF_UNSPEC)
-        mtype = AF_INET6;
-
-#endif
-
     // validation and short-cuts.
     if (cidr > 128)
         return false;
@@ -207,16 +167,8 @@ bool IpAddress::ApplyMask(const unsigned int cidr, int mtype)
     if (clearbits == 0)
         return true;
 
-#if USE_IPV6
-
     p = (uint8_t*)(&m_SocketAddr.sin6_addr) + 15;
 
-#else
-
-    p = (uint8_t*)(&m_SocketAddr.sin_addr) + 3;
-
-#endif
-
     for (; clearbits>0 && p >= (uint8_t*)&m_SocketAddr.sin6_addr ; p-- ) {
         if (clearbits < 8) {
             *p &= ((0xFF << clearbits) & 0xFF);
@@ -237,39 +189,23 @@ bool IpAddress::IsSockAddr() const
 
 bool IpAddress::IsIPv4() const
 {
-#if USE_IPV6
     return IsAnyAddr() || IsNoAddr() || IN6_IS_ADDR_V4MAPPED( &m_SocketAddr.sin6_addr );
-#else
-    return true; // enforce IPv4 in IPv4-only mode.
-#endif
 }
 
 bool IpAddress::IsIPv6() const
 {
-#if USE_IPV6
     return IsAnyAddr() || IsNoAddr() || !IN6_IS_ADDR_V4MAPPED( &m_SocketAddr.sin6_addr );
-#else
-    return false; // enforce IPv4 in IPv4-only mode.
-#endif
 }
 
 bool IpAddress::IsAnyAddr() const
 {
-#if USE_IPV6
     return IN6_IS_ADDR_UNSPECIFIED( &m_SocketAddr.sin6_addr );
-#else
-    return (INADDR_ANY == m_SocketAddr.sin_addr.s_addr);
-#endif
 }
 
 /// NOTE: Does NOT clear the Port stored. Ony the Address and Type.
 void IpAddress::SetAnyAddr()
 {
-#if USE_IPV6
     memset(&m_SocketAddr.sin6_addr, 0, sizeof(struct in6_addr) );
-#else
-    memset(&m_SocketAddr.sin_addr, 0, sizeof(struct in_addr) );
-#endif
 }
 
 /// NOTE: completely empties the IpAddress structure. Address, Port, Type, everything.
@@ -278,7 +214,6 @@ void IpAddress::SetEmpty()
     memset(&m_SocketAddr, 0, sizeof(m_SocketAddr) );
 }
 
-#if USE_IPV6
 const struct in6_addr IpAddress::v4_localhost = {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
             0x00, 0x00, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x01 }}
 };
@@ -291,12 +226,10 @@ const struct in6_addr IpAddress::v4_noaddr = {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0
 const struct in6_addr IpAddress::v6_noaddr = {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
             0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }}
 };
-#endif
 
 
 bool IpAddress::SetIPv4()
 {
-#if USE_IPV6
     if ( IsLocalhost() ) {
         m_SocketAddr.sin6_addr = v4_localhost;
         return true;
@@ -312,54 +245,36 @@ bool IpAddress::SetIPv4()
 
     // anything non-IPv4 and non-convertable is BAD.
     return false;
-#else
-    return true; // Always IPv4 in IPv4-only builds.
-#endif
 }
 
 bool IpAddress::IsLocalhost() const
 {
-#if USE_IPV6
     return IN6_IS_ADDR_LOOPBACK( &m_SocketAddr.sin6_addr ) || IN6_ARE_ADDR_EQUAL( &m_SocketAddr.sin6_addr, &v4_localhost );
-#else
-    return (htonl(0x7F000001) == m_SocketAddr.sin_addr.s_addr);
-#endif
 }
 
 void IpAddress::SetLocalhost()
 {
-#if USE_IPV6
-    m_SocketAddr.sin6_addr = in6addr_loopback;
-    m_SocketAddr.sin6_family = AF_INET6;
-#else
-    m_SocketAddr.sin_addr.s_addr = htonl(0x7F000001);
-    m_SocketAddr.sin_family = AF_INET;
-#endif
+    if (Ip::EnableIpv6) {
+        m_SocketAddr.sin6_addr = in6addr_loopback;
+        m_SocketAddr.sin6_family = AF_INET6;
+    } else {
+        m_SocketAddr.sin6_addr = v4_localhost;
+        m_SocketAddr.sin6_family = AF_INET;
+    }
 }
 
 bool IpAddress::IsNoAddr() const
 {
     // IFF the address == 0xff..ff (all ones)
-#if USE_IPV6
     return IN6_ARE_ADDR_EQUAL( &m_SocketAddr.sin6_addr, &v6_noaddr );
-#else
-    return 0xFFFFFFFF == m_SocketAddr.sin_addr.s_addr;
-#endif
 }
 
 void IpAddress::SetNoAddr()
 {
-#if USE_IPV6
     memset(&m_SocketAddr.sin6_addr, 0xFF, sizeof(struct in6_addr) );
     m_SocketAddr.sin6_family = AF_INET6;
-#else
-    memset(&m_SocketAddr.sin_addr, 0xFF, sizeof(struct in_addr) );
-    m_SocketAddr.sin_family = AF_INET;
-#endif
 }
 
-#if USE_IPV6
-
 bool IpAddress::GetReverseString6(char buf[MAX_IPSTRLEN], const struct in6_addr &dat) const
 {
     char *p = buf;
@@ -386,8 +301,6 @@ bool IpAddress::GetReverseString6(char buf[MAX_IPSTRLEN], const struct in6_addr
     return true;
 }
 
-#endif
-
 bool IpAddress::GetReverseString4(char buf[MAX_IPSTRLEN], const struct in_addr &dat) const
 {
     unsigned int i = (unsigned int) ntohl(dat.s_addr);
@@ -403,22 +316,14 @@ bool IpAddress::GetReverseString(char buf[MAX_IPSTRLEN], int show_type) const
 {
 
     if (show_type == AF_UNSPEC) {
-#if USE_IPV6
         show_type = IsIPv6() ? AF_INET6 : AF_INET ;
-#else
-        show_type = AF_INET;
-#endif
     }
 
     if (show_type == AF_INET && IsIPv4()) {
-#if USE_IPV6
         struct in_addr* tmp = (struct in_addr*)&m_SocketAddr.sin6_addr.s6_addr[12];
         return GetReverseString4(buf, *tmp);
     } else if ( show_type == AF_INET6 && IsIPv6() ) {
         return GetReverseString6(buf, m_SocketAddr.sin6_addr);
-#else
-        return GetReverseString4(buf, m_SocketAddr.sin_addr);
-#endif
     }
 
     debugs(14,0, "Unable to convert '" << NtoA(buf,MAX_IPSTRLEN) << "' to the rDNS type requested.");
@@ -437,7 +342,7 @@ IpAddress& IpAddress::operator =(const IpAddress &s)
 IpAddress::IpAddress(const char*s)
 {
     SetEmpty();
-    operator=(s);
+    LookupHostIP(s, true);
 }
 
 bool IpAddress::operator =(const char* s)
@@ -464,8 +369,9 @@ bool IpAddress::LookupHostIP(const char *s, bool nodns)
     if (nodns) {
         want.ai_flags = AI_NUMERICHOST; // prevent actual DNS lookups!
     }
-#if !USE_IPV6
-    want.ai_family = AF_INET;
+#if 0
+    else if (!Ip::EnableIpv6)
+        want.ai_family = AF_INET;  // maybe prevent IPv6 DNS lookups.
 #endif
 
     if ( (err = xgetaddrinfo(s, NULL, &want, &res)) != 0) {
@@ -502,21 +408,14 @@ IpAddress::IpAddress(struct sockaddr_in const &s)
 
 IpAddress& IpAddress::operator =(struct sockaddr_in const &s)
 {
-#if USE_IPV6
     Map4to6((const in_addr)s.sin_addr, m_SocketAddr.sin6_addr);
     m_SocketAddr.sin6_port = s.sin_port;
     m_SocketAddr.sin6_family = AF_INET6;
-#else
-
-    memcpy(&m_SocketAddr, &s, sizeof(struct sockaddr_in));
-#endif
-
     return *this;
 };
 
 IpAddress& IpAddress::operator =(const struct sockaddr_storage &s)
 {
-#if USE_IPV6
     /* some AF_* magic to tell socket types apart and what we need to do */
     if (s.ss_family == AF_INET6) {
         memcpy(&m_SocketAddr, &s, sizeof(struct sockaddr_in));
@@ -525,13 +424,9 @@ IpAddress& IpAddress::operator =(const struct sockaddr_storage &s)
         m_SocketAddr.sin6_port = sin->sin_port;
         Map4to6( sin->sin_addr, m_SocketAddr.sin6_addr);
     }
-#else
-    memcpy(&m_SocketAddr, &s, sizeof(struct sockaddr_in));
-#endif
     return *this;
 };
 
-#if USE_IPV6
 IpAddress::IpAddress(struct sockaddr_in6 const &s)
 {
     SetEmpty();
@@ -545,8 +440,6 @@ IpAddress& IpAddress::operator =(struct sockaddr_in6 const &s)
     return *this;
 };
 
-#endif
-
 IpAddress::IpAddress(struct in_addr const &s)
 {
     SetEmpty();
@@ -555,20 +448,11 @@ IpAddress::IpAddress(struct in_addr const &s)
 
 IpAddress& IpAddress::operator =(struct in_addr const &s)
 {
-#if USE_IPV6
     Map4to6((const in_addr)s, m_SocketAddr.sin6_addr);
     m_SocketAddr.sin6_family = AF_INET6;
-
-#else
-
-    memcpy(&m_SocketAddr.sin_addr, &s, sizeof(struct in_addr));
-
-#endif
     return *this;
 };
 
-#if USE_IPV6
-
 IpAddress::IpAddress(struct in6_addr const &s)
 {
     SetEmpty();
@@ -584,8 +468,6 @@ IpAddress& IpAddress::operator =(struct in6_addr const &s)
     return *this;
 };
 
-#endif
-
 IpAddress::IpAddress(const IpAddress &s)
 {
     SetEmpty();
@@ -630,17 +512,8 @@ bool IpAddress::operator =(const struct hostent &s)
 
     case AF_INET6:
         ipv6 = (in6_addr*)(s.h_addr_list[0]);
-#if USE_IPV6
         /* this */
         operator=(*ipv6);
-#else
-
-        debugs(14,1, HERE << "Discarded IPv6 Address. Protocol disabled.");
-
-        // FIXME see if there is another address in the list that might be usable ??
-        return false;
-#endif
-
         break;
 
     default:
@@ -686,22 +559,9 @@ bool IpAddress::operator =(const struct addrinfo &s)
 
     case AF_INET6:
         ipv6 = (sockaddr_in6*)(s.ai_addr);
-#if USE_IPV6
         /* this */
         assert(ipv6);
         operator=(*ipv6);
-#else
-
-        debugs(14,1, HERE << "Discarded IPv6 Address. Protocol disabled.");
-
-        // see if there is another address in the list that might be usable ??
-
-        if (s.ai_next)
-            return operator=(*s.ai_next);
-        else
-            return false;
-
-#endif
         break;
 
     case AF_UNSPEC:
@@ -709,16 +569,13 @@ bool IpAddress::operator =(const struct addrinfo &s)
         // attempt to handle partially initialised addrinfo.
         // such as those where data only comes from getsockopt()
         if (s.ai_addr != NULL) {
-#if USE_IPV6
             if (s.ai_addrlen == sizeof(struct sockaddr_in6)) {
                 operator=(*((struct sockaddr_in6*)s.ai_addr));
                 return true;
-            } else
-#endif
-                if (s.ai_addrlen == sizeof(struct sockaddr_in)) {
-                    operator=(*((struct sockaddr_in*)s.ai_addr));
-                    return true;
-                }
+            } else if (s.ai_addrlen == sizeof(struct sockaddr_in)) {
+                operator=(*((struct sockaddr_in*)s.ai_addr));
+                return true;
+            }
         }
         return false;
     }
@@ -748,8 +605,7 @@ void IpAddress::GetAddrInfo(struct addrinfo *&dst, int force) const
             && dst->ai_protocol == 0)
         dst->ai_protocol = IPPROTO_UDP;
 
-#if USE_IPV6
-    if ( force == AF_INET6 || (force == AF_UNSPEC && IsIPv6()) ) {
+    if (force == AF_INET6 || (force == AF_UNSPEC && IsIPv6()) ) {
         dst->ai_addr = (struct sockaddr*)new sockaddr_in6;
 
         memset(dst->ai_addr,0,sizeof(struct sockaddr_in6));
@@ -774,22 +630,20 @@ void IpAddress::GetAddrInfo(struct addrinfo *&dst, int force) const
         dst->ai_protocol = IPPROTO_IPV6;
 #endif
 
-    } else
-#endif
-        if ( force == AF_INET || (force == AF_UNSPEC && IsIPv4()) ) {
+    } else if ( force == AF_INET || (force == AF_UNSPEC && IsIPv4()) ) {
 
-            dst->ai_addr = (struct sockaddr*)new sockaddr_in;
+        dst->ai_addr = (struct sockaddr*)new sockaddr_in;
 
-            memset(dst->ai_addr,0,sizeof(struct sockaddr_in));
+        memset(dst->ai_addr,0,sizeof(struct sockaddr_in));
 
-            GetSockAddr(*((struct sockaddr_in*)dst->ai_addr));
+        GetSockAddr(*((struct sockaddr_in*)dst->ai_addr));
 
-            dst->ai_addrlen = sizeof(struct sockaddr_in);
+        dst->ai_addrlen = sizeof(struct sockaddr_in);
 
-            dst->ai_family = ((struct sockaddr_in*)dst->ai_addr)->sin_family;
-        } else {
-            IASSERT("false",false);
-        }
+        dst->ai_family = ((struct sockaddr_in*)dst->ai_addr)->sin_family;
+    } else {
+        IASSERT("false",false);
+    }
 }
 
 void IpAddress::InitAddrInfo(struct addrinfo *&ai) const
@@ -827,13 +681,8 @@ void IpAddress::FreeAddrInfo(struct addrinfo *&ai) const
 
 int IpAddress::matchIPAddr(const IpAddress &rhs) const
 {
-#if USE_IPV6
     uint8_t *l = (uint8_t*)m_SocketAddr.sin6_addr.s6_addr;
     uint8_t *r = (uint8_t*)rhs.m_SocketAddr.sin6_addr.s6_addr;
-#else
-    uint8_t *l = (uint8_t*)&m_SocketAddr.sin_addr.s_addr;
-    uint8_t *r = (uint8_t*)&rhs.m_SocketAddr.sin_addr.s_addr;
-#endif
 
     // loop a byte-wise compare
     // NP: match MUST be R-to-L : L-to-R produces inconsistent gt/lt results at varying CIDR
@@ -924,11 +773,7 @@ char* IpAddress::NtoA(char* buf, const unsigned int blen, int force) const
     /* some external code may have blindly memset a parent. */
     /* thats okay, our default is known */
     if ( IsAnyAddr() ) {
-#if USE_IPV6
         memcpy(buf,"::\0", min((const unsigned int)3,blen));
-#else
-        memcpy(buf,"0.0.0.0\0", min((const unsigned int)8,blen));
-#endif
         return buf;
     }
 
@@ -943,7 +788,6 @@ char* IpAddress::NtoA(char* buf, const unsigned int blen, int force) const
         return buf;
     }
 
-#if USE_IPV6
     if ( force == AF_INET6 || (force == AF_UNSPEC && IsIPv6()) ) {
 
         xinet_ntop(AF_INET6, &m_SocketAddr.sin6_addr, buf, blen);
@@ -953,10 +797,6 @@ char* IpAddress::NtoA(char* buf, const unsigned int blen, int force) const
         struct in_addr tmp;
         GetInAddr(tmp);
         xinet_ntop(AF_INET, &tmp, buf, blen);
-#else
-    if ( force == AF_UNSPEC || (force == AF_INET && IsIPv4()) ) {
-        xinet_ntop(AF_INET, &m_SocketAddr.sin_addr, buf, blen);
-#endif
     } else {
         debugs(14,0,"WARNING: Corrupt IP Address details OR required to display in unknown format (" <<
                force << "). accepted={" << AF_UNSPEC << "," << AF_INET << "," << AF_INET6 << "}");
@@ -1033,7 +873,6 @@ void IpAddress::GetSockAddr(struct sockaddr_storage &addr, const int family) con
         assert(false);
     }
 
-#if USE_IPV6
     if ( family == AF_INET6 || (family == AF_UNSPEC && IsIPv6()) ) {
         struct sockaddr_in6 *ss6 = (struct sockaddr_in6*)&addr;
         GetSockAddr(*ss6);
@@ -1043,16 +882,10 @@ void IpAddress::GetSockAddr(struct sockaddr_storage &addr, const int family) con
     } else {
         IASSERT("false",false);
     }
-#else /* not USE_IPV6 */
-    sin = (struct sockaddr_in*)&addr;
-    GetSockAddr(*sin);
-#endif /* USE_IPV6 */
 }
 
 void IpAddress::GetSockAddr(struct sockaddr_in &buf) const
 {
-#if USE_IPV6
-
     if ( IsIPv4() ) {
         buf.sin_family = AF_INET;
         buf.sin_port = m_SocketAddr.sin6_port;
@@ -1064,25 +897,12 @@ void IpAddress::GetSockAddr(struct sockaddr_in &buf) const
         assert(false);
     }
 
-#else
-
-    memcpy(&buf, &m_SocketAddr, sizeof(struct sockaddr_in));
-
-    if (buf.sin_family == 0) {
-        buf.sin_family = AF_INET;
-    }
-
-#endif
-
 #if HAVE_SIN_LEN_IN_SAI
     /* not all OS have this field, BUT when they do it can be a problem if set wrong */
     buf.sin_len = sizeof(struct sockaddr_in);
 #endif
-
 }
 
-#if USE_IPV6
-
 void IpAddress::GetSockAddr(struct sockaddr_in6 &buf) const
 {
     memcpy(&buf, &m_SocketAddr, sizeof(struct sockaddr_in6));
@@ -1095,10 +915,6 @@ void IpAddress::GetSockAddr(struct sockaddr_in6 &buf) const
 #endif
 }
 
-#endif
-
-#if USE_IPV6
-
 void IpAddress::Map4to6(const struct in_addr &in, struct in6_addr &out) const
 {
     /* check for special cases */
@@ -1132,31 +948,17 @@ void IpAddress::Map6to4(const struct in6_addr &in, struct in_addr &out) const
     ((uint8_t *)&out.s_addr)[3] = in.s6_addr[15];
 }
 
-#endif
-
-#if USE_IPV6
 void IpAddress::GetInAddr(in6_addr &buf) const
 {
     memcpy(&buf, &m_SocketAddr.sin6_addr, sizeof(struct in6_addr));
 }
 
-#endif
-
 bool IpAddress::GetInAddr(struct in_addr &buf) const
 {
-
-#if USE_IPV6
     if ( IsIPv4() ) {
         Map6to4((const in6_addr)m_SocketAddr.sin6_addr, buf);
         return true;
     }
-#else
-
-    if ( IsIPv4() ) {
-        memcpy(&buf, &m_SocketAddr.sin_addr, sizeof(struct in_addr));
-        return true;
-    }
-#endif
 
     // default:
     // non-compatible IPv6 Pure Address
index 287411882359b1eec8609f2d87fc355e9745b74c..fb6fec34ada1b274ab204bf52fd6ccba68ffd8eb 100644 (file)
 #include <ostream>
 #endif
 
-/* FreeBSD hack:
- *   This OS has at least one version that defines these as private
- *   kernel macros commented as being 'non-standard'.
- *   We need to use them, much nicer than the OS-provided __u*_*[]
- * UPDATE: OpenBSD 4.3 has the same.
- * UPDATE: MacOSX has the same.
- */
-#if USE_IPV6 && ( defined(_SQUID_FREEBSD_) || defined(_SQUID_OPENBSD_) || defined(_SQUID_APPLE_) || defined(_SQUID_NETBSD_))
-//#define s6_addr8  __u6_addr.__u6_addr8
-//#define s6_addr16 __u6_addr.__u6_addr16
-#define s6_addr32 __u6_addr.__u6_addr32
-#endif
-
-/* OpenBSD also hide v6only socket option we need for comm layer. :-( */
-#if !defined(IPV6_V6ONLY) && defined(_SQUID_OPENBSD_)
-#define IPV6_V6ONLY            27 // from OpenBSD 4.3 headers. (NP: does not match non-BSD OS values)
-#endif
-
-/* Bug 2500: Solaris 10/11 require s6_addr* defines. */
-#if USE_IPV6 && defined(_SQUID_SOLARIS_)
-//#define s6_addr8   _S6_un._S6_u8
-//#define s6_addr16  _S6_un._S6_u16
-#define s6_addr32  _S6_un._S6_u32
-#endif
-
 /// Length of buffer that needs to be allocated to old a null-terminated IP-string
 // Yuck. But there are still structures that need it to be an 'integer constant'.
 #define MAX_IPSTRLEN  75
@@ -115,17 +90,10 @@ public:
      *           Prefer the by-reference (&) version instead.
      */
     IpAddress(IpAddress *);
-
     IpAddress(const struct in_addr &);
-
     IpAddress(const struct sockaddr_in &);
-#if USE_IPV6
-
     IpAddress(const struct in6_addr &);
-
     IpAddress(const struct sockaddr_in6 &);
-#endif
-
     IpAddress(const struct hostent &);
     IpAddress(const struct addrinfo &);
     IpAddress(const char*);
@@ -139,10 +107,8 @@ public:
     IpAddress& operator =(struct sockaddr_in const &s);
     IpAddress& operator =(struct sockaddr_storage const &s);
     IpAddress& operator =(struct in_addr const &s);
-#if USE_IPV6
     IpAddress& operator =(struct in6_addr const &s);
     IpAddress& operator =(struct sockaddr_in6 const &s);
-#endif
     bool operator =(const struct hostent &s);
     bool operator =(const struct addrinfo &s);
     bool operator =(const char *s);
@@ -258,7 +224,7 @@ public:
      \param cidr   CIDR Mask being applied. As an integer in host format.
      \param mtype  Type of CIDR mask being applied (AF_INET or AF_INET6)
      */
-    bool ApplyMask(const unsigned int cidr, int mtype = AF_UNSPEC);
+    bool ApplyMask(const unsigned int cidr, int mtype);
 
 
     /** Return the ASCII equivalent of the address
@@ -324,18 +290,11 @@ public:
      \par
      *  IpAddress allocated objects MUST be destructed by IpAddress::FreeAddrInfo
      *  System getaddrinfo() allocated objects MUST be freed with system freeaddrinfo()
-     \par
-     *  Some OS require that IPv4 addresses are pre-mapped by the client.
-     *  The configure option --with-ipv4-mapping=yes will enable this.
      *
      \param ai structure to be filled out.
      \param force a specific sockaddr type is needed. default: don't care.
      */
-#if IPV6_SPECIAL_V4MAPPING
-    void GetAddrInfo(struct addrinfo *&ai, int force = AF_INET6) const;
-#else
     void GetAddrInfo(struct addrinfo *&ai, int force = AF_UNSPEC) const;
-#endif
 
     /**
      *  Equivalent to the sysem call freeaddrinfo() but for IpAddress allocated data
@@ -376,40 +335,27 @@ public:
 
     /// \deprecated Deprecated for public use. Use IpAddress::GetAddrInfo()
     bool GetInAddr(struct in_addr &) const; /* false if could not convert IPv6 down to IPv4 */
-#if USE_IPV6
-
-    /// \deprecated Deprecated for public use. Use IpAddress::GetAddrInfo()
     void GetSockAddr(struct sockaddr_in6 &) const;
 
     /// \deprecated Deprecated for public use. Use IpAddress::GetAddrInfo()
     void GetInAddr(struct in6_addr &) const;
-#endif
 
 private:
     /* Conversion for dual-type internals */
 
     bool GetReverseString4(char buf[MAX_IPSTRLEN], const struct in_addr &dat) const;
 
-#if USE_IPV6
-
     bool GetReverseString6(char buf[MAX_IPSTRLEN], const struct in6_addr &dat) const;
 
     void Map4to6(const struct in_addr &src, struct in6_addr &dest) const;
 
     void Map6to4(const struct in6_addr &src, struct in_addr &dest) const;
-#endif
 
     // Worker behind GetHostName and char* converters
     bool LookupHostIP(const char *s, bool nodns);
 
     /* variables */
-#if USE_IPV6
-
     struct sockaddr_in6 m_SocketAddr;
-#else
-
-    struct sockaddr_in m_SocketAddr;
-#endif
 
 private:
     /* Internally used constants */
@@ -417,7 +363,6 @@ private:
     static const unsigned int STRLEN_IP4R = 28;              // ddd.ccc.bbb.aaa.in-addr.arpa.\0
     static const unsigned int STRLEN_IP4S = 21;              // ddd.ccc.bbb.aaa:ppppp\0
     static const unsigned int MAX_IP4_STRLEN = STRLEN_IP4R;
-#if USE_IPV6
     static const unsigned int STRLEN_IP6A = 42;           // [ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]/0
     static const unsigned int STRLEN_IP6R = 75;           // f.f.f.f f.f.f.f f.f.f.f f.f.f.f f.f.f.f f.f.f.f f.f.f.f f.f.f.f ipv6.arpa./0
     static const unsigned int STRLEN_IP6S = 48;           // [ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]:00000/0
@@ -426,7 +371,6 @@ private:
     static const struct in6_addr v4_anyaddr;
     static const struct in6_addr v4_noaddr;
     static const struct in6_addr v6_noaddr;
-#endif
 };
 
 
index 35206a6276fd8324c8fda486341ce28c6d66b061..e35aabe7df35f2ec4d84633e3803a86114eb56ad 100644 (file)
@@ -447,14 +447,14 @@ IpIntercept::ProbeForTproxy(IpAddress &test)
     debugs(3, 3, "Detect TPROXY support on port " << test);
 #if LINUX_TPROXY2
 
-#if USE_IPV6
-    /* TPROXYv2 is not IPv6 capable. Force wildcard sockets to IPv4. Die on IPv6 IPs */
-    debugs(3, DBG_IMPORTANT, "Disabling IPv6 on port " << test << " (TPROXYv2 interception enabled)");
-    if ( test.IsIPv6() && !test.SetIPv4() ) {
-        debugs(3, DBG_CRITICAL, "IPv6 requires TPROXYv4 support. You only have TPROXYv2 for " << test );
-        return false;
+    if (Ip::EnableIpv6) {
+        /* TPROXYv2 is not IPv6 capable. Force wildcard sockets to IPv4. Die on IPv6 IPs */
+        debugs(3, DBG_IMPORTANT, "Disabling IPv6 on port " << test << " (TPROXYv2 interception enabled)");
+        if ( test.IsIPv6() && !test.SetIPv4() ) {
+           debugs(3, DBG_CRITICAL, "IPv6 requires TPROXYv4 support. You only have TPROXYv2 for " << test );
+            return false;
+        }
     }
-#endif /* USE_IPV6 */
     return true;
 
 #else /* not LINUX_TPROXY2 */
@@ -464,7 +464,6 @@ IpIntercept::ProbeForTproxy(IpAddress &test)
     int tos = 1;
     int tmp_sock = -1;
 
-#if USE_IPV6
     /* Probe to see if the Kernel TPROXY support is IPv6-enabled */
     if (test.IsIPv6()) {
         debugs(3, 3, "...Probing for IPv6 TPROXY support.");
@@ -492,7 +491,6 @@ IpIntercept::ProbeForTproxy(IpAddress &test)
         debugs(3, DBG_CRITICAL, "TPROXY lacks IPv6 support for " << test );
         return false;
     }
-#endif
 
     /* Probe to see if the Kernel TPROXY support is IPv4-enabled (aka present) */
     if (test.IsIPv4()) {
index 467b336ce558e8b4dad2a29415d6a7b02a829749..8f858eec76dc21e9e3ab1ea273d09e9caad099e6 100644 (file)
@@ -9,7 +9,9 @@ libip_la_SOURCES = \
        IpIntercept.h \
        IpIntercept.cc \
        QosConfig.h \
-       QosConfig.cc
+       QosConfig.cc \
+       tools.cc \
+       tools.h
 
 
 check_PROGRAMS += testIpAddress
@@ -18,8 +20,11 @@ TESTS += testIpAddress
 testIpAddress_SOURCES= \
        testIpAddress.cc \
        testIpAddress.h
+
 nodist_testIpAddress_SOURCES= \
-       ../tests/testMain.cc
+       $(top_srcdir)/src/tests/testMain.cc \
+       $(top_srcdir)/test-suite/test_tools.cc
+
 testIpAddress_LDADD= \
        $(top_builddir)/compat/libcompat.la \
        libip.la \
@@ -27,4 +32,5 @@ testIpAddress_LDADD= \
        $(XTRA_LIBS) \
        $(SQUID_CPPUNIT_LA) \
        $(SQUID_CPPUNIT_LIBS)
+
 testIpAddress_LDFLAGS= $(LIBADD_DL)
index e7f7f8e1a43ff113bf8b18e1a4d3b7a3899a0d0b..0048808fa6152a9ea6d937b268e62e0ca441b090 100644 (file)
@@ -1,6 +1,7 @@
 #include "config.h"
 #include "testIpAddress.h"
 #include "ip/IpAddress.h"
+#include "ip/tools.h"
 
 #if HAVE_CSTRING
 #include <cstring>
@@ -41,11 +42,7 @@ testIpAddress::testDefaults()
     CPPUNIT_ASSERT( anIPA.IsIPv4() );
     CPPUNIT_ASSERT( !anIPA.IsSockAddr() );
     CPPUNIT_ASSERT_EQUAL( (u_short) 0 , anIPA.GetPort() );
-#if USE_IPV6
     CPPUNIT_ASSERT( anIPA.IsIPv6() );
-#else
-    CPPUNIT_ASSERT( !anIPA.IsIPv6() );
-#endif
 }
 
 void
@@ -70,7 +67,6 @@ testIpAddress::testInAddrConstructor()
     CPPUNIT_ASSERT( memcmp(&inval, &outval, sizeof(struct in_addr)) == 0 );
 }
 
-#if USE_IPV6
 void
 testIpAddress::testInAddr6Constructor()
 {
@@ -94,7 +90,6 @@ testIpAddress::testInAddr6Constructor()
     anIPA.GetInAddr(outval);
     CPPUNIT_ASSERT( memcmp( &inval, &outval, sizeof(struct in6_addr)) == 0 );
 }
-#endif
 
 void
 testIpAddress::testSockAddrConstructor()
@@ -125,7 +120,6 @@ testIpAddress::testSockAddrConstructor()
     CPPUNIT_ASSERT( memcmp( &insock, &outsock, sizeof(struct sockaddr_in)) == 0 );
 }
 
-#if USE_IPV6
 void
 testIpAddress::testSockAddr6Constructor()
 {
@@ -157,7 +151,6 @@ testIpAddress::testSockAddr6Constructor()
     anIPA.GetSockAddr(outsock);
     CPPUNIT_ASSERT( memcmp( &insock, &outsock, sizeof(struct sockaddr_in6)) == 0 );
 }
-#endif
 
 
 void
@@ -236,7 +229,6 @@ testIpAddress::testStringConstructor()
     anIPA.GetInAddr(outval);
     CPPUNIT_ASSERT( memcmp( &expectval, &outval, sizeof(struct in_addr)) == 0 );
 
-#if USE_IPV6
     struct in6_addr expectv6;
     struct in6_addr outval6;
 
@@ -247,6 +239,10 @@ testIpAddress::testStringConstructor()
 
     IpAddress bnIPA = "2000:800::45";
 
+//char test[256];
+//bnIPA.NtoA(test, 256);
+//printf("bnIPA: %s\n", test);
+
     /* test stored values */
     CPPUNIT_ASSERT( !bnIPA.IsAnyAddr() );
     CPPUNIT_ASSERT( !bnIPA.IsNoAddr() );
@@ -274,7 +270,6 @@ testIpAddress::testStringConstructor()
     CPPUNIT_ASSERT_EQUAL( (u_short) 0 , cnIPA.GetPort() );
     cnIPA.GetInAddr(outval6);
     CPPUNIT_ASSERT( memcmp( &expectv6, &outval6, sizeof(struct in6_addr)) == 0 );
-#endif
 }
 
 void
@@ -301,11 +296,7 @@ testIpAddress::testSetEmpty()
     CPPUNIT_ASSERT( anIPA.IsAnyAddr() );
     CPPUNIT_ASSERT( !anIPA.IsNoAddr() );
     CPPUNIT_ASSERT( anIPA.IsIPv4() );
-#if USE_IPV6
     CPPUNIT_ASSERT( anIPA.IsIPv6() );
-#else
-    CPPUNIT_ASSERT( !anIPA.IsIPv6() );
-#endif
     CPPUNIT_ASSERT( !anIPA.IsSockAddr() );
     CPPUNIT_ASSERT_EQUAL( (u_short) 0 , anIPA.GetPort() );
 }
@@ -432,11 +423,7 @@ testIpAddress::testNtoA()
     anIPA.SetAnyAddr();
 
     /* test AnyAddr display values */
-#if USE_IPV6
     CPPUNIT_ASSERT( memcmp("::", anIPA.NtoA(buf,MAX_IPSTRLEN), 2) == 0 );
-#else
-    CPPUNIT_ASSERT( memcmp("0.0.0.0",anIPA.NtoA(buf,MAX_IPSTRLEN), 7) == 0 );
-#endif
 
     inval.s_addr = htonl(0xC0A8640C);
     anIPA = inval;
@@ -447,11 +434,7 @@ testIpAddress::testNtoA()
     anIPA.SetNoAddr();
 
     /* test NoAddr display values */
-#if USE_IPV6
     CPPUNIT_ASSERT( memcmp("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",anIPA.NtoA(buf,MAX_IPSTRLEN), 39) == 0 );
-#else
-    CPPUNIT_ASSERT( memcmp("255.255.255.255",anIPA.NtoA(buf,MAX_IPSTRLEN), 15) == 0 );
-#endif
 }
 
 void
@@ -469,8 +452,6 @@ testIpAddress::testToURL_fromInAddr()
     anIPA.ToURL(buf,MAX_IPSTRLEN);
     CPPUNIT_ASSERT( memcmp("192.168.100.12", buf, 14) == 0 );
 
-#if USE_IPV6
-
     /* test output when constructed from in6_addr with IPv6 */
     struct in6_addr ip6val;
 
@@ -483,8 +464,6 @@ testIpAddress::testToURL_fromInAddr()
 
     bnIPA.ToURL(buf,MAX_IPSTRLEN);
     CPPUNIT_ASSERT( memcmp("[c0a8:640c:ffff:ffff:ffff:ffff:ffff:ffff]", buf, 41) == 0 );
-
-#endif
 }
 
 void
@@ -505,8 +484,6 @@ testIpAddress::testToURL_fromSockAddr()
     anIPA.ToURL(buf,MAX_IPSTRLEN);
     CPPUNIT_ASSERT( memcmp("192.168.100.12:80", buf, 17) == 0 );
 
-#if USE_IPV6
-
     /* test output when constructed from in6_addr with IPv6 */
     struct sockaddr_in6 ip6val;
 
@@ -524,9 +501,6 @@ testIpAddress::testToURL_fromSockAddr()
 
     bnIPA.ToURL(buf,MAX_IPSTRLEN);
     CPPUNIT_ASSERT( memcmp("[c0a8:640c:ffff:ffff:ffff:ffff:ffff:ffff]:80", buf, 44) == 0 );
-
-#endif
-
 }
 
 void
@@ -549,8 +523,6 @@ testIpAddress::testGetReverseString()
     v4IPA.GetReverseString(buf,AF_INET6);
     CPPUNIT_ASSERT( memcmp("",buf, 1) == 0 );
 
-
-#if USE_IPV6
     struct in6_addr ip6val;
 
     ip6val.s6_addr32[0] = htonl(0xC0A8640C);
@@ -563,9 +535,6 @@ testIpAddress::testGetReverseString()
     /* test IPv6 output */
     v6IPA.GetReverseString(buf);
     CPPUNIT_ASSERT( memcmp("f.f.f.f.f.f.f.f.f.f.f.f.f.f.f.f.f.f.f.f.f.f.f.f.c.0.4.6.8.a.0.c.ip6.arpa.",buf,73) == 0 );
-
-#endif
-
 }
 
 void
@@ -580,37 +549,28 @@ testIpAddress::testMasking()
     CPPUNIT_ASSERT_EQUAL( 0 ,anIPA.GetCIDR() );
 
     anIPA.SetNoAddr();
-#if USE_IPV6
     CPPUNIT_ASSERT_EQUAL( 128 , anIPA.GetCIDR() );
-#else
-    CPPUNIT_ASSERT_EQUAL( 32 , anIPA.GetCIDR() );
-#endif
 
     /* Test Numeric ApplyCIDR */
     anIPA.SetNoAddr();
-    CPPUNIT_ASSERT( !anIPA.ApplyMask(129) );
-#if !USE_IPV6
-    CPPUNIT_ASSERT( !anIPA.ApplyMask(33) );
-#endif
-    CPPUNIT_ASSERT( anIPA.ApplyMask(31) );
-    CPPUNIT_ASSERT_EQUAL( 31 , anIPA.GetCIDR() );
+    CPPUNIT_ASSERT( !anIPA.ApplyMask(129,AF_INET6) );
+    CPPUNIT_ASSERT( !anIPA.ApplyMask(33,AF_INET) );
 
     anIPA.SetNoAddr();
-    anIPA.ApplyMask(31, AF_INET);
-#if USE_IPV6
+    CPPUNIT_ASSERT( anIPA.ApplyMask(31,AF_INET) );
+    CPPUNIT_ASSERT_EQUAL( 127 , anIPA.GetCIDR() );
+
+    anIPA.SetNoAddr();
+    CPPUNIT_ASSERT( anIPA.ApplyMask(127,AF_INET6) );
     CPPUNIT_ASSERT_EQUAL( 127 , anIPA.GetCIDR() );
-#else
-    CPPUNIT_ASSERT_EQUAL( 31 , anIPA.GetCIDR() );
-#endif
 
-#if USE_IPV6
     anIPA.SetNoAddr();
     anIPA.ApplyMask(80,AF_INET6);
     CPPUNIT_ASSERT_EQUAL( 80 , anIPA.GetCIDR() );
+
     /* BUG Check: test values by display. */
     CPPUNIT_ASSERT( anIPA.NtoA(buf,MAX_IPSTRLEN) != NULL );
     CPPUNIT_ASSERT( memcmp("ffff:ffff:ffff:ffff:ffff::", buf, 26) == 0 );
-#endif
 
     /* Test Network Bitmask from IpAddress */
     anIPA.SetNoAddr();
@@ -629,8 +589,6 @@ testIpAddress::testMasking()
     /* BUG Check failing test. Masked values for display. */
     CPPUNIT_ASSERT( memcmp("255.255.240.0",anIPA.NtoA(buf,MAX_IPSTRLEN), 13) == 0 );
 
-
-#if USE_IPV6
     anIPA.SetNoAddr();
     maskIPA.SetNoAddr();
 
@@ -658,8 +616,6 @@ testIpAddress::testMasking()
     CPPUNIT_ASSERT(  maskIPA.IsIPv4() );
     CPPUNIT_ASSERT( !maskIPA.IsIPv6() );
     CPPUNIT_ASSERT_EQUAL( 20 , anIPA.GetCIDR() );
-#endif
-
 }
 
 void
@@ -717,7 +673,6 @@ testIpAddress::testAddrInfo()
 #endif
 #endif /*0*/
 
-#if USE_IPV6
 #if HAVE_SS_LEN_IN_SS
     CPPUNIT_ASSERT_EQUAL( ((struct sockaddr_storage*)expect->ai_addr)->ss_len,
                           ((struct sockaddr_storage*)ipval->ai_addr)->ss_len );
@@ -737,22 +692,6 @@ testIpAddress::testAddrInfo()
                           ((struct sockaddr_in6*)ipval->ai_addr)->sin6_family );
     CPPUNIT_ASSERT_EQUAL( ((struct sockaddr_in6*)expect->ai_addr)->sin6_port,
                           ((struct sockaddr_in6*)ipval->ai_addr)->sin6_port );
-#else
-#if HAVE_SS_LEN_IN_SS
-    CPPUNIT_ASSERT_EQUAL( ((struct sockaddr_storage*)expect->ai_addr)->ss_len,
-                          ((struct sockaddr_storage*)ipval->ai_addr)->ss_len );
-    CPPUNIT_ASSERT_EQUAL( (socklen_t)((struct sockaddr_storage*)ipval->ai_addr)->ss_len, ipval->ai_addrlen );
-#endif
-#if HAVE_SIN_LEN_IN_SAI
-    CPPUNIT_ASSERT_EQUAL( ((struct sockaddr_in*)expect->ai_addr)->sin_len,
-                          ((struct sockaddr_in*)ipval->ai_addr)->sin_len );
-    CPPUNIT_ASSERT_EQUAL( (socklen_t)((struct sockaddr_in*)ipval->ai_addr)->sin_len, ipval->ai_addrlen );
-#endif
-    CPPUNIT_ASSERT_EQUAL( ((struct sockaddr_in*)expect->ai_addr)->sin_family,
-                          ((struct sockaddr_in*)ipval->ai_addr)->sin_family );
-    CPPUNIT_ASSERT_EQUAL( ((struct sockaddr_in*)expect->ai_addr)->sin_port,
-                          ((struct sockaddr_in*)ipval->ai_addr)->sin_port );
-#endif /* USE_IPV6 */
 
     CPPUNIT_ASSERT( memcmp( expect->ai_addr, ipval->ai_addr, expect->ai_addrlen ) == 0 );
 
index a223686f2bc4108422a37498424dc3209af7c49f..66ad59e503fc92c27b954a2742d4e5bffc822670 100644 (file)
@@ -12,13 +12,9 @@ class testIpAddress : public CPPUNIT_NS::TestFixture
     CPPUNIT_TEST_SUITE( testIpAddress );
     CPPUNIT_TEST( testDefaults );
     CPPUNIT_TEST( testInAddrConstructor );
-#if USE_IPV6
     CPPUNIT_TEST( testInAddr6Constructor );
-#endif
     CPPUNIT_TEST( testSockAddrConstructor );
-#if USE_IPV6
     CPPUNIT_TEST( testSockAddr6Constructor );
-#endif
     CPPUNIT_TEST( testHostentConstructor );
     CPPUNIT_TEST( testStringConstructor );
     CPPUNIT_TEST( testCopyConstructor );
@@ -40,13 +36,9 @@ protected:
     void testDefaults();
 
     void testInAddrConstructor();
-#if USE_IPV6
     void testInAddr6Constructor();
-#endif
     void testSockAddrConstructor();
-#if USE_IPV6
     void testSockAddr6Constructor();
-#endif
     void testHostentConstructor();
     void testStringConstructor();
     void testCopyConstructor();
diff --git a/src/ip/tools.cc b/src/ip/tools.cc
new file mode 100644 (file)
index 0000000..2c4daa1
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * DEBUG: section 21    Misc Functions
+ * AUTHOR: Amos Jeffries
+ *
+ * SQUID Web Proxy Cache          http://www.squid-cache.org/
+ * ----------------------------------------------------------
+ *
+ *  Squid is the result of efforts by numerous individuals from
+ *  the Internet community; see the CONTRIBUTORS file for full
+ *  details.   Many organizations have provided support for Squid's
+ *  development; see the SPONSORS file for full details.  Squid is
+ *  Copyrighted (C) 2001 by the Regents of the University of
+ *  California; see the COPYRIGHT file for full details.  Squid
+ *  incorporates software developed and/or copyrighted by other
+ *  sources; see the CREDITS file for full details.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ *
+ */
+
+#include "config.h"
+#include "Debug.h"
+#include "ip/tools.h"
+
+#if HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#if HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#if HAVE_NETINET_IN6_H
+#include <netinet/in6.h>
+#endif
+
+int Ip::EnableIpv6 = IPV6_OFF;
+
+void
+Ip::ProbeTransport()
+{
+#if USE_IPV6
+    // check for usable IPv6 sockets
+    int s = socket(PF_INET6, SOCK_STREAM, 0);
+    if (s < 0) {
+        debugs(3, 2, "IPv6 not supported on this machine. Auto-Disabled.");
+        EnableIpv6 = IPV6_OFF;
+        return;
+    }
+
+    // Test for v4-mapping capability
+    int tos = 0;
+    if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &tos, sizeof(int)) == 0) {
+        debugs(3, 2, "Detected IPv6 hybrid or v4-mapping stack...");
+        EnableIpv6 |= IPV6_SPECIAL_V4MAPPING;
+    } else {
+        debugs(3, 2, "Detected split IPv4 and IPv6 stacks ...");
+        // EnableIpv6 |= IPV6_SPECIAL_SPLITSTACK;
+        // TODO: remove death when split-stack is supported.
+        EnableIpv6 = IPV6_OFF;
+    }
+    close(s);
+
+    debugs(3, 2, "IPv6 transport " << (EnableIpv6?"Enabled":"Disabled"));
+#else
+    debugs(3, 2, "IPv6 transport forced OFF by build parameters.");
+    EnableIpv6 = IPV6_OFF;
+#endif
+}
diff --git a/src/ip/tools.h b/src/ip/tools.h
new file mode 100644 (file)
index 0000000..5b9831a
--- /dev/null
@@ -0,0 +1,21 @@
+#ifndef _SQUID_SRC_IP_TOOLS_H
+#define _SQUID_SRC_IP_TOOLS_H
+
+namespace Ip
+{
+
+/// Probe to discover IPv6 capabilities
+extern void ProbeTransport(void);
+
+/* Squids notion of IPv6 stack types and state */
+#define IPV6_OFF  0
+#define IPV6_ON   1
+#define IPV6_SPECIAL_V4MAPPING  2
+#define IPV6_SPECIAL_SPLITSTACK 4
+
+/// Whether IPv6 is supported and type of support.
+extern int EnableIpv6;
+
+}; // namespace Ip
+
+#endif /* _SQUID_SRC_IP_TOOLS_H */
index 01b61d397207ef233a3fc8abc6f58754b2a4cc17..f222623465fdea87b86ac7b2d451e44de65a786d 100644 (file)
  */
 
 #include "squid.h"
+#include "CacheManager.h"
 #include "cbdata.h"
 #include "event.h"
-#include "CacheManager.h"
+#include "ip/tools.h"
 #include "SquidTime.h"
 #include "Store.h"
 #include "wordlist.h"
@@ -497,8 +498,7 @@ ipcacheParse(ipcache_entry *i, rfc1035_rr * answers, int nr, const char *error_m
 
     for (k = 0; k < nr; k++) {
 
-#if USE_IPV6
-        if (answers[k].type == RFC1035_TYPE_AAAA) {
+        if (Ip::EnableIpv6 && answers[k].type == RFC1035_TYPE_AAAA) {
             if (answers[k].rdlength != sizeof(struct in6_addr)) {
                 debugs(14, 1, "ipcacheParse: Invalid IPv6 address in response to '" << name << "'");
                 continue;
@@ -507,7 +507,6 @@ ipcacheParse(ipcache_entry *i, rfc1035_rr * answers, int nr, const char *error_m
             IpcacheStats.rr_aaaa++;
             continue;
         }
-#endif
 
         if (answers[k].type == RFC1035_TYPE_A) {
             if (answers[k].rdlength != sizeof(struct in_addr)) {
@@ -579,8 +578,7 @@ ipcacheParse(ipcache_entry *i, rfc1035_rr * answers, int nr, const char *error_m
             debugs(14, 3, "ipcacheParse: " << name << " #" << j << " " << i->addrs.in_addrs[j]);
             j++;
 
-#if USE_IPV6
-        } else if (answers[k].type == RFC1035_TYPE_AAAA) {
+        } else if (Ip::EnableIpv6 && answers[k].type == RFC1035_TYPE_AAAA) {
             if (answers[k].rdlength != sizeof(struct in6_addr))
                 continue;
 
@@ -590,7 +588,6 @@ ipcacheParse(ipcache_entry *i, rfc1035_rr * answers, int nr, const char *error_m
 
             debugs(14, 3, "ipcacheParse: " << name << " #" << j << " " << i->addrs.in_addrs[j] );
             j++;
-#endif
         }
 #if DNS_CNAME
         else if (answers[k].type == RFC1035_TYPE_CNAME) {
@@ -977,16 +974,12 @@ ipcacheMergeIPLists(const IpAddress *aaddrs, const int alen,
     int fc=0, t=0, c=0;
 
     IpAddress const *ip4ptrs[255];
-#if USE_IPV6
     IpAddress const *ip6ptrs[255];
-#endif
     int num_ip4 = 0;
     int num_ip6 = 0;
 
     memset(ip4ptrs, 0, sizeof(IpAddress*)*255);
-#if USE_IPV6
     memset(ip6ptrs, 0, sizeof(IpAddress*)*255);
-#endif
 
     // for each unique address in list A - grab ptr
     for (t = 0; t < alen; t++) {
@@ -1000,7 +993,6 @@ ipcacheMergeIPLists(const IpAddress *aaddrs, const int alen,
                 num_ip4++;
             }
         }
-#if USE_IPV6
         else if (aaddrs[t].IsIPv6()) {
             debugs(14,8, HERE << "A[" << t << "]=IPv6 " << aaddrs[t]);
             // check against IPv6 pruned list
@@ -1012,7 +1004,6 @@ ipcacheMergeIPLists(const IpAddress *aaddrs, const int alen,
                 num_ip6++;
             }
         }
-#endif
     }
 
     // for each unique address in list B - grab ptr
@@ -1027,7 +1018,6 @@ ipcacheMergeIPLists(const IpAddress *aaddrs, const int alen,
                 num_ip4++;
             }
         }
-#if USE_IPV6
         else if (baddrs[t].IsIPv6()) {
             // check against IPv6 pruned list
             for (c = 0; c <= num_ip6; c++) {
@@ -1038,7 +1028,6 @@ ipcacheMergeIPLists(const IpAddress *aaddrs, const int alen,
                 num_ip6++;
             }
         }
-#endif
     }
 
     fc = num_ip6 + num_ip4;
@@ -1053,14 +1042,12 @@ ipcacheMergeIPLists(const IpAddress *aaddrs, const int alen,
 
     assert(out != NULL);
 
-#if USE_IPV6
     /* IPv6 are preferred (tried first) over IPv4 */
 
     for (int l = 0; outlen < num_ip6; l++, outlen++) {
         (*out)[outlen] = *ip6ptrs[l];
         debugs(14, 5, "ipcacheMergeIPLists:  #" << outlen << " " << (*out)[outlen] );
     }
-#endif /* USE_IPV6 */
 
     for (int l = 0; outlen < num_ip4; l++, outlen++) {
         (*out)[outlen] = *ip4ptrs[l];
@@ -1462,15 +1449,11 @@ ipcacheAddEntryFromHosts(const char *name, const char *ipaddr)
     IpAddress ip;
 
     if (!(ip = ipaddr)) {
-#if USE_IPV6
         if (strchr(ipaddr, ':') && strspn(ipaddr, "0123456789abcdefABCDEF:") == strlen(ipaddr)) {
             debugs(14, 3, "ipcacheAddEntryFromHosts: Skipping IPv6 address '" << ipaddr << "'");
         } else {
             debugs(14, 1, "ipcacheAddEntryFromHosts: Bad IP address '" << ipaddr << "'");
         }
-#else
-        debugs(14, 1, "ipcacheAddEntryFromHosts: Bad IP address '" << ipaddr << "'");
-#endif
 
         return 1;
     }
index 3fe99cce8e6804cfc10753e1d8b17e9c7015b4d7..fdfe274012c19ef3ddf3d671169f6a47c6ae67e9 100644 (file)
@@ -55,6 +55,7 @@
 #include "StoreFileSystem.h"
 #include "DiskIO/DiskIOModule.h"
 #include "comm.h"
+#include "ip/tools.h"
 #if USE_EPOLL
 #include "comm_epoll.h"
 #endif
@@ -1281,6 +1282,8 @@ SquidMain(int argc, char **argv)
         /* we may want the parsing process to set this up in the future */
         Store::Root(new StoreController);
 
+        Ip::ProbeTransport(); // determine IPv4 or IPv6 capabilities before parsing.
+
         parse_err = parseConfigFile(ConfigFile);
 
         Mem::Report();
index b3795e1ef3eb6ba6fd2ecb18a0b1145ba7041966..c8f273847f269ed0a9ffd38fdd0d1b737e8c4b43 100644 (file)
@@ -66,14 +66,12 @@ mcastJoinGroups(const ipcache_addrs *ia, const DnsLookupDetails &, void *datanot
     }
 
     for (i = 0; i < (int) ia->count; i++) {
-        debugs(7, 10, "Listening for ICP requests on " << ia->in_addrs[i] );
+        debugs(7, 9, "Listening for ICP requests on " << ia->in_addrs[i] );
 
-#if USE_IPV6
         if ( ! ia->in_addrs[i].IsIPv4() ) {
-            debugs(7, 10, "ERROR: IPv6 Multicast Listen has not been implemented!");
+            debugs(7, 9, "ERROR: IPv6 Multicast Listen has not been implemented!");
             continue;
         }
-#endif
 
         ia->in_addrs[i].GetInAddr(mr.imr_multiaddr);
 
index b45ee0c0c7e7190a39b862b30f04ffb8a7ee3f67..4fec167c6cda66263e754533cfef0184cf2812bf 100644 (file)
@@ -34,6 +34,7 @@
 #include "cache_snmp.h"
 #include "acl/FilledChecklist.h"
 #include "ip/IpAddress.h"
+#include "ip/tools.h"
 
 #define SNMP_REQUEST_SIZE 4096
 #define MAX_PROTOSTAT 5
@@ -801,10 +802,8 @@ client_Inst(oid * name, snint * len, mib_tree_entry * current, oid_ParseFn ** Fn
 
         if (laddr.IsIPv4())
             size = sizeof(in_addr);
-#if USE_IPV6
         else
             size = sizeof(in6_addr);
-#endif
 
         debugs(49, 6, HERE << "len" << *len << ", current-len" << current->len << ", addr=" << laddr << ", size=" << size);
 
@@ -827,10 +826,8 @@ client_Inst(oid * name, snint * len, mib_tree_entry * current, oid_ParseFn ** Fn
         if (!laddr.IsAnyAddr()) {
             if (laddr.IsIPv4())
                 newshift = sizeof(in_addr);
-#if USE_IPV6
             else
                 newshift = sizeof(in6_addr);
-#endif
 
             debugs(49, 6, HERE << "len" << *len << ", current-len" << current->len << ", addr=" << laddr << ", newshift=" << newshift);
 
@@ -1104,26 +1101,18 @@ addr2oid(IpAddress &addr, oid * Dest)
 {
     u_int i ;
     u_char *cp = NULL;
-    struct in_addr iaddr;
-#if USE_IPV6
+    struct in_addr i4addr;
     struct in6_addr i6addr;
     oid code = addr.IsIPv6()? INETADDRESSTYPE_IPV6  : INETADDRESSTYPE_IPV4 ;
     u_int size = (code == INETADDRESSTYPE_IPV4) ? sizeof(struct in_addr):sizeof(struct in6_addr);
-#else
-    oid code = INETADDRESSTYPE_IPV4 ;
-    u_int size = sizeof(struct in_addr) ;
-#endif /* USE_IPV6 */
     //  Dest[0] = code ;
     if ( code == INETADDRESSTYPE_IPV4 ) {
-        addr.GetInAddr(iaddr);
-        cp = (u_char *) &(iaddr.s_addr);
-    }
-#if USE_IPV6
-    else {
+        addr.GetInAddr(i4addr);
+        cp = (u_char *) &(i4addr.s_addr);
+    } else {
         addr.GetInAddr(i6addr);
         cp = (u_char *) &i6addr;
     }
-#endif
     for ( i=0 ; i < size ; i++) {
         // OID's are in network order
         Dest[i] = *cp++;
@@ -1141,32 +1130,23 @@ addr2oid(IpAddress &addr, oid * Dest)
 void
 oid2addr(oid * id, IpAddress &addr, u_int size)
 {
-    struct in_addr iaddr;
+    struct in_addr i4addr;
+    struct in6_addr i6addr;
     u_int i;
     u_char *cp;
-#if USE_IPV6
-    struct in6_addr i6addr;
     if ( size == sizeof(struct in_addr) )
-#endif /* USE_IPV6 */
-        cp = (u_char *) &(iaddr.s_addr);
-#if USE_IPV6
+        cp = (u_char *) &(i4addr.s_addr);
     else
         cp = (u_char *) &(i6addr);
-#endif /* USE_IPV6 */
     MemBuf tmp;
     debugs(49, 7, "oid2addr: id : " << snmpDebugOid(id, size, tmp) );
     for (i=0 ; i<size; i++) {
         cp[i] = id[i];
     }
-#if USE_IPV6
     if ( size == sizeof(struct in_addr) )
-#endif
-        addr = iaddr;
-#if USE_IPV6
+        addr = i4addr;
     else
         addr = i6addr;
-#endif
-
 }
 
 /* SNMP checklists */
diff --git a/src/stub_debug.cc b/src/stub_debug.cc
new file mode 100644 (file)
index 0000000..9a3fc61
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * A stub implementation of the Debug.h API.
+ * For use by binaries which do not need the full context debugging
+ */
+#include "config.h"
+#include "Debug.h"
+
+FILE *debug_log = NULL;
+int Debug::Levels[MAX_DEBUG_SECTIONS];
+int Debug::level;
+int Debug::TheDepth = 0;
+
+
+static void
+_db_print_stderr(const char *format, va_list args);
+
+void
+_db_print(const char *format,...)
+{
+    static char f[BUFSIZ];
+    va_list args1;
+    va_list args2;
+    va_list args3;
+
+    va_start(args1, format);
+    va_start(args2, format);
+    va_start(args3, format);
+
+    snprintf(f, BUFSIZ, "%s| %s",
+             "stub time", //debugLogTime(squid_curtime),
+             format);
+
+    _db_print_stderr(f, args2);
+
+    va_end(args1);
+    va_end(args2);
+    va_end(args3);
+}
+
+static void
+_db_print_stderr(const char *format, va_list args)
+{
+    /* FIXME? */
+    // if (opt_debug_stderr < Debug::level)
+
+    if (1 < Debug::level)
+        return;
+
+    vfprintf(stderr, format, args);
+}
+
+std::ostream &
+Debug::getDebugOut()
+{
+    assert(TheDepth >= 0);
+    ++TheDepth;
+    if (TheDepth > 1) {
+        assert(CurrentDebug);
+        *CurrentDebug << std::endl << "reentrant debuging " << TheDepth << "-{";
+    } else {
+        assert(!CurrentDebug);
+        CurrentDebug = new std::ostringstream();
+        // set default formatting flags
+        CurrentDebug->setf(std::ios::fixed);
+        CurrentDebug->precision(2);
+    }
+    return *CurrentDebug;
+}
+
+void
+Debug::finishDebug()
+{
+    assert(TheDepth >= 0);
+    assert(CurrentDebug);
+    if (TheDepth > 1) {
+        *CurrentDebug << "}-" << TheDepth << std::endl;
+    } else {
+        assert(TheDepth == 1);
+        _db_print("%s\n", CurrentDebug->str().c_str());
+        delete CurrentDebug;
+        CurrentDebug = NULL;
+    }
+    --TheDepth;
+}
+
+void
+Debug::xassert(const char *msg, const char *file, int line)
+{
+
+    if (CurrentDebug) {
+        *CurrentDebug << "assertion failed: " << file << ":" << line <<
+        ": \"" << msg << "\"";
+    }
+    abort();
+}
+
+std::ostringstream *Debug::CurrentDebug (NULL);
index a958be927926b1c7407ef9a9ddc943d3a4394a91..81535707628565f03d1b6b39f6bca5383d1447c0 100644 (file)
@@ -146,13 +146,7 @@ testHttpRequest::testIPv6HostColonBug()
     expected_port = 80;
     CPPUNIT_ASSERT_EQUAL(expected_port, aRequest->port);
     CPPUNIT_ASSERT(aRequest->method == METHOD_GET);
-#if USE_IPV6
-    /* We hasve fixed this in IPv6 build. */
     CPPUNIT_ASSERT_EQUAL(String("[2000:800::45]"), String(aRequest->GetHost()));
-#else
-    /* NO fix is possible in IPv4-pure build. */
-    CPPUNIT_ASSERT_EQUAL(String("2000:800::45"), String(aRequest->GetHost()));
-#endif
     CPPUNIT_ASSERT_EQUAL(String("/foo"), aRequest->urlpath);
     CPPUNIT_ASSERT_EQUAL(PROTO_HTTP, aRequest->protocol);
     CPPUNIT_ASSERT_EQUAL(String("http://2000:800::45/foo"), String(url));
index f56313e7a27d58f806cef5807d0cd041c0f4e6f7..9538908a137613ec782480be1fccf768366822a1 100644 (file)
@@ -1110,12 +1110,8 @@ parseEtcHosts(void)
             *nt = '\0';
             debugs(1, 5, "etc_hosts: got hostname '" << lt << "'");
 
-#if USE_IPV6
             /* For IPV6 addresses also check for a colon */
             if (Config.appendDomain && !strchr(lt, '.') && !strchr(lt, ':')) {
-#else
-            if (Config.appendDomain && !strchr(lt, '.')) {
-#endif
                 /* I know it's ugly, but it's only at reconfig */
                 strncpy(buf2, lt, 512);
                 strncat(buf2, Config.appendDomain, 512 - strlen(lt) - 1);
index 070f5eef2de2121a620d173f16c227dbe1ed9349..d862fdad3fdf5f31b4f088f1a0c15f01aa91d0f4 100644 (file)
@@ -43,17 +43,13 @@ static const char valid_hostname_chars_u[] =
     "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
     "abcdefghijklmnopqrstuvwxyz"
     "0123456789-._"
-#if USE_IPV6
     "[:]"
-#endif
     ;
 static const char valid_hostname_chars[] =
     "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
     "abcdefghijklmnopqrstuvwxyz"
     "0123456789-."
-#if USE_IPV6
     "[:]"
-#endif
     ;
 
 void
@@ -291,7 +287,6 @@ urlParse(const HttpRequestMethod& method, char *url, HttpRequest *request)
         if (*host == '[') {
             /* strip any IPA brackets. valid under IPv6. */
             dst = host;
-#if USE_IPV6
             /* only for IPv6 sadly, pre-IPv6/URL code can't handle the clean result properly anyway. */
             src = host;
             src++;
@@ -303,10 +298,6 @@ urlParse(const HttpRequestMethod& method, char *url, HttpRequest *request)
 
             /* we moved in-place, so truncate the actual hostname found */
             *(dst++) = '\0';
-#else
-            /* IPv4-pure needs to skip the whole hostname to ']' inclusive for now */
-            while (*dst != '\0' && *dst != ']') dst++;
-#endif
 
             /* skip ahead to either start of port, or original EOS */
             while (*dst != '\0' && *dst != ':') dst++;
@@ -351,12 +342,8 @@ urlParse(const HttpRequestMethod& method, char *url, HttpRequest *request)
         return NULL;
     }
 
-#if USE_IPV6
     /* For IPV6 addresses also check for a colon */
     if (Config.appendDomain && !strchr(host, '.') && !strchr(host, ':'))
-#else
-    if (Config.appendDomain && !strchr(host, '.'))
-#endif
         strncat(host, Config.appendDomain, SQUIDHOSTNAMELEN - strlen(host) - 1);
 
     /* remove trailing dots from hostnames */
@@ -889,11 +876,8 @@ URLHostName::findHostStart()
     while (*hostStart != '\0' && *hostStart == '/')
         ++hostStart;
 
-#if USE_IPV6
     if (*hostStart == ']')
         ++hostStart;
-#endif
-
 }
 
 void
@@ -907,11 +891,8 @@ URLHostName::trimTrailingChars()
     if ((t = strrchr(Host, ':')))
         *t = '\0';
 
-#if USE_IPV6
     if ((t = strchr(Host, ']')))
         *t = '\0';
-#endif
-
 }
 
 void
index 550183280e804cfcf30724eb224578286db53dc6..23d6f4734cc135f688eecfc798fb021360759667 100644 (file)
@@ -11,6 +11,15 @@ AUTOMAKE_OPTIONS = subdir-objects
 ## we need our local files too (but avoid -I. at all costs)
 INCLUDES += -I$(srcdir)
 
+##  src/stub_debug.cc provides a usable stub debugs() API.
+stub_debug.cc: $(top_srcdir)/src/stub_debug.cc
+       cp $(top_srcdir)/src/stub_debug.cc .
+
+##  src/time.cc provides a usable time API.
+time.cc: $(top_srcdir)/src/time.cc
+       cp $(top_srcdir)/src/time.cc .
+
+CLEANFILES += stub_debug.cc time.cc
 
 SUBDIRS                = 
 
@@ -25,8 +34,9 @@ man_MANS = \
 
 DEFAULT_CACHEMGR_CONFIG = $(sysconfdir)/cachemgr.conf
 
-squidclient_SOURCES = squidclient.cc
-cachemgr__CGIEXT__SOURCES = cachemgr.cc
+squidclient_SOURCES = squidclient.cc time.cc stub_debug.cc
+
+cachemgr__CGIEXT__SOURCES = cachemgr.cc time.cc stub_debug.cc
 cachemgr__CGIEXT__CXXFLAGS = -DDEFAULT_CACHEMGR_CONFIG=\"$(DEFAULT_CACHEMGR_CONFIG)\" $(AM_CXXFLAGS)
 
 LDADD = \
index 89338b4324a54dce1d08ceb444ae0aebb21d48ae..35cc6a35d2e5657121796a75212b7153d99bf04e 100644 (file)
  */
 
 #include "config.h"
+#include "getfullhostname.h"
+#include "ip/IpAddress.h"
 #include "rfc1738.h"
+#include "util.h"
 
 #if HAVE_UNISTD_H
 #include <unistd.h>
@@ -129,10 +132,6 @@ extern "C" {
 }
 #endif
 
-#include "util.h"
-#include "ip/IpAddress.h"
-#include "getfullhostname.h"
-
 #ifndef DEFAULT_CACHEMGR_CONFIG
 #define DEFAULT_CACHEMGR_CONFIG "/etc/squid/cachemgr.conf"
 #endif
index e45496fad127fa471b0418120da3b27f67e36b58..479de4daadfe8f592187d0e0f8612596148e6fa2 100644 (file)
@@ -33,6 +33,9 @@
  */
 
 #include "config.h"
+#include "ip/IpAddress.h"
+#include "util.h"
+#include "squid_types.h"
 
 #ifdef _SQUID_MSWIN_
 /** \cond AUTODOCS-IGNORE */
@@ -84,11 +87,6 @@ using namespace Squid;
 #include <getopt.h>
 #endif
 
-#include "squid_types.h"
-
-#include "util.h"
-#include "ip/IpAddress.h"
-
 #ifndef BUFSIZ
 #define BUFSIZ         8192
 #endif