ladybird/Kernel/Net/NetworkingManagement.h
Liav A 1c94b5e8eb 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.
2021-06-09 22:44:09 +04:30

47 lines
1.1 KiB
C++

/*
* Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Function.h>
#include <AK/NonnullOwnPtr.h>
#include <AK/NonnullRefPtr.h>
#include <AK/NonnullRefPtrVector.h>
#include <AK/Types.h>
#include <Kernel/PCI/Definitions.h>
#include <Kernel/VM/Region.h>
namespace Kernel {
class NetworkAdapter;
class NetworkingManagement {
friend class NetworkAdapter;
AK_MAKE_ETERNAL
public:
static NetworkingManagement& the();
static bool is_initialized();
bool initialize();
NetworkingManagement();
void for_each(Function<void(NetworkAdapter&)>);
RefPtr<NetworkAdapter> from_ipv4_address(const IPv4Address&) const;
RefPtr<NetworkAdapter> lookup_by_name(const StringView&) const;
NonnullRefPtr<NetworkAdapter> loopback_adapter() const;
private:
RefPtr<NetworkAdapter> determine_network_device(PCI::Address address) const;
NonnullRefPtrVector<NetworkAdapter> m_adapters;
RefPtr<NetworkAdapter> m_loopback_adapter;
mutable Lock m_lock { "Networking" };
};
}