From 4c28adf19d1e871f18fe9f443fb26edca2b506d6 Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Tue, 27 Jul 2010 07:02:31 -0600 Subject: [PATCH] Replace most USE_IPV6 with run-time support probing 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. --- compat/Makefile.am | 1 + compat/compat.h | 1 + compat/os/freebsd.h | 9 ++ compat/os/macosx.h | 26 ++++ compat/os/openbsd.h | 14 ++ compat/os/solaris.h | 5 + configure.in | 114 ++-------------- lib/getaddrinfo.c | 4 - src/Makefile.am | 1 - src/acl/Ip.cc | 20 +-- src/cache_cf.cc | 61 +++++---- src/cf.data.pre | 12 +- src/client_db.cc | 6 +- src/client_side.cc | 2 +- src/comm.cc | 30 +---- src/comm_poll.cc | 9 +- src/comm_select.cc | 9 +- src/comm_select_win32.cc | 9 +- src/dns_internal.cc | 104 +++++---------- src/dnsserver.cc | 2 - src/external_acl.cc | 9 +- src/ftp.cc | 27 ++-- src/icmp/Icmp.h | 2 - src/icmp/Icmp6.cc | 4 +- src/icmp/Icmp6.h | 3 - src/icmp/IcmpPinger.cc | 4 - src/icmp/IcmpSquid.cc | 6 +- src/icmp/net_db.cc | 3 - src/icmp/pinger.cc | 26 +--- src/internal.cc | 14 +- src/ip/IpAddress.cc | 250 ++++------------------------------- src/ip/IpAddress.h | 58 +------- src/ip/IpIntercept.cc | 16 +-- src/ip/Makefile.am | 10 +- src/ip/testIpAddress.cc | 87 ++---------- src/ip/testIpAddress.h | 8 -- src/ip/tools.cc | 79 +++++++++++ src/ip/tools.h | 21 +++ src/ipcache.cc | 25 +--- src/main.cc | 3 + src/multicast.cc | 6 +- src/snmp_core.cc | 38 ++---- src/stub_debug.cc | 97 ++++++++++++++ src/tests/testHttpRequest.cc | 6 - src/tools.cc | 4 - src/url.cc | 19 --- tools/Makefile.am | 14 +- tools/cachemgr.cc | 7 +- tools/squidclient.cc | 8 +- 49 files changed, 479 insertions(+), 814 deletions(-) create mode 100644 compat/os/macosx.h create mode 100644 src/ip/tools.cc create mode 100644 src/ip/tools.h create mode 100644 src/stub_debug.cc diff --git a/compat/Makefile.am b/compat/Makefile.am index 9ff0fc182e..1bfccce74a 100644 --- a/compat/Makefile.am +++ b/compat/Makefile.am @@ -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 \ diff --git a/compat/compat.h b/compat/compat.h index bacbc5aae2..3059cdeff9 100644 --- a/compat/compat.h +++ b/compat/compat.h @@ -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" diff --git a/compat/os/freebsd.h b/compat/os/freebsd.h index e4fb395942..88708ccbdd 100644 --- a/compat/os/freebsd.h +++ b/compat/os/freebsd.h @@ -27,5 +27,14 @@ #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 index 0000000000..4490e24402 --- /dev/null +++ b/compat/os/macosx.h @@ -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 */ diff --git a/compat/os/openbsd.h b/compat/os/openbsd.h index eae2cdf003..d11e2affd4 100644 --- a/compat/os/openbsd.h +++ b/compat/os/openbsd.h @@ -21,5 +21,19 @@ #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 */ diff --git a/compat/os/solaris.h b/compat/os/solaris.h index fe1c039ea3..eb1d1b92e6 100644 --- a/compat/os/solaris.h +++ b/compat/os/solaris.h @@ -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 */ diff --git a/configure.in b/configure.in index b77bedcb0d..1d82b2cf56 100644 --- a/configure.in +++ b/configure.in @@ -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 -# include - 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 -# include -# include -#if HAVE_NETINET_IN6_H -# include -#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 #include #include - ]], [[ 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], diff --git a/lib/getaddrinfo.c b/lib/getaddrinfo.c index 25917df2af..f9350d4b50 100644 --- a/lib/getaddrinfo.c +++ b/lib/getaddrinfo.c @@ -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; } diff --git a/src/Makefile.am b/src/Makefile.am index 178521fb6d..0abe1bc989 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 >$@ diff --git a/src/acl/Ip.cc b/src/acl/Ip.cc index 982293be44..14be32b9bb 100644 --- a/src/acl/Ip.cc +++ b/src/acl/Ip.cc @@ -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)) { diff --git a/src/cache_cf.cc b/src/cache_cf.cc index 29c9dd5b7b..f2863d2521 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -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; diff --git a/src/cf.data.pre b/src/cf.data.pre index f2f033f545..57dba6a57a 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -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 diff --git a/src/client_db.cc b/src/client_db.cc index 77697e2f37..b91c034786 100644 --- a/src/client_db.cc +++ b/src/client_db.cc @@ -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; diff --git a/src/client_side.cc b/src/client_side.cc index a3f4b8d90d..dc185fea07 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -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); diff --git a/src/comm.cc b/src/comm.cc index 4459e85c1c..4937bb2874 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -49,6 +49,7 @@ #include "ip/IpAddress.h" #include "ip/IpIntercept.h" #include "protos.h" +#include "ip/tools.h" #if defined(_SQUID_CYGWIN_) #include @@ -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); diff --git a/src/comm_poll.cc b/src/comm_poll.cc index 2b9639b034..9b00ea3631 100644 --- a/src/comm_poll.cc +++ b/src/comm_poll.cc @@ -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); diff --git a/src/comm_select.cc b/src/comm_select.cc index 95500c7af3..8d1a330db1 100644 --- a/src/comm_select.cc +++ b/src/comm_select.cc @@ -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); diff --git a/src/comm_select_win32.cc b/src/comm_select_win32.cc index cdb572589f..edada5c6d1 100644 --- a/src/comm_select_win32.cc +++ b/src/comm_select_win32.cc @@ -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); diff --git a/src/dns_internal.cc b/src/dns_internal.cc index f2c4f1e666..6512b6ce9a 100644 --- a/src/dns_internal.cc +++ b/src/dns_internal.cc @@ -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); diff --git a/src/dnsserver.cc b/src/dnsserver.cc index 871af9155c..99ffb14337 100644 --- a/src/dnsserver.cc +++ b/src/dnsserver.cc @@ -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; diff --git a/src/external_acl.cc b/src/external_acl.cc index 5bc3c56e27..def991913a 100644 --- a/src/external_acl.cc +++ b/src/external_acl.cc @@ -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; } diff --git a/src/ftp.cc b/src/ftp.cc index 745c684489..5b72df2e9a 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -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; diff --git a/src/icmp/Icmp.h b/src/icmp/Icmp.h index d9b9715c04..f30d7f6471 100644 --- a/src/icmp/Icmp.h +++ b/src/icmp/Icmp.h @@ -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 diff --git a/src/icmp/Icmp6.cc b/src/icmp/Icmp6.cc index 9f0e492ba0..f37e23766d 100644 --- a/src/icmp/Icmp6.cc +++ b/src/icmp/Icmp6.cc @@ -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 */ diff --git a/src/icmp/Icmp6.h b/src/icmp/Icmp6.h index edcc5ddea3..7b688f1672 100644 --- a/src/icmp/Icmp6.h +++ b/src/icmp/Icmp6.h @@ -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 */ diff --git a/src/icmp/IcmpPinger.cc b/src/icmp/IcmpPinger.cc index 773f235372..88398b4d54 100644 --- a/src/icmp/IcmpPinger.cc +++ b/src/icmp/IcmpPinger.cc @@ -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()) { diff --git a/src/icmp/IcmpSquid.cc b/src/icmp/IcmpSquid.cc index ea45720699..6250a670af 100644 --- a/src/icmp/IcmpSquid.cc +++ b/src/icmp/IcmpSquid.cc @@ -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"); diff --git a/src/icmp/net_db.cc b/src/icmp/net_db.cc index 38b1c238e7..dcaebb612f 100644 --- a/src/icmp/net_db.cc +++ b/src/icmp/net_db.cc @@ -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; diff --git a/src/icmp/pinger.cc b/src/icmp/pinger.cc index d3380bd722..4837ad59d7 100644 --- a/src/icmp/pinger.cc +++ b/src/icmp/pinger.cc @@ -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(); } diff --git a/src/internal.cc b/src/internal.cc index f6082d27e1..5b4ccdbe6b 100644 --- a/src/internal.cc +++ b/src/internal.cc @@ -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); diff --git a/src/ip/IpAddress.cc b/src/ip/IpAddress.cc index aea1872850..5614dac2a0 100644 --- a/src/ip/IpAddress.cc +++ b/src/ip/IpAddress.cc @@ -36,6 +36,7 @@ #include "config.h" #include "ip/IpAddress.h" +#include "ip/tools.h" #include "util.h" @@ -52,9 +53,6 @@ #include /* 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. */ @@ -65,18 +63,7 @@ # 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')); \ @@ -85,14 +72,6 @@ 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 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 diff --git a/src/ip/IpAddress.h b/src/ip/IpAddress.h index 2874118823..fb6fec34ad 100644 --- a/src/ip/IpAddress.h +++ b/src/ip/IpAddress.h @@ -66,31 +66,6 @@ #include #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 }; diff --git a/src/ip/IpIntercept.cc b/src/ip/IpIntercept.cc index 35206a6276..e35aabe7df 100644 --- a/src/ip/IpIntercept.cc +++ b/src/ip/IpIntercept.cc @@ -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()) { diff --git a/src/ip/Makefile.am b/src/ip/Makefile.am index 467b336ce5..8f858eec76 100644 --- a/src/ip/Makefile.am +++ b/src/ip/Makefile.am @@ -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) diff --git a/src/ip/testIpAddress.cc b/src/ip/testIpAddress.cc index e7f7f8e1a4..0048808fa6 100644 --- a/src/ip/testIpAddress.cc +++ b/src/ip/testIpAddress.cc @@ -1,6 +1,7 @@ #include "config.h" #include "testIpAddress.h" #include "ip/IpAddress.h" +#include "ip/tools.h" #if HAVE_CSTRING #include @@ -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 ); diff --git a/src/ip/testIpAddress.h b/src/ip/testIpAddress.h index a223686f2b..66ad59e503 100644 --- a/src/ip/testIpAddress.h +++ b/src/ip/testIpAddress.h @@ -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 index 0000000000..2c4daa19b4 --- /dev/null +++ b/src/ip/tools.cc @@ -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 +#endif +#if HAVE_NETINET_IN_H +#include +#endif +#if HAVE_NETINET_IN6_H +#include +#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 index 0000000000..5b9831a488 --- /dev/null +++ b/src/ip/tools.h @@ -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 */ diff --git a/src/ipcache.cc b/src/ipcache.cc index 01b61d3972..f222623465 100644 --- a/src/ipcache.cc +++ b/src/ipcache.cc @@ -31,9 +31,10 @@ */ #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; } diff --git a/src/main.cc b/src/main.cc index 3fe99cce8e..fdfe274012 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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(); diff --git a/src/multicast.cc b/src/multicast.cc index b3795e1ef3..c8f273847f 100644 --- a/src/multicast.cc +++ b/src/multicast.cc @@ -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); diff --git a/src/snmp_core.cc b/src/snmp_core.cc index b45ee0c0c7..4fec167c6c 100644 --- a/src/snmp_core.cc +++ b/src/snmp_core.cc @@ -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= 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); diff --git a/src/tests/testHttpRequest.cc b/src/tests/testHttpRequest.cc index a958be9279..8153570762 100644 --- a/src/tests/testHttpRequest.cc +++ b/src/tests/testHttpRequest.cc @@ -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)); diff --git a/src/tools.cc b/src/tools.cc index f56313e7a2..9538908a13 100644 --- a/src/tools.cc +++ b/src/tools.cc @@ -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); diff --git a/src/url.cc b/src/url.cc index 070f5eef2d..d862fdad3f 100644 --- a/src/url.cc +++ b/src/url.cc @@ -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 diff --git a/tools/Makefile.am b/tools/Makefile.am index 550183280e..23d6f4734c 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -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 = \ diff --git a/tools/cachemgr.cc b/tools/cachemgr.cc index 89338b4324..35cc6a35d2 100644 --- a/tools/cachemgr.cc +++ b/tools/cachemgr.cc @@ -31,7 +31,10 @@ */ #include "config.h" +#include "getfullhostname.h" +#include "ip/IpAddress.h" #include "rfc1738.h" +#include "util.h" #if HAVE_UNISTD_H #include @@ -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 diff --git a/tools/squidclient.cc b/tools/squidclient.cc index e45496fad1..479de4daad 100644 --- a/tools/squidclient.cc +++ b/tools/squidclient.cc @@ -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 #endif -#include "squid_types.h" - -#include "util.h" -#include "ip/IpAddress.h" - #ifndef BUFSIZ #define BUFSIZ 8192 #endif -- 2.47.3