From 5efe0fa2b0c30e93afb4ded08539faf46ad1f46b Mon Sep 17 00:00:00 2001 From: Cameron Bytheway Date: Thu, 11 Jan 2024 16:44:37 -0700 Subject: [PATCH 1/2] feat(s2n-quic-platform): make GSO/GRO configuration more ergonomic --- .../s2n-quic-platform/src/io/tokio/builder.rs | 22 +++++++++++++++++++ quic/s2n-quic-qns/src/io.rs | 14 ++++-------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/quic/s2n-quic-platform/src/io/tokio/builder.rs b/quic/s2n-quic-platform/src/io/tokio/builder.rs index 5cab9c330e..096f2f611e 100644 --- a/quic/s2n-quic-platform/src/io/tokio/builder.rs +++ b/quic/s2n-quic-platform/src/io/tokio/builder.rs @@ -122,6 +122,17 @@ impl Builder { Ok(self) } + /// Configures Generic Segmentation Offload (GSO) + /// + /// By default, GSO will be used unless the platform does not support it or an attempt to use + /// GSO fails. If it is known that GSO is not available, set this option to explicitly disable it. + pub fn with_gso(mut self, enabled: bool) -> io::Result { + if !enabled { + self.max_segments = 1.try_into().expect("1 is always a valid MaxSegments value"); + } + Ok(self) + } + /// Disables Generic Receive Offload (GRO) /// /// By default, GRO will be used unless the platform does not support it. If it is known that @@ -131,6 +142,17 @@ impl Builder { Ok(self) } + /// Configures Generic Receive Offload (GRO) + /// + /// By default, GRO will be used unless the platform does not support it. If it is known that + /// GRO is not available, set this option to explicitly disable it. + pub fn with_gro(mut self, enabled: bool) -> io::Result { + if !enabled { + self.gro_enabled = Some(false); + } + Ok(self) + } + /// Enables the port reuse (SO_REUSEPORT) socket option pub fn with_reuse_port(mut self) -> io::Result { if !cfg!(unix) { diff --git a/quic/s2n-quic-qns/src/io.rs b/quic/s2n-quic-qns/src/io.rs index 9a7983b139..1c8c1489b2 100644 --- a/quic/s2n-quic-qns/src/io.rs +++ b/quic/s2n-quic-qns/src/io.rs @@ -46,11 +46,8 @@ impl Server { pub fn build(&self) -> Result { let mut io_builder = io::Default::builder() .with_receive_address((self.ip, self.port).into())? - .with_max_mtu(self.max_mtu)?; - - if self.disable_gso { - io_builder = io_builder.with_gso_disabled()?; - } + .with_max_mtu(self.max_mtu)? + .with_gso(!self.disable_gso)?; if let Some(size) = self.queue_send_buffer_size { io_builder = io_builder.with_internal_send_buffer_size(size)?; @@ -102,11 +99,8 @@ impl Client { pub fn build(&self) -> Result { let mut io_builder = io::Default::builder() .with_receive_address((self.local_ip, 0u16).into())? - .with_max_mtu(self.max_mtu)?; - - if self.disable_gso { - io_builder = io_builder.with_gso_disabled()?; - } + .with_max_mtu(self.max_mtu)? + .with_gso(!self.disable_gso)?; if let Some(size) = self.queue_send_buffer_size { io_builder = io_builder.with_internal_send_buffer_size(size)?; From c6fc937db8877ea5a61f52e0d113515f17ee6ae6 Mon Sep 17 00:00:00 2001 From: Cameron Bytheway Date: Fri, 12 Jan 2024 10:02:11 -0700 Subject: [PATCH 2/2] pr feedback --- quic/s2n-quic-platform/src/io/tokio/builder.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/quic/s2n-quic-platform/src/io/tokio/builder.rs b/quic/s2n-quic-platform/src/io/tokio/builder.rs index 096f2f611e..af21948d91 100644 --- a/quic/s2n-quic-platform/src/io/tokio/builder.rs +++ b/quic/s2n-quic-platform/src/io/tokio/builder.rs @@ -126,11 +126,12 @@ impl Builder { /// /// By default, GSO will be used unless the platform does not support it or an attempt to use /// GSO fails. If it is known that GSO is not available, set this option to explicitly disable it. - pub fn with_gso(mut self, enabled: bool) -> io::Result { - if !enabled { - self.max_segments = 1.try_into().expect("1 is always a valid MaxSegments value"); + pub fn with_gso(self, enabled: bool) -> io::Result { + if enabled { + Ok(self) + } else { + self.with_gso_disabled() } - Ok(self) } /// Disables Generic Receive Offload (GRO) @@ -146,11 +147,12 @@ impl Builder { /// /// By default, GRO will be used unless the platform does not support it. If it is known that /// GRO is not available, set this option to explicitly disable it. - pub fn with_gro(mut self, enabled: bool) -> io::Result { - if !enabled { - self.gro_enabled = Some(false); + pub fn with_gro(self, enabled: bool) -> io::Result { + if enabled { + Ok(self) + } else { + self.with_gro_disabled() } - Ok(self) } /// Enables the port reuse (SO_REUSEPORT) socket option