From 15d259b98a221b169f2a65b3bf66b14dab0b2c70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Bl=C3=A4se?= Date: Fri, 12 Feb 2021 03:39:47 +0100 Subject: [PATCH] fff-network: add support for DSA switch configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Starting with OpenWrt 21.02 some devices now use upstream kernel drivers for the built-in switch instead of relying on OpenWrt's swconfig driver. The upstream kernel drivers use the Distributed Switch Architecture (DSA) for configuration of the switch. Instead of explicitly configuring the hardware switch, all ports appear as distinct interfaces and linux bridges are offloaded to the hardware switch if possible. To keep changes small, this patch adds support for DSA devices by setting up a linux bridge, which is then treated just like the cpuport-interface of the swconfig driver. Signed-off-by: Fabian Bläse Tested-by: Fabian Bläse --- src/packages/fff/fff-layer3-config/Makefile | 2 +- .../files/etc/layer3.d/20-vlan | 8 ++- .../files/etc/layer3.d/30-network-client | 2 +- src/packages/fff/fff-network/Makefile | 2 +- .../files/usr/sbin/configurenetwork | 63 +++++++++++++------ 5 files changed, 53 insertions(+), 24 deletions(-) diff --git a/src/packages/fff/fff-layer3-config/Makefile b/src/packages/fff/fff-layer3-config/Makefile index 7a7588c0..867d788b 100644 --- a/src/packages/fff/fff-layer3-config/Makefile +++ b/src/packages/fff/fff-layer3-config/Makefile @@ -1,7 +1,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=fff-layer3-config -PKG_RELEASE:=6 +PKG_RELEASE:=7 include $(INCLUDE_DIR)/package.mk diff --git a/src/packages/fff/fff-layer3-config/files/etc/layer3.d/20-vlan b/src/packages/fff/fff-layer3-config/files/etc/layer3.d/20-vlan index 2ace14f1..81590ee0 100644 --- a/src/packages/fff/fff-layer3-config/files/etc/layer3.d/20-vlan +++ b/src/packages/fff/fff-layer3-config/files/etc/layer3.d/20-vlan @@ -13,7 +13,12 @@ configure() { local ports="$(uci -q get gateway.$vlan.ports)" local name="$SWITCHDEV"_$vlan - uci set network.$name='switch_vlan' + if [ "$DSA" = "1" ]; then + uci set network.$name='bridge-vlan' + else + uci set network.$name='switch_vlan' + fi + uci set network.$name.device="$(uci get network.$SWITCHDEV.name)" uci set network.$name.vlan="$vlan" uci set network.$name.ports="$(get_cpu_port) $ports" @@ -34,6 +39,7 @@ configure() { config_load network config_foreach remove_vlan switch_vlan + config_foreach remove_vlan bridge-vlan config_load gateway config_foreach add_vlan vlan diff --git a/src/packages/fff/fff-layer3-config/files/etc/layer3.d/30-network-client b/src/packages/fff/fff-layer3-config/files/etc/layer3.d/30-network-client index 371846cf..59865364 100644 --- a/src/packages/fff/fff-layer3-config/files/etc/layer3.d/30-network-client +++ b/src/packages/fff/fff-layer3-config/files/etc/layer3.d/30-network-client @@ -50,7 +50,7 @@ configure() { # set interface #remove all eth interfaces - ifaces=$(uci get network.client.ifname | sed 's/\beth[^ ]* *//g') + ifaces=$(uci get network.client.ifname | sed 's/\beth[^ ]* *//g' | sed 's/\bswitch[^ ]* *//g') if vlan=$(uci -q get gateway.@client[0].vlan); then uci set network.client.ifname="${SWITCHDEV}.$vlan $ifaces" elif iface=$(uci -q get gateway.@client[0].iface); then diff --git a/src/packages/fff/fff-network/Makefile b/src/packages/fff/fff-network/Makefile index 25cef9ee..982e45ab 100644 --- a/src/packages/fff/fff-network/Makefile +++ b/src/packages/fff/fff-network/Makefile @@ -1,7 +1,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=fff-network -PKG_RELEASE:=45 +PKG_RELEASE:=46 include $(INCLUDE_DIR)/package.mk diff --git a/src/packages/fff/fff-network/files/usr/sbin/configurenetwork b/src/packages/fff/fff-network/files/usr/sbin/configurenetwork index 75edf03c..a9721989 100755 --- a/src/packages/fff/fff-network/files/usr/sbin/configurenetwork +++ b/src/packages/fff/fff-network/files/usr/sbin/configurenetwork @@ -113,31 +113,54 @@ elif [ "$TWO_PORT" = "YES" ]; then else if ! uci -q get network.$SWITCHDEV > /dev/null || [ "$FORCEPARSE" = '1' ] ; then - SWITCHHW=$(swconfig list | awk '{ print $4 }') + if [ "$DSA" = "1" ]; then + uci set network.$SWITCHDEV=device + uci set network.$SWITCHDEV.name=$SWITCHDEV + uci set network.$SWITCHDEV.type=bridge - uci set network.$SWITCHDEV=switch - uci set network.$SWITCHDEV.name=$SWITCHHW - uci set network.$SWITCHDEV.enable=1 - uci set network.$SWITCHDEV.reset=1 - uci set network.$SWITCHDEV.enable_vlan=1 + uci set network.${SWITCHDEV}_1=bridge-vlan + uci set network.${SWITCHDEV}_1.device=$SWITCHDEV + uci set network.${SWITCHDEV}_1.vlan=1 + uci set network.${SWITCHDEV}_1.ports="$CLIENT_PORTS" - uci set network.${SWITCHDEV}_1=switch_vlan - uci set network.${SWITCHDEV}_1.device=$SWITCHHW - uci set network.${SWITCHDEV}_1.vlan=1 - uci set network.${SWITCHDEV}_1.ports="$CLIENT_PORTS" + if [ "$WANDEV" = "$SWITCHDEV" ] || ! [ -z "$WAN_PORTS" ]; then + uci set network.${SWITCHDEV}_2=bridge-vlan + uci set network.${SWITCHDEV}_2.device=$SWITCHDEV + uci set network.${SWITCHDEV}_2.vlan=2 + uci set network.${SWITCHDEV}_2.ports="$WAN_PORTS" + fi - if [ "$WANDEV" = "$SWITCHDEV" ] || [ -n "$WAN_PORTS" ]; then - uci set network.${SWITCHDEV}_2=switch_vlan - uci set network.${SWITCHDEV}_2.device=$SWITCHHW - uci set network.${SWITCHDEV}_2.vlan=2 - uci set network.${SWITCHDEV}_2.ports="$WAN_PORTS" + uci set network.${SWITCHDEV}_3=bridge-vlan + uci set network.${SWITCHDEV}_3.device=$SWITCHDEV + uci set network.${SWITCHDEV}_3.vlan=3 + uci set network.${SWITCHDEV}_3.ports="$BATMAN_PORTS" + else + SWITCHHW=$(swconfig list | awk '{ print $4 }') + + uci set network.$SWITCHDEV=switch + uci set network.$SWITCHDEV.name=$SWITCHHW + uci set network.$SWITCHDEV.enable=1 + uci set network.$SWITCHDEV.reset=1 + uci set network.$SWITCHDEV.enable_vlan=1 + + uci set network.${SWITCHDEV}_1=switch_vlan + uci set network.${SWITCHDEV}_1.device=$SWITCHHW + uci set network.${SWITCHDEV}_1.vlan=1 + uci set network.${SWITCHDEV}_1.ports="$CLIENT_PORTS" + + if [ "$WANDEV" = "$SWITCHDEV" ] || [ -n "$WAN_PORTS" ]; then + uci set network.${SWITCHDEV}_2=switch_vlan + uci set network.${SWITCHDEV}_2.device=$SWITCHHW + uci set network.${SWITCHDEV}_2.vlan=2 + uci set network.${SWITCHDEV}_2.ports="$WAN_PORTS" + fi + + uci set network.${SWITCHDEV}_3=switch_vlan + uci set network.${SWITCHDEV}_3.device=$SWITCHHW + uci set network.${SWITCHDEV}_3.vlan=3 + uci set network.${SWITCHDEV}_3.ports="$BATMAN_PORTS" fi - uci set network.${SWITCHDEV}_3=switch_vlan - uci set network.${SWITCHDEV}_3.device=$SWITCHHW - uci set network.${SWITCHDEV}_3.vlan=3 - uci set network.${SWITCHDEV}_3.ports="$BATMAN_PORTS" - uci set network.client.ifname="$SWITCHDEV.1 bat0" uci set network.ethmesh.ifname="$SWITCHDEV.3"