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

Allow withholding the SYN|ACK packet by user code #863

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/socket/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,9 @@ pub struct Socket<'a> {
/// Used for rate-limiting: No more challenge ACKs will be sent until this instant.
challenge_ack_timer: Instant,

/// If this is set, we will not send a SYN|ACK until this is unset.
synack_paused: bool,

/// Nagle's Algorithm enabled.
nagle: bool,

Expand Down Expand Up @@ -522,6 +525,7 @@ impl<'a> Socket<'a> {
ack_delay_timer: AckDelayTimer::Idle,
challenge_ack_timer: Instant::from_secs(0),
nagle: true,
synack_paused: false,

#[cfg(feature = "async")]
rx_waker: WakerRegistration::new(),
Expand Down Expand Up @@ -586,6 +590,15 @@ impl<'a> Socket<'a> {
self.nagle
}

/// Pause sending of SYN|ACK packets.
///
/// When this flag is set, the socket will get stuck in `SynReceived` state without sending
/// any SYN|ACK packets back, until this flag is unset. This is useful for certain niche TCP
/// proxy usecases.
pub fn pause_synack(&mut self, pause: bool) {
self.synack_paused = pause;
}

/// Return the current window field value, including scaling according to RFC 1323.
///
/// Used in internal calculations as well as packet generation.
Expand Down Expand Up @@ -2098,6 +2111,10 @@ impl<'a> Socket<'a> {
}
}

if matches!(self.state, State::SynReceived) && self.synack_paused {
return Ok(());
}

// Decide whether we're sending a packet.
if self.seq_to_transmit(cx) {
// If we have data to transmit and it fits into partner's window, do it.
Expand Down