]>
Commit | Line | Data |
---|---|---|
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 | ||
f7f3304a | 33 | #include "squid.h" |
055421ee AJ |
34 | #include "Debug.h" |
35 | #include "ip/tools.h" | |
36 | ||
60d08fa6 AJ |
37 | #if HAVE_UNISTD_H |
38 | #include <unistd.h> | |
39 | #endif | |
055421ee AJ |
40 | #if HAVE_SYS_SOCKET_H |
41 | #include <sys/socket.h> | |
42 | #endif | |
43 | #if HAVE_NETINET_IN_H | |
44 | #include <netinet/in.h> | |
45 | #endif | |
46 | #if HAVE_NETINET_IN6_H | |
47 | #include <netinet/in6.h> | |
48 | #endif | |
49 | ||
50 | int Ip::EnableIpv6 = IPV6_OFF; | |
51 | ||
52 | void | |
53 | Ip::ProbeTransport() | |
54 | { | |
55 | #if USE_IPV6 | |
56 | // check for usable IPv6 sockets | |
57 | int s = socket(PF_INET6, SOCK_STREAM, 0); | |
58 | if (s < 0) { | |
59 | debugs(3, 2, "IPv6 not supported on this machine. Auto-Disabled."); | |
60 | EnableIpv6 = IPV6_OFF; | |
61 | return; | |
62 | } | |
63 | ||
64 | // Test for v4-mapping capability | |
ca44fd48 AJ |
65 | // (AKA. the operating system supports RFC 3493 section 5.3) |
66 | #if defined(IPV6_V6ONLY) | |
055421ee | 67 | int tos = 0; |
6df7ad56 | 68 | if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &tos, sizeof(int)) == 0) { |
055421ee AJ |
69 | debugs(3, 2, "Detected IPv6 hybrid or v4-mapping stack..."); |
70 | EnableIpv6 |= IPV6_SPECIAL_V4MAPPING; | |
71 | } else { | |
72 | debugs(3, 2, "Detected split IPv4 and IPv6 stacks ..."); | |
e0209dae | 73 | EnableIpv6 |= IPV6_SPECIAL_SPLITSTACK; |
055421ee | 74 | } |
ca44fd48 AJ |
75 | #else |
76 | // compliance here means they at least supply the option for compilers building code | |
77 | // even if possibly to return hard-coded -1 on use. | |
78 | debugs(3, 2, "Missing RFC 3493 compliance - attempting split IPv4 and IPv6 stacks ..."); | |
79 | EnableIpv6 |= IPV6_SPECIAL_SPLITSTACK; | |
80 | #endif | |
055421ee AJ |
81 | close(s); |
82 | ||
83 | debugs(3, 2, "IPv6 transport " << (EnableIpv6?"Enabled":"Disabled")); | |
84 | #else | |
85 | debugs(3, 2, "IPv6 transport forced OFF by build parameters."); | |
86 | EnableIpv6 = IPV6_OFF; | |
87 | #endif | |
88 | } |