proposal: net/netaddr: add new IP address type, netaddr package (discussion) #47323
Replies: 14 comments 42 replies
-
@zephyr suggested |
Beta Was this translation helpful? Give feedback.
-
The API surface proposed is (not including deprecated functions):
It has been tweaked a bit since #46518 was originally proposed as well. Unless this is a "meta-proposal" and there are going to be more detailed proposals for different parts of the API, I think it would help for the proposal to list every single type, function, and method along with doc comments, and also update that list in response to feedback (same as we've been doing for e.g. the slices proposal). |
Beta Was this translation helpful? Give feedback.
-
[Status: change accepted] I think that functions with "bits" parameters should use int rather than uint8:
|
Beta Was this translation helpful? Give feedback.
-
[Status: retracted] I don't think we need |
Beta Was this translation helpful? Give feedback.
-
[Status: change accepted] Instead of |
Beta Was this translation helpful? Give feedback.
-
What's the purpose of |
Beta Was this translation helpful? Give feedback.
-
It's surprising that |
Beta Was this translation helpful? Give feedback.
-
The The proposal says:
"Working together well" seems like a necessary-but-not-sufficient reason for adding something to the standard library. Could you say more about why these types are important to add? Additionally, these types are built on top of the other ones, so it would be easy enough to leave them out initially and add them in later. |
Beta Was this translation helpful? Give feedback.
-
I've pasted the current API from Brad's CL into the top comment on this discussion. If we decide to do (1), then it looks like only IP and IPPort are needed, If we decide to do (2), then the whole set IP, IPPort, IPPrefix, IPRange, IPSet, IPSetBuilder makes some sense. If we do (2), then net/ip or net/netip still seems like a properly scoped name, I suppose there is an alternative (3) a general purpose all-address package, The argument in favor of (1) is that it keeps things small. |
Beta Was this translation helpful? Give feedback.
-
Independent of the answer to the general approach, we have to figure out the terminology to use for the new versus old IP addresses and explain clearly when to use each. The current netaddr package calls them “standard IP addresses” (FromStd) but we are talking about making the new representation “standard” too. I spent a while thinking about alternatives (legacy, old, etc), and I had an aha! moment on “slice”. It's just the slice form of the address. For example:
and in net/netip (assuming we go that way):
This would be instead of FromStdIP and FromStdIPRaw, with the “raw” (no unmapping) semantics. @bradfitz, do you have any numbers on how often code needed FromStdIP and couldn't have used FromStdIPRaw instead? |
Beta Was this translation helpful? Give feedback.
-
To try to move forward, I suggest we answer #47323 by saying (2) a general IP manipulation package, imported as net/netip, and have it contain: type Addr but for now leave out Set and SetBuilder, which can be provided in x/net/ipset or something like that. (With the various adapters in package net to use them, as before.) |
Beta Was this translation helpful? Give feedback.
-
@rsc the current API at the top contains
which should also be dropped. |
Beta Was this translation helpful? Give feedback.
-
Seems like we are getting close. Based on chat with Brad, I made the following changes in the API atop the discussion:
Any remaining objections? |
Beta Was this translation helpful? Give feedback.
-
Not sure if this is the best place for this comment, but I recently used this in my implementation of a security control to prevent server-side request forgery (migrating from this solution). Unfortunately, while doing so I shot myself in the foot by solely using |
Beta Was this translation helpful? Give feedback.
-
This discussion is for capturing more structured discussion of proposal #46518. The current API additions are:
Beta Was this translation helpful? Give feedback.
All reactions