fff-network: move PORTORDER to function/library

Submitted by Adrian Schmutzler on Sept. 18, 2020, 11:54 p.m.

Details

Message ID 20200918235426.29153-1-freifunk@adrianschmutzler.de
State Superseded
Headers show

Commit Message

Adrian Schmutzler Sept. 18, 2020, 11:54 p.m.
So far, we define PORTORDER individually in each network.* file.
This creates a lot of duplications, and makes the code to parse those
values very ugly (and it's only used outside of configurenetwork
anyway).

Therefore, move the assignment to a library file, and wrap it into
a function for tidyness. This gives us more overview and nicer
implementation of the retrieval.

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
---
 .../fff/fff-network/arm/network.tplink,c2600  |  2 -
 .../files/lib/functions/fff/portorder         | 45 +++++++++++++++++++
 .../fff/fff-network/mips/network.cpe210       |  2 -
 .../fff/fff-network/mips/network.cpe510       |  2 -
 .../fff-network/mips/network.glinet,gl-ar150  |  2 -
 .../mips/network.tplink,archer-c25-v1         |  2 -
 .../mips/network.tplink,archer-c60-v1         |  2 -
 .../mips/network.tplink,archer-c60-v2         |  2 -
 .../mips/network.tplink,archer-c7-v2          |  2 -
 .../mips/network.tplink,archer-c7-v5          |  2 -
 .../mips/network.tplink,tl-wr1043n-v5         |  2 -
 .../mips/network.tplink,tl-wr1043nd-v4        |  2 -
 .../mips/network.tplink,tl-wr841-v10          |  2 -
 .../mips/network.tplink,tl-wr841-v11          |  2 -
 .../mips/network.tplink,tl-wr841-v12          |  2 -
 .../mips/network.tplink,tl-wr841-v8           |  2 -
 .../fff/fff-network/mipsel/network.r6220      |  2 -
 .../fff-network/mipsel/network.tl-wr841n-v13  |  2 -
 src/packages/fff/fff-support/Makefile         |  2 +-
 .../fff/fff-support/files/usr/sbin/show_info  |  5 +--
 src/packages/fff/fff-web/Makefile             |  2 +-
 .../fff-web/files/www/ssl/cgi-bin/ports.html  |  5 +--
 22 files changed, 51 insertions(+), 42 deletions(-)
 create mode 100644 src/packages/fff/fff-network/files/lib/functions/fff/portorder

Patch hide | download patch | download mbox

diff --git a/src/packages/fff/fff-network/arm/network.tplink,c2600 b/src/packages/fff/fff-network/arm/network.tplink,c2600
index 3535c62d..8c3fc205 100644
--- a/src/packages/fff/fff-network/arm/network.tplink,c2600
+++ b/src/packages/fff/fff-network/arm/network.tplink,c2600
@@ -1,5 +1,3 @@ 
-PORTORDER="5 4 3 2 1"
-
 WANDEV=eth0
 SWITCHDEV=eth0
 CLIENT_PORTS="0t 1 2"
diff --git a/src/packages/fff/fff-network/files/lib/functions/fff/portorder b/src/packages/fff/fff-network/files/lib/functions/fff/portorder
new file mode 100644
index 00000000..f2ea5962
--- /dev/null
+++ b/src/packages/fff/fff-network/files/lib/functions/fff/portorder
@@ -0,0 +1,45 @@ 
+# Copyright 2019 Adrian Schmutzler
+# License GPLv3
+
+get_port_order() {
+	BOARD="$(uci get board.model.name)"
+
+	case "$BOARD" in
+		glinet,gl-ar150)
+			PORTORDER="1"
+			;;
+		r6220)
+			PORTORDER="4 3 2 1 0"
+			;;
+		tplink,archer-c25-v1|\
+		tplink,archer-c60-v1|\
+		tplink,archer-c60-v2|\
+		tplink,tl-wr841-v10|\
+		tplink,tl-wr841-v11|\
+		tplink,tl-wr841-v12)
+			PORTORDER="4 3 2 1"
+			;;
+		tplink,archer-c7-v2|\
+		tplink,archer-c7-v5|\
+		tplink,tl-wdr4300-v1)
+			PORTORDER="1 2 3 4 5"
+			;;
+		tplink,c2600|\
+		tplink,tl-wr1043nd-v4|\
+		tplink,tl-wr1043n-v5)
+			PORTORDER="5 4 3 2 1"
+			;;
+		cpe210|\
+		cpe510)
+			PORTORDER="5 4"
+			;;
+		tplink,tl-wr841-v8)
+			PORTORDER="2 3 4 1"
+			;;
+		tl-wr841n-v13)
+			PORTORDER="0 1 2 3 4"
+			;;
+	esac
+
+	echo "$PORTORDER"
+}
diff --git a/src/packages/fff/fff-network/mips/network.cpe210 b/src/packages/fff/fff-network/mips/network.cpe210
index 7b009946..a690d54a 100644
--- a/src/packages/fff/fff-network/mips/network.cpe210
+++ b/src/packages/fff/fff-network/mips/network.cpe210
@@ -1,7 +1,5 @@ 
 . /lib/functions/fff/network
 
