[LEDE-DEV,v3] base-files: expand ucidef_set_interface_raw to allow custom configuration

Message ID 20171205231641.13394-1-roman@advem.lv
State Changes Requested
Delegated to: John Crispin
Headers show
Series
  • [LEDE-DEV,v3] base-files: expand ucidef_set_interface_raw to allow custom configuration
Related show

Commit Message

Roman Yeryomin Dec. 5, 2017, 11:16 p.m.
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 <roman@advem.lv>
---
 .../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(-)

Patch

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|\