tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 39621] Strange result in getRemoteAddr() and Access Logs using APR
Date Mon, 26 Jul 2010 05:48:48 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=39621

--- Comment #7 from Lalit Mishra <lalit.mishra@airtightnetworks.com> 2010-07-26 01:48:36
EDT ---
Created an attachment (id=25801)
 --> (https://issues.apache.org/bugzilla/attachment.cgi?id=25801)
apr-1.3.9-patch

We faced this problem with RedHat 9 only when IPv6 is disabled.
Linux 2.6.12.3 #1 SMP Tue Jun 10 17:56:55 IST 2008 i686 i686 i386 GNU/Linux
(this is not the stock kernel in RH 9).

APR version 1.3.9.

Absence of AI_ADDRCONFIG flag for getaddrinfo in glibc is the root cause. 
>From man getaddrinfo -

    If hints.ai_flags includes the AI_ADDRCONFIG flag, then IPv4 addresses are
returned in the list pointed to by result only if the  local system has at lea
st one IPv4 address configured, and IPv6 addresses are only returned if the
local system has at least one IPv6 address configured.

When tomcat searches for local address to bind, it finally calls call_resolver
function of sockaddr.c in APR with hostname=null. As AI_ADDRCONFIG flag is not
present, getaddrinfo returns "::" and 0.0.0.0 in the list of available
addresses.  The tcnative method (Address.info, see address.c) prefers the IPv6
(::) address among these and returns this to Tomcat, and Tomcat specifies this
address to bind to the socket (surprisingly, the kernel does not complain when
binding an IPv6 address to an AF_INET socket). Therefore, APR code falsely ends
up setting AF_INET6 to local_addr->family and (later when accept returns) to
remote_addr->family as well. Thus when an IPv4 host connects, though accept
returns proper IPv4 address to APR, APR still believes it to be IPv6 address
and messes up while translating to presentation format.

Fix:
If AI_ADDRCONFIF flag is not present, we need to determine if IPv6 is
*actually* available or not. This can be achieved by trying to open an IPv6
socket. If this fails then set hints.ai_family to AF_INET so that getaddrinfo
returns IPv4 addresses only. Of course do this only when family has been
specified as AF_UNSPEC. We do not want to return IPv4 addresses when asked
specifically for IPv6 addresses.
Please see attached patch (for APR 1.3.9).

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message