mirror of
https://github.com/RGBCube/serenity
synced 2025-05-23 15:25:08 +00:00
ProcFS: Expose ARP table
This commit is contained in:
parent
ac154999f5
commit
41d113713d
1 changed files with 20 additions and 0 deletions
|
@ -17,6 +17,7 @@
|
||||||
#include <Kernel/KParams.h>
|
#include <Kernel/KParams.h>
|
||||||
#include <Kernel/Net/LocalSocket.h>
|
#include <Kernel/Net/LocalSocket.h>
|
||||||
#include <Kernel/Net/NetworkAdapter.h>
|
#include <Kernel/Net/NetworkAdapter.h>
|
||||||
|
#include <Kernel/Net/Routing.h>
|
||||||
#include <Kernel/Net/TCPSocket.h>
|
#include <Kernel/Net/TCPSocket.h>
|
||||||
#include <Kernel/Net/UDPSocket.h>
|
#include <Kernel/Net/UDPSocket.h>
|
||||||
#include <Kernel/PCI.h>
|
#include <Kernel/PCI.h>
|
||||||
|
@ -59,6 +60,7 @@ enum ProcFileType {
|
||||||
FI_Root_sys_variable,
|
FI_Root_sys_variable,
|
||||||
|
|
||||||
FI_Root_net_adapters,
|
FI_Root_net_adapters,
|
||||||
|
FI_Root_net_arp,
|
||||||
FI_Root_net_tcp,
|
FI_Root_net_tcp,
|
||||||
FI_Root_net_udp,
|
FI_Root_net_udp,
|
||||||
FI_Root_net_local,
|
FI_Root_net_local,
|
||||||
|
@ -335,6 +337,20 @@ Optional<KBuffer> procfs$net_adapters(InodeIdentifier)
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Optional<KBuffer> procfs$net_arp(InodeIdentifier)
|
||||||
|
{
|
||||||
|
KBufferBuilder builder;
|
||||||
|
JsonArraySerializer array { builder };
|
||||||
|
LOCKER(arp_table().lock());
|
||||||
|
for (auto& it : arp_table().resource()) {
|
||||||
|
JsonObjectSerializer obj = array.add_object();
|
||||||
|
obj.add("mac_address", it.value.to_string());
|
||||||
|
obj.add("ip_address", it.key.to_string());
|
||||||
|
}
|
||||||
|
array.finish();
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
Optional<KBuffer> procfs$net_tcp(InodeIdentifier)
|
Optional<KBuffer> procfs$net_tcp(InodeIdentifier)
|
||||||
{
|
{
|
||||||
KBufferBuilder builder;
|
KBufferBuilder builder;
|
||||||
|
@ -1022,6 +1038,7 @@ bool ProcFSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntry&)
|
||||||
|
|
||||||
case FI_Root_net:
|
case FI_Root_net:
|
||||||
callback({ "adapters", 8, to_identifier(fsid(), PDI_Root_net, 0, FI_Root_net_adapters), 0 });
|
callback({ "adapters", 8, to_identifier(fsid(), PDI_Root_net, 0, FI_Root_net_adapters), 0 });
|
||||||
|
callback({ "arp", 3, to_identifier(fsid(), PDI_Root_net, 0, FI_Root_net_arp), 0 });
|
||||||
callback({ "tcp", 3, to_identifier(fsid(), PDI_Root_net, 0, FI_Root_net_tcp), 0 });
|
callback({ "tcp", 3, to_identifier(fsid(), PDI_Root_net, 0, FI_Root_net_tcp), 0 });
|
||||||
callback({ "udp", 3, to_identifier(fsid(), PDI_Root_net, 0, FI_Root_net_udp), 0 });
|
callback({ "udp", 3, to_identifier(fsid(), PDI_Root_net, 0, FI_Root_net_udp), 0 });
|
||||||
callback({ "local", 5, to_identifier(fsid(), PDI_Root_net, 0, FI_Root_net_local), 0 });
|
callback({ "local", 5, to_identifier(fsid(), PDI_Root_net, 0, FI_Root_net_local), 0 });
|
||||||
|
@ -1109,6 +1126,8 @@ InodeIdentifier ProcFSInode::lookup(StringView name)
|
||||||
if (proc_file_type == FI_Root_net) {
|
if (proc_file_type == FI_Root_net) {
|
||||||
if (name == "adapters")
|
if (name == "adapters")
|
||||||
return to_identifier(fsid(), PDI_Root, 0, FI_Root_net_adapters);
|
return to_identifier(fsid(), PDI_Root, 0, FI_Root_net_adapters);
|
||||||
|
if (name == "arp")
|
||||||
|
return to_identifier(fsid(), PDI_Root, 0, FI_Root_net_arp);
|
||||||
if (name == "tcp")
|
if (name == "tcp")
|
||||||
return to_identifier(fsid(), PDI_Root, 0, FI_Root_net_tcp);
|
return to_identifier(fsid(), PDI_Root, 0, FI_Root_net_tcp);
|
||||||
if (name == "udp")
|
if (name == "udp")
|
||||||
|
@ -1244,6 +1263,7 @@ ProcFS::ProcFS()
|
||||||
m_entries[FI_Root_net] = { "net", FI_Root_net };
|
m_entries[FI_Root_net] = { "net", FI_Root_net };
|
||||||
|
|
||||||
m_entries[FI_Root_net_adapters] = { "adapters", FI_Root_net_adapters, procfs$net_adapters };
|
m_entries[FI_Root_net_adapters] = { "adapters", FI_Root_net_adapters, procfs$net_adapters };
|
||||||
|
m_entries[FI_Root_net_arp] = { "arp", FI_Root_net_arp, procfs$net_arp };
|
||||||
m_entries[FI_Root_net_tcp] = { "tcp", FI_Root_net_tcp, procfs$net_tcp };
|
m_entries[FI_Root_net_tcp] = { "tcp", FI_Root_net_tcp, procfs$net_tcp };
|
||||||
m_entries[FI_Root_net_udp] = { "udp", FI_Root_net_udp, procfs$net_udp };
|
m_entries[FI_Root_net_udp] = { "udp", FI_Root_net_udp, procfs$net_udp };
|
||||||
m_entries[FI_Root_net_local] = { "local", FI_Root_net_local, procfs$net_local };
|
m_entries[FI_Root_net_local] = { "local", FI_Root_net_local, procfs$net_local };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue