Skip to content

Commit 076f710

Browse files
authored
Unrolled build for rust-lang#119006
Rollup merge of rust-lang#119006 - jstasiak:fix-special-ip-ranges, r=cuviper Fix is_global special address handling IANA explicitly documents 192.0.0.9/32, 192.0.0.9/32 and 2001:30::/28 as globally reachable[1][2] and the is_global implementations declare following IANA so let's make this happen. In case of 2002::/16 IANA says N/A so I think it's safe to say we shouldn't return true from is_global for addresses in that block. [1] https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml [2] https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml
2 parents 0a89233 + 4621357 commit 076f710

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

library/core/src/net/ip_addr.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,11 @@ impl Ipv4Addr {
771771
|| self.is_loopback()
772772
|| self.is_link_local()
773773
// addresses reserved for future protocols (`192.0.0.0/24`)
774-
||(self.octets()[0] == 192 && self.octets()[1] == 0 && self.octets()[2] == 0)
774+
// .9 and .10 are documented as globally reachable so they're excluded
775+
|| (
776+
self.octets()[0] == 192 && self.octets()[1] == 0 && self.octets()[2] == 0
777+
&& self.octets()[3] != 9 && self.octets()[3] != 10
778+
)
775779
|| self.is_documentation()
776780
|| self.is_benchmarking()
777781
|| self.is_reserved()
@@ -1515,8 +1519,12 @@ impl Ipv6Addr {
15151519
// AS112-v6 (`2001:4:112::/48`)
15161520
|| matches!(self.segments(), [0x2001, 4, 0x112, _, _, _, _, _])
15171521
// ORCHIDv2 (`2001:20::/28`)
1518-
|| matches!(self.segments(), [0x2001, b, _, _, _, _, _, _] if b >= 0x20 && b <= 0x2F)
1522+
// Drone Remote ID Protocol Entity Tags (DETs) Prefix (`2001:30::/28`)`
1523+
|| matches!(self.segments(), [0x2001, b, _, _, _, _, _, _] if b >= 0x20 && b <= 0x3F)
15191524
))
1525+
// 6to4 (`2002::/16`) – it's not explicitly documented as globally reachable,
1526+
// IANA says N/A.
1527+
|| matches!(self.segments(), [0x2002, _, _, _, _, _, _, _])
15201528
|| self.is_documentation()
15211529
|| self.is_unique_local()
15221530
|| self.is_unicast_link_local())

library/core/tests/net/ip_addr.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,10 @@ fn ipv4_properties() {
461461
check!("198.18.54.2", benchmarking);
462462
check!("198.19.255.255", benchmarking);
463463
check!("192.0.0.0");
464+
check!("192.0.0.8");
465+
check!("192.0.0.9", global);
466+
check!("192.0.0.10", global);
467+
check!("192.0.0.11");
464468
check!("192.0.0.255");
465469
check!("192.0.0.100");
466470
check!("240.0.0.0", reserved);
@@ -480,6 +484,10 @@ fn ipv6_properties() {
480484
}
481485

482486
macro_rules! check {
487+
($s:expr, &[$($octet:expr),*]) => {
488+
check!($s, &[$($octet),*], 0);
489+
};
490+
483491
($s:expr, &[$($octet:expr),*], $mask:expr) => {
484492
assert_eq!($s, ip!($s).to_string());
485493
let octets = &[$($octet),*];
@@ -656,15 +664,17 @@ fn ipv6_properties() {
656664
&[0x20, 1, 0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
657665
global | unicast_global
658666
);
659-
660-
check!("2001:30::", &[0x20, 1, 0, 0x30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], unicast_global);
667+
check!("2001:30::", &[0x20, 1, 0, 0x30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], global | unicast_global);
668+
check!("2001:40::", &[0x20, 1, 0, 0x40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], unicast_global);
661669

662670
check!(
663671
"2001:200::",
664672
&[0x20, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
665673
global | unicast_global
666674
);
667675

676+
check!("2002::", &[0x20, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], unicast_global);
677+
668678
check!("fc00::", &[0xfc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], unique_local);
669679

670680
check!(

0 commit comments

Comments
 (0)