Kernel: Cleanup network code and implement basic ARP request
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <BAN/HashMap.h>
|
||||
#include <BAN/IPv4.h>
|
||||
#include <BAN/MAC.h>
|
||||
#include <BAN/UniqPtr.h>
|
||||
#include <kernel/Networking/NetworkInterface.h>
|
||||
|
||||
namespace Kernel
|
||||
{
|
||||
@@ -16,14 +15,28 @@ namespace Kernel
|
||||
public:
|
||||
static BAN::ErrorOr<BAN::UniqPtr<ARPTable>> create();
|
||||
|
||||
BAN::ErrorOr<BAN::MACAddress> get_mac_from_ipv4(BAN::IPv4Address);
|
||||
BAN::ErrorOr<BAN::MACAddress> get_mac_from_ipv4(NetworkInterface&, BAN::IPv4Address);
|
||||
|
||||
void handle_arp_packet(BAN::ConstByteSpan);
|
||||
|
||||
private:
|
||||
ARPTable();
|
||||
|
||||
private:
|
||||
struct ARPReply
|
||||
{
|
||||
BAN::IPv4Address ipv4_address { 0 };
|
||||
BAN::MACAddress mac_address;
|
||||
};
|
||||
|
||||
private:
|
||||
SpinLock m_lock;
|
||||
|
||||
BAN::HashMap<BAN::IPv4Address, BAN::MACAddress> m_arp_table;
|
||||
|
||||
BAN::Atomic<bool> m_has_got_reply;
|
||||
ARPReply m_reply;
|
||||
|
||||
friend class BAN::UniqPtr<ARPTable>;
|
||||
};
|
||||
|
||||
|
||||
@@ -9,6 +9,20 @@
|
||||
namespace Kernel
|
||||
{
|
||||
|
||||
struct EthernetHeader
|
||||
{
|
||||
BAN::MACAddress dst_mac;
|
||||
BAN::MACAddress src_mac;
|
||||
BAN::NetworkEndian<uint16_t> ether_type;
|
||||
};
|
||||
static_assert(sizeof(EthernetHeader) == 14);
|
||||
|
||||
enum EtherType : uint16_t
|
||||
{
|
||||
IPv4 = 0x0800,
|
||||
ARP = 0x0806,
|
||||
};
|
||||
|
||||
class NetworkInterface : public CharacterDevice
|
||||
{
|
||||
BAN_NON_COPYABLE(NetworkInterface);
|
||||
|
||||
@@ -9,6 +9,11 @@
|
||||
namespace Kernel
|
||||
{
|
||||
|
||||
enum NetworkProtocol : uint8_t
|
||||
{
|
||||
UDP = 0x11,
|
||||
};
|
||||
|
||||
class NetworkSocket : public TmpInode, public BAN::Weakable<NetworkSocket>
|
||||
{
|
||||
BAN_NON_COPYABLE(NetworkSocket);
|
||||
@@ -23,7 +28,7 @@ namespace Kernel
|
||||
|
||||
virtual size_t protocol_header_size() const = 0;
|
||||
virtual void add_protocol_header(BAN::ByteSpan packet, uint16_t src_port, uint16_t dst_port) = 0;
|
||||
virtual uint8_t protocol() const = 0;
|
||||
virtual NetworkProtocol protocol() const = 0;
|
||||
|
||||
virtual void add_packet(BAN::ConstByteSpan, BAN::IPv4Address sender_address, uint16_t sender_port) = 0;
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Kernel
|
||||
|
||||
virtual size_t protocol_header_size() const override { return sizeof(UDPHeader); }
|
||||
virtual void add_protocol_header(BAN::ByteSpan packet, uint16_t src_port, uint16_t dst_port) override;
|
||||
virtual uint8_t protocol() const override { return 0x11; }
|
||||
virtual NetworkProtocol protocol() const override { return NetworkProtocol::UDP; }
|
||||
|
||||
protected:
|
||||
virtual void add_packet(BAN::ConstByteSpan, BAN::IPv4Address sender_addr, uint16_t sender_port) override;
|
||||
|
||||
Reference in New Issue
Block a user