fff-network: move PORTORDER to function/library

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>
Acked-by: Christian Dresel <freifunk@dresel.systems>
Reviewed-by: Robert Langhammer <rlanghammer@web.de>
This commit is contained in:
Adrian Schmutzler 2020-09-19 01:50:31 +02:00
parent 37695a1cfc
commit cb4bce7cc2
24 changed files with 56 additions and 47 deletions

View File

@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=fff-network
PKG_RELEASE:=29
PKG_RELEASE:=30
include $(INCLUDE_DIR)/package.mk

View File

@ -1,5 +1,3 @@
PORTORDER="5 4 3 2 1"
WANDEV=eth0
SWITCHDEV=eth0
CLIENT_PORTS="0t 1 2"

View File

@ -0,0 +1,47 @@
# Copyright 2019 Adrian Schmutzler
# License GPLv3
get_port_order() {
local BOARD=$(uci get board.model.name)
local PORTORDER
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,c50-v4|\
tl-wr841n-v13)
PORTORDER="0 1 2 3 4"
;;
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"
;;
esac
echo "$PORTORDER"
}

View File

@ -1,7 +1,5 @@
. /lib/functions/fff/network
PORTORDER="5 4"
WANDEV=eth0
SWITCHDEV=eth0
CLIENT_PORTS="0t"

View File

@ -1,7 +1,5 @@
. /lib/functions/fff/network
PORTORDER="5 4"
WANDEV=eth0
SWITCHDEV=eth0
CLIENT_PORTS="0t"

View File

@ -1,7 +1,5 @@
. /lib/functions/fff/network
PORTORDER="1"
WANDEV=eth1
SWITCHDEV=eth0
WAN_PORTS=

View File

@ -1,5 +1,3 @@
PORTORDER="4 3 2 1"
WANDEV=eth1
SWITCHDEV=eth0
CLIENT_PORTS="1 2 0t"

View File

@ -1,5 +1,3 @@
PORTORDER="4 3 2 1"
WANDEV=eth1
SWITCHDEV=eth0
CLIENT_PORTS="1 2 0t"

View File

@ -1,5 +1,3 @@
PORTORDER="4 3 2 1"
WANDEV=eth1
SWITCHDEV=eth0
CLIENT_PORTS="1 2 0t"

View File

@ -1,5 +1,3 @@
PORTORDER="1 2 3 4 5"
WANDEV=eth1
SWITCHDEV=eth1
CLIENT_PORTS="4 5 0t"

View File

@ -1,7 +1,5 @@
. /lib/functions/fff/network
PORTORDER="1 2 3 4 5"
WANDEV=eth0
SWITCHDEV=eth0
CLIENT_PORTS="4 5 0t"

View File

@ -1,5 +1,3 @@
PORTORDER="5 4 3 2 1"
WANDEV=eth0
SWITCHDEV=eth0
CLIENT_PORTS="1 2 0t"

View File

@ -1,5 +1,3 @@
PORTORDER="5 4 3 2 1"
WANDEV=eth0
SWITCHDEV=eth0
CLIENT_PORTS="1 2 0t"

View File

@ -1,5 +1,3 @@
PORTORDER="4 3 2 1"
WANDEV=eth1
SWITCHDEV=eth0
CLIENT_PORTS="1 2 0t"

View File

@ -1,5 +1,3 @@
PORTORDER="4 3 2 1"
WANDEV=eth1
SWITCHDEV=eth0
CLIENT_PORTS="1 2 0t"

View File

@ -1,5 +1,3 @@
PORTORDER="4 3 2 1"
WANDEV=eth1
SWITCHDEV=eth0
CLIENT_PORTS="1 2 0t"

View File

@ -1,5 +1,3 @@
PORTORDER="2 3 4 1"
WANDEV=eth1
SWITCHDEV=eth0
CLIENT_PORTS="1 4 0t"

View File

@ -1,7 +1,5 @@
. /lib/functions/fff/network
PORTORDER="4 3 2 1 0"
WANDEV=eth0
SWITCHDEV=eth0
CLIENT_PORTS="6t 0 1"

View File

@ -1,7 +1,5 @@
. /lib/functions/system.sh
PORTORDER="0 1 2 3 4"
WANDEV=eth0
SWITCHDEV=eth0
CLIENT_PORTS="6t 3 4"

View File

@ -1,7 +1,5 @@
. /lib/functions/fff/network
PORTORDER="0 1 2 3 4"
WANDEV=eth0
SWITCHDEV=eth0
CLIENT_PORTS="6t 3 4"

View File

@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=fff-support
PKG_RELEASE:=6
PKG_RELEASE:=7
include $(INCLUDE_DIR)/package.mk

View File

@ -3,6 +3,7 @@
. /etc/firmware_release
. /lib/functions/fff/evalhoodinfo
. /lib/functions/fff/evalbytes
. /lib/functions/fff/portorder
. /lib/functions.sh # required for config_load and config_foreach
board_name=$(uci -q get board.model.name)
@ -171,9 +172,7 @@ 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
portorder=$(get_port_order)
echo ""
if swconfig list | grep -q switch0 ; then

View File

@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=fff-web-ui
PKG_RELEASE:=17
PKG_RELEASE:=18
include $(INCLUDE_DIR)/package.mk

View File

@ -107,10 +107,9 @@ format_port() {
echo "<span class=\"stat\">$speed</span>"
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')
@ -123,7 +122,7 @@ format_port() {
if [ -n "$portorder" ] ; then
echo "<td class=\"swport\" style=\"width:4em\"></td>"
fi
swconfig dev switch0 show | grep "\t*link:" | while read line ; do
line=$(echo "$line" | tr -d '\n' | tr -d '\t')
port=$(echo "$line" | sed 's/.* port:\([^ ]*\) .*/\1/')