summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsf <sf@13f79535-47bb-0310-9956-ffa450edef68>2012-05-28 13:10:28 +0000
committersf <sf@13f79535-47bb-0310-9956-ffa450edef68>2012-05-28 13:10:28 +0000
commit1b8a85c73485ba0746d2693f7ecf371c19a8f1c2 (patch)
treeeea6678a46e74fb6ee5b8c4eb2b5ec7a3252375b
parentf1accd9c0a1e14afd1372450151636499439e119 (diff)
downloadlibapr-1b8a85c73485ba0746d2693f7ecf371c19a8f1c2.tar.gz
Merge r1343233 and add CHANGES entry:
Improve handling of AI_ADDRCONFIG with getaddrinfo() Using AI_ADDRCONFIG involves some unfortunate guesswork because it does not consider loopback addresses when trying to determine if IPv4 or IPv6 is configured (RFC 3493). This is a problem if one actually wants to listen on or connect to the loopback address of a protocol family that is not otherwise configured on the system. Also, some implementations (glibc, cough) behave strangely if no other addresses besides 127.0.0.1 and ::1 are configured. A real fix would enhance apr_sockaddr_info_get's interface to allow the caller to specify if he wants to use the address for listen() or connect(), and if he wants to make the result dependant on the presence of non-loopback addresses. Then apr_sockaddr_info_get could pass the right combination of AI_ADDRCONFIG and AI_PASSIVE to getaddrinfo(). As a workaround, retry getaddrinfo() without AI_ADDRCONFIG in case of EAI_ADDRFAMILY. This solves the most common problems but not all corner cases. PR: 52709 Submitted by: Nirgal Vourgère <jmv_deb nirgal com>, Stefan Fritsch Many thanks also to Aurelien Jarno for helping to debug this. git-svn-id: http://svn.apache.org/repos/asf/apr/apr/branches/1.4.x@1343239 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--CHANGES5
-rw-r--r--network_io/unix/sockaddr.c19
2 files changed, 22 insertions, 2 deletions
diff --git a/CHANGES b/CHANGES
index 99bcab4bb..83ccb620f 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,11 @@
-*- coding: utf-8 -*-
Changes for APR 1.4.7
+ *) Fix some problems in apr_sockaddr_info_get() when trying to resolve
+ the loopback addresses of a protocol family that is not otherwise
+ configured on the system. PR 52709. [Nirgal Vourgère
+ <jmv_deb nirgal com>, Stefan Fritsch]
+
*) Fix file not being unlocked if truncate call on a file fails.
[Mladen Turk]
diff --git a/network_io/unix/sockaddr.c b/network_io/unix/sockaddr.c
index 89053f007..e9cfbd7ed 100644
--- a/network_io/unix/sockaddr.c
+++ b/network_io/unix/sockaddr.c
@@ -356,8 +356,23 @@ static apr_status_t call_resolver(apr_sockaddr_t **sa,
}
error = getaddrinfo(hostname, servname, &hints, &ai_list);
#ifdef HAVE_GAI_ADDRCONFIG
- if (error == EAI_BADFLAGS && family == APR_UNSPEC) {
- /* Retry without AI_ADDRCONFIG if it was rejected. */
+ /*
+ * Using AI_ADDRCONFIG involves some unfortunate guesswork because it
+ * does not consider loopback addresses when trying to determine if
+ * IPv4 or IPv6 is configured on a system (see RFC 3493).
+ * This is a problem if one actually wants to listen on or connect to
+ * the loopback address of a protocol family that is not otherwise
+ * configured on the system. See PR 52709.
+ * To work around some of the problems, retry without AI_ADDRCONFIG
+ * in case of EAI_ADDRFAMILY.
+ * XXX: apr_sockaddr_info_get() should really accept a flag to determine
+ * XXX: if AI_ADDRCONFIG's guesswork is wanted and if the address is
+ * XXX: to be used for listen() or connect().
+ *
+ * In case of EAI_BADFLAGS, AI_ADDRCONFIG is not supported.
+ */
+ if ((family == APR_UNSPEC) && (error == EAI_BADFLAGS
+ || error == EAI_ADDRFAMILY)) {
hints.ai_flags &= ~AI_ADDRCONFIG;
error = getaddrinfo(hostname, servname, &hints, &ai_list);
}