[Patch] [BZ 14505] Avoid unwanted A lookups on IPV6 only host
Jeff Law
law@redhat.com
Wed Aug 22 16:33:00 GMT 2012
On 08/21/2012 04:06 PM, Roland McGrath wrote:
> Seems simpler to test "&& req->ai_family == PF_UNSPEC".
> Also, you shouldn't call __nss_lookup_function at all when
> you're not going to use its result. So make it:
>
> nss_gethostbyname4_r fct4 = NULL;
> /* comment */
> if (req->ai_family == PF_UNSPEC)
> fct4 = __nss_lookup_function (nip, "gethostbyname4_r");
> if (fct4 != NULL)
Thanks. I went back and forth between testing PF_UNSPEC and testing for
PF_INET/PF_INET6 and selected the latter because I thought it was
marginally clearer. It's certainly not a big deal to me. Testing
PF_UNSPEC is slight more efficient from a code generation standpoint.
Totally agreed on avoiding the nss_lookup_function call.
Updated patch & ChangeLog entry attached.
-------------- next part --------------
2012-08-22 Jeff Law <law@redhat.com>
[BZ #14505]
* sysdeps/posix/getaddrinfo.c (gaih_inet): Only use gethostbyname4_r
if the family is PF_UNSPEC.
diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index 81e928a..05883bd 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -832,8 +832,13 @@ gaih_inet (const char *name, const struct gaih_service *service,
while (!no_more)
{
no_data = 0;
- nss_gethostbyname4_r fct4
- = __nss_lookup_function (nip, "gethostbyname4_r");
+ nss_gethostbyname4_r fct4 = NULL;
+
+ /* gethostbyname4_r sends out parallel A and AAAA queries and
+ is thus only suitable for PF_UNSPEC. */
+ if (req->ai_family == PF_UNSPEC)
+ fct4 = __nss_lookup_function (nip, "gethostbyname4_r");
+
if (fct4 != NULL)
{
int herrno;
More information about the Libc-alpha
mailing list