1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 05:25:09 +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:
Conrad Pankoff 2019-08-06 23:40:38 +10:00 committed by Andreas Kling
parent c973a51a23
commit 73c998dbfc
12 changed files with 446 additions and 84 deletions

View file

@ -14,6 +14,7 @@
#include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/KParams.h>
#include <Kernel/Net/NetworkAdapter.h>
#include <Kernel/Net/TCPSocket.h>
#include <Kernel/PCI.h>
#include <Kernel/VM/MemoryManager.h>
#include <Kernel/kmalloc.h>
@ -46,6 +47,7 @@ enum ProcFileType {
FI_Root_uptime,
FI_Root_cmdline,
FI_Root_netadapters,
FI_Root_net_tcp,
FI_Root_self, // symlink
FI_Root_sys, // directory
__FI_Root_End,
@ -278,6 +280,23 @@ Optional<KBuffer> procfs$netadapters(InodeIdentifier)
return builder.to_byte_buffer();
}
Optional<KBuffer> procfs$net_tcp(InodeIdentifier)
{
JsonArray json;
TCPSocket::for_each([&json](auto& socket) {
JsonObject obj;
obj.set("local_address", socket->local_address().to_string());
obj.set("local_port", socket->local_port());
obj.set("peer_address", socket->peer_address().to_string());
obj.set("peer_port", socket->peer_port());
obj.set("state", TCPSocket::to_string(socket->state()));
obj.set("ack_number", socket->ack_number());
obj.set("sequence_number", socket->sequence_number());
json.append(obj);
});
return json.serialized().to_byte_buffer();
}
Optional<KBuffer> procfs$pid_vmo(InodeIdentifier identifier)
{
auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier));
@ -1077,6 +1096,7 @@ ProcFS::ProcFS()
m_entries[FI_Root_uptime] = { "uptime", FI_Root_uptime, procfs$uptime };
m_entries[FI_Root_cmdline] = { "cmdline", FI_Root_cmdline, procfs$cmdline };
m_entries[FI_Root_netadapters] = { "netadapters", FI_Root_netadapters, procfs$netadapters };
m_entries[FI_Root_net_tcp] = { "net_tcp", FI_Root_net_tcp, procfs$net_tcp };
m_entries[FI_Root_sys] = { "sys", FI_Root_sys };
m_entries[FI_PID_vm] = { "vm", FI_PID_vm, procfs$pid_vm };