Kernel: Start work on network stack

This commit is contained in:
2024-02-01 23:38:06 +02:00
parent f4e86028d0
commit 99eed9c37a
10 changed files with 224 additions and 27 deletions

View File

@@ -0,0 +1,39 @@
#pragma once
#include <BAN/Vector.h>
#include <kernel/FS/TmpFS/FileSystem.h>
#include <kernel/Networking/NetworkInterface.h>
#include <kernel/Networking/NetworkSocket.h>
#include <kernel/PCI.h>
namespace Kernel
{
class NetworkManager : public TmpFileSystem
{
public:
enum class SocketType
{
STREAM,
DGRAM,
SEQPACKET,
};
public:
static BAN::ErrorOr<void> initialize();
static NetworkManager& get();
BAN::ErrorOr<void> add_interface(PCI::Device& pci_device);
BAN::ErrorOr<void> bind_socket(int port, BAN::RefPtr<NetworkSocket>);
BAN::ErrorOr<BAN::RefPtr<NetworkSocket>> create_socket(SocketType, mode_t, uid_t, gid_t);
private:
NetworkManager();
private:
BAN::Vector<BAN::RefPtr<NetworkInterface>> m_interfaces;
BAN::HashMap<int, BAN::RefPtr<NetworkSocket>> m_bound_sockets;
};
}

View File

@@ -0,0 +1,21 @@
#pragma once
#include <kernel/FS/TmpFS/Inode.h>
#include <kernel/Networking/NetworkInterface.h>
namespace Kernel
{
class NetworkSocket : public TmpInode
{
public:
void bind_interface(NetworkInterface*);
protected:
NetworkSocket(mode_t mode, uid_t uid, gid_t gid);
protected:
NetworkInterface* m_interface = nullptr;
};
}

View File

@@ -0,0 +1,29 @@
#pragma once
#include <kernel/Networking/NetworkInterface.h>
#include <kernel/Networking/NetworkSocket.h>
namespace Kernel
{
class UDPSocket final : public NetworkSocket
{
public:
static BAN::ErrorOr<BAN::RefPtr<UDPSocket>> create(mode_t, uid_t, gid_t);
void bind_interface(NetworkInterface*);
protected:
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override;
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override;
private:
UDPSocket(mode_t, uid_t, gid_t);
private:
NetworkInterface* m_interface = nullptr;
friend class BAN::RefPtr<UDPSocket>;
};
}