diff mbox series

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

Message ID mailman.133959.1728987213.1280.openwrt-devel@lists.openwrt.org
State New
Headers show
Series None | expand

Commit Message

Evan Jobling Oct. 15, 2024, 10:13 a.m. UTC
The sender domain has a DMARC Reject/Quarantine policy which disallows
sending mailing list messages using the original "From" header.

To mitigate this problem, the original message has been wrapped
automatically by the mailing list software.
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@mslsc.com.au>
---
 .../files/lib/preinit/10_indicate_preinit     | 42 ++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)
diff mbox series

Patch

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"