Listening with IPV6

420 views
Skip to first unread message

Dirk Koopman

unread,
Jul 25, 2013, 1:59:59 PM7/25/13
to mojol...@googlegroups.com
With Ubuntu perl 5.14.2, latest git code and latest IO::Socket:IP it appears that one cannot start a listener on an IPV6 address such '::1'.  Neither will it 'make test' successfully:

djk@dirk6:~/mojo$ TEST_IPV6=1 make test
PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t t/*/*.t
t/mojo/app.t ............................... ok   
t/mojo/asset.t ............................. ok    
t/mojo/base.t .............................. ok    
t/mojo/bytestream.t ........................ ok   
t/mojo/cache.t ............................. ok   
t/mojo/cgi.t ............................... ok   
t/mojo/collection.t ........................ ok   
t/mojo/content.t ........................... ok   
t/mojo/cookie.t ............................ ok    
t/mojo/cookiejar.t ......................... ok    
t/mojo/date.t .............................. ok   
t/mojo/delay.t ............................. ok   
t/mojo/dom.t ............................... ok    
t/mojo/eventemitter.t ...................... ok   
t/mojo/headers.t ........................... ok    
t/mojo/home.t .............................. ok   
t/mojo/hypnotoad.t ......................... skipped: set TEST_HYPNOTOAD to enable this test (developer only!)
t/mojo/ioloop.t ............................ ok   
t/mojo/ioloop_ipv6.t ....................... Can't create listen socket: Address family for hostname not supported at /home/djk/mojo/blib/lib/Mojo/IOLoop.pm line 122.
t/mojo/ioloop_ipv6.t ....................... Dubious, test returned 22 (wstat 5632, 0x1600)

In all cases one gets the error shown.

Looking at the code, I am wondering why you don't just use IO::Socket::INET6 instead of IO::Socket:IP. I know that the newer module is supposed to be a drop in replacement for
IO::Socket::INET, but then so is IO::Socket::INET6, at least for the use that you are putting to it.



Sebastian Riedel

unread,
Jul 25, 2013, 2:08:44 PM7/25/13
to mojol...@googlegroups.com
> Looking at the code, I am wondering why you don't just use IO::Socket::INET6 instead of IO::Socket:IP. I know that the newer module is supposed to be a drop in replacement for
> IO::Socket::INET, but then so is IO::Socket::INET6, at least for the use that you are putting to it.

Nope, IO::Socket::IP is not just a drop in replacement, it supports multi-homed non-blocking connect for example, something IO::Socket::INET6 can't do because of its broken design.

--
Sebastian Riedel
http://twitter.com/kraih
http://mojolicio.us

sri

unread,
Jul 25, 2013, 2:14:10 PM7/25/13
to mojol...@googlegroups.com, kra...@googlemail.com
Nope, IO::Socket::IP is not just a drop in replacement...

Guess it's also worth mentioning that IO::Socket::IP is on its way to becoming a core module, so as far as i'm concerned IO::Socket::INET6 is dead.

--
sebastian 

Dirk Koopman

unread,
Jul 26, 2013, 5:17:27 AM7/26/13
to mojol...@googlegroups.com, kra...@googlemail.com


On Thursday, 25 July 2013 19:08:44 UTC+1, Sebastian Riedel wrote:
> Looking at the code, I am wondering why you don't just use IO::Socket::INET6 instead of IO::Socket:IP. I know that the newer module is supposed to be a drop in replacement for
> IO::Socket::INET, but then so is IO::Socket::INET6, at least for the use that you are putting to it.

Nope, IO::Socket::IP is not just a drop in replacement, it supports multi-homed non-blocking connect for example, something IO::Socket::INET6 can't do because of its broken design.


Okaayyy.

So any suggestions as to why I can't listen on an ipv6 addess?

Dirk

Stefan Adams

unread,
Dec 20, 2013, 6:53:25 PM12/20/13
to mojolicious

On Fri, Jul 26, 2013 at 4:17 AM, Dirk Koopman <gb7...@googlemail.com> wrote:
So any suggestions as to why I can't listen on an ipv6 addess?

Confirmation that it works.

$ /sbin/ifconfig eth0 | grep inet6.*Scope:Global
          inet6 addr: 2001:470:1f11:d34::4/64 Scope:Global

$ mojo version
CORE
  Perl        (v5.18.0, linux)
  Mojolicious (4.63, Top Hat)

OPTIONAL
  EV 4.0+               (4.15)
  IO::Socket::IP 0.16+  (0.22)
  IO::Socket::SSL 1.75+ (1.953)

$ env MOJO_LOG_LEVEL=debug MOJO_LISTEN=http://[2001:470:1f11:d34::4]:3000 perl -Mojo -E 'a("/"=>sub{$_->app->log->debug("Remote Address: ".$_->tx->remote_address); $_->render(text=>$_->tx->remote_address)})->start' daemon
[Fri Dec 20 17:48:12 2013] [info] Listening at "http://[2001:470:1f11:d34::4]:3000".
Server available at http://[2001:470:1f11:d34::4]:3000.
[Fri Dec 20 17:48:14 2013] [debug] Your secret passphrase needs to be changed!!!
[Fri Dec 20 17:48:14 2013] [debug] GET "/".
[Fri Dec 20 17:48:14 2013] [debug] Routing to a callback.
[Fri Dec 20 17:48:14 2013] [debug] Remote Address: 2001:470:1f11:d34::4
[Fri Dec 20 17:48:14 2013] [debug] 200 OK (0.001000s, 1000.000/s).

...

sri, can the * in MOJO_LISTEN=http://*:3000 also include any IPv6 interfaces?

Is it possible to listen on the same port number on both the IPv4 address and the IPv6 address?

Stefan Adams

unread,
Jan 14, 2014, 4:43:32 PM1/14/14
to mojolicious

On Fri, Dec 20, 2013 at 5:53 PM, Stefan Adams <ste...@cogentinnovators.com> wrote:
Is it possible to listen on the same port number on both the IPv4 address and the IPv6 address?

# env MOJO_LOG_LEVEL=debug MOJO_LISTEN=http://[2001:1890:1221:800::61]:80,http://12.110.226.61:80 perl -Mojo -E 'a("/"=>sub{$_->app->log->debug("Remote Address: ".$_->tx->remote_address); $_->render(text=>$_->tx->remote_address."\n")})->start' daemon

Only IPv6 connections will connect on port 80.
2001:470:7b:1e5::2
$ curl 12.110.226.61
curl: (7) couldn't connect to host

# env MOJO_LOG_LEVEL=debug MOJO_LISTEN=http://[2001:1890:1221:800::61]:80,http://12.110.226.61:81 perl -Mojo -E 'a("/"=>sub{$_->app->log->debug("Remote Address: ".$_->tx->remote_address); $_->render(text=>$_->tx->remote_address."\n")})->start' daemon

IPv6 connections will connect on port 80 and IPv4 connections will connect on port 81.
$ curl ipv6.cogent-it.com  # 2001:1890:1221:800::61 (It seems curl won't connect to IPv6 IP addresses??)
2001:470:7b:1e5::2
24.107.112.178

Is it possible for one Mojolicious process to listen on port 80 for both the IPv6 address as well as the IPv4 address?  I can SSH to the box on both the IPv6 address as well as the IPv4 address...  Why can't I do the same with an HTTP connection?

sri

unread,
Jan 14, 2014, 10:02:43 PM1/14/14
to mojol...@googlegroups.com
Is it possible for one Mojolicious process to listen on port 80 for both the IPv6 address as well as the IPv4 address?

Should we have IPv6 experts on this list, this might be worth investigating (and possibly patch), but i suppose portability and backwards compatibility (especially regarding security) could be problematic.

--
sebastian

Stefan Adams

unread,
Jan 14, 2014, 10:37:38 PM1/14/14
to mojol...@googlegroups.com
On Tue, Jan 14, 2014 at 9:02 PM, sri <kra...@googlemail.com> wrote:
Is it possible for one Mojolicious process to listen on port 80 for both the IPv6 address as well as the IPv4 address?

Should we have IPv6 experts on this list, this might be worth investigating (and possibly patch), but i suppose portability and backwards compatibility (especially regarding security) could be problematic.

Perhaps the issue is related to this.  When listening to two different interfaces, only the first works.  When using * both work.  But * does not pick up on IPv6 addresses.

$ env MOJO_LOG_LEVEL=debug MOJO_LISTEN=http://127.0.0.1:8080,http://192.168.0.108:8080 perl -Mojo -E 'a("/"=>sub{$_->app->log->debug("Remote Address: ".$_->tx->remote_address); $_->render(text=>$_->tx->remote_address."\n")})->start' daemon
[Tue Jan 14 21:30:46 2014] [info] Listening at "http://127.0.0.1:8080".
Server available at http://127.0.0.1:8080.
[Tue Jan 14 21:30:46 2014] [info] Listening at "http://192.168.0.108:8080".
Server available at http://192.168.0.108:8080.

127.0.0.1
curl: (7) couldn't connect to host

$ env MOJO_LOG_LEVEL=debug MOJO_LISTEN=http://192.168.0.108:8080,http://127.0.0.1:8080 perl -Mojo -E 'a("/"=>sub{$_->app->log->debug("Remote Address: ".$_->tx->remote_address); $_->render(text=>$_->tx->remote_address."\n")})->start' daemon
[Tue Jan 14 21:34:26 2014] [info] Listening at "http://192.168.0.108:8080".
Server available at http://192.168.0.108:8080.
[Tue Jan 14 21:34:26 2014] [info] Listening at "http://127.0.0.1:8080".
Server available at http://127.0.0.1:8080.

curl: (7) couldn't connect to host
192.168.0.108

$ env MOJO_LOG_LEVEL=debug MOJO_LISTEN=http://*:8080 perl -Mojo -E 'a("/"=>sub{$_->app->log->debug("Remote Address: ".$_->tx->remote_address); $_->render(text=>$_->tx->remote_address."\n")})->start' daemon
127.0.0.1
192.168.0.108


----------------------------------------------------------------
Keystone IT made the following notation
----------------------------------------------------------------
Email Confidentiality Notice: The information contained in this transmission is confidential, proprietary or privileged and may be subject to protection under the law, including the Health Insurance Portability and Accountability Act (HIPAA). 

This message is for the sole use of the intended individual or entity to whom it is addressed. If you are not the intended recipient, you are notified that any use, distribution or copying of the message is strictly prohibited and may subject you to criminal or civil penalties. If you received this transmission in error, please contact the sender immediately at (314) 621-9500 and delete the material from all computers.

Stefan Adams

unread,
Jan 14, 2014, 11:37:18 PM1/14/14
to mojol...@googlegroups.com
On Tue, Jan 14, 2014 at 9:37 PM, Stefan Adams <ste...@cog-ent.com> wrote:



On Tue, Jan 14, 2014 at 9:02 PM, sri <kra...@googlemail.com> wrote:
Is it possible for one Mojolicious process to listen on port 80 for both the IPv6 address as well as the IPv4 address?

Should we have IPv6 experts on this list, this might be worth investigating (and possibly patch), but i suppose portability and backwards compatibility (especially regarding security) could be problematic.

Perhaps the issue is related to this.  When listening to two different interfaces, only the first works.  When using * both work.  But * does not pick up on IPv6 addresses.

$ env MOJO_LOG_LEVEL=debug MOJO_LISTEN=http://127.0.0.1:8080,http://192.168.0.108:8080 perl -Mojo -E 'a("/"=>sub{$_->app->log->debug("Remote Address: ".$_->tx->remote_address); $_->render(text=>$_->tx->remote_address."\n")})->start' daemon
[Tue Jan 14 21:30:46 2014] [info] Listening at "http://127.0.0.1:8080".
Server available at http://127.0.0.1:8080.
[Tue Jan 14 21:30:46 2014] [info] Listening at "http://192.168.0.108:8080".
Server available at http://192.168.0.108:8080.

$ netstat -tulpen | grep :8080
tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN      1000       5615073     14990/perl      
 
127.0.0.1
curl: (7) couldn't connect to host

$ env MOJO_LOG_LEVEL=debug MOJO_LISTEN=http://192.168.0.108:8080,http://127.0.0.1:8080 perl -Mojo -E 'a("/"=>sub{$_->app->log->debug("Remote Address: ".$_->tx->remote_address); $_->render(text=>$_->tx->remote_address."\n")})->start' daemon
[Tue Jan 14 21:34:26 2014] [info] Listening at "http://192.168.0.108:8080".
Server available at http://192.168.0.108:8080.
[Tue Jan 14 21:34:26 2014] [info] Listening at "http://127.0.0.1:8080".
Server available at http://127.0.0.1:8080.

$ netstat -tulpen | grep :8080
tcp        0      0 192.168.0.108:8080      0.0.0.0:*               LISTEN      1000       5614881     14979/perl      
 
curl: (7) couldn't connect to host
192.168.0.108

$ env MOJO_LOG_LEVEL=debug MOJO_LISTEN=http://*:8080 perl -Mojo -E 'a("/"=>sub{$_->app->log->debug("Remote Address: ".$_->tx->remote_address); $_->render(text=>$_->tx->remote_address."\n")})->start' daemon
127.0.0.1
192.168.0.108

$ env MOJO_LOG_LEVEL=debug MOJO_LISTEN=http://127.0.0.1:8080,http://127.0.0.1:8081 perl -Mojo -E 'a("/"=>sub{$_->app->log->debug("Remote Address: ".$_->tx->remote_address); $_->render(text=>$_->tx->remote_address."\n")})->start' daemon$VAR1 = {
[Tue Jan 14 22:06:49 2014] [info] Listening at "http://127.0.0.1:8080".
Server available at http://127.0.0.1:8080.
[Tue Jan 14 22:06:49 2014] [info] Listening at "http://127.0.0.1:8081".
Server available at http://127.0.0.1:8081.

$ netstat -tulpen | grep :808
tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN      1000       5623199     15058/perl      
tcp        0      0 127.0.0.1:8081          0.0.0.0:*               LISTEN      1000       5623201     15058/perl      

$ env MOJO_LOG_LEVEL=debug MOJO_LISTEN=http://127.0.0.1:8080,http://192.168.0.108:8081 perl -Mojo -E 'a("/"=>sub{$_->app->log->debug("Remote Address: ".$_->tx->remote_address); $_->render(text=>$_->tx->remote_address."\n")})->start' daemon
[Tue Jan 14 22:24:12 2014] [info] Listening at "http://127.0.0.1:8080".
Server available at http://127.0.0.1:8080.
[Tue Jan 14 22:24:12 2014] [info] Listening at "http://192.168.0.108:8081".
Server available at http://192.168.0.108:8081.

$ netstat -tulpen | grep :808
tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN      1000       5629196     15160/perl      
tcp        0      0 192.168.0.108:8081      0.0.0.0:*               LISTEN      1000       5629198     15160/perl      

So the only scenario in which I see issue is when using the same port, regardless of host name.

I don't know what this means, but between lines 63 and 64 of Mojo::IOLoop::Server, I did `undef $fd;'  Upon doing so, I now get this:

$ env MOJO_LOG_LEVEL=debug MOJO_LISTEN=http://127.0.0.1:8080,http://192.168.0.108:8080 perl -Mojo -E 'a("/"=>sub{$_->app->log->debug("Remote Address: ".$_->tx->remote_address); $_->render(text=>$_->tx->remote_address."\n")})->start' daemon
[Tue Jan 14 22:34:24 2014] [info] Listening at "http://127.0.0.1:8080".
Server available at http://127.0.0.1:8080.
[Tue Jan 14 22:34:24 2014] [info] Listening at "http://192.168.0.108:8080".
Server available at http://192.168.0.108:8080.

$ netstat -tulpen | grep :808
tcp        0      0 192.168.0.108:8080      0.0.0.0:*               LISTEN      1000       5632339     15201/perl      
tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN      1000       5632337     15201/perl      

And Mojolicious now behaves as expected in which it's listening on two different hosts on the same port.

[Tue Jan 14 22:35:50 2014] [debug] Your secret passphrase needs to be changed!!!
[Tue Jan 14 22:35:50 2014] [debug] GET "/".
[Tue Jan 14 22:35:50 2014] [debug] Routing to a callback.
[Tue Jan 14 22:35:50 2014] [debug] Remote Address: 192.168.0.108
[Tue Jan 14 22:35:50 2014] [debug] 200 OK (0.000680s, 1470.588/s).
[Tue Jan 14 22:36:12 2014] [debug] GET "/".
[Tue Jan 14 22:36:12 2014] [debug] Routing to a callback.
[Tue Jan 14 22:36:12 2014] [debug] Remote Address: 2001:470:7c:1e5::108
[Tue Jan 14 22:36:12 2014] [debug] 200 OK (0.000302s, 3311.258/s).

Obviously, setting $fd to undef where I did is NOT the right thing to do.  I'm not sure what is.  I hope this helps!!

sri

unread,
Jan 14, 2014, 11:56:18 PM1/14/14
to mojol...@googlegroups.com
I don't know what this means, but between lines 63 and 64 of Mojo::IOLoop::Server, I did `undef $fd;'...

Ah! That makes perfect sense and is easy to improve. :)


--
sebastian 

Stefan Adams

unread,
Jan 15, 2014, 12:32:35 AM1/15/14
to mojol...@googlegroups.com
Wonderful!  Thanks so much!!  Naturally, it works like a charm!

Dirk Koopman

unread,
Jan 15, 2014, 8:30:41 AM1/15/14
to mojol...@googlegroups.com
On 14/01/14 21:43, Stefan Adams wrote:
>
> On Fri, Dec 20, 2013 at 5:53 PM, Stefan Adams
> <ste...@cogentinnovators.com <mailto:ste...@cogentinnovators.com>> wrote:
>
> Is it possible to listen on the same port number on both the IPv4
> address and the IPv6 address?
>
>
> # env MOJO_LOG_LEVEL=debug
> MOJO_LISTEN=http://[2001:1890:1221:800::61]*:80*,http://12.110.226.61*:80*
> perl -Mojo -E 'a("/"=>sub{$_->app->log->debug("Remote Address:
> ".$_->tx->remote_address);
> $_->render(text=>$_->tx->remote_address."\n")})->start' daemon
>

Am I missing something here? Unless you are perming these two addresses
out of several more, what's wrong with: MOJO_LISTEN=http://[::]:80 ?
This will happily answer on both IPV4 as well IPV6 (on a linux box at
least).



Stefan Adams

unread,
Jan 15, 2014, 8:37:34 AM1/15/14
to mojol...@googlegroups.com

On Wed, Jan 15, 2014 at 7:30 AM, Dirk Koopman <d...@tobit.co.uk> wrote:
Am I missing something here? Unless you are perming these two addresses out of several more, what's wrong with: MOJO_LISTEN=http://[::]:80 ? This will happily answer on both IPV4 as well IPV6 (on a linux box at least).

Thanks, Dirk!  I just figured this out this morning.  Nevertheless, the fix that sri applied last night was an appropriate one.

When I listen on http://[::]:80 I get these checkip responses:

::ffff:24.107.112.178
$ mojo get http://[2001:1890:1221:800::61]:80
2001:470:7c:1e5::108

Compare this to listening on http://[2001:1890:1221:800::61]:80,http://12.110.226.61:80

24.107.112.178
$ mojo get http://[2001:1890:1221:800::61]:80
2001:470:7c:1e5::108

For the purpose of my checkip app, the latter is a more desirable behavior.

Stefan Adams

unread,
Jan 18, 2014, 1:55:37 PM1/18/14
to mojolicious
On Tue, Jan 14, 2014 at 10:56 PM, sri <kra...@googlemail.com> wrote:

$ env MOJO_LISTEN=http://*:8080,http://*:8181 mojo daemon
Server available at http://127.0.0.1:8080.
Server available at http://127.0.0.1:8181.
$ mojo daemon -l http://*:8080,http://*:8181
Can't create listen socket: Name or service not known at /home/s/perl5/perlbrew/perls/perl-5.18.1/lib/site_perl/5.18.1/Mojo/IOLoop.pm line 119.
$ mojo daemon -l http://*:8080 -l http://*:8181
Server available at http://127.0.0.1:8080.
Server available at http://127.0.0.1:8181.
$ morbo -l http://*:8080 -l http://*:8181 ./hello
Server available at http://127.0.0.1:8080.
Server available at http://127.0.0.1:8181.
$ morbo -l http://*:8080,http://*:8181 ./hello
Server available at http://127.0.0.1:8080.
Server available at http://127.0.0.1:8181.

With the daemon and prefork commands, should you be able to specify multiple listen sockets separated by , to the -l parameter like you do with morbo / MOJO_LISTEN?  Or should you only be able to do it by specifying one listen socket per -l parameter in contrast to morbo and MOJO_LISTEN?
Reply all
Reply to author
Forward
0 new messages