public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Ulrich Drepper <drepper@redhat.com>
Cc: Glibc hackers <libc-hacker@sources.redhat.com>
Subject: [PATCH] Fix libresolv when last IPv6 nameserver is removed
Date: Mon, 18 Jun 2007 19:54:00 -0000	[thread overview]
Message-ID: <20070618195751.GA3081@sunsite.mff.cuni.cz> (raw)

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  <jakub@redhat.com>

	[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 <tjanouse@redhat.com>.

--- 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

                 reply	other threads:[~2007-06-18 19:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070618195751.GA3081@sunsite.mff.cuni.cz \
    --to=jakub@redhat.com \
    --cc=drepper@redhat.com \
    --cc=libc-hacker@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).