Skip to content

Commit

Permalink
[Linux] net_if_stats() returns an incorrect speed value for 100GbE …
Browse files Browse the repository at this point in the history
…network cards (#2096)
  • Loading branch information
garrisoncarter authored Jul 11, 2022
1 parent 072e3bf commit d4eea1f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
``min`` and ``max`` are in MHz.
- 2050_, [Linux]: `virtual_memory()`_ may raise ``ValueError`` if running in a
LCX container.
- 2095_, [Linux]: `net_if_stats()` returns incorrect interface speed for 100GbE
network cards

5.9.0
=====
Expand Down
11 changes: 10 additions & 1 deletion psutil/_psutil_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)) {
Expand Down

0 comments on commit d4eea1f

Please sign in to comment.