net: linkwatch: only report IF_OPER_LOWERLAYERDOWN if iflink is actually down
authorVladimir Oltean <vladimir.oltean@nxp.com>
Mon, 14 Nov 2022 14:42:56 +0000 (16:42 +0200)
committerDavid S. Miller <davem@davemloft.net>
Wed, 16 Nov 2022 09:45:00 +0000 (09:45 +0000)
commit8c55facecd7ade835287298ce325f930d888d8ec
tree856bdecb4f4a2a592ee65ca118ab69bc565bee4c
parentfd258f2aba2cfb2babe85b47ce01d0167c61a4db
net: linkwatch: only report IF_OPER_LOWERLAYERDOWN if iflink is actually down

RFC 2863 says:

   The lowerLayerDown state is also a refinement on the down state.
   This new state indicates that this interface runs "on top of" one or
   more other interfaces (see ifStackTable) and that this interface is
   down specifically because one or more of these lower-layer interfaces
   are down.

DSA interfaces are virtual network devices, stacked on top of the DSA
master, but they have a physical MAC, with a PHY that reports a real
link status.

But since DSA (perhaps improperly) uses an iflink to describe the
relationship to its master since commit c084080151e1 ("dsa: set ->iflink
on slave interfaces to the ifindex of the parent"), default_operstate()
will misinterpret this to mean that every time the carrier of a DSA
interface is not ok, it is because of the master being not ok.

In fact, since commit c0a8a9c27493 ("net: dsa: automatically bring user
ports down when master goes down"), DSA cannot even in theory be in the
lowerLayerDown state, because it just calls dev_close_many(), thereby
going down, when the master goes down.

We could revert the commit that creates an iflink between a DSA user
port and its master, especially since now we have an alternative
IFLA_DSA_MASTER which has less side effects. But there may be tooling in
use which relies on the iflink, which has existed since 2009.

We could also probably do something local within DSA to overwrite what
rfc2863_policy() did, in a way similar to hsr_set_operstate(), but this
seems like a hack.

What seems appropriate is to follow the iflink, and check the carrier
status of that interface as well. If that's down too, yes, keep
reporting lowerLayerDown, otherwise just down.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/link_watch.c