diff options
Diffstat (limited to 'package/base-files/files/lib/preinit')
-rw-r--r-- | package/base-files/files/lib/preinit/10_indicate_preinit | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/package/base-files/files/lib/preinit/10_indicate_preinit b/package/base-files/files/lib/preinit/10_indicate_preinit index debb3d4480..87a4f4da3e 100644 --- a/package/base-files/files/lib/preinit/10_indicate_preinit +++ b/package/base-files/files/lib/preinit/10_indicate_preinit @@ -63,6 +63,20 @@ preinit_config_switch() { json_select .. } +preinit_config_port() { + local original + + local netdev="$1" + local path="$2" + + [ -d "/sys/devices/$path/net" ] || return + original="$(ls "/sys/devices/$path/net" | head -1)" + + [ "$netdev" = "$original" ] && return + + ip link set "$original" name "$netdev" +} + preinit_config_board() { /bin/board_detect /tmp/board.json @@ -73,6 +87,35 @@ preinit_config_board() { json_init json_load "$(cat /tmp/board.json)" + # Find the current highest eth* + max_eth=$(grep -o '^ *eth[0-9]*:' /proc/net/dev | tr -dc '[0-9]\n' | sort -n | tail -1) + # Find and move netdevs using eth*s we are configuring + json_get_keys keys "network_device" + for netdev in $keys; do + json_select "network_device" + json_select "$netdev" + json_get_vars path path + next_eth="$(echo "$netdev" | grep 'eth[0-9]*' | tr -dc '[0-9]')" + [ "$next_eth" -gt "$max_eth" ] && max_eth=$next_eth + if [ -n "$path" -a -h "/sys/class/net/$netdev" ]; then + ip link set "$netdev" down + ip link set "$netdev" name eth$((++max_eth)) + fi + json_select .. + json_select .. + done + + # Move interfaces by path to their netdev name + json_get_keys keys "network_device" + for netdev in $keys; do + json_select "network_device" + json_select "$netdev" + json_get_vars path path + [ -n "$path" ] && preinit_config_port "$netdev" "$path" + json_select .. + json_select .. + done + json_select network json_select "lan" json_get_vars device |