base-files: use "ports" array in board.json network for bridges
[openwrt/openwrt.git] / package / base-files / files / lib / functions / uci-defaults.sh
old mode 100755 (executable)
new mode 100644 (file)
index 12b9000..407a9c7
@@ -1,5 +1,3 @@
-#!/bin/ash
-
 . /lib/functions.sh
 . /usr/share/libubox/jshn.sh
 
@@ -41,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
@@ -68,6 +72,12 @@ ucidef_set_model_name() {
        json_select ..
 }
 
+ucidef_set_compat_version() {
+       json_select_object system
+       json_add_string compat_version "${1:-1.0}"
+       json_select ..
+}
+
 ucidef_set_interface_lan() {
        ucidef_set_interface "lan" ifname "$1" protocol "${2:-static}"
 }
@@ -84,6 +94,26 @@ ucidef_set_interfaces_lan_wan() {
        ucidef_set_interface_wan "$wan_if"
 }
 
+ucidef_set_bridge_device() {
+       json_select_object bridge
+       json_add_string name "${1:switch0}"
+       json_select ..
+}
+
+ucidef_set_bridge_mac() {
+       json_select_object bridge
+       json_add_string macaddr "${1}"
+       json_select ..
+}
+
+ucidef_set_network_device_mac() {
+       json_select_object "network-device"
+       json_select_object "${1}"
+       json_add_string macaddr "${2}"
+       json_select ..
+       json_select ..
+}
+
 _ucidef_add_switch_port() {
        # inherited: $num $device $need_tag $want_untag $role $index $prev_role
        # inherited: $n_cpu $n_ports $n_vlan $cpu0 $cpu1 $cpu2 $cpu3 $cpu4 $cpu5