Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Linux] Network interface isup returned from net_if_stats doesn't represent interface state #1830

Closed
phobozad opened this issue Sep 20, 2020 · 1 comment

Comments

@phobozad
Copy link
Contributor

Platform

  • Debian 10.4
  • psutil version: 5.5.1
  • Python 3.7.3

Bug description
On Linux, the value of isup for network interfaces isn't accurate to the operational state of the interface (i.e. link is up).

Currently the code looks for the flag IFF_UP to set the value of isup. However, the IFF_UP flag only represents the interface being administratively up (i.e. not disabled) but not the operational state (i.e. connected). The operational state is represented by the IFF_RUNNING flag.
https://www.kernel.org/doc/Documentation/networking/operstates.txt
https://stackoverflow.com/questions/11679514/what-is-the-difference-between-iff-up-and-iff-running

I suspect this issue is also why the test for isup in test_linux.py was disabled - the test was looking for the RUNNING flag but the code was looking at the UP flag. Thus if there was an interface that was administratively up but didn't have a cable connected, it would fail the test suite. In this case, the test failing was correct since the code wasn't actually checking the correct flag.

This same issue is also mentioned in relation to OSX Wireless status in #805.

@giampaolo
Copy link
Owner

According to https://stackoverflow.com/a/11679939... it seems this make sense. I will change the doc in accordance.
As for Windows, it seems there's a similar distinction:
https://docs.microsoft.com/en-us/previous-versions/windows/embedded/ms894611(v=msdn.10)
Currently we're doing:

        // is up?
        if ((pIfRow->dwOperStatus == MIB_IF_OPER_STATUS_CONNECTED ||
                pIfRow->dwOperStatus == MIB_IF_OPER_STATUS_OPERATIONAL) &&
                pIfRow->dwAdminStatus == 1 ) {
            py_is_up = Py_True;
        }
        else {
            py_is_up = Py_False;
        }

I cannot disconnect the Ethernet cable on Windows because it's virtualized, but I did ipconfig /release (release IP address assigned by DHCP) and the status keeps being MIB_IF_OPER_STATUS_OPERATIONAL, which seems correct (the same as on Linux). As such, it appears Windows code is fine as it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants