mirror of
https://github.com/openwrt/openwrt.git
synced 2026-11-28 16:41:08 +04:00
The 04_set_netdev_label preinit scripts (airoha, mediatek/mt7622,
microchipsw/lan969x, qualcommax/ipq50xx, ramips/mt7621) rename
interfaces with a plain "ip link set <netdev> name <label>". The kernel
refuses to rename an interface to a name that is already in use
(-EEXIST), and the scripts neither check the result nor log a failure,
so the rename silently does not happen.
This breaks whenever the requested name is currently held by another
interface, most notably when two interfaces have to swap names, e.g.
because their probe order is not deterministic. Swapping them needs
an intermediate name, as each rename asks for the name the other
interface still holds.
Rename in two phases instead:
1. park: move every interface that needs a new name to a temporary
name ("tmp%d"), which the kernel expands to the lowest free
"tmpN"
2. rename: give each parked interface its final name
After the first phase none of the affected interfaces holds its old
name any more, so the target names are free in the second phase and
the result no longer depends on the order in which /sys/class/net is
walked.
Interfaces that already have the requested name are left alone, so
nothing changes (and nothing shows up in the boot log) when the names
are already correct. An interface that has to be renamed now takes two
renames instead of one.
The label is read again in the second phase, which works because the
of_node of an interface follows it across renames. Letting the kernel
pick the temporary name means it cannot collide with an existing
interface and always fits in IFNAMSIZ, regardless of the label length.
This does not help if the requested name is held by an interface that
has no label of its own, as there is nobody to move it out of the way.
Where a script handles both "label" and "openwrt,netdev-name", the
latter takes precedence, as before, but both are now evaluated in a
single pass over /sys/class/net.
The filogic target is not changed here. Its set_netdev_labels loop
calls netdev_name_set from /lib/functions/netdev-name.sh, which is
shared with the preinit_netdev event handler that renames one
interface at a time. Making it two-phase needs a change to that
shared helper and is left for a separate patch.
Signed-off-by: Mieczyslaw Nalewaj <namiltd@yahoo.com>
Link: https://github.com/openwrt/openwrt/pull/25460
Signed-off-by: Robert Marko <robimarko@gmail.com>