summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2015-11-24 21:16:35 +0000
committerJo-Philipp Wich <jow@openwrt.org>2015-11-24 21:16:35 +0000
commitd6b5ce48dd95f05842df892cf4afe68d117ac34a (patch)
tree91d736419959795784d26406200f8f1eeb73b85b
parent11f2007895cd7287da785213591148202a321c8e (diff)
downloadmtk-20170518-d6b5ce48dd95f05842df892cf4afe68d117ac34a.zip
mtk-20170518-d6b5ce48dd95f05842df892cf4afe68d117ac34a.tar.gz
mtk-20170518-d6b5ce48dd95f05842df892cf4afe68d117ac34a.tar.bz2
base-files: add ucidef_set_interface_wan() and ucidef_add_switch_ports()
Add further helper functions to uci-defaults-new.sh for easier declarations of complex switch layouts. Signed-off-by: Jo-Philipp Wich <jow@openwrt.org> SVN-Revision: 47638
-rwxr-xr-xpackage/base-files/files/lib/functions/uci-defaults-new.sh50
1 files changed, 50 insertions, 0 deletions
diff --git a/package/base-files/files/lib/functions/uci-defaults-new.sh b/package/base-files/files/lib/functions/uci-defaults-new.sh
index 7222ff8..6a8b6b9 100755
--- a/package/base-files/files/lib/functions/uci-defaults-new.sh
+++ b/package/base-files/files/lib/functions/uci-defaults-new.sh
@@ -52,6 +52,14 @@ ucidef_set_interface_lan() {
json_select ..
}
+ucidef_set_interface_wan() {
+ local wan_if=$1
+
+ json_select_object network
+ _ucidef_set_interface wan $wan_if
+ json_select ..
+}
+
ucidef_set_interfaces_lan_wan() {
local lan_if=$1
local wan_if=$2
@@ -91,6 +99,48 @@ ucidef_add_switch_attr() {
json_select ..
}
+ucidef_add_switch_ports() {
+ local name="$1"; shift
+ local port num role dev idx
+
+ json_select_object switch
+ json_select_object "$name"
+ json_select_array ports
+
+ for port in "$@"; do
+ case "$port" in
+ [0-9]*@*)
+ num="${port%%@*}"
+ dev="${port##*@}"
+ ;;
+ [0-9]*:*:[0-9]*)
+ num="${port%%:*}"
+ idx="${port##*:}"
+ role="${port#[0-9]*:}"; role="${role%:*}"
+ ;;
+ [0-9]*:*)
+ num="${port%%:*}"
+ role="${port##*:}"
+ ;;
+ esac
+
+ if [ -n "$num" ] && [ -n "$dev$role" ]; then
+ json_add_object
+ json_add_int num "$num"
+ [ -n "$dev" ] && json_add_string device "$dev"
+ [ -n "$role" ] && json_add_string role "$role"
+ [ -n "$idx" ] && json_add_int index "$idx"
+ json_close_object
+ fi
+
+ unset num dev role idx
+ done
+
+ json_select ..
+ json_select ..
+ json_select ..
+}
+
ucidef_add_switch_vlan() {
local name=$1
local vlan=$2