Skip to content

Commit

Permalink
Use just stabilized is_unicast_link_local(). Bump MSRV 1.84.0
Browse files Browse the repository at this point in the history
  • Loading branch information
oherrala committed Jan 14, 2025
1 parent f1b8e9c commit 167b7f5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust_matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- stable
- beta
- nightly
- 1.82.0 # MSRV
- 1.84.0 # MSRV

steps:
- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ members = [
[workspace.package]
license = "MIT"
edition = "2021"
rust-version = "1.82.0" # MSRV
rust-version = "1.84.0" # MSRV
16 changes: 4 additions & 12 deletions luomu-common/src/ipaddr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@ pub const fn is_documentation(address: Ipv6Addr) -> bool {
(address.segments()[0] == 0x2001) && (address.segments()[1] == 0x0db8)
}

/// Returns true if the address is a unicast address with link-local scope, as
/// defined in RFC 4291.
// Copied from Rust std/net/ip.rs as not yet in stable
// FIXME: Remove when stable https://github.com/rust-lang/rust/issues/27709
pub const fn is_unicast_link_local(address: Ipv6Addr) -> bool {
(address.segments()[0] & 0xffc0) == 0xfe80
}

/// Is this valid IP source address?
///
/// Mirrors what's specified in
Expand Down Expand Up @@ -156,11 +148,11 @@ pub const fn is_valid_destination_ip6(ip: Ipv6Addr) -> bool {
// We've skipped handling "2001::/23 IETF Protocol Assignments [RFC2928]"
// since it's not valid with a footnote of "Unless allowed by a more
// specific allocation."
!(matches!(ip.segments(), [0, 0, 0, 0, 0, 0, 0, 0])
!(ip.is_unspecified()
|| ip.is_loopback()
|| matches!(ip.segments(), [0, 0, 0, 0, 0, 0xffff, _, _])
|| matches!(ip.segments(), [0x2001, 0xdb8, _, _, _, _, _, _])
|| (ip.segments()[0] == 0x3fff && ip.segments()[1] >> 12 == 0))
|| ((ip.segments()[0] == 0x3fff) && (ip.segments()[1] >> 12 == 0)))
}

/// Is this valid IPv6 forwardable address?
Expand All @@ -178,7 +170,7 @@ pub const fn is_valid_forwardable_ip6(ip: Ipv6Addr) -> bool {

// If the value of "Destination" is FALSE, the values of "Forwardable" and
// "Globally Reachable" must also be false.
!is_valid_destination_ip6(ip) && !(ip.segments()[0] & 0xffc0) == 0xfe80
is_valid_destination_ip6(ip) && !ip.is_unicast_link_local()
}

#[cfg(test)]
Expand Down Expand Up @@ -323,7 +315,7 @@ mod tests {
#[test]
fn test_is_valid_destination_ip4() {
for ip in yield_invalid_destination_ip4() {
assert!(!is_valid_destination_ip4(ip))
assert!(!is_valid_destination_ip4(ip), "invalid ip {ip}");
}
}

Expand Down

0 comments on commit 167b7f5

Please sign in to comment.