Hello Remi.

I do understand that I'm a bit late with this one, but this patch actually 
FORCES IPv6 for port-only syntax.
I've got both IPv6 and IPv4 configured and getaddrinfo() returns only 1 address 
- the IPv6 one.
This happens because "::" seems to be a shorthand for "::1".

So when no hostname is specified FPM always tries to listen on IPv6 only 
instead of doing what the patch was intended to do.
The only way to force IPv4 is to specify IP address or a hostname ("localhost" 
is enough).

This either needs to be fixed, or reflected in the docs.

Here's to demonstrate it:

288             if ((status = getaddrinfo(addr, port_str, &hints, &servinfo)) 
!= 0) {
(gdb)
294             for (p = servinfo; p != NULL; p = p->ai_next) {
(gdb) p *servinfo
$4 = {ai_flags = 0, ai_family = 10, ai_socktype = 1, ai_protocol = 6, ai_addrlen = 
28, ai_addr = 0xbdb3c0, ai_canonname = 0x0, ai_next = 0x0} <---- NO ai_next, so 
it's the only option.
(gdb) p addr
$5 = 0x8ace8c "::"



On 11/24/2014 08:38 AM, Remi Collet wrote:
Commit:    95a609c5d14a2c5295886065a24db8344844ca8b
Author:    Remi Collet <r...@php.net>         Mon, 24 Nov 2014 09:38:36 +0100
Parents:   d8fbcca725264cbca3ea88375bfb7879f81175d7
Branches:  master

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=95a609c5d14a2c5295886065a24db8344844ca8b

Log:
FPM: change "listen = port" behavior from IPv4 catch-all to IPv6 catch-all (+ 
IPv4-mapped)

Changed paths:
   M  UPGRADING
   M  sapi/fpm/fpm/fpm_sockets.c
   M  sapi/fpm/php-fpm.conf.in


Diff:
diff --git a/UPGRADING b/UPGRADING
index fe28213..9d5d8e7 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -63,6 +63,7 @@ PHP X.Y UPGRADE NOTES

  - FPM
    . Fixed bug #65933 (Cannot specify config lines longer than 1024 bytes).
+  . Listen = port now listen on all addresses (IPv6 and IPv4-mapped).

  ========================================
  4. Deprecated Functionality
diff --git a/sapi/fpm/fpm/fpm_sockets.c b/sapi/fpm/fpm/fpm_sockets.c
index 0286f0e..e4e4948 100644
--- a/sapi/fpm/fpm/fpm_sockets.c
+++ b/sapi/fpm/fpm/fpm_sockets.c
@@ -268,6 +268,8 @@ static int fpm_socket_af_inet_listening_socket(struct 
fpm_worker_pool_s *wp) /*
        } else if (strlen(dup_address) == strspn(dup_address, "0123456789")) { 
/* this is port */
                port = atoi(dup_address);
                port_str = dup_address;
+               /* IPv6 catch-all + IPv4-mapped */
+               addr = "::";
        }

        if (port == 0) {
@@ -275,18 +277,6 @@ static int fpm_socket_af_inet_listening_socket(struct 
fpm_worker_pool_s *wp) /*
                return -1;
        }

-       if (!addr) {
-               /* no address: default documented behavior, all IPv4 addresses 
*/
-               struct sockaddr_in sa_in;
-
-               memset(&sa_in, 0, sizeof(sa_in));
-               sa_in.sin_family = AF_INET;
-               sa_in.sin_port = htons(port);
-               sa_in.sin_addr.s_addr = htonl(INADDR_ANY);
-               free(dup_address);
-               return fpm_sockets_get_listening_socket(wp, (struct sockaddr *) 
&sa_in, sizeof(struct sockaddr_in));
-       }
-
        /* strip brackets from address for getaddrinfo */
        addr_len = strlen(addr);
        if (addr[0] == '[' && addr[addr_len - 1] == ']') {
@@ -307,10 +297,10 @@ static int fpm_socket_af_inet_listening_socket(struct 
fpm_worker_pool_s *wp) /*
                inet_ntop(p->ai_family, fpm_get_in_addr(p->ai_addr), tmpbuf, 
INET6_ADDRSTRLEN);
                if (sock < 0) {
                        if ((sock = fpm_sockets_get_listening_socket(wp, 
p->ai_addr, p->ai_addrlen)) != -1) {
-                               zlog(ZLOG_DEBUG, "Found address for %s, socket 
opened on %s", dup_address, tmpbuf);
+                               zlog(ZLOG_DEBUG, "Found address for %s, socket 
opened on %s", addr, tmpbuf);
                        }
                } else {
-                       zlog(ZLOG_WARNING, "Found multiple addresses for %s, %s 
ignored", dup_address, tmpbuf);
+                       zlog(ZLOG_WARNING, "Found multiple addresses for %s, %s 
ignored", addr, tmpbuf);
                }
        }

diff --git a/sapi/fpm/php-fpm.conf.in b/sapi/fpm/php-fpm.conf.in
index b2d8a22..850a369 100644
--- a/sapi/fpm/php-fpm.conf.in
+++ b/sapi/fpm/php-fpm.conf.in
@@ -155,9 +155,7 @@ group = @php_fpm_group@
  ;                            a specific port;
  ;   '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 
address on
  ;                            a specific port;
-;   'port'                 - to listen on a TCP socket to all IPv4 addresses 
on a
-;                            specific port;
-;   '[::]:port'            - to listen on a TCP socket to all addresses
+;   'port'                 - to listen on a TCP socket to all addresses
  ;                            (IPv6 and IPv4-mapped) on a specific port;
  ;   '/path/to/unix/socket' - to listen on a unix socket.
  ; Note: This value is mandatory.




--
Wbr,
Antony Dovgal
---
http://pinba.org - realtime profiling for PHP

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to