-PORTORDER="5 4"
-
 WANDEV=eth0
 SWITCHDEV=eth0
 CLIENT_PORTS="0t"
diff --git a/src/packages/fff/fff-network/mips/network.cpe510 b/src/packages/fff/fff-network/mips/network.cpe510
index 7b009946..a690d54a 100644
--- a/src/packages/fff/fff-network/mips/network.cpe510
+++ b/src/packages/fff/fff-network/mips/network.cpe510
@@ -1,7 +1,5 @@ 
 . /lib/functions/fff/network
 
-PORTORDER="5 4"
-
 WANDEV=eth0
 SWITCHDEV=eth0
 CLIENT_PORTS="0t"
diff --git a/src/packages/fff/fff-network/mips/network.glinet,gl-ar150 b/src/packages/fff/fff-network/mips/network.glinet,gl-ar150
index 49bffebe..cb1ce84c 100644
--- a/src/packages/fff/fff-network/mips/network.glinet,gl-ar150
+++ b/src/packages/fff/fff-network/mips/network.glinet,gl-ar150
@@ -1,7 +1,5 @@ 
 . /lib/functions/fff/network
 
-PORTORDER="1"
-
 WANDEV=eth1
 SWITCHDEV=eth0
 WAN_PORTS=
diff --git a/src/packages/fff/fff-network/mips/network.tplink,archer-c25-v1 b/src/packages/fff/fff-network/mips/network.tplink,archer-c25-v1
index 59149cf7..13355d53 100644
--- a/src/packages/fff/fff-network/mips/network.tplink,archer-c25-v1
+++ b/src/packages/fff/fff-network/mips/network.tplink,archer-c25-v1
@@ -1,5 +1,3 @@ 
-PORTORDER="4 3 2 1"
-
 WANDEV=eth1
 SWITCHDEV=eth0
 CLIENT_PORTS="1 2 0t"
diff --git a/src/packages/fff/fff-network/mips/network.tplink,archer-c60-v1 b/src/packages/fff/fff-network/mips/network.tplink,archer-c60-v1
index 6d2578f6..aafc5af3 100644
--- a/src/packages/fff/fff-network/mips/network.tplink,archer-c60-v1
+++ b/src/packages/fff/fff-network/mips/network.tplink,archer-c60-v1
@@ -1,5 +1,3 @@ 
-PORTORDER="4 3 2 1"
-
 WANDEV=eth1
 SWITCHDEV=eth0
 CLIENT_PORTS="1 2 0t"
diff --git a/src/packages/fff/fff-network/mips/network.tplink,archer-c60-v2 b/src/packages/fff/fff-network/mips/network.tplink,archer-c60-v2
index 6d2578f6..aafc5af3 100644
--- a/src/packages/fff/fff-network/mips/network.tplink,archer-c60-v2
+++ b/src/packages/fff/fff-network/mips/network.tplink,archer-c60-v2
@@ -1,5 +1,3 @@ 
-PORTORDER="4 3 2 1"
-
 WANDEV=eth1
 SWITCHDEV=eth0
 CLIENT_PORTS="1 2 0t"
diff --git a/src/packages/fff/fff-network/mips/network.tplink,archer-c7-v2 b/src/packages/fff/fff-network/mips/network.tplink,archer-c7-v2
index f774a53e..9a8f8614 100644
--- a/src/packages/fff/fff-network/mips/network.tplink,archer-c7-v2
+++ b/src/packages/fff/fff-network/mips/network.tplink,archer-c7-v2
@@ -1,5 +1,3 @@ 
-PORTORDER="1 2 3 4 5"
-
 WANDEV=eth1
 SWITCHDEV=eth1
 CLIENT_PORTS="4 5 0t"
diff --git a/src/packages/fff/fff-network/mips/network.tplink,archer-c7-v5 b/src/packages/fff/fff-network/mips/network.tplink,archer-c7-v5
index 493134a1..1a217e8b 100644
--- a/src/packages/fff/fff-network/mips/network.tplink,archer-c7-v5
+++ b/src/packages/fff/fff-network/mips/network.tplink,archer-c7-v5
@@ -1,7 +1,5 @@ 
 . /lib/functions/fff/network
 
-PORTORDER="1 2 3 4 5"
-
 WANDEV=eth0
 SWITCHDEV=eth0
 CLIENT_PORTS="4 5 0t"
diff --git a/src/packages/fff/fff-network/mips/network.tplink,tl-wr1043n-v5 b/src/packages/fff/fff-network/mips/network.tplink,tl-wr1043n-v5
index c52e74e6..734922ae 100644
--- a/src/packages/fff/fff-network/mips/network.tplink,tl-wr1043n-v5
+++ b/src/packages/fff/fff-network/mips/network.tplink,tl-wr1043n-v5
@@ -1,5 +1,3 @@ 
-PORTORDER="5 4 3 2 1"
-
 WANDEV=eth0
 SWITCHDEV=eth0
 CLIENT_PORTS="1 2 0t"
diff --git a/src/packages/fff/fff-network/mips/network.tplink,tl-wr1043nd-v4 b/src/packages/fff/fff-network/mips/network.tplink,tl-wr1043nd-v4
index c52e74e6..734922ae 100644
--- a/src/packages/fff/fff-network/mips/network.tplink,tl-wr1043nd-v4
+++ b/src/packages/fff/fff-network/mips/network.tplink,tl-wr1043nd-v4
@@ -1,5 +1,3 @@ 
-PORTORDER="5 4 3 2 1"
-
 WANDEV=eth0
 SWITCHDEV=eth0
 CLIENT_PORTS="1 2 0t"
diff --git a/src/packages/fff/fff-network/mips/network.tplink,tl-wr841-v10 b/src/packages/fff/fff-network/mips/network.tplink,tl-wr841-v10
index 44054065..498708b0 100644
--- a/src/packages/fff/fff-network/mips/network.tplink,tl-wr841-v10
+++ b/src/packages/fff/fff-network/mips/network.tplink,tl-wr841-v10
@@ -1,5 +1,3 @@ 
-PORTORDER="4 3 2 1"
-
 WANDEV=eth1
 SWITCHDEV=eth0
 CLIENT_PORTS="1 2 0t"
diff --git a/src/packages/fff/fff-network/mips/network.tplink,tl-wr841-v11 b/src/packages/fff/fff-network/mips/network.tplink,tl-wr841-v11
index 44054065..498708b0 100644
--- a/src/packages/fff/fff-network/mips/network.tplink,tl-wr841-v11
+++ b/src/packages/fff/fff-network/mips/network.tplink,tl-wr841-v11
@@ -1,5 +1,3 @@ 
-PORTORDER="4 3 2 1"
-
 WANDEV=eth1
 SWITCHDEV=eth0
 CLIENT_PORTS="1 2 0t"
diff --git a/src/packages/fff/fff-network/mips/network.tplink,tl-wr841-v12 b/src/packages/fff/fff-network/mips/network.tplink,tl-wr841-v12
index 44054065..498708b0 100644
--- a/src/packages/fff/fff-network/mips/network.tplink,tl-wr841-v12
+++ b/src/packages/fff/fff-network/mips/network.tplink,tl-wr841-v12
@@ -1,5 +1,3 @@ 
-PORTORDER="4 3 2 1"
-
 WANDEV=eth1
 SWITCHDEV=eth0
 CLIENT_PORTS="1 2 0t"
