From 83523cabda25b9a9e08d4c38811e60d9a2913919 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 6 Feb 2022 17:31:32 +0100 Subject: [PATCH] Kernel: Fix bugs in TCP state handling in FinWait1 & FinWait2 1. When receiving FIN while in FinWait1, we now reply with ACK in addition to the FinWait1->Closing transition. 2. When receiving FIN|ACK while in FinWait1, we now reply with ACK and transition from FinWait1->TimeWait. 3. When receiving FIN while in FinWait2, we now reply with ACK. --- Kernel/Net/NetworkTask.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Kernel/Net/NetworkTask.cpp b/Kernel/Net/NetworkTask.cpp index e1d973af20f..c99d167f80b 100644 --- a/Kernel/Net/NetworkTask.cpp +++ b/Kernel/Net/NetworkTask.cpp @@ -571,6 +571,12 @@ void handle_tcp(IPv4Packet const& ipv4_packet, Time const& packet_timestamp) case TCPFlags::FIN: socket->set_ack_number(tcp_packet.sequence_number() + payload_size + 1); socket->set_state(TCPSocket::State::Closing); + (void)socket->send_ack(true); + return; + case TCPFlags::FIN | TCPFlags::ACK: + socket->set_ack_number(tcp_packet.sequence_number() + payload_size + 1); + socket->set_state(TCPSocket::State::TimeWait); + (void)socket->send_ack(true); return; default: dbgln("handle_tcp: unexpected flags in FinWait1 state ({:x})", tcp_packet.flags()); @@ -583,8 +589,10 @@ void handle_tcp(IPv4Packet const& ipv4_packet, Time const& packet_timestamp) case TCPFlags::FIN: socket->set_ack_number(tcp_packet.sequence_number() + payload_size + 1); socket->set_state(TCPSocket::State::TimeWait); + (void)socket->send_ack(true); return; case TCPFlags::ACK | TCPFlags::RST: + // FIXME: Verify that this transition is legitimate. socket->set_state(TCPSocket::State::Closed); return; default: