diff mbox series

base-files: use "ports" array in board.json network for bridges

Message ID 20210514092147.30666-1-zajec5@gmail.com
State Accepted
Delegated to: Rafał Miłecki
Headers show
Series base-files: use "ports" array in board.json network for bridges | expand

Commit Message

Rafał Miłecki May 14, 2021, 9:21 a.m. UTC
From: Rafał Miłecki <rafal@milecki.pl>

Bridge aggregates multiple ports so use a more accurate name ("ports")
and format (array) for storing them in board.json.

Example:

"network": {
	"lan": {
		"ports": [
			"lan1",
			"lan2",
			"lan3",
			"lan4"
		],
		"protocol": "static"
	},
	"wan": {
		"ifname": "wan",
		"protocol": "dhcp"
	}
}

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
 package/base-files/files/bin/config_generate           | 5 ++++-
 package/base-files/files/lib/functions/uci-defaults.sh | 8 +++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/package/base-files/files/bin/config_generate b/package/base-files/files/bin/config_generate
index ee3958e733..a99f4f5968 100755
--- a/package/base-files/files/bin/config_generate
+++ b/package/base-files/files/bin/config_generate
@@ -91,15 +91,18 @@  generate_static_network() {
 
 addr_offset=2
 generate_network() {
-	local ifname macaddr protocol type ipaddr netmask vlan
+	local ports ifname macaddr protocol type ipaddr netmask vlan
 	local bridge=$2
 
 	json_select network
 		json_select "$1"
+			json_get_values ports ports
 			json_get_vars ifname macaddr protocol ipaddr netmask vlan
 		json_select ..
 	json_select ..
 
+	[ -n "$ports" ] && ifname="$ports"
+
 	[ -n "$ifname" ] || return
 
 	# force bridge for multi-interface devices (and lan)
diff --git a/package/base-files/files/lib/functions/uci-defaults.sh b/package/base-files/files/lib/functions/uci-defaults.sh
index 134c527d8d..407a9c710f 100644
--- a/package/base-files/files/lib/functions/uci-defaults.sh
+++ b/package/base-files/files/lib/functions/uci-defaults.sh
@@ -39,7 +39,13 @@  ucidef_set_interface() {
 
 		[ -n "$opt" -a -n "$val" ] || break
 
-		json_add_string "$opt" "$val"
+		[ "$opt" = "ifname" -a "$val" != "${val/ //}" ] && {
+			json_select_array "ports"
+			for e in $val; do json_add_string "" "$e"; done
+			json_close_array
+		} || {
+			json_add_string "$opt" "$val"
+		}
 	done
 
 	if ! json_is_a protocol string; then