From 1801a765103c0e26ebb9e6b895b3cc36eced471a Mon Sep 17 00:00:00 2001
From: Markus Gothe <markus.gothe@genexis.eu>
Date: Tue, 25 Feb 2025 17:16:06 +0100
Subject: [PATCH] airoha: Allow aribtrary portmapping in UCI.

---
 airoha/base-files/lib/network/switch.sh | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/airoha/base-files/lib/network/switch.sh b/airoha/base-files/lib/network/switch.sh
index 4844f4f9d..762cae131 100644
--- a/airoha/base-files/lib/network/switch.sh
+++ b/airoha/base-files/lib/network/switch.sh
@@ -6,7 +6,8 @@ WANDEV=
 LANDEVS=
 
 tc3162_eth_portmap() {
-	wan_port="-1"
+	local wan_port="-1"
+	local portmap port i
 
 	case "$WANDEV" in
 		eth0.[0-9])
@@ -15,13 +16,10 @@ tc3162_eth_portmap() {
 	esac
 
 	portmap="${wan_port}"
-	j=1
-	for i in `seq 1 6`; do
-		iface="$(echo $LANDEVS | cut -d' ' -f$j)"
+	for i in $(seq 1 6); do
 		port="-1"
 		if [ "${i}" -ne "${wan_port}" ]; then
-			[ "${iface:0:5}" = "eth0." ] && port=${iface#eth0.}
-			j=$((j+1))
+			echo $LANDEVS | tr ' ' '\n' | grep -qxF "eth0.${i}" && port=$i
 		fi
 		portmap="${portmap} ${port}"
 	done
-- 
GitLab