Hi John,

> -----Original Message-----
> From: openwrt-devel [mailto:openwrt-devel-boun...@lists.openwrt.org]
> On Behalf Of John Crispin
> Sent: Dienstag, 3. November 2020 17:43
> To: openwrt-devel@lists.openwrt.org
> Cc: John Crispin <j...@phrozen.org>
> Subject: [PATCH] base-files: add board.d support for bridge device
> 
> Latest netifd allows us to setup network bridges with implicit vlan tagging. 
> For
> this to work, we need to setup several additional uci sections. This feature 
> is
> particularly usefull for DSA tupe devices.
> Add board.d and uci-defaults support for generating the sections.

Please also bump PKG_RELEASE for base-files when you apply this.

One typo below ...

> 
> Signed-off-by: John Crispin <j...@phrozen.org>
> ---
>  package/base-files/files/bin/config_generate  | 35 +++++++++++++++++--
>  .../files/lib/functions/uci-defaults.sh       |  4 +++
>  2 files changed, 37 insertions(+), 2 deletions(-)
> 
> diff --git a/package/base-files/files/bin/config_generate b/package/base-
> files/files/bin/config_generate
> index eb6816e519..e23f901504 100755
> --- a/package/base-files/files/bin/config_generate
> +++ b/package/base-files/files/bin/config_generate
> @@ -7,6 +7,28 @@ CFG=/etc/board.json
>  [ -s $CFG ] || /bin/board_detect || exit 1  [ -s /etc/config/network -a -s
> /etc/config/system ] && exit 0
> 
> +generate_bridge() {
> +     local name=$1
> +     uci -q batch <<-EOF
> +             set network.$name=device
> +             set network.$name.name=$name
> +             set network.$name.type=bridge
> +     EOF
> +}
> +
> +bridge_vlan_id=0
> +generate_bridge_vlan() {
> +     local device=$1
> +     local ports="$2"
> +     bridge_vlan_id=$((bridge_vlan_id + 1))
> +     uci -q batch <<-EOF
> +             add network bridge-vlan
> +             set network.@bridge-vlan[-1].device='$device'
> +             set network.@bridge-vlan[-1].vlan='$bridge_vlan_id'
> +             set network.@bridge-vlan[-1].ports='$ports'
> +     EOF
> +}
> +
>  generate_static_network() {
>       uci -q batch <<-EOF
>               delete network.loopback
> @@ -63,6 +85,7 @@ generate_static_network() {
>  addr_offset=2
>  generate_network() {
>       local ifname macaddr protocol type ipaddr netmask
> +     local bridge=$2
> 
>       json_select network
>               json_select "$1"
> @@ -77,6 +100,12 @@ generate_network() {
>               *\ * | lan:*) type="bridge" ;;
>       esac
> 
> +     [ -n "$bridge" ] && {
> +             generate_bridge_vlan $bridge "$ifname"
> +             ifname=$bridge.$bridge_vlan_id
> +             type=""
> +     }
> +
>       uci -q batch <<-EOF
>               delete network.$1
>               set network.$1='interface'
> @@ -236,7 +265,6 @@ generate_switch() {
>       json_select ..
>  }
> 
> -
>  generate_static_system() {
>       uci -q batch <<-EOF
>               delete system.@system[0]
> @@ -439,8 +467,11 @@ if [ ! -s /etc/config/network ]; then
>       touch /etc/config/network
>       generate_static_network
> 
> +     json_get_vars bridge
> +     [ -n "$bridge" ] && generate_bridge $bridge
> +
>       json_get_keys keys network
> -     for key in $keys; do generate_network $key; done
> +     for key in $keys; do generate_network $key $bridge; done
> 
>       json_get_keys keys switch
>       for key in $keys; do generate_switch $key; done diff --git
> a/package/base-files/files/lib/functions/uci-defaults.sh b/package/base-
> files/files/lib/functions/uci-defaults.sh
> index 27a409fe3b..73ba279fd5 100755
> --- a/package/base-files/files/lib/functions/uci-defaults.sh
> +++ b/package/base-files/files/lib/functions/uci-defaults.sh
> @@ -90,6 +90,10 @@ ucidef_set_interfaces_lan_wan() {
>       ucidef_set_interface_wan "$wan_if"
>  }
> 
> +ucidef_set_brigde_device() {

brigde->bridge

Best

Adrian

> +     json_add_string bridge "${1:switch0}"
> +}
> +
>  _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
> --
> 2.25.1
> 
> 
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Attachment: openpgp-digital-signature.asc
Description: PGP signature

_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to