From: Sander Vanheule Date: Wed, 24 Jan 2024 09:49:41 +0000 (+0100) Subject: realtek: move port filtering out of uci_set_poe() X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=7cbfe5654d6e;p=openwrt%2Fstaging%2Fthess.git realtek: move port filtering out of uci_set_poe() uci_set_poe() now performs two duties: filtering the list of device ports to exclude non-PoE ports, and generating the PoE related device config. Extract the port filtering to an external function, which is made a bit more readable by the use of 'sort -V [-r] | uniq -u' to filter duplicate entries out of a (reverse) version sorted list. Signed-off-by: Sander Vanheule --- diff --git a/target/linux/realtek/base-files/etc/board.d/02_network b/target/linux/realtek/base-files/etc/board.d/02_network index fb9c28d794..1c1e4e9cd2 100644 --- a/target/linux/realtek/base-files/etc/board.d/02_network +++ b/target/linux/realtek/base-files/etc/board.d/02_network @@ -8,20 +8,32 @@ ucidef_set_poe() { json_add_string "budget" "$1" json_select_array ports for port in $2; do - if [ -n "$3" -a -n "$(expr "$3" : "\(.\+[[:space:]]\)\{0,1\}$port\([[:space:]].*\|\$\)")" ]; then - continue # skip ports passed via $3 - fi json_add_string "" "$port" done json_select .. json_select .. } +_filter_port_list_ordered() { + local ports="$1" + local excluded="$2" + local sort_opts="$3" + echo $ports $excluded | xargs -n1 basename | sort -V $sort_opts | uniq -u | xargs +} + +filter_port_list() { + _filter_port_list_ordered "$1" "$2" +} + +filter_port_list_reverse() { + _filter_port_list_ordered "$1" "$2" "-r" +} + board=$(board_name) board_config_update lan_list=$(ls -1 -v -d /sys/class/net/lan* | xargs -n1 basename | xargs) -lan_list_rev=$(ls -1 -v -d -r /sys/class/net/lan* | xargs -n1 basename | xargs) + ucidef_set_bridge_device switch ucidef_set_interface_lan "$lan_list" @@ -70,35 +82,35 @@ done case $board in d-link,dgs-1210-10mp-f) - ucidef_set_poe 130 "$lan_list" "lan9 lan10" + ucidef_set_poe 130 "$(filter_port_list "$lan_list" "lan9 lan10")" ;; d-link,dgs-1210-10p) - ucidef_set_poe 65 "$lan_list" "lan9 lan10" + ucidef_set_poe 65 "$(filter_port_list "$lan_list" "lan9 lan10")" ;; d-link,dgs-1210-28mp-f) ucidef_set_poe 370 "lan8 lan7 lan6 lan5 lan4 lan3 lan2 lan1 lan16 lan15 lan14 lan13 lan12 lan11 lan10 lan9 lan24 lan23 - lan22 lan21 lan20 lan19 lan18 lan17" "lan25 lan26 lan27 lan28" + lan22 lan21 lan20 lan19 lan18 lan17" ;; engenius,ews2910p) - ucidef_set_poe 60 "$lan_list" "lan9 lan10" + ucidef_set_poe 60 "$(filter_port_list "$lan_list" "lan9 lan10")" ;; hpe,1920-8g-poe-65w) - ucidef_set_poe 65 "$lan_list_rev" "lan9 lan10" + ucidef_set_poe 65 "$(filter_port_list_reversed "$lan_list" "lan9 lan10")" ;; hpe,1920-8g-poe-180w) - ucidef_set_poe 180 "$lan_list_rev" "lan9 lan10" + ucidef_set_poe 180 "$(filter_port_list_reversed "$lan_list" "lan9 lan10")" ;; netgear,gs110tpp-v1) - ucidef_set_poe 130 "$lan_list" "lan9 lan10" + ucidef_set_poe 130 "$(filter_port_list "$lan_list" "lan9 lan10")" ;; netgear,gs110tup-v1) - ucidef_set_poe 240 "$lan_list" "lan9 lan10" + ucidef_set_poe 240 "$(filter_port_list "$lan_list" "lan9 lan10")" ;; netgear,gs310tp-v1) - ucidef_set_poe 55 "$lan_list" "lan9 lan10" + ucidef_set_poe 55 "$(filter_port_list "$lan_list" "lan9 lan10")" ;; zyxel,gs1900-10hp) - ucidef_set_poe 77 "$lan_list" "lan9 lan10" + ucidef_set_poe 77 "$(filter_port_list "$lan_list" "lan9 lan10")" ;; zyxel,gs1900-8hp-v1|\ zyxel,gs1900-8hp-v2) @@ -106,7 +118,7 @@ zyxel,gs1900-8hp-v2) ;; zyxel,gs1900-24hp-v1|\ zyxel,gs1900-24hp-v2) - ucidef_set_poe 170 "$lan_list" "lan25 lan26" + ucidef_set_poe 170 "$(filter_port_list "$lan_list" "lan25 lan26")" ;; esac