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

Adjusting TCP connection 3-way handshake state management #367

Merged
merged 6 commits into from
Aug 17, 2020
Merged
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
20 changes: 20 additions & 0 deletions src/socket/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,15 @@ impl<'a> TcpSocket<'a> {
self.meta.handle, self.local_endpoint, self.remote_endpoint);
return Err(Error::Dropped)
}
// Any ACK in the SYN-SENT state must have the SYN flag set.
(State::SynSent, &TcpRepr {
control: TcpControl::None, ack_number: Some(_), ..
}) => {
net_debug!("{}:{}:{}: expecting a SYN|ACK",
self.meta.handle, self.local_endpoint, self.remote_endpoint);
self.abort();
return Err(Error::Dropped)
}
// Every acknowledgement must be for transmitted but unacknowledged data.
(_, &TcpRepr { ack_number: Some(ack_number), .. }) => {
let unacknowledged = self.tx_buffer.len() + control_len;
Expand Down Expand Up @@ -2490,6 +2499,17 @@ mod test {
assert_eq!(s.state, State::SynSent);
}

#[test]
fn test_syn_sent_bad_ack() {
let mut s = socket_syn_sent();
send!(s, TcpRepr {
control: TcpControl::None,
ack_number: Some(TcpSeqNumber(1)),
..SEND_TEMPL
}, Err(Error::Dropped));
assert_eq!(s.state, State::Closed);
}

#[test]
fn test_syn_sent_close() {
let mut s = socket();
Expand Down