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

Recognise new IPv6 documentation range from IETF RFC 9637 #135741

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions library/core/src/net/ip_addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1539,8 +1539,9 @@ impl Ipv6Addr {
/// // Addresses reserved for benchmarking (`2001:2::/48`)
/// assert_eq!(Ipv6Addr::new(0x2001, 2, 0, 0, 0, 0, 0, 1,).is_global(), false);
///
/// // Addresses reserved for documentation (`2001:db8::/32`)
/// // Addresses reserved for documentation (`2001:db8::/32` and `3fff::/20`)
/// assert_eq!(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1).is_global(), false);
/// assert_eq!(Ipv6Addr::new(0x3fff, 0, 0, 0, 0, 0, 0, 0).is_global(), false);
///
/// // Unique local addresses (`fc00::/7`)
/// assert_eq!(Ipv6Addr::new(0xfc02, 0, 0, 0, 0, 0, 0, 1).is_global(), false);
Expand Down Expand Up @@ -1686,11 +1687,12 @@ impl Ipv6Addr {
}

/// Returns [`true`] if this is an address reserved for documentation
/// (`2001:db8::/32`).
/// (`2001:db8::/32` and `3fff::/20`).
///
/// This property is defined in [IETF RFC 3849].
/// This property is defined by [IETF RFC 3849] and [IETF RFC 9637].
///
/// [IETF RFC 3849]: https://tools.ietf.org/html/rfc3849
/// [IETF RFC 9637]: https://tools.ietf.org/html/rfc9637
///
/// # Examples
///
Expand All @@ -1701,12 +1703,13 @@ impl Ipv6Addr {
///
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_documentation(), false);
/// assert_eq!(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0).is_documentation(), true);
/// assert_eq!(Ipv6Addr::new(0x3fff, 0, 0, 0, 0, 0, 0, 0).is_documentation(), true);
/// ```
#[unstable(feature = "ip", issue = "27709")]
#[must_use]
#[inline]
pub const fn is_documentation(&self) -> bool {
(self.segments()[0] == 0x2001) && (self.segments()[1] == 0xdb8)
matches!(self.segments(), [0x2001, 0xdb8, ..] | [0x3fff, 0..=0x0fff, ..])
}

/// Returns [`true`] if this is an address reserved for benchmarking (`2001:2::/48`).
Expand Down
10 changes: 10 additions & 0 deletions library/core/tests/net/ip_addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ fn ip_properties() {
check!("ff08::", global | multicast);
check!("ff0e::", global | multicast);
check!("2001:db8:85a3::8a2e:370:7334", doc);
check!("3fff:fff:ffff:ffff:ffff:ffff:ffff:ffff", doc);
check!("2001:2::ac32:23ff:21", benchmarking);
check!("102:304:506:708:90a:b0c:d0e:f10", global);
}
Expand Down Expand Up @@ -790,6 +791,15 @@ fn ipv6_properties() {
documentation
);

check!(
"3fff:fff:ffff:ffff:ffff:ffff:ffff:ffff",
&[
0x3f, 0xff, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff
],
documentation
);

check!(
"2001:2::ac32:23ff:21",
&[0x20, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0xac, 0x32, 0x23, 0xff, 0, 0x21],
Expand Down
Loading