From patchwork Fri May 4 15:42:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Yeryomin X-Patchwork-Id: 908821 X-Patchwork-Delegate: blogic@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (helo) smtp.helo=arrakis.dune.hu (client-ip=78.24.191.176; helo=arrakis.dune.hu; envelope-from=openwrt-devel-bounces@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=advem.lv Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40cx9q2h4mz9s3D for ; Sat, 5 May 2018 01:43:11 +1000 (AEST) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 1C149B802C7; Fri, 4 May 2018 17:43:07 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00,RDNS_NONE autolearn=no autolearn_force=no version=3.4.1 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP; Fri, 4 May 2018 17:43:07 +0200 (CEST) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id C3C26B800CE for ; Fri, 4 May 2018 17:43:04 +0200 (CEST) X-policyd-weight: using cached result; rate:hard: -6.1 Received: from mail.pbx.lv (unknown [213.175.92.62]) by arrakis.dune.hu (Postfix) with ESMTP for ; Fri, 4 May 2018 17:43:04 +0200 (CEST) Received: from localhost.localdomain (unknown [213.175.92.61]) by mail.pbx.lv (MailSystem) with ESMTPSA id 582141A40EC for ; Fri, 4 May 2018 18:43:04 +0300 (EEST) From: Roman Yeryomin To: OpenWrt Development List Date: Fri, 4 May 2018 18:42:36 +0300 Message-Id: <20180504154236.9804-1-roman@advem.lv> X-Mailer: git-send-email 2.14.1 Subject: [OpenWrt-Devel] [PATCH] base-files: rework _ucidef_set_interface to be more generic X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" 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 +++++++--------------- .../linux/ar71xx/base-files/etc/board.d/02_network | 6 +- 2 files changed, 27 insertions(+), 53 deletions(-) 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() { diff --git a/target/linux/ar71xx/base-files/etc/board.d/02_network b/target/linux/ar71xx/base-files/etc/board.d/02_network index cbbcf53946..0c7034525b 100755 --- a/target/linux/ar71xx/base-files/etc/board.d/02_network +++ b/target/linux/ar71xx/base-files/etc/board.d/02_network @@ -400,7 +400,7 @@ ar71xx_setup_interfaces() "0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan" ;; ew-balin) - ucidef_set_interface_raw "usb2" "usb0" "static" + ucidef_set_interface "usb2" ifname "usb0" protocol "static" ucidef_add_switch "switch0" \ "0@eth0" "5:lan:4" "4:lan:5" "3:wan" ;; @@ -467,7 +467,7 @@ ar71xx_setup_interfaces() ;; tellstick-znet-lite) ucidef_set_interface_wan "eth0" - ucidef_set_interface_raw "wlan" "wlan0" "dhcp" + ucidef_set_interface "wlan" ifname "wlan0" protocol "dhcp" ;; tl-mr3420-v2|\ tl-wr841n-v8|\ @@ -498,7 +498,7 @@ ar71xx_setup_interfaces() ;; tl-wr841n-v1|\ tl-wr941nd) - ucidef_set_interface_raw "eth" "eth0" + ucidef_set_interface "eth" ifname "eth0" ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "wan" ;; tl-wr741nd|\