mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06:58:11 +00:00
Kernel: Migrate IPv4 socket table locking to ProtectedValue
This commit is contained in:
parent
edd6c04024
commit
583abc27d8
4 changed files with 15 additions and 15 deletions
|
@ -26,11 +26,11 @@
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
static AK::Singleton<Lockable<HashTable<IPv4Socket*>>> s_table;
|
static AK::Singleton<ProtectedValue<HashTable<IPv4Socket*>>> s_table;
|
||||||
|
|
||||||
using BlockFlags = Thread::FileDescriptionBlocker::BlockFlags;
|
using BlockFlags = Thread::FileDescriptionBlocker::BlockFlags;
|
||||||
|
|
||||||
Lockable<HashTable<IPv4Socket*>>& IPv4Socket::all_sockets()
|
ProtectedValue<HashTable<IPv4Socket*>>& IPv4Socket::all_sockets()
|
||||||
{
|
{
|
||||||
return *s_table;
|
return *s_table;
|
||||||
}
|
}
|
||||||
|
@ -77,14 +77,17 @@ IPv4Socket::IPv4Socket(int type, int protocol, NonnullOwnPtr<DoubleBuffer> recei
|
||||||
if (m_buffer_mode == BufferMode::Bytes) {
|
if (m_buffer_mode == BufferMode::Bytes) {
|
||||||
VERIFY(m_scratch_buffer);
|
VERIFY(m_scratch_buffer);
|
||||||
}
|
}
|
||||||
MutexLocker locker(all_sockets().lock());
|
|
||||||
all_sockets().resource().set(this);
|
all_sockets().with_exclusive([&](auto& table) {
|
||||||
|
table.set(this);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
IPv4Socket::~IPv4Socket()
|
IPv4Socket::~IPv4Socket()
|
||||||
{
|
{
|
||||||
MutexLocker locker(all_sockets().lock());
|
all_sockets().with_exclusive([&](auto& table) {
|
||||||
all_sockets().resource().remove(this);
|
table.remove(this);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void IPv4Socket::get_local_address(sockaddr* address, socklen_t* address_size)
|
void IPv4Socket::get_local_address(sockaddr* address, socklen_t* address_size)
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#include <AK/SinglyLinkedListWithCount.h>
|
#include <AK/SinglyLinkedListWithCount.h>
|
||||||
#include <Kernel/DoubleBuffer.h>
|
#include <Kernel/DoubleBuffer.h>
|
||||||
#include <Kernel/KBuffer.h>
|
#include <Kernel/KBuffer.h>
|
||||||
#include <Kernel/Locking/Lockable.h>
|
#include <Kernel/Locking/ProtectedValue.h>
|
||||||
#include <Kernel/Net/IPv4.h>
|
#include <Kernel/Net/IPv4.h>
|
||||||
#include <Kernel/Net/IPv4SocketTuple.h>
|
#include <Kernel/Net/IPv4SocketTuple.h>
|
||||||
#include <Kernel/Net/Socket.h>
|
#include <Kernel/Net/Socket.h>
|
||||||
|
@ -31,7 +31,7 @@ public:
|
||||||
static KResultOr<NonnullRefPtr<Socket>> create(int type, int protocol);
|
static KResultOr<NonnullRefPtr<Socket>> create(int type, int protocol);
|
||||||
virtual ~IPv4Socket() override;
|
virtual ~IPv4Socket() override;
|
||||||
|
|
||||||
static Lockable<HashTable<IPv4Socket*>>& all_sockets();
|
static ProtectedValue<HashTable<IPv4Socket*>>& all_sockets();
|
||||||
|
|
||||||
virtual KResult close() override;
|
virtual KResult close() override;
|
||||||
virtual KResult bind(Userspace<const sockaddr*>, socklen_t) override;
|
virtual KResult bind(Userspace<const sockaddr*>, socklen_t) override;
|
||||||
|
|
|
@ -223,14 +223,10 @@ void handle_icmp(EthernetFrameHeader const& eth, IPv4Packet const& ipv4_packet,
|
||||||
|
|
||||||
{
|
{
|
||||||
NonnullRefPtrVector<IPv4Socket> icmp_sockets;
|
NonnullRefPtrVector<IPv4Socket> icmp_sockets;
|
||||||
{
|
IPv4Socket::all_sockets().for_each_shared([&](const auto& socket) {
|
||||||
MutexLocker locker(IPv4Socket::all_sockets().lock(), Mutex::Mode::Shared);
|
if (socket->protocol() == (unsigned)IPv4Protocol::ICMP)
|
||||||
for (auto* socket : IPv4Socket::all_sockets().resource()) {
|
|
||||||
if (socket->protocol() != (unsigned)IPv4Protocol::ICMP)
|
|
||||||
continue;
|
|
||||||
icmp_sockets.append(*socket);
|
icmp_sockets.append(*socket);
|
||||||
}
|
});
|
||||||
}
|
|
||||||
for (auto& socket : icmp_sockets)
|
for (auto& socket : icmp_sockets)
|
||||||
socket.did_receive(ipv4_packet.source(), 0, { &ipv4_packet, sizeof(IPv4Packet) + ipv4_packet.payload_size() }, packet_timestamp);
|
socket.did_receive(ipv4_packet.source(), 0, { &ipv4_packet, sizeof(IPv4Packet) + ipv4_packet.payload_size() }, packet_timestamp);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <AK/SinglyLinkedList.h>
|
#include <AK/SinglyLinkedList.h>
|
||||||
#include <AK/WeakPtr.h>
|
#include <AK/WeakPtr.h>
|
||||||
#include <Kernel/KResult.h>
|
#include <Kernel/KResult.h>
|
||||||
|
#include <Kernel/Locking/Lockable.h>
|
||||||
#include <Kernel/Net/IPv4Socket.h>
|
#include <Kernel/Net/IPv4Socket.h>
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue