summaryrefslogtreecommitdiff
path: root/Kernel/Net/Routing.cpp
diff options
context:
space:
mode:
authorLiav A <liavalb@gmail.com>2021-06-04 07:43:16 +0300
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-06-09 22:44:09 +0430
commit1c94b5e8eb9723149a76ef54d38224c995c1a765 (patch)
treeaee54ac8ce3e7f2195f3a575aa8848e0e7635343 /Kernel/Net/Routing.cpp
parent8b1d4d1b8ea7cc0a801b097c977f4d39a39ba5aa (diff)
downloadserenity-1c94b5e8eb9723149a76ef54d38224c995c1a765.zip
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.
Diffstat (limited to 'Kernel/Net/Routing.cpp')
-rw-r--r--Kernel/Net/Routing.cpp11
1 files changed, 6 insertions, 5 deletions
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 <Kernel/Debug.h>
#include <Kernel/Net/LoopbackAdapter.h>
#include <Kernel/Net/NetworkTask.h>
+#include <Kernel/Net/NetworkingManagement.h>
#include <Kernel/Net/Routing.h>
#include <Kernel/Thread.h>
@@ -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<NetworkAdapter> local_adapter = nullptr;
RefPtr<NetworkAdapter> 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())