Skip to content
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

IP Utility Methods #85612

Open
CDirkx opened this issue May 23, 2021 · 4 comments
Open

IP Utility Methods #85612

CDirkx opened this issue May 23, 2021 · 4 comments
Labels
A-io Area: `std::io`, `std::fs`, `std::net` and `std::path` T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@CDirkx
Copy link
Contributor

CDirkx commented May 23, 2021

This issue is split out of the larger discussion around stabilization of the ip feature (tracking issue: #27709). The focus of this issue is on the question of what utility methods Rust should provide for handling IPv4 and IPv6 addresses.

For discussion about the conversion methods (to_ipv6_mapped, to_ipv6_compatible, to_ipv4, to_ipv4_mapped) see #85609 IPv4-in-IPv6 Address Support.

For discussion about the IPv6 unicast methods (is_unicast_link_local, is_unicast_link_local_strict, is_unicast_site_local, is_unicast_global) see #85604 IPv6 Unicast Interface.

Specifically this issue concerns itself with the various special address utility methods:

impl Ipv4Addr {
    #[unstable]
    fn is_benchmarking(&self) -> bool;
    fn is_documentation(&self) -> bool;
    #[unstable]
    fn is_ietf_protocol_assignment(&self) -> bool;
    #[unstable]
    fn is_global(&self) -> bool;
    fn is_private(&self) -> bool;
    #[unstable]
    fn is_reserved(&self) -> bool;
    #[unstable]
    fn is_shared(&self) -> bool;
}

impl Ipv6Addr {
    #[unstable]
    fn is_documentation(&self) -> bool;
    #[unstable]
    fn is_global(&self) -> bool;
}

All of these excluding is_global currently correspond to various special addresses in the IANA IPv4 Special-Purpose Address Registry and IANA IPv6 Special-Purpose Address Registry.

Note that of these only Ipv4Addr::is_documentation and is_private are currently stable.

Open Problems

Semantics of utility methods

What should the exact semantics of is_global be? The current documentation of Ipv4Addr::is_global mentions the IANA IPv4 Special-Purpose Address Registry and follows it exactly, Ipv6Addr::is_global does not (#76098 (comment)). For IPv6 specifically, should IPv4-mapped addresses be considered global? Python does not (#76098 (comment)). Is there an official definition for which addresses are globally reachable? What would be the least surprising to users.

There is a similar question for all the other methods: should we strictly adhere to standards and the address registry, or for IPv6 addresses also consider IPv4-mapped addresses. Is it a problem if the IPv4 version and IPv6 version of a method have different definitions?

Unresolved: Settle on the exact semantics of is_global and other methods. See also #85609 IPv4-in-IPv6 Address Support.

Which utility methods are useful

Which utility methods do we want to offer? Maybe offer the equivalent of is_reserved, is_benchmarking etc. for Ipv6Addr as well? Maybe not expose is_ietf_protocol_assignment (what would be a real-world use case for this other than computing is_global?) A lot of these methods are not offered by other languages, but .NET does have IsIPv6Teredo. is_ipv4_mapped and maybe is_ipv4_compatible could also be useful.

Unresolved: Which utility methods should be stabilized. How do we determine if a method is useful enough to be added.

Methods on both Ipv4Addr and Ipv6Addr

If methods like is_documentation and is_benchmarking are added to both Ipv4Addr and Ipv6Addr they can also be implemented for IpAddr. Does this make sense semantically? Is the definition of Ipv4Addr::is_documentation equivalent to Ipv6Addr::documentation? Does a user ever needs to check in practice if they have an IPv4 documentation address or an IPv6 documentation address? It has been suggested that for these common methods on IpAddr, Ipv4Addr and Ipv6Addr there could be a trait.

Unresolved: Which utility methods should be implemented for IpAddr.

Previous Discussion

@the8472
Copy link
Member

the8472 commented May 24, 2021

Is there an official definition for which addresses are globally reachable?

Yes and no. The spec defines global unicast as the complement of all the other special-purpose ranges. With a strong emphasis on "subject to change". And of course that covers pretty much everything, including ranges that won't be allocated for a very long time. So this is fundamentally different from the way IPv4 categories are defined.

https://datatracker.ietf.org/doc/html/rfc4291#section-2.4

@CDirkx
Copy link
Contributor Author

CDirkx commented May 25, 2021

I propose removing (or making private) the utility function Ipv4Addr::is_ietf_protocol_assignment and not adding a (public) equivalent Ipv6Addr::is_ietf_protocol_assignment. The method was introduced in #60145 along with other methods to be used in making is_global more accurate, however it can still be used for this purpose as a private function.

To me it is not clear what practical use of is_ietf_protocol_assignment is; I can't think of anything that a user might want to do with the knowledge that a certain address is reserved for IETF protocol assignment, outside of computing more useful properties like is_global or is is_special_use. It has been more than 2 years ago that this function was added, but I couldn't find any real usage in the wild: 1 2.

To me all of this suggest that is_ietf_protocol_assignment is not a good candidate for stabilization.

Edit: PR #86439 submitted

@CDirkx
Copy link
Contributor Author

CDirkx commented Jun 25, 2021

Regarding is_global: In the current implementation there is a conflation between the concepts of globally reachable, and having global scope. To address this I submitted #85696 to rework is_unicast_global and #86634 to rework is_global.

JohnTitor added a commit to JohnTitor/rust that referenced this issue Aug 2, 2021
…ou-se

Remove `Ipv4Addr::is_ietf_protocol_assignment`

This PR removes the unstable method `Ipv4Addr::is_ietf_protocol_assignment`, as I suggested in rust-lang#85612 (comment). The method was added in rust-lang#60145, as far as I can tell primarily for the implementation of `Ipv4Addr::is_global` (addresses reserved for IETF protocol assignment are not globally reachable unless otherwise specified).

The method was added in 2019, but I haven't been able to find any open-source code using this method so far. I'm also having a hard time coming up with a usecase for specifically this method; knowing that an address is reserved for future protocols doesn't allow you to do much with it, especially since now some of those addresses are indeed assigned to a protocol and have their own behaviour (and might even be defined to be globally reachable, so if that is what you care about it is always more accurate to call `!is_global()`, instead of `is_ietf_protocol_assignment()`).

Because of these reasons, I propose removing the method (or alternatively make it a private helper for `is_global`) and also not introduce `Ipv6Addr::is_ietf_protocol_assignment` and `IpAddr::is_ietf_protocol_assignment` in the future.
@clubby789
Copy link
Contributor

@rustbot label +T-libs

@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Mar 30, 2023
@Enselic Enselic added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. A-io Area: `std::io`, `std::fs`, `std::net` and `std::path` and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-io Area: `std::io`, `std::fs`, `std::net` and `std::path` T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants