Bug 711827 - getaddrinfo does not honor hint.ai_family = AF_INET6
Summary: getaddrinfo does not honor hint.ai_family = AF_INET6
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: glibc
Version: 15
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Andreas Schwab
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2011-06-08 16:14 UTC by Jeff Bastian
Modified: 2016-11-24 15:50 UTC (History)
5 users (show)

Fixed In Version: glibc-2.14-3
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2011-06-24 17:54:40 UTC
Type: ---


Attachments (Terms of Use)

Description Jeff Bastian 2011-06-08 16:14:42 UTC
Description of problem:
I cannot ping6 a system with both an IPv4 and IPv6 address in DNS:

$ ping6 -v -n -c 1 www.google.com
PING www.google.com(::) 56 data bytes
ping: sendmsg: Address family not supported by protocol

$ ping6 -v -n -c 1 www.kame.net
PING www.kame.net(::) 56 data bytes
ping: sendmsg: Address family not supported by protocol


However, a system with IPv6 only works fine:

$ ping6 -v -n -c 1 ipv6.google.com
PING ipv6.google.com(2001:4860:b009::68) 56 data bytes
64 bytes from 2001:4860:b009::68: icmp_seq=1 ttl=54 time=68.0 ms


Version-Release number of selected component (if applicable):
iputils-20101006-7.fc15.x86_64

How reproducible:
every time

Steps to Reproduce:
1. ping6 -v -n -c 1 www.google.com
  
Actual results:
ping: sendmsg: Address family not supported by protocol

Expected results:
successful ping

Additional info:

Comment 1 Jeff Bastian 2011-06-08 16:24:48 UTC
Hmmm, I found that if I moved my /etc/gai.conf out of the way, ping6 started working.


$ sudo mv /etc/gai.conf /etc/gai.conf.OLD

$ ping6 -v -n -c 1 www.google.com
PING www.google.com(2001:4860:b009::69) 56 data bytes
64 bytes from 2001:4860:b009::69: icmp_seq=1 ttl=54 time=67.3 ms


My gai.conf only had defaults in it, though:

$ cat /etc/gai.conf
precedence  ::1/128       50
precedence  ::/0          40
precedence  2002::/16     30
precedence ::/96          20
precedence ::ffff:0:0/96  100

Comment 2 Björn Persson 2011-06-08 16:48:25 UTC
I have this problem on a 32-bit F15.

$ rpm -q --file `which ping6`
iputils-20101006-7.fc15.i686

$ host orange.kame.net
orange.kame.net has address 203.178.141.194
orange.kame.net has IPv6 address 2001:200:dff:fff1:216:3eff:feb1:44d7

$ ping6 orange.kame.net
PING orange.kame.net(::57.0.0.0) 56 data bytes
ping: sendmsg: Address family not supported by protocol

$ host ipv6.l.google.com
ipv6.l.google.com has IPv6 address 2a00:1450:4001:c01::68

$ ping6 ipv6.l.google.com
PING ipv6.l.google.com(fra07s07-in-x68.1e100.net) 56 data bytes
64 bytes from fra07s07-in-x68.1e100.net: icmp_seq=1 ttl=58 time=61.1 ms


The symptoms when there are both IPv4 and IPv6 addresses are the same as when there is only an IPv4 address:

$ host freshmeat.net
freshmeat.net has address 216.34.181.101

$ ping6 freshmeat.net
PING freshmeat.net(::57.0.0.0) 56 data bytes
ping: sendmsg: Address family not supported by protocol


strace shows that ping6 tries to use the IPv4 address even though there is an IPv6 address:

# strace -f -e sendto ping6 orange.kame.net
sendto(4, "\24\0\0\0\26\0\1\3\324\245\357M\0\0\0\0\0\0\0\0", 20, 0, {sa_family=AF_NETLINK, pid=0, groups=00000000}, 12) = 20
PING orange.kame.net(::57.0.0.0) 56 data bytes
sendto(3, "\200\0\0\0\7\333\0\1\324\245\357M\325\212\2\0\10\t\n\v\f\r\16\17\20\21\22\23\24\25\26\27"..., 64, 0, {sa_family=AF_INET, sin_port=htons(58), sin_addr=inet_addr("203.178.141.194")}, 28) = -1 EAFNOSUPPORT (Address family not supported by protocol)
ping: sendmsg: Address family not supported by protocol

Comment 3 Jiri Skala 2011-06-10 05:58:48 UTC
Works for me fine on F15 as well as F14 (with & without gai.conf). If your issue is affected by gai.conf it will relate to glibc. What's NVR of your's installed glibc?

Comment 4 Jeff Bastian 2011-06-10 15:23:56 UTC
I'm running with glibc-2.14-2.

$ rpm -qa glibc\* | sort
glibc-2.14-2.i686
glibc-2.14-2.x86_64
glibc-common-2.14-2.x86_64
glibc-devel-2.14-2.x86_64
glibc-headers-2.14-2.x86_64


Just to double-check, I tried again.  Without gai.conf, it works:

$ ls /etc/gai.conf
ls: cannot access /etc/gai.conf: No such file or directory

