3

I have a network interface that ip link show reports like this:

3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default 
    link/ether 02:42:43:e6:b1:e7 brd ff:ff:ff:ff:ff:ff

But /sys/class/net/docker0/flags says this:

$ cat /sys/class/net/docker0/flags 
    0x1003

The three bits that are set are IFF_MULTICAST, IFF_BROADCAST and IFF_UP. This looks like an interface that is UP. Why does ip link report state DOWN?

The system is Linux 4.15 / Ubuntu 18.04.

Tom
  • 535
  • 1
  • 3
  • 15

1 Answers1

3

The three bits that are set are IFF_MULTICAST, IFF_BROADCAST and IFF_UP. This looks like an interface that is UP

And that corresponds perfectly well to the actual flags output:

3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP>
                           ↑         ↑      ↑

Why does ip link report state DOWN?

That's a different kind of state.

  • The flag IFF_UP (shown above as "<UP>") describes administrative state, which is the manual knob that you can set via ip link set eth0 up.

  • On the other hand, the "state […]" text describes operational state, which indicates whether the interface is capable of working.

Operational state is roughly the same as 'carrier' presence – e.g. Ethernet link fully established, or Wi-Fi access point associated to. A bridge is reported to be up (have a carrier) if at least one of its member ports is up. For that reason you may want to add a dummy0 interface as bridge member.

Operational state roughly corresponds to the flags IFF_LOWER_UP (shown as "<LOWER_UP>" in the flags area) and IFF_RUNNING (its absence shown as pseudo-flag "<NO-CARRIER>" in your example). (source code)

However, iproute tools obtain interface information via Netlink, and the state … section is printed based on the IFLA_OPERSTATE netlink attribute. (source code)

This attribute is available via sysfs at …/operstate as well. The Linux documentation has a more detailed explanation of these flags and attributes in operstates.txt.

u1686_grawity
  • 426,297
  • 64
  • 894
  • 966
  • Thanks for the explanation. I also have an ethernet interface which `ip link` reports to have flags `BROADCAST,MULTICAST,UP,LOWER_UP` but which sysfs shows to have flags 0x1003 (same as the docker0 interface above). I guess the discrepancy is because iproute tools are not using sysfs. Is ti reasonable to try to infer operational link state from sysfs, or is it necessary to use another interface? I'm doing this in python and trying to avoid `subprocess.call('ip link show | grep eth0'.split()).split()` etc. – Tom Oct 11 '18 at 10:22
  • Bah, never mind, I found `/sys/class/net/eth0/operstate` on my own now... – Tom Oct 11 '18 at 10:23
  • 1
    @Tom: Use the `operstate` sysfs attribute. Use a rtnetlink python module. (I have a slight suspicion that IFF_LOWER_UP is only reported via netlink butn not via sysfs.) Use `ip -json link show | jq ".[]|.operstate"` if you must... – u1686_grawity Oct 11 '18 at 10:23