Kernel: Implement barebones arp table
This commit is contained in:
30
kernel/include/kernel/Networking/ARPTable.h
Normal file
30
kernel/include/kernel/Networking/ARPTable.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <BAN/HashMap.h>
|
||||
#include <BAN/IPv4.h>
|
||||
#include <BAN/MAC.h>
|
||||
#include <BAN/UniqPtr.h>
|
||||
|
||||
namespace Kernel
|
||||
{
|
||||
|
||||
class ARPTable
|
||||
{
|
||||
BAN_NON_COPYABLE(ARPTable);
|
||||
BAN_NON_MOVABLE(ARPTable);
|
||||
|
||||
public:
|
||||
static BAN::ErrorOr<BAN::UniqPtr<ARPTable>> create();
|
||||
|
||||
BAN::ErrorOr<BAN::MACAddress> get_mac_from_ipv4(BAN::IPv4Address);
|
||||
|
||||
private:
|
||||
ARPTable();
|
||||
|
||||
private:
|
||||
BAN::HashMap<BAN::IPv4Address, BAN::MACAddress> m_arp_table;
|
||||
|
||||
friend class BAN::UniqPtr<ARPTable>;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <BAN/Vector.h>
|
||||
#include <kernel/FS/TmpFS/FileSystem.h>
|
||||
#include <kernel/Networking/ARPTable.h>
|
||||
#include <kernel/Networking/NetworkInterface.h>
|
||||
#include <kernel/Networking/NetworkSocket.h>
|
||||
#include <kernel/PCI.h>
|
||||
@@ -13,6 +14,9 @@ namespace Kernel
|
||||
|
||||
class NetworkManager : public TmpFileSystem
|
||||
{
|
||||
BAN_NON_COPYABLE(NetworkManager);
|
||||
BAN_NON_MOVABLE(NetworkManager);
|
||||
|
||||
public:
|
||||
enum class SocketType
|
||||
{
|
||||
@@ -25,6 +29,8 @@ namespace Kernel
|
||||
static BAN::ErrorOr<void> initialize();
|
||||
static NetworkManager& get();
|
||||
|
||||
ARPTable& arp_table() { return *m_arp_table; }
|
||||
|
||||
BAN::ErrorOr<void> add_interface(PCI::Device& pci_device);
|
||||
|
||||
void unbind_socket(uint16_t port, BAN::RefPtr<NetworkSocket>);
|
||||
@@ -38,6 +44,7 @@ namespace Kernel
|
||||
NetworkManager();
|
||||
|
||||
private:
|
||||
BAN::UniqPtr<ARPTable> m_arp_table;
|
||||
BAN::Vector<BAN::RefPtr<NetworkInterface>> m_interfaces;
|
||||
BAN::HashMap<int, BAN::WeakPtr<NetworkSocket>> m_bound_sockets;
|
||||
};
|
||||
|
||||
@@ -11,6 +11,9 @@ namespace Kernel
|
||||
|
||||
class NetworkSocket : public TmpInode, public BAN::Weakable<NetworkSocket>
|
||||
{
|
||||
BAN_NON_COPYABLE(NetworkSocket);
|
||||
BAN_NON_MOVABLE(NetworkSocket);
|
||||
|
||||
public:
|
||||
static constexpr uint16_t PORT_NONE = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user