From patchwork Fri Jun 13 15:32:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Jarno X-Patchwork-Id: 1493 Received: (qmail 2700 invoked by alias); 13 Jun 2014 15:32:22 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 2509 invoked by uid 89); 13 Jun 2014 15:32:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: hall.aurel32.net From: Aurelien Jarno To: libc-alpha@sourceware.org Cc: Aurelien Jarno Subject: [PATCH 3/4] resolv: fix issues when using IPv6 name servers only Date: Fri, 13 Jun 2014 17:32:12 +0200 Message-Id: <1402673533-13243-4-git-send-email-aurelien@aurel32.net> In-Reply-To: <1402673533-13243-1-git-send-email-aurelien@aurel32.net> References: <1402673533-13243-1-git-send-email-aurelien@aurel32.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 * 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;