diff options
author | Liav A <liavalb@gmail.com> | 2023-04-11 03:50:15 +0300 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-04-14 19:27:56 +0200 |
commit | 7c1f645e27038eb12e2e46ea0103cc04c96edbb8 (patch) | |
tree | 4624c34cec0b0477dd0cf4fc9181163e17373d19 /Kernel/Net/NetworkTask.cpp | |
parent | bd7d4513bfcc250c472c84365649f522b074816f (diff) | |
download | serenity-7c1f645e27038eb12e2e46ea0103cc04c96edbb8.zip |
Kernel/Net: Iron out the locking mechanism across the subsystem
There is a big mix of LockRefPtrs all over the Networking subsystem, as
well as lots of room for improvements with our locking patterns, which
this commit will not pursue, but will give a good start for such work.
To deal with this situation, we change the following things:
- Creating instances of NetworkAdapter should always yield a non-locking
NonnullRefPtr. Acquiring an instance from the NetworkingManagement
should give a simple RefPtr,as giving LockRefPtr does not really
protect from concurrency problems in such case.
- Since NetworkingManagement works with normal RefPtrs we should
protect all instances of RefPtr<NetworkAdapter> with SpinlockProtected
to ensure references are gone unexpectedly.
- Protect the so_error class member with a proper spinlock. This happens
to be important because the clear_so_error() method lacked any proper
locking measures. It also helps preventing a possible TOCTOU when we
might do a more fine-grained locking in the Socket code, so this could
be definitely a start for this.
- Change unnecessary LockRefPtr<PacketWithTimestamp> in the structure
of OutgoingPacket to a simple RefPtr<PacketWithTimestamp> as the whole
list should be MutexProtected.
Diffstat (limited to 'Kernel/Net/NetworkTask.cpp')
-rw-r--r-- | Kernel/Net/NetworkTask.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/Kernel/Net/NetworkTask.cpp b/Kernel/Net/NetworkTask.cpp index b5de06dda8..a89860452c 100644 --- a/Kernel/Net/NetworkTask.cpp +++ b/Kernel/Net/NetworkTask.cpp @@ -31,7 +31,7 @@ static void handle_icmp(EthernetFrameHeader const&, IPv4Packet const&, Time cons static void handle_udp(IPv4Packet const&, Time const& packet_timestamp); static void handle_tcp(IPv4Packet const&, Time const& packet_timestamp); static void send_delayed_tcp_ack(TCPSocket& socket); -static void send_tcp_rst(IPv4Packet const& ipv4_packet, TCPPacket const& tcp_packet, LockRefPtr<NetworkAdapter> adapter); +static void send_tcp_rst(IPv4Packet const& ipv4_packet, TCPPacket const& tcp_packet, RefPtr<NetworkAdapter> adapter); static void flush_delayed_tcp_acks(); static void retransmit_tcp_packets(); @@ -333,7 +333,7 @@ void flush_delayed_tcp_acks() } } -void send_tcp_rst(IPv4Packet const& ipv4_packet, TCPPacket const& tcp_packet, LockRefPtr<NetworkAdapter> adapter) +void send_tcp_rst(IPv4Packet const& ipv4_packet, TCPPacket const& tcp_packet, RefPtr<NetworkAdapter> adapter) { auto routing_decision = route_to(ipv4_packet.source(), ipv4_packet.destination(), adapter); if (routing_decision.is_zero()) |