This is the mail archive of the libc-hacker@sourceware.org mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix libresolv when last IPv6 nameserver is removed


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]