* [PATCH] Fix libresolv when last IPv6 nameserver is removed
@ 2007-06-18 19:54 Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2007-06-18 19:54 UTC (permalink / raw)
To: Ulrich Drepper; +Cc: Glibc hackers
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2007-06-18 19:54 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-18 19:54 [PATCH] Fix libresolv when last IPv6 nameserver is removed Jakub Jelinek
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).