2024-02-01 23:38:06 +02:00
|
|
|
#pragma once
|
|
|
|
|
2024-02-02 01:31:58 +02:00
|
|
|
#include <BAN/WeakPtr.h>
|
2024-02-08 02:28:19 +02:00
|
|
|
#include <kernel/FS/Socket.h>
|
2024-02-01 23:38:06 +02:00
|
|
|
#include <kernel/FS/TmpFS/Inode.h>
|
|
|
|
#include <kernel/Networking/NetworkInterface.h>
|
2024-02-06 12:30:01 +02:00
|
|
|
#include <kernel/Networking/NetworkLayer.h>
|
2024-02-01 23:38:06 +02:00
|
|
|
|
|
|
|
namespace Kernel
|
|
|
|
{
|
|
|
|
|
2024-02-03 02:39:26 +02:00
|
|
|
enum NetworkProtocol : uint8_t
|
|
|
|
{
|
2024-02-06 12:30:01 +02:00
|
|
|
ICMP = 0x01,
|
2024-02-03 02:39:26 +02:00
|
|
|
UDP = 0x11,
|
|
|
|
};
|
|
|
|
|
2024-02-02 01:31:58 +02:00
|
|
|
class NetworkSocket : public TmpInode, public BAN::Weakable<NetworkSocket>
|
2024-02-01 23:38:06 +02:00
|
|
|
{
|
2024-02-03 01:26:06 +02:00
|
|
|
BAN_NON_COPYABLE(NetworkSocket);
|
|
|
|
BAN_NON_MOVABLE(NetworkSocket);
|
|
|
|
|
2024-02-02 03:16:01 +02:00
|
|
|
public:
|
|
|
|
static constexpr uint16_t PORT_NONE = 0;
|
|
|
|
|
2024-02-01 23:38:06 +02:00
|
|
|
public:
|
2024-02-02 01:31:58 +02:00
|
|
|
void bind_interface_and_port(NetworkInterface*, uint16_t port);
|
|
|
|
~NetworkSocket();
|
2024-02-01 23:38:06 +02:00
|
|
|
|
2024-02-06 12:30:01 +02:00
|
|
|
NetworkInterface& interface() { ASSERT(m_interface); return *m_interface; }
|
|
|
|
|
2024-02-02 13:50:00 +02:00
|
|
|
virtual size_t protocol_header_size() const = 0;
|
2024-02-08 18:33:49 +02:00
|
|
|
virtual void add_protocol_header(BAN::ByteSpan packet, uint16_t dst_port, PseudoHeader) = 0;
|
2024-02-03 02:39:26 +02:00
|
|
|
virtual NetworkProtocol protocol() const = 0;
|
2024-02-02 03:16:01 +02:00
|
|
|
|
2024-02-09 17:05:07 +02:00
|
|
|
virtual void receive_packet(BAN::ConstByteSpan, const sockaddr_storage& sender) = 0;
|
|
|
|
|
|
|
|
bool is_bound() const { return m_interface != nullptr; }
|
2024-02-02 13:50:00 +02:00
|
|
|
|
2024-02-01 23:38:06 +02:00
|
|
|
protected:
|
2024-02-06 12:30:01 +02:00
|
|
|
NetworkSocket(NetworkLayer&, ino_t, const TmpInodeInfo&);
|
2024-02-01 23:38:06 +02:00
|
|
|
|
2024-02-03 01:24:55 +02:00
|
|
|
virtual BAN::ErrorOr<long> ioctl_impl(int request, void* arg) override;
|
|
|
|
|
2024-02-01 23:38:06 +02:00
|
|
|
protected:
|
2024-02-06 12:30:01 +02:00
|
|
|
NetworkLayer& m_network_layer;
|
2024-02-02 03:16:01 +02:00
|
|
|
NetworkInterface* m_interface = nullptr;
|
2024-02-09 17:05:07 +02:00
|
|
|
uint16_t m_port { PORT_NONE };
|
2024-02-01 23:38:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|