-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
net: add IP.IsPrivate (RFC 1918 & RFC 4193) #29146
Comments
How many more kinds of groups are there besides loopback, multicast, private, etc? That is, what else might we be missing? I'd like to understand if this is the last one or just the next on a very long sequence. It seems OK if we're almost done. |
/cc @mikioh |
One problem with an |
ping @mikioh, @aaranmcguire: roughly speaking, are there 2 more of these IP address classes that we need to add, or 20 more? |
I don't know any more classes of addresses, however I'm not a network person so there may be more I'm unaware of. |
Since we think there are not many more of these, this seems OK to do. IPv4 calls these Private; IPv6 calls these "Unique Local" at least in RFC 4193. One function should probably do both. Should it be IsPrivate or IsLocal? |
Will take a look, sorry my laptop is still broken (and my fingertips are not good for touch screens.) |
One roadblock is that we still have no concrete consensus on how to deal with IPv4 addresses including IPv4-IPv4(-IPv4) translation addresses and IPv6 addresses including IPv4-IPv6 transition addresses. For example, I'm still not sure whether reporting
If you think the above methods look confusing, that might be a clear signal that it's better to have an external package, like #11772.
Yes, and the helper methods have an essential characteristic: each helper follows basic IP addressing architecture and never jumps across the line of complicated operational stuff; e.g., geographic things, translation things, and IANA-allocated special-purpose (e.g., for documentation, for AS112/honeypot) things.
People in some organization operating IPv4 private address blocks might want a method reporting organization-specific private/local IP addresses. I personally hope to solve this sort of issues with #18804. |
It should be the case that net.IsPrivate(ip) == net.IsPrivate(ip.To16()) always, and net.IsPrivate(ip) == net.IsPrivate(ip.To4()) when ip.To4() != nil. We always treat IPv4-formatted and IPv4-in-IPv6-formatted addresss as equivalent in package net. That answers I'm not familiar with Does anyone object to adding net.IsPrivate? |
Are you talking about IPv4-mapped IPv6 address? Or something you or people in the Go team defined one? If the former, it's better to document why the prefix for IPv4-mapped IPv6 address
It should be IsLocalUnicast if it also covers IPv6 ULA. |
Why? We can easily include the "Unique Local Address" and "ULA" and "RFC 4193" in the docs, but is "private" an inaccurate description? These are addresses that don't route out to the internet, right? That's what private has always meant in V4. |
This is just a reply to @rsc for sharing the background.
Not so pedantic, two concerns:
|
I'd recommend renaming IsPrivate with IsPrivateUnicast. IsPrivate looks a bit vague and we already have IsGlobalUnicast. |
Change https://golang.org/cl/162998 mentions this issue: |
Fixes golang#29146 Change-Id: I69f51f943a684bdffaa9a32bea56eb2c5d881b33
What's the status of this? Can it be merged now? |
Kindly paging @MaxSem the author of CL https://go-review.googlesource.com/c/go/+/162998/, @mikioh left some comments on your CL sometime ago, please take a look. Thank you! |
As I see it, there were disagreements about the proposed function name among project members. I'm happy to change it, but I'd appreciate clarity as to the correct name :) |
I'm going to create a Pull ... |
Add IsPrivate() helper to check if an IP is private according to RFC 1918 & RFC 4193 Fixes golang#29146
If I have to do something just tell me :) -> #42793 |
Change https://golang.org/cl/272668 mentions this issue: |
Add IsPrivate() helper to check if an IP is private according to RFC 1918 & RFC 4193 Fixes golang#29146
Add IsPrivate() helper to check if an IP is private according to RFC 1918 & RFC 4193 Fixes golang#29146
Add IsPrivate() helper to check if an IP is private according to RFC 1918 & RFC 4193 Fixes golang#29146
would also love to see this merged 👍 |
Add IsPrivate() helper to check if an IP is private according to RFC 1918 & RFC 4193 Fixes golang#29146
Add IsPrivate helper to check if an IP is private according to RFC 1918 & RFC 4193. Fixes golang#29146
Add IsPrivate() helper to check if an IP is private according to RFC 1918 & RFC 4193 Fixes golang#29146
Add IsPrivate() helper to check if an IP is private according to RFC 1918 & RFC 4193 Fixes golang#29146
I think the comment in the For the local IPv4 addresses, the comment cites RFC 4193, but this document only specifies local IPv6 addresses. |
@perillo, you are correct, thank you; it was just a typo. I had highlighted the change in my comment https://go-review.googlesource.com/c/go/+/272668/7..11/src/net/ip.go#b135 But I missed it in the later revision. Please feel free to send a change and tag me and I’ll review it. |
@odeke-em thanks to you for the contribution. I have also noted another small issue. Unlike RFC 1918, RFC 4193 in section 3 does not say "The Internet Assigned Numbers Authority (IANA) has reserved ...". Instead in section 8 (IANA Considerations) it just says "The IANA has assigned the FC00::/7 prefix to "Unique Local Unicast". See https://tools.ietf.org/html/rfc4193#section-3 and https://tools.ietf.org/html/rfc4193#section-8. Thanks |
Did I miss something?!? |
@perillo sorry it was me geting these typos in :/ should I send a pull with your suggestions? |
Change https://golang.org/cl/309249 mentions this issue: |
Properly cite RFC 1918 Section 3 for ipv4, and RFC 4193 Section 8 for ipv6 comments. Updates #29146 Change-Id: I8a2df0d7bef50444294bb3301fe09fb09f21ffaf GitHub-Last-Rev: b034179 GitHub-Pull-Request: #45500 Reviewed-on: https://go-review.googlesource.com/c/go/+/309249 Reviewed-by: Emmanuel Odeke <[email protected]> Reviewed-by: Tobias Klauser <[email protected]> Run-TryBot: Emmanuel Odeke <[email protected]>
The
net
package seems to have many helpers to report what an IP is. e.g:IsLoopback()
IsMulticast()
IsInterfaceLocalMulticast()
However there are no helpers to report if a IP address is in the private ranges (RFC 1918 & RFC 4193).
If no one has any objections I can make a method in net/ip.go named
IsPrivate()
that will check for the ranges listed in both RFCs using the same syntax the other helpers use.The text was updated successfully, but these errors were encountered: