From e0e509a78aab9399783ea05fda216f814fc9b40c Mon Sep 17 00:00:00 2001 From: Yury Yarashevich Date: Wed, 20 Nov 2024 15:21:45 +0100 Subject: [PATCH] #2057: Option to disable GREASE random transport parameter. --- quinn-proto/src/config.rs | 17 ++++++++++++++ quinn-proto/src/transport_parameters.rs | 30 ++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/quinn-proto/src/config.rs b/quinn-proto/src/config.rs index 571f998dd..d28903b3d 100644 --- a/quinn-proto/src/config.rs +++ b/quinn-proto/src/config.rs @@ -63,6 +63,8 @@ pub struct TransportConfig { pub(crate) congestion_controller_factory: Arc, pub(crate) enable_segmentation_offload: bool, + + pub(crate) send_grease_transport_parameter: bool, } impl TransportConfig { @@ -334,6 +336,14 @@ impl TransportConfig { self.enable_segmentation_offload = enabled; self } + + /// Specifies whether the GREASE transport parameter is sent during transport parameter negotiation. + /// + /// Defaults to `true`. + pub fn send_grease_random_transport_parameter(&mut self, enabled: bool) -> &mut Self { + self.send_grease_transport_parameter = enabled; + self + } } impl Default for TransportConfig { @@ -374,6 +384,8 @@ impl Default for TransportConfig { congestion_controller_factory: Arc::new(congestion::CubicConfig::default()), enable_segmentation_offload: true, + + send_grease_transport_parameter: true, } } } @@ -405,6 +417,7 @@ impl fmt::Debug for TransportConfig { deterministic_packet_numbers: _, congestion_controller_factory: _, enable_segmentation_offload, + send_grease_transport_parameter, } = self; fmt.debug_struct("TransportConfig") .field("max_concurrent_bidi_streams", max_concurrent_bidi_streams) @@ -432,6 +445,10 @@ impl fmt::Debug for TransportConfig { .field("datagram_send_buffer_size", datagram_send_buffer_size) .field("congestion_controller_factory", &"[ opaque ]") .field("enable_segmentation_offload", enable_segmentation_offload) + .field( + "send_grease_transport_parameter", + send_grease_transport_parameter, + ) .finish() } } diff --git a/quinn-proto/src/transport_parameters.rs b/quinn-proto/src/transport_parameters.rs index 381968059..43476dd54 100644 --- a/quinn-proto/src/transport_parameters.rs +++ b/quinn-proto/src/transport_parameters.rs @@ -167,7 +167,11 @@ impl TransportParameters { min_ack_delay: Some( VarInt::from_u64(u64::try_from(TIMER_GRANULARITY.as_micros()).unwrap()).unwrap(), ), - grease_transport_parameter: Some(ReservedTransportParameter::random(rng)), + grease_transport_parameter: if config.send_grease_transport_parameter { + Some(ReservedTransportParameter::random(rng)) + } else { + None + }, ..Self::default() } } @@ -636,6 +640,30 @@ mod test { assert_eq!(read_params, TransportParameters::default()); } + #[test] + fn grease_transport_parameter_not_serialized_when_disabled() { + let mut params = TransportParameters::default(); + params.grease_transport_parameter = None; + + let mut buf = Vec::new(); + params.write(&mut buf); + assert!(buf.is_empty()); + } + + #[test] + fn grease_transport_parameter_is_serialized_when_enabled() { + let mut params = TransportParameters::default(); + params.grease_transport_parameter = Some(ReservedTransportParameter { + id: VarInt::from_u32(27), + payload: [0xAB, 0xFF, 0x1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + payload_len: 3, + }); + + let mut buf = Vec::new(); + params.write(&mut buf); + assert_eq!(buf, [27, 3, 0xAB, 0xFF, 0x1]) + } + #[test] fn read_semantic_validation() { #[allow(clippy::type_complexity)]