mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:58:11 +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
|
@ -89,6 +89,22 @@ KResult IPv4Socket::bind(const sockaddr* address, socklen_t address_size)
|
|||
return protocol_bind();
|
||||
}
|
||||
|
||||
KResult IPv4Socket::listen(int backlog)
|
||||
{
|
||||
int rc = allocate_local_port_if_needed();
|
||||
if (rc < 0)
|
||||
return KResult(-EADDRINUSE);
|
||||
|
||||
if (m_local_address.to_u32() == 0)
|
||||
return KResult(-EADDRINUSE);
|
||||
|
||||
set_backlog(backlog);
|
||||
|
||||
kprintf("IPv4Socket{%p} listening with backlog=%d\n", this, backlog);
|
||||
|
||||
return protocol_listen();
|
||||
}
|
||||
|
||||
KResult IPv4Socket::connect(FileDescription& description, const sockaddr* address, socklen_t address_size, ShouldBlock should_block)
|
||||
{
|
||||
if (address_size != sizeof(sockaddr_in))
|
||||
|
@ -157,6 +173,9 @@ ssize_t IPv4Socket::sendto(FileDescription&, const void* data, size_t data_lengt
|
|||
if (!adapter)
|
||||
return -EHOSTUNREACH;
|
||||
|
||||
if (m_local_address.to_u32() == 0)
|
||||
m_local_address = adapter->ipv4_address();
|
||||
|
||||
int rc = allocate_local_port_if_needed();
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue