Bug 52709 - Apache can't bind to 127.0.0.1 if eth0 has only IPv6
Summary: Apache can't bind to 127.0.0.1 if eth0 has only IPv6
Status: CLOSED FIXED
Alias: None
Product: APR
Classification: Unclassified
Component: APR (show other bugs)
Version: 1.4.5
Hardware: PC Linux
: P2 normal with 3 votes (vote)
Target Milestone: ---
Assignee: Apache Portable Runtime bugs mailinglist
URL:
Keywords: PatchAvailable
Depends on:
Blocks:
 
Reported: 2012-02-19 15:38 UTC by Nirgal Vourgère
Modified: 2014-01-21 13:00 UTC (History)
0 users



Attachments
Patch for loopback support in call_resolver() IPv6/IPv4 mismatch (714 bytes, patch)
2012-02-21 18:05 UTC, Nirgal Vourgère
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nirgal Vourgère 2012-02-19 15:38:33 UTC
From http://bugs.debian.org/500558

Apache can't bind to 127.0.0.1 if eth0 as only IPv6

I traced back that problem to a call in libapr1, in call_resolver()
getaddrinfo("127.0.0.1", NULL, &hints, ...) that returns -9
because hints contains AI_ADDRCONFIG

Without that hint, it works.

Extract from call_resolver:
    if (family == APR_UNSPEC) {
        /* By default, only look up addresses using address types for
         * which a local interface is configured, i.e. no IPv6 if no
         * IPv6 interfaces configured. */
        hints.ai_flags = AI_ADDRCONFIG;
    }

Aurelien Jarno pointed out that whatever what the documentation says, RFC3493 explicitly exclude the loopback addresses:

   If the AI_ADDRCONFIG flag is specified, IPv4 addresses shall be
   returned only if an IPv4 address is configured on the local system,
   and IPv6 addresses shall be returned only if an IPv6 address is
   configured on the local system.  The loopback address is not
   considered for this case as valid as a configured address.

This results in:
[Mon Sep 29 10:33:20 2008] [crit] (EAI 9)Address family for hostname not supported: alloc_listener: failed to set up sockaddr for 127.0.0.1
Syntax error on line 1 of /etc/apache2/ports.conf:
Listen setup failed

I think cannot use AI_ADDRCONFIG if we are to allow localhost binding.
Comment 1 Nirgal Vourgère 2012-02-21 18:05:33 UTC
Created attachment 28360 [details]
Patch for loopback support in call_resolver() IPv6/IPv4 mismatch

It is a pity not to use AI_ADDRCONFIG hint for production servers not using loopback.
So I used the existing retry mechanism designed for EAI_BADFLAGS.

Tested on version 1.4.2, but should apply to all recent ones.
Comment 2 Nirgal Vourgère 2012-02-22 11:15:11 UTC
This bug also affects httpd function ap_get_local_host() as described in http://bugs.debian.org/629899
Httpd will then fail to get the fully qualified domain name.

This occurs when apache starts before dhclient finished its job.
Comment 3 Stefan Fritsch 2012-05-28 13:13:01 UTC
trunk: r1343233
1.5: r1343236
1.4: r1343239 (will be in 1.4.7)