Skip to content

Commit 8a7db69

Browse files
authored
Rollup merge of #135741 - bardiharborow:std/net/rfc9637, r=Amanieu
Recognise new IPv6 documentation range from IETF RFC 9637 This PR adds the `3fff::/20` range defined by [IETF RFC 9637](https://datatracker.ietf.org/doc/rfc9637/) to those ranges which `Ipv6Addr::is_documentation` recognises as a documentation IP. See also: https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml Unstable tracking issue: #27709
2 parents 0d5b813 + 1f0e35e commit 8a7db69

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

library/core/src/net/ip_addr.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -1539,8 +1539,9 @@ impl Ipv6Addr {
15391539
/// // Addresses reserved for benchmarking (`2001:2::/48`)
15401540
/// assert_eq!(Ipv6Addr::new(0x2001, 2, 0, 0, 0, 0, 0, 1,).is_global(), false);
15411541
///
1542-
/// // Addresses reserved for documentation (`2001:db8::/32`)
1542+
/// // Addresses reserved for documentation (`2001:db8::/32` and `3fff::/20`)
15431543
/// assert_eq!(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1).is_global(), false);
1544+
/// assert_eq!(Ipv6Addr::new(0x3fff, 0, 0, 0, 0, 0, 0, 0).is_global(), false);
15441545
///
15451546
/// // Unique local addresses (`fc00::/7`)
15461547
/// assert_eq!(Ipv6Addr::new(0xfc02, 0, 0, 0, 0, 0, 0, 1).is_global(), false);
@@ -1686,11 +1687,12 @@ impl Ipv6Addr {
16861687
}
16871688

16881689
/// Returns [`true`] if this is an address reserved for documentation
1689-
/// (`2001:db8::/32`).
1690+
/// (`2001:db8::/32` and `3fff::/20`).
16901691
///
1691-
/// This property is defined in [IETF RFC 3849].
1692+
/// This property is defined by [IETF RFC 3849] and [IETF RFC 9637].
16921693
///
16931694
/// [IETF RFC 3849]: https://tools.ietf.org/html/rfc3849
1695+
/// [IETF RFC 9637]: https://tools.ietf.org/html/rfc9637
16941696
///
16951697
/// # Examples
16961698
///
@@ -1701,12 +1703,13 @@ impl Ipv6Addr {
17011703
///
17021704
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_documentation(), false);
17031705
/// assert_eq!(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0).is_documentation(), true);
1706+
/// assert_eq!(Ipv6Addr::new(0x3fff, 0, 0, 0, 0, 0, 0, 0).is_documentation(), true);
17041707
/// ```
17051708
#[unstable(feature = "ip", issue = "27709")]
17061709
#[must_use]
17071710
#[inline]
17081711
pub const fn is_documentation(&self) -> bool {
1709-
(self.segments()[0] == 0x2001) && (self.segments()[1] == 0xdb8)
1712+
matches!(self.segments(), [0x2001, 0xdb8, ..] | [0x3fff, 0..=0x0fff, ..])
17101713
}
17111714

17121715
/// Returns [`true`] if this is an address reserved for benchmarking (`2001:2::/48`).

library/core/tests/net/ip_addr.rs

+10
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ fn ip_properties() {
332332
check!("ff08::", global | multicast);
333333
check!("ff0e::", global | multicast);
334334
check!("2001:db8:85a3::8a2e:370:7334", doc);
335+
check!("3fff:fff:ffff:ffff:ffff:ffff:ffff:ffff", doc);
335336
check!("2001:2::ac32:23ff:21", benchmarking);
336337
check!("102:304:506:708:90a:b0c:d0e:f10", global);
337338
}
@@ -790,6 +791,15 @@ fn ipv6_properties() {
790791
documentation
791792
);
792793

794+
check!(
795+
"3fff:fff:ffff:ffff:ffff:ffff:ffff:ffff",
796+
&[
797+
0x3f, 0xff, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
798+
0xff, 0xff
799+
],
800+
documentation
801+
);
802+
793803
check!(
794804
"2001:2::ac32:23ff:21",
795805
&[0x20, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0xac, 0x32, 0x23, 0xff, 0, 0x21],

0 commit comments

Comments
 (0)