summaryrefslogtreecommitdiff
path: root/Kernel/Net/NetworkTask.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-02-08 15:52:32 +0100
committerAndreas Kling <kling@serenityos.org>2020-02-08 16:04:27 +0100
commit228a1e90998fb0f729e6fe9fa3057fe15b203088 (patch)
treea9224e262e20717b9393f736b2570cfafaeb40f7 /Kernel/Net/NetworkTask.cpp
parent8325662186ace9d9d356f6ab37433df98b4842da (diff)
downloadserenity-228a1e90998fb0f729e6fe9fa3057fe15b203088.zip
IPv4: Basic implementation of TCP socket shutdown
We can now participate in the TCP connection closing handshake. :^) This implementation is definitely not complete and needs to handle a bunch of other cases. But it's a huge improvement over not being able to close connections at all. Note that we hold on to pending-close sockets indefinitely, until they are moved into the Closed state. This should also have a timeout but that's still a FIXME. :^) Fixes #428.
Diffstat (limited to 'Kernel/Net/NetworkTask.cpp')
-rw-r--r--Kernel/Net/NetworkTask.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/Kernel/Net/NetworkTask.cpp b/Kernel/Net/NetworkTask.cpp
index 1c52923fcb..0d93f2bd0e 100644
--- a/Kernel/Net/NetworkTask.cpp
+++ b/Kernel/Net/NetworkTask.cpp
@@ -572,6 +572,9 @@ void handle_tcp(const IPv4Packet& ipv4_packet)
socket->set_ack_number(tcp_packet.sequence_number() + payload_size + 1);
socket->set_state(TCPSocket::State::TimeWait);
return;
+ case TCPFlags::ACK | TCPFlags::RST:
+ socket->set_state(TCPSocket::State::Closed);
+ return;
default:
kprintf("handle_tcp: unexpected flags in FinWait2 state\n");
socket->send_tcp_packet(TCPFlags::RST);
@@ -596,12 +599,8 @@ void handle_tcp(const IPv4Packet& ipv4_packet)
socket->did_receive(ipv4_packet.source(), tcp_packet.source_port(), KBuffer::copy(&ipv4_packet, sizeof(IPv4Packet) + ipv4_packet.payload_size()));
socket->set_ack_number(tcp_packet.sequence_number() + payload_size + 1);
- // TODO: We should only send a FIN packet out once we're shutting
- // down our side of the socket, so we should change this back to
- // just being an ACK and a transition to CloseWait once we have a
- // shutdown() implementation.
- socket->send_tcp_packet(TCPFlags::FIN | TCPFlags::ACK);
- socket->set_state(TCPSocket::State::Closing);
+ socket->send_tcp_packet(TCPFlags::ACK);
+ socket->set_state(TCPSocket::State::CloseWait);
socket->set_connected(false);
return;
}