base-files: use "ports" array in board.json network for bridges
authorRafał Miłecki <rafal@milecki.pl>
Fri, 14 May 2021 09:09:57 +0000 (11:09 +0200)
committerRafał Miłecki <rafal@milecki.pl>
Mon, 24 May 2021 08:36:28 +0000 (10:36 +0200)
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>
(cherry picked from commit d42640e389a8b22a31fb0061c12cd9dfbddb87b8)

package/base-files/files/bin/config_generate
package/base-files/files/lib/functions/uci-defaults.sh

index ee3958e..56f6c44 100755 (executable)
@@ -91,21 +91,28 @@ 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 "$ifname" ] || return
+       [ -n "$ifname" -o -n "$ports" ] || return
 
-       # force bridge for multi-interface devices (and lan)
-       case "$1:$ifname" in
-               *\ * | lan:*) type="bridge" ;;
-       esac
+       # Force bridge for "lan" as it may have other devices (e.g. wireless)
+       # bridged
+       [ "$1" = "lan" -a -z "$ports" ] && {
+               ports="$ifname"
+       }
+
+       [ -n "$ports" ] && {
+               type="bridge"
+               ifname="$ports"
+       }
 
        [ -n "$bridge" ] && {
                if [ -z "$vlan" ]; then
index 134c527..407a9c7 100644 (file)
@@ -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