layer3-config: Add dsa migration script

Due to the switch from swconfig to DSA, the switchport names have to be
migrated for some devices. Add a script to translate the switchport
names to their DSA equivalents, where applicable.

Fixes: #156

Signed-off-by: Fabian Bläse <fabian@blaese.de>
Reviewed-by: Robert Langhammer <rlanghammer@web.de>
Reviewed-by: Christian Dresel <freifunk@dresel.systems>
Tested-by: Fabian Bläse <fabian@blaese.de>
This commit is contained in:
Fabian Bläse 2021-09-03 00:34:04 +02:00
parent 341d215cf2
commit 984e334adb
2 changed files with 80 additions and 1 deletions

View File

@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=fff-layer3-config
PKG_RELEASE:=8
PKG_RELEASE:=9
include $(INCLUDE_DIR)/package.mk

View File

@ -0,0 +1,79 @@
## this script migrates configs from version 1 to 2.
##
## with version 2 the switchport names of some devices changed
## due to the switch to DSA
BOARD="$(uci get board.model.name)"
# only migrate appropriate config versions
[ "$(uci -q get gateway.meta.config_version)" = "1" ] || exit 1
translate_ports() {
local vlan="$1"
local oldports="$(uci -q get gateway.$vlan.ports)"
local newports
local name
local tag
for port in $oldports; do
# generate new tagged/untagged syntax
if [ -z "${port##*t}" ]; then
# port is tagged
tag=":t"
else
# port is untagged
tag=":*"
fi
# generate new name
case "$BOARD" in
ubnt,edgerouter-x|\
ubnt,edgerouter-x-sfp)
case "${port%%t}" in
0) name="eth0" ;;
1) name="eth1" ;;
2) name="eth2" ;;
3) name="eth3" ;;
4) name="eth4" ;;
5) name="eth5" ;;
*) name="" ;;
esac
;;
netgear,r6220)
case "${port%%t}" in
0) name="lan1" ;;
1) name="lan2" ;;
2) name="lan3" ;;
3) name="lan4" ;;
4) name="wan" ;;
*) name="" ;;
esac
;;
esac
# catch empty name (invalid entry or old cpuport)
[ -z "$name" ] && continue
# assemble new port name
newports="$newports ${name}${tag}"
done
# cleanup unnecessary spaces
newports=$(echo "$newports" | xargs)
uci set gateway.$vlan.ports="$newports"
}
case "$BOARD" in
ubnt,edgerouter-x|\
ubnt,edgerouter-x-sfp|\
netgear,r6220)
config_load gateway
config_foreach translate_ports vlan
;;
esac
uci set gateway.meta.config_version='2'
uci commit gateway