From 5c9dc91f64ff6baca3ba1d74b425ac501fe02332 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Wed, 13 Nov 2024 13:55:58 -0500 Subject: [PATCH] network: Aggregate statistics from the device, if any are provided. This way, we report the real receive/send statistics, not just the ones the stack knows. Adjust the FreeBSD compatibility layer to report its stats directly so they are accounted for this way. --- src/add-ons/kernel/network/stack/datalink.cpp | 14 ++++++++++++-- src/libs/compat/freebsd_network/device_hooks.c | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/add-ons/kernel/network/stack/datalink.cpp b/src/add-ons/kernel/network/stack/datalink.cpp index 9c4d502230..df4fae254c 100644 --- a/src/add-ons/kernel/network/stack/datalink.cpp +++ b/src/add-ons/kernel/network/stack/datalink.cpp @@ -886,9 +886,19 @@ interface_protocol_control(net_datalink_protocol* _protocol, int32 option, case SIOCGIFSTATS: { // get stats + struct ifreq_stats stats = interface->DeviceInterface()->device->stats; + + struct ifreq_stats deviceStats; + if (protocol->device_module->control(protocol->device, SIOCGIFSTATS, + &deviceStats, sizeof(struct ifreq_stats)) == B_OK) { + stats.receive.dropped += deviceStats.receive.dropped; + stats.receive.errors += deviceStats.receive.errors; + stats.send = deviceStats.send; + stats.collisions += deviceStats.collisions; + } + return user_memcpy(&((struct ifreq*)argument)->ifr_stats, - &interface->DeviceInterface()->device->stats, - sizeof(struct ifreq_stats)); + &stats, sizeof(struct ifreq_stats)); } case SIOCGIFTYPE: diff --git a/src/libs/compat/freebsd_network/device_hooks.c b/src/libs/compat/freebsd_network/device_hooks.c index 4d5915ed72..72d62ac3ab 100644 --- a/src/libs/compat/freebsd_network/device_hooks.c +++ b/src/libs/compat/freebsd_network/device_hooks.c @@ -346,6 +346,24 @@ compat_control(void *cookie, uint32 op, void *arg, size_t length) return B_BAD_ADDRESS; return compat_receive(cookie, (net_buffer**)arg); + case SIOCGIFSTATS: + { + struct ifreq_stats stats; + stats.receive.packets = ifp->if_data.ifi_ipackets; + stats.receive.errors = ifp->if_data.ifi_ierrors; + stats.receive.bytes = ifp->if_data.ifi_ibytes; + stats.receive.multicast_packets = ifp->if_data.ifi_imcasts; + stats.receive.dropped = ifp->if_data.ifi_iqdrops; + stats.send.packets = ifp->if_data.ifi_opackets; + stats.send.errors = ifp->if_data.ifi_oerrors; + stats.send.bytes = ifp->if_data.ifi_obytes; + stats.send.multicast_packets = ifp->if_data.ifi_omcasts; + stats.send.dropped = ifp->if_data.ifi_oqdrops; + stats.collisions = ifp->if_data.ifi_collisions; + memcpy(arg, &stats, sizeof(stats)); + return B_OK; + } + case SIOCSIFFLAGS: case SIOCSIFMEDIA: case SIOCSIFMTU: