This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH 3/4] resolv: fix issues when using IPv6 name servers only
- From: Aurelien Jarno <aurelien at aurel32 dot net>
- To: libc-alpha at sourceware dot org
- Cc: Aurelien Jarno <aurelien at aurel32 dot net>
- Date: Fri, 13 Jun 2014 17:32:12 +0200
- Subject: [PATCH 3/4] resolv: fix issues when using IPv6 name servers only
- Authentication-results: sourceware.org; auth=none
- References: <1402673533-13243-1-git-send-email-aurelien at aurel32 dot net>
statp->nscount contains the number of servers in the statp->nsaddr_list
array, which only contains IPv4 name servers.
When resolv.conf only contains IPv6 name servers, statp->nscount equals
to 0, which causes the existing code to add a 127.0.0.1 entry. Change
that by checking nservall, contains the number of IPv4 + IPv6 servers
instead.
The same way __libc_res_nsend exits almost immediately when
statp->nscount considering that no name servers are available, while
IPv6 name servers are actually available. Change that by checking
(statp->nscount + EXT(statp).nscount6) instead.
Finally in send_dg, the seconds variable is wrongly computed in case of
IPv6 only name servers. Use (statp->nscount + EXT(statp).nscount6)
instead of statp->nscount.
2014-06-13 Aurelien Jarno <aurelien@aurel32.net>
* resolv/res_init.c (__res_vinit): Check for both IPv4 and IPv6
name servers before adding a localhost name server entry.
* resolv/res_send.c (__libc_res_nsend): Check for both IPv4 and
IPv6 name servers before ignoring the request.
(send_dg): Check for both IPv4 and IPv6 name servers to compute
time for the total operation.
diff --git a/resolv/res_init.c b/resolv/res_init.c
index 37004ab..95564af 100644
--- a/resolv/res_init.c
+++ b/resolv/res_init.c
@@ -427,7 +427,7 @@ __res_vinit(res_state statp, int preinit) {
#endif
(void) fclose(fp);
}
- if (__builtin_expect(statp->nscount == 0, 0)) {
+ if (__builtin_expect(nservall == 0, 0)) {
statp->nsaddr.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1);
statp->nsaddr.sin_family = AF_INET;
statp->nsaddr.sin_port = htons(NAMESERVER_PORT);
diff --git a/resolv/res_send.c b/resolv/res_send.c
index af42b8a..82242bd 100644
--- a/resolv/res_send.c
+++ b/resolv/res_send.c
@@ -347,7 +347,7 @@ __libc_res_nsend(res_state statp, const u_char *buf, int buflen,
{
int gotsomewhere, terrno, try, v_circuit, resplen, ns, n;
- if (statp->nscount == 0) {
+ if ((statp->nscount + EXT(statp).nscount6) == 0) {
__set_errno (ESRCH);
return (-1);
}
@@ -1013,7 +1013,7 @@ send_dg(res_state statp,
*/
int seconds = (statp->retrans << ns);
if (ns > 0)
- seconds /= statp->nscount;
+ seconds /= (statp->nscount + EXT(statp).nscount6);
if (seconds <= 0)
seconds = 1;
bool single_request_reopen = (statp->options & RES_SNGLKUPREOP) != 0;
--
2.0.0