]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ip/tools.cc
Replace most USE_IPV6 with run-time support probing
[thirdparty/squid.git] / src / ip / tools.cc
CommitLineData
055421ee
AJ
1/*
2 * DEBUG: section 21 Misc Functions
3 * AUTHOR: Amos Jeffries
4 *
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
7 *
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
30 *
31 */
32
33#include "config.h"
34//#include "compat/getaddrinfo.h"
35//#include "compat/getnameinfo.h"
36#include "Debug.h"
37#include "ip/tools.h"
38
39#if HAVE_SYS_SOCKET_H
40#include <sys/socket.h>
41#endif
42#if HAVE_NETINET_IN_H
43#include <netinet/in.h>
44#endif
45#if HAVE_NETINET_IN6_H
46#include <netinet/in6.h>
47#endif
48
49int Ip::EnableIpv6 = IPV6_OFF;
50
51void
52Ip::ProbeTransport()
53{
54#if USE_IPV6
55 // check for usable IPv6 sockets
56 int s = socket(PF_INET6, SOCK_STREAM, 0);
57 if (s < 0) {
58 debugs(3, 2, "IPv6 not supported on this machine. Auto-Disabled.");
59 EnableIpv6 = IPV6_OFF;
60 return;
61 }
62
63 // Test for v4-mapping capability
64 int tos = 0;
65 if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &tos, sizeof(int)) < 0) {
66 debugs(3, 2, "Detected IPv6 hybrid or v4-mapping stack...");
67 EnableIpv6 |= IPV6_SPECIAL_V4MAPPING;
68 } else {
69 debugs(3, 2, "Detected split IPv4 and IPv6 stacks ...");
70 // EnableIpv6 |= IPV6_SPECIAL_SPLITSTACK;
71 // TODO: remove death when split-stack is supported.
72 EnableIpv6 = IPV6_OFF;
73 }
74 close(s);
75
76 debugs(3, 2, "IPv6 transport " << (EnableIpv6?"Enabled":"Disabled"));
77#else
78 debugs(3, 2, "IPv6 transport forced OFF by build parameters.");
79 EnableIpv6 = IPV6_OFF;
80#endif
81}