浏览代码

Accept data packets in FIN_WAIT_2 state.

Previously, data packets were never accepted in FIN_WAIT_2. The missing
match case was dropping them as "unexpected packet"s.
Dario Nieuwenhuis 4 年之前
父节点
当前提交
b7a14980d0
共有 1 个文件被更改,包括 37 次插入0 次删除
  1. 37 0
      src/socket/tcp.rs

+ 37 - 0
src/socket/tcp.rs

@@ -1195,6 +1195,11 @@ impl<'a> TcpSocket<'a> {
                 }
             }
 
+            // Data packets in FIN-WAIT-2 reset the idle timer.
+            (State::FinWait2, TcpControl::None) => {
+                self.timer.set_for_idle(timestamp, self.keep_alive);
+            }
+
             // FIN packets in FIN-WAIT-2 state change it to TIME-WAIT.
             (State::FinWait2, TcpControl::Fin) => {
                 self.remote_seq_no  += 1;
@@ -2947,6 +2952,22 @@ mod test {
         assert_eq!(s.state, State::FinWait1);
     }
 
+    #[test]
+    fn test_fin_wait_1_recv() {
+        let mut s = socket_fin_wait_1();
+        send!(s, TcpRepr {
+            seq_number: REMOTE_SEQ + 1,
+            ack_number: Some(LOCAL_SEQ + 1),
+            payload:    &b"abc"[..],
+            ..SEND_TEMPL
+        });
+        assert_eq!(s.state, State::FinWait1);
+        s.recv(|data| {
+            assert_eq!(data, b"abc");
+            (3, ())
+        }).unwrap();
+    }
+
     #[test]
     fn test_fin_wait_1_close() {
         let mut s = socket_fin_wait_1();
@@ -2971,6 +2992,22 @@ mod test {
         sanity!(s, socket_time_wait(false));
     }
 
+    #[test]
+    fn test_fin_wait_2_recv() {
+        let mut s = socket_fin_wait_2();
+        send!(s, TcpRepr {
+            seq_number: REMOTE_SEQ + 1,
+            ack_number: Some(LOCAL_SEQ + 1 + 1),
+            payload:    &b"abc"[..],
+            ..SEND_TEMPL
+        });
+        assert_eq!(s.state, State::FinWait2);
+        s.recv(|data| {
+            assert_eq!(data, b"abc");
+            (3, ())
+        }).unwrap();
+    }
+
     #[test]
     fn test_fin_wait_2_close() {
         let mut s = socket_fin_wait_2();