2021-06-04 07:43:16 +03:00
|
|
|
/*
|
|
|
|
* 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>
|
2023-04-11 03:50:15 +03:00
|
|
|
#include <AK/RefPtr.h>
|
2021-06-04 07:43:16 +03:00
|
|
|
#include <AK/Types.h>
|
2021-06-25 09:46:17 +03:00
|
|
|
#include <Kernel/Bus/PCI/Definitions.h>
|
2022-02-03 03:33:19 +03:00
|
|
|
#include <Kernel/Locking/SpinlockProtected.h>
|
2021-08-06 11:45:34 +03:00
|
|
|
#include <Kernel/Memory/Region.h>
|
2022-08-18 22:46:28 +03:00
|
|
|
#include <Kernel/Net/NetworkAdapter.h>
|
2021-06-04 07:43:16 +03:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
|
|
|
class NetworkAdapter;
|
|
|
|
class NetworkingManagement {
|
|
|
|
friend class NetworkAdapter;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static NetworkingManagement& the();
|
|
|
|
static bool is_initialized();
|
|
|
|
bool initialize();
|
|
|
|
|
2023-08-12 00:41:18 +03:00
|
|
|
static ErrorOr<FixedStringBuffer<IFNAMSIZ>> generate_interface_name_from_pci_address(PCI::DeviceIdentifier const&);
|
2021-10-17 16:05:14 +03:00
|
|
|
|
2021-06-04 07:43:16 +03:00
|
|
|
NetworkingManagement();
|
|
|
|
|
|
|
|
void for_each(Function<void(NetworkAdapter&)>);
|
2022-02-24 21:04:32 +03:00
|
|
|
ErrorOr<void> try_for_each(Function<ErrorOr<void>(NetworkAdapter&)>);
|
2021-06-04 07:43:16 +03:00
|
|
|
|
2023-04-11 03:50:15 +03:00
|
|
|
RefPtr<NetworkAdapter> from_ipv4_address(IPv4Address const&) const;
|
|
|
|
RefPtr<NetworkAdapter> lookup_by_name(StringView) const;
|
2021-06-04 07:43:16 +03:00
|
|
|
|
2023-04-11 03:50:15 +03:00
|
|
|
NonnullRefPtr<NetworkAdapter> loopback_adapter() const;
|
2021-06-04 07:43:16 +03:00
|
|
|
|
|
|
|
private:
|
2023-04-11 03:41:49 +03:00
|
|
|
ErrorOr<NonnullRefPtr<NetworkAdapter>> determine_network_device(PCI::DeviceIdentifier const&) const;
|
2021-06-04 07:43:16 +03:00
|
|
|
|
2023-04-11 03:50:15 +03:00
|
|
|
SpinlockProtected<Vector<NonnullRefPtr<NetworkAdapter>>, LockRank::None> m_adapters {};
|
|
|
|
RefPtr<NetworkAdapter> m_loopback_adapter;
|
2021-06-04 07:43:16 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|