From c797eaa9f818a36b57add06497ff465b1263708c Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 11 Feb 2022 12:38:10 +0100 Subject: [PATCH] Kernel/Net: Don't update TCP socket "last sent ACK" field too early Defer updating this field until after the last fallible operation has succeeded. --- Kernel/Net/TCPSocket.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Kernel/Net/TCPSocket.cpp b/Kernel/Net/TCPSocket.cpp index 86143a8b526..2fe8161a415 100644 --- a/Kernel/Net/TCPSocket.cpp +++ b/Kernel/Net/TCPSocket.cpp @@ -237,12 +237,6 @@ ErrorOr TCPSocket::send_tcp_packet(u16 flags, const UserOrKernelBuffer* pa tcp_packet.set_data_offset(tcp_header_size / sizeof(u32)); tcp_packet.set_flags(flags); - if (flags & TCPFlags::ACK) { - m_last_ack_number_sent = m_ack_number; - m_last_ack_sent_time = kgettimeofday(); - tcp_packet.set_ack_number(m_ack_number); - } - if (payload) { if (auto result = payload->read(tcp_packet.payload(), payload_size); result.is_error()) { routing_decision.adapter->release_packet_buffer(*packet); @@ -250,6 +244,12 @@ ErrorOr TCPSocket::send_tcp_packet(u16 flags, const UserOrKernelBuffer* pa } } + if (flags & TCPFlags::ACK) { + m_last_ack_number_sent = m_ack_number; + m_last_ack_sent_time = kgettimeofday(); + tcp_packet.set_ack_number(m_ack_number); + } + if (flags & TCPFlags::SYN) { ++m_sequence_number; } else {