-
Notifications
You must be signed in to change notification settings - Fork 18k
net/netip: missing odds and ends for 1.18 [freeze exception] #49298
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
Comments
import "golang.zx2c4.com/go118/netip" |
(1) is just an omission. I think @josharian was going to send a change for that. (2) doesn't seem objectionable to me at least. We had that originally as https://pkg.go.dev/inet.af/netaddr#IP.IPAddr but for circular dependency reasons we couldn't include it in net/netip. @rsc, opinions? |
(psst, I think you may have meant to tag @danderson instead of me. :-) |
Change https://golang.org/cl/360874 mentions this issue: |
Unless I'm misunderstanding something, |
Maybe we can drop |
Change https://golang.org/cl/360875 mentions this issue: |
The idea of The CL has been updated with @seankhliao's suggestion. |
Top post of issue updated to contain mention of |
Change https://golang.org/cl/361056 mentions this issue: |
Also, @josharian has a change to remove the remaining 1 alloc in the UDP paths so UDP sends/receives can be allocation-free, which is the main motivation of netip in the first place. It'd be a better story if the package & its benefit came together in the same release, rather than waiting for Go 1.19 to make use of netip in net be zero-alloc. In the same spirit of the #49073 freeze exception proposal, this is a proposal that we finish the misc loose ends on netip for 1.18. |
CC @golang/release |
I've now updated the top post of this issue to include that. |
Added to top post entry about missing UDPAddr and TCPAddr analogs. |
Change https://golang.org/cl/361477 mentions this issue: |
Added to top post entry about AddrFromSlice should return only one value. |
Change https://golang.org/cl/361479 mentions this issue: |
We've discussed this on the release team. Freeze exception granted. Please be mindful of timing and stability as you proceed. (Thanks for already documenting this new package in 1.18 release notes, it helps a lot!) |
Great. There are currently CLs submitted for 5/6 of the items (afaik). The relation chain begins here: https://go-review.googlesource.com/c/go/+/360874/ |
We have AddrFrom4, AddrFrom6, AddrFromSlice and As4, As6, but we are missing AsSlice, so this commit adds the missing function. It also gets rid of the less ergonomic and inconsistently named IPAddrParts. Updates #49298. Change-Id: I1c6a2c32fc6c69b244ab49765412ffe3bbe7e5c2 Reviewed-on: https://go-review.googlesource.com/c/go/+/360874 Trust: Jason A. Donenfeld <[email protected]> Trust: Josh Bleecher Snyder <[email protected]> Run-TryBot: Jason A. Donenfeld <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
The Addr type got an encoding.BinaryUnmarshaler implementation, but not AddrPort and Prefix. This commit adds the missing implementation of that interface to these types. It also adds two round trip tests that follow the template of the existing one for Addr. Updates #49298. Change-Id: Iac633aed8aac579960815bb64d06ff3181214841 Reviewed-on: https://go-review.googlesource.com/c/go/+/360875 Trust: Jason A. Donenfeld <[email protected]> Run-TryBot: Jason A. Donenfeld <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
There is IPv6Unspecified but there is not IPv4Unspecified, making for inconsistent code. This commit adds the missing function. Updates #49298. Change-Id: Id2519b646323642f59fb1cc6ea8e335fdde16290 Reviewed-on: https://go-review.googlesource.com/c/go/+/361056 Trust: Jason A. Donenfeld <[email protected]> Trust: Brad Fitzpatrick <[email protected]> Run-TryBot: Jason A. Donenfeld <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
One thing I was hoping to reach some consensus about was item 6: 6.
|
Change https://golang.org/cl/362596 mentions this issue: |
Change https://golang.org/cl/362595 mentions this issue: |
Change https://golang.org/cl/362597 mentions this issue: |
…nverse We already have various member functions of TCPAddr that return an AddrPort, but we don't have a helper function to go from a AddrPort to a TCPAddr. UDP has this, but it was left out of TCP. This commit adds the corresponding function. Updates #49298. Change-Id: I85732cf34f47c792fe13a6b4af64fd4b0e85d06a Reviewed-on: https://go-review.googlesource.com/c/go/+/362596 Trust: Jason A. Donenfeld <[email protected]> Run-TryBot: Jason A. Donenfeld <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
Now that netip has landed, I've started porting code to it. I'm hoping to get a bit of experience doing this before Go 1.18 in order to catch issues before it ships. So far I've identified six things that are missing, which I was hoping we could get into Go 1.18, as a followup to #46518.
Items with ⏳ have CLs still pending, and items with ✅ have CLs that have been submitted.
1.
MarshalBinary
/UnmarshalBinary
onAddrPort
andPrefix
✅Addr.MarshalBinary
andAddr.UnmarshalBinary
both exist. However, the same is not true for the remaining two types,AddrPort
andPrefix
. This makes it very hard to use withencoding/gob
, because not only are these marshals missing, but the inner addr + port/cidr members are unexported. So, I propose adding these two methods, with implementations that simply concatenateAddr.MarshalBinary
output with little-endian encoding of the port (uint16
) forAddrPort
or cidr (uint8
) forPrefix
.2.
Addr.AsSlice
✅There is
netip.AddrFromSlice()
andnetip.AddrFrom4
, but there is onlynetip.As4
and nonetip.AsSlice
. This may seem kind of trifling, but it winds up being kind of annoying when coding things; I find myself writing a lot of:You can't slice an rvalue, so that temporary is needed. And sometimes I just want a slice, regardless of what kind of IP it is, and having to open code dispatch for that every time is a bit of a pain. The above snippet would be simplified to:
3.
IPv4Unspecified()
✅There is
IPv6Unspecified()
, but notIPv4Unspecified()
. This is sort of confusing, and code would be more clear and consistent if I could writenetip.IPv4Unspecified()
instead ofnetip.AddrFrom4([4]byte{})
.4. One remaining allocation in UDP path
The "net" package has one remaining allocation in the UDP packet path, which @josharian has a change to fix, so that UDP sends/receives can be allocation-free. Being alloc-free is one of the original motivations behind
netip
in the first place.5. Missing
UDPAddr
andTCPAddr
analogs ❌ (partially accepted, partially punted to go 1.19)We have
ReadFromUDPAddrPort
and such, for reads and writes of UDP and TCP sockets, but the listener/dialer functions still take the oldTCPAddr
andUDPAddr
structs. So, we'll need new functions there, to avoid unwanted type conversions by users.6.
AddrFromSlice
should return only one value ❌ (rejected)The
AddrFrom4
andAddrFrom6
functions never fail, and that makes it easy to pass them around with function composition.AddrFromSlice
, however, awkwardly returns anok
value. But, whenok==false
, the returnedAddr
isn't valid anyway. So folks who want to check for validity can just doaddr.IsValid()
like normal, instead of having to learn something new and odd. So, we should drop theok
return value, especially as most users already ignore it.(I'll update this issue if I find anything new.)
CC @bradfitz @crawshaw @josharian @danderson @ianlancetaylor
The text was updated successfully, but these errors were encountered: