From 6fbb924bbffaf85ac64f2574225aaafef3692bf0 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 3 Feb 2022 01:07:57 +0100 Subject: Kernel: Protect ARP table with spinlock instead of mutex --- Kernel/Net/Routing.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'Kernel/Net/Routing.cpp') diff --git a/Kernel/Net/Routing.cpp b/Kernel/Net/Routing.cpp index 3e5d066301..46d57744de 100644 --- a/Kernel/Net/Routing.cpp +++ b/Kernel/Net/Routing.cpp @@ -16,7 +16,7 @@ namespace Kernel { -static Singleton>> s_arp_table; +static Singleton>> s_arp_table; class ARPTableBlocker final : public Thread::Blocker { public: @@ -70,7 +70,7 @@ protected: { VERIFY(b.blocker_type() == Thread::Blocker::Type::Routing); auto& blocker = static_cast(b); - auto maybe_mac_address = arp_table().with_shared([&](auto const& table) -> auto { + auto maybe_mac_address = arp_table().with([&](auto const& table) -> auto { return table.get(blocker.ip_address()); }); if (!maybe_mac_address.has_value()) @@ -94,7 +94,7 @@ bool ARPTableBlocker::setup_blocker() void ARPTableBlocker::will_unblock_immediately_without_blocking(UnblockImmediatelyReason) { - auto addr = arp_table().with_shared([&](auto const& table) -> auto { + auto addr = arp_table().with([&](auto const& table) -> auto { return table.get(ip_address()); }); @@ -105,14 +105,14 @@ void ARPTableBlocker::will_unblock_immediately_without_blocking(UnblockImmediate } } -MutexProtected>& arp_table() +SpinlockProtected>& arp_table() { return *s_arp_table; } void update_arp_table(IPv4Address const& ip_addr, MACAddress const& addr, UpdateArp update) { - arp_table().with_exclusive([&](auto& table) { + arp_table().with([&](auto& table) { if (update == UpdateArp::Set) table.set(ip_addr, addr); if (update == UpdateArp::Delete) @@ -121,7 +121,7 @@ void update_arp_table(IPv4Address const& ip_addr, MACAddress const& addr, Update s_arp_table_blocker_set->unblock_blockers_waiting_for_ipv4_address(ip_addr, addr); if constexpr (ARP_DEBUG) { - arp_table().with_shared([&](auto const& table) { + arp_table().with([&](auto const& table) { dmesgln("ARP table ({} entries):", table.size()); for (auto& it : table) dmesgln("{} :: {}", it.value.to_string(), it.key.to_string()); @@ -232,7 +232,7 @@ RoutingDecision route_to(IPv4Address const& target, IPv4Address const& source, R return { adapter, multicast_ethernet_address(target) }; { - auto addr = arp_table().with_shared([&](auto const& table) -> auto { + auto addr = arp_table().with([&](auto const& table) -> auto { return table.get(next_hop_ip); }); if (addr.has_value()) { -- cgit v1.2.3