[PATCH 3/5] base-files: preinit: add ethernet label name pass

Evan Jobling evan.jobling at mslsc.com.au
Tue Oct 15 03:13:26 PDT 2024


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

A device specific example:
The Firebox M300 by factory has ports eth3-eth7
which are on a DSA switch and which conflict
with eth3/eth4 which are the default names for
the switch conduits.

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 627b56e41d..cb99cbea60 100644
--- a/package/base-files/files/lib/preinit/10_indicate_preinit
+++ b/package/base-files/files/lib/preinit/10_indicate_preinit
@@ -77,6 +77,19 @@ preinit_config_port_bypath() {
 	ip link set "$original" name "$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_board() {
 	/bin/board_detect /tmp/board.json
 
@@ -89,7 +102,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"
@@ -123,6 +136,33 @@ preinit_config_board() {
 
 	[ -n "$device" -o -n "$ports" ] || return
 
+	# 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
+
 	# swconfig uses $device and DSA uses ports
 	[ -z "$ports" ] && {
 		ports="$device"
-- 
2.39.5




More information about the openwrt-devel mailing list