From ea61d5860cea0ed3802c1da0e40955b7046469e8 Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Fri, 14 May 2010 04:07:21 +0200 Subject: [PATCH] IPv4 fallback if IPv6 disabled --- src/comm.cc | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/comm.cc b/src/comm.cc index ebaf35d12d..16618c0ac2 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -630,16 +630,6 @@ comm_open_listener(int sock_type, /* attempt native enabled port. */ sock = comm_openex(sock_type, proto, addr, flags, 0, note); -#if USE_IPV6 - /* under IPv6 there is the possibility IPv6 is present but disabled. */ - /* try again as IPv4-native */ - if ( sock < 0 && addr.IsIPv6() && addr.SetIPv4() ) { - /* attempt to open this IPv4-only. */ - sock = comm_openex(sock_type, proto, addr, flags, 0, note); - debugs(50, 2, HERE << "attempt open " << note << " socket on: " << addr); - } -#endif - return sock; } @@ -724,7 +714,24 @@ comm_openex(int sock_type, debugs(50, 3, "comm_openex: Attempt open socket for: " << addr ); - if ((new_socket = socket(AI->ai_family, AI->ai_socktype, AI->ai_protocol)) < 0) { + 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 ( sock < 0 && addr.IsIPv6() && addr.SetIPv4() ) { + /* attempt to open this IPv4-only. */ + addr.FreeAddrInfo(AI); + /* Setup the socket addrinfo details for use */ + addr.GetAddrInfo(AI); + AI->ai_socktype = sock_type; + AI->ai_protocol = proto; + debugs(50, 3, "comm_openex: Attempt fallback open socket for: " << addr ); + new_socket = comm_openex(sock_type, proto, addr, flags, 0, note); + 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() * are failing because the open file table is full. This * limits the number of simultaneous clients */ -- 2.47.3