1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter.git synced 2025-02-15 04:42:02 +00:00

Added automatic switch setup in DSA mode

This commit is contained in:
Olli 2021-03-07 07:03:35 +01:00
parent c003535dfa
commit 35b806a8c9
2 changed files with 93 additions and 5 deletions

View file

@ -3,11 +3,20 @@ if [ -f "/etc/.lamobo-r1.dsa" ]; then
uci delete network.@switch_vlan[0]
uci delete network.@switch[0]
uci set network.lan.ifname="wan"
uci set network.wan1.ifname="lan1"
uci set network.wan2.ifname="lan2"
uci set network.wan3.ifname="lan3"
uci set network.wan4.ifname="lan4"
uci set network.lan.ifname="wan eth0"
uci set network.lan.type="bridge"
uci set network.wan1.ifname="lan1 eth0.11"
uci set network.wan1.type="bridge"
uci set network.wan2.ifname="lan2 eth0.12"
uci set network.wan2.type="bridge"
uci set network.wan3.ifname="lan3 eth0.13"
uci set network.wan3.type="bridge"
uci set network.wan4.ifname="lan4 eth0.14"
uci set network.wan4.type="bridge"
else
uci delete network.@switch_vlan[0]
uci delete network.@switch_vlan[1]

View file

@ -0,0 +1,79 @@
#!/bin/sh
# Copyright (C) 2009 OpenWrt.org
# Copyright (c) 2021 Oliver Welter
setup_switch_dsa() {
local tries=15
/bin/sleep 10
local bridge_names=`/sbin/uci show network | /bin/grep type | /bin/grep bridge | /usr/bin/cut -d . -f2`
for name in $bridge_names; do
local bridge_interface=`/sbin/uci get network.$name.ifname`
local trycount=1
while true; do
local my_interface=""
for intf in $bridge_interface; do
local eth=`/bin/echo $intf | /bin/grep -v eth`
if [ "$eth" != "" ]; then
my_interface="$eth"
fi
done
if [ "$my_interface" = "" ]; then
break
fi
local has_interface=`/sbin/ifconfig $my_interface >/dev/null 2>&1 && echo 1`
if [ "$has_interface" = "" ]; then
/bin/sleep 1
trycount=$(($trycount+1))
if [ $trycount -gt $tries ]; then
break
fi
else
break
fi
done
if [ "$has_interface" = "1" -a "$bridge_interface" != "" ]; then
for iface in $bridge_interface; do
local eth=`/bin/echo $iface | /bin/grep eth`
if [ "$eth" != "" ]; then
local vlan=`/bin/echo $iface | /usr/bin/cut -d . -f2`
if [ "$vlan" != "" -a "$vlan" != "$eth" ]; then
/usr/bin/logger -t switch.sh "Found interface $my_interface for alias $iface in bridge $name - adding to VLAN $vlan"
/usr/sbin/bridge vlan add dev $my_interface vid $vlan pvid untagged
fi
fi
done
fi
done
}
setup_switch_dev() {
local name
config_get name "$1" name
name="${name:-$1}"
[ -d "/sys/class/net/$name" ] && ip link set dev "$name" up
swconfig dev "$name" load network
}
setup_switch() {
config_load network
if [ -f "/etc/.lamobo-r1.dsa" ]; then
setup_switch_dsa & return
else
config_foreach setup_switch_dev switch
fi
}