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

speed/isup returned by net_if_stats are incorrect on OSX #805

Open
weyou opened this issue Apr 15, 2016 · 3 comments
Open

speed/isup returned by net_if_stats are incorrect on OSX #805

weyou opened this issue Apr 15, 2016 · 3 comments

Comments

@weyou
Copy link

weyou commented Apr 15, 2016

For wireless interface, the link speed is always 0.
The link status isup is always True even the wireless is turn off or the ethernet cable is disconnected.

@weyou weyou changed the title speed/isup returned by net_if_stats are incorrect on OSX speed/isup returned by net_if_stats are incorrect on OSX Apr 15, 2016
@giampaolo
Copy link
Owner

We may have a better chance to figure out what's wrong with this when we get around #898.

@alexbakker
Copy link

This issue also exists on Linux.

@ewedlund
Copy link
Contributor

"isup" reflects the value of the flag IFF_UP.

In OSX the flag IFF_UP is set even if the airport is disabled (using OSX tools, such as 'networksetup'), but the flag IFF_RUNNING reflects the airport state. Also, there is no way to set an ethernet interface to down (IFF_UP not set) and IFF_RUNNING remains set even if the cable is disconnected. (It is however possible to manually set the IFF_UP flag through 'ifconfig')

In linux the flags are set as one would expect, i.e. IFF_UP is set if the interface is enabled/configured and IFF_RUNNING if it is connected.

Here is a description of the two (from Stack Overflow):


From Linux Device Drivers 3:

IFF_UP This flag is read-only for the driver. The kernel turns it on when the interface is active and ready to transfer packets.
...
IFF_RUNNING This flag indicates that the interface is up and running. It is mostly present for BSD compatibility; the kernel makes little use of it. Most network drivers need not worry about IFF_RUNNING.

Digging a bit deeper, it seems that there is one significant difference:

IFF_RUNNING is supposed to reflect the operational status on a network interface, rather than its administrative one. To provide an example, an Ethernet interface may be brought UP by the administrator (e.g. ifconfig eth0 up), but it will not be considered operational (i.e. RUNNING as per RFC2863) if the cable is not plugged in.


I think there are two options, either to add 'is_running' to the interface dict, or to consider checking IFF_RUNNING instead of IFF_UP for 'isup'.

Both the above solutions would solve the problem with WiFi status in OSX, but not the Ethernet status, since it appears to always be both "UP" and "RUNNING". However, the speed will be 0 on a disconnected Ethernet interface.

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

4 participants