[ipv6] RFR: 8223737: HostsFileNameService doesn't handle IPv6 literal addresses correctly

Chris Hegarty chris.hegarty at oracle.com
Tue May 14 09:15:38 UTC 2019


Mark,

The comparison by String was a reasonable choice when this mechanism was
added. What is being proposed here expands the functionality so that
logically equivalent IPv6 literals can be used without the need for
additional entries.

I did the following testing on my Linux box, Ubuntu 16.04, and it shows,
at least on this Linux flavour, that the platform name service operates
in a similar way to that of the change that is being proposed here.

$ cat /etc/*release*
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.5 LTS"
NAME="Ubuntu"
VERSION="16.04.5 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.5 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
$ uname -a
Linux chhegar 4.15.0-39-generic #42~16.04.1-Ubuntu SMP Wed Oct 24 17:09:54 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
$
$
$ cat /etc/hosts
::3	xxyyzz

::1	localhost
::1	chhegar

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

$ ~/binaries/jdk-12/bin/jshell
|  Welcome to JShell -- Version 12
|  For an introduction type: /help intro

jshell> InetAddress.getByName("::3").getHostName()
$1 ==> "xxyyzz"

jshell> InetAddress.getByName("0:0:0:0:0:0:0:3").getHostName()
$2 ==> "xxyyzz"

jshell> InetAddress.getByName("0000:0000:0000:0000:0000:0000:0000:0003").getHostName()
$3 ==> "xxyyzz"


> On 14 May 2019, at 00:52, mark sheppard <macanaoire at hotmail.com> wrote:
> 
> Hi Arthur, Chris,
>    just a note in passing, as you are well set on the changes, which is all  good -- needs must, as they say.
> 
> The current implementation is an emulation of the gethostbyname and gethostbyaddr lookup on /etc/hosts.
> The reverse lookup  issue is also solved by adding an additional entry in the hosts file
> 0:0:0:0:0:0:0:1 ip6-localhost ip6-loopback. Your reverse lookup will pass.
> 
> $ /cygdrive/c/Development/jdk-installs/jdk-12/bin/java InternalNameServiceWithHostsFileTest
> ############################  InetAddress == ip6-localhost/0:0:0:0:0:0:0:1​
> retrieved address == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1] equal to expected address == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]​
> testReverseLookup: host addr ::1 : expected host name ip6-localhost​
> testReverseLookup: host addr 0:0:0:0:0:0:0:1 : expected host name ip6-localhost​
> testReverseLookup: host addr 0000:0000:0000:0000:0000:0000:0000:0001 : expected host name ip6-localhost​
> 
> That was the design -- the hosts file would contain whatever set of mapping are required for a particular context.
> So the string comparison was sufficient.
> 
> IF your reverse lookup tests are run against the PlatformFormNameService, 
> which is the fall through to the native OS calls gethostbyname, getaddrinfo etc.
> then you get the same set of failure afaik.
> 
> on windows using jdk12 test output shown below 
> so you could say there is some degree of consistent behaviour between the two services!!
> 
> regards
> Mark
> 
> 
> 
> msheppard at MARKS-LAPTOP /cygdrive/c/Users/msheppard/eclipse-workspace/JDK-Tests
> $ /cygdrive/c/Development/jdk-installs/jdk-12/bin/java  -Djava.net.preferIPv6Addresses=true PlatformNameServiceTest​
> ############################  InetAddress == localhost/0:0:0:0:0:0:0:1​
> retrieved address == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1] equal to expected address == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]​
> testReverseLookup: host addr ::1 : expected host name localhost​
> Exception in thread "main" java.lang.RuntimeException: reverse lookup of "::1" is "0:0:0:0:0:0:0:1", should be "localhost"​
>>         at PlatformNameServiceTest.testReverseLookup(PlatformNameServiceTest.java:64)​
>         at PlatformNameServiceTest.main(PlatformNameServiceTest.java:25)​
>> msheppard at MARKS-LAPTOP /cygdrive/c/Users/msheppard/eclipse-workspace/JDK-Tests​
> $ /cygdrive/c/Development/jdk-installs/jdk-12/bin/java  -Djava.net.preferIPv6Addresses=true PlatformNameServiceTest​
> ############################  InetAddress == localhost/0:0:0:0:0:0:0:1​
> retrieved address == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1] equal to expected address == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]​
> testReverseLookup: host addr 0:0:0:0:0:0:0:1 : expected host name localhost​
> Exception in thread "main" java.lang.RuntimeException: reverse lookup of "0:0:0:0:0:0:0:1" is "0:0:0:0:0:0:0:1", should be "localhost"​
>>         at PlatformNameServiceTest.testReverseLookup(PlatformNameServiceTest.java:64)​
>         at PlatformNameServiceTest.main(PlatformNameServiceTest.java:26)​
>> msheppard at MARKS-LAPTOP /cygdrive/c/Users/msheppard/eclipse-workspace/JDK-Tests​
> $ /cygdrive/c/Development/jdk-installs/jdk-12/bin/java  -Djava.net.preferIPv6Addresses=true PlatformNameServiceTest​
> ############################  InetAddress == localhost/0:0:0:0:0:0:0:1​
> retrieved address == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1] equal to expected address == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]​
> testReverseLookup: host addr 0000:0000:0000:0000:0000:0000:0000:0001 : expected host name localhost​
> Exception in thread "main" java.lang.RuntimeException: reverse lookup of "0000:0000:0000:0000:0000:0000:0000:0001" is "0:0:0:0:0:0:0:1", should be "localhost"​
>>         at PlatformNameServiceTest.testReverseLookup(PlatformNameServiceTest.java:64)​
>         at PlatformNameServiceTest.main(PlatformNameServiceTest.java:27)​
> 
> 
> From: net-dev <net-dev-bounces at openjdk.java.net> on behalf of Arthur Eubanks <aeubanks at google.com>
> Sent: Monday 13 May 2019 17:59
> To: Chris Hegarty
> Cc: OpenJDK Network Dev list
> Subject: Re: [ipv6] RFR: 8223737: HostsFileNameService doesn't handle IPv6 literal addresses correctly
>  
> 
> 
> From: Chris Hegarty <chris.hegarty at oracle.com <mailto:chris.hegarty at oracle.com>>
> Date: Mon, May 13, 2019 at 9:33 AM
> To: Arthur Eubanks, OpenJDK Network Dev list
> 
> Arthur,
> 
> On 11/05/2019 01:17, Arthur Eubanks wrote:
> > Bug: https://bugs.openjdk.java.net/browse/JDK-8223737 <https://bugs.openjdk.java.net/browse/JDK-8223737>
> > Webrev: http://cr.openjdk.java.net/~aeubanks/8223737/webrev.00/index.html <http://cr.openjdk.java.net/~aeubanks/8223737/webrev.00/index.html>
> > 
> > HostsFileNameService doesn't handle IPv6 literal addresses correctly.
> > For example, ::1 and 0:0:0:0:0:0:0:1 should yield the same output.
> > 
> > Rather than comparing address strings, compare the address byte arrays.
> 
> Comparison of byte arrays is much better. The changes look good.
> 
> Trivially, can I ask you to please include a number of other reverse
> lookup's to fill out the test a little. Here's what I came up with:
> 
>      testReverseLookup("10.2.3.4", "testHost.testDomain");
> 
>      // ::1 and 0:0:0:0:0:0:0:1 should map to ip6-localhost
>      testReverseLookup("::1", "ip6-localhost");
>      testReverseLookup("0:0:0:0:0:0:0:1", "ip6-localhost");
> 
> testReverseLookup("0000:0000:0000:0000:0000:0000:0000:0001","ip6-localhost");
> 
>      testReverseLookup("fe00::0", "ip6-localnet");
>      testReverseLookup("fe00:0:0:0:0:0:0:0", "ip6-localnet");
>      testReverseLookup("fe00:0000:0000:0000:0000:0000:0000:0000", 
> "ip6-localnet");
> 
>      testReverseLookup("fe80::1", "link-local-host");
>      testReverseLookup("fe80:000:0:00:0:000:00:1", "link-local-host");
>      testReverseLookup("fe80:0000:0000:0000:0000:0000:0000:0001", 
> "link-local-host");
> 
> Thanks,
> -Chris.
> Added the extra reverse lookups.
> 
> I also noticed that the test is catching UnknownHostException and not rethrowing it, so I removed the try/catch.
> 
> Updated webrev: http://cr.openjdk.java.net/~aeubanks/8223737/webrev.01/index.html <http://cr.openjdk.java.net/~aeubanks/8223737/webrev.01/index.html>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/net-dev/attachments/20190514/db0f59b7/attachment-0001.html>


More information about the net-dev mailing list