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

Rafał Miłecki zajec5 at gmail.com
Fri May 14 02:21:47 PDT 2021


From: Rafał Miłecki <rafal at 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 at 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 --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
-- 
2.26.2




More information about the openwrt-devel mailing list