diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2021-08-02 11:03:19 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-02 11:03:19 +0900 |
| commit | a03d6da3ef7852cbcfcf98b7639b529b96587ca3 (patch) | |
| tree | 07b433868914e1d64e897429fafc0120b90c9972 | |
| parent | 016612dc8d9ed850a066bccd42e4d6f7816f0484 (diff) | |
| parent | a26237e634be7f94dbd40cc1204514f2b4c380d2 (diff) | |
| download | rust-a03d6da3ef7852cbcfcf98b7639b529b96587ca3.tar.gz rust-a03d6da3ef7852cbcfcf98b7639b529b96587ca3.zip | |
Rollup merge of #86439 - CDirkx:ip-protocol-assignment, r=m-ou-se
Remove `Ipv4Addr::is_ietf_protocol_assignment` This PR removes the unstable method `Ipv4Addr::is_ietf_protocol_assignment`, as I suggested in https://github.com/rust-lang/rust/issues/85612#issuecomment-847863404. The method was added in #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.
| -rw-r--r-- | library/std/src/net/ip.rs | 40 | ||||
| -rw-r--r-- | library/std/src/net/ip/tests.rs | 17 |
2 files changed, 6 insertions, 51 deletions
diff --git a/library/std/src/net/ip.rs b/library/std/src/net/ip.rs index 88309875978..929286a343b 100644 --- a/library/std/src/net/ip.rs +++ b/library/std/src/net/ip.rs @@ -486,8 +486,7 @@ impl Ipv4Addr { /// - addresses used for documentation (see [`Ipv4Addr::is_documentation()`]) /// - the unspecified address (see [`Ipv4Addr::is_unspecified()`]), and the whole /// `0.0.0.0/8` block - /// - addresses reserved for future protocols (see - /// [`Ipv4Addr::is_ietf_protocol_assignment()`], except + /// - addresses reserved for future protocols, except /// `192.0.0.9/32` and `192.0.0.10/32` which are globally routable /// - addresses reserved for future use (see [`Ipv4Addr::is_reserved()`] /// - addresses reserved for networking devices benchmarking (see @@ -560,7 +559,8 @@ impl Ipv4Addr { && !self.is_broadcast() && !self.is_documentation() && !self.is_shared() - && !self.is_ietf_protocol_assignment() + // addresses reserved for future protocols (`192.0.0.0/24`) + && !(self.octets()[0] == 192 && self.octets()[1] == 0 && self.octets()[2] == 0) && !self.is_reserved() && !self.is_benchmarking() // Make sure the address is not in 0.0.0.0/8 @@ -589,40 +589,6 @@ impl Ipv4Addr { self.octets()[0] == 100 && (self.octets()[1] & 0b1100_0000 == 0b0100_0000) } - /// Returns [`true`] if this address is part of `192.0.0.0/24`, which is reserved to - /// IANA for IETF protocol assignments, as documented in [IETF RFC 6890]. - /// - /// Note that parts of this block are in use: - /// - /// - `192.0.0.8/32` is the "IPv4 dummy address" (see [IETF RFC 7600]) - /// - `192.0.0.9/32` is the "Port Control Protocol Anycast" (see [IETF RFC 7723]) - /// - `192.0.0.10/32` is used for NAT traversal (see [IETF RFC 8155]) - /// - /// [IETF RFC 6890]: https://tools.ietf.org/html/rfc6890 - /// [IETF RFC 7600]: https://tools.ietf.org/html/rfc7600 - /// [IETF RFC 7723]: https://tools.ietf.org/html/rfc7723 - /// [IETF RFC 8155]: https://tools.ietf.org/html/rfc8155 - /// - /// # Examples - /// - /// ``` - /// #![feature(ip)] - /// use std::net::Ipv4Addr; - /// - /// assert_eq!(Ipv4Addr::new(192, 0, 0, 0).is_ietf_protocol_assignment(), true); - /// assert_eq!(Ipv4Addr::new(192, 0, 0, 8).is_ietf_protocol_assignment(), true); - /// assert_eq!(Ipv4Addr::new(192, 0, 0, 9).is_ietf_protocol_assignment(), true); - /// assert_eq!(Ipv4Addr::new(192, 0, 0, 255).is_ietf_protocol_assignment(), true); - /// assert_eq!(Ipv4Addr::new(192, 0, 1, 0).is_ietf_protocol_assignment(), false); - /// assert_eq!(Ipv4Addr::new(191, 255, 255, 255).is_ietf_protocol_assignment(), false); - /// ``` - #[rustc_const_unstable(feature = "const_ipv4", issue = "76205")] - #[unstable(feature = "ip", issue = "27709")] - #[inline] - pub const fn is_ietf_protocol_assignment(&self) -> bool { - self.octets()[0] == 192 && self.octets()[1] == 0 && self.octets()[2] == 0 - } - /// Returns [`true`] if this address part of the `198.18.0.0/15` range, which is reserved for /// network devices benchmarking. This range is defined in [IETF RFC 2544] as `192.18.0.0` /// through `198.19.255.255` but [errata 423] corrects it to `198.18.0.0/15`. diff --git a/library/std/src/net/ip/tests.rs b/library/std/src/net/ip/tests.rs index 2109980ad05..dbfab9dde40 100644 --- a/library/std/src/net/ip/tests.rs +++ b/library/std/src/net/ip/tests.rs @@ -339,7 +339,6 @@ fn ipv4_properties() { let broadcast: u16 = 1 << 6; let documentation: u16 = 1 << 7; let benchmarking: u16 = 1 << 8; - let ietf_protocol_assignment: u16 = 1 << 9; let reserved: u16 = 1 << 10; let shared: u16 = 1 << 11; @@ -397,12 +396,6 @@ fn ipv4_properties() { assert!(!ip!($s).is_benchmarking()); } - if ($mask & ietf_protocol_assignment) == ietf_protocol_assignment { - assert!(ip!($s).is_ietf_protocol_assignment()); - } else { - assert!(!ip!($s).is_ietf_protocol_assignment()); - } - if ($mask & reserved) == reserved { assert!(ip!($s).is_reserved()); } else { @@ -426,7 +419,6 @@ fn ipv4_properties() { let broadcast: u16 = 1 << 6; let documentation: u16 = 1 << 7; let benchmarking: u16 = 1 << 8; - let ietf_protocol_assignment: u16 = 1 << 9; let reserved: u16 = 1 << 10; let shared: u16 = 1 << 11; @@ -449,9 +441,9 @@ fn ipv4_properties() { check!("198.18.0.0", benchmarking); check!("198.18.54.2", benchmarking); check!("198.19.255.255", benchmarking); - check!("192.0.0.0", ietf_protocol_assignment); - check!("192.0.0.255", ietf_protocol_assignment); - check!("192.0.0.100", ietf_protocol_assignment); + check!("192.0.0.0"); + check!("192.0.0.255"); + check!("192.0.0.100"); check!("240.0.0.0", reserved); check!("251.54.1.76", reserved); check!("254.255.255.255", reserved); @@ -823,9 +815,6 @@ fn ipv4_const() { const IS_SHARED: bool = IP_ADDRESS.is_shared(); assert!(!IS_SHARED); - const IS_IETF_PROTOCOL_ASSIGNMENT: bool = IP_ADDRESS.is_ietf_protocol_assignment(); - assert!(!IS_IETF_PROTOCOL_ASSIGNMENT); - const IS_BENCHMARKING: bool = IP_ADDRESS.is_benchmarking(); assert!(!IS_BENCHMARKING); |
