summaryrefslogtreecommitdiff
path: root/Kernel/Net/NetworkTask.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/NetworkTask.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/NetworkTask.cpp')
-rw-r--r--Kernel/Net/NetworkTask.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/Kernel/Net/NetworkTask.cpp b/Kernel/Net/NetworkTask.cpp
index 99c5f7bc2c..f65d846b4e 100644
--- a/Kernel/Net/NetworkTask.cpp
+++ b/Kernel/Net/NetworkTask.cpp
@@ -14,6 +14,7 @@
#include <Kernel/Net/IPv4Socket.h>
#include <Kernel/Net/LoopbackAdapter.h>
#include <Kernel/Net/NetworkTask.h>
+#include <Kernel/Net/NetworkingManagement.h>
#include <Kernel/Net/Routing.h>
#include <Kernel/Net/TCP.h>
#include <Kernel/Net/TCPSocket.h>
@@ -55,7 +56,7 @@ void NetworkTask_main(void*)
WaitQueue packet_wait_queue;
int pending_packets = 0;
- NetworkAdapter::for_each([&](auto& adapter) {
+ NetworkingManagement::the().for_each([&](auto& adapter) {
dmesgln("NetworkTask: {} network adapter found: hw={}", adapter.class_name(), adapter.mac_address().to_string());
if (String(adapter.class_name()) == "LoopbackAdapter") {
@@ -74,7 +75,7 @@ void NetworkTask_main(void*)
if (pending_packets == 0)
return 0;
size_t packet_size = 0;
- NetworkAdapter::for_each([&](auto& adapter) {
+ NetworkingManagement::the().for_each([&](auto& adapter) {
if (packet_size || !adapter.has_queued_packets())
return;
packet_size = adapter.dequeue_packet(buffer, buffer_size, packet_timestamp);
@@ -155,7 +156,7 @@ void handle_arp(const EthernetFrameHeader& eth, size_t frame_size)
if (packet.operation() == ARPOperation::Request) {
// Who has this IP address?
- if (auto adapter = NetworkAdapter::from_ipv4_address(packet.target_protocol_address())) {
+ if (auto adapter = NetworkingManagement::the().from_ipv4_address(packet.target_protocol_address())) {
// We do!
dbgln("handle_arp: Responding to ARP request for my IPv4 address ({})", adapter->ipv4_address());
ARPPacket response;
@@ -193,7 +194,7 @@ void handle_ipv4(const EthernetFrameHeader& eth, size_t frame_size, const Time&
dbgln_if(IPV4_DEBUG, "handle_ipv4: source={}, destination={}", packet.source(), packet.destination());
- NetworkAdapter::for_each([&](auto& adapter) {
+ NetworkingManagement::the().for_each([&](auto& adapter) {
if (adapter.link_up()) {
auto my_net = adapter.ipv4_address().to_u32() & adapter.ipv4_netmask().to_u32();
auto their_net = packet.source().to_u32() & adapter.ipv4_netmask().to_u32();
@@ -234,7 +235,7 @@ void handle_icmp(const EthernetFrameHeader& eth, const IPv4Packet& ipv4_packet,
socket.did_receive(ipv4_packet.source(), 0, { &ipv4_packet, sizeof(IPv4Packet) + ipv4_packet.payload_size() }, packet_timestamp);
}
- auto adapter = NetworkAdapter::from_ipv4_address(ipv4_packet.destination());
+ auto adapter = NetworkingManagement::the().from_ipv4_address(ipv4_packet.destination());
if (!adapter)
return;
@@ -292,7 +293,7 @@ void handle_udp(const IPv4Packet& ipv4_packet, const Time& packet_timestamp)
auto& destination = ipv4_packet.destination();
- if (destination == IPv4Address(255, 255, 255, 255) || NetworkAdapter::from_ipv4_address(destination) || socket->multicast_memberships().contains_slow(destination))
+ if (destination == IPv4Address(255, 255, 255, 255) || NetworkingManagement::the().from_ipv4_address(destination) || socket->multicast_memberships().contains_slow(destination))
socket->did_receive(ipv4_packet.source(), udp_packet.source_port(), { &ipv4_packet, sizeof(IPv4Packet) + ipv4_packet.payload_size() }, packet_timestamp);
}
@@ -365,7 +366,7 @@ void handle_tcp(const IPv4Packet& ipv4_packet, const Time& packet_timestamp)
tcp_packet.window_size(),
payload_size);
- auto adapter = NetworkAdapter::from_ipv4_address(ipv4_packet.destination());
+ auto adapter = NetworkingManagement::the().from_ipv4_address(ipv4_packet.destination());
if (!adapter) {
dbgln("handle_tcp: this packet is not for me, it's for {}", ipv4_packet.destination());
return;