From 1c94b5e8eb9723149a76ef54d38224c995c1a765 Mon Sep 17 00:00:00 2001 From: Liav A Date: Fri, 4 Jun 2021 07:43:16 +0300 Subject: Kernel: Introduce the NetworkingManagement singleton Instead of initializing network adapters in init.cpp, let's move that logic into a separate class to handle this. Also, it seems like a good idea to shift responsiblity on enumeration of network adapters after the boot process, so this singleton will take care of finding the appropriate network adapter when asked to with an IPv4 address or interface name. With this change being merged, we simplify the creation logic of NetworkAdapter derived classes, so we enumerate the PCI bus only once, searching for driver candidates when doing so, and we let each driver to test if it is resposible for the specified PCI device. --- Kernel/Net/Routing.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'Kernel/Net/Routing.cpp') diff --git a/Kernel/Net/Routing.cpp b/Kernel/Net/Routing.cpp index 41f7e94587..90d7d268fe 100644 --- a/Kernel/Net/Routing.cpp +++ b/Kernel/Net/Routing.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -142,9 +143,9 @@ RoutingDecision route_to(const IPv4Address& target, const IPv4Address& source, c }; if (target[0] == 0 && target[1] == 0 && target[2] == 0 && target[3] == 0) - return if_matches(LoopbackAdapter::the(), LoopbackAdapter::the().mac_address()); + return if_matches(*NetworkingManagement::the().loopback_adapter(), NetworkingManagement::the().loopback_adapter()->mac_address()); if (target[0] == 127) - return if_matches(LoopbackAdapter::the(), LoopbackAdapter::the().mac_address()); + return if_matches(*NetworkingManagement::the().loopback_adapter(), NetworkingManagement::the().loopback_adapter()->mac_address()); auto target_addr = target.to_u32(); auto source_addr = source.to_u32(); @@ -152,12 +153,12 @@ RoutingDecision route_to(const IPv4Address& target, const IPv4Address& source, c RefPtr local_adapter = nullptr; RefPtr gateway_adapter = nullptr; - NetworkAdapter::for_each([source_addr, &target_addr, &local_adapter, &gateway_adapter, &matches, &through](auto& adapter) { + NetworkingManagement::the().for_each([source_addr, &target_addr, &local_adapter, &gateway_adapter, &matches, &through](NetworkAdapter& adapter) { auto adapter_addr = adapter.ipv4_address().to_u32(); auto adapter_mask = adapter.ipv4_netmask().to_u32(); if (target_addr == adapter_addr) { - local_adapter = LoopbackAdapter::the(); + local_adapter = NetworkingManagement::the().loopback_adapter(); return; } @@ -213,7 +214,7 @@ RoutingDecision route_to(const IPv4Address& target, const IPv4Address& source, c if (target_addr == 0xffffffff && matches(adapter)) return { adapter, { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } }; - if (adapter == LoopbackAdapter::the()) + if (adapter == NetworkingManagement::the().loopback_adapter()) return { adapter, adapter->mac_address() }; if ((target_addr & IPv4Address { 240, 0, 0, 0 }.to_u32()) == IPv4Address { 224, 0, 0, 0 }.to_u32()) -- cgit v1.2.3