]>
Commit | Line | Data |
---|---|---|
055421ee | 1 | /* |
5b74111a | 2 | * Copyright (C) 1996-2018 The Squid Software Foundation and contributors |
055421ee | 3 | * |
bbc27441 AJ |
4 | * Squid software is distributed under GPLv2+ license and includes |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
055421ee AJ |
7 | */ |
8 | ||
bbc27441 AJ |
9 | /* DEBUG: section 21 Misc Functions */ |
10 | ||
f7f3304a | 11 | #include "squid.h" |
055421ee AJ |
12 | #include "Debug.h" |
13 | #include "ip/tools.h" | |
14 | ||
60d08fa6 AJ |
15 | #if HAVE_UNISTD_H |
16 | #include <unistd.h> | |
17 | #endif | |
055421ee AJ |
18 | #if HAVE_SYS_SOCKET_H |
19 | #include <sys/socket.h> | |
20 | #endif | |
21 | #if HAVE_NETINET_IN_H | |
22 | #include <netinet/in.h> | |
23 | #endif | |
24 | #if HAVE_NETINET_IN6_H | |
25 | #include <netinet/in6.h> | |
26 | #endif | |
27 | ||
28 | int Ip::EnableIpv6 = IPV6_OFF; | |
29 | ||
30 | void | |
31 | Ip::ProbeTransport() | |
32 | { | |
055421ee AJ |
33 | // check for usable IPv6 sockets |
34 | int s = socket(PF_INET6, SOCK_STREAM, 0); | |
35 | if (s < 0) { | |
36 | debugs(3, 2, "IPv6 not supported on this machine. Auto-Disabled."); | |
37 | EnableIpv6 = IPV6_OFF; | |
38 | return; | |
39 | } | |
40 | ||
41 | // Test for v4-mapping capability | |
ca44fd48 AJ |
42 | // (AKA. the operating system supports RFC 3493 section 5.3) |
43 | #if defined(IPV6_V6ONLY) | |
055421ee | 44 | int tos = 0; |
6df7ad56 | 45 | if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &tos, sizeof(int)) == 0) { |
055421ee AJ |
46 | debugs(3, 2, "Detected IPv6 hybrid or v4-mapping stack..."); |
47 | EnableIpv6 |= IPV6_SPECIAL_V4MAPPING; | |
48 | } else { | |
49 | debugs(3, 2, "Detected split IPv4 and IPv6 stacks ..."); | |
e0209dae | 50 | EnableIpv6 |= IPV6_SPECIAL_SPLITSTACK; |
055421ee | 51 | } |
ca44fd48 AJ |
52 | #else |
53 | // compliance here means they at least supply the option for compilers building code | |
54 | // even if possibly to return hard-coded -1 on use. | |
55 | debugs(3, 2, "Missing RFC 3493 compliance - attempting split IPv4 and IPv6 stacks ..."); | |
56 | EnableIpv6 |= IPV6_SPECIAL_SPLITSTACK; | |
57 | #endif | |
041c8f46 AJ |
58 | // TODO: attempt to use the socket to connect somewhere ? |
59 | // needs to be safe to contact and with guaranteed working IPv6 at the other end. | |
055421ee AJ |
60 | close(s); |
61 | ||
041c8f46 | 62 | #if USE_IPV6 |
055421ee AJ |
63 | debugs(3, 2, "IPv6 transport " << (EnableIpv6?"Enabled":"Disabled")); |
64 | #else | |
041c8f46 AJ |
65 | debugs(3, 2, "IPv6 transport " << (EnableIpv6?"Available":"Disabled")); |
66 | if (EnableIpv6 != IPV6_OFF) { | |
67 | debugs(3, DBG_CRITICAL, "WARNING: BCP 177 violation. IPv6 transport forced OFF by build parameters."); | |
68 | EnableIpv6 = IPV6_OFF; | |
69 | } | |
055421ee AJ |
70 | #endif |
71 | } | |
f53969cc | 72 |