From 9cc67c55ec74d23ee90c1daa5843a8aaca7f211a Mon Sep 17 00:00:00 2001 From: Adrian Schmutzler Date: Wed, 5 Aug 2020 22:31:19 +0200 Subject: [PATCH 1/4] fff-network: fix code flow for one-port devices in configurenetwork MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Acked-by: Fabian Bläse --- .../files/usr/sbin/configurenetwork | 110 +++++++++--------- 1 file changed, 56 insertions(+), 54 deletions(-) diff --git a/src/packages/fff/fff-network/files/usr/sbin/configurenetwork b/src/packages/fff/fff-network/files/usr/sbin/configurenetwork index 42dee1e2..de737500 100755 --- a/src/packages/fff/fff-network/files/usr/sbin/configurenetwork +++ b/src/packages/fff/fff-network/files/usr/sbin/configurenetwork @@ -65,66 +65,68 @@ if [ -n "$LAN1PORT" ] ; then setupPorts "$LAN1PORT" "${LAN1MODE}" fi -if ! uci -q get network.$SWITCHDEV > /dev/null || [ "$FORCEPARSE" = '1' ] ; then +if [ "$ONE_PORT" != "YES" ]; then + if ! uci -q get network.$SWITCHDEV > /dev/null || [ "$FORCEPARSE" = '1' ] ; then - SWITCHHW=$(swconfig list | awk '{ print $4 }') + 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=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" + 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" + 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 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" + + if [ "$WANDEV" = "$SWITCHDEV" ]; then + uci set network.wan.ifname=$WANDEV.2 + else + uci set network.wan.ifname=$WANDEV + 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.client.ifname="$SWITCHDEV.1 bat0" - - uci set network.ethmesh.ifname="$SWITCHDEV.3" - - if [ "$WANDEV" = "$SWITCHDEV" ]; then - uci set network.wan.ifname=$WANDEV.2 - else - uci set network.wan.ifname=$WANDEV +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.client.ifname="bat0" + uci set network.wan.ifname="$WANDEV" + uci del network.ethmesh.ifname + uci del network.${SWITCHDEV}.macaddr + elif [ "$ETHMODE" = "CLIENT" ] ; then + uci set network.client.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.${SWITCHDEV}.macaddr + elif [ "$ETHMODE" = "BATMAN" ] ; then + uci set network.client.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 - -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.client.ifname="bat0" - uci set network.wan.ifname="$WANDEV" - uci del network.ethmesh.ifname - uci del network.${SWITCHDEV}.macaddr - elif [ "$ETHMODE" = "CLIENT" ] ; then - uci set network.client.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.${SWITCHDEV}.macaddr - elif [ "$ETHMODE" = "BATMAN" ] ; then - uci set network.client.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 /etc/init.d/network restart -- 2.39.2 From 0c5ed565bdbc486ebebadc7a749909880c4eb08e Mon Sep 17 00:00:00 2001 From: Adrian Schmutzler Date: Tue, 8 Jun 2021 21:58:03 +0200 Subject: [PATCH 2/4] fff-network: support native two-port devices Support native two-port devices by adding TWO_PORT variable and exploiting the LAN0PORT and LAN1PORT variables designed for the TP-Link CPE devices. Since the latter have been converted to real two-port devices, we can now repurpose these variable for the new setup. This exploits the existing WANDEV and SWITCHDEV variables to define the primary and secondary interfaces. Note that by default this takes the initial values from network.mode, so if initial WAN/CLIENT should swapped, this has to be added to the relevant network.* file of the devices. No device-specific changes are done in this patch. Signed-off-by: Adrian Schmutzler --- src/packages/fff/fff-network/Makefile | 2 +- .../files/usr/sbin/configurenetwork | 143 ++++++++++-------- 2 files changed, 84 insertions(+), 61 deletions(-) diff --git a/src/packages/fff/fff-network/Makefile b/src/packages/fff/fff-network/Makefile index 057e3ccb..81b29cb1 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:=40 +PKG_RELEASE:=41 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 de737500..b1559758 100755 --- a/src/packages/fff/fff-network/files/usr/sbin/configurenetwork +++ b/src/packages/fff/fff-network/files/usr/sbin/configurenetwork @@ -4,23 +4,6 @@ . /lib/functions/system.sh . /lib/functions/fff/network -setupPorts() { - # Add a single port to the *_PORTS config - # Usage: setupPorts - - local port=$1 - local mode=$2 - - #default: BATMAN - if [ "$mode" = "WAN" ] ; then - WAN_PORTS="${WAN_PORTS} $port" - elif [ "$mode" = "CLIENT" ] ; then - CLIENT_PORTS="${CLIENT_PORTS} $port" - else - BATMAN_PORTS="${BATMAN_PORTS} $port" - fi -} - BOARD="$(uci get board.model.name)" . /etc/network.$BOARD [ -n "$ROUTERMAC" ] || ROUTERMAC=$(get_mac_label) @@ -37,10 +20,8 @@ else if [ "$ONE_PORT" = "YES" ] || [ -n "$ETHPORT" ] ; then echo "ETHMODE='$ETHMODE' # use BATMAN, CLIENT or WAN" >> /etc/network.config fi - if [ -n "$LAN0PORT" ] ; then + if [ -n "$TWO_PORT" ] ; then echo "LAN0MODE='$LAN0MODE' # use BATMAN, CLIENT or WAN" >> /etc/network.config - fi - if [ -n "$LAN1PORT" ] ; then echo "LAN1MODE='$LAN1MODE' # use BATMAN, CLIENT or WAN" >> /etc/network.config fi echo "FORCEPARSE='0' # Parse at: 0=first boot only, 1=every reboot, 2=next reboot (once)" >> /etc/network.config @@ -52,20 +33,84 @@ if [ "$FORCEPARSE" = '2' ] ; then FORCEPARSE='1' fi -if [ -n "$ETHPORT" ] ; then - #LAN@AR150: default: BATMAN - setupPorts "$ETHPORT" "${ETHMODE}" -fi -if [ -n "$LAN0PORT" ] ; then - #LAN0@two-port: default: BATMAN - setupPorts "$LAN0PORT" "${LAN0MODE}" -fi -if [ -n "$LAN1PORT" ] ; then - #LAN1@two-port: default: BATMAN - setupPorts "$LAN1PORT" "${LAN1MODE}" -fi +if [ "$ONE_PORT" = "YES" ]; then + 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.client.ifname="bat0" + uci set network.wan.ifname="$WANDEV" + uci del network.ethmesh.ifname + uci del network.${SWITCHDEV}.macaddr + elif [ "$ETHMODE" = "CLIENT" ] ; then + uci set network.client.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.${SWITCHDEV}.macaddr + elif [ "$ETHMODE" = "BATMAN" ] ; then + uci set network.client.ifname="bat0" + uci set network.wan.ifname="eth2" #eth2 because it is default in config file + uci set network.ethmesh.ifname="$SWITCHDEV" + ETH0DEV="$SWITCHDEV" + ETH0MAC="w2ap" + fi + uci commit network + fi +elif [ "$TWO_PORT" = "YES" ]; then + if ! uci -q get network.$WANDEV.ifname || [ "$FORCEPARSE" = '1' ] ; then + uci set network.$WANDEV=interface + uci set network.$WANDEV.ifname="$WANDEV" + uci set network.$SWITCHDEV=interface + uci set network.$SWITCHDEV.ifname="$SWITCHDEV" + # Only one WAN possible, second port will be unset if both are WAN + if [ "$LAN0MODE" = "WAN" ]; then + if [ "$LAN1MODE" = "CLIENT" ]; then + uci set network.client.ifname="bat0 $SWITCHDEV"; else + uci set network.client.ifname=bat0; fi + # WAN + uci set network.wan.ifname="$WANDEV" + if [ "$LAN1MODE" = "BATMAN" ]; then + uci set network.ethmesh.ifname="$SWITCHDEV"; else + uci del network.ethmesh.ifname; fi + # Two client ports are possible + elif [ "$LAN0MODE" = "CLIENT" ]; then + if [ "$LAN1MODE" = "CLIENT" ]; then + uci set network.client.ifname="bat0 $WANDEV $SWITCHDEV"; else + uci set network.client.ifname="bat0 $WANDEV"; fi + if [ "$LAN1MODE" = "WAN" ]; then + uci set network.wan.ifname="$SWITCHDEV"; else + uci set network.wan.ifname=eth2; fi #eth2 because it is default in config file + if [ "$LAN1MODE" = "BATMAN" ]; then + uci set network.ethmesh.ifname="$SWITCHDEV"; else + uci del network.ethmesh.ifname; fi + # Only one BATMAN port possible, second port will be unset if both are BATMAN + elif [ "$LAN0MODE" = "BATMAN" ] ; then + if [ "$LAN1MODE" = "CLIENT" ]; then + uci set network.client.ifname="bat0 $SWITCHDEV"; else + uci set network.client.ifname=bat0; fi + if [ "$LAN1MODE" = "WAN" ]; then + uci set network.wan.ifname="$SWITCHDEV"; else + uci set network.wan.ifname=eth2; fi #eth2 because it is default in config file + # BATMAN + uci set network.ethmesh.ifname="$WANDEV" + fi + if [ "$LAN0MODE" = "BATMAN" ]; then + ETH0DEV="$WANDEV" # only needed for setting macaddr + ETH0MAC=w2ap + uci del network.$SWITCHDEV.macaddr + elif [ "$LAN1MODE" = "BATMAN" ]; then + # $WANDEV will win if both are set to BATMAN, as above + ETH0DEV="$SWITCHDEV" # only needed for setting macaddr + ETH0MAC=w2ap + uci del network.$WANDEV.macaddr + else + uci del network.$WANDEV.macaddr + uci del network.$SWITCHDEV.macaddr + fi -if [ "$ONE_PORT" != "YES" ]; then + uci commit network + fi +else if ! uci -q get network.$SWITCHDEV > /dev/null || [ "$FORCEPARSE" = '1' ] ; then SWITCHHW=$(swconfig list | awk '{ print $4 }') @@ -103,28 +148,6 @@ if [ "$ONE_PORT" != "YES" ]; then 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.client.ifname="bat0" - uci set network.wan.ifname="$WANDEV" - uci del network.ethmesh.ifname - uci del network.${SWITCHDEV}.macaddr - elif [ "$ETHMODE" = "CLIENT" ] ; then - uci set network.client.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.${SWITCHDEV}.macaddr - elif [ "$ETHMODE" = "BATMAN" ] ; then - uci set network.client.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 fi @@ -168,14 +191,14 @@ if [ -n "$ROUTERMAC" ]; then fi if [ -n "$ETH0MAC" ]; then - echo "Fixing MAC on $SWITCHDEV" + echo "Fixing MAC on $ETH0DEV" sleep 10 NEW_MACADDR=$(cat "/sys/class/net/${ETH0MAC}/address") - uci set network.${SWITCHDEV}.macaddr=$NEW_MACADDR + uci set network.$ETH0DEV.macaddr=$NEW_MACADDR uci commit network - ifconfig $SWITCHDEV down - ifconfig $SWITCHDEV hw ether $NEW_MACADDR - ifconfig $SWITCHDEV up + ifconfig $ETH0DEV down + ifconfig $ETH0DEV hw ether $NEW_MACADDR + ifconfig $ETH0DEV up /etc/init.d/network restart fi -- 2.39.2 From b6308700b3501f12be69fc2165cd3183c8a040a0 Mon Sep 17 00:00:00 2001 From: Adrian Schmutzler Date: Wed, 9 Jun 2021 12:31:29 +0200 Subject: [PATCH 3/4] fff-network: improve "-n" vs. "-z" test in configurenetwork Simplify a single test. Signed-off-by: Adrian Schmutzler --- src/packages/fff/fff-network/Makefile | 2 +- src/packages/fff/fff-network/files/usr/sbin/configurenetwork | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/packages/fff/fff-network/Makefile b/src/packages/fff/fff-network/Makefile index 81b29cb1..cdbfa5cb 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:=41 +PKG_RELEASE:=42 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 b1559758..75edf03c 100755 --- a/src/packages/fff/fff-network/files/usr/sbin/configurenetwork +++ b/src/packages/fff/fff-network/files/usr/sbin/configurenetwork @@ -126,7 +126,7 @@ else uci set network.${SWITCHDEV}_1.vlan=1 uci set network.${SWITCHDEV}_1.ports="$CLIENT_PORTS" - if [ "$WANDEV" = "$SWITCHDEV" ] || ! [ -z "$WAN_PORTS" ]; then + 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 -- 2.39.2 From 0bfc3a656d4be6270bb47234422df4136cd0c7d8 Mon Sep 17 00:00:00 2001 From: Adrian Schmutzler Date: Wed, 9 Jun 2021 12:37:52 +0200 Subject: [PATCH 4/4] fff-network: adapt support for TP-Link CPE210/510 v1 This migrates the support for the TP-Link CPE210 v1 and CPE510 v1 so they are recognized by the new two-port setup code. Assignment of ports should be consistent to the ar71xx implementation, i.e. primary port (PoE in) assigned to WAN and secondary port (PoE out) assigned to CLIENT by default. Note that this is the exact opposite of the default configuration of what OpenWrt does (but both have been consistent in behavior). Since they work again, also re-enable image transfer. Signed-off-by: Adrian Schmutzler --- bsp/ath79-generic.bsp | 4 ++-- src/packages/fff/fff-network/Makefile | 2 +- .../fff-network/mips/network.tplink,cpe210-v1 | 16 ++-------------- .../fff-network/mips/network.tplink,cpe510-v1 | 16 ++-------------- 4 files changed, 7 insertions(+), 31 deletions(-) diff --git a/bsp/ath79-generic.bsp b/bsp/ath79-generic.bsp index b530d160..0402ee23 100644 --- a/bsp/ath79-generic.bsp +++ b/bsp/ath79-generic.bsp @@ -6,10 +6,10 @@ images=("openwrt-${chipset}-${subtarget}-glinet_gl-ar150-squashfs-*" "openwrt-${chipset}-${subtarget}-tplink_archer-c60-v2-squashfs-*" "openwrt-${chipset}-${subtarget}-tplink_archer-c7-v2-squashfs-*" "openwrt-${chipset}-${subtarget}-tplink_archer-c7-v5-squashfs-*" -# "openwrt-${chipset}-${subtarget}-tplink_cpe210-v1-squashfs-*" + "openwrt-${chipset}-${subtarget}-tplink_cpe210-v1-squashfs-*" "openwrt-${chipset}-${subtarget}-tplink_cpe210-v2-squashfs-*" "openwrt-${chipset}-${subtarget}-tplink_cpe210-v3-squashfs-*" -# "openwrt-${chipset}-${subtarget}-tplink_cpe510-v1-squashfs-*" + "openwrt-${chipset}-${subtarget}-tplink_cpe510-v1-squashfs-*" "openwrt-${chipset}-${subtarget}-tplink_tl-wdr3500-v1-squashfs-*" "openwrt-${chipset}-${subtarget}-tplink_tl-wdr3600-v1-squashfs-*" "openwrt-${chipset}-${subtarget}-tplink_tl-wdr4300-v1-squashfs-*" diff --git a/src/packages/fff/fff-network/Makefile b/src/packages/fff/fff-network/Makefile index cdbfa5cb..25f81c54 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:=42 +PKG_RELEASE:=43 include $(INCLUDE_DIR)/package.mk diff --git a/src/packages/fff/fff-network/mips/network.tplink,cpe210-v1 b/src/packages/fff/fff-network/mips/network.tplink,cpe210-v1 index 3c0a422b..0f2898fd 100644 --- a/src/packages/fff/fff-network/mips/network.tplink,cpe210-v1 +++ b/src/packages/fff/fff-network/mips/network.tplink,cpe210-v1 @@ -1,17 +1,5 @@ -. /lib/functions/fff/network - -WANDEV=eth0 +WANDEV=eth1 SWITCHDEV=eth0 -CLIENT_PORTS="0t" -WAN_PORTS="0t" -BATMAN_PORTS="0t" - -# use mac address from phy0 with 'locally administered' bit set to '1' -# only possible, because wXmesh is created first and therefore gets the 'universally administered address' - -ETHMESHMAC=$(macFlipLocalBit "$(cat /sys/class/ieee80211/phy0/macaddress)") +TWO_PORT=YES . /etc/network.mode - -LAN0PORT=5 -LAN1PORT=4 diff --git a/src/packages/fff/fff-network/mips/network.tplink,cpe510-v1 b/src/packages/fff/fff-network/mips/network.tplink,cpe510-v1 index 3c0a422b..0f2898fd 100644 --- a/src/packages/fff/fff-network/mips/network.tplink,cpe510-v1 +++ b/src/packages/fff/fff-network/mips/network.tplink,cpe510-v1 @@ -1,17 +1,5 @@ -. /lib/functions/fff/network - -WANDEV=eth0 +WANDEV=eth1 SWITCHDEV=eth0 -CLIENT_PORTS="0t" -WAN_PORTS="0t" -BATMAN_PORTS="0t" - -# use mac address from phy0 with 'locally administered' bit set to '1' -# only possible, because wXmesh is created first and therefore gets the 'universally administered address' - -ETHMESHMAC=$(macFlipLocalBit "$(cat /sys/class/ieee80211/phy0/macaddress)") +TWO_PORT=YES . /etc/network.mode - -LAN0PORT=5 -LAN1PORT=4 -- 2.39.2