forked from freifunk-franken/firmware
Fabian Bläse
15d259b98a
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 <fabian@blaese.de> Tested-by: Fabian Bläse <fabian@blaese.de>
265 lines
9.6 KiB
Bash
Executable File
265 lines
9.6 KiB
Bash
Executable File
#!/bin/sh
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
. /lib/functions/system.sh
|
|
. /lib/functions/fff/network
|
|
|
|
BOARD="$(uci get board.model.name)"
|
|
. /etc/network.$BOARD
|
|
[ -n "$ROUTERMAC" ] || ROUTERMAC=$(get_mac_label)
|
|
|
|
if [ -s /etc/network.config ] ; then
|
|
. /etc/network.config
|
|
else
|
|
# Write network.config
|
|
echo "CLIENT_PORTS='$CLIENT_PORTS'" > /etc/network.config
|
|
echo "BATMAN_PORTS='$BATMAN_PORTS'" >> /etc/network.config
|
|
if [ -n "$WAN_PORTS" ] ; then
|
|
echo "WAN_PORTS='$WAN_PORTS'" >> /etc/network.config
|
|
fi
|
|
if [ "$ONE_PORT" = "YES" ] || [ -n "$ETHPORT" ] ; then
|
|
echo "ETHMODE='$ETHMODE' # use BATMAN, CLIENT or WAN" >> /etc/network.config
|
|
fi
|
|
if [ -n "$TWO_PORT" ] ; then
|
|
echo "LAN0MODE='$LAN0MODE' # use BATMAN, CLIENT or WAN" >> /etc/network.config
|
|
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
|
|
fi
|
|
|
|
if [ "$FORCEPARSE" = '2' ] ; then
|
|
sed -i '/^FORCEPARSE/d' /etc/network.config
|
|
echo "FORCEPARSE='0' # Parse at: 0=first boot only, 1=every reboot, 2=next reboot (once)" >> /etc/network.config
|
|
FORCEPARSE='1'
|
|
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
|
|
|
|
uci commit network
|
|
fi
|
|
else
|
|
if ! uci -q get network.$SWITCHDEV > /dev/null || [ "$FORCEPARSE" = '1' ] ; then
|
|
|
|
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}_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"
|
|
|
|
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
|
|
|
|
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.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
|
|
fi
|
|
|
|
/etc/init.d/network restart
|
|
|
|
if [ -n "$ETHMESHMAC" ]; then
|
|
if uci get network.ethmesh.macaddr
|
|
then
|
|
echo "MAC for ethmesh is set already"
|
|
else
|
|
echo "Fixing MAC on $SWITCHDEV.3 (ethmesh)"
|
|
sleep 10
|
|
|
|
uci set network.ethmesh.macaddr=$ETHMESHMAC
|
|
uci commit network
|
|
|
|
ifconfig $SWITCHDEV.3 down
|
|
ifconfig $SWITCHDEV.3 hw ether $ETHMESHMAC
|
|
ifconfig $SWITCHDEV.3 up
|
|
/etc/init.d/network restart
|
|
fi
|
|
fi
|
|
|
|
if [ -n "$ROUTERMAC" ]; then
|
|
if uci get network.client.macaddr
|
|
then
|
|
echo "MAC for client is set already"
|
|
else
|
|
echo "Fixing MAC on br-client"
|
|
sleep 10
|
|
|
|
uci set network.client.macaddr=$ROUTERMAC
|
|
uci commit network
|
|
|
|
ifconfig br-client down
|
|
ifconfig br-client hw ether $ROUTERMAC
|
|
ifconfig br-client up
|
|
/etc/init.d/network restart
|
|
fi
|
|
fi
|
|
|
|
if [ -n "$ETH0MAC" ]; then
|
|
echo "Fixing MAC on $ETH0DEV"
|
|
sleep 10
|
|
NEW_MACADDR=$(cat "/sys/class/net/${ETH0MAC}/address")
|
|
uci set network.$ETH0DEV.macaddr=$NEW_MACADDR
|
|
uci commit network
|
|
ifconfig $ETH0DEV down
|
|
ifconfig $ETH0DEV hw ether $NEW_MACADDR
|
|
ifconfig $ETH0DEV up
|
|
/etc/init.d/network restart
|
|
fi
|
|
|
|
if uci -q get "network.client.ip6addr" > /dev/null
|
|
then
|
|
echo "IPv6 for client is set already"
|
|
else
|
|
echo "Setting IPv6 addresses"
|
|
# Some time needed :(
|
|
sleep 5
|
|
|
|
for ip in $(ip -6 addr show br-client | awk '/fdff/{ print $2 }'); do
|
|
ip -6 addr del $ip dev br-client
|
|
done
|
|
|
|
prefix="fdff::/64"
|
|
# Set $prefix::MAC as IP
|
|
addr=$(owipcalc "$prefix" add "::$(ipMacSuffix "$ROUTERMAC")")
|
|
ip -6 addr add $addr dev br-client
|
|
|
|
uci -q del network.globals
|
|
uci -q set network.globals=globals
|
|
uci -q set network.globals.ula_prefix=$prefix
|
|
uci -q add_list network.client.ip6addr=$addr
|
|
uci -q set network.client.proto=static
|
|
|
|
# Set $prefix::1 as IP
|
|
addr=$(owipcalc "$prefix" add ::1)
|
|
ip -6 addr add $addr dev br-client
|
|
uci -q add_list network.client.ip6addr=$addr
|
|
|
|
# Set $prefix::link-local as IP
|
|
addr=$(owipcalc "$prefix" add "::$(ipEUISuffix "$ROUTERMAC")")
|
|
ip -6 addr add $addr dev br-client
|
|
uci -q add_list network.client.ip6addr=$addr
|
|
|
|
uci -q commit network
|
|
|
|
[ -s /etc/init.d/fff-uradvd ] && /etc/init.d/fff-uradvd restart
|
|
fi
|