tools.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9/* DEBUG: section 21 Misc Functions */
10
11#include "squid.h"
12#include "debug/Messages.h"
13#include "ip/Address.h"
14#include "ip/tools.h"
15
16#if HAVE_UNISTD_H
17#include <unistd.h>
18#endif
19#if HAVE_SYS_SOCKET_H
20#include <sys/socket.h>
21#endif
22#if HAVE_NETINET_IN_H
23#include <netinet/in.h>
24#endif
25#if HAVE_NETINET_IN6_H
26#include <netinet/in6.h>
27#endif
28
30
31void
33{
34 // check for usable IPv6 sockets
35 int s = socket(PF_INET6, SOCK_STREAM, 0);
36 if (s < 0) {
37 debugs(3, 2, "IPv6 not supported on this machine. Auto-Disabled.");
39 return;
40 }
41
42 // Test for v4-mapping capability
43 // (AKA. the operating system supports RFC 3493 section 5.3)
44#if defined(IPV6_V6ONLY)
45 int tos = 0;
46 if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &tos, sizeof(int)) == 0) {
47 debugs(3, 2, "Detected IPv6 hybrid or v4-mapping stack...");
49 } else {
50 debugs(3, 2, "Detected split IPv4 and IPv6 stacks ...");
52 }
53#else
54 // compliance here means they at least supply the option for compilers building code
55 // even if possibly to return hard-coded -1 on use.
56 debugs(3, 2, "Missing RFC 3493 compliance - attempting split IPv4 and IPv6 stacks ...");
58#endif
59
60 // Test for IPv6 loopback/localhost address binding
61 Ip::Address ip;
62 ip.setLocalhost();
63 if (ip.isIPv6()) { // paranoid; always succeeds if we got this far
64 struct sockaddr_in6 sin;
65 ip.getSockAddr(sin);
66 if (bind(s, reinterpret_cast<struct sockaddr *>(&sin), sizeof(sin)) != 0) {
67 debugs(3, Critical(66), "WARNING: BCP 177 violation. Detected non-functional IPv6 loopback.");
69 } else {
70 debugs(3, 2, "Detected functional IPv6 loopback ...");
71 }
72 }
73
74 close(s);
75
76#if USE_IPV6
77 debugs(3, 2, "IPv6 transport " << (EnableIpv6?"Enabled":"Disabled"));
78#else
79 debugs(3, 2, "IPv6 transport " << (EnableIpv6?"Available":"Disabled"));
80 if (EnableIpv6 != IPV6_OFF) {
81 debugs(3, Critical(67), "WARNING: BCP 177 violation. IPv6 transport forced OFF by build parameters.");
83 }
84#endif
85}
86
void getSockAddr(struct sockaddr_storage &addr, const int family) const
Definition: Address.cc:924
void setLocalhost()
Definition: Address.cc:255
bool isIPv6() const
Definition: Address.cc:164
#define Critical(id)
Definition: Messages.h:92
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:194
#define IPV6_SPECIAL_SPLITSTACK
Definition: tools.h:22
#define IPV6_SPECIAL_V4MAPPING
Definition: tools.h:21
#define IPV6_OFF
Definition: tools.h:19
void ProbeTransport(void)
Probe to discover IPv6 capabilities.
int EnableIpv6
Whether IPv6 is supported and type of support.
Definition: tools.h:25

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors