From patchwork Wed Aug 5 20:39:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [3/3] fff-network: fix code flow for one-port devices in configurenetwork From: Adrian Schmutzler X-Patchwork-Id: 1420 Message-Id: <20200805203959.53209-4-freifunk@adrianschmutzler.de> To: franken-dev@freifunk.net Date: Wed, 5 Aug 2020 22:39:59 +0200 So far, all one-port devices also triggered the switch-based setup in configurenetwork, as the one-port condition was not checked there. While the relevant parts are overwritten by the one-port config which comes later in the script, it still creates a lot of useless/broken switch/vlan setup entries in /etc/config/network. Properly check for one-port vs. non-one-port in the file, without touching anything else. Signed-off-by: Adrian Schmutzler --- src/packages/fff/fff-network/Makefile | 2 +- .../files/usr/sbin/configurenetwork | 108 +++++++++--------- 2 files changed, 56 insertions(+), 54 deletions(-) diff --git a/src/packages/fff/fff-network/Makefile b/src/packages/fff/fff-network/Makefile index c888205e..e1b603b5 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:=23 +PKG_RELEASE:=24 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) diff --git a/src/packages/fff/fff-network/files/usr/sbin/configurenetwork b/src/packages/fff/fff-network/files/usr/sbin/configurenetwork index e477bfa1..df7dcec1 100755 --- a/src/packages/fff/fff-network/files/usr/sbin/configurenetwork +++ b/src/packages/fff/fff-network/files/usr/sbin/configurenetwork @@ -71,66 +71,68 @@ if [ -n "$LAN1PORT" ] ; then setupPorts "$LAN1PORT" "${LAN1MODE}" fi -if ! uci -q get network.$SWITCHDEV > /dev/null || [ "$FORCEPARSE" = '1' ] ; then - - 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" ] || ! [ -z "$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 +if [ "$ONE_PORT" != "YES" ]; then + if ! uci -q get network.$SWITCHDEV > /dev/null || [ "$FORCEPARSE" = '1' ] ; then - 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" + SWITCHHW=$(swconfig list | awk '{ print $4 }') - uci set network.mesh.ifname="$SWITCHDEV.1 bat0" + 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.ethmesh.ifname="$SWITCHDEV.3" + 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" ]; then - uci set network.wan.ifname=$WANDEV.2 - else - uci set network.wan.ifname=$WANDEV - fi + if [ "$WANDEV" = "$SWITCHDEV" ] || ! [ -z "$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 commit network -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.mesh.ifname="$SWITCHDEV.1 bat0" + + uci set network.ethmesh.ifname="$SWITCHDEV.3" -if [ "$ONE_PORT" = "YES" ] && ( ! uci -q get network.$SWITCHDEV.ifname || [ "$FORCEPARSE" = '1' ] ) ; then - uci set network.$SWITCHDEV=interface - uci set network.$SWITCHDEV.ifname=$SWITCHDEV - if [ "$ETHMODE" = "WAN" ]; then - uci set network.mesh.ifname="bat0" - uci set network.wan.ifname="$WANDEV" - uci del network.ethmesh.ifname - uci del network.eth0.macaddr - elif [ "$ETHMODE" = "CLIENT" ] ; then - uci set network.mesh.ifname="bat0 $SWITCHDEV" - uci set network.wan.ifname="eth2" #eth2 because it is default in config file - uci del network.ethmesh.ifname - uci del network.eth0.macaddr - elif [ "$ETHMODE" = "BATMAN" ] ; then - uci set network.mesh.ifname="bat0" - uci set network.wan.ifname="eth2" #eth2 because it is default in config file - uci set network.ethmesh.ifname="$SWITCHDEV" - ETH0MAC="w2ap" + if [ "$WANDEV" = "$SWITCHDEV" ]; then + uci set network.wan.ifname=$WANDEV.2 + else + uci set network.wan.ifname=$WANDEV + fi + + uci commit network + fi +else + if ! uci -q get network.$SWITCHDEV.ifname || [ "$FORCEPARSE" = '1' ] ; then + uci set network.$SWITCHDEV=interface + uci set network.$SWITCHDEV.ifname=$SWITCHDEV + if [ "$ETHMODE" = "WAN" ]; then + uci set network.mesh.ifname="bat0" + uci set network.wan.ifname="$WANDEV" + uci del network.ethmesh.ifname + uci del network.eth0.macaddr + elif [ "$ETHMODE" = "CLIENT" ] ; then + uci set network.mesh.ifname="bat0 $SWITCHDEV" + uci set network.wan.ifname="eth2" #eth2 because it is default in config file + uci del network.ethmesh.ifname + uci del network.eth0.macaddr + elif [ "$ETHMODE" = "BATMAN" ] ; then + uci set network.mesh.ifname="bat0" + uci set network.wan.ifname="eth2" #eth2 because it is default in config file + uci set network.ethmesh.ifname="$SWITCHDEV" + ETH0MAC="w2ap" + fi + uci commit network fi - uci commit network fi /etc/init.d/network restart