Subject: | [PATCHES] Improve IPv6 support |
Hi Peter,
I'm trying to install Net::LDAP::Server::Test and just about every test fails out with "Connection refused". I've determined (after lots of blood sweat and tears :)) that the problem is not in fact any firewall blockade, as hinted at in the README, but instead a matter of IPv4 vs IPv6 support.
In short, Net::LDAP prefers to use IPv6 where available (using IO::Socket 0.20+ then IO::Socket::INET6):
https://metacpan.org/source/MARSCHAP/perl-ldap-0.65/lib/Net/LDAP.pm#L32
https://metacpan.org/source/MARSCHAP/perl-ldap-0.65/lib/Net/LDAP.pm#L153
But, Net::LDAP::Server::Test is hardcoded to use IPv4 (by its use of IO::Socket::INET):
https://metacpan.org/source/KARMAN/Net-LDAP-Server-Test-0.20/lib/Net/LDAP/Server/Test.pm#L923
https://metacpan.org/source/KARMAN/Net-LDAP-Server-Test-0.20/lib/Net/LDAP/Server/Test.pm#L1043
This means that in certain configurations, Net::LDAP (connecting with IPv6) cannot connect to Net::LDAP::Server::Test (listening on IPv4). For a more concrete example, setting up a standalone Net::LDAP::Server::Test instance and trying to connect to it with "nc" fails using IPv6, but succeeds when using IPv4, like so:
$ nc -v 127.0.0.1 10636
Connection to 127.0.0.1 10636 port [tcp/*] succeeded!
$ nc -4v localhost 10636
Connection to localhost 10636 port [tcp/*] succeeded!
$ nc -v ::1 10636
nc: connect to ::1 port 10636 (tcp) failed: Connection refused
$ nc -6v localhost 10636
nc: connect to localhost port 10636 (tcp) failed: Connection refused
I'm submitting two pull requests to your GitHub repo. What you merge is up to you, but I don't think merging both would make much sense.
The first PR (ipv4-loopback-address) switches the tests from using "localhost" to "127.0.0.1". This should fix the symptom by forcing use of the IPv4 stack. It's a less invasive change, but unfortunately it doesn't help anyone downstream whose own tests specify "localhost" as documented in Net::LDAP::Server::Test.
The other (prefer-ipv6) switches the server from using IPv4 exclusively to preferring IPv6 where available, in the 100% exact same way that Net::LDAP does, which means they should always be able to connect. I left t/03-socket.t using the IPv4 stack to continue exercising that behavior.
Thanks very much!
Shawn