Remove Ipv4Addr::is_ietf_protocol_assignment

This commit is contained in:
Christiaan Dirkx 2021-06-18 18:02:56 +02:00
parent d192c80d22
commit a26237e634
2 changed files with 6 additions and 51 deletions

View File

@ -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`.

View File

@ -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);