ipv6 loopbacks fix for GNU libc getaddrinfo()

On any OS with a properly implemented getaddrinfo() this change is a
no-op. Passing NULL for the hint is supposed to be the same as an
addrinfo structure with all fields set to 0. There is no need to set
ai_family to AF_UNSPEC because that value is already 0.

GNU libc doesn't follow standard behaviour. Quoting from
http://man7.org/linux/man-pages/man3/getaddrinfo.3.html :

  "Specifying hints as NULL is equivalent to setting ai_socktype and
  ai_protocol to 0; ai_family to AF_UNSPEC; and ai_flags to
  (AI_V4MAPPED | AI_ADDRCONFIG). (POSIX specifies different defaults for
  ai_flags; see NOTES.)"

The NOTES section says:

  "According to POSIX.1-2001, specifying hints as NULL should cause
  ai_flags to be assumed as 0. The GNU C library instead assumes a value
  of (AI_V4MAPPED | AI_ADDRCONFIG) for this case, since this value is
  considered an improvement on the specification."

The patch makes sure that krb5_parse_address works consistently on both
GNU libc and systems that follow POSIX.1-2001 to the letter. Some
incorrect Fedora 17 patches managed to break IPv6 connectivity and were
later backed out (see discussion at https://bugzilla.redhat.com/808147).
This patch resolves the incompatibility.

Signed-off-by: Ken Dreyer <ktdreyer@ktdreyer.com>
This commit is contained in:
Rok Papež, ARNES
2013-10-16 15:57:55 -06:00
committed by Ken Dreyer
parent ef8e4da010
commit 59b8f4ff84

View File

@@ -1161,6 +1161,7 @@ krb5_parse_address(krb5_context context,
{
int i, n;
struct addrinfo *ai, *a;
struct addrinfo hint;
int error;
int save_errno;
@@ -1180,7 +1181,10 @@ krb5_parse_address(krb5_context context,
}
}
error = getaddrinfo (string, NULL, NULL, &ai);
/* if not parsed as numeric address, do a name lookup */
memset(&hint, 0, sizeof(hint));
hint.ai_family = AF_UNSPEC;
error = getaddrinfo (string, NULL, &hint, &ai);
if (error) {
krb5_error_code ret2;
save_errno = errno;