$ ping6 -n -c 1 www.kame.net
PING www.kame.net(2001:200:dff:fff1:216:3eff:feb1:44d7) 56 data bytes
64 bytes from 2001:200:dff:fff1:216:3eff:feb1:44d7: icmp_seq=1 ttl=52 time=182 ms

--- www.kame.net ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 182.051/182.051/182.051/0.000 ms


But with gai.conf, it fails:

$ sudo mv /etc/gai.conf.bak /etc/gai.conf

$ cat /etc/gai.conf
label  ::1/128       0
label  ::/0          1
label  2002::/16     2
label ::/96          3
label ::ffff:0:0/96  4
precedence  ::1/128       50
precedence  ::/0          40
precedence  2002::/16     30
precedence ::/96          20
precedence ::ffff:0:0/96  100

$ ping6 -n -c 1 www.kame.net
PING www.kame.net(::) 56 data bytes
ping: sendmsg: Address family not supported by protocol

--- www.kame.net ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms

Comment 5 Jeff Bastian 2011-06-10 16:53:48 UTC
getaddrinfo() doesn't seem to be honoring the hints which tell it to retrieve IPv6 addresses only.

Below is a simple program that calls getaddrinfo() on www.kame.net with hints.ai_family restricted to AF_INET6 only, but it prints out both IPv4 and IPv6 addresses.

$ ./getaddrinfo-example 
203.178.141.194
203.178.141.194
203.178.141.194
2001:200:dff:fff1:216:3eff:feb1:44d7
2001:200:dff:fff1:216:3eff:feb1:44d7
2001:200:dff:fff1:216:3eff:feb1:44d7



$ cat getaddrinfo-example.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>

int main(void)
{
    struct addrinfo *result;
    struct addrinfo *res;
    struct addrinfo hint;
    int error;

    memset(&hint, 0, sizeof(struct addrinfo));
    hint.ai_family = AF_INET6;
    hint.ai_socktype = 0;
    hint.ai_protocol = 0;
    hint.ai_flags = 0;

    /* resolve the domain name into a list of addresses */
    error = getaddrinfo("www.kame.net", NULL, &hint, &result);
    if (error != 0)
    {
        fprintf(stderr, "error in getaddrinfo: %s\n", gai_strerror(error));
        return EXIT_FAILURE;
    }

    /* loop over all returned results and print the addresses */
    for (res = result; res != NULL; res = res->ai_next)
    {
        void *addr;
        char address[64] = "";
        if (res->ai_family == AF_INET) {
           addr = &((struct sockaddr_in *)(res->ai_addr))->sin_addr;
        } else if (res->ai_family == AF_INET6) {
           addr = &((struct sockaddr_in6 *)(res->ai_addr))->sin6_addr;
        }
        inet_ntop(res->ai_addr->sa_family, addr, address, 64);
        printf("%s\n", address);
    }

    freeaddrinfo(result);
    return EXIT_SUCCESS;
}

Comment 6 Jeff Bastian 2011-06-10 16:59:18 UTC
The above test program correctly returns the IPv6 address only on a RHEL 6.1 system with glibc-2.12-1.25.el6.x86_64

Changing component to glibc.

Comment 7 Jeff Bastian 2011-06-10 19:42:18 UTC
Downgrading to 2.13.90-9 fixes it (it shows only the IPv6 addresses); upgrading back to 2.14-2 breaks it again (it shows both IPv4 and IPv6 addresses).

$ sudo yum downgrade glibc-2.13.90-9 \
                     glibc-common-2.13.90-9 \
                     glibc-devel-2.13.90-9 \
                     glibc-headers-2.13.90-9 \
                     nscd-2.13.90-9
...

$ rpm -q glibc
glibc-2.13.90-9.x86_64
glibc-2.13.90-9.i686

$ ./getaddrinfo-example-hints
2001:200:dff:fff1:216:3eff:feb1:44d7
2001:200:dff:fff1:216:3eff:feb1:44d7
2001:200:dff:fff1:216:3eff:feb1:44d7

$ sudo yum -y update glibc
...

$ rpm -q glibc
glibc-2.14-2.x86_64
glibc-2.14-2.i686

$ ./getaddrinfo-example-hints                         
203.178.141.194
203.178.141.194
203.178.141.194
2001:200:dff:fff1:216:3eff:feb1:44d7
2001:200:dff:fff1:216:3eff:feb1:44d7
2001:200:dff:fff1:216:3eff:feb1:44d7

Comment 8 Fedora Update System 2011-06-22 15:45:02 UTC
glibc-2.14-3 has been submitted as an update for Fedora 15.
https://admin.fedoraproject.org/updates/glibc-2.14-3

Comment 9 Fedora Update System 2011-06-24 03:38:37 UTC
Package glibc-2.14-3:
* should fix your issue,
* was pushed to the Fedora 15 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing glibc-2.14-3'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/glibc-2.14-3
then log in and leave karma (feedback).

Comment 10 Fedora Update System 2011-06-24 17:54:14 UTC
glibc-2.14-3 has been pushed to the Fedora 15 stable repository.  If problems still persist, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.