From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23538 invoked by alias); 18 Jun 2007 19:54:04 -0000 Received: (qmail 23521 invoked by uid 22791); 18 Jun 2007 19:54:03 -0000 X-Spam-Check-By: sourceware.org Received: from sunsite.ms.mff.cuni.cz (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 18 Jun 2007 19:54:01 +0000 Received: from sunsite.mff.cuni.cz (localhost.localdomain [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.8/8.13.8) with ESMTP id l5IJvqS9020138; Mon, 18 Jun 2007 21:57:52 +0200 Received: (from jakub@localhost) by sunsite.mff.cuni.cz (8.13.8/8.13.8/Submit) id l5IJvqcf020137; Mon, 18 Jun 2007 21:57:52 +0200 Date: Mon, 18 Jun 2007 19:54:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers Subject: [PATCH] Fix libresolv when last IPv6 nameserver is removed Message-ID: <20070618195751.GA3081@sunsite.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.2i Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2007-06/txt/msg00016.txt.bz2 Hi! If nscount6 used to be > 0 but changed to 0 in some res_init, socket_pf can be PF_INET6, yet the socket created is PF_INET. The patch below from Tomas calls convaddr4to6 only if nssocks[ns] is really PF_INET6 and renames socket_pf variable to match its current usage (i.e. don't try IPv6 if socket(PF_INET6, SOCK_DGRAM, 0) already failed once). Tested with the BZ#4647 testcase. 2007-06-18 Jakub Jelinek [BZ #4647] * resolv/res_send.c (send_dg): Rename socket_pf to ipv6_unavail, only convaddr4to6 if nssocks[ns] is a PF_INET6 socket. Patch by Tomas Janousek . --- libc/resolv/res_send.c.jj 2007-02-26 18:13:46.000000000 +0100 +++ libc/resolv/res_send.c 2007-06-18 21:42:41.000000000 +0200 @@ -813,17 +813,20 @@ send_dg(res_state statp, struct pollfd pfd[1]; int ptimeout; struct sockaddr_in6 from; - static int socket_pf = 0; + static bool ipv6_unavail = false; socklen_t fromlen; int resplen, seconds, n; if (EXT(statp).nssocks[ns] == -1) { /* only try IPv6 if IPv6 NS and if not failed before */ - if ((EXT(statp).nscount6 > 0) && (socket_pf != PF_INET)) { + if ((EXT(statp).nscount6 > 0) && !ipv6_unavail) { EXT(statp).nssocks[ns] = socket(PF_INET6, SOCK_DGRAM, 0); - socket_pf = EXT(statp).nssocks[ns] < 0 ? PF_INET - : PF_INET6; + if (EXT(statp).nssocks[ns] < 0) + ipv6_unavail = true; + /* If IPv6 socket and nsap is IPv4, make it IPv4-mapped */ + else if (nsap->sin6_family == AF_INET) + convaddr4to6(nsap); } if (EXT(statp).nssocks[ns] < 0) EXT(statp).nssocks[ns] = socket(PF_INET, SOCK_DGRAM, 0); @@ -832,9 +835,7 @@ send_dg(res_state statp, Perror(statp, stderr, "socket(dg)", errno); return (-1); } - /* If IPv6 socket and nsap is IPv4, make it IPv4-mapped */ - if ((socket_pf == PF_INET6) && (nsap->sin6_family == AF_INET)) - convaddr4to6(nsap); + /* * On a 4.3BSD+ machine (client and server, * actually), sending to a nameserver datagram Jakub