diff --git a/common/s2n-codec/Cargo.toml b/common/s2n-codec/Cargo.toml index 085b9c99ab..f9d78e5001 100644 --- a/common/s2n-codec/Cargo.toml +++ b/common/s2n-codec/Cargo.toml @@ -31,3 +31,9 @@ bolero-generator = "0.11" [package.metadata.kani] flags = { tests = true } unstable = { stubbing = true } + +[lints.rust.unexpected_cfgs] +level = "warn" +check-cfg = [ + 'cfg(kani)', +] diff --git a/common/s2n-codec/src/lib.rs b/common/s2n-codec/src/lib.rs index ae7c6723ce..a00265e8e5 100644 --- a/common/s2n-codec/src/lib.rs +++ b/common/s2n-codec/src/lib.rs @@ -1,7 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -#![allow(unexpected_cfgs)] #![cfg_attr(not(any(test, feature = "std")), no_std)] #[cfg(feature = "alloc")] diff --git a/dc/s2n-quic-dc/Cargo.toml b/dc/s2n-quic-dc/Cargo.toml index 3538b82d41..fea7c9a014 100644 --- a/dc/s2n-quic-dc/Cargo.toml +++ b/dc/s2n-quic-dc/Cargo.toml @@ -49,3 +49,9 @@ insta = "1" s2n-codec = { path = "../../common/s2n-codec", features = ["testing"] } s2n-quic-core = { path = "../../quic/s2n-quic-core", features = ["testing"] } tokio = { version = "1", features = ["full"] } + +[lints.rust.unexpected_cfgs] +level = "warn" +check-cfg = [ + 'cfg(kani)', +] diff --git a/dc/s2n-quic-dc/benches/Cargo.toml b/dc/s2n-quic-dc/benches/Cargo.toml index 401518e8e6..bdef01d857 100644 --- a/dc/s2n-quic-dc/benches/Cargo.toml +++ b/dc/s2n-quic-dc/benches/Cargo.toml @@ -6,7 +6,7 @@ publish = false [dependencies] aws-lc-rs = "1" -criterion = { version = "0.4", features = ["html_reports"] } +criterion = { version = "0.5", features = ["html_reports"] } s2n-codec = { path = "../../../common/s2n-codec" } s2n-quic-dc = { path = "../../s2n-quic-dc", features = ["testing"] } diff --git a/dc/s2n-quic-dc/src/lib.rs b/dc/s2n-quic-dc/src/lib.rs index a016a68983..98b5e5ad95 100644 --- a/dc/s2n-quic-dc/src/lib.rs +++ b/dc/s2n-quic-dc/src/lib.rs @@ -1,8 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -#![allow(unexpected_cfgs)] - pub mod allocator; pub mod clock; pub mod congestion; diff --git a/quic/s2n-quic-bench/Cargo.toml b/quic/s2n-quic-bench/Cargo.toml index f89d03705c..d86be94703 100644 --- a/quic/s2n-quic-bench/Cargo.toml +++ b/quic/s2n-quic-bench/Cargo.toml @@ -10,7 +10,7 @@ publish = false [dependencies] bytes = "1" -criterion = { version = "0.4", features = ["html_reports"] } +criterion = { version = "0.5", features = ["html_reports"] } crossbeam-channel = { version = "0.5" } internet-checksum = "0.2" s2n-codec = { path = "../../common/s2n-codec", features = ["testing"] } diff --git a/quic/s2n-quic-core/Cargo.toml b/quic/s2n-quic-core/Cargo.toml index 2059543913..af191f62aa 100644 --- a/quic/s2n-quic-core/Cargo.toml +++ b/quic/s2n-quic-core/Cargo.toml @@ -64,3 +64,14 @@ loom = { version = "0.7", features = ["checkpoint", "futures"] } [package.metadata.kani] flags = { tests = true } unstable = { stubbing = true } + +[lints.rust.unexpected_cfgs] +level = "warn" +check-cfg = [ + 'cfg(feature, values("thiserror"))', + 'cfg(fuzzing)', + 'cfg(loom)', + 'cfg(kani)', + 'cfg(kani_slow)', + 'cfg(target_pointer_width, values("8", "128"))', +] diff --git a/quic/s2n-quic-core/src/lib.rs b/quic/s2n-quic-core/src/lib.rs index e8a6297cac..c0f811aa97 100644 --- a/quic/s2n-quic-core/src/lib.rs +++ b/quic/s2n-quic-core/src/lib.rs @@ -1,7 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -#![allow(unexpected_cfgs)] #![cfg_attr(not(any(test, feature = "std")), no_std)] #[cfg(feature = "alloc")] diff --git a/quic/s2n-quic-platform/Cargo.toml b/quic/s2n-quic-platform/Cargo.toml index b37c276a94..4a9c463549 100644 --- a/quic/s2n-quic-platform/Cargo.toml +++ b/quic/s2n-quic-platform/Cargo.toml @@ -48,3 +48,20 @@ tracing = { version = "0.1" } [package.metadata.kani] flags = { tests = true } unstable = { stubbing = true } + +# Remove once MSRV is 1.80.0, see https://github.com/aws/s2n-quic/issues/2334 +[lints.rust.unexpected_cfgs] +level = "warn" +check-cfg = [ + 'cfg(fuzz)', + 'cfg(kani)', + 'cfg(kani_slow)', + 'cfg(s2n_quic_platform_cmsg)', + 'cfg(s2n_quic_platform_socket_msg)', + 'cfg(s2n_quic_platform_socket_mmsg)', + 'cfg(s2n_quic_platform_mtu_disc)', + 'cfg(s2n_quic_platform_gso)', + 'cfg(s2n_quic_platform_gro)', + 'cfg(s2n_quic_platform_pktinfo)', + 'cfg(s2n_quic_platform_tos)', +] diff --git a/quic/s2n-quic-platform/build.rs b/quic/s2n-quic-platform/build.rs index 0da5fb1a46..882a970b46 100644 --- a/quic/s2n-quic-platform/build.rs +++ b/quic/s2n-quic-platform/build.rs @@ -1,8 +1,59 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +use crate::Feature::*; use std::{fs::read_dir, io::Error, path::Path, process::Command}; +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] +enum Feature { + ControlMessage, + SocketMessage, + SocketMultiMessage, + MtuDiscovery, + GenericSegmentationOffload, + GenericReceiveOffload, + PacketInfo, + TypeOfService, +} + +impl Feature { + fn name(&self) -> &str { + match self { + ControlMessage => "cmsg", + SocketMessage => "socket_msg", + SocketMultiMessage => "socket_mmsg", + MtuDiscovery => "mtu_disc", + GenericSegmentationOffload => "gso", + GenericReceiveOffload => "gro", + PacketInfo => "pktinfo", + TypeOfService => "tos", + } + } +} + +impl From<&str> for Feature { + fn from(value: &str) -> Self { + for feature in ALL_FEATURES { + if feature.name() == value { + return feature; + } + } + + panic!("unsupported feature: {value}"); + } +} + +const ALL_FEATURES: [Feature; 8] = [ + ControlMessage, + SocketMessage, + SocketMultiMessage, + MtuDiscovery, + GenericSegmentationOffload, + GenericReceiveOffload, + PacketInfo, + TypeOfService, +]; + fn main() -> Result<(), Error> { let mut features = Features::default(); @@ -10,8 +61,8 @@ fn main() -> Result<(), Error> { if let Some(list) = option_env("S2N_QUIC_PLATFORM_FEATURES_OVERRIDE") { // iterate twice in case there is dependence on another feature that comes later for _ in 0..2 { - for feature in list.split(',') { - features.insert(feature.trim()); + for feature in list.split(',').filter(|&s| !s.is_empty()) { + features.insert(feature.trim().into()); } } return Ok(()); @@ -24,7 +75,7 @@ fn main() -> Result<(), Error> { if let Some(name) = path.file_stem() { println!("cargo:rerun-if-changed={}", path.display()); if env.check(&path)? { - features.insert(name.to_str().expect("valid feature name")); + features.insert(name.to_str().expect("valid feature name").into()); } } } @@ -35,63 +86,78 @@ fn main() -> Result<(), Error> { "linux" => { // miri doesn't support the way we detect syscall support so override it if is_miri { - features.insert("socket_msg"); - features.insert("socket_mmsg"); + features.insert(SocketMessage); + features.insert(SocketMultiMessage); } - features.insert("mtu_disc"); - features.insert("gso"); - features.insert("gro"); - features.insert("pktinfo"); - features.insert("tos"); + features.insert(MtuDiscovery); + features.insert(GenericSegmentationOffload); + features.insert(GenericReceiveOffload); + features.insert(PacketInfo); + features.insert(TypeOfService); } "macos" => { // miri doesn't support the way we detect syscall support so override it if is_miri { - features.insert("socket_msg"); + features.insert(SocketMessage); } - features.insert("pktinfo"); - features.insert("tos"); + features.insert(PacketInfo); + features.insert(TypeOfService); } "android" => { - features.insert("mtu_disc"); - features.insert("pktinfo"); - features.insert("tos"); + features.insert(MtuDiscovery); + features.insert(PacketInfo); + features.insert(TypeOfService); } _ => { // TODO others } } + // TODO: Uncomment once MSRV is 1.80.0, see https://github.com/aws/s2n-quic/issues/2334 + // for name in ALL_FEATURES.iter().map(|f| f.name()) { + // println!("cargo::rustc-check-cfg=cfg(s2n_quic_platform_{name})"); + // } + // + // println!("cargo::rustc-check-cfg=cfg(fuzz, kani, kani_slow)"); + Ok(()) } #[derive(Debug, Default)] struct Features { - features: std::collections::HashSet, + features: std::collections::HashSet, } impl Features { - fn insert(&mut self, name: &str) { + fn insert(&mut self, feature: Feature) { // supporting any kind message implies cmsg support - if name == "socket_msg" || name == "socket_mmsg" { - self.insert("cmsg"); + if matches!(feature, SocketMessage | SocketMultiMessage) { + self.insert(ControlMessage); } // the following features only make sense if cmsg is supported - if ["gso", "gro", "pktinfo", "tos"].contains(&name) && !self.supports("cmsg") { + if [ + GenericSegmentationOffload, + GenericReceiveOffload, + PacketInfo, + TypeOfService, + ] + .contains(&feature) + && !self.supports(ControlMessage) + { return; } - let newly_inserted = self.features.insert(name.to_string()); + let newly_inserted = self.features.insert(feature); if newly_inserted { - println!("cargo:rustc-cfg=s2n_quic_platform_{name}"); + println!("cargo:rustc-cfg=s2n_quic_platform_{}", feature.name()); } } - fn supports(&self, name: &str) -> bool { - self.features.contains(name) + fn supports(&self, feature: Feature) -> bool { + self.features.contains(&feature) } } diff --git a/quic/s2n-quic-platform/src/lib.rs b/quic/s2n-quic-platform/src/lib.rs index 88e414473e..8f1ca70464 100644 --- a/quic/s2n-quic-platform/src/lib.rs +++ b/quic/s2n-quic-platform/src/lib.rs @@ -4,7 +4,6 @@ //! This module contains abstractions around the platform on which the //! stack is running -#![allow(unexpected_cfgs)] #![cfg_attr(not(any(test, feature = "std")), no_std)] extern crate alloc; diff --git a/quic/s2n-quic-qns/Cargo.toml b/quic/s2n-quic-qns/Cargo.toml index 686b6cbf9f..c7a90ee688 100644 --- a/quic/s2n-quic-qns/Cargo.toml +++ b/quic/s2n-quic-qns/Cargo.toml @@ -48,3 +48,10 @@ mimalloc = { version = "0.1", default-features = false } s2n-quic = { path = "../s2n-quic", features = ["unstable_client_hello", "unstable_resumption"] } [target.'cfg(s2n_internal_dev)'.dependencies] s2n-quic = { path = "../s2n-quic", features = ["unstable-provider-packet-interceptor"] } + +[lints.rust.unexpected_cfgs] +level = "warn" +check-cfg = [ + 'cfg(s2n_internal_dev)', + 'cfg(feature, values("unstable_client_hello"))', +] diff --git a/quic/s2n-quic-qns/src/main.rs b/quic/s2n-quic-qns/src/main.rs index 016b5fcf51..230127ca7d 100644 --- a/quic/s2n-quic-qns/src/main.rs +++ b/quic/s2n-quic-qns/src/main.rs @@ -1,8 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -#![allow(unexpected_cfgs)] - use structopt::StructOpt; pub type Error = Box; diff --git a/quic/s2n-quic-tls/Cargo.toml b/quic/s2n-quic-tls/Cargo.toml index 2602ddb0d8..079718d57a 100644 --- a/quic/s2n-quic-tls/Cargo.toml +++ b/quic/s2n-quic-tls/Cargo.toml @@ -39,3 +39,9 @@ s2n-quic-rustls = { path = "../s2n-quic-rustls" } # we don't use openssl-sys directly; it's just here to pin and vendor in dev [package.metadata.cargo-udeps.ignore] development = [ "openssl-sys" ] + +[lints.rust.unexpected_cfgs] +level = "warn" +check-cfg = [ + 'cfg(s2n_quic_enable_pq_tls)', +] diff --git a/quic/s2n-quic-tls/src/lib.rs b/quic/s2n-quic-tls/src/lib.rs index d0d0c6c093..53b50d25c5 100644 --- a/quic/s2n-quic-tls/src/lib.rs +++ b/quic/s2n-quic-tls/src/lib.rs @@ -1,8 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -#![allow(unexpected_cfgs)] - use s2n_quic_core::application::ServerName; /// Ensure memory is correctly managed in tests diff --git a/quic/s2n-quic-transport/Cargo.toml b/quic/s2n-quic-transport/Cargo.toml index e17869e6c5..f0ad20ffc0 100644 --- a/quic/s2n-quic-transport/Cargo.toml +++ b/quic/s2n-quic-transport/Cargo.toml @@ -34,3 +34,10 @@ futures-test = "0.3" # For testing Waker interactions insta = { version = "1", features = ["json"] } s2n-codec = { path = "../../common/s2n-codec", features = ["testing"] } s2n-quic-core = { path = "../s2n-quic-core", features = ["testing"] } + +[lints.rust.unexpected_cfgs] +level = "warn" +check-cfg = [ + 'cfg(s2n_quic_dump_on_panic)', + 'cfg(feature, values("testing"))', +] diff --git a/quic/s2n-quic-transport/src/lib.rs b/quic/s2n-quic-transport/src/lib.rs index eb515c7729..40cb9e6d1e 100644 --- a/quic/s2n-quic-transport/src/lib.rs +++ b/quic/s2n-quic-transport/src/lib.rs @@ -4,7 +4,6 @@ //! This module contains all main runtime components for receiving and sending //! data via the QUIC protocol. -#![allow(unexpected_cfgs)] #![deny(unused_must_use)] extern crate alloc; diff --git a/rust-toolchain b/rust-toolchain index a8c550885a..0be624d809 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "1.71.1" +channel = "1.74.1" components = [ "rustc", "clippy", "rustfmt" ]