From patchwork Tue Dec 5 23:16:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Yeryomin X-Patchwork-Id: 844961 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=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="PEHRcs7d"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yryN8721lz9sxR for ; Wed, 6 Dec 2017 10:18:16 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Subject:Message-Id:Date:To: From:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=DPcn9KwA85b8RQaH+ASOlHGLg4Vhx3+Gga9fIqdabpI=; b=PEHRcs7dfmY2NZ g2McMZeiks4G6uGAyTgzz8fnSsv+DvxfyOoMHFurbB0l94Zxc2QA0YU4EVwZiDzKGc/6lxgT9qu0U BaAsV4jAbqA8mK13s+r5kx0nVIHuNIXB/i6u9dWcjDOg+jm36pG2d3JlQOZXeqz9WoKE57B/As+lg X8+P1kb6VTRjKdMyIQOs19L0gGtBEbgBg+2LB8DV4LftmS20hhtxBubnqeGq1gu4yq5z3mRWyuCcv J318t1QiMclUFHec1i59EQJ1NbbsHrx2mDJWJzoj8mW/srvl36mH0w+b9XkIYxxmYgBs2P7sqYSRb oig02y9Bs1wTgJ9+PHpg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eMMTT-0007vE-68; Tue, 05 Dec 2017 23:18:03 +0000 Received: from [213.175.92.62] (helo=mail.pbx.lv) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eMMT3-0007t5-OE for lede-dev@lists.infradead.org; Tue, 05 Dec 2017 23:17:40 +0000 Received: from localhost.localdomain (unknown [213.175.92.61]) by mail.pbx.lv (MailSystem) with ESMTPSA id 5B7F319F583 for ; Wed, 6 Dec 2017 01:17:09 +0200 (EET) From: Roman Yeryomin To: LEDE Development List Date: Wed, 6 Dec 2017 01:16:41 +0200 Message-Id: <20171205231641.13394-1-roman@advem.lv> X-Mailer: git-send-email 2.14.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171205_151738_034558_D8071D07 X-CRM114-Status: UNSURE ( 6.23 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -1.1 (-) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-1.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.8 RDNS_NONE Delivered to internal network by a host with no rDNS Subject: [LEDE-DEV] [PATCH v3] base-files: expand ucidef_set_interface_raw to allow custom configuration X-BeenThere: lede-dev@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This allows custom config generation. E.g. setting lan adrress from eeprom or random address (so that routers can be chained by default) or configuring a fully custom interface. Changes from v2: - use shift istead of hack with arbitrary string Changes from v1: - fix protocol option name for users Signed-off-by: Roman Yeryomin --- .../base-files/files/lib/functions/uci-defaults.sh | 23 +++++++++++++++++++++- .../linux/ar71xx/base-files/etc/board.d/02_network | 4 ++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/package/base-files/files/lib/functions/uci-defaults.sh b/package/base-files/files/lib/functions/uci-defaults.sh index 606183ec37..ece4483b15 100755 --- a/package/base-files/files/lib/functions/uci-defaults.sh +++ b/package/base-files/files/lib/functions/uci-defaults.sh @@ -88,8 +88,29 @@ ucidef_set_interfaces_lan_wan() { } ucidef_set_interface_raw() { + local opt="" + local val="" + + [ -z "$1" ] && return + json_select_object network - _ucidef_set_interface "$@" + json_select_object "$1" + shift + + for i in "$@"; do + [ -z $opt ] && { + opt="$i" + continue + } + [ -z $val ] && val="$i" + + json_add_string "$opt" "$val" + + opt="" + val="" + done + + json_select .. json_select .. } 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 7cf4212ac7..c9473b64f7 100755 --- a/target/linux/ar71xx/base-files/etc/board.d/02_network +++ b/target/linux/ar71xx/base-files/etc/board.d/02_network @@ -427,7 +427,7 @@ ar71xx_setup_interfaces() ;; tellstick-znet-lite) ucidef_set_interface_wan "eth0" - ucidef_set_interface_raw "wlan" "wlan0" "dhcp" + ucidef_set_interface_raw "wlan" iface "wlan0" protocol "dhcp" ;; tl-mr3420-v2|\ tl-wr841n-v8|\ @@ -458,7 +458,7 @@ ar71xx_setup_interfaces() ;; tl-wr841n-v1|\ tl-wr941nd) - ucidef_set_interface_raw "eth" "eth0" + ucidef_set_interface_raw "eth" iface "eth0" ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "wan" ;; tl-wr741nd|\