mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:47:45 +00:00
Kernel: Refactor TCP/IP stack
This has several significant changes to the networking stack. * Significant refactoring of the TCP state machine. Right now it's probably more fragile than it used to be, but handles quite a lot more of the handshake process. * `TCPSocket` holds a `NetworkAdapter*`, assigned during `connect()` or `bind()`, whichever comes first. * `listen()` is now virtual in `Socket` and intended to be implemented in its child classes * `listen()` no longer works without `bind()` - this is a bit of a regression, but listening sockets didn't work at all before, so it's not possible to observe the regression. * A file is exposed at `/proc/net_tcp`, which is a JSON document listing the current TCP sockets with a bit of metadata. * There's an `ETHERNET_VERY_DEBUG` flag for dumping packet's content out to `kprintf`. It is, indeed, _very debug_.
This commit is contained in:
parent
c973a51a23
commit
73c998dbfc
12 changed files with 446 additions and 84 deletions
|
@ -2,10 +2,11 @@
|
|||
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/SinglyLinkedList.h>
|
||||
#include <Kernel/KBuffer.h>
|
||||
#include <Kernel/DoubleBuffer.h>
|
||||
#include <Kernel/KBuffer.h>
|
||||
#include <Kernel/Lock.h>
|
||||
#include <Kernel/Net/IPv4.h>
|
||||
#include <Kernel/Net/IPv4SocketTuple.h>
|
||||
#include <Kernel/Net/Socket.h>
|
||||
|
||||
class IPv4SocketHandle;
|
||||
|
@ -23,6 +24,7 @@ public:
|
|||
|
||||
virtual KResult bind(const sockaddr*, socklen_t) override;
|
||||
virtual KResult connect(FileDescription&, const sockaddr*, socklen_t, ShouldBlock = ShouldBlock::Yes) override;
|
||||
virtual KResult listen(int) override;
|
||||
virtual bool get_local_address(sockaddr*, socklen_t*) override;
|
||||
virtual bool get_peer_address(sockaddr*, socklen_t*) override;
|
||||
virtual void attach(FileDescription&) override;
|
||||
|
@ -34,7 +36,7 @@ public:
|
|||
|
||||
void did_receive(const IPv4Address& peer_address, u16 peer_port, KBuffer&&);
|
||||
|
||||
const IPv4Address& local_address() const;
|
||||
const IPv4Address& local_address() const { return m_local_address; }
|
||||
u16 local_port() const { return m_local_port; }
|
||||
void set_local_port(u16 port) { m_local_port = port; }
|
||||
|
||||
|
@ -42,6 +44,8 @@ public:
|
|||
u16 peer_port() const { return m_peer_port; }
|
||||
void set_peer_port(u16 port) { m_peer_port = port; }
|
||||
|
||||
IPv4SocketTuple tuple() const { return IPv4SocketTuple(m_local_address, m_local_port, m_peer_address, m_peer_port); }
|
||||
|
||||
protected:
|
||||
IPv4Socket(int type, int protocol);
|
||||
virtual const char* class_name() const override { return "IPv4Socket"; }
|
||||
|
@ -49,12 +53,16 @@ protected:
|
|||
int allocate_local_port_if_needed();
|
||||
|
||||
virtual KResult protocol_bind() { return KSuccess; }
|
||||
virtual KResult protocol_listen() { return KSuccess; }
|
||||
virtual int protocol_receive(const KBuffer&, void*, size_t, int) { return -ENOTIMPL; }
|
||||
virtual int protocol_send(const void*, int) { return -ENOTIMPL; }
|
||||
virtual KResult protocol_connect(FileDescription&, ShouldBlock) { return KSuccess; }
|
||||
virtual int protocol_allocate_local_port() { return 0; }
|
||||
virtual bool protocol_is_disconnected() const { return false; }
|
||||
|
||||
void set_local_address(IPv4Address address) { m_local_address = address; }
|
||||
void set_peer_address(IPv4Address address) { m_peer_address = address; }
|
||||
|
||||
private:
|
||||
virtual bool is_ipv4() const override { return true; }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue