diff --git a/Kernel/Net/NetworkTask.cpp b/Kernel/Net/NetworkTask.cpp index 4ab97a1982..7757fb040f 100644 --- a/Kernel/Net/NetworkTask.cpp +++ b/Kernel/Net/NetworkTask.cpp @@ -29,12 +29,20 @@ static void handle_icmp(const EthernetFrameHeader&, const IPv4Packet&, const Tim static void handle_udp(const IPv4Packet&, const Time& packet_timestamp); static void handle_tcp(const IPv4Packet&, const Time& packet_timestamp); +static Thread* network_task = nullptr; + [[noreturn]] static void NetworkTask_main(void*); void NetworkTask::spawn() { RefPtr thread; Process::create_kernel_process(thread, "NetworkTask", NetworkTask_main, nullptr); + network_task = thread; +} + +bool NetworkTask::is_current() +{ + return Thread::current() == network_task; } void NetworkTask_main(void*) diff --git a/Kernel/Net/NetworkTask.h b/Kernel/Net/NetworkTask.h index eea9508c23..821c85b430 100644 --- a/Kernel/Net/NetworkTask.h +++ b/Kernel/Net/NetworkTask.h @@ -10,5 +10,6 @@ namespace Kernel { class NetworkTask { public: static void spawn(); + static bool is_current(); }; } diff --git a/Kernel/Net/Routing.cpp b/Kernel/Net/Routing.cpp index 8e434d290c..28e44057dd 100644 --- a/Kernel/Net/Routing.cpp +++ b/Kernel/Net/Routing.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -216,6 +217,13 @@ RoutingDecision route_to(const IPv4Address& target, const IPv4Address& source, c request.set_sender_protocol_address(adapter->ipv4_address()); adapter->send({ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, request); + if (NetworkTask::is_current()) { + // FIXME: Waiting for the ARP response from inside the NetworkTask would + // deadlock, so let's hope that whoever called route_to() tries again in a bit. + dbgln_if(ROUTING_DEBUG, "Routing: Not waiting for ARP response from inside NetworkTask, sent ARP request using adapter {} for {}", adapter->name(), target); + return { nullptr, {} }; + } + Optional addr; if (!Thread::current()->block({}, next_hop_ip, addr).was_interrupted()) { if (addr.has_value()) { diff --git a/Kernel/Net/TCPSocket.cpp b/Kernel/Net/TCPSocket.cpp index 58322e3199..f41cfa8812 100644 --- a/Kernel/Net/TCPSocket.cpp +++ b/Kernel/Net/TCPSocket.cpp @@ -197,7 +197,8 @@ KResult TCPSocket::send_tcp_packet(u16 flags, const UserOrKernelBuffer* payload, } auto routing_decision = route_to(peer_address(), local_address(), bound_interface()); - VERIFY(!routing_decision.is_zero()); + if (routing_decision.is_zero()) + return EHOSTUNREACH; auto packet_buffer = UserOrKernelBuffer::for_kernel_buffer(buffer.data()); auto result = routing_decision.adapter->send_ipv4( @@ -214,7 +215,8 @@ KResult TCPSocket::send_tcp_packet(u16 flags, const UserOrKernelBuffer* payload, void TCPSocket::send_outgoing_packets() { auto routing_decision = route_to(peer_address(), local_address(), bound_interface()); - VERIFY(!routing_decision.is_zero()); + if (routing_decision.is_zero()) + return; auto now = kgettimeofday();