From 3035ef07fb45d5eb9cfcbd849aef6caddae2de37 Mon Sep 17 00:00:00 2001 From: whitequark Date: Fri, 25 Aug 2017 06:27:00 +0000 Subject: [PATCH] Fix a bug that caused TCP packets with PSH bit to be dropped. --- src/socket/tcp.rs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/socket/tcp.rs b/src/socket/tcp.rs index 09e36b7..2547d49 100644 --- a/src/socket/tcp.rs +++ b/src/socket/tcp.rs @@ -750,7 +750,7 @@ impl<'a> TcpSocket<'a> { if self.state == State::Closed { return Err(Error::Rejected) } let packet = TcpPacket::new_checked(&payload[..ip_repr.payload_len()])?; - let repr = TcpRepr::parse(&packet, &ip_repr.src_addr(), &ip_repr.dst_addr())?; + let mut repr = TcpRepr::parse(&packet, &ip_repr.src_addr(), &ip_repr.dst_addr())?; // If we're still listening for SYNs and the packet has an ACK, it cannot // be destined to this socket, but another one may well listen on the same @@ -901,6 +901,11 @@ impl<'a> TcpSocket<'a> { } } + if repr.control == TcpControl::Psh { + // We don't care about the PSH flag. + repr.control = TcpControl::None; + } + // Validate and update the state. match (self.state, repr) { // RSTs are not accepted in the LISTEN state. @@ -2891,7 +2896,7 @@ mod test { // =========================================================================================// #[test] - fn test_psh() { + fn test_psh_transmit() { let mut s = socket_established(); s.remote_win_len = 6; s.send_slice(b"abcdef").unwrap(); @@ -2911,4 +2916,21 @@ mod test { ..RECV_TEMPL }), exact); } + + #[test] + fn test_psh_receive() { + let mut s = socket_established(); + send!(s, TcpRepr { + control: TcpControl::Psh, + seq_number: REMOTE_SEQ + 1, + ack_number: Some(LOCAL_SEQ + 1), + payload: &b"abcdef"[..], + ..SEND_TEMPL + }, Ok(Some(TcpRepr { + seq_number: LOCAL_SEQ + 1, + ack_number: Some(REMOTE_SEQ + 1 + 6), + window_len: 58, + ..RECV_TEMPL + }))); + } }