-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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.IsLocal #30278
net: add IP.IsLocal #30278
Conversation
This PR (HEAD: 4bedd5d) has been imported to Gerrit for code review. Please visit https://go-review.googlesource.com/c/go/+/162998 to see it. Tip: You can toggle comments from me using the |
Message from Gobot Gobot: Patch Set 1: Congratulations on opening your first change. Thank you for your contribution! Next steps: Most changes in the Go project go through a few rounds of revision. This can be During May-July and Nov-Jan the Go project is in a code freeze, during which Please don’t reply on this GitHub thread. Visit golang.org/cl/162998. |
Message from Brad Fitzpatrick: Patch Set 1: (2 comments) Please don’t reply on this GitHub thread. Visit golang.org/cl/162998. |
Message from Max Semenik: Patch Set 3: (2 comments) Please don’t reply on this GitHub thread. Visit golang.org/cl/162998. |
Message from Max Semenik: Patch Set 3: Uh, the bot reverted my PS2? Please don’t reply on this GitHub thread. Visit golang.org/cl/162998. |
Fixes golang#29146 Change-Id: I69f51f943a684bdffaa9a32bea56eb2c5d881b33
This PR (HEAD: 424bea4) has been imported to Gerrit for code review. Please visit https://go-review.googlesource.com/c/go/+/162998 to see it. Tip: You can toggle comments from me using the |
Message from Max Semenik: Patch Set 6: Okay, back to pushing to GitHub :D This is ready for review. Please don’t reply on this GitHub thread. Visit golang.org/cl/162998. |
Message from Mikio Hara: Patch Set 7: (5 comments) Please don’t reply on this GitHub thread. Visit golang.org/cl/162998. |
Message from Mikio Hara: Patch Set 7: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/162998. |
Message from Juan Antonio Osorio: Patch Set 7: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/162998. |
Message from Mikio Hara: Patch Set 7: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/162998. |
// Local IPv4 addresses are defined in https://tools.ietf.org/html/rfc1918 | ||
return ip4[0] == 10 || | ||
(ip4[0] == 172 && ip4[1]&0xf0 == 16) || | ||
(ip4[0] == 192 && ip4[1] == 168) |
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.
IsLocal
name is miss-leading. Did you meanIsPrivate
? I would interpretIsLocal
as a private address in the same network- How to handle cases
0.0.0.0
and127.0.0.1
and::1
?
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.
- I also think
IsPrivate
would be a better name. - We do at least have
IsUnspecified()
andIsLoopback()
to cover those cases with IsLocal you can doIsLocal() || IsUnspecified() || IsLoopback()
if you want to cover all.
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.
Speaking about private addresses - 100.64.0.0/10
is private, 198.18.0.0/15
is private too.
This implementation is true only for RFC 1918 (IPv4 addresses) and RFC 4193 (IPv6 addresses).
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.
Sure but that doesn't mean it would still be useful too have a group for RFC 1918 and RFC 4193... We're using this to filter webhook calls, so people can't setup a webhook that calls a private address in our internal networks. The carrier grade nat scope 100.64.0.0/10 and/or the benchmark test net 198.18.0.0/15 is not really any concern for us, protecting internal networks is.
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.
i was not clear, my points are:
IsLocal
is a bad name, i am with you on it.IsPrivate
is ok name, but changing the name brings new problem - current implementation includes only part of private ip address blocks.
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.
I have a second thought about it. IsPrivate
wont do, because there are a lot of other ip block in the private scope.
IP blocks from rfc1918
fall into private
category but they have special purpose. rfc1918
doesnt name them local tho. But the gist is - local communication (inside enterprise). So the grouping is ok, naming is a little bit miss-leading. Proof - our comments 😄
But IsLocal
makes more sense then IsPrivate
and this logical block shouldnt cover
How to handle cases 0.0.0.0 and 127.0.0.1 and ::1?
Only blocks from RFC 1918 (IPv4 addresses) and RFC 4193 (IPv6 addresses)
should be there.
Message from Alex Miasoedov: Patch Set 7: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/162998. |
53bd915
to
6139019
Compare
4a7ed1f
to
0f992b9
Compare
Fixes #29146