diff --git a/src/packages/fff/fff-network/mips/network.tplink,tl-wr841-v8 b/src/packages/fff/fff-network/mips/network.tplink,tl-wr841-v8
index ace93630..541fb3d3 100644
--- a/src/packages/fff/fff-network/mips/network.tplink,tl-wr841-v8
+++ b/src/packages/fff/fff-network/mips/network.tplink,tl-wr841-v8
@@ -1,5 +1,3 @@ 
-PORTORDER="2 3 4 1"
-
 WANDEV=eth1
 SWITCHDEV=eth0
 CLIENT_PORTS="1 4 0t"
diff --git a/src/packages/fff/fff-network/mipsel/network.r6220 b/src/packages/fff/fff-network/mipsel/network.r6220
index 800dcb40..f1f77bfe 100644
--- a/src/packages/fff/fff-network/mipsel/network.r6220
+++ b/src/packages/fff/fff-network/mipsel/network.r6220
@@ -1,7 +1,5 @@ 
 . /lib/functions/fff/network
 
-PORTORDER="4 3 2 1 0"
-
 WANDEV=eth0
 SWITCHDEV=eth0
 CLIENT_PORTS="6t 0 1"
diff --git a/src/packages/fff/fff-network/mipsel/network.tl-wr841n-v13 b/src/packages/fff/fff-network/mipsel/network.tl-wr841n-v13
index 602b77e1..273381a9 100644
--- a/src/packages/fff/fff-network/mipsel/network.tl-wr841n-v13
+++ b/src/packages/fff/fff-network/mipsel/network.tl-wr841n-v13
@@ -1,7 +1,5 @@ 
 . /lib/functions/system.sh
 
-PORTORDER="0 1 2 3 4"
-
 WANDEV=eth0
 SWITCHDEV=eth0
 CLIENT_PORTS="6t 3 4"
diff --git a/src/packages/fff/fff-support/Makefile b/src/packages/fff/fff-support/Makefile
index 76ca26c8..32c91dda 100644
--- a/src/packages/fff/fff-support/Makefile
+++ b/src/packages/fff/fff-support/Makefile
@@ -1,7 +1,7 @@ 
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=fff-support
-PKG_RELEASE:=5
+PKG_RELEASE:=6
 
 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
 
diff --git a/src/packages/fff/fff-support/files/usr/sbin/show_info b/src/packages/fff/fff-support/files/usr/sbin/show_info
index cd3b4d2e..5024daa7 100755
--- a/src/packages/fff/fff-support/files/usr/sbin/show_info
+++ b/src/packages/fff/fff-support/files/usr/sbin/show_info
@@ -171,9 +171,8 @@  else
 	echo "simple-tc nicht installiert."
 fi
 
-if grep -q 'PORTORDER=' /etc/network.$board_name ; then
-	portorder=$(awk -F= '/PORTORDER=/ { print $2 }' /etc/network.$board_name | sed "s/\"//g")
-fi
+. /lib/functions/fff/portorder
+portorder="$(get_port_order)"
 
 echo ""
 if swconfig list | grep -q switch0 ; then
diff --git a/src/packages/fff/fff-web/Makefile b/src/packages/fff/fff-web/Makefile
index c0783b7b..139cd24d 100644
--- a/src/packages/fff/fff-web/Makefile
+++ b/src/packages/fff/fff-web/Makefile
@@ -1,7 +1,7 @@ 
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=fff-web
-PKG_RELEASE:=11
+PKG_RELEASE:=12
 
 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
 
diff --git a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html
index 01506fce..9bbd68db 100755
--- a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html
+++ b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/ports.html
@@ -108,9 +108,8 @@  format_port() {
 					echo "</td>"
 				fi
 				
-				if grep -q 'PORTORDER=' /etc/network.$board_name ; then
-					portorder=$(awk -F= '/PORTORDER=/ { print $2 }' /etc/network.$board_name | sed "s/\"//g")
-				fi
+				. /lib/functions/fff/portorder
+				portorder="$(get_port_order)"
 				for internalport in $portorder
 				do
 					line=$(swconfig dev switch0 port "$internalport" show | tr -d '\n' | tr -d '\t')