summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-03-14 15:28:23 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-03-14 15:28:23 +0100
commitf9569db1e5d57cb486dcb4cb84eb86d9f3092ef6 (patch)
tree8a01c9128a8b173502d4397fe2dfd80dae4c39f8 /Kernel
parent25e521f510b8da36ce6d60aeec019c97206face8 (diff)
downloadserenity-f9569db1e5d57cb486dcb4cb84eb86d9f3092ef6.zip
TCP: Collect the payload if present in a packet with FIN set.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/IPv4Socket.cpp4
-rw-r--r--Kernel/IPv4Socket.h2
-rw-r--r--Kernel/NetworkTask.cpp4
3 files changed, 9 insertions, 1 deletions
diff --git a/Kernel/IPv4Socket.cpp b/Kernel/IPv4Socket.cpp
index b58feb72be..6a24230174 100644
--- a/Kernel/IPv4Socket.cpp
+++ b/Kernel/IPv4Socket.cpp
@@ -222,9 +222,11 @@ ssize_t IPv4Socket::recvfrom(void* buffer, size_t buffer_length, int flags, sock
void IPv4Socket::did_receive(ByteBuffer&& packet)
{
LOCKER(lock());
+ auto packet_size = packet.size();
m_receive_queue.append(move(packet));
m_can_read = true;
+ m_bytes_received += packet_size;
#ifdef IPV4_SOCKET_DEBUG
- kprintf("IPv4Socket(%p): did_receive %d bytes, packets in queue: %d\n", this, packet.size(), m_receive_queue.size_slow());
+ kprintf("IPv4Socket(%p): did_receive %d bytes, total_received=%u, packets in queue: %d\n", this, packet_size, m_bytes_received, m_receive_queue.size_slow());
#endif
}
diff --git a/Kernel/IPv4Socket.h b/Kernel/IPv4Socket.h
index 5a3a92fae2..1d249dece7 100644
--- a/Kernel/IPv4Socket.h
+++ b/Kernel/IPv4Socket.h
@@ -68,6 +68,8 @@ private:
word m_source_port { 0 };
word m_destination_port { 0 };
+ dword m_bytes_received { 0 };
+
bool m_can_read { false };
};
diff --git a/Kernel/NetworkTask.cpp b/Kernel/NetworkTask.cpp
index 151e0a62e2..4b129723f2 100644
--- a/Kernel/NetworkTask.cpp
+++ b/Kernel/NetworkTask.cpp
@@ -302,6 +302,10 @@ void handle_tcp(const EthernetFrameHeader& eth, int frame_size)
if (tcp_packet.has_fin()) {
kprintf("handle_tcp: Got FIN, payload_size=%u\n", payload_size);
+
+ if (payload_size != 0)
+ socket->did_receive(ByteBuffer::copy((const byte*)&ipv4_packet, sizeof(IPv4Packet) + ipv4_packet.payload_size()));
+
socket->set_ack_number(tcp_packet.sequence_number() + payload_size + 1);
socket->send_tcp_packet(TCPFlags::FIN | TCPFlags::ACK);
socket->set_state(TCPSocket::State::Disconnecting);