-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8315767: InetAddress: constructing objects from BSD literal addresses #18493
Conversation
👋 Welcome back schernyshev! A progress list of the required criteria for merging this PR into |
@sercher This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 726 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@dfuch, @AlekseiEfimov, @Michael-Mc-Mahon, @jaikiran) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
/csr needed |
@AlekseiEfimov has indicated that a compatibility and specification (CSR) request is needed for this pull request. @sercher please create a CSR request for issue JDK-8315767 with the correct fix version. This pull request cannot be integrated until the CSR request is approved. |
Webrevs
|
Co-authored-by: Daniel Fuchs <67001856+dfuch@users.noreply.github.com>
…ed code examples to reflect the network byte order
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking on the feedback @sercher . I believe we're in a much better place now. I will let @AlekseiEfimov comment on the test and implementation.
Co-authored-by: Daniel Fuchs <67001856+dfuch@users.noreply.github.com>
Co-authored-by: Daniel Fuchs <67001856+dfuch@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parsing code and the test changes look good to me with a couple of minor suggestions.
Should we be setting any expectations by specifying what |
In the InetAddress class level API documentation we have:
Do you think it should be reiterated in the |
The changes proposed in this PR introduce a new paragraph in the class level documentation just before the line which states the dotted-quad string. So I think it may not be clear enough whether dotted-quad string implies decimal values ( |
Good point. |
Co-authored-by: Daniel Fuchs <67001856+dfuch@users.noreply.github.com>
Thanks - LGTM now. @AlekseiEfimov, @Michael-Mc-Mahon are you also good with this version of the changes? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The latest changes LGTM.
Thank you @AlekseiEfimov, @dfuch for your reviews! |
I'd just like to have one more look at it today, if that's okay. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Just a couple of minor nits to suggest.
I read through the API docs in the latest revision (664fccb) and it looks very good. The new method is not easily discovered, which is okay as it's very much a method for experts, I see wonder if we should put a |
Co-authored-by: Michael McMahon <70538289+Michael-Mc-Mahon@users.noreply.github.com>
Thanks @AlanBateman for your note. There's a link to |
I think you may have mis-read my comment. I think we need to add |
Thanks @AlanBateman , apologize for mis-reading your comment. I added |
/integrate |
/sponsor |
Going to push as commit c2180d1.
Your commit was automatically rebased without conflicts. |
There are two distinct approaches to parsing IPv4 literal addresses. One is the Java baseline "strict" syntax (all-decimal d.d.d.d form family), another one is the "loose" syntax of RFC 6943 section 3.1.1 [1] (POSIX
inet_addr
allowing octal and hexadecimal forms [2]). The goal of this PR is to provide interface to construct InetAddress objects from literal addresses in POSIX form, to applications that need to mimic the behavior ofinet_addr
used by standard network utilities such as netcat/curl/wget and the majority of web browsers. At present time, there's no way to constructInetAddress
object from such literal addresses because the existing APIs such asInetAddress.getByName()
,InetAddress#ofLiteral()
andInet4Address#ofLiteral()
will consume an address and successfully parse it as decimal, regardless of the octal prefix. Hence, the resulting object will point to a different IP address.Historically
InetAddress.getByName()/.getAllByName()
were the only way to convert a literal address into an InetAddress object.getAllByName()
API relies on POSIXgetaddrinfo
/inet_addr
which parses IP address segments withstrtoul
(accepts octal and hexadecimal bases).The fallback to
getaddrinfo
is undesirable as it may end up with network queries (blocking mode), ifinet_addr
rejects the input literal address. The Java standard explicitly says that@AlekseiEfimov contributed JDK-8272215 [3] that adds new factory methods
.ofLiteral()
toInetAddress
classes. Although the new API is not affected by thegetaddrinfo
fallback issue, it is not sufficient for an application that needs to interoperate with external tooling that follows POSIX standard. In the current state,InetAddress#ofLiteral()
andInet4Address#ofLiteral()
will consume the input literal address and (regardless of the octal prefix) parse it as decimal numbers. Hence, it's not possible to reliably construct anInetAddress
object from a literal address in POSIX form that would point to the desired host.It is proposed to extend the factory methods with
Inet4Address#ofPosixLiteral()
that allows parsing literal IP(v4) addresses in "loose" syntax, compatible withinet_addr
POSIX api. The implementation is based on.isBsdParsableV4()
method added along with JDK-8277608 [4]. The changes in the original algorithm are as follows:IPAddressUtil#parseBsdLiteralV4()
method is extracted from.isBsdParsableV4()
null
is returned whenever the original algorithm failsThe new method hasn't been added to InetAddress superclass because the change is only related to IPv4 addressing. This reduces the chance that client code will call the wrong factory method.
test/jdk/java/net/InetAddress/OfLiteralTest.java
was updated to include.ofPosixLiteral()
testsJavadocs in
Inet4Address
were updated accordinglyThe new method can be used as follows
The output would be
[1] https://www.ietf.org/rfc/rfc6943.html#section-3.1.1
[2] https://pubs.opengroup.org/onlinepubs/9699919799/functions/inet_addr.html
[3] https://bugs.openjdk.org/browse/JDK-8272215
[4] cdc1582
Progress
Issues
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/18493/head:pull/18493
$ git checkout pull/18493
Update a local copy of the PR:
$ git checkout pull/18493
$ git pull https://git.openjdk.org/jdk.git pull/18493/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 18493
View PR using the GUI difftool:
$ git pr show -t 18493
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/18493.diff
Webrev
Link to Webrev Comment