From a7db718ffb67386c21e2c97ec689b7c959d452f6 Mon Sep 17 00:00:00 2001 From: Tom Finet Date: Wed, 21 Feb 2024 23:15:01 +0000 Subject: [PATCH] Kernel/Net: Send RST packet when socket receives in closed state RFC9293 states that a closed socket should reply to all non-RST packets with an RST. This change implements this behaviour as specified in section 3.5.2 in bullet point 1. --- Kernel/Net/NetworkTask.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Kernel/Net/NetworkTask.cpp b/Kernel/Net/NetworkTask.cpp index 35c00a041e..7c45d10e02 100644 --- a/Kernel/Net/NetworkTask.cpp +++ b/Kernel/Net/NetworkTask.cpp @@ -447,7 +447,12 @@ void handle_tcp(IPv4Packet const& ipv4_packet, UnixDateTime const& packet_timest switch (socket->state()) { case TCPSocket::State::Closed: dbgln("handle_tcp: unexpected flags in Closed state ({:x}) for socket with tuple {}", tcp_packet.flags(), tuple.to_string()); - // TODO: we may want to send an RST here, maybe as a configurable option + if (tcp_packet.has_rst()) { + return; + } + socket->set_sequence_number(tcp_packet.has_ack() ? tcp_packet.ack_number() : 0); + socket->set_ack_number(tcp_packet.sequence_number() + payload_size + 1); + (void)socket->send_tcp_packet(TCPFlags::RST | TCPFlags::ACK); return; case TCPSocket::State::TimeWait: dbgln("handle_tcp: unexpected flags in TimeWait state ({:x}) for socket with tuple {}", tcp_packet.flags(), tuple.to_string());