You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bugs@apr.apache.org by bu...@apache.org on 2010/07/30 13:09:12 UTC

DO NOT REPLY [Bug 49678] New: getRemoteAddr() returns IPv6 address on RedHat 9 when IPv6 is disabled

https://issues.apache.org/bugzilla/show_bug.cgi?id=49678

           Summary: getRemoteAddr() returns IPv6 address on RedHat 9 when
                    IPv6 is disabled
           Product: APR
           Version: 1.3.9
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: APR
        AssignedTo: bugs@apr.apache.org
        ReportedBy: lalit.mishra@airtightnetworks.com


This issue is reported in bug#39621. 
Opening this bug in product APR.

The address returned is not actually an IPv6 address, but looks like one. 

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 (2.3.2-27.9.7) 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: bugs-unsubscribe@apr.apache.org
For additional commands, e-mail: bugs-help@apr.apache.org


DO NOT REPLY [Bug 49678] getRemoteAddr() returns IPv6 address on RedHat 9 when IPv6 is disabled

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49678

--- Comment #4 from Joe Orton <jo...@redhat.com> 2010-08-02 08:48:42 EDT ---
This explanation is still not clear to me.

What do you mean precisely by having "IPv6 disabled"?

Are you saying there is a kernel bug here which needs to be worked around?

Maybe you could give a minimal example of code needed to reproduce this with
APR, the output of running that code, and the output from running it under
strace (or similar).

-- 
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: bugs-unsubscribe@apr.apache.org
For additional commands, e-mail: bugs-help@apr.apache.org


DO NOT REPLY [Bug 49678] getRemoteAddr() returns IPv6 address on RedHat 9 when IPv6 is disabled

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49678

--- Comment #10 from Lalit Mishra <la...@airtightnetworks.com> 2010-08-10 08:39:40 EDT ---
(In reply to comment #9)
> Created an attachment (id=25874)
 --> (https://issues.apache.org/bugzilla/attachment.cgi?id=25874) [details]
> possible fix
> 
> Does it work if you apply this patch to APR?

Yes, this works as well.

-- 
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: bugs-unsubscribe@apr.apache.org
For additional commands, e-mail: bugs-help@apr.apache.org


DO NOT REPLY [Bug 49678] getRemoteAddr() returns IPv6 address on RedHat 9 when IPv6 is disabled

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49678

--- Comment #9 from Joe Orton <jo...@redhat.com> 2010-08-10 06:57:11 EDT ---
Created an attachment (id=25874)
 --> (https://issues.apache.org/bugzilla/attachment.cgi?id=25874)
possible fix

Does it work if you apply this patch to APR?

-- 
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: bugs-unsubscribe@apr.apache.org
For additional commands, e-mail: bugs-help@apr.apache.org


DO NOT REPLY [Bug 49678] getRemoteAddr() returns IPv6 address on RedHat 9 when IPv6 is disabled

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49678

--- Comment #3 from Lalit Mishra <la...@airtightnetworks.com> 2010-08-02 02:18:47 EDT ---
(In reply to comment #2)
> "messes up while translating to presentation format."
> 
> messes up how?  It sounds like you are trying to work around some bug in
> handling v4-mapped IPv6 addresses.  What is the actual bug?

This issue is happening when IPv6 is *disabled*. So the socket is actually
bound with AF_INET while APR believes it has been bound with AF_INET6. So,
accept actually returns IPv4 and not v4 mapped IPv6 address. So the conversion
to presentation format essentially produces garbage, which looks like some IPv6
address. For example: ::68f3:7fbd:dcdb:240, ::78f4:dfbd:dcdb:240, etc.

The actual bug is because of "getaddrinfo". It returns IPv6 address "::" even
when IPv6 is disabled. This behavior of getaddrinfo can be bypassed with
AI_ADDRCONFIG flag, which is absent in RH9 and hence the bug.

-- 
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: bugs-unsubscribe@apr.apache.org
For additional commands, e-mail: bugs-help@apr.apache.org


DO NOT REPLY [Bug 49678] getRemoteAddr() returns IPv6 address on RedHat 9 when IPv6 is disabled

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49678

--- Comment #7 from Joe Orton <jo...@redhat.com> 2010-08-04 06:51:31 EDT ---
Sorry I meant bind() will fail there.

-- 
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: bugs-unsubscribe@apr.apache.org
For additional commands, e-mail: bugs-help@apr.apache.org


DO NOT REPLY [Bug 49678] getRemoteAddr() returns IPv6 address on RedHat 9 when IPv6 is disabled

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49678

--- Comment #8 from Lalit Mishra <la...@airtightnetworks.com> 2010-08-05 03:10:27 EDT ---
(In reply to comment #7)
> Sorry I meant bind() will fail there.

As mentioned in bug description 

> (surprisingly, the kernel does not complain when
binding an IPv6 address to an AF_INET socket).

bind() does not fail.

Let me illustrate the whole problem with a minimal program. This listing is
extension of previous program. Still this code follows the same behavior as
AprEndPoint.init() does.


#include "apr.h"
#include "apr_pools.h"
#include "apr_arch_networkio.h"
#include "apr_network_io.h"
#include "apr_strings.h"
#include "apr_mmap.h"
#include "stdio.h"

int main() {
    apr_pool_t *pool = NULL;
    apr_sockaddr_t *sa, *sl, *bindAddr = NULL;
    apr_int32_t f = 0;
    apr_socket_t *socket, *acceptedSocket;
    int ret_val = 0;

    apr_initialize();
    apr_pool_create(&pool, NULL);

    apr_sockaddr_info_get(&sa, NULL, AF_UNSPEC, 1756, f, pool);

    sl = sa;

        /* if there is an IPv6 address returned, prefer to use that (tcnative
         * has similar behavior).
    while(sl) {
        char addrStr[100];

        memset(addrStr, '\0', 100);

        if(sl->family == AF_INET6) {
            apr_sockaddr_ip_getbuf (addrStr, 99, sl);
            printf("Found IPv6 address %s. Breaking.\n", addrStr);
            bindAddr = sl;
        }

        sl = sl->next;
    }

    if(bindAddr == NULL) 
        bindAddr = sa;

    ret_val = apr_socket_create(&socket, AF_UNSPEC, SOCK_STREAM, APR_PROTO_TCP,
pool);

    ret_val = apr_socket_bind(socket, bindAddr);

    ret_val = apr_socket_listen(socket, 1);

    ret_val = apr_socket_accept(&acceptedSocket, socket, pool);

    {
        char remoteAddrStr[100];
        memset(remoteAddrStr, '\0', 100);
        apr_sockaddr_ip_getbuf(remoteAddrStr, 99, acceptedSocket->remote_addr);
        printf("Remote address %s\n", remoteAddrStr);
    }
}


In both following cases after running this program, I'd simply telnet to the
machine on the chosen port (1756 in this case) from a different machine
(192.168.11.184).

When run on CentOS machine with IPv6 disabled
=============================================

ifconfig 
eth0      Link encap:Ethernet  HWaddr xx:xx:xx:xx:xx:xx  
          inet addr:192.168.8.215  Bcast:192.168.11.255  Mask:255.255.252.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:10648137 errors:0 dropped:0 overruns:0 frame:0
          TX packets:272642 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100 
          RX bytes:1111501223 (1.0 GiB)  TX bytes:230566540 (219.8 MiB)
          Memory:d0200000-d0220000 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:67332 errors:0 dropped:0 overruns:0 frame:0
          TX packets:67332 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:24496050 (23.3 MiB)  TX bytes:24496050 (23.3 MiB)

./getLocalAddr 
Remote address 192.168.11.184

telnet 192.168.8.215 1756
Trying 192.168.8.215...
Connected to 192.168.8.215.
Escape character is '^]'.
Connection closed by foreign host.

When run on RH9 machine with IPv6 disabled
==========================================

ifconfig 
eth0      Link encap:Ethernet  HWaddr xx:xx:xx:xx:xx:xx  
          inet addr:192.168.8.97  Bcast:192.168.11.255  Mask:255.255.252.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:6696363 errors:0 dropped:0 overruns:0 frame:0
          TX packets:205660 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:482996699 (460.6 Mb)  TX bytes:70162877 (66.9 Mb)
          Base address:0x2000 Memory:48180000-481a0000 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:214777 errors:0 dropped:0 overruns:0 frame:0
          TX packets:214777 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:47510460 (45.3 Mb)  TX bytes:47510460 (45.3 Mb)


./getLocalAddr 
Found IPv6 address ::. Breaking.
Remote address ::9b1b:0:28b3:fcb7

telnet 192.168.8.97 1756
Trying 192.168.8.97...
Connected to 192.168.8.97.
Escape character is '^]'.
Connection closed by foreign host.

Note the remote address returned on RH9 machine. I hope this clears what is
happening here.
The problem is because apr_socket_t.local_addr is IPv6 and so it believes
apr_socket_t.remote_addr will also be IPv6. So the while converting from
network to presentation format, we are trying to convert bytes which are
actually IPv4 address believing those bytes represent an IPv6 address. There is
no bug in the conversion to presentation format.

-- 
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: bugs-unsubscribe@apr.apache.org
For additional commands, e-mail: bugs-help@apr.apache.org


DO NOT REPLY [Bug 49678] getRemoteAddr() returns IPv6 address on RedHat 9 when IPv6 is disabled

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49678

Joe Orton <jo...@redhat.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

--- Comment #12 from Joe Orton <jo...@redhat.com> 2011-01-15 10:15:32 EST ---
Fixed in r1059351.

-- 
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: bugs-unsubscribe@apr.apache.org
For additional commands, e-mail: bugs-help@apr.apache.org


DO NOT REPLY [Bug 49678] getRemoteAddr() returns IPv6 address on RedHat 9 when IPv6 is disabled

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49678

--- Comment #1 from Lalit Mishra <la...@airtightnetworks.com> 2010-07-30 07:10:04 EDT ---
Created an attachment (id=25822)
 --> (https://issues.apache.org/bugzilla/attachment.cgi?id=25822)
Patch as described in description

-- 
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: bugs-unsubscribe@apr.apache.org
For additional commands, e-mail: bugs-help@apr.apache.org


DO NOT REPLY [Bug 49678] getRemoteAddr() returns IPv6 address on RedHat 9 when IPv6 is disabled

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49678

--- Comment #11 from Joe Orton <jo...@redhat.com> 2010-08-10 09:47:07 EDT ---
Thanks.  You should use:

        apr_socket_addr_get(&sa, APR_REMOTE, acceptedSocket);

        apr_sockaddr_ip_getbuf(remoteAddrStr, 99, sa);

rather than attempting to dereference the socket object, BTW.

-- 
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: bugs-unsubscribe@apr.apache.org
For additional commands, e-mail: bugs-help@apr.apache.org


DO NOT REPLY [Bug 49678] getRemoteAddr() returns IPv6 address on RedHat 9 when IPv6 is disabled

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49678

--- Comment #2 from Joe Orton <jo...@redhat.com> 2010-07-30 07:37:10 EDT ---
"messes up while translating to presentation format."

messes up how?  It sounds like you are trying to work around some bug in
handling v4-mapped IPv6 addresses.  What is the actual bug?

-- 
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: bugs-unsubscribe@apr.apache.org
For additional commands, e-mail: bugs-help@apr.apache.org


[Bug 49678] getRemoteAddr() returns IPv6 address on RedHat 9 when IPv6 is disabled

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49678

Jeff Trawick <tr...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |CLOSED

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@apr.apache.org
For additional commands, e-mail: bugs-help@apr.apache.org


DO NOT REPLY [Bug 49678] getRemoteAddr() returns IPv6 address on RedHat 9 when IPv6 is disabled

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49678

--- Comment #6 from Joe Orton <jo...@redhat.com> 2010-08-04 06:50:13 EDT ---
This is what you'd expect to see on a machine without AI_ADDRCONFIG support. 
Where is the bug in "presentation format" that you mentioned?  accept() will
fail if you try to bind to the AF_INET6 address, too, presumably.  What is the
bug?

-- 
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: bugs-unsubscribe@apr.apache.org
For additional commands, e-mail: bugs-help@apr.apache.org


DO NOT REPLY [Bug 49678] getRemoteAddr() returns IPv6 address on RedHat 9 when IPv6 is disabled

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49678

--- Comment #5 from Lalit Mishra <la...@airtightnetworks.com> 2010-08-02 10:55:45 EDT ---
(In reply to comment #4)

> What do you mean precisely by having "IPv6 disabled"?

It means that "ipv6" modules has not been loaded, though kernel was compiled
with IPv6 support enabled. No IPv6 addresses are assigned on any network
interfaces.

> Are you saying there is a kernel bug here which needs to be worked around?

Different results are obtained on same kernel with different glibc version.
RH9 uses 2.3.2 - gives wrong result
CentOS 5.2 uses 2.5-24 - gives correct result

> Maybe you could give a minimal example of code needed to reproduce this with
> APR, the output of running that code, and the output from running it under
> strace (or similar).

Consider following code :

#include "apr.h"
#include "apr_pools.h"
#include "apr_network_io.h"
#include "apr_strings.h"
#include "apr_mmap.h"
#include "stdio.h"

int main() {
        apr_pool_t *pool = NULL;
        apr_sockaddr_t *sa, *sl;
        apr_int32_t f = 0;

        apr_initialize();
        apr_pool_create(&pool, NULL);

        apr_sockaddr_info_get(&sa, NULL, AF_UNSPEC, 0, f, pool);

        sl = sa;

        while(sl) {
                char addrStr[100];

                memset(addrStr, '\0', 100);

                apr_sockaddr_ip_getbuf(addrStr, 99, sl);
                printf("%s\n", addrStr);

                sl = sl->next;
        }
}

Now let's consider output on two machines

CentOS Machine (with IPv6 disabled)
===================================

ifconfig 
eth0      Link encap:Ethernet  HWaddr xx:xx:xx:xx:xx:xx  
          inet addr:192.168.8.215  Bcast:192.168.11.255  Mask:255.255.252.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1146747 errors:0 dropped:0 overruns:0 frame:0
          TX packets:28212 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100 
          RX bytes:72940682 (69.5 MiB)  TX bytes:30817941 (29.3 MiB)
          Memory:d0200000-d0220000 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:4557 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4557 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1540826 (1.4 MiB)  TX bytes:1540826 (1.4 MiB)

./getLocalAddr 
0.0.0.0

RH9 Machine (with IPv6 disabled)
==============================

ifconfig 
eth0      Link encap:Ethernet  HWaddr xx:xx:xx:xx:xx:xx  
          inet addr:192.168.8.97  Bcast:192.168.11.255  Mask:255.255.252.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:27661 errors:0 dropped:0 overruns:0 frame:0
          TX packets:760 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1848721 (1.7 Mb)  TX bytes:154774 (151.1 Kb)
          Base address:0x2000 Memory:48180000-481a0000 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:4553 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4553 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1045939 (1021.4 Kb)  TX bytes:1045939 (1021.4 Kb)

./getLocalAddr 
::
0.0.0.0

Note that on RH9 "::" address (sl->family == AF_INET6) was returned. This makes
APR believe that IPv6 is enabled. On CentOS presence of AI_ADDRCONFIG prevents
"::" from appearing here.

-- 
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: bugs-unsubscribe@apr.apache.org
For additional commands, e-mail: bugs-help@apr.apache.org