summaryrefslogtreecommitdiff
path: root/Kernel/Net/IPv4Socket.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-10-21 20:51:02 +0200
committerAndreas Kling <kling@serenityos.org>2020-10-21 20:51:02 +0200
commita6aee0c097ed244582ef7e1ed4d45a453ddb6302 (patch)
tree344295cde7f958440ed2d6bebca658696fa282d9 /Kernel/Net/IPv4Socket.cpp
parent91ea6057d632184c1969a6ffcba314c0623875f4 (diff)
downloadserenity-a6aee0c097ed244582ef7e1ed4d45a453ddb6302.zip
IPv4: Take the socket lock more (fixes TCP connection to localhost)
This fixes an issue where making a TCP connection to localhost didn't work correctly since the loopback interface is currently synchronous. (Sending something to localhost would enqueue a packet on the same interface and then immediately wake the network task to process that packet.) This was preventing the TCP handshake from working correctly with localhost since we'd send out the SYN packet before moving to the SynSent state. The lock is now held long enough for this operation to be atomic.
Diffstat (limited to 'Kernel/Net/IPv4Socket.cpp')
-rw-r--r--Kernel/Net/IPv4Socket.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp
index 459a9f2477..98d400456e 100644
--- a/Kernel/Net/IPv4Socket.cpp
+++ b/Kernel/Net/IPv4Socket.cpp
@@ -131,6 +131,7 @@ KResult IPv4Socket::bind(Userspace<const sockaddr*> user_address, socklen_t addr
KResult IPv4Socket::listen(size_t backlog)
{
+ LOCKER(lock());
int rc = allocate_local_port_if_needed();
if (rc < 0)
return KResult(-EADDRINUSE);
@@ -203,6 +204,8 @@ int IPv4Socket::allocate_local_port_if_needed()
KResultOr<size_t> IPv4Socket::sendto(FileDescription&, const UserOrKernelBuffer& data, size_t data_length, int flags, Userspace<const sockaddr*> addr, socklen_t addr_length)
{
+ LOCKER(lock());
+
(void)flags;
if (addr && addr_length != sizeof(sockaddr_in))
return KResult(-EINVAL);