summaryrefslogtreecommitdiff
path: root/psutil
diff options
context:
space:
mode:
authorgarrisoncarter <31416563+garrisoncarter@users.noreply.github.com>2022-07-11 00:57:14 -0700
committerGitHub <noreply@github.com>2022-07-11 09:57:14 +0200
commitd4eea1f8fc138b39ea78b3bf555c2e0438f2404e (patch)
tree73345897298cdd69a1dd706a69adb264d1436430 /psutil
parent072e3bfcf2dfc45288dd00de816f2940e5d5f2bc (diff)
downloadpsutil-d4eea1f8fc138b39ea78b3bf555c2e0438f2404e.tar.gz
[Linux] `net_if_stats()` returns an incorrect speed value for 100GbE network cards (#2096)
Diffstat (limited to 'psutil')
-rw-r--r--psutil/_psutil_linux.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/psutil/_psutil_linux.c b/psutil/_psutil_linux.c
index 70cf5d1b..c59050cb 100644
--- a/psutil/_psutil_linux.c
+++ b/psutil/_psutil_linux.c
@@ -417,6 +417,7 @@ psutil_net_if_duplex_speed(PyObject* self, PyObject* args) {
int sock = 0;
int ret;
int duplex;
+ __u32 uint_speed;
int speed;
struct ifreq ifr;
struct ethtool_cmd ethcmd;
@@ -438,7 +439,15 @@ psutil_net_if_duplex_speed(PyObject* self, PyObject* args) {
if (ret != -1) {
duplex = ethcmd.duplex;
- speed = ethcmd.speed;
+ // speed is returned from ethtool as a __u32 ranging from 0 to INT_MAX
+ // or SPEED_UNKNOWN (-1)
+ uint_speed = ethtool_cmd_speed(&ethcmd);
+ if (uint_speed == (__u32)SPEED_UNKNOWN || uint_speed > INT_MAX) {
+ speed = 0;
+ }
+ else {
+ speed = (int)uint_speed;
+ }
}
else {
if ((errno == EOPNOTSUPP) || (errno == EINVAL)) {