summaryrefslogtreecommitdiff
path: root/network_io/unix
diff options
context:
space:
mode:
authorsf <sf@13f79535-47bb-0310-9956-ffa450edef68>2012-05-28 13:01:04 +0000
committersf <sf@13f79535-47bb-0310-9956-ffa450edef68>2012-05-28 13:01:04 +0000
commite7e16ed7aa65ad36712b5f470e0f2af3245af98d (patch)
treeac7056a9de8f653a169677e5f9a299ee2113e67c /network_io/unix
parent284b11598b50b29c03952262d064fa360b304538 (diff)
downloadlibapr-e7e16ed7aa65ad36712b5f470e0f2af3245af98d.tar.gz
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/trunk@1343233 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'network_io/unix')
-rw-r--r--network_io/unix/sockaddr.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/network_io/unix/sockaddr.c b/network_io/unix/sockaddr.c
index efa7ee09e..fe42998e7 100644
--- a/network_io/unix/sockaddr.c
+++ b/network_io/unix/sockaddr.c
@@ -364,8 +364,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);
}