feat: kernel network statistics reporting, new Network configuration applet

This commit is contained in:
2026-05-03 10:45:33 +02:00
parent 3919d166f7
commit 3ad5ae2e75
28 changed files with 1167 additions and 115 deletions
+37
View File
@@ -107,6 +107,43 @@ namespace Montauk {
out->dnsServer = Net::GetDnsServer();
}
static void CopyNetStatusDriver(char* dst, const char* src) {
static constexpr uint64_t DriverNameBytes = 32;
if (!dst) return;
uint64_t i = 0;
for (; i < DriverNameBytes - 1 && src && src[i]; i++) {
dst[i] = src[i];
}
dst[i] = '\0';
}
static void Sys_NetStatus(NetStatus* out) {
if (out == nullptr) return;
out->initialized = 0;
out->linkUp = 0;
out->polling = 0;
out->_pad0 = 0;
out->rxPackets = 0;
out->txPackets = 0;
CopyNetStatusDriver(out->driver, "No adapter");
if (Drivers::Net::E1000::IsInitialized()) {
out->initialized = 1;
out->linkUp = Drivers::Net::E1000::IsLinkUp() ? 1 : 0;
out->rxPackets = Drivers::Net::E1000::GetRxPacketCount();
out->txPackets = Drivers::Net::E1000::GetTxPacketCount();
CopyNetStatusDriver(out->driver, "Intel 82540EM");
} else if (Drivers::Net::E1000E::IsInitialized()) {
out->initialized = 1;
out->linkUp = Drivers::Net::E1000E::IsLinkUp() ? 1 : 0;
out->polling = Drivers::Net::E1000E::RequiresPolling() ? 1 : 0;
out->rxPackets = Drivers::Net::E1000E::GetRxPacketCount();
out->txPackets = Drivers::Net::E1000E::GetTxPacketCount();
CopyNetStatusDriver(out->driver, "Intel e1000e");
}
}
static int Sys_SetNetCfg(const NetCfg* in) {
if (in == nullptr) return -1;
Net::SetIpAddress(in->ipAddress);
+5 -1
View File
@@ -21,7 +21,7 @@
#include "Keyboard.hpp" // SYS_ISKEYAVAILABLE, SYS_GETKEY, SYS_GETCHAR
#include "Info.hpp" // SYS_GETINFO
#include "Graphics.hpp" // SYS_FBINFO, SYS_FBMAP, SYS_TERMSIZE, SYS_TERMSCALE
#include "Net.hpp" // SYS_PING, SYS_SOCKET, SYS_CONNECT, SYS_BIND, SYS_LISTEN, SYS_ACCEPT, SYS_SEND, SYS_RECV, SYS_CLOSESOCK, SYS_SENDTO, SYS_RECVFROM, SYS_GETNETCFG, SYS_SETNETCFG, SYS_RESOLVE
#include "Net.hpp" // SYS_PING, SYS_SOCKET, SYS_CONNECT, SYS_BIND, SYS_LISTEN, SYS_ACCEPT, SYS_SEND, SYS_RECV, SYS_CLOSESOCK, SYS_SENDTO, SYS_RECVFROM, SYS_GETNETCFG, SYS_SETNETCFG, SYS_RESOLVE, SYS_NETSTATUS
#include "Power.hpp" // SYS_RESET, SYS_SHUTDOWN, SYS_SUSPEND
#include "Mouse.hpp" // SYS_MOUSESTATE, SYS_SETMOUSEBOUNDS
#include "IoRedir.hpp" // SYS_SPAWN_REDIR, SYS_CHILDIO_READ, SYS_CHILDIO_WRITE, SYS_CHILDIO_WRITEKEY, SYS_CHILDIO_SETTERMSZ
@@ -175,6 +175,10 @@ namespace Montauk {
case SYS_SETNETCFG:
if (!UserMemory::Readable<NetCfg>(frame->arg1)) return -1;
return (int64_t)Sys_SetNetCfg((const NetCfg*)frame->arg1);
case SYS_NETSTATUS:
if (!UserMemory::Writable<NetStatus>(frame->arg1)) return -1;
Sys_NetStatus((NetStatus*)frame->arg1);
return 0;
case SYS_SENDTO:
if (!UserMemory::Range(frame->arg2, frame->arg3, false)) return -1;
return (int64_t)Sys_SendTo((int)frame->arg1, (const uint8_t*)frame->arg2,
+13
View File
@@ -225,6 +225,9 @@ namespace Montauk {
/* Filesystem.hpp */
static constexpr uint64_t SYS_DRIVELABEL = 124;
/* Net.hpp */
static constexpr uint64_t SYS_NETSTATUS = 125;
static constexpr uint32_t CLIPBOARD_MAX_TEXT_BYTES = 256 * 1024;
static constexpr uint32_t IPC_SIGNAL_READABLE = 1u << 0;
@@ -269,6 +272,16 @@ namespace Montauk {
uint32_t dnsServer; // network byte order
};
struct NetStatus {
uint8_t initialized;
uint8_t linkUp;
uint8_t polling;
uint8_t _pad0;
char driver[32];
uint64_t rxPackets;
uint64_t txPackets;
};
struct KeyEvent {
uint8_t scancode;
char ascii;
+14 -1
View File
@@ -502,8 +502,21 @@ namespace Drivers::Net::E1000 {
return g_initialized;
}
bool IsLinkUp() {
if (!g_initialized || g_mmioBase == nullptr) return false;
return (ReadReg(REG_STATUS) & (1 << 1)) != 0;
}
uint64_t GetRxPacketCount() {
return g_rxPacketCount;
}
uint64_t GetTxPacketCount() {
return g_txPacketCount;
}
void SetRxCallback(RxCallback callback) {
g_rxCallback = callback;
}
};
};
+8 -1
View File
@@ -115,10 +115,17 @@ namespace Drivers::Net::E1000 {
// Check if the device was found and initialized
bool IsInitialized();
// Read current carrier/link state from the device status register
bool IsLinkUp();
// Packet counters maintained by the driver
uint64_t GetRxPacketCount();
uint64_t GetTxPacketCount();
// RX callback type: called with (packet data, length)
using RxCallback = void(*)(const uint8_t* data, uint16_t length);
// Register a callback for received packets
void SetRxCallback(RxCallback callback);
};
};
+13
View File
@@ -740,10 +740,23 @@ namespace Drivers::Net::E1000E {
return g_initialized;
}
bool IsLinkUp() {
if (!g_initialized || g_mmioBase == nullptr) return false;
return (ReadReg(REG_STATUS) & (1 << 1)) != 0;
}
bool RequiresPolling() {
return g_initialized && g_pollingMode;
}
uint64_t GetRxPacketCount() {
return g_rxPacketCount;
}
uint64_t GetTxPacketCount() {
return g_txPacketCount;
}
void SetRxCallback(RxCallback callback) {
g_rxCallback = callback;
}
+7
View File
@@ -149,9 +149,16 @@ namespace Drivers::Net::E1000E {
// Check if the device was found and initialized
bool IsInitialized();
// Read current carrier/link state from the device status register
bool IsLinkUp();
// Returns true only when the driver had to fall back to timer polling.
bool RequiresPolling();
// Packet counters maintained by the driver
uint64_t GetRxPacketCount();
uint64_t GetTxPacketCount();
// RX callback type: called with (packet data, length)
using RxCallback = void(*)(const uint8_t* data, uint16_t length);