-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add Ipv6Addr::is_ipv4_mapped
#86490
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
Add Ipv6Addr::is_ipv4_mapped
#86490
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -475,27 +475,28 @@ fn ipv6_properties() { | |
assert_eq!(&ip!($s).octets(), octets); | ||
assert_eq!(Ipv6Addr::from(*octets), ip!($s)); | ||
|
||
let unspecified: u16 = 1 << 0; | ||
let loopback: u16 = 1 << 1; | ||
let unique_local: u16 = 1 << 2; | ||
let global: u16 = 1 << 3; | ||
let unicast_link_local: u16 = 1 << 4; | ||
let unicast_global: u16 = 1 << 7; | ||
let documentation: u16 = 1 << 8; | ||
let multicast_interface_local: u16 = 1 << 9; | ||
let multicast_link_local: u16 = 1 << 10; | ||
let multicast_realm_local: u16 = 1 << 11; | ||
let multicast_admin_local: u16 = 1 << 12; | ||
let multicast_site_local: u16 = 1 << 13; | ||
let multicast_organization_local: u16 = 1 << 14; | ||
let multicast_global: u16 = 1 << 15; | ||
let multicast: u16 = multicast_interface_local | ||
let unspecified: u32 = 1 << 0; | ||
let loopback: u32 = 1 << 1; | ||
let unique_local: u32 = 1 << 2; | ||
let global: u32 = 1 << 3; | ||
let unicast_link_local: u32 = 1 << 4; | ||
let unicast_global: u32 = 1 << 7; | ||
let documentation: u32 = 1 << 8; | ||
let multicast_interface_local: u32 = 1 << 9; | ||
let multicast_link_local: u32 = 1 << 10; | ||
let multicast_realm_local: u32 = 1 << 11; | ||
let multicast_admin_local: u32 = 1 << 12; | ||
let multicast_site_local: u32 = 1 << 13; | ||
let multicast_organization_local: u32 = 1 << 14; | ||
let multicast_global: u32 = 1 << 15; | ||
let multicast: u32 = multicast_interface_local | ||
| multicast_admin_local | ||
| multicast_global | ||
| multicast_link_local | ||
| multicast_realm_local | ||
| multicast_site_local | ||
| multicast_organization_local; | ||
let ipv4_mapped = 1 << 17; | ||
|
||
if ($mask & unspecified) == unspecified { | ||
assert!(ip!($s).is_unspecified()); | ||
|
@@ -567,23 +568,29 @@ fn ipv6_properties() { | |
assert_eq!(ip!($s).multicast_scope().unwrap(), | ||
Ipv6MulticastScope::Global); | ||
} | ||
if ($mask & ipv4_mapped) == ipv4_mapped { | ||
assert!(ip!($s).is_ipv4_mapped()); | ||
} else { | ||
assert!(!ip!($s).is_ipv4_mapped()); | ||
} | ||
} | ||
} | ||
|
||
let unspecified: u16 = 1 << 0; | ||
let loopback: u16 = 1 << 1; | ||
let unique_local: u16 = 1 << 2; | ||
let global: u16 = 1 << 3; | ||
let unicast_link_local: u16 = 1 << 4; | ||
let unicast_global: u16 = 1 << 7; | ||
let documentation: u16 = 1 << 8; | ||
let multicast_interface_local: u16 = 1 << 9; | ||
let multicast_link_local: u16 = 1 << 10; | ||
let multicast_realm_local: u16 = 1 << 11; | ||
let multicast_admin_local: u16 = 1 << 12; | ||
let multicast_site_local: u16 = 1 << 13; | ||
let multicast_organization_local: u16 = 1 << 14; | ||
let multicast_global: u16 = 1 << 15; | ||
let unspecified: u32 = 1 << 0; | ||
let loopback: u32 = 1 << 1; | ||
let unique_local: u32 = 1 << 2; | ||
let global: u32 = 1 << 3; | ||
let unicast_link_local: u32 = 1 << 4; | ||
let unicast_global: u32 = 1 << 7; | ||
let documentation: u32 = 1 << 8; | ||
let multicast_interface_local: u32 = 1 << 9; | ||
let multicast_link_local: u32 = 1 << 10; | ||
let multicast_realm_local: u32 = 1 << 11; | ||
let multicast_admin_local: u32 = 1 << 12; | ||
let multicast_site_local: u32 = 1 << 13; | ||
let multicast_organization_local: u32 = 1 << 14; | ||
let multicast_global: u32 = 1 << 15; | ||
let ipv4_mapped: u32 = 1 << 17; | ||
|
||
check!("::", &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], unspecified); | ||
|
||
|
@@ -593,6 +600,12 @@ fn ipv6_properties() { | |
|
||
check!("1::", &[0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], global | unicast_global); | ||
|
||
check!( | ||
"::ffff:127.0.0.1", | ||
&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0x7f, 0, 0, 1], | ||
global | unicast_global | ipv4_mapped | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the IANA IPv6 Special Address Registry IPv4-mapped addresses are not globally reachable. However due to the current simplistic implementation of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The rework of |
||
); | ||
|
||
check!("fc00::", &[0xfc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], unique_local); | ||
|
||
check!( | ||
|
@@ -894,6 +907,9 @@ fn ipv6_const() { | |
const IS_MULTICAST: bool = IP_ADDRESS.is_multicast(); | ||
assert!(!IS_MULTICAST); | ||
|
||
const IS_IPV4_MAPPED: bool = IP_ADDRESS.is_ipv4_mapped(); | ||
assert!(!IS_IPV4_MAPPED); | ||
|
||
const IP_V4: Option<Ipv4Addr> = IP_ADDRESS.to_ipv4(); | ||
assert_eq!(IP_V4.unwrap(), Ipv4Addr::new(0, 0, 0, 1)); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assigned
ipv4_mapped
to1 << 17
, as I already assigned1 << 16
tobenchmarking
in the related PR #86434. (the actual values don't really matter, only that they are distinct)