diff options
author | Gunnar Beutner <gbeutner@serenityos.org> | 2021-05-13 11:34:38 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-14 16:50:00 +0200 |
commit | c22296505cab8f1d19ca4bbca99ded57480b327f (patch) | |
tree | 9bfe71d4fbf78d77f8adb1abd273a4625013a013 /Kernel | |
parent | 08aa3a91e356b1599fe6e58caf27cd21b9b28670 (diff) | |
download | serenity-c22296505cab8f1d19ca4bbca99ded57480b327f.zip |
Kernel: Merge do_retransmit_packets() into retransmit_packets()
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/Net/TCPSocket.cpp | 97 | ||||
-rw-r--r-- | Kernel/Net/TCPSocket.h | 1 |
2 files changed, 46 insertions, 52 deletions
diff --git a/Kernel/Net/TCPSocket.cpp b/Kernel/Net/TCPSocket.cpp index 26422ecec3..92f918f268 100644 --- a/Kernel/Net/TCPSocket.cpp +++ b/Kernel/Net/TCPSocket.cpp @@ -242,56 +242,6 @@ KResult TCPSocket::send_tcp_packet(u16 flags, const UserOrKernelBuffer* payload, return KSuccess; } -void TCPSocket::do_retransmit_packets() -{ - auto routing_decision = route_to(peer_address(), local_address(), bound_interface()); - if (routing_decision.is_zero()) - return; - - Locker locker(m_not_acked_lock, Lock::Mode::Shared); - for (auto& packet : m_not_acked) { - packet.tx_counter++; - - if constexpr (TCP_SOCKET_DEBUG) { - auto& tcp_packet = *(const TCPPacket*)(packet.buffer.data()); - dbgln("Sending TCP packet from {}:{} to {}:{} with ({}{}{}{}) seq_no={}, ack_no={}, tx_counter={}", - local_address(), local_port(), - peer_address(), peer_port(), - (tcp_packet.has_syn() ? "SYN " : ""), - (tcp_packet.has_ack() ? "ACK " : ""), - (tcp_packet.has_fin() ? "FIN " : ""), - (tcp_packet.has_rst() ? "RST " : ""), - tcp_packet.sequence_number(), - tcp_packet.ack_number(), - packet.tx_counter); - } - - auto packet_buffer = UserOrKernelBuffer::for_kernel_buffer(packet.buffer.data()); - int err = routing_decision.adapter->send_ipv4( - local_address(), routing_decision.next_hop, peer_address(), - IPv4Protocol::TCP, packet_buffer, packet.buffer.size(), ttl()); - if (err < 0) { - auto& tcp_packet = *(const TCPPacket*)(packet.buffer.data()); - dmesgln("Error ({}) sending TCP packet from {}:{} to {}:{} with ({}{}{}{}) seq_no={}, ack_no={}, tx_counter={}", - err, - local_address(), - local_port(), - peer_address(), - peer_port(), - (tcp_packet.has_syn() ? "SYN " : ""), - (tcp_packet.has_ack() ? "ACK " : ""), - (tcp_packet.has_fin() ? "FIN " : ""), - (tcp_packet.has_rst() ? "RST " : ""), - tcp_packet.sequence_number(), - tcp_packet.ack_number(), - packet.tx_counter); - } else { - m_packets_out++; - m_bytes_out += packet.buffer.size(); - } - } -} - void TCPSocket::receive_tcp_packet(const TCPPacket& packet, u16 size) { if (packet.has_ack()) { @@ -566,7 +516,52 @@ void TCPSocket::retransmit_packets() return; } - do_retransmit_packets(); + auto routing_decision = route_to(peer_address(), local_address(), bound_interface()); + if (routing_decision.is_zero()) + return; + + Locker locker(m_not_acked_lock, Lock::Mode::Shared); + for (auto& packet : m_not_acked) { + packet.tx_counter++; + + if constexpr (TCP_SOCKET_DEBUG) { + auto& tcp_packet = *(const TCPPacket*)(packet.buffer.data()); + dbgln("Sending TCP packet from {}:{} to {}:{} with ({}{}{}{}) seq_no={}, ack_no={}, tx_counter={}", + local_address(), local_port(), + peer_address(), peer_port(), + (tcp_packet.has_syn() ? "SYN " : ""), + (tcp_packet.has_ack() ? "ACK " : ""), + (tcp_packet.has_fin() ? "FIN " : ""), + (tcp_packet.has_rst() ? "RST " : ""), + tcp_packet.sequence_number(), + tcp_packet.ack_number(), + packet.tx_counter); + } + + auto packet_buffer = UserOrKernelBuffer::for_kernel_buffer(packet.buffer.data()); + int err = routing_decision.adapter->send_ipv4( + local_address(), routing_decision.next_hop, peer_address(), + IPv4Protocol::TCP, packet_buffer, packet.buffer.size(), ttl()); + if (err < 0) { + auto& tcp_packet = *(const TCPPacket*)(packet.buffer.data()); + dmesgln("Error ({}) sending TCP packet from {}:{} to {}:{} with ({}{}{}{}) seq_no={}, ack_no={}, tx_counter={}", + err, + local_address(), + local_port(), + peer_address(), + peer_port(), + (tcp_packet.has_syn() ? "SYN " : ""), + (tcp_packet.has_ack() ? "ACK " : ""), + (tcp_packet.has_fin() ? "FIN " : ""), + (tcp_packet.has_rst() ? "RST " : ""), + tcp_packet.sequence_number(), + tcp_packet.ack_number(), + packet.tx_counter); + } else { + m_packets_out++; + m_bytes_out += packet.buffer.size(); + } + } } } diff --git a/Kernel/Net/TCPSocket.h b/Kernel/Net/TCPSocket.h index 767b2dc405..39d5e5a651 100644 --- a/Kernel/Net/TCPSocket.h +++ b/Kernel/Net/TCPSocket.h @@ -176,7 +176,6 @@ private: virtual KResult protocol_bind() override; virtual KResult protocol_listen() override; - void do_retransmit_packets(); void enqueue_for_retransmit(); void dequeue_for_retransmit(); |