summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorbrapru <brapru@pm.me>2022-03-12 14:16:44 -0500
committerBrian Gianforcaro <b.gianfo@gmail.com>2022-04-28 08:41:11 -0700
commit19912a0b32393ba9f1535bfd518fa7a4fec9d00b (patch)
tree86b84f3535c86e5e204255a1d147350674975323 /Kernel
parent419cd479e285240f9a14261dac0566ae59dec1bd (diff)
downloadserenity-19912a0b32393ba9f1535bfd518fa7a4fec9d00b.zip
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.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/GlobalProcessExposed.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/Kernel/GlobalProcessExposed.cpp b/Kernel/GlobalProcessExposed.cpp
index 45574cc781..7f2af55ba2 100644
--- a/Kernel/GlobalProcessExposed.cpp
+++ b/Kernel/GlobalProcessExposed.cpp
@@ -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)
{