1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 04:58:13 +00:00

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.
This commit is contained in:
Andreas Kling 2020-10-21 20:51:02 +02:00
parent 91ea6057d6
commit a6aee0c097
4 changed files with 12 additions and 0 deletions

View file

@ -369,6 +369,8 @@ void handle_tcp(const IPv4Packet& ipv4_packet, const timeval& packet_timestamp)
return;
}
LOCKER(socket->lock());
ASSERT(socket->type() == SOCK_STREAM);
ASSERT(socket->local_port() == tcp_packet.destination_port());
@ -401,6 +403,7 @@ void handle_tcp(const IPv4Packet& ipv4_packet, const timeval& packet_timestamp)
klog() << "handle_tcp: couldn't create client socket";
return;
}
LOCKER(client->lock());
#ifdef TCP_DEBUG
klog() << "handle_tcp: created new client socket with tuple " << client->tuple().to_string().characters();
#endif