mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:38:11 +00:00
Kernel+Utilities: Add the route utility
This exposes the global routing table in the /proc directory and adds the userspace utility to query dynamically add from the table.
This commit is contained in:
parent
419cd479e2
commit
19912a0b32
3 changed files with 229 additions and 1 deletions
|
@ -100,6 +100,34 @@ private:
|
|||
}
|
||||
};
|
||||
|
||||
class ProcFSRoute final : public ProcFSGlobalInformation {
|
||||
public:
|
||||
static NonnullRefPtr<ProcFSRoute> must_create();
|
||||
|
||||
private:
|
||||
ProcFSRoute();
|
||||
virtual ErrorOr<void> try_generate(KBufferBuilder& builder) override
|
||||
{
|
||||
auto array = TRY(JsonArraySerializer<>::try_create(builder));
|
||||
TRY(routing_table().with([&](auto const& table) -> ErrorOr<void> {
|
||||
for (auto& it : table) {
|
||||
auto obj = TRY(array.add_object());
|
||||
auto destination = TRY(it.destination.to_string());
|
||||
TRY(obj.add("destination", destination->view()));
|
||||
auto gateway = TRY(it.gateway.to_string());
|
||||
TRY(obj.add("gateway", gateway->view()));
|
||||
auto netmask = TRY(it.netmask.to_string());
|
||||
TRY(obj.add("genmask", netmask->view()));
|
||||
TRY(obj.add("interface", it.adapter->name()));
|
||||
TRY(obj.finish());
|
||||
}
|
||||
return {};
|
||||
}));
|
||||
TRY(array.finish());
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
class ProcFSTCP final : public ProcFSGlobalInformation {
|
||||
public:
|
||||
static NonnullRefPtr<ProcFSTCP> must_create();
|
||||
|
@ -217,6 +245,10 @@ UNMAP_AFTER_INIT NonnullRefPtr<ProcFSARP> ProcFSARP::must_create()
|
|||
{
|
||||
return adopt_ref_if_nonnull(new (nothrow) ProcFSARP).release_nonnull();
|
||||
}
|
||||
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSRoute> ProcFSRoute::must_create()
|
||||
{
|
||||
return adopt_ref_if_nonnull(new (nothrow) ProcFSRoute).release_nonnull();
|
||||
}
|
||||
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSTCP> ProcFSTCP::must_create()
|
||||
{
|
||||
return adopt_ref_if_nonnull(new (nothrow) ProcFSTCP).release_nonnull();
|
||||
|
@ -235,6 +267,7 @@ UNMAP_AFTER_INIT NonnullRefPtr<ProcFSNetworkDirectory> ProcFSNetworkDirectory::m
|
|||
auto directory = adopt_ref(*new (nothrow) ProcFSNetworkDirectory(parent_directory));
|
||||
directory->m_components.append(ProcFSAdapters::must_create());
|
||||
directory->m_components.append(ProcFSARP::must_create());
|
||||
directory->m_components.append(ProcFSRoute::must_create());
|
||||
directory->m_components.append(ProcFSTCP::must_create());
|
||||
directory->m_components.append(ProcFSLocalNet::must_create());
|
||||
directory->m_components.append(ProcFSUDP::must_create());
|
||||
|
@ -249,6 +282,10 @@ UNMAP_AFTER_INIT ProcFSARP::ProcFSARP()
|
|||
: ProcFSGlobalInformation("arp"sv)
|
||||
{
|
||||
}
|
||||
UNMAP_AFTER_INIT ProcFSRoute::ProcFSRoute()
|
||||
: ProcFSGlobalInformation("route"sv)
|
||||
{
|
||||
}
|
||||
UNMAP_AFTER_INIT ProcFSTCP::ProcFSTCP()
|
||||
: ProcFSGlobalInformation("tcp"sv)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue