-
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
proposal: net/netip: add netip.Prefix.Range #53236
Comments
When bringing netip into std, there was an explicit decision to leave out the IP address calculation support in netaddr. I think if we want to start adding it, we should consider adding the full suite rather than nickel and diming it. IPRange seems like the perfect fit for this particular use case. See https://pkg.go.dev/inet.af/netaddr#IPPrefix.Range (netaddr might still need some updating for netip; I haven’t kept track of it recently.) |
@josharian I can fully understand that the first reflex is: no feature creep in stdlib! But, if tailscale would rebuild their inet-af/netaddr/IPRange on top of stdlib, they would also depend on certain additional methods from net/netip, if they want to be performant for large IP address input sets. I don't want IPRange and IPSet to be put in the stdlib, I just suggest that the minimum useful methods be included, so that third party libs can build on them without having to implement/copy their own uint128 math module With the already public methods |
This comment was marked as off-topic.
This comment was marked as off-topic.
cc @danderson |
One possible effective implementation would be (file netip.go)
and some tests (file netip_test.go):
|
please see also my bug report for ParsePrefix and 4in6 prefixes with bits < 96 |
If we leave this out of the standard library (which I'm happy to do), what is the suggestion for how people should write this code today? |
This proposal has been added to the active column of the proposals project |
here is a possible implementation without netip.Prefix.Range: Päambel to explain the code for FromPrefix()
BUT, before you decide pro/contra, we should define the API of IP blocks(aka IP Range), maybe other parts would also need access to the underlying 128 bit representation, e.g. It would be preferable if golang would get an IP Range library in the standard lib. |
For now it seems like we should probably err on the side of not adding it. https://pkg.go.dev/inet.af/netaddr#IPPrefix.Range already provides this for now for people who need it. |
Of course I accept your decision, it is your work and time that you would have to invest and with the overall project Go you have done wonderful over the past years with an incredible number of man-years.
Together with the already existing methods |
It seems like what would be needed is a constructor in netaddr to accept a netip.Prefix to make a netaddr.IPPrefix. I think @bradfitz intends to do this in a new netip-aware netaddr package (perhaps with a different import path). |
If you prefer this path, |
Based on the discussion above, this proposal seems like a likely decline. |
If desired and helpful I could also formulate a complete proposal and create a test implementation. |
No change in consensus, so declined. |
for the sake of completeness: after the decline I wrote an extension library for public use with a tiny API,
if you are interested, you find it at https://github.com/gaissmai/extnetip happy coding |
When working with IP addresses and Prefixes (a.k.a CIDRs) often you have to merge and split address ranges. The current implementation hides for good reasons the internal IP address representation, but then it is unnecessary hard to calculate the last address of a prefix. Within the netip package it is very easy to calc the last address of a prefix.
// last = base | ^netmask
And for symmetry, please also add a netip.Prefix.Base method, even if this is already covered with netip.Prefix.Masked().Addr()
The text was updated successfully, but these errors were encountered: