From 85048a9c1fa4d37b5896d9237d28bbadbbe09d19 Mon Sep 17 00:00:00 2001 From: Roman Yeryomin Date: Fri, 4 May 2018 18:42:36 +0300 Subject: base-files: rework _ucidef_set_interface to be more generic This is a rework of previously submitted patch reworking ucidef_set_interface_raw [1]. Here, keep the idea but instead make _ucidef_set_interface more generic and use it instead of ucidef_set_interface_raw. Also change the users like ucidef_set_interface_lan and others. [1] https://patchwork.ozlabs.org/patch/844961/ Signed-off-by: Roman Yeryomin --- .../base-files/files/lib/functions/uci-defaults.sh | 74 +++++++--------------- 1 file changed, 24 insertions(+), 50 deletions(-) (limited to 'package/base-files') diff --git a/package/base-files/files/lib/functions/uci-defaults.sh b/package/base-files/files/lib/functions/uci-defaults.sh index 3126fe6510..8065af24a5 100755 --- a/package/base-files/files/lib/functions/uci-defaults.sh +++ b/package/base-files/files/lib/functions/uci-defaults.sh @@ -27,29 +27,26 @@ json_select_object() { json_select "$1" } -_ucidef_set_interface() { - local name="$1" - local iface="$2" - local proto="$3" +ucidef_set_interface() { + local network=$1 - json_select_object "$name" - json_add_string ifname "$iface" - - if ! json_is_a protocol string || [ -n "$proto" ]; then - case "$proto" in - static|dhcp|none|pppoe) : ;; - *) - case "$name" in - lan) proto="static" ;; - wan) proto="dhcp" ;; - *) proto="none" ;; - esac - ;; - esac + [ -z "$network" ] && return - json_add_string protocol "$proto" - fi + json_select_object network + json_select_object "$network" + shift + + while [ -n "$1" ]; do + local opt="$1" + local val="$2" + shift; shift; + [ -n "$opt" -a -n "$val" ] || break + + json_add_string "$opt" "$val" + done + + json_select .. json_select .. } @@ -66,31 +63,19 @@ ucidef_set_model_name() { } ucidef_set_interface_lan() { - json_select_object network - _ucidef_set_interface lan "$@" - json_select .. + ucidef_set_interface "lan" ifname "$1" protocol "${2:-static}" } ucidef_set_interface_wan() { - json_select_object network - _ucidef_set_interface wan "$@" - json_select .. + ucidef_set_interface "wan" ifname "$1" protocol "${2:-dhcp}" } ucidef_set_interfaces_lan_wan() { local lan_if="$1" local wan_if="$2" - json_select_object network - _ucidef_set_interface lan "$lan_if" - _ucidef_set_interface wan "$wan_if" - json_select .. -} - -ucidef_set_interface_raw() { - json_select_object network - _ucidef_set_interface "$@" - json_select .. + ucidef_set_interface_lan "$lan_if" + ucidef_set_interface_wan "$wan_if" } _ucidef_add_switch_port() { @@ -185,9 +170,9 @@ _ucidef_finish_switch_roles() { devices="${devices:+$devices }$device" fi json_select .. - - _ucidef_set_interface "$role" "$devices" json_select .. + + ucidef_set_interface "$role" ifname "$devices" done } @@ -300,18 +285,7 @@ ucidef_set_interface_macaddr() { local network="$1" local macaddr="$2" - json_select_object network - - json_select "$network" - [ $? -eq 0 ] || { - json_select .. - return - } - - json_add_string macaddr "$macaddr" - json_select .. - - json_select .. + ucidef_set_interface "$network" macaddr "$macaddr" } ucidef_add_atm_bridge() { -- cgit v1.2.3