| Summary: | getaddrinfo does not honor hint.ai_family = AF_INET6 | ||
|---|---|---|---|
| Product: | [Fedora] Fedora | Reporter: | Jeff Bastian <jbastian> |
| Component: | glibc | Assignee: | Andreas Schwab <schwab> |
| Status: | CLOSED ERRATA | QA Contact: | Fedora Extras Quality Assurance <extras-qa> |
| Severity: | medium | Docs Contact: | |
| Priority: | medium | ||
| Version: | 15 | CC: | fweimer, jakub, jskala, raina, schwab |
| Target Milestone: | --- | ||
| Target Release: | --- | ||
| Hardware: | All | ||
| OS: | Linux | ||
| Whiteboard: | |||
| Fixed In Version: | glibc-2.14-3 | Doc Type: | Bug Fix |
| Doc Text: | Story Points: | --- | |
| Clone Of: | Environment: | ||
| Last Closed: | 2011-06-24 17:54:40 UTC | Type: | --- |
| Regression: | --- | Mount Type: | --- |
| Documentation: | --- | CRM: | |
| Verified Versions: | Category: | --- | |
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |
| Cloudforms Team: | --- | Target Upstream Version: | |
|
Description
Jeff Bastian
2011-06-08 16:14:42 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 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
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? 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 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;
}
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. 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
glibc-2.14-3 has been submitted as an update for Fedora 15. https://admin.fedoraproject.org/updates/glibc-2.14-3 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). 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. |