From dd3641f0544cdcf29dcc1f248c5992ec2d733fa9 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Mon, 5 Feb 2024 17:37:23 +0200 Subject: [PATCH] Kernel: Cleanup ARPTable code Packet process is now killed if ARPTable dies. ARP wait loop now just reschecules so timeout actually works. --- kernel/include/kernel/Networking/ARPTable.h | 1 + kernel/kernel/Networking/ARPTable.cpp | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/kernel/include/kernel/Networking/ARPTable.h b/kernel/include/kernel/Networking/ARPTable.h index 499bbd393d..ab4e99a684 100644 --- a/kernel/include/kernel/Networking/ARPTable.h +++ b/kernel/include/kernel/Networking/ARPTable.h @@ -31,6 +31,7 @@ namespace Kernel public: static BAN::ErrorOr> create(); + ~ARPTable(); BAN::ErrorOr get_mac_from_ipv4(NetworkInterface&, BAN::IPv4Address); diff --git a/kernel/kernel/Networking/ARPTable.cpp b/kernel/kernel/Networking/ARPTable.cpp index ff9cdc4d6d..b9f23842e7 100644 --- a/kernel/kernel/Networking/ARPTable.cpp +++ b/kernel/kernel/Networking/ARPTable.cpp @@ -1,5 +1,6 @@ #include #include +#include #include namespace Kernel @@ -32,12 +33,20 @@ namespace Kernel { } + ARPTable::~ARPTable() + { + if (m_process) + m_process->exit(0, SIGKILL); + m_process = nullptr; + } + BAN::ErrorOr ARPTable::get_mac_from_ipv4(NetworkInterface& interface, BAN::IPv4Address ipv4_address) { + if (ipv4_address == s_broadcast_ipv4) + return s_broadcast_mac; + { LockGuard _(m_lock); - if (ipv4_address == s_broadcast_ipv4) - return s_broadcast_mac; if (m_arp_table.contains(ipv4_address)) return m_arp_table[ipv4_address]; } @@ -64,7 +73,7 @@ namespace Kernel TRY(interface.send_raw_bytes(full_packet)); - uint64_t timeout = SystemTimer::get().ms_since_boot() + 5'000; + uint64_t timeout = SystemTimer::get().ms_since_boot() + 1'000; while (SystemTimer::get().ms_since_boot() < timeout) { { @@ -72,10 +81,10 @@ namespace Kernel if (m_arp_table.contains(ipv4_address)) return m_arp_table[ipv4_address]; } - TRY(Thread::current().block_or_eintr(m_pending_semaphore)); + Scheduler::get().reschedule(); } - return BAN::Error::from_errno(EINVAL); + return BAN::Error::from_errno(ETIMEDOUT); } BAN::ErrorOr ARPTable::handle_arp_packet(NetworkInterface& interface, const ARPPacket& packet)