-
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/netip: add new IP address package, use in net #46518
Comments
cc @marten-seemann for quic-go |
If there's any way we could address the JSON marshalling of CIDR address formats at the same time, that would be very convenient -- rather than having to rely on making custom encoders etc. I realise that the backwards compatibility guarantee means that's unlikely to be fixed in the standard library version of "net", but if it could be addressed in this proposed new package, it would certainly make the life of network engineers much simpler! |
https://play.golang.org/p/5QWiD-tArCc
|
As someone who had to invent their own IP datatype (https://pkg.go.dev/github.com/bio-routing/bio-rd/net#IP) for the very same reasons, I'm really glad to see progress on this topic. Looking forward to see a decent IP datatype in Golang. Thanks! |
This proposal has been added to the active column of the proposals project |
Would it be worth considering adding a runtime primitive of some sort to help avoid the "workarounds" in the intern package? I don't think it would need to be done at the same time, but having a user for it in the stdlib might make it more compelling. |
@kylelemons There have been and are some proposals related to that, most notable probably #43615. In the interim, the workarounds are much less problematic when they are in the stdlib, because if anything is changed in the implementation that would prevent them from working, they can be changed alongside with it. |
@kylelemons, what @Merovius said. And to be clear (to anybody just researching the intern package and being horrified), we are definitely not proposing exposing the intern package or any of its API. It's very much an internal implementation detail. |
I don’t want to start bikeshedding, but i think that the proposed type names look a little bit cluttered, since they all share the
Couldn’t the IP-part just move into the package name instead:
Or maybe something like Otherwise: Thank you, @bradfitz, for this great proposal and your highly enjoyable blog post! |
My only nitpick about the package name |
@mdlayher While i still think that |
Might also make it ip2 as introduced in Go "2". Or use |
Opened a discussion at #47323. |
Change https://golang.org/cl/339309 mentions this issue: |
Given that there seems to be consensus on the four types, it seems like the full API for those would be:
I've also updated the discussion's top comment with this API. Please comment there if you have opinions. Thanks. |
Minor updates at #47323 (comment). |
Based on the discussion above, this proposal seems like a likely accept. |
@rsc, I assume your #46518 (comment) comment is just missing the |
No change in consensus, so accepted. 🎉 |
Change https://golang.org/cl/360634 mentions this issue: |
Change https://golang.org/cl/370134 mentions this issue: |
Change https://golang.org/cl/373834 mentions this issue: |
I propose we fix #18804 (net: reconsider representation of IP) by importing the
inet.af/netaddr
into the standard library, probably asnet/netaddr
, so theIP
type isnetaddr.IP
(thenet
package already has an IP type). We wouldn't need to import all of it, at least not right away, but I think it'd be nice if we did... the package types work together very well.This blog post explains the advantages of
netaddr.IP
overnet.IP
:https://tailscale.com/blog/netaddr-new-ip-type-for-go/
Notably, it's small, comparable, and doesn't allocate.
Code is at https://github.com/inetaf/netaddr. Everybody has a Go CLA filed ( inetaf/netaddr#181) and the license is compatible.
Having an allocation-free IP address in the standard library means we'd be able to fix #45886 ("net: add API to receive multiple UDP packets (potentially in one system call)") which ends with #45886 (comment) ("We may want to wait on doing anything here until we figure out what to do with IP addresses, which still allocate."). More generally, this would improve Go's UDP performance, which has never gotten much attention. But with things like QUIC and WireGuard (both UDP-based), Go's alloc-heavy UDP handling is starting to get in the way.
Yes, we'd then have two IP types in the standard library.
As part of this, we'd then add:
net
would depend onnetaddr
, not vice-versa)net
package internals would switch tonetaddr.IP
for performance/allocs, converting tonet.IP
orIPAddr
on the edges only.UDPConn
) to send/receive UDP packets usingnetaddr.IP
alloc-free (we'd then have ~5 ways to send/recv UDP packets instead of ~4)/cc @danderson, @josharian, @mdlayher, @crawshaw, @tklauser (co-authors), @neild (co-author for #45886)
The text was updated successfully, but these errors were encountered: