Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(s2n-quic-platform): disable REUSEADDR by default #2110

Merged
merged 3 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions quic/s2n-quic-platform/src/io/tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ impl Io {
mut max_mtu,
max_segments,
gro_enabled,
reuse_address,
reuse_port,
} = self.builder;

Expand Down Expand Up @@ -90,7 +91,7 @@ impl Io {
let rx_socket = if let Some(rx_socket) = rx_socket {
rx_socket
} else if let Some(recv_addr) = recv_addr {
syscall::bind_udp(recv_addr, reuse_port)?
syscall::bind_udp(recv_addr, reuse_address, reuse_port)?
} else {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
Expand All @@ -103,7 +104,7 @@ impl Io {
let tx_socket = if let Some(tx_socket) = tx_socket {
tx_socket
} else if let Some(send_addr) = send_addr {
syscall::bind_udp(send_addr, reuse_port)?
syscall::bind_udp(send_addr, reuse_address, reuse_port)?
} else {
// No tx_socket or send address was specified, so the tx socket
// will be a handle to the rx socket.
Expand Down
7 changes: 7 additions & 0 deletions quic/s2n-quic-platform/src/io/tokio/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct Builder {
pub(super) max_mtu: MaxMtu,
pub(super) max_segments: gso::MaxSegments,
pub(super) gro_enabled: Option<bool>,
pub(super) reuse_address: bool,
pub(super) reuse_port: bool,
}

Expand Down Expand Up @@ -155,6 +156,12 @@ impl Builder {
}
}

/// Enables the address reuse (SO_REUSEADDR) socket option
pub fn with_reuse_address(mut self, enabled: bool) -> io::Result<Self> {
self.reuse_address = enabled;
Ok(self)
}

/// Enables the port reuse (SO_REUSEPORT) socket option
pub fn with_reuse_port(mut self) -> io::Result<Self> {
if !cfg!(unix) {
Expand Down
4 changes: 2 additions & 2 deletions quic/s2n-quic-platform/src/io/tokio/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ async fn runtime<A: ToSocketAddrs>(
receive_addr: A,
send_addr: Option<A>,
) -> io::Result<(super::Io, SocketAddress)> {
let rx_socket = syscall::bind_udp(receive_addr, false)?;
let rx_socket = syscall::bind_udp(receive_addr, false, false)?;
rx_socket.set_nonblocking(true)?;
let rx_socket: std::net::UdpSocket = rx_socket.into();
let rx_addr = rx_socket.local_addr()?;

let mut io_builder = Io::builder().with_rx_socket(rx_socket)?;

if let Some(tx_addr) = send_addr {
let tx_socket = syscall::bind_udp(tx_addr, false)?;
let tx_socket = syscall::bind_udp(tx_addr, false, false)?;
tx_socket.set_nonblocking(true)?;
let tx_socket: std::net::UdpSocket = tx_socket.into();
io_builder = io_builder.with_tx_socket(tx_socket)?
Expand Down
10 changes: 7 additions & 3 deletions quic/s2n-quic-platform/src/syscall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ pub fn udp_socket(addr: std::net::SocketAddr) -> io::Result<Socket> {
// allow ipv4 to also connect - ignore the error if it fails
let _ = socket.set_only_v6(false);

socket.set_reuse_address(true)?;

Ok(socket)
}

/// Creates a UDP socket bound to the provided address
pub fn bind_udp<A: std::net::ToSocketAddrs>(addr: A, reuse_port: bool) -> io::Result<Socket> {
pub fn bind_udp<A: std::net::ToSocketAddrs>(
addr: A,
reuse_address: bool,
reuse_port: bool,
) -> io::Result<Socket> {
let addr = addr.to_socket_addrs()?.next().ok_or_else(|| {
std::io::Error::new(
io::ErrorKind::InvalidInput,
Expand All @@ -84,6 +86,8 @@ pub fn bind_udp<A: std::net::ToSocketAddrs>(addr: A, reuse_port: bool) -> io::Re
})?;
let socket = udp_socket(addr)?;

socket.set_reuse_address(reuse_address)?;

#[cfg(unix)]
socket.set_reuse_port(reuse_port)?;

Expand Down
22 changes: 0 additions & 22 deletions scripts/perf/bin/quinn

This file was deleted.

4 changes: 2 additions & 2 deletions scripts/perf/bin/s2n-quic
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ set -e

case "$PS" in
server*)
../../target/release/s2n-quic-qns \
exec ../../target/release/s2n-quic-qns \
perf \
server \
--port $SERVER_PORT \
--max-mtu 16000 \
--stats
;;
client*)
../../target/release/s2n-quic-qns \
exec ../../target/release/s2n-quic-qns \
perf \
client \
--receive "${DOWNLOAD_BYTES}" \
Expand Down
4 changes: 2 additions & 2 deletions scripts/perf/bin/s2n-quic-null
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ set -e

case "$PS" in
server*)
../../target/release/s2n-quic-qns \
exec ../../target/release/s2n-quic-qns \
perf \
server \
--port $SERVER_PORT \
Expand All @@ -18,7 +18,7 @@ case "$PS" in
--stats
;;
client*)
../../target/release/s2n-quic-qns \
exec ../../target/release/s2n-quic-qns \
perf \
client \
--receive "${DOWNLOAD_BYTES}" \
Expand Down
12 changes: 0 additions & 12 deletions scripts/perf/build
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,6 @@ if ! command -v "ultraman" &> /dev/null; then
cargo install ultraman
fi

if [ ! -f target/perf/quinn/bin/perf_client ] || [ ! -f target/perf/quinn/bin/perf_server ]; then
mkdir -p target/perf/quinn
cargo +stable install \
--git https://github.com/quinn-rs/quinn \
--rev 6e4bcbb2fcb57ced2ef261c9662521c5baf37f3c \
--bin perf_client \
--bin perf_server \
--root target/perf/quinn \
--target-dir target/perf/quinn \
perf
fi

cargo \
+stable \
build \
Expand Down
Loading