[RFC 4/6] base-files: preinit: add ethernet label name pass

Evan Jobling evan.jobling at mslsc.com.au
Wed Oct 9 01:07:53 PDT 2024


Add a second pass for renaming in case named devices
by path conflict with dsa labels for example.

Signed-off-by: Evan Jobling <evan.jobling at mslsc.com.au>
---
 .../files/lib/preinit/10_indicate_preinit     | 42 ++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/package/base-files/files/lib/preinit/10_indicate_preinit b/package/base-files/files/lib/preinit/10_indicate_preinit
index 380728f8d6..eb5b50616b 100644
--- a/package/base-files/files/lib/preinit/10_indicate_preinit
+++ b/package/base-files/files/lib/preinit/10_indicate_preinit
@@ -76,6 +76,19 @@ preinit_config_altname() {
        ip link set "$original" altname "$netdev"
 }
 
+preinit_config_port_label() {
+       local original
+
+       local netdev="$1"
+       local label="$2"
+
+       [ -d "/sys/class/net/$label" ] && return
+
+       [ "$netdev" = "$label" ] && return
+
+       ip link set "$netdev" name "$label"
+}
+
 preinit_config_port_path() {
 	local original
 
@@ -102,7 +115,7 @@ preinit_config_board() {
 
 	# 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
+	# Find and move netdevs using eth*s we are configuring by path
 	json_get_keys keys "network_device"
 	for netdev in $keys; do
 		json_select "network_device"
@@ -127,6 +140,33 @@ preinit_config_board() {
 		json_select ..
 	done
 
+       # 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 by label
+       json_get_keys keys "network_device"
+       for netdev in $keys; do
+               json_select "network_device"
+                       json_select "$netdev"
+                               json_get_vars label label
+                               if [ -n "$label" -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 old name to their label name
+       json_get_keys keys "network_device"
+       for netdev in $keys; do
+               json_select "network_device"
+                       json_select "$netdev"
+                               json_get_vars label label
+                               [ -n "$label" ] && preinit_config_port_label "$netdev" "$label"
+                       json_select ..
+               json_select ..
+       done
+
 	json_select network
 		json_select "lan"
 			json_get_vars device
-- 
2.39.5




More information about the openwrt-devel mailing list