diff --git a/tools/ipcheck/README.md b/tools/ipcheck/README.md index 694760a..b0df59d 100644 --- a/tools/ipcheck/README.md +++ b/tools/ipcheck/README.md @@ -1,6 +1,7 @@ # IP Check -Created for https://github.com/rust-lang/rust/pull/76098 +Originally created for https://github.com/rust-lang/rust/pull/76098, the tool now tests +the *current* implementation of various helper methods against other programming languages. This is a little utility program for checking the behavior of various language's IP address implementations. The goal is to make sure the Rust programs are either the same or deliberately different to other languages. @@ -11,13 +12,15 @@ This same approach might be useful for other APIs that have externally specified These live under the `impls` directory. -- Rust (New) (`impls/rust`) with the behavior proposed in `#76098` - Rust (Current) (`impls/rust_current`) with the current behavior on `nightly` - .NET (`impls/dotnet`) - Python (`impls/python`) - Go (`impls/go`) - Java (`impls/java`) +There was a Rust implementation with behavior proposed in `#76098` ("Rust (New)") +but the PR didn't go through so the implementation has been removed. + ## Running With the comparison languages available, you can run `cd host && cargo run` to compare them. diff --git a/tools/ipcheck/host/build/build.rs b/tools/ipcheck/host/build/build.rs index 7eaa52a..5b8094b 100644 --- a/tools/ipcheck/host/build/build.rs +++ b/tools/ipcheck/host/build/build.rs @@ -12,8 +12,7 @@ fn main() { let mut impls = std::fs::File::create("../artifacts/.impls").expect("failed to create .impls file"); - output_impl(&mut impls, "Rust (New)", rust::build_new()); - output_impl(&mut impls, "Rust (Current)", rust::build_current()); + output_impl(&mut impls, "Rust", rust::build_current()); output_impl(&mut impls, ".NET", dotnet::build()); output_impl(&mut impls, "Python", python::build()); output_impl(&mut impls, "Go", go::build()); diff --git a/tools/ipcheck/host/build/rust.rs b/tools/ipcheck/host/build/rust.rs index 70117ad..0de0aa2 100644 --- a/tools/ipcheck/host/build/rust.rs +++ b/tools/ipcheck/host/build/rust.rs @@ -1,9 +1,5 @@ use std::path::Path; -pub fn build_new() -> std::io::Result { - build_bin("../impls/rust_new", "../artifacts/rust_new", "ipcheck_new") -} - pub fn build_current() -> std::io::Result { build_bin( "../impls/rust_current", diff --git a/tools/ipcheck/host/main.rs b/tools/ipcheck/host/main.rs index 966379c..c31f5cc 100644 --- a/tools/ipcheck/host/main.rs +++ b/tools/ipcheck/host/main.rs @@ -1,7 +1,7 @@ use serde_json::{Map, Value}; use std::{collections::BTreeSet, fmt::Write, io::BufRead, net::IpAddr}; -const REF_LANG: &'static str = "Rust (New)"; +const REF_LANG: &'static str = "Rust"; fn is_ref(lang: &str) -> bool { lang.starts_with("Rust") diff --git a/tools/ipcheck/impls/README.md b/tools/ipcheck/impls/README.md index bb024b1..6a0defe 100644 --- a/tools/ipcheck/impls/README.md +++ b/tools/ipcheck/impls/README.md @@ -1,9 +1,8 @@ Programs that accept as input a ASCII-encoded IP address to parse and run operations on. As output, these programs produce a JSON object. ## Implementations - - Rust (`rust_*`) (with the behavior specified in https://github.com/rust-lang/rust/pull/76098 as `rust_new`) + - Rust (`rust`) - .NET (`dotnet`) - Python (`python`) - Go (`go`) - Java (`java`) - \ No newline at end of file diff --git a/tools/ipcheck/impls/rust_new/.gitignore b/tools/ipcheck/impls/rust_new/.gitignore deleted file mode 100644 index fa8d85a..0000000 --- a/tools/ipcheck/impls/rust_new/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -Cargo.lock -target diff --git a/tools/ipcheck/impls/rust_new/Cargo.toml b/tools/ipcheck/impls/rust_new/Cargo.toml deleted file mode 100644 index 0e3604e..0000000 --- a/tools/ipcheck/impls/rust_new/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "ipcheck_new" -version = "0.0.0" -authors = ["Ashley Mannix ", "Christiaan Dirkx "] -publish = false -edition = "2018" - -[[bin]] -name = "ipcheck_new" -path = "main.rs" - -[dependencies.serde_json] -version = "1" diff --git a/tools/ipcheck/impls/rust_new/main.rs b/tools/ipcheck/impls/rust_new/main.rs deleted file mode 100644 index 12b7917..0000000 --- a/tools/ipcheck/impls/rust_new/main.rs +++ /dev/null @@ -1,138 +0,0 @@ -#![feature(ip)] - -use serde_json::json; -use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, Ipv6MulticastScope}; - -fn main() { - let input = std::env::args() - .skip(1) - .next() - .expect("missing input argument"); - let addr: IpAddr = input.parse().expect("failed to parse IP"); - - let data = json!({ - "to_ipv4": match addr { - IpAddr::V4(addr) => json!(addr.to_string()), - IpAddr::V6(addr) => json!(to_ipv4_new(&addr).map(|addr| addr.to_string())), - }, - "to_ipv6": match addr { - IpAddr::V4(addr) => addr.to_ipv6_mapped().to_string(), - IpAddr::V6(addr) => addr.to_string(), - }, - "is_unspecified": addr.is_unspecified(), - "is_loopback": match addr { - IpAddr::V4(addr) => addr.is_loopback(), - // ipv6 Behavior changed (already stable) - IpAddr::V6(addr) => - u128::from_be_bytes(addr.octets()) == u128::from_be_bytes(Ipv6Addr::LOCALHOST.octets()) || - if let Some(v4_addr) = to_ipv4_new(&addr) { v4_addr.is_loopback() } else { false }, - }, - "is_documentation": match addr { - IpAddr::V4(addr) => addr.is_documentation(), - // ipv6 Behavior changed (already stable) - IpAddr::V6(addr) => - ((addr.segments()[0] == 0x2001) && (addr.segments()[1] == 0xdb8)) || - if let Some(v4_addr) = to_ipv4_new(&addr) { v4_addr.is_documentation() } else { false } - }, - "is_shared": match addr { - IpAddr::V4(addr) => addr.is_shared(), - IpAddr::V6(_) => false, - }, - "is_reserved": match addr { - IpAddr::V4(addr) => addr.is_reserved(), - IpAddr::V6(_) => false, - }, - "is_benchmarking": match addr { - IpAddr::V4(addr) => addr.is_benchmarking(), - IpAddr::V6(_) => false, - }, - "is_global": match addr { - IpAddr::V4(addr) => addr.is_global(), - // ipv6 Behavior changed - IpAddr::V6(addr) => - (match addr.multicast_scope() { - Some(Ipv6MulticastScope::Global) => true, - None => addr.is_unicast_global(), - _ => false, - }) || - if let Some(v4_addr) = to_ipv4_new(&addr) { v4_addr.is_global() } else { false }, - }, - "is_unicast_link_local": match addr { - IpAddr::V4(addr) => addr.is_link_local(), - // ipv6 Behavior changed - IpAddr::V6(addr) => - (addr.segments()[0] & 0xffc0) == 0xfe80 || - if let Some(v4_addr) = to_ipv4_new(&addr) { v4_addr.is_link_local() } else { false }, - }, - "is_unspecified": match addr { - IpAddr::V4(addr) => addr.is_unspecified(), - // ipv6 Behavior changed (already stable) - IpAddr::V6(addr) => - u128::from_be_bytes(addr.octets()) == u128::from_be_bytes(Ipv6Addr::UNSPECIFIED.octets()) || - if let Some(v4_addr) = to_ipv4_new(&addr) { v4_addr.is_unspecified() } else { false }, - }, - "is_unique_local": match addr { - IpAddr::V4(_) => false, - IpAddr::V6(addr) => addr.is_unique_local(), - }, - "mc_scope_iface_local": match addr { - IpAddr::V4(_) => false, - IpAddr::V6(addr) => addr.multicast_scope() == Some(Ipv6MulticastScope::InterfaceLocal), - }, - "mc_scope_link_local": match addr { - IpAddr::V4(_) => false, - IpAddr::V6(addr) => addr.multicast_scope() == Some(Ipv6MulticastScope::LinkLocal), - }, - "mc_scope_realm_local": match addr { - IpAddr::V4(_) => false, - IpAddr::V6(addr) => addr.multicast_scope() == Some(Ipv6MulticastScope::RealmLocal), - }, - "mc_scope_admin_local": match addr { - IpAddr::V4(_) => false, - IpAddr::V6(addr) => addr.multicast_scope() == Some(Ipv6MulticastScope::AdminLocal), - }, - "mc_scope_org_local": match addr { - IpAddr::V4(_) => false, - IpAddr::V6(addr) => addr.multicast_scope() == Some(Ipv6MulticastScope::OrganizationLocal), - }, - "mc_scope_global": match addr { - IpAddr::V4(_) => false, - IpAddr::V6(addr) => addr.multicast_scope() == Some(Ipv6MulticastScope::Global), - }, - "mc_scope_reserved": match addr { - IpAddr::V4(_) => false, - // ipv6 New behavior - IpAddr::V6(addr) => if addr.is_multicast() { - match addr.segments()[0] & 0x000f { - 0 | 15 => true, - _ => false, - } - } else { - false - }, - }, - "mc_scope_unassigned": match addr { - IpAddr::V4(_) => false, - // ipv6 New behavior - IpAddr::V6(addr) => if addr.is_multicast() { - match addr.segments()[0] & 0x000f { - 0 | 15 | 1 | 2 | 3 | 4 | 5 | 8 | 14 => false, - _ => true, - } - } else { - false - }, - }, - }); - - fn to_ipv4_new(addr: &Ipv6Addr) -> Option { - match addr.octets() { - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, a, b, c, d] => { - Some(Ipv4Addr::new(a, b, c, d)) - } - _ => None, - } - } - - println!("{}", data); -}